123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- package com.winhc.task;
- import com.alibaba.fastjson.JSONObject;
- import com.aliyun.oss.OSS;
- import com.aliyun.oss.OSSClientBuilder;
- import com.winhc.task.bean.Company;
- import com.winhc.task.bean.CompanyOut;
- import com.winhc.task.common.CompanyChangeArgs;
- import com.winhc.task.util.CsvToXlsxUtil;
- import com.winhc.task.util.ZipUtils;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.*;
- import java.util.function.Function;
- import java.util.stream.Collectors;
- import java.util.stream.Stream;
- import static com.winhc.task.common.Constant.*;
- import static com.winhc.task.util.CsvToXlsxUtil.jsonToXLSxNewCompany;
- import static com.winhc.task.util.CsvToXlsxUtil.jsonToXLSxChange;
- import static com.winhc.task.util.DateUtils.getYesterday_ymd;
- /**
- * @author π
- * @Description:
- * @date 2022/11/7 16:10
- */
- public class TransToExcelNewCompany {
- public static void main(String[] args) throws IOException {
- //全部任务
- //run();
- //映射跑
- mapping_run();
- }
- private static void mapping_run() {
- Stream.of("company", "company_double_random_check_info", "company_staff",
- "company_abnormal_info",
- "cancellation_announcement", "company_change", "company_punishment_info",
- "company_holder", "company_check_info", "company_illegal_info", "company_judicial_assistance", "company_equity_info")
- .forEach(tn -> {
- String outXlsxPath = "D:\\tmp\\mapping\\" + tn + ".xlsx";
- String objectNamePath = "anshuo/mapping/" + tn + ".json";
- toTrans2(outXlsxPath, objectNamePath, tn);
- });
- }
- private static void run() throws FileNotFoundException {
- String ds = getYesterday_ymd();
- String outPathPre = "D:\\tmp\\data\\" + ds + "\\";
- File file = new File(outPathPre);
- //如果文件夹不存在则会创建
- if (!file.exists()) file.mkdirs();
- //新公司
- newCompanyToExcel(outPathPre, ds);
- //变更
- changeToExcel(outPathPre, ds);
- //压缩文件
- FileOutputStream outZipPath = new FileOutputStream(new File("D:\\tmp\\data\\" + ds + ".zip"));
- ZipUtils.toZip("D:\\tmp\\data\\" + ds, outZipPath, true);
- }
- public static void changeToExcel(String outPathPre, String ds) {
- Map<String, CompanyChangeArgs> exportArgs = CompanyChangeArgs.EXPORT_ARGS;
- exportArgs.keySet().forEach(tn -> {
- toTrans(outPathPre, ds, tn);
- });
- }
- public static void toTrans(String outPathPre, String ds, String tn) {
- Map<String, CompanyChangeArgs> exportArgs = CompanyChangeArgs.EXPORT_ARGS;
- CompanyChangeArgs args = exportArgs.get(tn);
- Function<JSONObject, JSONObject> handles = args.getHandles();
- List<List<String>> company_head_list = Arrays.stream(args.getHead().split("@"))
- .map(Collections::singletonList)
- .collect(Collectors.toList());
- String objectName = "anshuo/dim_change/" + ds + "/" + tn + ".json";
- String outPath = outPathPre + "change_" + tn + ".xlsx";
- Set<String> excludeColumnFiledNames = new HashSet<>();
- excludeColumnFiledNames.add("old_name");
- jsonToXLSxChange(tn, outPath, objectName, company_head_list, args.getClazz(), handles, excludeColumnFiledNames);
- }
- public static void toTrans2(String outPath, String objectNamePath, String tn) {
- Map<String, CompanyChangeArgs> exportArgs = CompanyChangeArgs.EXPORT_ARGS;
- CompanyChangeArgs args = exportArgs.get(tn);
- Function<JSONObject, JSONObject> handles = args.getHandles();
- String head = "原始名称@" + args.getHead();
- List<List<String>> company_head_list = Arrays.stream(head.split("@"))
- .map(Collections::singletonList)
- .collect(Collectors.toList());
- jsonToXLSxChange(tn, outPath, objectNamePath, company_head_list, args.getClazz(), handles, null);
- }
- public static void newCompanyToExcel(String outPathPre, String ds) {
- List<List<String>> company_head_list = Arrays.stream(company_head.split("@"))
- .map(Collections::singletonList)
- .collect(Collectors.toList());
- List<List<String>> holder_head_list = Arrays.stream(holder_head.split("@"))
- .map(Collections::singletonList)
- .collect(Collectors.toList());
- List<List<String>> staff_head_list = Arrays.stream(staff_head.split("@"))
- .map(Collections::singletonList)
- .collect(Collectors.toList());
- String objectName = "anshuo/new_company/" + ds + "/new_company.json";
- Set<String> excludeColumnFiledNames = new HashSet<>();
- excludeColumnFiledNames.add("old_name");
- jsonToXLSxNewCompany(outPathPre, objectName, company_head_list, holder_head_list, staff_head_list, excludeColumnFiledNames);
- }
- }
|