Forráskód Böngészése

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

trick9191 7 éve
szülő
commit
5483d8d9bc

+ 125 - 0
common/common-entity/src/main/java/com/yihu/es/entity/AssistantMsgPushLog.java

@ -0,0 +1,125 @@
package com.yihu.es.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.searchbox.annotations.JestId;
import org.springframework.data.annotation.CreatedDate;
import java.util.Date;
/**
 * Created by 刘文彬 on 2018/8/7.
 * 推送医生助手的日志
 */
public class AssistantMsgPushLog {
    @JestId
    private String id;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyyMMdd'T'HHmmss.SSS'Z'")
    @CreatedDate
    private Date createTime;  // 创建时间
    private Integer pushPlatform; //推送的平台 1、微信平台,2、平台消息
    private String accessToken;//微信AccessToken(微信平台)
    private String type;//消息类型
    private String openid;//微信的openid
    private String url;//微信跳转url
    private String data;//数据(微信平台、平台消息)
    private String receiver;//接受人(平台消息)
    private String title;// 标题(平台消息)
    private String msg;//消息(平台消息)
    private Integer success;//是否推送成功(1、成功,-1、失败)
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Integer getPushPlatform() {
        return pushPlatform;
    }
    public void setPushPlatform(Integer pushPlatform) {
        this.pushPlatform = pushPlatform;
    }
    public String getAccessToken() {
        return accessToken;
    }
    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getOpenid() {
        return openid;
    }
    public void setOpenid(String openid) {
        this.openid = openid;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public String getData() {
        return data;
    }
    public void setData(String data) {
        this.data = data;
    }
    public String getReceiver() {
        return receiver;
    }
    public void setReceiver(String receiver) {
        this.receiver = receiver;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getMsg() {
        return msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }
    public Integer getSuccess() {
        return success;
    }
    public void setSuccess(Integer success) {
        this.success = success;
    }
}

+ 62 - 0
patient-co/patient-co-doctor-assistant/doc/技术文档/es/推送医生助手消息日志新增索引.txt

@ -0,0 +1,62 @@
创建索引
POST  http://172.19.103.68:9200/assistant_msg_push_log
查询索引
GET http://172.19.103.68:9200/assistant_msg_push_log/
给索引加mapping
POST http://172.19.103.68:9200/assistant_msg_push_log/assistant_msg_push_log/_mapping
{
    "assistant_msg_push_log": {
        "properties": {
            "createTime": {
                "format": "strict_date_optional_time||epoch_millis",
                "type": "date"
            },
            "pushPlatform": {
                "type": "integer"
            },
			"accessToken": {
                "index": "not_analyzed",
                "type": "string"
            },
			"type": {
                "index": "not_analyzed",
                "type": "string"
            },
			"openid": {
                "index": "not_analyzed",
                "type": "string"
            },
			"url": {
                "index": "not_analyzed",
                "type": "string"
            },
			"data": {
                "index": "not_analyzed",
                "type": "string"
            },
			"receiver": {
                "index": "not_analyzed",
                "type": "string"
            },
			"title": {
                "index": "not_analyzed",
                "type": "string"
            },
			"msg": {
                "index": "not_analyzed",
                "type": "string"
            },
			"success": {
                "type": "integer"
            }
        }
    }
}
增加索引搜索大小
PUT  http://172.19.103.68:9200/assistant_msg_push_log/_settings
{
  "index": {
    "max_result_window": 500000
  }
}

+ 2 - 1
patient-co/patient-co-doctor-assistant/src/main/java/com/yihu/wlyy/config/SwaggerConfig.java

@ -177,7 +177,8 @@ public class SwaggerConfig {
                        regex("/idc10/.*"),
                        regex("/im_new/.*"),
                        regex("/version/.*"),
                        regex("/express/.*")
                        regex("/express/.*"),
                        regex("/wlyy/.*")
                ))
                .build()

+ 104 - 0
patient-co/patient-co-doctor-assistant/src/main/java/com/yihu/wlyy/config/es/ElasticFactory.java

@ -0,0 +1,104 @@
package com.yihu.wlyy.config.es;
import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.config.HttpClientConfig;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
/**
 * Created by chenweida on 2017/6/5.
 */
@Component
public class ElasticFactory {
    private static JestClientFactory factory = null;
    @Value("${es.host}")
    private String esHost;//http://59.61.92.90:9065,http://59.61.92.90:9067
    @Value("${es.tHost}")
    private String tHost;// 59.61.92.90:9066,59.61.92.90:9068
    @Value("${es.clusterName}")
    private String clusterName;
//-----------------------------------jestClient----------------------------------------
    /**
     * @param "http://localhost:9200"
     * @return
     */
    public JestClient getJestClient() {
        if (factory == null) {
            //初始化链接
            init();
        }
        return factory.getObject();
    }
    /**
     * 初始化链接
     * 9200
     */
    public synchronized void init() {
        String[] hostArray = esHost.split(",");
        // Construct a new Jest client according to configuration via factory
        factory = new JestClientFactory();
        HttpClientConfig httpClientConfig = new HttpClientConfig
                .Builder(Arrays.asList(hostArray))
                .multiThreaded(true)
                .maxTotalConnection(50)// 最大链接
                .maxConnectionIdleTime(10, TimeUnit.MINUTES)//链接等待时间
                .connTimeout(60 * 1000*10)
                // .discoveryEnabled(true)
                .readTimeout(60 * 1000*10)//60秒
                .build();
        factory.setHttpClientConfig(httpClientConfig);//得到链接
    }
    //-----------------------------------TransportClient----------------------------------------
    private TransportClient transportClient;
    public Client getTransportClient() {
        try {
            initTranClient();
            return transportClient;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 9300
     *
     * @throws UnknownHostException
     */
    private synchronized void initTranClient() throws UnknownHostException {
        if (transportClient == null) {
            String[] hosts = tHost.split(",");
            Settings settings = Settings.settingsBuilder()
                    // .put("client.transport.sniff", true)//开启嗅探功能
                    .put("cluster.name", StringUtils.isEmpty(clusterName) ? "jkzl" : clusterName)//默认集群名字是jkzl
                    .build();
            transportClient = TransportClient.builder().settings(settings).build();
            for (String oneHost : hosts) {
                String[] hostAndport = oneHost.split(":");
                transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostAndport[0]), Integer.valueOf(hostAndport[1])));
            }
        }
    }
}

