Browse Source

添加TimerService

张泳健 5 years ago
parent
commit
97c38bce71

+ 11 - 8
src/main/java/com/vcarecity/cvs/FileExporterApp.java View File

@@ -8,6 +8,7 @@ import com.vcarecity.cvs.module.SQLModule;
8 8
 import com.vcarecity.cvs.properties.AppProperties;
9 9
 import com.vcarecity.cvs.properties.DbProperties;
10 10
 import com.vcarecity.cvs.starter.SQLStarter;
11
+import com.vcarecity.cvs.type.ResultHandlerEnum;
11 12
 import me.yuxiaoyao.config.loader.ConfigLoader;
12 13
 
13 14
 import java.util.Map;
@@ -39,35 +40,37 @@ public class FileExporterApp {
39 40
         boolean isMysql;
40 41
         Object properties;
41 42
 
42
-        if (isImportToMysql(args)) {
43
+        final ResultHandlerEnum type = isImportToMysql(args);
44
+
45
+        if (type == ResultHandlerEnum.MYSQL || type == ResultHandlerEnum.MYSQL_PS) {
43 46
             properties = "mysql";
44
-            isMysql = true;
45
-        } else {
46 47
 
48
+        } else {
47 49
             String basePath = table;
48 50
             final AppProperties.Export export = appProperties.getExport();
49 51
             if (export != null) {
50 52
                 basePath = export.getFolder() + table;
51 53
             }
52 54
             properties = basePath;
53
-            isMysql = false;
54 55
         }
55 56
 
56 57
 
57
-        injector = Guice.createInjector(new PropertiesModule(appProperties), new SQLModule(isMysql));
58
+        injector = Guice.createInjector(new PropertiesModule(appProperties), new SQLModule(type));
58 59
 
59 60
         final SQLStarter instance = injector.getInstance(SQLStarter.class);
60 61
         instance.exportDataAndConvert(table, properties, tableClass);
61 62
     }
62 63
 
63 64
 
64
-    private static boolean isImportToMysql(String[] args) {
65
+    private static ResultHandlerEnum isImportToMysql(String[] args) {
66
+        String type = null;
65 67
         for (String arg : args) {
66 68
             if (arg.startsWith("--type=")) {
67
-                return !"csv".equalsIgnoreCase(arg.substring("--type=".length()));
69
+                type = arg.substring("--type=".length()).trim();
70
+                break;
68 71
             }
69 72
         }
70
-        return true;
73
+        return ResultHandlerEnum.fromType(type);
71 74
     }
72 75
 
73 76
 

+ 19 - 8
src/main/java/com/vcarecity/cvs/module/SQLModule.java View File

@@ -13,6 +13,7 @@ import com.vcarecity.cvs.properties.DbProperties;
13 13
 import com.vcarecity.cvs.service.ResultHandlerService;
14 14
 import com.vcarecity.cvs.service.SQLQueryService;
15 15
 import com.vcarecity.cvs.service.impl.*;
16
+import com.vcarecity.cvs.type.ResultHandlerEnum;
16 17
 import com.vcarecity.cvs.util.CreateDatasource;
17 18
 import com.zaxxer.hikari.HikariDataSource;
18 19
 
@@ -21,10 +22,10 @@ import com.zaxxer.hikari.HikariDataSource;
21 22
  */
22 23
 
23 24
 public class SQLModule extends AbstractModule {
24
-    private final boolean isMysql;
25
+    private final ResultHandlerEnum resultHandlerEnum;
25 26
 
26
-    public SQLModule(boolean isMysql) {
27
-        this.isMysql = isMysql;
27
+    public SQLModule(ResultHandlerEnum resultHandlerEnum) {
28
+        this.resultHandlerEnum = resultHandlerEnum;
28 29
     }
29 30
 
30 31
     @Override
@@ -33,11 +34,21 @@ public class SQLModule extends AbstractModule {
33 34
         bind(ExportEventListener.class).to(MySQLImportEvent.class);
34 35
 
35 36
         Class<? extends ResultHandlerService> resultClass;
36
-        if (isMysql) {
37
-             resultClass = MySQLResultStatHandlerServiceImpl.class;
38
-            //resultClass = MySQLResultHandlerServiceImpl.class;
39
-        } else {
40
-            resultClass = CSVResultHandlerServiceImpl.class;
37
+
38
+        switch (resultHandlerEnum) {
39
+            case CSV:
40
+                resultClass = CSVResultHandlerServiceImpl.class;
41
+                break;
42
+            case MYSQL:
43
+                resultClass = MySQLResultStatHandlerServiceImpl.class;
44
+                break;
45
+            case MYSQL_PS:
46
+                resultClass = MySQLResultHandlerServiceImpl.class;
47
+                break;
48
+            case DEFAULT:
49
+            default:
50
+                resultClass = LogResultHandlerServiceImpl.class;
51
+                break;
41 52
         }
42 53
 
43 54
         install(new FactoryModuleBuilder()

+ 18 - 0
src/main/java/com/vcarecity/cvs/service/impl/LogResultHandlerServiceImpl.java View File

@@ -0,0 +1,18 @@
1
+package com.vcarecity.cvs.service.impl;
2
+
3
+import com.vcarecity.cvs.service.ResultHandlerService;
4
+import lombok.extern.slf4j.Slf4j;
5
+
6
+import java.util.List;
7
+
8
+/**
9
+ * @author Kerry on 19/12/03
10
+ */
11
+
12
+@Slf4j
13
+public class LogResultHandlerServiceImpl implements ResultHandlerService {
14
+    @Override
15
+    public <T> void resultHandler(String table, String[] header, List<T> dataList) throws Exception {
16
+        logger.debug("LogResultHandlerServiceImpl.resultHandler. table = {}, header = {}, dataList = {}", table, header, dataList);
17
+    }
18
+}

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

@@ -62,6 +62,8 @@ public class SQLStarter {
62 62
         int currentSize;
63 63
         int page = 1;
64 64
 
65
+        long queryCount = 0;
66
+
65 67
         do {
66 68
             // query
67 69
             List<T> result = queryService.queryByPage(table, page, this.pageCount, cls);
@@ -69,6 +71,9 @@ public class SQLStarter {
69 71
             // convert or save
70 72
             resultHandler.resultHandler(table, headers, result);
71 73
             currentSize = result.size();
74
+            queryCount += currentSize;
75
+
76
+            logger.info("current query count is {}", queryCount);
72 77
 
73 78
             page++;
74 79
 

+ 33 - 0
src/main/java/com/vcarecity/cvs/type/ResultHandlerEnum.java View File

@@ -0,0 +1,33 @@
1
+package com.vcarecity.cvs.type;
2
+
3
+/**
4
+ * @author Kerry on 19/12/03
5
+ */
6
+
7
+public enum ResultHandlerEnum {
8
+    CSV("csv"),
9
+    MYSQL("mysql"),
10
+    MYSQL_PS("mysqlps"),
11
+    DEFAULT("");
12
+    private String type;
13
+
14
+    ResultHandlerEnum(String type) {
15
+        this.type = type;
16
+    }
17
+
18
+    public String getType() {
19
+        return type;
20
+    }
21
+
22
+    public static ResultHandlerEnum fromType(String type) {
23
+        if (type == null) {
24
+            return ResultHandlerEnum.DEFAULT;
25
+        }
26
+        for (ResultHandlerEnum value : values()) {
27
+            if (value.getType().equalsIgnoreCase(type)) {
28
+                return value;
29
+            }
30
+        }
31
+        return ResultHandlerEnum.DEFAULT;
32
+    }
33
+}