Browse Source

Merge branch 'dev' of chenweida/patient-co-management into dev

chenweida 8 years ago
parent
commit
97490bd242

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

@ -1,18 +1,14 @@
package com.yihu.wlyy.analysis.listener;
import com.yihu.wlyy.analysis.model.LabelDataModel;
import com.yihu.wlyy.analysis.model.BusinessDataModel;
import com.yihu.wlyy.analysis.model.OperatorDataModel;
import net.sf.json.JSONObject;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoDbUtils;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.SendResult;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;
import java.util.Optional;
@ -20,31 +16,33 @@ import java.util.Optional;
 * Created by Administrator on 2017/2/6.
 */
public class LabelDataListener {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private MongoTemplate mongoTemplate;
    private static String mongoDbTableName = "WLYY_ANALYSIS";
    private static String mongoDb_Business_TableName = "WLYY_BUSINESS_LOG";
    private static String mongoDb_Operator_TableName = "WLYY_OPERATOR_LOG";
    //@Scheduled(cron = "0 0/1 * * * ?") //每分钟执行一次
    @KafkaListener(topics = "flumeLog1")
    public void labelData(ConsumerRecord<?, ?> record) {
        Long startTime = System.currentTimeMillis();
        logger.info("Kafka开始消费");
        logger.debug("Kafka开始消费");
        Optional<?> kafkaMessage = Optional.ofNullable(record.value());
        if (kafkaMessage.isPresent()) {
            Object message = kafkaMessage.get();
            try {
                logger.info("接受到的消息:" + String.valueOf(message));
                String[] value = String.valueOf(message).split(" - ");
                if (value.length == 5) {
                    mongoTemplate.insert(
                            new LabelDataModel(value[0], value[1], value[2], value[3], value[4]), mongoDbTableName
                    );
                JSONObject jsonObject = JSONObject.fromObject(message);
                if (jsonObject.has("logType")) {
                    String logType = jsonObject.getString("logType");
                    //根据日志类别保存到mongodb
                    saveLogToMongo(logType, jsonObject);
                    Long endTime = System.currentTimeMillis();
                    Long time = startTime - endTime;
                    logger.info("time(ms):" + time);
                    logger.info("保存成功 message:" + message);
                    logger.debug("time(ms):" + time);
                    logger.debug("保存成功 message:" + message);
                } else {
                    logger.error("数据格式错误,message:" + message);
                }
@ -55,7 +53,27 @@ public class LabelDataListener {
        logger.debug("Kafka结束消费");
    }
    private void saveLogToMongo(String logType, JSONObject jsonObject) throws Exception {
        switch (logType) {
            case "1": {
                //业务日志
                insertMongo(OperatorDataModel.getByJsonObject(jsonObject),mongoDb_Operator_TableName);
                break;
            }
            case "2": {
                //操作日志
                insertMongo(BusinessDataModel.getByJsonObject(jsonObject),mongoDb_Business_TableName);
                break;
            }
        }
    }
    private void insertMongo(Object data, String tableName) {
        mongoTemplate.insert(
                data, tableName
        );
    }
//    @Scheduled(fixedRate=20000)//每20秒执行一次。开始
//    public void testTasks() {
//    }

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

@ -0,0 +1,80 @@
package com.yihu.wlyy.analysis.model;
import net.sf.json.JSONObject;
import org.springframework.data.mongodb.core.mapping.Document;
import java.io.Serializable;
/**
 * Created by Administrator on 2017/2/9.
 * <p>
 * * 数据对象的公工接口
 * // 业务日志
 * 0 consult // 咨询
 * 1 guidance  // 指导
 * 2 article  // 健康教育
 * 3 followup  // 随访
 * 4 appointment // 预约
 * 5 label // 标签
 * 6 register  // 注册
 * 7 archive // 健康档案
 * {
 * time:"" 时间
 * ,logType:2 日志类型
 * ,caller:"" 调用者
 * ,data:{
 * ,businessType:""  业务类型
 * ,patient:"" 居民
 * ,data:{} 业务数据
 * } 数据
 * }
 */
@Document
public class BusinessDataModel extends DataModel implements Serializable {
    private String businessType;
    private String patient;
    private String data;
    public String getBusinessType() {
        return businessType;
    }
    public void setBusinessType(String businessType) {
        this.businessType = businessType;
    }
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    public String getData() {
        return data;
    }
    public void setData(String data) {
        this.data = data;
    }
    public static BusinessDataModel getByJsonObject(JSONObject jsonObject) throws Exception {
        BusinessDataModel businessDataModel = new BusinessDataModel();
        try {
            businessDataModel.setLogType(jsonObject.getString("logType"));
            businessDataModel.setCaller(jsonObject.getString("caller"));
            businessDataModel.setTime(jsonObject.getString("time"));
            JSONObject chlidren = jsonObject.getJSONObject("data");
            businessDataModel.setData(chlidren.getString("data"));
            businessDataModel.setBusinessType(chlidren.getString("businessType"));
            businessDataModel.setPatient(chlidren.getString("patient"));
        } catch (Exception e) {
            throw new Exception("格式错误");
        }
        return businessDataModel;
    }
}

+ 79 - 0
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/model/DataModel.java

@ -0,0 +1,79 @@
package com.yihu.wlyy.analysis.model;
import org.springframework.data.annotation.Id;
/**
 * Created by Administrator on 2017/2/9.
 * 数据对象的公工接口
 * // 业务日志
 * 0 consult // 咨询
 * 1 guidance  // 指导
 * 2 article  // 健康教育
 * 3 followup  // 随访
 * 4 appointment // 预约
 * 5 label // 标签
 * 6 register  // 注册
 * 7 archive // 健康档案
 {
      time:"" 时间
     ,logType:2 日志类型
     ,caller:"" 调用者
     ,data:{
         ,businessType:""  业务类型
         ,patient:"" 居民
         ,data:{} 业务数据
     } 数据
 }
 // 接口调用日志
 {
  time:"" 时间
 ,logType:1 日志类型
 ,caller:"" 调用者
 ,data:{
      responseTime:"" 响应时间
     ,url:"" 接口URL
     ,params:{} 参数
    } 数据
 }
 */
public class DataModel {
    @Id
    protected String id;
    protected String time;//时间
    protected String caller; //调用者
    protected String logType;//日志类型 1接口 2业务
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getLogType() {
        return logType;
    }
    public void setLogType(String logType) {
        this.logType = logType;
    }
    public String getTime() {
        return time;
    }
    public void setTime(String time) {
        this.time = time;
    }
    public String getCaller() {
        return caller;
    }
    public void setCaller(String caller) {
        this.caller = caller;
    }
}

+ 0 - 80
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/model/LabelDataModel.java

@ -1,80 +0,0 @@
package com.yihu.wlyy.analysis.model;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.io.Serializable;
/**
 * Created by Administrator on 2017/2/7.
 * mongodb实体类
 */
@Document
public class LabelDataModel implements Serializable {
    @Id
    private String id;
    private String createTime;//时间
    private String code;//操作人code
    private String requestMapping;//web路径
    private String operaTime;//操作时间
    private String data;//具体的数据
    public LabelDataModel() {
    }
    public LabelDataModel(String createTime, String code, String requestMapping, String operaTime, String data) {
        this.createTime = createTime;
        this.code = code;
        this.requestMapping = requestMapping;
        this.operaTime = operaTime;
        this.data = data;
    }
    public String getData() {
        return data;
    }
    public void setData(String data) {
        this.data = data;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getCreateTime() {
        return createTime;
    }
    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getRequestMapping() {
        return requestMapping;
    }
    public void setRequestMapping(String requestMapping) {
        this.requestMapping = requestMapping;
    }
    public String getOperaTime() {
        return operaTime;
    }
    public void setOperaTime(String operaTime) {
        this.operaTime = operaTime;
    }
}

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

@ -0,0 +1,69 @@
package com.yihu.wlyy.analysis.model;
import net.sf.json.JSONObject;
import org.springframework.data.mongodb.core.mapping.Document;
import java.io.Serializable;
/**
 * Created by Administrator on 2017/2/9.
 * {
 * time:"" 时间
 * ,logType:1 日志类型
 * ,caller:"" 调用者
 * ,data:{
 * responseTime:"" 响应时间
 * ,url:"" 接口URL
 * ,params:{} 参数
 * } 数据
 * }
 */
@Document
public class OperatorDataModel extends DataModel implements Serializable {
    private String responseTime;
    private String url;
    private String params;
    public String getResponseTime() {
        return responseTime;
    }
    public void setResponseTime(String responseTime) {
        this.responseTime = responseTime;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public String getParams() {
        return params;
    }
    public void setParams(String params) {
        this.params = params;
    }
    public static OperatorDataModel getByJsonObject(JSONObject jsonObject) throws Exception {
        OperatorDataModel operatorDataModel = new OperatorDataModel();
        try {
            operatorDataModel.setLogType(jsonObject.getString("logType"));
            operatorDataModel.setCaller(jsonObject.getString("caller"));
            operatorDataModel.setTime(jsonObject.getString("time"));
            JSONObject chlidren = jsonObject.getJSONObject("data");
            operatorDataModel.setResponseTime(chlidren.getString("responseTime"));
            operatorDataModel.setUrl(chlidren.getString("url"));
            operatorDataModel.setParams(chlidren.getString("params"));
        } catch (Exception e) {
            throw new Exception("格式错误");
        }
        return operatorDataModel;
    }
}

+ 31 - 0
patient-co-analysis/src/main/java/com/yihu/wlyy/analysis/model/emun/BusinessType.java

@ -0,0 +1,31 @@
package com.yihu.wlyy.analysis.model.emun;
/**
 * Created by Administrator on 2017/2/9.
 * 业务日志类型
 */
public enum BusinessType {
    Consult("0"),//咨询
    Guidance("1"), // 指导
    Article("2"), // 健康教育
    Followup("3"),// 随访
    Appointment("4"), // 预约
    Label("5"),// 标签
    Register("6"),// 注册
    Archive("7"),// 健康档案
    Sign("8");// 签约
    private String value;
    BusinessType(String s) {
        this.value = s;
    }
    public String getValue() {
        return value;
    }
    public void setValue(String value) {
        this.value = value;
    }
}