pengcheng vor 3 Wochen
Ursprung
Commit
32bab7f250

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/clock/exception/AgentExceptionEnum.java

@@ -12,6 +12,8 @@ public enum AgentExceptionEnum implements IIntegerEnum {
     // TODO 注意检查错误码,保证系统内唯一
     AGENT_IS_NOT_EXISTS(200001, "代理商信息不存在"),
     AGENT_REPEAT(200002, "代理商已经存在"),
+    AGENT_USED(200003, "代理商下已存在门店,不能删除"),
+
 
 
     ;

+ 8 - 0
ruoyi-system/src/main/java/com/ruoyi/clock/service/IShopService.java

@@ -82,4 +82,12 @@ public interface IShopService {
      */
     Shop getShopByName(String shopName);
 
+    /**
+     * 查询门店信息
+     *
+     * @param agentId 代理商id
+     * @return 门店信息
+     */
+    Long selectShopCount(Long agentId);
+
 }

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/clock/service/impl/ActivityServiceImpl.java

@@ -3,6 +3,7 @@ package com.ruoyi.clock.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.ruoyi.clock.domain.Employee;
+import com.ruoyi.clock.domain.Shop;
 import com.ruoyi.clock.domain.bo.*;
 import com.ruoyi.clock.exception.ActivityExceptionEnum;
 import com.ruoyi.clock.service.IActivityAgentService;
@@ -189,4 +190,5 @@ public class ActivityServiceImpl implements IActivityService {
         activity.setStatus(bo.getStatus());
         return baseMapper.updateById(activity) > 0;
     }
+
 }

+ 9 - 0
ruoyi-system/src/main/java/com/ruoyi/clock/service/impl/AgentServiceImpl.java

@@ -3,6 +3,7 @@ package com.ruoyi.clock.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.ruoyi.clock.exception.AgentExceptionEnum;
+import com.ruoyi.clock.service.IShopService;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.BeanCopyUtils;
 import com.ruoyi.common.utils.StringUtils;
@@ -35,6 +36,7 @@ import java.util.Collection;
 public class AgentServiceImpl implements IAgentService {
 
     private final AgentMapper baseMapper;
+    private final IShopService shopService;
 
     /**
      * 查询代理商信息分页
@@ -159,6 +161,13 @@ public class AgentServiceImpl implements IAgentService {
     public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
         if(isValid){
             //TODO 做一些业务上的校验,判断是否需要校验
+            ids.forEach(agentId -> {
+                Long shopCount = shopService.selectShopCount(agentId);
+                //被使用的类别不能删除
+                if(shopCount > 0){
+                    throw new ServiceException(AgentExceptionEnum.AGENT_USED);
+                }
+            });
         }
         return baseMapper.deleteBatchIds(ids) > 0;
     }

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/clock/service/impl/ShopServiceImpl.java

@@ -149,6 +149,10 @@ public class ShopServiceImpl implements IShopService {
             .last("limit 1"));
     }
 
+    @Override
+    public Long selectShopCount(Long agentId) {
+        return baseMapper.selectCount(new LambdaQueryWrapper<Shop>().eq(Shop::getAgentId,agentId));
+    }
 
     /**
      * 批量删除门店信息