TransToExcelNewCompany.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package com.winhc.task;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.aliyun.oss.OSS;
  4. import com.aliyun.oss.OSSClientBuilder;
  5. import com.winhc.task.bean.Company;
  6. import com.winhc.task.bean.CompanyOut;
  7. import com.winhc.task.common.CompanyChangeArgs;
  8. import com.winhc.task.util.CsvToXlsxUtil;
  9. import com.winhc.task.util.ZipUtils;
  10. import java.io.File;
  11. import java.io.FileNotFoundException;
  12. import java.io.FileOutputStream;
  13. import java.io.IOException;
  14. import java.util.*;
  15. import java.util.function.Function;
  16. import java.util.stream.Collectors;
  17. import java.util.stream.Stream;
  18. import static com.winhc.task.common.Constant.*;
  19. import static com.winhc.task.util.CsvToXlsxUtil.jsonToXLSxNewCompany;
  20. import static com.winhc.task.util.CsvToXlsxUtil.jsonToXLSxChange;
  21. import static com.winhc.task.util.DateUtils.getYesterday_ymd;
  22. /**
  23. * @author π
  24. * @Description:
  25. * @date 2022/11/7 16:10
  26. */
  27. public class TransToExcelNewCompany {
  28. public static void main(String[] args) throws IOException {
  29. //全部任务
  30. //run();
  31. //映射跑
  32. mapping_run();
  33. }
  34. private static void mapping_run() {
  35. Stream.of("company", "company_double_random_check_info", "company_staff",
  36. "company_abnormal_info",
  37. "cancellation_announcement", "company_change", "company_punishment_info",
  38. "company_holder", "company_check_info", "company_illegal_info", "company_judicial_assistance", "company_equity_info")
  39. .forEach(tn -> {
  40. String outXlsxPath = "D:\\tmp\\mapping\\" + tn + ".xlsx";
  41. String objectNamePath = "anshuo/mapping/" + tn + ".json";
  42. toTrans2(outXlsxPath, objectNamePath, tn);
  43. });
  44. }
  45. private static void run() throws FileNotFoundException {
  46. String ds = getYesterday_ymd();
  47. String outPathPre = "D:\\tmp\\data\\" + ds + "\\";
  48. File file = new File(outPathPre);
  49. //如果文件夹不存在则会创建
  50. if (!file.exists()) file.mkdirs();
  51. //新公司
  52. newCompanyToExcel(outPathPre, ds);
  53. //变更
  54. changeToExcel(outPathPre, ds);
  55. //压缩文件
  56. FileOutputStream outZipPath = new FileOutputStream(new File("D:\\tmp\\data\\" + ds + ".zip"));
  57. ZipUtils.toZip("D:\\tmp\\data\\" + ds, outZipPath, true);
  58. }
  59. public static void changeToExcel(String outPathPre, String ds) {
  60. Map<String, CompanyChangeArgs> exportArgs = CompanyChangeArgs.EXPORT_ARGS;
  61. exportArgs.keySet().forEach(tn -> {
  62. toTrans(outPathPre, ds, tn);
  63. });
  64. }
  65. public static void toTrans(String outPathPre, String ds, String tn) {
  66. Map<String, CompanyChangeArgs> exportArgs = CompanyChangeArgs.EXPORT_ARGS;
  67. CompanyChangeArgs args = exportArgs.get(tn);
  68. Function<JSONObject, JSONObject> handles = args.getHandles();
  69. List<List<String>> company_head_list = Arrays.stream(args.getHead().split("@"))
  70. .map(Collections::singletonList)
  71. .collect(Collectors.toList());
  72. String objectName = "anshuo/dim_change/" + ds + "/" + tn + ".json";
  73. String outPath = outPathPre + "change_" + tn + ".xlsx";
  74. Set<String> excludeColumnFiledNames = new HashSet<>();
  75. excludeColumnFiledNames.add("old_name");
  76. jsonToXLSxChange(tn, outPath, objectName, company_head_list, args.getClazz(), handles, excludeColumnFiledNames);
  77. }
  78. public static void toTrans2(String outPath, String objectNamePath, String tn) {
  79. Map<String, CompanyChangeArgs> exportArgs = CompanyChangeArgs.EXPORT_ARGS;
  80. CompanyChangeArgs args = exportArgs.get(tn);
  81. Function<JSONObject, JSONObject> handles = args.getHandles();
  82. String head = "原始名称@" + args.getHead();
  83. List<List<String>> company_head_list = Arrays.stream(head.split("@"))
  84. .map(Collections::singletonList)
  85. .collect(Collectors.toList());
  86. jsonToXLSxChange(tn, outPath, objectNamePath, company_head_list, args.getClazz(), handles, null);
  87. }
  88. public static void newCompanyToExcel(String outPathPre, String ds) {
  89. List<List<String>> company_head_list = Arrays.stream(company_head.split("@"))
  90. .map(Collections::singletonList)
  91. .collect(Collectors.toList());
  92. List<List<String>> holder_head_list = Arrays.stream(holder_head.split("@"))
  93. .map(Collections::singletonList)
  94. .collect(Collectors.toList());
  95. List<List<String>> staff_head_list = Arrays.stream(staff_head.split("@"))
  96. .map(Collections::singletonList)
  97. .collect(Collectors.toList());
  98. String objectName = "anshuo/new_company/" + ds + "/new_company.json";
  99. Set<String> excludeColumnFiledNames = new HashSet<>();
  100. excludeColumnFiledNames.add("old_name");
  101. jsonToXLSxNewCompany(outPathPre, objectName, company_head_list, holder_head_list, staff_head_list, excludeColumnFiledNames);
  102. }
  103. }