消息推送修改

This commit is contained in:
zhangheng 2024-07-30 18:05:11 +08:00
parent ce17d4606d
commit b9a125dade
4 changed files with 53 additions and 16 deletions

View File

@ -19,6 +19,11 @@ public enum NodeExecuteResultStatusEnum {
* 失败
*/
FAILURE("FAILURE"),
/**
* 过期
*/
EXPIRED("EXPIRED"),
;
final private String info;

View File

@ -66,7 +66,7 @@ public interface HomePageMapper {
* @param signPatientManageRouteNodeIds 节点id
* @return int
*/
int updateNodeExecuteStatusByIds(@Param("signPatientManageRouteNodeIds") List<Long> signPatientManageRouteNodeIds);
int updateNodeExecuteStatusByIds(@Param("signPatientManageRouteNodeIds") List<Long> signPatientManageRouteNodeIds, @Param("nodeExecuteStatus") String nodeExecuteStatus, @Param("appletNodeExecuteResultStatus") String appletNodeExecuteResultStatus);
/**
* 查询个人任务消息

View File

@ -133,6 +133,7 @@
LEFT JOIN patient_info pi ON pi.id = spmr.patient_id
where
spmrn.node_execute_status = 'UNEXECUTED'
and (spmrn.applet_node_execute_result_status is null or spmrn.applet_node_execute_result_status = '')
and spmrn.del_flag = 0
and spmrn.applet_push_sign = 1
and pi.del_flag = 0
@ -148,9 +149,9 @@
<update id="updateNodeExecuteStatusByIds">
update sign_patient_manage_route_node
set node_execute_status = 'EXECUTED'
where
id in
set node_execute_status = #{nodeExecuteStatus},
applet_node_execute_result_status = #{appletNodeExecuteResultStatus}
where id in
<foreach item="signPatientManageRouteNodeIds" collection="signPatientManageRouteNodeIds" open="(" separator=","
close=")">
#{signPatientManageRouteNodeIds}

View File

@ -2,8 +2,10 @@ package com.xinelu.quartz.service.impl;
import com.alibaba.fastjson2.JSON;
import com.xinelu.common.config.WeChatAppletChatConfig;
import com.xinelu.common.enums.RouteNodeNameEnum;
import com.xinelu.common.enums.SubscribeStatusEnum;
import com.xinelu.common.enums.*;
import com.xinelu.common.utils.SecurityUtils;
import com.xinelu.manage.domain.subscribemessagesendrecord.SubscribeMessageSendRecord;
import com.xinelu.manage.mapper.subscribemessagesendrecord.SubscribeMessageSendRecordMapper;
import com.xinelu.mobile.domain.TemplateContent;
import com.xinelu.mobile.mapper.homepage.HomePageMapper;
import com.xinelu.mobile.utils.WeChatOfficialAccountUtils;
@ -15,6 +17,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -35,6 +38,8 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
private WeChatAppletChatConfig weChatAppletChatConfig;
@Resource
private WeChatOfficialAccountUtils weChatOfficialAccountUtils;
@Resource
private SubscribeMessageSendRecordMapper subscribeMessageSendRecordMapper;
/**
* 推送任务组装数据
@ -50,6 +55,8 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
List<PatientVO> signPatientManageRouteNodes = homePageMapper.selectSignPatientManageRouteNode(patientIdList);
// PatientVO 包含签约路径节点相关属性后面用于推送消息
List<PatientVO> patientVOList = new ArrayList<>();
//发送消息到期节点id集合
List<Long> expiredManageRouteNodeIds = new ArrayList<>();
for (PatientVO signPatientManageRouteNode : signPatientManageRouteNodes) {
//判断推送状态
if (Objects.isNull(signPatientManageRouteNode.getAppletPushSign()) || signPatientManageRouteNode.getAppletPushSign() != 1) {
@ -69,12 +76,21 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
}
boolean before = localDate.isBefore(LocalDate.now()) || localDate.isEqual(LocalDate.now());
if (before) {
int i = LocalDate.now().compareTo(localDate);
if (i >= 1) {
expiredManageRouteNodeIds.add(patientVO.getSignPatientManageRouteNodeId());
continue;
}
signPatientManageRouteNode.setOpenId(patientVO.getOpenId());
//转换成中文
signPatientManageRouteNode.setRouteNodeName(RouteNodeNameEnum.getNameByInfo(signPatientManageRouteNode.getRouteNodeName()).getName());
patientVOList.add(signPatientManageRouteNode);
}
}
//更改过期执行状态
if (CollectionUtils.isNotEmpty(expiredManageRouteNodeIds)) {
homePageMapper.updateNodeExecuteStatusByIds(expiredManageRouteNodeIds, NodeExecuteStatusEnum.EXECUTED.getInfo(), NodeExecuteResultStatusEnum.EXPIRED.getInfo());
}
// //如果节点 适用范围是 出院后或就诊/出院后
// if (signPatientManageRouteNode.getRouteNodeName().equals(RouteNodeNameEnum.AFTER_DISCHARGE.getInfo()) || signPatientManageRouteNode.getRouteNodeName().equals(RouteNodeNameEnum.AFTER_VISIT_DISCHARGE.getInfo())) {
@ -121,9 +137,9 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
// }
// }
// }
List<Long> signPatientManageRouteNodeIds = new ArrayList<>();
//发送
//发送失败id集合
List<Long> signPatientManageRouteNodeIds = new ArrayList<>();
for (PatientVO patientVO : patientVOList) {
try {
JSON.parseArray(patientVO.getAppletNodeContent(), TemplateContent.class);
@ -132,13 +148,28 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
}
// 开始推送消息
Integer integer = weChatOfficialAccountUtils.sendAppletTemplateMessage(patientVO);
SubscribeMessageSendRecord subscribeMessageSendRecord = new SubscribeMessageSendRecord();
if (integer == 0) {
signPatientManageRouteNodeIds.add(patientVO.getSignPatientManageRouteNodeId());
subscribeMessageSendRecord.setErrorCode(0);
subscribeMessageSendRecord.setErrorStatus(ErrorStatusEnum.success.getValue());
} else {
subscribeMessageSendRecord.setErrorCode(1);
subscribeMessageSendRecord.setErrorStatus(ErrorStatusEnum.fail.getValue());
}
//更改执行状态
subscribeMessageSendRecord.setPatientId(patientVO.getPatientId());
subscribeMessageSendRecord.setManageRouteNodeId(patientVO.getSignPatientManageRouteNodeId());
subscribeMessageSendRecord.setSubscribeTime(LocalDateTime.now());
subscribeMessageSendRecord.setOpenid(patientVO.getOpenId());
subscribeMessageSendRecord.setAppletId(weChatAppletChatConfig.getAppletId());
subscribeMessageSendRecord.setTemplateId(weChatAppletChatConfig.getHealthyPropagandaId());
subscribeMessageSendRecord.setCreateBy(SecurityUtils.getUsername());
subscribeMessageSendRecord.setCreateTime(LocalDateTime.now());
subscribeMessageSendRecordMapper.insertSubscribeMessageSendRecord(subscribeMessageSendRecord);
}
//更改成功执行状态
if (CollectionUtils.isNotEmpty(signPatientManageRouteNodeIds)) {
homePageMapper.updateNodeExecuteStatusByIds(signPatientManageRouteNodeIds);
}
homePageMapper.updateNodeExecuteStatusByIds(signPatientManageRouteNodeIds, NodeExecuteStatusEnum.EXECUTED.getInfo(), NodeExecuteResultStatusEnum.SUCCESS.getInfo());
}
}
}