Browse Source

代码修改

chenweida 7 years ago
parent
commit
80fbce99a0

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

@ -34,6 +34,11 @@ public class HealthEduArticlePatient {
    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;
@ -186,4 +191,44 @@ public class HealthEduArticlePatient {
    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;
    }
}

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

@ -12,34 +12,40 @@ POST http://172.19.103.68:9200/health_edu_article_patient_test/health_edu_articl
                    "index": "not_analyzed"
                },
                "patientName": {
                    "type": "string"
                    "type": "string",
                    "index": "not_analyzed"
                },
                "doctor": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "doctorName": {
                    "type": "string"
                    "type": "string",
                    "index": "not_analyzed"
                },
                "adminTeamCode": {
                    "type": "integer"
                    "type": "integer",
                    "index": "not_analyzed"
                },
                "adminTeamName": {
                    "type": "string"
                    "type": "string",
                    "index": "not_analyzed"
                },
                "hospital": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "hospitalName": {
                    "type": "string"
                    "type": "string",
                    "index": "not_analyzed"
                },
                "town": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "townName": {
                    "type": "string"
                    "type": "string",
                    "index": "not_analyzed"
                },
                "batchNo": {
                    "type": "string",
@ -65,8 +71,25 @@ POST http://172.19.103.68:9200/health_edu_article_patient_test/health_edu_articl
                    "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"
                    "type": "date",
                    "index": "not_analyzed"
                }
            }
        }

+ 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;
    }
}

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

@ -9,11 +9,14 @@ 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;
@ -50,16 +53,9 @@ 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
@ -68,53 +64,37 @@ public class GcEduArticleController extends WeixinBaseController {
    @RequestMapping(value = "logs", method = RequestMethod.POST)
    @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", "");
        } catch (Exception e) {
            return write(-1, "查询失败!");
        }
    }
    /**
     *
     * @param articleCodes
     * @return
     */
    @RequestMapping(value = "articleSendNums", method = RequestMethod.POST)
    @ApiOperation("文章的推送次数 ")
    @ResponseBody
    public String articleSendNums(
            @ApiParam(name = "articleCodes", value = "文章codes 多个逗号分割", required = false) @RequestParam(value = "articleCodes", required = false) String articleCodes) {
        try {
            //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)
@ -129,26 +109,24 @@ public class GcEduArticleController extends WeixinBaseController {
            @ApiParam(name = "labelType", value = "标签类型  1:服务类型(卫计委分组) 2:健康情况 3:疾病类型 4:团队标签(自定义标签)", required = true) @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 = "articleContents", value = "文章内容,多个逗号分割", required = true) @RequestParam(value = "articleTitles", required = true) String articleContents
            @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(",");
            String[] articleContentArr=articleContents.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<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients = gcEduArticleService.saveArticle(patientSet, sendCode, sendName, sendType,sendMessage, teamId, articleIdArr, articlePicArr, articleTitleArr,articleContentArr);
            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);
@ -166,7 +144,7 @@ public class GcEduArticleController extends WeixinBaseController {
        healthEduArticlePatients.stream().forEach(one -> {
            Patient patient = patientService.findByCode(one.getPatient());
            //卫纪委发送不推IM
            if (1==sendType) {
            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())) {
                    //发送备注
@ -175,7 +153,7 @@ public class GcEduArticleController extends WeixinBaseController {
            }
            // 推送消息给微信端
            JSONObject json = new JSONObject();
            json.put("first", patient.getName() + ",您好!\n" + one.getSendName() + "医生给您发来了一篇患教文章");
            json.put("first", patient.getName() + ",您好! " + one.getSendName() + "医生给您发来了一篇患教文章");
            json.put("toUser", patient.getCode());
            json.put("article", one.getId() + "");
            json.put("title", one.getAttachedTitle());

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

@ -9,11 +9,15 @@ 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.*;
@ -40,6 +44,10 @@ public class GcEduArticleService {
    private String esType;
    @Value("${es.index.HealthEduArticlePatient}")
    private String esIndex;
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    /**
     * 初始化需要发送的患者
     *
@ -97,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);
                }
            }
@ -107,55 +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<com.yihu.es.entity.HealthEduArticlePatient> saveArticle(Set<String> patientSet, String sendCode, String sendName,Integer sendType, String sendMessage, Long teamId, String[] articleIds, String[] articlePics, String[] articleTitles,String[] articleContentArr) {
    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);
        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++) {
                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);
            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(articleIds[i]);
                healthEduArticlePatient.setAttachedTitle(articleTitles[i]);
                healthEduArticlePatient.setAttachedPic(articlePics[i]);
                healthEduArticlePatient.setAttachedContent(articleContentArr[i]);
                healthEduArticlePatient.setAttachedMessage(sendMessage);
            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);
                healthEduArticlePatients.add(healthEduArticlePatient);
            }
        }
        //保存到ES中
        elastricSearchSave.save(healthEduArticlePatients,esIndex,esType);
        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)) {
            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  endTime<='" + 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;
    }
}