From 67d0eef6ef56713345e03afdfd7e5badf4d4ad3d Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期二, 24 十一月 2026 14:13:11 +0800
Subject: [PATCH] fix: 补提交妇幼随访 service_subtask 方案核心文件
---
smartor/src/test/java/com/smartor/service/mch/MchFollowupSubtaskLogicCheck.java | 114 ++++++
smartor/src/main/java/com/smartor/mapper/MchFollowupSubtaskMapper.java | 78 ++++
smartor/src/main/java/com/smartor/service/mch/IMchFollowupSubtaskService.java | 29 +
sql/drop_mch_followup_plan_tables_20261123.sql | 9
smartor/src/main/java/com/smartor/service/mch/MchFollowupSubtaskServiceImpl.java | 600 +++++++++++++++++++++++++++++++++
smartor/src/main/java/com/smartor/domain/MchFollowupArchiveCursor.java | 19 +
smartor/src/main/java/com/smartor/service/mch/MchFollowupSendContext.java | 42 ++
smartor/src/main/resources/mapper/smartor/MchFollowupSubtaskMapper.xml | 155 ++++++++
sql/service_subtask_add_mch_fields_20261123.sql | 33 +
9 files changed, 1,079 insertions(+), 0 deletions(-)
diff --git a/smartor/src/main/java/com/smartor/domain/MchFollowupArchiveCursor.java b/smartor/src/main/java/com/smartor/domain/MchFollowupArchiveCursor.java
new file mode 100644
index 0000000..cad97af
--- /dev/null
+++ b/smartor/src/main/java/com/smartor/domain/MchFollowupArchiveCursor.java
@@ -0,0 +1,19 @@
+package com.smartor.domain;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 濡囧辜妗f鎳掔敓鎴愭父鏍囷細褰撳墠璁″垝鍝堝笇 + 涓嬫闇�瑕佺敓鎴愪换鍔$殑鑺傜偣鏃堕棿銆�
+ */
+@Data
+public class MchFollowupArchiveCursor implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private String planHash;
+
+ private Date nextDueTime;
+}
diff --git a/smartor/src/main/java/com/smartor/mapper/MchFollowupSubtaskMapper.java b/smartor/src/main/java/com/smartor/mapper/MchFollowupSubtaskMapper.java
new file mode 100644
index 0000000..4bf624a
--- /dev/null
+++ b/smartor/src/main/java/com/smartor/mapper/MchFollowupSubtaskMapper.java
@@ -0,0 +1,78 @@
+package com.smartor.mapper;
+
+import com.smartor.domain.MchFollowupArchiveCandidate;
+import com.smartor.domain.MchFollowupArchiveCursor;
+import com.ruoyi.task.domain.ServiceSubtask;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 濡囧辜闅忚浠诲姟锛坰ervice_subtask锛変笓鐢� Mapper銆�
+ *
+ * <p>濡囧辜鑺傜偣涓嶅啀浣跨敤鐙珛璁″垝琛紝鑺傜偣蹇収钀藉湪 service_subtask 鐨�
+ * mch_archive_detail_id / mch_node_seq / mch_plan_hash / mch_node_json 涓娿��</p>
+ */
+@Mapper
+public interface MchFollowupSubtaskMapper {
+
+ /**
+ * 鎵弿宸茬‘璁ゃ�佷笖鎷熼殢璁挎棩鏈熷拰闅忚鍛ㄦ湡閮芥湁鍊肩殑濡囧辜妗f銆�
+ */
+ List<MchFollowupArchiveCandidate> selectCandidates(@Param("orgid") String orgid,
+ @Param("dueBefore") Date dueBefore,
+ @Param("limit") int limit);
+
+ /**
+ * 鏌ヨ鏌愭。妗堣鎯呬笅宸茬敓鎴愮殑濡囧辜 subtask銆�
+ */
+ List<ServiceSubtask> selectByArchiveDetailId(@Param("detailId") Long detailId);
+
+ /**
+ * 鎻掑叆涓�鏉″骞奸殢璁� subtask銆�
+ */
+ int insertMchSubtask(ServiceSubtask subtask);
+
+ /**
+ * 璁″垝鍙樻洿鏃跺彇娑堟棫璁″垝鐗堟湰涓嬫湭鍙戦�佺殑濡囧辜 subtask銆�
+ */
+ int cancelPendingByArchiveDetailId(@Param("detailId") Long detailId,
+ @Param("planHash") String planHash,
+ @Param("now") Date now);
+
+ /**
+ * 鏌ヨ妗f璇︽儏鐨勬噿鐢熸垚娓告爣銆�
+ */
+ MchFollowupArchiveCursor selectMchCursor(@Param("archiveType") String archiveType,
+ @Param("detailId") Long detailId);
+
+ /**
+ * 鏇存柊妗f璇︽儏鐨勬噿鐢熸垚娓告爣銆�
+ */
+ int updateMchCursor(@Param("archiveType") String archiveType,
+ @Param("detailId") Long detailId,
+ @Param("planHash") String planHash,
+ @Param("nextDueTime") Date nextDueTime);
+
+ /**
+ * 璇诲彇鑺傜偣 JSON锛屼緵鍙戦�佹椂浣跨敤銆�
+ */
+ String selectNodeJsonById(@Param("id") Long id);
+
+ /**
+ * 鎶㈠崰寰呭彂閫佷换鍔★紝閬垮厤骞跺彂閲嶅鍙戦�併��
+ */
+ int claimMchSubtask(@Param("id") Long id, @Param("now") Date now);
+
+ /**
+ * 鍥炲啓濡囧辜 subtask 鍙戦�佺粨鏋溿��
+ */
+ int updateMchSendResult(@Param("id") Long id,
+ @Param("sendstate") Long sendstate,
+ @Param("result") String result,
+ @Param("remark") String remark,
+ @Param("finishtime") Date finishtime,
+ @Param("now") Date now);
+}
diff --git a/smartor/src/main/java/com/smartor/service/mch/IMchFollowupSubtaskService.java b/smartor/src/main/java/com/smartor/service/mch/IMchFollowupSubtaskService.java
new file mode 100644
index 0000000..6bf9a86
--- /dev/null
+++ b/smartor/src/main/java/com/smartor/service/mch/IMchFollowupSubtaskService.java
@@ -0,0 +1,29 @@
+package com.smartor.service.mch;
+
+import com.ruoyi.task.domain.ServiceSubtask;
+
+/**
+ * 濡囧辜闅忚浠诲姟鐢熸垚/鍙戦�佹湇鍔°��
+ *
+ * <p>濡囧辜鑺傜偣涓嶅啀钀界嫭绔嬭鍒掕〃锛岃�屾槸鎸夋。妗堢殑 plannedFollowTime + followupPeriod
+ * 鐢熸垚 service_subtask锛岀敱 sfHandlle 鐨勫骞煎垎鏀彂閫併��</p>
+ */
+public interface IMchFollowupSubtaskService {
+
+ /**
+ * 鏍规嵁妗f璇︽儏閲嶅缓濡囧辜闅忚 subtask銆�
+ *
+ * @return 鏂扮敓鎴愮殑鑺傜偣鏁伴噺
+ */
+ int rebuildForArchive(String archiveType, Long archiveId, Long archiveDetailId);
+
+ /**
+ * 琛ュ伩鎵弿锛氫负宸叉湁濡囧辜妗f琛ュ缓 subtask銆�
+ */
+ int rebuildAll(int limit);
+
+ /**
+ * 鍙戦�佷竴鏉″骞� subtask锛堢敱 sfHandlle 璋冪敤锛夈��
+ */
+ void sendSubtask(ServiceSubtask subtask);
+}
diff --git a/smartor/src/main/java/com/smartor/service/mch/MchFollowupSendContext.java b/smartor/src/main/java/com/smartor/service/mch/MchFollowupSendContext.java
new file mode 100644
index 0000000..2c91a4c
--- /dev/null
+++ b/smartor/src/main/java/com/smartor/service/mch/MchFollowupSendContext.java
@@ -0,0 +1,42 @@
+package com.smartor.service.mch;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 濡囧辜闅忚娑堟伅鍙戦�佷笂涓嬫枃銆�
+ *
+ * <p>鐢� service_subtask + mch_node_json 缁勮锛屽彂閫佸櫒涓嶅啀渚濊禆鐙珛璁″垝琛ㄣ��</p>
+ */
+@Data
+public class MchFollowupSendContext {
+
+ private String orgid;
+
+ private Long patid;
+
+ private String patname;
+
+ private String phone;
+
+ private String idcardno;
+
+ private String sourceBizNo;
+
+ private String archiveType;
+
+ private Date plannedFollowTime;
+
+ private Integer seq;
+
+ private String sendType;
+
+ private String content;
+
+ private String titleName;
+
+ private Long templateId;
+
+ private String url;
+}
diff --git a/smartor/src/main/java/com/smartor/service/mch/MchFollowupSubtaskServiceImpl.java b/smartor/src/main/java/com/smartor/service/mch/MchFollowupSubtaskServiceImpl.java
new file mode 100644
index 0000000..cee5cb8
--- /dev/null
+++ b/smartor/src/main/java/com/smartor/service/mch/MchFollowupSubtaskServiceImpl.java
@@ -0,0 +1,600 @@
+package com.smartor.service.mch;
+
+import com.alibaba.fastjson2.JSON;
+import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.system.service.ISysConfigService;
+import com.ruoyi.task.domain.ServiceSubtask;
+import com.ruoyi.task.domain.ServiceTask;
+import com.ruoyi.task.mapper.ServiceTaskMapper;
+import com.smartor.common.MchFollowupConstants;
+import com.smartor.common.SpecificArchiveConstants;
+import com.smartor.domain.MchFollowupArchiveCandidate;
+import com.smartor.domain.MchFollowupArchiveCursor;
+import com.smartor.domain.MchFollowupNode;
+import com.smartor.domain.PatChildArchiveDetail;
+import com.smartor.domain.PatMaternityArchiveDetail;
+import com.smartor.mapper.MchFollowupSubtaskMapper;
+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.dao.DuplicateKeyException;
+import org.springframework.stereotype.Service;
+
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * 濡囧辜闅忚浠诲姟鐢熸垚/鍙戦�佸疄鐜般��
+ *
+ * <p>鑺傜偣鏉ユ簮锛氭。妗堣鎯呯殑 plannedFollowTime + followupPeriod锛�
+ * 钀藉簱锛歴ervice_subtask锛坰ervice_type=21锛夛紝鐢� sfHandlle 鐨勫骞煎垎鏀彂閫併��</p>
+ */
+@Slf4j
+@Service
+public class MchFollowupSubtaskServiceImpl implements IMchFollowupSubtaskService {
+
+ private static final String TASK_TYPE_FOLLOWUP = "1";
+
+ private static final String PREACHFORM_SMS = "4";
+
+ private static final String PREACHFORM_WECHAT = "5";
+
+ private static final long FAR_FUTURE_MILLIS =
+ java.sql.Timestamp.valueOf("9999-12-31 23:59:59").getTime();
+
+ @Autowired
+ private MchFollowupSubtaskMapper subtaskMapper;
+
+ @Autowired
+ private MchFollowupPeriodParser periodParser;
+
+ @Autowired
+ private MchFollowupTimeResolver timeResolver;
+
+ @Autowired
+ private MchFollowupMessageSender messageSender;
+
+ @Autowired
+ private PatMaternityArchiveDetailMapper maternityDetailMapper;
+
+ @Autowired
+ private PatChildArchiveDetailMapper childDetailMapper;
+
+ @Autowired
+ private ServiceTaskMapper serviceTaskMapper;
+
+ @Autowired
+ private ISysConfigService configService;
+
+ @Override
+ public int rebuildForArchive(String archiveType, Long archiveId, Long archiveDetailId) {
+ try {
+ return doRebuildForArchive(archiveType, archiveId, archiveDetailId);
+ } catch (Exception e) {
+ log.error("銆愬骞奸殢璁裤�戠敓鎴� subtask 寮傚父锛宎rchiveType={}锛宎rchiveId={}锛宒etailId={}",
+ 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 || snapshot.archiveDetailId == null) {
+ return 0;
+ }
+ if (!SpecificArchiveConstants.LISHUI_MCH_ORG_ID.equals(snapshot.orgid)) {
+ return 0;
+ }
+ if (!MchFollowupConstants.FOLLOWUP_STATUS_ACTIVE.equals(snapshot.followupStatus)) {
+ log.debug("銆愬骞奸殢璁裤�戞。妗堟湭纭闅忚锛岃烦杩� subtask 鐢熸垚锛宒etailId={}锛宖ollowupStatus={}",
+ snapshot.archiveDetailId, snapshot.followupStatus);
+ return 0;
+ }
+ if (snapshot.plannedFollowTime == null || StringUtils.isBlank(snapshot.followupPeriod)) {
+ return 0;
+ }
+
+ List<MchFollowupNode> nodes;
+ try {
+ nodes = periodParser.parse(snapshot.followupPeriod, snapshot.followupCycleTimes);
+ } catch (Exception e) {
+ log.error("銆愬骞奸殢璁裤�戦殢璁垮懆鏈熻В鏋愬け璐ワ紝detailId={}锛宲eriod={}",
+ snapshot.archiveDetailId, snapshot.followupPeriod, e);
+ return 0;
+ }
+ if (nodes == null || nodes.isEmpty()) {
+ return 0;
+ }
+
+ String planHash = planHash(snapshot);
+ Date now = DateUtils.getNowDate();
+ long aheadMillis = generateAheadMillis();
+ Date dueBefore = new Date(now.getTime() + aheadMillis);
+ long notBefore = now.getTime() - MchFollowupConstants.CATCHUP_MILLIS;
+
+ MchFollowupArchiveCursor cursor =
+ subtaskMapper.selectMchCursor(snapshot.archiveType, snapshot.archiveDetailId);
+ boolean planChanged = cursor == null || !planHash.equals(cursor.getPlanHash());
+ if (planChanged) {
+ subtaskMapper.cancelPendingByArchiveDetailId(snapshot.archiveDetailId, planHash, now);
+ }
+
+ Set<String> existingKeys = new HashSet<>();
+ List<ServiceSubtask> existing = subtaskMapper.selectByArchiveDetailId(snapshot.archiveDetailId);
+ if (existing != null) {
+ for (ServiceSubtask subtask : existing) {
+ if (subtask.getMchNodeSeq() == null || !planHash.equals(subtask.getMchPlanHash())) {
+ continue;
+ }
+ existingKeys.add(planHash + "#" + subtask.getMchNodeSeq());
+ }
+ }
+
+ Long taskId = null;
+ Date nextDue = null;
+ boolean retryNow = false;
+ int generated = 0;
+ for (MchFollowupNode node : nodes) {
+ if (node == null || node.getSeq() == null) {
+ continue;
+ }
+ Date sendTime = timeResolver.resolve(snapshot.plannedFollowTime, node);
+ if (sendTime == null) {
+ continue;
+ }
+ if (sendTime.getTime() > dueBefore.getTime()) {
+ // 鏈潵鑺傜偣鍏堜笉鐢熸垚锛屽彧璁板綍鏈�鏃╃殑鏈潵鍒版湡鏃堕棿
+ if (nextDue == null || sendTime.before(nextDue)) {
+ nextDue = sendTime;
+ }
+ continue;
+ }
+ if (sendTime.getTime() < notBefore) {
+ // 瓒呰繃琛ュ彂绐楀彛锛屼笉鍐嶇敓鎴愶紝閬垮厤浜х敓涓�鎵瑰繀鐒惰秴鏃剁殑浠诲姟
+ continue;
+ }
+ String key = planHash + "#" + node.getSeq();
+ if (existingKeys.contains(key)) {
+ continue;
+ }
+ if (taskId == null) {
+ taskId = ensureTask(snapshot);
+ if (taskId == null) {
+ log.error("銆愬骞奸殢璁裤�戞湭鑾峰彇鍒板骞奸殢璁夸换鍔★紝detailId={}", snapshot.archiveDetailId);
+ retryNow = true;
+ break;
+ }
+ }
+ ServiceSubtask subtask = buildSubtask(snapshot, node, sendTime, planHash, taskId, now);
+ try {
+ generated += subtaskMapper.insertMchSubtask(subtask);
+ existingKeys.add(key);
+ } catch (DuplicateKeyException e) {
+ log.debug("銆愬骞奸殢璁裤�憇ubtask 宸插瓨鍦紝detailId={}锛宻eq={}", snapshot.archiveDetailId, node.getSeq());
+ } catch (Exception e) {
+ log.error("銆愬骞奸殢璁裤�憇ubtask 鎻掑叆澶辫触锛宒etailId={}锛宻eq={}",
+ snapshot.archiveDetailId, node.getSeq(), e);
+ retryNow = true;
+ }
+ }
+
+ Date nextDueTime;
+ if (retryNow) {
+ nextDueTime = now;
+ } else if (nextDue != null) {
+ nextDueTime = nextDue;
+ } else {
+ nextDueTime = new Date(FAR_FUTURE_MILLIS);
+ }
+ subtaskMapper.updateMchCursor(snapshot.archiveType, snapshot.archiveDetailId, planHash, nextDueTime);
+ if (generated > 0) {
+ log.info("銆愬骞奸殢璁裤�戝埌鏈� subtask 鐢熸垚瀹屾垚锛宒etailId={}锛岃妭鐐规暟={}锛屼笅娆$敓鎴愭椂闂�={}",
+ snapshot.archiveDetailId, generated, nextDueTime);
+ }
+ return generated;
+ }
+
+ @Override
+ public int rebuildAll(int limit) {
+ if (!isEnabled()) {
+ return 0;
+ }
+ int batch = limit <= 0 ? MchFollowupConstants.DEFAULT_BATCH_SIZE : limit;
+ Date dueBefore = new Date(DateUtils.getNowDate().getTime() + generateAheadMillis());
+ List<MchFollowupArchiveCandidate> candidates =
+ subtaskMapper.selectCandidates(SpecificArchiveConstants.LISHUI_MCH_ORG_ID, dueBefore, 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("銆愬骞奸殢璁裤�戣ˉ寤� subtask 澶辫触锛宎rchiveType={}锛宎rchiveId={}锛宒etailId={}",
+ candidate.getArchiveType(), candidate.getArchiveId(),
+ candidate.getArchiveDetailId(), e);
+ }
+ }
+ return generated;
+ }
+
+ @Override
+ public void sendSubtask(ServiceSubtask subtask) {
+ if (subtask == null || subtask.getId() == null) {
+ log.warn("銆愬骞奸殢璁裤�憇ubtask 涓虹┖锛岃烦杩囧彂閫�");
+ return;
+ }
+ if (!MchFollowupConstants.SERVICE_TYPE_MCH.equals(subtask.getServiceType())) {
+ return;
+ }
+ Date now = DateUtils.getNowDate();
+ // longTaskSend/compensateTask 鎸夆�滄棩鏈熲�濇崬鍙栵紝濡囧辜鑺傜偣闇�瑕佸啀鎸夌簿纭椂闂村垽鏂紝閬垮厤鎻愬墠鍙戦��
+ if (subtask.getVisitTime() != null && subtask.getVisitTime().getTime() > now.getTime()) {
+ return;
+ }
+ int claimed = subtaskMapper.claimMchSubtask(subtask.getId(), now);
+ if (claimed == 0) {
+ log.debug("銆愬骞奸殢璁裤�憇ubtask 宸茶棰嗗彇鎴栭潪寰呭彂閫侊紝subtaskId={}", subtask.getId());
+ return;
+ }
+ try {
+ // 涓庢棫濡囧辜鍙戦�侀�昏緫淇濇寔涓�鑷达細鍙ˉ鍙� 1 澶╁唴鍒版湡鐨勮妭鐐癸紝瓒呮椂鑺傜偣涓嶅啀鍙戦��
+ if (subtask.getVisitTime() != null
+ && now.getTime() - subtask.getVisitTime().getTime() > MchFollowupConstants.CATCHUP_MILLIS) {
+ finish(subtask.getId(), 7L, "expired", "瓒呰繃琛ュ彂绐楀彛锛屼换鍔¤秴鏃�", null, now);
+ return;
+ }
+
+ String nodeJson = subtask.getMchNodeJson();
+ if (StringUtils.isBlank(nodeJson)) {
+ nodeJson = subtaskMapper.selectNodeJsonById(subtask.getId());
+ }
+ if (StringUtils.isBlank(nodeJson)) {
+ finish(subtask.getId(), 5L, "error", "濡囧辜闅忚鑺傜偣JSON涓虹┖", null, now);
+ return;
+ }
+
+ MchFollowupNode node;
+ try {
+ node = JSON.parseObject(nodeJson, MchFollowupNode.class);
+ } catch (Exception e) {
+ log.error("銆愬骞奸殢璁裤�戣妭鐐笿SON瑙f瀽澶辫触锛宻ubtaskId={}锛宩son={}", subtask.getId(), nodeJson, e);
+ finish(subtask.getId(), 5L, "error", "濡囧辜闅忚鑺傜偣JSON瑙f瀽澶辫触", null, now);
+ return;
+ }
+ if (node == null) {
+ finish(subtask.getId(), 5L, "error", "濡囧辜闅忚鑺傜偣JSON涓虹┖", null, now);
+ return;
+ }
+
+ MchFollowupSendContext context = buildContext(subtask, node);
+ MchFollowupSendOutcome outcome = MchFollowupConstants.SEND_TYPE_WECHAT.equals(node.getSendType())
+ ? messageSender.sendWechat(context)
+ : messageSender.sendSms(context);
+
+ if (outcome.isOk()) {
+ String remark = "濡囧辜闅忚鍙戦�佹垚鍔�";
+ if (StringUtils.isNotBlank(outcome.getProviderMsgId())) {
+ remark = remark + "锛�" + outcome.getProviderMsgId();
+ }
+ finish(subtask.getId(), 6L, "success", truncate(remark), now, now);
+ } else if (outcome.isSkipped()) {
+ finish(subtask.getId(), 4L, "skip", truncate(outcome.getMessage()), null, now);
+ } else {
+ finish(subtask.getId(), 5L, "error", truncate(outcome.getMessage()), null, now);
+ }
+ } catch (Exception e) {
+ log.error("銆愬骞奸殢璁裤�戝彂閫佸紓甯革紝subtaskId={}", subtask.getId(), e);
+ finish(subtask.getId(), 5L, "error", truncate("鍙戦�佸紓甯革細" + e.getMessage()), null, now);
+ }
+ }
+
+ private void finish(Long id, Long sendstate, String result, String remark, Date finishtime, Date now) {
+ int updated = subtaskMapper.updateMchSendResult(id, sendstate, result, remark, finishtime, now);
+ if (updated == 0) {
+ log.warn("銆愬骞奸殢璁裤�戝洖鍐欏彂閫佺粨鏋滃け璐ワ紝subtaskId={}锛宻endstate={}", id, sendstate);
+ }
+ }
+
+ private ServiceSubtask buildSubtask(ArchiveSnapshot snapshot, MchFollowupNode node, Date sendTime,
+ String planHash, Long taskId, Date now) {
+ node.setArchiveType(snapshot.archiveType);
+ node.setArchiveSubType(snapshot.archiveSubType);
+ node.setPlannedFollowTime(snapshot.plannedFollowTime);
+
+ ServiceSubtask subtask = new ServiceSubtask();
+ subtask.setTaskid(taskId);
+ subtask.setTaskName(resolveTaskName(snapshot.archiveType, snapshot.archiveSubType));
+ subtask.setTaskDesc(node.getContent());
+ subtask.setSendname(snapshot.patname);
+ subtask.setPatid(snapshot.patid);
+ subtask.setPhone(snapshot.phone);
+ subtask.setSfzh(snapshot.idcardno);
+ subtask.setHospno(snapshot.sourceBizNo);
+ subtask.setVisitTime(sendTime);
+ subtask.setSendstate(2L);
+ subtask.setOrgid(snapshot.orgid);
+ subtask.setCampusid(snapshot.campusid);
+ subtask.setServiceType(MchFollowupConstants.SERVICE_TYPE_MCH);
+ subtask.setType(TASK_TYPE_FOLLOWUP);
+ subtask.setCurrentPreachform(MchFollowupConstants.SEND_TYPE_WECHAT.equals(node.getSendType())
+ ? PREACHFORM_WECHAT : PREACHFORM_SMS);
+ subtask.setSendType("2");
+ subtask.setTemplateid(node.getTemplateId());
+ subtask.setTemplatename(node.getTitleName());
+ subtask.setIsVisitAgain(1);
+ subtask.setCreateTime(now);
+ subtask.setUpdateTime(now);
+ subtask.setDelFlag("0");
+ subtask.setMchArchiveDetailId(snapshot.archiveDetailId);
+ subtask.setMchNodeSeq(node.getSeq());
+ subtask.setMchPlanHash(planHash);
+ subtask.setMchNodeJson(JSON.toJSONString(node));
+ return subtask;
+ }
+
+ private MchFollowupSendContext buildContext(ServiceSubtask subtask, MchFollowupNode node) {
+ MchFollowupSendContext context = new MchFollowupSendContext();
+ context.setOrgid(subtask.getOrgid());
+ context.setPatid(subtask.getPatid());
+ context.setPatname(subtask.getSendname());
+ context.setPhone(subtask.getPhone());
+ context.setIdcardno(subtask.getSfzh());
+ context.setSourceBizNo(subtask.getHospno());
+ context.setArchiveType(node.getArchiveType());
+ context.setPlannedFollowTime(node.getPlannedFollowTime());
+ context.setSeq(node.getSeq());
+ context.setSendType(node.getSendType());
+ context.setContent(node.getContent());
+ context.setTitleName(node.getTitleName());
+ context.setTemplateId(node.getTemplateId());
+ context.setUrl(node.getUrl());
+ return context;
+ }
+
+ /**
+ * 纭繚姣忕濡囧辜妗f绫诲瀷鏈変竴鏉′笓鐢� service_task銆�
+ * 濡囧辜浠诲姟璧� sfHandlle 鐨� service_type=21 鍒嗘敮锛屼笉渚濊禆 preachform_desc銆�
+ */
+ private synchronized Long ensureTask(ArchiveSnapshot snapshot) {
+ String taskName = resolveTaskName(snapshot.archiveType, snapshot.archiveSubType);
+
+ ServiceTask query = new ServiceTask();
+ query.setTaskName(taskName);
+ query.setServiceType(MchFollowupConstants.SERVICE_TYPE_MCH);
+ query.setDelFlag("0");
+ List<ServiceTask> tasks = serviceTaskMapper.selectServiceTaskList(query);
+ if (tasks != null) {
+ for (ServiceTask task : tasks) {
+ if (taskName.equals(task.getTaskName())
+ && MchFollowupConstants.SERVICE_TYPE_MCH.equals(task.getServiceType())
+ && "0".equals(task.getDelFlag())) {
+ return task.getTaskid();
+ }
+ }
+ }
+
+ Date now = DateUtils.getNowDate();
+ ServiceTask task = new ServiceTask();
+ task.setTaskName(taskName);
+ task.setTypename("濡囧辜闅忚");
+ task.setTaskDesc("濡囧辜涓撶妗f闅忚");
+ task.setServiceType(MchFollowupConstants.SERVICE_TYPE_MCH);
+ task.setType(TASK_TYPE_FOLLOWUP);
+ task.setPreachform(PREACHFORM_SMS);
+ task.setPreachformDesc("[{\"preachform\":\"4\",\"sort\":1,\"compensateTime\":\"0\"}]");
+ task.setSendType(3L);
+ task.setSendState(2L);
+ task.setLongTask(1);
+ task.setOrgid(SpecificArchiveConstants.LISHUI_MCH_ORG_ID);
+ task.setCampusid("1");
+ task.setDelFlag("0");
+ task.setCreateBy("system");
+ task.setCreateTime(now);
+ task.setUpdateTime(now);
+ int inserted = serviceTaskMapper.insertServiceTask(task);
+ if (inserted > 0 && task.getTaskid() != null) {
+ log.info("銆愬骞奸殢璁裤�戝垱寤轰笓鐢ㄤ换鍔★紝taskid={}锛宼askName={}", task.getTaskid(), taskName);
+ return task.getTaskid();
+ }
+ log.error("銆愬骞奸殢璁裤�戝垱寤轰笓鐢ㄤ换鍔″け璐ワ紝taskName={}", taskName);
+ return null;
+ }
+
+ private String resolveTaskName(String archiveType, String archiveSubType) {
+ if (MchFollowupConstants.ARCHIVE_TYPE_MATERNITY.equals(archiveType)) {
+ if ("1".equals(archiveSubType)) {
+ return "鏃╁瓡鍏崇埍闅忚";
+ }
+ if ("2".equals(archiveSubType)) {
+ return "鍥寸粷缁忔湡MHI闅忚";
+ }
+ return "濡囦繚闅忚";
+ }
+ if (MchFollowupConstants.ARCHIVE_TYPE_CHILD.equals(archiveType)) {
+ if ("1".equals(archiveSubType)) {
+ return "钀ュ吇鎬х柧鐥呴殢璁�";
+ }
+ if ("2".equals(archiveSubType)) {
+ return "瀛︿範鍥伴毦闅忚";
+ }
+ if ("3".equals(archiveSubType)) {
+ return "楂樺嵄鍎夸笓妗堥殢璁�";
+ }
+ return "鍎夸繚闅忚";
+ }
+ return "濡囧辜闅忚";
+ }
+
+ 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);
+ }
+ 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.archiveSubType = detail.getArchiveType();
+ 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();
+ snapshot.followupStatus = detail.getFollowupStatus();
+ 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.archiveSubType = detail.getArchiveType();
+ 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();
+ snapshot.followupStatus = detail.getFollowupStatus();
+ return snapshot;
+ }
+
+ private String planHash(ArchiveSnapshot snapshot) {
+ String raw = (snapshot.plannedFollowTime == null ? "" : snapshot.plannedFollowTime.getTime())
+ + "|" + nvl(snapshot.followupPeriod)
+ + "|" + nvl(snapshot.followupCycleTimes);
+ try {
+ MessageDigest digest = MessageDigest.getInstance("SHA-256");
+ byte[] bytes = digest.digest(raw.getBytes(StandardCharsets.UTF_8));
+ StringBuilder sb = new StringBuilder(bytes.length * 2);
+ for (byte b : bytes) {
+ sb.append(String.format("%02x", b));
+ }
+ return sb.toString();
+ } catch (Exception e) {
+ throw new BaseException("璁$畻濡囧辜闅忚璁″垝鍝堝笇澶辫触锛�" + e.getMessage());
+ }
+ }
+
+ private long generateAheadMillis() {
+ try {
+ String value = configService.selectConfigByKey(
+ MchFollowupConstants.CONFIG_GENERATE_AHEAD_MINUTES);
+ if (StringUtils.isNotBlank(value)) {
+ long minutes = Long.parseLong(value.trim());
+ if (minutes >= 0) {
+ return minutes * 60_000L;
+ }
+ }
+ } catch (Exception e) {
+ log.warn("銆愬骞奸殢璁裤�戣鍙栨噿鐢熸垚鎻愬墠閲忛厤缃け璐ワ紝浣跨敤榛樿鍊硷細{}", e.getMessage());
+ }
+ return MchFollowupConstants.GENERATE_AHEAD_MILLIS;
+ }
+
+ 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 String firstNotBlank(String first, String second) {
+ return StringUtils.isNotBlank(first) ? first : second;
+ }
+
+ private static String nvl(String value) {
+ return value == null ? "" : value;
+ }
+
+ private static String truncate(String text) {
+ if (text == null) {
+ return null;
+ }
+ return text.length() <= 500 ? text : text.substring(0, 500);
+ }
+
+ private static class ArchiveSnapshot {
+ private String archiveType;
+ private Long archiveId;
+ private Long archiveDetailId;
+ private String orgid;
+ private String campusid;
+ private String archiveSubType;
+ 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;
+ private String followupStatus;
+ }
+}
diff --git a/smartor/src/main/resources/mapper/smartor/MchFollowupSubtaskMapper.xml b/smartor/src/main/resources/mapper/smartor/MchFollowupSubtaskMapper.xml
new file mode 100644
index 0000000..ab6e186
--- /dev/null
+++ b/smartor/src/main/resources/mapper/smartor/MchFollowupSubtaskMapper.xml
@@ -0,0 +1,155 @@
+<?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.MchFollowupSubtaskMapper">
+
+ <resultMap id="MchSubtaskResult" type="com.ruoyi.task.domain.ServiceSubtask">
+ <id property="id" column="id"/>
+ <result property="taskid" column="taskid"/>
+ <result property="taskName" column="task_name"/>
+ <result property="taskDesc" column="task_desc"/>
+ <result property="sendname" column="sendname"/>
+ <result property="patid" column="patid"/>
+ <result property="phone" column="phone"/>
+ <result property="sfzh" column="sfzh"/>
+ <result property="hospno" column="hospno"/>
+ <result property="visitTime" column="visit_time"/>
+ <result property="sendstate" column="sendstate"/>
+ <result property="orgid" column="orgid"/>
+ <result property="campusid" column="campusid"/>
+ <result property="serviceType" column="service_type"/>
+ <result property="type" column="type"/>
+ <result property="currentPreachform" column="current_preachform"/>
+ <result property="templateid" column="templateid"/>
+ <result property="templatename" column="templatename"/>
+ <result property="isVisitAgain" column="is_visit_again"/>
+ <result property="delFlag" column="del_flag"/>
+ <result property="mchArchiveDetailId" column="mch_archive_detail_id"/>
+ <result property="mchNodeSeq" column="mch_node_seq"/>
+ <result property="mchPlanHash" column="mch_plan_hash"/>
+ <result property="mchNodeJson" column="mch_node_json"/>
+ </resultMap>
+
+ <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.followup_status = '1'
+ 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
+ and (d.mch_next_due_time is null or d.mch_next_due_time <= #{dueBefore})
+ 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.followup_status = '1'
+ 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
+ and (d.mch_next_due_time is null or d.mch_next_due_time <= #{dueBefore})
+ limit #{limit}
+ </select>
+
+ <select id="selectMchCursor" resultType="com.smartor.domain.MchFollowupArchiveCursor">
+ <choose>
+ <when test='archiveType == "1"'>
+ select mch_plan_hash as planHash, mch_next_due_time as nextDueTime
+ from pat_maternity_archive_detail
+ where id = #{detailId}
+ </when>
+ <otherwise>
+ select mch_plan_hash as planHash, mch_next_due_time as nextDueTime
+ from pat_child_archive_detail
+ where id = #{detailId}
+ </otherwise>
+ </choose>
+ </select>
+
+ <update id="updateMchCursor">
+ <choose>
+ <when test='archiveType == "1"'>
+ update pat_maternity_archive_detail
+ set mch_plan_hash = #{planHash},
+ mch_next_due_time = #{nextDueTime}
+ where id = #{detailId}
+ </when>
+ <otherwise>
+ update pat_child_archive_detail
+ set mch_plan_hash = #{planHash},
+ mch_next_due_time = #{nextDueTime}
+ where id = #{detailId}
+ </otherwise>
+ </choose>
+ </update>
+
+ <select id="selectByArchiveDetailId" resultMap="MchSubtaskResult">
+ select id, taskid, task_name, task_desc, sendname, patid, phone, sfzh, hospno,
+ visit_time, sendstate, orgid, campusid, service_type, type,
+ current_preachform, templateid, templatename, is_visit_again, del_flag,
+ mch_archive_detail_id, mch_node_seq, mch_plan_hash, mch_node_json
+ from service_subtask
+ where mch_archive_detail_id = #{detailId}
+ and (del_flag is null or del_flag = '0')
+ order by mch_node_seq asc, id asc
+ </select>
+
+ <insert id="insertMchSubtask" parameterType="com.ruoyi.task.domain.ServiceSubtask"
+ useGeneratedKeys="true" keyProperty="id">
+ insert into service_subtask
+ (taskid, task_name, task_desc, sendname, patid, phone, sfzh, hospno,
+ visit_time, sendstate, orgid, campusid, service_type, type,
+ current_preachform, templateid, templatename, is_visit_again,
+ create_time, update_time, del_flag,
+ mch_archive_detail_id, mch_node_seq, mch_plan_hash, mch_node_json)
+ values
+ (#{taskid}, #{taskName}, #{taskDesc}, #{sendname}, #{patid}, #{phone}, #{sfzh}, #{hospno},
+ #{visitTime}, #{sendstate}, #{orgid}, #{campusid}, #{serviceType}, #{type},
+ #{currentPreachform}, #{templateid}, #{templatename}, #{isVisitAgain},
+ #{createTime}, #{updateTime}, #{delFlag},
+ #{mchArchiveDetailId}, #{mchNodeSeq}, #{mchPlanHash}, #{mchNodeJson})
+ </insert>
+
+ <update id="cancelPendingByArchiveDetailId">
+ update service_subtask
+ set sendstate = 4,
+ remark = concat(ifnull(remark, ''), ';濡囧辜璁″垝鍙樻洿锛屽彇娑堟湭鍙戦�佷换鍔�'),
+ update_time = #{now}
+ where mch_archive_detail_id = #{detailId}
+ and sendstate = 2
+ and (mch_plan_hash is null or mch_plan_hash <> #{planHash})
+ and (del_flag is null or del_flag = '0')
+ </update>
+
+ <select id="selectNodeJsonById" resultType="java.lang.String">
+ select mch_node_json
+ from service_subtask
+ where id = #{id}
+ </select>
+
+ <update id="claimMchSubtask">
+ update service_subtask
+ set sendstate = 1,
+ update_time = #{now}
+ where id = #{id}
+ and (sendstate = 2
+ or (sendstate = 1 and update_time < date_sub(#{now}, interval 10 minute)))
+ </update>
+
+ <update id="updateMchSendResult">
+ update service_subtask
+ set sendstate = #{sendstate},
+ result = #{result},
+ remark = #{remark},
+ finishtime = #{finishtime},
+ update_time = #{now}
+ where id = #{id}
+ and sendstate = 1
+ </update>
+
+</mapper>
diff --git a/smartor/src/test/java/com/smartor/service/mch/MchFollowupSubtaskLogicCheck.java b/smartor/src/test/java/com/smartor/service/mch/MchFollowupSubtaskLogicCheck.java
new file mode 100644
index 0000000..144ce9b
--- /dev/null
+++ b/smartor/src/test/java/com/smartor/service/mch/MchFollowupSubtaskLogicCheck.java
@@ -0,0 +1,114 @@
+package com.smartor.service.mch;
+
+import com.smartor.common.MchFollowupConstants;
+import com.smartor.domain.MchFollowupNode;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 濡囧辜闅忚 service_subtask 鏂规鑷锛堢函 main锛屼笉渚濊禆鏁版嵁搴擄級銆�
+ *
+ * <p>瑕嗙洊锛歠ollowupPeriod 瑙f瀽銆佸彂閫佹椂闂磋绠椼�佸崰浣嶇娓叉煋銆丮apper XML銆丼QL 杩佺Щ鑴氭湰銆�</p>
+ */
+public final class MchFollowupSubtaskLogicCheck {
+
+ 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);
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ System.out.println("========== 濡囧辜闅忚 service_subtask 鏂规鑷 ==========");
+
+ System.out.println("-- 1) items 瑙f瀽 --");
+ MchFollowupPeriodParser parser = new MchFollowupPeriodParser();
+ List<MchFollowupNode> nodes = parser.parse("{\"items\":["
+ + "{\"seq\":1,\"dayOffset\":0,\"sendType\":\"sms\",\"content\":\"A\"},"
+ + "{\"seq\":2,\"dayOffset\":3,\"sendType\":\"wechat\",\"templateId\":16,\"content\":\"B\"}]}", null);
+ check("鑺傜偣鏁�", 2, nodes.size());
+ check("鑺傜偣1鍙戦�佹柟寮�", MchFollowupConstants.SEND_TYPE_SMS, nodes.get(0).getSendType());
+ check("鑺傜偣2妯℃澘ID", 16L, nodes.get(1).getTemplateId());
+
+ System.out.println("-- 2) intervalDays 瑙f瀽 --");
+ List<MchFollowupNode> interval = parser.parse(
+ "{\"intervalDays\":3,\"count\":3,\"sendType\":\"sms\",\"content\":\"X\"}", null);
+ check("闂撮殧鑺傜偣鏁�", 3, interval.size());
+ check("绗�3鑺傜偣鍋忕Щ", 6, interval.get(2).getDayOffset());
+
+ System.out.println("-- 3) 鍙戦�佹椂闂磋绠� --");
+ Date base = DATE_TIME.parse("2026-11-20 00:00:00");
+ MchFollowupTimeResolver resolver = new MchFollowupTimeResolver();
+ Date sendTime = resolver.resolve(base, interval.get(1));
+ check("绗�2鑺傜偣鏃堕棿", "2026-11-23 09:00:00", DATE_TIME.format(sendTime));
+
+ System.out.println("-- 4) 鍗犱綅绗︽覆鏌� --");
+ MchFollowupMessageSender sender = new MchFollowupMessageSender();
+ MchFollowupSendContext context = new MchFollowupSendContext();
+ context.setPatname("寮犱笁");
+ context.setPatid(100L);
+ context.setPhone("13800000000");
+ context.setIdcardno("330102199001010000");
+ context.setSourceBizNo("MZ001");
+ context.setArchiveType("1");
+ context.setOrgid("47226079133110211G1001");
+ context.setSeq(2);
+ context.setPlannedFollowTime(base);
+ String rendered = sender.renderContent(
+ "鎮ㄥソ${patname}锛孖D=${patid}锛岀數璇�=${phone}锛屽熀鍑�=${plannedFollowTime}锛屽簭鍙�=${seq}", context);
+ check("鍗犱綅绗�", "鎮ㄥソ寮犱笁锛孖D=100锛岀數璇�=13800000000锛屽熀鍑�=2026-11-20 00:00:00锛屽簭鍙�=2", rendered);
+
+ System.out.println("-- 5) Mapper XML 鍙В鏋� --");
+ check("MchFollowupSubtaskMapper.xml", true, xmlOk(
+ "smartor/src/main/resources/mapper/smartor/MchFollowupSubtaskMapper.xml"));
+
+ System.out.println("-- 6) SQL 杩佺Щ鑴氭湰 --");
+ String sql = new String(Files.readAllBytes(
+ Paths.get("sql/service_subtask_add_mch_fields_20261123.sql")), StandardCharsets.UTF_8);
+ check("鍚� mch_archive_detail_id", true, sql.contains("mch_archive_detail_id"));
+ check("鍚� mch_node_json", true, sql.contains("mch_node_json"));
+ check("鍚敮涓�閿�", true, sql.contains("uk_mch_node"));
+ check("鍚噿鐢熸垚娓告爣", true, sql.contains("mch_next_due_time"));
+ check("鍚鍒掑搱甯�", true, sql.contains("mch_plan_hash"));
+
+ System.out.println("========== 缁撴灉锛歅ASS=" + passed + "锛孎AIL=" + failed + " ==========");
+ if (failed > 0) {
+ System.exit(1);
+ }
+ }
+
+ private static boolean xmlOk(String path) {
+ try {
+ File file = new File(path);
+ if (!file.exists()) {
+ System.out.println(" [WARN] 鏂囦欢涓嶅瓨鍦�: " + path);
+ return false;
+ }
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
+ factory.newDocumentBuilder().parse(file);
+ return true;
+ } catch (Exception e) {
+ System.out.println(" [WARN] XML 瑙f瀽澶辫触: " + e.getMessage());
+ return false;
+ }
+ }
+}
diff --git a/sql/drop_mch_followup_plan_tables_20261123.sql b/sql/drop_mch_followup_plan_tables_20261123.sql
new file mode 100644
index 0000000..2c87055
--- /dev/null
+++ b/sql/drop_mch_followup_plan_tables_20261123.sql
@@ -0,0 +1,9 @@
+-- =============================================================================
+-- 濡囧辜闅忚鏀逛负 service_subtask 鎵胯浇鍚庯紝娓呯悊鏃ц鍒掕〃
+-- 鏃ユ湡锛�2026-11-23
+-- 鈿狅笍 鎵ц鍓嶈鍏堝浠斤紱纭鏂版祦绋嬪凡楠岃瘉銆佹棫琛ㄦ棤淇濈暀浠峰�煎悗鍐嶆墽琛屻��
+-- =============================================================================
+
+DROP TABLE IF EXISTS mch_followup_plan_item;
+DROP TABLE IF EXISTS mch_followup_plan;
+DROP TABLE IF EXISTS mch_followup_send_log;
diff --git a/sql/service_subtask_add_mch_fields_20261123.sql b/sql/service_subtask_add_mch_fields_20261123.sql
new file mode 100644
index 0000000..11cd1c8
--- /dev/null
+++ b/sql/service_subtask_add_mch_fields_20261123.sql
@@ -0,0 +1,33 @@
+-- =============================================================================
+-- 濡囧辜闅忚浠诲姟鏀逛负 service_subtask 鎵胯浇锛氬鍔犲骞艰妭鐐瑰瓧娈�
+-- 鏃ユ湡锛�2026-11-23
+-- 鍓嶇疆锛氬凡鎵ц sql/pat_mch_archive_followup_status_20261123.sql
+-- 璇存槑锛�
+-- 1. 濡囧辜闅忚涓嶅啀浣跨敤 mch_followup_plan / mch_followup_plan_item / mch_followup_send_log锛�
+-- 2. 姣忎釜闅忚鑺傜偣鍒版椂闂存墠鐢熸垚涓�鏉� service_subtask锛�
+-- 3. 鍞竴閿繚璇佸悓涓�妗f璇︽儏銆佸悓涓�璁″垝鐗堟湰銆佸悓涓�鑺傜偣鍙敓鎴愪竴娆★紱
+-- 4. 妗f璇︽儏璁板綍涓嬫闇�瑕佺敓鎴愪换鍔$殑鏃堕棿锛岄伩鍏嶅畾鏃朵换鍔″弽澶嶈В鏋愭湭鏉ヨ妭鐐广��
+-- =============================================================================
+
+ALTER TABLE service_subtask
+ ADD COLUMN mch_archive_detail_id BIGINT NULL
+ COMMENT '濡囧辜妗f璇︽儏ID' AFTER service_type,
+ ADD COLUMN mch_node_seq INT NULL
+ COMMENT '濡囧辜闅忚鑺傜偣搴忓彿' AFTER mch_archive_detail_id,
+ ADD COLUMN mch_plan_hash VARCHAR(64) NULL
+ COMMENT '濡囧辜闅忚璁″垝鍝堝笇' AFTER mch_node_seq,
+ ADD COLUMN mch_node_json TEXT NULL
+ COMMENT '濡囧辜闅忚鑺傜偣JSON' AFTER mch_plan_hash,
+ ADD UNIQUE KEY uk_mch_node (mch_archive_detail_id, mch_plan_hash, mch_node_seq),
+ ADD KEY idx_mch_archive_detail (mch_archive_detail_id);
+
+-- 妗f璇︽儏涓婄殑鎳掔敓鎴愭父鏍囷細璁板綍褰撳墠璁″垝鐗堟湰鍜屼笅娆¢渶瑕佺敓鎴愪换鍔$殑鑺傜偣鏃堕棿
+ALTER TABLE pat_maternity_archive_detail
+ ADD COLUMN mch_plan_hash VARCHAR(64) NULL COMMENT '濡囧辜闅忚璁″垝鍝堝笇' AFTER followup_confirm_by,
+ ADD COLUMN mch_next_due_time DATETIME NULL COMMENT '涓嬫闇�瑕佺敓鎴愪换鍔$殑鑺傜偣鏃堕棿' AFTER mch_plan_hash,
+ ADD KEY idx_maternity_mch_next_due (orgid, mch_next_due_time);
+
+ALTER TABLE pat_child_archive_detail
+ ADD COLUMN mch_plan_hash VARCHAR(64) NULL COMMENT '濡囧辜闅忚璁″垝鍝堝笇' AFTER followup_confirm_by,
+ ADD COLUMN mch_next_due_time DATETIME NULL COMMENT '涓嬫闇�瑕佺敓鎴愪换鍔$殑鑺傜偣鏃堕棿' AFTER mch_plan_hash,
+ ADD KEY idx_child_mch_next_due (orgid, mch_next_due_time);
--
Gitblit v1.9.3