| ¶Ô±ÈÐÂÎļþ |
| | |
| | | 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; |
| | | } |
| | | } |