123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package com.vcarecity.cvs;
-
- import com.google.inject.Guice;
- import com.google.inject.Injector;
- import com.vcarecity.cvs.core.ReflectionUtil;
- import com.vcarecity.cvs.module.PropertiesModule;
- import com.vcarecity.cvs.module.SQLModule;
- import com.vcarecity.cvs.properties.AppProperties;
- import com.vcarecity.cvs.properties.DbProperties;
- import com.vcarecity.cvs.starter.SQLStarter;
- import me.yuxiaoyao.config.loader.ConfigLoader;
-
- import java.util.Map;
- import java.util.concurrent.ConcurrentHashMap;
-
- /**
- * @author Kerry on 19/11/27
- */
-
- public class FileExporterApp {
-
- public static Injector injector;
- public static Map<String, String[]> TABLE_COLUMN = new ConcurrentHashMap<>();
-
-
- public static void main(String[] args) throws Exception {
-
- ReflectionUtil.initTableClassMapper("com.vcarecity.cvs.entity");
-
- AppProperties appProperties = ConfigLoader.parseConfig(args, AppProperties.class, null);
- jdbcArgs(args, appProperties);
-
- String table = getTableByArgs(args);
- if (table == null || table.length() == 0) {
- throw new Error("table name must not be null or empty!");
- }
- Class<?> tableClass = ReflectionUtil.getTableClass(table);
-
- boolean isMysql;
- Object properties;
-
- if (isImportToMysql(args)) {
- properties = "mysql";
- isMysql = true;
- } else {
-
- String basePath = table;
- final AppProperties.Export export = appProperties.getExport();
- if (export != null) {
- basePath = export.getFolder() + table;
- }
- properties = basePath;
- isMysql = false;
- }
-
-
- injector = Guice.createInjector(new PropertiesModule(appProperties), new SQLModule(isMysql));
-
- final SQLStarter instance = injector.getInstance(SQLStarter.class);
- instance.exportDataAndConvert(table, properties, tableClass);
- }
-
-
- private static boolean isImportToMysql(String[] args) {
- for (String arg : args) {
- if (arg.startsWith("--type=")) {
- return !"csv".equalsIgnoreCase(arg.substring("--type=".length()));
- }
- }
- return true;
- }
-
-
- private static String getTableByArgs(String[] args) {
- for (String arg : args) {
- if (arg.startsWith("--table=")) {
- return arg.substring("--table=".length()).trim();
- } else if (arg.startsWith("-t=")) {
- return arg.substring("-t=".length()).trim();
- }
- }
- return null;
- }
-
-
- private static void jdbcArgs(String[] args, AppProperties properties) {
- final DbProperties database = properties.getFromDb();
- for (String arg : args) {
- if (arg.startsWith("jdbc.url=")) {
- database.setUrl(arg.substring("jdbc.url=".length()).trim());
- } else if (arg.startsWith("jdbc.user=")) {
- database.setUser(arg.substring("jdbc.user=".length()).trim());
- } else if (arg.startsWith("jdbc.password=")) {
- database.setPassword(arg.substring("jdbc.password=".length()).trim());
- }
- }
- properties.setFromDb(database);
- }
- }
|