|
|
@@ -1,7 +1,10 @@
|
|
|
package com.test;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.lang.Console;
|
|
|
+import cn.hutool.core.lang.Snowflake;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.http.Header;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
@@ -33,7 +36,6 @@ public class GetDictItem {
|
|
|
for (KeyResult.DataDto category : keyResult.getData()) {
|
|
|
Console.log(category.getDictCode(), category.getDictName());
|
|
|
getDictResult(category);
|
|
|
- break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -61,12 +63,14 @@ public class GetDictItem {
|
|
|
for (ItemResult.DataDto datum : itemResult.getData()) {
|
|
|
Console.log(datum.getXh(), datum.getItemType(), datum.getItemValue());
|
|
|
}
|
|
|
- writeExcel(category, itemResult.getData());
|
|
|
+// writeExcel(category, itemResult.getData());
|
|
|
+ writeSQL(category, itemResult.getData());
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 生成Excel
|
|
|
+ *
|
|
|
* @param category
|
|
|
* @param items
|
|
|
*/
|
|
|
@@ -81,16 +85,25 @@ public class GetDictItem {
|
|
|
writer.close();
|
|
|
}
|
|
|
|
|
|
+ private static final Snowflake snowflake = IdUtil.getSnowflake(0, 0);
|
|
|
+
|
|
|
/**
|
|
|
* 生成SQL
|
|
|
+ *
|
|
|
* @param category
|
|
|
* @param items
|
|
|
*/
|
|
|
private static void writeSQL(KeyResult.DataDto category, List<ItemResult.DataDto> items) {
|
|
|
- List <String> list = new ArrayList<>();
|
|
|
-
|
|
|
- list.add("");
|
|
|
-
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ String nowTime = DateUtil.now();
|
|
|
+ long categoryId = snowflake.nextId();
|
|
|
+ // 添加分类数据
|
|
|
+ list.add(String.format("INSERT INTO `datacollect-pub`.`sys_dict_type` (`id`, `name`, `code`, `sort`, `remark`, `status`, `create_time`, `create_user`, `update_time`, `update_user`) VALUES (%s, '%s', '%s', 100, '%s', 0, '%s', -1, '%s', -1);", categoryId, category.getDictName(), category.getDictCode(), category.getDictName(), nowTime, nowTime));
|
|
|
+ // 添加条目信息
|
|
|
+ for (ItemResult.DataDto item : items) {
|
|
|
+ list.add(String.format("INSERT INTO `datacollect-pub`.`sys_dict_data` (`id`, `type_id`, `value`, `code`, `sort`, `remark`, `status`, `create_time`, `create_user`, `update_time`, `update_user`) VALUES (%s, %s, '%s', '%s', %s, '%s', 0, '%s', -1, NULL, NULL);", snowflake.nextId(), categoryId, item.getItemValue(), item.getItemCode(), item.getXh(), item.getItemBz(), nowTime));
|
|
|
+ }
|
|
|
+ FileUtil.writeLines(list, TARGET_PATH + "sql/" + category.getDictCode() + "_" + category.getDictName() + ".txt", StandardCharsets.UTF_8);
|
|
|
}
|
|
|
|
|
|
|