Merge remote-tracking branch 'origin/dev' into warm-flow-future
This commit is contained in:
commit
af762e87d1
@ -34,6 +34,7 @@ MaxKey 业界领先单点登录产品 - https://gitee.com/dromara/MaxKey <br>
|
|||||||
CCFlow 驰聘低代码-流程-表单 - https://gitee.com/opencc/RuoYi-JFlow <br>
|
CCFlow 驰聘低代码-流程-表单 - https://gitee.com/opencc/RuoYi-JFlow <br>
|
||||||
数舵科技 软件定制开发APP小程序等 - http://www.shuduokeji.com/ <br>
|
数舵科技 软件定制开发APP小程序等 - http://www.shuduokeji.com/ <br>
|
||||||
引迈信息 软件开发平台 - https://www.jnpfsoft.com/index.html?from=plus-doc <br>
|
引迈信息 软件开发平台 - https://www.jnpfsoft.com/index.html?from=plus-doc <br>
|
||||||
|
<font color="red">**启山商城系统 多租户商城源码可免费商用可二次开发 - https://www.73app.cn/** </font><br>
|
||||||
[如何成为赞助商 加群联系作者详谈](https://plus-doc.dromara.org/#/common/add_group)
|
[如何成为赞助商 加群联系作者详谈](https://plus-doc.dromara.org/#/common/add_group)
|
||||||
|
|
||||||
# 本框架与RuoYi的功能差异
|
# 本框架与RuoYi的功能差异
|
||||||
|
@ -15,7 +15,7 @@ public class SqlUtil {
|
|||||||
/**
|
/**
|
||||||
* 定义常用的 sql关键字
|
* 定义常用的 sql关键字
|
||||||
*/
|
*/
|
||||||
public static String SQL_REGEX = "and |extractvalue|updatexml|sleep|exec |insert |select |delete |update |drop |count |chr |mid |master |truncate |char |declare |or |union |like |+|/*|user()";
|
public static String SQL_REGEX = "\u000B|and |extractvalue|updatexml|sleep|exec |insert |select |delete |update |drop |count |chr |mid |master |truncate |char |declare |or |union |like |+|/*|user()";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
|
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package org.dromara.common.excel.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批注
|
||||||
|
* @author guzhouyanyu
|
||||||
|
*/
|
||||||
|
@Target({ElementType.FIELD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface ExcelNotation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* col index
|
||||||
|
*/
|
||||||
|
int index() default -1;
|
||||||
|
/**
|
||||||
|
* 批注内容
|
||||||
|
*/
|
||||||
|
String value() default "";
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package org.dromara.common.excel.annotation;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否必填
|
||||||
|
* @author guzhouyanyu
|
||||||
|
*/
|
||||||
|
@Target({ElementType.FIELD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface ExcelRequired {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* col index
|
||||||
|
*/
|
||||||
|
int index() default -1;
|
||||||
|
/**
|
||||||
|
* 字体颜色
|
||||||
|
*/
|
||||||
|
IndexedColors fontColor() default IndexedColors.RED;
|
||||||
|
}
|
@ -0,0 +1,135 @@
|
|||||||
|
package org.dromara.common.excel.handler;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.alibaba.excel.metadata.data.DataFormatData;
|
||||||
|
import com.alibaba.excel.metadata.data.WriteCellData;
|
||||||
|
import com.alibaba.excel.util.StyleUtil;
|
||||||
|
import com.alibaba.excel.write.handler.CellWriteHandler;
|
||||||
|
import com.alibaba.excel.write.handler.SheetWriteHandler;
|
||||||
|
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
|
||||||
|
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
|
||||||
|
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
||||||
|
import com.alibaba.excel.write.metadata.style.WriteFont;
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||||
|
import org.dromara.common.core.utils.reflect.ReflectUtils;
|
||||||
|
import org.dromara.common.excel.annotation.ExcelNotation;
|
||||||
|
import org.dromara.common.excel.annotation.ExcelRequired;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批注、必填
|
||||||
|
*
|
||||||
|
* @author guzhouyanyu
|
||||||
|
*/
|
||||||
|
public class DataWriteHandler implements SheetWriteHandler, CellWriteHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批注
|
||||||
|
*/
|
||||||
|
private final Map<Integer, String> notationMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头列字体颜色
|
||||||
|
*/
|
||||||
|
private final Map<Integer, Short> headColumnMap;
|
||||||
|
|
||||||
|
|
||||||
|
public DataWriteHandler(Class<?> clazz) {
|
||||||
|
notationMap = getNotationMap(clazz);
|
||||||
|
headColumnMap = getRequiredMap(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterCellDispose(CellWriteHandlerContext context) {
|
||||||
|
if (CollUtil.isEmpty(notationMap) && CollUtil.isEmpty(headColumnMap)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
WriteCellData<?> cellData = context.getFirstCellData();
|
||||||
|
WriteCellStyle writeCellStyle = cellData.getOrCreateStyle();
|
||||||
|
|
||||||
|
DataFormatData dataFormatData = new DataFormatData();
|
||||||
|
// 单元格设置为文本格式
|
||||||
|
dataFormatData.setIndex((short) 49);
|
||||||
|
writeCellStyle.setDataFormatData(dataFormatData);
|
||||||
|
|
||||||
|
if (context.getHead()) {
|
||||||
|
Cell cell = context.getCell();
|
||||||
|
WriteSheetHolder writeSheetHolder = context.getWriteSheetHolder();
|
||||||
|
Sheet sheet = writeSheetHolder.getSheet();
|
||||||
|
Workbook workbook = writeSheetHolder.getSheet().getWorkbook();
|
||||||
|
Drawing<?> drawing = sheet.createDrawingPatriarch();
|
||||||
|
// 设置标题字体样式
|
||||||
|
WriteFont headWriteFont = new WriteFont();
|
||||||
|
// 加粗
|
||||||
|
headWriteFont.setBold(true);
|
||||||
|
if (CollUtil.isNotEmpty(headColumnMap) && headColumnMap.containsKey(cell.getColumnIndex())) {
|
||||||
|
// 设置字体颜色
|
||||||
|
headWriteFont.setColor(headColumnMap.get(cell.getColumnIndex()));
|
||||||
|
}
|
||||||
|
writeCellStyle.setWriteFont(headWriteFont);
|
||||||
|
CellStyle cellStyle = StyleUtil.buildCellStyle(workbook, null, writeCellStyle);
|
||||||
|
cell.setCellStyle(cellStyle);
|
||||||
|
|
||||||
|
if (CollUtil.isNotEmpty(notationMap) && notationMap.containsKey(cell.getColumnIndex())) {
|
||||||
|
// 批注内容
|
||||||
|
String notationContext = notationMap.get(cell.getColumnIndex());
|
||||||
|
// 创建绘图对象
|
||||||
|
Comment comment = drawing.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), 0, (short) 5, 5));
|
||||||
|
comment.setString(new XSSFRichTextString(notationContext));
|
||||||
|
cell.setCellComment(comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取必填列
|
||||||
|
*/
|
||||||
|
private static Map<Integer, Short> getRequiredMap(Class<?> clazz) {
|
||||||
|
Map<Integer, Short> requiredMap = new HashMap<>();
|
||||||
|
Field[] fields = clazz.getDeclaredFields();
|
||||||
|
// 检查 fields 数组是否为空
|
||||||
|
if (fields.length == 0) {
|
||||||
|
return requiredMap;
|
||||||
|
}
|
||||||
|
Field[] filteredFields = ReflectUtils.getFields(clazz, field -> !"serialVersionUID".equals(field.getName()));
|
||||||
|
|
||||||
|
for (int i = 0; i < filteredFields.length; i++) {
|
||||||
|
Field field = filteredFields[i];
|
||||||
|
if (!field.isAnnotationPresent(ExcelRequired.class)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ExcelRequired excelRequired = field.getAnnotation(ExcelRequired.class);
|
||||||
|
int columnIndex = excelRequired.index() == -1 ? i : excelRequired.index();
|
||||||
|
requiredMap.put(columnIndex, excelRequired.fontColor().getIndex());
|
||||||
|
}
|
||||||
|
return requiredMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取批注
|
||||||
|
*/
|
||||||
|
private static Map<Integer, String> getNotationMap(Class<?> clazz) {
|
||||||
|
Map<Integer, String> notationMap = new HashMap<>();
|
||||||
|
Field[] fields = clazz.getDeclaredFields();
|
||||||
|
// 检查 fields 数组是否为空
|
||||||
|
if (fields.length == 0) {
|
||||||
|
return notationMap;
|
||||||
|
}
|
||||||
|
Field[] filteredFields = ReflectUtils.getFields(clazz, field -> !"serialVersionUID".equals(field.getName()));
|
||||||
|
for (int i = 0; i < filteredFields.length; i++) {
|
||||||
|
Field field = filteredFields[i];
|
||||||
|
if (!field.isAnnotationPresent(ExcelNotation.class)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ExcelNotation excelNotation = field.getAnnotation(ExcelNotation.class);
|
||||||
|
int columnIndex = excelNotation.index() == -1 ? i : excelNotation.index();
|
||||||
|
notationMap.put(columnIndex, excelNotation.value());
|
||||||
|
}
|
||||||
|
return notationMap;
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@ import org.dromara.common.core.utils.StringUtils;
|
|||||||
import org.dromara.common.core.utils.file.FileUtils;
|
import org.dromara.common.core.utils.file.FileUtils;
|
||||||
import org.dromara.common.excel.convert.ExcelBigNumberConvert;
|
import org.dromara.common.excel.convert.ExcelBigNumberConvert;
|
||||||
import org.dromara.common.excel.core.*;
|
import org.dromara.common.excel.core.*;
|
||||||
|
import org.dromara.common.excel.handler.DataWriteHandler;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -191,6 +192,7 @@ public class ExcelUtil {
|
|||||||
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
||||||
// 大数值自动转换 防止失真
|
// 大数值自动转换 防止失真
|
||||||
.registerConverter(new ExcelBigNumberConvert())
|
.registerConverter(new ExcelBigNumberConvert())
|
||||||
|
.registerWriteHandler(new DataWriteHandler(clazz))
|
||||||
.sheet(sheetName);
|
.sheet(sheetName);
|
||||||
if (merge) {
|
if (merge) {
|
||||||
// 合并处理器
|
// 合并处理器
|
||||||
@ -211,7 +213,7 @@ public class ExcelUtil {
|
|||||||
* @param data 模板需要的数据
|
* @param data 模板需要的数据
|
||||||
* @param response 响应体
|
* @param response 响应体
|
||||||
*/
|
*/
|
||||||
public static void exportTemplate(List<Object> data, String filename, String templatePath, HttpServletResponse response) {
|
public static <T> void exportTemplate(List<T> data, String filename, String templatePath, HttpServletResponse response) {
|
||||||
try {
|
try {
|
||||||
resetResponse(filename, response);
|
resetResponse(filename, response);
|
||||||
ServletOutputStream os = response.getOutputStream();
|
ServletOutputStream os = response.getOutputStream();
|
||||||
@ -230,20 +232,21 @@ public class ExcelUtil {
|
|||||||
* @param data 模板需要的数据
|
* @param data 模板需要的数据
|
||||||
* @param os 输出流
|
* @param os 输出流
|
||||||
*/
|
*/
|
||||||
public static void exportTemplate(List<Object> data, String templatePath, OutputStream os) {
|
public static <T> void exportTemplate(List<T> data, String templatePath, OutputStream os) {
|
||||||
|
if (CollUtil.isEmpty(data)) {
|
||||||
|
throw new IllegalArgumentException("数据为空");
|
||||||
|
}
|
||||||
ClassPathResource templateResource = new ClassPathResource(templatePath);
|
ClassPathResource templateResource = new ClassPathResource(templatePath);
|
||||||
ExcelWriter excelWriter = EasyExcel.write(os)
|
ExcelWriter excelWriter = EasyExcel.write(os)
|
||||||
.withTemplate(templateResource.getStream())
|
.withTemplate(templateResource.getStream())
|
||||||
.autoCloseStream(false)
|
.autoCloseStream(false)
|
||||||
// 大数值自动转换 防止失真
|
// 大数值自动转换 防止失真
|
||||||
.registerConverter(new ExcelBigNumberConvert())
|
.registerConverter(new ExcelBigNumberConvert())
|
||||||
|
.registerWriteHandler(new DataWriteHandler(data.get(0).getClass()))
|
||||||
.build();
|
.build();
|
||||||
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
||||||
if (CollUtil.isEmpty(data)) {
|
|
||||||
throw new IllegalArgumentException("数据为空");
|
|
||||||
}
|
|
||||||
// 单表多数据导出 模板格式为 {.属性}
|
// 单表多数据导出 模板格式为 {.属性}
|
||||||
for (Object d : data) {
|
for (T d : data) {
|
||||||
excelWriter.fill(d, writeSheet);
|
excelWriter.fill(d, writeSheet);
|
||||||
}
|
}
|
||||||
excelWriter.finish();
|
excelWriter.finish();
|
||||||
@ -299,6 +302,9 @@ public class ExcelUtil {
|
|||||||
* @param os 输出流
|
* @param os 输出流
|
||||||
*/
|
*/
|
||||||
public static void exportTemplateMultiList(Map<String, Object> data, String templatePath, OutputStream os) {
|
public static void exportTemplateMultiList(Map<String, Object> data, String templatePath, OutputStream os) {
|
||||||
|
if (CollUtil.isEmpty(data)) {
|
||||||
|
throw new IllegalArgumentException("数据为空");
|
||||||
|
}
|
||||||
ClassPathResource templateResource = new ClassPathResource(templatePath);
|
ClassPathResource templateResource = new ClassPathResource(templatePath);
|
||||||
ExcelWriter excelWriter = EasyExcel.write(os)
|
ExcelWriter excelWriter = EasyExcel.write(os)
|
||||||
.withTemplate(templateResource.getStream())
|
.withTemplate(templateResource.getStream())
|
||||||
@ -307,9 +313,6 @@ public class ExcelUtil {
|
|||||||
.registerConverter(new ExcelBigNumberConvert())
|
.registerConverter(new ExcelBigNumberConvert())
|
||||||
.build();
|
.build();
|
||||||
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
||||||
if (CollUtil.isEmpty(data)) {
|
|
||||||
throw new IllegalArgumentException("数据为空");
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, Object> map : data.entrySet()) {
|
for (Map.Entry<String, Object> map : data.entrySet()) {
|
||||||
// 设置列表后续还有数据
|
// 设置列表后续还有数据
|
||||||
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
||||||
@ -333,6 +336,9 @@ public class ExcelUtil {
|
|||||||
* @param os 输出流
|
* @param os 输出流
|
||||||
*/
|
*/
|
||||||
public static void exportTemplateMultiSheet(List<Map<String, Object>> data, String templatePath, OutputStream os) {
|
public static void exportTemplateMultiSheet(List<Map<String, Object>> data, String templatePath, OutputStream os) {
|
||||||
|
if (CollUtil.isEmpty(data)) {
|
||||||
|
throw new IllegalArgumentException("数据为空");
|
||||||
|
}
|
||||||
ClassPathResource templateResource = new ClassPathResource(templatePath);
|
ClassPathResource templateResource = new ClassPathResource(templatePath);
|
||||||
ExcelWriter excelWriter = EasyExcel.write(os)
|
ExcelWriter excelWriter = EasyExcel.write(os)
|
||||||
.withTemplate(templateResource.getStream())
|
.withTemplate(templateResource.getStream())
|
||||||
@ -340,9 +346,6 @@ public class ExcelUtil {
|
|||||||
// 大数值自动转换 防止失真
|
// 大数值自动转换 防止失真
|
||||||
.registerConverter(new ExcelBigNumberConvert())
|
.registerConverter(new ExcelBigNumberConvert())
|
||||||
.build();
|
.build();
|
||||||
if (CollUtil.isEmpty(data)) {
|
|
||||||
throw new IllegalArgumentException("数据为空");
|
|
||||||
}
|
|
||||||
for (int i = 0; i < data.size(); i++) {
|
for (int i = 0; i < data.size(); i++) {
|
||||||
WriteSheet writeSheet = EasyExcel.writerSheet(i).build();
|
WriteSheet writeSheet = EasyExcel.writerSheet(i).build();
|
||||||
for (Map.Entry<String, Object> map : data.get(i).entrySet()) {
|
for (Map.Entry<String, Object> map : data.get(i).entrySet()) {
|
||||||
|
@ -32,7 +32,7 @@ public class BigNumberSerializer extends NumberSerializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(Number value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
public void serialize(Number value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||||
// 超出范围 序列化位字符串
|
// 超出范围 序列化为字符串
|
||||||
if (value.longValue() > MIN_SAFE_INTEGER && value.longValue() < MAX_SAFE_INTEGER) {
|
if (value.longValue() > MIN_SAFE_INTEGER && value.longValue() < MAX_SAFE_INTEGER) {
|
||||||
super.serialize(value, gen, provider);
|
super.serialize(value, gen, provider);
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,6 +3,7 @@ package org.dromara.common.mybatis.handler;
|
|||||||
import cn.hutool.core.annotation.AnnotationUtil;
|
import cn.hutool.core.annotation.AnnotationUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.sf.jsqlparser.JSQLParserException;
|
import net.sf.jsqlparser.JSQLParserException;
|
||||||
import net.sf.jsqlparser.expression.Expression;
|
import net.sf.jsqlparser.expression.Expression;
|
||||||
@ -28,9 +29,7 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
|||||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||||
import org.springframework.core.type.ClassMetadata;
|
import org.springframework.core.type.ClassMetadata;
|
||||||
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||||
import org.springframework.expression.BeanResolver;
|
import org.springframework.expression.*;
|
||||||
import org.springframework.expression.ExpressionParser;
|
|
||||||
import org.springframework.expression.ParserContext;
|
|
||||||
import org.springframework.expression.common.TemplateParserContext;
|
import org.springframework.expression.common.TemplateParserContext;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
@ -130,7 +129,9 @@ public class PlusDataPermissionHandler {
|
|||||||
joinStr = " " + dataPermission.joinStr() + " ";
|
joinStr = " " + dataPermission.joinStr() + " ";
|
||||||
}
|
}
|
||||||
LoginUser user = DataPermissionHelper.getVariable("user");
|
LoginUser user = DataPermissionHelper.getVariable("user");
|
||||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
Object defaultValue = "-1";
|
||||||
|
NullSafeStandardEvaluationContext context = new NullSafeStandardEvaluationContext(defaultValue);
|
||||||
|
context.addPropertyAccessor(new NullSafePropertyAccessor(context.getPropertyAccessors().get(0), defaultValue));
|
||||||
context.setBeanResolver(beanResolver);
|
context.setBeanResolver(beanResolver);
|
||||||
DataPermissionHelper.getContext().forEach(context::setVariable);
|
DataPermissionHelper.getContext().forEach(context::setVariable);
|
||||||
Set<String> conditions = new HashSet<>();
|
Set<String> conditions = new HashSet<>();
|
||||||
@ -257,4 +258,64 @@ public class PlusDataPermissionHandler {
|
|||||||
return getDataPermission(mapperId) == null;
|
return getDataPermission(mapperId) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对所有null变量找不到的变量返回默认值
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
private static class NullSafeStandardEvaluationContext extends StandardEvaluationContext {
|
||||||
|
|
||||||
|
private final Object defaultValue;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object lookupVariable(String name) {
|
||||||
|
Object obj = super.lookupVariable(name);
|
||||||
|
// 如果读取到的值是 null,则返回默认值
|
||||||
|
if (obj == null) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对所有null变量找不到的变量返回默认值 委托模式 将不需要处理的方法委托给原处理器
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
private static class NullSafePropertyAccessor implements PropertyAccessor {
|
||||||
|
|
||||||
|
private final PropertyAccessor delegate;
|
||||||
|
private final Object defaultValue;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?>[] getSpecificTargetClasses() {
|
||||||
|
return delegate.getSpecificTargetClasses();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||||
|
return delegate.canRead(context, target, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||||
|
TypedValue value = delegate.read(context, target, name);
|
||||||
|
// 如果读取到的值是 null,则返回默认值
|
||||||
|
if (value.getValue() == null) {
|
||||||
|
return new TypedValue(defaultValue);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||||
|
return delegate.canWrite(context, target, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
|
||||||
|
delegate.write(context, target, name, newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -80,12 +80,12 @@ public enum SensitiveStrategy {
|
|||||||
FIRST_MASK(DesensitizedUtil::firstMask),
|
FIRST_MASK(DesensitizedUtil::firstMask),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空为null
|
* 清空为""
|
||||||
*/
|
*/
|
||||||
CLEAR(s -> DesensitizedUtil.clear()),
|
CLEAR(s -> DesensitizedUtil.clear()),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空为""
|
* 清空为null
|
||||||
*/
|
*/
|
||||||
CLEAR_TO_NULL(s -> DesensitizedUtil.clearToNull());
|
CLEAR_TO_NULL(s -> DesensitizedUtil.clearToNull());
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.dromara.common.sse.core;
|
package org.dromara.common.sse.core;
|
||||||
|
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.common.redis.utils.RedisUtils;
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
import org.dromara.common.sse.dto.SseMessageDto;
|
import org.dromara.common.sse.dto.SseMessageDto;
|
||||||
@ -65,7 +66,7 @@ public class SseEmitterManager {
|
|||||||
*/
|
*/
|
||||||
public void disconnect(Long userId, String token) {
|
public void disconnect(Long userId, String token) {
|
||||||
Map<String, SseEmitter> emitters = USER_TOKEN_EMITTERS.get(userId);
|
Map<String, SseEmitter> emitters = USER_TOKEN_EMITTERS.get(userId);
|
||||||
if (emitters != null) {
|
if (MapUtil.isNotEmpty(emitters)) {
|
||||||
try {
|
try {
|
||||||
SseEmitter sseEmitter = emitters.get(token);
|
SseEmitter sseEmitter = emitters.get(token);
|
||||||
sseEmitter.send(SseEmitter.event().comment("disconnected"));
|
sseEmitter.send(SseEmitter.event().comment("disconnected"));
|
||||||
@ -73,6 +74,8 @@ public class SseEmitterManager {
|
|||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
}
|
}
|
||||||
emitters.remove(token);
|
emitters.remove(token);
|
||||||
|
} else {
|
||||||
|
USER_TOKEN_EMITTERS.remove(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +96,7 @@ public class SseEmitterManager {
|
|||||||
*/
|
*/
|
||||||
public void sendMessage(Long userId, String message) {
|
public void sendMessage(Long userId, String message) {
|
||||||
Map<String, SseEmitter> emitters = USER_TOKEN_EMITTERS.get(userId);
|
Map<String, SseEmitter> emitters = USER_TOKEN_EMITTERS.get(userId);
|
||||||
if (emitters != null) {
|
if (MapUtil.isNotEmpty(emitters)) {
|
||||||
for (Map.Entry<String, SseEmitter> entry : emitters.entrySet()) {
|
for (Map.Entry<String, SseEmitter> entry : emitters.entrySet()) {
|
||||||
try {
|
try {
|
||||||
entry.getValue().send(SseEmitter.event()
|
entry.getValue().send(SseEmitter.event()
|
||||||
@ -103,6 +106,8 @@ public class SseEmitterManager {
|
|||||||
emitters.remove(entry.getKey());
|
emitters.remove(entry.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
USER_TOKEN_EMITTERS.remove(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,14 @@ import org.dromara.common.sse.dto.SseMessageDto;
|
|||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class SseMessageUtils {
|
public class SseMessageUtils {
|
||||||
|
|
||||||
private final static SseEmitterManager MANAGER = SpringUtils.getBean(SseEmitterManager.class);
|
private final static Boolean SSE_ENABLE = SpringUtils.getProperty("sse.enabled", Boolean.class, true);
|
||||||
|
private static SseEmitterManager MANAGER;
|
||||||
|
|
||||||
|
static {
|
||||||
|
if (isEnable() && MANAGER == null) {
|
||||||
|
MANAGER = SpringUtils.getBean(SseEmitterManager.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向指定的WebSocket会话发送消息
|
* 向指定的WebSocket会话发送消息
|
||||||
@ -25,6 +32,9 @@ public class SseMessageUtils {
|
|||||||
* @param message 要发送的消息内容
|
* @param message 要发送的消息内容
|
||||||
*/
|
*/
|
||||||
public static void sendMessage(Long userId, String message) {
|
public static void sendMessage(Long userId, String message) {
|
||||||
|
if (!isEnable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
MANAGER.sendMessage(userId, message);
|
MANAGER.sendMessage(userId, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +44,9 @@ public class SseMessageUtils {
|
|||||||
* @param message 要发送的消息内容
|
* @param message 要发送的消息内容
|
||||||
*/
|
*/
|
||||||
public static void sendMessage(String message) {
|
public static void sendMessage(String message) {
|
||||||
|
if (!isEnable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
MANAGER.sendMessage(message);
|
MANAGER.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,6 +56,9 @@ public class SseMessageUtils {
|
|||||||
* @param sseMessageDto 要发布的SSE消息对象
|
* @param sseMessageDto 要发布的SSE消息对象
|
||||||
*/
|
*/
|
||||||
public static void publishMessage(SseMessageDto sseMessageDto) {
|
public static void publishMessage(SseMessageDto sseMessageDto) {
|
||||||
|
if (!isEnable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
MANAGER.publishMessage(sseMessageDto);
|
MANAGER.publishMessage(sseMessageDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +68,17 @@ public class SseMessageUtils {
|
|||||||
* @param message 要发布的消息内容
|
* @param message 要发布的消息内容
|
||||||
*/
|
*/
|
||||||
public static void publishAll(String message) {
|
public static void publishAll(String message) {
|
||||||
|
if (!isEnable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
MANAGER.publishAll(message);
|
MANAGER.publishAll(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否开启
|
||||||
|
*/
|
||||||
|
public static Boolean isEnable() {
|
||||||
|
return SSE_ENABLE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package org.dromara.demo.domain.vo;
|
|||||||
|
|
||||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||||
import com.alibaba.excel.annotation.ExcelProperty;
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
import org.dromara.common.excel.annotation.ExcelNotation;
|
||||||
|
import org.dromara.common.excel.annotation.ExcelRequired;
|
||||||
import org.dromara.common.translation.annotation.Translation;
|
import org.dromara.common.translation.annotation.Translation;
|
||||||
import org.dromara.common.translation.constant.TransConstant;
|
import org.dromara.common.translation.constant.TransConstant;
|
||||||
import org.dromara.demo.domain.TestDemo;
|
import org.dromara.demo.domain.TestDemo;
|
||||||
@ -36,30 +38,35 @@ public class TestDemoVo implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 部门id
|
* 部门id
|
||||||
*/
|
*/
|
||||||
|
@ExcelRequired
|
||||||
@ExcelProperty(value = "部门id")
|
@ExcelProperty(value = "部门id")
|
||||||
private Long deptId;
|
private Long deptId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户id
|
* 用户id
|
||||||
*/
|
*/
|
||||||
|
@ExcelRequired
|
||||||
@ExcelProperty(value = "用户id")
|
@ExcelProperty(value = "用户id")
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 排序号
|
* 排序号
|
||||||
*/
|
*/
|
||||||
|
@ExcelRequired
|
||||||
@ExcelProperty(value = "排序号")
|
@ExcelProperty(value = "排序号")
|
||||||
private Integer orderNum;
|
private Integer orderNum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* key键
|
* key键
|
||||||
*/
|
*/
|
||||||
|
@ExcelNotation(value = "测试key")
|
||||||
@ExcelProperty(value = "key键")
|
@ExcelProperty(value = "key键")
|
||||||
private String testKey;
|
private String testKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 值
|
* 值
|
||||||
*/
|
*/
|
||||||
|
@ExcelNotation(value = "测试value")
|
||||||
@ExcelProperty(value = "值")
|
@ExcelProperty(value = "值")
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user