加注释

This commit is contained in:
zhuangyuanke 2024-11-04 15:57:32 +08:00
parent 87175fac69
commit 984eb00163

View File

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