|
@ -1,21 +1,16 @@
|
|
|
package com.yihu.wlyy.web.third.gateway.controller.doctor;
|
|
|
|
|
|
import com.yihu.wlyy.config.es.ElastricSearchSave;
|
|
|
import com.yihu.es.entity.HealthEduArticlePatient;
|
|
|
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.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;
|
|
@ -24,10 +19,11 @@ import io.swagger.annotations.ApiParam;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.json.JSONArray;
|
|
|
import org.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.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
@ -44,6 +40,7 @@ import java.util.*;
|
|
|
@ResponseBody
|
|
|
@Api(description = "医生文章相关服务")
|
|
|
public class GcEduArticleController extends WeixinBaseController {
|
|
|
private Logger logger = LoggerFactory.getLogger(GcEduArticleController.class);
|
|
|
|
|
|
@Autowired
|
|
|
private WeiXinOpenIdUtils weiXinOpenIdUtils;
|
|
@ -55,6 +52,11 @@ public class GcEduArticleController extends WeixinBaseController {
|
|
|
private ConsultService consultService;
|
|
|
@Autowired
|
|
|
private GcEduArticleService gcEduArticleService;
|
|
|
@Autowired
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
|
|
private String channelName = "healthArticleChannel";
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @param doctorCode
|
|
@ -64,13 +66,13 @@ public class GcEduArticleController extends WeixinBaseController {
|
|
|
*/
|
|
|
@RequestMapping(value = "logs", method = RequestMethod.GET)
|
|
|
@ApiOperation("查询医生给患者推送记录 ")
|
|
|
@ResponseBody
|
|
|
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 = "patientCode", value = "接收人code", required = false) @RequestParam(value = "patientCode", required = false) String patientCode,
|
|
|
@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,
|
|
@ -80,7 +82,11 @@ public class GcEduArticleController extends WeixinBaseController {
|
|
|
if (org.springframework.util.StringUtils.isEmpty(doctorCode)) {
|
|
|
doctorCode = getUID();
|
|
|
}
|
|
|
List<HealthEduArticlePatientModel> eduArticlePatients = gcEduArticleService.getPatientHealthLogs(getUID(), articleType, level1Type, level2Type, level, articleTitle, startTime, endTime, page, pagesize);
|
|
|
//最大1000
|
|
|
if (pagesize > 1000) {
|
|
|
pagesize = 1000;
|
|
|
}
|
|
|
List<HealthEduArticlePatientModel> eduArticlePatients = gcEduArticleService.getPatientHealthLogs(doctorCode, 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,
|
|
@ -126,70 +132,29 @@ public class GcEduArticleController extends WeixinBaseController {
|
|
|
|
|
|
//得到需要发送的患者
|
|
|
gcEduArticleService.initPatient(patientSet, patients, unPatients, labelType, labelCode, teamId);
|
|
|
//保存发送记录
|
|
|
List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients = gcEduArticleService.saveArticle(patientSet, sendCode, sendName, sendType, sendMessage, teamId, articleId, articlePic, articleTitle, articleContent, articleType, level1Type, level2Type, level);
|
|
|
//获取保存发送记录
|
|
|
List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients = gcEduArticleService.getSaveArticle(patientSet, sendCode, sendName, sendType, sendMessage, teamId, articleId, articlePic, articleTitle, articleContent, articleType, level1Type, level2Type, level);
|
|
|
//推送微信模板消息和发送im消息
|
|
|
|
|
|
sendWxTemplateAndIM(healthEduArticlePatients, sendType);
|
|
|
|
|
|
|
|
|
new Thread(() -> {
|
|
|
//发送任务到redis
|
|
|
sender(healthEduArticlePatients);
|
|
|
}).start();
|
|
|
System.out.println("结束");
|
|
|
return new BaseResultModel();
|
|
|
} catch (Exception e) {
|
|
|
return new BaseResultModel(BaseResultModel.statusEm.opera_error.getCode(), BaseResultModel.statusEm.opera_error.getMessage() + ":" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
@Async
|
|
|
private void sendWxTemplateAndIM(List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients, Integer sendType) throws Exception {
|
|
|
String endMsg = "";//"为了您的健康," + doctor.getName() + "医生给您发送了一篇患教文章,请仔细查阅,如有问题,可随时咨询医生。";
|
|
|
|
|
|
/**
|
|
|
* 发送到redis
|
|
|
*
|
|
|
* @param healthEduArticlePatients
|
|
|
*/
|
|
|
public void sender(List<HealthEduArticlePatient> healthEduArticlePatients) {
|
|
|
healthEduArticlePatients.stream().forEach(one -> {
|
|
|
Patient patient = patientService.findByCode(one.getPatient());
|
|
|
//卫纪委发送不推IM
|
|
|
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.getSendCode(), one.getSendName(), patient.getCode(), one.getAttachedMessage(), ImUtill.CONTENT_TYPE_TEXT, patient.getName());
|
|
|
}
|
|
|
}
|
|
|
// 推送消息给微信端
|
|
|
JSONObject json = new JSONObject();
|
|
|
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.getSendName());
|
|
|
json.put("represented", patient.getCode());//被代理人
|
|
|
json.put("date", DateUtil.dateToStrLong(DateUtil.getNowDate()));
|
|
|
json.put("remark", org.springframework.util.StringUtils.isEmpty(one.getAttachedMessage()) ? " " : one.getAttachedMessage());
|
|
|
|
|
|
if (StringUtils.isNotBlank(patient.getOpenid())) {
|
|
|
pushMsgTask.putWxMsg(getAccessToken(), 9,
|
|
|
patient.getOpenid(),
|
|
|
patient.getName(),
|
|
|
json);
|
|
|
}
|
|
|
//发送代理人
|
|
|
JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
|
|
|
if (jsonArray != null && jsonArray.length() > 0) {
|
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
|
JSONObject j = jsonArray.getJSONObject(i);
|
|
|
Patient member = (Patient) j.get("member");
|
|
|
json.remove("toUser");
|
|
|
json.put("toUser", member.getCode());
|
|
|
json.remove("first");
|
|
|
try {
|
|
|
json.put("first", weiXinOpenIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName()));
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(member.getOpenid())) {
|
|
|
pushMsgTask.putWxMsg(getAccessToken(), 9, member.getOpenid(), patient.getName(), json);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
redisTemplate.convertAndSend(channelName, net.sf.json.JSONObject.fromObject(one).toString());
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|