瀏覽代碼

日志分析

lyr 8 年之前
父節點
當前提交
69efa1514f

+ 9 - 3
patient-co-analysis/pom.xml

@ -403,10 +403,16 @@
            <artifactId>spring-orm</artifactId>
            <artifactId>spring-orm</artifactId>
            <version>4.1.8.RELEASE</version>
            <version>4.1.8.RELEASE</version>
        </dependency>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>net.sf.json-lib</groupId>-->
            <!--<artifactId>json-lib</artifactId>-->
            <!--<version>2.4</version>-->
        <!--</dependency>-->
        <dependency>
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <groupId>org.ansj</groupId>
            <artifactId>ansj_seg</artifactId>
            <version>5.1.0</version>
        </dependency>
        </dependency>
    </dependencies>
    </dependencies>

+ 30 - 36
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/entity/UserPortrait.java

@ -1,6 +1,9 @@
package com.yihu.wlyy.analysis.entity;
package com.yihu.wlyy.analysis.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import javax.persistence.*;
import javax.persistence.*;
import java.util.Date;
/**
/**
 * 用户画像实体类
 * 用户画像实体类
@ -14,20 +17,18 @@ public class UserPortrait {
    private Long id;
    private Long id;
    // 居民code
    // 居民code
    private String userCode;
    private String userCode;
    // 姓名
    private String userName;
    // 身份证号
    private String idcard;
    // 标签类型
    // 标签类型
    private String type;
    private Integer labelType;
    // 标签名称
    // 标签名称
    private String typeName;
    private String labelName;
    // 子标签类型
    // 子标签类型
    private String subType;
    private Integer subType;
    // 子标签名称
    // 子标签名称
    private String subTypeName;
    private String subName;
    // 标签值
    // 标签值
    private String value;
    private String value;
    // 创建日期
    private Date czrq;
    @Id
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
@ -47,52 +48,45 @@ public class UserPortrait {
        this.userCode = userCode;
        this.userCode = userCode;
    }
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getIdcard() {
        return idcard;
    public Integer getLabelType() {
        return labelType;
    }
    }
    public void setIdcard(String idcard) {
        this.idcard = idcard;
    public void setLabelType(Integer labelType) {
        this.labelType = labelType;
    }
    }
    public String getType() {
        return type;
    public String getLabelName() {
        return labelName;
    }
    }
    public void setType(String type) {
        this.type = type;
    public void setLabelName(String labelName) {
        this.labelName = labelName;
    }
    }
    public String getTypeName() {
        return typeName;
    public Integer getSubType() {
        return subType;
    }
    }
    public void setTypeName(String typeName) {
        this.typeName = typeName;
    public void setSubType(Integer subType) {
        this.subType = subType;
    }
    }
    public String getSubType() {
        return subType;
    public String getSubName() {
        return subName;
    }
    }
    public void setSubType(String subType) {
        this.subType = subType;
    public void setSubName(String subName) {
        this.subName = subName;
    }
    }
    public String getSubTypeName() {
        return subTypeName;
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+08:00")
    public Date getCzrq() {
        return czrq;
    }
    }
    public void setSubTypeName(String subTypeName) {
        this.subTypeName = subTypeName;
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
    }
    public String getValue() {
    public String getValue() {

+ 19 - 1
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/etl/ETLConstantData.java

@ -21,5 +21,23 @@ public class ETLConstantData {
        }
        }
    }
    }
    /**
     * 年龄段
     *
     * @param age
     * @return
     */
    public static String ageInterval(int age) {
        if (age < 7) {
            return "儿童";
        } else if (age >= 7 && age <= 14) {
            return "少年";
        } else if (age >= 15 && age <= 35) {
            return "青年";
        } else if (age >= 36 && age <= 60) {
            return "中年";
        } else {
            return "老年";
        }
    }
}
}

+ 1 - 1
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/etl/ILogTransform.java

@ -1,7 +1,7 @@
package com.yihu.wlyy.analysis.etl;
package com.yihu.wlyy.analysis.etl;
import com.yihu.wlyy.analysis.entity.UserPortrait;
import com.yihu.wlyy.analysis.entity.UserPortrait;
import net.sf.json.JSONObject;
import org.json.JSONObject;
import java.util.List;
import java.util.List;

+ 4 - 4
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/etl/LogDataTransform.java

