Bläddra i källkod

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

chenweida 7 år sedan
förälder
incheckning
62587e4fef

+ 18 - 0
common/common-entity/src/main/java/com/yihu/es/entity/HealthEduArticlePatient.java

@ -20,6 +20,8 @@ public class HealthEduArticlePatient {
    private String patient; // 患者标识
    @Transient
    private String patientName;    // 患者标识
    private String doctorCode;  //推送的医生code(包括医生本人、卫计委)
    private String doctorName;  //推送的医生名称(包括医生本人、卫计委)
    private String sendCode;   // 发送人code
    private String sendName;   // 发送人名称
    private String sendPic;   // 发送人头像
@ -292,4 +294,20 @@ public class HealthEduArticlePatient {
    public void setPatients(List<Patient> patients) {
        this.patients = patients;
    }
    public String getDoctorCode() {
        return doctorCode;
    }
    public void setDoctorCode(String doctorCode) {
        this.doctorCode = doctorCode;
    }
    public String getDoctorName() {
        return doctorName;
    }
    public void setDoctorName(String doctorName) {
        this.doctorName = doctorName;
    }
}

+ 90 - 90
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/activemq/StartListener.java

@ -1,90 +1,90 @@
//package com.yihu.wlyy.activemq;
//
//import com.yihu.wlyy.util.SpringUtil;
//import org.apache.activemq.ActiveMQSession;
//import org.apache.activemq.command.ActiveMQQueue;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.jms.connection.CachingConnectionFactory;
//import org.springframework.jms.listener.DefaultMessageListenerContainer;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import javax.jms.MessageListener;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * Created by chenweida on 2017/9/9.
// */
//@Component
//public class StartListener {
//    private static Map<String, DefaultMessageListenerContainer> holder = new HashMap<String, DefaultMessageListenerContainer>();
//    private Logger logger = LoggerFactory.getLogger(StartListener.class);
//
//    @Value("${activemq.queue.healtHarticleQueue}")
//    private String healtHarticleQueue;
//    @Value("${activemq.consumers.count}")
//    private Integer count;
//    @Autowired
//    private HealthArtListener healthArtListener;
//    @Autowired
//    private CachingConnectionFactory cachingConnectionFactory;
//
//    @PostConstruct
//    public void startListener() {
//        startHealthArticQueueListener();
//    }
//
//    /**
//     * 启动健康教育消费
//     */
//    private void startHealthArticQueueListener() {
//        try {
//            //启动监听
//            startReceiverByQueueName(healthArtListener, healtHarticleQueue);
//            logger.info("start HealthArtListener success");
//        } catch (Exception e) {
//            logger.error("start HealthArtListener error");
//        }
//    }
//
//    /**
//     * 启动
//     *
//     * @param receiver
//     * @param queueName
//     */
//    private void startReceiverByQueueName(MessageListener receiver, String queueName) {
//        if (holder.get(queueName) != null) {
//            return;
//        }
//        ActiveMQQueue destination = new ActiveMQQueue(queueName);
//
//        DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer();
//        // 监听容器属性的配置
//        listenerContainer.setConnectionFactory(cachingConnectionFactory);
//        // 设置目的地
//        listenerContainer.setDestination(destination);
//        // 设置监听器
//        listenerContainer.setMessageListener(receiver);
//        // 设置消费者集群数
//        int consumers = count;
//        listenerContainer.setConcurrentConsumers(2);
//        listenerContainer.setMaxConcurrentConsumers(consumers);
//        // 设置监听队列还是主题 默认是队列
//        listenerContainer.setPubSubNoLocal(false);
//        // listenerContainer.setAcceptMessagesWhileStopping(true);
//        // 设置应答模式 默认是4
//        listenerContainer.setSessionAcknowledgeMode(ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
//        // 设置是否启动事物 默认不开启
//        listenerContainer.setSessionTransacted(false);
//        // 将监听容器保存在holder中
//        holder.put(queueName, listenerContainer);
//        listenerContainer.initialize();
//        // 启动监听
//        listenerContainer.start();
//    }
//}
package com.yihu.wlyy.activemq;
import com.yihu.wlyy.util.SpringUtil;
import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.command.ActiveMQQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.jms.MessageListener;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by chenweida on 2017/9/9.
 */
@Component
public class StartListener {
    private static Map<String, DefaultMessageListenerContainer> holder = new HashMap<String, DefaultMessageListenerContainer>();
    private Logger logger = LoggerFactory.getLogger(StartListener.class);
    @Value("${activemq.queue.healtHarticleQueue}")
    private String healtHarticleQueue;
    @Value("${activemq.consumers.count}")
    private Integer count;
    @Autowired
    private HealthArtListener healthArtListener;
    @Autowired
    private CachingConnectionFactory cachingConnectionFactory;
    @PostConstruct
    public void startListener() {
        startHealthArticQueueListener();
    }
    /**
     * 启动健康教育消费
     */
    private void startHealthArticQueueListener() {
        try {
            //启动监听
            startReceiverByQueueName(healthArtListener, healtHarticleQueue);
            logger.info("start HealthArtListener success");
        } catch (Exception e) {
            logger.error("start HealthArtListener error");
        }
    }
    /**
     * 启动
     *
     * @param receiver
     * @param queueName
     */
    private void startReceiverByQueueName(MessageListener receiver, String queueName) {
        if (holder.get(queueName) != null) {
            return;
        }
        ActiveMQQueue destination = new ActiveMQQueue(queueName);
        DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer();
        // 监听容器属性的配置
        listenerContainer.setConnectionFactory(cachingConnectionFactory);
        // 设置目的地
        listenerContainer.setDestination(destination);
        // 设置监听器
        listenerContainer.setMessageListener(receiver);
        // 设置消费者集群数
        int consumers = count;
        listenerContainer.setConcurrentConsumers(2);
        listenerContainer.setMaxConcurrentConsumers(consumers);
        // 设置监听队列还是主题 默认是队列
        listenerContainer.setPubSubNoLocal(false);
        // listenerContainer.setAcceptMessagesWhileStopping(true);
        // 设置应答模式 默认是4
        listenerContainer.setSessionAcknowledgeMode(ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
        // 设置是否启动事物 默认不开启
        listenerContainer.setSessionTransacted(false);
        // 将监听容器保存在holder中
        holder.put(queueName, listenerContainer);
        listenerContainer.initialize();
        // 启动监听
        listenerContainer.start();
    }
}

+ 70 - 70
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/config/ActiveMQConfig.java

@ -1,70 +1,70 @@
//package com.yihu.wlyy.config;
//
//import com.yihu.wlyy.activemq.HealthArtListener;
//import com.yihu.wlyy.util.SpringUtil;
//import org.apache.activemq.ActiveMQConnectionFactory;
//import org.apache.activemq.ActiveMQSession;
//import org.apache.activemq.command.ActiveMQQueue;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.jms.annotation.EnableJms;
//import org.springframework.jms.connection.CachingConnectionFactory;
//import org.springframework.jms.core.JmsTemplate;
//import org.springframework.jms.listener.DefaultMessageListenerContainer;
//
//import javax.annotation.PostConstruct;
//import javax.jms.MessageListener;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * Created by chenweida on 2017/9/9.
// * 生产者配置
// */
//@EnableJms
//@Configuration
//public class ActiveMQConfig {
//   @Value("${activemq.username}")
//    private String username;
//    @Value("${activemq.password}")
//    private String password;
//    @Value("${activemq.url}")
//    private String url;
//
//    @Bean
//    public ActiveMQConnectionFactory activeMQConnectionFactory() {
//        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(username, password, url);
//        //设置异步发送
//        activeMQConnectionFactory.setUseAsyncSend(true);
//        return activeMQConnectionFactory;
//    }
//
//    /**
//     * 缓存session链接
//     *
//     * @return
//     */
//    @Bean
//    @Primary
//    public CachingConnectionFactory CachingConnectionFactory() {
//        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
//        //目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory
//        cachingConnectionFactory.setTargetConnectionFactory(activeMQConnectionFactory());
//        //Session缓存数量,这里属性也可以直接在这里配置
//        cachingConnectionFactory.setSessionCacheSize(100);
//        return cachingConnectionFactory;
//    }
//
//    @Bean
//    public JmsTemplate jmsTemplate() {
//        JmsTemplate jmsTemplate = new JmsTemplate();
//        jmsTemplate.setConnectionFactory(CachingConnectionFactory());
//
//        return jmsTemplate;
//    }
//
//}
package com.yihu.wlyy.config;
import com.yihu.wlyy.activemq.HealthArtListener;
import com.yihu.wlyy.util.SpringUtil;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.command.ActiveMQQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import javax.annotation.PostConstruct;
import javax.jms.MessageListener;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by chenweida on 2017/9/9.
 * 生产者配置
 */
@EnableJms
@Configuration
public class ActiveMQConfig {
   @Value("${activemq.username}")
    private String username;
    @Value("${activemq.password}")
    private String password;
    @Value("${activemq.url}")
    private String url;
    @Bean
    public ActiveMQConnectionFactory activeMQConnectionFactory() {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(username, password, url);
        //设置异步发送
        activeMQConnectionFactory.setUseAsyncSend(true);
        return activeMQConnectionFactory;
    }
    /**
     * 缓存session链接
     *
     * @return
     */
    @Bean
    @Primary
    public CachingConnectionFactory CachingConnectionFactory() {
        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
        //目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory
        cachingConnectionFactory.setTargetConnectionFactory(activeMQConnectionFactory());
        //Session缓存数量,这里属性也可以直接在这里配置
        cachingConnectionFactory.setSessionCacheSize(100);
        return cachingConnectionFactory;
    }
    @Bean
    public JmsTemplate jmsTemplate() {
        JmsTemplate jmsTemplate = new JmsTemplate();
        jmsTemplate.setConnectionFactory(CachingConnectionFactory());
        return jmsTemplate;
    }
}

+ 2 - 2
patient-co/patient-co-wlyy-job/src/main/resources/application-devtest.yml

@ -21,7 +21,7 @@ channel:
  redis:
    host: 172.19.103.88 # Redis server host.
    port: 6379 # Redis server port.
    password: jkzl_ehr
    password:
server:
  server_url: http://ehr.yihu.com/wlyy/
@ -105,7 +105,7 @@ activemq:
  password: admin
  url: tcp://172.19.103.87:61616
  queue:
    healtHarticleQueue: healthArticleChannel_devtest  #健康文章推送
    healtHarticleQueue: healthArticleChannel_devtest
  consumers:
    count: 10 #消费者集群数

+ 59 - 59
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/config/ActiveMQConfig.java

@ -1,59 +1,59 @@
//package com.yihu.wlyy.config;
//
//import org.apache.activemq.ActiveMQConnectionFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.context.annotation.Profile;
//import org.springframework.jms.annotation.EnableJms;
//import org.springframework.jms.connection.CachingConnectionFactory;
//import org.springframework.jms.core.JmsTemplate;
//
///**
// * Created by chenweida on 2017/9/9.
// * 生产者配置
// */
//@EnableJms
//@Configuration
//@Profile({"dev", "devtest", "prod", "test"})
//public class ActiveMQConfig {
//    @Value("${activemq.username}")
//    private String username;
//    @Value("${activemq.password}")
//    private String password;
//    @Value("${activemq.url}")
//    private String url;
//
//    @Bean
//    public ActiveMQConnectionFactory activeMQConnectionFactory() {
//        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(username, password, url);
//        //设置异步发送
//        activeMQConnectionFactory.setUseAsyncSend(true);
//        return activeMQConnectionFactory;
//    }
//
//    /**
//     * 缓存session链接
//     *
//     * @return
//     */
//    @Bean
//    @Primary
//    public CachingConnectionFactory CachingConnectionFactory() {
//        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
//        //目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory
//        cachingConnectionFactory.setTargetConnectionFactory(activeMQConnectionFactory());
//        //Session缓存数量,这里属性也可以直接在这里配置
//        cachingConnectionFactory.setSessionCacheSize(100);
//        return cachingConnectionFactory;
//    }
//
//    @Bean
//    public JmsTemplate jmsTemplate() {
//        JmsTemplate jmsTemplate = new JmsTemplate();
//        jmsTemplate.setConnectionFactory( CachingConnectionFactory());
//
//        return jmsTemplate;
//    }
//}
package com.yihu.wlyy.config;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.core.JmsTemplate;
/**
 * Created by chenweida on 2017/9/9.
 * 生产者配置
 */
@EnableJms
@Configuration
@Profile({"dev", "devtest", "prod", "test"})
public class ActiveMQConfig {
    @Value("${activemq.username}")
    private String username;
    @Value("${activemq.password}")
    private String password;
    @Value("${activemq.url}")
    private String url;
    @Bean
    public ActiveMQConnectionFactory activeMQConnectionFactory() {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(username, password, url);
        //设置异步发送
        activeMQConnectionFactory.setUseAsyncSend(true);
        return activeMQConnectionFactory;
    }
    /**
     * 缓存session链接
     *
     * @return
     */
    @Bean
    @Primary
    public CachingConnectionFactory CachingConnectionFactory() {
        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
        //目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory
        cachingConnectionFactory.setTargetConnectionFactory(activeMQConnectionFactory());
        //Session缓存数量,这里属性也可以直接在这里配置
        cachingConnectionFactory.setSessionCacheSize(100);
        return cachingConnectionFactory;
    }
    @Bean
    public JmsTemplate jmsTemplate() {
        JmsTemplate jmsTemplate = new JmsTemplate();
        jmsTemplate.setConnectionFactory( CachingConnectionFactory());
        return jmsTemplate;
    }
}

+ 402 - 148
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/fzzb/HealthEducationArticleService.java

@ -7,6 +7,7 @@ import com.yihu.es.entity.HealthEduArticlePatient;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.util.HttpClientUtil;
@ -29,7 +30,7 @@ import java.util.*;
 * Created by yeshijie on 2017/9/11.
 */
@Service
public class HealthEducationArticleService extends BaseService{
public class HealthEducationArticleService extends BaseService {
    private static Logger logger = LoggerFactory.getLogger(HealthEducationArticleService.class);
@ -47,10 +48,14 @@ public class HealthEducationArticleService extends BaseService{
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private HealthEducationArticleService healthEducationArticleService;
    @Autowired
    private PatientService patientService;
    @Value("${jkEdu.web.articleBaseUrl}")
    private String articleBaseUrl;
//    private String baseUrl = "http://service.yihu.com:8085/WsPlatform/rest";
    private String baseUrl = "http://172.17.110.230:83/WsPlatform/rest";
//    private String baseUrl = "http://172.19.103.87:9088/JkEdu";
    //    private String baseUrl = "http://service.yihu.com:8085/WsPlatform/rest";
//    private String baseUrl = "http://172.17.110.230:83/WsPlatform/rest";
//    private String baseUrl = articleBaseUrl+"/WsPlatform/rest";
    @Value("${yihu.yihu_OpenPlatform_appId}")
    private String clientId;
@ -68,128 +73,132 @@ public class HealthEducationArticleService extends BaseService{
    /**
     * 封装入参
     *
     * @param api
     * @param param
     * @param version
     * @return
     */
    public Map<String,String> getParamsMap(String api,String param,String version){
        Map<String,String> params = new HashMap<>();
    public Map<String, String> getParamsMap(String api, String param, String version) {
        Map<String, String> params = new HashMap<>();
        JSONObject authInfo = new JSONObject();
        authInfo.put("clientId",clientId);//填渠道ID(必填,固定为9000276)
        authInfo.put("clientVersion",clientVersion);//接入方系统版本号(非必须,默认 1.0)
        authInfo.put("sign","");//(保留,非必填)
        authInfo.put("sessionKey","");//(保留,非必填)
        params.put("AuthInfo",authInfo.toString());
        authInfo.put("clientId", clientId);//填渠道ID(必填,固定为9000276)
        authInfo.put("clientVersion", clientVersion);//接入方系统版本号(非必须,默认 1.0)
        authInfo.put("sign", "");//(保留,非必填)
        authInfo.put("sessionKey", "");//(保留,非必填)
        params.put("AuthInfo", authInfo.toString());
        params.put("SequenceNoString", DateUtil.getUserDate(DateUtil.YYYYMMddHHmmssSSS));//请求序列号,yyyyMMddHHmmssSSS 格式的时间戳
        params.put("Api",api);//Api 名称    需要调用的 API 名称
        params.put("Param",param);//本次请求的方法参数   Json结构的字符串
        params.put("ParamType","0");//指定 param 参数的类型,固定传0
        params.put("OutType","0");//指定返回 JSON/Xml 结构的字符串,固定传0
        params.put("V",version);//API 版本号。版本号为整型,从数字 1 开始递增.
        params.put("Api", api);//Api 名称    需要调用的 API 名称
        params.put("Param", param);//本次请求的方法参数   Json结构的字符串
        params.put("ParamType", "0");//指定 param 参数的类型,固定传0
        params.put("OutType", "0");//指定返回 JSON/Xml 结构的字符串,固定传0
        params.put("V", version);//API 版本号。版本号为整型,从数字 1 开始递增.
        return params;
    }
    /**
     * 获取文章列表
     * @param articleTitle 否 文章标题
     * @param articleState 否 传1
     *
     * @param articleTitle         否 文章标题
     * @param articleState         否 传1
     * @param firstLevelCategoryId 否    一级类别ID ,多个逗号隔开
     * @param pageIndex 否    起始页数 0开始,默认0
     * @param pageSize 否    每页显示数 ,默认5
     * @param userId 是    当前用户ID
     * @param pageIndex            否    起始页数 0开始,默认0
     * @param pageSize             否    每页显示数 ,默认5
     * @param userId               是    当前用户ID
     * @return
     */
    public JSONArray getDoctorArticalList(String articleTitle, Integer articleState, String firstLevelCategoryId, Integer pageIndex, Integer pageSize,String userId) throws Exception{
    public JSONArray getDoctorArticalList(String articleTitle, Integer articleState, String firstLevelCategoryId, Integer pageIndex, Integer pageSize, String userId) throws Exception {
        JSONArray re = new JSONArray();
        JSONObject json = null;
        try{
        try {
            JSONObject param = new JSONObject();
            param.put("articleTitle",articleTitle);
            param.put("articleState",articleState);
            param.put("firstLevelCategoryId",firstLevelCategoryId);
            param.put("pageIndex",pageIndex);
            param.put("pageSize",pageSize);
            param.put("userId",userId);
            String response = httpClientUtil.httpPost(baseUrl,getParamsMap(getDoctorArticalList,param.toString(),"1"));
            param.put("articleTitle", articleTitle);
            param.put("articleState", articleState);
            param.put("firstLevelCategoryId", firstLevelCategoryId);
            param.put("pageIndex", pageIndex);
            param.put("pageSize", pageSize);
            param.put("userId", userId);
            String response = httpClientUtil.httpPost(articleBaseUrl+"/WsPlatform/rest", getParamsMap(getDoctorArticalList, param.toString(), "1"));
            json = JSON.parseObject(response);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return re;
        }
        if("10000".equals(json.getString("Code"))){
        if ("10000".equals(json.getString("Code"))) {
            return json.getJSONArray("Result");
        }else {
        } else {
            throw new Exception(json.getString("Message"));
        }
    }
    /**
     * 获取文章详情
     *
     * @param articleId 文章id
     * @return
     */
    public JSONObject getArticalById(String articleId) throws Exception{
    public JSONObject getArticalById(String articleId) throws Exception {
        JSONObject re = new JSONObject();
        JSONObject json = null;
        try{
        try {
            JSONObject param = new JSONObject();
            param.put("articleId",articleId);
            String response = httpClientUtil.httpPost(baseUrl,getParamsMap(getArticalById,param.toString(),"1"));
            param.put("articleId", articleId);
            String response = httpClientUtil.httpPost(articleBaseUrl+"/WsPlatform/rest", getParamsMap(getArticalById, param.toString(), "1"));
            json = JSON.parseObject(response);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return re;
        }
        if("10000".equals(json.getString("Code"))){
        if ("10000".equals(json.getString("Code"))) {
            JSONArray result = json.getJSONArray("Result");
            if(result.size()>0){
            if (result.size() > 0) {
                return result.getJSONObject(0);
            }
            return re;
        }else {
        } else {
            throw new Exception(json.getString("Message"));
        }
    }
    /**
     * 获取收藏文章列表
     * @param articleTitle 否 文章标题
     * @param articleState 否 传1
     *
     * @param articleTitle         否 文章标题
     * @param articleState         否 传1
     * @param firstLevelCategoryId 否    一级类别ID ,多个逗号隔开
     * @param pageIndex 否    起始页数 0开始,默认0
     * @param pageSize 否    每页显示数 ,默认5
     * @param userId 是    当前用户ID
     * @param userType 是    1 医生 2 居民
     * @param pageIndex            否    起始页数 0开始,默认0
     * @param pageSize             否    每页显示数 ,默认5
     * @param userId               是    当前用户ID
     * @param userType             是    1 医生 2 居民
     * @return
     */
    public JSONArray getCollectionArticalList(String articleTitle, Integer articleState, String firstLevelCategoryId,
                                              Integer pageIndex, Integer pageSize,String userId,Integer userType) throws Exception{
                                              Integer pageIndex, Integer pageSize, String userId, Integer userType) throws Exception {
        JSONArray re = new JSONArray();
        JSONObject json = null;
        try{
        try {
            JSONObject param = new JSONObject();
            param.put("articleTitle",articleTitle);
            param.put("articleState",articleState);
            param.put("firstLevelCategoryId",firstLevelCategoryId);
            param.put("pageIndex",pageIndex);
            param.put("pageSize",pageSize);
            param.put("userId",userId);
            param.put("userType",userType);
            String response = httpClientUtil.httpPost(baseUrl,getParamsMap(getCollectionArticalList,param.toString(),"1"));
            param.put("articleTitle", articleTitle);
            param.put("articleState", articleState);
            param.put("firstLevelCategoryId", firstLevelCategoryId);
            param.put("pageIndex", pageIndex);
            param.put("pageSize", pageSize);
            param.put("userId", userId);
            param.put("userType", userType);
            String response = httpClientUtil.httpPost(articleBaseUrl+"/WsPlatform/rest", getParamsMap(getCollectionArticalList, param.toString(), "1"));
            json = JSON.parseObject(response);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return re;
        }
        if("10000".equals(json.getString("Code"))){
        if ("10000".equals(json.getString("Code"))) {
            return json.getJSONArray("Result");
        }else {
        } else {
            throw new Exception(json.getString("Message"));
        }
    }
@ -197,154 +206,158 @@ public class HealthEducationArticleService extends BaseService{
    /**
     * 获取文章类别
     *
     * @param categoryLevel 是    获取类别:1、一级类别 2、二级类别
     * @return
     */
    public JSONArray getCategoryList(String categoryLevel) throws Exception{
    public JSONArray getCategoryList(String categoryLevel) throws Exception {
        JSONArray re = new JSONArray();
        JSONObject json = null;
        try{
        try {
            JSONObject param = new JSONObject();
            param.put("categoryLevel",categoryLevel);
            param.put("categoryLevel", categoryLevel);
            String response = httpClientUtil.httpPost(baseUrl,getParamsMap(getCategoryList,param.toString(),"1"));
            String response = httpClientUtil.httpPost(articleBaseUrl+"/WsPlatform/rest", getParamsMap(getCategoryList, param.toString(), "1"));
            json = JSON.parseObject(response);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return re;
        }
        if("10000".equals(json.getString("Code"))){
        if ("10000".equals(json.getString("Code"))) {
            return json.getJSONObject("Result").getJSONArray("result");
        }else {
        } else {
            throw new Exception(json.getString("Message"));
        }
    }
    /**
     * 取消收藏文章
     *
     * @param articleId 是 文章id
     * @param userId 是    当前用户ID
     * @param userType 是    1 医生 2 居民
     * @param userId    是    当前用户ID
     * @param userType  是    1 医生 2 居民
     * @return
     */
    public void cancelArticleCollection(String articleId,String userId,Integer userType) throws Exception{
    public void cancelArticleCollection(String articleId, String userId, Integer userType) throws Exception {
        String response = "";
        JSONObject json = null;
        try{
        try {
            JSONObject param = new JSONObject();
            param.put("articleId",articleId);
            param.put("userId",userId);
            param.put("userType",userType);
            param.put("articleId", articleId);
            param.put("userId", userId);
            param.put("userType", userType);
            response = httpClientUtil.httpPost(baseUrl,getParamsMap(cancelArticleCollection,param.toString(),"1"));
            response = httpClientUtil.httpPost(articleBaseUrl+"/WsPlatform/rest", getParamsMap(cancelArticleCollection, param.toString(), "1"));
            json = JSON.parseObject(response);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
        if("10000".equals(json.getString("Code"))){
        if ("10000".equals(json.getString("Code"))) {
        }else {
        } else {
            new Exception(json.getString("Message"));
        }
    }
    /**
     * 收藏文章列表
     * @param articleId 文章id
     * @param articleCategoryId 文章类别ID
     *
     * @param articleId           文章id
     * @param articleCategoryId   文章类别ID
     * @param articleCategoryName 文章类别名称
     * @param userId 是    当前用户ID
     * @param userType 是    1 医生 2 居民
     * @param userId              是    当前用户ID
     * @param userType            是    1 医生 2 居民
     * @return
     */
    public void saveArticleCollection(String articleId, String articleCategoryId, String articleCategoryName,String userId,Integer userType){
    public void saveArticleCollection(String articleId, String articleCategoryId, String articleCategoryName, String userId, Integer userType) {
        String response = "";
        JSONObject json = null;
        try{
        try {
            Doctor doctor = doctorDao.findByCode(userId);
            String orgName = doctor.getHospitalName();//用户所属机构
            String orgId = doctor.getHospital();//用户所属机构ID
            String cName = doctor.getName();//用户名
            JSONObject param = new JSONObject();
            param.put("articleId",articleId);
            param.put("cName",cName);
            param.put("articleCategoryId",articleCategoryId);
            param.put("articleCategoryName",articleCategoryName);
            param.put("orgName",orgName);
            param.put("orgId",orgId);
            param.put("userId",userId);
            param.put("userType",userType);
            response = httpClientUtil.httpPost(baseUrl,getParamsMap(saveArticleCollection,param.toString(),"1"));
            param.put("articleId", articleId);
            param.put("cName", cName);
            param.put("articleCategoryId", articleCategoryId);
            param.put("articleCategoryName", articleCategoryName);
            param.put("orgName", orgName);
            param.put("orgId", orgId);
            param.put("userId", userId);
            param.put("userType", userType);
            response = httpClientUtil.httpPost(articleBaseUrl+"/WsPlatform/rest", getParamsMap(saveArticleCollection, param.toString(), "1"));
            json = JSON.parseObject(response);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
        if("10000".equals(json.getString("Code"))){
        if ("10000".equals(json.getString("Code"))) {
        }else {
        } else {
            new Exception(json.getString("Message"));
        }
    }
    /**
     * 获取医生发表的文章列表
     * @param articleTitle 否 文章标题
     * @param articleState 否 传1
     *
     * @param articleTitle         否 文章标题
     * @param articleState         否 传1
     * @param firstLevelCategoryId 否    一级类别ID ,多个逗号隔开
     * @param pageIndex 否    起始页数 0开始,默认0
     * @param pageSize 否    每页显示数 ,默认5
     * @param userId 是    当前用户ID
     * @param pageIndex            否    起始页数 0开始,默认0
     * @param pageSize             否    每页显示数 ,默认5
     * @param userId               是    当前用户ID
     * @return
     */
    public JSONArray getDoctorArticalByUserId(String articleTitle, Integer articleState, String firstLevelCategoryId,
                                              Integer pageIndex, Integer pageSize,String userId) throws Exception{
                                              Integer pageIndex, Integer pageSize, String userId) throws Exception {
        JSONArray re = new JSONArray();
        JSONObject json = null;
        try{
        try {
            JSONObject param = new JSONObject();
            param.put("articleTitle",articleTitle);
            param.put("articleState",articleState);
            param.put("firstLevelCategoryId",firstLevelCategoryId);
            param.put("pageIndex",pageIndex);
            param.put("pageSize",pageSize);
            param.put("userId",userId);
            String response = httpClientUtil.httpPost(baseUrl,getParamsMap(getDoctorArticalByUserId,param.toString(),"1"));
            param.put("articleTitle", articleTitle);
            param.put("articleState", articleState);
            param.put("firstLevelCategoryId", firstLevelCategoryId);
            param.put("pageIndex", pageIndex);
            param.put("pageSize", pageSize);
            param.put("userId", userId);
            String response = httpClientUtil.httpPost(articleBaseUrl+"/WsPlatform/rest", getParamsMap(getDoctorArticalByUserId, param.toString(), "1"));
            json = JSON.parseObject(response);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return re;
        }
        if("10000".equals(json.getString("Code"))){
        if ("10000".equals(json.getString("Code"))) {
            return json.getJSONArray("Result");
        }else {
        } else {
            throw new Exception(json.getString("Message"));
        }
    }
    public JSONArray getArticalList(String articleId,int articleState,int pageIndex,int pageSize) throws Exception{
    public JSONArray getArticalList(String articleId, int articleState, int pageIndex, int pageSize) throws Exception {
        JSONArray re = new JSONArray();
        JSONObject json = null;
        try{
        try {
            JSONObject param = new JSONObject();
            param.put("articleId",articleId);
            param.put("articleState",articleState);
            param.put("pageIndex",pageIndex);
            param.put("pageSize",pageSize);
            String response = httpClientUtil.httpPost(baseUrl,getParamsMap(getArticalList,param.toString(),"1"));
            param.put("articleId", articleId);
            param.put("articleState", articleState);
            param.put("pageIndex", pageIndex);
            param.put("pageSize", pageSize);
            String response = httpClientUtil.httpPost(articleBaseUrl+"/WsPlatform/rest", getParamsMap(getArticalList, param.toString(), "1"));
            json = JSON.parseObject(response);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return re;
        }
        if("10000".equals(json.getString("Code"))){
        if ("10000".equals(json.getString("Code"))) {
            return json.getJSONArray("Result");
        }else {
        } else {
            throw new Exception(json.getString("Message"));
        }
    }
@ -367,40 +380,122 @@ public class HealthEducationArticleService extends BaseService{
//        return null;
//    }
    public JSONArray labelWithPushPatients(String labelType){
    public JSONArray labelWithPushPatients(String labelType, String condition,String teamCode) {
        String[] cond = {};
        if (!StringUtils.isEmpty(condition)) {
            cond = condition.split(",");
        }
        StringBuilder whereSql = new StringBuilder();
        String tableSql = "";
        for (String one : cond) {
            if ("1".equals(one)) {//有绑定设备
                tableSql = "LEFT JOIN wlyy_patient_device d on d.user=aa.patient and d.device_id is not null ";
            } else if ("2".equals(one)) {//孕产妇
//                temp.add("41");
                whereSql.append(" and tt LIKE '%41%' ");
            } else if ("3".equals(one)) {//65岁以上老年人
//                temp.add("13");
                whereSql.append(" and tt LIKE '%13%' ");
            }
        }
        String sql = "";
        List<DictModel> returnList = null;
        Map<String, Object> map = null;
        JSONArray re = new JSONArray();
        switch (labelType) {
            case "1": {
                sql = "select s.code code,s.name name from wlyy_sign_dict s where s.year='2017' order by s.sort asc";
                returnList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DictModel.class));
                sql = "select count(DISTINCT(w.patient)) as num from wlyy_sign_family w "+
                        " left join wlyy_sign_family_server s on w.code= s.sign_code "+
                        " left join wlyy_patient p on p.code=w.patient "+
                        " where w.status>0 and p.town='350211' ";
                for(DictModel one:returnList){
                    sql +=" s.server_type='"+one.getCode()+"'";
                    Map<String, Object> map = jdbcTemplate.queryForMap(sql);
                for (DictModel one : returnList) {
//                    sql = "select count(DISTINCT(w.patient)) as num from wlyy_sign_family w "+
//                            " left join wlyy_sign_family_server s on w.code= s.sign_code "+
//                            " left join wlyy_patient p on p.code=w.patient "+
//                            " where w.status>0 and p.town='350211' ";
//                    sql +=" and s.server_type='"+one.getCode()+"'";
                    sql = " SELECT count(DISTINCT(aa.patient)) AS num FROM " +
                            " ( SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
                            " FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l, " +
                            " wlyy_sign_family_server q WHERE w. STATUS > 0 AND l. STATUS = 1 AND w.team_code=" +teamCode+
                            " AND w.patient = l.patient AND LEFT (w.hospital, 6) = '350211' " +
                            " AND w. CODE = q.sign_code AND q.server_type = 1 ) a " +
                            " GROUP BY a.patient HAVING 1 = 1 AND tt LIKE '%1" + one.getCode() + "%' " + whereSql.toString() + ") aa " + tableSql;
                    map = jdbcTemplate.queryForMap(sql);
                    JSONObject obj = new JSONObject();
                    obj.put("code",one.getCode());
                    obj.put("name",one.getName());
                    obj.put("num",(Long)map.get("num"));
                    obj.put("code", one.getCode());
                    obj.put("name", one.getName());
                    obj.put("num", (Long) map.get("num"));
                    re.add(obj);
                }
                break;
            }
            case "2": {
                sql = "select label_code code, label_name name from wlyy_sign_patient_label  where label_type=2 and status=1";
                returnList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DictModel.class));
                for (DictModel one : returnList) {
//                    sql =" select count(DISTINCT(w.patient)) as num from wlyy_sign_family w "+
//                            " left join wlyy_sign_patient_label_info l on w.patient=l.patient "+
//                            " left join wlyy_patient p on p.code=w.patient "+
//                            " where w.status>0 and p.town='350211' and l.status=1 and l.label_type = 2 AND l.label ="+one.getCode();
                    sql = " select count(DISTINCT(aa.patient)) as num from ( " +
                            " SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
                            " FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l " +//AND w.team_code=" +teamCode+
                            " WHERE w. STATUS > 0 and l.status=1 AND  w.team_code="+teamCode+" AND w.patient = l.patient AND LEFT (w.hospital, 6) = '350211' ) a " +
                            " GROUP BY a.patient HAVING tt LIKE '%2" + one.getCode() + "%' " + whereSql.toString() + ") aa " + tableSql;
                    map = jdbcTemplate.queryForMap(sql);
                    JSONObject obj = new JSONObject();
                    obj.put("code", one.getCode());
                    obj.put("name", one.getName());
                    obj.put("num", (Long) map.get("num"));
                    re.add(obj);
                }
                break;
            }
            case "3": {
                sql = "select label_code code, label_name name from wlyy_sign_patient_label  where label_type=3 and status=1";
                returnList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DictModel.class));
                for (DictModel one : returnList) {
//                    sql =" select count(DISTINCT(w.patient)) as num from wlyy_sign_family w "+
//                            " left join wlyy_sign_patient_label_info l on w.patient=l.patient "+
//                            " left join wlyy_patient p on p.code=w.patient "+
//                            " where w.status>0 and p.town='350211'  and l.status=1 and l.label_type = 3 AND l.label ="+one.getCode();
                    sql = " select count(DISTINCT(aa.patient)) as num from ( " +
                            " SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
                            " FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l " +
                            " WHERE w. STATUS > 0 and l.status=1 AND  w.team_code="+teamCode+" AND w.patient = l.patient AND LEFT (w.hospital, 6) = '350211' ) a " +
                            " GROUP BY a.patient HAVING tt LIKE '%3" + one.getCode() + "%' " + whereSql.toString() + ") aa " + tableSql;
                    map = jdbcTemplate.queryForMap(sql);
                    JSONObject obj = new JSONObject();
                    obj.put("code", one.getCode());
                    obj.put("name", one.getName());
                    obj.put("num", (Long) map.get("num"));
                    re.add(obj);
                }
                break;
            }
            case "4": {
                sql = "select label_code code, label_name name from wlyy_sign_patient_label  where label_type=4 and status=1";
                returnList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DictModel.class));
                for (DictModel one : returnList) {
//                    sql =" select count(DISTINCT(w.patient)) as num from wlyy_sign_family w "+
//                            " left join wlyy_sign_patient_label_info l on w.patient=l.patient "+
//                            " left join wlyy_patient p on p.code=w.patient "+
//                            " where w.status>0 and p.town='350211'  and l.status=1 and l.label_type = 4 AND l.label ='"+one.getCode()+"'";
                    sql = " select count(DISTINCT(aa.patient)) as num from ( " +
                            " SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
                            " FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l " +
                            " WHERE w. STATUS > 0 and l.status=1 AND  w.team_code="+teamCode+" AND w.patient = l.patient AND LEFT (w.hospital, 6) = '350211' ) a " +
                            " GROUP BY a.patient HAVING tt LIKE '%4" + one.getCode() + "%' " + whereSql.toString() + ") aa " + tableSql;
                    map = jdbcTemplate.queryForMap(sql);
                    JSONObject obj = new JSONObject();
                    obj.put("code", one.getCode());
                    obj.put("name", one.getName());
                    obj.put("num", (Long) map.get("num"));
                    re.add(obj);
                }
                break;
            }
@ -408,7 +503,7 @@ public class HealthEducationArticleService extends BaseService{
        return re;
    }
    public JSONArray pushArticleLogs(int page, int pagesize,String patientCode)throws Exception{
    public JSONArray pushArticleLogs(int page, int pagesize, String patientCode) throws Exception {
        pagesize = page * pagesize;
        page = (page - 1) * pagesize;
@ -416,11 +511,12 @@ public class HealthEducationArticleService extends BaseService{
//        StringBuffer sql2 = new StringBuffer("select *  from   " + esType +
//                " where  sendCode='" + sendCode + "' ");
//        sql2.append("  order by createTime limit " + page + "," + pagesize);
        String sql = "SELECT * FROM "+esType+"  where nested(patients.code)= '"+patientCode+"' order by createTime desc limit "+ page + "," + pagesize;
        String sql = "SELECT * FROM " + esType + "  where nested(patients.code)= '" + patientCode + "' order by createTime desc limit " + page + "," + pagesize;
        List<com.yihu.es.entity.HealthEduArticlePatient> esList = elasticsearchUtil.excute(sql, com.yihu.es.entity.HealthEduArticlePatient.class, esIndex, esType);
        HealthEduArticlePatientModel heapm = null;
        com.alibaba.fastjson.JSONObject article = null;
        List<HealthEduArticlePatientModel> result = new ArrayList<>();
        Doctor doctor = null;
        for (HealthEduArticlePatient one : esList) {
            article = healthEducationArticleService.getArticalById(one.getArticleId());
            heapm = new HealthEduArticlePatientModel();
@ -440,6 +536,9 @@ public class HealthEducationArticleService extends BaseService{
            heapm.setPointNumber(Integer.valueOf(article.getString("pointNumber")));//文章点赞数
            heapm.setArticleCover(article.getString("articleCover"));//封面
            heapm.setComputeTime(computeTime(article.getString("insertTime")));
            heapm.setOperatorName(article.getString("operatorName"));
            doctor = doctorDao.findByCode(one.getDoctorCode());
            heapm.setPhoto(doctor.getPhoto());
            result.add(heapm);
            // heapm.setTime();//时间  xx小时前  2017-10-11
        }
@ -449,8 +548,7 @@ public class HealthEducationArticleService extends BaseService{
    }
    public  String computeTime(String create) {
    public String computeTime(String create) {
        Date createDate = DateUtil.strToDate(create, "yyyy-MM-dd HH:mm:ss.SSS");
        Date nowDate = new Date();
        //计算2个时间差
@ -459,15 +557,171 @@ public class HealthEducationArticleService extends BaseService{
        long hour = l / (60 * 60 * 1000); //小时
        long min = l / (60 * 1000);//分钟
        long s = l / 1000;//秒
        if(s<60){
            return s+"秒前";
        if (s < 60) {
            return s + "秒前";
        }
        if (min < 60) {
            return min + "分钟前";
        }
        if (hour < 24) {
            return hour + "小时前";
        }
        return DateUtil.dateToStr(createDate, "yyyy-MM-dd");
    }
    public JSONObject pushArticleConfirm(String articleId,String labelType, String condition, String groupType,String teamCode) throws Exception{
        JSONObject article = healthEducationArticleService.getArticalById(articleId);
        Set<String> patientSet = new HashSet<>();
        initPatient(patientSet,labelType,condition,groupType,teamCode);
        long num = patientSet.size();
        JSONObject result = new JSONObject();
        result.put("num", num);
        result.put("articleTitle", article.getString("articleTitle"));
        return result;
    }
    public void initPatient(Set<String> patientSet, String labelType, String condition, String groupType,String teamCode) {
        String[] cond = {};
        String[] group = {};
        if (!StringUtils.isEmpty(condition)) {
            cond = condition.split(",");
        }
        if(min<60){
            return min+"分钟前";
        StringBuilder whereSql = new StringBuilder();
        String tableSql = "";
        for (String one : cond) {
            if ("1".equals(one)) {//有绑定设备
                tableSql = " LEFT JOIN wlyy_patient_device d on d.user=aa.patient and d.device_id is not null ";
            } else if ("2".equals(one)) {//孕产妇
//                temp.add("41");
                whereSql.append(" and tt LIKE '%41%' ");
            } else if ("3".equals(one)) {//65岁以上老年人
//                temp.add("13");
                whereSql.append(" and tt LIKE '%13%' ");
            }
        }
        if(hour<24){
            return hour+"小时前";
        if (!StringUtils.isEmpty(groupType)) {
            group = groupType.split(",");
        }
        return DateUtil.dateToStr(createDate,"yyyy-MM-dd");
        StringBuilder whereSql2 = new StringBuilder();
//        for (String one : group) {
//            whereSql2.append(" and tt LIKE '%" + labelType + one + "%' ");
//        }
//        String whereSql2Str = whereSql2.toString().substring(3);
        String sql = "";
        Map<String, Object> map = null;
        List<String> groupPatient = null;
        List<String> resultList = new ArrayList<>();
        switch (labelType) {
            case "1": {
//                sql = "select s.code code,s.name name from wlyy_sign_dict s where s.year='2017' order by s.sort asc";
//                returnList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DictModel.class));
//                for(DictModel one:returnList){
//                    sql = "select count(DISTINCT(w.patient)) as num from wlyy_sign_family w "+
//                            " left join wlyy_sign_family_server s on w.code= s.sign_code "+
//                            " left join wlyy_patient p on p.code=w.patient "+
//                            " where w.status>0 and p.town='350211' ";
//                    sql +=" and s.server_type='"+one.getCode()+"'";
                for (String one : group) {
                    sql = " SELECT DISTINCT(aa.patient)  FROM " +
                            " ( SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
                            " FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l, " +
                            " wlyy_sign_family_server q WHERE w. STATUS > 0 AND l. STATUS = 1 AND w.team_code=" +teamCode+
                            " AND w.patient = l.patient AND LEFT (w.hospital, 6) = '350211' " +
                            " AND w. CODE = q.sign_code AND q.server_type = 1 ) a " +
                            " GROUP BY a.patient HAVING 1 = 1  " + whereSql +  " and tt LIKE '%" + labelType + one + "%'  ) aa " + tableSql;
                    groupPatient = jdbcTemplate.queryForList(sql, String.class);
//                    JSONObject obj = new JSONObject();
//                    obj.put("code",one.getCode());
//                    obj.put("name",one.getName());
//                    obj.put("num",(Long)map.get("num"));
//                    re.add(obj);
//                }
                    resultList.addAll(groupPatient);
                }
                break;
            }
            case "2": {
//                sql = "select label_code code, label_name name from wlyy_sign_patient_label  where label_type=2 and status=1";
//                returnList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DictModel.class));
//                for(DictModel one:returnList){
//                    sql =" select count(DISTINCT(w.patient)) as num from wlyy_sign_family w "+
//                            " left join wlyy_sign_patient_label_info l on w.patient=l.patient "+
//                            " left join wlyy_patient p on p.code=w.patient "+
//                            " where w.status>0 and p.town='350211' and l.status=1 and l.label_type = 2 AND l.label ="+one.getCode();
                for (String one : group) {
                    sql = " select DISTINCT(aa.patient) from ( " +
                            " SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
                            " FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l " +
                            " WHERE w. STATUS > 0 and l.status=1 AND w.team_code="+teamCode+" AND w.patient = l.patient AND LEFT (w.hospital, 6) = '350211' ) a " +
                            " GROUP BY a.patient HAVING 1=1 " + whereSql + "  and tt LIKE '%" + labelType + one + "%' ) aa " + tableSql;
//                    map = jdbcTemplate.queryForMap(sql);
//                JSONObject obj = new JSONObject();
//                obj.put("code",one.getCode());
//                obj.put("name",one.getName());
//                obj.put("num",(Long)map.get("num"));
//                re.add(obj);
                    groupPatient = jdbcTemplate.queryForList(sql, String.class);
                    resultList.addAll(groupPatient);
//                }
                }
                break;
            }
            case "3": {
//                sql = "select label_code code, label_name name from wlyy_sign_patient_label  where label_type=3 and status=1";
//                returnList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DictModel.class));
//                for(DictModel one:returnList){
//                    sql =" select count(DISTINCT(w.patient)) as num from wlyy_sign_family w "+
//                            " left join wlyy_sign_patient_label_info l on w.patient=l.patient "+
//                            " left join wlyy_patient p on p.code=w.patient "+
//                            " where w.status>0 and p.town='350211'  and l.status=1 and l.label_type = 3 AND l.label ="+one.getCode();
                for (String one : group) {
                    sql = " select DISTINCT(aa.patient)  from ( " +
                            " SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
                            " FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l " +
                            " WHERE w. STATUS > 0 and l.status=1 AND w.team_code="+teamCode+" AND w.patient = l.patient AND LEFT (w.hospital, 6) = '350211' ) a " +
                            " GROUP BY a.patient HAVING 1=1 " + whereSql + " and tt LIKE '%" + labelType + one + "%') aa " + tableSql;
//                    map = jdbcTemplate.queryForMap(sql);
//                    JSONObject obj = new JSONObject();
//                    obj.put("code",one.getCode());
//                    obj.put("name",one.getName());
//                    obj.put("num",(Long)map.get("num"));
//                    re.add(obj);
                    groupPatient = jdbcTemplate.queryForList(sql, String.class);
                    resultList.addAll(groupPatient);
//                }
                }
                break;
            }
            case "4": {
//                sql = "select label_code code, label_name name from wlyy_sign_patient_label  where label_type=4 and status=1";
//                returnList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DictModel.class));
//                for(DictModel one:returnList){
//                    sql =" select count(DISTINCT(w.patient)) as num from wlyy_sign_family w "+
//                            " left join wlyy_sign_patient_label_info l on w.patient=l.patient "+
//                            " left join wlyy_patient p on p.code=w.patient "+
//                            " where w.status>0 and p.town='350211'  and l.status=1 and l.label_type = 4 AND l.label ='"+one.getCode()+"'";
                for (String one : group) {
                    sql = " select DISTINCT(aa.patient) from ( " +
                            " SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
                            " FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l " +
                            " WHERE w. STATUS > 0 and l.status=1 AND w.team_code="+teamCode+" AND w.patient = l.patient AND LEFT (w.hospital, 6) = '350211' ) a " +
                            " GROUP BY a.patient HAVING 1=1 " + whereSql.toString() + " and tt LIKE '%" + labelType + one + "%') aa " + tableSql;
//                    map = jdbcTemplate.queryForMap(sql);
//                    JSONObject obj = new JSONObject();
//                    obj.put("code",one.getCode());
//                    obj.put("name",one.getName());
//                    obj.put("num",(Long)map.get("num"));
//                    re.add(obj);
                    groupPatient = jdbcTemplate.queryForList(sql, String.class);
                    resultList.addAll(groupPatient);
//                }
                }
                break;
            }
        }
        patientSet.addAll(resultList);
    }
}

+ 80 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthEduArticleController.java

@ -1,8 +1,10 @@
package com.yihu.wlyy.web.doctor.health;
import com.yihu.es.entity.*;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.education.*;
import com.yihu.wlyy.entity.education.HealthEduArticlePatient;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.event.ApplicationEvent;
@ -36,11 +38,18 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
import java.util.*;
/**
@ -90,6 +99,10 @@ public class DoctorHealthEduArticleController extends WeixinBaseController {
    private HealthEducationArticleService healthEducationArticleService;
    @Autowired
    private GcEduArticleService gcEduArticleService;
    @Autowired
    private JmsTemplate jmsTemplate;
    @Value("${activemq.queue.healtHarticleQueue}")
    private String channelName;
    /**
     * 查询
     *
@ -766,7 +779,7 @@ public class DoctorHealthEduArticleController extends WeixinBaseController {
    @RequestMapping(value = "logs", method = RequestMethod.GET)
    @ApiOperation("查询医生给患者推送记录 ")
    public ResultPageListModel<HealthEduArticlePatientModel> getPatientHealthLogs(
            @ApiParam(name = "articleType", value = "文章类别", required = false) @RequestParam(value = "articleType", required = false) String articleType,
            @ApiParam(name = "firstLevelCategoryId", value = "文章1级类别", required = false) @RequestParam(value = "firstLevelCategoryId", required = false) String firstLevelCategoryId,
//            @ApiParam(name = "level1Type", value = "一级分类", required = false) @RequestParam(value = "level1Type", required = false) String level1Type,
//            @ApiParam(name = "level2Type", value = "二级分类", required = false) @RequestParam(value = "level2Type", required = false) String level2Type,
//            @ApiParam(name = "level", value = "等级", required = false) @RequestParam(value = "level", required = false) String level,
@ -781,7 +794,7 @@ public class DoctorHealthEduArticleController extends WeixinBaseController {
            if (pagesize > 1000) {
                pagesize = 1000;
            }
            List<HealthEduArticlePatientModel> eduArticlePatients = gcEduArticleService.pushArticleLogs(page,pagesize,getUID(),2);
            List<HealthEduArticlePatientModel> eduArticlePatients = gcEduArticleService.pushArticleLogs(page,pagesize,getUID(),2,firstLevelCategoryId);
            Long count = gcEduArticleService.pushArticleLogsCount(getUID(),2);
            return new ResultPageListModel(
                    page,
@ -796,11 +809,13 @@ public class DoctorHealthEduArticleController extends WeixinBaseController {
    @RequestMapping(value = "labelWithPushPatients", method = RequestMethod.GET)
    @ApiOperation("查询推送对象 ")
    public String labelWithPushPatients(
            @ApiParam(name = "labelType", value = "1:服务类型(卫计委分组) 2:健康情况 3:疾病类型 4:团队标签(自定义标签)", required = true) @RequestParam(value = "labelType", required = true) String labelType){
            @ApiParam(name = "teamCode", value = "团队code", required = true) @RequestParam(value = "teamCode", required = true) String teamCode,
            @ApiParam(name = "labelType", value = "1:服务类型(卫计委分组) 2:健康情况 3:疾病类型 4:团队标签(自定义标签)", required = true) @RequestParam(value = "labelType", required = true) String labelType,
            @ApiParam(name = "codition", value = "多个筛选条件以逗号分割", required = false) @RequestParam(value = "codition", required = false) String codition){
        try {
            com.alibaba.fastjson.JSONArray response = healthEducationArticleService.labelWithPushPatients(labelType);
            com.alibaba.fastjson.JSONArray response = healthEducationArticleService.labelWithPushPatients(labelType,codition,teamCode);
//            Long count = healthEducationArticleService.pushArticleLogsCount("ece5c665b16542b0847e52b4a9fee44a");
            return write(200,"查询成功!","data",response);
        }catch (Exception e) {
@ -808,4 +823,65 @@ public class DoctorHealthEduArticleController extends WeixinBaseController {
            return error(-1,"查询失败!");
        }
    }
    @ApiOperation("确认推送人数")
    @RequestMapping(value = "pushArticleConfirm",method = RequestMethod.GET)
    public String pushArticleConfirm(
            @ApiParam(name = "teamCode", value = "团队code", required = true) @RequestParam(value = "teamCode", required = true) String teamCode,
            @ApiParam(name = "labelType", value = "1:服务类型(卫计委分组) 2:健康情况 3:疾病类型 4:团队标签(自定义标签)", required = true) @RequestParam(value = "labelType", required = true) String labelType,
            @ApiParam(name = "condition", value = "多个筛选条件以逗号分割", required = false) @RequestParam(value = "condition", required = false) String condition,
            @ApiParam(name = "groupType", value = "多个分组以逗号分割", required = false) @RequestParam(value = "groupType", required = false) String groupType,
            @ApiParam(name = "articleId", value = "文章ID", required = true) @RequestParam(value = "articleId", required = true) String articleId){
        try {
            com.alibaba.fastjson.JSONObject response = healthEducationArticleService.pushArticleConfirm(articleId,labelType,condition,groupType,teamCode);
            return write(200,"查询成功!","data",response);
        }catch (Exception e) {
            e.printStackTrace();
            return error(-1,"查询失败!");
        }
    }
    @RequestMapping(value = "sendArticleToPatients", method = RequestMethod.POST)
    @ApiOperation("文章群推送")
    public BaseResultModel sendArticleToPatients(
            @ApiParam(name = "teamCode", value = "团队code", required = true) @RequestParam(value = "teamCode", required = true) String teamCode,
            @ApiParam(name = "labelType", value = "1:服务类型(卫计委分组) 2:健康情况 3:疾病类型 4:团队标签(自定义标签)", required = true) @RequestParam(value = "labelType", required = true) String labelType,
            @ApiParam(name = "condition", value = "多个筛选条件以逗号分割", required = false) @RequestParam(value = "condition", required = false) String condition,
            @ApiParam(name = "groupType", value = "多个分组以逗号分割", required = false) @RequestParam(value = "groupType", required = false) String groupType,
            @ApiParam(name = "articleId", value = "文章ID", required = true) @RequestParam(value = "articleId", required = true) String articleId,
            @ApiParam(name = "sendName", value = "发送方名称(如:医生发送:医生名称)", required = true) @RequestParam(value = "sendName", required = true) String sendName){
        try {
            Set<String> patientSet = new HashSet<>(); //放入set中可以去重复
            //得到需要发送的患者
            healthEducationArticleService.initPatient(patientSet, labelType, condition, groupType,teamCode);
            com.yihu.es.entity.HealthEduArticlePatient healthEduArticlePatient = gcEduArticleService.getSaveArticle(patientSet, getUID(), sendName, 1, "", 0L, articleId);
            //推送微信模板消息和发送im消息
            new Thread(() -> {
                //发送任务到redis
                sender(healthEduArticlePatient);
            }).start();
            return new BaseResultModel();
        }catch (Exception e) {
            return new BaseResultModel(BaseResultModel.statusEm.opera_error.getCode(), BaseResultModel.statusEm.opera_error.getMessage() + ":" + e.getMessage());
        }
    }
    /**
     * 发送到redis
     *
     */
    public void sender(com.yihu.es.entity.HealthEduArticlePatient healthEduArticlePatient) {
        //送到到队列
        List<Patient> patients = healthEduArticlePatient.getPatients();
        patients.stream().forEach(one -> {
            healthEduArticlePatient.setPatient(one.getCode());
            jmsTemplate.send(channelName, new MessageCreator() {
                @Override
                public Message createMessage(Session session) throws JMSException {
                    TextMessage textMessage = session.createTextMessage();
                    textMessage.setText(net.sf.json.JSONObject.fromObject(healthEduArticlePatient).toString());
                    return textMessage;
                }
            });
        });
    }
}

+ 3 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcEduArticleController.java

@ -152,6 +152,7 @@ public class GcEduArticleController extends WeixinBaseController {
        List<Patient> patients = healthEduArticlePatient.getPatients();
        patients.stream().forEach(one -> {
            healthEduArticlePatient.setPatient(one.getCode());
            healthEduArticlePatient.setPatients(null);
            jmsTemplate.send(channelName, new MessageCreator() {
                @Override
                public Message createMessage(Session session) throws JMSException {
@ -200,13 +201,14 @@ public class GcEduArticleController extends WeixinBaseController {
    @RequestMapping(value = "pushArticleLogs", method = RequestMethod.GET)
    @ApiOperation("查询卫计委给患者推送记录 ")
    public ResultPageListModel<HealthEduArticlePatientModel> pushArticleLogs(
            @ApiParam(name = "firstLevelCategoryId", value = "文章所属一级类别ID", required = false) @RequestParam(value = "firstLevelCategoryId", required = false) String firstLevelCategoryId,
            @ApiParam(name = "page", value = "当前页 起始1", required = true) @RequestParam(value = "page", required = true) Integer page,
            @ApiParam(name = "pagesize", value = "每页显示条数", required = true) @RequestParam(value = "pagesize", required = true) Integer pagesize){
        try {
            if (pagesize > 1000) {
                pagesize = 1000;
            }
            List<HealthEduArticlePatientModel> eduArticlePatients = gcEduArticleService.pushArticleLogs(page,pagesize,getUID(),1);
            List<HealthEduArticlePatientModel> eduArticlePatients = gcEduArticleService.pushArticleLogs(page,pagesize,getUID(),1,firstLevelCategoryId);
            Long count = gcEduArticleService.pushArticleLogsCount(getUID(),1);
            return new ResultPageListModel(
                    page,

+ 13 - 8
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/service/GcEduArticleService.java

@ -224,17 +224,18 @@ public class GcEduArticleService {
        HealthEduArticlePatient healthEduArticlePatient = new HealthEduArticlePatient();
        //1、医生,2、卫计委
        //如果是卫计委得区别角色
        Doctor doctor = null;
        Doctor doctor = doctorDao.findByCode(sendCode);
        if (sendType == 2) {
            String sql = "select r.code as roleCode from wlyy_user_role u " +
                    "left join wlyy_role r on r.`code`=u.role where u.user='" + sendCode + "'";
                    "left join wlyy_role r on r.`code`=u.role where u.user='" + sendCode + "' and LENGTH(u.role)=6";
            Map<String, Object> result = jdbcTemplate.queryForMap(sql);
            //角色的code值
            healthEduArticlePatient.setSendCode(result.get("roleCode") + "");
        } else {
            doctor = doctorDao.findByCode(sendCode);
            healthEduArticlePatient.setSendCode(sendCode);
        }
        healthEduArticlePatient.setDoctorCode(sendCode);
        healthEduArticlePatient.setDoctorName(doctor.getName());
        healthEduArticlePatient.setSendName(sendName);
        healthEduArticlePatient.setSendType(sendType);
        healthEduArticlePatient.setAdminTeamCode(teamId);
@ -250,6 +251,7 @@ public class GcEduArticleService {
        healthEduArticlePatient.setBatchNo(batchNo);
        healthEduArticlePatient.setCreateTime(new Date());
        //通过文章id 获取文章详情
        JSONObject article = healthEducationArticleService.getArticalById(articleId);
@ -263,7 +265,7 @@ public class GcEduArticleService {
        healthEduArticlePatient.setLevel1Type(article.get("firstLevelCategoryId") + "");
        healthEduArticlePatient.setLevel2Type(article.get("secondLevelCategoryId") + "");
        healthEduArticlePatient.setType("1");//文章
        healthEduArticlePatient.setArticleUrl(articleBaseUrl+"/web/jkEdu/articleDetail.html?behavior=4&articleId="+articleId);
        healthEduArticlePatient.setArticleUrl(articleBaseUrl+"JkEduWeb/web/jkEdu/articleDetail.html?behavior=4&articleId="+articleId);
        healthEduArticlePatient.setPatients(patientList);
        //保存到ES中
@ -497,19 +499,22 @@ public class GcEduArticleService {
     * @return
     * @throws Exception
     */
    public List<HealthEduArticlePatientModel> pushArticleLogs(int page, int pagesize, String sendCode,int sendType) throws Exception {
    public List<HealthEduArticlePatientModel> pushArticleLogs(int page, int pagesize, String sendCode,int sendType,String firstLevelCategoryId) throws Exception {
        pagesize = page * pagesize;
        page = (page - 1) * pagesize;
        if(sendType==1){
            String sql = "select r.code as roleCode from wlyy_user_role u " +
                    "left join wlyy_role r on r.`code`=u.role where u.user='" + sendCode + "'";
                    "left join wlyy_role r on r.`code`=u.role where u.user='" + sendCode + "' and LENGTH(u.role)=6";
            Map<String, Object> resultMap = jdbcTemplate.queryForMap(sql);
            sendCode = resultMap.get("roleCode").toString();
        }
        StringBuffer sql2 = new StringBuffer("select *  from   " + esType +
                " where  sendCode='" + sendCode + "' ");
                " where  sendCode='" + sendCode + "'");
        if(!StringUtils.isEmpty(firstLevelCategoryId)){
            sql2.append("and level1Type="+firstLevelCategoryId);
        }
        sql2.append("  order by createTime limit " + page + "," + pagesize);
        List<com.yihu.es.entity.HealthEduArticlePatient> esList = elasticsearchUtil.excute(sql2.toString(), com.yihu.es.entity.HealthEduArticlePatient.class, esIndex, esType);
        Map<String, HealthEduArticlePatientModel> result = new HashMap<>();
@ -586,7 +591,7 @@ public class GcEduArticleService {
        if(sendType==1){
            String sql = "select r.code as roleCode from wlyy_user_role u " +
                    "left join wlyy_role r on r.`code`=u.role where u.user='" + sendCode + "'";
                    "left join wlyy_role r on r.`code`=u.role where u.user='" + sendCode + "'"+ " and LENGTH(u.role)=6";;
            Map<String, Object> resultMap = jdbcTemplate.queryForMap(sql);
            sendCode = resultMap.get("roleCode").toString();

+ 18 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/vo/HealthEduArticlePatientModel.java

@ -47,6 +47,8 @@ public class HealthEduArticlePatientModel {
    private String articleCover="";//封面图
    private String computeTime;//时间
    private String photo;//医生头像
    private String operatorName;//文章作者
    public String getSendCode() {
        return sendCode;
@ -175,4 +177,20 @@ public class HealthEduArticlePatientModel {
    public void setComputeTime(String computeTime) {
        this.computeTime = computeTime;
    }
    public String getPhoto() {
        return photo;
    }
    public void setPhoto(String photo) {
        this.photo = photo;
    }
    public String getOperatorName() {
        return operatorName;
    }
    public void setOperatorName(String operatorName) {
        this.operatorName = operatorName;
    }
}

+ 1 - 1
patient-co/patient-co-wlyy/src/main/resources/application-dev.yml

@ -113,7 +113,7 @@ es:
#集美宣教居民端健康文章
jkEdu:
  web:
    articleBaseUrl: http://172.19.103.87:9088/jkeduweb
    articleBaseUrl: http://172.19.103.87:9088/
#消息队列
activemq:

+ 3 - 3
patient-co/patient-co-wlyy/src/main/resources/application-devtest.yml

@ -97,11 +97,11 @@ pushMes:
  redis_prescription_title: redisPrescription
es:
  index:
    HealthEduArticlePatient: health_edu_article_patient_test2
    HealthEduArticlePatient: health_edu_article_patient_test3
    FollowUp: wlyy_followup
    Statistics: wlyy_quota_test
  type:
    HealthEduArticlePatient: health_edu_article_patient_test2
    HealthEduArticlePatient: health_edu_article_patient_test3
    FollowUpContent: wlyy_followup_content
    Statistics: wlyy_quota_test
  host:  http://172.19.103.68:9200
@ -112,7 +112,7 @@ es:
#http://172.19.103.87:9088/JkEduWeb
jkEdu:
  web:
    articleBaseUrl: http://172.19.103.87:9088/jkeduweb
    articleBaseUrl: http://172.19.103.87:9088/
#消息队列

+ 1 - 1
patient-co/patient-co-wlyy/src/main/resources/application-localtest.yml

@ -110,7 +110,7 @@ es:
#集美宣教居民端健康文章
jkEdu:
  web:
    articleBaseUrl: http://172.19.103.87:9088/jkeduweb
    articleBaseUrl: http://172.19.103.87:9088/
#消息队列
activemq:

+ 3 - 3
patient-co/patient-co-wlyy/src/main/resources/application-test.yml

@ -94,11 +94,11 @@ pushMes:
es:
  index:
    HealthEduArticlePatient: health_edu_article_patient_test
    HealthEduArticlePatient: health_edu_article_patient_test3
    FollowUp: wlyy_followup
    Statistics: wlyy_quota_test
  type:
    HealthEduArticlePatient: health_edu_article_patient_test
    HealthEduArticlePatient: health_edu_article_patient_test3
    FollowUpContent: wlyy_followup_content
    Statistics: wlyy_quota_test
  host:  http://172.19.103.68:9200
@ -108,7 +108,7 @@ es:
#集美宣教居民端健康文章
jkEdu:
  web:
    articleBaseUrl: http://172.19.103.87:9088/jkeduweb
    articleBaseUrl: http://172.19.103.87:9088/
#消息队列
activemq: