|  | @ -1,10 +1,9 @@
 | 
												
													
														
															|  | package com.yihu.wlyy.web.third.gateway.controller.doctor;
 |  | 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.entity.patient.Patient;
 | 
												
													
														
															|  | import com.yihu.wlyy.repository.patient.SignFamilyDao;
 |  | import com.yihu.wlyy.repository.patient.SignFamilyDao;
 | 
												
													
														
															|  | import com.yihu.wlyy.service.app.consult.ConsultService;
 |  | 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.app.label.SignPatientLabelInfoService;
 | 
												
													
														
															|  | import com.yihu.wlyy.service.common.account.DoctorService;
 |  | import com.yihu.wlyy.service.common.account.DoctorService;
 | 
												
													
														
															|  | import com.yihu.wlyy.service.common.account.PatientService;
 |  | import com.yihu.wlyy.service.common.account.PatientService;
 | 
												
											
												
													
														
															|  | @ -23,6 +22,7 @@ import org.apache.commons.lang3.StringUtils;
 | 
												
													
														
															|  | import org.json.JSONArray;
 |  | import org.json.JSONArray;
 | 
												
													
														
															|  | import org.json.JSONObject;
 |  | import org.json.JSONObject;
 | 
												
													
														
															|  | import org.springframework.beans.factory.annotation.Autowired;
 |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
												
													
														
															|  | 
 |  | import org.springframework.beans.factory.annotation.Value;
 | 
												
													
														
															|  | import org.springframework.http.MediaType;
 |  | import org.springframework.http.MediaType;
 | 
												
													
														
															|  | import org.springframework.stereotype.Controller;
 |  | import org.springframework.stereotype.Controller;
 | 
												
													
														
															|  | import org.springframework.web.bind.annotation.RequestMapping;
 |  | import org.springframework.web.bind.annotation.RequestMapping;
 | 
												
											
												
													
														
															|  | @ -58,7 +58,6 @@ public class GcEduArticleController extends WeixinBaseController {
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private GcEduArticleService gcEduArticleService;
 |  |     private GcEduArticleService gcEduArticleService;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      *
 |  |      *
 | 
												
													
														
															|  |      * @param doctorCode
 |  |      * @param doctorCode
 | 
												
											
												
													
														
															|  | @ -83,6 +82,24 @@ public class GcEduArticleController extends WeixinBaseController {
 | 
												
													
														
															|  |             return write(-1, "查询失败!");
 |  |             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", "");
 | 
												
													
														
															|  | 
 |  |         } catch (Exception e) {
 | 
												
													
														
															|  | 
 |  |             return write(-1, "查询失败!");
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      * 参考原来的教育文章推送
 |  |      * 参考原来的教育文章推送
 | 
												
											
												
													
														
															|  | @ -103,18 +120,19 @@ public class GcEduArticleController extends WeixinBaseController {
 | 
												
													
														
															|  |     @RequestMapping(value = "send", method = RequestMethod.POST)
 |  |     @RequestMapping(value = "send", method = RequestMethod.POST)
 | 
												
													
														
															|  |     @ApiOperation("文章推送")
 |  |     @ApiOperation("文章推送")
 | 
												
													
														
															|  |     public BaseResultModel send(
 |  |     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 = "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 = "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 = "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 = "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 = 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 = "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 = "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 = "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 = "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 = "articleTitles", value = "文章标题,多个逗号分割", required = true) @RequestParam(value = "articleTitles", required = true) String articleTitles,
 | 
												
													
														
															|  | 
 |  |             @ApiParam(name = "articleContents", value = "文章内容,多个逗号分割", required = true) @RequestParam(value = "articleTitles", required = true) String articleContents
 | 
												
													
														
															|  |     ) {
 |  |     ) {
 | 
												
													
														
															|  |         try {
 |  |         try {
 | 
												
													
														
															|  |             String[] patients = receiveCodes.split(",");//接收人的code
 |  |             String[] patients = receiveCodes.split(",");//接收人的code
 | 
												
											
												
													
														
															|  | @ -123,13 +141,14 @@ public class GcEduArticleController extends WeixinBaseController {
 | 
												
													
														
															|  |             String[] articleIdArr = articleIds.split(",");
 |  |             String[] articleIdArr = articleIds.split(",");
 | 
												
													
														
															|  |             String[] articlePicArr = articlePics.split(",");
 |  |             String[] articlePicArr = articlePics.split(",");
 | 
												
													
														
															|  |             String[] articleTitleArr = articleTitles.split(",");
 |  |             String[] articleTitleArr = articleTitles.split(",");
 | 
												
													
														
															|  | 
 |  |             String[] articleContentArr=articleContents.split(",");
 | 
												
													
														
															|  |             if ((articleIdArr.length != articlePicArr.length) || (articleIdArr.length != articleTitleArr.length) || (articlePicArr.length != articleTitleArr.length)) {
 |  |             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() + ":文章参数长度错误");
 |  |                 return new ResultBatchModel(BaseResultModel.statusEm.opera_error.getCode(), BaseResultModel.statusEm.opera_error.getMessage() + ":文章参数长度错误");
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |             //得到需要发送的患者
 |  |             //得到需要发送的患者
 | 
												
													
														
															|  |             gcEduArticleService.initPatient(patientSet, patients, unPatients, labelType, labelCode, teamId);
 |  |             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, articleIdArr, articlePicArr, articleTitleArr,articleContentArr);
 | 
												
													
														
															|  |             //推送微信模板消息和发送im消息
 |  |             //推送微信模板消息和发送im消息
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |             sendWxTemplateAndIM(healthEduArticlePatients, sendType);
 |  |             sendWxTemplateAndIM(healthEduArticlePatients, sendType);
 | 
												
											
												
													
														
															|  | @ -141,29 +160,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() + "医生给您发送了一篇患教文章,请仔细查阅,如有问题,可随时咨询医生。";
 |  |         String endMsg = "";//"为了您的健康," + doctor.getName() + "医生给您发送了一篇患教文章,请仔细查阅,如有问题,可随时咨询医生。";
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         healthEduArticlePatients.stream().forEach(one -> {
 |  |         healthEduArticlePatients.stream().forEach(one -> {
 | 
												
													
														
															|  |             Patient patient = patientService.findByCode(one.getPatient());
 |  |             Patient patient = patientService.findByCode(one.getPatient());
 | 
												
													
														
															|  |             //卫纪委发送不推IM
 |  |             //卫纪委发送不推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();
 |  |             JSONObject json = new JSONObject();
 | 
												
													
														
															|  |             json.put("first", patient.getName() + ",您好!\n" + one.getDoctorName() + "医生给您发来了一篇患教文章");
 |  | 
 | 
												
													
														
															|  | 
 |  |             json.put("first", patient.getName() + ",您好!\n" + one.getSendName() + "医生给您发来了一篇患教文章");
 | 
												
													
														
															|  |             json.put("toUser", patient.getCode());
 |  |             json.put("toUser", patient.getCode());
 | 
												
													
														
															|  |             json.put("article", one.getId() + "");
 |  |             json.put("article", one.getId() + "");
 | 
												
													
														
															|  |             json.put("title", one.getAttachedTitle());
 |  |             json.put("title", one.getAttachedTitle());
 | 
												
													
														
															|  |             json.put("doctorName", one.getDoctorName());
 |  | 
 | 
												
													
														
															|  | 
 |  |             json.put("doctorName", one.getSendName());
 | 
												
													
														
															|  |             json.put("represented", patient.getCode());//被代理人
 |  |             json.put("represented", patient.getCode());//被代理人
 | 
												
													
														
															|  |             json.put("date", DateUtil.dateToStrLong(DateUtil.getNowDate()));
 |  |             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())) {
 |  |             if (StringUtils.isNotBlank(patient.getOpenid())) {
 | 
												
													
														
															|  |                 pushMsgTask.putWxMsg(getAccessToken(), 9,
 |  |                 pushMsgTask.putWxMsg(getAccessToken(), 9,
 |