|
@@ -4,7 +4,6 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
import com.winhc.common.enums.CompanyEnum;
|
|
|
import com.winhc.db.mongodb.dataobject.NodeRelationError;
|
|
@@ -83,21 +82,6 @@ public class CompanyUtils {
|
|
|
return list.stream().filter(r -> (r.getOrDefault("topic_type", "-1").equals(type))).collect(toList());
|
|
|
}
|
|
|
|
|
|
- public static List<String> getMergeIds(List<Map<String, Object>> list) {
|
|
|
- return list.stream()
|
|
|
- .filter(r -> r.getOrDefault("start_id", "0").toString().length() == 33)
|
|
|
- .collect(Collectors.toMap(t -> t.getOrDefault("start_id", "0").toString(), t -> t, (n, o) -> n))
|
|
|
- .values().stream().map(x -> {
|
|
|
- Map<String, String> m = (Map) x;
|
|
|
- ImmutableMap<String, String> m2 = ImmutableMap.of(
|
|
|
- "person_id", m.get("start_id")
|
|
|
- , "name", m.get("start_name")
|
|
|
- , "topic_type", "800"
|
|
|
- );
|
|
|
- return JSONObject.toJSONString(m2, SerializerFeature.WriteMapNullValue);
|
|
|
- }).collect(toList());
|
|
|
- }
|
|
|
-
|
|
|
public static List<Map<String, Object>> getMergeIds2(List<Map<String, Object>> list) {
|
|
|
return list.stream()
|
|
|
.filter(r -> r.getOrDefault("start_id", "0").toString().length() == 33)
|
|
@@ -151,10 +135,7 @@ public class CompanyUtils {
|
|
|
}
|
|
|
|
|
|
public static String writeNeo4j2(Session session, String cql, HashMap<String, Object> parameters) {
|
|
|
- List<Record> dataList = session.writeTransaction(tx -> {
|
|
|
- Result result = tx.run(cql, parameters);
|
|
|
- return result.list();
|
|
|
- });
|
|
|
+ List<Record> dataList = getRecords(session, cql, parameters);
|
|
|
Map<String, MergePerson> data = dataList.stream()
|
|
|
.map(record -> JSON.parseObject(JSON.toJSONString(record.asMap()), MergePerson.class))
|
|
|
.collect(Collectors.toMap(MergePerson::getId, t -> t, (n, o) -> n));
|
|
@@ -163,26 +144,25 @@ public class CompanyUtils {
|
|
|
}
|
|
|
|
|
|
public static List<Map<String, String>> writeNeo4j1(Session session, String cql, HashMap<String, Object> parameters) {
|
|
|
- List<Record> dataList = session.writeTransaction(tx -> {
|
|
|
- Result result = tx.run(cql, parameters);
|
|
|
- return result.list();
|
|
|
- });
|
|
|
- Map<String, List<MergePerson>> collect = dataList.stream()
|
|
|
- .map(record -> JSON.parseObject(JSON.toJSONString(record.asMap()), MergePerson.class))
|
|
|
- .collect(Collectors.groupingBy(MergePerson::getNew_human_pid));
|
|
|
+ Collection<List<MergePerson>> collect = getMergePerson(session, cql, parameters);
|
|
|
+ return trans(collect);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<Map<String, String>> trans(Collection<List<MergePerson>> collect) {
|
|
|
List<Map<String, String>> list = new ArrayList<>();
|
|
|
- collect.forEach((k, v) -> {
|
|
|
- v.stream().max(Comparator.comparing(MergePerson::getCnt)).ifPresent(maxPerson -> v.forEach(m -> {
|
|
|
- if (!m.getOld_human_pid().equals(maxPerson.getOld_human_pid())) {
|
|
|
- HashMap<String, String> map = new HashMap<>();
|
|
|
- map.put("new_human_pid", maxPerson.getOld_human_pid());
|
|
|
- map.put("new_human_name", maxPerson.getOld_human_name());
|
|
|
- map.put("old_human_pid", m.getOld_human_pid());
|
|
|
- map.put("old_human_name", m.getOld_human_name());
|
|
|
- list.add(map);
|
|
|
- }
|
|
|
- }));
|
|
|
- });
|
|
|
+ collect.forEach(v -> v.stream()
|
|
|
+ .max(Comparator.comparing(MergePerson::getCnt))
|
|
|
+ .ifPresent(maxPerson -> v.forEach(m -> {
|
|
|
+ if (!m.getOld_human_pid().equals(maxPerson.getOld_human_pid())) {
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("new_human_pid", maxPerson.getOld_human_pid());
|
|
|
+ map.put("new_human_name", maxPerson.getOld_human_name());
|
|
|
+ map.put("old_human_pid", m.getOld_human_pid());
|
|
|
+ map.put("old_human_name", m.getOld_human_name());
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+ })));
|
|
|
return list.stream().collect(
|
|
|
Collectors.collectingAndThen(
|
|
|
Collectors.toCollection(
|
|
@@ -190,14 +170,24 @@ public class CompanyUtils {
|
|
|
), ArrayList::new
|
|
|
)
|
|
|
);
|
|
|
+ }
|
|
|
|
|
|
+ public static Collection<List<MergePerson>> getMergePerson(Session session, String cql, HashMap<String, Object> parameters) {
|
|
|
+ List<Record> dataList = getRecords(session, cql, parameters);
|
|
|
+ return dataList.stream()
|
|
|
+ .map(record -> JSON.parseObject(JSON.toJSONString(record.asMap()), MergePerson.class))
|
|
|
+ .collect(Collectors.groupingBy(MergePerson::getNew_human_pid)).values();
|
|
|
}
|
|
|
|
|
|
- public static List<Map<String, String>> writeNeo4j3(Session session, String cql, HashMap<String, Object> parameters) {
|
|
|
- List<Record> dataList = session.writeTransaction(tx -> {
|
|
|
+ private static List<Record> getRecords(Session session, String cql, HashMap<String, Object> parameters) {
|
|
|
+ return session.writeTransaction(tx -> {
|
|
|
Result result = tx.run(cql, parameters);
|
|
|
return result.list();
|
|
|
});
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<Map<String, String>> writeNeo4j3(Session session, String cql, HashMap<String, Object> parameters) {
|
|
|
+ List<Record> dataList = getRecords(session, cql, parameters);
|
|
|
Set<String> newIds = new HashSet<>();
|
|
|
Set<String> oldIds = new HashSet<>();
|
|
|
List<Map<String, String>> list = dataList.stream()
|
|
@@ -266,8 +256,8 @@ public class CompanyUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static String mergePerson(Session session, List<Map<String, String>> mergeData) {
|
|
|
- String data = null;
|
|
|
+ public static String mergePerson(Session session, List<Map<String, String>> mergeData) {
|
|
|
+ String data = null;
|
|
|
if (!mergeData.isEmpty()) {
|
|
|
final String merge_cql =
|
|
|
"\nWITH {merge_list} AS batch_list \n" +
|