feat: 实现妇幼随访按周期发送
- 新增妇幼随访计划、节点、发送日志表及 Mapper
- 支持 followupPeriod JSON 解析,按 plannedFollowTime 基准日排期
- 短信走云MAS,微信走 sendChatLs,独立于普通随访补偿链路
- 增加 1 天补发窗口、过期标记、失败重试及定时任务入口
- 补充功能说明、测试报告和本地库 DDL 实测记录
| | |
| | | !/sql/quartz.sql |
| | | !/sql/ry_20220822.sql |
| | | !/sql/pat_specific_archive_generate_config_lishui_mch_20261104.sql |
| | | !/sql/mch_followup_plan_20261117.sql |
| | | sql/_probe/ |
| | | *.log |
| | | _dbcheck.txt |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | # å¦å¹¼é访æå¨æåéåè½è¯´æ |
| | | |
| | | > çæ¬ï¼2026-11-17 |
| | | > éç¨æºæï¼ä¸½æ°´å¸å¦å¹¼ä¿å¥é¢ `orgid = 47226079133110211G1001` |
| | | > å
³è模åï¼`smartor`ã`ruoyi-quartz` |
| | | > å
³è表ï¼`mch_followup_plan`ã`mch_followup_plan_item`ã`mch_followup_send_log` |
| | | |
| | | --- |
| | | |
| | | ## ä¸ãåè½ç®æ |
| | | |
| | | å¦å¹¼ä¸ç§æ¡£æ¡ï¼å¦ä¿/å¿ä¿ï¼ç»´æ¤äºï¼ |
| | | |
| | | - `plannedFollowTime`ï¼æ´ä¸ªéè®¿å¨æç**åºåæ¥** |
| | | - `followupPeriod`ï¼JSON æ ¼å¼çéè®¿å¨æï¼å
å«åéæ¹å¼ãåéå
容ãåé天æ°ç |
| | | |
| | | ç³»ç»æè¿ä¸¤ä¸ªå段çæå¦å¹¼ä¸ç¨çåé计åï¼å¹¶å¨å°ææ¶ï¼ |
| | | |
| | | - çä¿¡ï¼è°ç¨ä¸å½ç§»å¨äºMAS `SmsUtils.sendYunMasSms` |
| | | - 微信ï¼è°ç¨ `SmsUtils.sendChatLs`ï¼å³ `/sms/sendChatFuyou` çå
é¨å®ç°ï¼ |
| | | |
| | | å¦å¹¼é访**ä¸è¿å
¥**æ®éé访ç `service_subtask_preachform` / `compensateTask` è¡¥å¿é¾è·¯ï¼é¿å
ä¸éç¨é访äºç¸å½±åã |
| | | |
| | | --- |
| | | |
| | | ## äºãæ¶é´å£å¾ |
| | | |
| | | ### 2.1 åºåæ¥ |
| | | |
| | | `plannedFollowTime` æ¯æ´ä¸ªå¨æçåºåæ¥ï¼ææèç¹é½ä»¥å®è®¡ç®ï¼ |
| | | |
| | | ```text |
| | | èç¹åéæ¶é´ = plannedFollowTime çæ¥æ + item.dayOffset 天 + æ¶åç§ |
| | | ``` |
| | | |
| | | **䏿¯**âä¸ä¸æ¬¡åéå顺延âï¼èæ¯åºå®ä»åºåæ¥ææã |
| | | |
| | | ### 2.2 æ¶åç§è§å |
| | | |
| | | ä¼å
çº§ï¼ |
| | | |
| | | 1. `item.sendTime` æå¼ â ä½¿ç¨ `item.sendTime`ï¼ |
| | | 2. å¦åï¼`plannedFollowTime` çæ¶åç§ä¸æ¯ `00:00:00` â æ²¿ç¨ `plannedFollowTime` çæ¶åç§ï¼ |
| | | 3. å¦åé»è®¤ `09:00`ã |
| | | |
| | | å¦æç¡®å®éè¦é¶ç¹åéï¼å¿
é¡»æ¾å¼é
ç½®ï¼ |
| | | |
| | | ```json |
| | | {"sendTime": "00:00"} |
| | | ``` |
| | | |
| | | ### 2.3 ç¤ºä¾ |
| | | |
| | | `plannedFollowTime = 2026-11-20 14:30:00` |
| | | |
| | | | dayOffset | sendTime | å®é
åéæ¶é´ | |
| | | |---|---|---| |
| | | | 0 | 空 | 2026-11-20 14:30:00 | |
| | | | 3 | 空 | 2026-11-23 14:30:00 | |
| | | | 7 | 09:00 | 2026-11-27 09:00:00 | |
| | | |
| | | `plannedFollowTime = 2026-11-20 00:00:00` |
| | | |
| | | | dayOffset | sendTime | å®é
åéæ¶é´ | |
| | | |---|---|---| |
| | | | 0 | 空 | 2026-11-20 09:00:00 | |
| | | | 3 | 空 | 2026-11-23 09:00:00 | |
| | | |
| | | --- |
| | | |
| | | ## ä¸ãfollowupPeriod JSON æ ¼å¼ |
| | | |
| | | `followup_period` å·²ç± `varchar(100)` æ©å±ä¸º `TEXT`ã |
| | | |
| | | ### 3.1 æ¾å¼èç¹ï¼æ¨èï¼ |
| | | |
| | | ```json |
| | | { |
| | | "version": 1, |
| | | "items": [ |
| | | { |
| | | "seq": 1, |
| | | "dayOffset": 0, |
| | | "sendTime": "09:00", |
| | | "sendType": "sms", |
| | | "content": "æ¨å¥½${patname}ï¼è¯·æè®¡åå¤è¯ã" |
| | | }, |
| | | { |
| | | "seq": 2, |
| | | "dayOffset": 3, |
| | | "sendTime": "09:00", |
| | | "sendType": "wechat", |
| | | "templateId": 16, |
| | | "titleName": "è¯åé访æé", |
| | | "content": "æ¨å¥½${patname}ï¼è¯·æè®¡åå¤è¯ã", |
| | | "url": "https://example.com/followup" |
| | | }, |
| | | { |
| | | "seq": 3, |
| | | "dayOffset": 7, |
| | | "sendType": "sms", |
| | | "content": "æ¨å¥½${patname}ï¼è¯·ææ¶å¤è¯ã" |
| | | } |
| | | ] |
| | | } |
| | | ``` |
| | | |
| | | åæ®µï¼ |
| | | |
| | | | åæ®µ | å¿
å¡« | 说æ | |
| | | |---|---|---| |
| | | | `seq` | å¦ | èç¹é¡ºåºï¼ç¼ºçææ°ç»é¡ºåº 1..N | |
| | | | `dayOffset` | æ¯ | ç¸å¯¹ `plannedFollowTime` çç»å¯¹å¤©æ°ï¼å¿
须 ⥠0 | |
| | | | `sendTime` | å¦ | `HH:mm` æ `HH:mm:ss` | |
| | | | `sendType` | æ¯ | `sms` / `wechat`ï¼å
¼å®¹ `4` / `5`ã`çä¿¡` / `å
¬ä¼å·` / `微信` | |
| | | | `content` | çä¿¡å¿
å¡« | çä¿¡æ£æï¼å¾®ä¿¡æ£æå¯é | |
| | | | `templateId` | å¦ | å¾®ä¿¡æ¨¡æ¿ ID | |
| | | | `titleName` | å¦ | 微信æ é¢ | |
| | | | `url` | å¦ | 微信跳转å°å | |
| | | |
| | | çä¿¡èç¹å¦æ `content` 为空ä¼è§£æå¤±è´¥ï¼è®¡åè¿å
¥âå¾
è¡¥å
/é
ç½®å¼å¸¸âç¶æã |
| | | |
| | | ### 3.2 é´é + æ¬¡æ° |
| | | |
| | | ```json |
| | | { |
| | | "intervalDays": 3, |
| | | "count": 4, |
| | | "sendTime": "09:00", |
| | | "sendType": "sms", |
| | | "content": "æ¨å¥½${patname}ï¼è¯·æè®¡åå¤è¯ã" |
| | | } |
| | | ``` |
| | | |
| | | è¡¨ç¤ºï¼ |
| | | |
| | | ```text |
| | | 第1次ï¼åºåæ¥ + 0天 |
| | | 第2次ï¼åºåæ¥ + 3天 |
| | | 第3次ï¼åºåæ¥ + 6天 |
| | | 第4次ï¼åºåæ¥ + 9天 |
| | | ``` |
| | | |
| | | `count` ç¼ºçæ¶å¯ç¨ `followupCycleTimes` å
åºã |
| | | |
| | | ### 3.3 days æ°ç» |
| | | |
| | | ```json |
| | | { |
| | | "days": [0, 7, 14], |
| | | "sendType": "sms", |
| | | "content": "æ¨å¥½${patname}ï¼è¯·æè®¡åå¤è¯ã" |
| | | } |
| | | ``` |
| | | |
| | | 表示åºåæ¥ + 0/7/14 天ã |
| | | |
| | | --- |
| | | |
| | | ## åãè¡¥åçªå£ |
| | | |
| | | åªè¡¥å **1 天å
**å°æçèç¹ï¼ |
| | | |
| | | | æ¡ä»¶ | å¤ç | |
| | | |---|---| |
| | | | `send_time > now` | å¾
åé | |
| | | | `now - 24å°æ¶ <= send_time <= now` | è¡¥å | |
| | | | `send_time < now - 24å°æ¶` | æ è®°âè¿æâï¼ä¸ååé | |
| | | |
| | | è¿æèç¹ç¶æä¸º `4`ï¼ä¸ä¼ç»æ£è
åéè¿æ¶æ¶æ¯ã |
| | | |
| | | --- |
| | | |
| | | ## äºã计åç¶æä¸èç¹ç¶æ |
| | | |
| | | ### 5.1 计åç¶æ `mch_followup_plan.plan_status` |
| | | |
| | | | å¼ | å«ä¹ | |
| | | |---|---| |
| | | | 0 | ææ | |
| | | | 1 | 已忶ï¼é建æ¶åæ¶æ§è®¡åï¼ | |
| | | | 2 | å·²å®æï¼æ å¾
åé/åéä¸èç¹ï¼ | |
| | | | 3 | å¾
è¡¥å
/é
ç½®å¼å¸¸ï¼æé访æ¶é´ä¸ºç©ºãJSON éæ³çï¼ | |
| | | |
| | | ### 5.2 èç¹ç¶æ `mch_followup_plan_item.send_status` |
| | | |
| | | | å¼ | å«ä¹ | |
| | | |---|---| |
| | | | 0 | å¾
åé | |
| | | | 1 | åéä¸ | |
| | | | 2 | æå | |
| | | | 3 | 失败ï¼éè¯èå°½ï¼ | |
| | | | 4 | è¿æï¼è¶
è¿ 1 天补åçªå£ï¼ | |
| | | | 5 | åæ¶ | |
| | | | 6 | è·³è¿ï¼ææºå·ä¸ºç©ºçï¼ | |
| | | |
| | | --- |
| | | |
| | | ## å
ãæ´ä½æµç¨ |
| | | |
| | | ### 6.1 æ¡£æ¡ä¿ååèªå¨é建计å |
| | | |
| | | 以ä¸å
¥å£ä¿åæ¡£æ¡åé½ä¼è°ç¨ `IMchFollowupPlanService.rebuildForArchive`ï¼ |
| | | |
| | | - `PatMaternityArchiveServiceImpl.insertOrUpdateMaternityArchive` |
| | | - `PatChildArchiveServiceImpl.insertOrUpdateChildArchive` |
| | | |
| | | èªå¨æ¡£æ¡çæï¼é¨è¯æ¥è¯å®æãä½é¢éè®¿å®æï¼ä¹èµ°è¿ä¸¤ä¸ª Serviceï¼å æ¤åæ ·ä¼è§¦åã |
| | | |
| | | é建è§åï¼ |
| | | |
| | | 1. åªå¤ç丽水å¦å¹¼ï¼ |
| | | 2. `plannedFollowTime` 为空 â çæâå¾
è¡¥å
â计åï¼ä¸çæèç¹ï¼ |
| | | 3. `followupPeriod` éæ³ â çæâé
ç½®å¼å¸¸â计åï¼ä¸çæèç¹ï¼ |
| | | 4. åºåæ¥/JSON æªåå â åªå·æ°è系人信æ¯ï¼ä¸éå¤çæèç¹ï¼ |
| | | 5. åºåæ¥/JSON åå â åæ¶æ§è®¡å䏿ªåéèç¹ï¼çææ°è®¡ååæ°èç¹ï¼ |
| | | 6. å·²æå/å·²è¿æ/已失败èç¹ä¿çåå²ã |
| | | |
| | | ### 6.2 宿¶åé |
| | | |
| | | `RyTask.sendMchFollowup()`ï¼ |
| | | |
| | | ```text |
| | | æ¥è¯¢ send_status=0 |
| | | and send_time <= now |
| | | and (next_retry_time is null or next_retry_time <= now) |
| | | and plan.plan_status=0 |
| | | and plan.orgid=丽水å¦å¹¼ |
| | | â éæ¡å¤æè¡¥åçªå£ |
| | | â çä¿¡/微信åé |
| | | â ååéæ¥å¿ |
| | | â æ´æ°èç¹ç¶æ |
| | | â æ å¾
åéèç¹æ¶è®¡åç½®ä¸ºå®æ |
| | | ``` |
| | | |
| | | ### 6.3 å岿°æ®è¡¥è®¡å |
| | | |
| | | `RyTask.generateMchFollowupPlan()`ï¼ |
| | | |
| | | ```text |
| | | æ«æå·²æå¦ä¿/å¿ä¿æ¡£æ¡è¯¦æ
|
| | | planned_follow_time é空 |
| | | followup_period é空 |
| | | â 补建计å |
| | | ``` |
| | | |
| | | --- |
| | | |
| | | ## ä¸ãçä¿¡å微信åé |
| | | |
| | | ### 7.1 çä¿¡ï¼äºMAS |
| | | |
| | | ```java |
| | | String configJson = sysConfigService.selectConfigByKey("ls.msg.yunmas", orgid); |
| | | SmsUtils.YunMasConfig config = SmsUtils.YunMasConfig.of(configJson); |
| | | SmsUtils.SmsResult result = SmsUtils.sendYunMasSms(config, phone, content); |
| | | ``` |
| | | |
| | | æåå¤å®ï¼`result.isOk()`ï¼å³ `success=true` ä¸ `rspcod=success`ã |
| | | |
| | | çä¿¡å
容ä¸è¦æå·¥æ¼ãç¾åãï¼äºMAS 伿 ¹æ® `sign` ç¼ç èªå¨è¿½å ã |
| | | |
| | | ### 7.2 微信ï¼sendChatLs |
| | | |
| | | ```java |
| | | String configJson = sysConfigService.selectConfigByKey("ls.wx.fuyou", orgid); |
| | | SmsUtils.LsWxConfig config = SmsUtils.LsWxConfig.of(configJson); |
| | | |
| | | SmsUtils.LsWxMessage message = new SmsUtils.LsWxMessage(); |
| | | message.setId(templateId); |
| | | message.setPatientId(String.valueOf(patid)); |
| | | message.setPatientName(patname); |
| | | message.setIdCard(idcardno); |
| | | message.setMobile(phone); |
| | | message.setMedCardNo(sourceBizNo); |
| | | message.setTitleName(titleName); |
| | | message.setContent(content); |
| | | message.setUrl(url); |
| | | |
| | | String resp = SmsUtils.sendChatLs(config, message); |
| | | ``` |
| | | |
| | | æåå¤å®ï¼ååº JSON `code == 0`ã |
| | | |
| | | `ls.wx.fuyou` æªé
ç½®æ¶ï¼`LsWxConfig.of(null)` 使ç¨å
ç½®ç丽水å¦å¹¼é»è®¤é
ç½®ï¼ä¸ `/sms/sendChatFuyou` ä¸è´ï¼ã |
| | | |
| | | --- |
| | | |
| | | ## å
«ãéè¯è§å |
| | | |
| | | - åèç¹å¤±è´¥åæå¤éè¯ 3 æ¬¡ï¼ |
| | | - æ¯æ¬¡éè¯é´é 10 åéï¼ |
| | | - éè¯æ¬¡æ°è¾¾å°ä¸éå置为â失败âï¼ |
| | | - 失败ä¸ä¼èªå¨åæ¢çä¿¡/微信ééï¼ |
| | | - å¦éééé级ï¼åºå¨ `followupPeriod` 䏿¾å¼é
ç½®å¦ä¸ä¸ªèç¹ï¼è䏿¯å¤ç¨æ®éé访补å¿ã |
| | | |
| | | --- |
| | | |
| | | ## ä¹ãé¨ç½²æ¥éª¤ |
| | | |
| | | ### 9.1 æ§è¡ SQL |
| | | |
| | | ```text |
| | | sql/mch_followup_plan_20261117.sql |
| | | ``` |
| | | |
| | | > 2026-11-17 已卿¬å°/å¼ååº `smartor_lishui`ï¼MySQL 5.7.34ï¼æ§è¡éè¿ï¼ |
| | | > æ§è¡åè¡¨ç»æå¤ä»½è§ `target/ddlcheck/backup-before-20261117.sql`ã |
| | | |
| | | å
å«ï¼ |
| | | |
| | | - `followup_period` æ©å±ä¸º `TEXT`ï¼ |
| | | - `mch_followup_plan`ï¼ |
| | | - `mch_followup_plan_item`ï¼ |
| | | - `mch_followup_send_log`ã |
| | | |
| | | ### 9.2 é
ç½®å®æ¶ä»»å¡ |
| | | |
| | | å¨âç³»ç»ç®¡ç â 宿¶ä»»å¡âæ°å¢ï¼ |
| | | |
| | | | ç¨é | è°ç¨ç®æ | 建议é¢ç | |
| | | |---|---|---| |
| | | | å岿¡£æ¡è¡¥è®¡å | `ryTask.generateMchFollowupPlan()` | æ¯å¤©ä¸æ¬¡ | |
| | | | å¦å¹¼é访åé | `ryTask.sendMchFollowup()` | æ¯ 5 åé | |
| | | |
| | | 建议åªå¨ `server.port=8095` èç¹æ§è¡ï¼å¹¶è®¾ç½®âç¦æ¢å¹¶åâã |
| | | |
| | | ### 9.3 é
ç½®åæ° |
| | | |
| | | | é
ç½® key | 说æ | 缺ç | |
| | | |---|---|---| |
| | | | `mch.followup.enabled` | å¦å¹¼é访å¼å
³ | 缺çè§ä¸º `true` | |
| | | | `ls.msg.yunmas` | äºMAS é
ç½® JSON | ä½¿ç¨ `SmsUtils` å
ç½®é»è®¤ | |
| | | | `ls.wx.fuyou` | 丽水å¦å¹¼å¾®ä¿¡é
ç½® JSON | ä½¿ç¨ `SmsUtils` å
ç½®é»è®¤ | |
| | | |
| | | --- |
| | | |
| | | ## åãä»£ç æ¸
å |
| | | |
| | | ### æ°å¢ |
| | | |
| | | ```text |
| | | smartor/src/main/java/com/smartor/common/MchFollowupConstants.java |
| | | smartor/src/main/java/com/smartor/domain/MchFollowupPlan.java |
| | | smartor/src/main/java/com/smartor/domain/MchFollowupPlanItem.java |
| | | smartor/src/main/java/com/smartor/domain/MchFollowupSendLog.java |
| | | smartor/src/main/java/com/smartor/domain/MchFollowupNode.java |
| | | smartor/src/main/java/com/smartor/domain/MchFollowupArchiveCandidate.java |
| | | smartor/src/main/java/com/smartor/mapper/MchFollowupPlanMapper.java |
| | | smartor/src/main/java/com/smartor/mapper/MchFollowupPlanItemMapper.java |
| | | smartor/src/main/java/com/smartor/mapper/MchFollowupSendLogMapper.java |
| | | smartor/src/main/java/com/smartor/service/mch/* |
| | | smartor/src/main/resources/mapper/smartor/MchFollowupPlanMapper.xml |
| | | smartor/src/main/resources/mapper/smartor/MchFollowupPlanItemMapper.xml |
| | | smartor/src/main/resources/mapper/smartor/MchFollowupSendLogMapper.xml |
| | | sql/mch_followup_plan_20261117.sql |
| | | ``` |
| | | |
| | | ### ä¿®æ¹ |
| | | |
| | | ```text |
| | | PatMaternityArchiveServiceImpl æ¡£æ¡ä¿ååé建计å |
| | | PatChildArchiveServiceImpl æ¡£æ¡ä¿ååé建计å |
| | | PatSpecificArchiveGenerateServiceImpl æ¡£æ¡çææ¶åå
¥ plannedFollowTime |
| | | RyTask æ°å¢ generateMchFollowupPlan / sendMchFollowup |
| | | ``` |
| | | |
| | | --- |
| | | |
| | | ## åä¸ã注æäºé¡¹ |
| | | |
| | | 1. `plannedFollowTime` å¿
é¡»æå¼ï¼å¦åä¸ä¼èªå¨åéï¼ |
| | | 2. èªå¨çæçå¦å¹¼æ¡£æ¡ä¼ä¼å
å `pat_med_outhosp.fudate` / `pat_med_inhosp.fudate` ä½ä¸º `plannedFollowTime`ï¼ |
| | | 3. è¿æèç¹ä¸åéï¼åªè¡¥å 1 天å
èç¹ï¼ |
| | | 4. å¦å¹¼è®¡åä¸è¿å
¥æ®éé访补å¿é¾è·¯ï¼ |
| | | 5. åªå¯¹ `orgid=47226079133110211G1001` çæï¼ |
| | | 6. 建议åéä»»å¡åèç¹æ§è¡ï¼é¿å
éå¤åéï¼ |
| | | 7. äºMAS/微信é
ç½®é误æ¶åªå½±å对åºèç¹ï¼ä¸å½±åå
¶ä»èç¹ã |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | # å¦å¹¼é访æå¨æåéæµè¯æ¥å |
| | | |
| | | > æµè¯æ¥æï¼2026-11-17 |
| | | > æµè¯æ¨¡åï¼`smartor`ã`ruoyi-quartz` |
| | | > æµè¯ç¯å¢ï¼Windows 10 / Git Bash / JDK 21.0.12 / Maven 3.9.9 |
| | | > æµè¯æ¹å¼ï¼çº¯ main èªæ£ï¼ä¸ä¾èµ JUnitãSpring 容å¨ãæ°æ®åºãç¬¬ä¸æ¹çä¿¡/微信æ¥å£ï¼ |
| | | |
| | | --- |
| | | |
| | | ## ä¸ãæµè¯ç»è®º |
| | | |
| | | | æµè¯å¥ä»¶ | ç¨ä¾æ° | éè¿ | 失败 | |
| | | |---|---:|---:|---:| |
| | | | `MchFollowupLogicCheck` | 40 | 40 | 0 | |
| | | | `MchFollowupPlanServiceCheck` | 19 | 19 | 0 | |
| | | | `MchFollowupSendServiceCheck` | 18 | 18 | 0 | |
| | | | **å计** | **77** | **77** | **0** | |
| | | |
| | | ç»è®ºï¼**æ ¸å¿é»è¾æµè¯å
¨é¨éè¿ã** |
| | | |
| | | è¡¥å
ï¼DDL 已卿¬å°/å¼ååº `smartor_lishui`ï¼MySQL 5.7.34ï¼å®é
æ§è¡éè¿ï¼ |
| | | 详è§âäºãæ¬å°æ°æ®åº DDL 宿µâã |
| | | |
| | | å¦å¤å·²æ§è¡ï¼ |
| | | |
| | | ```bash |
| | | mvn -q -DskipTests compile |
| | | mvn -q -pl smartor -am -DskipTests test-compile |
| | | ``` |
| | | |
| | | å
¨æ¨¡åç¼è¯éè¿ï¼`smartor` æµè¯ä»£ç ç¼è¯éè¿ã |
| | | |
| | | --- |
| | | |
| | | ## äºãæµè¯èå´ |
| | | |
| | | ### 2.1 `MchFollowupLogicCheck` |
| | | |
| | | è¦çï¼ |
| | | |
| | | 1. `items` JSON è§£æï¼ |
| | | 2. `intervalDays + count` è§£æï¼ |
| | | 3. `intervalDays + followupCycleTimes` å
åºï¼ |
| | | 4. `days` æ°ç»è§£æï¼ |
| | | 5. éæ³ JSONã空èç¹ãéæ³ `sendType`ãç信缺 `content`ãéæ³ `sendTime`ï¼ |
| | | 6. åºåæ¥æ¶é´è®¡ç®ï¼ |
| | | - `plannedFollowTime` 带æ¶åç§æ¶æ²¿ç¨ï¼ |
| | | - `item.sendTime` è¦çï¼ |
| | | - åºåæ¥ `00:00:00` é»è®¤ `09:00`ï¼ |
| | | 7. 1 天补åçªå£ï¼ |
| | | - æªæ¥èç¹å¾
åéï¼ |
| | | - 1 å°æ¶å
è¡¥åï¼ |
| | | - æ°å¥½ 24 å°æ¶è¡¥åï¼ |
| | | - è¶
è¿ 24 å°æ¶è¿æï¼ |
| | | 8. èç¹ç»è£
ï¼ |
| | | 9. 3 个æ°å¢ Mapper XML å¯è§£æï¼ |
| | | 10. DDL èæ¬åå¨ã |
| | | |
| | | ### 2.2 `MchFollowupPlanServiceCheck` |
| | | |
| | | 使ç¨å¨æä»£ç模æ Mapper å `ISysConfigService`ï¼è¦çï¼ |
| | | |
| | | 1. å¦ä¿è®¡åçæï¼çæ 3 个èç¹ï¼ |
| | | 2. èç¹æ¶é´æ `plannedFollowTime + dayOffset` 计ç®ï¼ |
| | | 3. ç¸ååºåæ¥å卿æ¶å¹çï¼ä¸éå¤çæï¼ |
| | | 4. `plannedFollowTime` 为空æ¶çæâå¾
è¡¥å
â计åï¼ä¸çæèç¹ï¼ |
| | | 5. å¿ä¿æ¡£æ¡ä½¿ç¨ `parentPhone` å
åºï¼ |
| | | 6. é丽水å¦å¹¼æºæä¸çæè®¡åã |
| | | |
| | | ### 2.3 `MchFollowupSendServiceCheck` |
| | | |
| | | 使ç¨å¨æä»£ç模æ Mapperï¼å¹¶è¦åæ¶æ¯åéå¨ï¼è¦çï¼ |
| | | |
| | | 1. çä¿¡åéæåï¼ |
| | | - èç¹ç¶æç½®ä¸ºæåï¼ |
| | | - åå
¥ç¬¬ä¸æ¹æ¶æ¯ IDï¼ |
| | | - åå鿥å¿ï¼ |
| | | - æ å¾
åéèç¹æ¶è®¡åç½®ä¸ºå®æï¼ |
| | | 2. è¶
è¿ 1 天èç¹ï¼ |
| | | - ä¸è°ç¨ `claimItem`ï¼ |
| | | - æ è®°è¿æï¼ |
| | | - ä¸åéï¼ |
| | | 3. 微信åéå¤±è´¥ï¼ |
| | | - ä¸è®¡æ°æåï¼ |
| | | - èç¹åå°å¾
åéï¼ |
| | | - éè¯æ¬¡æ° +1ï¼ |
| | | - çæä¸æ¬¡éè¯æ¶é´ã |
| | | |
| | | --- |
| | | |
| | | ## ä¸ãæ§è¡å½ä»¤ |
| | | |
| | | ### 3.1 ç¼è¯ |
| | | |
| | | ```bash |
| | | mvn -q -DskipTests compile |
| | | mvn -q -pl smartor -am -DskipTests test-compile |
| | | ``` |
| | | |
| | | ç»æï¼`exitCode=0`ã |
| | | |
| | | ### 3.2 çæä¾èµ classpath |
| | | |
| | | ```bash |
| | | mvn -q -pl smartor dependency:build-classpath \ |
| | | -Dmdep.outputFile=target/mch-cp.txt |
| | | ``` |
| | | |
| | | ### 3.3 æ§è¡èªæ£ |
| | | |
| | | ```bash |
| | | CP="smartor/target/classes;smartor/target/test-classes;$(cat smartor/target/mch-cp.txt)" |
| | | |
| | | java -Dfile.encoding=UTF-8 -cp "$CP" \ |
| | | com.smartor.service.mch.MchFollowupLogicCheck |
| | | |
| | | java -Dfile.encoding=UTF-8 -cp "$CP" \ |
| | | com.smartor.service.mch.MchFollowupPlanServiceCheck |
| | | |
| | | java -Dfile.encoding=UTF-8 -cp "$CP" \ |
| | | com.smartor.service.mch.MchFollowupSendServiceCheck |
| | | ``` |
| | | |
| | | ### 3.4 ç»ææè¦ |
| | | |
| | | ```text |
| | | MchFollowupLogicCheck PASS=40ï¼FAIL=0 |
| | | MchFollowupPlanServiceCheck PASS=19ï¼FAIL=0 |
| | | MchFollowupSendServiceCheck PASS=18ï¼FAIL=0 |
| | | ``` |
| | | |
| | | --- |
| | | |
| | | ## åãéç¹éªè¯ç»æ |
| | | |
| | | ### 4.1 æ¶é´è®¡ç® |
| | | |
| | | | åºæ¯ | ææ | å®é
| ç»æ | |
| | | |---|---|---|---| |
| | | | åºåæ¥ 14:30ï¼dayOffset=0ï¼æ sendTime | 14:30 | 14:30 | éè¿ | |
| | | | åºåæ¥ 14:30ï¼dayOffset=3ï¼æ sendTime | 第3天 14:30 | 第3天 14:30 | éè¿ | |
| | | | dayOffset=7ï¼sendTime=09:00 | 第7天 09:00 | 第7天 09:00 | éè¿ | |
| | | | åºåæ¥ 00:00ï¼æ sendTime | 09:00 | 09:00 | éè¿ | |
| | | |
| | | ### 4.2 è¡¥åçªå£ |
| | | |
| | | | åºæ¯ | ææ | å®é
| ç»æ | |
| | | |---|---|---|---| |
| | | | æªæ¥èç¹ | PENDING | PENDING | éè¿ | |
| | | | 1 å°æ¶å
å°æ | SEND | SEND | éè¿ | |
| | | | æ°å¥½ 24 å°æ¶ | SEND | SEND | éè¿ | |
| | | | è¶
è¿ 24 å°æ¶ | EXPIRED | EXPIRED | éè¿ | |
| | | |
| | | ### 4.3 计åçæ |
| | | |
| | | | åºæ¯ | ææ | å®é
| ç»æ | |
| | | |---|---|---|---| |
| | | | å¦ä¿ 3 èç¹ | 3 | 3 | éè¿ | |
| | | | ç¸ååºåæ¥/卿éå¤è°ç¨ | 0 | 0 | éè¿ | |
| | | | æé访æ¶é´ä¸ºç©º | 0 èç¹ï¼è®¡åå¾
è¡¥å
| ä¸è´ | éè¿ | |
| | | | å¿ä¿ä½¿ç¨ parentPhone | 13700000000 | 13700000000 | éè¿ | |
| | | | é丽水å¦å¹¼ | 0 | 0 | éè¿ | |
| | | |
| | | ### 4.4 åéç¶æ |
| | | |
| | | | åºæ¯ | ææ | å®é
| ç»æ | |
| | | |---|---|---|---| |
| | | | çä¿¡æå | èç¹ç¶æ 2 | 2 | éè¿ | |
| | | | è¶
è¿ 1 天 | èç¹ç¶æ 4 | 4 | éè¿ | |
| | | | 微信失败 | èç¹ç¶æ 0ï¼éè¯æ¬¡æ° 1 | ä¸è´ | éè¿ | |
| | | |
| | | --- |
| | | |
| | | ## äºãæ¬å°æ°æ®åº DDL 宿µ |
| | | |
| | | ### 5.1 æµè¯åº |
| | | |
| | | ä½¿ç¨ `application-druid.yml` å½åé
ç½®çæ¬å°/å¼ååºï¼ |
| | | |
| | | ```text |
| | | database = smartor_lishui |
| | | version = MySQL 5.7.34 |
| | | ``` |
| | | |
| | | æ§è¡åå·²èªå¨å¤ä»½åè¡¨ç»æï¼ |
| | | |
| | | ```text |
| | | target/ddlcheck/backup-before-20261117.sql |
| | | ``` |
| | | |
| | | ### 5.2 æ§è¡ç»æ |
| | | |
| | | æ§è¡èæ¬ï¼ |
| | | |
| | | ```text |
| | | sql/mch_followup_plan_20261117.sql |
| | | ``` |
| | | |
| | | å
± 6 æ¡ DDL è¯å¥ï¼å
¨é¨æ§è¡æåï¼ |
| | | |
| | | | åºå· | è¯å¥ | ç»æ | |
| | | |---|---|---| |
| | | | 1 | `pat_maternity_archive_detail.followup_period` â `TEXT` | æå | |
| | | | 2 | `pat_child_archive_detail.followup_period` â `TEXT` | æå | |
| | | | 3 | `pat_specific_archive_generate_config.followup_period` â `TEXT` | æå | |
| | | | 4 | å建 `mch_followup_plan` | æå | |
| | | | 5 | å建 `mch_followup_plan_item` | æå | |
| | | | 6 | å建 `mch_followup_send_log` | æå | |
| | | |
| | | ### 5.3 éªè¯ç»æ |
| | | |
| | | | éªè¯é¡¹ | ç»æ | |
| | | |---|---| |
| | | | 3 个 `followup_period` åæ®µç±»åå为 `TEXT` | éè¿ | |
| | | | `mch_followup_plan` åå¨ | éè¿ | |
| | | | `mch_followup_plan_item` åå¨ | éè¿ | |
| | | | `mch_followup_send_log` åå¨ | éè¿ | |
| | | | å¯ä¸ç´¢å¼ `uk_mch_plan_seq` åå¨ | éè¿ | |
| | | | 计å + èç¹ + æ¥å¿ DML åå
¥/å
³èæ¥è¯¢ | éè¿ | |
| | | | DML äºå¡åæ» | éè¿ | |
| | | | æµè¯æ°æ®æ¸
çåä¸å¼ æ°è¡¨è¡æ° | `0 / 0 / 0` | |
| | | |
| | | ### 5.4 åè¡¨æ°æ®æ£æ¥ |
| | | |
| | | æ§è¡ååç»è®¡ä¸è´ï¼ |
| | | |
| | | ```text |
| | | pat_maternity_archive_detail rows=4, max_followup_period_len=110 |
| | | pat_child_archive_detail rows=3, max_followup_period_len=0 |
| | | pat_specific_archive_generate_config rows=1, max_followup_period_len=2 |
| | | ``` |
| | | |
| | | 说æï¼ |
| | | |
| | | - æ¬æ¬¡æµè¯åºä¸ `followup_period` åæ¬å·²ç»æ¯ `TEXT`ï¼`MODIFY COLUMN` 为å¹çæä½ï¼ |
| | | - å
¶ä»ä»ä¸º `varchar(100)` çç¯å¢æ§è¡èæ¬æ¶ä¼æ£å¸¸æ©å±ä¸º `TEXT`ï¼ |
| | | - æµè¯æ°æ®å·²åæ»/æ¸
çï¼æ°è¡¨ä¸ºç©ºã |
| | | |
| | | --- |
| | | |
| | | ## å
ãæªè¦ç项 |
| | | |
| | | 以ä¸å
容æªå¨æ¬æ¬¡èªå¨åæµè¯ä¸è¦çï¼éè¦å¨æµè¯ç¯å¢è¡¥å
éªè¯ï¼ |
| | | |
| | | 1. **MyBatis XML ä¸ç宿°æ®åºç SQL å
¼å®¹æ§** |
| | | å·²æ§è¡ DDL å JDBC DMLï¼ä½æªéè¿ MyBatis æ§è¡ `selectDueItems`ã`selectCandidates`ã`updateSendResult` ç SQLã |
| | | å·²å XML å¯è§£ææ§æ£æ¥ï¼ä½æªè¿æ¥æ°æ®åºæ§è¡ `selectDueItems`ã`selectCandidates`ã`updateSendResult` ç SQLã |
| | | |
| | | 3. **çå®äºMASçä¿¡åé** |
| | | æªè°ç¨çå®äºMASæ¥å£ï¼é¿å
产ççå®çä¿¡è´¹ç¨åæ£è
ææ°ã |
| | | |
| | | 4. **çå®ä¸½æ°´å¦å¹¼å¾®ä¿¡åé** |
| | | æªè°ç¨çå® `sendChatLs` æ¥å£ï¼é¿å
åç宿£è
åéæ¶æ¯ã |
| | | |
| | | 5. **Spring 容å¨å¯å¨éªè¯** |
| | | æªå¯å¨å®æ´ `ruoyi-admin`ï¼å»ºè®®å¨æµè¯ç¯å¢å¯å¨åç¡®è®¤ï¼ |
| | | - `IMchFollowupPlanService` / `IMchFollowupSendService` 注å
¥æ£å¸¸ï¼ |
| | | - `RyTask` è½è°ç¨æ°ä»»å¡ï¼ |
| | | - æ¡£æ¡ä¿åå计åè¡¨ææ°æ®ã |
| | | |
| | | 6. **å¤èç¹å¹¶ååé** |
| | | å½ååé任塿ªå åå¸å¼éï¼ç产ç¯å¢å»ºè®®åªå¨ 8095 èç¹æ§è¡ï¼å¹¶è®¾ç½®âç¦æ¢å¹¶åâã |
| | | |
| | | --- |
| | | |
| | | ## ä¸ãé£é©ä¸å»ºè®® |
| | | |
| | | 1. `followup_period` å¨é¨åç¯å¢ä»ä¸º `varchar(100)`ï¼å¿
é¡»æ§è¡ DDL æ©å±ä¸º `TEXT`ï¼å¦åå
å«åéå
容ç JSON ä¼è¢«æªæï¼æ¬æ¬¡ `smartor_lishui` æµè¯åºåæ¬å·²æ¯ `TEXT`ï¼èæ¬å¹çæ§è¡æåã |
| | | 2. èªå¨çæå¦å¹¼æ¡£æ¡æ¶ï¼`plannedFollowTime` ä¼å
å `pat_med_outhosp.fudate` / `pat_med_inhosp.fudate`ï¼å¦æ HIS 没ç»éè®¿æ¥æï¼è®¡åä¼è¿å
¥âå¾
è¡¥å
âç¶æã |
| | | 3. è¿æèç¹åªæ è®°ä¸åéï¼ç¬¦åâåªè¡¥å 1 天å
âçä¸å¡å£å¾ã |
| | | 4. äºMAS/微信é
ç½®é误åªå½±å对åºèç¹ï¼ä¸ä¼é»æè®¡åçæã |
| | | 5. 建议ä¸çº¿åç¨ä¸æ¡æµè¯æ¡£æ¡å®æ´èµ°ä¸éï¼ |
| | | - æ¡£æ¡ä¿å â 计åçæï¼ |
| | | - ä¿®æ¹ `plannedFollowTime` â æ§èç¹åæ¶ãæ°èç¹çæï¼ |
| | | - å°æèç¹ â çä¿¡/微信åéï¼ |
| | | - è¶
è¿ 1 天èç¹ â æ è®°è¿æã |
| | |
| | | import com.ruoyi.task.domain.VO.ServiceSubtaskDetailTraceVO; |
| | | import com.smartor.mapper.*; |
| | | import com.smartor.service.*; |
| | | import com.smartor.service.mch.IMchFollowupPlanService; |
| | | import com.smartor.service.mch.IMchFollowupSendService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | |
| | | |
| | | @Autowired |
| | | private IPatSpecificArchiveGenerateService patSpecificArchiveGenerateService; |
| | | |
| | | @Autowired |
| | | private IMchFollowupPlanService mchFollowupPlanService; |
| | | |
| | | @Autowired |
| | | private IMchFollowupSendService mchFollowupSendService; |
| | | |
| | | @Autowired |
| | | private com.ruoyi.task.event.FollowupCompletedEventPublisher followupCompletedEventPublisher; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¦å¹¼é访ï¼ä¸ºå·²æå¦å¹¼æ¡£æ¡è¡¥å»ºè®¡åã |
| | | * |
| | | * <p>æ¡£æ¡æ°å¢/ä¿®æ¹æ¶ä¼èªå¨é建计åï¼æ¬ä»»å¡ç¨äºå岿°æ®è¡¥å»ºåå¼å¸¸è¡¥å¿ã</p> |
| | | */ |
| | | public void generateMchFollowupPlan() { |
| | | try { |
| | | int generated = mchFollowupPlanService.rebuildAll(200); |
| | | log.info("ãgenerateMchFollowupPlanãå¦å¹¼é访计åè¡¥å»ºå®æï¼çæèç¹æ°={}", generated); |
| | | } catch (Exception e) { |
| | | log.error("ãgenerateMchFollowupPlanãå¦å¹¼é访计å补建失败", e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¦å¹¼éè®¿ï¼æ«æå°æèç¹å¹¶åéã |
| | | * |
| | | * <p>åªè¡¥å 1 天å
å°æçèç¹ï¼è¶
è¿ 1 天æ è®°è¿æãçä¿¡èµ°äºMASï¼å¾®ä¿¡èµ° sendChatLsã</p> |
| | | */ |
| | | public void sendMchFollowup() { |
| | | try { |
| | | int sent = mchFollowupSendService.sendDue(200); |
| | | log.info("ãsendMchFollowupãå¦å¹¼é访åéå®æï¼æåæ°é={}", sent); |
| | | } catch (Exception e) { |
| | | log.error("ãsendMchFollowupãå¦å¹¼é访åé失败", e); |
| | | } |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.common; |
| | | |
| | | /** |
| | | * å¦å¹¼é访计åç¸å
³å¸¸éã |
| | | * |
| | | * <p>å¦å¹¼é访åªéç¨äºä¸½æ°´å¸å¦å¹¼ä¿å¥é¢ï¼ä¸ä½¿ç¨ç¬ç«ç计å表ååéä»»å¡ï¼ |
| | | * ä¸è¿å
¥æ®éé访ç {@code service_subtask_preachform} / {@code compensateTask} è¡¥å¿é¾è·¯ã</p> |
| | | */ |
| | | public final class MchFollowupConstants { |
| | | |
| | | /** æ¡£æ¡ç±»åï¼å¦ä¿ */ |
| | | public static final String ARCHIVE_TYPE_MATERNITY = "1"; |
| | | |
| | | /** æ¡£æ¡ç±»åï¼å¿ä¿ */ |
| | | public static final String ARCHIVE_TYPE_CHILD = "2"; |
| | | |
| | | /** 计åç¶æï¼ææ */ |
| | | public static final String PLAN_STATUS_ACTIVE = "0"; |
| | | |
| | | /** 计åç¶æï¼å·²åæ¶ */ |
| | | public static final String PLAN_STATUS_CANCELED = "1"; |
| | | |
| | | /** 计åç¶æï¼å·²å®æ */ |
| | | public static final String PLAN_STATUS_COMPLETED = "2"; |
| | | |
| | | /** 计åç¶æï¼å¾
è¡¥å
åºåæ¥/é
ç½®å¼å¸¸ */ |
| | | public static final String PLAN_STATUS_WAITING = "3"; |
| | | |
| | | /** èç¹ç¶æï¼å¾
åé */ |
| | | public static final String ITEM_STATUS_PENDING = "0"; |
| | | |
| | | /** èç¹ç¶æï¼åéä¸ */ |
| | | public static final String ITEM_STATUS_SENDING = "1"; |
| | | |
| | | /** èç¹ç¶æï¼æå */ |
| | | public static final String ITEM_STATUS_SUCCESS = "2"; |
| | | |
| | | /** èç¹ç¶æï¼å¤±è´¥ï¼éè¯èå°½ï¼ */ |
| | | public static final String ITEM_STATUS_FAILED = "3"; |
| | | |
| | | /** èç¹ç¶æï¼è¿æï¼è¶
è¿è¡¥åçªå£ï¼æªåéï¼ */ |
| | | public static final String ITEM_STATUS_EXPIRED = "4"; |
| | | |
| | | /** èç¹ç¶æï¼åæ¶ */ |
| | | public static final String ITEM_STATUS_CANCELED = "5"; |
| | | |
| | | /** èç¹ç¶æï¼è·³è¿ï¼ææºå·ä¸ºç©ºçï¼ */ |
| | | public static final String ITEM_STATUS_SKIPPED = "6"; |
| | | |
| | | /** åéæ¹å¼ï¼çä¿¡ */ |
| | | public static final String SEND_TYPE_SMS = "sms"; |
| | | |
| | | /** åéæ¹å¼ï¼å¾®ä¿¡å
¬ä¼å· */ |
| | | public static final String SEND_TYPE_WECHAT = "wechat"; |
| | | |
| | | /** è¡¥åçªå£ï¼åªè¡¥å 1 天å
å°æçèç¹ã */ |
| | | public static final long CATCHUP_MILLIS = 24L * 60L * 60L * 1000L; |
| | | |
| | | /** é»è®¤æå¤§éè¯æ¬¡æ°ã */ |
| | | public static final int DEFAULT_MAX_RETRY = 3; |
| | | |
| | | /** é»è®¤éè¯é´éï¼åéï¼ã */ |
| | | public static final int DEFAULT_RETRY_DELAY_MINUTES = 10; |
| | | |
| | | /** 忬¡æ«æé»è®¤ä¸éã */ |
| | | public static final int DEFAULT_BATCH_SIZE = 200; |
| | | |
| | | /** å¯ç¨å¼å
³ï¼sys_configï¼ææºæè¯»åï¼ç¼ºçè§ä¸ºå¯ç¨ï¼ã */ |
| | | public static final String CONFIG_ENABLED = "mch.followup.enabled"; |
| | | |
| | | /** äºMAS çä¿¡é
ç½®ï¼sys_configï¼ææºæè¯»åï¼ã */ |
| | | public static final String CONFIG_YUNMAS = "ls.msg.yunmas"; |
| | | |
| | | /** 丽水å¦å¹¼å¾®ä¿¡é
ç½®ï¼sys_configï¼ææºæè¯»åï¼ä¸ºç©ºæ¶ä½¿ç¨ SmsUtils å
ç½®é»è®¤é
ç½®ï¼ã */ |
| | | public static final String CONFIG_LS_WX = "ls.wx.fuyou"; |
| | | |
| | | private MchFollowupConstants() { |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.domain; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * å¦å¹¼éè®¿è¡¥è®¡åæ«æåéã |
| | | */ |
| | | @Data |
| | | public class MchFollowupArchiveCandidate implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String archiveType; |
| | | |
| | | private Long archiveId; |
| | | |
| | | private Long archiveDetailId; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.domain; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * followupPeriod JSON è§£æåçåéèç¹å®ä¹ï¼å°æªè®¡ç®ç»å¯¹åéæ¶é´ï¼ã |
| | | */ |
| | | @Data |
| | | public class MchFollowupNode implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private Integer seq; |
| | | |
| | | private Integer dayOffset; |
| | | |
| | | /** HH:mm æ HH:mm:ssï¼å¯ä¸ºç©º */ |
| | | private String sendTime; |
| | | |
| | | /** sms / wechat */ |
| | | private String sendType; |
| | | |
| | | private String content; |
| | | |
| | | private String titleName; |
| | | |
| | | private Long templateId; |
| | | |
| | | private String url; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.domain; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * å¦å¹¼é访计å主表 mch_followup_planã |
| | | * |
| | | * <p>ä¸ä¸ªæ¡£æ¡è¯¦æ
对åºä¸æ¡ææè®¡åï¼è®¡å䏿å¤ä¸ªåéèç¹ã |
| | | * plannedFollowTime æ¯æ´ä¸ªå¨æçåºåæ¥ï¼èç¹åéæ¶é´ = åºåæ¥ + dayOffsetã</p> |
| | | */ |
| | | @Data |
| | | @ApiModel(value = "å¦å¹¼é访计å") |
| | | public class MchFollowupPlan implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private Long id; |
| | | |
| | | @ApiModelProperty(value = "æºæID") |
| | | private String orgid; |
| | | |
| | | @ApiModelProperty(value = "é¢åºID") |
| | | private String campusid; |
| | | |
| | | @ApiModelProperty(value = "æ¡£æ¡ç±»åï¼1å¦ä¿ 2å¿ä¿") |
| | | private String archiveType; |
| | | |
| | | @ApiModelProperty(value = "æ¡£æ¡ä¸»è¡¨ID") |
| | | private Long archiveId; |
| | | |
| | | @ApiModelProperty(value = "æ¡£æ¡è¯¦æ
ID") |
| | | private Long archiveDetailId; |
| | | |
| | | @ApiModelProperty(value = "æ¥æºç±»åï¼1é¨è¯ 2ä½é¢é访 3æå·¥") |
| | | private String sourceType; |
| | | |
| | | @ApiModelProperty(value = "æ¥æºä¸å¡ç¼å·ï¼é¨è¯å·/ä½é¢å·") |
| | | private String sourceBizNo; |
| | | |
| | | @ApiModelProperty(value = "æ£è
ID") |
| | | private Long patid; |
| | | |
| | | @ApiModelProperty(value = "æ£è
å§å") |
| | | private String patname; |
| | | |
| | | @ApiModelProperty(value = "èç³»çµè¯") |
| | | private String phone; |
| | | |
| | | @ApiModelProperty(value = "è¯ä»¶å·ç ") |
| | | private String idcardno; |
| | | |
| | | @ApiModelProperty(value = "卿åºåæ¥") |
| | | private Date plannedFollowTime; |
| | | |
| | | @ApiModelProperty(value = "éè®¿å¨æ JSON å¿«ç
§") |
| | | private String followupPeriod; |
| | | |
| | | @ApiModelProperty(value = "计åç¶æï¼0ææ 1åæ¶ 2宿 3å¾
è¡¥å
/é
ç½®å¼å¸¸") |
| | | private String planStatus; |
| | | |
| | | @ApiModelProperty(value = "夿³¨") |
| | | private String remark; |
| | | |
| | | private Date createTime; |
| | | |
| | | private Date updateTime; |
| | | |
| | | @ApiModelProperty(value = "åéèç¹ï¼éè¡¨åæ®µï¼") |
| | | private List<MchFollowupPlanItem> items; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.domain; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * å¦å¹¼é访计ååéèç¹ mch_followup_plan_itemã |
| | | */ |
| | | @Data |
| | | @ApiModel(value = "å¦å¹¼é访计ååéèç¹") |
| | | public class MchFollowupPlanItem implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private Long id; |
| | | |
| | | @ApiModelProperty(value = "计åID") |
| | | private Long planId; |
| | | |
| | | @ApiModelProperty(value = "èç¹é¡ºåº") |
| | | private Integer seq; |
| | | |
| | | @ApiModelProperty(value = "åéæ¹å¼ï¼sms/wechat") |
| | | private String sendType; |
| | | |
| | | @ApiModelProperty(value = "åéæ¶é´") |
| | | private Date sendTime; |
| | | |
| | | @ApiModelProperty(value = "微信æ é¢") |
| | | private String titleName; |
| | | |
| | | @ApiModelProperty(value = "åéå
容") |
| | | private String content; |
| | | |
| | | @ApiModelProperty(value = "微信模æ¿ID") |
| | | private Long templateId; |
| | | |
| | | @ApiModelProperty(value = "微信跳转å°å") |
| | | private String url; |
| | | |
| | | @ApiModelProperty(value = "åéç¶æï¼0å¾
åé 1åéä¸ 2æå 3失败 4è¿æ 5åæ¶ 6è·³è¿") |
| | | private String sendStatus; |
| | | |
| | | @ApiModelProperty(value = "å·²éè¯æ¬¡æ°") |
| | | private Integer retryCount; |
| | | |
| | | @ApiModelProperty(value = "䏿¬¡éè¯æ¶é´") |
| | | private Date nextRetryTime; |
| | | |
| | | @ApiModelProperty(value = "å®é
åéæ¶é´") |
| | | private Date sendTimeActual; |
| | | |
| | | @ApiModelProperty(value = "ç»æè¯´æ") |
| | | private String resultMsg; |
| | | |
| | | @ApiModelProperty(value = "ç¬¬ä¸æ¹æ¶æ¯ID") |
| | | private String providerMsgId; |
| | | |
| | | private Date createTime; |
| | | |
| | | private Date updateTime; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.domain; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * å¦å¹¼é访åéæ¥å¿ mch_followup_send_logã |
| | | */ |
| | | @Data |
| | | public class MchFollowupSendLog implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private Long id; |
| | | |
| | | private Long planId; |
| | | |
| | | private Long itemId; |
| | | |
| | | private String sendType; |
| | | |
| | | private String requestBody; |
| | | |
| | | private String responseBody; |
| | | |
| | | private String sendStatus; |
| | | |
| | | private String resultMsg; |
| | | |
| | | private Date createTime; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.mapper; |
| | | |
| | | import com.smartor.domain.MchFollowupPlanItem; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * å¦å¹¼é访计åèç¹ Mapperã |
| | | */ |
| | | @Mapper |
| | | public interface MchFollowupPlanItemMapper { |
| | | |
| | | int insertMchFollowupPlanItem(MchFollowupPlanItem item); |
| | | |
| | | int updateMchFollowupPlanItem(MchFollowupPlanItem item); |
| | | |
| | | int updateSendResult(MchFollowupPlanItem item); |
| | | |
| | | MchFollowupPlanItem selectMchFollowupPlanItemById(@Param("id") Long id); |
| | | |
| | | List<MchFollowupPlanItem> selectByPlanId(@Param("planId") Long planId); |
| | | |
| | | /** |
| | | * æ¥è¯¢å°æèç¹ï¼è®¡åææãæºæä¸ºä¸½æ°´å¦å¹¼ãå¾
åéãå°è¾¾åéæ¶é´ãä¸ä¸å¨éè¯çå¾
ä¸ã |
| | | */ |
| | | List<MchFollowupPlanItem> selectDueItems(@Param("orgid") String orgid, |
| | | @Param("now") Date now, |
| | | @Param("limit") int limit); |
| | | |
| | | int claimItem(@Param("id") Long id, @Param("now") Date now); |
| | | |
| | | int cancelPendingByPlanId(@Param("planId") Long planId, @Param("now") Date now); |
| | | |
| | | int countPendingByPlanId(@Param("planId") Long planId); |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.mapper; |
| | | |
| | | import com.smartor.domain.MchFollowupArchiveCandidate; |
| | | import com.smartor.domain.MchFollowupPlan; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * å¦å¹¼é访计å主表 Mapperã |
| | | */ |
| | | @Mapper |
| | | public interface MchFollowupPlanMapper { |
| | | |
| | | int insertMchFollowupPlan(MchFollowupPlan plan); |
| | | |
| | | int updateMchFollowupPlan(MchFollowupPlan plan); |
| | | |
| | | MchFollowupPlan selectMchFollowupPlanById(@Param("id") Long id); |
| | | |
| | | List<MchFollowupPlan> selectActiveByArchive(@Param("archiveType") String archiveType, |
| | | @Param("archiveId") Long archiveId, |
| | | @Param("archiveDetailId") Long archiveDetailId); |
| | | |
| | | int cancelById(@Param("id") Long id, @Param("updateTime") java.util.Date updateTime); |
| | | |
| | | int completeById(@Param("id") Long id, @Param("updateTime") java.util.Date updateTime); |
| | | |
| | | List<MchFollowupArchiveCandidate> selectCandidates(@Param("orgid") String orgid, |
| | | @Param("limit") int limit); |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.mapper; |
| | | |
| | | import com.smartor.domain.MchFollowupSendLog; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * å¦å¹¼é访åéæ¥å¿ Mapperã |
| | | */ |
| | | @Mapper |
| | | public interface MchFollowupSendLogMapper { |
| | | |
| | | int insertMchFollowupSendLog(MchFollowupSendLog log); |
| | | } |
| | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.smartor.domain.PatChildArchive; |
| | | import com.smartor.domain.PatChildArchiveDetail; |
| | | import com.smartor.common.MchFollowupConstants; |
| | | import com.smartor.mapper.PatChildArchiveMapper; |
| | | import com.smartor.service.IPatChildArchiveDetailService; |
| | | import com.smartor.service.IPatChildArchiveService; |
| | | import com.smartor.service.mch.IMchFollowupPlanService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | @Autowired |
| | | private IPatChildArchiveDetailService patChildArchiveDetailService; |
| | | |
| | | @Autowired |
| | | private IMchFollowupPlanService mchFollowupPlanService; |
| | | |
| | | @Override |
| | | public PatChildArchive selectPatChildArchiveById(Long id) |
| | |
| | | patChildArchiveDetailService.insertPatChildArchiveDetail(patChildArchiveDetail); |
| | | } |
| | | |
| | | // å¦å¹¼é访计åï¼æ¡£æ¡æ°å¢/ä¿®æ¹åæ plannedFollowTime + followupPeriod é建 |
| | | try { |
| | | if (mchFollowupPlanService != null) { |
| | | mchFollowupPlanService.rebuildForArchive( |
| | | MchFollowupConstants.ARCHIVE_TYPE_CHILD, |
| | | patChildArchive.getId(), patChildArchiveDetail.getId()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("å¦å¹¼é访计åé建失败ï¼archiveId={}ï¼detailId={}", |
| | | patChildArchive.getId(), patChildArchiveDetail.getId(), e); |
| | | } |
| | | |
| | | log.info("insertOrUpdateChildArchiveå¤ç宿ï¼ä¸»è¡¨idï¼{}ï¼è¯¦æ
idï¼{}", patChildArchive.getId(), patChildArchiveDetail.getId()); |
| | | return patChildArchive.getId().intValue(); |
| | | } |
| | |
| | | import com.smartor.domain.PatChildArchiveDetail; |
| | | import com.smartor.domain.PatMaternityArchive; |
| | | import com.smartor.domain.PatMaternityArchiveDetail; |
| | | import com.smartor.common.MchFollowupConstants; |
| | | import com.smartor.mapper.PatMaternityArchiveDetailMapper; |
| | | import com.smartor.mapper.PatMaternityArchiveMapper; |
| | | import com.smartor.service.IPatMaternityArchiveDetailService; |
| | | import com.smartor.service.IPatMaternityArchiveService; |
| | | import com.smartor.service.mch.IMchFollowupPlanService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | private IPatMaternityArchiveDetailService patMaternityArchiveDetailService; |
| | | @Autowired |
| | | private PatMaternityArchiveDetailMapper patMaternityArchiveDetailMapper; |
| | | |
| | | @Autowired |
| | | private IMchFollowupPlanService mchFollowupPlanService; |
| | | |
| | | @Override |
| | | public PatMaternityArchive selectPatMaternityArchiveById(Long id) |
| | |
| | | patMaternityArchiveDetailService.insertPatMaternityArchiveDetail(patMaternityArchiveDetail); |
| | | } |
| | | |
| | | // å¦å¹¼é访计åï¼æ¡£æ¡æ°å¢/ä¿®æ¹åæ plannedFollowTime + followupPeriod é建 |
| | | try { |
| | | if (mchFollowupPlanService != null) { |
| | | mchFollowupPlanService.rebuildForArchive( |
| | | MchFollowupConstants.ARCHIVE_TYPE_MATERNITY, |
| | | patMaternityArchive.getId(), patMaternityArchiveDetail.getId()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("å¦å¹¼é访计åé建失败ï¼archiveId={}ï¼detailId={}", |
| | | patMaternityArchive.getId(), patMaternityArchiveDetail.getId(), e); |
| | | } |
| | | |
| | | log.info("insertOrUpdateMaternityArchiveå¤ç宿ï¼ä¸»è¡¨idï¼{}ï¼è¯¦æ
idï¼{}", patMaternityArchive.getId(), patMaternityArchiveDetail.getId()); |
| | | return patMaternityArchive.getId().intValue(); |
| | | } |
| | |
| | | PatMaternityArchiveDetail detail = new PatMaternityArchiveDetail(); |
| | | detail.setArchiveType(config.getArchiveType()); |
| | | detail.setFollowupPeriod(config.getFollowupPeriod()); |
| | | detail.setPlannedFollowTime(patMedOuthosp.getFudate()); |
| | | detail.setSourceType(SpecificArchiveConstants.SOURCE_TYPE_OUTHOSP); |
| | | detail.setSourceBizId(patMedOuthosp.getId()); |
| | | detail.setSourceBizNo(patMedOuthosp.getOuthospno()); |
| | |
| | | PatChildArchiveDetail detail = new PatChildArchiveDetail(); |
| | | detail.setArchiveType(config.getArchiveType()); |
| | | detail.setFollowupPeriod(config.getFollowupPeriod()); |
| | | detail.setPlannedFollowTime(patMedOuthosp.getFudate()); |
| | | detail.setSourceType(SpecificArchiveConstants.SOURCE_TYPE_OUTHOSP); |
| | | detail.setSourceBizId(patMedOuthosp.getId()); |
| | | detail.setSourceBizNo(patMedOuthosp.getOuthospno()); |
| | |
| | | PatMaternityArchiveDetail detail = new PatMaternityArchiveDetail(); |
| | | detail.setArchiveType(config.getArchiveType()); |
| | | detail.setFollowupPeriod(config.getFollowupPeriod()); |
| | | detail.setPlannedFollowTime(context.inhosp == null ? null : context.inhosp.getFudate()); |
| | | detail.setSourceType(SpecificArchiveConstants.SOURCE_TYPE_INHOSP_FOLLOWUP); |
| | | detail.setSourceBizId(inInhospid(context)); |
| | | detail.setSourceBizNo(inInhospno(context)); |
| | |
| | | PatChildArchiveDetail detail = new PatChildArchiveDetail(); |
| | | detail.setArchiveType(config.getArchiveType()); |
| | | detail.setFollowupPeriod(config.getFollowupPeriod()); |
| | | detail.setPlannedFollowTime(context.inhosp == null ? null : context.inhosp.getFudate()); |
| | | detail.setSourceType(SpecificArchiveConstants.SOURCE_TYPE_INHOSP_FOLLOWUP); |
| | | detail.setSourceBizId(inInhospid(context)); |
| | | detail.setSourceBizNo(inInhospno(context)); |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | /** |
| | | * å¦å¹¼é访计åæå¡ã |
| | | */ |
| | | public interface IMchFollowupPlanService { |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡£æ¡è¯¦æ
é建å¦å¹¼é访计åã |
| | | * |
| | | * @param archiveType 1å¦ä¿ 2å¿ä¿ |
| | | * @param archiveId æ¡£æ¡ä¸»è¡¨ID |
| | | * @param archiveDetailId æ¡£æ¡è¯¦æ
ID |
| | | * @return æ°çæçåéèç¹æ°é |
| | | */ |
| | | int rebuildForArchive(String archiveType, Long archiveId, Long archiveDetailId); |
| | | |
| | | /** |
| | | * è¡¥å¿æ«æï¼ä¸ºå·²æå¦å¹¼æ¡£æ¡è¡¥å»ºè®¡åã |
| | | * |
| | | * @param limit 忬¡æ«æä¸é |
| | | * @return æ°çæçåéèç¹æ°é |
| | | */ |
| | | int rebuildAll(int limit); |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | /** |
| | | * å¦å¹¼é访åéæå¡ã |
| | | */ |
| | | public interface IMchFollowupSendService { |
| | | |
| | | /** |
| | | * æ«æå¹¶åéå°æèç¹ã |
| | | * |
| | | * @param limit 忬¡å¤çä¸é |
| | | * @return æ¬æ¬¡å®é
åéæåæ°é |
| | | */ |
| | | int sendDue(int limit); |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | /** |
| | | * å¦å¹¼éè®¿å°æå¤æç»æã |
| | | */ |
| | | public enum MchFollowupDueDecision { |
| | | PENDING, |
| | | SEND, |
| | | EXPIRED |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.sms.SmsUtils; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.smartor.common.MchFollowupConstants; |
| | | import com.smartor.domain.MchFollowupPlan; |
| | | import com.smartor.domain.MchFollowupPlanItem; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * å¦å¹¼éè®¿æ¶æ¯åéå¨ã |
| | | * |
| | | * <p>çä¿¡å¤ç¨ {@link SmsUtils#sendYunMasSms}ï¼å¾®ä¿¡å¤ç¨ |
| | | * {@link SmsUtils#sendChatLs}ï¼å³ {@code /sms/sendChatFuyou} çå
é¨å®ç°ï¼ã |
| | | * ä¸ç»è¿æ®éé访çå鿹工åä¸è¡¥å¿é¾è·¯ã</p> |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class MchFollowupMessageSender { |
| | | |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | public MchFollowupSendOutcome sendSms(MchFollowupPlan plan, MchFollowupPlanItem item) { |
| | | String phone = plan == null ? null : plan.getPhone(); |
| | | String content = item == null ? null : item.getContent(); |
| | | if (StringUtils.isBlank(phone)) { |
| | | return MchFollowupSendOutcome.skip("ææºå·ä¸ºç©º"); |
| | | } |
| | | if (StringUtils.isBlank(content)) { |
| | | return MchFollowupSendOutcome.fail("çä¿¡å
容为空", requestSummary("sms", phone, null), null); |
| | | } |
| | | try { |
| | | String configJson = configService.selectConfigByKey( |
| | | MchFollowupConstants.CONFIG_YUNMAS, plan.getOrgid()); |
| | | SmsUtils.YunMasConfig config = SmsUtils.YunMasConfig.of(configJson); |
| | | SmsUtils.SmsResult result = SmsUtils.sendYunMasSms(config, phone, content); |
| | | String requestBody = requestSummary("sms", phone, null); |
| | | String responseBody = JSON.toJSONString(result); |
| | | if (result != null && result.isOk()) { |
| | | return MchFollowupSendOutcome.ok(result.getMsgGroup(), requestBody, responseBody); |
| | | } |
| | | String message = result == null ? "äºMASè¿å为空" : result.getMessage(); |
| | | return MchFollowupSendOutcome.fail(message, requestBody, responseBody); |
| | | } catch (Exception e) { |
| | | log.error("ãå¦å¹¼é访ãçä¿¡åéå¼å¸¸ï¼planId={}ï¼itemId={}", plan.getId(), item.getId(), e); |
| | | return MchFollowupSendOutcome.fail("çä¿¡åéå¼å¸¸ï¼" + e.getMessage(), |
| | | requestSummary("sms", phone, null), null); |
| | | } |
| | | } |
| | | |
| | | public MchFollowupSendOutcome sendWechat(MchFollowupPlan plan, MchFollowupPlanItem item) { |
| | | String phone = plan == null ? null : plan.getPhone(); |
| | | if (StringUtils.isBlank(phone) && StringUtils.isBlank(plan == null ? null : plan.getIdcardno())) { |
| | | return MchFollowupSendOutcome.skip("ææºå·åè¯ä»¶å·é½ä¸ºç©º"); |
| | | } |
| | | try { |
| | | String configJson = configService.selectConfigByKey( |
| | | MchFollowupConstants.CONFIG_LS_WX, plan.getOrgid()); |
| | | SmsUtils.LsWxConfig config = SmsUtils.LsWxConfig.of(configJson); |
| | | |
| | | SmsUtils.LsWxMessage message = new SmsUtils.LsWxMessage(); |
| | | message.setId(item.getTemplateId()); |
| | | message.setPatientId(plan.getPatid() == null ? null : String.valueOf(plan.getPatid())); |
| | | message.setPatientName(plan.getPatname()); |
| | | message.setIdCard(plan.getIdcardno()); |
| | | message.setMobile(phone); |
| | | message.setMedCardNo(plan.getSourceBizNo()); |
| | | message.setTitleName(item.getTitleName()); |
| | | message.setContent(item.getContent()); |
| | | message.setUrl(item.getUrl()); |
| | | |
| | | String requestBody = requestSummary("wechat", phone, item.getTemplateId()); |
| | | String resp = SmsUtils.sendChatLs(config, message); |
| | | String messageText = parseWechatMessage(resp); |
| | | boolean ok = parseWechatOk(resp); |
| | | if (ok) { |
| | | return MchFollowupSendOutcome.ok(null, requestBody, resp); |
| | | } |
| | | return MchFollowupSendOutcome.fail(messageText, requestBody, resp); |
| | | } catch (Exception e) { |
| | | log.error("ãå¦å¹¼é访ã微信åéå¼å¸¸ï¼planId={}ï¼itemId={}", plan.getId(), item.getId(), e); |
| | | return MchFollowupSendOutcome.fail("微信åéå¼å¸¸ï¼" + e.getMessage(), |
| | | requestSummary("wechat", phone, item == null ? null : item.getTemplateId()), null); |
| | | } |
| | | } |
| | | |
| | | private boolean parseWechatOk(String resp) { |
| | | if (StringUtils.isBlank(resp)) { |
| | | return false; |
| | | } |
| | | try { |
| | | JSONObject object = JSON.parseObject(resp); |
| | | return object != null && object.getIntValue("code") == 0; |
| | | } catch (Exception e) { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | private String parseWechatMessage(String resp) { |
| | | if (StringUtils.isBlank(resp)) { |
| | | return "微信è¿å为空"; |
| | | } |
| | | try { |
| | | JSONObject object = JSON.parseObject(resp); |
| | | if (object == null) { |
| | | return "微信è¿å为空"; |
| | | } |
| | | String msg = object.getString("msg"); |
| | | return StringUtils.isBlank(msg) ? resp : msg; |
| | | } catch (Exception e) { |
| | | return resp; |
| | | } |
| | | } |
| | | |
| | | private String requestSummary(String sendType, String phone, Long templateId) { |
| | | return "sendType=" + sendType |
| | | + "ï¼phone=" + maskPhone(phone) |
| | | + (templateId == null ? "" : "ï¼templateId=" + templateId); |
| | | } |
| | | |
| | | private String maskPhone(String phone) { |
| | | if (StringUtils.isBlank(phone) || phone.length() < 7) { |
| | | return phone; |
| | | } |
| | | return phone.substring(0, 3) + "****" + phone.substring(phone.length() - 4); |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.smartor.common.MchFollowupConstants; |
| | | import com.smartor.domain.MchFollowupNode; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Locale; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * å¦å¹¼éè®¿å¨æ JSON è§£æå¨ã |
| | | * |
| | | * <p>æ¯æä¸¤ç§åæ³ï¼</p> |
| | | * <pre> |
| | | * 1) æ¾å¼èç¹ï¼ |
| | | * { |
| | | * "items": [ |
| | | * {"seq":1,"dayOffset":0,"sendTime":"09:00","sendType":"sms","content":"..."}, |
| | | * {"seq":2,"dayOffset":3,"sendType":"wechat","templateId":16,"content":"..."} |
| | | * ] |
| | | * } |
| | | * |
| | | * 2) é´é + 次æ°ï¼ |
| | | * { |
| | | * "intervalDays": 3, |
| | | * "count": 4, |
| | | * "sendType": "sms", |
| | | * "content": "..." |
| | | * } |
| | | * </pre> |
| | | * |
| | | * <p>dayOffset ä¸å¾è¡¨ç¤ºç¸å¯¹ plannedFollowTime çç»å¯¹å移天æ°ï¼ä¸æ¯âä»ä¸ä¸æ¬¡åéå顺延âã</p> |
| | | */ |
| | | @Component |
| | | public class MchFollowupPeriodParser { |
| | | |
| | | public List<MchFollowupNode> parse(String json, String fallbackCycleTimes) { |
| | | if (StringUtils.isBlank(json)) { |
| | | throw new IllegalArgumentException("éè®¿å¨æ followupPeriod 为空"); |
| | | } |
| | | JSONObject root; |
| | | try { |
| | | root = JSON.parseObject(json); |
| | | } catch (Exception e) { |
| | | throw new IllegalArgumentException("éè®¿å¨æä¸æ¯åæ³ JSONï¼" + e.getMessage(), e); |
| | | } |
| | | if (root == null) { |
| | | throw new IllegalArgumentException("éè®¿å¨æä¸æ¯åæ³ JSON 对象"); |
| | | } |
| | | |
| | | JSONArray items = root.getJSONArray("items"); |
| | | if (items != null) { |
| | | return parseItems(items); |
| | | } |
| | | |
| | | JSONArray days = root.getJSONArray("days"); |
| | | if (days != null) { |
| | | return parseDays(days, root); |
| | | } |
| | | |
| | | Integer intervalDays = root.getInteger("intervalDays"); |
| | | if (intervalDays != null) { |
| | | int count = resolveCount(root, fallbackCycleTimes); |
| | | return parseInterval(intervalDays, count, root); |
| | | } |
| | | |
| | | throw new IllegalArgumentException("éè®¿å¨æç¼ºå° items / days / intervalDays é
ç½®"); |
| | | } |
| | | |
| | | private List<MchFollowupNode> parseItems(JSONArray items) { |
| | | if (items.isEmpty()) { |
| | | throw new IllegalArgumentException("éè®¿å¨æ items ä¸è½ä¸ºç©º"); |
| | | } |
| | | List<MchFollowupNode> nodes = new ArrayList<>(items.size()); |
| | | Set<Integer> seqSet = new HashSet<>(); |
| | | for (int i = 0; i < items.size(); i++) { |
| | | JSONObject item = items.getJSONObject(i); |
| | | if (item == null) { |
| | | throw new IllegalArgumentException("éè®¿å¨æ items[" + i + "] 为空"); |
| | | } |
| | | MchFollowupNode node = buildNode(item, i + 1); |
| | | if (!seqSet.add(node.getSeq())) { |
| | | throw new IllegalArgumentException("éè®¿å¨æ seq éå¤ï¼" + node.getSeq()); |
| | | } |
| | | nodes.add(node); |
| | | } |
| | | return nodes; |
| | | } |
| | | |
| | | private List<MchFollowupNode> parseDays(JSONArray days, JSONObject root) { |
| | | if (days.isEmpty()) { |
| | | throw new IllegalArgumentException("éè®¿å¨æ days ä¸è½ä¸ºç©º"); |
| | | } |
| | | List<MchFollowupNode> nodes = new ArrayList<>(days.size()); |
| | | for (int i = 0; i < days.size(); i++) { |
| | | Integer day = days.getInteger(i); |
| | | if (day == null || day < 0) { |
| | | throw new IllegalArgumentException("éè®¿å¨æ days[" + i + "] å¿
é¡»æ¯éè´æ´æ°"); |
| | | } |
| | | JSONObject item = new JSONObject(); |
| | | item.put("seq", i + 1); |
| | | item.put("dayOffset", day); |
| | | copySharedFields(root, item); |
| | | nodes.add(buildNode(item, i + 1)); |
| | | } |
| | | return nodes; |
| | | } |
| | | |
| | | private List<MchFollowupNode> parseInterval(int intervalDays, int count, JSONObject root) { |
| | | if (intervalDays < 0) { |
| | | throw new IllegalArgumentException("intervalDays ä¸è½å°äº 0"); |
| | | } |
| | | if (count <= 0) { |
| | | throw new IllegalArgumentException("count å¿
é¡»å¤§äº 0"); |
| | | } |
| | | List<MchFollowupNode> nodes = new ArrayList<>(count); |
| | | for (int i = 0; i < count; i++) { |
| | | JSONObject item = new JSONObject(); |
| | | item.put("seq", i + 1); |
| | | item.put("dayOffset", intervalDays * i); |
| | | copySharedFields(root, item); |
| | | nodes.add(buildNode(item, i + 1)); |
| | | } |
| | | return nodes; |
| | | } |
| | | |
| | | private MchFollowupNode buildNode(JSONObject item, int defaultSeq) { |
| | | MchFollowupNode node = new MchFollowupNode(); |
| | | Integer seq = item.getInteger("seq"); |
| | | node.setSeq(seq == null ? defaultSeq : seq); |
| | | if (node.getSeq() <= 0) { |
| | | throw new IllegalArgumentException("éè®¿å¨æ seq å¿
é¡»å¤§äº 0"); |
| | | } |
| | | |
| | | Integer dayOffset = item.getInteger("dayOffset"); |
| | | if (dayOffset == null) { |
| | | dayOffset = item.getInteger("day"); |
| | | } |
| | | if (dayOffset == null || dayOffset < 0) { |
| | | throw new IllegalArgumentException("éè®¿å¨æ dayOffset å¿
é¡»æ¯éè´æ´æ°ï¼seq=" + node.getSeq()); |
| | | } |
| | | node.setDayOffset(dayOffset); |
| | | |
| | | String sendType = normalizeSendType(item.getString("sendType")); |
| | | node.setSendType(sendType); |
| | | node.setSendTime(normalizeSendTime(item.getString("sendTime"))); |
| | | node.setContent(item.getString("content")); |
| | | node.setTitleName(item.getString("titleName")); |
| | | node.setTemplateId(item.getLong("templateId")); |
| | | node.setUrl(item.getString("url")); |
| | | |
| | | if (MchFollowupConstants.SEND_TYPE_SMS.equals(sendType) |
| | | && StringUtils.isBlank(node.getContent())) { |
| | | throw new IllegalArgumentException("çä¿¡èç¹ content ä¸è½ä¸ºç©ºï¼seq=" + node.getSeq()); |
| | | } |
| | | return node; |
| | | } |
| | | |
| | | private void copySharedFields(JSONObject root, JSONObject item) { |
| | | copyIfPresent(root, item, "sendTime"); |
| | | copyIfPresent(root, item, "sendType"); |
| | | copyIfPresent(root, item, "content"); |
| | | copyIfPresent(root, item, "titleName"); |
| | | copyIfPresent(root, item, "templateId"); |
| | | copyIfPresent(root, item, "url"); |
| | | } |
| | | |
| | | private void copyIfPresent(JSONObject from, JSONObject to, String key) { |
| | | if (!to.containsKey(key) && from.containsKey(key)) { |
| | | to.put(key, from.get(key)); |
| | | } |
| | | } |
| | | |
| | | private int resolveCount(JSONObject root, String fallbackCycleTimes) { |
| | | Integer count = root.getInteger("count"); |
| | | if (count == null && StringUtils.isNotBlank(fallbackCycleTimes)) { |
| | | try { |
| | | count = Integer.valueOf(fallbackCycleTimes.trim()); |
| | | } catch (NumberFormatException e) { |
| | | throw new IllegalArgumentException("followupCycleTimes 䏿¯åæ³æ¬¡æ°ï¼" + fallbackCycleTimes); |
| | | } |
| | | } |
| | | if (count == null || count <= 0) { |
| | | throw new IllegalArgumentException("intervalDays 模å¼å¿
é¡»é
ç½® count æ followupCycleTimes"); |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | static String normalizeSendType(String raw) { |
| | | if (StringUtils.isBlank(raw)) { |
| | | throw new IllegalArgumentException("éè®¿å¨æ sendType ä¸è½ä¸ºç©º"); |
| | | } |
| | | String value = raw.trim().toLowerCase(Locale.ROOT); |
| | | if ("sms".equals(value) || "4".equals(value) || "çä¿¡".equals(raw.trim())) { |
| | | return MchFollowupConstants.SEND_TYPE_SMS; |
| | | } |
| | | if ("wechat".equals(value) || "wechat_mp".equals(value) || "5".equals(value) |
| | | || "å
¬ä¼å·".equals(raw.trim()) || "微信".equals(raw.trim())) { |
| | | return MchFollowupConstants.SEND_TYPE_WECHAT; |
| | | } |
| | | throw new IllegalArgumentException("䏿¯æç sendTypeï¼" + raw + "ï¼ä»
æ¯æ sms/wechatï¼"); |
| | | } |
| | | |
| | | static String normalizeSendTime(String raw) { |
| | | if (StringUtils.isBlank(raw)) { |
| | | return null; |
| | | } |
| | | String value = raw.trim(); |
| | | if (value.matches("^([01]\\d|2[0-3]):[0-5]\\d$")) { |
| | | return value; |
| | | } |
| | | if (value.matches("^([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$")) { |
| | | return value; |
| | | } |
| | | throw new IllegalArgumentException("sendTime æ ¼å¼åºä¸º HH:mm æ HH:mm:ssï¼" + raw); |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | import com.smartor.common.MchFollowupConstants; |
| | | import com.smartor.domain.MchFollowupNode; |
| | | import com.smartor.domain.MchFollowupPlanItem; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * æè§£æåçèç¹å®ä¹ç»è£
æå¯è½åºçåéèç¹ã |
| | | */ |
| | | @Component |
| | | public class MchFollowupPlanAssembler { |
| | | |
| | | @Autowired |
| | | private MchFollowupTimeResolver timeResolver; |
| | | |
| | | public List<MchFollowupPlanItem> assemble(Long planId, Date plannedFollowTime, List<MchFollowupNode> nodes) { |
| | | List<MchFollowupPlanItem> items = new ArrayList<>(); |
| | | if (nodes == null || nodes.isEmpty()) { |
| | | return items; |
| | | } |
| | | Date now = new Date(); |
| | | for (MchFollowupNode node : nodes) { |
| | | MchFollowupPlanItem item = new MchFollowupPlanItem(); |
| | | item.setPlanId(planId); |
| | | item.setSeq(node.getSeq()); |
| | | item.setSendType(node.getSendType()); |
| | | item.setSendTime(timeResolver.resolve(plannedFollowTime, node)); |
| | | item.setTitleName(node.getTitleName()); |
| | | item.setContent(node.getContent()); |
| | | item.setTemplateId(node.getTemplateId()); |
| | | item.setUrl(node.getUrl()); |
| | | item.setSendStatus(MchFollowupConstants.ITEM_STATUS_PENDING); |
| | | item.setRetryCount(0); |
| | | item.setCreateTime(now); |
| | | item.setUpdateTime(now); |
| | | items.add(item); |
| | | } |
| | | return items; |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.smartor.common.MchFollowupConstants; |
| | | import com.smartor.common.SpecificArchiveConstants; |
| | | import com.smartor.domain.MchFollowupArchiveCandidate; |
| | | import com.smartor.domain.MchFollowupNode; |
| | | import com.smartor.domain.MchFollowupPlan; |
| | | import com.smartor.domain.MchFollowupPlanItem; |
| | | import com.smartor.domain.PatChildArchiveDetail; |
| | | import com.smartor.domain.PatMaternityArchiveDetail; |
| | | import com.smartor.mapper.MchFollowupPlanItemMapper; |
| | | import com.smartor.mapper.MchFollowupPlanMapper; |
| | | import com.smartor.mapper.PatChildArchiveDetailMapper; |
| | | import com.smartor.mapper.PatMaternityArchiveDetailMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * å¦å¹¼é访计åæå¡å®ç°ã |
| | | * |
| | | * <p>åªå¤ç丽水å¸å¦å¹¼ä¿å¥é¢ã计åçæä¸åéæ¶æ¯ï¼åéç± |
| | | * {@link IMchFollowupSendService} ç¬ç«å®æã</p> |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class MchFollowupPlanServiceImpl implements IMchFollowupPlanService { |
| | | |
| | | @Autowired |
| | | private MchFollowupPlanMapper planMapper; |
| | | |
| | | @Autowired |
| | | private MchFollowupPlanItemMapper itemMapper; |
| | | |
| | | @Autowired |
| | | private PatMaternityArchiveDetailMapper maternityDetailMapper; |
| | | |
| | | @Autowired |
| | | private PatChildArchiveDetailMapper childDetailMapper; |
| | | |
| | | @Autowired |
| | | private MchFollowupPeriodParser periodParser; |
| | | |
| | | @Autowired |
| | | private MchFollowupPlanAssembler planAssembler; |
| | | |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int rebuildForArchive(String archiveType, Long archiveId, Long archiveDetailId) { |
| | | try { |
| | | return doRebuildForArchive(archiveType, archiveId, archiveDetailId); |
| | | } catch (Exception e) { |
| | | // 计åçæå¤±è´¥ä¸è½å½±åæ¡£æ¡ä¸»æµç¨ï¼å¼å¸¸å¨äºå¡è¾¹çå
æ¶å |
| | | log.error("ãå¦å¹¼é访ã计åé建å¼å¸¸ï¼archiveType={}ï¼archiveId={}ï¼detailId={}", |
| | | archiveType, archiveId, archiveDetailId, e); |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | private int doRebuildForArchive(String archiveType, Long archiveId, Long archiveDetailId) { |
| | | if (!isEnabled()) { |
| | | return 0; |
| | | } |
| | | ArchiveSnapshot snapshot = loadSnapshot(archiveType, archiveId, archiveDetailId); |
| | | if (snapshot == null) { |
| | | return 0; |
| | | } |
| | | if (snapshot.archiveId == null || snapshot.archiveDetailId == null) { |
| | | log.warn("ãå¦å¹¼éè®¿ãæ¡£æ¡ä¸»é®æè¯¦æ
主é®ä¸ºç©ºï¼è·³è¿è®¡åé建ï¼archiveType={}ï¼archiveId={}ï¼detailId={}", |
| | | archiveType, archiveId, archiveDetailId); |
| | | return 0; |
| | | } |
| | | if (!SpecificArchiveConstants.LISHUI_MCH_ORG_ID.equals(snapshot.orgid)) { |
| | | return 0; |
| | | } |
| | | |
| | | List<MchFollowupPlan> actives = planMapper.selectActiveByArchive( |
| | | snapshot.archiveType, snapshot.archiveId, snapshot.archiveDetailId); |
| | | if (actives == null) { |
| | | actives = Collections.emptyList(); |
| | | } |
| | | for (MchFollowupPlan active : actives) { |
| | | if (sameTime(active.getPlannedFollowTime(), snapshot.plannedFollowTime) |
| | | && StringUtils.equals(active.getFollowupPeriod(), snapshot.followupPeriod)) { |
| | | MchFollowupPlan contactUpdate = new MchFollowupPlan(); |
| | | contactUpdate.setId(active.getId()); |
| | | contactUpdate.setCampusid(snapshot.campusid); |
| | | contactUpdate.setSourceBizNo(snapshot.sourceBizNo); |
| | | contactUpdate.setPatname(snapshot.patname); |
| | | contactUpdate.setPhone(snapshot.phone); |
| | | contactUpdate.setIdcardno(snapshot.idcardno); |
| | | contactUpdate.setUpdateTime(DateUtils.getNowDate()); |
| | | planMapper.updateMchFollowupPlan(contactUpdate); |
| | | log.debug("ãå¦å¹¼é访ãè®¡åæªååï¼ä»
å·æ°è系人信æ¯ï¼archiveType={}ï¼archiveId={}ï¼detailId={}", |
| | | snapshot.archiveType, snapshot.archiveId, snapshot.archiveDetailId); |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | Date now = DateUtils.getNowDate(); |
| | | for (MchFollowupPlan active : actives) { |
| | | itemMapper.cancelPendingByPlanId(active.getId(), now); |
| | | planMapper.cancelById(active.getId(), now); |
| | | } |
| | | |
| | | MchFollowupPlan plan = new MchFollowupPlan(); |
| | | plan.setOrgid(snapshot.orgid); |
| | | plan.setCampusid(snapshot.campusid); |
| | | plan.setArchiveType(snapshot.archiveType); |
| | | plan.setArchiveId(snapshot.archiveId); |
| | | plan.setArchiveDetailId(snapshot.archiveDetailId); |
| | | plan.setSourceType(snapshot.sourceType); |
| | | plan.setSourceBizNo(snapshot.sourceBizNo); |
| | | plan.setPatid(snapshot.patid); |
| | | plan.setPatname(snapshot.patname); |
| | | plan.setPhone(snapshot.phone); |
| | | plan.setIdcardno(snapshot.idcardno); |
| | | plan.setPlannedFollowTime(snapshot.plannedFollowTime); |
| | | plan.setFollowupPeriod(snapshot.followupPeriod); |
| | | plan.setCreateTime(now); |
| | | plan.setUpdateTime(now); |
| | | |
| | | if (snapshot.plannedFollowTime == null) { |
| | | plan.setPlanStatus(MchFollowupConstants.PLAN_STATUS_WAITING); |
| | | plan.setRemark("æé访æ¶é´ä¸ºç©ºï¼å¾
è¡¥å
"); |
| | | planMapper.insertMchFollowupPlan(plan); |
| | | log.warn("ãå¦å¹¼é访ãæé访æ¶é´ä¸ºç©ºï¼çæå¾
è¡¥å
计åï¼archiveType={}ï¼detailId={}", |
| | | snapshot.archiveType, snapshot.archiveDetailId); |
| | | return 0; |
| | | } |
| | | |
| | | List<MchFollowupNode> nodes; |
| | | try { |
| | | nodes = periodParser.parse(snapshot.followupPeriod, snapshot.followupCycleTimes); |
| | | } catch (Exception e) { |
| | | plan.setPlanStatus(MchFollowupConstants.PLAN_STATUS_WAITING); |
| | | plan.setRemark("éè®¿å¨æJSONè§£æå¤±è´¥ï¼" + truncate(e.getMessage(), 200)); |
| | | planMapper.insertMchFollowupPlan(plan); |
| | | log.error("ãå¦å¹¼é访ãéè®¿å¨æè§£æå¤±è´¥ï¼archiveType={}ï¼detailId={}ï¼period={}", |
| | | snapshot.archiveType, snapshot.archiveDetailId, snapshot.followupPeriod, e); |
| | | return 0; |
| | | } |
| | | if (nodes.isEmpty()) { |
| | | plan.setPlanStatus(MchFollowupConstants.PLAN_STATUS_WAITING); |
| | | plan.setRemark("éè®¿å¨ææªé
ç½®åéèç¹"); |
| | | planMapper.insertMchFollowupPlan(plan); |
| | | return 0; |
| | | } |
| | | |
| | | plan.setPlanStatus(MchFollowupConstants.PLAN_STATUS_ACTIVE); |
| | | planMapper.insertMchFollowupPlan(plan); |
| | | List<MchFollowupPlanItem> items = planAssembler.assemble(plan.getId(), snapshot.plannedFollowTime, nodes); |
| | | for (MchFollowupPlanItem item : items) { |
| | | itemMapper.insertMchFollowupPlanItem(item); |
| | | } |
| | | log.info("ãå¦å¹¼é访ã计åéå»ºå®æï¼archiveType={}ï¼archiveId={}ï¼detailId={}ï¼èç¹æ°={}", |
| | | snapshot.archiveType, snapshot.archiveId, snapshot.archiveDetailId, items.size()); |
| | | return items.size(); |
| | | } |
| | | |
| | | @Override |
| | | public int rebuildAll(int limit) { |
| | | if (!isEnabled()) { |
| | | return 0; |
| | | } |
| | | int batch = limit <= 0 ? MchFollowupConstants.DEFAULT_BATCH_SIZE : limit; |
| | | List<MchFollowupArchiveCandidate> candidates = |
| | | planMapper.selectCandidates(SpecificArchiveConstants.LISHUI_MCH_ORG_ID, batch); |
| | | if (candidates == null || candidates.isEmpty()) { |
| | | return 0; |
| | | } |
| | | int generated = 0; |
| | | for (MchFollowupArchiveCandidate candidate : candidates) { |
| | | try { |
| | | generated += rebuildForArchive(candidate.getArchiveType(), |
| | | candidate.getArchiveId(), candidate.getArchiveDetailId()); |
| | | } catch (Exception e) { |
| | | log.error("ãå¦å¹¼é访ã补建计å失败ï¼archiveType={}ï¼archiveId={}ï¼detailId={}", |
| | | candidate.getArchiveType(), candidate.getArchiveId(), |
| | | candidate.getArchiveDetailId(), e); |
| | | } |
| | | } |
| | | return generated; |
| | | } |
| | | |
| | | private ArchiveSnapshot loadSnapshot(String archiveType, Long archiveId, Long archiveDetailId) { |
| | | if (MchFollowupConstants.ARCHIVE_TYPE_MATERNITY.equals(archiveType)) { |
| | | return loadMaternitySnapshot(archiveId, archiveDetailId); |
| | | } |
| | | if (MchFollowupConstants.ARCHIVE_TYPE_CHILD.equals(archiveType)) { |
| | | return loadChildSnapshot(archiveId, archiveDetailId); |
| | | } |
| | | log.warn("ãå¦å¹¼éè®¿ãæªç¥æ¡£æ¡ç±»åï¼{}", archiveType); |
| | | return null; |
| | | } |
| | | |
| | | private ArchiveSnapshot loadMaternitySnapshot(Long archiveId, Long archiveDetailId) { |
| | | PatMaternityArchiveDetail detail = null; |
| | | if (archiveDetailId != null) { |
| | | detail = maternityDetailMapper.selectPatMaternityArchiveDetailById(archiveDetailId); |
| | | } |
| | | if (detail == null && archiveId != null) { |
| | | PatMaternityArchiveDetail query = new PatMaternityArchiveDetail(); |
| | | query.setArchiveid(archiveId); |
| | | List<PatMaternityArchiveDetail> list = |
| | | maternityDetailMapper.selectPatMaternityArchiveDetailList(query); |
| | | if (list != null && !list.isEmpty()) { |
| | | detail = list.get(0); |
| | | } |
| | | } |
| | | if (detail == null) { |
| | | return null; |
| | | } |
| | | ArchiveSnapshot snapshot = new ArchiveSnapshot(); |
| | | snapshot.archiveType = MchFollowupConstants.ARCHIVE_TYPE_MATERNITY; |
| | | snapshot.archiveId = detail.getArchiveid() == null ? archiveId : detail.getArchiveid(); |
| | | snapshot.archiveDetailId = detail.getId(); |
| | | snapshot.orgid = detail.getOrgid(); |
| | | snapshot.campusid = detail.getCampusid(); |
| | | snapshot.sourceType = detail.getSourceType(); |
| | | snapshot.sourceBizNo = detail.getSourceBizNo(); |
| | | snapshot.patid = detail.getPatid(); |
| | | snapshot.patname = detail.getPatname(); |
| | | snapshot.phone = detail.getPhone(); |
| | | snapshot.idcardno = detail.getIdcardno(); |
| | | snapshot.plannedFollowTime = detail.getPlannedFollowTime(); |
| | | snapshot.followupPeriod = detail.getFollowupPeriod(); |
| | | snapshot.followupCycleTimes = detail.getFollowupCycleTimes(); |
| | | return snapshot; |
| | | } |
| | | |
| | | private ArchiveSnapshot loadChildSnapshot(Long archiveId, Long archiveDetailId) { |
| | | PatChildArchiveDetail detail = null; |
| | | if (archiveDetailId != null) { |
| | | detail = childDetailMapper.selectPatChildArchiveDetailById(archiveDetailId); |
| | | } |
| | | if (detail == null && archiveId != null) { |
| | | PatChildArchiveDetail query = new PatChildArchiveDetail(); |
| | | query.setArchiveid(archiveId); |
| | | List<PatChildArchiveDetail> list = |
| | | childDetailMapper.selectPatChildArchiveDetailList(query); |
| | | if (list != null && !list.isEmpty()) { |
| | | detail = list.get(0); |
| | | } |
| | | } |
| | | if (detail == null) { |
| | | return null; |
| | | } |
| | | ArchiveSnapshot snapshot = new ArchiveSnapshot(); |
| | | snapshot.archiveType = MchFollowupConstants.ARCHIVE_TYPE_CHILD; |
| | | snapshot.archiveId = detail.getArchiveid() == null ? archiveId : detail.getArchiveid(); |
| | | snapshot.archiveDetailId = detail.getId(); |
| | | snapshot.orgid = detail.getOrgid(); |
| | | snapshot.campusid = detail.getCampusid(); |
| | | snapshot.sourceType = detail.getSourceType(); |
| | | snapshot.sourceBizNo = detail.getSourceBizNo(); |
| | | snapshot.patid = detail.getPatid(); |
| | | snapshot.patname = detail.getPatname(); |
| | | snapshot.phone = firstNotBlank(detail.getParentPhone(), detail.getPhone()); |
| | | snapshot.idcardno = detail.getIdcardno(); |
| | | snapshot.plannedFollowTime = detail.getPlannedFollowTime(); |
| | | snapshot.followupPeriod = detail.getFollowupPeriod(); |
| | | return snapshot; |
| | | } |
| | | |
| | | private boolean isEnabled() { |
| | | try { |
| | | String value = configService.selectConfigByKey(MchFollowupConstants.CONFIG_ENABLED); |
| | | return value == null || !"false".equalsIgnoreCase(value.trim()); |
| | | } catch (Exception e) { |
| | | log.warn("ãå¦å¹¼é访ã读åå¯ç¨å¼å
³å¤±è´¥ï¼æå¯ç¨å¤çï¼{}", e.getMessage()); |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | private static boolean sameTime(Date left, Date right) { |
| | | if (left == null || right == null) { |
| | | return left == right; |
| | | } |
| | | return Math.abs(left.getTime() - right.getTime()) < 1000L; |
| | | } |
| | | |
| | | private static String firstNotBlank(String first, String second) { |
| | | return StringUtils.isNotBlank(first) ? first : second; |
| | | } |
| | | |
| | | private static String truncate(String text, int maxLength) { |
| | | if (text == null || text.length() <= maxLength) { |
| | | return text; |
| | | } |
| | | return text.substring(0, maxLength); |
| | | } |
| | | |
| | | private static class ArchiveSnapshot { |
| | | private String archiveType; |
| | | private Long archiveId; |
| | | private Long archiveDetailId; |
| | | private String orgid; |
| | | private String campusid; |
| | | private String sourceType; |
| | | private String sourceBizNo; |
| | | private Long patid; |
| | | private String patname; |
| | | private String phone; |
| | | private String idcardno; |
| | | private Date plannedFollowTime; |
| | | private String followupPeriod; |
| | | private String followupCycleTimes; |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | /** |
| | | * å¦å¹¼éè®¿åæ¬¡åéç»æã |
| | | */ |
| | | public class MchFollowupSendOutcome { |
| | | |
| | | private boolean ok; |
| | | |
| | | private boolean skipped; |
| | | |
| | | private String message; |
| | | |
| | | private String providerMsgId; |
| | | |
| | | private String requestBody; |
| | | |
| | | private String responseBody; |
| | | |
| | | public static MchFollowupSendOutcome ok(String providerMsgId, String requestBody, String responseBody) { |
| | | MchFollowupSendOutcome outcome = new MchFollowupSendOutcome(); |
| | | outcome.ok = true; |
| | | outcome.providerMsgId = providerMsgId; |
| | | outcome.requestBody = requestBody; |
| | | outcome.responseBody = responseBody; |
| | | return outcome; |
| | | } |
| | | |
| | | public static MchFollowupSendOutcome fail(String message, String requestBody, String responseBody) { |
| | | MchFollowupSendOutcome outcome = new MchFollowupSendOutcome(); |
| | | outcome.ok = false; |
| | | outcome.message = message; |
| | | outcome.requestBody = requestBody; |
| | | outcome.responseBody = responseBody; |
| | | return outcome; |
| | | } |
| | | |
| | | public static MchFollowupSendOutcome skip(String message) { |
| | | MchFollowupSendOutcome outcome = new MchFollowupSendOutcome(); |
| | | outcome.ok = false; |
| | | outcome.skipped = true; |
| | | outcome.message = message; |
| | | return outcome; |
| | | } |
| | | |
| | | public boolean isOk() { |
| | | return ok; |
| | | } |
| | | |
| | | public boolean isSkipped() { |
| | | return skipped; |
| | | } |
| | | |
| | | public String getMessage() { |
| | | return message; |
| | | } |
| | | |
| | | public String getProviderMsgId() { |
| | | return providerMsgId; |
| | | } |
| | | |
| | | public String getRequestBody() { |
| | | return requestBody; |
| | | } |
| | | |
| | | public String getResponseBody() { |
| | | return responseBody; |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.smartor.common.MchFollowupConstants; |
| | | import com.smartor.common.SpecificArchiveConstants; |
| | | import com.smartor.domain.MchFollowupPlan; |
| | | import com.smartor.domain.MchFollowupPlanItem; |
| | | import com.smartor.domain.MchFollowupSendLog; |
| | | import com.smartor.mapper.MchFollowupPlanItemMapper; |
| | | import com.smartor.mapper.MchFollowupPlanMapper; |
| | | import com.smartor.mapper.MchFollowupSendLogMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * å¦å¹¼é访åéæå¡å®ç°ã |
| | | * |
| | | * <p>åªåé丽水å¦å¹¼ç计åèç¹ï¼ä¸è¿å
¥æ®éé访çè¡¥å¿åéé¾è·¯ã</p> |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class MchFollowupSendServiceImpl implements IMchFollowupSendService { |
| | | |
| | | @Autowired |
| | | private MchFollowupPlanMapper planMapper; |
| | | |
| | | @Autowired |
| | | private MchFollowupPlanItemMapper itemMapper; |
| | | |
| | | @Autowired |
| | | private MchFollowupSendLogMapper sendLogMapper; |
| | | |
| | | @Autowired |
| | | private MchFollowupMessageSender messageSender; |
| | | |
| | | @Autowired |
| | | private MchFollowupSendWindow sendWindow; |
| | | |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | @Override |
| | | public int sendDue(int limit) { |
| | | if (!isEnabled()) { |
| | | return 0; |
| | | } |
| | | int batch = limit <= 0 ? MchFollowupConstants.DEFAULT_BATCH_SIZE : limit; |
| | | Date now = new Date(); |
| | | List<MchFollowupPlanItem> dueItems = itemMapper.selectDueItems( |
| | | SpecificArchiveConstants.LISHUI_MCH_ORG_ID, now, batch); |
| | | if (dueItems == null || dueItems.isEmpty()) { |
| | | return 0; |
| | | } |
| | | |
| | | int success = 0; |
| | | for (MchFollowupPlanItem item : dueItems) { |
| | | try { |
| | | MchFollowupDueDecision decision = sendWindow.decide(item.getSendTime(), now); |
| | | if (decision == MchFollowupDueDecision.PENDING) { |
| | | continue; |
| | | } |
| | | if (decision == MchFollowupDueDecision.EXPIRED) { |
| | | markExpired(item, now); |
| | | refreshPlanStatus(item.getPlanId()); |
| | | continue; |
| | | } |
| | | if (itemMapper.claimItem(item.getId(), now) != 1) { |
| | | continue; |
| | | } |
| | | |
| | | MchFollowupPlan plan = planMapper.selectMchFollowupPlanById(item.getPlanId()); |
| | | if (plan == null || !MchFollowupConstants.PLAN_STATUS_ACTIVE.equals(plan.getPlanStatus())) { |
| | | markCanceled(item, now, "计åä¸å卿已失æ"); |
| | | refreshPlanStatus(item.getPlanId()); |
| | | continue; |
| | | } |
| | | |
| | | MchFollowupSendOutcome outcome = send(plan, item); |
| | | Date finishTime = new Date(); |
| | | if (outcome.isSkipped()) { |
| | | markSkipped(item, finishTime, outcome.getMessage()); |
| | | } else if (outcome.isOk()) { |
| | | markSuccess(item, finishTime, outcome); |
| | | success++; |
| | | } else { |
| | | markFailureOrRetry(item, finishTime, outcome); |
| | | } |
| | | writeLog(item, outcome, now); |
| | | refreshPlanStatus(plan.getId()); |
| | | } catch (Exception e) { |
| | | log.error("ãå¦å¹¼é访ãåéèç¹å¼å¸¸ï¼itemId={}ï¼planId={}", |
| | | item.getId(), item.getPlanId(), e); |
| | | try { |
| | | markFailureOrRetry(item, new Date(), |
| | | MchFollowupSendOutcome.fail("åéå¼å¸¸ï¼" + e.getMessage(), null, null)); |
| | | refreshPlanStatus(item.getPlanId()); |
| | | } catch (Exception ignore) { |
| | | log.error("ãå¦å¹¼é访ãå¼å¸¸åå失败ï¼itemId={}", item.getId(), ignore); |
| | | } |
| | | } |
| | | } |
| | | return success; |
| | | } |
| | | |
| | | private MchFollowupSendOutcome send(MchFollowupPlan plan, MchFollowupPlanItem item) { |
| | | if (MchFollowupConstants.SEND_TYPE_SMS.equals(item.getSendType())) { |
| | | return messageSender.sendSms(plan, item); |
| | | } |
| | | if (MchFollowupConstants.SEND_TYPE_WECHAT.equals(item.getSendType())) { |
| | | return messageSender.sendWechat(plan, item); |
| | | } |
| | | return MchFollowupSendOutcome.fail("䏿¯æçåéæ¹å¼ï¼" + item.getSendType(), null, null); |
| | | } |
| | | |
| | | private void markExpired(MchFollowupPlanItem item, Date now) { |
| | | item.setSendStatus(MchFollowupConstants.ITEM_STATUS_EXPIRED); |
| | | item.setNextRetryTime(null); |
| | | item.setSendTimeActual(null); |
| | | item.setProviderMsgId(null); |
| | | item.setResultMsg("è¶
è¿è¡¥åçªå£ï¼1天ï¼ï¼æ è®°è¿æ"); |
| | | item.setUpdateTime(now); |
| | | itemMapper.updateSendResult(item); |
| | | writeLog(item, MchFollowupSendOutcome.fail(item.getResultMsg(), null, null), now); |
| | | } |
| | | |
| | | private void markCanceled(MchFollowupPlanItem item, Date now, String message) { |
| | | item.setSendStatus(MchFollowupConstants.ITEM_STATUS_CANCELED); |
| | | item.setNextRetryTime(null); |
| | | item.setResultMsg(message); |
| | | item.setUpdateTime(now); |
| | | itemMapper.updateSendResult(item); |
| | | } |
| | | |
| | | private void markSkipped(MchFollowupPlanItem item, Date now, String message) { |
| | | item.setSendStatus(MchFollowupConstants.ITEM_STATUS_SKIPPED); |
| | | item.setNextRetryTime(null); |
| | | item.setResultMsg(message); |
| | | item.setUpdateTime(now); |
| | | itemMapper.updateSendResult(item); |
| | | } |
| | | |
| | | private void markSuccess(MchFollowupPlanItem item, Date now, MchFollowupSendOutcome outcome) { |
| | | item.setSendStatus(MchFollowupConstants.ITEM_STATUS_SUCCESS); |
| | | item.setNextRetryTime(null); |
| | | item.setSendTimeActual(now); |
| | | item.setProviderMsgId(outcome.getProviderMsgId()); |
| | | item.setResultMsg("åéæå"); |
| | | item.setUpdateTime(now); |
| | | itemMapper.updateSendResult(item); |
| | | } |
| | | |
| | | private void markFailureOrRetry(MchFollowupPlanItem item, Date now, MchFollowupSendOutcome outcome) { |
| | | int retryCount = item.getRetryCount() == null ? 0 : item.getRetryCount(); |
| | | retryCount++; |
| | | item.setRetryCount(retryCount); |
| | | item.setSendTimeActual(now); |
| | | item.setProviderMsgId(outcome.getProviderMsgId()); |
| | | if (retryCount < MchFollowupConstants.DEFAULT_MAX_RETRY) { |
| | | item.setSendStatus(MchFollowupConstants.ITEM_STATUS_PENDING); |
| | | item.setNextRetryTime(new Date(now.getTime() |
| | | + MchFollowupConstants.DEFAULT_RETRY_DELAY_MINUTES * 60L * 1000L)); |
| | | item.setResultMsg((outcome.getMessage() == null ? "åé失败" : outcome.getMessage()) |
| | | + "ï¼ç¬¬" + retryCount + "次éè¯åè¿å
¥çå¾
"); |
| | | } else { |
| | | item.setSendStatus(MchFollowupConstants.ITEM_STATUS_FAILED); |
| | | item.setNextRetryTime(null); |
| | | item.setResultMsg((outcome.getMessage() == null ? "åé失败" : outcome.getMessage()) |
| | | + "ï¼éè¯æ¬¡æ°å·²è¾¾ä¸é"); |
| | | } |
| | | item.setUpdateTime(now); |
| | | itemMapper.updateSendResult(item); |
| | | } |
| | | |
| | | private void writeLog(MchFollowupPlanItem item, MchFollowupSendOutcome outcome, Date now) { |
| | | MchFollowupSendLog sendLog = new MchFollowupSendLog(); |
| | | sendLog.setPlanId(item.getPlanId()); |
| | | sendLog.setItemId(item.getId()); |
| | | sendLog.setSendType(item.getSendType()); |
| | | sendLog.setRequestBody(outcome.getRequestBody()); |
| | | sendLog.setResponseBody(outcome.getResponseBody()); |
| | | sendLog.setSendStatus(item.getSendStatus()); |
| | | sendLog.setResultMsg(item.getResultMsg()); |
| | | sendLog.setCreateTime(now); |
| | | sendLogMapper.insertMchFollowupSendLog(sendLog); |
| | | } |
| | | |
| | | private void refreshPlanStatus(Long planId) { |
| | | if (planId == null) { |
| | | return; |
| | | } |
| | | if (itemMapper.countPendingByPlanId(planId) == 0) { |
| | | planMapper.completeById(planId, new Date()); |
| | | } |
| | | } |
| | | |
| | | private boolean isEnabled() { |
| | | try { |
| | | String value = configService.selectConfigByKey(MchFollowupConstants.CONFIG_ENABLED); |
| | | return value == null || !"false".equalsIgnoreCase(value.trim()); |
| | | } catch (Exception e) { |
| | | log.warn("ãå¦å¹¼é访ã读åå¯ç¨å¼å
³å¤±è´¥ï¼æå¯ç¨å¤çï¼{}", e.getMessage()); |
| | | return true; |
| | | } |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | import com.smartor.common.MchFollowupConstants; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * å¦å¹¼é访补åçªå£å¤æã |
| | | * |
| | | * <p>åªè¡¥å 1 天å
å°æçèç¹ï¼è¶
è¿ 1 天æ è®°è¿æï¼é¿å
ç»æ£è
åè¿æ¶æ¶æ¯ã</p> |
| | | */ |
| | | @Component |
| | | public class MchFollowupSendWindow { |
| | | |
| | | public MchFollowupDueDecision decide(Date sendTime, Date now) { |
| | | if (sendTime == null) { |
| | | return MchFollowupDueDecision.PENDING; |
| | | } |
| | | Date current = now == null ? new Date() : now; |
| | | if (sendTime.after(current)) { |
| | | return MchFollowupDueDecision.PENDING; |
| | | } |
| | | Date expireBefore = new Date(current.getTime() - MchFollowupConstants.CATCHUP_MILLIS); |
| | | if (sendTime.before(expireBefore)) { |
| | | return MchFollowupDueDecision.EXPIRED; |
| | | } |
| | | return MchFollowupDueDecision.SEND; |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | import com.smartor.domain.MchFollowupNode; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * å¦å¹¼é访èç¹åéæ¶é´è®¡ç®ã |
| | | * |
| | | * <p>plannedFollowTime æ¯æ´ä¸ªå¨æçåºåæ¥ï¼</p> |
| | | * <pre> |
| | | * send_time = date(plannedFollowTime) + dayOffset + æ¶åç§ |
| | | * </pre> |
| | | * |
| | | * <p>æ¶åç§ä¼å
级ï¼item.sendTime > plannedFollowTime çæ¶åç§ï¼é 00:00:00ï¼> 09:00ã</p> |
| | | */ |
| | | @Component |
| | | public class MchFollowupTimeResolver { |
| | | |
| | | private static final LocalTime DEFAULT_TIME = LocalTime.of(9, 0); |
| | | |
| | | private static final DateTimeFormatter HH_MM = DateTimeFormatter.ofPattern("HH:mm"); |
| | | |
| | | private static final DateTimeFormatter HH_MM_SS = DateTimeFormatter.ofPattern("HH:mm:ss"); |
| | | |
| | | public Date resolve(Date plannedFollowTime, MchFollowupNode node) { |
| | | if (plannedFollowTime == null || node == null || node.getDayOffset() == null) { |
| | | return null; |
| | | } |
| | | LocalDateTime base = LocalDateTime.ofInstant(plannedFollowTime.toInstant(), ZoneId.systemDefault()); |
| | | LocalDate sendDate = base.toLocalDate().plusDays(node.getDayOffset()); |
| | | LocalTime sendTime = resolveTime(base.toLocalTime(), node.getSendTime()); |
| | | return Date.from(LocalDateTime.of(sendDate, sendTime).atZone(ZoneId.systemDefault()).toInstant()); |
| | | } |
| | | |
| | | private LocalTime resolveTime(LocalTime baselineTime, String itemSendTime) { |
| | | if (StringUtils.isNotBlank(itemSendTime)) { |
| | | return parseTime(itemSendTime); |
| | | } |
| | | if (baselineTime != null && baselineTime.toSecondOfDay() != 0) { |
| | | return baselineTime; |
| | | } |
| | | return DEFAULT_TIME; |
| | | } |
| | | |
| | | private LocalTime parseTime(String value) { |
| | | String text = value.trim(); |
| | | if (text.length() == 5) { |
| | | return LocalTime.parse(text, HH_MM); |
| | | } |
| | | return LocalTime.parse(text, HH_MM_SS); |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.smartor.mapper.MchFollowupPlanItemMapper"> |
| | | |
| | | <resultMap id="MchFollowupPlanItemResult" type="com.smartor.domain.MchFollowupPlanItem"> |
| | | <id property="id" column="id"/> |
| | | <result property="planId" column="plan_id"/> |
| | | <result property="seq" column="seq"/> |
| | | <result property="sendType" column="send_type"/> |
| | | <result property="sendTime" column="send_time"/> |
| | | <result property="titleName" column="title_name"/> |
| | | <result property="content" column="content"/> |
| | | <result property="templateId" column="template_id"/> |
| | | <result property="url" column="url"/> |
| | | <result property="sendStatus" column="send_status"/> |
| | | <result property="retryCount" column="retry_count"/> |
| | | <result property="nextRetryTime" column="next_retry_time"/> |
| | | <result property="sendTimeActual" column="send_time_actual"/> |
| | | <result property="resultMsg" column="result_msg"/> |
| | | <result property="providerMsgId" column="provider_msg_id"/> |
| | | <result property="createTime" column="create_time"/> |
| | | <result property="updateTime" column="update_time"/> |
| | | </resultMap> |
| | | |
| | | <sql id="selectItemVo"> |
| | | select id, plan_id, seq, send_type, send_time, title_name, content, template_id, url, |
| | | send_status, retry_count, next_retry_time, send_time_actual, |
| | | result_msg, provider_msg_id, create_time, update_time |
| | | from mch_followup_plan_item |
| | | </sql> |
| | | |
| | | <insert id="insertMchFollowupPlanItem" parameterType="com.smartor.domain.MchFollowupPlanItem" |
| | | useGeneratedKeys="true" keyProperty="id"> |
| | | insert into mch_followup_plan_item |
| | | (plan_id, seq, send_type, send_time, title_name, content, template_id, url, |
| | | send_status, retry_count, next_retry_time, send_time_actual, |
| | | result_msg, provider_msg_id, create_time, update_time) |
| | | values |
| | | (#{planId}, #{seq}, #{sendType}, #{sendTime}, #{titleName}, #{content}, #{templateId}, #{url}, |
| | | #{sendStatus}, #{retryCount}, #{nextRetryTime}, #{sendTimeActual}, |
| | | #{resultMsg}, #{providerMsgId}, #{createTime}, #{updateTime}) |
| | | </insert> |
| | | |
| | | <update id="updateMchFollowupPlanItem" parameterType="com.smartor.domain.MchFollowupPlanItem"> |
| | | update mch_followup_plan_item |
| | | <set> |
| | | <if test="sendType != null">send_type = #{sendType},</if> |
| | | <if test="sendTime != null">send_time = #{sendTime},</if> |
| | | <if test="titleName != null">title_name = #{titleName},</if> |
| | | <if test="content != null">content = #{content},</if> |
| | | <if test="templateId != null">template_id = #{templateId},</if> |
| | | <if test="url != null">url = #{url},</if> |
| | | <if test="sendStatus != null">send_status = #{sendStatus},</if> |
| | | <if test="retryCount != null">retry_count = #{retryCount},</if> |
| | | <if test="nextRetryTime != null">next_retry_time = #{nextRetryTime},</if> |
| | | <if test="sendTimeActual != null">send_time_actual = #{sendTimeActual},</if> |
| | | <if test="resultMsg != null">result_msg = #{resultMsg},</if> |
| | | <if test="providerMsgId != null">provider_msg_id = #{providerMsgId},</if> |
| | | <if test="updateTime != null">update_time = #{updateTime},</if> |
| | | </set> |
| | | where id = #{id} |
| | | </update> |
| | | |
| | | <update id="updateSendResult" parameterType="com.smartor.domain.MchFollowupPlanItem"> |
| | | update mch_followup_plan_item |
| | | set send_status = #{sendStatus,jdbcType=CHAR}, |
| | | retry_count = #{retryCount,jdbcType=INTEGER}, |
| | | next_retry_time = #{nextRetryTime,jdbcType=TIMESTAMP}, |
| | | send_time_actual = #{sendTimeActual,jdbcType=TIMESTAMP}, |
| | | result_msg = #{resultMsg,jdbcType=VARCHAR}, |
| | | provider_msg_id = #{providerMsgId,jdbcType=VARCHAR}, |
| | | update_time = #{updateTime,jdbcType=TIMESTAMP} |
| | | where id = #{id} |
| | | </update> |
| | | |
| | | <select id="selectMchFollowupPlanItemById" resultMap="MchFollowupPlanItemResult"> |
| | | <include refid="selectItemVo"/> |
| | | where id = #{id} |
| | | </select> |
| | | |
| | | <select id="selectByPlanId" resultMap="MchFollowupPlanItemResult"> |
| | | <include refid="selectItemVo"/> |
| | | where plan_id = #{planId} |
| | | order by seq asc, id asc |
| | | </select> |
| | | |
| | | <select id="selectDueItems" resultMap="MchFollowupPlanItemResult"> |
| | | select i.id, i.plan_id, i.seq, i.send_type, i.send_time, i.title_name, i.content, |
| | | i.template_id, i.url, i.send_status, i.retry_count, i.next_retry_time, |
| | | i.send_time_actual, i.result_msg, i.provider_msg_id, i.create_time, i.update_time |
| | | from mch_followup_plan_item i |
| | | inner join mch_followup_plan p on p.id = i.plan_id |
| | | where p.orgid = #{orgid} |
| | | and p.plan_status = '0' |
| | | and i.send_status = '0' |
| | | and i.send_time <= #{now} |
| | | and (i.next_retry_time is null or i.next_retry_time <= #{now}) |
| | | order by i.send_time asc, i.seq asc, i.id asc |
| | | limit #{limit} |
| | | </select> |
| | | |
| | | <update id="claimItem"> |
| | | update mch_followup_plan_item |
| | | set send_status = '1', |
| | | update_time = #{now} |
| | | where id = #{id} |
| | | and send_status = '0' |
| | | </update> |
| | | |
| | | <update id="cancelPendingByPlanId"> |
| | | update mch_followup_plan_item |
| | | set send_status = '5', |
| | | result_msg = '计åé建ï¼åæ¶æªåéèç¹', |
| | | update_time = #{now} |
| | | where plan_id = #{planId} |
| | | and send_status = '0' |
| | | </update> |
| | | |
| | | <select id="countPendingByPlanId" resultType="int"> |
| | | select count(1) |
| | | from mch_followup_plan_item |
| | | where plan_id = #{planId} |
| | | and send_status in ('0', '1') |
| | | </select> |
| | | |
| | | </mapper> |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.smartor.mapper.MchFollowupPlanMapper"> |
| | | |
| | | <resultMap id="MchFollowupPlanResult" type="com.smartor.domain.MchFollowupPlan"> |
| | | <id property="id" column="id"/> |
| | | <result property="orgid" column="orgid"/> |
| | | <result property="campusid" column="campusid"/> |
| | | <result property="archiveType" column="archive_type"/> |
| | | <result property="archiveId" column="archive_id"/> |
| | | <result property="archiveDetailId" column="archive_detail_id"/> |
| | | <result property="sourceType" column="source_type"/> |
| | | <result property="sourceBizNo" column="source_biz_no"/> |
| | | <result property="patid" column="patid"/> |
| | | <result property="patname" column="patname"/> |
| | | <result property="phone" column="phone"/> |
| | | <result property="idcardno" column="idcardno"/> |
| | | <result property="plannedFollowTime" column="planned_follow_time"/> |
| | | <result property="followupPeriod" column="followup_period"/> |
| | | <result property="planStatus" column="plan_status"/> |
| | | <result property="remark" column="remark"/> |
| | | <result property="createTime" column="create_time"/> |
| | | <result property="updateTime" column="update_time"/> |
| | | </resultMap> |
| | | |
| | | <sql id="selectPlanVo"> |
| | | select id, orgid, campusid, archive_type, archive_id, archive_detail_id, |
| | | source_type, source_biz_no, patid, patname, phone, idcardno, |
| | | planned_follow_time, followup_period, plan_status, remark, |
| | | create_time, update_time |
| | | from mch_followup_plan |
| | | </sql> |
| | | |
| | | <insert id="insertMchFollowupPlan" parameterType="com.smartor.domain.MchFollowupPlan" |
| | | useGeneratedKeys="true" keyProperty="id"> |
| | | insert into mch_followup_plan |
| | | (orgid, campusid, archive_type, archive_id, archive_detail_id, |
| | | source_type, source_biz_no, patid, patname, phone, idcardno, |
| | | planned_follow_time, followup_period, plan_status, remark, |
| | | create_time, update_time) |
| | | values |
| | | (#{orgid}, #{campusid}, #{archiveType}, #{archiveId}, #{archiveDetailId}, |
| | | #{sourceType}, #{sourceBizNo}, #{patid}, #{patname}, #{phone}, #{idcardno}, |
| | | #{plannedFollowTime}, #{followupPeriod}, #{planStatus}, #{remark}, |
| | | #{createTime}, #{updateTime}) |
| | | </insert> |
| | | |
| | | <update id="updateMchFollowupPlan" parameterType="com.smartor.domain.MchFollowupPlan"> |
| | | update mch_followup_plan |
| | | <set> |
| | | <if test="orgid != null">orgid = #{orgid},</if> |
| | | <if test="campusid != null">campusid = #{campusid},</if> |
| | | <if test="archiveType != null">archive_type = #{archiveType},</if> |
| | | <if test="archiveId != null">archive_id = #{archiveId},</if> |
| | | <if test="archiveDetailId != null">archive_detail_id = #{archiveDetailId},</if> |
| | | <if test="sourceType != null">source_type = #{sourceType},</if> |
| | | <if test="sourceBizNo != null">source_biz_no = #{sourceBizNo},</if> |
| | | <if test="patid != null">patid = #{patid},</if> |
| | | <if test="patname != null">patname = #{patname},</if> |
| | | <if test="phone != null">phone = #{phone},</if> |
| | | <if test="idcardno != null">idcardno = #{idcardno},</if> |
| | | <if test="plannedFollowTime != null">planned_follow_time = #{plannedFollowTime},</if> |
| | | <if test="followupPeriod != null">followup_period = #{followupPeriod},</if> |
| | | <if test="planStatus != null">plan_status = #{planStatus},</if> |
| | | <if test="remark != null">remark = #{remark},</if> |
| | | <if test="updateTime != null">update_time = #{updateTime},</if> |
| | | </set> |
| | | where id = #{id} |
| | | </update> |
| | | |
| | | <select id="selectMchFollowupPlanById" resultMap="MchFollowupPlanResult"> |
| | | <include refid="selectPlanVo"/> |
| | | where id = #{id} |
| | | </select> |
| | | |
| | | <select id="selectActiveByArchive" resultMap="MchFollowupPlanResult"> |
| | | <include refid="selectPlanVo"/> |
| | | where archive_type = #{archiveType} |
| | | and archive_id = #{archiveId} |
| | | <if test="archiveDetailId != null"> |
| | | and archive_detail_id = #{archiveDetailId} |
| | | </if> |
| | | and plan_status in ('0', '3') |
| | | order by id desc |
| | | </select> |
| | | |
| | | <update id="cancelById"> |
| | | update mch_followup_plan |
| | | set plan_status = '1', |
| | | update_time = #{updateTime} |
| | | where id = #{id} |
| | | and plan_status in ('0', '3') |
| | | </update> |
| | | |
| | | <update id="completeById"> |
| | | update mch_followup_plan |
| | | set plan_status = '2', |
| | | update_time = #{updateTime} |
| | | where id = #{id} |
| | | and plan_status = '0' |
| | | </update> |
| | | |
| | | <select id="selectCandidates" resultType="com.smartor.domain.MchFollowupArchiveCandidate"> |
| | | select '1' as archiveType, d.archiveid as archiveId, d.id as archiveDetailId |
| | | from pat_maternity_archive_detail d |
| | | where d.orgid = #{orgid} |
| | | and (d.del_flag is null or d.del_flag = '0') |
| | | and d.planned_follow_time is not null |
| | | and d.followup_period is not null |
| | | and d.followup_period <> '' |
| | | and d.archiveid is not null |
| | | union all |
| | | select '2' as archiveType, d.archiveid as archiveId, d.id as archiveDetailId |
| | | from pat_child_archive_detail d |
| | | where d.orgid = #{orgid} |
| | | and (d.del_flag is null or d.del_flag = '0') |
| | | and d.planned_follow_time is not null |
| | | and d.followup_period is not null |
| | | and d.followup_period <> '' |
| | | and d.archiveid is not null |
| | | limit #{limit} |
| | | </select> |
| | | |
| | | </mapper> |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.smartor.mapper.MchFollowupSendLogMapper"> |
| | | |
| | | <insert id="insertMchFollowupSendLog" parameterType="com.smartor.domain.MchFollowupSendLog" |
| | | useGeneratedKeys="true" keyProperty="id"> |
| | | insert into mch_followup_send_log |
| | | (plan_id, item_id, send_type, request_body, response_body, send_status, result_msg, create_time) |
| | | values |
| | | (#{planId}, #{itemId}, #{sendType}, #{requestBody}, #{responseBody}, #{sendStatus}, #{resultMsg}, #{createTime}) |
| | | </insert> |
| | | |
| | | </mapper> |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | import com.smartor.common.MchFollowupConstants; |
| | | import com.smartor.domain.MchFollowupNode; |
| | | import com.smartor.domain.MchFollowupPlanItem; |
| | | |
| | | import javax.xml.parsers.DocumentBuilderFactory; |
| | | import java.io.File; |
| | | import java.lang.reflect.Field; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * å¦å¹¼é访é»è¾èªæ£ï¼çº¯ mainï¼ä¸ä¾èµ JUnit / Spring / æ°æ®åºï¼ã |
| | | * |
| | | * è¦çï¼followupPeriod JSON è§£æã计ååºåæ¥æ¶é´è®¡ç®ã1 天补åçªå£ã |
| | | * èç¹ç»è£
ãMapper XML å¯è§£ææ§ã |
| | | */ |
| | | public final class MchFollowupLogicCheck { |
| | | |
| | | private static int passed = 0; |
| | | private static int failed = 0; |
| | | |
| | | private static final SimpleDateFormat DATE_TIME = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | private static void check(String key, Object expected, Object actual) { |
| | | boolean ok = expected == null ? actual == null : expected.equals(actual); |
| | | if (ok) { |
| | | passed++; |
| | | System.out.println(" [OK] " + key + " = " + actual); |
| | | } else { |
| | | failed++; |
| | | System.out.println(" [FAIL] " + key + " ææ=" + expected + " å®é
=" + actual); |
| | | } |
| | | } |
| | | |
| | | private static void expectFail(String key, Runnable action) { |
| | | try { |
| | | action.run(); |
| | | failed++; |
| | | System.out.println(" [FAIL] " + key + " æææå¼å¸¸ï¼å®é
æªæ"); |
| | | } catch (Exception e) { |
| | | passed++; |
| | | System.out.println(" [OK] " + key + " æå¼å¸¸ï¼" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private static Date date(String text) throws Exception { |
| | | return DATE_TIME.parse(text); |
| | | } |
| | | |
| | | private static MchFollowupPlanAssembler assembler() throws Exception { |
| | | MchFollowupPlanAssembler assembler = new MchFollowupPlanAssembler(); |
| | | Field field = MchFollowupPlanAssembler.class.getDeclaredField("timeResolver"); |
| | | field.setAccessible(true); |
| | | field.set(assembler, new MchFollowupTimeResolver()); |
| | | return assembler; |
| | | } |
| | | |
| | | private static MchFollowupNode node(int seq, int dayOffset, String sendTime, String sendType) { |
| | | MchFollowupNode node = new MchFollowupNode(); |
| | | node.setSeq(seq); |
| | | node.setDayOffset(dayOffset); |
| | | node.setSendTime(sendTime); |
| | | node.setSendType(sendType); |
| | | node.setContent("å
容" + seq); |
| | | return node; |
| | | } |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | System.out.println("========== å¦å¹¼é访é»è¾èªæ£ =========="); |
| | | MchFollowupPeriodParser parser = new MchFollowupPeriodParser(); |
| | | MchFollowupTimeResolver resolver = new MchFollowupTimeResolver(); |
| | | MchFollowupSendWindow window = new MchFollowupSendWindow(); |
| | | |
| | | System.out.println("-- 1) items JSON è§£æ --"); |
| | | String itemsJson = "{" |
| | | + "\"version\":1," |
| | | + "\"items\":[" |
| | | + "{\"seq\":1,\"dayOffset\":0,\"sendTime\":\"09:00\",\"sendType\":\"sms\",\"content\":\"çä¿¡1\"}," |
| | | + "{\"seq\":2,\"dayOffset\":3,\"sendType\":\"5\",\"templateId\":16,\"titleName\":\"æé\",\"content\":\"微信2\"}," |
| | | + "{\"seq\":3,\"dayOffset\":7,\"sendType\":\"çä¿¡\",\"content\":\"çä¿¡3\"}" |
| | | + "]}"; |
| | | List<MchFollowupNode> itemNodes = parser.parse(itemsJson, null); |
| | | check("èç¹æ°", 3, itemNodes.size()); |
| | | check("seq1", 1, itemNodes.get(0).getSeq()); |
| | | check("dayOffset1", 0, itemNodes.get(0).getDayOffset()); |
| | | check("sendType1", "sms", itemNodes.get(0).getSendType()); |
| | | check("sendType2", "wechat", itemNodes.get(1).getSendType()); |
| | | check("templateId2", 16L, itemNodes.get(1).getTemplateId()); |
| | | check("sendTime1", "09:00", itemNodes.get(0).getSendTime()); |
| | | |
| | | System.out.println("-- 2) intervalDays + count è§£æ --"); |
| | | String intervalJson = "{\"intervalDays\":3,\"count\":4,\"sendType\":\"sms\",\"content\":\"é´éçä¿¡\",\"sendTime\":\"08:30\"}"; |
| | | List<MchFollowupNode> intervalNodes = parser.parse(intervalJson, null); |
| | | check("é´éèç¹æ°", 4, intervalNodes.size()); |
| | | check("èç¹1åç§»", 0, intervalNodes.get(0).getDayOffset()); |
| | | check("èç¹2åç§»", 3, intervalNodes.get(1).getDayOffset()); |
| | | check("èç¹3åç§»", 6, intervalNodes.get(2).getDayOffset()); |
| | | check("èç¹4åç§»", 9, intervalNodes.get(3).getDayOffset()); |
| | | check("é´ésendTime", "08:30", intervalNodes.get(0).getSendTime()); |
| | | |
| | | System.out.println("-- 3) intervalDays + followupCycleTimes å
åº --"); |
| | | List<MchFollowupNode> cycleNodes = parser.parse( |
| | | "{\"intervalDays\":2,\"sendType\":\"wechat\",\"content\":\"微信\"}", "3"); |
| | | check("å
åºæ¬¡æ°", 3, cycleNodes.size()); |
| | | check("å
åºèç¹3åç§»", 4, cycleNodes.get(2).getDayOffset()); |
| | | |
| | | System.out.println("-- 4) days æ°ç»è§£æ --"); |
| | | List<MchFollowupNode> dayNodes = parser.parse( |
| | | "{\"days\":[0,7,14],\"sendType\":\"sms\",\"content\":\"æå¤©\"}", null); |
| | | check("daysèç¹æ°", 3, dayNodes.size()); |
| | | check("daysèç¹2åç§»", 7, dayNodes.get(1).getDayOffset()); |
| | | |
| | | System.out.println("-- 5) éæ³ JSON / 鿳忮µ --"); |
| | | expectFail("éæ³JSON", () -> parser.parse("{bad", null)); |
| | | expectFail("空èç¹", () -> parser.parse("{\"items\":[]}", null)); |
| | | expectFail("éæ³sendType", () -> parser.parse( |
| | | "{\"items\":[{\"dayOffset\":0,\"sendType\":\"phone\",\"content\":\"x\"}]}", null)); |
| | | expectFail("ç信缺content", () -> parser.parse( |
| | | "{\"items\":[{\"dayOffset\":0,\"sendType\":\"sms\"}]}", null)); |
| | | expectFail("éæ³sendTime", () -> parser.parse( |
| | | "{\"items\":[{\"dayOffset\":0,\"sendTime\":\"25:00\",\"sendType\":\"sms\",\"content\":\"x\"}]}", null)); |
| | | |
| | | System.out.println("-- 6) åºåæ¥æ¶é´è®¡ç® --"); |
| | | Date baseline = date("2026-11-20 14:30:00"); |
| | | check("day0沿ç¨14:30", "2026-11-20 14:30:00", |
| | | DATE_TIME.format(resolver.resolve(baseline, node(1, 0, null, "sms")))); |
| | | check("day3沿ç¨14:30", "2026-11-23 14:30:00", |
| | | DATE_TIME.format(resolver.resolve(baseline, node(2, 3, null, "sms")))); |
| | | check("day7æ¾å¼09:00", "2026-11-27 09:00:00", |
| | | DATE_TIME.format(resolver.resolve(baseline, node(3, 7, "09:00", "wechat")))); |
| | | Date midnight = date("2026-11-20 00:00:00"); |
| | | check("åºåæ¥00:00é»è®¤09:00", "2026-11-20 09:00:00", |
| | | DATE_TIME.format(resolver.resolve(midnight, node(1, 0, null, "sms")))); |
| | | |
| | | System.out.println("-- 7) 1 天补åçªå£ --"); |
| | | Date now = date("2026-11-20 12:00:00"); |
| | | check("æªæ¥èç¹å¾
åé", MchFollowupDueDecision.PENDING, |
| | | window.decide(date("2026-11-20 12:01:00"), now)); |
| | | check("1å°æ¶å
è¡¥å", MchFollowupDueDecision.SEND, |
| | | window.decide(date("2026-11-20 11:00:00"), now)); |
| | | check("æ°å¥½24å°æ¶è¡¥å", MchFollowupDueDecision.SEND, |
| | | window.decide(date("2026-11-19 12:00:00"), now)); |
| | | check("è¶
è¿24å°æ¶è¿æ", MchFollowupDueDecision.EXPIRED, |
| | | window.decide(date("2026-11-19 11:59:59"), now)); |
| | | |
| | | System.out.println("-- 8) èç¹ç»è£
--"); |
| | | List<MchFollowupPlanItem> items = assembler().assemble(99L, baseline, itemNodes); |
| | | check("ç»è£
èç¹æ°", 3, items.size()); |
| | | check("planId", 99L, items.get(0).getPlanId()); |
| | | check("åå§ç¶æ", MchFollowupConstants.ITEM_STATUS_PENDING, items.get(0).getSendStatus()); |
| | | check("éè¯æ¬¡æ°", 0, items.get(0).getRetryCount()); |
| | | check("ç»è£
æ¶é´1", "2026-11-20 09:00:00", DATE_TIME.format(items.get(0).getSendTime())); |
| | | check("ç»è£
æ¶é´3沿ç¨åºåæ¥14:30", "2026-11-27 14:30:00", DATE_TIME.format(items.get(2).getSendTime())); |
| | | |
| | | System.out.println("-- 9) Mapper XML å¯è§£ææ§ --"); |
| | | String[] xmlFiles = new String[]{ |
| | | "smartor/src/main/resources/mapper/smartor/MchFollowupPlanMapper.xml", |
| | | "smartor/src/main/resources/mapper/smartor/MchFollowupPlanItemMapper.xml", |
| | | "smartor/src/main/resources/mapper/smartor/MchFollowupSendLogMapper.xml" |
| | | }; |
| | | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
| | | factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); |
| | | for (String xmlFile : xmlFiles) { |
| | | try { |
| | | factory.newDocumentBuilder().parse(new File(xmlFile)); |
| | | check(xmlFile, "OK", "OK"); |
| | | } catch (Exception e) { |
| | | check(xmlFile, "OK", e.getClass().getSimpleName() + ":" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | System.out.println("-- 10) SQL èæ¬å卿§ --"); |
| | | check("DDLèæ¬", true, new File("sql/mch_followup_plan_20261117.sql").isFile()); |
| | | |
| | | System.out.println("========== ç»æï¼PASS=" + passed + "ï¼FAIL=" + failed + " =========="); |
| | | if (failed > 0) { |
| | | System.exit(1); |
| | | } |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.smartor.common.MchFollowupConstants; |
| | | import com.smartor.common.SpecificArchiveConstants; |
| | | import com.smartor.domain.MchFollowupPlan; |
| | | import com.smartor.domain.MchFollowupPlanItem; |
| | | import com.smartor.domain.PatChildArchiveDetail; |
| | | import com.smartor.domain.PatMaternityArchiveDetail; |
| | | import com.smartor.mapper.MchFollowupPlanItemMapper; |
| | | import com.smartor.mapper.MchFollowupPlanMapper; |
| | | import com.smartor.mapper.PatChildArchiveDetailMapper; |
| | | import com.smartor.mapper.PatMaternityArchiveDetailMapper; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.InvocationHandler; |
| | | import java.lang.reflect.Method; |
| | | import java.lang.reflect.Proxy; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * å¦å¹¼é访计åæå¡èªæ£ï¼çº¯ mainï¼ä½¿ç¨å¨æä»£ç模æ Mapperï¼ä¸ä¾èµæ°æ®åºï¼ã |
| | | * |
| | | * è¦çï¼è®¡åçæãèç¹æ¶é´ãå¹çé建ãæé访æ¶é´ä¸ºç©ºãå¿ä¿å®¶é¿çµè¯å
åºã |
| | | */ |
| | | public final class MchFollowupPlanServiceCheck { |
| | | |
| | | private static int passed = 0; |
| | | private static int failed = 0; |
| | | |
| | | private static final SimpleDateFormat DATE_TIME = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | private static void check(String key, Object expected, Object actual) { |
| | | boolean ok = expected == null ? actual == null : expected.equals(actual); |
| | | if (ok) { |
| | | passed++; |
| | | System.out.println(" [OK] " + key + " = " + actual); |
| | | } else { |
| | | failed++; |
| | | System.out.println(" [FAIL] " + key + " ææ=" + expected + " å®é
=" + actual); |
| | | } |
| | | } |
| | | |
| | | private static Date date(String text) throws Exception { |
| | | return DATE_TIME.parse(text); |
| | | } |
| | | |
| | | private static void setField(Object target, String name, Object value) throws Exception { |
| | | Field field = target.getClass().getDeclaredField(name); |
| | | field.setAccessible(true); |
| | | field.set(target, value); |
| | | } |
| | | |
| | | private static Object defaultValue(Class<?> type) { |
| | | if (!type.isPrimitive()) { |
| | | return null; |
| | | } |
| | | if (type == boolean.class) { |
| | | return false; |
| | | } |
| | | if (type == byte.class) { |
| | | return (byte) 0; |
| | | } |
| | | if (type == short.class) { |
| | | return (short) 0; |
| | | } |
| | | if (type == int.class) { |
| | | return 0; |
| | | } |
| | | if (type == long.class) { |
| | | return 0L; |
| | | } |
| | | if (type == float.class) { |
| | | return 0F; |
| | | } |
| | | if (type == double.class) { |
| | | return 0D; |
| | | } |
| | | if (type == char.class) { |
| | | return '\0'; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | private static <T> T proxy(Class<T> type, InvocationHandler handler) { |
| | | return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, handler); |
| | | } |
| | | |
| | | private static MchFollowupPlanAssembler assembler() throws Exception { |
| | | MchFollowupPlanAssembler assembler = new MchFollowupPlanAssembler(); |
| | | setField(assembler, "timeResolver", new MchFollowupTimeResolver()); |
| | | return assembler; |
| | | } |
| | | |
| | | private static PatMaternityArchiveDetail maternityDetail(Long detailId, Long archiveId, Date plannedTime) { |
| | | PatMaternityArchiveDetail detail = new PatMaternityArchiveDetail(); |
| | | detail.setId(detailId); |
| | | detail.setArchiveid(archiveId); |
| | | detail.setOrgid(SpecificArchiveConstants.LISHUI_MCH_ORG_ID); |
| | | detail.setCampusid("1"); |
| | | detail.setSourceType("1"); |
| | | detail.setSourceBizNo("MZ001"); |
| | | detail.setPatid(100L); |
| | | detail.setPatname("å¼ ä¸"); |
| | | detail.setPhone("13800000000"); |
| | | detail.setIdcardno("330102199001010000"); |
| | | detail.setPlannedFollowTime(plannedTime); |
| | | detail.setFollowupPeriod("{\"items\":[" |
| | | + "{\"dayOffset\":0,\"sendTime\":\"09:00\",\"sendType\":\"sms\",\"content\":\"çä¿¡1\"}," |
| | | + "{\"dayOffset\":3,\"sendType\":\"wechat\",\"templateId\":16,\"content\":\"微信2\"}," |
| | | + "{\"dayOffset\":7,\"sendType\":\"sms\",\"content\":\"çä¿¡3\"}]}"); |
| | | return detail; |
| | | } |
| | | |
| | | private static PatChildArchiveDetail childDetail(Long detailId, Long archiveId, Date plannedTime) { |
| | | PatChildArchiveDetail detail = new PatChildArchiveDetail(); |
| | | detail.setId(detailId); |
| | | detail.setArchiveid(archiveId); |
| | | detail.setOrgid(SpecificArchiveConstants.LISHUI_MCH_ORG_ID); |
| | | detail.setCampusid("1"); |
| | | detail.setSourceType("1"); |
| | | detail.setSourceBizNo("MZ002"); |
| | | detail.setPatid(200L); |
| | | detail.setPatname("æå"); |
| | | detail.setPhone("13900000000"); |
| | | detail.setParentPhone("13700000000"); |
| | | detail.setIdcardno("330102199202020000"); |
| | | detail.setPlannedFollowTime(plannedTime); |
| | | detail.setFollowupPeriod("{\"items\":[{\"dayOffset\":1,\"sendType\":\"sms\",\"content\":\"å¿ä¿çä¿¡\"}]}"); |
| | | return detail; |
| | | } |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | System.out.println("========== å¦å¹¼é访计åæå¡èªæ£ =========="); |
| | | |
| | | List<MchFollowupPlan> activePlans = new ArrayList<>(); |
| | | List<MchFollowupPlanItem> insertedItems = new ArrayList<>(); |
| | | long[] planId = {1L}; |
| | | long[] itemId = {1L}; |
| | | |
| | | MchFollowupPlanMapper planMapper = proxy(MchFollowupPlanMapper.class, (p, method, a) -> { |
| | | String name = method.getName(); |
| | | if ("selectActiveByArchive".equals(name)) { |
| | | return new ArrayList<>(activePlans); |
| | | } |
| | | if ("insertMchFollowupPlan".equals(name)) { |
| | | MchFollowupPlan plan = (MchFollowupPlan) a[0]; |
| | | plan.setId(planId[0]++); |
| | | activePlans.add(plan); |
| | | return 1; |
| | | } |
| | | if ("cancelById".equals(name)) { |
| | | Long id = (Long) a[0]; |
| | | for (MchFollowupPlan plan : activePlans) { |
| | | if (id.equals(plan.getId())) { |
| | | plan.setPlanStatus(MchFollowupConstants.PLAN_STATUS_CANCELED); |
| | | } |
| | | } |
| | | return 1; |
| | | } |
| | | if ("completeById".equals(name)) { |
| | | return 1; |
| | | } |
| | | return defaultValue(method.getReturnType()); |
| | | }); |
| | | |
| | | MchFollowupPlanItemMapper itemMapper = proxy(MchFollowupPlanItemMapper.class, (p, method, a) -> { |
| | | String name = method.getName(); |
| | | if ("insertMchFollowupPlanItem".equals(name)) { |
| | | MchFollowupPlanItem item = (MchFollowupPlanItem) a[0]; |
| | | item.setId(itemId[0]++); |
| | | insertedItems.add(item); |
| | | return 1; |
| | | } |
| | | if ("cancelPendingByPlanId".equals(name)) { |
| | | return 1; |
| | | } |
| | | if ("countPendingByPlanId".equals(name)) { |
| | | return 1; |
| | | } |
| | | return defaultValue(method.getReturnType()); |
| | | }); |
| | | |
| | | Map<Long, PatMaternityArchiveDetail> maternityMap = new HashMap<>(); |
| | | maternityMap.put(20L, maternityDetail(20L, 10L, date("2026-11-20 14:30:00"))); |
| | | maternityMap.put(21L, maternityDetail(21L, 11L, null)); |
| | | PatMaternityArchiveDetailMapper maternityMapper = proxy(PatMaternityArchiveDetailMapper.class, (p, method, a) -> { |
| | | String name = method.getName(); |
| | | if ("selectPatMaternityArchiveDetailById".equals(name)) { |
| | | return maternityMap.get((Long) a[0]); |
| | | } |
| | | if ("selectPatMaternityArchiveDetailList".equals(name)) { |
| | | PatMaternityArchiveDetail query = (PatMaternityArchiveDetail) a[0]; |
| | | List<PatMaternityArchiveDetail> list = new ArrayList<>(); |
| | | for (PatMaternityArchiveDetail detail : maternityMap.values()) { |
| | | if (query.getArchiveid() == null || query.getArchiveid().equals(detail.getArchiveid())) { |
| | | list.add(detail); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | return defaultValue(method.getReturnType()); |
| | | }); |
| | | |
| | | Map<Long, PatChildArchiveDetail> childMap = new HashMap<>(); |
| | | childMap.put(30L, childDetail(30L, 12L, date("2026-12-01 08:00:00"))); |
| | | PatChildArchiveDetailMapper childMapper = proxy(PatChildArchiveDetailMapper.class, (p, method, a) -> { |
| | | String name = method.getName(); |
| | | if ("selectPatChildArchiveDetailById".equals(name)) { |
| | | return childMap.get((Long) a[0]); |
| | | } |
| | | if ("selectPatChildArchiveDetailList".equals(name)) { |
| | | return new ArrayList<>(childMap.values()); |
| | | } |
| | | return defaultValue(method.getReturnType()); |
| | | }); |
| | | |
| | | ISysConfigService configService = proxy(ISysConfigService.class, (p, method, a) -> { |
| | | if ("selectConfigByKey".equals(method.getName())) { |
| | | return null; |
| | | } |
| | | return defaultValue(method.getReturnType()); |
| | | }); |
| | | |
| | | MchFollowupPlanServiceImpl service = new MchFollowupPlanServiceImpl(); |
| | | setField(service, "planMapper", planMapper); |
| | | setField(service, "itemMapper", itemMapper); |
| | | setField(service, "maternityDetailMapper", maternityMapper); |
| | | setField(service, "childDetailMapper", childMapper); |
| | | setField(service, "periodParser", new MchFollowupPeriodParser()); |
| | | setField(service, "planAssembler", assembler()); |
| | | setField(service, "configService", configService); |
| | | |
| | | System.out.println("-- 1) å¦ä¿è®¡åçæ --"); |
| | | int generated = service.rebuildForArchive(MchFollowupConstants.ARCHIVE_TYPE_MATERNITY, 10L, 20L); |
| | | check("çæèç¹æ°", 3, generated); |
| | | check("è®¡åæ°", 1, activePlans.size()); |
| | | check("计åç¶æ", MchFollowupConstants.PLAN_STATUS_ACTIVE, activePlans.get(0).getPlanStatus()); |
| | | check("è®¡åæºæ", SpecificArchiveConstants.LISHUI_MCH_ORG_ID, activePlans.get(0).getOrgid()); |
| | | check("èç¹æ°", 3, insertedItems.size()); |
| | | check("èç¹1æ¶é´", "2026-11-20 09:00:00", DATE_TIME.format(insertedItems.get(0).getSendTime())); |
| | | check("èç¹2æ¶é´", "2026-11-23 14:30:00", DATE_TIME.format(insertedItems.get(1).getSendTime())); |
| | | check("èç¹3æ¶é´", "2026-11-27 14:30:00", DATE_TIME.format(insertedItems.get(2).getSendTime())); |
| | | |
| | | System.out.println("-- 2) ç¸ååºåæ¥/卿å¹ç --"); |
| | | int again = service.rebuildForArchive(MchFollowupConstants.ARCHIVE_TYPE_MATERNITY, 10L, 20L); |
| | | check("å¹çè¿å", 0, again); |
| | | check("è®¡åæ°ä¸å", 1, activePlans.size()); |
| | | check("èç¹æ°ä¸å", 3, insertedItems.size()); |
| | | |
| | | System.out.println("-- 3) æé访æ¶é´ä¸ºç©º --"); |
| | | int waiting = service.rebuildForArchive(MchFollowupConstants.ARCHIVE_TYPE_MATERNITY, 11L, 21L); |
| | | check("çå¾
计åä¸çæèç¹", 0, waiting); |
| | | check("çå¾
è®¡åæ°", 2, activePlans.size()); |
| | | check("çå¾
计åç¶æ", MchFollowupConstants.PLAN_STATUS_WAITING, activePlans.get(1).getPlanStatus()); |
| | | |
| | | System.out.println("-- 4) å¿ä¿å®¶é¿çµè¯å
åº --"); |
| | | int childGenerated = service.rebuildForArchive(MchFollowupConstants.ARCHIVE_TYPE_CHILD, 12L, 30L); |
| | | check("å¿ä¿èç¹æ°", 1, childGenerated); |
| | | check("å¿ä¿è®¡åæ°", 3, activePlans.size()); |
| | | check("å¿ä¿çµè¯", "13700000000", activePlans.get(2).getPhone()); |
| | | check("å¿ä¿èç¹æ¶é´", "2026-12-02 08:00:00", |
| | | DATE_TIME.format(insertedItems.get(insertedItems.size() - 1).getSendTime())); |
| | | |
| | | System.out.println("-- 5) é丽水å¦å¹¼ä¸çæ --"); |
| | | PatMaternityArchiveDetail other = maternityDetail(40L, 20L, date("2026-11-20 14:30:00")); |
| | | other.setOrgid("OTHER_ORG"); |
| | | maternityMap.put(40L, other); |
| | | int otherGenerated = service.rebuildForArchive(MchFollowupConstants.ARCHIVE_TYPE_MATERNITY, 20L, 40L); |
| | | check("å
¶ä»æºæä¸çæ", 0, otherGenerated); |
| | | |
| | | System.out.println("========== ç»æï¼PASS=" + passed + "ï¼FAIL=" + failed + " =========="); |
| | | if (failed > 0) { |
| | | System.exit(1); |
| | | } |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.mch; |
| | | |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.smartor.common.MchFollowupConstants; |
| | | import com.smartor.domain.MchFollowupPlan; |
| | | import com.smartor.domain.MchFollowupPlanItem; |
| | | import com.smartor.domain.MchFollowupSendLog; |
| | | import com.smartor.mapper.MchFollowupPlanItemMapper; |
| | | import com.smartor.mapper.MchFollowupPlanMapper; |
| | | import com.smartor.mapper.MchFollowupSendLogMapper; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.InvocationHandler; |
| | | import java.lang.reflect.Proxy; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * å¦å¹¼é访åéæå¡èªæ£ï¼çº¯ mainï¼å¨æä»£ç模æ Mapperï¼ä¸ä¾èµæ°æ®åº/ç¬¬ä¸æ¹æ¥å£ï¼ã |
| | | */ |
| | | public final class MchFollowupSendServiceCheck { |
| | | |
| | | private static int passed = 0; |
| | | private static int failed = 0; |
| | | |
| | | private static void check(String key, Object expected, Object actual) { |
| | | boolean ok = expected == null ? actual == null : expected.equals(actual); |
| | | if (ok) { |
| | | passed++; |
| | | System.out.println(" [OK] " + key + " = " + actual); |
| | | } else { |
| | | failed++; |
| | | System.out.println(" [FAIL] " + key + " ææ=" + expected + " å®é
=" + actual); |
| | | } |
| | | } |
| | | |
| | | private static void setField(Object target, String name, Object value) throws Exception { |
| | | Field field = target.getClass().getDeclaredField(name); |
| | | field.setAccessible(true); |
| | | field.set(target, value); |
| | | } |
| | | |
| | | private static Object defaultValue(Class<?> type) { |
| | | if (!type.isPrimitive()) { |
| | | return null; |
| | | } |
| | | if (type == boolean.class) { |
| | | return false; |
| | | } |
| | | if (type == int.class) { |
| | | return 0; |
| | | } |
| | | if (type == long.class) { |
| | | return 0L; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | private static <T> T proxy(Class<T> type, InvocationHandler handler) { |
| | | return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, handler); |
| | | } |
| | | |
| | | private static MchFollowupPlanItem item(String sendType, long sendTimeMillis) { |
| | | MchFollowupPlanItem item = new MchFollowupPlanItem(); |
| | | item.setId(1L); |
| | | item.setPlanId(10L); |
| | | item.setSeq(1); |
| | | item.setSendType(sendType); |
| | | item.setSendTime(new Date(sendTimeMillis)); |
| | | item.setContent("å
容"); |
| | | item.setSendStatus(MchFollowupConstants.ITEM_STATUS_PENDING); |
| | | item.setRetryCount(0); |
| | | return item; |
| | | } |
| | | |
| | | private static MchFollowupPlan plan() { |
| | | MchFollowupPlan plan = new MchFollowupPlan(); |
| | | plan.setId(10L); |
| | | plan.setOrgid("47226079133110211G1001"); |
| | | plan.setPlanStatus(MchFollowupConstants.PLAN_STATUS_ACTIVE); |
| | | plan.setPhone("13800000000"); |
| | | return plan; |
| | | } |
| | | |
| | | private static int run(MchFollowupPlanItem targetItem, MchFollowupMessageSender sender, |
| | | boolean expectClaim) throws Exception { |
| | | List<MchFollowupPlanItem> dueItems = new ArrayList<>(); |
| | | dueItems.add(targetItem); |
| | | List<MchFollowupSendLog> logs = new ArrayList<>(); |
| | | boolean[] claimed = {false}; |
| | | boolean[] planCompleted = {false}; |
| | | |
| | | MchFollowupPlanItemMapper itemMapper = proxy(MchFollowupPlanItemMapper.class, (p, method, a) -> { |
| | | String name = method.getName(); |
| | | if ("selectDueItems".equals(name)) { |
| | | return dueItems; |
| | | } |
| | | if ("claimItem".equals(name)) { |
| | | claimed[0] = true; |
| | | return 1; |
| | | } |
| | | if ("updateSendResult".equals(name)) { |
| | | return 1; |
| | | } |
| | | if ("countPendingByPlanId".equals(name)) { |
| | | return 0; |
| | | } |
| | | return defaultValue(method.getReturnType()); |
| | | }); |
| | | |
| | | MchFollowupPlanMapper planMapper = proxy(MchFollowupPlanMapper.class, (p, method, a) -> { |
| | | String name = method.getName(); |
| | | if ("selectMchFollowupPlanById".equals(name)) { |
| | | return plan(); |
| | | } |
| | | if ("completeById".equals(name)) { |
| | | planCompleted[0] = true; |
| | | return 1; |
| | | } |
| | | return defaultValue(method.getReturnType()); |
| | | }); |
| | | |
| | | MchFollowupSendLogMapper logMapper = proxy(MchFollowupSendLogMapper.class, (p, method, a) -> { |
| | | if ("insertMchFollowupSendLog".equals(method.getName())) { |
| | | logs.add((MchFollowupSendLog) a[0]); |
| | | return 1; |
| | | } |
| | | return defaultValue(method.getReturnType()); |
| | | }); |
| | | |
| | | ISysConfigService configService = proxy(ISysConfigService.class, (p, method, a) -> { |
| | | if ("selectConfigByKey".equals(method.getName())) { |
| | | return null; |
| | | } |
| | | return defaultValue(method.getReturnType()); |
| | | }); |
| | | |
| | | MchFollowupSendServiceImpl service = new MchFollowupSendServiceImpl(); |
| | | setField(service, "planMapper", planMapper); |
| | | setField(service, "itemMapper", itemMapper); |
| | | setField(service, "sendLogMapper", logMapper); |
| | | setField(service, "messageSender", sender); |
| | | setField(service, "sendWindow", new MchFollowupSendWindow()); |
| | | setField(service, "configService", configService); |
| | | |
| | | int sent = service.sendDue(10); |
| | | check("claimItemè°ç¨", expectClaim, claimed[0]); |
| | | check("计åå®ææ´æ°", true, planCompleted[0]); |
| | | check("åéæ¥å¿æ°", 1, logs.size()); |
| | | return sent; |
| | | } |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | System.out.println("========== å¦å¹¼é访åéæå¡èªæ£ =========="); |
| | | long now = System.currentTimeMillis(); |
| | | |
| | | System.out.println("-- 1) çä¿¡åéæå --"); |
| | | MchFollowupPlanItem smsItem = item(MchFollowupConstants.SEND_TYPE_SMS, now - 60L * 60L * 1000L); |
| | | MchFollowupMessageSender okSender = new MchFollowupMessageSender() { |
| | | @Override |
| | | public MchFollowupSendOutcome sendSms(MchFollowupPlan plan, MchFollowupPlanItem item) { |
| | | return MchFollowupSendOutcome.ok("MSG-1", "req", "resp"); |
| | | } |
| | | |
| | | @Override |
| | | public MchFollowupSendOutcome sendWechat(MchFollowupPlan plan, MchFollowupPlanItem item) { |
| | | return MchFollowupSendOutcome.fail("微信失败", "req", "resp"); |
| | | } |
| | | }; |
| | | int success = run(smsItem, okSender, true); |
| | | check("æåæ°é", 1, success); |
| | | check("èç¹ç¶æ", MchFollowupConstants.ITEM_STATUS_SUCCESS, smsItem.getSendStatus()); |
| | | check("ç¬¬ä¸æ¹ID", "MSG-1", smsItem.getProviderMsgId()); |
| | | |
| | | System.out.println("-- 2) è¶
è¿ 1 天æ è®°è¿æ --"); |
| | | MchFollowupPlanItem expiredItem = item( |
| | | MchFollowupConstants.SEND_TYPE_SMS, now - 25L * 60L * 60L * 1000L); |
| | | int expiredSent = run(expiredItem, okSender, false); |
| | | check("è¿æä¸åé", 0, expiredSent); |
| | | check("è¿æç¶æ", MchFollowupConstants.ITEM_STATUS_EXPIRED, expiredItem.getSendStatus()); |
| | | |
| | | System.out.println("-- 3) 微信失败è¿å
¥éè¯ --"); |
| | | MchFollowupPlanItem retryItem = item( |
| | | MchFollowupConstants.SEND_TYPE_WECHAT, now - 60L * 60L * 1000L); |
| | | int retrySent = run(retryItem, okSender, true); |
| | | check("失败ä¸è®¡æ°", 0, retrySent); |
| | | check("éè¯ç¶æ", MchFollowupConstants.ITEM_STATUS_PENDING, retryItem.getSendStatus()); |
| | | check("éè¯æ¬¡æ°", 1, retryItem.getRetryCount()); |
| | | check("䏿¬¡éè¯æ¶é´é空", true, retryItem.getNextRetryTime() != null); |
| | | |
| | | System.out.println("========== ç»æï¼PASS=" + passed + "ï¼FAIL=" + failed + " =========="); |
| | | if (failed > 0) { |
| | | System.exit(1); |
| | | } |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | -- ============================================================================= |
| | | -- å¦å¹¼é访æå¨æåéï¼è®¡å表 + èç¹è¡¨ + å鿥å¿è¡¨ |
| | | -- éç¨æºæï¼ä¸½æ°´å¸å¦å¹¼ä¿å¥é¢ orgid = 47226079133110211G1001 |
| | | -- æ¥æï¼2026-11-17 |
| | | -- ============================================================================= |
| | | |
| | | -- 1. followup_period æ¹ä¸º TEXTï¼å®¹çº³ JSONï¼å varchar(100) æ¾ä¸ä¸åéå
å®¹ï¼ |
| | | ALTER TABLE pat_maternity_archive_detail |
| | | MODIFY COLUMN followup_period TEXT NULL COMMENT 'éè®¿å¨æJSON'; |
| | | |
| | | ALTER TABLE pat_child_archive_detail |
| | | MODIFY COLUMN followup_period TEXT NULL COMMENT 'éè®¿å¨æJSON'; |
| | | |
| | | ALTER TABLE pat_specific_archive_generate_config |
| | | MODIFY COLUMN followup_period TEXT NULL COMMENT 'éè®¿å¨æJSON'; |
| | | |
| | | -- 2. å¦å¹¼é访计å主表 |
| | | CREATE TABLE IF NOT EXISTS mch_followup_plan ( |
| | | id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主é®', |
| | | orgid VARCHAR(64) NOT NULL COMMENT 'æºæID', |
| | | campusid VARCHAR(64) DEFAULT NULL COMMENT 'é¢åºID', |
| | | archive_type VARCHAR(8) NOT NULL COMMENT 'æ¡£æ¡ç±»åï¼1å¦ä¿ 2å¿ä¿', |
| | | archive_id BIGINT NOT NULL COMMENT 'æ¡£æ¡ä¸»è¡¨ID', |
| | | archive_detail_id BIGINT NOT NULL COMMENT 'æ¡£æ¡è¯¦æ
ID', |
| | | source_type VARCHAR(8) DEFAULT NULL COMMENT 'æ¥æºç±»åï¼1é¨è¯ 2ä½é¢é访 3æå·¥', |
| | | source_biz_no VARCHAR(128) DEFAULT NULL COMMENT 'æ¥æºä¸å¡ç¼å·ï¼é¨è¯å·/ä½é¢å·', |
| | | patid BIGINT DEFAULT NULL COMMENT 'æ£è
ID', |
| | | patname VARCHAR(255) DEFAULT NULL COMMENT 'æ£è
å§å', |
| | | phone VARCHAR(32) DEFAULT NULL COMMENT 'èç³»çµè¯', |
| | | idcardno VARCHAR(64) DEFAULT NULL COMMENT 'è¯ä»¶å·ç ', |
| | | planned_follow_time DATETIME DEFAULT NULL COMMENT '卿åºåæ¥', |
| | | followup_period TEXT DEFAULT NULL COMMENT 'éè®¿å¨æJSONå¿«ç
§', |
| | | plan_status CHAR(1) NOT NULL DEFAULT '0' COMMENT 'ç¶æï¼0ææ 1åæ¶ 2宿 3å¾
è¡¥å
/é
ç½®å¼å¸¸', |
| | | remark VARCHAR(500) DEFAULT NULL COMMENT '夿³¨', |
| | | create_time DATETIME DEFAULT NULL, |
| | | update_time DATETIME DEFAULT NULL, |
| | | PRIMARY KEY (id), |
| | | KEY idx_mch_plan_archive (archive_type, archive_id, archive_detail_id), |
| | | KEY idx_mch_plan_status (orgid, plan_status) |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='å¦å¹¼é访计å主表'; |
| | | |
| | | -- 3. å¦å¹¼é访计ååéèç¹ |
| | | CREATE TABLE IF NOT EXISTS mch_followup_plan_item ( |
| | | id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主é®', |
| | | plan_id BIGINT NOT NULL COMMENT '计åID', |
| | | seq INT NOT NULL COMMENT 'èç¹é¡ºåº', |
| | | send_type VARCHAR(16) NOT NULL COMMENT 'åéæ¹å¼ï¼sms/wechat', |
| | | send_time DATETIME NOT NULL COMMENT 'åéæ¶é´', |
| | | title_name VARCHAR(255) DEFAULT NULL COMMENT '微信æ é¢', |
| | | content TEXT DEFAULT NULL COMMENT 'åéå
容', |
| | | template_id BIGINT DEFAULT NULL COMMENT '微信模æ¿ID', |
| | | url VARCHAR(1000) DEFAULT NULL COMMENT '微信跳转å°å', |
| | | send_status CHAR(1) NOT NULL DEFAULT '0' COMMENT 'ç¶æï¼0å¾
åé 1åéä¸ 2æå 3失败 4è¿æ 5åæ¶ 6è·³è¿', |
| | | retry_count INT NOT NULL DEFAULT 0 COMMENT 'å·²éè¯æ¬¡æ°', |
| | | next_retry_time DATETIME DEFAULT NULL COMMENT '䏿¬¡éè¯æ¶é´', |
| | | send_time_actual DATETIME DEFAULT NULL COMMENT 'å®é
åéæ¶é´', |
| | | result_msg VARCHAR(1000) DEFAULT NULL COMMENT 'ç»æè¯´æ', |
| | | provider_msg_id VARCHAR(255) DEFAULT NULL COMMENT 'ç¬¬ä¸æ¹æ¶æ¯ID', |
| | | create_time DATETIME DEFAULT NULL, |
| | | update_time DATETIME DEFAULT NULL, |
| | | PRIMARY KEY (id), |
| | | UNIQUE KEY uk_mch_plan_seq (plan_id, seq), |
| | | KEY idx_mch_item_due (send_status, send_time), |
| | | KEY idx_mch_item_plan (plan_id) |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='å¦å¹¼é访计ååéèç¹'; |
| | | |
| | | -- 4. å¦å¹¼é访åéæ¥å¿ |
| | | CREATE TABLE IF NOT EXISTS mch_followup_send_log ( |
| | | id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主é®', |
| | | plan_id BIGINT DEFAULT NULL COMMENT '计åID', |
| | | item_id BIGINT DEFAULT NULL COMMENT 'èç¹ID', |
| | | send_type VARCHAR(16) DEFAULT NULL COMMENT 'åéæ¹å¼', |
| | | request_body TEXT DEFAULT NULL COMMENT 'è¯·æ±æè¦ï¼ææºå·è±æï¼', |
| | | response_body TEXT DEFAULT NULL COMMENT 'ç¬¬ä¸æ¹ååº', |
| | | send_status CHAR(1) DEFAULT NULL COMMENT 'åéåç¶æ', |
| | | result_msg VARCHAR(1000) DEFAULT NULL COMMENT 'ç»æè¯´æ', |
| | | create_time DATETIME DEFAULT NULL, |
| | | PRIMARY KEY (id), |
| | | KEY idx_mch_log_item (item_id), |
| | | KEY idx_mch_log_plan (plan_id) |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='å¦å¹¼é访å鿥å¿'; |