多店铺需求
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
package com.czg.service.account.mapper;
|
||||
|
||||
import com.czg.account.dto.ShopBranchDTO;
|
||||
import com.czg.account.entity.ShopConfig;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 店铺配置扩展
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-04-03
|
||||
*/
|
||||
* 店铺配置扩展
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-04-03
|
||||
*/
|
||||
@Mapper
|
||||
public interface ShopConfigMapper extends BaseMapper<ShopConfig> {
|
||||
|
||||
|
||||
List<ShopBranchDTO> findBranchList(@Param("shopId") Long shopId);
|
||||
|
||||
}
|
||||
@@ -49,6 +49,8 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
@Resource
|
||||
private SysMenuMapper sysMenuMapper;
|
||||
@Resource
|
||||
private ShopBranchService shopBranchService;
|
||||
@Resource
|
||||
private HandoverRecordService handoverRecordService;
|
||||
|
||||
|
||||
@@ -140,7 +142,10 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
throw new ApiNotPrintException("店铺已到期,请联系区域经理续费");
|
||||
}
|
||||
}
|
||||
|
||||
boolean isAllowAccountLogin = shopBranchService.isAllowAccountLogin(shopInfo.getId());
|
||||
if (!isAllowAccountLogin) {
|
||||
throw new ApiNotPrintException("当前分店账号被禁止登录");
|
||||
}
|
||||
StpKit.USER.login(user.getId(), user.getAccount(), shopInfo.getId(), shopInfo.getShopName(), isStaff ? MyStpLogic.LoginType.STAFF : MyStpLogic.LoginType.MANAGER, user.getIsAdmin());
|
||||
// 查询角色
|
||||
List<SysRole> roleList = sysRoleService.getByUserId(user.getId());
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import com.czg.account.dto.ShopBranchDTO;
|
||||
import com.czg.account.entity.ShopConfig;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.czg.account.enums.BranchDataSyncMethodEnum;
|
||||
import com.czg.account.enums.ShopTypeEnum;
|
||||
import com.czg.account.service.ShopBranchService;
|
||||
import com.czg.enums.YesNoEnum;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.account.mapper.ShopConfigMapper;
|
||||
import com.czg.service.account.mapper.ShopInfoMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分店管理Service实现类
|
||||
*
|
||||
* @author tankaikai
|
||||
* @since 2025-04-07 14:20
|
||||
*/
|
||||
@Service
|
||||
public class ShopBranchServiceImpl implements ShopBranchService {
|
||||
|
||||
@Resource
|
||||
private ShopConfigMapper shopConfigMapper;
|
||||
|
||||
@Resource
|
||||
private ShopInfoMapper shopInfoMapper;
|
||||
|
||||
@Override
|
||||
public Page<ShopBranchDTO> findPage(Long shopId) {
|
||||
PageHelper.startPage(PageUtil.buildPageHelp());
|
||||
List<ShopBranchDTO> branchList = shopConfigMapper.findBranchList(shopId);
|
||||
return PageUtil.convert(new PageInfo<>(branchList));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void settingDataSyncMethod(Long shopId, String dataSyncMethod) {
|
||||
ShopInfo shopInfo = shopInfoMapper.selectOneById(shopId);
|
||||
if (shopInfo == null) {
|
||||
throw new CzgException("店铺不存在");
|
||||
}
|
||||
ShopConfig shopConfig = shopConfigMapper.selectOneById(shopInfo.getId());
|
||||
if (shopConfig == null) {
|
||||
throw new CzgException("店铺配置信息不存在");
|
||||
}
|
||||
if (ShopTypeEnum.ONLY.getValue().equals(shopInfo.getShopType())) {
|
||||
throw new CzgException("单店不支持设置数据同步方式");
|
||||
}
|
||||
if (ObjUtil.defaultIfNull(shopInfo.getIsHeadShop(), 0) == YesNoEnum.NO.value()) {
|
||||
throw new CzgException("非主店不能设置数据同步方式");
|
||||
}
|
||||
boolean contains = BranchDataSyncMethodEnum.checkValue(dataSyncMethod);
|
||||
if (!contains) {
|
||||
throw new CzgException("非法的数据同步方式值");
|
||||
}
|
||||
shopConfig.setBranchDataSyncMethod(dataSyncMethod);
|
||||
shopConfigMapper.update(shopConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dataSyncEnable(Long branchShopId) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
ShopInfo shopInfo = shopInfoMapper.selectOneById(shopId);
|
||||
if (shopInfo == null) {
|
||||
throw new CzgException("主店铺不存在");
|
||||
}
|
||||
ShopConfig shopConfig = shopConfigMapper.selectOneById(shopInfo.getId());
|
||||
if (shopConfig == null) {
|
||||
throw new CzgException("主店铺配置信息不存在");
|
||||
}
|
||||
if (ShopTypeEnum.ONLY.getValue().equals(shopInfo.getShopType())) {
|
||||
throw new CzgException("数据错误:主单店铺类型为单店");
|
||||
}
|
||||
if (ObjUtil.defaultIfNull(shopInfo.getIsHeadShop(), 0) == YesNoEnum.NO.value()) {
|
||||
throw new CzgException("数据错误:当前店铺不是主店");
|
||||
}
|
||||
ShopInfo branchShop = shopInfoMapper.selectOneByQuery(QueryWrapper.create().eq(ShopInfo::getMainId, shopInfo.getId()).eq(ShopInfo::getId, branchShopId));
|
||||
if (branchShop == null) {
|
||||
throw new CzgException("对应的分店信息不存在");
|
||||
}
|
||||
if (ShopTypeEnum.ONLY.getValue().equals(branchShop.getShopType())) {
|
||||
throw new CzgException("数据错误:分店店铺类型错误");
|
||||
}
|
||||
ShopConfig branchConfig = shopConfigMapper.selectOneById(branchShop.getId());
|
||||
branchConfig.setIsEnableProdSync(YesNoEnum.YES.value());
|
||||
branchConfig.setIsEnableConsSync(YesNoEnum.YES.value());
|
||||
branchConfig.setIsEnableVipSync(YesNoEnum.YES.value());
|
||||
shopConfigMapper.update(branchConfig);
|
||||
// TODO 异步事务同步商品数据、会员数据、耗材数据
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accountEnable(Long branchShopId) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
ShopInfo shopInfo = shopInfoMapper.selectOneById(shopId);
|
||||
if (shopInfo == null) {
|
||||
throw new CzgException("主店铺不存在");
|
||||
}
|
||||
ShopConfig shopConfig = shopConfigMapper.selectOneById(shopInfo.getId());
|
||||
if (shopConfig == null) {
|
||||
throw new CzgException("主店铺配置信息不存在");
|
||||
}
|
||||
if (ShopTypeEnum.ONLY.getValue().equals(shopInfo.getShopType())) {
|
||||
throw new CzgException("数据错误:主单店铺类型为单店");
|
||||
}
|
||||
if (ObjUtil.defaultIfNull(shopInfo.getIsHeadShop(), 0) == YesNoEnum.NO.value()) {
|
||||
throw new CzgException("数据错误:当前店铺不是主店");
|
||||
}
|
||||
ShopInfo branchShop = shopInfoMapper.selectOneByQuery(QueryWrapper.create().eq(ShopInfo::getMainId, shopInfo.getId()).eq(ShopInfo::getId, branchShopId));
|
||||
if (branchShop == null) {
|
||||
throw new CzgException("对应的分店信息不存在");
|
||||
}
|
||||
if (ShopTypeEnum.ONLY.getValue().equals(branchShop.getShopType())) {
|
||||
throw new CzgException("数据错误:分店店铺类型错误");
|
||||
}
|
||||
ShopConfig branchConfig = shopConfigMapper.selectOneById(branchShop.getId());
|
||||
branchConfig.setIsAllowAccountLogin(YesNoEnum.YES.value());
|
||||
shopConfigMapper.update(branchConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accountDisable(Long branchShopId) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
ShopInfo shopInfo = shopInfoMapper.selectOneById(shopId);
|
||||
if (shopInfo == null) {
|
||||
throw new CzgException("主店铺不存在");
|
||||
}
|
||||
ShopConfig shopConfig = shopConfigMapper.selectOneById(shopInfo.getId());
|
||||
if (shopConfig == null) {
|
||||
throw new CzgException("主店铺配置信息不存在");
|
||||
}
|
||||
if (ShopTypeEnum.ONLY.getValue().equals(shopInfo.getShopType())) {
|
||||
throw new CzgException("数据错误:主单店铺类型为单店");
|
||||
}
|
||||
if (ObjUtil.defaultIfNull(shopInfo.getIsHeadShop(), 0) == YesNoEnum.NO.value()) {
|
||||
throw new CzgException("数据错误:当前店铺不是主店");
|
||||
}
|
||||
ShopInfo branchShop = shopInfoMapper.selectOneByQuery(QueryWrapper.create().eq(ShopInfo::getMainId, shopInfo.getId()).eq(ShopInfo::getId, branchShopId));
|
||||
if (branchShop == null) {
|
||||
throw new CzgException("对应的分店信息不存在");
|
||||
}
|
||||
if (ShopTypeEnum.ONLY.getValue().equals(branchShop.getShopType())) {
|
||||
throw new CzgException("数据错误:分店店铺类型错误");
|
||||
}
|
||||
ShopConfig branchConfig = shopConfigMapper.selectOneById(branchShop.getId());
|
||||
branchConfig.setIsAllowAccountLogin(YesNoEnum.NO.value());
|
||||
shopConfigMapper.update(branchConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowAccountLogin(Long branchShopId) {
|
||||
ShopConfig shopConfig = shopConfigMapper.selectOneById(branchShopId);
|
||||
if (shopConfig == null) {
|
||||
return true;
|
||||
}
|
||||
if (shopConfig.getMainId() == null) {
|
||||
return true;
|
||||
}
|
||||
if (shopConfig.getIsAllowAccountLogin() == YesNoEnum.YES.value()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -352,4 +353,22 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
||||
PageHelper.startPage(PageUtil.buildPageHelp());
|
||||
return PageUtil.convert(new PageInfo<>(mapper.getSubList(lng, lat, distance)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ShopBranchSelectDTO> findShopBranch(Long shopId) {
|
||||
List<ShopBranchSelectDTO> list = new ArrayList<>();
|
||||
ShopInfo shopInfo = mapper.selectOneById(shopId);
|
||||
ShopBranchSelectDTO head = new ShopBranchSelectDTO();
|
||||
head.setShopId(shopInfo.getId());
|
||||
head.setShopName(shopInfo.getShopName());
|
||||
list.add(head);
|
||||
List<ShopInfo> branchList = mapper.selectListByQuery(query().select(ShopInfo::getId, ShopInfo::getShopName).eq(ShopInfo::getMainId, shopId).orderBy(ShopInfo::getId, true));
|
||||
for (ShopInfo info : branchList) {
|
||||
ShopBranchSelectDTO branch = new ShopBranchSelectDTO();
|
||||
head.setShopId(info.getId());
|
||||
head.setShopName(info.getShopName());
|
||||
list.add(branch);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,14 @@
|
||||
|
||||
<mapper namespace="com.czg.service.account.mapper.ShopConfigMapper">
|
||||
|
||||
<select id="findBranchList" resultType="com.czg.account.dto.ShopBranchDTO">
|
||||
select t1.*,
|
||||
t2.shop_name,
|
||||
t2.phone,
|
||||
t3.account
|
||||
from tb_shop_config t1
|
||||
left join tb_shop_info t2 on t1.id = t2.id
|
||||
left join sys_user t3 on t1.id = t3.id
|
||||
where t1.main_id = #{shopId}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user