|
@@ -0,0 +1,245 @@
|
|
|
|
+package com.winhc.max.compute.graph.job.enterprise_group;
|
|
|
|
+
|
|
|
|
+import com.aliyun.odps.graph.ComputeContext;
|
|
|
|
+import com.aliyun.odps.graph.Edge;
|
|
|
|
+import com.aliyun.odps.graph.Vertex;
|
|
|
|
+import com.aliyun.odps.graph.WorkerContext;
|
|
|
|
+import com.aliyun.odps.io.BooleanWritable;
|
|
|
|
+import com.aliyun.odps.io.LongWritable;
|
|
|
|
+import com.aliyun.odps.io.NullWritable;
|
|
|
|
+import com.aliyun.odps.io.Text;
|
|
|
|
+import com.aliyun.odps.utils.StringUtils;
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
+import com.winhc.max.compute.graph.job.enterprise_group.entity.EntGroupMsg;
|
|
|
|
+import com.winhc.max.compute.graph.job.enterprise_group.entity.EnterpriseGroupVertexValue;
|
|
|
|
+import com.winhc.max.compute.graph.job.enterprise_group.entity.HolderEdge;
|
|
|
|
+import com.winhc.max.compute.graph.util.WritableRecordExtensions;
|
|
|
|
+import lombok.experimental.ExtensionMethod;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author: XuJiakai
|
|
|
|
+ * 2023/2/7 13:59
|
|
|
|
+ */
|
|
|
|
+@ExtensionMethod({
|
|
|
|
+ WritableRecordExtensions.class
|
|
|
|
+ , EnterpriseGroupUtils.class
|
|
|
|
+})
|
|
|
|
+@Slf4j
|
|
|
|
+public class EnterpriseGroupVertex extends
|
|
|
|
+ Vertex<Text, EnterpriseGroupVertexValue, HolderEdge, EntGroupMsg> {
|
|
|
|
+
|
|
|
|
+ private static Gson gson;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setup(WorkerContext<Text, EnterpriseGroupVertexValue, HolderEdge, EntGroupMsg> context) throws IOException {
|
|
|
|
+ gson = new Gson();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void compute(ComputeContext<Text, EnterpriseGroupVertexValue, HolderEdge, EntGroupMsg> context, Iterable<EntGroupMsg> messages) throws IOException {
|
|
|
|
+ context.aggregate(NullWritable.get());
|
|
|
|
+ if (getId().toString().length() == 33) {
|
|
|
|
+ voteToHalt();
|
|
|
|
+ //跳过人员节点
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<String> list = getValue().getLegalEntityIds().tuple2List();
|
|
|
|
+
|
|
|
|
+ //获取需要传递的下一个节点,如无,当前企业则为控股控股公司。
|
|
|
|
+ Map<String, Double> majorityShareholder = new HashMap<>();
|
|
|
|
+ List<String> thisVertexHoldKeyno = new ArrayList<>();
|
|
|
|
+ List<String> thisVertexHoldCompanyId = new ArrayList<>();
|
|
|
|
+ List<String> thisVertexOtherHolderKeyno = new ArrayList<>();
|
|
|
|
+ List<String> thisVertexOtherHolderCompanyId = new ArrayList<>();
|
|
|
|
+ if (hasEdges()) {
|
|
|
|
+ //获取下游目标节点
|
|
|
|
+ List<Edge<Text, HolderEdge>> edges = getEdges();
|
|
|
|
+ majorityShareholder = edges.getMajorityShareholder(list);
|
|
|
|
+ thisVertexHoldKeyno = new ArrayList<>(majorityShareholder.keySet());
|
|
|
|
+ thisVertexHoldCompanyId = thisVertexHoldKeyno.stream().filter(e -> e.length() == 32).collect(Collectors.toList());
|
|
|
|
+ thisVertexOtherHolderKeyno = edges.getOtherHolder(thisVertexHoldKeyno);
|
|
|
|
+ thisVertexOtherHolderCompanyId = thisVertexOtherHolderKeyno.stream().filter(e -> e.length() == 32).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ //todo:如果控股股东中有国有企业,则将国有企业从控股股东中移出
|
|
|
|
+ Set<String> collect = edges.stream().filter(e -> {
|
|
|
|
+ int i = e.getValue().getHolderType().get();
|
|
|
|
+ return i == 2;
|
|
|
|
+ }).map(e -> e.getDestVertexId().toString()).collect(Collectors.toSet());
|
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
|
+ thisVertexHoldCompanyId = thisVertexHoldCompanyId.stream().filter(e -> !collect.contains(e)).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //将本节点传递到下一节点
|
|
|
|
+ if (!getValue().isSendMsg()) {
|
|
|
|
+ for (String destVertexId : thisVertexHoldCompanyId) {
|
|
|
|
+ //传递控股企业
|
|
|
|
+ EntGroupMsg entGroupMsg = EntGroupMsg.ofByType_1(getId(), getValue().getCompanyName(), thisVertexOtherHolderCompanyId);
|
|
|
|
+ boolean flag = entGroupMsg.routeLog(destVertexId);
|
|
|
|
+ if (!flag) {
|
|
|
|
+// getValue().setOutput();
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ entGroupMsg.addStockRightControlChain(getId().toString(), majorityShareholder.get(destVertexId), destVertexId);
|
|
|
|
+
|
|
|
|
+ context.sendMessage(new Text(destVertexId), entGroupMsg);
|
|
|
|
+ context.aggregate(new BooleanWritable(true));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (String destVertexId : thisVertexOtherHolderCompanyId) {
|
|
|
|
+ //传递参股企业
|
|
|
|
+ EntGroupMsg entGroupMsg = EntGroupMsg.ofByType_2(getId(), getValue().getCompanyName());
|
|
|
|
+ boolean flag = entGroupMsg.routeLog(destVertexId);
|
|
|
|
+ if (!flag) {
|
|
|
|
+// getValue().setOutput(); todo:参股企业没必要输出
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ context.sendMessage(new Text(destVertexId), entGroupMsg);
|
|
|
|
+ context.aggregate(new BooleanWritable(true));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (thisVertexHoldCompanyId.isEmpty()) {
|
|
|
|
+ //如果没有控股企业,则本节点为集团,需将本节点的参股股东,添加至集团股东
|
|
|
|
+ List<String> groupHolderCompanyIds = getValue().getGroupHolderCompanyIds().tuple2List();
|
|
|
|
+ groupHolderCompanyIds.addAll(thisVertexOtherHolderCompanyId);
|
|
|
|
+ getValue().setGroupHolderCompanyIds(groupHolderCompanyIds);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ getValue().setEndFlag();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //是否将消息汇总至该节点
|
|
|
|
+ boolean collect = thisVertexHoldCompanyId.isEmpty();
|
|
|
|
+
|
|
|
|
+ if (collect) {
|
|
|
|
+ //无法传递,则在本节点汇总
|
|
|
|
+ mergeMsg2Vertex(getValue(), messages, thisVertexHoldKeyno);
|
|
|
|
+ } else {
|
|
|
|
+ for (EntGroupMsg message : messages) {
|
|
|
|
+ //将本节点获取的消息直接传递至下一节点,只传递到控股企业。不必将接收到的参股企业做区分,直接只往控股企业传递就行
|
|
|
|
+ for (String destVertexId : thisVertexHoldCompanyId) {
|
|
|
|
+ boolean flag = message.routeLog(destVertexId);
|
|
|
|
+ if (!flag) {
|
|
|
|
+ mergeMsg2Vertex(getValue(), Arrays.asList(message), Collections.emptyList());
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ message.addStockRightControlChain(getId().toString(), majorityShareholder.get(destVertexId), destVertexId);
|
|
|
|
+
|
|
|
|
+ context.sendMessage(new Text(destVertexId), message);
|
|
|
|
+ context.aggregate(new BooleanWritable(true));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ voteToHalt();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 将msg信息合并到当前节点
|
|
|
|
+ *
|
|
|
|
+ * @param vertexEntity
|
|
|
|
+ * @param messages
|
|
|
|
+ * @param thisVertexHoldKeyno
|
|
|
|
+ */
|
|
|
|
+ private static void mergeMsg2Vertex(EnterpriseGroupVertexValue vertexEntity, Iterable<EntGroupMsg> messages, List<String> thisVertexHoldKeyno) {
|
|
|
|
+ long holdNum = vertexEntity.getHoldNum().get();
|
|
|
|
+ List<String> holdCompanyId = vertexEntity.getHoldCompanyIds().tuple2List();
|
|
|
|
+ List<String> groupInvestmentCompanyId = vertexEntity.getGroupInvestmentCompanyIds().tuple2List();
|
|
|
|
+ List<String> groupHolderCompanyId = vertexEntity.getGroupHolderCompanyIds().tuple2List();
|
|
|
|
+ List<String> stockRightControlChain = Arrays.stream(vertexEntity.getStockRightControlChain().toString().split(",")).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ for (EntGroupMsg message : messages) {
|
|
|
|
+ holdNum += message.getHoldNum().get();
|
|
|
|
+ holdCompanyId.addAll(message.getHoldCompanyIds().tuple2List());
|
|
|
|
+ groupHolderCompanyId.addAll(message.getGroupHolderCompanyIds().tuple2List());
|
|
|
|
+ groupInvestmentCompanyId.addAll(message.getGroupInvestmentCompanyIds().tuple2List());
|
|
|
|
+ stockRightControlChain.add(message.getStockRightControlChain().toString());
|
|
|
|
+ }
|
|
|
|
+ Text groupControllerKeyno = new Text();
|
|
|
|
+ if (!thisVertexHoldKeyno.isEmpty()) {
|
|
|
|
+ groupControllerKeyno = new Text(String.join(",", thisVertexHoldKeyno));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String collect = stockRightControlChain.stream().filter(StringUtils::isNotBlank).collect(Collectors.joining(","));
|
|
|
|
+
|
|
|
|
+ vertexEntity.setHoldNum(holdNum);
|
|
|
|
+ vertexEntity.setHoldCompanyIds(holdCompanyId);
|
|
|
|
+ vertexEntity.setGroupInvestmentCompanyIds(groupInvestmentCompanyId);
|
|
|
|
+ vertexEntity.setGroupHolderCompanyIds(groupHolderCompanyId);
|
|
|
|
+ vertexEntity.setGroupControllerKeyno(groupControllerKeyno);
|
|
|
|
+ vertexEntity.setStockRightControlChain(new Text(collect));
|
|
|
|
+ vertexEntity.setOutput();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void cleanup(WorkerContext<Text, EnterpriseGroupVertexValue, HolderEdge, EntGroupMsg> context) throws IOException {
|
|
|
|
+ if (getId().toString().length() == 33) {
|
|
|
|
+ //跳过人员节点
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //判断是否是集团企业
|
|
|
|
+// if (hasEdges()) {
|
|
|
|
+// List<Edge<Text, HolderEdge>> edges = getEdges();
|
|
|
|
+//
|
|
|
|
+// List<String> thisVertexHoldKeyno = new ArrayList<>(edges.getMajorityShareholder().keySet());
|
|
|
|
+// List<String> thisVertexHoldCompanyId = thisVertexHoldKeyno.stream().filter(e -> e.length() == 32).collect(Collectors.toList());
|
|
|
|
+//
|
|
|
|
+// if (!getValue().isOutput() && !thisVertexHoldCompanyId.isEmpty()) {
|
|
|
|
+// //不属于企业集团
|
|
|
|
+// return;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ if(!getValue().isOutput()){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //输出
|
|
|
|
+ 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_controller_keyno = getValue().getGroupControllerKeyno();
|
|
|
|
+ Text stockRightControlChain = getValue().getStockRightControlChain();
|
|
|
|
+
|
|
|
|
+// System.out.println("save:"
|
|
|
|
+// + enterprise_group_hold_company_id + ","
|
|
|
|
+// + enterprise_group_hold_company_name + ","
|
|
|
|
+// + hold_num + ","
|
|
|
|
+// + group_company_id + ","
|
|
|
|
+// + group_investment_company_id + ","
|
|
|
|
+// + group_holder_company_id + ","
|
|
|
|
+// + group_controller_keyno + ","
|
|
|
|
+// + stockRightControlChain
|
|
|
|
+// );
|
|
|
|
+
|
|
|
|
+ if (hold_num.get() > 200) {
|
|
|
|
+ String s = EnterpriseGroupUtils.stockChainTrim(enterprise_group_hold_company_id.toString(), stockRightControlChain.toString(), 10);
|
|
|
|
+ stockRightControlChain = new Text(s);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ context.write(enterprise_group_hold_company_id
|
|
|
|
+ , enterprise_group_hold_company_id
|
|
|
|
+ , enterprise_group_hold_company_name
|
|
|
|
+ , hold_num
|
|
|
|
+ , group_company_id
|
|
|
|
+ , group_investment_company_id
|
|
|
|
+ , group_holder_company_id
|
|
|
|
+ , group_controller_keyno
|
|
|
|
+ , stockRightControlChain
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+}
|