浏览代码

excel加入动态导入扩展

wangliang 4 年之前
父节点
当前提交
2e56fafce6

+ 18 - 14
themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java

@@ -42,15 +42,19 @@ public class SystemConstant {
     /**
      * 腾讯云
      */
-    public static final String TENCENT_APPID = "appId";
+//    public static final String TENCENT_APPID = "appId";
 
-    public static final String TENCENT_KEY = "key";
+//    public static final String TENCENT_KEY = "key";
 
     public static final long TENCENT_EXPIRE_TIME = 24 * 3600 * 30;
 
     /**
      * 系统相关
      */
+    public static final String EXTEND_COLUMN = "extendColumn";
+
+    public static final String MAP = "Map";
+
     public static final String IMPORT_INIT = "准备开始处理导入数据";
 
     public static final String EXPORT_INIT = "准备开始处理导出数据";
@@ -141,9 +145,9 @@ public class SystemConstant {
 
     public static String TEMP_FILES_DIR;
 
-    public static final String MONITOR_LIVE_URL_ = "monitorLiveUrl_";
+//    public static final String MONITOR_LIVE_URL_ = "monitorLiveUrl_";
 
-    public static final String STREAM_NAME = "streamName_";
+//    public static final String STREAM_NAME = "streamName_";
 
     public static final String MONITOR_STATUS_ = "monitorStatus_";
 
@@ -233,7 +237,7 @@ public class SystemConstant {
     /**
      * rocket mq
      */
-    public static final String MQDTO_OBJ = "mqDtoObj";
+//    public static final String MQDTO_OBJ = "mqDtoObj";
 
     public static final int CONSUME_MESSAGE_BATCH_MAX_SIZE = 10;
 
@@ -265,15 +269,15 @@ public class SystemConstant {
     /**
      * 线程池配置
      */
-    public static final String THREAD_POOL_NAME = "arbitrateThreadPool";
-
-    public static final int THREAD_POOL_CORE_POOL_SIZE = 20;
-
-    public static final int THREAD_POOL_MAX_POOL_SIZE = 40;
-
-    public static final int THREAD_POOL_KEEP_ALIVE_SECONDS = 60;
-
-    public static final int THREAD_POOL_QUEUE_CAPACITY = 100;
+//    public static final String THREAD_POOL_NAME = "arbitrateThreadPool";
+//
+//    public static final int THREAD_POOL_CORE_POOL_SIZE = 20;
+//
+//    public static final int THREAD_POOL_MAX_POOL_SIZE = 40;
+//
+//    public static final int THREAD_POOL_KEEP_ALIVE_SECONDS = 60;
+//
+//    public static final int THREAD_POOL_QUEUE_CAPACITY = 100;
 
     /**
      * websocket

+ 22 - 5
themis-business/src/main/java/com/qmth/themis/business/util/ExcelUtil.java

@@ -2,6 +2,7 @@ package com.qmth.themis.business.util;
 
 import com.qmth.themis.business.annotation.ExcelNotNull;
 import com.qmth.themis.business.annotation.ExcelNote;
+import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import org.apache.poi.ss.usermodel.Cell;
@@ -16,9 +17,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * @Description: excel util
@@ -68,6 +67,7 @@ public class ExcelUtil {
                         int lastcell = row.getLastCellNum();
                         o = clazz.get(y).newInstance();
                         Field[] fields = o.getClass().getDeclaredFields();
+                        Map map = null;
                         for (int j = firstcell; j < lastcell; j++) {
                             //获取第j列
                             Cell cell = row.getCell(j);
@@ -76,8 +76,25 @@ public class ExcelUtil {
                             } else {
                                 if (Objects.nonNull(cell)) {
                                     Object obj = convert(cell);
-                                    fields[j].setAccessible(true);
-                                    fields[j].set(o, obj);
+                                    if (Objects.isNull(map)) {
+                                        fields[j].setAccessible(true);
+                                        String string = fields[j].getGenericType().getTypeName();
+                                        if (string.contains(SystemConstant.MAP)) {
+                                            map = (Map) fields[j].get(o);
+                                            if (Objects.isNull(map)) {
+                                                map = new LinkedHashMap<>();
+                                            }
+                                            map.put(columnNameList.get(y).get(j), obj);
+                                            fields[j].set(o, map);
+                                        } else {
+                                            fields[j].set(o, obj);
+                                        }
+                                    } else {
+                                        Field field = o.getClass().getDeclaredField(SystemConstant.EXTEND_COLUMN);
+                                        field.setAccessible(true);
+                                        map.put(columnNameList.get(y).get(j), obj);
+                                        field.set(o, map);
+                                    }
                                 }
                             }
                         }