Bladeren bron

后线人员修改

785834757 2 jaren geleden
bovenliggende
commit
5e21c48369

+ 45 - 0
src/main/java/com/ydtech/modules/admin/constants/RoleConstants.java

@@ -0,0 +1,45 @@
+package com.ydtech.modules.admin.constants;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.Getter;
+
+@AllArgsConstructor
+@Getter
+public enum RoleConstants {
+
+    R01("1", "超级管理员",""),
+    R02("2", "初始用户权限",""),
+    R17("17", "部长","42,22,19,17"),
+    R18("18","门店长",""),
+    R19("19","出单员",""),
+    R20("20","代理人",""),
+    R21("21","团队长",""),
+    R22("22","后线人员",""),
+    R23("23","运营总监",""),
+    R24("24","系统管理员",""),
+    R25("25","人员管理",""),
+    R28("28","财务专员",""),
+    R29("29","总公司最高管理权限",""),
+    R30("30","核保部门",""),
+    R31("31","总公司人事行政部",""),
+    R32("32","财务部门",""),
+    R38("38","运营管理权限",""),
+    R39("39","测试角色",""),
+    R40("40","cc",""),
+    R42("42","机构管理员","42,22,19");
+
+    private final String code;
+    private final String name;
+    private final String roleIds;
+
+
+    public static RoleConstants getRoleConstants(String code) {
+        for (RoleConstants roleConstants : RoleConstants.values()) {
+            if (roleConstants.getCode().equals(code)) {
+                return roleConstants;
+            }
+        }
+        return null;
+    }
+}

+ 12 - 1
src/main/java/com/ydtech/modules/admin/controller/SysLoginController.java

@@ -7,8 +7,12 @@ import com.google.code.kaptcha.Producer;
 import com.ydtech.config.MasterPasswordConfig;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.exception.SystemException;
+import com.ydtech.modules.admin.model.SysRole;
 import com.ydtech.modules.admin.model.SysUser;
+import com.ydtech.modules.admin.model.SysUserRole;
 import com.ydtech.modules.admin.model.vo.LoginBean;
+import com.ydtech.modules.admin.service.SysRoleService;
+import com.ydtech.modules.admin.service.SysUserRoleService;
 import com.ydtech.modules.admin.service.SysUserService;
 import com.ydtech.security.utils.PasswordUtils;
 import com.ydtech.utils.IPUtil;
