ソースを参照

给客户赋角色

shasha 3 ヶ月 前
コミット
0b80bb1294

+ 19 - 0
snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/customer/service/impl/BizCustomerServiceImpl.java

@@ -116,6 +116,11 @@ public class BizCustomerServiceImpl extends ServiceImpl<BizCustomerMapper, BizCu
                 throw new CommonException("手机号码:{}格式错误", bizCustomerAddParam.getPhone());
             }
         }
+        //查询用友平台ID是否添加过
+        long countYong = this.count(new QueryWrapper<BizCustomer>().lambda().eq(BizCustomer::getYongId, bizCustomerAddParam.getYongId()));
+        if(countYong>0){
+            throw new CommonException("客户关联的用友平台ID已存在!");
+        }
         //查询客户账号是否添加过
         long countLogin = this.count(new QueryWrapper<BizCustomer>().lambda().eq(BizCustomer::getLoginAccount, bizCustomerAddParam.getLoginAccount()));
         if(countLogin>0){
@@ -156,6 +161,20 @@ public class BizCustomerServiceImpl extends ServiceImpl<BizCustomerMapper, BizCu
             }
         }
         BizCustomer bizCustomer = this.queryEntity(bizCustomerEditParam.getId());
+        if(!StringUtils.equals(bizCustomer.getYongId(),bizCustomerEditParam.getYongId())){
+            //查询用友平台ID是否添加过
+            long countYong = this.count(new QueryWrapper<BizCustomer>().lambda().eq(BizCustomer::getYongId, bizCustomerEditParam.getYongId()));
+            if(countYong>0){
+                throw new CommonException("客户关联的用友平台ID已存在!");
+            }
+        }
+        if(!StringUtils.equals(bizCustomer.getLoginAccount(),bizCustomerEditParam.getLoginAccount())){
+            //查询客户账号是否添加过
+            long countLogin = this.count(new QueryWrapper<BizCustomer>().lambda().eq(BizCustomer::getLoginAccount, bizCustomerEditParam.getLoginAccount()));
+            if(countLogin>0){
+                throw new CommonException("客户账号已存在!");
+            }
+        }
         if(!StringUtils.equals(bizCustomer.getName(),bizCustomerEditParam.getName())){
             //查询客户名称是否添加过
             long count = this.count(new QueryWrapper<BizCustomer>().lambda().eq(BizCustomer::getName, bizCustomerEditParam.getName()));

+ 48 - 14
snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/goodsConf/service/impl/BizGoodsConfServiceImpl.java

@@ -44,6 +44,7 @@ import vip.xiaonuo.biz.modular.goodsConf.service.BizGoodsConfService;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -109,8 +110,8 @@ public class BizGoodsConfServiceImpl extends ServiceImpl<BizGoodsConfMapper, Biz
     public void add(BizGoodsConfAddParam goodsConfAddParam) {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         String goodsJson = goodsConfAddParam.getGoodsJson();
+        List<BizGoodsConf> goodsConfAddList = new ArrayList<>();
         if (ObjectUtil.isNotEmpty(goodsJson)) {
-
             JSONUtil.parseArray(goodsJson).forEach(object -> {
                 JSONObject jsonObject = JSONUtil.parseObj(object);
                 String goodsId = jsonObject.getStr("goodsId");
@@ -130,23 +131,34 @@ public class BizGoodsConfServiceImpl extends ServiceImpl<BizGoodsConfMapper, Biz
                         }
                         /** 货物id */
                         goodsConf.setGoodsId(goodsId);
-                        /** 货品编码 */
-                        goodsConf.setGoodsCode(bizGoods.getGoodsCode());
-                        /** 货品名称 */
-                        goodsConf.setGoodsName(bizGoods.getGoodsName());
-                        /** 货品规格 */
-                        goodsConf.setGoodsModel(bizGoods.getGoodsModel());
-                        /** 可提重量(KG) */
-                        goodsConf.setConfWeight(confWeight);
-                        /** 已提重量(KG) */
-                        goodsConf.setUsedWeight(0.0);
-                        /** 剩余提货重量(KG) */
-                        goodsConf.setLastWeight(goodsConf.getConfWeight());
-                        this.save(goodsConf);
+                        if(!checkGoodsConf(goodsConf)){
+                            // 当前时间段内的提货配置重叠了
+                            throw new CommonException("货品在当前的提货时间段内已存在其他配置信息("+ bizGoods.getGoodsName() +"),请重新选择。");
+                        }else {
+                            /** 货品编码 */
+                            goodsConf.setGoodsCode(bizGoods.getGoodsCode());
+                            /** 货品名称 */
+                            goodsConf.setGoodsName(bizGoods.getGoodsName());
+                            /** 货品规格 */
+                            goodsConf.setGoodsModel(bizGoods.getGoodsModel());
+                            /** 可提重量(KG) */
+                            goodsConf.setConfWeight(confWeight);
+                            /** 已提重量(KG) */
+                            goodsConf.setUsedWeight(0.0);
+                            /** 剩余提货重量(KG) */
+                            goodsConf.setLastWeight(goodsConf.getConfWeight());
+
+                            goodsConfAddList.add(goodsConf);
+                        }
                     }
                 }
             });
