|
@@ -1,16 +1,19 @@
|
|
package com.abi.qms.platform.service.impl;
|
|
package com.abi.qms.platform.service.impl;
|
|
|
|
|
|
|
|
+import com.abi.qms.platform.dao.entity.UserRole;
|
|
|
|
+import com.abi.qms.platform.dao.enums.RoleLevelEnum;
|
|
|
|
+import com.abi.qms.platform.dao.mapper.UserMappingRoleResourceMapper;
|
|
|
|
+import com.abi.qms.platform.dao.mapper.UserRoleMapper;
|
|
import com.abi.qms.platform.dto.req.*;
|
|
import com.abi.qms.platform.dto.req.*;
|
|
import com.abi.qms.platform.dto.res.GetRoleInfoRes;
|
|
import com.abi.qms.platform.dto.res.GetRoleInfoRes;
|
|
import com.abi.qms.platform.dto.res.ListResourceRes;
|
|
import com.abi.qms.platform.dto.res.ListResourceRes;
|
|
import com.abi.qms.platform.dto.res.ListRoleRes;
|
|
import com.abi.qms.platform.dto.res.ListRoleRes;
|
|
import com.abi.qms.platform.service.RoleManagerService;
|
|
import com.abi.qms.platform.service.RoleManagerService;
|
|
|
|
+import com.abi.task.common.api.exception.BusinessException;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
-import org.springframework.util.StringUtils;
|
|
|
|
-
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -22,13 +25,79 @@ import java.util.List;
|
|
@Service
|
|
@Service
|
|
public class RoleManagerServiceImpl implements RoleManagerService {
|
|
public class RoleManagerServiceImpl implements RoleManagerService {
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserRoleMapper userRoleMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserMappingRoleResourceMapper userMappingRoleResourceMapper;
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 创建角色
|
|
* 创建角色
|
|
**/
|
|
**/
|
|
@Override
|
|
@Override
|
|
- public void createRole(CreateRoleReq createRoleReq) {
|
|
|
|
- //TODO
|
|
|
|
-
|
|
|
|
|
|
+ public void createRole(CreateRoleReq req) {
|
|
|
|
+ //1-查询上级角色信息
|
|
|
|
+ UserRole parentRole = getRoleByCode(req.getParentRoleCode());
|
|
|
|
+ if(RoleLevelEnum.LEVEL_5.is(parentRole.getRoleLevel())){
|
|
|
|
+ throw new BusinessException("父类是最底层角色,不可继续创建角色");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //2-插入角色信息
|
|
|
|
+ UserRole userRole = new UserRole();
|
|
|
|
+ userRole.setRoleName(req.getRoleName());
|
|
|
|
+ userRole.setRoleDesc(req.getRoleDesc());
|
|
|
|
+ userRole.setRoleLevel(parentRole.getRoleLevel()+1);
|
|
|
|
+ userRole.setParentRoleCode(req.getParentRoleCode());
|
|
|
|
+ userRoleMapper.insert(userRole);
|
|
|
|
+
|
|
|
|
+ //3-放入角色code以及对应level的角色code
|
|
|
|
+ userRole.setRoleCode(generateRoleCode(userRole.getId(),userRole.getRoleLevel()));
|
|
|
|
+ setUserLevelRoleCode(userRole,parentRole);
|
|
|
|
+ userRoleMapper.updateById(userRole);
|
|
|
|
+
|
|
|
|
+ //4-放入角色资源mapping
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 构造角色code
|
|
|
|
+ * 规则:level+n个0+id
|
|
|
|
+ * @param roleId
|
|
|
|
+ * @param roleLevel
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private String generateRoleCode(Long roleId,Integer roleLevel){
|
|
|
|
+ return roleLevel+ StringUtils.leftPad(String.valueOf(roleId), 10, "0");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 填充level1-5的角色code
|
|
|
|
+ * @param userRole
|
|
|
|
+ * @param parentUserRole
|
|
|
|
+ */
|
|
|
|
+ private void setUserLevelRoleCode(UserRole userRole,UserRole parentUserRole){
|
|
|
|
+ //1-先循环把父类的级别拷贝过来
|
|
|
|
+ userRole.setL1RoleCode(parentUserRole.getL1RoleCode());
|
|
|
|
+ userRole.setL2RoleCode(parentUserRole.getL2RoleCode());
|
|
|
|
+ userRole.setL3RoleCode(parentUserRole.getL3RoleCode());
|
|
|
|
+ userRole.setL4RoleCode(parentUserRole.getL4RoleCode());
|
|
|
|
+ userRole.setL5RoleCode(parentUserRole.getL3RoleCode());
|
|
|
|
+
|
|
|
|
+ //2-然后根据自己的层级,填充对应那一层的code
|
|
|
|
+ if(RoleLevelEnum.LEVEL_1.is(userRole.getRoleLevel())){
|
|
|
|
+ userRole.setL1RoleCode(userRole.getRoleCode());
|
|
|
|
+ }else if(RoleLevelEnum.LEVEL_2.is(userRole.getRoleLevel())){
|
|
|
|
+ userRole.setL2RoleCode(userRole.getRoleCode());
|
|
|
|
+ }else if(RoleLevelEnum.LEVEL_3.is(userRole.getRoleLevel())){
|
|
|
|
+ userRole.setL3RoleCode(userRole.getRoleCode());
|
|
|
|
+ }else if(RoleLevelEnum.LEVEL_4.is(userRole.getRoleLevel())){
|
|
|
|
+ userRole.setL4RoleCode(userRole.getRoleCode());
|
|
|
|
+ }else if(RoleLevelEnum.LEVEL_5.is(userRole.getRoleLevel())){
|
|
|
|
+ userRole.setL5RoleCode(userRole.getRoleCode());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -67,6 +136,18 @@ public class RoleManagerServiceImpl implements RoleManagerService {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 角色code查询角色信息
|
|
|
|
+ * @param roleCode
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public UserRole getRoleByCode(String roleCode) {
|
|
|
|
+ QueryWrapper<UserRole> userRoleQw = new QueryWrapper<>();
|
|
|
|
+ userRoleQw.eq("role_code",roleCode);
|
|
|
|
+ userRoleQw.eq("is_delete",0);
|
|
|
|
+ UserRole userRole = userRoleMapper.selectOne(userRoleQw);
|
|
|
|
|
|
-
|
|
|
|
|
|
+ return userRole;
|
|
|
|
+ }
|
|
}
|
|
}
|