a2101aa52a00ae103a26a950b54f985f46769239..67d0eef6ef56713345e03afdfd7e5badf4d4ad3d
2 天以前 陈昶聿
fix: 补提交妇幼随访 service_subtask 方案核心文件
67d0ee 对比 | 目录
2 天以前 陈昶聿
【丽水】妇幼随访发送
2356e2 对比 | 目录
已修改1个文件
已添加9个文件
1085 ■■■■■ 文件已修改
smartor/src/main/java/com/smartor/common/MchFollowupConstants.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/domain/MchFollowupArchiveCursor.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/mapper/MchFollowupSubtaskMapper.java 78 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/mch/IMchFollowupSubtaskService.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/mch/MchFollowupSendContext.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/mch/MchFollowupSubtaskServiceImpl.java 600 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/MchFollowupSubtaskMapper.xml 155 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/test/java/com/smartor/service/mch/MchFollowupSubtaskLogicCheck.java 114 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
sql/drop_mch_followup_plan_tables_20261123.sql 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
sql/service_subtask_add_mch_fields_20261123.sql 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/common/MchFollowupConstants.java
@@ -44,6 +44,12 @@
    /** è¡¥å‘窗口:只补发 1 å¤©å†…到期的节点。 */
    public static final long CATCHUP_MILLIS = 24L * 60L * 60L * 1000L;
    /** æ‡’生成提前量:默认提前 60 åˆ†é’Ÿç”Ÿæˆå³å°†åˆ°æœŸçš„节点。 */
    public static final long GENERATE_AHEAD_MILLIS = 60L * 60L * 1000L;
    /** æ‡’生成提前量(分钟)配置 key。 */
    public static final String CONFIG_GENERATE_AHEAD_MINUTES = "mch.followup.generate.ahead.minutes";
    /** å¯ç”¨å¼€å…³ï¼ˆsys_config,按机构读取;缺省视为启用)。 */
    public static final String CONFIG_ENABLED = "mch.followup.enabled";
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;
/**
 * å¦‡å¹¼æ¡£æ¡ˆæ‡’生成游标:当前计划哈希 + ä¸‹æ¬¡éœ€è¦ç”Ÿæˆä»»åŠ¡çš„èŠ‚ç‚¹æ—¶é—´ã€‚
 */
@Data
public class MchFollowupArchiveCursor implements Serializable {
    private static final long serialVersionUID = 1L;
    private String planHash;
    private Date nextDueTime;
}
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;
/**
 * å¦‡å¹¼éšè®¿ä»»åŠ¡ï¼ˆservice_subtask)专用 Mapper。
 *
 * <p>妇幼节点不再使用独立计划表,节点快照落在 service_subtask çš„
 * mch_archive_detail_id / mch_node_seq / mch_plan_hash / mch_node_json ä¸Šã€‚</p>
 */
@Mapper
public interface MchFollowupSubtaskMapper {
    /**
     * æ‰«æå·²ç¡®è®¤ã€ä¸”拟随访日期和随访周期都有值的妇幼档案。
     */
    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);
    /**
     * æŸ¥è¯¢æ¡£æ¡ˆè¯¦æƒ…的懒生成游标。
     */
    MchFollowupArchiveCursor selectMchCursor(@Param("archiveType") String archiveType,
                                            @Param("detailId") Long detailId);
    /**
     * æ›´æ–°æ¡£æ¡ˆè¯¦æƒ…的懒生成游标。
     */
    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);
}
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 {
    /**
     * æ ¹æ®æ¡£æ¡ˆè¯¦æƒ…重建妇幼随访 subtask。
     *
     * @return æ–°ç”Ÿæˆçš„节点数量
     */
    int rebuildForArchive(String archiveType, Long archiveId, Long archiveDetailId);
    /**
     * è¡¥å¿æ‰«æï¼šä¸ºå·²æœ‰å¦‡å¹¼æ¡£æ¡ˆè¡¥å»º subtask。
     */
    int rebuildAll(int limit);
    /**
     * å‘送一条妇幼 subtask(由 sfHandlle è°ƒç”¨ï¼‰ã€‚
     */
    void sendSubtask(ServiceSubtask subtask);
}
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;
}
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;
 * è½åº“:service_subtask(service_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 å¼‚常,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 || 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 ç”Ÿæˆï¼ŒdetailId={},followupStatus={}",
                    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={},period={}",
                    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("【妇幼随访】subtask å·²å­˜åœ¨ï¼ŒdetailId={},seq={}", snapshot.archiveDetailId, node.getSeq());
            } catch (Exception e) {
                log.error("【妇幼随访】subtask æ’入失败,detailId={},seq={}",
                        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 ç”Ÿæˆå®Œæˆï¼ŒdetailId={},节点数={},下次生成时间={}",
                    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 å¤±è´¥ï¼ŒarchiveType={},archiveId={},detailId={}",
                        candidate.getArchiveType(), candidate.getArchiveId(),
                        candidate.getArchiveDetailId(), e);
            }
        }
        return generated;
    }
    @Override
    public void sendSubtask(ServiceSubtask subtask) {
        if (subtask == null || subtask.getId() == null) {
            log.warn("【妇幼随访】subtask ä¸ºç©ºï¼Œè·³è¿‡å‘送");
            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("【妇幼随访】subtask å·²è¢«é¢†å–或非待发送,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("【妇幼随访】节点JSON解析失败,subtaskId={},json={}", subtask.getId(), nodeJson, e);
            finish(subtask.getId(), 5L, "error", "妇幼随访节点JSON解析失败", 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={},sendstate={}", 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;
    }
    /**
     * ç¡®ä¿æ¯ç§å¦‡å¹¼æ¡£æ¡ˆç±»åž‹æœ‰ä¸€æ¡ä¸“用 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("妇幼专科档案随访");
        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={},taskName={}", 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;
    }
}
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 &lt;&gt; ''
          and d.archiveid is not null
          and (d.mch_next_due_time is null or d.mch_next_due_time &lt;= #{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 &lt;&gt; ''
          and d.archiveid is not null
          and (d.mch_next_due_time is null or d.mch_next_due_time &lt;= #{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 &lt;&gt; #{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 &lt; 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>
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>覆盖:followupPeriod è§£æžã€å‘送时间计算、占位符渲染、Mapper XML、SQL è¿ç§»è„šæœ¬ã€‚</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 è§£æž --");
        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 è§£æž --");
        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},ID=${patid},电话=${phone},基准=${plannedFollowTime},序号=${seq}", context);
        check("占位符", "您好张三,ID=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("========== ç»“果:PASS=" + passed + ",FAIL=" + 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 è§£æžå¤±è´¥: " + e.getMessage());
            return false;
        }
    }
}
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;
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. å”¯ä¸€é”®ä¿è¯åŒä¸€æ¡£æ¡ˆè¯¦æƒ…、同一计划版本、同一节点只生成一次;
--   4. æ¡£æ¡ˆè¯¦æƒ…记录下次需要生成任务的时间,避免定时任务反复解析未来节点。
-- =============================================================================
ALTER TABLE service_subtask
    ADD COLUMN mch_archive_detail_id BIGINT NULL
        COMMENT '妇幼档案详情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);
-- æ¡£æ¡ˆè¯¦æƒ…上的懒生成游标:记录当前计划版本和下次需要生成任务的节点时间
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);