家医消息通知接口修改

This commit is contained in:
mengkuiliang 2023-10-25 11:05:08 +08:00
parent 7dd7d1c2d7
commit c399e2e922
8 changed files with 179 additions and 45 deletions

View File

@ -15,12 +15,24 @@ import lombok.Data;
@ApiModel(value = "消息推送请求对象")
public class MessagePushBody {
/**
* 消息类别 1通知公告2健康推送3在线咨询 4消息通知
*/
@ApiModelProperty(value = "消息类别 1通知公告2健康推送3在线咨询 4消息通知")
private String messageCategory;
/**
* 业务类型1 默认 9申请 10用药提醒通知
*/
@ApiModelProperty(value = "务类型1 家医默认通知 10申请通知 9用药提醒通知")
private String busType;
/**
* 身份证号
*/
@ApiModelProperty(value = "cardNo")
private String cardNo;
/**
* openid
*/

View File

@ -1,6 +1,6 @@
package com.xinelu.familydoctor.applet.pojo.dto;
import com.xinelu.familydoctor.applet.pojo.dto.FDMessageExtentDto;
import com.xinelu.applet.dto.chatrecord.ChatRecordDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -60,4 +60,7 @@ public class FDMessageDto extends FDMessageExtentDto {
@ApiModelProperty(value = "模版类型MessageTemplateType枚举", required = true)
private String templateType;
@ApiModelProperty("消息记录对象")
ChatRecordDTO chatRecord;
}

View File

@ -81,13 +81,16 @@ public class ResidentRescindApplyServiceImpl implements IResidentRescindApplySer
residentRescindApplyMapper.insert(entity);
MessagePushBody messagePushBody = new MessagePushBody();
messagePushBody.setMessageCategory("4");
messagePushBody.setBusType("10");
messagePushBody.setOpenid(patientInfo.getOpenid());
messagePushBody.setReceiveName(patientInfo.getPatientName());
messagePushBody.setText1(body.getOrgName());
messagePushBody.setText2("解约申请");
messagePushBody.setSendTitle("解约申请");
messagePushBody.setSendTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", new Date()));
messagePushBody.setSendContent(patientInfo.getPatientName() + "已提交申请");
messagePushBody.setCardNo(body.getIdentity());
messagePushService.fdApprovePush(JSONObject.parseObject(JSONObject.toJSONString(messagePushBody)));
}

View File

@ -96,13 +96,17 @@ public class ResidentServiceApplyServiceImpl implements IResidentServiceAppletSe
residentServiceApplyMapper.insert(entity);
MessagePushBody messagePushBody = new MessagePushBody();
messagePushBody.setMessageCategory("4");
messagePushBody.setBusType("10");
messagePushBody.setOpenid(patientInfo.getOpenid());
messagePushBody.setReceiveName(patientInfo.getPatientName());
messagePushBody.setText1(body.getOrgName());
messagePushBody.setText2(body.getFormName().length() >= 20? body.getFormName().substring(0,17) + "...": body.getFormName());
messagePushBody.setText3(body.getFormName());
messagePushBody.setSendTitle("服务预约");
messagePushBody.setSendTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", new Date()));
messagePushBody.setSendContent(patientInfo.getPatientName() + "已提交服务申请");
messagePushBody.setCardNo(body.getIdentity());
messagePushService.fdApprovePush(JSONObject.parseObject(JSONObject.toJSONString(messagePushBody)));
}

View File

@ -98,13 +98,16 @@ public class ResidentSignApplyServiceImpl implements IResidentSignAppletService
residentSignApplyMapper.insert(entity);
MessagePushBody messagePushBody = new MessagePushBody();
messagePushBody.setMessageCategory("4");
messagePushBody.setBusType("10");
messagePushBody.setOpenid(patientInfo.getOpenid());
messagePushBody.setReceiveName(body.getResidentName());
messagePushBody.setText1(body.getOrgName());
messagePushBody.setText2("签约申请");
messagePushBody.setSendTitle("签约申请");
messagePushBody.setSendTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", new Date()));
messagePushBody.setSendContent(body.getResidentName() + "已提交申请");
messagePushBody.setCardNo(body.getIdentity());
messagePushService.fdApprovePush(JSONObject.parseObject(JSONObject.toJSONString(messagePushBody)));
}

View File

