Browse Source

加标签

xufei 4 years ago
parent
commit
101690a80a

+ 3 - 2
src/main/java/com/winhc/common/enums/CompanyEnum.java

@@ -3,7 +3,7 @@ package com.winhc.common.enums;
 public class CompanyEnum {
 
     public enum Lable {
-        COMPANY("企业"), PERSON("个人"),
+        COMPANY("企业"), PERSON("个人"), 新增("新增"),
         法人("法人"), 高管("高管"), 投资("投资");
 
         public final String code;
@@ -20,7 +20,8 @@ public class CompanyEnum {
         HOLDER_RELATION_V2("3", "holderRelationV2ServiceImpl"),
         LEGAL_ENTITY_RELATION_V1("4", "legalEntityRelationV1ServiceImpl"),
         LEGAL_ENTITY_RELATION_V2("5", "legalEntityRelationV2ServiceImpl"),
-        STAFF_RELATION("6", "staffRelationServiceImpl");
+        STAFF_RELATION("6", "staffRelationServiceImpl"),
+        PERSON_NODE_LABEL("7", "personNodeLabelServiceImpl");
 
         public final String CODE;
         public final String VALUE;

+ 1 - 0
src/main/java/com/winhc/kafka/consumer/KafkaConsumerNeo4jV2.java

@@ -41,6 +41,7 @@ public class KafkaConsumerNeo4jV2 {
         this.map.get(CompanyEnum.TopicType.LEGAL_ENTITY_RELATION_V1.VALUE).save(CompanyUtils.filterList(listMap, CompanyEnum.TopicType.LEGAL_ENTITY_RELATION_V1.CODE));
         this.map.get(CompanyEnum.TopicType.LEGAL_ENTITY_RELATION_V2.VALUE).save(CompanyUtils.filterList(listMap, CompanyEnum.TopicType.LEGAL_ENTITY_RELATION_V2.CODE));
         this.map.get(CompanyEnum.TopicType.STAFF_RELATION.VALUE).save(CompanyUtils.filterList(listMap, CompanyEnum.TopicType.STAFF_RELATION.CODE));
+        this.map.get(CompanyEnum.TopicType.PERSON_NODE_LABEL.VALUE).save(CompanyUtils.filterList(listMap, CompanyEnum.TopicType.PERSON_NODE_LABEL.CODE));
     }
 
 

+ 2 - 0
src/main/java/com/winhc/service/impl/HolderRelationV1ServiceImpl.java

@@ -7,6 +7,7 @@ import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.neo4j.driver.*;
 import org.springframework.stereotype.Service;
+
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -32,6 +33,7 @@ public class HolderRelationV1ServiceImpl implements RelationService {
                 "UNWIND batch_list AS row \n" +
                 "MERGE(s:" + CompanyEnum.Lable.PERSON.code + "{person_id:row.start_id}) \n" +
                 "SET s.name=row.start_name, s.person_id=row.start_id \n" +
+                "SET s:" + CompanyUtils.getIncrPersonLabel() + " \n" +
                 "MERGE(e:" + CompanyEnum.Lable.COMPANY.code + "{company_id:row.end_id}) \n" +
                 "SET e.name=row.end_name, e.company_id=row.end_id \n" +
                 "WITH s,e,row \n" +

+ 45 - 0
src/main/java/com/winhc/service/impl/PersonNodeLabelServiceImpl.java

@@ -0,0 +1,45 @@
+package com.winhc.service.impl;
+
+import com.winhc.common.enums.CompanyEnum;
+import com.winhc.service.RelationService;
+import com.winhc.utils.CompanyUtils;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.neo4j.driver.Driver;
+import org.neo4j.driver.Session;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author π
+ * @Description:新增人员加标签
+ * @date 2021/1/11 10:03
+ */
+@Slf4j
+@Service("personNodeLabelServiceImpl")
+@AllArgsConstructor
+public class PersonNodeLabelServiceImpl implements RelationService {
+
+    private final Driver driver;
+
+    @Override
+    public String save(List<Map<String, Object>> batch_list) {
+        if (batch_list.isEmpty()) return null;
+        long start = System.currentTimeMillis();
+        Session session = driver.session();
+        final String cql = "WITH  {batch_list} AS batch_list \n" +
+                "UNWIND batch_list AS row \n" +
+                "MERGE(e:" + CompanyEnum.Lable.PERSON.code + "{person_id:row.id}) \n" +
+                "SET e: " + CompanyEnum.Lable.新增.code + " \n";
+        log.info("consumer size: {}, cql:{}", batch_list.size(), cql);
+        String data = CompanyUtils.writeNeo4j(session, cql, new HashMap<String, Object>() {{
+            put("batch_list", batch_list);
+        }});
+        session.close();
+        log.info("class:{} | save size:{} | cost:{}", PersonNodeLabelServiceImpl.class.getSimpleName(), batch_list.size(), (System.currentTimeMillis() - start));
+        return data;
+    }
+}

+ 5 - 0
src/main/java/com/winhc/utils/CompanyUtils.java

@@ -1,6 +1,7 @@
 package com.winhc.utils;
 
 import cn.hutool.json.JSONUtil;
+import com.winhc.common.enums.CompanyEnum;
 import com.winhc.db.mongodb.dataobject.NodeRelationError;
 import org.apache.kafka.clients.consumer.ConsumerRecord;
 import org.neo4j.driver.Result;
@@ -52,4 +53,8 @@ public class CompanyUtils {
         });
         return data;
     }
+
+    public static String getIncrPersonLabel(){
+        return CompanyEnum.Lable.新增.code + DateUtil.formatDate_YYYYMMDD(new Date());
+    }
 }

+ 487 - 0
src/main/java/com/winhc/utils/DateUtil.java

@@ -0,0 +1,487 @@
+package com.winhc.utils;
+
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * 日期工具类
+ * 
+ * @author David.Huang
+ */
+public class DateUtil {
+
+    /** yyyy-MM-dd */
+    public static final String FORMAT_YYYY_MM_DD = "yyyy-MM-dd";
+
+    /** yyyyMMdd */
+    public static final String FORMAT_YYYYMMDD = "yyyyMMdd";
+
+    /** yyyyMM */
+    public static final String FORMAT_YYYYMM = "yyyyMM";
+
+    /** yyMMdd */
+    public static final String FORMAT_YYMMDD = "yyMMdd";
+
+    /** yyyy-MM-dd HH:mm:ss */
+    public static final String FORMAT_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
+
+    /** yyyy-MM-dd HH:mm */
+    public static final String FORMAT_YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
+
+    /** yyyyMMddHHmmss */
+    public static final String FORMAT_YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
+
+    /** HH:mm:ss */
+    public static final String FORMAT_HH_MM_SS = "HH:mm:ss";
+
+    /** HHmmss */
+    public static final String FORMAT_HHMMSS = "HHmmss";
+
+    /**
+     * 转换为2017年01月26日
+     * 
+     * @param dateString 20170126
+     * @return
+     */
+    public static String convertToYearMoth(String dateString) {
+        String s_nd = dateString.substring(0, 4); // 年份
+        String s_yf = dateString.substring(4, 6); // 月份
+        String s_rq = dateString.substring(6, 8); // 日期
+        String targetDateString = s_nd + "年" + s_yf + "月" + s_rq + "日";
+        return targetDateString;
+    }
+
+    /**
+     * 2017-12-08
+     * 
+     * @param dateString
+     * @return
+     */
+    public static String convertToYearMothDate(String dateString) {
+        String s_nd = dateString.substring(0, 4); // 年份
+        String s_yf = dateString.substring(4, 6); // 月份
+        String s_rq = dateString.substring(6, 8); // 日期
+        String targetDateString = s_nd + "-" + s_yf + "-" + s_rq;
+        return targetDateString;
+    }
+
+    /**
+     * 11:04:23
+     * 
+     * @param dateString
+     * @return
+     */
+    public static String convertToHHMMSS(String dateString) {
+        String s_nd = dateString.substring(0, 2); // 时间
+        String s_yf = dateString.substring(2, 4); // 分钟
+        String s_rq = dateString.substring(4, 6); // 秒
+        String targetDateString = s_nd + ":" + s_yf + ":" + s_rq;
+        return targetDateString;
+    }
+
+    /**
+     * 字符串 转 日期
+     * 
+     * @param dateString 日期字符串
+     * @param pattern 格式化样式
+     * @return 日期对象
+     */
+    public static final Date parseDate(String dateString, String pattern) {
+        Date date = null;
+        if (StringUtils.isEmpty(dateString))
+            return null;
+        try {
+            SimpleDateFormat sdf = new SimpleDateFormat(pattern);
+            date = sdf.parse(dateString);
+        } catch (Exception e) {
+            // do nothing
+        }
+        return date;
+    }
+
+
+    /**
+     * 日期对象格式化
+     * 
+     * @param date 日期对象
+     * @param pattern 格式化样式
+     * @return 字符串日期
+     */
+    public static final String formatDate(Date date, String pattern) {
+        String v = null;
+        try {
+            if (date == null)
+                return null;
+            SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
+            v = dateFormat.format(date);
+        } catch (Exception e) {
+            // do nothing
+        }
+        return v;
+    }
+
+    public static final String formatDate_YYYYMMDD(Date date) {
+        String v = "";
+        try {
+            if (date == null)
+                return v;
+            SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT_YYYYMMDD);
+            v = dateFormat.format(date);
+        } catch (Exception e) {
+            // do nothing
+        }
+        return v;
+    }
+
+    public static final String formatDate_YYYY_MM_DD(Date date) {
+        String v = null;
+        try {
+            if (date == null)
+                return null;
+            SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT_YYYY_MM_DD);
+            v = dateFormat.format(date);
+        } catch (Exception e) {
+            // do nothing
+        }
+        return v;
+    }
+
+    public static final String formatDate_HHMMSS(Date date) {
+        String v = null;
+        try {
+            if (date == null)
+                return null;
+            SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT_HHMMSS);
+            v = dateFormat.format(date);
+        } catch (Exception e) {
+            // do nothing
+        }
+        return v;
+    }
+
+    public static final String formatDate_YYYY_MM_DD_HH_MM_SS(Date date) {
+        String v = null;
+        try {
+            if (date == null)
+                return null;
+            SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT_YYYY_MM_DD_HH_MM_SS);
+            v = dateFormat.format(date);
+        } catch (Exception e) {
+            // do nothing
+        }
+        return v;
+    }
+
+    /**
+     * 日期字符串之间的类型转换.
+     * <p>
+     * 例如:convertDate("2012-01-02", "yyyy-MM-dd", "yyyy/mm/dd")返回2012/01/02
+     * </p>
+     * 
+     * @param source 待处理的日期字符串
+     * @param sformat 原来的格式
+     * @param dformat 新的格式
+     * @return 转换后的日期字符串
+     */
+    public static String convertDate(String source, String sformat, String dformat) {
+        // 参数检查
+        if (StringUtils.isEmpty(source) || StringUtils.isEmpty(sformat) || StringUtils.isEmpty(dformat))
+            return source;
+        // 开始转换
+        String newString = formatDate(parseDate(source, sformat), dformat);
+        // 如果转换失败返回原始字符串
+        return (newString == null) ? source : newString;
+    }
+
+    /**
+     * 获得当前日期字符串,格式为 yyyyMM
+     * 
+     * @return 当前日期字符串(yyyyMM)
+     */
+
+    public static String getCurrDate_YYYYMMDD() {
+        return formatDate(new Date(), FORMAT_YYYYMMDD);
+    }
+
+    /**
+     * 获得当前日期字符串,格式为 yyyyMMdd
+     * 
+     * @return 当前日期字符串(yyyyMMdd)
+     */
+    public static String getCurrDate_YYYYMM() {
+        return formatDate(new Date(), FORMAT_YYYYMM);
+    }
+
+    /**
+     * 获得当前日期字符串,格式为 HHmmss
+     * 
+     * @return 当前日期字符串(HHmmss)
+     */
+    public static String getCurrDate_HHMMSS() {
+        return formatDate(new Date(), FORMAT_HHMMSS);
+    }
+
+    /**
+     * 获得当前日期字符串,格式为 yyyy-MM-dd
+     * 
+     * @return 当前日期字符串(yyyy-MM-dd)
+     */
+    public static String getCurrDate_YYYY_MM_DD() {
+        return formatDate(new Date(), FORMAT_YYYY_MM_DD);
+    }
+
+    /**
+     * 获得当前日期字符串,格式为 yyyy-MM-dd HH:mm:ss
+     * 
+     * @return 当前日期字符串(yyyy-MM-dd HH:mm:ss)
+     */
+    public static String getCurrDate_YYYY_MM_DD_HH_MM_SS() {
+        return formatDate(new Date(), FORMAT_YYYY_MM_DD_HH_MM_SS);
+    }
+
+    /**
+     * 获得当前日期字符串,格式为 yyyy-MM-dd HH:mm
+     * 
+     * @return 当前日期字符串(yyyy-MM-dd HH:mm)
+     */
+    public static String getCurrDate_YYYY_MM_DD_HH_MM() {
+        return formatDate(new Date(), FORMAT_YYYY_MM_DD_HH_MM);
+    }
+
+    /**
+     * 获得当前日期字符串,格式为 yyyyMMddHHmmss
+     * 
+     * @return 当前日期字符串(yyyyMMddHHmmss)
+     */
+    public static String getCurrTime_YYYYMMDDHHMMSS() {
+        return formatDate(new Date(), FORMAT_YYYYMMDDHHMMSS);
+    }
+
+    /**
+     * 判断是否是日期
+     * 
+     * @return dateString 日期字符串
+     * @param pattern 格式化样式(yyyyMMddHHmmss)
+     * @return 是日期返回true, 否则返回false
+     */
+    public static boolean isDateString(String dateString, String pattern) {
+        boolean v = false;
+        try {
+            if (StringUtils.isNotEmpty(dateString)) {
+                SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
+                Date d = dateFormat.parse(dateString);
+                if (d != null) {
+                    v = true;
+                }
+            }
+        } catch (Exception e) {
+            // do nothing
+        }
+        return v;
+    }
+
+    /**
+     * 判断是否是日期
+     * 
+     * @return dateString 日期字符串
+     * @param pattern 格式化样式(yyyyMMddHHmmss)
+     * @return 不是日期返回true, 否则返回false
+     */
+    public static boolean isNotDateString(String dateString, String pattern) {
+        return !isDateString(dateString, pattern);
+    }
+
+    /**
+     * 获取上个月的月份
+     * 
+     * @return dateString 日期字符串
+     * @return 不是日期返回true, 否则返回false
+     */
+    public static String getLastMonth() {
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.MONTH, -1);
+        SimpleDateFormat format = new SimpleDateFormat("MM");
+        return format.format(c.getTime());
+    }
+
+    /**
+     * 获取上个月的年月份
+     * 
+     * @return dateString 日期字符串
+     * @return 不是日期返回true, 否则返回false
+     */
+    public static String getLastYearMonth() {
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.MONTH, -1);
+        SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
+        return format.format(c.getTime());
+    }
+
+    /**
+     * 获取上个月的年
+     * 
+     * @return dateString 日期字符串
+     * @return 不是日期返回true, 否则返回false
+     */
+    public static String getYearByLastMonth() {
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.MONTH, -1);
+        SimpleDateFormat format = new SimpleDateFormat("yyyy");
+        return format.format(c.getTime());
+    }
+
+    public final static String getBetweenStr(Date beginDate, Date endDate) {
+        if (beginDate == null || endDate == null) {
+            return null;
+        }
+        long time = endDate.getTime() - beginDate.getTime();
+        long minute = (time / (60 * 1000));
+        long second = (time / 1000 - minute * 60);
+        if (time % 1000 > 0)
+            second += 1L;
+        return minute + "\u5206" + second + "\u79d2";
+    }
+
+    /**
+     * 计算日期
+     * 
+     * @param date
+     * @param yearNum
+     * @param monthNum
+     * @param dateNum
+     * @return
+     */
+    public static String calDate(String date, int yearNum, int monthNum, int dateNum) {
+        String result = "";
+        try {
+            SimpleDateFormat sd = new SimpleDateFormat(FORMAT_YYYY_MM_DD);
+            Calendar cal = Calendar.getInstance();
+            cal.setTime(sd.parse(date));
+            cal.add(Calendar.MONTH, monthNum);
+            cal.add(Calendar.YEAR, yearNum);
+            cal.add(Calendar.DATE, dateNum);
+            result = sd.format(cal.getTime());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    
+
+    public static Date getOnlyDate(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.set(Calendar.HOUR_OF_DAY, 0);
+        calendar.set(Calendar.MINUTE, 0);
+        calendar.set(Calendar.SECOND, 0);
+        calendar.set(Calendar.MILLISECOND, 0);
+        return calendar.getTime();
+    }
+
+
+  
+  
+    /**
+     * 计算时间差值,单位为天 去除时间后的计算结果+1,例如20180410
+     * 
+     * @return
+     * @throws Exception
+     */
+    public static long diffDays(Date startDate, Date endDate) throws Exception {
+        long time = removeTime(endDate).getTime();
+        long time2 = removeTime(startDate).getTime();
+        Long t = time - time2;
+        Long day = t / (24 * 60 * 60 * 1000);
+        if (day == 0L) {
+            day = day + 1;
+        }
+        return day;
+
+    }
+
+    private static Date removeTime(Date nowDate) throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        String s = sdf.format(nowDate);
+        Date date = sdf.parse(s); // 这样就是 yyyy-MM-dd
+        return date;
+    }
+
+    /**
+     * 获取该日期几天后的日期
+     * 
+     * @return
+     */
+    public static Date getDateAfter(Date date, int dayNum) {
+        Calendar now = Calendar.getInstance();
+        now.setTime(date);
+        now.add(Calendar.DATE, dayNum);
+
+        return now.getTime();
+    }
+
+    /**
+     * 
+     * 描述:获取一月后的日期.
+     * 
+     * @return yyyyMMdd
+     */
+    public static String getDateAfterOneMonth() {
+        Calendar cal = Calendar.getInstance();
+        cal.add(Calendar.MONTH, 1);
+        return formatDate(cal.getTime(), FORMAT_YYYYMMDD);
+    }
+
+    /**
+     * 
+     * 获取一周后的日期
+     * 
+     * @return yyyyMMdd
+     */
+    public static String getDateAfterOneWeek() {
+        Calendar cal = Calendar.getInstance();
+        cal.add(Calendar.DATE, 7);
+
+        return formatDate(cal.getTime(), FORMAT_YYYYMMDD);
+    }
+
+    /**
+     * 
+     * 获取dayNum天后的日期
+     * 
+     * @return yyyyMMdd
+     */
+    public static String getDateAfterDayNum(Integer dayNum) {
+        Calendar cal = Calendar.getInstance();
+        cal.add(Calendar.DATE, dayNum);
+
+        return formatDate(cal.getTime(), FORMAT_YYYYMMDD);
+    }
+
+    /**
+     * 获取N分钟以后的日期,格式: yyyyMMddHHmmsss
+     * 
+     * @param minuts
+     * @return
+     */
+    public static String getDateAfterMinutes(Integer minuts, Date date) {
+        SimpleDateFormat FORMAT2 = new SimpleDateFormat("yyyyMMddHHmmss");
+
+        Calendar can = Calendar.getInstance();
+        System.out.println(FORMAT2.format(date.getTime()));
+        can.add(Calendar.MINUTE, +minuts);
+
+        return FORMAT2.format(can.getTime());
+
+    }
+
+    public static void main(String[] args) throws Exception {
+        System.out.println(formatDate_YYYYMMDD(new Date()));
+    }
+
+}

