Browse Source

添加TimerService

张泳健 5 years ago
parent
commit
97c38bce71

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

8
 import com.vcarecity.cvs.properties.AppProperties;
8
 import com.vcarecity.cvs.properties.AppProperties;
9
 import com.vcarecity.cvs.properties.DbProperties;
9
 import com.vcarecity.cvs.properties.DbProperties;
10
 import com.vcarecity.cvs.starter.SQLStarter;
10
 import com.vcarecity.cvs.starter.SQLStarter;
11
+import com.vcarecity.cvs.type.ResultHandlerEnum;
11
 import me.yuxiaoyao.config.loader.ConfigLoader;
12
 import me.yuxiaoyao.config.loader.ConfigLoader;
12
 
13
 
13
 import java.util.Map;
14
 import java.util.Map;
39
         boolean isMysql;
40
         boolean isMysql;
40
         Object properties;
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
             properties = "mysql";
46
             properties = "mysql";
44
-            isMysql = true;
45
-        } else {
46
 
47
 
48
+        } else {
47
             String basePath = table;
49
             String basePath = table;
48
             final AppProperties.Export export = appProperties.getExport();
50
             final AppProperties.Export export = appProperties.getExport();
49
             if (export != null) {
51
             if (export != null) {
50
                 basePath = export.getFolder() + table;
52
                 basePath = export.getFolder() + table;
51
             }
53
             }
52
             properties = basePath;
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
         final SQLStarter instance = injector.getInstance(SQLStarter.class);
60
         final SQLStarter instance = injector.getInstance(SQLStarter.class);
60
         instance.exportDataAndConvert(table, properties, tableClass);
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
         for (String arg : args) {
67
         for (String arg : args) {
66
             if (arg.startsWith("--type=")) {
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
 import com.vcarecity.cvs.service.ResultHandlerService;
13
 import com.vcarecity.cvs.service.ResultHandlerService;
14
 import com.vcarecity.cvs.service.SQLQueryService;
14
 import com.vcarecity.cvs.service.SQLQueryService;
15
 import com.vcarecity.cvs.service.impl.*;
15
 import com.vcarecity.cvs.service.impl.*;
16
+import com.vcarecity.cvs.type.ResultHandlerEnum;
16
 import com.vcarecity.cvs.util.CreateDatasource;
17
 import com.vcarecity.cvs.util.CreateDatasource;
17
 import com.zaxxer.hikari.HikariDataSource;
18
 import com.zaxxer.hikari.HikariDataSource;
18
 
19
 
21
  */
22
  */
22
 
23
 
23
 public class SQLModule extends AbstractModule {
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
     @Override
31
     @Override
33
         bind(ExportEventListener.class).to(MySQLImportEvent.class);
34
         bind(ExportEventListener.class).to(MySQLImportEvent.class);
34
 
35
 
35
         Class<? extends ResultHandlerService> resultClass;
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
         install(new FactoryModuleBuilder()
54
         install(new FactoryModuleBuilder()

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

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

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

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
+}