Jelajahi Sumber

fix: 企业集团优化

- 解决复杂投资链路情况下,导致公司id的重复
- 解决复杂投资链路情况下,导致集团成员企业和集团股东和对外投资的交叉
许家凯 1 tahun lalu
induk
melakukan
5e4ee542e5

+ 18 - 1
src/main/java/com/winhc/max/compute/graph/job/enterprise_group/EnterpriseGroupUtils.java

@@ -72,6 +72,24 @@ public class EnterpriseGroupUtils {
         List<String> collect = edges.stream().map(Edge::getDestVertexId).map(Text::toString).filter(e -> !set.contains(e)).collect(Collectors.toList());
         return collect;
     }
+    public static List<String> tuple2ListByDistinct(Tuple tuple) {
+        if (tuple == null) {
+            return Collections.emptyList();
+        }
+
+        List<String> collect = tuple.getAll().stream().filter(Objects::nonNull).map(e -> ((Text) e).toString()).distinct().collect(Collectors.toList());
+        return collect;
+    }
+
+
+    public static Set<String> tuple2Set(Tuple tuple) {
+        if (tuple == null) {
+            return Collections.emptySet();
+        }
+
+        Set<String> collect = tuple.getAll().stream().filter(Objects::nonNull).map(e -> ((Text) e).toString()).collect(Collectors.toSet());
+        return collect;
+    }
 
 
     public static List<String> tuple2List(Tuple tuple) {
@@ -79,7 +97,6 @@ public class EnterpriseGroupUtils {
             return Collections.emptyList();
         }
 
-
         List<String> collect = tuple.getAll().stream().filter(Objects::nonNull).map(e -> ((Text) e).toString()).collect(Collectors.toList());
         return collect;
     }

+ 22 - 7
src/main/java/com/winhc/max/compute/graph/job/enterprise_group/EnterpriseGroupVertex.java

@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -120,7 +121,13 @@ public class EnterpriseGroupVertex extends
                 for (String destVertexId : vertexInfo.getHoldCompanyId()) {
                     boolean flag = message.routeLog(destVertexId);
                     if (!flag) {
-                        mergeMsg2Vertex(getValue(), Arrays.asList(message), null);
+                        //todo:debug
+                       /*prodEnvDebug.debug_3(getId()
+                                , "\nvertexInfo: {}\nroteLog:{}\n"
+                                , vertexInfo
+                                ,message
+                        );
+                        mergeMsg2Vertex(getValue(), Arrays.asList(message), null);*/
                         continue;
                     }
                     message.addStockRightControlChain(getId().toString(), vertexInfo.getInvestmentProportion(destVertexId), destVertexId);
@@ -211,19 +218,27 @@ public class EnterpriseGroupVertex extends
         if (!getValue().isOutput()) {
             return;
         }
-
+        Set<String> holdCompanyId = getValue().getHoldCompanyIds().tuple2Set();
 
         //输出
         Text enterprise_group_hold_company_id = getId();
         Text enterprise_group_hold_company_name = getValue().getCompanyName();
-        LongWritable hold_num = new LongWritable(getValue().getHoldNum().get() + 1);
-        Text group_company_id = new Text(gson.toJson(getValue().getHoldCompanyIds().tuple2List()));
-        Text group_investment_company_id = new Text(gson.toJson(getValue().getGroupInvestmentCompanyIds().tuple2List()));
-        Text group_holder_company_id = new Text(gson.toJson(getValue().getGroupHolderCompanyIds().tuple2List()));
+        Text group_company_id = new Text(gson.toJson(holdCompanyId));
+
+        //todo:可能会出现集团股东 本就是控股企业,需要排除
+        Set<String> groupInvestmentCompanyId = getValue().getGroupInvestmentCompanyIds().tuple2Set();
+        groupInvestmentCompanyId.removeAll(holdCompanyId);
+        Text group_investment_company_id = new Text(gson.toJson(groupInvestmentCompanyId));
+        Set<String> groupHolderCompanyId = getValue().getGroupHolderCompanyIds().tuple2Set();
+        groupHolderCompanyId.removeAll(holdCompanyId);
+        Text group_holder_company_id = new Text(gson.toJson(groupHolderCompanyId));
         Text group_controller_keyno = getValue().getGroupControllerKeyno();
         Text stockRightControlChain = getValue().getStockRightControlChain();
 
-        List<String> subgroupList = getValue().getSubgroup().tuple2List();
+        LongWritable hold_num = new LongWritable(holdCompanyId.size() + 1);
+
+
+        List<String> subgroupList = getValue().getSubgroup().tuple2ListByDistinct();
         Text subgroup = new Text();
         if (getValue().getCompanyName().toString().contains("集团")) {
             subgroup = new Text(subgroupList.stream().filter(e -> !e.equals(getId().toString())).collect(Collectors.joining(",")));

+ 0 - 14
src/main/java/com/winhc/max/compute/graph/job/enterprise_group/ProdEnvDebug.java

@@ -6,7 +6,6 @@ import com.aliyun.odps.io.Text;
 import com.winhc.max.compute.graph.util.BaseUtils;
 
 import java.util.Arrays;
-import java.util.HashSet;
 import java.util.Set;
 import java.util.stream.Collectors;
 
@@ -104,17 +103,4 @@ public class ProdEnvDebug {
         }
     }
 
-
-    public static void main(String[] args) {
-        ProdEnvDebug prodEnvDebug = new ProdEnvDebug();
-
-        prodEnvDebug.debugIndices = new HashSet<String>() {{
-            add("1");
-        }};
-
-        prodEnvDebug.enableDebug = true;
-        prodEnvDebug.debugVertexId = "aaa";
-
-        prodEnvDebug.debug_1(new Text("aaa"),"{}","a");
-    }
 }

+ 14 - 0
src/main/java/com/winhc/max/compute/graph/job/enterprise_group/entity/EntGroupMsg.java

@@ -249,6 +249,20 @@ public class EntGroupMsg implements Writable {
         stockRightControlChain.readFields(in);
         this.sourceVertexId.readFields(in);
         this.sourceVertexName.readFields(in);
+    }
 
+    @Override
+    public String toString() {
+        return "EntGroupMsg{" +
+                "msgType=" + msgType +
+                ", holdNum=" + holdNum +
+                ", holdCompanyIds=" + holdCompanyIds +
+                ", groupInvestmentCompanyIds=" + groupInvestmentCompanyIds +
+                ", groupHolderCompanyIds=" + groupHolderCompanyIds +
+                ", sourceVertexId=" + sourceVertexId +
+                ", sourceVertexName=" + sourceVertexName +
+                ", routeLog=" + routeLog +
+                ", stockRightControlChain=" + stockRightControlChain +
+                '}';
     }
 }