mirror of
https://gitee.com/y_project/RuoYi-Cloud.git
synced 2026-01-26 11:51:55 +08:00
Compare commits
3 Commits
47c58b4e80
...
f7489caec4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7489caec4 | ||
|
|
8c096cba8d | ||
|
|
e492538513 |
@@ -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.ColumnType;
|
||||
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.web.domain.BaseEntity;
|
||||
import com.ruoyi.common.core.xss.Xss;
|
||||
@@ -116,7 +117,7 @@ public class SysUser extends BaseEntity
|
||||
|
||||
public static boolean isAdmin(Long userId)
|
||||
{
|
||||
return userId != null && 1L == userId;
|
||||
return UserConstants.isAdmin(userId);
|
||||
}
|
||||
|
||||
public Long getDeptId()
|
||||
|
||||
@@ -80,4 +80,9 @@ public class UserConstants
|
||||
public static final int PASSWORD_MIN_LENGTH = 5;
|
||||
|
||||
public static final int PASSWORD_MAX_LENGTH = 20;
|
||||
|
||||
public static boolean isAdmin(Long userId)
|
||||
{
|
||||
return userId != null && 1L == userId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,49 @@ import org.apache.poi.ss.usermodel.Workbook;
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ExcelHandlerAdapter
|
||||
{
|
||||
@SuppressWarnings("unused")
|
||||
public interface ExcelHandlerAdapter {
|
||||
|
||||
/**
|
||||
* 格式化
|
||||
*
|
||||
*
|
||||
* @deprecated 弃用,使用两个方法分别处理导入导出数据格式化
|
||||
*
|
||||
* @param value 单元格数据值
|
||||
* @param args excel注解args参数组
|
||||
* @param cell 单元格对象
|
||||
* @param wb 工作簿对象
|
||||
*
|
||||
* @return 处理后的值
|
||||
*/
|
||||
Object format(Object value, String[] args, Cell cell, Workbook wb);
|
||||
@Deprecated
|
||||
default Object format(Object value, String[] args, Cell cell, Workbook wb) {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入时自定义数据处理器
|
||||
*
|
||||
* @param value 单元格数据
|
||||
* @param args excel注解args参数组
|
||||
* @param cell 单元格对象
|
||||
* @param wb 工作簿对象
|
||||
* @return 处理后的值
|
||||
*/
|
||||
default Object importFormat(Object value, String[] args, Cell cell, Workbook wb) {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出时自定义数据处理器
|
||||
*
|
||||
* @param value 单元格数据
|
||||
* @param args excel注解args参数组
|
||||
* @param cell 单元格对象
|
||||
* @param wb 工作簿对象
|
||||
* @return 处理后的值
|
||||
*/
|
||||
default Object exportFormat(Object value, String[] args, Cell cell, Workbook wb) {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -455,7 +455,7 @@ public class ExcelUtil<T>
|
||||
}
|
||||
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
||||
{
|
||||
val = dataFormatHandlerAdapter(val, attr, null);
|
||||
val = importFormatHandlerAdapter(val, attr, null);
|
||||
}
|
||||
ReflectUtils.invokeSetter(entity, propertyName, val);
|
||||
}
|
||||
@@ -1013,7 +1013,7 @@ public class ExcelUtil<T>
|
||||
}
|
||||
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
||||
{
|
||||
cell.setCellValue(dataFormatHandlerAdapter(value, attr, cell));
|
||||
cell.setCellValue(exportFormatHandlerAdapter(value, attr, cell));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1196,10 +1196,13 @@ public class ExcelUtil<T>
|
||||
/**
|
||||
* 数据处理器
|
||||
*
|
||||
* @deprecated 方法弃用。分别使用导入导出的两个数据处理器分别处理导入导出的数据
|
||||
*
|
||||
* @param value 数据值
|
||||
* @param excel 数据注解
|
||||
* @return
|
||||
* @return 处理后的结果值
|
||||
*/
|
||||
@Deprecated
|
||||
public String dataFormatHandlerAdapter(Object value, Excel excel, Cell cell)
|
||||
{
|
||||
try
|
||||
@@ -1215,6 +1218,46 @@ public class ExcelUtil<T>
|
||||
return Convert.toStr(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入时的数据处理器
|
||||
*
|
||||
* @param value 数据值
|
||||
* @param excel 数据注解
|
||||
* @param cell 单元格对象
|
||||
* @return 处理后的结果值
|
||||
*/
|
||||
public String importFormatHandlerAdapter(Object value, Excel excel, Cell cell) {
|
||||
try {
|
||||
Object instance = excel.handler().getDeclaredConstructor().newInstance();
|
||||
Method formatMethod = excel.handler().getMethod("importFormat",
|
||||
Object.class, String[].class, Cell.class, Workbook.class);
|
||||
value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb);
|
||||
} catch (Exception e) {
|
||||
log.error("不能格式化数据 " + excel.handler() + "{}", e.getMessage());
|
||||
}
|
||||
return Convert.toStr(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出时的数据处理器
|
||||
*
|
||||
* @param value 数据值
|
||||
* @param excel 数据注解
|
||||
* @param cell 单元格对象
|
||||
* @return 处理后的结果值
|
||||
*/
|
||||
public String exportFormatHandlerAdapter(Object value, Excel excel, Cell cell) {
|
||||
try {
|
||||
Object instance = excel.handler().getDeclaredConstructor().newInstance();
|
||||
Method formatMethod = excel.handler().getMethod("exportFormat",
|
||||
Object.class, String[].class, Cell.class, Workbook.class);
|
||||
value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb);
|
||||
} catch (Exception e) {
|
||||
log.error("不能格式化数据 " + excel.handler() + "{}", e.getMessage());
|
||||
}
|
||||
return Convert.toStr(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 合计统计信息
|
||||
*/
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- RuoYi Common Security -->
|
||||
<!-- RuoYi Common Core -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-security</artifactId>
|
||||
<artifactId>ruoyi-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -8,10 +8,10 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
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.enums.DesensitizedType;
|
||||
import com.ruoyi.system.api.model.LoginUser;
|
||||
|
||||
/**
|
||||
* 数据脱敏序列化过滤
|
||||
@@ -55,9 +55,9 @@ public class SensitiveJsonSerializer extends JsonSerializer<String> implements C
|
||||
{
|
||||
try
|
||||
{
|
||||
LoginUser securityUser = SecurityUtils.getLoginUser();
|
||||
Long userId = SecurityContextHolder.getUserId();
|
||||
// 管理员不脱敏
|
||||
return !securityUser.getSysUser().isAdmin();
|
||||
return !UserConstants.isAdmin(userId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user