@ -1,7 +1,7 @@
package com.yihu.wlyy.analysis.etl;
package com.yihu.wlyy.analysis.etl;
import com.yihu.wlyy.analysis.entity.UserPortrait;
import com.yihu.wlyy.analysis.entity.UserPortrait;
import net.sf.json.JSONObject;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.LoggerFactory;
@ -56,9 +56,9 @@ public class LogDataTransform {
     */
     */
    public List<UserPortrait> transform(JSONObject log) {
    public List<UserPortrait> transform(JSONObject log) {
        try {
        try {
            String logType = log.getString("logType");
            if (logType.equals("1")) {
                String businessType = log.getJSONObject("data").getString("businessType");
            String logType = String.valueOf(log.get("logType"));
            if (logType.equals("2")) {
                String businessType = String.valueOf(log.getJSONObject("data").get("businessType"));
                ILogTransform transform = transforms.get(businessType);
                ILogTransform transform = transforms.get(businessType);
                if (transform == null) {
                if (transform == null) {

+ 69 - 3
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/etl/transform/ConsultLogTransform.java

@ -3,8 +3,14 @@ package com.yihu.wlyy.analysis.etl.transform;
import com.yihu.wlyy.analysis.entity.UserPortrait;
import com.yihu.wlyy.analysis.entity.UserPortrait;
import com.yihu.wlyy.analysis.etl.BusinessTypeEnum;
import com.yihu.wlyy.analysis.etl.BusinessTypeEnum;
import com.yihu.wlyy.analysis.etl.ILogTransform;
import com.yihu.wlyy.analysis.etl.ILogTransform;
import net.sf.json.JSONObject;
import org.ansj.domain.Result;
import org.ansj.domain.Term;
import org.ansj.splitWord.analysis.ToAnalysis;
import org.json.JSONObject;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.List;
/**
/**
@ -17,8 +23,14 @@ public class ConsultLogTransform implements ILogTransform {
    private final BusinessTypeEnum logType = BusinessTypeEnum.consult;
    private final BusinessTypeEnum logType = BusinessTypeEnum.consult;
    @Override
    @Override
    public List<UserPortrait> transform(JSONObject log) {
        return null;
    public List<UserPortrait> transform(JSONObject log) throws UnsupportedEncodingException {
        JSONObject logData = log.getJSONObject("data");
        JSONObject businessData = logData.getJSONObject("data");
        List<UserPortrait> labelInfoList = new ArrayList<>();
        // 慢病分析
        labelInfoList.addAll(transformGxyTnbMb(businessData));
        return labelInfoList;
    }
    }
    @Override
    @Override
@ -30,4 +42,58 @@ public class ConsultLogTransform implements ILogTransform {
    public String getLogTypeName() {
    public String getLogTypeName() {
        return logType.name();
        return logType.name();
    }
    }
    public List<UserPortrait> transformGxyTnbMb(JSONObject log) throws UnsupportedEncodingException {
        String symptoms = log.getString("symptoms");
        Result fc = ToAnalysis.parse(symptoms);
        List<String> wordList = new ArrayList<>();
        List<UserPortrait> UserPortraits = new ArrayList<>();
        for(Term term : fc.getTerms()) {
            wordList.add(term.getName());
        }
        if(wordList.contains("糖尿病")) {
            UserPortrait labelInfo = new UserPortrait();
            labelInfo.setUserCode(log.getString("patient"));
            labelInfo.setLabelType(1);
            labelInfo.setLabelName("基础特征");
            labelInfo.setSubType(3);
            labelInfo.setSubName("疾病");
            labelInfo.setValue("糖尿病");
            labelInfo.setCzrq(new Date());
            UserPortraits.add(labelInfo);
        }
        if(wordList.contains("高血压")) {
            UserPortrait labelInfo = new UserPortrait();
            labelInfo.setUserCode(log.getString("patient"));
            labelInfo.setLabelType(1);
            labelInfo.setLabelName("基础特征");
            labelInfo.setSubType(3);
            labelInfo.setSubName("疾病");
            labelInfo.setValue("高血压");
            labelInfo.setCzrq(new Date());
            UserPortraits.add(labelInfo);
        }
        if(wordList.contains("慢病")) {
            UserPortrait labelInfo = new UserPortrait();
            labelInfo.setUserCode(log.getString("patient"));
            labelInfo.setLabelType(1);
            labelInfo.setLabelName("基础特征");
            labelInfo.setSubType(3);
            labelInfo.setSubName("疾病");
            labelInfo.setValue("慢病");
            labelInfo.setCzrq(new Date());
            UserPortraits.add(labelInfo);
        }
        return UserPortraits;
    }
}
}

+ 38 - 7
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/etl/transform/RegisterLogTransform.java

@ -5,10 +5,11 @@ import com.yihu.wlyy.analysis.etl.ILogTransform;
import com.yihu.wlyy.analysis.etl.BusinessTypeEnum;
import com.yihu.wlyy.analysis.etl.BusinessTypeEnum;
import com.yihu.wlyy.analysis.entity.UserPortrait;
import com.yihu.wlyy.analysis.entity.UserPortrait;
import com.yihu.wlyy.analysis.etl.util.IdcardUtil;
import com.yihu.wlyy.analysis.etl.util.IdcardUtil;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.List;
/**
/**
@ -30,6 +31,10 @@ public class RegisterLogTransform implements ILogTransform {
        UserPortrait sexInfo = tranformSex(businessData);
        UserPortrait sexInfo = tranformSex(businessData);
        if (sexInfo != null) labelInfoList.add(sexInfo);
        if (sexInfo != null) labelInfoList.add(sexInfo);
        // 年龄
        UserPortrait ageInfo = tranformAge(businessData);
        if (ageInfo != null) labelInfoList.add(ageInfo);
        return labelInfoList;
        return labelInfoList;
    }
    }
@ -60,13 +65,39 @@ public class RegisterLogTransform implements ILogTransform {
        }
        }
        labelInfo.setUserCode(log.getString("code"));
        labelInfo.setUserCode(log.getString("code"));
        labelInfo.setUserName(log.getString("name"));
        labelInfo.setIdcard(idcard);
        labelInfo.setType("1");
        labelInfo.setTypeName("基础特征");
        labelInfo.setSubType("1");
        labelInfo.setSubTypeName("性别");
        labelInfo.setLabelType(1);
        labelInfo.setLabelName("基础特征");
        labelInfo.setSubType(1);
        labelInfo.setSubName("性别");
        labelInfo.setValue(ETLConstantData.sexName(sex));
        labelInfo.setValue(ETLConstantData.sexName(sex));
        labelInfo.setCzrq(new Date());
        return labelInfo;
    }
    /**
     * 获取性别信息
     *
     * @param log
     * @return
     */
    private UserPortrait tranformAge(JSONObject log) throws Exception {
        String idcard = log.getString("idcard");
        UserPortrait labelInfo = new UserPortrait();
        int age = 0;
        if (StringUtils.isNotEmpty(idcard)) {
            age = IdcardUtil.getAgeFromIdcard(idcard);
        } else {
            return null;
        }
        labelInfo.setUserCode(log.getString("code"));
        labelInfo.setLabelType(1);
        labelInfo.setLabelName("基础特征");
        labelInfo.setSubType(2);
        labelInfo.setSubName("年龄");
        labelInfo.setValue(ETLConstantData.ageInterval(age));
        labelInfo.setCzrq(new Date());
        return labelInfo;
        return labelInfo;
    }
    }

+ 1 - 1
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/etl/util/IdcardUtil.java

@ -19,7 +19,7 @@ public class IdcardUtil {
     * @param
     * @param
     * @throws Exception
     * @throws Exception
     */
     */
    public static int getAgeForIdcard(String idcard) {
    public static int getAgeFromIdcard(String idcard) {
        try {
        try {
            int age = -1;
            int age = -1;

+ 3 - 3
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/listener/LabelDataListener.java

@ -5,8 +5,8 @@ import com.yihu.wlyy.analysis.etl.LogDataTransform;
import com.yihu.wlyy.analysis.model.BusinessDataModel;
import com.yihu.wlyy.analysis.model.BusinessDataModel;
import com.yihu.wlyy.analysis.model.OperatorDataModel;
import com.yihu.wlyy.analysis.model.OperatorDataModel;
import com.yihu.wlyy.analysis.repository.UserPortraitDao;
import com.yihu.wlyy.analysis.repository.UserPortraitDao;
import net.sf.json.JSONObject;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
@ -41,9 +41,9 @@ public class LabelDataListener {
        if (kafkaMessage.isPresent()) {
        if (kafkaMessage.isPresent()) {
            Object message = kafkaMessage.get();
            Object message = kafkaMessage.get();
            try {
            try {
                JSONObject jsonObject = JSONObject.fromObject(message);
                JSONObject jsonObject = new JSONObject(message.toString());
                if (jsonObject.has("logType")) {
                if (jsonObject.has("logType")) {
                    String logType = jsonObject.getString("logType");
                    String logType = String.valueOf(jsonObject.get("logType"));
                    // 根据日志类别保存到mongodb
                    // 根据日志类别保存到mongodb
                    saveLogToMongo(logType, jsonObject);
                    saveLogToMongo(logType, jsonObject);
                    // 日志分析
                    // 日志分析

+ 4 - 4
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/model/BusinessDataModel.java

@ -1,6 +1,6 @@
package com.yihu.wlyy.analysis.model;
package com.yihu.wlyy.analysis.model;
import net.sf.json.JSONObject;
import org.json.JSONObject;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Document;
import java.io.Serializable;
import java.io.Serializable;
@ -63,13 +63,13 @@ public class BusinessDataModel extends DataModel implements Serializable {
    public static BusinessDataModel getByJsonObject(JSONObject jsonObject) throws Exception {
    public static BusinessDataModel getByJsonObject(JSONObject jsonObject) throws Exception {
        BusinessDataModel businessDataModel = new BusinessDataModel();
        BusinessDataModel businessDataModel = new BusinessDataModel();
        try {
        try {
            businessDataModel.setLogType(jsonObject.getString("logType"));
            businessDataModel.setLogType(String.valueOf(jsonObject.get("logType")));
            businessDataModel.setCaller(jsonObject.getString("caller"));
            businessDataModel.setCaller(jsonObject.getString("caller"));
            businessDataModel.setTime(jsonObject.getString("time"));
            businessDataModel.setTime(jsonObject.getString("time"));
            JSONObject chlidren = jsonObject.getJSONObject("data");
            JSONObject chlidren = jsonObject.getJSONObject("data");
            businessDataModel.setData(chlidren.getString("data"));
            businessDataModel.setBusinessType(chlidren.getString("businessType"));
            businessDataModel.setData(chlidren.getJSONObject("data").toString());
            businessDataModel.setBusinessType(String.valueOf(chlidren.get("businessType")));
            businessDataModel.setPatient(chlidren.getString("patient"));
            businessDataModel.setPatient(chlidren.getString("patient"));
        } catch (Exception e) {
        } catch (Exception e) {

+ 3 - 3
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/model/OperatorDataModel.java

@ -1,6 +1,6 @@
package com.yihu.wlyy.analysis.model;
package com.yihu.wlyy.analysis.model;
import net.sf.json.JSONObject;
import org.json.JSONObject;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Document;
import java.io.Serializable;
import java.io.Serializable;
@ -52,12 +52,12 @@ public class OperatorDataModel extends DataModel implements Serializable {
    public static OperatorDataModel getByJsonObject(JSONObject jsonObject) throws Exception {
    public static OperatorDataModel getByJsonObject(JSONObject jsonObject) throws Exception {
        OperatorDataModel operatorDataModel = new OperatorDataModel();
        OperatorDataModel operatorDataModel = new OperatorDataModel();
        try {
        try {
            operatorDataModel.setLogType(jsonObject.getString("logType"));
            operatorDataModel.setLogType(String.valueOf(jsonObject.get("logType")));
            operatorDataModel.setCaller(jsonObject.getString("caller"));
            operatorDataModel.setCaller(jsonObject.getString("caller"));
            operatorDataModel.setTime(jsonObject.getString("time"));
            operatorDataModel.setTime(jsonObject.getString("time"));
            JSONObject chlidren = jsonObject.getJSONObject("data");
            JSONObject chlidren = jsonObject.getJSONObject("data");
            operatorDataModel.setResponseTime(chlidren.getString("responseTime"));
            operatorDataModel.setResponseTime(chlidren.get("responseTime").toString());
            operatorDataModel.setUrl(chlidren.getString("url"));
            operatorDataModel.setUrl(chlidren.getString("url"));
            operatorDataModel.setParams(chlidren.getString("params"));
            operatorDataModel.setParams(chlidren.getString("params"));