编辑 | blame | 历史 | 原始文档

妇幼随访按周期发送功能说明

版本: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 是整个周期的基准日,所有节点都以它计算:

节点发送时间 = plannedFollowTime 的日期 + item.dayOffset 天 + 时分秒

不是“上一次发送后顺延”,而是固定从基准日排期。

2.2 时分秒规则

优先级:

  1. item.sendTime 有值 → 使用 item.sendTime;
  2. 否则,plannedFollowTime 的时分秒不是 00:00:00 → 沿用 plannedFollowTime 的时分秒;
  3. 否则默认 09:00。

如果确实需要零点发送,必须显式配置:

{"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 显式节点(推荐)

{
  "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 间隔 + 次数

{
  "intervalDays": 3,
  "count": 4,
  "sendTime": "09:00",
  "sendType": "sms",
  "content": "您好${patname},请按计划复诊。"
}

表示:

第1次:基准日 + 0天
第2次:基准日 + 3天
第3次:基准日 + 6天
第4次:基准日 + 9天

count 缺省时可用 followupCycleTimes 兜底。

3.3 days 数组

{
  "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():

查询 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():

扫描已有妇保/儿保档案详情
  planned_follow_time 非空
  followup_period 非空
→ 补建计划

七、短信和微信发送

7.1 短信:云MAS

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

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

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 内置默认

十、代码清单

新增

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

修改

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/微信配置错误时只影响对应节点,不影响其他节点。