浏览代码

修改区域主管角色信息

黄远 5 年之前
父节点
当前提交
cf0a61d62d

+ 24 - 7
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/MtCompanyUserService.java

@@ -71,18 +71,35 @@ public class MtCompanyUserService extends ServiceImpl<MtCompanyUserMapper, MtCom
     public RestResponse assignRole(MtCompanyUserRequest mtCompanyUserRequest) {
         //获取用户是否已有mtCompanyUser信息。
         MtCompanyUser mtCompanyUser = this.getById(mtCompanyUserRequest.getId());
-        //保存职业信息
-        mtCompanyUser.setJob(mtCompanyUserRequest.getJob());
-        this.updateById(mtCompanyUser);
         //保存用户角色关联信息
         Long roleId = mtCompanyUserRequest.getRoleId();
         Long userId = mtCompanyUser.getUserId();
         Long companyId = mtCompanyUser.getMtCompanyId();
+        //获取用户原来关联的角色信息
+        UserRole userRole = userRoleService.getOne(new QueryWrapper<UserRole>()
+                .eq("company_id", companyId)
+                .eq("user_id", userId)
+        );
+        if (userRole != null) {
+            //获取用户的角色信息
+            Role role = roleService.getById(userRole.getId());
+            if (role != null) {
+                //若角色为区域主管,判断角色是否有关联的信息
+                if (CommonEnum.DefaultRole.REGION_DIRECTOR.getCode().equals(role.getCode())) {
+                    Map<String, String> judgeMsg = projectService.judgeKickOutTeam(new ProjectUser(userId, companyId));
+                    if (ApiConstants.RESULT_ERROR.equals(judgeMsg.get(CommonConstants.RETURN_CODE_FIELD))) {
+                        return RestResponse.fail(ApiConstants.RESULT_ERROR, "区域主管存在关联项目无法更改角色信息");
+                    }
+                }
+            }
+        }
+        //保存职业信息
+        mtCompanyUser.setJob(mtCompanyUserRequest.getJob());
+        if (!this.updateById(mtCompanyUser)) {
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return RestResponse.fail(ApiConstants.RESULT_ERROR, "更新职业信息失败");
+        }
         if (roleId != null) {
-            UserRole userRole = userRoleService.getOne(new QueryWrapper<UserRole>()
-                    .eq("company_id", companyId)
-                    .eq("user_id", userId)
-            );
             if (userRole != null) {
                 //删除原有的关联关系
                 boolean deleteUserRoleFlag = userRoleService.removeById(userRole.getId());