+ 4 - 10
src/main/resources/application-dev.properties

@@ -3,17 +3,11 @@
 #Neo4j配置
 spring.data.neo4j.username=neo4j
 spring.data.neo4j.password=neo4j168
-#spring.data.neo4j.uri=http://106.14.211.187:7474
-spring.data.neo4j.uri=bolt://106.14.211.187:7687
 #spring.data.neo4j.uri=bolt://127.0.0.1:7687
-#prod
-#spring.data.neo4j.uri=bolt://10.29.30.244:7687
-
-#org.neo4j.driver.uri=bolt://106.14.211.187:7687
-#org.neo4j.driver.authentication.username=neo4j
-#org.neo4j.driver.authentication.password=neo4j168
-#spring.data.neo4j.embedded.enabled=true
-#spring.data.neo4j.driver=org.neo4j.ogm.drivers.http.driver.HttpDriver
+
+#爬虫
+spring.data.neo4j.uri=bolt://192.168.2.56:7687
+
 #数据库uri地址
 #spring.data.neo4j.uri=http://10.29.26.76:7474
 #spring.data.neo4j.uri=http://47.101.212.122:7474

+ 3 - 10
src/main/resources/application-prd.properties

@@ -4,18 +4,11 @@
 spring.data.neo4j.username=neo4j
 spring.data.neo4j.password=neo4j168
 
