fix: 修复组织机构 用户数据权限过滤不生效问题

pull/9/head
Carina 3 years ago
parent 7327944bff
commit d755705949

@ -18,6 +18,7 @@ package org.opsli.api.wrapper.system.org;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -51,9 +52,14 @@ public class SysOrgModel extends ApiWrapper {
@ExcelInfo
private String parentIds;
/** 组织机构ID组 xxx,xxx */
@ApiModelProperty(value = "组织机构ID组")
@JsonIgnore
private String orgIds;
/** 组织机构编号 */
@ApiModelProperty(value = "组织机构编号")
@ExcelProperty(value = "组织机构编号", order = 3)
@ExcelProperty(value = "组织机构编号", order = 4)
@ExcelInfo
@Validator({ValidatorType.IS_NOT_NULL, ValidatorType.IS_GENERAL})
@ValidatorLenMax(120)
@ -61,7 +67,7 @@ public class SysOrgModel extends ApiWrapper {
/** 组织机构名称 */
@ApiModelProperty(value = "组织机构名称")
@ExcelProperty(value = "组织机构名称", order = 4)
@ExcelProperty(value = "组织机构名称", order = 5)
@ExcelInfo
@Validator({ValidatorType.IS_NOT_NULL, ValidatorType.IS_GENERAL_WITH_CHINESE})
@ValidatorLenMax(120)
@ -69,14 +75,14 @@ public class SysOrgModel extends ApiWrapper {
/** 排序 */
@ApiModelProperty(value = "排序")
@ExcelProperty(value = "排序", order = 5)
@ExcelProperty(value = "排序", order = 6)
@ExcelInfo
@ValidatorLenMax(10)
private Integer sortNo;
/** 备注 */
@ApiModelProperty(value = "备注")
@ExcelProperty(value = "备注", order = 6)
@ExcelProperty(value = "备注", order = 7)
@ExcelInfo
@ValidatorLenMax(255)
private String remark;

@ -117,4 +117,8 @@ public class UserInfo extends ApiWrapper {
@ApiModelProperty(value = "切换后的租户管理员")
private String switchTenantUserId;
/** 数据范围*/
@ApiModelProperty(value = "数据范围")
private String dataScope;
}

@ -37,6 +37,13 @@ public enum DictType {
MENU_BUTTON("menu_type","2", "按钮"),
MENU_EXTERNAL("menu_type","3", "外链"),
/** 数据范围 */
DATA_SCOPE_SELF("role_data_scope","0", "仅本人数据"),
DATA_SCOPE_DEPT("role_data_scope","1", "本部门数据"),
DATA_SCOPE_DEPT_AND_UNDER("role_data_scope","2", "本部门及以下数据"),
DATA_SCOPE_ALL("role_data_scope","3", "全部数据"),
;
private final String type;

@ -23,6 +23,7 @@ import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.Map;
@ -43,6 +44,8 @@ public enum TreeBuildUtil {
/** 默认父节点ID */
public static final String DEF_PARENT_ID = "0";
private static final String DEF_ID = "";
/** 默认排除字段 */
private static final List<String> DEF_EXCLUDE_FIELDS;
static {
@ -51,32 +54,51 @@ public enum TreeBuildUtil {
DEF_EXCLUDE_FIELDS.add("izManual");
}
/**
* Tree
* @param dataList
* @return List<Tree<Object>>
*/
public List<Tree<Object>> build(List<?> dataList){
return this.build(dataList, DEF_PARENT_ID, null);
}
/**
* Tree
* @param dataList
* @param parentId ID
* @return List<Tree<Object>>
*/
public List<Tree<Object>> build(List<?> dataList, String parentId){
return this.build(dataList, parentId, null);
}
/**
* Tree
* @param dataList
* @param config
* @return List<Tree<Object>>
*/
public List<Tree<Object>> build(List<?> dataList, TreeNodeConfig config){
return this.build(dataList, DEF_PARENT_ID, config);
}
/**
* Tree
* @param dataList
* @param parentId ID
* @param config
* @return List<Tree<Object>>
*/
public List<Tree<Object>> build(List<?> dataList, String parentId, TreeNodeConfig config){
if(CollUtil.isEmpty(dataList)){
return ListUtil.empty();
}
boolean isMap = false;
// 处理Map集合
Object obj = dataList.get(0);
if(obj instanceof Map){
isMap = true;
}
if(!isMap){
if(!(obj instanceof Map)){
// 处理Bean 验证
boolean isBean = BeanUtil.isBean(obj.getClass());
if(!isBean){
@ -95,17 +117,90 @@ public enum TreeBuildUtil {
excludeFields.add(config.getWeightKey());
//转换器
final boolean finalIsMap = isMap;
return TreeUtil.build(dataList, defParentId, treeConfig,
(treeNode, tree) -> {
(treeNode, tree) -> handlerTreeNode(treeNode, tree, config, excludeFields));
}
/**
* Tree
* @param dataList
* @return List<Tree<Object>>
*/
public List<Tree<Object>> buildByLazy(List<?> dataList){
return this.buildByLazy(dataList, null);
}
/**
* Tree
* @param dataList
* @param config
* @return List<Tree<Object>>
*/
public List<Tree<Object>> buildByLazy(List<?> dataList, TreeNodeConfig config){
if(CollUtil.isEmpty(dataList)){
return ListUtil.empty();
}
// 处理Map集合
Object obj = dataList.get(0);
if(!(obj instanceof Map)){
// 处理Bean 验证
boolean isBean = BeanUtil.isBean(obj.getClass());
if(!isBean){
return ListUtil.empty();
}
}
// 默认值处理
final TreeNodeConfig treeConfig = ObjectUtil.defaultIfNull(config, TreeNodeConfig.DEFAULT_CONFIG);
List<String> excludeFields = ListUtil.list(false);
excludeFields.addAll(DEF_EXCLUDE_FIELDS);
excludeFields.add(config.getIdKey());
excludeFields.add(config.getParentIdKey());
excludeFields.add(config.getWeightKey());
//转换器
List<Tree<Object>> treeNodes = Lists.newArrayListWithCapacity(dataList.size());
for (Object model : dataList) {
Tree<Object> emptyNode = TreeUtil.createEmptyNode(DEF_ID);
// 处理对象数据
TreeBuildUtil.INSTANCE.handlerTreeNode(model, emptyNode, treeConfig, excludeFields);
treeNodes.add(emptyNode);
}
return treeNodes;
}
/**
*
* @param config
* @param excludeFields
* @param treeNode
* @param tree
*/
private void handlerTreeNode(Object treeNode, Tree<Object> tree,
TreeNodeConfig config, List<String> excludeFields) {
// 非空校验
if(ObjectUtil.isEmpty(treeNode)){
if(ObjectUtil.isEmpty(treeNode) || null == tree){
return;
}
// 初始化
if(null == config){
config = TreeNodeConfig.DEFAULT_CONFIG;
}
if(CollUtil.isEmpty(excludeFields)){
excludeFields = ListUtil.list(false);
excludeFields.addAll(DEF_EXCLUDE_FIELDS);
excludeFields.add(config.getIdKey());
excludeFields.add(config.getParentIdKey());
excludeFields.add(config.getWeightKey());
}
// Bean 对象转 Map
Map<String, Object> beanMap;
if(finalIsMap){
if(treeNode instanceof Map){
beanMap = Convert.toMap(String.class, Object.class, treeNode);
}else{
beanMap = BeanUtil.beanToMap(treeNode);
@ -128,7 +223,6 @@ public enum TreeBuildUtil {
}
tree.putExtra(key, value);
}
});
}
@ -139,7 +233,9 @@ public enum TreeBuildUtil {
* @return T
*/
private <T> Comparable<T> cast(T obj){
return (Comparable<T>) Convert.toInt(obj);
@SuppressWarnings("unchecked")
Comparable<T> comparable = (Comparable<T>) Convert.toInt(obj);
return comparable;
}
}

@ -90,6 +90,7 @@ public enum SystemMsg implements BaseMsg {
EXCEPTION_ORG_UNIQUE(20500,"组织机构编号重复,已存在"),
EXCEPTION_ORG_USE(20501,"组织机构已被引用,不能操作"),
EXCEPTION_ORG_USE_TENANT(20501,"组织机构已被引用,不能修改租户"),
EXCEPTION_ORG_NOT_PERMISSION(20502,"无组织机构新增权限"),
/**

@ -201,7 +201,6 @@ public class MenuRestController extends BaseRestController<SysMenu, MenuModel, I
/**
*
*
* @param label
* @param parentId ID
* @return ResultVo
*/

@ -59,6 +59,9 @@ public class SysOrg extends BaseEntity {
@TableLogic
private String deleted;
/** 组织机构 */
private String orgIds;
/** 多租户字段 */
private String tenantId;

@ -20,6 +20,8 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.system.org.SysOrgModel;
@ -28,6 +30,7 @@ import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.enums.DictType;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.FieldUtil;
import org.opsli.common.utils.ListDistinctUtil;
import org.opsli.core.base.entity.HasChildren;
import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.core.msg.CoreMsg;
@ -40,6 +43,7 @@ import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.org.entity.SysOrg;
import org.opsli.modulars.system.org.mapper.SysOrgMapper;
import org.opsli.modulars.system.org.service.ISysOrgService;
import org.opsli.modulars.system.user.service.IUserOrgRefService;
import org.opsli.modulars.system.user.service.IUserRoleRefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -69,6 +73,8 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
private SysOrgMapper mapper;
@Autowired
private IUserRoleRefService iUserRoleRefService;
@Autowired
private IUserOrgRefService iUserOrgRefService;
@Override
@Transactional(rollbackFor = Exception.class)
@ -117,13 +123,39 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
this.clearCache(Collections.singletonList(superAdmin.getId()));
}
}
// 用户ID 集合
List<String> userIdList =
// 更新 orgIds 字段
SysOrgModel insertModel = super.insert(model);
if(null != insertModel){
String orgIds = StrUtil.appendIfMissing(
insertModel.getParentIds(), DELIMITER) +
insertModel.getId();
UpdateWrapper<SysOrg> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq(
FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID), insertModel.getId());
updateWrapper.set(
FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ORG_GROUP), orgIds);
boolean updateFlag = this.update(updateWrapper);
if(!updateFlag){
// 手动触发回滚效果
throw new RuntimeException("更新OrgIds失败");
}
// 获得当前租户下 数据权限为全部数据的 用户ID 集合
List<String> userIdList = Lists.newArrayList();
List<String> userIdListByTenantId =
iUserRoleRefService.getUserIdListByTenantIdAndAllData(UserUtil.getTenantId());
// 获得当前租户下 ordIds 分组后 所有用户ID 集合
List<String> userIdListByOrgIds = iUserOrgRefService.getUserIdListByOrgIds(orgIds);
// 组合ID
userIdList.addAll(userIdListByTenantId);
userIdList.addAll(userIdListByOrgIds);
// 清除缓存
this.clearCache(userIdList);
}
return super.insert(model);
return insertModel;
}
@Transactional(rollbackFor = Exception.class)
@ -134,6 +166,7 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
}
model.setParentIds(null);
model.setOrgIds(null);
// 唯一验证
boolean verificationByCode = this.uniqueVerificationByCode(model);
@ -156,6 +189,11 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
StrUtil.appendIfMissing(
sysOrgModel.getParentIds(), DELIMITER) +
sysOrgModel.getId());
// 下级沿用上级OrgIds
model.setOrgIds(
StrUtil.appendIfMissing(
model.getParentIds(), DELIMITER) +
model.getId());
}
SysOrgModel sysOrgModel = super.get(model);
@ -181,9 +219,16 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
this.updateChildrenParentIdsByParentId(sysOrgModel.getId());
}
// 刷新当前用户缓存
UserUtil.refreshUserOrgs(UserUtil.getUser().getId());
UserUtil.refreshUserDefOrg(UserUtil.getUser().getId());
// 获得当前租户下 数据权限为全部数据的 用户ID 集合
List<String> userIdList =
iUserRoleRefService.getUserIdListByTenantIdAndAllData(UserUtil.getTenantId());
// 获得当前租户下 ordIds 分组后 所有用户ID 集合
List<String> userIdListByOrgIds = iUserOrgRefService.getUserIdListByOrgIds(updateRet.getOrgIds());
// 组合ID
userIdList.addAll(userIdListByOrgIds);
// 清除缓存
this.clearCache(userIdList);
// 修改
return updateRet;
@ -263,6 +308,12 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
sysOrgModel.getParentIds(), DELIMITER) +
sysOrgModel.getId());
// 下级沿用上级OrgIds
sysOrg.setOrgIds(
StrUtil.appendIfMissing(
sysOrg.getParentIds(), DELIMITER) +
sysOrg.getId());
super.updateById(sysOrg);
// 逐级删除子数据
this.updateChildrenParentIdsByParentId(sysOrg.getId());
@ -323,7 +374,10 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
if(CollUtil.isEmpty(parentIds)){
return null;
}
QueryWrapper<SysOrg> wrapper = new QueryWrapper<>();
// 添加 数据权限过滤器
QueryWrapper<SysOrg> wrapper = super.addHandler(SysOrg.class);
wrapper.in(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentIds)
.eq(MyBatisConstants.FIELD_DELETE_LOGIC, DictType.NO_YES_NO.getValue())
.groupBy(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID));
@ -360,8 +414,11 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
*/
private void clearCache(List<String> userIdList){
if(CollUtil.isNotEmpty(userIdList)){
// 去重
List<String> distinctUserIdList = ListDistinctUtil.distinct(userIdList);
int cacheCount = 0;
for (String userId : userIdList) {
for (String userId : distinctUserIdList) {
cacheCount += 2;
boolean tmp;
// 清空当期用户缓存 组织

@ -19,6 +19,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -32,12 +33,15 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.opsli.api.base.result.ResultVo;
import org.opsli.api.web.system.org.SysOrgRestApi;
import org.opsli.api.wrapper.system.org.SysOrgModel;
import org.opsli.api.wrapper.system.role.RoleModel;
import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.api.wrapper.system.user.UserOrgRefModel;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.annotation.EnableLog;
import org.opsli.common.annotation.RequiresPermissionsCus;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.enums.DictType;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.FieldUtil;
import org.opsli.common.utils.ListDistinctUtil;
import org.opsli.common.utils.WrapperUtil;
@ -48,6 +52,7 @@ import org.opsli.core.persistence.querybuilder.WebQueryBuilder;
import org.opsli.core.utils.OrgUtil;
import org.opsli.core.utils.TreeBuildUtil;
import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.org.entity.SysOrg;
import org.opsli.modulars.system.org.service.ISysOrgService;
import org.springframework.web.multipart.MultipartHttpServletRequest;
@ -55,6 +60,7 @@ import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -173,6 +179,30 @@ public class SysOrgRestController extends BaseRestController<SysOrg, SysOrgModel
// 获得组织
List<SysOrg> dataList = IService.findList(wrapper);
if(CollUtil.isEmpty(dataList)){
Set<String> genOrgIdSet = new HashSet<>();
List<UserOrgRefModel> orgListByUserId = UserUtil.getOrgByCurrUser();
for (UserOrgRefModel userOrgRefModel : orgListByUserId) {
List<String> orgIdList = StrUtil.split(userOrgRefModel.getOrgIds(), ',');
if(CollUtil.isEmpty(orgIdList)){
continue;
}
// 只取最后一位
genOrgIdSet.add(orgIdList.get(orgIdList.size()-1));
}
QueryWrapper<SysOrg> wrapperByEmpty = queryBuilder.build();
wrapperByEmpty.in(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID), genOrgIdSet);
// 如果传入ID 则不包含自身
if(StringUtils.isNotEmpty(id)){
wrapperByEmpty.notIn(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID), id);
}
// 获得组织
dataList = IService.findList(wrapperByEmpty);
}
orgModelList = WrapperUtil.transformInstance(dataList, modelClazz);
}
@ -185,7 +215,6 @@ public class SysOrgRestController extends BaseRestController<SysOrg, SysOrgModel
* @return ResultVo
*/
@ApiOperation(value = "获得组织树", notes = "获得组织树")
@RequiresPermissions("system_org_select")
@Override
public ResultVo<?> findTreeByDef(boolean isGen, String id) {
List<SysOrgModel> orgModelList = Lists.newArrayList();
@ -198,20 +227,53 @@ public class SysOrgRestController extends BaseRestController<SysOrg, SysOrgModel
}
QueryBuilder<SysOrg> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysOrg> wrapper = queryBuilder.build();
// // 左模糊匹配
// wrapper.likeLeft(
// FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_IDS), parentId);
// 获得最外层节点
Set<String> genOrgIdSet = new HashSet<>();
List<UserOrgRefModel> orgListByUserId = UserUtil.getOrgByCurrUser();
for (UserOrgRefModel userOrgRefModel : orgListByUserId) {
List<String> orgIdList = StrUtil.split(userOrgRefModel.getOrgIds(), ',');
if(CollUtil.isEmpty(orgIdList)){
continue;
}
// 只取最后一位
genOrgIdSet.add(orgIdList.get(orgIdList.size()-1));
}
QueryWrapper<SysOrg> wrapperByEmpty = queryBuilder.build();
wrapperByEmpty.in(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID), genOrgIdSet);
// 如果传入ID 则不包含自身
if(StringUtils.isNotEmpty(id)){
wrapperByEmpty.notIn(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID), id);
}
// 获得父节点组织
List<SysOrg> dataList = IService.findList(wrapperByEmpty);
if(CollUtil.isEmpty(dataList)){
dataList = Lists.newArrayList();
}
for (SysOrg sysOrg : dataList) {
// 设置默认父节点
sysOrg.setParentId(TreeBuildUtil.DEF_PARENT_ID);
}
QueryWrapper<SysOrg> wrapper = queryBuilder.build();
// 如果传入ID 则不包含自身
if(StringUtils.isNotEmpty(id)){
wrapper.notIn(
FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID), id);
}
// 排除父节点ID
wrapper.notIn(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID), genOrgIdSet);
// 获得子节点组织
List<SysOrg> childList = IService.findList(wrapper);
if(CollUtil.isNotEmpty(childList)){
dataList.addAll(childList);
}
// 获得组织
List<SysOrg> dataList = IService.findList(wrapper);
if(CollUtil.isNotEmpty(dataList)){
orgModelList.addAll(
WrapperUtil.transformInstance(dataList, modelClazz)
@ -261,8 +323,18 @@ public class SysOrgRestController extends BaseRestController<SysOrg, SysOrgModel
@EnableLog
@Override
public ResultVo<?> insert(SysOrgModel model) {
// 演示模式 不允许操作
//super.demoError();
// 如果新增的是 根节点数据 则需要验证权限
if(null != model && TreeBuildUtil.DEF_PARENT_ID.equals(model.getParentId())){
UserModel currUser = UserUtil.getUser();
RoleModel defRoleByUserId = UserUtil.getUserDefRoleByUserId(currUser.getId());
if(null == defRoleByUserId ||
StringUtils.isEmpty(defRoleByUserId.getDataScope()) ||
!DictType.DATA_SCOPE_ALL.getValue().equals(defRoleByUserId.getDataScope())){
// 无组织机构新增权限
throw new ServiceException(SystemMsg.EXCEPTION_ORG_NOT_PERMISSION);
}
}
// 调用新增方法
IService.insert(model);
@ -397,17 +469,23 @@ public class SysOrgRestController extends BaseRestController<SysOrg, SysOrgModel
// 自定义属性名 都要默认值的
treeNodeConfig.setWeightKey(SORT_FIELD);
// 最大递归深度 最多支持4层
treeNodeConfig.setDeep(4);
//treeNodeConfig.setDeep(4);
//转换器
List<Tree<Object>> treeNodes = TreeBuildUtil.INSTANCE.build(orgModelList, parentId, treeNodeConfig);
List<Tree<Object>> treeNodes;
// 是否懒加载
if(izLazy){
//转换器
treeNodes = TreeBuildUtil.INSTANCE.buildByLazy(orgModelList, treeNodeConfig);
// 处理是否包含子集
super.handleTreeHasChildren(treeNodes,
(parentIds)-> IService.hasChildren(parentIds));
}else{
//转换器
treeNodes = TreeBuildUtil.INSTANCE.build(orgModelList, parentId, treeNodeConfig);
Set<String> parentIdSet = Sets.newHashSet();
for (SysOrgModel sysOrgModel : orgModelList) {
parentIdSet.add(sysOrgModel.getParentId());

@ -36,6 +36,13 @@ public interface IUserOrgRefService {
*/
boolean setOrg(UserOrgRefWebModel model);
/**
* OrgIds ID
* @param orgIds ID
* @return List
*/
List<String> getUserIdListByOrgIds(String orgIds);
/**
* ID
* @param userId ID

@ -75,6 +75,31 @@ public class UserOrgRefServiceImpl extends ServiceImpl<UserOrgRefMapper, SysUser
@Autowired
private ISysOrgService iSysOrgService;
@Override
public List<String> getUserIdListByOrgIds(String orgIds){
List<String> conditionList = getParentIdsGroup(orgIds);
if(CollUtil.isEmpty(conditionList)){
return ListUtil.empty();
}
// 获得用户ID
QueryWrapper<SysUserOrgRef> queryWrapper = new QueryWrapper<>();
queryWrapper.in(
FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ORG_GROUP), conditionList);
List<SysUserOrgRef> userOrgRefs = this.list(queryWrapper);
if(CollUtil.isEmpty(userOrgRefs)){
return ListUtil.empty();
}
List<String> userIdList = Lists.newArrayListWithCapacity(userOrgRefs.size());
for (SysUserOrgRef userOrgRef : userOrgRefs) {
userIdList.add(userOrgRef.getUserId());
}
// 去重
return ListDistinctUtil.distinct(userIdList);
}
@Override
public List<UserOrgRefModel> findListByUserId(String userId) {
if(StrUtil.isEmpty(userId)){
@ -259,6 +284,26 @@ public class UserOrgRefServiceImpl extends ServiceImpl<UserOrgRefMapper, SysUser
}
}
/**
* ID ID
* @param parentIds ID
* @return List
*/
private List<String> getParentIdsGroup(String parentIds) {
if(StrUtil.isEmpty(parentIds)){
return ListUtil.empty();
}
List<String> parentIdList = StrUtil.split(parentIds, ',');
List<String> condition = Lists.newArrayListWithCapacity(parentIdList.size());
for (int i = 0; i < parentIdList.size(); i++) {
List<String> tempList = ListUtil.sub(parentIdList, 0, parentIdList.size() - i);
String parentIdsTemp = StrUtil.join(",", tempList);
condition.add(parentIdsTemp);
}
return condition;
}
}

@ -28,10 +28,8 @@ import org.opsli.api.wrapper.system.menu.MenuModel;
import org.opsli.api.wrapper.system.role.RoleModel;
import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.api.wrapper.system.user.UserRoleRefModel;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.enums.DictType;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.FieldUtil;
import org.opsli.common.utils.ListDistinctUtil;
import org.opsli.common.utils.WrapperUtil;
import org.opsli.core.msg.CoreMsg;
@ -105,7 +103,7 @@ public class UserRoleRefServiceImpl extends ServiceImpl<UserRoleRefMapper, SysUs
QueryBuilder<SysMenu> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysMenu> queryWrapper = queryBuilder.build();
queryWrapper.notIn("parent_id", -1);
queryWrapper.eq("type", '2');
queryWrapper.eq("type", DictType.MENU_BUTTON.getValue());
queryWrapper.eq("hidden", DictType.NO_YES_NO.getValue());
queryWrapper.like("label",DictType.MENU_LABEL_SYSTEM.getValue());
List<SysMenu> menuList = iMenuService.findList(queryWrapper);
@ -140,7 +138,7 @@ public class UserRoleRefServiceImpl extends ServiceImpl<UserRoleRefMapper, SysUs
QueryBuilder<SysMenu> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysMenu> queryWrapper = queryBuilder.build();
queryWrapper.notIn("parent_id", -1);
queryWrapper.in("type", '1', '3');
queryWrapper.in("type", DictType.MENU_MENU.getValue(), DictType.MENU_EXTERNAL.getValue());
queryWrapper.eq("hidden", DictType.NO_YES_NO.getValue());
queryWrapper.like("label",DictType.MENU_LABEL_SYSTEM.getValue());
menuList = iMenuService.findList(queryWrapper);
@ -231,8 +229,8 @@ public class UserRoleRefServiceImpl extends ServiceImpl<UserRoleRefMapper, SysUs
public List<String> getUserIdListByTenantIdAndAllData(String tenantId) {
QueryWrapper<SysUserRoleRef> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("b.deleted", DictType.NO_YES_NO.getValue());
queryWrapper.eq("c.tenant_id", tenantId);
queryWrapper.eq("c.data_scope", "3");
queryWrapper.eq("b.tenant_id", tenantId);
queryWrapper.eq("c.data_scope", DictType.DATA_SCOPE_ALL.getValue());
List<String> users = mapper.getUserIdList(queryWrapper);
if(CollUtil.isEmpty(users)){

@ -30,6 +30,7 @@ import org.opsli.api.base.result.ResultVo;
import org.opsli.api.web.system.user.UserApi;
import org.opsli.api.wrapper.system.menu.MenuModel;
import org.opsli.api.wrapper.system.options.OptionsModel;
import org.opsli.api.wrapper.system.role.RoleModel;
import org.opsli.api.wrapper.system.tenant.TenantModel;
import org.opsli.api.wrapper.system.user.*;
import org.opsli.common.annotation.ApiRestController;
@ -120,6 +121,7 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
userIdTemp = switchUser.getId();
}
List<String> userRolesByUserId = UserUtil.getUserRolesByUserId(userIdTemp);
List<String> userAllPermsByUserId = UserUtil.getUserAllPermsByUserId(userIdTemp);
@ -127,6 +129,12 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
userInfo.setRoles(userRolesByUserId);
userInfo.setPerms(userAllPermsByUserId);
// 数据范围
RoleModel defRole = UserUtil.getUserDefRoleByUserId(userIdTemp);
if(null != defRole){
userInfo.setDataScope(defRole.getDataScope());
}
// 判断是否是超级管理员
if(StringUtils.equals(UserUtil.SUPER_ADMIN, currUser.getUsername())){
userInfo.setIzSuperAdmin(true);
@ -398,8 +406,8 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
@Override
public ResultVo<?> insert(UserModel model) {
// 调用新增方法
IService.insert(model);
return ResultVo.success("新增用户信息成功");
UserModel userModel = IService.insert(model);
return ResultVo.success("新增用户信息成功", userModel);
}
/**

Loading…
Cancel
Save