mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-12 13:39:01 +08:00
feat(flow): 扩展流程发起人权限验证支持岗位类型
- 在NodeUserTypeEnum中新增POST类型以支持岗位权限验证 - 修改CombinationGroupServiceImpl中的权限验证逻辑,增加对岗位权限的检查 - 调整PigxUser结构以支持多部门、多角色、多岗位的存储 - 更新AssignUserLeaderStrategyImpl以适配用户的多部门信息 - 在SysDeptServiceImpl的getOrgTree方法中增加对岗位类型的支持 - 优化UserVO中集合属性的初始化以避免空指针异常
This commit is contained in:
1 parent
883293cc2a
commit
7710baa92a
8 files changed
+327
-283
No files matched your search
+99
-91
@@ -22,17 +22,18 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDept;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRole;
|
||||
import com.pig4cloud.pigx.admin.api.feign.RemoteDataScopeService;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.UserTypeEnum;
|
||||
import com.pig4cloud.pigx.common.core.util.RetOps;
|
||||
import com.pig4cloud.pigx.common.security.service.PigxUser;
|
||||
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
@@ -50,108 +51,115 @@ import java.util.stream.Collectors;
|
||||
@RequiredArgsConstructor
|
||||
public class PigxDefaultDataScopeHandle implements DataScopeHandle {
|
||||
|
||||
private final RemoteDataScopeService dataScopeService;
|
||||
private final RemoteDataScopeService dataScopeService;
|
||||
|
||||
@Override
|
||||
public Boolean calcScope(DataScope dataScope) {
|
||||
// 对于TOC客户端,不进行数据权限校验
|
||||
PigxUser user = SecurityUtils.getUser();
|
||||
if (UserTypeEnum.TOC.getStatus().equals(user.getUserType())) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public Boolean calcScope(DataScope dataScope) {
|
||||
// 对于TOC客户端,不进行数据权限校验
|
||||
PigxUser user = SecurityUtils.getUser();
|
||||
if (UserTypeEnum.TOC.getStatus().equals(user.getUserType())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 业务代码里的规则,覆盖计算规则
|
||||
if (StrUtil.isNotBlank(dataScope.getUsername()) || CollUtil.isNotEmpty(dataScope.getDeptList())) {
|
||||
return false;
|
||||
}
|
||||
// 业务代码里的规则,覆盖计算规则
|
||||
if (StrUtil.isNotBlank(dataScope.getUsername()) || CollUtil.isNotEmpty(dataScope.getDeptList())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取用户角色ID列表
|
||||
List<Long> roleIdList = SecurityUtils.getRoleIds();
|
||||
if (CollUtil.isEmpty(roleIdList)) {
|
||||
return false;
|
||||
}
|
||||
// 获取用户角色ID列表
|
||||
List<String> roleIdList = user.getAuthorities()
|
||||
.stream()
|
||||
.map(GrantedAuthority::getAuthority)
|
||||
.filter(authority -> authority.startsWith(SecurityConstants.ROLE))
|
||||
.map(authority -> authority.split(StrUtil.UNDERLINE)[1])
|
||||
.toList();
|
||||
if (CollUtil.isEmpty(roleIdList)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取角色列表
|
||||
List<SysRole> roleList = RetOps.of(dataScopeService.getRoleList(roleIdList))
|
||||
.getData()
|
||||
.orElseGet(Collections::emptyList);
|
||||
if (CollUtil.isEmpty(roleList)) {
|
||||
return false;
|
||||
}
|
||||
// 获取角色列表
|
||||
List<SysRole> roleList = RetOps.of(dataScopeService.getRoleList(roleIdList))
|
||||
.getData()
|
||||
.orElseGet(Collections::emptyList);
|
||||
if (CollUtil.isEmpty(roleList)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 处理数据权限
|
||||
return processDataScope(user, dataScope, roleList);
|
||||
}
|
||||
// 处理数据权限
|
||||
return processDataScope(user, dataScope, roleList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理数据权限
|
||||
*/
|
||||
private boolean processDataScope(PigxUser user, DataScope dataScope, List<SysRole> roleList) {
|
||||
List<Long> deptList = dataScope.getDeptList();
|
||||
|
||||
/**
|
||||
* 处理数据权限
|
||||
*/
|
||||
private boolean processDataScope(PigxUser user, DataScope dataScope, List<SysRole> roleList) {
|
||||
List<Long> deptList = dataScope.getDeptList();
|
||||
for (SysRole role : roleList) {
|
||||
Integer dsType = role.getDsType();
|
||||
|
||||
for (SysRole role : roleList) {
|
||||
Integer dsType = role.getDsType();
|
||||
// 处理不同数据权限类型
|
||||
switch (Objects.requireNonNull(DataScopeTypeEnum.getByType(dsType))) {
|
||||
case ALL:
|
||||
return true;
|
||||
case CUSTOM:
|
||||
handleCustomScope(role, deptList);
|
||||
break;
|
||||
case OWN_CHILD_LEVEL:
|
||||
handleOwnChildLevelScope(user, deptList);
|
||||
break;
|
||||
case OWN_LEVEL:
|
||||
handleOwnLevelScope(user, deptList);
|
||||
break;
|
||||
case SELF_LEVEL:
|
||||
handleSelfLevelScope(user, dataScope);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理不同数据权限类型
|
||||
switch (Objects.requireNonNull(DataScopeTypeEnum.getByType(dsType))) {
|
||||
case ALL:
|
||||
return true;
|
||||
case CUSTOM:
|
||||
handleCustomScope(role, deptList);
|
||||
break;
|
||||
case OWN_CHILD_LEVEL:
|
||||
handleOwnChildLevelScope(user, deptList);
|
||||
break;
|
||||
case OWN_LEVEL:
|
||||
handleOwnLevelScope(user, deptList);
|
||||
break;
|
||||
case SELF_LEVEL:
|
||||
handleSelfLevelScope(user, dataScope);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 处理自定义数据权限
|
||||
*/
|
||||
private void handleCustomScope(SysRole role, List<Long> deptList) {
|
||||
if (StrUtil.isNotBlank(role.getDsScope())) {
|
||||
deptList.addAll(Arrays.stream(role.getDsScope().split(StrUtil.COMMA)).map(Long::parseLong).toList());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理自定义数据权限
|
||||
*/
|
||||
private void handleCustomScope(SysRole role, List<Long> deptList) {
|
||||
if (StrUtil.isNotBlank(role.getDsScope())) {
|
||||
deptList.addAll(Arrays.stream(role.getDsScope().split(StrUtil.COMMA))
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 处理本级及下级数据权限
|
||||
*/
|
||||
private void handleOwnChildLevelScope(PigxUser user, List<Long> deptList) {
|
||||
|
||||
/**
|
||||
* 处理本级及下级数据权限
|
||||
*/
|
||||
private void handleOwnChildLevelScope(PigxUser user, List<Long> deptList) {
|
||||
List<Long> descendantDeptIds = RetOps.of(dataScopeService.getDescendantList(user.getDeptId()))
|
||||
.getData()
|
||||
.orElseGet(Collections::emptyList)
|
||||
.stream()
|
||||
.map(SysDept::getDeptId)
|
||||
.collect(Collectors.toList());
|
||||
deptList.addAll(descendantDeptIds);
|
||||
}
|
||||
for (Long deptId : user.getDeptIds()) {
|
||||
List<Long> descendantDeptIds = RetOps.of(dataScopeService.getDescendantList(deptId))
|
||||
.getData()
|
||||
.orElseGet(Collections::emptyList)
|
||||
.stream()
|
||||
.map(SysDept::getDeptId)
|
||||
.toList();
|
||||
deptList.addAll(descendantDeptIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理本级数据权限
|
||||
*/
|
||||
private void handleOwnLevelScope(PigxUser user, List<Long> deptList) {
|
||||
deptList.add(user.getDeptId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理本级数据权限
|
||||
*/
|
||||
private void handleOwnLevelScope(PigxUser user, List<Long> deptList) {
|
||||
deptList.addAll(user.getDeptIds());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理个人数据权限
|
||||
*/
|
||||
private void handleSelfLevelScope(PigxUser user, DataScope dataScope) {
|
||||
dataScope.setUsername(user.getUsername());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理个人数据权限
|
||||
*/
|
||||
private void handleSelfLevelScope(PigxUser user, DataScope dataScope) {
|
||||
dataScope.setUsername(user.getUsername());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -110,7 +110,7 @@ public class PigxTocDefaultUserDetailsServiceImpl implements PigxUserDetailsServ
|
||||
AppUser user = info.getAppUser();
|
||||
// 构造security用户
|
||||
|
||||
return new PigxUser(user.getUserId(), user.getUsername(), null, user.getPhone(), user.getAvatar(),
|
||||
return new PigxUser(user.getUserId(), user.getUsername(), null, null, null, user.getPhone(), user.getAvatar(),
|
||||
user.getNickname(), user.getName(), user.getEmail(), user.getTenantId(),
|
||||
SecurityConstants.BCRYPT + user.getPassword(), true, true, UserTypeEnum.TOC.getStatus(), true, null,
|
||||
!CommonConstants.STATUS_LOCK.equals(user.getLockFlag()), authorities);
|
||||
|
||||
+1
-1
@@ -100,7 +100,7 @@ public class PigxTocMobileUserDetailsServiceImpl implements PigxUserDetailsServi
|
||||
AppUser user = info.getAppUser();
|
||||
// 构造security用户
|
||||
|
||||
return new PigxUser(user.getUserId(), user.getUsername(), null, user.getPhone(), user.getAvatar(),
|
||||
return new PigxUser(user.getUserId(), user.getUsername(), null, null, null, user.getPhone(), user.getAvatar(),
|
||||
user.getNickname(), user.getName(), user.getEmail(), user.getTenantId(),
|
||||
SecurityConstants.BCRYPT + user.getPassword(), true, true, UserTypeEnum.TOC.getStatus(), true, null,
|
||||
!CommonConstants.STATUS_LOCK.equals(user.getLockFlag()), authorities);
|
||||
|
||||
+16
-4
@@ -30,6 +30,7 @@ import java.io.Serial;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -52,11 +53,19 @@ public class PigxUser extends User implements OAuth2AuthenticatedPrincipal {
|
||||
@Getter
|
||||
private Long id;
|
||||
|
||||
/** 角色ID列表 */
|
||||
@Getter
|
||||
private List<Long> roleIds;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
@Getter
|
||||
private Long deptId;
|
||||
private List<Long> deptIds;
|
||||
|
||||
/** 岗位ID列表 */
|
||||
@Getter
|
||||
private List<Long> postIds;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
@@ -106,7 +115,7 @@ public class PigxUser extends User implements OAuth2AuthenticatedPrincipal {
|
||||
* Construct the <code>User</code> with the details required by
|
||||
* {@link DaoAuthenticationProvider}.
|
||||
* @param id 用户ID
|
||||
* @param deptId 部门ID
|
||||
* @param deptIds 部门ID
|
||||
* @param tenantId 租户ID
|
||||
* @param nickname 昵称
|
||||
* @param name 姓名
|
||||
@@ -126,7 +135,8 @@ public class PigxUser extends User implements OAuth2AuthenticatedPrincipal {
|
||||
*/
|
||||
@JsonCreator
|
||||
public PigxUser(@JsonProperty("id") Long id, @JsonProperty("username") String username,
|
||||
@JsonProperty("deptId") Long deptId, @JsonProperty("phone") String phone,
|
||||
@JsonProperty("roleIds") List<Long> roleIds, @JsonProperty("deptIds") List<Long> deptIds,
|
||||
@JsonProperty("postIds") List<Long> postIds, @JsonProperty("phone") String phone,
|
||||
@JsonProperty("avatar") String avatar, @JsonProperty("nickname") String nickname,
|
||||
@JsonProperty("name") String name, @JsonProperty("email") String email,
|
||||
@JsonProperty("tenantId") Long tenantId, @JsonProperty("password") String password,
|
||||
@@ -138,7 +148,9 @@ public class PigxUser extends User implements OAuth2AuthenticatedPrincipal {
|
||||
@JsonProperty("authorities") Collection<? extends GrantedAuthority> authorities) {
|
||||
super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
|
||||
this.id = id;
|
||||
this.deptId = deptId;
|
||||
this.roleIds = roleIds;
|
||||
this.deptIds = deptIds;
|
||||
this.postIds = postIds;
|
||||
this.phone = phone;
|
||||
this.avatar = avatar;
|
||||
this.tenantId = tenantId;
|
||||
|
||||
+7
-7
@@ -16,8 +16,10 @@
|
||||
*/
|
||||
package com.pig4cloud.pigx.common.security.service;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDept;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysPost;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRole;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.UserTypeEnum;
|
||||
@@ -92,12 +94,10 @@ public interface PigxUserDetailsService extends UserDetailsService, Ordered {
|
||||
Collection<GrantedAuthority> authorities = AuthorityUtils
|
||||
.createAuthorityList(dbAuthsSet.toArray(new String[0]));
|
||||
|
||||
// 构造security用户
|
||||
Long deptId = null;
|
||||
if (CollUtil.isNotEmpty(info.getDeptList())) {
|
||||
deptId = CollUtil.getFirst(info.getDeptList()).getDeptId();
|
||||
}
|
||||
return new PigxUser(info.getUserId(), info.getUsername(), deptId, info.getPhone(), info.getAvatar(),
|
||||
return new PigxUser(info.getUserId(), info.getUsername(),
|
||||
info.getRoleList().stream().map(SysRole::getRoleId).toList(),
|
||||
info.getDeptList().stream().map(SysDept::getDeptId).toList(),
|
||||
info.getPostList().stream().map(SysPost::getPostId).toList(), info.getPhone(), info.getAvatar(),
|
||||
info.getNickname(), info.getName(), info.getEmail(), info.getTenantId(),
|
||||
SecurityConstants.BCRYPT + info.getPassword(), true, true, UserTypeEnum.TOB.getStatus(),
|
||||
!CommonConstants.STATUS_LOCK.equals(info.getPasswordExpireFlag()) // 密码过期判断
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ package com.pig4cloud.pigx.admin.api.constant;
|
||||
*/
|
||||
public enum OrgTypeEnum {
|
||||
|
||||
USER("user", "用户"), ROLE("role", "角色"), DEPT("dept", "部门");
|
||||
USER("user", "用户"), ROLE("role", "角色"), DEPT("dept", "部门"), POST("post", "岗位");
|
||||
|
||||
private String type;
|
||||
|
||||
|
||||
+120
-119
@@ -31,6 +31,7 @@ import lombok.Data;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -41,149 +42,149 @@ import java.util.List;
|
||||
@Schema(description = "前端用户展示对象")
|
||||
public class UserVO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@Schema(description = "主键")
|
||||
private Long userId;
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@Schema(description = "主键")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String password;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 随机盐
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String salt;
|
||||
/**
|
||||
* 随机盐
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String salt;
|
||||
|
||||
/**
|
||||
* 微信openid
|
||||
*/
|
||||
@Schema(description = "微信open id")
|
||||
private String wxOpenid;
|
||||
/**
|
||||
* 微信openid
|
||||
*/
|
||||
@Schema(description = "微信open id")
|
||||
private String wxOpenid;
|
||||
|
||||
/**
|
||||
* QQ openid
|
||||
*/
|
||||
@Schema(description = "qq open id")
|
||||
private String qqOpenid;
|
||||
/**
|
||||
* QQ openid
|
||||
*/
|
||||
@Schema(description = "qq open id")
|
||||
private String qqOpenid;
|
||||
|
||||
/**
|
||||
* gitee openid
|
||||
*/
|
||||
@Schema(description = "gitee open id")
|
||||
private String giteeOpenId;
|
||||
/**
|
||||
* gitee openid
|
||||
*/
|
||||
@Schema(description = "gitee open id")
|
||||
private String giteeOpenId;
|
||||
|
||||
/**
|
||||
* 开源中国 openid
|
||||
*/
|
||||
@Schema(description = "开源中国 open id")
|
||||
private String oscOpenId;
|
||||
/**
|
||||
* 开源中国 openid
|
||||
*/
|
||||
@Schema(description = "开源中国 open id")
|
||||
private String oscOpenId;
|
||||
|
||||
/**
|
||||
* 企微微信 userid
|
||||
*/
|
||||
@Schema(description = "企微微信 userid")
|
||||
private String wxCpUserid;
|
||||
/**
|
||||
* 企微微信 userid
|
||||
*/
|
||||
@Schema(description = "企微微信 userid")
|
||||
private String wxCpUserid;
|
||||
|
||||
/**
|
||||
* 钉钉 userid
|
||||
*/
|
||||
@Schema(description = "钉钉 userid")
|
||||
private String wxDingUserid;
|
||||
/**
|
||||
* 钉钉 userid
|
||||
*/
|
||||
@Schema(description = "钉钉 userid")
|
||||
private String wxDingUserid;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Schema(description = "修改时间")
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Schema(description = "修改时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 0-正常,1-删除
|
||||
*/
|
||||
@Schema(description = "删除标记,1:已删除,0:正常")
|
||||
private String delFlag;
|
||||
/**
|
||||
* 0-正常,1-删除
|
||||
*/
|
||||
@Schema(description = "删除标记,1:已删除,0:正常")
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 锁定标记
|
||||
*/
|
||||
@Schema(description = "锁定标记,0:正常,9:已锁定")
|
||||
private String lockFlag;
|
||||
/**
|
||||
* 锁定标记
|
||||
*/
|
||||
@Schema(description = "锁定标记,0:正常,9:已锁定")
|
||||
private String lockFlag;
|
||||
|
||||
/**
|
||||
* 密码过期标记
|
||||
*/
|
||||
@Schema(description = "密码过期标记")
|
||||
private String passwordExpireFlag;
|
||||
/**
|
||||
* 密码过期标记
|
||||
*/
|
||||
@Schema(description = "密码过期标记")
|
||||
private String passwordExpireFlag;
|
||||
|
||||
/**
|
||||
* 密码修改时间
|
||||
*/
|
||||
@Schema(description = "密码修改时间")
|
||||
private LocalDateTime passwordModifyTime;
|
||||
/**
|
||||
* 密码修改时间
|
||||
*/
|
||||
@Schema(description = "密码修改时间")
|
||||
private LocalDateTime passwordModifyTime;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@Sensitive(type = SensitiveTypeEnum.MOBILE_PHONE)
|
||||
@Schema(description = "手机号")
|
||||
private String phone;
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@Sensitive(type = SensitiveTypeEnum.MOBILE_PHONE)
|
||||
@Schema(description = "手机号")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
@Schema(description = "头像")
|
||||
private String avatar;
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
@Schema(description = "头像")
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
@Schema(description = "所属租户")
|
||||
private Long tenantId;
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
@Schema(description = "所属租户")
|
||||
private Long tenantId;
|
||||
|
||||
@Schema(description = "所属部门名称")
|
||||
private List<SysDept> deptList;
|
||||
@Schema(description = "所属部门名称")
|
||||
private List<SysDept> deptList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
*/
|
||||
@Schema(description = "拥有的角色列表")
|
||||
private List<SysRole> roleList;
|
||||
/**
|
||||
* 角色列表
|
||||
*/
|
||||
@Schema(description = "拥有的角色列表")
|
||||
private List<SysRole> roleList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 岗位列表
|
||||
*/
|
||||
@Schema(description = "拥有的岗位列表")
|
||||
private List<SysPost> postList;
|
||||
/**
|
||||
* 岗位列表
|
||||
*/
|
||||
@Schema(description = "拥有的岗位列表")
|
||||
private List<SysPost> postList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@Schema(description = "昵称")
|
||||
private String nickname;
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@Schema(description = "昵称")
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
@Schema(description = "姓名")
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
@Schema(description = "姓名")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
|
||||
+82
-59
@@ -80,7 +80,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean removeDeptById(Long id) {
|
||||
// 级联删除部门
|
||||
List<Long> idList = this.listDescendant(id).stream().map(SysDept::getDeptId).toList();
|
||||
List<Long> idList = this.listDescendant(id).stream().map(SysDept::getDeptId).toList();
|
||||
|
||||
Optional.ofNullable(idList).filter(CollUtil::isNotEmpty).ifPresent(this::removeByIds);
|
||||
|
||||
@@ -97,34 +97,34 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
public List<Tree<Long>> selectTree(String deptName, Long parentId) {
|
||||
// 查询全部部门
|
||||
List<SysDept> deptAllList = deptMapper
|
||||
.selectList(Wrappers.<SysDept>lambdaQuery().like(StrUtil.isNotBlank(deptName), SysDept::getName, deptName));
|
||||
.selectList(Wrappers.<SysDept>lambdaQuery().like(StrUtil.isNotBlank(deptName), SysDept::getName, deptName));
|
||||
// 查询数据权限内部门
|
||||
List<Long> deptOwnIdList = deptMapper
|
||||
.selectListByScope(
|
||||
Wrappers.<SysDept>lambdaQuery().like(StrUtil.isNotBlank(deptName), SysDept::getName, deptName),
|
||||
DataScope.of())
|
||||
.stream()
|
||||
.map(SysDept::getDeptId)
|
||||
.toList();
|
||||
.selectListByScope(
|
||||
Wrappers.<SysDept>lambdaQuery().like(StrUtil.isNotBlank(deptName), SysDept::getName, deptName),
|
||||
DataScope.of())
|
||||
.stream()
|
||||
.map(SysDept::getDeptId)
|
||||
.toList();
|
||||
|
||||
// 权限内部门
|
||||
List<TreeNode<Long>> collect = deptAllList.stream()
|
||||
.filter(dept -> dept.getDeptId().intValue() != dept.getParentId())
|
||||
.sorted(Comparator.comparingInt(SysDept::getSortOrder))
|
||||
.map(dept -> {
|
||||
TreeNode<Long> treeNode = new TreeNode<>();
|
||||
treeNode.setId(dept.getDeptId());
|
||||
treeNode.setParentId(dept.getParentId());
|
||||
treeNode.setName(dept.getName());
|
||||
treeNode.setWeight(dept.getSortOrder());
|
||||
// 有权限不返回标识
|
||||
Map<String, Object> extra = new HashMap<>(8);
|
||||
extra.put("isLock", !deptOwnIdList.contains(dept.getDeptId()));
|
||||
extra.put("createTime", dept.getCreateTime());
|
||||
treeNode.setExtra(extra);
|
||||
return treeNode;
|
||||
})
|
||||
.toList();
|
||||
.filter(dept -> dept.getDeptId().intValue() != dept.getParentId())
|
||||
.sorted(Comparator.comparingInt(SysDept::getSortOrder))
|
||||
.map(dept -> {
|
||||
TreeNode<Long> treeNode = new TreeNode<>();
|
||||
treeNode.setId(dept.getDeptId());
|
||||
treeNode.setParentId(dept.getParentId());
|
||||
treeNode.setName(dept.getName());
|
||||
treeNode.setWeight(dept.getSortOrder());
|
||||
// 有权限不返回标识
|
||||
Map<String, Object> extra = new HashMap<>(8);
|
||||
extra.put("isLock", !deptOwnIdList.contains(dept.getDeptId()));
|
||||
extra.put("createTime", dept.getCreateTime());
|
||||
treeNode.setExtra(extra);
|
||||
return treeNode;
|
||||
})
|
||||
.toList();
|
||||
|
||||
// 模糊查询 不组装树结构 直接返回 表格方便编辑
|
||||
if (StrUtil.isNotBlank(deptName)) {
|
||||
@@ -133,7 +133,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
tree.putAll(node.getExtra());
|
||||
BeanUtils.copyProperties(node, tree);
|
||||
return tree;
|
||||
}).toList();
|
||||
}).toList();
|
||||
}
|
||||
|
||||
return TreeUtil.build(collect, parentId == null ? 0 : parentId);
|
||||
@@ -150,14 +150,14 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
DeptExcelVO deptExcelVo = new DeptExcelVO();
|
||||
deptExcelVo.setName(item.getName());
|
||||
Optional<String> first = this.list()
|
||||
.stream()
|
||||
.filter(it -> item.getParentId().equals(it.getDeptId()))
|
||||
.map(SysDept::getName)
|
||||
.findFirst();
|
||||
.stream()
|
||||
.filter(it -> item.getParentId().equals(it.getDeptId()))
|
||||
.map(SysDept::getName)
|
||||
.findFirst();
|
||||
deptExcelVo.setParentName(first.orElse("根部门"));
|
||||
deptExcelVo.setSortOrder(item.getSortOrder());
|
||||
return deptExcelVo;
|
||||
}).toList();
|
||||
}).toList();
|
||||
return deptExcelVos;
|
||||
}
|
||||
|
||||
@@ -186,7 +186,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
sysDept.setParentId(one.getDeptId());
|
||||
sysDept.setSortOrder(item.getSortOrder());
|
||||
baseMapper.insert(sysDept);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// 数据不合法情况
|
||||
errorMessageList.add(new ErrorMessage(item.getLineNum(), errorMsg));
|
||||
}
|
||||
@@ -226,30 +227,30 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
@Override
|
||||
public List<Long> listDeptLeader(Long deptId) {
|
||||
|
||||
List<SysUserDept> userDeptList = userDeptMapper
|
||||
.selectList(Wrappers.<SysUserDept>lambdaQuery().eq(SysUserDept::getDeptId, deptId));
|
||||
List<SysUserDept> userDeptList = userDeptMapper
|
||||
.selectList(Wrappers.<SysUserDept>lambdaQuery().eq(SysUserDept::getDeptId, deptId));
|
||||
if (CollUtil.isEmpty(userDeptList)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SysPost deptLeader = postMapper
|
||||
.selectOne(Wrappers.<SysPost>lambdaQuery().eq(SysPost::getPostCode, PostCodeEnum.TEAM_LEADER.getCode()));
|
||||
.selectOne(Wrappers.<SysPost>lambdaQuery().eq(SysPost::getPostCode, PostCodeEnum.TEAM_LEADER.getCode()));
|
||||
if (deptLeader == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Long> userIdList = userDeptList.stream().map(SysUserDept::getUserId).toList();
|
||||
return userPostMapper.selectList(Wrappers.<SysUserPost>lambdaQuery().in(SysUserPost::getUserId, userIdList))
|
||||
.stream()
|
||||
.filter(post -> Objects.equals(post.getPostId(), deptLeader.getPostId()))
|
||||
.map(SysUserPost::getUserId)
|
||||
.toList();
|
||||
.stream()
|
||||
.filter(post -> Objects.equals(post.getPostId(), deptLeader.getPostId()))
|
||||
.map(SysUserPost::getUserId)
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父部门ID和类型获取组织树
|
||||
* @param parentDeptId 父部门ID
|
||||
* @param type 类型
|
||||
* @param type 类型
|
||||
* @return 组织树信息
|
||||
*/
|
||||
public Map<String, Object> listOrgTree(Long parentDeptId, String type) {
|
||||
@@ -270,15 +271,37 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
});
|
||||
|
||||
return Dict.create()
|
||||
.set("roleList", orgs)
|
||||
.set("childDepartments", orgs)
|
||||
.set("employees", new ArrayList<>());
|
||||
.set("roleList", orgs)
|
||||
.set("postList", new ArrayList<>())
|
||||
.set("childDepartments", orgs)
|
||||
.set("employees", new ArrayList<>());
|
||||
}
|
||||
|
||||
if (StrUtil.equals(type, OrgTypeEnum.POST.getType())) {
|
||||
// 角色
|
||||
List<SysPost> postList = postMapper.selectList(Wrappers.emptyWrapper());
|
||||
|
||||
postList.forEach(post -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(post.getPostId());
|
||||
orgTreeVo.setName(post.getPostName());
|
||||
orgTreeVo.setType(OrgTypeEnum.POST.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
orgs.add(orgTreeVo);
|
||||
});
|
||||
|
||||
return Dict.create()
|
||||
.set("roleList", new ArrayList<>())
|
||||
.set("postList", orgs)
|
||||
.set("childDepartments", orgs)
|
||||
.set("employees", new ArrayList<>());
|
||||
}
|
||||
|
||||
Dict dict = Dict.create()
|
||||
.set("titleDepartments", new ArrayList<>())
|
||||
.set("roleList", new ArrayList<>())
|
||||
.set("employees", new ArrayList<>());
|
||||
.set("titleDepartments", new ArrayList<>())
|
||||
.set("roleList", new ArrayList<>())
|
||||
.set("postList", new ArrayList<>())
|
||||
.set("employees", new ArrayList<>());
|
||||
|
||||
List<SysDept> deptList = this.list(
|
||||
Wrappers.<SysDept>lambdaQuery().eq(Objects.nonNull(parentDeptId), SysDept::getParentId, parentDeptId));
|
||||
@@ -301,8 +324,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
|
||||
MPJLambdaWrapper<SysUser> userQuery = new MPJLambdaWrapper<>();
|
||||
userQuery.selectAll(SysUser.class)
|
||||
.leftJoin(SysUserDept.class, SysUserDept::getUserId, SysUser::getUserId)
|
||||
.eq(SysUserDept::getDeptId, parentDeptId);
|
||||
.leftJoin(SysUserDept.class, SysUserDept::getUserId, SysUser::getUserId)
|
||||
.eq(SysUserDept::getDeptId, parentDeptId);
|
||||
|
||||
List<SysUser> userList = userMapper.selectJoinList(userQuery);
|
||||
|
||||
@@ -334,23 +357,23 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
*/
|
||||
public List<OrgTreeVO> getOrgTreeUser(String username) {
|
||||
return userMapper.selectList(Wrappers.<SysUser>lambdaQuery().like(SysUser::getUsername, username))
|
||||
.stream()
|
||||
.map(user -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(user.getUserId());
|
||||
orgTreeVo.setName(user.getUsername());
|
||||
orgTreeVo.setType(OrgTypeEnum.USER.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
orgTreeVo.setAvatar(user.getAvatar());
|
||||
return orgTreeVo;
|
||||
})
|
||||
.toList();
|
||||
.stream()
|
||||
.map(user -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(user.getUserId());
|
||||
orgTreeVo.setName(user.getUsername());
|
||||
orgTreeVo.setType(OrgTypeEnum.USER.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
orgTreeVo.setAvatar(user.getAvatar());
|
||||
return orgTreeVo;
|
||||
})
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查询所有子节点。
|
||||
* @param allDeptList 所有部门列表
|
||||
* @param parentId 父部门ID
|
||||
* @param parentId 父部门ID
|
||||
* @param resDeptList 结果集合
|
||||
*/
|
||||
private void recursiveDept(List<SysDept> allDeptList, Long parentId, List<SysDept> resDeptList) {
|
||||
|
||||
Reference in new issue
Block a user