diff --git a/postdischarge-common/src/main/java/com/xinelu/common/constant/Constants.java b/postdischarge-common/src/main/java/com/xinelu/common/constant/Constants.java index 4707cd62..a4b39c7e 100644 --- a/postdischarge-common/src/main/java/com/xinelu/common/constant/Constants.java +++ b/postdischarge-common/src/main/java/com/xinelu/common/constant/Constants.java @@ -264,6 +264,11 @@ public class Constants { */ public static final String OFFICIAL_ACCOUNT_TEMPLATE_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="; + /** + * 微信小程序模板消息推送发送接口地址 + */ + public static final String OFFICIAL_ACCOUNT_SUBSCRIBE_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="; + /** * 获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口 */ @@ -294,6 +299,11 @@ public class Constants { */ public static final int ARGUMENT_INVALID = 47003; + /** + * api功能未授权 + */ + public static final int API_UNAUTHORIZED = 48001; + /** * 成功 */ diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/controller/homepage/HomePageController.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/controller/homepage/HomePageController.java index 8baa2adb..6c5c8603 100644 --- a/postdischarge-mobile/src/main/java/com/xinelu/mobile/controller/homepage/HomePageController.java +++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/controller/homepage/HomePageController.java @@ -82,4 +82,12 @@ public class HomePageController extends BaseController { private TableDataInfo satisfactionQuestionnaire(Long residentId) { return homePageService.satisfactionQuestionnaire(residentId); } + + /** + * 微信小程序消息通知跳转页面 + */ + @GetMapping("/subscriptionMessage") + public AjaxResult subscriptionMessage(Long id){ + return homePageService.subscriptionMessage(id); + } } \ No newline at end of file diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/homepage/HomePageService.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/homepage/HomePageService.java index ffb89cbb..5ac77c2e 100644 --- a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/homepage/HomePageService.java +++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/homepage/HomePageService.java @@ -6,7 +6,6 @@ import com.xinelu.manage.domain.patienttaskexecuterecord.PatientTaskExecuteRecor import com.xinelu.manage.domain.scriptInfo.ScriptInfo; import com.xinelu.manage.dto.patientquestionsubmitresult.PatientQuestionSubmitResultDTO; import com.xinelu.mobile.vo.myfollowup.MyFollowUpVO; -import com.xinelu.mobile.vo.satisfactionquestionnaire.SatisfactionQuestionnaire; import java.util.List; @@ -42,7 +41,7 @@ public interface HomePageService { * @param patientQuestionSubmitResultId 记录表id * @return AjaxResult */ - AjaxResult selectQuestionSubmit(Long patientQuestionSubmitResultId,Long patientTaskExecuteRecordId); + AjaxResult selectQuestionSubmit(Long patientQuestionSubmitResultId, Long patientTaskExecuteRecordId); /** * 问卷提交 @@ -67,4 +66,12 @@ public interface HomePageService { * @return SatisfactionQuestionnaire */ TableDataInfo satisfactionQuestionnaire(Long residentId); + + /** + * 微信小程序消息通知跳转页面 + * + * @param id 节点 + * @return AjaxResult + */ + AjaxResult subscriptionMessage(Long id); } \ No newline at end of file diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/homepage/Impl/HomePageServiceImpl.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/homepage/Impl/HomePageServiceImpl.java index caf652ad..d598e71c 100644 --- a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/homepage/Impl/HomePageServiceImpl.java +++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/homepage/Impl/HomePageServiceImpl.java @@ -26,6 +26,7 @@ import com.xinelu.manage.mapper.questioninfo.QuestionInfoMapper; import com.xinelu.manage.mapper.questionsubject.QuestionSubjectMapper; import com.xinelu.manage.mapper.questionsubjectoption.QuestionSubjectOptionMapper; import com.xinelu.manage.mapper.scriptInfo.ScriptInfoMapper; +import com.xinelu.manage.mapper.signpatientmanageroutenode.SignPatientManageRouteNodeMapper; import com.xinelu.manage.vo.questionInfo.QuestionVO; import com.xinelu.manage.vo.questionsubject.QuestionSubjectVO; import com.xinelu.manage.vo.questionsubjectoption.QuestionSubjectOptionVO; @@ -70,6 +71,8 @@ public class HomePageServiceImpl implements HomePageService { private PatientQuestionSubjectResultMapper patientQuestionSubjectResultMapper; @Resource private PatientQuestionOptionResultMapper patientQuestionOptionResultMapper; + @Resource + private SignPatientManageRouteNodeMapper signPatientManageRouteNodeMapper; /** * 我的随访列表 @@ -244,4 +247,18 @@ public class HomePageServiceImpl implements HomePageService { } return pageServiceUtil.getDataTable(satisfactionQuestionnaires); } + + /** + * 微信小程序消息通知跳转页面 + * + * @param id 节点 + * @return AjaxResult + */ + @Override + public AjaxResult subscriptionMessage(Long id) { + if (Objects.isNull(id)) { + return AjaxResult.error("该节点以清空!"); + } + return AjaxResult.success(signPatientManageRouteNodeMapper.selectSignPatientManageRouteNodeById(id)); + } } \ No newline at end of file diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/subscribemessagesendrecord/SubscribeMessageSendDataService.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/subscribemessagesendrecord/SubscribeMessageSendDataService.java deleted file mode 100644 index 1951a0eb..00000000 --- a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/subscribemessagesendrecord/SubscribeMessageSendDataService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.xinelu.mobile.service.subscribemessagesendrecord; - -/** - * @Description 订阅消息数据业务层 - * @Author zh - * @Date 2024-05-24 - */ -public interface SubscribeMessageSendDataService { - - void subscribeMessageSendDataTask(); -} \ No newline at end of file diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/subscribemessagesendrecord/impl/SubscribeMessageSendDataServiceImpl.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/subscribemessagesendrecord/impl/SubscribeMessageSendDataServiceImpl.java deleted file mode 100644 index b91e6e43..00000000 --- a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/subscribemessagesendrecord/impl/SubscribeMessageSendDataServiceImpl.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.xinelu.mobile.service.subscribemessagesendrecord.impl; - -import com.xinelu.common.config.WeChatAppletChatConfig; -import com.xinelu.common.enums.PatientTypeEnum; -import com.xinelu.common.enums.RouteNodeNameEnum; -import com.xinelu.common.enums.SubscribeStatusEnum; -import com.xinelu.mobile.mapper.homepage.HomePageMapper; -import com.xinelu.mobile.service.subscribemessagesendrecord.SubscribeMessageSendDataService; -import com.xinelu.mobile.utils.WeChatOfficialAccountUtils; -import com.xinelu.mobile.vo.wechatofficialaccountcallback.PatientVO; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -/** - * @Description 订阅消息数据实现层 - * @Author zh - * @Date 2024-05-24 - */ -@Service -@Slf4j -public class SubscribeMessageSendDataServiceImpl implements SubscribeMessageSendDataService { - - @Resource - private HomePageMapper homePageMapper; - @Resource - private WeChatAppletChatConfig weChatAppletChatConfig; - @Resource - private WeChatOfficialAccountUtils weChatOfficialAccountUtils; - - public void subscribeMessageSendDataTask() { - List patient = homePageMapper.selectResidentAndSubscribeMessageRecord(SubscribeStatusEnum.accept.getValue(), weChatAppletChatConfig.getSignTemplateId()); - List collect = patient.stream().filter(Objects::nonNull).map(PatientVO::getPatientId).filter(Objects::nonNull).collect(Collectors.toList()); - List signPatientManageRouteNodes = homePageMapper.selectSignPatientManageRouteNode(collect); - List patientVOS = new ArrayList<>(); - for (PatientVO signPatientManageRouteNode : signPatientManageRouteNodes) { - if (Objects.isNull(signPatientManageRouteNode.getAppletPushSign()) || signPatientManageRouteNode.getAppletPushSign() != 1) { - continue; - } - if (signPatientManageRouteNode.getRouteNodeName().equals(RouteNodeNameEnum.AFTER_DISCHARGE.getInfo()) || signPatientManageRouteNode.getRouteNodeName().equals(RouteNodeNameEnum.AFTER_VISIT_DISCHARGE.getInfo())) { - PatientVO patientVO = patient.stream().filter(Objects::nonNull).filter(item -> signPatientManageRouteNode.getPatientId().equals(item.getPatientId())).findFirst().orElse(new PatientVO()); - if (patientVO.getPatientType().equals(PatientTypeEnum.DISCHARGED_PATIENT.getInfo())) { - LocalDate localDate = patientVO.getDischargeTime().plusDays(signPatientManageRouteNode.getRouteNodeDay()); - boolean before = localDate.isEqual(LocalDate.now()); - if (before) { - patientVOS.add(signPatientManageRouteNode); - } - } - } - if (signPatientManageRouteNode.getRouteNodeName().equals(RouteNodeNameEnum.AFTER_ADMISSION.getInfo())) { - PatientVO patientVO = patient.stream().filter(Objects::nonNull).filter(item -> signPatientManageRouteNode.getPatientId().equals(item.getPatientId())).findFirst().orElse(new PatientVO()); - if (patientVO.getPatientType().equals(PatientTypeEnum.IN_HOSPITAL_PATIENT.getInfo())) { - LocalDate localDate = patientVO.getAdmissionTime().plusDays(signPatientManageRouteNode.getRouteNodeDay()); - boolean before = localDate.isEqual(LocalDate.now()); - if (before) { - patientVOS.add(signPatientManageRouteNode); - } - } - } - if (signPatientManageRouteNode.getRouteNodeName().equals(RouteNodeNameEnum.AFTER_CONSULTATION.getInfo()) || signPatientManageRouteNode.getRouteNodeName().equals(RouteNodeNameEnum.AFTER_VISIT_DISCHARGE.getInfo())) { - PatientVO patientVO = patient.stream().filter(Objects::nonNull).filter(item -> signPatientManageRouteNode.getPatientId().equals(item.getPatientId())).findFirst().orElse(new PatientVO()); - if (patientVO.getPatientType().equals(PatientTypeEnum.OUTPATIENT.getInfo()) && patientVO.getDischargeTime() == null) { - LocalDate localDate = patientVO.getVisitDate().plusDays(signPatientManageRouteNode.getRouteNodeDay()); - boolean before = localDate.isEqual(LocalDate.now()); - if (before) { - patientVOS.add(signPatientManageRouteNode); - } - } - } - } - for (PatientVO patientVO : patientVOS) { - weChatOfficialAccountUtils.sendOfficialAccountTemplateMessage(patientVO); - } - } -} diff --git a/postdischarge-mobile/src/main/resources/mapper/homepage/HomePageMapper.xml b/postdischarge-mobile/src/main/resources/mapper/homepage/HomePageMapper.xml index 576322be..daca4435 100644 --- a/postdischarge-mobile/src/main/resources/mapper/homepage/HomePageMapper.xml +++ b/postdischarge-mobile/src/main/resources/mapper/homepage/HomePageMapper.xml @@ -116,17 +116,21 @@ spmrn.task_subdivision, spmrn.applet_push_sign, spmrn.node_content, - spmrn.node_execute_status + spmrn.node_execute_status, + spmr.patient_id from sign_patient_manage_route_node spmrn LEFT JOIN sign_patient_manage_route spmr ON spmr.id = spmrn.manage_route_id LEFT JOIN patient_info pi ON pi.id = spmr.patient_id - spmr.patient_id in - - #{patientId} - - and node_execute_status = 'UNEXECUTED' - and del_flag = 0 + + spmr.patient_id in + + #{patientId} + + + and spmrn.node_execute_status = 'UNEXECUTED' + and spmrn.del_flag = 0 + and pi.del_flag = 0 \ No newline at end of file diff --git a/postdischarge-quartz/src/main/java/com/xinelu/quartz/controller/MessageSubscriptionController.java b/postdischarge-quartz/src/main/java/com/xinelu/quartz/controller/MessageSubscriptionController.java new file mode 100644 index 00000000..0904226d --- /dev/null +++ b/postdischarge-quartz/src/main/java/com/xinelu/quartz/controller/MessageSubscriptionController.java @@ -0,0 +1,30 @@ +package com.xinelu.quartz.controller; + +import com.xinelu.quartz.task.SubscribeTask; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 消息推送 + * + * @author xinelu + */ +@RestController +@RequestMapping("/monitor/messageSubscription") +public class MessageSubscriptionController { + + @Resource + private SubscribeTask subscribeTask; + + + /** + * 手动执行专病路径定时任务 + */ + @GetMapping("/signPatientManageRouteNode") + public void signPatientManageRouteNode() { + subscribeTask.automaticSendSignPatientManageRouteNodeTask(); + } +} diff --git a/postdischarge-quartz/src/main/java/com/xinelu/quartz/service/impl/subscribeTaskServiceImpl.java b/postdischarge-quartz/src/main/java/com/xinelu/quartz/service/impl/subscribeTaskServiceImpl.java index a77f02d4..d8d25949 100644 --- a/postdischarge-quartz/src/main/java/com/xinelu/quartz/service/impl/subscribeTaskServiceImpl.java +++ b/postdischarge-quartz/src/main/java/com/xinelu/quartz/service/impl/subscribeTaskServiceImpl.java @@ -1,21 +1,83 @@ package com.xinelu.quartz.service.impl; -import com.xinelu.mobile.service.subscribemessagesendrecord.SubscribeMessageSendDataService; +import com.xinelu.common.config.WeChatAppletChatConfig; +import com.xinelu.common.enums.PatientTypeEnum; +import com.xinelu.common.enums.RouteNodeNameEnum; +import com.xinelu.common.enums.SubscribeStatusEnum; +import com.xinelu.mobile.mapper.homepage.HomePageMapper; +import com.xinelu.mobile.utils.WeChatOfficialAccountUtils; +import com.xinelu.mobile.vo.wechatofficialaccountcallback.PatientVO; import com.xinelu.quartz.service.SubscribeTaskService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; @Service @Slf4j public class subscribeTaskServiceImpl implements SubscribeTaskService { @Resource - private SubscribeMessageSendDataService subscribeMessageSendRecordService; + private HomePageMapper homePageMapper; + @Resource + private WeChatAppletChatConfig weChatAppletChatConfig; + @Resource + private WeChatOfficialAccountUtils weChatOfficialAccountUtils; - @Override public void signPatientManageRouteNodeTask() { - subscribeMessageSendRecordService.subscribeMessageSendDataTask(); + List patient = homePageMapper.selectResidentAndSubscribeMessageRecord(SubscribeStatusEnum.accept.getValue(), weChatAppletChatConfig.getSignTemplateId()); + List collect = patient.stream().filter(Objects::nonNull).map(PatientVO::getPatientId).filter(Objects::nonNull).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(collect)) { + return; + } + List signPatientManageRouteNodes = homePageMapper.selectSignPatientManageRouteNode(collect); + List patientVOS = new ArrayList<>(); + for (PatientVO signPatientManageRouteNode : signPatientManageRouteNodes) { + if (Objects.isNull(signPatientManageRouteNode.getAppletPushSign()) || signPatientManageRouteNode.getAppletPushSign() != 1) { + continue; + } + if (signPatientManageRouteNode.getRouteNodeName().equals(RouteNodeNameEnum.AFTER_DISCHARGE.getInfo()) || signPatientManageRouteNode.getRouteNodeName().equals(RouteNodeNameEnum.AFTER_VISIT_DISCHARGE.getInfo())) { + PatientVO patientVO = patient.stream().filter(Objects::nonNull).filter(item -> signPatientManageRouteNode.getPatientId().equals(item.getPatientId())).findFirst().orElse(new PatientVO()); + if (patientVO.getPatientType().equals(PatientTypeEnum.DISCHARGED_PATIENT.getInfo())) { + LocalDate localDate = patientVO.getDischargeTime().plusDays(signPatientManageRouteNode.getRouteNodeDay()); + boolean before = localDate.isEqual(LocalDate.now()); + if (before) { + signPatientManageRouteNode.setOpenId(patientVO.getOpenId()); + patientVOS.add(signPatientManageRouteNode); + } + } + } + if (signPatientManageRouteNode.getRouteNodeName().equals(RouteNodeNameEnum.AFTER_ADMISSION.getInfo())) { + PatientVO patientVO = patient.stream().filter(Objects::nonNull).filter(item -> signPatientManageRouteNode.getPatientId().equals(item.getPatientId())).findFirst().orElse(new PatientVO()); + if (patientVO.getPatientType().equals(PatientTypeEnum.IN_HOSPITAL_PATIENT.getInfo())) { + LocalDate localDate = patientVO.getAdmissionTime().plusDays(signPatientManageRouteNode.getRouteNodeDay()); + boolean before = localDate.isEqual(LocalDate.now()); + if (before) { + signPatientManageRouteNode.setOpenId(patientVO.getOpenId()); + patientVOS.add(signPatientManageRouteNode); + } + } + } + if (signPatientManageRouteNode.getRouteNodeName().equals(RouteNodeNameEnum.AFTER_CONSULTATION.getInfo()) || signPatientManageRouteNode.getRouteNodeName().equals(RouteNodeNameEnum.AFTER_VISIT_DISCHARGE.getInfo())) { + PatientVO patientVO = patient.stream().filter(Objects::nonNull).filter(item -> signPatientManageRouteNode.getPatientId().equals(item.getPatientId())).findFirst().orElse(new PatientVO()); + if (patientVO.getPatientType().equals(PatientTypeEnum.OUTPATIENT.getInfo()) && patientVO.getDischargeTime() == null) { + LocalDate localDate = patientVO.getVisitDate().plusDays(signPatientManageRouteNode.getRouteNodeDay()); + boolean before = localDate.isEqual(LocalDate.now()); + if (before) { + signPatientManageRouteNode.setOpenId(patientVO.getOpenId()); + patientVOS.add(signPatientManageRouteNode); + } + } + } + } + for (PatientVO patientVO : patientVOS) { + weChatOfficialAccountUtils.sendOfficialAccountTemplateMessage(patientVO); + } } } diff --git a/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/SubscribeTask.java b/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/SubscribeTask.java index 92782468..f7becbd3 100644 --- a/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/SubscribeTask.java +++ b/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/SubscribeTask.java @@ -21,7 +21,7 @@ public class SubscribeTask { /** * 签约患者管理任务路径节点消息推送定时任务,每10分钟执行一次 */ - public void automaticSendGoodsOrderTask() { + public void automaticSendSignPatientManageRouteNodeTask() { log.info("开始执行签约患者管理任务路径节点推送定时任务......"); subscribeTaskService.signPatientManageRouteNodeTask(); log.info("完成订阅签约患者管理任务路径节点推送定时任务......");