xufei 2 年之前
父节点
当前提交
6514122df0

+ 10 - 0
pom.xml

@@ -229,6 +229,16 @@
             <artifactId>hutool-all</artifactId>
             <version>5.3.7</version>
         </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel</artifactId>
+            <version>3.1.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-compress</artifactId>
+            <version>1.19</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 17 - 0
src/main/java/com/winhc/task/bean/User.java

@@ -0,0 +1,17 @@
+package com.winhc.task.bean;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+/**
+ * @author π
+ * @Description:
+ * @date 2022/6/30 11:41
+ */
+@Data
+@AllArgsConstructor
+public class User {
+    private Integer id;
+    private String name;
+    private String back;
+}

+ 375 - 49
src/main/java/com/winhc/task/common/SummaryArgs.java

@@ -29,28 +29,11 @@ public class SummaryArgs {
 
     private static Map<String, SummaryArgs> createArgs() {
         HashMap<String, SummaryArgs> a = new HashMap<>();
-//        a.put("company_holder", new SummaryArgs(
-//                "ng_rt_company_holder"
-//                , Collections.singletonList(new ArgsInfo(
-//                "company_id"
-//                , ""
-//                , "deleted"))
-//                , Arrays.asList(new ValueAlias(
-//                        ""
-//                        , "0"
-//                        , "company_holder_del_0"),
-//                new ValueAlias(
-//                        ""
-//                        , "1"
-//                        , "company_holder_del_1"))
-//                , (j) -> Collections.singletonList(j.getString("company_id"))
-//        ));
-
         a.put("company_holder", new SummaryArgs(
                 "ng_rt_company_holder"
                 , Arrays.asList(new ArgsInfo(
                 "company_id"
-                , ""
+                , "company_id"
                 , "deleted"), new ArgsInfo(
                 "invest"
                 , "invest"
@@ -72,12 +55,15 @@ public class SummaryArgs {
                         , "1"
                         , "company_holder_del_1_invest")
         )
-                , (j) -> Stream.of(getKey(j, "company_id"), getKey(j, "holder_id"))
-                .filter(x -> x.length() == 32).distinct().collect(Collectors.toList())
+                , (j) -> {
+            //Collections.singletonList(j.getString("company_id"))
+            //暂时只计算人摘要
+            return Stream.of(getKey(j, "company_id"), getKey(j, "holder_id"))
+                    .filter(x -> x.length() == 32).distinct().collect(Collectors.toList());
+        }
         ));
-
-        a.put("company_staff", new SummaryArgs(
-                "ng_rt_company_staff"
+        a.put("company_holder_sponsor", new SummaryArgs(
+                "ng_rt_company_holder_sponsor"
                 , Collections.singletonList(new ArgsInfo(
                 "company_id"
                 , ""
@@ -85,15 +71,15 @@ public class SummaryArgs {
                 , Arrays.asList(new ValueAlias(
                         ""
                         , "0"
-                        , "company_staff_del_0"),
+                        , "company_holder_sponsor_del_0"),
                 new ValueAlias(
                         ""
                         , "1"
-                        , "company_staff_del_1"))
+                        , "company_holder_sponsor_del_1"))
                 , (j) -> Collections.singletonList(j.getString("company_id"))
         ));
-        a.put("company_change", new SummaryArgs(
-                "ng_rt_company_change"
+        a.put("company_staff", new SummaryArgs(
+                "ng_rt_company_staff"
                 , Collections.singletonList(new ArgsInfo(
                 "company_id"
                 , ""
@@ -101,15 +87,15 @@ public class SummaryArgs {
                 , Arrays.asList(new ValueAlias(
                         ""
                         , "0"
-                        , "company_change_del_0"),
+                        , "company_staff_del_0"),
                 new ValueAlias(
                         ""
                         , "1"
-                        , "company_change_del_1"))
+                        , "company_staff_del_1"))
                 , (j) -> Collections.singletonList(j.getString("company_id"))
         ));
-        a.put("company_change_tmp", new SummaryArgs(
-                "ng_rt_company_change_tmp"
+        a.put("company_change", new SummaryArgs(
+                "ng_rt_company_change"
                 , Collections.singletonList(new ArgsInfo(
                 "company_id"
                 , ""
@@ -117,11 +103,11 @@ public class SummaryArgs {
                 , Arrays.asList(new ValueAlias(
                         ""
                         , "0"
-                        , "company_change_tmp_del_0"),
+                        , "company_change_del_0"),
                 new ValueAlias(
                         ""
                         , "1"
-                        , "company_change_tmp_del_1"))
+                        , "company_change_del_1"))
                 , (j) -> Collections.singletonList(j.getString("company_id"))
         ));
         a.put("company_tm", new SummaryArgs(
@@ -197,7 +183,8 @@ public class SummaryArgs {
                 , Arrays.asList(new ValueAlias(
                         ""
                         , "0"
-                        , "company_dishonest_info_del_0"),
+                        , "company_dishonest_info_del_0"
+                        , true),
                 new ValueAlias(
                         ""
                         , "1"
@@ -213,7 +200,7 @@ public class SummaryArgs {
                 , Arrays.asList(new ValueAlias(
                         ""
                         , "0"
-                        , "company_zxr_del_0"),
+                        , "company_zxr_del_0", true),
                 new ValueAlias(
                         ""
                         , "1"
@@ -229,7 +216,7 @@ public class SummaryArgs {
                 , Arrays.asList(new ValueAlias(
                         ""
                         , "0"
-                        , "company_zxr_restrict_del_0"),
+                        , "company_zxr_restrict_del_0", true),
                 new ValueAlias(
                         ""
                         , "1"
@@ -245,7 +232,7 @@ public class SummaryArgs {
                 , Arrays.asList(new ValueAlias(
                         ""
                         , "0"
-                        , "company_zxr_final_case_del_0"),
+                        , "company_zxr_final_case_del_0", true),
                 new ValueAlias(
                         ""
                         , "1"
@@ -304,7 +291,7 @@ public class SummaryArgs {
                         , "bankruptcy_open_case_del_1_applicant"), new ValueAlias(
                         "respondent"
                         , "0"
-                        , "bankruptcy_open_case_del_0_respondent"),
+                        , "bankruptcy_open_case_del_0_respondent", true),
                 new ValueAlias(
                         "respondent"
                         , "1"
@@ -581,7 +568,7 @@ public class SummaryArgs {
                 , Arrays.asList(new ValueAlias(
                         ""
                         , "0"
-                        , "company_abnormal_info_del_0"),
+                        , "company_abnormal_info_del_0", true),
                 new ValueAlias(
                         ""
                         , "1"
@@ -615,13 +602,13 @@ public class SummaryArgs {
         )
                 , Arrays.asList(new ValueAlias("related"
                         , "0"
-                        , "company_judicial_assistance_del_0_related")
+                        , "company_judicial_assistance_del_0_related", true)
                 , new ValueAlias("related"
                         , "1"
                         , "company_judicial_assistance_del_1_related")
                 , new ValueAlias("executed"
                         , "0"
-                        , "company_judicial_assistance_del_0_executed_person")
+                        , "company_judicial_assistance_del_0_executed_person", true)
                 , new ValueAlias("executed"
                         , "1"
                         , "company_judicial_assistance_del_1_executed_person")
@@ -674,7 +661,7 @@ public class SummaryArgs {
                 , Arrays.asList(new ValueAlias(
                         ""
                         , "0"
-                        , "company_liquidating_info_del_0"),
+                        , "company_liquidating_info_del_0", true),
                 new ValueAlias(
                         ""
                         , "1"
@@ -722,7 +709,7 @@ public class SummaryArgs {
                 , Arrays.asList(new ValueAlias(
                         ""
                         , "0"
-                        , "company_punishment_info_del_0"),
+                        , "company_punishment_info_del_0", true),
                 new ValueAlias(
                         ""
                         , "1"
@@ -794,19 +781,19 @@ public class SummaryArgs {
                 )
         )
                 , Arrays.asList(new ValueAlias(
-                        ""
+                        "del"
                         , "0"
                         , "finance_info_v3_del_0"),
                 new ValueAlias(
-                        ""
+                        "del"
                         , "1"
                         , "finance_info_v3_del_1"),
                 new ValueAlias(
-                        ""
+                        "dis"
                         , "0"
                         , "finance_info_v3_dis_0"),
                 new ValueAlias(
-                        ""
+                        "dis"
                         , "1"
                         , "finance_info_v3_dis_1")
 
@@ -845,7 +832,6 @@ public class SummaryArgs {
                         , "company_annual_report_del_1"))
                 , (j) -> Collections.singletonList(j.getString("company_id"))
         ));
-
         a.put("construction_qualification", new SummaryArgs(
                 "ng_rt_construction_qualification"
                 , Collections.singletonList(new ArgsInfo(
@@ -894,6 +880,36 @@ public class SummaryArgs {
                         , "construction_project_del_1"))
                 , (j) -> Collections.singletonList(j.getString("company_id"))
         ));
+
+        a.put("company_bid_new", new SummaryArgs(
+                "ng_rt_company_bid_new"
+                , Arrays.asList(new ArgsInfo("supplier"
+                        , "supplier"
+                        , "deleted")
+                , new ArgsInfo("purchaser"
+                        , "purchaser"
+                        , "deleted")
+        )
+                , Arrays.asList(new ValueAlias("supplier"
+                        , "0"
+                        , "company_bid_new_del_0_supplier")
+                , new ValueAlias("supplier"
+                        , "1"
+                        , "company_bid_new_del_1_supplier")
+                , new ValueAlias("purchaser"
+                        , "0"
+                        , "company_bid_new_del_0_purchaser")
+                , new ValueAlias("purchaser"
+                        , "1"
+                        , "company_bid_new_del_1_purchaser")
+        )
+                , (j) -> {
+            Set<String> set = new HashSet<>();
+            set.addAll(parseJsonArray(j.getString("supplier_info"), "$.keyno"));
+            set.addAll(parseJsonArray(j.getString("purchaser_info"), "$.keyno"));
+            return new ArrayList<>(set);
+        }
+        ));
         a.put("reduction_registered_capital_info", new SummaryArgs(
                 "ng_rt_reduction_registered_capital_info"
                 , Collections.singletonList(new ArgsInfo(
@@ -936,13 +952,315 @@ public class SummaryArgs {
                 , Arrays.asList(new ValueAlias(
                         ""
                         , "0"
-                        , "general_taxpayer_del_0"),
+                        , "general_taxpayer_del_0", true),
                 new ValueAlias(
                         ""
                         , "1"
                         , "general_taxpayer_del_1"))
                 , (j) -> Collections.singletonList(j.getString("company_id"))
         ));
+        a.put("company_mortgage_info", new SummaryArgs(
+                "company_mortgage_info"
+                , Collections.singletonList(new ArgsInfo(
+                "company_id"
+                , ""
+                , "deleted"))
+                , Arrays.asList(new ValueAlias(
+                        ""
+                        , "0"
+                        , "company_mortgage_info_del_0", true),
+                new ValueAlias(
+                        ""
+                        , "1"
+                        , "company_mortgage_info_del_1"))
+                , (j) -> Collections.singletonList(j.getString("company_id"))
+        ));
+        a.put("wenshu_detail_v2", new SummaryArgs(
+                "ng_rt_wenshu_detail_v2"
+                , Arrays.asList(new ArgsInfo("plaintiff"
+                        , "plaintiff"
+                        , "deleted")
+                , new ArgsInfo("defendant"
+                        , "defendant"
+                        , "deleted")
+        )
+                , Arrays.asList(new ValueAlias("plaintiff"
+                        , "0"
+                        , "wenshu_detail_v2_del_0_plaintiff", true)
+                , new ValueAlias("plaintiff"
+                        , "1"
+                        , "wenshu_detail_v2_del_1_plaintiff")
+                , new ValueAlias("defendant"
+                        , "0"
+                        , "wenshu_detail_v2_del_0_defendant", true)
+                , new ValueAlias("defendant"
+                        , "1"
+                        , "wenshu_detail_v2_del_1_defendant")
+        )
+                , (j) -> {
+            Set<String> set = new HashSet<>();
+            set.addAll(parseJsonArray(j.getString("plaintiff_info"), "$.litigant_id"));
+            set.addAll(parseJsonArray(j.getString("defendant_info"), "$.litigant_id"));
+            return new ArrayList<>(set);
+        }
+        ));
+        a.put("company_env_punishment", new SummaryArgs(
+                "ng_rt_company_env_punishment"
+                , Collections.singletonList(new ArgsInfo(
+                "company_id"
+                , ""
+                , "deleted"))
+                , Arrays.asList(new ValueAlias(
+                        ""
+                        , "0"
+                        , "company_env_punishment_del_0"),
+                new ValueAlias(
+                        ""
+                        , "1"
+                        , "company_env_punishment_del_1"))
+                , (j) -> Collections.singletonList(j.getString("company_id"))
+        ));
+        a.put("company_own_tax", new SummaryArgs(
+                "ng_rt_company_own_tax"
+                , Collections.singletonList(new ArgsInfo(
+                "company_id"
+                , ""
+                , "deleted"))
+                , Arrays.asList(new ValueAlias(
+                        ""
+                        , "0"
+                        , "company_own_tax_del_0"),
+                new ValueAlias(
+                        ""
+                        , "1"
+                        , "company_own_tax_del_1"))
+                , (j) -> Collections.singletonList(j.getString("company_id"))
+        ));
+        a.put("company_land_announcement", new SummaryArgs(
+                "ng_rt_company_land_announcement"
+                , Collections.singletonList(new ArgsInfo(
+                "company_id"
+                , ""
+                , "deleted"))
+                , Arrays.asList(new ValueAlias(
+                        ""
+                        , "0"
+                        , "company_land_announcement_del_0"),
+                new ValueAlias(
+                        ""
+                        , "1"
+                        , "company_land_announcement_del_1"))
+                , (j) -> Collections.singletonList(j.getString("company_id"))
+        ));
+        a.put("company_land_publicity", new SummaryArgs(
+                "ng_rt_company_land_publicity"
+                , Collections.singletonList(new ArgsInfo(
+                "company_id"
+                , ""
+                , "deleted"))
+                , Arrays.asList(new ValueAlias(
+                        ""
+                        , "0"
+                        , "company_land_publicity_del_0"),
+                new ValueAlias(
+                        ""
+                        , "1"
+                        , "company_land_publicity_del_1"))
+                , (j) -> Collections.singletonList(j.getString("company_id"))
+        ));
+        a.put("company_land_transfer", new SummaryArgs(
+                "ng_rt_company_land_transfer"
+                , Arrays.asList(new ArgsInfo("user_pre"
+                        , "user_pre"
+                        , "deleted")
+                , new ArgsInfo("user_now"
+                        , "user_now"
+                        , "deleted")
+        )
+                , Arrays.asList(new ValueAlias("user_pre"
+                        , "0"
+                        , "company_land_transfer_del_0_user_pre")
+                , new ValueAlias("user_pre"
+                        , "1"
+                        , "company_land_transfer_del_1_user_pre")
+                , new ValueAlias("user_now"
+                        , "0"
+                        , "company_land_transfer_del_0_user_now")
+                , new ValueAlias("user_now"
+                        , "1"
+                        , "company_land_transfer_del_1_user_now")
+        )
+                , (j) -> {
+            Set<String> set = new HashSet<>();
+            set.add(j.getString("pre_keyno"));
+            set.add(j.getString("now_keyno"));
+            return new ArrayList<>(set);
+        }
+        ));
+        a.put("company_equity_pledge_holder", new SummaryArgs(
+                "ng_rt_company_equity_pledge_holder"
+                , Arrays.asList(new ArgsInfo("company"
+                        , "company"
+                        , "deleted")
+                , new ArgsInfo("holder"
+                        , "holder"
+                        , "deleted")
+                , new ArgsInfo("pledgee"
+                        , "pledgee"
+                        , "deleted")
+        )
+                , Arrays.asList(new ValueAlias("company"
+                        , "0"
+                        , "company_equity_pledge_holder_del_0_company")
+                , new ValueAlias("company"
+                        , "1"
+                        , "company_equity_pledge_holder_del_1_company")
+                , new ValueAlias("holder"
+                        , "0"
+                        , "company_equity_pledge_holder_del_0_holder")
+                , new ValueAlias("holder"
+                        , "1"
+                        , "company_equity_pledge_holder_del_1_holder")
+                , new ValueAlias("pledgee"
+                        , "0"
+                        , "company_equity_pledge_holder_del_0_pledgee")
+                , new ValueAlias("pledgee"
+                        , "1"
+                        , "company_equity_pledge_holder_del_1_pledgee")
+        )
+                , (j) -> {
+            Set<String> set = new HashSet<>();
+            set.add(j.getString("company_id"));
+            set.add(j.getString("holder_id"));
+            set.add(j.getString("pledgee_id"));
+            return new ArrayList<>(set);
+        }
+        ));
+        a.put("company_land_mortgage", new SummaryArgs(
+                "ng_rt_company_land_mortgage"
+                , Arrays.asList(new ArgsInfo("mortgagor"
+                        , "mortgagor"
+                        , "deleted")
+                , new ArgsInfo("mortgagee"
+                        , "mortgagee"
+                        , "deleted")
+        )
+                , Arrays.asList(new ValueAlias("mortgagor"
+                        , "0"
+                        , "company_land_mortgage_del_0_mortgagor")
+                , new ValueAlias("mortgagor"
+                        , "1"
+                        , "company_land_mortgage_del_1_mortgagor")
+                , new ValueAlias("mortgagee"
+                        , "0"
+                        , "company_land_mortgage_del_0_mortgagee")
+                , new ValueAlias("mortgagee"
+                        , "1"
+                        , "company_land_mortgage_del_1_mortgagee")
+        )
+                , (j) -> {
+            Set<String> set = new HashSet<>();
+            set.add(j.getString("mortgagor_company_id"));
+            set.add(j.getString("mortgagee_company_id"));
+            return new ArrayList<>(set);
+        }
+        ));
+        a.put("company_equity_pledge", new SummaryArgs(
+                "ng_rt_company_equity_pledge"
+                , Collections.singletonList(new ArgsInfo(
+                "company_id"
+                , ""
+                , "deleted"))
+                , Arrays.asList(new ValueAlias(
+                        ""
+                        , "0"
+                        , "company_equity_pledge_del_0"),
+                new ValueAlias(
+                        ""
+                        , "1"
+                        , "company_equity_pledge_del_1"))
+                , (j) -> Collections.singletonList(j.getString("company_id"))
+        ));
+        a.put("company_tax_contravention", new SummaryArgs(
+                "ng_rt_company_tax_contravention"
+                , Collections.singletonList(new ArgsInfo(
+                "company_id"
+                , ""
+                , "deleted"))
+                , Arrays.asList(new ValueAlias(
+                        ""
+                        , "0"
+                        , "company_tax_contravention_del_0"),
+                new ValueAlias(
+                        ""
+                        , "1"
+                        , "company_tax_contravention_del_1"))
+                , (j) -> Collections.singletonList(j.getString("company_id"))
+        ));
+        a.put("company_punishment_info_creditchina", new SummaryArgs(
+                "ng_rt_company_punishment_info_creditchina"
+                , Collections.singletonList(new ArgsInfo(
+                "company_id"
+                , ""
+                , "deleted"))
+                , Arrays.asList(new ValueAlias(
+                        ""
+                        , "0"
+                        , "company_punishment_info_creditchina_del_0"),
+                new ValueAlias(
+                        ""
+                        , "1"
+                        , "company_punishment_info_creditchina_del_1"))
+                , (j) -> Collections.singletonList(j.getString("company_id"))
+        ));
+        a.put("company_license_creditchina", new SummaryArgs(
+                "ng_rt_company_license_creditchina"
+                , Collections.singletonList(new ArgsInfo(
+                "company_id"
+                , ""
+                , "deleted"))
+                , Arrays.asList(new ValueAlias(
+                        ""
+                        , "0"
+                        , "company_license_creditchina_del_0"),
+                new ValueAlias(
+                        ""
+                        , "1"
+                        , "company_license_creditchina_del_1"))
+                , (j) -> Collections.singletonList(j.getString("company_id"))
+        ));
+        a.put("company_license_entpub", new SummaryArgs(
+                "ng_rt_company_license_entpub"
+                , Collections.singletonList(new ArgsInfo(
+                "company_id"
+                , ""
+                , "deleted"))
+                , Arrays.asList(new ValueAlias(
+                        ""
+                        , "0"
+                        , "company_license_entpub_del_0"),
+                new ValueAlias(
+                        ""
+                        , "1"
+                        , "company_license_entpub_del_1"))
+                , (j) -> Collections.singletonList(j.getString("company_id"))
+        ));
+        a.put("company_public_announcement", new SummaryArgs(
+                "ng_rt_company_public_announcement"
+                , Collections.singletonList(new ArgsInfo(
+                "company_id"
+                , ""
+                , "deleted"))
+                , Arrays.asList(new ValueAlias(
+                        ""
+                        , "0"
+                        , "company_public_announcement_del_0"),
+                new ValueAlias(
+                        ""
+                        , "1"
+                        , "company_public_announcement_del_1"))
+                , (j) -> Collections.singletonList(j.getString("company_id"))
+        ));
         return a;
     }
 
@@ -977,11 +1295,19 @@ public class SummaryArgs {
         private String category;
         private String value;
         private String alias;
+        private boolean isSum = false;
 
         public ValueAlias(String category, String value, String alias) {
             this.category = category;
             this.value = value;
             this.alias = alias;
         }
+
+        public ValueAlias(String category, String value, String alias, Boolean isSum) {
+            this.category = category;
+            this.value = value;
+            this.alias = alias;
+            this.isSum = isSum;
+        }
     }
 }

+ 80 - 0
src/main/java/com/winhc/task/job/CalcSummaryJob.java

@@ -54,6 +54,16 @@ public class CalcSummaryJob {
 
     }
 
+    public void start2(List<String> list, String sourceTable, String result_table) throws HoloClientException, IOException {
+
+        //初始化sql
+        List<Tuple> list_sql = initSql2(list, sourceTable);
+
+        calcSummary2(sourceTable, list_sql, result_table);
+
+
+    }
+
     private void switch_index(JobArgs jobArgs, String summary_company, String summary_person, ArrayList<String> tnList) throws IOException {
         for (String tn : tnList) {
             if (Constant.PERSON_SUMMARYS.contains(tn)) {
@@ -93,6 +103,33 @@ public class CalcSummaryJob {
         }
     }
 
+    private void calcSummary2(String source_table, List<Tuple> collect, String result_table) throws HoloClientException {
+        for (int i = 0; i < collect.size(); i++) {
+            HoloClient holoClient = HoloUtils.init();
+            String s0 = "";
+            //初始化清空table
+            if (i == 0) {
+                s0 = "truncate table " + source_table;
+            }
+            String tn = collect.get(i).get(0).toString();
+            String s1 = "analyze " + source_table;
+            String s2 = "analyze ng_rt_" + tn;
+            Stream.of(s0, s1, s2, collect.get(i).get(1)).filter(StringUtils::isNotBlank).forEach(x -> HoloUtils.exexSql(holoClient, x));
+            holoClient.close();
+        }
+        //最终聚合
+        HoloClient holoClient = HoloUtils.init();
+        String t0 = "truncate table " + result_table;
+        String t1 = "analyze " + result_table;
+        HashMap<String, String> m = new HashMap<>();
+        m.put("source_table", source_table);
+        m.put("result_table", result_table);
+        String t2 = freeMarkUtil.genStr("agg_exists_step3.ftl", m);
+        Stream.of(t0, t1, t2).filter(StringUtils::isNotBlank).forEach(x -> HoloUtils.exexSql(holoClient, x));
+        holoClient.close();
+
+    }
+
     private List<Tuple> initSql(List<String> list, JobArgs jobArgs, ArrayList<String> tnList) {
         return SummaryArgs.SUMMARY_ARGS.entrySet()
                 .stream()
@@ -125,6 +162,49 @@ public class CalcSummaryJob {
                 }).collect(Collectors.toList());
     }
 
+    private List<Tuple> initSql2(List<String> list, String source_table) {
+        return SummaryArgs.SUMMARY_ARGS.entrySet()
+                .stream()
+                .filter(x -> (list.isEmpty() || list.contains(x.getKey())))
+                .filter(y -> {
+                    List<SummaryArgs.ValueAlias> l = y.getValue()
+                            .getValueAlias()
+                            .stream()
+                            .filter(SummaryArgs.ValueAlias::isSum)
+                            .collect(Collectors.toList());
+                    return l.size() > 0;
+                })
+                .map(x -> {
+                    Map<String, String> m0 = x.getValue()
+                            .getArgsInfo()
+                            .stream()
+                            .collect(Collectors.toMap(SummaryArgs.ArgsInfo::getCategory, y -> y.filterField, (t1, t2) -> t2));
+
+                    List<String> l1 = x.getValue()
+                            .getValueAlias()
+                            .stream()
+                            .filter(SummaryArgs.ValueAlias::isSum)
+                            .map(SummaryArgs.ValueAlias::getCategory)
+                            .filter(m0::containsKey)
+                            .distinct()
+                            .collect(Collectors.toList());
+
+                    String tn = x.getKey();
+                    String p_sql = l1.stream().map(a -> {
+                        Map<String, String> m = new HashMap<>();
+                        m.put("tn", tn);
+                        m.put("keyno", m0.get(a));
+                        return freeMarkUtil.genStr("agg_exists_step1.ftl", m);
+                    }).collect(Collectors.joining("\nUNION ALL\n"));
+                    Map<String, String> m2 = new HashMap<>();
+                    m2.put("table_view", p_sql);
+                    m2.put("tn", tn);
+                    m2.put("source_table", source_table);
+                    String calc_sql = freeMarkUtil.genStr("agg_exists_step2.ftl", m2);
+                    return new Tuple(tn, calc_sql);
+                }).collect(Collectors.toList());
+    }
+
     private void tranIndex(JobArgs jobArgs, String tn, String type) throws IOException {
         String c_index = Stream.of(jobArgs.getTargetIndexPrefix(), type, tn, jobArgs.getTargetIndexSuffix())
                 .filter(StringUtils::isNotBlank).collect(Collectors.joining("_"));

+ 6 - 0
src/main/resources/templates/agg_exists_step1.ftl

@@ -0,0 +1,6 @@
+SELECT
+    unnest(${keyno}) AS id
+FROM
+    ng_rt_${tn}
+WHERE
+    deleted IN ('0')

+ 11 - 0
src/main/resources/templates/agg_exists_step2.ftl

@@ -0,0 +1,11 @@
+INSERT INTO ${source_table}
+SELECT
+    id,
+    '${tn}' AS tn
+FROM (
+${table_view}
+) a
+WHERE
+    LENGTH(id) = 32
+GROUP BY
+    id

+ 13 - 0
src/main/resources/templates/agg_exists_step3.ftl

@@ -0,0 +1,13 @@
+INSERT INTO ${result_table}
+SELECT
+id,
+CONCAT('{', string_agg(dims, ','), '}') AS dims
+FROM (
+SELECT
+*,
+CONCAT('"', tn, '":', 1) AS dims
+FROM
+${source_table}
+) a
+GROUP BY
+id