Просмотр исходного кода

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

yeshijie 7 лет назад
Родитель
Сommit
10fd265261
20 измененных файлов с 1121 добавлено и 111 удалено
  1. 14 0
      common/common-entity/pom.xml
  2. 234 0
      common/common-entity/src/main/java/com/yihu/es/entity/HealthEduArticlePatient.java
  3. 26 2
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/redis/RedisThread.java
  4. 4 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/task/PushMsgTask.java
  5. 96 0
      patient-co/patient-co-wlyy/doc/技术文档/es/统计新增索引.txt
  6. BIN
      patient-co/patient-co-wlyy/doc/接口文档/对外接口文档/集美健康教育/集美健康教育对外接口文档.docx
  7. 6 0
      patient-co/patient-co-wlyy/pom.xml
  8. 94 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/config/es/ElasticFactory.java
  9. 52 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/config/es/ElastricSearchSave.java
  10. 3 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/HealthEduArticlePatientService.java
  11. 1 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/HealthEduArticleService.java
  12. 5 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java
  13. 201 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ElasticsearchUtil.java
  14. 4 4
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcDoctorController.java
  15. 48 51
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcEduArticleController.java
  16. 157 45
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/service/GcEduArticleService.java
  17. 128 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/vo/HealthEduArticlePatientModel.java
  18. 45 1
      patient-co/patient-co-wlyy/src/main/resources/application.yml
  19. 2 2
      patient-co/patient-co-wlyy/src/main/resources/logback.xml
  20. 1 1
      pom.xml

+ 14 - 0
common/common-entity/pom.xml

@ -45,5 +45,19 @@
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
        </dependency>
        <dependency>
            <groupId>io.searchbox</groupId>
            <artifactId>jest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
            <version>1.11.4.RELEASE</version>
        </dependency>
    </dependencies>
</project>

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

@ -0,0 +1,234 @@
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 chenweida on 2017/9/7.
 */
public class HealthEduArticlePatient {
    @JestId
    private String id;
    private String patient; // 患者标识
    private String patientName;    // 患者标识
    private String sendCode;   // 发送人code
    private String sendName;   // 发送人名称
    private Integer sendType;//发送类型 1医生发送 2卫纪委发送
    private Long adminTeamCode;// 行政团队
    private String adminTeamName;// 行政团队
    private String hospital; // 所属机构
    private String hospitalName; // 所属机构
    private String town; // 所属区划
    private String townName; // 所属区划
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyyMMdd'T'HHmmss.SSS'Z'")
    @CreatedDate
    private Date createTime;  // 创建时间
    private String batchNo;//批次号记录发送所属批次
    private String articleId;  //文章id
    private String attachedTitle;  //文章标题
    private String attachedPic;//文章封面
    private String attachedContent; //文章内容
    private String attachedMessage; //文章附加文件
    private String articleType;//文章类别
    private String level1Type;//1级类别
    private String level2Type;//2级类别
    private String level;//等级
    private Integer allCount;//所有的推送数目
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    public String getPatientName() {
        return patientName;
    }
    public void setPatientName(String patientName) {
        this.patientName = patientName;
    }
    public String getSendCode() {
        return sendCode;
    }
    public void setSendCode(String sendCode) {
        this.sendCode = sendCode;
    }
    public String getSendName() {
        return sendName;
    }
    public void setSendName(String sendName) {
        this.sendName = sendName;
    }
    public Integer getSendType() {
        return sendType;
    }
    public void setSendType(Integer sendType) {
        this.sendType = sendType;
    }
    public Long getAdminTeamCode() {
        return adminTeamCode;
    }
    public void setAdminTeamCode(Long adminTeamCode) {
        this.adminTeamCode = adminTeamCode;
    }
    public String getHospital() {
        return hospital;
    }
    public void setHospital(String hospital) {
        this.hospital = hospital;
    }
    public String getTown() {
        return town;
    }
    public void setTown(String town) {
        this.town = town;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getBatchNo() {
        return batchNo;
    }
    public void setBatchNo(String batchNo) {
        this.batchNo = batchNo;
    }
    public String getArticleId() {
        return articleId;
    }
    public void setArticleId(String articleId) {
        this.articleId = articleId;
    }
    public String getAttachedTitle() {
        return attachedTitle;
    }
    public void setAttachedTitle(String attachedTitle) {
        this.attachedTitle = attachedTitle;
    }
    public String getAttachedPic() {
        return attachedPic;
    }
    public void setAttachedPic(String attachedPic) {
        this.attachedPic = attachedPic;
    }
    public String getAttachedContent() {
        return attachedContent;
    }
    public void setAttachedContent(String attachedContent) {
        this.attachedContent = attachedContent;
    }
    public String getAttachedMessage() {
        return attachedMessage;
    }
    public void setAttachedMessage(String attachedMessage) {
        this.attachedMessage = attachedMessage;
    }
    public String getAdminTeamName() {
        return adminTeamName;
    }
    public void setAdminTeamName(String adminTeamName) {
        this.adminTeamName = adminTeamName;
    }
    public String getHospitalName() {
        return hospitalName;
    }
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
    public String getTownName() {
        return townName;
    }
    public void setTownName(String townName) {
        this.townName = townName;
    }
    public String getArticleType() {
        return articleType;
    }
    public void setArticleType(String articleType) {
        this.articleType = articleType;
    }
    public String getLevel1Type() {
        return level1Type;
    }
    public void setLevel1Type(String level1Type) {
        this.level1Type = level1Type;
    }
    public String getLevel2Type() {
        return level2Type;
    }
    public void setLevel2Type(String level2Type) {
        this.level2Type = level2Type;
    }
    public String getLevel() {
        return level;
    }
    public void setLevel(String level) {
        this.level = level;
    }
    public Integer getAllCount() {
        return allCount;
    }
    public void setAllCount(Integer allCount) {
        this.allCount = allCount;
    }
}

+ 26 - 2
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/redis/RedisThread.java

@ -1,6 +1,8 @@
package com.yihu.wlyy.redis;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.service.app.prescription.PrescriptionService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.SystemConf;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@ -30,7 +32,8 @@ public class RedisThread implements Runnable {
    private StringRedisTemplate redisTemplate;
    @Autowired
    private PrescriptionService prescriptionService;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Override
    public void run() {
@ -55,7 +58,7 @@ public class RedisThread implements Runnable {
                if(StringUtils.isEmpty(message)){
                    Thread.sleep(1000L);//如果没有读取到记录,等待1秒
                }else {
                    prescriptionService.redisMessage(message);
                    redisMessage(message);
                }
            }catch (Exception e){
                e.printStackTrace();
@ -64,4 +67,25 @@ public class RedisThread implements Runnable {
        }
    }
    public void redisMessage(String message){
        logger.info("redis_onMessage...:"+message);
        //this.unsubscribe();
        try{
            JSONObject json = JSONObject.parseObject(message);
            String title =  json.getString("title");
            if("dispensingComplete".equals(title)){//配药完成
                //药品配送完成,提醒取药
                String prescriptionCode = json.getString("prescription");
                prescriptionService.dispensingComplete(prescriptionCode);
            }else if("wechat".equals(title)){
                String data = json.getString("value");
                pushMsgTask.getQueue().put(new org.json.JSONObject(data));
            }else{
            }
        }catch (Exception e){
            logger.error("redis_error...",e);
        }
    }
}

+ 4 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/task/PushMsgTask.java

@ -80,6 +80,10 @@ public class PushMsgTask {
        }
    }
    public static LinkedBlockingQueue<JSONObject> getQueue() {
        return queue;
    }
    /**
     * 添加微信消息
     *

+ 96 - 0
patient-co/patient-co-wlyy/doc/技术文档/es/统计新增索引.txt

@ -0,0 +1,96 @@
创建索引
POST  http://172.19.103.68:9200/health_edu_article_patient_test
查询索引
GET http://172.19.103.68:9200/health_edu_article_patient_test/
给索引加mapping
POST http://172.19.103.68:9200/health_edu_article_patient_test/health_edu_article_patient_test/_mapping
{
    "health_edu_article_patient_test": {
            "properties": {
                "patient": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "patientName": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "doctor": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "doctorName": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "adminTeamCode": {
                    "type": "integer",
                    "index": "not_analyzed"
                },
                "adminTeamName": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "hospital": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "hospitalName": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "town": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "townName": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "batchNo": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "articleId": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "attachedTitle": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "attachedPic": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "attachedContent": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "attachedMessage": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "articleType": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "level1Type": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "level2Type": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "level": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "createTime": {
                    "type": "date",
                    "index": "not_analyzed"
                }
            }
        }
  }

BIN
patient-co/patient-co-wlyy/doc/接口文档/对外接口文档/集美健康教育/集美健康教育对外接口文档.docx


+ 6 - 0
patient-co/patient-co-wlyy/pom.xml

@ -403,6 +403,12 @@
            <groupId>com.ylz</groupId>
            <artifactId>onpay-java-sdk-all</artifactId>
        </dependency>
        <dependency>
            <groupId>org.nlpcn</groupId>
            <artifactId>elasticsearch-sql</artifactId>
            <version>2.4.1.0</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>wlyy</finalName>

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

@ -0,0 +1,94 @@
package com.yihu.wlyy.config.es;
import com.google.common.util.concurrent.MoreExecutors;
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 javax.annotation.PostConstruct;
import java.net.InetAddress;
import java.net.UnknownHostException;
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;
    @Value("${es.port}")
    private String port;
    @Value("${es.tPort}")
    private String tPort;
    @Value("${es.clusterName}")
    private String clusterName;
//-----------------------------------jestClient----------------------------------------
    /**
     * @param "http://localhost:9200"
     * @return
     */
    @PostConstruct
    public JestClient getJestClient() {
        synchronized (ElasticFactory.class) {
            if (factory == null) {
                //初始化链接
                init();
            }
        }
        return factory.getObject();
    }
    /**
     * 初始化链接
     */
    public synchronized void init() {
        // Construct a new Jest client according to configuration via factory
        factory = new JestClientFactory();
        factory.setHttpClientConfig(new HttpClientConfig
                .Builder("http://" + esHost + ":" + port)
                .multiThreaded(true)
                .maxTotalConnection(50)// 最大链接
                .maxConnectionIdleTime(120, TimeUnit.SECONDS)//链接等待时间
                .connTimeout(30000)
                .discoveryEnabled(true)
                .readTimeout(30000)//30秒
                .build());//得到链接
    }
    //-----------------------------------TransportClient----------------------------------------
    private Client transportClient;
    public Client getTransportClient() {
        try {
            initTranClient();
            return transportClient;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    private synchronized void initTranClient() throws UnknownHostException {
        if (transportClient == null) {
            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()
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(esHost), Integer.valueOf(tPort)));
        }
    }
}

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