-#187
-#spring.data.neo4j.uri=http://192.168.2.55:7474
-#spring.data.neo4j.uri=bolt://192.168.2.55:7687
-#spring.data.neo4j.uri=bolt://106.14.211.187:7687
-
 #爬虫
-spring.data.neo4j.uri=bolt://192.168.2.56:7687
-
+#spring.data.neo4j.uri=bolt://192.168.2.56:7687
 
-#local
-#spring.data.neo4j.uri=bolt://127.0.0.1:7687
-#spring.data.neo4j.uri=bolt://10.1.10.213:7687
+#neo4j_prd
+spring.data.neo4j.uri=bolt://192.168.2.57:7687
 
 
 #spring.datasource.url = jdbc:mysql://rm-uf61r3m23ba1p5z3dfo.mysql.rds.aliyuncs.com:3306/prism1?useUnicode=true&characterEncoding=utf-8

+ 7 - 0
src/test/java/com/winhc/test/TestJson.java

@@ -7,6 +7,7 @@ import com.alibaba.fastjson.parser.Feature;
 import com.alibaba.fastjson.serializer.DoubleSerializer;
 import com.alibaba.fastjson.serializer.SerializeConfig;
 import com.google.gson.Gson;
+import com.winhc.utils.CompanyUtils;
 import org.apache.ibatis.javassist.expr.NewArray;
 import org.junit.Test;
 
@@ -55,4 +56,10 @@ public class TestJson {
         System.out.println(jsonObject);
 
     }
+
+    @Test
+    public void test2(){
+        String r1 = CompanyUtils.getIncrPersonLabel();
+        System.out.println(r1);
+    }
 }