陈昶聿
3 天以前 c885a9c26e624f403e3d73beac8c6346657ad561
smartor/src/main/java/com/smartor/service/mch/MchFollowupPlanServiceImpl.java
@@ -1,5 +1,6 @@
package com.smartor.service.mch;
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;
@@ -9,6 +10,8 @@
import com.smartor.domain.MchFollowupNode;
import com.smartor.domain.MchFollowupPlan;
import com.smartor.domain.MchFollowupPlanItem;
import com.smartor.domain.MchFollowupTaskQuery;
import com.smartor.domain.MchFollowupTaskVO;
import com.smartor.domain.PatChildArchiveDetail;
import com.smartor.domain.PatMaternityArchiveDetail;
import com.smartor.mapper.MchFollowupPlanItemMapper;
@@ -84,6 +87,12 @@
        if (!SpecificArchiveConstants.LISHUI_MCH_ORG_ID.equals(snapshot.orgid)) {
            return 0;
        }
        // 档案必须经过人工保存/确认后才允许生成计划;接诊完成自动建档只是草稿。
        if (!isFollowupActive(snapshot.followupStatus)) {
            log.debug("【妇幼随访】档案未确认随访,跳过计划重建,archiveType={},archiveId={},detailId={},followupStatus={}",
                    snapshot.archiveType, snapshot.archiveId, snapshot.archiveDetailId, snapshot.followupStatus);
            return 0;
        }
        List<MchFollowupPlan> actives = planMapper.selectActiveByArchive(
                snapshot.archiveType, snapshot.archiveId, snapshot.archiveDetailId);
@@ -91,7 +100,10 @@
            actives = Collections.emptyList();
        }
        for (MchFollowupPlan active : actives) {
            if (sameTime(active.getPlannedFollowTime(), snapshot.plannedFollowTime)
            // 只有“有效”计划才做幂等判断;待补充计划即使日期/周期字符串相同,
            // 也可能是因为之前配置非法而挂起,人工确认后必须重新解析并生成节点。
            if (MchFollowupConstants.PLAN_STATUS_ACTIVE.equals(active.getPlanStatus())
                    && sameTime(active.getPlannedFollowTime(), snapshot.plannedFollowTime)
                    && StringUtils.equals(active.getFollowupPeriod(), snapshot.followupPeriod)) {
                MchFollowupPlan contactUpdate = new MchFollowupPlan();
                contactUpdate.setId(active.getId());
@@ -194,6 +206,50 @@
        return generated;
    }
    @Override
    public int updateItemFollowupResult(MchFollowupPlanItem item) {
        if (item == null || item.getId() == null) {
            throw new BaseException("随访节点ID不能为空");
        }
        String followupStatus = item.getFollowupStatus();
        if (StringUtils.isEmpty(followupStatus)) {
            throw new BaseException("随访状态不能为空");
        }
        if (!isValidItemFollowupStatus(followupStatus)) {
            throw new BaseException("不支持的随访状态:" + followupStatus);
        }
        MchFollowupPlanItem existing = itemMapper.selectMchFollowupPlanItemById(item.getId());
        if (existing == null) {
            throw new BaseException("随访节点不存在:" + item.getId());
        }
        item.setUpdateTime(DateUtils.getNowDate());
        return itemMapper.updateFollowupResult(item);
    }
    @Override
    public List<MchFollowupPlanItem> listItems(Long planId) {
        if (planId == null) {
            throw new BaseException("计划ID不能为空");
        }
        return itemMapper.selectByPlanId(planId);
    }
    @Override
    public List<MchFollowupTaskVO> listTasks(MchFollowupTaskQuery query) {
        if (query == null || StringUtils.isEmpty(query.getOrgid())) {
            throw new BaseException("机构ID不能为空");
        }
        return itemMapper.selectTaskList(query);
    }
    private boolean isValidItemFollowupStatus(String status) {
        return MchFollowupConstants.ITEM_FOLLOWUP_STATUS_PENDING.equals(status)
                || MchFollowupConstants.ITEM_FOLLOWUP_STATUS_DONE.equals(status)
                || MchFollowupConstants.ITEM_FOLLOWUP_STATUS_LOST.equals(status)
                || MchFollowupConstants.ITEM_FOLLOWUP_STATUS_REFUSED.equals(status)
                || MchFollowupConstants.ITEM_FOLLOWUP_STATUS_BAD_NUMBER.equals(status);
    }
    private ArchiveSnapshot loadSnapshot(String archiveType, Long archiveId, Long archiveDetailId) {
        if (MchFollowupConstants.ARCHIVE_TYPE_MATERNITY.equals(archiveType)) {
            return loadMaternitySnapshot(archiveId, archiveDetailId);
@@ -237,6 +293,7 @@
        snapshot.plannedFollowTime = detail.getPlannedFollowTime();
        snapshot.followupPeriod = detail.getFollowupPeriod();
        snapshot.followupCycleTimes = detail.getFollowupCycleTimes();
        snapshot.followupStatus = detail.getFollowupStatus();
        return snapshot;
    }
@@ -271,7 +328,16 @@
        snapshot.idcardno = detail.getIdcardno();
        snapshot.plannedFollowTime = detail.getPlannedFollowTime();
        snapshot.followupPeriod = detail.getFollowupPeriod();
        snapshot.followupStatus = detail.getFollowupStatus();
        return snapshot;
    }
    /**
     * 历史数据没有状态时按已确认处理,保证已有档案的计划不受影响。
     */
    private boolean isFollowupActive(String followupStatus) {
        return StringUtils.isEmpty(followupStatus)
                || MchFollowupConstants.FOLLOWUP_STATUS_ACTIVE.equals(followupStatus);
    }
    private boolean isEnabled() {
@@ -317,5 +383,6 @@
        private Date plannedFollowTime;
        private String followupPeriod;
        private String followupCycleTimes;
        private String followupStatus;
    }
}