+
+            for (int i = 0; i < goodsConfAddList.size(); i++) {
+                this.save(goodsConfAddList.get(i));
+            }
         }
+
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -154,6 +166,11 @@ public class BizGoodsConfServiceImpl extends ServiceImpl<BizGoodsConfMapper, Biz
     public void edit(BizGoodsConfEditParam goodsConfEditParam) {
         BizGoodsConf goodsConf = this.queryEntity(goodsConfEditParam.getId());
         BeanUtil.copyProperties(goodsConfEditParam, goodsConf);
+        if(!checkGoodsConf(goodsConf)){
+            // 当前时间段内的提货配置重叠了
+            throw new CommonException("提货配置信息时间段重叠,请重新选择。");
+        }
+
         /** 可提重量(KG) */
         Double confWeight = goodsConf.getConfWeight();
         /** 已提重量(KG) */
@@ -184,6 +201,23 @@ public class BizGoodsConfServiceImpl extends ServiceImpl<BizGoodsConfMapper, Biz
         return goodsConf;
     }
 
+    // 校验 货品在当前时间段内是否已有配置信息
+    public Boolean checkGoodsConf(BizGoodsConf bizGoodsConf){
+        QueryWrapper<BizGoodsConf> queryWrapper = new QueryWrapper<BizGoodsConf>().checkSqlInjection();
+        queryWrapper.lambda().ne(ObjectUtil.isNotEmpty(bizGoodsConf.getId()), BizGoodsConf::getId, bizGoodsConf.getId());
+        queryWrapper.lambda().eq(BizGoodsConf::getGoodsId, bizGoodsConf.getGoodsId());
+        queryWrapper.lambda().lt(BizGoodsConf::getConfStartTime, bizGoodsConf.getConfEndTime());
+        queryWrapper.lambda().gt(BizGoodsConf::getConfEndTime, bizGoodsConf.getConfStartTime());
+        queryWrapper.lambda().eq(BizGoodsConf::getDeleteFlag, BizGoodsConfEnum.NOT_DELETE.getValue());
+        long count = this.count(queryWrapper);
+        if(count > 0){
+            return false;
+        }else{
+            return true;
+        }
+    }
+
+
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void editUsedWeight(String goodsConfId, Double newUsedWeight) {

+ 8 - 0
snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/relation/service/SysRelationService.java

@@ -81,6 +81,14 @@ public interface SysRelationService extends IService<SysRelation> {
      */
     void saveRelationBatchWithClear(String objectId, List<String> targetIdList, String category);
 
+    /**
+     * 清空原关系并保存为指定角色
+     *
+     * @author sandy
+     * @date 2025/3/27 11:29
+     */
+    void saveRelationTypeWithClear(String objectId, String roleName, String category);
+
     /**
      * 清空原关系并批量保存关系
      *

+ 35 - 0
snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/relation/service/impl/SysRelationServiceImpl.java

@@ -14,6 +14,7 @@ package vip.xiaonuo.sys.modular.relation.service.impl;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.ObjectUtil;
+import jakarta.annotation.Resource;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
@@ -21,6 +22,9 @@ import org.springframework.transaction.annotation.Transactional;
 import vip.xiaonuo.sys.modular.relation.entity.SysRelation;
 import vip.xiaonuo.sys.modular.relation.mapper.SysRelationMapper;
 import vip.xiaonuo.sys.modular.relation.service.SysRelationService;
+import vip.xiaonuo.sys.modular.role.service.SysRoleService;
+import vip.xiaonuo.sys.modular.role.entity.SysRole;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 
 import java.util.List;
 import java.util.stream.Collectors;
@@ -34,6 +38,9 @@ import java.util.stream.Collectors;
 @Service
 public class SysRelationServiceImpl extends ServiceImpl<SysRelationMapper, SysRelation> implements SysRelationService {
 
+    @Resource
+    private SysRoleService sysRoleService;
+
     @Transactional(rollbackFor = Exception.class)
     public void saveRelation(String objectId, String targetId, String category, String extJson, boolean clear) {
         // 是否需要先删除关系
@@ -72,6 +79,29 @@ public class SysRelationServiceImpl extends ServiceImpl<SysRelationMapper, SysRe
         }
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    public void saveRelationType(String objectId, String roleName, String category, boolean clear) {
+        // 是否需要先删除关系
+        if(clear) {
+            this.remove(new LambdaQueryWrapper<SysRelation>().eq(SysRelation::getObjectId, objectId)
+                    .eq(SysRelation::getCategory, category));
+        }
+        List<SysRelation> sysRelationList = CollectionUtil.newArrayList();
+        QueryWrapper<SysRole> queryWrapper = new QueryWrapper<SysRole>().checkSqlInjection();
+        queryWrapper.lambda().like(SysRole::getName, roleName);
+        List<SysRole> sysRoleList = this.sysRoleService.list(queryWrapper);
+        for(int i = 0; i < sysRoleList.size(); i++) {
+            SysRelation sysRelation = new SysRelation();
+            sysRelation.setObjectId(objectId);
+            sysRelation.setTargetId(sysRoleList.get(i).getId());
+            sysRelation.setCategory(category);
+            sysRelationList.add(sysRelation);
+        }
+        if(ObjectUtil.isNotEmpty(sysRelationList)) {
+            this.saveBatch(sysRelationList);
+        }
+    }
+
     @Override
     public void saveRelationWithAppend(String objectId, String targetId, String category) {
         this.saveRelation(objectId, targetId, category, null, false);
@@ -107,6 +137,11 @@ public class SysRelationServiceImpl extends ServiceImpl<SysRelationMapper, SysRe
         this.saveRelationBatch(objectId, targetIdList, category, null, true);
     }
 
+    @Override
+    public void saveRelationTypeWithClear(String objectId, String roleName, String category) {
+        this.saveRelationType(objectId, roleName, category, true);
+    }
+
     @Override
     public void saveRelationBatchWithClear(String objectId, List<String> targetIdList, String category, List<String> extJsonList) {
         this.saveRelationBatch(objectId, targetIdList, category, extJsonList, true);

+ 1 - 1
snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/provider/SysUserApiProvider.java

@@ -97,7 +97,7 @@ public class SysUserApiProvider implements SysUserApi {
         SysUserGrantRoleParam sysUserGrantRoleParam = new SysUserGrantRoleParam();
         sysUserGrantRoleParam.setId(userId);
         sysUserGrantRoleParam.setRoleName(roleName);
-        sysUserService.grantRole(sysUserGrantRoleParam);
+        sysUserService.grantRoleType(sysUserGrantRoleParam);
     }
 
     @Override

+ 8 - 0
snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/SysUserService.java

@@ -245,6 +245,14 @@ public interface SysUserService extends IService<SysUser> {
      **/
     void grantRole(SysUserGrantRoleParam sysUserGrantRoleParam);
 
+    /**
+     * 给用户授权指定名称角色
+     *
+     * @author sandy
+     * @date 2025/3/27 11:13
+     **/
+    void grantRoleType(SysUserGrantRoleParam sysUserGrantRoleParam) ;
+
     /**
      * 获取用户拥有资源
      *

+ 6 - 0
snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java

@@ -784,6 +784,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
                 SysRelationCategoryEnum.SYS_USER_HAS_ROLE.getValue());
     }
 
+    @Override
+    public void grantRoleType(SysUserGrantRoleParam sysUserGrantRoleParam) {
+        sysRelationService.saveRelationTypeWithClear(sysUserGrantRoleParam.getId(), sysUserGrantRoleParam.getRoleName(),
+                SysRelationCategoryEnum.SYS_USER_HAS_ROLE.getValue());
+    }
+
     @Override
     public SysUserOwnResourceResult ownResource(SysUserIdParam sysUserIdParam) {
         SysUserOwnResourceResult sysUserOwnResourceResult = new SysUserOwnResourceResult();