mirror of
https://gitee.com/y_project/RuoYi-Cloud.git
synced 2026-02-05 08:21:56 +08:00
Compare commits
3 Commits
e1503a0f2f
...
2d5e12395f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d5e12395f | ||
|
|
8c096cba8d | ||
|
|
8db4f0c8f7 |
@@ -8,6 +8,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
|||||||
import com.ruoyi.common.core.annotation.Excel;
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
import com.ruoyi.common.core.annotation.Excel.ColumnType;
|
import com.ruoyi.common.core.annotation.Excel.ColumnType;
|
||||||
import com.ruoyi.common.core.annotation.Excel.Type;
|
import com.ruoyi.common.core.annotation.Excel.Type;
|
||||||
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.annotation.Excels;
|
import com.ruoyi.common.core.annotation.Excels;
|
||||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||||
import com.ruoyi.common.core.xss.Xss;
|
import com.ruoyi.common.core.xss.Xss;
|
||||||
@@ -116,7 +117,7 @@ public class SysUser extends BaseEntity
|
|||||||
|
|
||||||
public static boolean isAdmin(Long userId)
|
public static boolean isAdmin(Long userId)
|
||||||
{
|
{
|
||||||
return userId != null && 1L == userId;
|
return UserConstants.isAdmin(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getDeptId()
|
public Long getDeptId()
|
||||||
|
|||||||
@@ -80,4 +80,9 @@ public class UserConstants
|
|||||||
public static final int PASSWORD_MIN_LENGTH = 5;
|
public static final int PASSWORD_MIN_LENGTH = 5;
|
||||||
|
|
||||||
public static final int PASSWORD_MAX_LENGTH = 20;
|
public static final int PASSWORD_MAX_LENGTH = 20;
|
||||||
|
|
||||||
|
public static boolean isAdmin(Long userId)
|
||||||
|
{
|
||||||
|
return userId != null && 1L == userId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,136 @@
|
|||||||
|
package com.ruoyi.common.core.utils.trees;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 树形菜单生成工具类
|
||||||
|
* @param <T>
|
||||||
|
*/
|
||||||
|
public class Tree <T>{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扁平化的树形结构
|
||||||
|
*/
|
||||||
|
protected List<TreeNode> flatTrees = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有根节点
|
||||||
|
*/
|
||||||
|
public List<TreeNode> rootTrees = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Id key标识
|
||||||
|
*/
|
||||||
|
protected String idFlag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pid key标识
|
||||||
|
*/
|
||||||
|
protected String pidFlag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* name key标识
|
||||||
|
*/
|
||||||
|
protected String nameFlag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用默认属性名
|
||||||
|
*/
|
||||||
|
public Tree() {
|
||||||
|
this("MenuId", "ParentId", "MenuName");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义修改属性名
|
||||||
|
* @param idFlag
|
||||||
|
* @param pidFlag
|
||||||
|
* @param nameFlag
|
||||||
|
*/
|
||||||
|
public Tree(String idFlag, String pidFlag, String nameFlag) {
|
||||||
|
this.idFlag = idFlag;
|
||||||
|
this.pidFlag = pidFlag;
|
||||||
|
this.nameFlag = nameFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成树形菜单
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<TreeNode> generateTrees(List<T> anyTrees) throws Exception {
|
||||||
|
|
||||||
|
// 处理给定的树形结构
|
||||||
|
screenTrees(anyTrees);
|
||||||
|
|
||||||
|
// 找到父节点下面所有子节点 - 递归
|
||||||
|
generateRecursionTrees();
|
||||||
|
|
||||||
|
return rootTrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从任意扁平树结构中生成待处理的扁平化的树形结构 以及 根节点
|
||||||
|
* @param anyTrees
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected void screenTrees(List<T> anyTrees) throws Exception {
|
||||||
|
for (T anyTree: anyTrees) {
|
||||||
|
TreeNode treeNode = new TreeNode();
|
||||||
|
|
||||||
|
try {
|
||||||
|
treeNode.id = (Long) anyTree.getClass().getMethod("get" + idFlag).invoke(anyTree);
|
||||||
|
treeNode.pid = (Long) anyTree.getClass().getMethod("get" + pidFlag).invoke(anyTree);
|
||||||
|
treeNode.label = (String) anyTree.getClass().getMethod("get" + nameFlag).invoke(anyTree);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new Exception(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取root节点和子节点
|
||||||
|
if (treeNode.pid == 0L) {
|
||||||
|
this.rootTrees.add(treeNode);
|
||||||
|
} else {
|
||||||
|
this.flatTrees.add(treeNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用递归方式生成树形结构
|
||||||
|
*/
|
||||||
|
protected void generateRecursionTrees() {
|
||||||
|
for (TreeNode rootTreeNode : rootTrees) {
|
||||||
|
recursionFunction(rootTreeNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归函数
|
||||||
|
* @param rootTreeNode
|
||||||
|
*/
|
||||||
|
protected void recursionFunction(TreeNode rootTreeNode) {
|
||||||
|
|
||||||
|
List<TreeNode> usedTreeNode = new ArrayList<>();
|
||||||
|
|
||||||
|
for(TreeNode treeNode : flatTrees) {
|
||||||
|
if (treeNode.pid == rootTreeNode.id) {
|
||||||
|
rootTreeNode.children.add(treeNode);
|
||||||
|
// 标记使用过的node
|
||||||
|
usedTreeNode.add(treeNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除标记的node
|
||||||
|
flatTrees.removeAll(usedTreeNode);
|
||||||
|
|
||||||
|
// 终止条件
|
||||||
|
if (usedTreeNode.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 递归
|
||||||
|
for (TreeNode treeNode: usedTreeNode) {
|
||||||
|
recursionFunction(treeNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.ruoyi.common.core.utils.trees;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tree node
|
||||||
|
*/
|
||||||
|
public class TreeNode {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
public Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parentId
|
||||||
|
*/
|
||||||
|
public Long pid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Node name
|
||||||
|
*/
|
||||||
|
public String label;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Child nodes
|
||||||
|
*/
|
||||||
|
public List<TreeNode> children = new ArrayList<>();
|
||||||
|
}
|
||||||
@@ -17,10 +17,10 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- RuoYi Common Security -->
|
<!-- RuoYi Common Core -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-security</artifactId>
|
<artifactId>ruoyi-common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
|||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
||||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
|
import com.ruoyi.common.core.context.SecurityContextHolder;
|
||||||
import com.ruoyi.common.sensitive.annotation.Sensitive;
|
import com.ruoyi.common.sensitive.annotation.Sensitive;
|
||||||
import com.ruoyi.common.sensitive.enums.DesensitizedType;
|
import com.ruoyi.common.sensitive.enums.DesensitizedType;
|
||||||
import com.ruoyi.system.api.model.LoginUser;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据脱敏序列化过滤
|
* 数据脱敏序列化过滤
|
||||||
@@ -55,9 +55,9 @@ public class SensitiveJsonSerializer extends JsonSerializer<String> implements C
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LoginUser securityUser = SecurityUtils.getLoginUser();
|
Long userId = SecurityContextHolder.getUserId();
|
||||||
// 管理员不脱敏
|
// 管理员不脱敏
|
||||||
return !securityUser.getSysUser().isAdmin();
|
return !UserConstants.isAdmin(userId);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user