💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
``` /** * @author 张跃帅 * @Description: 系统角色-工具 * @date 2020/08/12 */ public class SystemRoleUtil { private static final SystemRoleService systemRoleService = SpringUtil.getBean(SystemRoleService.class); /** * 获取-机构角色List */ public static List<SystemRoleEntity> getOrgRoleList(String orgCode, String roleName) { // 获取参数 String appCode = SystemContext.me().getAppCode(); // 创建查询包装器 LambdaQueryWrapper<SystemRoleEntity> queryWrapper = new LambdaQueryWrapper<>(); // 设置条件 queryWrapper.eq(SystemRoleEntity::getAppCode, appCode) .eq(SystemRoleEntity::getOrgCode, orgCode) .eq(SystemRoleEntity::getDataFlag, CommonDataFlagEnum.NORMAL.getCode()) .eq(SystemRoleEntity::getDelFlag, CommonDelFlagEnum.NOT_DELETE.getCode()); // 设置排序 queryWrapper.orderByAsc(SystemRoleEntity::getSort); // 判断 if (StrUtil.isNotBlank(roleName)) { // 追加条件 queryWrapper.like(SystemRoleEntity::getRoleName, roleName); } // 返回 return systemRoleService.list(queryWrapper); } /** * 获取-机构类型tree树 */ public static List<Tree<String>> getOrgRoleTree(String orgCode, String roleName) { // 获取参数 String appCode = SystemContext.me().getAppCode(); // 变量创建ArrayList List<Tree<String>> treeNodeList = CollectionUtil.newArrayList(); // 创建查询包装器 LambdaQueryWrapper<SystemRoleEntity> queryWrapper = new LambdaQueryWrapper<>(); // 设置条件 queryWrapper.eq(SystemRoleEntity::getAppCode, appCode) .eq(SystemRoleEntity::getOrgCode, appCode) .eq(SystemRoleEntity::getDataFlag, CommonDataFlagEnum.NORMAL.getCode()) .eq(SystemRoleEntity::getDelFlag, CommonDelFlagEnum.NOT_DELETE.getCode()); // 设置排序 queryWrapper.orderByAsc(SystemRoleEntity::getSort); // 查询 List<SystemRoleEntity> systemRoleList = systemRoleService.list(queryWrapper); // 判断 if (systemRoleList != null && systemRoleList.size() > 0) { // 变量-tree父节点id String parentId = CommonTreeParentIdEnum.PARENTID_0.getCode(); // tree转换器 treeNodeList = TreeUtil.build(systemRoleList, parentId, (systemRole, tree) -> { // 赋值 tree.setId(Convert.toStr(systemRole.getId())); tree.setParentId(parentId); tree.setName(systemRole.getRoleName()); // 追加自定义属性 tree.putExtra("code", systemRole.getRoleCode()); }); } // 判断-条件搜索 if (treeNodeList != null && treeNodeList.size() > 0 && StrUtil.isNotBlank(roleName)) { // 变量创建ArrayList List<Tree<String>> searchTreeNodeList = CollectionUtil.newArrayList(); // 遍历 for (Tree<String> treeNode : treeNodeList) { // 搜索查询 searchTreeNodeByName(treeNode, roleName, searchTreeNodeList); } // 赋值 treeNodeList = searchTreeNodeList; } // 返回 return treeNodeList; } /** * 递归遍历树节点-搜索匹配节点 */ private static List<Tree<String>> searchTreeNodeByName(Tree<String> treeNode, String name, List<Tree<String>> searchTreeNodeList) { // 获取参数 String nodeName = treeNode.getName().toString(); List<Tree<String>> childNodeList = treeNode.getChildren(); // 判断 if (nodeName.contains(name)) { // 添加 searchTreeNodeList.add(treeNode); } // 判断 if (childNodeList != null && childNodeList.size() > 0) { // 遍历 for (Tree<String> childNode : treeNode.getChildren()) { // 匹配子节点 searchTreeNodeByName(childNode, name, searchTreeNodeList); } } // 返回 return searchTreeNodeList; } }