Quellcode durchsuchen

增加机构编码生成

lsj2008bj vor 1 Jahr
Ursprung
Commit
63940165cf
10 geänderte Dateien mit 91 neuen und 2 gelöschten Zeilen
  1. 5 0
      sso-module-system/sso-module-system-api/src/main/java/com/poteviohealth/cgp/sso/module/system/enums/ErrorCodeConstants.java
  2. 4 0
      sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/controller/admin/dept/vo/dept/DeptRespVO.java
  3. 3 0
      sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/controller/admin/dept/vo/dept/DeptSaveReqVO.java
  4. 3 0
      sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/controller/admin/dept/vo/dept/DeptSimpleRespVO.java
  5. 1 0
      sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/controller/admin/userclient/UserClientController.java
  6. 4 0
      sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/controller/admin/userclient/vo/UserClientRespVO.java
  7. 3 0
      sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/dal/dataobject/dept/DeptDO.java
  8. 4 0
      sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/dal/dataobject/oauth2/OAuth2ClientDO.java
  9. 3 0
      sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/dal/dataobject/sequence/SequenceDO.java
  10. 61 2
      sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/service/dept/DeptServiceImpl.java

+ 5 - 0
sso-module-system/sso-module-system-api/src/main/java/com/poteviohealth/cgp/sso/module/system/enums/ErrorCodeConstants.java