@ -0,0 +1,52 @@
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 net.sf.json.JSONObject;
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.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.Date;
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) {
        try {
            //得到链接
            JestClient 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());
        }
        return null;
    }
}

+ 3 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/HealthEduArticlePatientService.java

@ -118,7 +118,7 @@ public class HealthEduArticlePatientService extends BaseService {
                "     , wlyy_health_edu_article b" +
                " where" +
                "      a.article = b.code" +
                " and (a.type =1 or a.type is null or a.type = '')"+  //添加类型判断是集美的推送还是三师原来的推送
                " and ( a.send_type =1 or a.send_type is null or a.send_type = '') "+  //添加类型判断是集美的推送还是三师原来的推送
                " and a.patient = ?" +
                (id > 0 ? " and a.id < ? " : "") +
                (wheaType > 0 ? " and a.wheaType = ? " : "") +
@ -161,7 +161,7 @@ public class HealthEduArticlePatientService extends BaseService {
        " wlyy_patient p"+
        " where"+
        " a.article = b.code"+
        " and (a.type =1 or a.type is null or a.type = '')"+  //添加类型判断是集美的推送还是三师原来的推送
        " and ( a.send_type =1 or a.send_type is null or a.send_type = '') "+  //添加类型判断是集美的推送还是三师原来的推送
        " and a.patient = p.code"+
        " and a.doctor =? "+
        " group BY a.batch_no,a.article,a.attached_content,b.summary,a.doctor order by a.czrq desc  limit ?,? ";
@ -185,6 +185,7 @@ public class HealthEduArticlePatientService extends BaseService {
                " where"+
                " a.article = b.code"+
                " and a.patient = p.code"+
                " and ( a.send_type =1 or a.send_type is null or a.send_type = '') "+  //添加类型判断是集美的推送还是三师原来的推送
                " and a.doctor =? "+
                " and a.article =? "+
                (StringUtils.isNotBlank(batchNo)?" and a.batch_no =? ":"and a.batch_no is null ")+

+ 1 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/HealthEduArticleService.java

@ -249,6 +249,7 @@ public class HealthEduArticleService extends BaseService {
                "  where" +
                "    a.article = b.code " +
                "    and a.doctor = d.code " +
                "   and ( a.send_type =1 or a.send_type is null or a.send_type = '') "+  //添加类型判断是集美的推送还是三师原来的推送
                "    and a.patient = ?" +
                "    and a.admin_team_code = ?" +
                "  order by a.czrq desc limit " + page*pageSize + "," + pageSize;

+ 5 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -4040,11 +4040,13 @@ public class FamilyContractService extends BaseService {
                "  wlyy_sign_family a ," +
                "  wlyy_patient p ," +
                "WHERE " +
                "  a.admin_team_code =? " +
                " AND a.patient=p.`code` " +
                "  a.patient=p.`code` " +
                " AND a.`status` IN (1, 2) ");
        List params = new ArrayList<>();
        params.add(teamCode);
        if (teamCode!=null&&teamCode>0) {
            sb.append(" AND a.admin_team_code =?  ");
            params.add(teamCode);
        }
        if (!org.springframework.util.StringUtils.isEmpty(patientName)) {
            sb.append(" AND a.`name` LIKE ? ");
            params.add("%" + patientName + "%");

+ 201 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ElasticsearchUtil.java

@ -0,0 +1,201 @@
package com.yihu.wlyy.util;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
import com.alibaba.druid.sql.parser.SQLExprParser;
import com.yihu.wlyy.config.es.ElasticFactory;
import org.elasticsearch.action.search.SearchResponse;
import org.nlpcn.es4sql.domain.Select;
import org.nlpcn.es4sql.jdbc.ObjectResult;
import org.nlpcn.es4sql.jdbc.ObjectResultsExtractor;
import org.nlpcn.es4sql.parse.ElasticSqlExprParser;
import org.nlpcn.es4sql.parse.SqlParser;
import org.nlpcn.es4sql.query.AggregationQueryAction;
import org.nlpcn.es4sql.query.DefaultQueryAction;
import org.nlpcn.es4sql.query.SqlElasticSearchRequestBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by chenweida on 2017/7/17.
 * SELECT town,townName,sum(result1) result1 FROM wlyy_quota_test
 * where quotaCode='1'
 * group by town,townName , date_histogram(field='quotaDate','interval'='week')
 */
@Component
public class ElasticsearchUtil {
    private Logger logger = LoggerFactory.getLogger(ElasticsearchUtil.class);
    @Autowired
    private ElasticFactory elasticFactory;
    public List excute(String sql, Class clazz, String esType, String esIndex) {
        List saveModels = new ArrayList<>();
        try {
            SQLExprParser parser = new ElasticSqlExprParser(sql);
            SQLExpr expr = parser.expr();
            SQLQueryExpr queryExpr = (SQLQueryExpr) expr;
            Select select = null;
            select = new SqlParser().parseSelect(queryExpr);
            //通过抽象语法树,封装成自定义的Select,包含了select、from、where group、limit等
            AggregationQueryAction action = null;
            DefaultQueryAction queryAction = null;
            SqlElasticSearchRequestBuilder requestBuilder = null;
            if (select.isAgg) {
                //包含计算的的排序分组的
                action = new AggregationQueryAction(elasticFactory.getTransportClient(), select);
                requestBuilder = action.explain();
            } else {
                //封装成自己的Select对象
                queryAction = new DefaultQueryAction(elasticFactory.getTransportClient(), select);
                requestBuilder = queryAction.explain();
            }
            SearchResponse response = (SearchResponse) requestBuilder.get();
            ObjectResult temp = new ObjectResultsExtractor(true, true, true).extractResults(response.getAggregations(), true);
            List<String> heads = temp.getHeaders();
            temp.getLines().stream().forEach(one -> {
                Object saveModel = null;
                try {
                    saveModel = clazz.newInstance();
                } catch (Exception e) {
                    logger.error(e.getMessage());
                }
                for (int i = 0; i < one.size(); i++) {
                    try {
                        String key = null;
                        Object value = one.get(i);
                        if (heads.get(i).contains("date_histogram")) {
                            key = "setQuotaDate";
                            value = DateUtil.strToDate(String.valueOf(value), "yyyy-MM-dd HH:mm:ss");
                        } else {
                            key = "set" + UpFirstStr(heads.get(i));
                        }
                        if (value instanceof String) {
                            clazz.getMethod(key, String.class).invoke(saveModel, value);
                        } else if (value instanceof Integer) {
                            clazz.getMethod(key, Integer.class).invoke(saveModel, value);
                        } else if (value instanceof Double) {
                            clazz.getMethod(key, Integer.class).invoke(saveModel, ((Double) value).intValue());
                        } else if (value instanceof java.util.Date) {
                            clazz.getMethod(key, java.util.Date.class).invoke(saveModel, value);
                        }
                    } catch (Exception e) {
                        logger.warn(e.getMessage());
                    }
                }
                saveModels.add(saveModel);
            });
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return saveModels;
    }
    public Long excuteForLong(String sql, String esType, String esIndex) {
        try {
            SQLExprParser parser = new ElasticSqlExprParser(sql);
            SQLExpr expr = parser.expr();
            SQLQueryExpr queryExpr = (SQLQueryExpr) expr;
            Select select = null;
            select = new SqlParser().parseSelect(queryExpr);
            //通过抽象语法树,封装成自定义的Select,包含了select、from、where group、limit等
            AggregationQueryAction action = null;
            DefaultQueryAction queryAction = null;
            SqlElasticSearchRequestBuilder requestBuilder = null;
            if (select.isAgg) {
                //包含计算的的排序分组的
                action = new AggregationQueryAction(elasticFactory.getTransportClient(), select);
                requestBuilder = action.explain();
            } else {
                //封装成自己的Select对象
                queryAction = new DefaultQueryAction(elasticFactory.getTransportClient(), select);
                requestBuilder = queryAction.explain();
            }
            SearchResponse response = (SearchResponse) requestBuilder.get();
            ObjectResult temp = new ObjectResultsExtractor(true, true, true).extractResults(response.getAggregations(), true);
            Long Longvalue = ((Double) temp.getLines().get(0).get(1)).longValue();
            return Longvalue;
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return 0L;
    }
    /**
     * 首字母大写
     *
     * @param str
     * @return
     */
    private String UpFirstStr(String str) {
        return str.replaceFirst(str.substring(0, 1), str.substring(0, 1).toUpperCase());
    }
    public Object excuteOneObject(String sql, Class clazz, String esType, String esIndex) {
        try {
            SQLExprParser parser = new ElasticSqlExprParser(sql);
            SQLExpr expr = parser.expr();
            SQLQueryExpr queryExpr = (SQLQueryExpr) expr;
            Select select = null;
            select = new SqlParser().parseSelect(queryExpr);
            //通过抽象语法树,封装成自定义的Select,包含了select、from、where group、limit等
            AggregationQueryAction action = null;
            DefaultQueryAction queryAction = null;
            SqlElasticSearchRequestBuilder requestBuilder = null;
            if (select.isAgg) {
                //包含计算的的排序分组的
                action = new AggregationQueryAction(elasticFactory.getTransportClient(), select);
                requestBuilder = action.explain();
            } else {
                //封装成自己的Select对象
                queryAction = new DefaultQueryAction(elasticFactory.getTransportClient(), select);
                requestBuilder = queryAction.explain();
            }
            SearchResponse response = (SearchResponse) requestBuilder.get();
            ObjectResult temp = new ObjectResultsExtractor(true, true, true).extractResults(response.getHits(), true);
            List<String> heads = temp.getHeaders();
            Object saveModel = clazz.newInstance();
            try {
                for (int i = 0; i < temp.getLines().get(0).size(); i++) {
                    String key = null;
                    Object value = temp.getLines().get(0).get(i);
                    if (heads.get(i).contains("createTime")) {
                        key = "setCreateTime";
                        value = DateUtil.strToDate(String.valueOf(value).replace("+0800","").replace("T"," "), "yyyy-MM-dd HH:mm:ss");
                    } else {
                        key = "set" + UpFirstStr(heads.get(i));
                    }
                    if (value instanceof String) {
                        clazz.getMethod(key, String.class).invoke(saveModel, value);
                    } else if (value instanceof Integer) {
                        clazz.getMethod(key, Integer.class).invoke(saveModel, value);
                    } else if (value instanceof Double) {
                        clazz.getMethod(key, Integer.class).invoke(saveModel, ((Double) value).intValue());
                    } else if (value instanceof java.util.Date) {
                        clazz.getMethod(key, java.util.Date.class).invoke(saveModel, value);
                    }
                }
            } catch (Exception e) {
                logger.warn(e.getMessage());
            }
            return saveModel;
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return null;
    }
}

+ 4 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcDoctorController.java

@ -121,8 +121,8 @@ public class GcDoctorController extends BaseController {
    @RequestMapping(value = "/signPatientsByName", method = RequestMethod.GET)
    @ApiOperation("查找医生所属团队下的某个居民")
    public ResultPageListModel<PatientModel> signPatientsByName(
            @ApiParam(name = "teamCode", value = "所属团队", required = true) @RequestParam(value = "teamCode", required = true) Long teamCode,
            @ApiParam(name = "patientName", value = "患者名称", required = true) @RequestParam(value = "patientName", required = true) String patientName,
            @ApiParam(name = "teamCode", value = "所属团队", required = false) @RequestParam(value = "teamCode", required = false) Long teamCode,
            @ApiParam(name = "patientName", value = "患者名称", required = false) @RequestParam(value = "patientName", required = false) String patientName,
            @ApiParam(name = "page", value = "当前页(1开始)", required = true) @RequestParam(value = "page", required = true, defaultValue = "1") Integer page,
            @ApiParam(name = "pageSize", value = "每页大小", required = true) @RequestParam(value = "pageSize", required = true, defaultValue = "10") Integer pageSize
    ) {
@ -136,8 +136,8 @@ public class GcDoctorController extends BaseController {
                    patientModels.add(patientModel);
                });
            }
           Integer count= familyContractService.signPatientsByNameCount(teamCode, patientName);
            return new ResultPageListModel(page,pageSize,count,patientModels);
            Integer count = familyContractService.signPatientsByNameCount(teamCode, patientName);
            return new ResultPageListModel(page, pageSize, count, patientModels);
        } catch (Exception e) {
            return new ResultPageListModel(BaseResultModel.statusEm.find_error.getCode(), BaseResultModel.statusEm.find_error.getMessage() + "," + e.getMessage());
        }

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

@ -1,20 +1,22 @@
package com.yihu.wlyy.web.third.gateway.controller.doctor;
import com.yihu.wlyy.entity.education.HealthEduArticlePatient;
import com.yihu.wlyy.config.es.ElastricSearchSave;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.service.app.health.HealthEduArticleService;
import com.yihu.wlyy.service.app.label.SignPatientLabelInfoService;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.util.ImUtill;
import com.yihu.wlyy.web.WeixinBaseController;
import com.yihu.wlyy.web.third.gateway.service.GcEduArticleService;
import com.yihu.wlyy.web.third.gateway.vo.HealthEduArticlePatientModel;
import com.yihu.wlyy.web.third.gateway.vo.base.BaseResultModel;
import com.yihu.wlyy.web.third.gateway.vo.base.ResultBatchModel;
import com.yihu.wlyy.web.third.gateway.vo.base.ResultPageListModel;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -23,6 +25,7 @@ import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@ -50,86 +53,80 @@ public class GcEduArticleController extends WeixinBaseController {
    @Autowired
    private ConsultService consultService;
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private SignPatientLabelInfoService signPatientLabelInfoService;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private GcEduArticleService gcEduArticleService;
    /**
     *
     * @param doctorCode
     * @param page
     * @param pagesize
     * @return
     */
    @RequestMapping(value = "logs", method = RequestMethod.POST)
    @RequestMapping(value = "logs", method = RequestMethod.GET)
    @ApiOperation("查询医生给患者推送记录 ")
    @ResponseBody
    public String getPatientHealthLogs(
    public ResultPageListModel<HealthEduArticlePatientModel> getPatientHealthLogs(
            @ApiParam(name = "articleType", value = "文章类别", required = false) @RequestParam(value = "articleType", required = false) String articleType,
            @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,
            @ApiParam(name = "doctorCode", value = "医生code,为空从useragent取", required = false) @RequestParam(value = "doctorCode", required = false) String doctorCode,
            @ApiParam(name = "page", value = "当前页 起始1", required = false) @RequestParam(value = "page", required = false) int page,
            @ApiParam(name = "pagesize", value = "每页显示条数", required = false) @RequestParam(value = "pagesize", required = false) int pagesize) {
            @ApiParam(name = "articleTitle", value = "文章标题", required = false) @RequestParam(value = "articleTitle", required = false) String articleTitle,
            @ApiParam(name = "startTime", value = "开始时间yyyy-Mm-dd", required = false) @RequestParam(value = "startTime", required = false) String startTime,
            @ApiParam(name = "endTime", value = "结束时间yyyy-Mm-dd", required = false) @RequestParam(value = "endTime", required = false) String endTime,
            @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(org.springframework.util.StringUtils.isEmpty(doctorCode)){
                doctorCode=getUID();
            if (org.springframework.util.StringUtils.isEmpty(doctorCode)) {
                doctorCode = getUID();
            }
            //List<Map<String, Object>> result = gcEduArticleService.findByDoctor(doctorCode, page, pagesize);
            return write(200, "查询成功!", "list", "");
            List<HealthEduArticlePatientModel> eduArticlePatients = gcEduArticleService.getPatientHealthLogs(getUID(), articleType, level1Type, level2Type, level, articleTitle, startTime, endTime, page, pagesize);
            Long count = gcEduArticleService.getPatientHealthLogsCount(getUID(), articleType, level1Type, level2Type, level, articleTitle, startTime, endTime);
            return new ResultPageListModel(
                    page,
                    pagesize,
                    count.intValue()
                    , eduArticlePatients);
        } catch (Exception e) {
            return write(-1, "查询失败!");
            return new ResultPageListModel(BaseResultModel.statusEm.find_error.getCode(), BaseResultModel.statusEm.find_error.getMessage() + "," + e.getMessage());
        }
    }
    /**
     * 参考原来的教育文章推送
     * * 参考原来的教育文章推送
     * http://172.19.103.88:9092/wlyy//doctor/health/edu/send?code=2e6467b5bb2f4b81b598633624d7f98e&patient=e911d1b756cd4680ab241ab76a463282&teamCode=1&attachedContent=
     *
     * @param sendCode
     * @param sendName
     * @param sendMessage
     * @param labelCode
     * @param labelType
     * @param teamId
     * @param receiveCodes
     * @param articleIds
     * @param articlePics
     * @param articleTitles
     * @return
     */
    @RequestMapping(value = "send", method = RequestMethod.POST)
    @ApiOperation("文章推送")
    public BaseResultModel send(
            @ApiParam(name = "sendType", value = "发送类型 1医生发送 2卫纪委发送", required = true) @RequestParam(value = "sendType", required = true) String sendType,
            @ApiParam(name = "sendType", value = "发送类型 1医生发送 2卫纪委发送", required = true) @RequestParam(value = "sendType", required = true) Integer sendType,
            @ApiParam(name = "sendCode", value = "发送人code", required = true) @RequestParam(value = "sendCode", required = true) String sendCode,
            @ApiParam(name = "sendName", value = "发送人名", required = true) @RequestParam(value = "sendName", required = true) String sendName,
            @ApiParam(name = "sendMessage", value = "发送人信息", required = false) @RequestParam(value = "sendMessage", required = false) String sendMessage,
            @ApiParam(name = "teamId", value = "发送人是医生的时候,医生所属的团队", required = true) @RequestParam(value = "teamId", required = true) Long teamId,
            @ApiParam(name = "teamId", value = "发送人是医生的时候,医生所属的团队", required = false) @RequestParam(value = "teamId", required = false) Long teamId,
            @ApiParam(name = "labelCode", value = "所选群组,多个用逗号分隔", required = true) @RequestParam(value = "labelCode", required = false, defaultValue = "") String labelCode,
            @ApiParam(name = "labelType", value = "标签类型  1:服务类型(卫计委分组) 2:健康情况 3:疾病类型 4:团队标签(自定义标签)", required = true) @RequestParam(value = "labelType", required = false, defaultValue = "") String labelType,
            @ApiParam(name = "labelType", value = "标签类型  1:服务类型(卫计委分组) 2:健康情况 3:疾病类型 4:团队标签(自定义标签)", required = false) @RequestParam(value = "labelType", required = false, defaultValue = "") String labelType,
            @ApiParam(name = "receiveCodes", value = "接收人code,多个逗号分割", required = false) @RequestParam(value = "receiveCodes", required = false, defaultValue = "") String receiveCodes,
            @ApiParam(name = "unReceiveCodes", value = "不接收人code,多个逗号分割(如果同时存在receiveCodes和unReceiveCodes,也不会发送)", required = false) @RequestParam(value = "unReceiveCodes", required = false, defaultValue = "") String unReceiveCodes,
            @ApiParam(name = "articleIds", value = "文章ID,多个逗号分割", required = true) @RequestParam(value = "articleIds", required = true) String articleIds,
            @ApiParam(name = "articlePics", value = "文章封面,多个逗号分割", required = true) @RequestParam(value = "articlePics", required = true) String articlePics,
            @ApiParam(name = "articleTitles", value = "文章标题,多个逗号分割", required = true) @RequestParam(value = "articleTitles", required = true) String articleTitles
            @ApiParam(name = "articleId", value = "文章ID", required = true) @RequestParam(value = "articleId", required = true) String articleId,
            @ApiParam(name = "articlePic", value = "文章封面", required = true) @RequestParam(value = "articlePic", required = true) String articlePic,
            @ApiParam(name = "articleTitle", value = "文章标题", required = true) @RequestParam(value = "articleTitle", required = true) String articleTitle,
            @ApiParam(name = "articleContent", value = "文章内容", required = true) @RequestParam(value = "articleContent", required = true) String articleContent,
            @ApiParam(name = "articleType", value = "文章类别", required = true) @RequestParam(value = "articleType", required = true) String articleType,
            @ApiParam(name = "level1Type", value = "一级分类", required = true) @RequestParam(value = "level1Type", required = true) String level1Type,
            @ApiParam(name = "level2Type", value = "二级分类", required = true) @RequestParam(value = "level2Type", required = true) String level2Type,
            @ApiParam(name = "level", value = "等级", required = true) @RequestParam(value = "level", required = true) String level
    ) {
        try {
            String[] patients = receiveCodes.split(",");//接收人的code
            String[] unPatients = unReceiveCodes.split(",");//接收人的code
            Set<String> patientSet = new HashSet<>(); //放入set中可以去重复
            String[] articleIdArr = articleIds.split(",");
            String[] articlePicArr = articlePics.split(",");
            String[] articleTitleArr = articleTitles.split(",");
            if ((articleIdArr.length != articlePicArr.length) || (articleIdArr.length != articleTitleArr.length) || (articlePicArr.length != articleTitleArr.length)) {
                return new ResultBatchModel(BaseResultModel.statusEm.opera_error.getCode(), BaseResultModel.statusEm.opera_error.getMessage() + ":文章参数长度错误");
            }
            //得到需要发送的患者
            gcEduArticleService.initPatient(patientSet, patients, unPatients, labelType, labelCode, teamId);
            //保存发送记录
            List<HealthEduArticlePatient> healthEduArticlePatients = gcEduArticleService.saveArticle(patientSet, sendCode, sendName, sendMessage, teamId, articleIdArr, articlePicArr, articleTitleArr);
            List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients = gcEduArticleService.saveArticle(patientSet, sendCode, sendName, sendType, sendMessage, teamId, articleId, articlePic, articleTitle, articleContent, articleType, level1Type, level2Type, level);
            //推送微信模板消息和发送im消息
            sendWxTemplateAndIM(healthEduArticlePatients, sendType);
@ -141,29 +138,29 @@ public class GcEduArticleController extends WeixinBaseController {
        }
    }
    private void sendWxTemplateAndIM(List<HealthEduArticlePatient> healthEduArticlePatients, String sendType) throws Exception {
    private void sendWxTemplateAndIM(List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients, Integer sendType) throws Exception {
        String endMsg = "";//"为了您的健康," + doctor.getName() + "医生给您发送了一篇患教文章,请仔细查阅,如有问题,可随时咨询医生。";
        healthEduArticlePatients.stream().forEach(one -> {
            Patient patient = patientService.findByCode(one.getPatient());
            //卫纪委发送不推IM
            if ("1".equals(sendType)) {
                consultService.sendMucMessageBySingnType(one.getDoctor(), one.getDoctorName(), patient.getCode(), "{\"title\":\"" + one.getAttachedTitle() + "\",\"type\":0,\"id\":\"" + one.getId() + "\",\"img\":\"" + one.getAttachedPic() + "\",\"content\":\"为了您的健康,我给您发送了一篇文章,请咨询查阅,如有问题,可随时与我沟通\"}", "4", patient.getName());
                if (StringUtils.isNotBlank(one.getAttachedContent())) {
            if (1 == sendType) {
                consultService.sendMucMessageBySingnType(one.getSendCode(), one.getSendName(), patient.getCode(), "{\"title\":\"" + one.getAttachedTitle() + "\",\"type\":0,\"id\":\"" + one.getId() + "\",\"img\":\"" + one.getAttachedPic() + "\",\"content\":\"为了您的健康,我给您发送了一篇文章,请咨询查阅,如有问题,可随时与我沟通\"}", "4", patient.getName());
                if (StringUtils.isNotBlank(one.getAttachedMessage())) {
                    //发送备注
                    consultService.sendMucMessageBySingnType(one.getDoctor(), one.getDoctorName(), patient.getCode(), one.getAttachedContent(), ImUtill.CONTENT_TYPE_TEXT, patient.getName());
                    consultService.sendMucMessageBySingnType(one.getSendCode(), one.getSendName(), patient.getCode(), one.getAttachedMessage(), ImUtill.CONTENT_TYPE_TEXT, patient.getName());
                }
            }
            // 推送消息给微信端
            JSONObject json = new JSONObject();
            json.put("first", patient.getName() + ",您好!\n" + one.getDoctorName() + "医生给您发来了一篇患教文章");
            json.put("first", patient.getName() + ",您好! " + one.getSendName() + "医生给您发来了一篇患教文章");
            json.put("toUser", patient.getCode());
            json.put("article", one.getId() + "");
            json.put("title", one.getAttachedTitle());
            json.put("doctorName", one.getDoctorName());
            json.put("doctorName", one.getSendName());
            json.put("represented", patient.getCode());//被代理人
            json.put("date", DateUtil.dateToStrLong(DateUtil.getNowDate()));
            json.put("remark", org.springframework.util.StringUtils.isEmpty(one.getAttachedContent()) ? "  " : one.getAttachedContent());
            json.put("remark", org.springframework.util.StringUtils.isEmpty(one.getAttachedMessage()) ? "  " : one.getAttachedMessage());
            if (StringUtils.isNotBlank(patient.getOpenid())) {
                pushMsgTask.putWxMsg(getAccessToken(), 9,

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

@ -1,15 +1,23 @@
package com.yihu.wlyy.web.third.gateway.service;
import com.yihu.wlyy.config.es.ElastricSearchSave;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.education.HealthEduArticleOpHistory;
import com.yihu.wlyy.entity.education.HealthEduArticlePatient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.education.HealthEduArticlePatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.health.HealthEduArticleOpHistoryService;
import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.web.third.gateway.vo.HealthEduArticlePatientModel;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.*;
@ -26,6 +34,19 @@ public class GcEduArticleService {
    private HealthEduArticleOpHistoryService healthEduArticleOpHistoryService;
    @Autowired
    private HealthEduArticlePatientDao healthEduArticlePatientDao;
    @Autowired
    private DoctorDao doctorDao;
    @Autowired
    private ElastricSearchSave elastricSearchSave;
    @Value("${es.type.HealthEduArticlePatient}")
    private String esType;
    @Value("${es.index.HealthEduArticlePatient}")
    private String esIndex;
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    /**
     * 初始化需要发送的患者
@ -84,7 +105,7 @@ public class GcEduArticleService {
        }
        if (unPatients != null && unPatients.length > 0) {
            for (String unPatient : unPatients) {
                if(patientSet.contains(unPatient)){
                if (patientSet.contains(unPatient)) {
                    patientSet.remove(unPatient);
                }
            }
@ -94,62 +115,153 @@ public class GcEduArticleService {
    /**
     * 保存发送信息
     *
     * @param patientSet    患者set集和
     * @param sendCode      发送人code、
     * @param sendName      发送人名称
     * @param sendMessage   发送人携带的信息
     * @param teamId        发送人所属团队
     * @param articleIds    文章列表
     * @param articlePics   文件封面
     * @param articleTitles 文章主题
     * @param patientSet   患者set集和
     * @param sendCode     发送人code、
     * @param sendName     发送人名称
     * @param sendMessage  发送人携带的信息
     * @param teamId       发送人所属团队
     * @param articleId    文章列表
     * @param articlePic   文件封面
     * @param articleTitle 文章主题
     */
    @Transactional
    public List<HealthEduArticlePatient> saveArticle(Set<String> patientSet, String sendCode, String sendName, String sendMessage, Long teamId, String[] articleIds, String[] articlePics, String[] articleTitles) {
        List<HealthEduArticlePatient> healthEduArticlePatients = new ArrayList<>();
    public List<com.yihu.es.entity.HealthEduArticlePatient> saveArticle(Set<String> patientSet,
                                                                        String sendCode,
                                                                        String sendName,
                                                                        Integer sendType,
                                                                        String sendMessage,
                                                                        Long teamId,
                                                                        String articleId,
                                                                        String articlePic,
                                                                        String articleTitle,
                                                                        String articleContent,
                                                                        String articleType,
                                                                        String level1Type,
                                                                        String level2Type,
                                                                        String level) {
        List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients = new ArrayList<>();
        Doctor doctor = doctorDao.findByCode(sendCode);
        String batchNo = UUID.randomUUID().toString();
        Date createTime = new Date();
        for (String patient : patientSet) {
            SignFamily signFamily = signFamilyDao.findByjiatingPatient(patient);
            if(signFamily==null){
            if (signFamily == null) {
                continue;
            }
            for (int i = 0; i < articleIds.length; i++) {
                HealthEduArticlePatient healthEduArticlePatient = new HealthEduArticlePatient();
                // 设置文章标识
                healthEduArticlePatient.setArticle(articleIds[i]);
                // 设置医生标识
                healthEduArticlePatient.setDoctor(sendCode);
                // 设置医生姓名
                healthEduArticlePatient.setDoctorName(sendName);
                // 设置患者标识
                healthEduArticlePatient.setPatient(patient);
                // 设置为示读
                healthEduArticlePatient.setRead(1);
                // 签约类型
                healthEduArticlePatient.setSignType(2);
                // 行政团队
                healthEduArticlePatient.setAdminTeamCode(teamId);
                //附加内容
                healthEduArticlePatient.setAttachedContent(sendMessage);
                //批次号记录发送批次
                healthEduArticlePatient.setBatchNo(batchNo);
                //创建时间
                healthEduArticlePatient.setCzrq(createTime);
                healthEduArticlePatient.setSignCode(signFamily.getCode());
                healthEduArticlePatient.setSendType(2);
                healthEduArticlePatient.setAttachedTitle(articleTitles[i]);
                healthEduArticlePatient.setAttachedPic(articlePics[i]);
                healthEduArticlePatients.add(healthEduArticlePatient);
            com.yihu.es.entity.HealthEduArticlePatient healthEduArticlePatient = new com.yihu.es.entity.HealthEduArticlePatient();
            healthEduArticlePatient.setSendCode(sendCode);
            healthEduArticlePatient.setSendName(sendName);
            healthEduArticlePatient.setSendType(sendType);
            healthEduArticlePatient.setPatient(patient);
            healthEduArticlePatient.setPatientName(signFamily.getName());
            healthEduArticlePatient.setAdminTeamCode(teamId);
            if (doctor != null) {
                healthEduArticlePatient.setHospital(doctor.getHospital());
                healthEduArticlePatient.setHospitalName(doctor.getHospitalName());
                healthEduArticlePatient.setTown(doctor.getTown());
                healthEduArticlePatient.setTownName(doctor.getTownName());
            }
            healthEduArticlePatient.setBatchNo(batchNo);
            healthEduArticlePatient.setCreateTime(createTime);
            healthEduArticlePatient.setArticleId(articleId);
            healthEduArticlePatient.setAttachedTitle(articleTitle);
            healthEduArticlePatient.setAttachedPic(articlePic);
            healthEduArticlePatient.setAttachedContent(articleContent);
            healthEduArticlePatient.setLevel(level);
            healthEduArticlePatient.setArticleType(articleType);
            healthEduArticlePatient.setLevel1Type(level1Type);
            healthEduArticlePatient.setLevel2Type(level2Type);
            healthEduArticlePatient.setAttachedMessage(sendMessage);
            healthEduArticlePatients.add(healthEduArticlePatient);
        }
        healthEduArticlePatientDao.save(healthEduArticlePatients);
        //记录转发量
        for (HealthEduArticlePatient healthEduArticlePatient : healthEduArticlePatients) {
            healthEduArticleOpHistoryService.saveByStatus(HealthEduArticleOpHistory.REPEAT_STATUS, healthEduArticlePatient.getArticle(), healthEduArticlePatient.getTitle(), healthEduArticlePatient.getDoctor());
        //保存到ES中
        elastricSearchSave.save(healthEduArticlePatients, esIndex, esType);
        return healthEduArticlePatients;
    }
    public List<HealthEduArticlePatientModel> getPatientHealthLogs(String sendCode, String articleType, String level1Type, String level2Type, String level, String attachedTitle, String startTime, String endTime, int page, int pagesize) {
        pagesize = page * pagesize;
        page = (page - 1) * pagesize;
        StringBuffer sql = new StringBuffer("select *,count(articleId) allCount from health_edu_article_patient_test  " +
                " where  sendCode='" + sendCode + "' ");
        if (!StringUtils.isEmpty(articleType)) {
            sql.append(" and  articleType='" + articleType + "'  ");
        }
        if (!StringUtils.isEmpty(attachedTitle)) {
            sql.append(" and  attachedTitle like '%" + attachedTitle + "%'  ");
        }
        if (!StringUtils.isEmpty(level1Type)) {
            sql.append(" and  level1Type='" + level1Type + "'  ");
        }
        if (!StringUtils.isEmpty(level2Type)) {
            sql.append(" and  level2Type='" + level2Type + "'  ");
        }
        if (!StringUtils.isEmpty(level)) {
            sql.append(" and  level='" + level + "'  ");
        }
        if (!StringUtils.isEmpty(startTime)) {
        return healthEduArticlePatients;
            sql.append(" and  createTime>='" + changeDate(startTime) + "'  ");
        }
        if (!StringUtils.isEmpty(endTime)) {
            sql.append(" and  createTime<='" + changeDate(endTime) + "'  ");
        }
        sql.append(" group by articleId order by createTime limit " + page + "," + pagesize);
        List<com.yihu.es.entity.HealthEduArticlePatient> esList = elasticsearchUtil.excute(sql.toString(), com.yihu.es.entity.HealthEduArticlePatient.class, esIndex, esType);
        List<HealthEduArticlePatientModel> returnList = new ArrayList<>();
        esList.stream().forEach(one -> {
            com.yihu.es.entity.HealthEduArticlePatient p = findOne(one.getArticleId());
            if (p != null) {
                p.setAllCount(one.getAllCount());
                HealthEduArticlePatientModel heapm=new HealthEduArticlePatientModel();
                BeanUtils.copyProperties(p,heapm);
                returnList.add(heapm);
            }
        });
        return returnList;
    }
    private com.yihu.es.entity.HealthEduArticlePatient findOne(String articleId) {
        String sql = "select level,level2Type,level1Type,attachedContent,attachedTitle,articleId,createTime,articleType,sendCode,sendName from health_edu_article_patient_test where articleId='" + articleId + "' order by createTime desc limit 0,1";
        com.yihu.es.entity.HealthEduArticlePatient esList = (com.yihu.es.entity.HealthEduArticlePatient) elasticsearchUtil.excuteOneObject(sql, com.yihu.es.entity.HealthEduArticlePatient.class, esIndex, esType);
        return esList;
    }
    public Long getPatientHealthLogsCount(String sendCode, String articleType, String level1Type, String level2Type, String level, String attachedTitle, String startTime, String endTime) {
        StringBuffer sql = new StringBuffer("select count(distinct articleId) count from health_edu_article_patient_test  " +
                " where  sendCode='" + sendCode + "' ");
        if (!StringUtils.isEmpty(articleType)) {
            sql.append(" and  articleType='" + articleType + "'  ");
        }
        if (!StringUtils.isEmpty(attachedTitle)) {
            sql.append(" and  attachedTitle like '%" + attachedTitle + "%'  ");
        }
        if (!StringUtils.isEmpty(level1Type)) {
            sql.append(" and  level1Type='" + level1Type + "'  ");
        }
        if (!StringUtils.isEmpty(level2Type)) {
            sql.append(" and  level2Type='" + level2Type + "'  ");
        }
        if (!StringUtils.isEmpty(level)) {
            sql.append(" and  level='" + level + "'  ");
        }
        if (!StringUtils.isEmpty(startTime)) {
            sql.append(" and  createTime>='" + changeDate(startTime) + "'  ");
        }
        if (!StringUtils.isEmpty(endTime)) {
            sql.append(" and  createTime<='" + changeDate(endTime) + "'  ");
        }
        sql.append(" group by articleId ");
        return elasticsearchUtil.excuteForLong(sql.toString(), esIndex, esType);
    }
    private String changeDate(String quotaDate) {
        return quotaDate + "T00:00:00+0800";
    }
}

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

@ -0,0 +1,128 @@
package com.yihu.wlyy.web.third.gateway.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.searchbox.annotations.JestId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.data.annotation.CreatedDate;
import java.util.Date;
/**
 * 推送记录表
 * Created by chenweida on 2017/9/7.
 */
@ApiModel(description = "推送记录")
public class HealthEduArticlePatientModel {
    @ApiModelProperty(value = "发送人code", required = false, access = "response")
    private String sendCode;   // 发送人code
    @ApiModelProperty(value = "发送人名称", required = false, access = "response")
    private String sendName;   // 发送人名称
    @ApiModelProperty(value = "创建时间", required = false, access = "response")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date createTime;  // 创建时间
    @ApiModelProperty(value = "文章id", required = false, access = "response")
    private String articleId;  //文章id
    @ApiModelProperty(value = "文章标题", required = false, access = "response")
    private String attachedTitle;  //文章标题
    @ApiModelProperty(value = "文章内容", required = false, access = "response")
    private String attachedContent; //文章内容
    @ApiModelProperty(value = "文章类别", required = false, access = "response")
    private String articleType;//文章类别
    @ApiModelProperty(value = "1级类别", required = false, access = "response")
    private String level1Type;//1级类别
    @ApiModelProperty(value = "2级类别", required = false, access = "response")
    private String level2Type;//2级类别
    @ApiModelProperty(value = "等级", required = false, access = "response")
    private String level;//等级
    @ApiModelProperty(value = "所有的推送数目", required = false, access = "response")
    private Integer allCount;//所有的推送数目
    public String getSendCode() {
        return sendCode;
    }
    public void setSendCode(String sendCode) {
        this.sendCode = sendCode;
    }
    public String getSendName() {
        return sendName;
    }
    public void setSendName(String sendName) {
        this.sendName = sendName;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getArticleId() {
        return articleId;
    }
    public void setArticleId(String articleId) {
        this.articleId = articleId;
    }
    public String getAttachedTitle() {
        return attachedTitle;
    }
    public void setAttachedTitle(String attachedTitle) {
        this.attachedTitle = attachedTitle;
    }
    public String getAttachedContent() {
        return attachedContent;
    }
    public void setAttachedContent(String attachedContent) {
        this.attachedContent = attachedContent;
    }
    public String getArticleType() {
        return articleType;
    }
    public void setArticleType(String articleType) {
        this.articleType = articleType;
    }
    public String getLevel1Type() {
        return level1Type;
    }
    public void setLevel1Type(String level1Type) {
        this.level1Type = level1Type;
    }
    public String getLevel2Type() {
        return level2Type;
    }
    public void setLevel2Type(String level2Type) {
        this.level2Type = level2Type;
    }
    public String getLevel() {
        return level;
    }
    public void setLevel(String level) {
        this.level = level;
    }
    public Integer getAllCount() {
        return allCount;
    }
    public void setAllCount(Integer allCount) {
        this.allCount = allCount;
    }
}

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

@ -184,6 +184,16 @@ express:
  sf_code: SDDF
  sf_check_word: ttzlgGyOQu4L
es:
  index:
    HealthEduArticlePatient: health_edu_article_patient_test
  type:
    health_edu_article_patient: health_edu_article_patient_test
  host: 172.19.103.68
  port: 9200
  tPort: 9300
  clusterName: jkzl
---
##正式的配置
@ -281,6 +291,18 @@ express:
  sf_code: sddf
  sf_check_word: PqFN0ADkTwnvXArMhqGxVduag44vyDQ7
es:
  index:
    HealthEduArticlePatient: health_edu_article_patient_prod
  type:
    HealthEduArticlePatient: health_edu_article_patient_prod
  host: 172.19.103.68
  port: 9200
  tPort: 9300
  clusterName: jkzl
---
##开发的配置
spring:
@ -378,6 +400,17 @@ express:
  sf_code: SDDF
  sf_check_word: ttzlgGyOQu4L
es:
  index:
    HealthEduArticlePatient: health_edu_article_patient_dev
  type:
    HealthEduArticlePatient: health_edu_article_patient_dev
  host: 172.19.103.68
  port: 9200
  tPort: 9300
  clusterName: jkzl
---
##开发连测试用这个版本的配置
spring:
@ -465,4 +498,15 @@ express:
  sf_url: http://218.17.248.244:11080/bsp-oisp/sfexpressService
#  sf_url: https://bsp-ois.sit.sf-express.com:9443/bsp-ois/sfexpressServic
  sf_code: SDDF
  sf_check_word: ttzlgGyOQu4L
  sf_check_word: ttzlgGyOQu4L
es:
  index:
    HealthEduArticlePatient: health_edu_article_patient_test
  type:
    HealthEduArticlePatient: health_edu_article_patient_test
  host: 172.19.103.68
  port: 9200
  tPort: 9300
  clusterName: jkzl

+ 2 - 2
patient-co/patient-co-wlyy/src/main/resources/logback.xml

@ -5,7 +5,7 @@
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
            <pattern>%d{yyyy/MM/dd-HH:mm:ss} %level [%thread] %caller{1} - %msg%n</pattern>
            <charset class="java.nio.charset.Charset">UTF-8</charset>
        </encoder>
    </appender>
@ -106,7 +106,7 @@
    </logger>
    <!--处方支付日志 end-->
    <root level="WARN">
    <root level="INFO">
        <!--<appender-ref ref="console" />-->
        <appender-ref ref="rollingFile" />
    </root>

+ 1 - 1
pom.xml

@ -57,7 +57,7 @@
        <jackson.version>2.6.6</jackson.version>
        <slf4j.version>1.7.7</slf4j.version>
        <commons-lang3.version>3.3.2</commons-lang3.version>
        <guava.version>17.0</guava.version>
        <guava.version>18.0</guava.version>
        <assertj.version>1.6.1</assertj.version>
        <mockito.version>1.9.5</mockito.version>
        <selenium.version>2.42.2</selenium.version>