mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-04-04 01:33:23 +08:00
update 优化 项目中的一些存在null的问题 与一些性能问题 小优化
This commit is contained in:
@@ -23,6 +23,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||||||
|
|
||||||
public static final String SLASH = "/";
|
public static final String SLASH = "/";
|
||||||
|
|
||||||
|
private static final AntPathMatcher ANT_PATH_MATCHER = new AntPathMatcher();
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private StringUtils() {
|
private StringUtils() {
|
||||||
}
|
}
|
||||||
@@ -233,8 +235,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||||||
* @param url 需要匹配的url
|
* @param url 需要匹配的url
|
||||||
*/
|
*/
|
||||||
public static boolean isMatch(String pattern, String url) {
|
public static boolean isMatch(String pattern, String url) {
|
||||||
AntPathMatcher matcher = new AntPathMatcher();
|
return ANT_PATH_MATCHER.match(pattern, url);
|
||||||
return matcher.match(pattern, url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.dromara.common.core.utils.sql;
|
package org.dromara.common.core.utils.sql;
|
||||||
|
|
||||||
|
import cn.hutool.core.exceptions.UtilException;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
@@ -15,7 +16,7 @@ public class SqlUtil {
|
|||||||
/**
|
/**
|
||||||
* 定义常用的 sql关键字
|
* 定义常用的 sql关键字
|
||||||
*/
|
*/
|
||||||
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()";
|
public static final String SQL_REGEX = "\u000B|%0A|and |extractvalue|updatexml|sleep|information_schema|exec |insert |select |delete |update |drop |count |chr |mid |master |truncate |char |declare |or |union |like |+|/*|user()";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
|
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
|
||||||
@@ -46,10 +47,11 @@ public class SqlUtil {
|
|||||||
if (StringUtils.isEmpty(value)) {
|
if (StringUtils.isEmpty(value)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
String normalizedValue = value.replaceAll("\\p{Z}|\\s", "");
|
||||||
String[] sqlKeywords = StringUtils.split(SQL_REGEX, "\\|");
|
String[] sqlKeywords = StringUtils.split(SQL_REGEX, "\\|");
|
||||||
for (String sqlKeyword : sqlKeywords) {
|
for (String sqlKeyword : sqlKeywords) {
|
||||||
if (StringUtils.indexOfIgnoreCase(value, sqlKeyword) > -1) {
|
if (StringUtils.indexOf(normalizedValue, sqlKeyword) > -1) {
|
||||||
throw new IllegalArgumentException("参数存在SQL注入风险");
|
throw new UtilException("请求参数包含敏感关键词'" + sqlKeyword + "',可能存在安全风险");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ public class ExcelBigNumberConvert implements Converter<Long> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WriteCellData<Object> convertToExcelData(Long object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
public WriteCellData<Object> convertToExcelData(Long object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||||
|
if (ObjectUtil.isNull(object)) {
|
||||||
|
return new WriteCellData<>("");
|
||||||
|
}
|
||||||
if (ObjectUtil.isNotNull(object)) {
|
if (ObjectUtil.isNotNull(object)) {
|
||||||
String str = Convert.toStr(object);
|
String str = Convert.toStr(object);
|
||||||
if (str.length() > 15) {
|
if (str.length() > 15) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 枚举格式化转换处理
|
* 枚举格式化转换处理
|
||||||
@@ -25,6 +26,9 @@ import java.util.Map;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class ExcelEnumConvert implements Converter<Object> {
|
public class ExcelEnumConvert implements Converter<Object> {
|
||||||
|
|
||||||
|
private static final Map<Field, Map<Object, String>> ENUM_MAP_CACHE = new ConcurrentHashMap<>();
|
||||||
|
private static final Map<Field, Map<Object, Object>> ENUM_REVERSE_MAP_CACHE = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<Object> supportJavaTypeKey() {
|
public Class<Object> supportJavaTypeKey() {
|
||||||
return Object.class;
|
return Object.class;
|
||||||
@@ -50,10 +54,15 @@ public class ExcelEnumConvert implements Converter<Object> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Map<Object, String> enumCodeToTextMap = beforeConvert(contentProperty);
|
Map<Object, String> enumCodeToTextMap = beforeConvert(contentProperty);
|
||||||
// 从Java输出至Excel是code转text
|
// 从Java输出至Excel是code转text,从Excel转Java应将text与code对调
|
||||||
// 因此从Excel转Java应该将text与code对调
|
Map<Object, Object> enumTextToCodeMap = ENUM_REVERSE_MAP_CACHE.computeIfAbsent(
|
||||||
Map<Object, Object> enumTextToCodeMap = new HashMap<>();
|
contentProperty.getField(),
|
||||||
enumCodeToTextMap.forEach((key, value) -> enumTextToCodeMap.put(value, key));
|
f -> {
|
||||||
|
Map<Object, Object> reverseMap = new HashMap<>();
|
||||||
|
enumCodeToTextMap.forEach((key, value) -> reverseMap.put(value, key));
|
||||||
|
return reverseMap;
|
||||||
|
}
|
||||||
|
);
|
||||||
// 应该从text -> code中查找
|
// 应该从text -> code中查找
|
||||||
Object codeValue = enumTextToCodeMap.get(textValue);
|
Object codeValue = enumTextToCodeMap.get(textValue);
|
||||||
return Convert.convert(contentProperty.getField().getType(), codeValue);
|
return Convert.convert(contentProperty.getField().getType(), codeValue);
|
||||||
@@ -70,15 +79,17 @@ public class ExcelEnumConvert implements Converter<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<Object, String> beforeConvert(ExcelContentProperty contentProperty) {
|
private Map<Object, String> beforeConvert(ExcelContentProperty contentProperty) {
|
||||||
ExcelEnumFormat anno = getAnnotation(contentProperty.getField());
|
return ENUM_MAP_CACHE.computeIfAbsent(contentProperty.getField(), field -> {
|
||||||
Map<Object, String> enumValueMap = new HashMap<>();
|
ExcelEnumFormat anno = getAnnotation(field);
|
||||||
Enum<?>[] enumConstants = anno.enumClass().getEnumConstants();
|
Map<Object, String> enumValueMap = new HashMap<>();
|
||||||
for (Enum<?> enumConstant : enumConstants) {
|
Enum<?>[] enumConstants = anno.enumClass().getEnumConstants();
|
||||||
Object codeValue = ReflectUtils.invokeGetter(enumConstant, anno.codeField());
|
for (Enum<?> enumConstant : enumConstants) {
|
||||||
String textValue = ReflectUtils.invokeGetter(enumConstant, anno.textField());
|
Object codeValue = ReflectUtils.invokeGetter(enumConstant, anno.codeField());
|
||||||
enumValueMap.put(codeValue, textValue);
|
String textValue = ReflectUtils.invokeGetter(enumConstant, anno.textField());
|
||||||
}
|
enumValueMap.put(codeValue, textValue);
|
||||||
return enumValueMap;
|
}
|
||||||
|
return enumValueMap;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExcelEnumFormat getAnnotation(Field field) {
|
private ExcelEnumFormat getAnnotation(Field field) {
|
||||||
|
|||||||
@@ -73,6 +73,10 @@ public class DefaultExcelListener<T> extends AnalysisEventListener<T> implements
|
|||||||
log.error(errMsg);
|
log.error(errMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (errMsg == null) {
|
||||||
|
errMsg = StrUtil.format("第{}行数据异常: {}", context.readRowHolder().getRowIndex() + 1, exception.getMessage());
|
||||||
|
log.error(errMsg, exception);
|
||||||
|
}
|
||||||
excelResult.getErrorList().add(errMsg);
|
excelResult.getErrorList().add(errMsg);
|
||||||
throw new ExcelAnalysisException(errMsg);
|
throw new ExcelAnalysisException(errMsg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class DefaultExcelResult<T> implements ExcelResult<T> {
|
|||||||
if (errorCount == 0) {
|
if (errorCount == 0) {
|
||||||
return StrUtil.format("恭喜您,全部读取成功!共{}条", successCount);
|
return StrUtil.format("恭喜您,全部读取成功!共{}条", successCount);
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return StrUtil.format("共{}条,成功导入{}条,错误{}条", successCount + errorCount, successCount, errorCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,9 +182,10 @@ public class ExcelDownHandler implements SheetWriteHandler {
|
|||||||
Sheet linkedOptionsDataSheet = workbook.createSheet(WorkbookUtil.createSafeSheetName(linkedOptionsSheetName));
|
Sheet linkedOptionsDataSheet = workbook.createSheet(WorkbookUtil.createSafeSheetName(linkedOptionsSheetName));
|
||||||
// 将下拉表隐藏
|
// 将下拉表隐藏
|
||||||
workbook.setSheetHidden(workbook.getSheetIndex(linkedOptionsDataSheet), true);
|
workbook.setSheetHidden(workbook.getSheetIndex(linkedOptionsDataSheet), true);
|
||||||
// 选项数据
|
// 选项数据(使用副本,避免修改调用方的原始数据)
|
||||||
List<String> firstOptions = options.getOptions();
|
List<String> firstOptions = options.getOptions();
|
||||||
Map<String, List<String>> secoundOptionsMap = options.getNextOptions();
|
Map<String, List<String>> secoundOptionsMap = new HashMap<>();
|
||||||
|
options.getNextOptions().forEach((k, v) -> secoundOptionsMap.put(k, new ArrayList<>(v)));
|
||||||
|
|
||||||
// 采用按行填充数据的方式,避免出现数据无法写入的问题
|
// 采用按行填充数据的方式,避免出现数据无法写入的问题
|
||||||
// Attempting to write a row in the range that is already written to disk
|
// Attempting to write a row in the range that is already written to disk
|
||||||
@@ -378,7 +379,6 @@ public class ExcelDownHandler implements SheetWriteHandler {
|
|||||||
//选定提示
|
//选定提示
|
||||||
dataValidation.createPromptBox("填写说明:", "填写内容只能为下拉中数据,其他数据将导致导入失败");
|
dataValidation.createPromptBox("填写说明:", "填写内容只能为下拉中数据,其他数据将导致导入失败");
|
||||||
dataValidation.setShowPromptBox(true);
|
dataValidation.setShowPromptBox(true);
|
||||||
sheet.addValidationData(dataValidation);
|
|
||||||
} else {
|
} else {
|
||||||
dataValidation.setSuppressDropDownArrow(false);
|
dataValidation.setSuppressDropDownArrow(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,6 +99,9 @@ public class DataWriteHandler implements SheetWriteHandler, CellWriteHandler {
|
|||||||
}
|
}
|
||||||
ExcelRequired excelRequired = field.getAnnotation(ExcelRequired.class);
|
ExcelRequired excelRequired = field.getAnnotation(ExcelRequired.class);
|
||||||
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
|
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
|
||||||
|
if (excelProperty == null || excelProperty.value().length == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
requiredMap.put(excelProperty.value()[0], excelRequired.fontColor().getIndex());
|
requiredMap.put(excelProperty.value()[0], excelRequired.fontColor().getIndex());
|
||||||
}
|
}
|
||||||
return requiredMap;
|
return requiredMap;
|
||||||
@@ -116,6 +119,9 @@ public class DataWriteHandler implements SheetWriteHandler, CellWriteHandler {
|
|||||||
}
|
}
|
||||||
ExcelNotation excelNotation = field.getAnnotation(ExcelNotation.class);
|
ExcelNotation excelNotation = field.getAnnotation(ExcelNotation.class);
|
||||||
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
|
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
|
||||||
|
if (excelProperty == null || excelProperty.value().length == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
notationMap.put(excelProperty.value()[0], excelNotation.value());
|
notationMap.put(excelProperty.value()[0], excelNotation.value());
|
||||||
}
|
}
|
||||||
return notationMap;
|
return notationMap;
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public class ExcelUtil {
|
|||||||
ServletOutputStream os = response.getOutputStream();
|
ServletOutputStream os = response.getOutputStream();
|
||||||
exportExcel(list, sheetName, clazz, false, os, null);
|
exportExcel(list, sheetName, clazz, false, os, null);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("导出Excel异常");
|
throw new RuntimeException("导出Excel异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ public class ExcelUtil {
|
|||||||
ServletOutputStream os = response.getOutputStream();
|
ServletOutputStream os = response.getOutputStream();
|
||||||
exportExcel(list, sheetName, clazz, false, os, options);
|
exportExcel(list, sheetName, clazz, false, os, options);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("导出Excel异常");
|
throw new RuntimeException("导出Excel异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ public class ExcelUtil {
|
|||||||
ServletOutputStream os = response.getOutputStream();
|
ServletOutputStream os = response.getOutputStream();
|
||||||
exportExcel(list, sheetName, clazz, merge, os, null);
|
exportExcel(list, sheetName, clazz, merge, os, null);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("导出Excel异常");
|
throw new RuntimeException("导出Excel异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ public class ExcelUtil {
|
|||||||
ServletOutputStream os = response.getOutputStream();
|
ServletOutputStream os = response.getOutputStream();
|
||||||
exportExcel(list, sheetName, clazz, merge, os, options);
|
exportExcel(list, sheetName, clazz, merge, os, options);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("导出Excel异常");
|
throw new RuntimeException("导出Excel异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +261,7 @@ public class ExcelUtil {
|
|||||||
ServletOutputStream os = response.getOutputStream();
|
ServletOutputStream os = response.getOutputStream();
|
||||||
exportTemplate(data, templatePath, os);
|
exportTemplate(data, templatePath, os);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("导出Excel异常");
|
throw new RuntimeException("导出Excel异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,13 +283,16 @@ public class ExcelUtil {
|
|||||||
.registerConverter(new ExcelBigNumberConvert())
|
.registerConverter(new ExcelBigNumberConvert())
|
||||||
.registerWriteHandler(new DataWriteHandler(data.getFirst().getClass()))
|
.registerWriteHandler(new DataWriteHandler(data.getFirst().getClass()))
|
||||||
.build();
|
.build();
|
||||||
WriteSheet writeSheet = FesodSheet.writerSheet().build();
|
try {
|
||||||
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
WriteSheet writeSheet = FesodSheet.writerSheet().build();
|
||||||
// 单表多数据导出 模板格式为 {.属性}
|
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
||||||
for (T d : data) {
|
// 单表多数据导出 模板格式为 {.属性}
|
||||||
excelWriter.fill(d, fillConfig, writeSheet);
|
for (T d : data) {
|
||||||
|
excelWriter.fill(d, fillConfig, writeSheet);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
excelWriter.finish();
|
||||||
}
|
}
|
||||||
excelWriter.finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -311,7 +314,7 @@ public class ExcelUtil {
|
|||||||
ServletOutputStream os = response.getOutputStream();
|
ServletOutputStream os = response.getOutputStream();
|
||||||
exportTemplateMultiList(data, templatePath, os);
|
exportTemplateMultiList(data, templatePath, os);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("导出Excel异常");
|
throw new RuntimeException("导出Excel异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,7 +337,7 @@ public class ExcelUtil {
|
|||||||
ServletOutputStream os = response.getOutputStream();
|
ServletOutputStream os = response.getOutputStream();
|
||||||
exportTemplateMultiSheet(data, templatePath, os);
|
exportTemplateMultiSheet(data, templatePath, os);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("导出Excel异常");
|
throw new RuntimeException("导出Excel异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,18 +358,21 @@ public class ExcelUtil {
|
|||||||
// 大数值自动转换 防止失真
|
// 大数值自动转换 防止失真
|
||||||
.registerConverter(new ExcelBigNumberConvert())
|
.registerConverter(new ExcelBigNumberConvert())
|
||||||
.build();
|
.build();
|
||||||
WriteSheet writeSheet = FesodSheet.writerSheet().build();
|
try {
|
||||||
for (Map.Entry<String, Object> map : data.entrySet()) {
|
WriteSheet writeSheet = FesodSheet.writerSheet().build();
|
||||||
// 设置列表后续还有数据
|
for (Map.Entry<String, Object> map : data.entrySet()) {
|
||||||
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
// 设置列表后续还有数据
|
||||||
if (map.getValue() instanceof Collection) {
|
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
||||||
// 多表导出必须使用 FillWrapper
|
if (map.getValue() instanceof Collection) {
|
||||||
excelWriter.fill(new FillWrapper(map.getKey(), (Collection<?>) map.getValue()), fillConfig, writeSheet);
|
// 多表导出必须使用 FillWrapper
|
||||||
} else {
|
excelWriter.fill(new FillWrapper(map.getKey(), (Collection<?>) map.getValue()), fillConfig, writeSheet);
|
||||||
excelWriter.fill(map.getValue(), fillConfig, writeSheet);
|
} else {
|
||||||
|
excelWriter.fill(map.getValue(), fillConfig, writeSheet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
excelWriter.finish();
|
||||||
}
|
}
|
||||||
excelWriter.finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -386,20 +392,23 @@ public class ExcelUtil {
|
|||||||
// 大数值自动转换 防止失真
|
// 大数值自动转换 防止失真
|
||||||
.registerConverter(new ExcelBigNumberConvert())
|
.registerConverter(new ExcelBigNumberConvert())
|
||||||
.build();
|
.build();
|
||||||
for (int i = 0; i < data.size(); i++) {
|
try {
|
||||||
WriteSheet writeSheet = FesodSheet.writerSheet(i).build();
|
for (int i = 0; i < data.size(); i++) {
|
||||||
for (Map.Entry<String, Object> map : data.get(i).entrySet()) {
|
WriteSheet writeSheet = FesodSheet.writerSheet(i).build();
|
||||||
// 设置列表后续还有数据
|
for (Map.Entry<String, Object> map : data.get(i).entrySet()) {
|
||||||
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
// 设置列表后续还有数据
|
||||||
if (map.getValue() instanceof Collection) {
|
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
||||||
// 多表导出必须使用 FillWrapper
|
if (map.getValue() instanceof Collection) {
|
||||||
excelWriter.fill(new FillWrapper(map.getKey(), (Collection<?>) map.getValue()), fillConfig, writeSheet);
|
// 多表导出必须使用 FillWrapper
|
||||||
} else {
|
excelWriter.fill(new FillWrapper(map.getKey(), (Collection<?>) map.getValue()), fillConfig, writeSheet);
|
||||||
excelWriter.fill(map.getValue(), writeSheet);
|
} else {
|
||||||
|
excelWriter.fill(map.getValue(), writeSheet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
excelWriter.finish();
|
||||||
}
|
}
|
||||||
excelWriter.finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class BigNumberSerializer extends NumberSerializer {
|
|||||||
@Override
|
@Override
|
||||||
public void serialize(Number value, JsonGenerator gen, SerializationContext provider) {
|
public void serialize(Number value, JsonGenerator gen, SerializationContext provider) {
|
||||||
// 超出范围 序列化为字符串
|
// 超出范围 序列化为字符串
|
||||||
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 {
|
||||||
gen.writeString(value.toString());
|
gen.writeString(value.toString());
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public enum DataScopeType {
|
|||||||
/**
|
/**
|
||||||
* 自定数据权限
|
* 自定数据权限
|
||||||
*/
|
*/
|
||||||
CUSTOM("2", " #{#deptName} IN ( #{@sdss.getRoleCustom( #user.roleId )} ) ", " 1 = 0 "),
|
CUSTOM("2", " #{#deptName} IN ( #{@sdss.getRoleCustom( #roleId )} ) ", " 1 = 0 "),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门数据权限
|
* 部门数据权限
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class InjectionMetaObjectHandler implements MetaObjectHandler {
|
|||||||
this.strictInsertFill(metaObject, "updateTime", Date.class, date);
|
this.strictInsertFill(metaObject, "updateTime", Date.class, date);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED);
|
throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,17 +81,14 @@ public class InjectionMetaObjectHandler implements MetaObjectHandler {
|
|||||||
baseEntity.setUpdateTime(current);
|
baseEntity.setUpdateTime(current);
|
||||||
|
|
||||||
// 获取当前登录用户的ID,并填充更新人信息
|
// 获取当前登录用户的ID,并填充更新人信息
|
||||||
Long userId = LoginHelper.getUserId();
|
LoginUser loginUser = getLoginUser();
|
||||||
if (ObjectUtil.isNotNull(userId)) {
|
Long userId = ObjectUtil.isNotNull(loginUser) ? loginUser.getUserId() : DEFAULT_USER_ID;
|
||||||
baseEntity.setUpdateBy(userId);
|
baseEntity.setUpdateBy(userId);
|
||||||
} else {
|
|
||||||
baseEntity.setUpdateBy(DEFAULT_USER_ID);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
|
this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED);
|
throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ public class PlusDataPermissionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (RoleDTO role : scopeRoles) {
|
for (RoleDTO role : scopeRoles) {
|
||||||
user.setRoleId(role.getRoleId());
|
context.setVariable("roleId", role.getRoleId());
|
||||||
// 获取角色权限泛型
|
// 获取角色权限泛型
|
||||||
DataScopeType type = DataScopeType.findCode(role.getDataScope());
|
DataScopeType type = DataScopeType.findCode(role.getDataScope());
|
||||||
if (ObjectUtil.isNull(type)) {
|
if (ObjectUtil.isNull(type)) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.dromara.common.mybatis.helper;
|
|||||||
|
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
||||||
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
@@ -14,6 +15,7 @@ import java.sql.DatabaseMetaData;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库助手
|
* 数据库助手
|
||||||
@@ -24,6 +26,7 @@ import java.util.List;
|
|||||||
public class DataBaseHelper {
|
public class DataBaseHelper {
|
||||||
|
|
||||||
private static final DynamicRoutingDataSource DS = SpringUtils.getBean(DynamicRoutingDataSource.class);
|
private static final DynamicRoutingDataSource DS = SpringUtils.getBean(DynamicRoutingDataSource.class);
|
||||||
|
private static final Map<String, DataBaseType> DB_TYPE_CACHE = new java.util.concurrent.ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前数据源对应的数据库类型
|
* 获取当前数据源对应的数据库类型
|
||||||
@@ -37,13 +40,17 @@ public class DataBaseHelper {
|
|||||||
*/
|
*/
|
||||||
public static DataBaseType getDataBaseType() {
|
public static DataBaseType getDataBaseType() {
|
||||||
DataSource dataSource = DS.determineDataSource();
|
DataSource dataSource = DS.determineDataSource();
|
||||||
try (Connection conn = dataSource.getConnection()) {
|
String dsKey = DynamicDataSourceContextHolder.peek();
|
||||||
DatabaseMetaData metaData = conn.getMetaData();
|
final String key = dsKey != null ? dsKey : "primary";
|
||||||
String databaseProductName = metaData.getDatabaseProductName();
|
return DB_TYPE_CACHE.computeIfAbsent(key, k -> {
|
||||||
return DataBaseType.find(databaseProductName);
|
try (Connection conn = dataSource.getConnection()) {
|
||||||
} catch (SQLException e) {
|
DatabaseMetaData metaData = conn.getMetaData();
|
||||||
throw new RuntimeException("获取数据库类型失败", e);
|
String databaseProductName = metaData.getDatabaseProductName();
|
||||||
}
|
return DataBaseType.find(databaseProductName);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException("获取数据库类型失败", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,9 +12,10 @@ import org.dromara.common.mybatis.core.domain.DataPermissionAccess;
|
|||||||
import org.dromara.common.core.utils.reflect.ReflectUtils;
|
import org.dromara.common.core.utils.reflect.ReflectUtils;
|
||||||
import org.dromara.common.mybatis.annotation.DataPermission;
|
import org.dromara.common.mybatis.annotation.DataPermission;
|
||||||
|
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.Deque;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Stack;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,7 +31,7 @@ public class DataPermissionHelper {
|
|||||||
private static final String DATA_PERMISSION_KEY = "data:permission";
|
private static final String DATA_PERMISSION_KEY = "data:permission";
|
||||||
private static final String ACCESS_KEY = "data:permission:access";
|
private static final String ACCESS_KEY = "data:permission:access";
|
||||||
|
|
||||||
private static final ThreadLocal<Stack<Integer>> REENTRANT_IGNORE = ThreadLocal.withInitial(Stack::new);
|
private static final ThreadLocal<Deque<Integer>> REENTRANT_IGNORE = ThreadLocal.withInitial(ArrayDeque::new);
|
||||||
|
|
||||||
private static final ThreadLocal<DataPermission> PERMISSION_CACHE = new ThreadLocal<>();
|
private static final ThreadLocal<DataPermission> PERMISSION_CACHE = new ThreadLocal<>();
|
||||||
|
|
||||||
@@ -116,7 +117,7 @@ public class DataPermissionHelper {
|
|||||||
if (attribute instanceof Map map) {
|
if (attribute instanceof Map map) {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
throw new NullPointerException("data permission context type exception");
|
throw new IllegalStateException("data permission context type exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -144,7 +145,7 @@ public class DataPermissionHelper {
|
|||||||
} else {
|
} else {
|
||||||
ignoreStrategy.setDataPermission(true);
|
ignoreStrategy.setDataPermission(true);
|
||||||
}
|
}
|
||||||
Stack<Integer> reentrantStack = REENTRANT_IGNORE.get();
|
Deque<Integer> reentrantStack = REENTRANT_IGNORE.get();
|
||||||
reentrantStack.push(reentrantStack.size() + 1);
|
reentrantStack.push(reentrantStack.size() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,7 +160,7 @@ public class DataPermissionHelper {
|
|||||||
&& !Boolean.TRUE.equals(ignoreStrategy.getIllegalSql())
|
&& !Boolean.TRUE.equals(ignoreStrategy.getIllegalSql())
|
||||||
&& !Boolean.TRUE.equals(ignoreStrategy.getTenantLine())
|
&& !Boolean.TRUE.equals(ignoreStrategy.getTenantLine())
|
||||||
&& CollectionUtil.isEmpty(ignoreStrategy.getOthers());
|
&& CollectionUtil.isEmpty(ignoreStrategy.getOthers());
|
||||||
Stack<Integer> reentrantStack = REENTRANT_IGNORE.get();
|
Deque<Integer> reentrantStack = REENTRANT_IGNORE.get();
|
||||||
boolean empty = reentrantStack.isEmpty() || reentrantStack.pop() == 1;
|
boolean empty = reentrantStack.isEmpty() || reentrantStack.pop() == 1;
|
||||||
if (noOtherIgnoreStrategy && empty) {
|
if (noOtherIgnoreStrategy && empty) {
|
||||||
InterceptorIgnoreHelper.clearIgnoreStrategy();
|
InterceptorIgnoreHelper.clearIgnoreStrategy();
|
||||||
|
|||||||
@@ -241,9 +241,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
|||||||
genTable.setOptions(options);
|
genTable.setOptions(options);
|
||||||
int row = baseMapper.updateById(genTable);
|
int row = baseMapper.updateById(genTable);
|
||||||
if (row > 0) {
|
if (row > 0) {
|
||||||
for (GenTableColumn cenTableColumn : genTable.getColumns()) {
|
genTableColumnMapper.updateBatchById(genTable.getColumns());
|
||||||
genTableColumnMapper.updateById(cenTableColumn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,6 +287,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
log.error("导入失败", e);
|
||||||
throw new ServiceException("导入失败:" + e.getMessage());
|
throw new ServiceException("导入失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -471,7 +470,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
|||||||
zip.flush();
|
zip.flush();
|
||||||
zip.closeEntry();
|
zip.closeEntry();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("渲染模板失败,表名:" + table.getTableName(), e);
|
log.error("渲染模板失败,表名:{}", table.getTableName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ public class GenUtils {
|
|||||||
String text = replacementm;
|
String text = replacementm;
|
||||||
for (String searchString : searchList) {
|
for (String searchString : searchList) {
|
||||||
if (replacementm.startsWith(searchString)) {
|
if (replacementm.startsWith(searchString)) {
|
||||||
text = replacementm.replaceFirst(searchString, StringUtils.EMPTY);
|
text = StringUtils.removeStart(replacementm, searchString);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,6 +220,10 @@ public class GenUtils {
|
|||||||
public static Integer getColumnLength(String columnType) {
|
public static Integer getColumnLength(String columnType) {
|
||||||
if (StringUtils.indexOf(columnType, "(") > 0) {
|
if (StringUtils.indexOf(columnType, "(") > 0) {
|
||||||
String length = StringUtils.substringBetween(columnType, "(", ")");
|
String length = StringUtils.substringBetween(columnType, "(", ")");
|
||||||
|
// 处理 decimal(10,2) 这类带精度的类型,只取长度部分
|
||||||
|
if (length.contains(",")) {
|
||||||
|
length = StringUtils.substringBefore(length, ",");
|
||||||
|
}
|
||||||
return Integer.valueOf(length);
|
return Integer.valueOf(length);
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo>, MPJBa
|
|||||||
default List<SysUserExportVo> selectUserExportList(SysUserBo user, List<Long> deptIds) {
|
default List<SysUserExportVo> selectUserExportList(SysUserBo user, List<Long> deptIds) {
|
||||||
MPJLambdaWrapper<SysUser> wrapper = JoinWrappers.lambda("u", SysUser.class)
|
MPJLambdaWrapper<SysUser> wrapper = JoinWrappers.lambda("u", SysUser.class)
|
||||||
.selectAll(SysUser.class)
|
.selectAll(SysUser.class)
|
||||||
.selectAs(SysDept::getDeptName, SysUserExportVo::getDeptName)
|
|
||||||
.selectAs("u1", SysUser::getUserName, SysUserExportVo::getLeaderName)
|
.selectAs("u1", SysUser::getUserName, SysUserExportVo::getLeaderName)
|
||||||
.leftJoin(SysDept.class, "d", SysDept::getDeptId, SysUser::getDeptId)
|
.leftJoin(SysDept.class, "d", SysDept::getDeptId, SysUser::getDeptId)
|
||||||
.leftJoin(SysUser.class, "u1", SysUser::getUserId, SysDept::getLeader)
|
.leftJoin(SysUser.class, "u1", SysUser::getUserId, SysDept::getLeader)
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
|
|||||||
SysConfig config = MapstructUtils.convert(bo, SysConfig.class);
|
SysConfig config = MapstructUtils.convert(bo, SysConfig.class);
|
||||||
if (config.getConfigId() != null) {
|
if (config.getConfigId() != null) {
|
||||||
SysConfig temp = baseMapper.selectById(config.getConfigId());
|
SysConfig temp = baseMapper.selectById(config.getConfigId());
|
||||||
if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey())) {
|
if (ObjectUtil.isNotNull(temp) && !StringUtils.equals(temp.getConfigKey(), config.getConfigKey())) {
|
||||||
CacheUtils.evict(CacheNames.SYS_CONFIG, temp.getConfigKey());
|
CacheUtils.evict(CacheNames.SYS_CONFIG, temp.getConfigKey());
|
||||||
}
|
}
|
||||||
row = baseMapper.updateById(config);
|
row = baseMapper.updateById(config);
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||||||
@Override
|
@Override
|
||||||
public Long selectDeptLeaderById(Long deptId) {
|
public Long selectDeptLeaderById(Long deptId) {
|
||||||
SysDeptVo vo = SpringUtils.getAopProxy(this).selectDeptById(deptId);
|
SysDeptVo vo = SpringUtils.getAopProxy(this).selectDeptById(deptId);
|
||||||
return vo.getLeader();
|
return ObjectUtil.isNull(vo) ? null : vo.getLeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -312,7 +312,10 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||||||
@Override
|
@Override
|
||||||
public int insertDept(SysDeptBo bo) {
|
public int insertDept(SysDeptBo bo) {
|
||||||
SysDept info = baseMapper.selectById(bo.getParentId());
|
SysDept info = baseMapper.selectById(bo.getParentId());
|
||||||
// 如果父节点不为正常状态,则不允许新增子节点
|
// 如果父节点不存在或不为正常状态,则不允许新增子节点
|
||||||
|
if (ObjectUtil.isNull(info)) {
|
||||||
|
throw new ServiceException("父部门不存在");
|
||||||
|
}
|
||||||
if (!SystemConstants.NORMAL.equals(info.getStatus())) {
|
if (!SystemConstants.NORMAL.equals(info.getStatus())) {
|
||||||
throw new ServiceException("部门停用,不允许新增");
|
throw new ServiceException("部门停用,不允许新增");
|
||||||
}
|
}
|
||||||
@@ -390,7 +393,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||||||
for (SysDept child : children) {
|
for (SysDept child : children) {
|
||||||
SysDept dept = new SysDept();
|
SysDept dept = new SysDept();
|
||||||
dept.setDeptId(child.getDeptId());
|
dept.setDeptId(child.getDeptId());
|
||||||
dept.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
|
dept.setAncestors(StringUtils.replaceOnce(child.getAncestors(), oldAncestors, newAncestors));
|
||||||
list.add(dept);
|
list.add(dept);
|
||||||
}
|
}
|
||||||
if (CollUtil.isNotEmpty(list)) {
|
if (CollUtil.isNotEmpty(list)) {
|
||||||
@@ -408,7 +411,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||||||
*/
|
*/
|
||||||
@Caching(evict = {
|
@Caching(evict = {
|
||||||
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId"),
|
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId"),
|
||||||
@CacheEvict(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, key = "#deptId")
|
@CacheEvict(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, allEntries = true)
|
||||||
})
|
})
|
||||||
@Override
|
@Override
|
||||||
public int deleteDeptById(Long deptId) {
|
public int deleteDeptById(Long deptId) {
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
|||||||
@Override
|
@Override
|
||||||
public List<SysDictDataVo> selectDictDataByType(String dictType) {
|
public List<SysDictDataVo> selectDictDataByType(String dictType) {
|
||||||
List<SysDictDataVo> dictDatas = dictDataMapper.selectDictDataByType(dictType);
|
List<SysDictDataVo> dictDatas = dictDataMapper.selectDictDataByType(dictType);
|
||||||
return CollUtil.isNotEmpty(dictDatas) ? dictDatas : null;
|
return CollUtil.isNotEmpty(dictDatas) ? dictDatas : Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user