From aa5f2e221887d16ab0c83dca5430befb405f41fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?niohe=C2=B7erbao?= Date: Fri, 5 May 2023 16:06:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=93=E5=AE=B6=E5=8F=AF?= =?UTF-8?q?=E6=8E=A7=E8=A7=92=E8=89=B2=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/sys/service/impl/RoleServiceImpl.java | 2 ++ .../pmapi/user/controller/RoleInfoController.java | 20 ----------- .../pmapi/user/controller/UserInfoController.java | 7 ++++ .../com/ningdatech/pmapi/user/entity/RoleInfo.java | 41 ---------------------- .../pmapi/user/manage/UserInfoManage.java | 39 ++++++++++++++++++++ 5 files changed, 48 insertions(+), 61 deletions(-) delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/user/controller/RoleInfoController.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/user/entity/RoleInfo.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java index 46e9844..e47f79c 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java @@ -24,6 +24,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -150,6 +151,7 @@ public class RoleServiceImpl extends ServiceImpl implements IR throw BizException.wrap("角色名 %s 已经存在", data.getName()); } Role role = BeanUtil.toBean(data, Role.class); + role.setUpdateOn(LocalDateTime.now()); role.setUpdateBy(userId); updateById(role); saveRoleMenu(data.getMenuIds(), role.getId()); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/RoleInfoController.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/RoleInfoController.java deleted file mode 100644 index 4ab591d..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/RoleInfoController.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ningdatech.pmapi.user.controller; - - -import org.springframework.web.bind.annotation.RequestMapping; - -import org.springframework.stereotype.Controller; - -/** - *

- * 角色表 前端控制器 - *

- * - * @author Liuxinxin - * @since 2023-01-05 - */ -@Controller -@RequestMapping("/pmapi.user/role-info") -public class RoleInfoController { - -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserInfoController.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserInfoController.java index 3519bdf..3faf708 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserInfoController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserInfoController.java @@ -9,6 +9,7 @@ import com.ningdatech.pmapi.user.model.po.ReqUserDisableOrEnablePO; import com.ningdatech.pmapi.user.model.po.ReqUserInfoListPO; import com.ningdatech.pmapi.user.model.vo.ResUserDetailVO; import com.ningdatech.pmapi.user.model.vo.ResUserInfoListVO; +import com.ningdatech.pmapi.user.model.vo.UserRoleVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -18,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; +import java.util.List; /** * @author Liuxinxin @@ -61,4 +63,9 @@ public class UserInfoController { return userInfoManage.currentUserInfo(); } + @ApiOperation(value = "获取当前用户可控角色列表") + @PostMapping("/controlled/role-list") + public List getControlledRoleList() { + return userInfoManage.getControlledRoleList(); + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/RoleInfo.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/RoleInfo.java deleted file mode 100644 index 67d8aec..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/RoleInfo.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.ningdatech.pmapi.user.entity; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import java.io.Serializable; -import java.time.LocalDateTime; - -/** - *

- * 角色表 - *

- * - * @author Liuxinxin - * @since 2023-01-05 - */ -@Data -@TableName("nd_role_info") -@ApiModel(value = "RoleInfo对象", description = "角色表") -public class RoleInfo implements Serializable { - - private static final long serialVersionUID = 1L; - - @TableId(value = "id", type = IdType.AUTO) - private Long id; - - @ApiModelProperty("角色名称") - private String name; - - @ApiModelProperty("备注") - private String description; - - private LocalDateTime createOn; - - private LocalDateTime updateOn; - -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java index fb052a2..51f688c 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java @@ -10,6 +10,7 @@ import com.ningdatech.basic.model.PageVo; import com.ningdatech.pmapi.common.constant.RegionConst; import com.ningdatech.pmapi.common.helper.RegionCacheHelper; import com.ningdatech.pmapi.common.helper.UserInfoHelper; +import com.ningdatech.pmapi.common.util.BizUtils; import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo; import com.ningdatech.pmapi.organization.model.entity.DingOrganization; import com.ningdatech.pmapi.organization.service.IDingEmployeeInfoService; @@ -490,4 +491,42 @@ public class UserInfoManage { } return processInstanceUserDto; } + + /** + * 获取当前用户可控角色列表 + * + * @return + */ + public List getControlledRoleList() { + Long userId = LoginUserUtil.getUserId(); + // 装配用户角色信息列表 + List userRoleList = iUserRoleService.list(Wrappers.lambdaQuery(UserRole.class) + .eq(UserRole::getUserId, userId)); + + List controlledRoleVOList = new ArrayList<>(); + List controlledRoleIdList = new ArrayList<>(); + if (CollUtil.isNotEmpty(userRoleList)) { + List roleIdList = userRoleList.stream().map(UserRole::getRoleId).distinct().collect(Collectors.toList()); + controlledRoleIdList.addAll(roleIdList); + List roleList = iRoleService.list(Wrappers.lambdaQuery(Role.class).in(Role::getId, roleIdList)); + + for (Role role : roleList) { + List manageRoleIdList = BizUtils.splitToLong(role.getManageRoleIds()); + if (CollUtil.isNotEmpty(manageRoleIdList)) { + controlledRoleIdList.addAll(manageRoleIdList); + } + } + controlledRoleIdList = controlledRoleIdList.stream().distinct().collect(Collectors.toList()); + List controlledRoleList = iRoleService.list(Wrappers.lambdaQuery(Role.class).in(Role::getId, controlledRoleIdList)); + + controlledRoleVOList = controlledRoleList.stream().map(r -> { + UserRoleVO userRoleVO = new UserRoleVO(); + userRoleVO.setId(r.getId()); + userRoleVO.setName(r.getName()); + userRoleVO.setCode(r.getCode()); + return userRoleVO; + }).collect(Collectors.toList()); + } + return controlledRoleVOList; + } }