Jelajahi Sumber

feat:
程序文件导入导出

18339543638 2 tahun lalu
induk
melakukan
dd2d895f77

+ 16 - 7
tr-modules-api/tr-module-export-api/src/main/java/cn/tr/module/export/handler/AbstractCascadeSelectConverter.java

@@ -1,12 +1,12 @@
 package cn.tr.module.export.handler;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.lang.Pair;
 import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.tr.module.export.annotation.ExcelPropertySupport;
-import cn.tr.module.export.annotation.ExcelSelect;
 import com.alibaba.excel.converters.Converter;
 import com.alibaba.excel.metadata.GlobalConfiguration;
 import com.alibaba.excel.metadata.data.ReadCellData;
@@ -22,7 +22,7 @@ import java.util.*;
  */
 
 public abstract class AbstractCascadeSelectConverter<T> implements Converter<T> {
-    private static final ThreadLocal<List<Pair<String, String>>> threadLocal = ThreadUtil.createThreadLocal(false);
+    private static final ThreadLocal<Map<String,List<Pair<String, String>>>> threadLocal = ThreadUtil.createThreadLocal(false);
     @Override
     public Class<T> supportJavaTypeKey() {
         return doSupportJavaTypeKey();
@@ -104,12 +104,21 @@ public abstract class AbstractCascadeSelectConverter<T> implements Converter<T>
      * @return  在excel转java 和 java转excel时使用
      */
     public List<Pair<String, String>>  getSelectPairs(Collection<String> params){
-        List<Pair<String, String>> selectPairs = threadLocal.get();
-        if(ObjectUtil.isNull(selectPairs)){
-            selectPairs=doGetSelectPairs(params);
+        String key=this.getClass().getSimpleName();
+        if(CollectionUtil.isNotEmpty(params)){
+            key=key+"-"+CollectionUtil.join(params,"-");
         }
-        threadLocal.set(selectPairs);
-        return selectPairs;
+        Map<String,List<Pair<String, String>>> selectPairsMap = threadLocal.get();
+        if(selectPairsMap==null){
+            selectPairsMap=new WeakHashMap<>();
+        }
+        List<Pair<String, String>> result=selectPairsMap.get(key);
+        if(ObjectUtil.isNull(result)){
+            result=doGetSelectPairs(params);
+        }
+        selectPairsMap.put(key,result);
+        threadLocal.set(selectPairsMap);
+        return result;
     };