@@ -60,6 +64,8 @@ public class SysLoginController {
 
     private final StringRedisTemplate redisTemplate;
 
+    private final SysUserRoleService sysUserRoleService;
+
     private final MasterPasswordConfig masterPasswordConfig;
 
     @GetMapping("captcha.jpg")
@@ -169,6 +175,7 @@ public class SysLoginController {
 //
         // 用户信息
         SysUser user = sysUserService.getById(username);
+
         //验证用户
         SysUser.verifyUser(user);
 
@@ -181,7 +188,11 @@ public class SysLoginController {
                 return HttpResult.error("密码不正确");
             }
         }
-
+        //查询用户角色
+        SysRole sysRole = sysUserRoleService.gainRoleByUserId(user.getId());
+        //设置用户角色
+        user.setRoleId(sysRole.getId().toString());
+        user.setRoleName(sysRole.getName());
         // 获取这个人的token
         String token = StpUtil.createLoginSession(user.getId());
         StpUtil.getSessionByLoginId(user.getId()).set(SaSession.USER, user);

+ 14 - 2
src/main/java/com/ydtech/modules/admin/controller/SysRoleController.java

@@ -4,10 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.ydtech.constants.SysConstants;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.core.page.PageRequest;
+import com.ydtech.modules.admin.constants.RoleConstants;
 import com.ydtech.modules.admin.model.SysRole;
 import com.ydtech.modules.admin.model.SysRoleMenu;
+import com.ydtech.modules.admin.model.SysUser;
 import com.ydtech.modules.admin.service.SysRoleMenuService;
 import com.ydtech.modules.admin.service.SysRoleService;
+import com.ydtech.modules.base.controller.BaseController;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
@@ -24,7 +27,7 @@ import java.util.stream.Collectors;
  */
 @RestController
 @RequestMapping("role")
-public class SysRoleController {
+public class SysRoleController extends BaseController {
 
     @Autowired
     private SysRoleService sysRoleService;
@@ -69,9 +72,18 @@ public class SysRoleController {
 //    @PreAuthorize("hasAuthority('sys:role:view')")
     @GetMapping(value = "/findAll")
     public HttpResult findAll() {
+        //获取登录人员该有的角色信息
+        SysUser user = getUser();
         LambdaQueryWrapper<SysRole> lqw = new LambdaQueryWrapper<>();
+        //获取角色的配置信息
+        RoleConstants roleConstants = RoleConstants.getRoleConstants(user.getRoleId());
+        if(!"".equals(roleConstants.getRoleIds())){
+            lqw.in(SysRole::getId,RoleConstants.R42.getRoleIds().split(","));
+        }
+
         lqw.eq(SysRole::getDelFlag,"0");
-        return HttpResult.ok(sysRoleService.list(lqw));
+        List<SysRole> list = sysRoleService.list(lqw);
+        return HttpResult.ok(list);
 //        return HttpResult.ok(sysRoleService.selectAll());
     }
 

+ 40 - 22
src/main/java/com/ydtech/modules/admin/controller/SysUserController.java

@@ -10,6 +10,7 @@ import com.ydtech.core.page.HttpResult;
 import com.ydtech.core.page.PageRequest;
 import com.ydtech.core.page.PageResult;
 import com.ydtech.exception.SystemException;
+import com.ydtech.modules.admin.constants.RoleConstants;
 import com.ydtech.modules.admin.model.*;
 import com.ydtech.modules.admin.model.dto.AgentUserDto;
 import com.ydtech.modules.admin.model.dto.SysUserDto;
@@ -42,6 +43,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.Valid;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
@@ -365,6 +367,23 @@ public class SysUserController extends BaseController {
     @ApiOperation(value = "(重构)用户查询分页")
     @PostMapping(value = "/findPage")
     public HttpResult<PageVo<SysUserBaseVO>> findPage(@RequestBody PageDto<SysUserDto> pageDto) {
+        //获取用户角色
+        SysUser user = getUser();
+        List<String> roleIds = new ArrayList<String>();
+        //机构管理员
+        roleIds.add(RoleConstants.R42.getCode());
+        //后线人员
+        roleIds.add(RoleConstants.R22.getCode());
+        if(RoleConstants.R01.getCode().equals(user.getRoleId()) ||
+                RoleConstants.R01.getCode().equals(user.getRoleId())){
+            //部长
+            roleIds.add(RoleConstants.R17.getCode());
+        }
+        pageDto.getDto().setRoleId(String.join(",",roleIds));
+        //设置登录用户的部门
+        if("".equals(pageDto.getDto().getDeptId())) {
+            pageDto.getDto().setDeptId(user.getDeptId());
+        }
         return HttpResult.ok(sysUserService.gainUserPage(pageDto));
 
     }
@@ -698,7 +717,6 @@ public class SysUserController extends BaseController {
     @ApiOperation(value = "保存用户基本详情信息")
     @PostMapping(value = "/saveUserInfo")
     public HttpResult saveUserInfo(@RequestBody SysUser2Vo sysUserVo) {
-
         //by gws 21	团队长 20	代理人 必须归属团队
         // 22	后线人员 必须归属部门
         SysUser sysUser = sysUserVo.getSysUser();
@@ -711,32 +729,30 @@ public class SysUserController extends BaseController {
         if (StringUtils.isNullOrEmpty(sysUser.getRoleId())) {
             throw new SystemException("角色id不能为空");
         }
+        //获取机构层级
+        int deptLevel = sysUserService.getDeptLevel(sysUserVo);
         if (!StringUtils.isNullOrEmpty(sysUser.getRoleId())) {
-            if ("21".equals(sysUser.getRoleId()) || "20".equals(sysUser.getRoleId())|| "19".equals(sysUser.getRoleId())) {//19 出单员 21	团队长 20	代理人
-                boolean teamflag = false;
-                char[] deptids = sysUser.getDeptId().toCharArray();
-                char ch1 = 'D';
-                char ch2 = 'M';
-                if (deptids.length > 6) {
-                    teamflag = deptids[deptids.length - 3] == ch1 && deptids[deptids.length - 6] == ch2;
-                }
-                if (!teamflag) {
+            if (RoleConstants.R21.getCode().equals(sysUser.getRoleId())
+                    || RoleConstants.R20.getCode().equals(sysUser.getRoleId())
+                    || RoleConstants.R19.getCode().equals(sysUser.getRoleId())) {//19 出单员 21	团队长 20	代理人
+
+                if (deptLevel != 6) {
                     throw new SystemException("团队长、代理人、出单员只能归属团队中");
                 }
-            } else if ("22".equals(sysUser.getRoleId())) {//22	后线人员
-                boolean deptflag = false;
-                char[] deptids = sysUser.getDeptId().toCharArray();
-                char ch1 = 'D';
-                char ch2 = 'M';
-                if (deptids.length > 6) {
-                    deptflag = deptids[deptids.length - 3] == ch1 && deptids[deptids.length - 6] != ch2;
-                } else if (deptids.length > 3) {
-                    deptflag = deptids[deptids.length - 3] == ch1;
-                }
-                if (!deptflag) {
+            } else if (RoleConstants.R22.getCode().equals(sysUser.getRoleId())) {//22	后线人员
+
+                if (deptLevel != 5) {
                     throw new SystemException("后线人员只能归属业务部门中");
                 }
-            } else {
+            } else if (RoleConstants.R42.getCode().equals(sysUser.getRoleId())){ // 42 机构管理员
+                if(deptLevel != 5){
+                    throw new SystemException("机构管理员只能归属机构中");
+                }
+            } else if(RoleConstants.R17.getCode().equals(sysUser.getRoleId())){
+                if(deptLevel != 4){
+                    throw new SystemException("部长只能归属于4级");
+                }
+            }else {
                 throw new SystemException("角色id有误");
             }
 
@@ -745,6 +761,8 @@ public class SysUserController extends BaseController {
     }
 
 
+
+
     @ApiOperation(value = "修改用户详情信息")
     @PostMapping(value = "/updateUserInfo/{userId}")
     @ApiImplicitParams({

+ 2 - 0
src/main/java/com/ydtech/modules/admin/service/SysUserService.java

@@ -102,6 +102,8 @@ public interface SysUserService extends IService<SysUser> {
     public List<SysUser> getAllUsers(String userId);
 
     public List<SysUser> findAllAgentRoleUser(String userId,String roleId);
+
+    public int getDeptLevel(SysUser2Vo sysUser2Vo);
 }
 
 

+ 16 - 0
src/main/java/com/ydtech/modules/admin/service/impl/SysUserServiceImpl.java

@@ -527,6 +527,22 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
     public List<SysUser> findAllAgentRoleUser(String userId,String roleId) {
         return super.baseMapper.findAllAgentRoleUser(userId,roleId);
     }
+
+    @Override
+    public int getDeptLevel(SysUser2Vo sysUser2Vo) {
+        //获取机构层级
+        SysUser sysUser = sysUser2Vo.getSysUser();
+        String deptId = sysUser.getDeptId();
+        int level = 0;
+        //1 2 3 4 5级 M 6级 D
+        if(deptId.length() > 8){
+            String substring = deptId.substring(8);
+            return substring.length() / 3 + 4;
+        }else{
+            level = deptId.length() / 2;
+        }
+        return level;
+    }
 }
 
 

+ 1 - 1
src/main/resources/mapper/modules/admin/SysUserMapper.xml

@@ -113,7 +113,7 @@
                  and su.dept_id like concat('%',#{user.deptId},'%')
                 </if>
             <if test='user.roleId !=null and user.roleId!=""  '>
-                 and t3.role_id = #{user.roleId}
+                 and t3.role_id in (${user.roleId})
                 </if>
             </if>