mirror of
https://gitee.com/xiaonuobase/snowy.git
synced 2026-03-22 02:37:16 +08:00
【更新】机构大数据完善与登录优化(待验证)
This commit is contained in:
@@ -18,7 +18,7 @@ import cn.dev33.satoken.stp.StpInterface;
|
||||
import cn.dev33.satoken.stp.StpLogic;
|
||||
import cn.dev33.satoken.strategy.SaAnnotationStrategy;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -31,8 +31,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import vip.xiaonuo.auth.core.enums.SaClientTypeEnum;
|
||||
import vip.xiaonuo.auth.core.util.StpClientLoginUserUtil;
|
||||
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
|
||||
import vip.xiaonuo.common.cache.CommonCacheOperator;
|
||||
import vip.xiaonuo.common.consts.CacheConstant;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -93,26 +91,24 @@ public class AuthConfigure implements WebMvcConfigurer {
|
||||
@Component
|
||||
public static class StpInterfaceImpl implements StpInterface {
|
||||
|
||||
@Resource
|
||||
private CommonCacheOperator commonCacheOperator;
|
||||
|
||||
/**
|
||||
* 返回一个账号所拥有的权限码集合
|
||||
* 返回一个账号所拥有的权限码集合,直接从TokenSession读取
|
||||
*/
|
||||
@Override
|
||||
public List<String> getPermissionList(Object loginId, String loginType) {
|
||||
Object permissionListObject;
|
||||
if (SaClientTypeEnum.B.getValue().equals(loginType)) {
|
||||
permissionListObject = commonCacheOperator.get(CacheConstant.AUTH_B_PERMISSION_LIST_CACHE_KEY + loginId);
|
||||
Object loginUser = StpLoginUserUtil.getLoginUser();
|
||||
if(ObjectUtil.isEmpty(loginUser)) {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
return StpLoginUserUtil.getLoginUser().getPermissionCodeList();
|
||||
} else {
|
||||
permissionListObject = commonCacheOperator.get(CacheConstant.AUTH_C_PERMISSION_LIST_CACHE_KEY + loginId);
|
||||
Object clientLoginUser = StpClientLoginUserUtil.getClientLoginUser();
|
||||
if(ObjectUtil.isEmpty(clientLoginUser)) {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
return StpClientLoginUserUtil.getClientLoginUser().getPermissionCodeList();
|
||||
}
|
||||
// 转为字符串
|
||||
String permissionListString = permissionListObject.toString();
|
||||
// 去除首尾的方括号
|
||||
String trimmedStr = StrUtil.sub(permissionListString, 1, -1);
|
||||
// 使用逗号和空格分割字符串,并转换为列表
|
||||
return CollectionUtil.newArrayList(StrUtil.split(trimmedStr, ", "));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,7 +46,6 @@ import vip.xiaonuo.auth.modular.login.result.AuthPicValidCodeResult;
|
||||
import vip.xiaonuo.auth.modular.login.service.AuthService;
|
||||
import vip.xiaonuo.client.ClientUserApi;
|
||||
import vip.xiaonuo.common.cache.CommonCacheOperator;
|
||||
import vip.xiaonuo.common.consts.CacheConstant;
|
||||
import vip.xiaonuo.common.exception.CommonException;
|
||||
import vip.xiaonuo.common.util.CommonCryptogramUtil;
|
||||
import vip.xiaonuo.common.util.CommonEmailUtil;
|
||||
@@ -59,6 +58,7 @@ import vip.xiaonuo.sys.api.SysUserApi;
|
||||
import vip.xiaonuo.auth.modular.login.prop.AuthThirdClientProperties;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -701,7 +701,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
* @date 2024/7/22 22:00
|
||||
*/
|
||||
private void fillSaBaseLoginUserAndUpdateCache(SaBaseLoginUser saBaseLoginUser) {
|
||||
// 角色集合
|
||||
// 角色集合(后续查询依赖角色ID,必须先执行)
|
||||
List<JSONObject> roleList = loginUserApi.getRoleListByUserId(saBaseLoginUser.getId());
|
||||
// 角色id集合
|
||||
List<String> roleIdList = roleList.stream().map(jsonObject -> jsonObject.getStr("id")).collect(Collectors.toList());
|
||||
@@ -709,20 +709,27 @@ public class AuthServiceImpl implements AuthService {
|
||||
List<String> roleCodeList = roleList.stream().map(jsonObject -> jsonObject.getStr("code")).collect(Collectors.toList());
|
||||
// 角色id和用户id集合
|
||||
List<String> userAndRoleIdList = CollectionUtil.unionAll(roleIdList, CollectionUtil.newArrayList(saBaseLoginUser.getId()));
|
||||
// 以下三个查询互不依赖,并行执行
|
||||
CompletableFuture<List<String>> buttonCodeFuture = CompletableFuture.supplyAsync(() ->
|
||||
loginUserApi.getButtonCodeListListByUserAndRoleIdList(userAndRoleIdList));
|
||||
CompletableFuture<List<String>> mobileButtonCodeFuture = CompletableFuture.supplyAsync(() ->
|
||||
loginUserApi.getMobileButtonCodeListListByUserIdAndRoleIdList(userAndRoleIdList));
|
||||
CompletableFuture<List<SaBaseLoginUser.DataScope>> dataScopeFuture = CompletableFuture.supplyAsync(() ->
|
||||
Convert.toList(SaBaseLoginUser.DataScope.class,
|
||||
loginUserApi.getPermissionListByUserIdAndRoleIdList(userAndRoleIdList, saBaseLoginUser.getOrgId())));
|
||||
// 等待所有查询完成
|
||||
CompletableFuture.allOf(buttonCodeFuture, mobileButtonCodeFuture, dataScopeFuture).join();
|
||||
// 获取按钮码
|
||||
saBaseLoginUser.setButtonCodeList(loginUserApi.getButtonCodeListListByUserAndRoleIdList(userAndRoleIdList));
|
||||
saBaseLoginUser.setButtonCodeList(buttonCodeFuture.join());
|
||||
// 获取移动端按钮码
|
||||
saBaseLoginUser.setMobileButtonCodeList(loginUserApi.getMobileButtonCodeListListByUserIdAndRoleIdList(userAndRoleIdList));
|
||||
saBaseLoginUser.setMobileButtonCodeList(mobileButtonCodeFuture.join());
|
||||
// 获取数据范围
|
||||
saBaseLoginUser.setDataScopeList(Convert.toList(SaBaseLoginUser.DataScope.class,
|
||||
loginUserApi.getPermissionListByUserIdAndRoleIdList(userAndRoleIdList, saBaseLoginUser.getOrgId())));
|
||||
saBaseLoginUser.setDataScopeList(dataScopeFuture.join());
|
||||
// 获取权限码
|
||||
List<String> permissionCodeList = saBaseLoginUser.getDataScopeList().stream()
|
||||
.map(SaBaseLoginUser.DataScope::getApiUrl).collect(Collectors.toList());
|
||||
// 设置权限码
|
||||
saBaseLoginUser.setPermissionCodeList(permissionCodeList);
|
||||
// 权限码列表存入缓存
|
||||
commonCacheOperator.put(CacheConstant.AUTH_B_PERMISSION_LIST_CACHE_KEY + saBaseLoginUser.getId(),permissionCodeList);
|
||||
// 获取角色码
|
||||
saBaseLoginUser.setRoleCodeList(roleCodeList);
|
||||
// 缓存用户信息,此处使用TokenSession为了指定时间内无操作则自动下线
|
||||
@@ -757,7 +764,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
* @date 2024/7/22 22:00
|
||||
*/
|
||||
private void fillSaBaseClientLoginUserAndUpdateCache(SaBaseClientLoginUser saBaseClientLoginUser) {
|
||||
// 角色集合
|
||||
// 角色集合(后续查询依赖角色ID,必须先执行)
|
||||
List<JSONObject> roleList = clientLoginUserApi.getRoleListByUserId(saBaseClientLoginUser.getId());
|
||||
// 角色id集合
|
||||
List<String> roleIdList = roleList.stream().map(jsonObject -> jsonObject.getStr("id")).collect(Collectors.toList());
|
||||
@@ -765,20 +772,27 @@ public class AuthServiceImpl implements AuthService {
|
||||
List<String> roleCodeList = roleList.stream().map(jsonObject -> jsonObject.getStr("code")).collect(Collectors.toList());
|
||||
// 角色id和用户id集合
|
||||
List<String> userAndRoleIdList = CollectionUtil.unionAll(roleIdList, CollectionUtil.newArrayList(saBaseClientLoginUser.getId()));
|
||||
// 以下三个查询互不依赖,并行执行
|
||||
CompletableFuture<List<String>> buttonCodeFuture = CompletableFuture.supplyAsync(() ->
|
||||
clientLoginUserApi.getButtonCodeListListByUserAndRoleIdList(userAndRoleIdList));
|
||||
CompletableFuture<List<String>> mobileButtonCodeFuture = CompletableFuture.supplyAsync(() ->
|
||||
clientLoginUserApi.getMobileButtonCodeListListByUserIdAndRoleIdList(userAndRoleIdList));
|
||||
CompletableFuture<List<SaBaseClientLoginUser.DataScope>> dataScopeFuture = CompletableFuture.supplyAsync(() ->
|
||||
Convert.toList(SaBaseClientLoginUser.DataScope.class,
|
||||
clientLoginUserApi.getPermissionListByUserIdAndRoleIdList(userAndRoleIdList, null)));
|
||||
// 等待所有查询完成
|
||||
CompletableFuture.allOf(buttonCodeFuture, mobileButtonCodeFuture, dataScopeFuture).join();
|
||||
// 获取按钮码
|
||||
saBaseClientLoginUser.setButtonCodeList(clientLoginUserApi.getButtonCodeListListByUserAndRoleIdList(userAndRoleIdList));
|
||||
saBaseClientLoginUser.setButtonCodeList(buttonCodeFuture.join());
|
||||
// 获取移动端按钮码
|
||||
saBaseClientLoginUser.setMobileButtonCodeList(clientLoginUserApi.getMobileButtonCodeListListByUserIdAndRoleIdList(userAndRoleIdList));
|
||||
saBaseClientLoginUser.setMobileButtonCodeList(mobileButtonCodeFuture.join());
|
||||
// 获取数据范围
|
||||
saBaseClientLoginUser.setDataScopeList(Convert.toList(SaBaseClientLoginUser.DataScope.class,
|
||||
clientLoginUserApi.getPermissionListByUserIdAndRoleIdList(userAndRoleIdList, null)));
|
||||
saBaseClientLoginUser.setDataScopeList(dataScopeFuture.join());
|
||||
// 获取权限码
|
||||
List<String> permissionCodeList = saBaseClientLoginUser.getDataScopeList().stream()
|
||||
.map(SaBaseClientLoginUser.DataScope::getApiUrl).collect(Collectors.toList());
|
||||
// 设置权限码
|
||||
saBaseClientLoginUser.setPermissionCodeList(permissionCodeList);
|
||||
// 权限码列表存入缓存
|
||||
commonCacheOperator.put(CacheConstant.AUTH_C_PERMISSION_LIST_CACHE_KEY + saBaseClientLoginUser.getId(),permissionCodeList);
|
||||
// 获取角色码
|
||||
saBaseClientLoginUser.setRoleCodeList(roleCodeList);
|
||||
// 缓存用户信息,此处使用TokenSession为了指定时间内无操作则自动下线
|
||||
@@ -793,20 +807,23 @@ public class AuthServiceImpl implements AuthService {
|
||||
**/
|
||||
@Override
|
||||
public SaBaseLoginUser getLoginUser() {
|
||||
// 获取当前缓存的用户信息
|
||||
// 直接从TokenSession获取缓存的用户信息
|
||||
SaBaseLoginUser saBaseLoginUser = StpLoginUserUtil.getLoginUser();
|
||||
// 获取B端用户信息
|
||||
saBaseLoginUser = loginUserApi.getUserById(saBaseLoginUser.getId());
|
||||
// 填充B端用户信息并更新缓存
|
||||
fillSaBaseLoginUserAndUpdateCache(saBaseLoginUser);
|
||||
// 如果缓存中没有用户信息(如旧session),回退到查DB+填充缓存
|
||||
if(ObjectUtil.isEmpty(saBaseLoginUser)) {
|
||||
saBaseLoginUser = loginUserApi.getUserById(StpUtil.getLoginIdAsString());
|
||||
fillSaBaseLoginUserAndUpdateCache(saBaseLoginUser);
|
||||
}
|
||||
// 通过JSON序列化深拷贝,避免修改缓存中的对象
|
||||
SaBaseLoginUser result = JSONUtil.toBean(JSONUtil.toJsonStr(saBaseLoginUser), saBaseLoginUser.getClass());
|
||||
// 去掉密码
|
||||
saBaseLoginUser.setPassword("******");
|
||||
result.setPassword("******");
|
||||
// 去掉权限码
|
||||
saBaseLoginUser.setPermissionCodeList(CollectionUtil.newArrayList());
|
||||
result.setPermissionCodeList(CollectionUtil.newArrayList());
|
||||
// 去掉数据范围
|
||||
saBaseLoginUser.setDataScopeList(CollectionUtil.newArrayList());
|
||||
result.setDataScopeList(CollectionUtil.newArrayList());
|
||||
// 返回
|
||||
return saBaseLoginUser;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -817,20 +834,23 @@ public class AuthServiceImpl implements AuthService {
|
||||
**/
|
||||
@Override
|
||||
public SaBaseClientLoginUser getClientLoginUser() {
|
||||
// 获取当前缓存的用户信息
|
||||
// 直接从TokenSession获取缓存的用户信息
|
||||
SaBaseClientLoginUser saBaseClientLoginUser = StpClientLoginUserUtil.getClientLoginUser();
|
||||
// 获取C端用户信息
|
||||
saBaseClientLoginUser = clientLoginUserApi.getClientUserById(saBaseClientLoginUser.getId());
|
||||
// 填充C端用户信息并更新缓存
|
||||
fillSaBaseClientLoginUserAndUpdateCache(saBaseClientLoginUser);
|
||||
// 如果缓存中没有用户信息(如旧session),回退到查DB+填充缓存
|
||||
if(ObjectUtil.isEmpty(saBaseClientLoginUser)) {
|
||||
saBaseClientLoginUser = clientLoginUserApi.getClientUserById(StpClientUtil.getLoginIdAsString());
|
||||
fillSaBaseClientLoginUserAndUpdateCache(saBaseClientLoginUser);
|
||||
}
|
||||
// 通过JSON序列化深拷贝,避免修改缓存中的对象
|
||||
SaBaseClientLoginUser result = JSONUtil.toBean(JSONUtil.toJsonStr(saBaseClientLoginUser), saBaseClientLoginUser.getClass());
|
||||
// 去掉密码
|
||||
saBaseClientLoginUser.setPassword("******");
|
||||
result.setPassword("******");
|
||||
// 去掉权限码
|
||||
saBaseClientLoginUser.setPermissionCodeList(CollectionUtil.newArrayList());
|
||||
result.setPermissionCodeList(CollectionUtil.newArrayList());
|
||||
// 去掉数据范围
|
||||
saBaseClientLoginUser.setDataScopeList(CollectionUtil.newArrayList());
|
||||
result.setDataScopeList(CollectionUtil.newArrayList());
|
||||
// 返回
|
||||
return saBaseClientLoginUser;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
package vip.xiaonuo.biz.modular.group.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -29,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import vip.xiaonuo.biz.modular.group.entity.BizGroup;
|
||||
import vip.xiaonuo.biz.modular.group.param.*;
|
||||
import vip.xiaonuo.biz.modular.group.service.BizGroupService;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.biz.modular.user.entity.BizUser;
|
||||
import vip.xiaonuo.common.annotation.CommonLog;
|
||||
import vip.xiaonuo.common.pojo.CommonResult;
|
||||
@@ -144,8 +143,8 @@ public class BizGroupController {
|
||||
@Operation(summary = "获取组织树选择器")
|
||||
@SaCheckPermission("/biz/group/orgTreeSelector")
|
||||
@GetMapping("/biz/group/orgTreeSelector")
|
||||
public CommonResult<List<JSONObject>> orgTreeSelector(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
|
||||
return CommonResult.data(bizGroupService.orgTreeLazySelector(bizOrgTreeLazyParam));
|
||||
public CommonResult<List<JSONObject>> orgTreeSelector(BizOrgSelectorTreeParam bizOrgSelectorTreeParam) {
|
||||
return CommonResult.data(bizGroupService.orgTreeSelector(bizOrgSelectorTreeParam));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,13 +12,12 @@
|
||||
*/
|
||||
package vip.xiaonuo.biz.modular.group.service;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import vip.xiaonuo.biz.modular.group.entity.BizGroup;
|
||||
import vip.xiaonuo.biz.modular.group.param.*;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.biz.modular.user.entity.BizUser;
|
||||
|
||||
import java.util.List;
|
||||
@@ -87,21 +86,13 @@ public interface BizGroupService extends IService<BizGroup> {
|
||||
*/
|
||||
List<String> ownUser(BizGroupIdParam sysGroupIdParam);
|
||||
|
||||
/**
|
||||
* 获取机构树选择器
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2024/12/21 01:25
|
||||
*/
|
||||
List<Tree<String>> orgTreeSelector();
|
||||
|
||||
/**
|
||||
* 获取机构树选择器(懒加载)
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
List<JSONObject> orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam);
|
||||
List<JSONObject> orgTreeSelector(BizOrgSelectorTreeParam bizOrgSelectorTreeParam);
|
||||
|
||||
/**
|
||||
* 获取用户选择器
|
||||
|
||||
@@ -14,10 +14,6 @@ package vip.xiaonuo.biz.modular.group.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollStreamUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNode;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
@@ -35,7 +31,7 @@ import vip.xiaonuo.biz.modular.group.mapper.BizGroupMapper;
|
||||
import vip.xiaonuo.biz.modular.group.param.*;
|
||||
import vip.xiaonuo.biz.modular.group.service.BizGroupService;
|
||||
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.biz.modular.org.service.BizOrgService;
|
||||
import vip.xiaonuo.biz.modular.user.entity.BizUser;
|
||||
import vip.xiaonuo.biz.modular.user.enums.BizUserStatusEnum;
|
||||
@@ -48,8 +44,6 @@ import vip.xiaonuo.common.page.CommonPageRequest;
|
||||
import vip.xiaonuo.sys.api.SysGroupApi;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户组Service接口实现类
|
||||
@@ -134,34 +128,8 @@ public class BizGroupServiceImpl extends ServiceImpl<BizGroupMapper, BizGroup> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tree<String>> orgTreeSelector() {
|
||||
// 获取所有机构
|
||||
List<BizOrg> allOrgList = bizOrgService.list();
|
||||
// 校验数据范围
|
||||
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
||||
// 确定用于构建树的机构集合
|
||||
List<BizOrg> resultOrgList;
|
||||
if(loginUserDataScope != null && loginUserDataScope.isEmpty()) {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
if(loginUserDataScope == null) {
|
||||
// SCOPE_ALL:使用全部机构
|
||||
resultOrgList = allOrgList;
|
||||
} else {
|
||||
Set<BizOrg> bizOrgSet = CollectionUtil.newHashSet();
|
||||
loginUserDataScope.forEach(orgId -> bizOrgSet.addAll(bizOrgService.getParentListById(allOrgList, orgId, true)));
|
||||
resultOrgList = CollectionUtil.newArrayList(bizOrgSet);
|
||||
}
|
||||
List<TreeNode<String>> treeNodeList = resultOrgList.stream().map(bizOrg ->
|
||||
new TreeNode<>(bizOrg.getId(), bizOrg.getParentId(),
|
||||
bizOrg.getName(), bizOrg.getSortCode()).setExtra(JSONUtil.parseObj(bizOrg)))
|
||||
.collect(Collectors.toList());
|
||||
return TreeUtil.build(treeNodeList, "0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
|
||||
return bizOrgService.treeLazy(bizOrgTreeLazyParam);
|
||||
public List<JSONObject> orgTreeSelector(BizOrgSelectorTreeParam bizOrgSelectorTreeParam) {
|
||||
return bizOrgService.orgTreeSelector(bizOrgSelectorTreeParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
package vip.xiaonuo.biz.modular.org.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.xingfudeshi.knife4j.annotations.ApiOperationSupport;
|
||||
@@ -77,8 +76,8 @@ public class BizOrgController {
|
||||
@Operation(summary = "获取机构树(懒加载)")
|
||||
@SaCheckPermission("/biz/org/tree")
|
||||
@GetMapping("/biz/org/tree")
|
||||
public CommonResult<List<JSONObject>> treeLazy(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
|
||||
return CommonResult.data(bizOrgService.treeLazy(bizOrgTreeLazyParam));
|
||||
public CommonResult<List<JSONObject>> tree(BizOrgSelectorTreeParam bizOrgSelectorTreeParam) {
|
||||
return CommonResult.data(bizOrgService.orgTreeSelector(bizOrgSelectorTreeParam));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,8 +171,8 @@ public class BizOrgController {
|
||||
@Operation(summary = "获取机构树选择器(懒加载)")
|
||||
@SaCheckPermission("/biz/org/orgTreeSelector")
|
||||
@GetMapping("/biz/org/orgTreeSelector")
|
||||
public CommonResult<List<JSONObject>> orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
|
||||
return CommonResult.data(bizOrgService.treeLazy(bizOrgTreeLazyParam));
|
||||
public CommonResult<List<JSONObject>> orgTreeSelector(BizOrgSelectorTreeParam bizOrgSelectorTreeParam) {
|
||||
return CommonResult.data(bizOrgService.orgTreeSelector(bizOrgSelectorTreeParam));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ import lombok.Setter;
|
||||
**/
|
||||
@Getter
|
||||
@Setter
|
||||
public class BizOrgTreeLazyParam {
|
||||
public class BizOrgSelectorTreeParam {
|
||||
|
||||
/** 父id */
|
||||
@Schema(description = "父id")
|
||||
@@ -20,7 +20,7 @@ import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vip.xiaonuo.biz.api.BizOrgApi;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgSelectorOrgListParam;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.biz.modular.org.service.BizOrgService;
|
||||
|
||||
import java.util.List;
|
||||
@@ -38,15 +38,10 @@ public class BizOrgApiProvider implements BizOrgApi {
|
||||
private BizOrgService bizOrgService;
|
||||
|
||||
@Override
|
||||
public List<Tree<String>> orgTreeSelector() {
|
||||
return bizOrgService.tree();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> orgTreeLazySelector(String parentId) {
|
||||
BizOrgTreeLazyParam bizOrgTreeLazyParam = new BizOrgTreeLazyParam();
|
||||
bizOrgTreeLazyParam.setParentId(parentId);
|
||||
return bizOrgService.treeLazy(bizOrgTreeLazyParam);
|
||||
public List<JSONObject> orgTreeSelector(String parentId) {
|
||||
BizOrgSelectorTreeParam bizOrgSelectorTreeParam = new BizOrgSelectorTreeParam();
|
||||
bizOrgSelectorTreeParam.setParentId(parentId);
|
||||
return bizOrgService.orgTreeSelector(bizOrgSelectorTreeParam);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package vip.xiaonuo.biz.modular.org.service;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
@@ -38,22 +37,6 @@ public interface BizOrgService extends IService<BizOrg> {
|
||||
*/
|
||||
Page<BizOrg> page(BizOrgPageParam bizOrgPageParam);
|
||||
|
||||
/**
|
||||
* 获取机构树
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:08
|
||||
*/
|
||||
List<Tree<String>> tree();
|
||||
|
||||
/**
|
||||
* 获取机构树(懒加载)
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:08
|
||||
*/
|
||||
List<JSONObject> treeLazy(BizOrgTreeLazyParam bizOrgTreeLazyParam);
|
||||
|
||||
/**
|
||||
* 添加机构
|
||||
*
|
||||
@@ -158,6 +141,14 @@ public interface BizOrgService extends IService<BizOrg> {
|
||||
**/
|
||||
BizOrg getChildById(List<BizOrg> originDataList, String id);
|
||||
|
||||
/**
|
||||
* 获取机构树(懒加载)
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:08
|
||||
*/
|
||||
List<JSONObject> orgTreeSelector(BizOrgSelectorTreeParam bizOrgSelectorTreeParam);
|
||||
|
||||
/**
|
||||
* 获取机构列表选择器
|
||||
*
|
||||
|
||||
@@ -128,56 +128,6 @@ public class BizOrgServiceImpl extends ServiceImpl<BizOrgMapper, BizOrg> impleme
|
||||
return this.page(CommonPageRequest.defaultPage(), queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tree<String>> tree() {
|
||||
LambdaQueryWrapper<BizOrg> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// 校验数据范围
|
||||
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
||||
// 定义机构集合
|
||||
Set<BizOrg> bizOrgSet = CollectionUtil.newHashSet();
|
||||
if(loginUserDataScope != null && loginUserDataScope.isEmpty()) {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
if(loginUserDataScope == null) {
|
||||
// SCOPE_ALL:不做过滤,查询全部机构
|
||||
} else {
|
||||
// 获取所有机构
|
||||
List<BizOrg> allOrgList = this.getAllOrgList();
|
||||
loginUserDataScope.forEach(orgId -> bizOrgSet.addAll(this.getParentListById(allOrgList, orgId, true)));
|
||||
List<String> loginUserDataScopeFullList = bizOrgSet.stream().map(BizOrg::getId).collect(Collectors.toList());
|
||||
CommonSqlUtil.safeIn(lambdaQueryWrapper, BizOrg::getId, loginUserDataScopeFullList);
|
||||
}
|
||||
lambdaQueryWrapper.orderByAsc(BizOrg::getSortCode);
|
||||
List<BizOrg> bizOrgList = this.list(lambdaQueryWrapper);
|
||||
List<TreeNode<String>> treeNodeList = bizOrgList.stream().map(bizOrg ->
|
||||
new TreeNode<>(bizOrg.getId(), bizOrg.getParentId(), bizOrg.getName(), bizOrg.getSortCode()))
|
||||
.collect(Collectors.toList());
|
||||
return TreeUtil.build(treeNodeList, "0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> treeLazy(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
|
||||
// searchKey不为null时,走全量搜索模式,返回嵌套树结构
|
||||
if (bizOrgTreeLazyParam.getSearchKey() != null) {
|
||||
return this.treeSearch(bizOrgTreeLazyParam.getSearchKey());
|
||||
}
|
||||
String parentId = ObjectUtil.isNotEmpty(bizOrgTreeLazyParam.getParentId()) ? bizOrgTreeLazyParam.getParentId() : "0";
|
||||
// 校验数据范围
|
||||
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
||||
if (loginUserDataScope != null && ObjectUtil.isEmpty(loginUserDataScope)) {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
// loginUserDataScope == null 时为 SCOPE_ALL,不做数据范围过滤;否则取可见机构ID集合
|
||||
Set<String> visibleOrgIds = null;
|
||||
if (loginUserDataScope != null) {
|
||||
visibleOrgIds = this.getVisibleOrgIds(loginUserDataScope);
|
||||
if (ObjectUtil.isEmpty(visibleOrgIds)) {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
}
|
||||
return this.fetchChildrenWithLeafFlag(parentId, visibleOrgIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定父节点下的直接子机构列表,并为每个子机构设置 isLeaf 标志。
|
||||
* visibleOrgIds 为 null 时表示 SCOPE_ALL,不做数据范围过滤(与 SysOrg 行为一致);
|
||||
@@ -522,6 +472,29 @@ public class BizOrgServiceImpl extends ServiceImpl<BizOrgMapper, BizOrg> impleme
|
||||
|
||||
/* ====机构部分所需要用到的选择器==== */
|
||||
|
||||
@Override
|
||||
public List<JSONObject> orgTreeSelector(BizOrgSelectorTreeParam bizOrgSelectorTreeParam) {
|
||||
// searchKey不为null时,走全量搜索模式,返回嵌套树结构
|
||||
if (bizOrgSelectorTreeParam.getSearchKey() != null) {
|
||||
return this.treeSearch(bizOrgSelectorTreeParam.getSearchKey());
|
||||
}
|
||||
String parentId = ObjectUtil.isNotEmpty(bizOrgSelectorTreeParam.getParentId()) ? bizOrgSelectorTreeParam.getParentId() : "0";
|
||||
// 校验数据范围
|
||||
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
||||
if (loginUserDataScope != null && ObjectUtil.isEmpty(loginUserDataScope)) {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
// loginUserDataScope == null 时为 SCOPE_ALL,不做数据范围过滤;否则取可见机构ID集合
|
||||
Set<String> visibleOrgIds = null;
|
||||
if (loginUserDataScope != null) {
|
||||
visibleOrgIds = this.getVisibleOrgIds(loginUserDataScope);
|
||||
if (ObjectUtil.isEmpty(visibleOrgIds)) {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
}
|
||||
return this.fetchChildrenWithLeafFlag(parentId, visibleOrgIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<BizOrg> orgListSelector(BizOrgSelectorOrgListParam bizOrgSelectorOrgListParam) {
|
||||
QueryWrapper<BizOrg> queryWrapper = new QueryWrapper<BizOrg>().checkSqlInjection();
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
package vip.xiaonuo.biz.modular.position.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.xingfudeshi.knife4j.annotations.ApiOperationSupport;
|
||||
@@ -32,7 +31,7 @@ import vip.xiaonuo.biz.modular.position.param.*;
|
||||
import vip.xiaonuo.biz.modular.position.service.BizPositionService;
|
||||
import vip.xiaonuo.common.annotation.CommonLog;
|
||||
import vip.xiaonuo.common.pojo.CommonResult;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgSelectorTreeParam;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
@@ -141,8 +140,8 @@ public class BizPositionController {
|
||||
@Operation(summary = "获取组织树选择器(懒加载)")
|
||||
@SaCheckPermission("/biz/position/orgTreeSelector")
|
||||
@GetMapping("/biz/position/orgTreeSelector")
|
||||
public CommonResult<List<JSONObject>> orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
|
||||
return CommonResult.data(bizPositionService.orgTreeLazySelector(bizOrgTreeLazyParam));
|
||||
public CommonResult<List<JSONObject>> orgTreeSelector(BizOrgSelectorTreeParam bizOrgSelectorTreeParam) {
|
||||
return CommonResult.data(bizPositionService.orgTreeSelector(bizOrgSelectorTreeParam));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,13 +12,12 @@
|
||||
*/
|
||||
package vip.xiaonuo.biz.modular.position.service;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import vip.xiaonuo.biz.modular.position.entity.BizPosition;
|
||||
import vip.xiaonuo.biz.modular.position.param.*;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgSelectorTreeParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -88,21 +87,13 @@ public interface BizPositionService extends IService<BizPosition> {
|
||||
|
||||
/* ====岗位部分所需要用到的选择器==== */
|
||||
|
||||
/**
|
||||
* 获取机构树选择器
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:08
|
||||
*/
|
||||
List<Tree<String>> orgTreeSelector();
|
||||
|
||||
/**
|
||||
* 获取机构树选择器(懒加载)
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:08
|
||||
*/
|
||||
List<JSONObject> orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam);
|
||||
List<JSONObject> orgTreeSelector(BizOrgSelectorTreeParam bizOrgSelectorTreeParam);
|
||||
|
||||
/**
|
||||
* 获取岗位选择器
|
||||
|
||||
@@ -16,9 +16,6 @@ import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollStreamUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNode;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -32,8 +29,7 @@ import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
|
||||
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.biz.modular.org.service.BizOrgService;
|
||||
import vip.xiaonuo.biz.modular.position.entity.BizPosition;
|
||||
import vip.xiaonuo.biz.modular.position.enums.BizPositionCategoryEnum;
|
||||
@@ -221,33 +217,8 @@ public class BizPositionServiceImpl extends ServiceImpl<BizPositionMapper, BizPo
|
||||
/* ====岗位部分所需要用到的选择器==== */
|
||||
|
||||
@Override
|
||||
public List<Tree<String>> orgTreeSelector() {
|
||||
LambdaQueryWrapper<BizOrg> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// 校验数据范围
|
||||
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
||||
// 定义机构集合
|
||||
Set<BizOrg> bizOrgSet = CollectionUtil.newHashSet();
|
||||
if(loginUserDataScope != null && loginUserDataScope.isEmpty()) {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
if(ObjectUtil.isNotEmpty(loginUserDataScope)) {
|
||||
// 获取所有机构
|
||||
List<BizOrg> allOrgList = bizOrgService.list();
|
||||
loginUserDataScope.forEach(orgId -> bizOrgSet.addAll(bizOrgService.getParentListById(allOrgList, orgId, true)));
|
||||
List<String> loginUserDataScopeFullList = bizOrgSet.stream().map(BizOrg::getId).collect(Collectors.toList());
|
||||
CommonSqlUtil.safeIn(lambdaQueryWrapper, BizOrg::getId, loginUserDataScopeFullList);
|
||||
}
|
||||
lambdaQueryWrapper.orderByAsc(BizOrg::getSortCode);
|
||||
List<BizOrg> bizOrgList = bizOrgService.list(lambdaQueryWrapper);
|
||||
List<TreeNode<String>> treeNodeList = bizOrgList.stream().map(bizOrg ->
|
||||
new TreeNode<>(bizOrg.getId(), bizOrg.getParentId(), bizOrg.getName(), bizOrg.getSortCode()))
|
||||
.collect(Collectors.toList());
|
||||
return TreeUtil.build(treeNodeList, "0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
|
||||
return bizOrgService.treeLazy(bizOrgTreeLazyParam);
|
||||
public List<JSONObject> orgTreeSelector(BizOrgSelectorTreeParam bizOrgSelectorTreeParam) {
|
||||
return bizOrgService.orgTreeSelector(bizOrgSelectorTreeParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
package vip.xiaonuo.biz.modular.user.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.xingfudeshi.knife4j.annotations.ApiOperationSupport;
|
||||
@@ -31,7 +30,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
|
||||
import vip.xiaonuo.biz.modular.position.entity.BizPosition;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.biz.modular.user.entity.BizUser;
|
||||
import vip.xiaonuo.biz.modular.user.enums.BizUserSourceFromTypeEnum;
|
||||
import vip.xiaonuo.biz.modular.user.param.*;
|
||||
@@ -256,8 +255,8 @@ public class BizUserController {
|
||||
@Operation(summary = "获取机构树选择器(懒加载)")
|
||||
@SaCheckPermission("/biz/user/orgTreeSelector")
|
||||
@GetMapping("/biz/user/orgTreeSelector")
|
||||
public CommonResult<List<JSONObject>> orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
|
||||
return CommonResult.data(bizUserService.orgTreeLazySelector(bizOrgTreeLazyParam));
|
||||
public CommonResult<List<JSONObject>> orgTreeSelector(BizOrgSelectorTreeParam bizOrgSelectorTreeParam) {
|
||||
return CommonResult.data(bizUserService.orgTreeSelector(bizOrgSelectorTreeParam));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,13 +12,12 @@
|
||||
*/
|
||||
package vip.xiaonuo.biz.modular.user.service;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.biz.modular.position.entity.BizPosition;
|
||||
import vip.xiaonuo.biz.modular.user.entity.BizUser;
|
||||
import vip.xiaonuo.biz.modular.user.param.*;
|
||||
@@ -141,21 +140,13 @@ public interface BizUserService extends IService<BizUser> {
|
||||
|
||||
/* ====人员部分所需要用到的选择器==== */
|
||||
|
||||
/**
|
||||
* 获取机构树选择器
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/5/13 21:00
|
||||
*/
|
||||
List<Tree<String>> orgTreeSelector();
|
||||
|
||||
/**
|
||||
* 获取机构树选择器(懒加载)
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/5/13 21:00
|
||||
*/
|
||||
List<JSONObject> orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam);
|
||||
List<JSONObject> orgTreeSelector(BizOrgSelectorTreeParam bizOrgSelectorTreeParam);
|
||||
|
||||
/**
|
||||
* 获取机构列表选择器
|
||||
|
||||
@@ -24,9 +24,6 @@ import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNode;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.PhoneUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -57,7 +54,7 @@ import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
|
||||
import vip.xiaonuo.biz.core.enums.BizBuildInEnum;
|
||||
import vip.xiaonuo.biz.core.enums.BizDataTypeEnum;
|
||||
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
|
||||
import vip.xiaonuo.biz.modular.org.param.BizOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.biz.modular.org.service.BizOrgService;
|
||||
import vip.xiaonuo.biz.modular.position.entity.BizPosition;
|
||||
import vip.xiaonuo.biz.modular.position.service.BizPositionService;
|
||||
@@ -619,33 +616,8 @@ public class BizUserServiceImpl extends ServiceImpl<BizUserMapper, BizUser> impl
|
||||
/* ====人员部分所需要用到的选择器==== */
|
||||
|
||||
@Override
|
||||
public List<Tree<String>> orgTreeSelector() {
|
||||
LambdaQueryWrapper<BizOrg> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// 校验数据范围
|
||||
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
||||
// 定义机构集合
|
||||
Set<BizOrg> bizOrgSet = CollectionUtil.newHashSet();
|
||||
if(loginUserDataScope != null && loginUserDataScope.isEmpty()) {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
if(ObjectUtil.isNotEmpty(loginUserDataScope)) {
|
||||
// 获取所有机构
|
||||
List<BizOrg> allOrgList = bizOrgService.list();
|
||||
loginUserDataScope.forEach(orgId -> bizOrgSet.addAll(bizOrgService.getParentListById(allOrgList, orgId, true)));
|
||||
List<String> loginUserDataScopeFullList = bizOrgSet.stream().map(BizOrg::getId).collect(Collectors.toList());
|
||||
CommonSqlUtil.safeIn(lambdaQueryWrapper, BizOrg::getId, loginUserDataScopeFullList);
|
||||
}
|
||||
lambdaQueryWrapper.orderByAsc(BizOrg::getSortCode);
|
||||
List<BizOrg> bizOrgList = bizOrgService.list(lambdaQueryWrapper);
|
||||
List<TreeNode<String>> treeNodeList = bizOrgList.stream().map(bizOrg ->
|
||||
new TreeNode<>(bizOrg.getId(), bizOrg.getParentId(), bizOrg.getName(), bizOrg.getSortCode()))
|
||||
.collect(Collectors.toList());
|
||||
return TreeUtil.build(treeNodeList, "0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
|
||||
return bizOrgService.treeLazy(bizOrgTreeLazyParam);
|
||||
public List<JSONObject> orgTreeSelector(BizOrgSelectorTreeParam bizOrgSelectorTreeParam) {
|
||||
return bizOrgService.orgTreeSelector(bizOrgSelectorTreeParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package vip.xiaonuo.dev.modular.config.controller;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.xingfudeshi.knife4j.annotations.ApiOperationSupport;
|
||||
@@ -190,27 +189,15 @@ public class DevConfigController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取机构选树
|
||||
* 获取组织树选择器(懒加载)
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2025/4/23 20:00
|
||||
*/
|
||||
@Operation(summary = "获取机构选树")
|
||||
@GetMapping("/dev/config/orgTree")
|
||||
public CommonResult<List<Tree<String>>> orgTree() {
|
||||
return CommonResult.data(sysOrgApi.orgTree());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取机构选树(懒加载)
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2025/4/23 20:00
|
||||
*/
|
||||
@Operation(summary = "获取机构选树(懒加载)")
|
||||
@GetMapping("/dev/config/orgTreeLazy")
|
||||
public CommonResult<List<JSONObject>> orgTreeLazy(String parentId) {
|
||||
return CommonResult.data(sysOrgApi.orgTreeLazy(parentId));
|
||||
@Operation(summary = "获取组织树选择器(懒加载)")
|
||||
@GetMapping("/dev/config/orgTreeSelector")
|
||||
public CommonResult<List<JSONObject>> orgTreeSelector(DevConfigSelectorOrgTreeParam devConfigSelectorOrgTreeParam) {
|
||||
return CommonResult.data(sysOrgApi.orgTreeSelector(devConfigSelectorOrgTreeParam.getParentId()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ import lombok.Setter;
|
||||
**/
|
||||
@Getter
|
||||
@Setter
|
||||
public class DevConfigSelectorOrgTreeLazyParam {
|
||||
public class DevConfigSelectorOrgTreeParam {
|
||||
|
||||
/** 父id */
|
||||
@Schema(description = "父id")
|
||||
@@ -36,7 +36,6 @@ import vip.xiaonuo.dev.modular.config.mapper.DevConfigMapper;
|
||||
import vip.xiaonuo.dev.modular.config.param.*;
|
||||
import vip.xiaonuo.dev.modular.config.service.DevConfigService;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package vip.xiaonuo.dev.modular.message.websocket;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import jakarta.websocket.*;
|
||||
|
||||
@@ -22,7 +22,6 @@ import cn.hutool.json.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.aliyun.config.AlibabaConfig;
|
||||
import org.dromara.sms4j.api.SmsBlend;
|
||||
import org.dromara.sms4j.api.dao.SmsDaoDefaultImpl;
|
||||
import org.dromara.sms4j.api.entity.SmsResponse;
|
||||
import org.dromara.sms4j.core.factory.SmsFactory;
|
||||
import org.dromara.sms4j.javase.config.SEInitializer;
|
||||
|
||||
@@ -29,7 +29,7 @@ import vip.xiaonuo.common.pojo.CommonResult;
|
||||
import vip.xiaonuo.sys.modular.group.entity.SysGroup;
|
||||
import vip.xiaonuo.sys.modular.group.param.*;
|
||||
import vip.xiaonuo.sys.modular.group.service.SysGroupService;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeLazyParam;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.sys.modular.user.entity.SysUser;
|
||||
|
||||
import java.util.List;
|
||||
@@ -135,8 +135,8 @@ public class SysGroupController {
|
||||
*/
|
||||
@Operation(summary = "获取组织树选择器")
|
||||
@GetMapping("/sys/group/orgTreeSelector")
|
||||
public CommonResult<List<JSONObject>> orgTreeSelector(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam) {
|
||||
return CommonResult.data(sysGroupService.orgTreeLazySelector(sysOrgSelectorTreeLazyParam));
|
||||
public CommonResult<List<JSONObject>> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam) {
|
||||
return CommonResult.data(sysGroupService.orgTreeSelector(sysOrgSelectorTreeParam));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,13 +12,12 @@
|
||||
*/
|
||||
package vip.xiaonuo.sys.modular.group.service;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import vip.xiaonuo.sys.modular.group.entity.SysGroup;
|
||||
import vip.xiaonuo.sys.modular.group.param.*;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeLazyParam;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.sys.modular.user.entity.SysUser;
|
||||
|
||||
import java.util.List;
|
||||
@@ -87,21 +86,13 @@ public interface SysGroupService extends IService<SysGroup> {
|
||||
*/
|
||||
List<String> ownUser(SysGroupIdParam sysGroupIdParam);
|
||||
|
||||
/**
|
||||
* 获取组织树选择器
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2024/12/21 01:25
|
||||
*/
|
||||
List<Tree<String>> orgTreeSelector();
|
||||
|
||||
/**
|
||||
* 获取组织树选择器(懒加载)
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
List<JSONObject> orgTreeLazySelector(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam);
|
||||
List<JSONObject> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam);
|
||||
|
||||
/**
|
||||
* 获取用户选择器
|
||||
|
||||
@@ -14,9 +14,6 @@ package vip.xiaonuo.sys.modular.group.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollStreamUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNode;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
@@ -38,7 +35,7 @@ import vip.xiaonuo.sys.modular.group.mapper.SysGroupMapper;
|
||||
import vip.xiaonuo.sys.modular.group.param.*;
|
||||
import vip.xiaonuo.sys.modular.group.service.SysGroupService;
|
||||
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeLazyParam;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.sys.modular.org.service.SysOrgService;
|
||||
import vip.xiaonuo.sys.modular.relation.entity.SysRelation;
|
||||
import vip.xiaonuo.sys.modular.relation.enums.SysRelationCategoryEnum;
|
||||
@@ -137,17 +134,8 @@ public class SysGroupServiceImpl extends ServiceImpl<SysGroupMapper, SysGroup> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tree<String>> orgTreeSelector() {
|
||||
List<SysOrg> sysOrgList = sysOrgService.getAllOrgList();
|
||||
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
|
||||
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode()))
|
||||
.collect(Collectors.toList());
|
||||
return TreeUtil.build(treeNodeList, "0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> orgTreeLazySelector(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam) {
|
||||
return sysOrgService.treeLazy(sysOrgSelectorTreeLazyParam);
|
||||
public List<JSONObject> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam) {
|
||||
return sysOrgService.orgTreeSelector(sysOrgSelectorTreeParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
import vip.xiaonuo.common.annotation.CommonLog;
|
||||
import vip.xiaonuo.common.pojo.CommonResult;
|
||||
import vip.xiaonuo.sys.modular.index.param.*;
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package vip.xiaonuo.sys.modular.index.service;
|
||||
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
import vip.xiaonuo.sys.modular.index.param.*;
|
||||
import vip.xiaonuo.sys.modular.index.result.*;
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ import vip.xiaonuo.sys.modular.role.service.SysRoleService;
|
||||
import vip.xiaonuo.sys.modular.user.service.SysUserService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
||||
@@ -73,8 +73,8 @@ public class SysOrgController {
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(summary = "获取组织树(懒加载)")
|
||||
@GetMapping("/sys/org/tree")
|
||||
public CommonResult<List<JSONObject>> treeLazy(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam) {
|
||||
return CommonResult.data(sysOrgService.treeLazy(sysOrgSelectorTreeLazyParam));
|
||||
public CommonResult<List<JSONObject>> tree(SysOrgSelectorTreeParam sysOrgSelectorTreeParam) {
|
||||
return CommonResult.data(sysOrgService.orgTreeSelector(sysOrgSelectorTreeParam));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,8 +162,8 @@ public class SysOrgController {
|
||||
@ApiOperationSupport(order = 8)
|
||||
@Operation(summary = "获取组织树选择器(懒加载)")
|
||||
@GetMapping("/sys/org/orgTreeSelector")
|
||||
public CommonResult<List<JSONObject>> orgTreeLazySelector(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam) {
|
||||
return CommonResult.data(sysOrgService.treeLazy(sysOrgSelectorTreeLazyParam));
|
||||
public CommonResult<List<JSONObject>> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam) {
|
||||
return CommonResult.data(sysOrgService.orgTreeSelector(sysOrgSelectorTreeParam));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ import lombok.Setter;
|
||||
**/
|
||||
@Getter
|
||||
@Setter
|
||||
public class SysOrgSelectorTreeLazyParam {
|
||||
public class SysOrgSelectorTreeParam {
|
||||
|
||||
/** 父id */
|
||||
@Schema(description = "父id")
|
||||
@@ -13,7 +13,6 @@
|
||||
package vip.xiaonuo.sys.modular.org.provider;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
@@ -23,7 +22,7 @@ import org.springframework.stereotype.Service;
|
||||
import vip.xiaonuo.sys.api.SysOrgApi;
|
||||
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorOrgListParam;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeLazyParam;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.sys.modular.org.service.SysOrgService;
|
||||
|
||||
import java.util.List;
|
||||
@@ -56,15 +55,10 @@ public class SysOrgApiProvider implements SysOrgApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tree<String>> orgTree() {
|
||||
return sysOrgService.tree();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> orgTreeLazy(String parentId) {
|
||||
SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam = new SysOrgSelectorTreeLazyParam();
|
||||
sysOrgSelectorTreeLazyParam.setParentId(parentId);
|
||||
return sysOrgService.treeLazy(sysOrgSelectorTreeLazyParam);
|
||||
public List<JSONObject> orgTreeSelector(String parentId) {
|
||||
SysOrgSelectorTreeParam sysOrgSelectorTreeParam = new SysOrgSelectorTreeParam();
|
||||
sysOrgSelectorTreeParam.setParentId(parentId);
|
||||
return sysOrgService.orgTreeSelector(sysOrgSelectorTreeParam);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package vip.xiaonuo.sys.modular.org.service;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
@@ -38,22 +37,6 @@ public interface SysOrgService extends IService<SysOrg> {
|
||||
*/
|
||||
Page<SysOrg> page(SysOrgPageParam sysOrgPageParam);
|
||||
|
||||
/**
|
||||
* 获取组织树
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:08
|
||||
*/
|
||||
List<Tree<String>> tree();
|
||||
|
||||
/**
|
||||
* 获取机构树(懒加载),支持搜索
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/21 16:13
|
||||
**/
|
||||
List<JSONObject> treeLazy(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam);
|
||||
|
||||
/**
|
||||
* 添加组织
|
||||
*
|
||||
@@ -174,6 +157,14 @@ public interface SysOrgService extends IService<SysOrg> {
|
||||
**/
|
||||
SysOrg getChildById(List<SysOrg> originDataList, String id);
|
||||
|
||||
/**
|
||||
* 获取组织树选择器(懒加载),支持搜索,搜索为空字符串走全量
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/21 16:13
|
||||
**/
|
||||
List<JSONObject> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam);
|
||||
|
||||
/**
|
||||
* 获取组织列表选择器
|
||||
*
|
||||
|
||||
@@ -111,69 +111,6 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
||||
return this.page(CommonPageRequest.defaultPage(), queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tree<String>> tree() {
|
||||
List<SysOrg> sysOrgList = this.getAllOrgList();
|
||||
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
|
||||
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode()))
|
||||
.collect(Collectors.toList());
|
||||
return TreeUtil.build(treeNodeList, "0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> treeLazy(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam) {
|
||||
// searchKey不为null时,走全量搜索模式,返回嵌套树结构
|
||||
if (sysOrgSelectorTreeLazyParam.getSearchKey() != null) {
|
||||
return this.treeSearch(sysOrgSelectorTreeLazyParam.getSearchKey());
|
||||
}
|
||||
String parentId = ObjectUtil.isNotEmpty(sysOrgSelectorTreeLazyParam.getParentId()) ? sysOrgSelectorTreeLazyParam.getParentId() : "0";
|
||||
// 超管接口,无需数据范围过滤,直接SQL查询当前父级下的子机构
|
||||
List<SysOrg> childList = this.list(new LambdaQueryWrapper<SysOrg>()
|
||||
.eq(SysOrg::getParentId, parentId)
|
||||
.orderByAsc(SysOrg::getSortCode)
|
||||
.orderByAsc(SysOrg::getId));
|
||||
if (ObjectUtil.isEmpty(childList)) {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
// 批量判断哪些子机构还有下级
|
||||
List<String> childIds = childList.stream().map(SysOrg::getId).collect(Collectors.toList());
|
||||
Set<String> hasChildrenParentIds = this.list(new LambdaQueryWrapper<SysOrg>()
|
||||
.select(SysOrg::getParentId)
|
||||
.in(SysOrg::getParentId, childIds))
|
||||
.stream().map(SysOrg::getParentId).collect(Collectors.toSet());
|
||||
return childList.stream().map(sysOrg -> {
|
||||
JSONObject jsonObject = JSONUtil.parseObj(sysOrg);
|
||||
jsonObject.set("isLeaf", !hasChildrenParentIds.contains(sysOrg.getId()));
|
||||
return jsonObject;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 全量搜索模式,返回嵌套树结构的JSONObject列表
|
||||
* searchKey为空字符串时返回全量树,非空时按关键字过滤
|
||||
*/
|
||||
private List<JSONObject> treeSearch(String searchKey) {
|
||||
List<SysOrg> allOrgList = this.getAllOrgList();
|
||||
List<SysOrg> sysOrgList;
|
||||
if (ObjectUtil.isNotEmpty(searchKey)) {
|
||||
Set<SysOrg> filteredSet = CollectionUtil.newLinkedHashSet();
|
||||
allOrgList.stream()
|
||||
.filter(org -> StrUtil.containsIgnoreCase(org.getName(), searchKey))
|
||||
.forEach(org -> filteredSet.addAll(this.getParentListById(allOrgList, org.getId(), true)));
|
||||
sysOrgList = new ArrayList<>(filteredSet);
|
||||
} else {
|
||||
sysOrgList = allOrgList;
|
||||
}
|
||||
sysOrgList.sort(Comparator.comparingInt(SysOrg::getSortCode)
|
||||
.thenComparing(SysOrg::getId));
|
||||
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
|
||||
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(),
|
||||
sysOrg.getName(), sysOrg.getSortCode()).setExtra(JSONUtil.parseObj(sysOrg)))
|
||||
.collect(Collectors.toList());
|
||||
List<Tree<String>> treeList = TreeUtil.build(treeNodeList, "0");
|
||||
return JSONUtil.toList(JSONUtil.parseArray(treeList), JSONObject.class);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void add(SysOrgAddParam sysOrgAddParam, String sourceFromType) {
|
||||
@@ -437,6 +374,60 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
||||
|
||||
/* ====组织部分所需要用到的选择器==== */
|
||||
|
||||
@Override
|
||||
public List<JSONObject> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam) {
|
||||
// searchKey不为null时,走全量搜索模式,返回嵌套树结构
|
||||
if (sysOrgSelectorTreeParam.getSearchKey() != null) {
|
||||
return this.treeSearch(sysOrgSelectorTreeParam.getSearchKey());
|
||||
}
|
||||
String parentId = ObjectUtil.isNotEmpty(sysOrgSelectorTreeParam.getParentId()) ? sysOrgSelectorTreeParam.getParentId() : "0";
|
||||
// 超管接口,无需数据范围过滤,直接SQL查询当前父级下的子机构
|
||||
List<SysOrg> childList = this.list(new LambdaQueryWrapper<SysOrg>()
|
||||
.eq(SysOrg::getParentId, parentId)
|
||||
.orderByAsc(SysOrg::getSortCode)
|
||||
.orderByAsc(SysOrg::getId));
|
||||
if (ObjectUtil.isEmpty(childList)) {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
// 批量判断哪些子机构还有下级
|
||||
List<String> childIds = childList.stream().map(SysOrg::getId).collect(Collectors.toList());
|
||||
Set<String> hasChildrenParentIds = this.list(new LambdaQueryWrapper<SysOrg>()
|
||||
.select(SysOrg::getParentId)
|
||||
.in(SysOrg::getParentId, childIds))
|
||||
.stream().map(SysOrg::getParentId).collect(Collectors.toSet());
|
||||
return childList.stream().map(sysOrg -> {
|
||||
JSONObject jsonObject = JSONUtil.parseObj(sysOrg);
|
||||
jsonObject.set("isLeaf", !hasChildrenParentIds.contains(sysOrg.getId()));
|
||||
return jsonObject;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 全量搜索模式,返回嵌套树结构的JSONObject列表
|
||||
* searchKey为空字符串时返回全量树,非空时按关键字过滤
|
||||
*/
|
||||
private List<JSONObject> treeSearch(String searchKey) {
|
||||
List<SysOrg> allOrgList = this.getAllOrgList();
|
||||
List<SysOrg> sysOrgList;
|
||||
if (ObjectUtil.isNotEmpty(searchKey)) {
|
||||
Set<SysOrg> filteredSet = CollectionUtil.newLinkedHashSet();
|
||||
allOrgList.stream()
|
||||
.filter(org -> StrUtil.containsIgnoreCase(org.getName(), searchKey))
|
||||
.forEach(org -> filteredSet.addAll(this.getParentListById(allOrgList, org.getId(), true)));
|
||||
sysOrgList = new ArrayList<>(filteredSet);
|
||||
} else {
|
||||
sysOrgList = allOrgList;
|
||||
}
|
||||
sysOrgList.sort(Comparator.comparingInt(SysOrg::getSortCode)
|
||||
.thenComparing(SysOrg::getId));
|
||||
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
|
||||
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(),
|
||||
sysOrg.getName(), sysOrg.getSortCode()).setExtra(JSONUtil.parseObj(sysOrg)))
|
||||
.collect(Collectors.toList());
|
||||
List<Tree<String>> treeList = TreeUtil.build(treeNodeList, "0");
|
||||
return JSONUtil.toList(JSONUtil.parseArray(treeList), JSONObject.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SysOrg> orgListSelector(SysOrgSelectorOrgListParam sysOrgSelectorOrgListParam) {
|
||||
QueryWrapper<SysOrg> queryWrapper = new QueryWrapper<SysOrg>().checkSqlInjection();
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import vip.xiaonuo.auth.core.pojo.SaBaseLoginUser;
|
||||
import vip.xiaonuo.sys.modular.org.entity.SysUserDataScope;
|
||||
import vip.xiaonuo.sys.modular.org.entity.SysUserDataScopeMap;
|
||||
import vip.xiaonuo.sys.modular.org.mapper.SysUserDataScopeMapper;
|
||||
import vip.xiaonuo.sys.modular.org.mapper.SysUserDataScopeMapMapper;
|
||||
import vip.xiaonuo.sys.modular.org.mapper.SysUserDataScopeMapper;
|
||||
import vip.xiaonuo.sys.modular.org.service.SysUserDataScopeService;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import vip.xiaonuo.common.annotation.CommonLog;
|
||||
import vip.xiaonuo.common.pojo.CommonResult;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeLazyParam;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.sys.modular.position.entity.SysPosition;
|
||||
import vip.xiaonuo.sys.modular.position.param.*;
|
||||
import vip.xiaonuo.sys.modular.position.service.SysPositionService;
|
||||
@@ -133,8 +133,8 @@ public class SysPositionController {
|
||||
@ApiOperationSupport(order = 6)
|
||||
@Operation(summary = "获取组织树选择器(懒加载)")
|
||||
@GetMapping("/sys/position/orgTreeSelector")
|
||||
public CommonResult<List<JSONObject>> orgTreeLazySelector(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam) {
|
||||
return CommonResult.data(sysPositionService.orgTreeLazySelector(sysOrgSelectorTreeLazyParam));
|
||||
public CommonResult<List<JSONObject>> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam) {
|
||||
return CommonResult.data(sysPositionService.orgTreeSelector(sysOrgSelectorTreeParam));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,11 +12,10 @@
|
||||
*/
|
||||
package vip.xiaonuo.sys.modular.position.service;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeLazyParam;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.sys.modular.position.entity.SysPosition;
|
||||
import vip.xiaonuo.sys.modular.position.param.*;
|
||||
|
||||
@@ -96,21 +95,13 @@ public interface SysPositionService extends IService<SysPosition> {
|
||||
|
||||
/* ====职位部分所需要用到的选择器==== */
|
||||
|
||||
/**
|
||||
* 获取组织树选择器
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:08
|
||||
*/
|
||||
List<Tree<String>> orgTreeSelector();
|
||||
|
||||
/**
|
||||
* 获取组织树选择器(懒加载)
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/22 15:53
|
||||
**/
|
||||
List<JSONObject> orgTreeLazySelector(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam);
|
||||
List<JSONObject> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam);
|
||||
|
||||
/**
|
||||
* 获取职位选择器
|
||||
|
||||
@@ -15,9 +15,6 @@ package vip.xiaonuo.sys.modular.position.service.impl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollStreamUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNode;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -35,8 +32,7 @@ import vip.xiaonuo.common.exception.CommonException;
|
||||
import vip.xiaonuo.common.listener.CommonDataChangeEventCenter;
|
||||
import vip.xiaonuo.common.page.CommonPageRequest;
|
||||
import vip.xiaonuo.sys.core.enums.SysDataTypeEnum;
|
||||
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeLazyParam;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.sys.modular.org.service.SysOrgService;
|
||||
import vip.xiaonuo.sys.modular.position.entity.SysPosition;
|
||||
import vip.xiaonuo.sys.modular.position.enums.SysPositionCategoryEnum;
|
||||
@@ -193,17 +189,8 @@ public class SysPositionServiceImpl extends ServiceImpl<SysPositionMapper, SysPo
|
||||
/* ====职位部分所需要用到的选择器==== */
|
||||
|
||||
@Override
|
||||
public List<Tree<String>> orgTreeSelector() {
|
||||
List<SysOrg> sysOrgList = sysOrgService.getAllOrgList();
|
||||
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
|
||||
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode()))
|
||||
.collect(Collectors.toList());
|
||||
return TreeUtil.build(treeNodeList, "0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> orgTreeLazySelector(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam) {
|
||||
return sysOrgService.treeLazy(sysOrgSelectorTreeLazyParam);
|
||||
public List<JSONObject> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam) {
|
||||
return sysOrgService.orgTreeSelector(sysOrgSelectorTreeParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import vip.xiaonuo.common.annotation.CommonLog;
|
||||
import vip.xiaonuo.common.pojo.CommonResult;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeLazyParam;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.sys.modular.role.entity.SysRole;
|
||||
import vip.xiaonuo.sys.modular.role.param.*;
|
||||
import vip.xiaonuo.sys.modular.role.result.*;
|
||||
@@ -248,8 +248,8 @@ public class SysRoleController {
|
||||
@ApiOperationSupport(order = 15)
|
||||
@Operation(summary = "获取组织树选择器(懒加载)")
|
||||
@GetMapping("/sys/role/orgTreeSelector")
|
||||
public CommonResult<List<JSONObject>> orgTreeLazySelector(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam) {
|
||||
return CommonResult.data(sysRoleService.orgTreeLazySelector(sysOrgSelectorTreeLazyParam));
|
||||
public CommonResult<List<JSONObject>> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam) {
|
||||
return CommonResult.data(sysRoleService.orgTreeSelector(sysOrgSelectorTreeParam));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,11 +12,10 @@
|
||||
*/
|
||||
package vip.xiaonuo.sys.modular.role.service;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeLazyParam;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.sys.modular.resource.entity.SysMenu;
|
||||
import vip.xiaonuo.sys.modular.role.entity.SysRole;
|
||||
import vip.xiaonuo.sys.modular.role.param.*;
|
||||
@@ -147,21 +146,13 @@ public interface SysRoleService extends IService<SysRole> {
|
||||
|
||||
/* ====角色部分所需要用到的选择器==== */
|
||||
|
||||
/**
|
||||
* 获取组织树选择器
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:08
|
||||
*/
|
||||
List<Tree<String>> orgTreeSelector();
|
||||
|
||||
/**
|
||||
* 获取组织树选择器(懒加载)
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
List<JSONObject> orgTreeLazySelector(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam);
|
||||
List<JSONObject> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam);
|
||||
|
||||
/**
|
||||
* 获取资源授权树
|
||||
|
||||
@@ -41,7 +41,7 @@ import vip.xiaonuo.mobile.api.MobileMenuApi;
|
||||
import vip.xiaonuo.sys.core.enums.SysBuildInEnum;
|
||||
import vip.xiaonuo.sys.core.enums.SysDataTypeEnum;
|
||||
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeLazyParam;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.sys.modular.org.service.SysOrgService;
|
||||
import vip.xiaonuo.sys.modular.relation.entity.SysRelation;
|
||||
import vip.xiaonuo.sys.modular.relation.enums.SysRelationCategoryEnum;
|
||||
@@ -350,17 +350,8 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
/* ====角色部分所需要用到的选择器==== */
|
||||
|
||||
@Override
|
||||
public List<Tree<String>> orgTreeSelector() {
|
||||
List<SysOrg> sysOrgList = sysOrgService.getAllOrgList();
|
||||
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
|
||||
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode()))
|
||||
.collect(Collectors.toList());
|
||||
return TreeUtil.build(treeNodeList, "0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> orgTreeLazySelector(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam) {
|
||||
return sysOrgService.treeLazy(sysOrgSelectorTreeLazyParam);
|
||||
public List<JSONObject> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam) {
|
||||
return sysOrgService.orgTreeSelector(sysOrgSelectorTreeParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,9 +28,9 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import vip.xiaonuo.common.annotation.CommonLog;
|
||||
import vip.xiaonuo.common.pojo.CommonResult;
|
||||
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.sys.modular.position.entity.SysPosition;
|
||||
import vip.xiaonuo.sys.modular.role.entity.SysRole;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeLazyParam;
|
||||
import vip.xiaonuo.sys.modular.user.entity.SysUser;
|
||||
import vip.xiaonuo.sys.modular.user.enums.SysUserSourceFromTypeEnum;
|
||||
import vip.xiaonuo.sys.modular.user.param.*;
|
||||
@@ -325,8 +325,8 @@ public class SysUserController {
|
||||
@ApiOperationSupport(order = 19)
|
||||
@Operation(summary = "获取组织树选择器(懒加载)")
|
||||
@GetMapping("/sys/user/orgTreeSelector")
|
||||
public CommonResult<List<JSONObject>> orgTreeLazySelector(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam) {
|
||||
return CommonResult.data(sysUserService.orgTreeLazySelector(sysOrgSelectorTreeLazyParam));
|
||||
public CommonResult<List<JSONObject>> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam) {
|
||||
return CommonResult.data(sysUserService.orgTreeSelector(sysOrgSelectorTreeParam));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,9 +20,9 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import vip.xiaonuo.sys.modular.group.entity.SysGroup;
|
||||
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.sys.modular.position.entity.SysPosition;
|
||||
import vip.xiaonuo.sys.modular.role.entity.SysRole;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeLazyParam;
|
||||
import vip.xiaonuo.sys.modular.user.entity.SysUser;
|
||||
import vip.xiaonuo.sys.modular.user.entity.SysUserExt;
|
||||
import vip.xiaonuo.sys.modular.user.param.*;
|
||||
@@ -473,21 +473,13 @@ public interface SysUserService extends IService<SysUser> {
|
||||
|
||||
/* ====用户部分所需要用到的选择器==== */
|
||||
|
||||
/**
|
||||
* 获取组织树选择器
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/5/13 21:00
|
||||
*/
|
||||
List<Tree<String>> orgTreeSelector();
|
||||
|
||||
/**
|
||||
* 获取组织树选择器(懒加载)
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/5/13 21:00
|
||||
*/
|
||||
List<JSONObject> orgTreeLazySelector(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam);
|
||||
List<JSONObject> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam);
|
||||
|
||||
/**
|
||||
* 获取组织列表选择器
|
||||
|
||||
@@ -88,7 +88,7 @@ import vip.xiaonuo.sys.core.util.SysPasswordUtl;
|
||||
import vip.xiaonuo.sys.modular.group.entity.SysGroup;
|
||||
import vip.xiaonuo.sys.modular.group.service.SysGroupService;
|
||||
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeLazyParam;
|
||||
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorTreeParam;
|
||||
import vip.xiaonuo.sys.modular.org.service.SysOrgService;
|
||||
import vip.xiaonuo.sys.modular.position.entity.SysPosition;
|
||||
import vip.xiaonuo.sys.modular.position.service.SysPositionService;
|
||||
@@ -2001,17 +2001,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
/* ====用户部分所需要用到的选择器==== */
|
||||
|
||||
@Override
|
||||
public List<Tree<String>> orgTreeSelector() {
|
||||
List<SysOrg> sysOrgList = sysOrgService.getAllOrgList();
|
||||
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
|
||||
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode()))
|
||||
.collect(Collectors.toList());
|
||||
return TreeUtil.build(treeNodeList, "0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> orgTreeLazySelector(SysOrgSelectorTreeLazyParam sysOrgSelectorTreeLazyParam) {
|
||||
return sysOrgService.treeLazy(sysOrgSelectorTreeLazyParam);
|
||||
public List<JSONObject> orgTreeSelector(SysOrgSelectorTreeParam sysOrgSelectorTreeParam) {
|
||||
return sysOrgService.orgTreeSelector(sysOrgSelectorTreeParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user