|
@@ -0,0 +1,301 @@
|
|
|
+package com.winhc.tmp;
|
|
|
+
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.winhc.utils.CompanyUtils;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.io.LineIterator;
|
|
|
+import org.neo4j.driver.Driver;
|
|
|
+import org.neo4j.driver.Session;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author π
|
|
|
+ * @Description:临时测试任务
|
|
|
+ * @date 2021/2/26 13:53
|
|
|
+ */
|
|
|
+
|
|
|
+//@Component
|
|
|
+@Slf4j
|
|
|
+//@EnableScheduling
|
|
|
+//@AllArgsConstructor
|
|
|
+public class PidUpdateExportTask {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("DriverV2")
|
|
|
+ Driver driver;
|
|
|
+
|
|
|
+ //@Scheduled(cron = "00 00 01 * * ?")
|
|
|
+ //@Scheduled(cron = "*/20 * * * * ?")
|
|
|
+ //@Scheduled(cron = "55 55 13 01 06 ?")
|
|
|
+ public void parseCSV() throws IOException {
|
|
|
+ String path = "D:\\data\\opt\\export\\error_pid_all.csv";
|
|
|
+ LineIterator it = FileUtils.lineIterator(FileUtil.file(path), "UTF-8");
|
|
|
+ try {
|
|
|
+ int i = 0;
|
|
|
+ List<Map<String, Object>> batch_list = new ArrayList<>();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ String person_id = it.nextLine();
|
|
|
+ ++i;
|
|
|
+ if (i == 1) continue;
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("person_id", person_id);
|
|
|
+ String message = JSON.toJSONString(map);
|
|
|
+ System.out.println(message);
|
|
|
+ batch_list.add(map);
|
|
|
+ if(batch_list.size() == 5000){
|
|
|
+ setLabel(batch_list, "个人", "update20210531");
|
|
|
+ System.out.println("size: "+batch_list.size());
|
|
|
+ batch_list.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(batch_list.size() > 0){
|
|
|
+ setLabel(batch_list, "个人", "update20210531");
|
|
|
+ System.out.println("size: "+batch_list.size());
|
|
|
+ batch_list.clear();
|
|
|
+ }
|
|
|
+ System.out.println(batch_list.size());
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ }finally {
|
|
|
+ LineIterator.closeQuietly(it);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setLabel(List<Map<String, Object>> batch_list, String fromLabel, String toLabel) {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ Session session = driver.session();
|
|
|
+ final String cql = "WITH {batch_list} AS batch_list \n" +
|
|
|
+ "UNWIND batch_list AS row \n" +
|
|
|
+ "MATCH(s:" + fromLabel + "{person_id:row.person_id}) \n" +
|
|
|
+ "SET s:" + toLabel + " \n";
|
|
|
+ log.info("consumer size: {}, cost: {}, cql:{}", batch_list.size(), (System.currentTimeMillis() - start), cql);
|
|
|
+ CompanyUtils.runNeo4j(session, cql, new HashMap<String, Object>() {{
|
|
|
+ put("batch_list", batch_list);
|
|
|
+ }});
|
|
|
+ session.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ //@Scheduled(cron = "00 00 01 * * ?")
|
|
|
+ //@Scheduled(cron = "*/20 * * * * ?")
|
|
|
+ //@Scheduled(cron = "20 43 14 01 06 ?")
|
|
|
+ public void parseTouZiCSV() throws IOException {
|
|
|
+ String path = "D:\\data\\opt\\export\\export-touzi-all.csv";
|
|
|
+ if (!CompanyUtils.isWindows()) {
|
|
|
+ path = "/data/opt/export/export-touzi-all.csv";
|
|
|
+ }
|
|
|
+ LineIterator it = FileUtils.lineIterator(FileUtil.file(path), "UTF-8");
|
|
|
+ try {
|
|
|
+ int i = 0;
|
|
|
+ List<Map<String, Object>> batch_list = new ArrayList<>();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ String line = it.nextLine();
|
|
|
+ ++i;
|
|
|
+ if (i == 1) continue;
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<String> list = Arrays.asList(line.split(",", -1)).stream()
|
|
|
+ .map(x -> x.replaceAll("\"", "")).collect(Collectors.toList());
|
|
|
+ if (list.size() < 2) continue;
|
|
|
+ map.put("person_id", list.get(0));
|
|
|
+ map.put("person_name", list.get(1));
|
|
|
+ map.put("percent", list.get(2));
|
|
|
+ map.put("deleted", list.get(3));
|
|
|
+ map.put("company_id", list.get(4));
|
|
|
+ map.put("company_name", list.get(5));
|
|
|
+ String message = JSON.toJSONString(map);
|
|
|
+ //System.out.println(message);
|
|
|
+ batch_list.add(map);
|
|
|
+ if(batch_list.size() == 1000){
|
|
|
+ setTouZiLabel(batch_list, "个人", "update20210601");
|
|
|
+ System.out.println("size: "+ i);
|
|
|
+ batch_list.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(batch_list.size() > 0){
|
|
|
+ setTouZiLabel(batch_list, "个人", "update20210601");
|
|
|
+ System.out.println("size: "+ i);
|
|
|
+ batch_list.clear();
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ LineIterator.closeQuietly(it);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void setTouZiLabel(List<Map<String, Object>> batch_list, String fromLabel, String toLabel) {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ Session session = driver.session();
|
|
|
+
|
|
|
+ final String cql = "\nWITH {batch_list} AS batch_list \n" +
|
|
|
+ "UNWIND batch_list AS row \n" +
|
|
|
+ "MERGE(s:" + fromLabel + "{person_id:row.person_id}) \n" +
|
|
|
+ "SET s.name=row.person_name, s.person_id=row.person_id \n" +
|
|
|
+ "SET s:" + toLabel + " \n" +
|
|
|
+ "MERGE(e:企业{company_id:row.company_id}) \n" +
|
|
|
+ "SET e.name=row.company_name, e.company_id=row.company_id \n" +
|
|
|
+ "WITH s,e,row \n" +
|
|
|
+ "MERGE(s)-[r:投资]->(e) \n" +
|
|
|
+ "SET r.percent=row.percent, r.deleted=row.deleted \n";
|
|
|
+
|
|
|
+ CompanyUtils.runNeo4j(session, cql, new HashMap<String, Object>() {{
|
|
|
+ put("batch_list", batch_list);
|
|
|
+ }});
|
|
|
+ log.info("consumer size: {}, cost: {}, cql:{}", batch_list.size(), (System.currentTimeMillis() - start), cql);
|
|
|
+ session.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ //@Scheduled(cron = "00 00 01 * * ?")
|
|
|
+ //@Scheduled(cron = "*/20 * * * * ?")
|
|
|
+ //@Scheduled(cron = "50 22 15 01 06 ?")
|
|
|
+ public void parseFaRenCSV() throws IOException {
|
|
|
+ String path = "D:\\data\\opt\\export\\export-faren-all.csv";
|
|
|
+ if (!CompanyUtils.isWindows()) {
|
|
|
+ path = "/data/opt/export/export-faren-all.csv";
|
|
|
+ }
|
|
|
+ LineIterator it = FileUtils.lineIterator(FileUtil.file(path), "UTF-8");
|
|
|
+ try {
|
|
|
+ int i = 0;
|
|
|
+ List<Map<String, Object>> batch_list = new ArrayList<>();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ String line = it.nextLine();
|
|
|
+ ++i;
|
|
|
+ if (i == 1) continue;
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<String> list = Arrays.asList(line.split(",", -1)).stream()
|
|
|
+ .map(x -> x.replaceAll("\"", "")).collect(Collectors.toList());
|
|
|
+ if (list.size() < 2) continue;
|
|
|
+ map.put("person_id", list.get(0));
|
|
|
+ map.put("person_name", list.get(1));
|
|
|
+ map.put("deleted", list.get(2));
|
|
|
+ map.put("company_id", list.get(3));
|
|
|
+ map.put("company_name", list.get(4));
|
|
|
+ String message = JSON.toJSONString(map);
|
|
|
+ //System.out.println(message);
|
|
|
+ batch_list.add(map);
|
|
|
+ if(batch_list.size() == 1000){
|
|
|
+ setFaRenLabel(batch_list, "个人", "update20210601");
|
|
|
+ System.out.println("size: "+ i);
|
|
|
+ batch_list.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(batch_list.size() > 0){
|
|
|
+ setFaRenLabel(batch_list, "个人", "update20210601");
|
|
|
+ System.out.println("size: "+ i);
|
|
|
+ batch_list.clear();
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ LineIterator.closeQuietly(it);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void setFaRenLabel(List<Map<String, Object>> batch_list, String fromLabel, String toLabel) {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ Session session = driver.session();
|
|
|
+
|
|
|
+ final String cql = "\nWITH {batch_list} AS batch_list \n" +
|
|
|
+ "UNWIND batch_list AS row \n" +
|
|
|
+ "MERGE(s:" + fromLabel + "{person_id:row.person_id}) \n" +
|
|
|
+ "SET s.name=row.person_name, s.person_id=row.person_id \n" +
|
|
|
+ "SET s:" + toLabel + " \n" +
|
|
|
+ "MERGE(e:企业{company_id:row.company_id}) \n" +
|
|
|
+ "SET e.name=row.company_name, e.company_id=row.company_id \n" +
|
|
|
+ "WITH s,e,row \n" +
|
|
|
+ "MERGE(s)-[r:法人]->(e) \n" +
|
|
|
+ "SET r.deleted=row.deleted \n";
|
|
|
+
|
|
|
+ CompanyUtils.runNeo4j(session, cql, new HashMap<String, Object>() {{
|
|
|
+ put("batch_list", batch_list);
|
|
|
+ }});
|
|
|
+ log.info("consumer size: {}, cost: {}, cql:{}", batch_list.size(), (System.currentTimeMillis() - start), cql);
|
|
|
+ session.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ //@Scheduled(cron = "00 00 01 * * ?")
|
|
|
+ //@Scheduled(cron = "*/20 * * * * ?")
|
|
|
+ //@Scheduled(cron = "20 39 15 01 06 ?")
|
|
|
+ public void parseGaoGuanCSV() throws IOException {
|
|
|
+ String path = "D:\\data\\opt\\export\\export-gaoguan-all.csv";
|
|
|
+ if (!CompanyUtils.isWindows()) {
|
|
|
+ path = "/data/opt/export/export-gaoguan-all.csv";
|
|
|
+ }
|
|
|
+ LineIterator it = FileUtils.lineIterator(FileUtil.file(path), "UTF-8");
|
|
|
+ try {
|
|
|
+ int i = 0;
|
|
|
+ List<Map<String, Object>> batch_list = new ArrayList<>();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ String line = it.nextLine();
|
|
|
+ ++i;
|
|
|
+ if (i == 1) continue;
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<String> list = Arrays.asList(line.split(",", -1)).stream()
|
|
|
+ .map(x -> x.replaceAll("\"", "")).collect(Collectors.toList());
|
|
|
+ if (list.size() < 2) continue;
|
|
|
+ map.put("person_id", list.get(0));
|
|
|
+ map.put("person_name", list.get(1));
|
|
|
+ map.put("staff_type", list.get(2));
|
|
|
+ map.put("deleted", list.get(3));
|
|
|
+ map.put("company_id", list.get(4));
|
|
|
+ map.put("company_name", list.get(5));
|
|
|
+ String message = JSON.toJSONString(map);
|
|
|
+ System.out.println(message);
|
|
|
+ batch_list.add(map);
|
|
|
+ if(batch_list.size() == 2000){
|
|
|
+ setGaoGuanLabel(batch_list, "个人", "update20210601");
|
|
|
+ System.out.println("size: "+ i);
|
|
|
+ batch_list.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(batch_list.size() > 0){
|
|
|
+ setGaoGuanLabel(batch_list, "个人", "update20210601");
|
|
|
+ System.out.println("size: "+ i);
|
|
|
+ batch_list.clear();
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ LineIterator.closeQuietly(it);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void setGaoGuanLabel(List<Map<String, Object>> batch_list, String fromLabel, String toLabel) {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ Session session = driver.session();
|
|
|
+
|
|
|
+ final String cql = "\nWITH {batch_list} AS batch_list \n" +
|
|
|
+ "UNWIND batch_list AS row \n" +
|
|
|
+ "MERGE(s:" + fromLabel + "{person_id:row.person_id}) \n" +
|
|
|
+ "SET s.name=row.person_name, s.person_id=row.person_id \n" +
|
|
|
+ "SET s:" + toLabel + " \n" +
|
|
|
+ "MERGE(e:企业{company_id:row.company_id}) \n" +
|
|
|
+ "SET e.name=row.company_name, e.company_id=row.company_id \n" +
|
|
|
+ "WITH s,e,row \n" +
|
|
|
+ "MERGE(s)-[r:高管]->(e) \n" +
|
|
|
+ "SET r.staff_type=row.staff_type , r.deleted=row.deleted \n";
|
|
|
+ CompanyUtils.runNeo4j(session, cql, new HashMap<String, Object>() {{
|
|
|
+ put("batch_list", batch_list);
|
|
|
+ }});
|
|
|
+ log.info("consumer size: {}, cost: {}, cql:{}", batch_list.size(), (System.currentTimeMillis() - start), cql);
|
|
|
+ session.close();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|