【更新】完善用户、机构选择器,启用缓存机制优化

This commit is contained in:
徐玉祥 2023-03-05 03:48:41 +08:00
parent 1cf1e1765e
commit fcc65450fc
9 changed files with 199 additions and 53 deletions

View File

@ -15,9 +15,13 @@ package vip.xiaonuo.sys.core.listener;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import vip.xiaonuo.common.cache.CommonCacheOperator;
import vip.xiaonuo.common.listener.CommonDataChangeListener; import vip.xiaonuo.common.listener.CommonDataChangeListener;
import vip.xiaonuo.sys.core.enums.SysDataTypeEnum; import vip.xiaonuo.sys.core.enums.SysDataTypeEnum;
import vip.xiaonuo.sys.modular.org.service.impl.SysOrgServiceImpl;
import vip.xiaonuo.sys.modular.user.service.impl.SysUserServiceImpl;
import javax.annotation.Resource;
import java.util.List; import java.util.List;
/** /**
@ -29,9 +33,19 @@ import java.util.List;
@Component @Component
public class SysDataChangeListener implements CommonDataChangeListener { public class SysDataChangeListener implements CommonDataChangeListener {
@Resource
private CommonCacheOperator commonCacheOperator;
@Override @Override
public void doAddWithDataIdList(String dataType, List<String> dataIdList) { public void doAddWithDataIdList(String dataType, List<String> dataIdList) {
// 此处可做额外处理 // 如果检测到机构增加则将机构的数据缓存清除
if(dataType.equals(SysDataTypeEnum.ORG.getValue())) {
commonCacheOperator.remove(SysOrgServiceImpl.ORG_CACHE_ALL_KEY);
}
// 如果检测到用户增加则将用户数据缓存清除
if(dataType.equals(SysDataTypeEnum.USER.getValue())) {
commonCacheOperator.remove(SysUserServiceImpl.USER_CACHE_ALL_KEY);
}
} }
@Override @Override
@ -41,7 +55,14 @@ public class SysDataChangeListener implements CommonDataChangeListener {
@Override @Override
public void doUpdateWithDataIdList(String dataType, List<String> dataIdList) { public void doUpdateWithDataIdList(String dataType, List<String> dataIdList) {
// 此处可做额外处理 // 如果检测到机构更新则将机构的数据缓存清除
if(dataType.equals(SysDataTypeEnum.ORG.getValue())) {
commonCacheOperator.remove(SysOrgServiceImpl.ORG_CACHE_ALL_KEY);
}
// 如果检测到用户更新则将用户数据缓存清除
if(dataType.equals(SysDataTypeEnum.USER.getValue())) {
commonCacheOperator.remove(SysUserServiceImpl.USER_CACHE_ALL_KEY);
}
} }
@Override @Override
@ -51,8 +72,13 @@ public class SysDataChangeListener implements CommonDataChangeListener {
@Override @Override
public void doDeleteWithDataIdList(String dataType, List<String> dataIdList) { public void doDeleteWithDataIdList(String dataType, List<String> dataIdList) {
// 如果检测到机构增加则将机构的数据缓存清除
if(dataType.equals(SysDataTypeEnum.ORG.getValue())) {
commonCacheOperator.remove(SysOrgServiceImpl.ORG_CACHE_ALL_KEY);
}
// 如果检测到用户删除则将用户数据缓存清除并将这些用户踢下线
if(dataType.equals(SysDataTypeEnum.USER.getValue())) { if(dataType.equals(SysDataTypeEnum.USER.getValue())) {
// 当用户被删除时此处将这些用户踢下线 commonCacheOperator.remove(SysUserServiceImpl.USER_CACHE_ALL_KEY);
dataIdList.forEach(StpUtil::kickout); dataIdList.forEach(StpUtil::kickout);
} }
} }

View File

@ -85,6 +85,22 @@ public interface SysOrgService extends IService<SysOrg> {
**/ **/
SysOrg queryEntity(String id); SysOrg queryEntity(String id);
/**
* 获取缓存的所有组织
*
* @author xuyuxiang
* @date 2022/7/25 19:42
**/
List<SysOrg> getCachedAllOrgList();
/**
* 根据id获取父子数据列表
*
* @author xuyuxiang
* @date 2022/8/15 14:55
**/
List<SysOrg> getParentAndChildListById(List<SysOrg> originDataList, String id, boolean includeSelf);
/** /**
* 根据id获取所有的子数据列表 * 根据id获取所有的子数据列表
* *
@ -93,6 +109,14 @@ public interface SysOrgService extends IService<SysOrg> {
**/ **/
List<SysOrg> getChildListById(List<SysOrg> originDataList, String id, boolean includeSelf); List<SysOrg> getChildListById(List<SysOrg> originDataList, String id, boolean includeSelf);
/**
* 根据id获取所有的父数据列表
*
* @author xuyuxiang
* @date 2022/8/15 14:55
**/
List<SysOrg> getParentListById(List<SysOrg> originDataList, String id, boolean includeSelf);
/** /**
* 根据id获取数据 * 根据id获取数据
* *
@ -101,6 +125,22 @@ public interface SysOrgService extends IService<SysOrg> {
**/ **/
SysOrg getById(List<SysOrg> originDataList, String id) ; SysOrg getById(List<SysOrg> originDataList, String id) ;
/**
* 根据id获取父数据
*
* @author xuyuxiang
* @date 2022/8/15 14:55
**/
SysOrg getParentById(List<SysOrg> originDataList, String id) ;
/**
* 根据id获取子数据
*
* @author xuyuxiang
* @date 2022/8/15 14:55
**/
SysOrg getChildById(List<SysOrg> originDataList, String id) ;
/** /**
* 获取组织树选择器 * 获取组织树选择器
* *

View File

@ -29,6 +29,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import vip.xiaonuo.common.cache.CommonCacheOperator;
import vip.xiaonuo.common.enums.CommonSortOrderEnum; import vip.xiaonuo.common.enums.CommonSortOrderEnum;
import vip.xiaonuo.common.exception.CommonException; import vip.xiaonuo.common.exception.CommonException;
import vip.xiaonuo.common.listener.CommonDataChangeEventCenter; import vip.xiaonuo.common.listener.CommonDataChangeEventCenter;
@ -59,6 +60,11 @@ import java.util.stream.Collectors;
@Service @Service
public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> implements SysOrgService { public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> implements SysOrgService {
public static final String ORG_CACHE_ALL_KEY = "sys-org:all";
@Resource
private CommonCacheOperator commonCacheOperator;
@Resource @Resource
private SysRoleService sysRoleService; private SysRoleService sysRoleService;
@ -92,9 +98,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
@Override @Override
public List<Tree<String>> tree() { public List<Tree<String>> tree() {
LambdaQueryWrapper<SysOrg> lambdaQueryWrapper = new LambdaQueryWrapper<>(); List<SysOrg> sysOrgList = this.getCachedAllOrgList();
lambdaQueryWrapper.orderByAsc(SysOrg::getSortCode);
List<SysOrg> sysOrgList = this.list(lambdaQueryWrapper);
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg -> List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(),
sysOrg.getName(), sysOrg.getSortCode()).setExtra(JSONUtil.parseObj(sysOrg))) sysOrg.getName(), sysOrg.getSortCode()).setExtra(JSONUtil.parseObj(sysOrg)))
@ -131,7 +135,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
if(repeatName) { if(repeatName) {
throw new CommonException("存在重复的同级组织,名称为:{}", sysOrg.getName()); throw new CommonException("存在重复的同级组织,名称为:{}", sysOrg.getName());
} }
List<SysOrg> originDataList = this.list(); List<SysOrg> originDataList = this.getCachedAllOrgList();
boolean errorLevel = this.getChildListById(originDataList, sysOrg.getId(), true).stream() boolean errorLevel = this.getChildListById(originDataList, sysOrg.getId(), true).stream()
.map(SysOrg::getId).collect(Collectors.toList()).contains(sysOrg.getParentId()); .map(SysOrg::getId).collect(Collectors.toList()).contains(sysOrg.getParentId());
if(errorLevel) { if(errorLevel) {
@ -148,7 +152,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
public void delete(List<SysOrgIdParam> sysOrgIdParamList) { public void delete(List<SysOrgIdParam> sysOrgIdParamList) {
List<String> orgIdList = CollStreamUtil.toList(sysOrgIdParamList, SysOrgIdParam::getId); List<String> orgIdList = CollStreamUtil.toList(sysOrgIdParamList, SysOrgIdParam::getId);
if(ObjectUtil.isNotEmpty(orgIdList)) { if(ObjectUtil.isNotEmpty(orgIdList)) {
List<SysOrg> allOrgList = this.list(); List<SysOrg> allOrgList = this.getCachedAllOrgList();
// 获取所有子组织 // 获取所有子组织
List<String> toDeleteOrgIdList = CollectionUtil.newArrayList(); List<String> toDeleteOrgIdList = CollectionUtil.newArrayList();
orgIdList.forEach(orgId -> toDeleteOrgIdList.addAll(this.getChildListById(allOrgList, orgId, true).stream() orgIdList.forEach(orgId -> toDeleteOrgIdList.addAll(this.getChildListById(allOrgList, orgId, true).stream()
@ -203,13 +207,26 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
return sysOrg; return sysOrg;
} }
@Override
public List<SysOrg> getCachedAllOrgList() {
// 从缓存中取
Object cacheValue = commonCacheOperator.get(ORG_CACHE_ALL_KEY);
if(ObjectUtil.isNotEmpty(cacheValue)) {
return JSONUtil.toList(JSONUtil.parseArray(cacheValue), SysOrg.class);
}
List<SysOrg> orgList = this.list(new LambdaQueryWrapper<SysOrg>().orderByAsc(SysOrg::getSortCode));
if(ObjectUtil.isNotEmpty(orgList)) {
// 更新到缓存
commonCacheOperator.put(ORG_CACHE_ALL_KEY, orgList);
}
return orgList;
}
/* ====组织部分所需要用到的选择器==== */ /* ====组织部分所需要用到的选择器==== */
@Override @Override
public List<Tree<String>> orgTreeSelector() { public List<Tree<String>> orgTreeSelector() {
LambdaQueryWrapper<SysOrg> lambdaQueryWrapper = new LambdaQueryWrapper<>(); List<SysOrg> sysOrgList = this.getCachedAllOrgList();
lambdaQueryWrapper.orderByAsc(SysOrg::getSortCode);
List<SysOrg> sysOrgList = this.list(lambdaQueryWrapper);
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg -> List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode())) new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode()))
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -236,9 +253,20 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
public List<SysUser> userSelector(SysOrgSelectorUserParam sysOrgSelectorUserParam) { public List<SysUser> userSelector(SysOrgSelectorUserParam sysOrgSelectorUserParam) {
LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
// 只查询部分字段 // 只查询部分字段
lambdaQueryWrapper.select(SysUser::getId, SysUser::getOrgId, SysUser::getAccount, SysUser::getName); lambdaQueryWrapper.select(SysUser::getId, SysUser::getOrgId, SysUser::getAccount, SysUser::getName, SysUser::getSortCode);
// 如果查询条件为空则从缓存中查询
if(ObjectUtil.isAllEmpty(sysOrgSelectorUserParam.getOrgId(), sysOrgSelectorUserParam.getSearchKey())) {
return sysUserService.getCachedAllUserList();
} else {
if(ObjectUtil.isNotEmpty(sysOrgSelectorUserParam.getOrgId())) { if(ObjectUtil.isNotEmpty(sysOrgSelectorUserParam.getOrgId())) {
lambdaQueryWrapper.eq(SysUser::getOrgId, sysOrgSelectorUserParam.getOrgId()); // 如果机构id不为空则查询该机构所在顶级机构下的所有人
List<String> parentAndChildOrgIdList = CollStreamUtil.toList(this.getParentAndChildListById(this
.getCachedAllOrgList(), sysOrgSelectorUserParam.getOrgId(), true), SysOrg::getId);
if (ObjectUtil.isNotEmpty(parentAndChildOrgIdList)) {
lambdaQueryWrapper.in(SysUser::getOrgId, parentAndChildOrgIdList);
} else {
return CollectionUtil.newArrayList();
}
} }
if(ObjectUtil.isNotEmpty(sysOrgSelectorUserParam.getSearchKey())) { if(ObjectUtil.isNotEmpty(sysOrgSelectorUserParam.getSearchKey())) {
lambdaQueryWrapper.like(SysUser::getName, sysOrgSelectorUserParam.getSearchKey()); lambdaQueryWrapper.like(SysUser::getName, sysOrgSelectorUserParam.getSearchKey());
@ -246,9 +274,18 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
lambdaQueryWrapper.orderByAsc(SysUser::getSortCode); lambdaQueryWrapper.orderByAsc(SysUser::getSortCode);
return sysUserService.list(lambdaQueryWrapper); return sysUserService.list(lambdaQueryWrapper);
} }
}
/* ====以下为各种递归方法==== */ /* ====以下为各种递归方法==== */
@Override
public List<SysOrg> getParentAndChildListById(List<SysOrg> originDataList, String id, boolean includeSelf) {
List<SysOrg> parentListById = this.getParentListById(originDataList, id, false);
List<SysOrg> childListById = this.getChildListById(originDataList, id, true);
parentListById.addAll(childListById);
return parentListById;
}
@Override @Override
public List<SysOrg> getChildListById(List<SysOrg> originDataList, String id, boolean includeSelf) { public List<SysOrg> getChildListById(List<SysOrg> originDataList, String id, boolean includeSelf) {
List<SysOrg> resultList = CollectionUtil.newArrayList(); List<SysOrg> resultList = CollectionUtil.newArrayList();
@ -262,6 +299,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
return resultList; return resultList;
} }
@Override
public List<SysOrg> getParentListById(List<SysOrg> originDataList, String id, boolean includeSelf) { public List<SysOrg> getParentListById(List<SysOrg> originDataList, String id, boolean includeSelf) {
List<SysOrg> resultList = CollectionUtil.newArrayList(); List<SysOrg> resultList = CollectionUtil.newArrayList();
execRecursionFindParent(originDataList, id, resultList); execRecursionFindParent(originDataList, id, resultList);
@ -301,11 +339,13 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
return index == -1?null:originDataList.get(index); return index == -1?null:originDataList.get(index);
} }
@Override
public SysOrg getParentById(List<SysOrg> originDataList, String id) { public SysOrg getParentById(List<SysOrg> originDataList, String id) {
SysOrg self = this.getById(originDataList, id); SysOrg self = this.getById(originDataList, id);
return ObjectUtil.isNotEmpty(self)?self:this.getById(originDataList, self.getParentId()); return ObjectUtil.isNotEmpty(self)?self:this.getById(originDataList, self.getParentId());
} }
@Override
public SysOrg getChildById(List<SysOrg> originDataList, String id) { public SysOrg getChildById(List<SysOrg> originDataList, String id) {
int index = CollStreamUtil.toList(originDataList, SysOrg::getParentId).indexOf(id); int index = CollStreamUtil.toList(originDataList, SysOrg::getParentId).indexOf(id);
return index == -1?null:originDataList.get(index); return index == -1?null:originDataList.get(index);

View File

@ -176,9 +176,7 @@ public class SysPositionServiceImpl extends ServiceImpl<SysPositionMapper, SysPo
@Override @Override
public List<Tree<String>> orgTreeSelector() { public List<Tree<String>> orgTreeSelector() {
LambdaQueryWrapper<SysOrg> lambdaQueryWrapper = new LambdaQueryWrapper<>(); List<SysOrg> sysOrgList = sysOrgService.getCachedAllOrgList();
lambdaQueryWrapper.orderByAsc(SysOrg::getSortCode);
List<SysOrg> sysOrgList = sysOrgService.list(lambdaQueryWrapper);
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg -> List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode())) new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode()))
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@ -302,9 +302,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
@Override @Override
public List<Tree<String>> orgTreeSelector() { public List<Tree<String>> orgTreeSelector() {
LambdaQueryWrapper<SysOrg> lambdaQueryWrapper = new LambdaQueryWrapper<>(); List<SysOrg> sysOrgList = sysOrgService.getCachedAllOrgList();
lambdaQueryWrapper.orderByAsc(SysOrg::getSortCode);
List<SysOrg> sysOrgList = sysOrgService.list(lambdaQueryWrapper);
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg -> List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode())) new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode()))
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -435,16 +433,28 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
public List<SysUser> userSelector(SysRoleSelectorUserParam sysRoleSelectorUserParam) { public List<SysUser> userSelector(SysRoleSelectorUserParam sysRoleSelectorUserParam) {
LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
// 只查询部分字段 // 只查询部分字段
lambdaQueryWrapper.select(SysUser::getId, SysUser::getOrgId, SysUser::getAccount, SysUser::getName); lambdaQueryWrapper.select(SysUser::getId, SysUser::getOrgId, SysUser::getAccount, SysUser::getName, SysUser::getSortCode);
if(ObjectUtil.isNotEmpty(sysRoleSelectorUserParam.getOrgId())) { // 如果查询条件为空则从缓存中查询
lambdaQueryWrapper.eq(SysUser::getOrgId, sysRoleSelectorUserParam.getOrgId()); if(ObjectUtil.isAllEmpty(sysRoleSelectorUserParam.getOrgId(), sysRoleSelectorUserParam.getSearchKey())) {
return sysUserService.getCachedAllUserList();
} else {
if (ObjectUtil.isNotEmpty(sysRoleSelectorUserParam.getOrgId())) {
// 如果机构id不为空则查询该机构所在顶级机构下的所有人
List<String> parentAndChildOrgIdList = CollStreamUtil.toList(sysOrgService.getParentAndChildListById(sysOrgService
.getCachedAllOrgList(), sysRoleSelectorUserParam.getOrgId(), true), SysOrg::getId);
if (ObjectUtil.isNotEmpty(parentAndChildOrgIdList)) {
lambdaQueryWrapper.in(SysUser::getOrgId, parentAndChildOrgIdList);
} else {
return CollectionUtil.newArrayList();
} }
if(ObjectUtil.isNotEmpty(sysRoleSelectorUserParam.getSearchKey())) { }
if (ObjectUtil.isNotEmpty(sysRoleSelectorUserParam.getSearchKey())) {
lambdaQueryWrapper.like(SysUser::getName, sysRoleSelectorUserParam.getSearchKey()); lambdaQueryWrapper.like(SysUser::getName, sysRoleSelectorUserParam.getSearchKey());
} }
lambdaQueryWrapper.orderByAsc(SysUser::getSortCode); lambdaQueryWrapper.orderByAsc(SysUser::getSortCode);
return sysUserService.list(lambdaQueryWrapper); return sysUserService.list(lambdaQueryWrapper);
} }
}
/* ====以下为各种递归方法==== */ /* ====以下为各种递归方法==== */

