|
@@ -1,20 +1,31 @@
|
|
|
package com.abi.qms.platform.service.impl;
|
|
|
|
|
|
+import com.abi.qms.platform.dao.entity.UserInfo;
|
|
|
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.dao.vo.result.ListRoleVO;
|
|
|
import com.abi.qms.platform.dto.req.*;
|
|
|
import com.abi.qms.platform.dto.res.GetRoleInfoRes;
|
|
|
import com.abi.qms.platform.dto.res.ListResourceRes;
|
|
|
import com.abi.qms.platform.dto.res.ListRoleRes;
|
|
|
+import com.abi.qms.platform.infrastructure.util.AssertUtil;
|
|
|
+import com.abi.qms.platform.infrastructure.util.PageUtil;
|
|
|
+import com.abi.qms.platform.infrastructure.util.UserUtil;
|
|
|
import com.abi.qms.platform.service.RoleManagerService;
|
|
|
+import com.abi.qms.platform.service.UserResourceService;
|
|
|
import com.abi.task.common.api.exception.BusinessException;
|
|
|
+import com.abi.task.common.utils.PojoConverterUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 角色管理
|
|
@@ -31,6 +42,12 @@ public class RoleManagerServiceImpl implements RoleManagerService {
|
|
|
@Autowired
|
|
|
private UserMappingRoleResourceMapper userMappingRoleResourceMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserResourceService userResourceService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserUtil userUtil;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 创建角色
|
|
@@ -57,10 +74,11 @@ public class RoleManagerServiceImpl implements RoleManagerService {
|
|
|
userRoleMapper.updateById(userRole);
|
|
|
|
|
|
//4-放入角色资源mapping
|
|
|
+ userResourceService.saveUserResourceMapping(userRole.getRoleCode(),req.getResourceCodeList());
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 构造角色code
|
|
@@ -104,36 +122,84 @@ public class RoleManagerServiceImpl implements RoleManagerService {
|
|
|
* 修改角色
|
|
|
**/
|
|
|
@Override
|
|
|
- public void updateRole(UpdateRoleReq updateRoleReq) {
|
|
|
- //TODO
|
|
|
-
|
|
|
+ public void updateRole(UpdateRoleReq req) {
|
|
|
+ //1-查询角色信息
|
|
|
+ UserRole userRole = getRoleByCode(req.getRoleCode());
|
|
|
+ AssertUtil.isNull(userRole,"角色不存在");
|
|
|
+
|
|
|
+ //2-修改角色信息
|
|
|
+ userRole.setRoleName(req.getRoleName());
|
|
|
+ userRole.setRoleDesc(req.getRoleDesc());
|
|
|
+ userRoleMapper.updateById(userRole);
|
|
|
+
|
|
|
+ //3-放入角色资源mapping
|
|
|
+ userResourceService.saveUserResourceMapping(userRole.getRoleCode(),req.getResourceCodeList());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询单个角色信息
|
|
|
**/
|
|
|
@Override
|
|
|
- public GetRoleInfoRes getRoleInfo(GetRoleInfoReq getRoleInfoReq) {
|
|
|
- //TODO
|
|
|
- return null;
|
|
|
+ public GetRoleInfoRes getRoleInfo(GetRoleInfoReq req) {
|
|
|
+ //1-查询角色信息
|
|
|
+ UserRole userRole = getRoleByCode(req.getRoleCode());
|
|
|
+ AssertUtil.isNull(userRole,"角色不存在");
|
|
|
+
|
|
|
+ //2-角色资源列表(仅最底层那一级别的资源)
|
|
|
+ List<String> resourceCodeList = userResourceService.listResourceByRoleCode(userRole.getRoleCode());
|
|
|
+
|
|
|
+ //构造出参
|
|
|
+ GetRoleInfoRes res = PojoConverterUtils.copy(userRole,GetRoleInfoRes.class);
|
|
|
+ res.setResourceCodeList(resourceCodeList);
|
|
|
+
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询角色列表
|
|
|
**/
|
|
|
@Override
|
|
|
- public ListRoleRes listRole(ListRoleReq listRoleReq) {
|
|
|
- //TODO
|
|
|
- return null;
|
|
|
+ public ListRoleRes listRole(ListRoleReq req) {
|
|
|
+ //获取当前登录的用户
|
|
|
+ UserInfo user = userUtil.getUser();
|
|
|
+ //获取当前用户的角色
|
|
|
+ UserRole role = getRoleByCode(user.getRoleCode());
|
|
|
+
|
|
|
+ //1-查询角色信息
|
|
|
+ IPage<ListRoleVO> roleVOPage = userRoleMapper.listRoleFromRootRoleCode(PageUtil.createPage(req),req, role.getRoleCode(), role.getRoleLevel());
|
|
|
+ List<ListRoleVO> roleVOList = roleVOPage.getRecords();
|
|
|
+
|
|
|
+ //2-循环补充该角色有多少用户
|
|
|
+ List<ListRoleRes.RoleBean> roleBeanList = PojoConverterUtils.copyList(roleVOList, ListRoleRes.RoleBean.class);
|
|
|
+ for(ListRoleRes.RoleBean roleBean:roleBeanList){
|
|
|
+ Long userCount = userRoleMapper.countList(roleBean.getRoleCode());
|
|
|
+ roleBean.setUserCount(userCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ //构造出参
|
|
|
+ ListRoleRes res = new ListRoleRes();
|
|
|
+ res.setRoleBeanList(roleBeanList);
|
|
|
+
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询当前用户能看到的资源
|
|
|
**/
|
|
|
@Override
|
|
|
- public ListResourceRes listResource(ListResourceReq listResourceReq) {
|
|
|
- //TODO
|
|
|
- return null;
|
|
|
+ public ListResourceRes listResource() {
|
|
|
+ //获取当前登录的用户
|
|
|
+ UserInfo user = userUtil.getUser();
|
|
|
+ //获取当前用户的角色
|
|
|
+ UserRole role = getRoleByCode(user.getRoleCode());
|
|
|
+
|
|
|
+ //1-查询角色下所有资源
|
|
|
+ List<String> roleCodeList = userResourceService.listResourceByRoleCode(role.getRoleCode());
|
|
|
+
|
|
|
+ ListResourceRes res = new ListResourceRes();
|
|
|
+ res.setRoleCodeList(roleCodeList);
|
|
|
+
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -146,8 +212,12 @@ public class RoleManagerServiceImpl implements RoleManagerService {
|
|
|
QueryWrapper<UserRole> userRoleQw = new QueryWrapper<>();
|
|
|
userRoleQw.eq("role_code",roleCode);
|
|
|
userRoleQw.eq("is_delete",0);
|
|
|
- UserRole userRole = userRoleMapper.selectOne(userRoleQw);
|
|
|
+ List<UserRole> userRoleList = userRoleMapper.selectList(userRoleQw);
|
|
|
+ if(CollectionUtils.isEmpty(userRoleList)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- return userRole;
|
|
|
+ return userRoleList.get(0);
|
|
|
}
|
|
|
+
|
|
|
}
|