Browse Source

动态支持MySQL/Oracle

张泳健 5 years ago
parent
commit
592b09f89f

+ 1 - 1
config/application-oracle.yml View File

@@ -3,4 +3,4 @@ database:
3 3
   user: C##FMMP
4 4
   password: vcare~1(^_^)
5 5
 export:
6
-  folder: ./
6
+  folder: ./logs/

+ 2 - 2
config/application.yml View File

@@ -1,3 +1,3 @@
1 1
 profile:
2
-#  active: mysql
3
-   active: oracle
2
+  active: mysql
3
+#   active: oracle

+ 1 - 2
src/main/java/com/vcarecity/cvs/service/ResultHandlerService.java View File

@@ -13,10 +13,9 @@ public interface ResultHandlerService {
13 13
      * ins
14 14
      *
15 15
      * @param dataList
16
-     * @param cls
17 16
      * @throws Exception
18 17
      */
19
-    <T> void resultHandler(List<T> dataList, Class<T> cls) throws Exception;
18
+    <T> void resultHandler(List<T> dataList) throws Exception;
20 19
 
21 20
 
22 21
 }

+ 7 - 3
src/main/java/com/vcarecity/cvs/service/impl/CSVResultHandlerServiceImpl.java View File

@@ -78,16 +78,19 @@ public class CSVResultHandlerServiceImpl implements ResultHandlerService {
78 78
     }
79 79
 
80 80
     @Override
81
-    public <T> void resultHandler(List<T> dataList, Class<T> cls) throws Exception {
81
+    public <T> void resultHandler(List<T> dataList) throws Exception {
82 82
         checkFile();
83 83
 
84 84
         logger.debug("start write to csv file size = {}", dataList.size());
85 85
 
86 86
         long startTime = System.currentTimeMillis();
87 87
 
88
+
89
+        Class<?> cls = Object.class;
90
+
88 91
         for (T t : dataList) {
92
+            cls = t.getClass();
89 93
             Object[] row;
90
-
91 94
             if (t.getClass().isArray()) {
92 95
                 row = (Object[]) t;
93 96
             } else if (List.class.isAssignableFrom(t.getClass())) {
@@ -95,7 +98,8 @@ public class CSVResultHandlerServiceImpl implements ResultHandlerService {
95 98
                 row = ((List) t).toArray();
96 99
             } else {
97 100
                 // auto mapper
98
-                row = resultMapper(t, cls);
101
+                //noinspection unchecked
102
+                row = resultMapper(t, (Class<T>) t.getClass());
99 103
             }
100 104
             Object[] handlerRow = toCsvContent(row);
101 105
             writer.printRecord(handlerRow);

+ 1 - 1
src/main/java/com/vcarecity/cvs/service/impl/MySQLResultHandlerServiceImpl.java View File

@@ -29,7 +29,7 @@ public class MySQLResultHandlerServiceImpl implements ResultHandlerService {
29 29
 
30 30
 
31 31
     @Override
32
-    public <T> void resultHandler(List<T> dataList, Class<T> cls) throws Exception {
32
+    public <T> void resultHandler(List<T> dataList) throws Exception {
33 33
         logger.debug("start write to mysql size = {}, on = {}", dataList.size(), LocalDateTime.now());
34 34
         long startTime = System.currentTimeMillis();
35 35
         final Connection connection = dataSource.getConnection();

+ 1 - 1
src/main/java/com/vcarecity/cvs/starter/SQLStarter.java View File

@@ -59,7 +59,7 @@ public class SQLStarter {
59 59
 
60 60
         do {
61 61
             List<T> result = queryService.queryByPage(table, page, this.pageCount, cls);
62
-            resultHandler.resultHandler(result, cls);
62
+            resultHandler.resultHandler(result);
63 63
             currentSize = result.size();
64 64
 
65 65
             page++;