This commit is contained in:
haown 2024-11-06 10:45:51 +08:00
commit 760af62433

View File

@ -59,12 +59,14 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
*/
public void signPatientManageRouteNodeTask() {
//微信小程序订阅消息记录表
//1获取已订阅 指定 小程序通知模版 患者列表
List<PatientVO> patientList = homePageMapper.selectResidentAndSubscribeMessageRecord(SubscribeStatusEnum.accept.getValue(), weChatAppletChatConfig.getHealthyPropagandaId());
//1.1 获取已订阅 指定 小程序通知模版 患者ID列表
List<Long> patientIdList = patientList.stream().filter(Objects::nonNull).map(PatientVO::getPatientId).filter(Objects::nonNull).collect(Collectors.toList());
if (CollectionUtils.isEmpty(patientIdList)) {
return;
}
// 患者节点表
// 2患者节点表患者任务表
List<PatientVO> signPatientManageRouteNodes = homePageMapper.selectSignPatientManageRouteNode(patientIdList);
if (CollectionUtils.isEmpty(signPatientManageRouteNodes)) {
return;
@ -73,6 +75,7 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
List<PatientVO> patientVOList = new ArrayList<>();
//发送消息到期节点id集合
List<Long> expiredManageRouteNodeIds = new ArrayList<>();
//2.1 开始遍历患者任务,组装数据
for (PatientVO signPatientManageRouteNode : signPatientManageRouteNodes) {
//判断推送状态
if (Objects.isNull(signPatientManageRouteNode.getAppletPushSign()) || signPatientManageRouteNode.getAppletPushSign() != 1) {
@ -93,6 +96,7 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
boolean before = localDate.isBefore(LocalDate.now()) || localDate.isEqual(LocalDate.now());
if (before) {
long until = localDate.until(LocalDate.now(), ChronoUnit.DAYS);
//已过期 任务
if (until >= pushMessageRestrictions.getTime()) {
expiredManageRouteNodeIds.add(signPatientManageRouteNode.getSignPatientManageRouteNodeId());
continue;
@ -100,10 +104,11 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
signPatientManageRouteNode.setOpenId(patientVO.getOpenId());
//转换成中文
signPatientManageRouteNode.setRouteNodeName(RouteNodeNameEnum.getNameByInfo(signPatientManageRouteNode.getRouteNodeName()).getName());
//待发送 任务列表
patientVOList.add(signPatientManageRouteNode);
}
}
//更改过期执行状态
//2.2 对过期的任务更改过期执行状态
if (CollectionUtils.isNotEmpty(expiredManageRouteNodeIds)) {
signPatientManageRouteNodeMapper.updateNodeExecuteStatusByIds(expiredManageRouteNodeIds, NodeExecuteStatusEnum.EXECUTED.getInfo(), NodeExecuteResultStatusEnum.EXPIRED.getInfo(), null, null);
}
@ -157,14 +162,18 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
if (CollectionUtils.isEmpty(patientVOList)) {
return;
}
//节点推送数量
List<Long> collect = patientVOList.stream().filter(Objects::nonNull).map(PatientVO::getSignPatientManageRouteNodeId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
//2.3 节点推送数量用于判断失败次数若达到最大值则认为失败
List<Long> collect = patientVOList.stream().filter(Objects::nonNull).map(PatientVO::getSignPatientManageRouteNodeId)
.filter(Objects::nonNull).distinct().collect(Collectors.toList());
//RecordNummanageRouteNodeId任务IDnum已推送次数
List<RecordNum> recordNums = subscribeMessageSendRecordMapper.selectRecordCountByManageRouteNodeIds(collect);
//发送成功id集合
List<Long> signPatientManageRouteNodeIds = new ArrayList<>();
//发送失败
List<Long> failSignPatientManageRouteNodeIds = new ArrayList<>();
Set<Long> patientIdSet = new HashSet<>();
//3----------开始推送------------//
for (PatientVO patientVO : patientVOList) {
// 开始推送消息
Integer integer = weChatOfficialAccountUtils.sendAppletTemplateMessage(patientVO);
@ -180,6 +189,7 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
subscribeMessageSendRecord.setErrorCode(integer);
subscribeMessageSendRecord.setErrorStatus(ErrorStatusEnum.fail.getValue());
RecordNum recordNum = recordNums.stream().filter(Objects::nonNull).filter(item -> Objects.nonNull(item.getManageRouteNodeId()) && item.getManageRouteNodeId().equals(patientVO.getSignPatientManageRouteNodeId())).findFirst().orElse(new RecordNum());
//若已推送次数达到 配置的 最大次数则认为失败
if (Objects.nonNull(recordNum.getNum()) && recordNum.getNum() >= pushMessageRestrictions.getNumber()) {
failSignPatientManageRouteNodeIds.add(patientVO.getSignPatientManageRouteNodeId());
}
@ -191,17 +201,20 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
subscribeMessageSendRecord.setAppletId(weChatAppletChatConfig.getAppletId());
subscribeMessageSendRecord.setTemplateId(weChatAppletChatConfig.getHealthyPropagandaId());
subscribeMessageSendRecord.setCreateTime(LocalDateTime.now());
//3.1 托送记录入库
subscribeMessageSendRecordMapper.insertSubscribeMessageSendRecord(subscribeMessageSendRecord);
}
//更改成功执行状态
//4更改成功执行状态
if (CollectionUtils.isNotEmpty(signPatientManageRouteNodeIds)) {
signPatientManageRouteNodeMapper.updateNodeExecuteStatusByIds(signPatientManageRouteNodeIds, NodeExecuteStatusEnum.EXECUTED.getInfo(), NodeExecuteResultStatusEnum.SUCCESS.getInfo(), null, null);
}
//更改失败执行状态
//4.2 更改失败执行状态
if (CollectionUtils.isNotEmpty(failSignPatientManageRouteNodeIds)) {
signPatientManageRouteNodeMapper.updateNodeExecuteStatusByIds(failSignPatientManageRouteNodeIds, NodeExecuteStatusEnum.EXECUTED.getInfo(), NodeExecuteResultStatusEnum.FAILURE.getInfo(), null, null);
}
// 患者任务统计表修改
//5 患者任务统计表修改
if (CollectionUtils.isNotEmpty(patientIdSet)) {
patientTaskStatisticsService.updateNum(new ArrayList<>(patientIdSet));
}