@ -28,6 +28,12 @@ public class ChatRecordDTO extends BaseEntity implements Serializable {
@NotNull(message = "聊天记录业务主键不能为空", groups = {Insert.class})
private Long consultationId;
/**
* 发送人
*/
@NotNull(message = "发送人信息不能为空", groups = {Insert.class})
private String messageNo;
/**
* 发送人
*/
@ -62,7 +68,6 @@ public class ChatRecordDTO extends BaseEntity implements Serializable {
@NotNull(message = "消息类型不能为空", groups = {Insert.class})
private String messageType;
/**
* 消息内容图片内容时内容为图片路径
*/
@ -70,5 +75,14 @@ public class ChatRecordDTO extends BaseEntity implements Serializable {
@Length(max = 400, message = "消息内容不能超过18位", groups = {Insert.class, Update.class})
private String content;
/**
* 标题
*/
private String title;
/**
* 消息类别 1通知公告2健康推送3在线咨询 4消息通知
*/
private String messageCategory;
}

View File

@ -2,9 +2,11 @@ package com.xinelu.applet.service.messagepush.Impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.xinelu.applet.dto.chatrecord.ChatRecordDTO;
import com.xinelu.applet.dto.messagepush.FDMessagePushDto;
import com.xinelu.applet.dto.messagepush.FDWxMegDto;
import com.xinelu.applet.dto.messagepush.TemplateData;
import com.xinelu.applet.service.chatRecord.IChatRecordService;
import com.xinelu.applet.service.messagepush.MessagePushService;
import com.xinelu.common.config.AppletChatConfig;
import com.xinelu.common.config.AppletPageConfig;
@ -15,6 +17,7 @@ import com.xinelu.common.enums.*;
import com.xinelu.common.utils.AppletChatUtil;
import com.xinelu.common.utils.http.HttpUtils;
import com.xinelu.common.utils.map.MapUtil;
import com.xinelu.common.utils.uuid.IdUtils;
import com.xinelu.manage.domain.subscribemessagerecord.SubscribeMessageRecord;
import com.xinelu.manage.domain.systemsettingsinfo.SystemSettingsInfo;
import com.xinelu.manage.mapper.subscribemessagerecord.SubscribeMessageRecordMapper;
@ -52,6 +55,8 @@ public class MessagePushServiceImpl implements MessagePushService {
private AppletPageConfig appletPageConfig;
@Resource
private IPatientInfoService patientInfoService;
@Resource
private IChatRecordService chatRecordService;
/**
* 微信消息推送url
@ -232,50 +237,82 @@ public class MessagePushServiceImpl implements MessagePushService {
@Override
@Async("asyncThreadServiceExecutor")
public void fdApprovePush(JSONObject body) {
AppletAccessToken appletAccessToken = AppletChatUtil.getAppletAccessToken(appletChatConfig.getAppletId(), appletChatConfig.getSecret());
if (Objects.isNull(appletAccessToken)) {
log.error("获取微信小程序accessToken信息失败");
}
if (Objects.nonNull(appletAccessToken.getErrcode()) && appletAccessToken.getErrcode() != AppletSubscriptionMessageEnum.SUCCESS_ERRCODE.getValue()) {
log.error("获取微信小程序accessToken信息失败失败信息为" + appletAccessToken.getErrmsg(), 201);
}
if (StringUtils.isBlank(appletAccessToken.getAccessToken())) {
log.error("accessToken信息为空");
}
if (body.containsKey("cardNo") && !StringUtils.isBlank(body.getString("cardNo"))) {
PatientInfoVO patientInfo = patientInfoService.selectPatientInfoByCardNo(body.getString("cardNo"));
if (patientInfo == null) {
log.error("接收方未注册 {}", body.getString("cardNo"));
}
AppletAccessToken appletAccessToken = AppletChatUtil.getAppletAccessToken(appletChatConfig.getAppletId(), appletChatConfig.getSecret());
if (Objects.isNull(appletAccessToken)) {
log.error("获取微信小程序accessToken信息失败");
}
if (Objects.nonNull(appletAccessToken.getErrcode()) && appletAccessToken.getErrcode() != AppletSubscriptionMessageEnum.SUCCESS_ERRCODE.getValue()) {
log.error("获取微信小程序accessToken信息失败失败信息为" + appletAccessToken.getErrmsg(), 201);
}
if (StringUtils.isBlank(appletAccessToken.getAccessToken())) {
log.error("accessToken信息为空");
}
ChatRecordDTO chatRecord = new ChatRecordDTO();
// 查询居民注册信息
if(!body.containsKey("patientId") || body.getLong("patientId") == null) {
chatRecord.setRecipientId(patientInfo.getId());
} else {
chatRecord.setRecipientId(body.getLong("patientId"));
}
//模板内容
Map<String, MessageValueEntity> messageValueEntityMap = new LinkedHashMap<>();
switch (body.getString("busType")) {
// 申请
case "10":
messageValueEntityMap.put("name2", new MessageValueEntity(body.getString("receiveName")));
messageValueEntityMap.put("thing6", new MessageValueEntity(body.getString("text1")));
messageValueEntityMap.put("thing5", new MessageValueEntity(body.getString("text2")));
messageValueEntityMap.put("thing8", new MessageValueEntity(body.getString("sendTime")));
messageValueEntityMap.put("thing9", new MessageValueEntity(body.getString("sendContent")));
break;
// 用药
case "9":
messageValueEntityMap.put("thing1", new MessageValueEntity(body.getString("text1")));
messageValueEntityMap.put("thing2", new MessageValueEntity(body.getString("text2")));
messageValueEntityMap.put("time3", new MessageValueEntity(body.getString("sendTime")));
messageValueEntityMap.put("thing4", new MessageValueEntity(body.getString("sendContent")));
break;
// 默认
default:
messageValueEntityMap.put("thing1", new MessageValueEntity(body.getString("senderName")));
messageValueEntityMap.put("time2", new MessageValueEntity(body.getString("sendTime")));
messageValueEntityMap.put("thing3", new MessageValueEntity(body.getString("sendContent")));
break;
}
//模板内容
Map<String, MessageValueEntity> messageValueEntityMap = new LinkedHashMap<>();
switch (body.getString("busType")) {
// 申请
case "10":
messageValueEntityMap.put("name2", new MessageValueEntity(body.getString("receiveName")));
messageValueEntityMap.put("thing6", new MessageValueEntity(body.getString("text1")));
messageValueEntityMap.put("thing5", new MessageValueEntity(body.getString("text2")));
messageValueEntityMap.put("thing8", new MessageValueEntity(body.getString("sendTime")));
messageValueEntityMap.put("thing9", new MessageValueEntity(body.getString("sendContent")));
chatRecord.setContent(body.getString("receiveName") + "" + body.getString("text1") + "提交服务申请,服务内容:" + (body.containsKey("text3") && !StringUtils.isBlank(body.getString("text3"))? body.getString("text3"): body.getString("text2")));
chatRecord.setRecipientName(body.getString("receiveName"));
chatRecord.setSenderName(body.getString("text1"));
break;
// 用药
case "9":
messageValueEntityMap.put("thing1", new MessageValueEntity(body.getString("text1")));
messageValueEntityMap.put("thing2", new MessageValueEntity(body.getString("text2")));
messageValueEntityMap.put("time3", new MessageValueEntity(body.getString("sendTime")));
messageValueEntityMap.put("thing4", new MessageValueEntity(body.getString("sendContent")));
chatRecord.setContent(body.getString("sendContent"));
chatRecord.setRecipientName(body.getString("receiveName"));
chatRecord.setSenderName(body.getString("senderName"));
break;
// 默认
default:
messageValueEntityMap.put("thing1", new MessageValueEntity(body.getString("senderName")));
messageValueEntityMap.put("time2", new MessageValueEntity(body.getString("sendTime")));
messageValueEntityMap.put("thing3", new MessageValueEntity(body.getString("sendContent")));
chatRecord.setContent(body.getString("sendContent"));
chatRecord.setRecipientName(body.getString("receiveName"));
chatRecord.setSenderName(body.getString("senderName"));
break;
}
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("touser", body.getString("openid"));
paramsMap.put("template_id", MessageTemplateType.getFolllowupTypeByCode(body.getString("busType")).getTemplateId());
paramsMap.put("page", appletPageConfig.getIntegralPageUrl());
paramsMap.put("data", messageValueEntityMap);
//发送
this.sendPosts(appletAccessToken, paramsMap);
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("touser", body.getString("openid"));
paramsMap.put("template_id", MessageTemplateType.getFolllowupTypeByCode(body.getString("busType")).getTemplateId());
paramsMap.put("page", appletPageConfig.getIntegralPageUrl());
paramsMap.put("data", messageValueEntityMap);
//发送
this.sendPosts(appletAccessToken, paramsMap);
// 记录通知消息
if(body.containsKey("messageCategory") && !StringUtils.isBlank(body.getString("messageCategory"))) {
chatRecord.setMessageType("1");
chatRecord.setTitle(body.getString("sendTitle"));
chatRecord.setMessageNo(IdUtils.fastSimpleUUID());
chatRecord.setSendTime(new Date());
chatRecord.setMessageCategory(body.getString("messageCategory"));
chatRecordService.insertChatRecord(chatRecord);
}
}
}
/**
@ -305,8 +342,62 @@ public class MessagePushServiceImpl implements MessagePushService {
if (StringUtils.isBlank(appletAccessToken.getAccessToken())) {
log.error("accessToken信息为空");
}
ChatRecordDTO chatRecord = new ChatRecordDTO();
// 查询居民注册信息
if(!req.containsKey("patientId") || req.getLong("patientId") == null) {
chatRecord.setRecipientId(patientInfo.getId());
} else {
chatRecord.setRecipientId(req.getLong("patientId"));
}
FDWxMegDto wxMegDto = new FDWxMegDto();
wxMegDto.setTouser(patientInfo.getOpenid());
wxMegDto.setTemplate_id(MessageTemplateType.getFolllowupTypeByCode(body.getTemplateType()).getTemplateId());
Map<String, TemplateData> meg = new HashMap<>();
switch (body.getTemplateType()) {
// 用药提醒
case "9":
meg.put("thing1", new TemplateData(body.getDrugName()));
meg.put("thing2", new TemplateData(body.getDrugUsage()));
meg.put("time3", new TemplateData(body.getHandleDate()));
meg.put("thing4", new TemplateData((!StringUtils.isBlank(body.getRecipientName())? body.getRecipientName(): "") + body.getContent()));
break;
// 筛查预约成功
case "10":
meg.put("name2", new TemplateData(body.getRecipientName()));
meg.put("thing5", new TemplateData(body.getApplyContent()));
meg.put("thing6", new TemplateData(body.getHospitalName()));
meg.put("thing8", new TemplateData(body.getHandleDate()));
meg.put("thing9", new TemplateData(body.getContent()));
break;
// 家庭医生消息通知
default:
meg.put("thing1", new TemplateData(body.getDoctorName()));
meg.put("time2", new TemplateData(body.getSendTime()));
meg.put("thing3", new TemplateData(body.getContent()));
break;
}
wxMegDto.setPage(MessageTypePath.getPathByType(body.getMessageType()).getPath() + (StringUtils.isBlank(body.getContentId()) ? "" : body.getContentId()));
wxMegDto.setData(meg);
//发送
this.sendPosts(appletAccessToken, MapUtil.object2Map(getTemplate(body, patientInfo.getOpenid())));
this.sendPosts(appletAccessToken, MapUtil.object2Map(wxMegDto));
// 记录通知消息
if(req.containsKey("messageCategory") && !StringUtils.isBlank(req.getString("messageCategory")) && req.containsKey("chatRecord")) {
ChatRecordDTO chat = req.getJSONObject("chatRecord").toJavaObject(ChatRecordDTO.class);
if(chat != null) {
chatRecord.setMessageType("1");
chatRecord.setMessageNo(IdUtils.fastSimpleUUID());
chatRecord.setSendTime(new Date());
chatRecord.setTitle(chat.getTitle());
chatRecord.setContent(chat.getContent());
chatRecord.setSenderName(chat.getSenderName());
chatRecord.setRecipientName(patientInfo.getPatientName());
chatRecord.setMessageCategory(req.getString("messageCategory"));
chatRecordService.insertChatRecord(chatRecord);
}
}
}
}

View File

@ -140,10 +140,14 @@ public class ScreeningRecordServiceImpl implements IScreeningRecordService {
result.put("receiveName", registerVo.getPatientName());
result.put("text1", body.getHospitalName());
result.put("text2", (body.getProjectName().length() >= 17? (body.getProjectName().substring(0, 17) + "..."): body.getProjectName()));
result.put("text3", body.getProjectName());
result.put("sendTitle", "筛查预约");
result.put("sendTime", DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", new Date()));
result.put("busType", "10");
result.put("sendContent", registerVo.getPatientName() + "预约筛查成功");
result.put("messageType", "5");
result.put("messageCategory", "4");
result.put("cardNo", registerVo.getCardNo());
}
return result;
}