+ 79 - 0
patient-co/patient-co-doctor-assistant/src/main/java/com/yihu/wlyy/config/es/ElastricSearchSave.java

@ -0,0 +1,79 @@
package com.yihu.wlyy.config.es;
import io.searchbox.client.JestClient;
import io.searchbox.core.Bulk;
import io.searchbox.core.BulkResult;
import io.searchbox.core.Index;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.List;
;
/**
 * Created by chenweida on 2017/6/2.
 */
@Component
@Scope("prototype")
public class ElastricSearchSave {
    private Logger logger = LoggerFactory.getLogger(ElastricSearchSave.class);
    @Autowired
    private ElasticFactory elasticFactory;
    public Boolean save(List sms, String esIndex, String esType) {
        JestClient jestClient = null;
        try {
            //得到链接
            jestClient = elasticFactory.getJestClient();
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            for (Object obj : sms) {
                Index index = new Index.Builder(obj).build();
                bulk.addAction(index);
            }
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("save data count:" + sms.size());
            logger.info("save flag:" + br.isSucceeded());
            return br.isSucceeded();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(" save error :" + e.getMessage());
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        return null;
    }
    public Boolean save(Object obj, String esIndex, String esType) {
        JestClient jestClient = null;
        try {
            //得到链接
            jestClient = elasticFactory.getJestClient();
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            Index index = new Index.Builder(obj).build();
            bulk.addAction(index);
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("save flag:" + br.isSucceeded());
            return br.isSucceeded();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(" save error :" + e.getMessage());
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        return null;
    }
}

+ 48 - 0
patient-co/patient-co-doctor-assistant/src/main/java/com/yihu/wlyy/task/PushMsgTask.java

@ -1,6 +1,8 @@
package com.yihu.wlyy.task;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.es.entity.AssistantMsgPushLog;
import com.yihu.wlyy.config.es.ElastricSearchSave;
import com.yihu.wlyy.entity.wechat.WechatTemplate;
import com.yihu.wlyy.entity.wechat.WechatTemplateData;
import com.yihu.wlyy.util.HttpUtil;
@ -15,6 +17,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
@ -64,6 +67,12 @@ public class PushMsgTask {
    private String putMesType;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private ElastricSearchSave elastricSearchSave;
    @Value("${es.type.AssistantMsgPushLog}")
    private String esType;
    @Value("${es.index.AssistantMsgPushLog}")
    private String esIndex;
    /**
@ -118,6 +127,8 @@ public class PushMsgTask {
                mes.put("title", putMesType);
                mes.put("value", json.toString());
                redisTemplate.opsForList().leftPush(redisQueue, mes.toString());
                saveAssistantMsgPushLog(access_token,1,type+"",openid,
                        url,data.toString(),null,null,null,null);
            } else {
                queue.put(json);
            }
@ -187,6 +198,8 @@ public class PushMsgTask {
                        String url = json.has("url") ? json.getString("url") : "";
                        // 发送消息到微信端
                        sendWeixinMessage(access_token, type, openid, url, data);
                        saveAssistantMsgPushLog(access_token,1,type+"",openid,
                                url,data.toString(),null,null,null,null);
                    } else {
                        // 推送平台消息
                        String receiver = json.has("receiver") ? json.getString("receiver") : "";
@ -197,8 +210,12 @@ public class PushMsgTask {
                        boolean res = httpUtil.pushMessage(receiver, type, title, msg, data);
                        if (res) {
                            logger.info("消息推送成功!");
                            saveAssistantMsgPushLog(null,2,type,null,
                                    null,data,receiver,title,msg,1);
                        } else {
                            logger.error("消息推送失败!");
                            saveAssistantMsgPushLog(null,2,type,null,
                                    null,data,receiver,title,msg,-1);
                        }
                    }
                } catch (Exception ex) {
@ -359,4 +376,35 @@ public class PushMsgTask {
        return templateId;
    }
    /**
     * 推送记录保存到ES
     * @param accessToken 微信AccessToken(微信平台)
     * @param pushPlatform 推送的平台 1、微信平台,2、平台消息
     * @param type 消息类型
     * @param openid 微信的openid
     * @param url 微信跳转url
     * @param data 数据(微信平台、平台消息)
     * @param receiver 接受人(平台消息)
     * @param title 标题(平台消息)
     * @param msg 消息(平台消息)
     * @param success 是否推送成功(1、成功,-1、失败)
     */
    public void saveAssistantMsgPushLog(String accessToken,Integer pushPlatform,String type,String openid,
                                        String url,String data,String receiver,String title,String msg,Integer success){
        AssistantMsgPushLog assistantMsgPushLog = new AssistantMsgPushLog();
        assistantMsgPushLog.setAccessToken(accessToken);
        assistantMsgPushLog.setCreateTime(new Date());
        assistantMsgPushLog.setPushPlatform(pushPlatform);
        assistantMsgPushLog.setType(type);
        assistantMsgPushLog.setOpenid(openid);
        assistantMsgPushLog.setUrl(url);
        assistantMsgPushLog.setData(data);
        assistantMsgPushLog.setReceiver(receiver);
        assistantMsgPushLog.setTitle(title);
        assistantMsgPushLog.setMsg(msg);
        assistantMsgPushLog.setSuccess(success);
        elastricSearchSave.save(assistantMsgPushLog, esIndex, esType);
    }
}

+ 6 - 5
patient-co/patient-co-doctor-assistant/src/main/resources/application-dev.yml

@ -92,12 +92,13 @@ pushMes:
es:
  index:
    HealthEduArticlePatient: health_edu_article_patient_dev
    HealthEduArticlePatient: health_edu_article_patient_test
    AssistantMsgPushLog: assistant_msg_push_log
  type:
    HealthEduArticlePatient: health_edu_article_patient_dev
  host: 172.19.103.68
  port: 9200
  tPort: 9300
    HealthEduArticlePatient: health_edu_article_patient_test
    AssistantMsgPushLog: assistant_msg_push_log
  host: http://172.19.103.68:9200
  tHost: http://172.19.103.68:9300
  clusterName: jkzl
#消息队列
activemq:

+ 4 - 3
patient-co/patient-co-doctor-assistant/src/main/resources/application-devtest.yml

@ -91,11 +91,12 @@ pushMes:
es:
  index:
    HealthEduArticlePatient: health_edu_article_patient_test
    AssistantMsgPushLog: assistant_msg_push_log
  type:
    HealthEduArticlePatient: health_edu_article_patient_test
  host: 172.19.103.68
  port: 9200
  tPort: 9300
    AssistantMsgPushLog: assistant_msg_push_log
  host: http://172.19.103.68:9200
  tHost: http://172.19.103.68:9300
  clusterName: jkzl

+ 4 - 3
patient-co/patient-co-doctor-assistant/src/main/resources/application-local.yml

@ -90,11 +90,12 @@ pushMes:
es:
  index:
    HealthEduArticlePatient: health_edu_article_patient_test
    AssistantMsgPushLog: assistant_msg_push_log
  type:
    HealthEduArticlePatient: health_edu_article_patient_test
  host: 172.19.103.68
  port: 9200
  tPort: 9300
    AssistantMsgPushLog: assistant_msg_push_log
  host: http://172.19.103.68:9200
  tHost: http://172.19.103.68:9300
  clusterName: jkzl

+ 4 - 3
patient-co/patient-co-doctor-assistant/src/main/resources/application-localtest.yml

@ -91,11 +91,12 @@ pushMes:
es:
  index:
    HealthEduArticlePatient: health_edu_article_patient_test
    AssistantMsgPushLog: assistant_msg_push_log
  type:
    HealthEduArticlePatient: health_edu_article_patient_test
  host: 172.19.103.68
  port: 9200
  tPort: 9300
    AssistantMsgPushLog: assistant_msg_push_log
  host: http://172.19.103.68:9200
  tHost: http://172.19.103.68:9300
  clusterName: jkzl

+ 11 - 1
patient-co/patient-co-doctor-assistant/src/main/resources/application-prod.yml

@ -85,4 +85,14 @@ pushMes:
# 1为推送redis,0为推送消息队列
  method: 0
  # redis队列名称
  redis_prescription_title: redisPrescription
  redis_prescription_title: redisPrescription
es:
  index:
    HealthEduArticlePatient: health_edu_article_patient
    AssistantMsgPushLog: assistant_msg_push_log
  type:
    HealthEduArticlePatient: health_edu_article_patient
    AssistantMsgPushLog: assistant_msg_push_log
  host: http://59.61.92.90:9065,http://59.61.92.90:9067
  tHost: 59.61.92.90:9066,59.61.92.90:9068
  clusterName: jkzl

+ 4 - 3
patient-co/patient-co-doctor-assistant/src/main/resources/application-test.yml

@ -89,11 +89,12 @@ pushMes:
es:
  index:
    HealthEduArticlePatient: health_edu_article_patient_test
    AssistantMsgPushLog: assistant_msg_push_log
  type:
    HealthEduArticlePatient: health_edu_article_patient_test
  host: 172.19.103.68
  port: 9200
  tPort: 9300
    AssistantMsgPushLog: assistant_msg_push_log
  host: http://172.19.103.68:9200
  tHost: http://172.19.103.68:9300
  clusterName: jkzl
#消息队列

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandingService.java

@ -517,7 +517,7 @@ public class DataHandingService {
     */
    public List<String> importKitInfo(Integer batch)throws Exception{
        String sql = " select * from wlyy.kit_bind_info_temp where batch="+batch;
        String sql = " select * from wlyy.kit_bind_info_temp where batch="+batch+" and import=0";
        List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
        List<String> errorList = new ArrayList<>();
        for(Map<String,Object> one:mapList){