|
@@ -0,0 +1,113 @@
|
|
|
+package com.winhc.max.compute.graph.job.enterprise_group;
|
|
|
+
|
|
|
+import com.aliyun.odps.graph.Edge;
|
|
|
+import com.aliyun.odps.graph.MutationContext;
|
|
|
+import com.aliyun.odps.io.Text;
|
|
|
+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.GraphLoaderTestData;
|
|
|
+import lombok.SneakyThrows;
|
|
|
+
|
|
|
+import java.util.Locale;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: XuJiakai
|
|
|
+ * 2023/4/20 10:53
|
|
|
+ */
|
|
|
+public class EgReaderTestData extends GraphLoaderTestData {
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ public static void addPersonVertex(MutationContext<Text, EnterpriseGroupVertexValue, HolderEdge, EntGroupMsg> context
|
|
|
+ , String personId
|
|
|
+ ) {
|
|
|
+ EnterpriseGroupVertex enterpriseGroupVertex = new EnterpriseGroupVertex();
|
|
|
+ enterpriseGroupVertex.setId(new Text(completeStr(personId, 33)));
|
|
|
+ enterpriseGroupVertex.setValue(EnterpriseGroupVertexValue.of(personId + "的人名", 6, null, null));
|
|
|
+ context.addVertexRequest(enterpriseGroupVertex);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String completeStr(String val, int length) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ if (val.length() == length) {
|
|
|
+ sb.append(val);
|
|
|
+ } else if (val.length() < length) {
|
|
|
+ sb.append(val);
|
|
|
+ while (sb.length() < length) {
|
|
|
+ sb.append("1");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ sb.append(val, 0, length);
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void addVertex(MutationContext<Text, EnterpriseGroupVertexValue, HolderEdge, EntGroupMsg> context
|
|
|
+ , String keyno
|
|
|
+ ) {
|
|
|
+ if (keyno.equals(keyno.toUpperCase(Locale.ROOT))) {
|
|
|
+ addCompanyVertex(context, keyno);
|
|
|
+ } else {
|
|
|
+ addPersonVertex(context, keyno);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ public static void addCompanyVertex(MutationContext<Text, EnterpriseGroupVertexValue, HolderEdge, EntGroupMsg> context
|
|
|
+ , String companyId
|
|
|
+ ) {
|
|
|
+ EnterpriseGroupVertex enterpriseGroupVertex = new EnterpriseGroupVertex();
|
|
|
+ enterpriseGroupVertex.setId(new Text(completeStr(companyId, 32)));
|
|
|
+ enterpriseGroupVertex.setValue(EnterpriseGroupVertexValue.of(companyId + "公司的名字"));
|
|
|
+ context.addVertexRequest(enterpriseGroupVertex);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param context
|
|
|
+ * @param thisCompanyId 当前公司id
|
|
|
+ * @param holderKeyno 股东id
|
|
|
+ * @param investmentProportion 股东投资比例
|
|
|
+ */
|
|
|
+ @SneakyThrows
|
|
|
+ public static void addEdge(MutationContext<Text, EnterpriseGroupVertexValue, HolderEdge, EntGroupMsg> context
|
|
|
+ , String thisCompanyId, String holderKeyno, Double investmentProportion
|
|
|
+ ) {
|
|
|
+
|
|
|
+ thisCompanyId = completeStr(thisCompanyId, 32);
|
|
|
+ if (holderKeyno.equals(holderKeyno.toUpperCase(Locale.ROOT))) {
|
|
|
+ holderKeyno = completeStr(holderKeyno, 32);
|
|
|
+ } else {
|
|
|
+ holderKeyno = completeStr(holderKeyno, 33);
|
|
|
+ }
|
|
|
+
|
|
|
+ int holderTypeVal = 1;
|
|
|
+ if (holderKeyno.length() == 33) {
|
|
|
+ holderTypeVal = 3;
|
|
|
+ }
|
|
|
+ HolderEdge edgeValue = HolderEdge.of(holderKeyno, holderTypeVal, investmentProportion);
|
|
|
+
|
|
|
+ Edge<Text, HolderEdge> edge = new Edge<Text, HolderEdge>(
|
|
|
+ new Text(holderKeyno), edgeValue);
|
|
|
+ context.addEdgeRequest(new Text(thisCompanyId), edge);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void loadTestData(MutationContext context) {
|
|
|
+
|
|
|
+ addVertex(context, "A");
|
|
|
+ addVertex(context, "B");
|
|
|
+ addVertex(context, "C");
|
|
|
+ addVertex(context, "D");
|
|
|
+ addVertex(context, "E");
|
|
|
+ addVertex(context, "g");
|
|
|
+
|
|
|
+ addEdge(context, "B", "A", 1d);
|
|
|
+ addEdge(context, "C", "B", 1d);
|
|
|
+ addEdge(context, "D", "B", 1d);
|
|
|
+ addEdge(context, "E", "B", 0.8d);
|
|
|
+ addEdge(context, "E", "g", 0.2d);
|
|
|
+ }
|
|
|
+}
|