|
@@ -1,15 +1,15 @@
|
|
package com.winhc.utils;
|
|
package com.winhc.utils;
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.winhc.common.enums.CompanyEnum;
|
|
import com.winhc.common.enums.CompanyEnum;
|
|
import com.winhc.db.mongodb.dataobject.NodeRelationError;
|
|
import com.winhc.db.mongodb.dataobject.NodeRelationError;
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
import org.neo4j.driver.Result;
|
|
import org.neo4j.driver.Result;
|
|
import org.neo4j.driver.Session;
|
|
import org.neo4j.driver.Session;
|
|
-import java.util.Date;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+
|
|
|
|
+import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -25,8 +25,51 @@ public class CompanyUtils {
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static List<Map<String, Object>> mapPlus(List<ConsumerRecord<?, ?>> records) {
|
|
|
|
+ return records.stream().filter(r -> (r != null && r.value() != null)).map(r -> {
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(r.value().toString());
|
|
|
|
+ String person_name = jsonObject.getString("person_name");
|
|
|
|
+ JSONArray company_infos = jsonObject.getJSONArray("company_infos");
|
|
|
|
+ ArrayList<String> list = new ArrayList<>();
|
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
|
+ for (Object company_info : company_infos) {
|
|
|
|
+ JSONObject jsonObject1 = (JSONObject) company_info;
|
|
|
|
+ String company_id = jsonObject1.getString("company_id");
|
|
|
|
+ list.add(company_id);
|
|
|
|
+ }
|
|
|
|
+ map.put("name", person_name);
|
|
|
|
+ map.put("company_ids", listToString(list));
|
|
|
|
+ return map;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static List<Map<String, Object>> mapPlusV1(List<ConsumerRecord<?, ?>> records) {
|
|
|
|
+ return records.stream().filter(r -> (r != null && r.value() != null)).map(r -> {
|
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(r.value().toString());
|
|
|
|
+ String merge_human_pid = jsonObject.getString("merge_human_pid");
|
|
|
|
+ String deleted_human_pid = jsonObject.getString("deleted_human_pid");
|
|
|
|
+
|
|
|
|
+ map.put("merge_human_pid", merge_human_pid);
|
|
|
|
+ map.put("deleted_human_pid", deleted_human_pid);
|
|
|
|
+ return map;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String listToString(List<String> list) {
|
|
|
|
+ if (list.size() == 0) return "";
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ sb.append(list.get(i));
|
|
|
|
+ if (i != list.size() - 1) {
|
|
|
|
+ sb.append("&");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return sb.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
public static List<Map<String, Object>> filterList(List<Map<String, Object>> list, String type) {
|
|
public static List<Map<String, Object>> filterList(List<Map<String, Object>> list, String type) {
|
|
- return list.stream().filter(r -> (r.getOrDefault("topic_type","-1").equals(type))).collect(Collectors.toList());
|
|
|
|
|
|
+ return list.stream().filter(r -> (r.getOrDefault("topic_type", "-1").equals(type))).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
public static List<NodeRelationError> toMessage(List<ConsumerRecord> records, String errorMessage) {
|
|
public static List<NodeRelationError> toMessage(List<ConsumerRecord> records, String errorMessage) {
|
|
@@ -46,7 +89,7 @@ public class CompanyUtils {
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
- public static String writeNeo4j(Session session, String cql, HashMap<String,Object> parameters) {
|
|
|
|
|
|
+ public static String writeNeo4j(Session session, String cql, HashMap<String, Object> parameters) {
|
|
String data = session.writeTransaction(tx -> {
|
|
String data = session.writeTransaction(tx -> {
|
|
Result result = tx.run(cql, parameters);
|
|
Result result = tx.run(cql, parameters);
|
|
return "success";
|
|
return "success";
|
|
@@ -54,8 +97,8 @@ public class CompanyUtils {
|
|
return data;
|
|
return data;
|
|
}
|
|
}
|
|
|
|
|
|
- public static String getIncrPersonLabel(){
|
|
|
|
- return CompanyEnum.Lable.新增.code +DateUtil.getDateBefore(-1).replace("-", "");
|
|
|
|
|
|
+ public static String getIncrPersonLabel() {
|
|
|
|
+ return CompanyEnum.Lable.新增.code + DateUtil.getDateBefore(-1).replace("-", "");
|
|
}
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|