View File

@ -37,7 +37,7 @@ import java.util.Date;
**/ **/
@Getter @Getter
@Setter @Setter
@TableName(value = "SYS_USER", autoResultMap = true) @TableName(value = "SYS_USER")
public class SysUser extends CommonEntity implements TransPojo { public class SysUser extends CommonEntity implements TransPojo {
/** id */ /** id */

View File

@ -14,9 +14,6 @@ package vip.xiaonuo.sys.modular.user.result;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat; import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

View File

@ -364,6 +364,14 @@ public interface SysUserService extends IService<SysUser> {
**/ **/
List<SysUserPositionResult> loginPositionInfo(SysUserIdParam sysUserIdParam); List<SysUserPositionResult> loginPositionInfo(SysUserIdParam sysUserIdParam);
/**
* 获取缓存的所有用户
*
* @author xuyuxiang
* @date 2022/7/25 19:42
**/
List<SysUser> getCachedAllUserList();
/* ====用户部分所需要用到的选择器==== */ /* ====用户部分所需要用到的选择器==== */
/** /**

View File

@ -109,6 +109,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
private static final String USER_CACHE_KEY = "user-validCode:"; private static final String USER_CACHE_KEY = "user-validCode:";
public static final String USER_CACHE_ALL_KEY = "sys-user:all";
@Resource @Resource
private CommonCacheOperator commonCacheOperator; private CommonCacheOperator commonCacheOperator;
@ -556,7 +558,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
// 获取菜单id列表 // 获取菜单id列表
List<String> menuIdList = sysRelationService.getRelationTargetIdListByObjectIdAndCategory(sysUserIdParam.getId(), List<String> menuIdList = sysRelationService.getRelationTargetIdListByObjectIdAndCategory(sysUserIdParam.getId(),
SysRelationCategoryEnum.SYS_USER_HAS_RESOURCE.getValue());; SysRelationCategoryEnum.SYS_USER_HAS_RESOURCE.getValue());
if (ObjectUtil.isNotEmpty(roleIdList)) { if (ObjectUtil.isNotEmpty(roleIdList)) {
menuIdList = sysRelationService.getRelationTargetIdListByObjectIdListAndCategory(roleIdList, menuIdList = sysRelationService.getRelationTargetIdListByObjectIdListAndCategory(roleIdList,
@ -789,9 +791,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override @Override
public List<Tree<String>> loginOrgTree(SysUserIdParam sysUserIdParam) { public List<Tree<String>> loginOrgTree(SysUserIdParam sysUserIdParam) {
LambdaQueryWrapper<SysOrg> lambdaQueryWrapper = new LambdaQueryWrapper<>(); List<SysOrg> sysOrgList = sysOrgService.getCachedAllOrgList();
lambdaQueryWrapper.orderByAsc(SysOrg::getSortCode);
List<SysOrg> sysOrgList = sysOrgService.list(lambdaQueryWrapper);
SysUser sysUser = this.queryEntity(sysUserIdParam.getId()); SysUser sysUser = this.queryEntity(sysUserIdParam.getId());
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg -> { List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg -> {
TreeNode<String> treeNode = new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode()); TreeNode<String> treeNode = new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode());
@ -963,7 +963,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
public List<JSONObject> getScopeListByMap(Map<String, List<SysRelation>> groupMap, String orgId) { public List<JSONObject> getScopeListByMap(Map<String, List<SysRelation>> groupMap, String orgId) {
List<JSONObject> resultList = CollectionUtil.newArrayList(); List<JSONObject> resultList = CollectionUtil.newArrayList();
List<SysOrg> sysOrgList = sysOrgService.list(); List<SysOrg> sysOrgList = sysOrgService.getCachedAllOrgList();
List<String> scopeAllList = sysOrgList.stream().map(SysOrg::getId).collect(Collectors.toList()); List<String> scopeAllList = sysOrgList.stream().map(SysOrg::getId).collect(Collectors.toList());
List<String> scopeOrgList = CollectionUtil.newArrayList(orgId); List<String> scopeOrgList = CollectionUtil.newArrayList(orgId);
List<String> scopeOrgChildList = sysOrgService.getChildListById(sysOrgList, orgId, true) List<String> scopeOrgChildList = sysOrgService.getChildListById(sysOrgList, orgId, true)
@ -1054,7 +1054,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
public List<SysUserPositionResult> loginPositionInfo(SysUserIdParam sysUserIdParam) { public List<SysUserPositionResult> loginPositionInfo(SysUserIdParam sysUserIdParam) {
SysUser sysUser = this.queryEntity(sysUserIdParam.getId()); SysUser sysUser = this.queryEntity(sysUserIdParam.getId());
List<SysUserPositionResult> sysUserPositionResultList = CollectionUtil.newArrayList(); List<SysUserPositionResult> sysUserPositionResultList = CollectionUtil.newArrayList();
List<SysOrg> sysOrgList = sysOrgService.list(); List<SysOrg> sysOrgList = sysOrgService.getCachedAllOrgList();
String primaryOrgId = sysUser.getOrgId(); String primaryOrgId = sysUser.getOrgId();
SysOrg primarySysOrg = sysOrgService.getById(sysOrgList, primaryOrgId); SysOrg primarySysOrg = sysOrgService.getById(sysOrgList, primaryOrgId);
if (ObjectUtil.isEmpty(primarySysOrg)) { if (ObjectUtil.isEmpty(primarySysOrg)) {
@ -1112,13 +1112,28 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return sysUserPositionResultList; return sysUserPositionResultList;
} }
@Override
public List<SysUser> getCachedAllUserList() {
// 从缓存中取
Object cacheValue = commonCacheOperator.get(USER_CACHE_ALL_KEY);
if(ObjectUtil.isNotEmpty(cacheValue)) {
return JSONUtil.toList(JSONUtil.parseArray(cacheValue), SysUser.class);
}
// 只查询部分字段
List<SysUser> userList = this.list(new LambdaQueryWrapper<SysUser>().select(SysUser::getId, SysUser::getOrgId,
SysUser::getAccount, SysUser::getName, SysUser::getSortCode).orderByAsc(SysUser::getSortCode));
if(ObjectUtil.isNotEmpty(userList)) {
// 更新到缓存
commonCacheOperator.put(USER_CACHE_ALL_KEY, userList);
}
return userList;
}
/* ====用户部分所需要用到的选择器==== */ /* ====用户部分所需要用到的选择器==== */
@Override @Override
public List<Tree<String>> orgTreeSelector() { public List<Tree<String>> orgTreeSelector() {
LambdaQueryWrapper<SysOrg> lambdaQueryWrapper = new LambdaQueryWrapper<>(); List<SysOrg> sysOrgList = sysOrgService.getCachedAllOrgList();
lambdaQueryWrapper.orderByAsc(SysOrg::getSortCode);
List<SysOrg> sysOrgList = sysOrgService.list(lambdaQueryWrapper);
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg -> List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode())) new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(), sysOrg.getName(), sysOrg.getSortCode()))
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -1180,8 +1195,19 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
// 只查询部分字段 // 只查询部分字段
lambdaQueryWrapper.select(SysUser::getId, SysUser::getOrgId, SysUser::getAccount, SysUser::getName, SysUser::getSortCode); lambdaQueryWrapper.select(SysUser::getId, SysUser::getOrgId, SysUser::getAccount, SysUser::getName, SysUser::getSortCode);
// 如果查询条件为空则从缓存中查询
if(ObjectUtil.isAllEmpty(sysUserSelectorUserParam.getOrgId(), sysUserSelectorUserParam.getSearchKey())) {
return this.getCachedAllUserList();
} else {
if (ObjectUtil.isNotEmpty(sysUserSelectorUserParam.getOrgId())) { if (ObjectUtil.isNotEmpty(sysUserSelectorUserParam.getOrgId())) {
lambdaQueryWrapper.eq(SysUser::getOrgId, sysUserSelectorUserParam.getOrgId()); // 如果机构id不为空则查询该机构所在顶级机构下的所有人
List<String> parentAndChildOrgIdList = CollStreamUtil.toList(sysOrgService.getParentAndChildListById(sysOrgService
.getCachedAllOrgList(), sysUserSelectorUserParam.getOrgId(), true), SysOrg::getId);
if (ObjectUtil.isNotEmpty(parentAndChildOrgIdList)) {
lambdaQueryWrapper.in(SysUser::getOrgId, parentAndChildOrgIdList);
} else {
return CollectionUtil.newArrayList();
}
} }
if (ObjectUtil.isNotEmpty(sysUserSelectorUserParam.getSearchKey())) { if (ObjectUtil.isNotEmpty(sysUserSelectorUserParam.getSearchKey())) {
lambdaQueryWrapper.like(SysUser::getName, sysUserSelectorUserParam.getSearchKey()); lambdaQueryWrapper.like(SysUser::getName, sysUserSelectorUserParam.getSearchKey());
@ -1189,6 +1215,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
lambdaQueryWrapper.orderByAsc(SysUser::getSortCode); lambdaQueryWrapper.orderByAsc(SysUser::getSortCode);
return this.list(lambdaQueryWrapper); return this.list(lambdaQueryWrapper);
} }
}
@Override @Override
public Page<SysUserMessageResult> loginMessagePage(SysUserMessagePageParam sysUserMessagePageParam) { public Page<SysUserMessageResult> loginMessagePage(SysUserMessagePageParam sysUserMessagePageParam) {