From d755705949b391eea9711795a1ab56797b3767f4 Mon Sep 17 00:00:00 2001 From: Carina Date: Wed, 1 Dec 2021 19:08:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E6=9C=BA=E6=9E=84=20=E7=94=A8=E6=88=B7=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90=E8=BF=87=E6=BB=A4=E4=B8=8D=E7=94=9F=E6=95=88?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/wrapper/system/org/SysOrgModel.java | 14 +- .../api/wrapper/system/user/UserInfo.java | 4 + .../java/org/opsli/common/enums/DictType.java | 7 + .../org/opsli/core/utils/TreeBuildUtil.java | 176 ++++++++++++++---- .../org/opsli/modulars/system/SystemMsg.java | 1 + .../system/menu/web/MenuRestController.java | 1 - .../modulars/system/org/entity/SysOrg.java | 3 + .../org/service/impl/SysOrgServiceImpl.java | 79 ++++++-- .../system/org/web/SysOrgRestController.java | 100 ++++++++-- .../user/service/IUserOrgRefService.java | 7 + .../service/impl/UserOrgRefServiceImpl.java | 45 +++++ .../service/impl/UserRoleRefServiceImpl.java | 10 +- .../system/user/web/UserRestController.java | 12 +- 13 files changed, 384 insertions(+), 75 deletions(-) diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/org/SysOrgModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/org/SysOrgModel.java index 00d29bb..4283670 100644 --- a/opsli-api/src/main/java/org/opsli/api/wrapper/system/org/SysOrgModel.java +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/org/SysOrgModel.java @@ -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; diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserInfo.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserInfo.java index ee730e4..eef19d3 100644 --- a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserInfo.java +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserInfo.java @@ -117,4 +117,8 @@ public class UserInfo extends ApiWrapper { @ApiModelProperty(value = "切换后的租户管理员") private String switchTenantUserId; + /** 数据范围*/ + @ApiModelProperty(value = "数据范围") + private String dataScope; + } diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/DictType.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/DictType.java index 217ac27..7b964f5 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/DictType.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/DictType.java @@ -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; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/TreeBuildUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/TreeBuildUtil.java index c8a221d..3975c18 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/TreeBuildUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/TreeBuildUtil.java @@ -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 DEF_EXCLUDE_FIELDS; static { @@ -51,32 +54,51 @@ public enum TreeBuildUtil { DEF_EXCLUDE_FIELDS.add("izManual"); } + /** + * 构建Tree + * @param dataList 数据集合 + * @return List> + */ public List> build(List dataList){ return this.build(dataList, DEF_PARENT_ID, null); } + /** + * 构建Tree + * @param dataList 数据集合 + * @param parentId 父节点ID + * @return List> + */ public List> build(List dataList, String parentId){ return this.build(dataList, parentId, null); } + /** + * 构建Tree + * @param dataList 数据集合 + * @param config 配置 + * @return List> + */ public List> build(List dataList, TreeNodeConfig config){ return this.build(dataList, DEF_PARENT_ID, config); } + /** + * 构建Tree + * @param dataList 数据集合 + * @param parentId 父节点ID + * @param config 配置 + * @return List> + */ public List> 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,40 +117,112 @@ public enum TreeBuildUtil { excludeFields.add(config.getWeightKey()); //转换器 - final boolean finalIsMap = isMap; return TreeUtil.build(dataList, defParentId, treeConfig, - (treeNode, tree) -> { - // 非空校验 - if(ObjectUtil.isEmpty(treeNode)){ - return; - } - - // Bean 对象转 Map - Map beanMap; - if(finalIsMap){ - beanMap = Convert.toMap(String.class, Object.class, treeNode); - }else{ - beanMap = BeanUtil.beanToMap(treeNode); - } - - // 主要属性 - tree.setId(beanMap.get(config.getIdKey())); - tree.setParentId(beanMap.get(config.getParentIdKey())); - tree.setWeight( - cast( - beanMap.get(config.getWeightKey()))); - - // 扩展属性 ... - for (Map.Entry entry : beanMap.entrySet()) { - String key = entry.getKey(); - Object value = entry.getValue(); - // 排除字段 - if(excludeFields.contains(key)){ - continue; - } - tree.putExtra(key, value); - } - }); + (treeNode, tree) -> handlerTreeNode(treeNode, tree, config, excludeFields)); + } + + /** + * 构建Tree + * @param dataList 数据集合 + * @return List> + */ + public List> buildByLazy(List dataList){ + return this.buildByLazy(dataList, null); + } + + /** + * 构建Tree + * @param dataList 数据集合 + * @param config 配置 + * @return List> + */ + public List> 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 excludeFields = ListUtil.list(false); + excludeFields.addAll(DEF_EXCLUDE_FIELDS); + excludeFields.add(config.getIdKey()); + excludeFields.add(config.getParentIdKey()); + excludeFields.add(config.getWeightKey()); + + //转换器 + List> treeNodes = Lists.newArrayListWithCapacity(dataList.size()); + for (Object model : dataList) { + Tree 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 tree, + TreeNodeConfig config, List excludeFields) { + // 非空校验 + 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 beanMap; + if(treeNode instanceof Map){ + beanMap = Convert.toMap(String.class, Object.class, treeNode); + }else{ + beanMap = BeanUtil.beanToMap(treeNode); + } + + // 主要属性 + tree.setId(beanMap.get(config.getIdKey())); + tree.setParentId(beanMap.get(config.getParentIdKey())); + tree.setWeight( + cast( + beanMap.get(config.getWeightKey()))); + + // 扩展属性 ... + for (Map.Entry entry : beanMap.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + // 排除字段 + if(excludeFields.contains(key)){ + continue; + } + tree.putExtra(key, value); + } } @@ -139,7 +233,9 @@ public enum TreeBuildUtil { * @return T */ private Comparable cast(T obj){ - return (Comparable) Convert.toInt(obj); + @SuppressWarnings("unchecked") + Comparable comparable = (Comparable) Convert.toInt(obj); + return comparable; } } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java index 5ffbc95..fe6ae5b 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java @@ -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,"无组织机构新增权限"), /** diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/web/MenuRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/web/MenuRestController.java index 72d47ed..d02b611 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/web/MenuRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/web/MenuRestController.java @@ -201,7 +201,6 @@ public class MenuRestController extends BaseRestController userIdList = - iUserRoleRefService.getUserIdListByTenantIdAndAllData(UserUtil.getTenantId()); - // 清除缓存 - this.clearCache(userIdList); - return super.insert(model); + // 更新 orgIds 字段 + SysOrgModel insertModel = super.insert(model); + if(null != insertModel){ + String orgIds = StrUtil.appendIfMissing( + insertModel.getParentIds(), DELIMITER) + + insertModel.getId(); + UpdateWrapper 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 userIdList = Lists.newArrayList(); + List userIdListByTenantId = + iUserRoleRefService.getUserIdListByTenantIdAndAllData(UserUtil.getTenantId()); + // 获得当前租户下 ordIds 分组后 所有用户ID 集合 + List userIdListByOrgIds = iUserOrgRefService.getUserIdListByOrgIds(orgIds); + // 组合ID + userIdList.addAll(userIdListByTenantId); + userIdList.addAll(userIdListByOrgIds); + + // 清除缓存 + this.clearCache(userIdList); + } + + return insertModel; } @Transactional(rollbackFor = Exception.class) @@ -134,6 +166,7 @@ public class SysOrgServiceImpl extends CrudServiceImpl userIdList = + iUserRoleRefService.getUserIdListByTenantIdAndAllData(UserUtil.getTenantId()); + // 获得当前租户下 ordIds 分组后 所有用户ID 集合 + List userIdListByOrgIds = iUserOrgRefService.getUserIdListByOrgIds(updateRet.getOrgIds()); + // 组合ID + userIdList.addAll(userIdListByOrgIds); + + // 清除缓存 + this.clearCache(userIdList); // 修改 return updateRet; @@ -263,6 +308,12 @@ public class SysOrgServiceImpl extends CrudServiceImpl wrapper = new QueryWrapper<>(); + + // 添加 数据权限过滤器 + QueryWrapper 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 userIdList){ if(CollUtil.isNotEmpty(userIdList)){ + // 去重 + List distinctUserIdList = ListDistinctUtil.distinct(userIdList); + int cacheCount = 0; - for (String userId : userIdList) { + for (String userId : distinctUserIdList) { cacheCount += 2; boolean tmp; // 清空当期用户缓存 组织 diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/web/SysOrgRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/web/SysOrgRestController.java index ec917d2..6bdecb2 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/web/SysOrgRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/web/SysOrgRestController.java @@ -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 dataList = IService.findList(wrapper); + if(CollUtil.isEmpty(dataList)){ + Set genOrgIdSet = new HashSet<>(); + List orgListByUserId = UserUtil.getOrgByCurrUser(); + for (UserOrgRefModel userOrgRefModel : orgListByUserId) { + List orgIdList = StrUtil.split(userOrgRefModel.getOrgIds(), ','); + if(CollUtil.isEmpty(orgIdList)){ + continue; + } + // 只取最后一位 + genOrgIdSet.add(orgIdList.get(orgIdList.size()-1)); + } + + + QueryWrapper 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 findTreeByDef(boolean isGen, String id) { List orgModelList = Lists.newArrayList(); @@ -198,20 +227,53 @@ public class SysOrgRestController extends BaseRestController queryBuilder = new GenQueryBuilder<>(); - QueryWrapper wrapper = queryBuilder.build(); -// // 左模糊匹配 -// wrapper.likeLeft( -// FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_IDS), parentId); + + // 获得最外层节点 + Set genOrgIdSet = new HashSet<>(); + List orgListByUserId = UserUtil.getOrgByCurrUser(); + for (UserOrgRefModel userOrgRefModel : orgListByUserId) { + List orgIdList = StrUtil.split(userOrgRefModel.getOrgIds(), ','); + if(CollUtil.isEmpty(orgIdList)){ + continue; + } + // 只取最后一位 + genOrgIdSet.add(orgIdList.get(orgIdList.size()-1)); + } + + QueryWrapper 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 dataList = IService.findList(wrapperByEmpty); + if(CollUtil.isEmpty(dataList)){ + dataList = Lists.newArrayList(); + } + for (SysOrg sysOrg : dataList) { + // 设置默认父节点 + sysOrg.setParentId(TreeBuildUtil.DEF_PARENT_ID); + } + + + QueryWrapper 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 childList = IService.findList(wrapper); + if(CollUtil.isNotEmpty(childList)){ + dataList.addAll(childList); + } - // 获得组织 - List dataList = IService.findList(wrapper); if(CollUtil.isNotEmpty(dataList)){ orgModelList.addAll( WrapperUtil.transformInstance(dataList, modelClazz) @@ -261,8 +323,18 @@ public class SysOrgRestController extends BaseRestController 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> treeNodes = TreeBuildUtil.INSTANCE.build(orgModelList, parentId, treeNodeConfig); + List> 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 parentIdSet = Sets.newHashSet(); for (SysOrgModel sysOrgModel : orgModelList) { parentIdSet.add(sysOrgModel.getParentId()); diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserOrgRefService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserOrgRefService.java index 660e7ac..82ea3b5 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserOrgRefService.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserOrgRefService.java @@ -36,6 +36,13 @@ public interface IUserOrgRefService { */ boolean setOrg(UserOrgRefWebModel model); + /** + * 根据 OrgIds 获得用户ID集合 + * @param orgIds 组织ID 集合 + * @return List + */ + List getUserIdListByOrgIds(String orgIds); + /** * 根据用户ID 获得组织列表 * @param userId 用户ID diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserOrgRefServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserOrgRefServiceImpl.java index aeedd03..8bd8055 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserOrgRefServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserOrgRefServiceImpl.java @@ -75,6 +75,31 @@ public class UserOrgRefServiceImpl extends ServiceImpl getUserIdListByOrgIds(String orgIds){ + List conditionList = getParentIdsGroup(orgIds); + if(CollUtil.isEmpty(conditionList)){ + return ListUtil.empty(); + } + + // 获得用户ID + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in( + FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ORG_GROUP), conditionList); + List userOrgRefs = this.list(queryWrapper); + if(CollUtil.isEmpty(userOrgRefs)){ + return ListUtil.empty(); + } + + List userIdList = Lists.newArrayListWithCapacity(userOrgRefs.size()); + for (SysUserOrgRef userOrgRef : userOrgRefs) { + userIdList.add(userOrgRef.getUserId()); + } + + // 去重 + return ListDistinctUtil.distinct(userIdList); + } + @Override public List findListByUserId(String userId) { if(StrUtil.isEmpty(userId)){ @@ -259,6 +284,26 @@ public class UserOrgRefServiceImpl extends ServiceImpl getParentIdsGroup(String parentIds) { + if(StrUtil.isEmpty(parentIds)){ + return ListUtil.empty(); + } + + List parentIdList = StrUtil.split(parentIds, ','); + List condition = Lists.newArrayListWithCapacity(parentIdList.size()); + for (int i = 0; i < parentIdList.size(); i++) { + List tempList = ListUtil.sub(parentIdList, 0, parentIdList.size() - i); + String parentIdsTemp = StrUtil.join(",", tempList); + condition.add(parentIdsTemp); + } + return condition; + } + } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserRoleRefServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserRoleRefServiceImpl.java index ee85cc4..4d3fa20 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserRoleRefServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserRoleRefServiceImpl.java @@ -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 queryBuilder = new GenQueryBuilder<>(); QueryWrapper 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 menuList = iMenuService.findList(queryWrapper); @@ -140,7 +138,7 @@ public class UserRoleRefServiceImpl extends ServiceImpl queryBuilder = new GenQueryBuilder<>(); QueryWrapper 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 getUserIdListByTenantIdAndAllData(String tenantId) { QueryWrapper 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 users = mapper.getUserIdList(queryWrapper); if(CollUtil.isEmpty(users)){ diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java index 4fc8e8e..9af3803 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java @@ -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 userRolesByUserId = UserUtil.getUserRolesByUserId(userIdTemp); List userAllPermsByUserId = UserUtil.getUserAllPermsByUserId(userIdTemp); @@ -127,6 +129,12 @@ public class UserRestController extends BaseRestController insert(UserModel model) { // 调用新增方法 - IService.insert(model); - return ResultVo.success("新增用户信息成功"); + UserModel userModel = IService.insert(model); + return ResultVo.success("新增用户信息成功", userModel); } /**