mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2026-05-11 06:12:09 +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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -547,4 +548,12 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||||||
return Strings.CS.containsAny(cs, searchCharSequences);
|
return Strings.CS.containsAny(cs, searchCharSequences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将一个字符串替换为较大字符串内的另一个字符串,一次
|
||||||
|
*/
|
||||||
|
public static String replaceOnce(final String text, final String searchString, final String replacement) {
|
||||||
|
return Strings.CS.replaceOnce(text, searchString, replacement);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,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()";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
|
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class DefaultExcelListener<T> extends AnalysisEventListener<T> implements
|
|||||||
errMsg = StrUtil.format("第{}行-第{}列-表头{}: 解析异常<br/>",
|
errMsg = StrUtil.format("第{}行-第{}列-表头{}: 解析异常<br/>",
|
||||||
rowIndex + 1, columnIndex + 1, headMap.get(columnIndex));
|
rowIndex + 1, columnIndex + 1, headMap.get(columnIndex));
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.error(errMsg);
|
log.warn(errMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (exception instanceof ConstraintViolationException constraintViolationException) {
|
if (exception instanceof ConstraintViolationException constraintViolationException) {
|
||||||
@@ -70,9 +70,13 @@ public class DefaultExcelListener<T> extends AnalysisEventListener<T> implements
|
|||||||
String constraintViolationsMsg = StreamUtils.join(constraintViolations, ConstraintViolation::getMessage, ", ");
|
String constraintViolationsMsg = StreamUtils.join(constraintViolations, ConstraintViolation::getMessage, ", ");
|
||||||
errMsg = StrUtil.format("第{}行数据校验异常: {}", context.readRowHolder().getRowIndex() + 1, constraintViolationsMsg);
|
errMsg = StrUtil.format("第{}行数据校验异常: {}", context.readRowHolder().getRowIndex() + 1, constraintViolationsMsg);
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.error(errMsg);
|
log.warn(errMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (errMsg == null) {
|
||||||
|
errMsg = StrUtil.format("第{}行数据异常: {}", context.readRowHolder().getRowIndex() + 1, exception.getMessage());
|
||||||
|
log.warn(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import cn.hutool.core.util.ArrayUtil;
|
|||||||
import cn.hutool.core.util.EnumUtil;
|
import cn.hutool.core.util.EnumUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.fesod.sheet.metadata.FieldCache;
|
import org.apache.fesod.sheet.metadata.FieldCache;
|
||||||
import org.apache.fesod.sheet.metadata.FieldWrapper;
|
import org.apache.fesod.sheet.metadata.FieldWrapper;
|
||||||
import org.apache.fesod.sheet.util.ClassUtils;
|
import org.apache.fesod.sheet.util.ClassUtils;
|
||||||
import org.apache.fesod.sheet.write.handler.SheetWriteHandler;
|
import org.apache.fesod.sheet.write.handler.SheetWriteHandler;
|
||||||
import org.apache.fesod.sheet.write.metadata.holder.WriteSheetHolder;
|
import org.apache.fesod.sheet.write.metadata.holder.WriteSheetHolder;
|
||||||
import org.apache.fesod.sheet.write.metadata.holder.WriteWorkbookHolder;
|
import org.apache.fesod.sheet.write.metadata.holder.WriteWorkbookHolder;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||||
import org.apache.poi.ss.util.WorkbookUtil;
|
import org.apache.poi.ss.util.WorkbookUtil;
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -3,17 +3,17 @@ package org.dromara.common.excel.utils;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.io.resource.ClassPathResource;
|
import cn.hutool.core.io.resource.ClassPathResource;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import jakarta.servlet.ServletOutputStream;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.apache.fesod.sheet.ExcelWriter;
|
|
||||||
import org.apache.fesod.sheet.FesodSheet;
|
import org.apache.fesod.sheet.FesodSheet;
|
||||||
|
import org.apache.fesod.sheet.ExcelWriter;
|
||||||
import org.apache.fesod.sheet.write.builder.ExcelWriterSheetBuilder;
|
import org.apache.fesod.sheet.write.builder.ExcelWriterSheetBuilder;
|
||||||
import org.apache.fesod.sheet.write.metadata.WriteSheet;
|
import org.apache.fesod.sheet.write.metadata.WriteSheet;
|
||||||
import org.apache.fesod.sheet.write.metadata.fill.FillConfig;
|
import org.apache.fesod.sheet.write.metadata.fill.FillConfig;
|
||||||
import org.apache.fesod.sheet.write.metadata.fill.FillWrapper;
|
import org.apache.fesod.sheet.write.metadata.fill.FillWrapper;
|
||||||
import org.apache.fesod.sheet.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
import org.apache.fesod.sheet.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
||||||
|
import jakarta.servlet.ServletOutputStream;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
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;
|
||||||
@@ -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 "),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门数据权限
|
* 部门数据权限
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import java.util.Date;
|
|||||||
* MP注入处理器
|
* MP注入处理器
|
||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
|
* @date 2021/4/25
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class InjectionMetaObjectHandler implements MetaObjectHandler {
|
public class InjectionMetaObjectHandler implements MetaObjectHandler {
|
||||||
@@ -62,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class PlusDataPermissionHandler {
|
|||||||
public Expression getSqlSegment(Expression where, boolean isSelect) {
|
public Expression getSqlSegment(Expression where, boolean isSelect) {
|
||||||
try {
|
try {
|
||||||
LoginUser currentUser = currentUser();
|
LoginUser currentUser = currentUser();
|
||||||
// 如果是超级管理员,则不过滤数据
|
// 如果是超级管理员或租户管理员,则不过滤数据
|
||||||
if (LoginHelper.isSuperAdmin()) {
|
if (LoginHelper.isSuperAdmin()) {
|
||||||
return where;
|
return where;
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,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)) {
|
||||||
@@ -175,7 +175,13 @@ public class PlusDataPermissionHandler {
|
|||||||
return StringUtils.EMPTY;
|
return StringUtils.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前登录用户信息
|
||||||
|
*
|
||||||
|
* @return 当前登录用户的LoginUser对象,可能为null(如未登录场景)
|
||||||
|
*/
|
||||||
private LoginUser currentUser() {
|
private LoginUser currentUser() {
|
||||||
|
// 从数据权限助手缓存中获取当前登录用户
|
||||||
LoginUser currentUser = DataPermissionHelper.getVariable("user");
|
LoginUser currentUser = DataPermissionHelper.getVariable("user");
|
||||||
if (ObjectUtil.isNull(currentUser)) {
|
if (ObjectUtil.isNull(currentUser)) {
|
||||||
currentUser = LoginHelper.getLoginUser();
|
currentUser = LoginHelper.getLoginUser();
|
||||||
@@ -194,32 +200,6 @@ public class PlusDataPermissionHandler {
|
|||||||
return resolvedAccess;
|
return resolvedAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataPermissionAccess resolveAccess() {
|
|
||||||
HttpServletRequest request = ServletUtils.getRequest();
|
|
||||||
if (request == null) {
|
|
||||||
return DataPermissionAccess.EMPTY;
|
|
||||||
}
|
|
||||||
Object handler = request.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
|
|
||||||
if (!(handler instanceof HandlerMethod handlerMethod)) {
|
|
||||||
return DataPermissionAccess.EMPTY;
|
|
||||||
}
|
|
||||||
Set<String> perms = new LinkedHashSet<>();
|
|
||||||
Set<String> roleKeys = new LinkedHashSet<>();
|
|
||||||
SaCheckPermission saCheckPermission = findAnnotation(handlerMethod, SaCheckPermission.class);
|
|
||||||
if (saCheckPermission != null) {
|
|
||||||
perms.addAll(toSet(saCheckPermission.value()));
|
|
||||||
roleKeys.addAll(toSet(saCheckPermission.orRole()));
|
|
||||||
}
|
|
||||||
SaCheckRole saCheckRole = findAnnotation(handlerMethod, SaCheckRole.class);
|
|
||||||
if (saCheckRole != null) {
|
|
||||||
roleKeys.addAll(toSet(saCheckRole.value()));
|
|
||||||
}
|
|
||||||
if (perms.isEmpty() && roleKeys.isEmpty()) {
|
|
||||||
return DataPermissionAccess.EMPTY;
|
|
||||||
}
|
|
||||||
return new DataPermissionAccess(Set.copyOf(perms), Set.copyOf(roleKeys));
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<RoleDTO> scopeRoles(LoginUser user, DataPermissionAccess access) {
|
private List<RoleDTO> scopeRoles(LoginUser user, DataPermissionAccess access) {
|
||||||
List<RoleDTO> roles = user.getRoles();
|
List<RoleDTO> roles = user.getRoles();
|
||||||
if (!access.constrained()) {
|
if (!access.constrained()) {
|
||||||
@@ -253,6 +233,32 @@ public class PlusDataPermissionHandler {
|
|||||||
return new ArrayList<>(roleMap.values());
|
return new ArrayList<>(roleMap.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DataPermissionAccess resolveAccess() {
|
||||||
|
HttpServletRequest request = ServletUtils.getRequest();
|
||||||
|
if (request == null) {
|
||||||
|
return DataPermissionAccess.EMPTY;
|
||||||
|
}
|
||||||
|
Object handler = request.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
|
||||||
|
if (!(handler instanceof HandlerMethod handlerMethod)) {
|
||||||
|
return DataPermissionAccess.EMPTY;
|
||||||
|
}
|
||||||
|
Set<String> perms = new LinkedHashSet<>();
|
||||||
|
Set<String> roleKeys = new LinkedHashSet<>();
|
||||||
|
SaCheckPermission saCheckPermission = findAnnotation(handlerMethod, SaCheckPermission.class);
|
||||||
|
if (saCheckPermission != null) {
|
||||||
|
perms.addAll(toSet(saCheckPermission.value()));
|
||||||
|
roleKeys.addAll(toSet(saCheckPermission.orRole()));
|
||||||
|
}
|
||||||
|
SaCheckRole saCheckRole = findAnnotation(handlerMethod, SaCheckRole.class);
|
||||||
|
if (saCheckRole != null) {
|
||||||
|
roleKeys.addAll(toSet(saCheckRole.value()));
|
||||||
|
}
|
||||||
|
if (perms.isEmpty() && roleKeys.isEmpty()) {
|
||||||
|
return DataPermissionAccess.EMPTY;
|
||||||
|
}
|
||||||
|
return new DataPermissionAccess(Set.copyOf(perms), Set.copyOf(roleKeys));
|
||||||
|
}
|
||||||
|
|
||||||
private <A extends Annotation> A findAnnotation(HandlerMethod handlerMethod, Class<A> annotationType) {
|
private <A extends Annotation> A findAnnotation(HandlerMethod handlerMethod, Class<A> annotationType) {
|
||||||
A annotation = AnnotationUtil.getAnnotation(handlerMethod.getMethod(), annotationType);
|
A annotation = AnnotationUtil.getAnnotation(handlerMethod.getMethod(), annotationType);
|
||||||
if (annotation != null) {
|
if (annotation != null) {
|
||||||
|
|||||||
@@ -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,8 @@ 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;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库助手
|
* 数据库助手
|
||||||
@@ -24,6 +27,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 ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前数据源对应的数据库类型
|
* 获取当前数据源对应的数据库类型
|
||||||
@@ -37,13 +41,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);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,7 +82,9 @@ public class DataBaseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前加载的数据库名
|
* 获取当前注册的数据源名称列表。
|
||||||
|
*
|
||||||
|
* @return 数据源名称列表
|
||||||
*/
|
*/
|
||||||
public static List<String> getDataSourceNameList() {
|
public static List<String> getDataSourceNameList() {
|
||||||
return new ArrayList<>(DS.getDataSources().keySet());
|
return new ArrayList<>(DS.getDataSources().keySet());
|
||||||
|
|||||||
@@ -8,13 +8,14 @@ import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy;
|
|||||||
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
|
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
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 org.dromara.common.mybatis.core.domain.DataPermissionAccess;
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,10 +28,10 @@ import java.util.function.Supplier;
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class DataPermissionHelper {
|
public class DataPermissionHelper {
|
||||||
|
|
||||||
public 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<>();
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ public class DataPermissionHelper {
|
|||||||
/**
|
/**
|
||||||
* 设置当前执行mapper权限注解
|
* 设置当前执行mapper权限注解
|
||||||
*
|
*
|
||||||
* @param dataPermission 数据权限注解
|
* @param dataPermission 数据权限注解
|
||||||
*/
|
*/
|
||||||
public static void setPermission(DataPermission dataPermission) {
|
public static void setPermission(DataPermission dataPermission) {
|
||||||
PERMISSION_CACHE.set(dataPermission);
|
PERMISSION_CACHE.set(dataPermission);
|
||||||
@@ -82,10 +83,20 @@ public class DataPermissionHelper {
|
|||||||
context.put(key, value);
|
context.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前数据权限访问控制对象。
|
||||||
|
*
|
||||||
|
* @return 访问控制对象
|
||||||
|
*/
|
||||||
public static DataPermissionAccess getAccess() {
|
public static DataPermissionAccess getAccess() {
|
||||||
return getVariable(ACCESS_KEY);
|
return getVariable(ACCESS_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置当前数据权限访问控制对象。
|
||||||
|
*
|
||||||
|
* @param access 访问控制对象
|
||||||
|
*/
|
||||||
public static void setAccess(DataPermissionAccess access) {
|
public static void setAccess(DataPermissionAccess access) {
|
||||||
setVariable(ACCESS_KEY, access);
|
setVariable(ACCESS_KEY, access);
|
||||||
}
|
}
|
||||||
@@ -97,21 +108,23 @@ public class DataPermissionHelper {
|
|||||||
* @throws NullPointerException 如果数据权限上下文类型异常,则抛出NullPointerException
|
* @throws NullPointerException 如果数据权限上下文类型异常,则抛出NullPointerException
|
||||||
*/
|
*/
|
||||||
public static Map<String, Object> getContext() {
|
public static Map<String, Object> getContext() {
|
||||||
Object attribute = new HashMap<>();
|
SaStorage saStorage = SaHolder.getStorage();
|
||||||
if (SaHolder.getContext().isValid()) {
|
Object attribute = saStorage.get(DATA_PERMISSION_KEY);
|
||||||
SaStorage saStorage = SaHolder.getStorage();
|
if (ObjectUtil.isNull(attribute)) {
|
||||||
|
saStorage.set(DATA_PERMISSION_KEY, new HashMap<>());
|
||||||
attribute = saStorage.get(DATA_PERMISSION_KEY);
|
attribute = saStorage.get(DATA_PERMISSION_KEY);
|
||||||
if (ObjectUtil.isNull(attribute)) {
|
|
||||||
saStorage.set(DATA_PERMISSION_KEY, new HashMap<>());
|
|
||||||
attribute = saStorage.get(DATA_PERMISSION_KEY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前忽略策略。
|
||||||
|
*
|
||||||
|
* @return 忽略策略
|
||||||
|
*/
|
||||||
private static IgnoreStrategy getIgnoreStrategy() {
|
private static IgnoreStrategy getIgnoreStrategy() {
|
||||||
Object ignoreStrategyLocal = ReflectUtils.getStaticFieldValue(ReflectUtils.getField(InterceptorIgnoreHelper.class, "IGNORE_STRATEGY_LOCAL"));
|
Object ignoreStrategyLocal = ReflectUtils.getStaticFieldValue(ReflectUtils.getField(InterceptorIgnoreHelper.class, "IGNORE_STRATEGY_LOCAL"));
|
||||||
if (ignoreStrategyLocal instanceof ThreadLocal<?> IGNORE_STRATEGY_LOCAL) {
|
if (ignoreStrategyLocal instanceof ThreadLocal<?> IGNORE_STRATEGY_LOCAL) {
|
||||||
@@ -132,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,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();
|
||||||
@@ -176,6 +189,7 @@ public class DataPermissionHelper {
|
|||||||
* 在忽略数据权限中执行
|
* 在忽略数据权限中执行
|
||||||
*
|
*
|
||||||
* @param handle 处理执行方法
|
* @param handle 处理执行方法
|
||||||
|
* @return 执行结果
|
||||||
*/
|
*/
|
||||||
public static <T> T ignore(Supplier<T> handle) {
|
public static <T> T ignore(Supplier<T> handle) {
|
||||||
enableIgnore();
|
enableIgnore();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.dromara.system.dubbo;
|
|||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.dubbo.config.annotation.DubboService;
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
@@ -53,7 +54,7 @@ public class RemoteDeptServiceImpl implements RemoteDeptService {
|
|||||||
@Override
|
@Override
|
||||||
public Long selectDeptLeaderById(Long deptId) {
|
public Long selectDeptLeaderById(Long deptId) {
|
||||||
SysDeptVo vo = deptService.selectDeptById(deptId);
|
SysDeptVo vo = deptService.selectDeptById(deptId);
|
||||||
return vo.getLeader();
|
return ObjectUtil.isNull(vo) ? null : vo.getLeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ public class SysConfigServiceImpl implements ISysConfigService {
|
|||||||
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);
|
||||||
|
|||||||
@@ -281,7 +281,10 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||||||
@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("部门停用,不允许新增");
|
||||||
}
|
}
|
||||||
@@ -356,7 +359,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||||||
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)) {
|
||||||
@@ -374,7 +377,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||||||
*/
|
*/
|
||||||
@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) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -100,7 +101,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService {
|
|||||||
@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