@@ -83,6 +83,8 @@ public interface ErrorCodeConstants {
 
     ErrorCode DEPT_LEVEL_BIG_THREE = new ErrorCode(1_002_004_010, "不支持三级以上机构");
 
+    ErrorCode DEPT_NULL_PARAM = new ErrorCode(1_002_004_011, "参数错误");
+
     // ========== 岗位模块 1-002-005-000 ==========
     ErrorCode POST_NOT_FOUND = new ErrorCode(1_002_005_000, "当前岗位不存在");
     ErrorCode POST_NOT_ENABLE = new ErrorCode(1_002_005_001, "岗位({}) 不处于开启状态,不允许选择");
@@ -196,4 +198,7 @@ public interface ErrorCodeConstants {
 
     ErrorCode SEQUENCE_NOT_EXISTS = new ErrorCode(1_002_029_000, "系统序列不存在");
 
+
+
+
 }

+ 4 - 0
sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/controller/admin/dept/vo/dept/DeptRespVO.java

@@ -95,4 +95,8 @@ public class DeptRespVO {
     @Schema(description = "附加信息", example = "中康科")
     private String remark;
 
+    @Schema(description = "负责人的用户姓名", example = "2048")
+    private String leaderUserName;
+
+
 }

+ 3 - 0
sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/controller/admin/dept/vo/dept/DeptSaveReqVO.java

@@ -111,4 +111,7 @@ public class DeptSaveReqVO {
     @Schema(description = "附加信息", example = "中康科")
     private String remark;
 
+    @Schema(description = "负责人的用户姓名", example = "2048")
+    private String leaderUserName;
+
 }

+ 3 - 0
sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/controller/admin/dept/vo/dept/DeptSimpleRespVO.java

@@ -86,4 +86,7 @@ public class DeptSimpleRespVO {
     @Schema(description = "附加信息", example = "中康科")
     private String remark;
 
+    @Schema(description = "负责人的用户姓名", example = "2048")
+    private String leaderUserName;
+
 }

+ 1 - 0
sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/controller/admin/userclient/UserClientController.java

@@ -123,6 +123,7 @@ public class UserClientController {
                 AdminUserDO adminUserDO = userMap.get(Long.parseLong(item.getCreator()));
                 if (Objects.nonNull(oAuth2ClientDO)) {
                     item.setClientName(oAuth2ClientDO.getName());
+                    item.setPermissionsLink(oAuth2ClientDO.getPermissionsLink());
                 }
                 if (Objects.nonNull(adminUserDO)) {
                     item.setCreatorDesc(adminUserDO.getName());

+ 4 - 0
sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/controller/admin/userclient/vo/UserClientRespVO.java

@@ -53,4 +53,8 @@ public class UserClientRespVO {
 
     private boolean canAuthorization = false;
 
+
+    @Schema(description = "授权链接", example = "1")
+    private Integer permissionsLink;
+
 }

+ 3 - 0
sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/dal/dataobject/dept/DeptDO.java

@@ -129,4 +129,7 @@ public class DeptDO extends TenantBaseDO {
 
     @Schema(description = "附加信息", example = "中康科")
     private String remark;
+
+    @Schema(description = "负责人姓名", example = "中康科")
+    private String leaderUserName;
 }

+ 4 - 0
sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/dal/dataobject/oauth2/OAuth2ClientDO.java

@@ -132,4 +132,8 @@ public class OAuth2ClientDO extends BaseDO {
     @Schema(description = "自定义appSecret", example = "1")
     private String appSecret;
 
+    @Schema(description = "授权链接", example = "1")
+    private Integer permissionsLink;
+
+
 }

+ 3 - 0
sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/dal/dataobject/sequence/SequenceDO.java

@@ -43,4 +43,7 @@ public class SequenceDO extends BaseDO {
      */
     private Integer increment;
 
+
+    private Integer version;
+
 }

+ 61 - 2
sso-module-system/sso-module-system-biz/src/main/java/com/poteviohealth/cgp/sso/module/system/service/dept/DeptServiceImpl.java

@@ -2,13 +2,17 @@ package com.poteviohealth.cgp.sso.module.system.service.dept;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.poteviohealth.cgp.sso.framework.common.enums.CommonStatusEnum;
 import com.poteviohealth.cgp.sso.framework.common.util.object.BeanUtils;
 import com.poteviohealth.cgp.sso.framework.datapermission.core.annotation.DataPermission;
 import com.poteviohealth.cgp.sso.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
 import com.poteviohealth.cgp.sso.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
 import com.poteviohealth.cgp.sso.module.system.dal.dataobject.dept.DeptDO;
+import com.poteviohealth.cgp.sso.module.system.dal.dataobject.sequence.SequenceDO;
 import com.poteviohealth.cgp.sso.module.system.dal.mysql.dept.DeptMapper;
+import com.poteviohealth.cgp.sso.module.system.dal.mysql.sequence.SequenceMapper;
 import com.poteviohealth.cgp.sso.module.system.dal.mysql.user.AdminUserMapper;
 import com.poteviohealth.cgp.sso.module.system.dal.redis.RedisKeyConstants;
 import com.google.common.annotations.VisibleForTesting;
@@ -18,10 +22,12 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
+import org.springframework.security.core.parameters.P;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
+import java.text.DecimalFormat;
 import java.util.*;
 
 import static com.poteviohealth.cgp.sso.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -42,6 +48,12 @@ public class DeptServiceImpl implements DeptService {
     private DeptMapper deptMapper;
     @Resource
     private AdminUserMapper adminUserMapper;
+    @Resource
+    private SequenceMapper sequenceMapper;
+
+
+    private static final DecimalFormat dfCompany = new DecimalFormat("000");
+    private static final DecimalFormat dfinstitution = new DecimalFormat("0000");
 
     @Override
     @CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
@@ -56,7 +68,7 @@ public class DeptServiceImpl implements DeptService {
         // 校验部门名的唯一性
         validateDeptNameUnique(null, createReqVO.getParentId(), createReqVO.getName());
         // 校验部门编码唯一性
-        validateDeptCodeUnique(null, createReqVO.getParentId(), createReqVO.getCode());
+//        validateDeptCodeUnique(null, createReqVO.getParentId(), createReqVO.getCode());
 
         if(!createReqVO.getParentId().equals(DeptDO.PARENT_ID_ROOT)){
             DeptDO parentDept = deptMapper.selectById(createReqVO.getParentId());
@@ -68,12 +80,58 @@ public class DeptServiceImpl implements DeptService {
         }else{
             createReqVO.setLevel(1);
         }
+        //自动生成部门编码
+        String code = constructDeptCode(createReqVO);
+        if(StringUtils.isEmpty(code)){
+            throw exception(DEPT_NULL_PARAM);
+        }
+        createReqVO.setCode(code);
         // 插入部门
         DeptDO dept = BeanUtils.toBean(createReqVO, DeptDO.class);
         deptMapper.insert(dept);
         return dept.getId();
     }
 
+    private String constructDeptCode(DeptSaveReqVO createReqVO) {
+        String deptCode = StringUtils.EMPTY;
+
+       if(Objects.isNull(createReqVO.getParentId())|| Objects.isNull(createReqVO.getLevel())) {
+           return deptCode;
+       }
+        SequenceDO sequenceDO = null;
+       if(createReqVO.getLevel()==1){
+           sequenceDO = sequenceMapper.selectOne(new QueryWrapper<SequenceDO>().lambda().eq(SequenceDO::getName, "dept").eq(SequenceDO::getType, "group"));
+       }
+       if(createReqVO.getLevel()==2){
+           sequenceDO = sequenceMapper.selectOne(new QueryWrapper<SequenceDO>().lambda().eq(SequenceDO::getName, "dept").eq(SequenceDO::getType, "company"));
+       }
+       if(createReqVO.getLevel()==3){
+           sequenceDO = sequenceMapper.selectOne(new QueryWrapper<SequenceDO>().lambda().eq(SequenceDO::getName, "dept").eq(SequenceDO::getType, "institution"));
+       }
+
+       if(Objects.nonNull(sequenceDO)){
+           Integer currentValue = sequenceDO.getCurrentValue()+1;
+           int updateNum = sequenceMapper.update(new UpdateWrapper<SequenceDO>().lambda().set(SequenceDO::getCurrentValue, currentValue).set(SequenceDO::getVersion, sequenceDO.getVersion() + 1).eq(SequenceDO::getId, sequenceDO.getId()));
+           if(updateNum==0){
+               return deptCode;
+           }
+           if(createReqVO.getLevel()==1 ){
+               deptCode = String.valueOf(createReqVO.getAreaId())+dfCompany.format(currentValue);
+           } else if(createReqVO.getLevel()==2){
+               deptCode = String.valueOf(createReqVO.getAreaId())+dfCompany.format(currentValue)+"0000";
+           }
+           else{
+               DeptDO deptDO = this.deptMapper.selectById(createReqVO.getParentId());
+               if(Objects.nonNull(deptDO)){
+                   String companyCode = deptDO.getCode().substring(6,9);
+                   deptCode = String.valueOf(createReqVO.getAreaId())+companyCode+dfinstitution.format(currentValue);
+               }
+           }
+       }
+       return deptCode;
+
+    }
+
     @Override
     @CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
             allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存
@@ -89,7 +147,7 @@ public class DeptServiceImpl implements DeptService {
         // 校验部门名的唯一性
         validateDeptNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName());
         // 校验部门编码唯一性
-        validateDeptCodeUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getCode());
+//        validateDeptCodeUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getCode());
         DeptDO deptDO = deptMapper.selectById(updateReqVO.getId());
         if(deptDO.getParentId().compareTo(updateReqVO.getParentId())!=0
                 &&!updateReqVO.getParentId().equals(DeptDO.PARENT_ID_ROOT)){
@@ -97,6 +155,7 @@ public class DeptServiceImpl implements DeptService {
             updateReqVO.setLevel(parentDept.getLevel()+1);
             updateReqVO.setTreePath(StringUtils.isNotEmpty(parentDept.getTreePath())?parentDept.getTreePath()+","+parentDept.getId():String.valueOf(parentDept.getId()));
         }
+        updateReqVO.setCode(null);
         // 更新部门
         DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class);
         deptMapper.updateById(updateObj);