Procházet zdrojové kódy

fix:
excel导入导出缓存清理

18339543638 před 2 roky
rodič
revize
a7dc82e4ed

+ 9 - 2
tr-modules-api/tr-module-export-api/src/main/java/cn/tr/module/export/handler/AbstractCascadeSelectConverter.java

@@ -22,7 +22,7 @@ import java.util.*;
  */
 
 public abstract class AbstractCascadeSelectConverter<T> implements Converter<T> {
-    private static final ThreadLocal<Map<String,List<Pair<String, String>>>> threadLocal = ThreadUtil.createThreadLocal(false);
+    public static final ThreadLocal<Map<String,List<Pair<String, String>>>> threadLocal = ThreadUtil.createThreadLocal(false);
     @Override
     public Class<T> supportJavaTypeKey() {
         return doSupportJavaTypeKey();
@@ -95,7 +95,14 @@ public abstract class AbstractCascadeSelectConverter<T> implements Converter<T>
      * [{"",["是","否"]}]
      * <pre/>
      */
-    public Map<String, List<String>>  buildCascadeSelectList(Collection<String> params){return new HashMap<>();};
+    public Map<String, List<String>>  buildCascadeSelectList(Collection<String> params){
+        HashMap<String, List<String>> result = new HashMap<>();
+        List<Pair<String, String>> selectPairs = getSelectPairs(params);
+        for (Pair<String, String> selectPair : selectPairs) {
+            result.put(selectPair.getValue(),null);
+        }
+        return result;
+    };
 
 
     /**

+ 6 - 0
tr-modules/tr-module-export/src/main/java/cn/tr/module/excel/core/service/ExcelService.java

@@ -13,6 +13,7 @@ import cn.tr.module.excel.core.handler.write.CustomCellWriteHandler;
 import cn.tr.module.excel.core.handler.write.CustomHorizontalCellStyleStrategy;
 import cn.tr.module.excel.core.handler.write.CustomRowWriteHandler;
 import cn.tr.module.excel.core.handler.write.CustomSheetWriteHandler;
+import cn.tr.module.export.handler.AbstractCascadeSelectConverter;
 import cn.tr.module.register.ExportSampleRegister;
 import cn.tr.module.excel.core.utils.ExcelTemplateDescUtil;
 import cn.tr.module.excel.core.utils.StyleUtils;
@@ -67,6 +68,7 @@ public class ExcelService {
      * @return
      */
     public  <T> byte[] exportExcel(Class<T> aClass, Collection<T> data){
+        AbstractCascadeSelectConverter.threadLocal.remove();
         ByteArrayOutputStream outputStream =new ByteArrayOutputStream();
         ExcelWriter excelWriter = EasyExcel.write(outputStream).build();
         String sheetName="导入(导出)数据";
@@ -79,6 +81,7 @@ public class ExcelService {
         createSheet(excelWriter,1,"模板注释",ExcelTemplateDescDTO.class,exportTemplate);
         IoUtil.flush(outputStream);
         IoUtil.close(excelWriter);
+        AbstractCascadeSelectConverter.threadLocal.remove();
         return outputStream.toByteArray();
     }
 
@@ -94,6 +97,7 @@ public class ExcelService {
      * @return  返回SheetId
      */
     public <T> String importExcel(String filename, InputStream inputStream, Class<T> aClass, Map<String,Object> customObj) throws Exception {
+        AbstractCascadeSelectConverter.threadLocal.remove();
         byte[] content = IoUtil.readBytes(inputStream);
         String fileId = storageApi.upload(content,filename);
         //新增sheet导入记录
@@ -117,6 +121,8 @@ public class ExcelService {
             storageApi.removeById(fileId);
 
             throw e;
+        }finally {
+            AbstractCascadeSelectConverter.threadLocal.remove();
         }
 
         return sheetId;