liusheng
2025-11-11 d14b89b7e05aaf1c375468dc8e579cf0836e37b2
smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java
@@ -1,5 +1,9 @@
package com.smartor.service.impl;
import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import com.ruoyi.common.core.domain.entity.SysDept;
@@ -11,6 +15,7 @@
import com.smartor.domain.*;
import com.smartor.mapper.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.smartor.service.IPatMedOuthospService;
@@ -64,7 +69,72 @@
    @Override
    public List<PatMedOuthosp> selectPatMedOuthospList(PatMedOuthosp patMedOuthosp) {
        List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.selectPatMedOuthospList(patMedOuthosp);
        for (PatMedOuthosp patMedOuthosp1 : patMedOuthosps) {
            PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp1.getPatid());
            if (patArchive.getBirthdate() != null) {
                Map<String, String> map = calculateAge(patArchive.getBirthdate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), LocalDate.now());
                patArchive.setAge(ObjectUtils.isNotEmpty(map.get("age")) ? Long.valueOf(map.get("age")) : null);
                patArchive.setAgeUnit(map.get("ageUnit"));
                patArchive.setAge2(ObjectUtils.isNotEmpty(map.get("age2")) ? Long.valueOf(map.get("age2")) : null);
                patArchive.setAgeUnit2(map.get("ageUnit2"));
                patMedOuthosp1.setAge(patArchive.getAge() + patArchive.getAgeUnit() + patArchive.getAge2() + patArchive.getAgeUnit2());
                patMedOuthosp1.setTelcode(patArchive.getTelcode());
                patMedOuthosp1.setIdcardno(patArchive.getIdcardno());
            }
        }
        return patMedOuthosps;
    }
    public Map<String, String> calculateAge(LocalDate birthdate, LocalDate today) {
        if (birthdate == null || today.isBefore(birthdate)) {
            return null;
        }
        Map<String, String> ageMap = new HashMap<>();
        Period period = Period.between(birthdate, today);
        long totalDays = ChronoUnit.DAYS.between(birthdate, today);
        long totalMonths = ChronoUnit.MONTHS.between(birthdate, today);
        int years = period.getYears();
        int months = period.getMonths();
        int days = period.getDays();
        String ageUnit;
        Integer age;
        String ageUnit2 = null;
        Integer age2 = null;
        if (totalDays < 30) {
            // 小于 1 个月,按天计算
            ageUnit = "天";
            age = (int) totalDays;
            ageMap.put("age", age != null ? age.toString() : null);
            ageMap.put("ageUnit", ageUnit);
            ageMap.put("age2", null);
            ageMap.put("ageUnit2", null);
        } else if (totalMonths < 12) {
            // 小于 一年,按月 + 天计算
            ageUnit = "月";
            age = (int) totalMonths;
            ageUnit2 = "天";
            age2 = days;
            ageMap.put("age", age != null ? age.toString() : null);
            ageMap.put("ageUnit", ageUnit);
            ageMap.put("age2", age2 != null ? age2.toString() : null);
            ageMap.put("ageUnit2", ageUnit2);
        } else {
            // 大于等于 一年,按年 + 月计算
            ageUnit = "岁";
            age = years;
            ageUnit2 = "月";
            age2 = months;
            ageMap.put("age", age != null ? age.toString() : null);
            ageMap.put("ageUnit", ageUnit);
            ageMap.put("age2", age2 != null ? age2.toString() : null);
            ageMap.put("ageUnit2", ageUnit2);
        }
        return ageMap;
    }
    /**
@@ -214,7 +284,7 @@
            subtask.setSendstate(2L);
            subtask.setTaskid(taskid);
            List<ServiceSubtask> selectServiceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(subtask);
            log.error("该患者待执行的任务:{}", selectServiceSubtaskList);
            log.error("该患者待执行的任务:{}", CollectionUtils.isEmpty(selectServiceSubtaskList) ? null : selectServiceSubtaskList.size());
            if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(selectServiceSubtaskList) && selectServiceSubtaskList.size() > 0) {
                for (ServiceSubtask serviceSubtask1 : selectServiceSubtaskList) {
                    if (Objects.isNull(serviceSubtask1.getLongSendTime())) {
@@ -264,7 +334,7 @@
            patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp1);
        } else {
            //生成子任务失败,
            log.error("生成子任务失败serviceSubtask为:{}", serviceSubtask);
            log.error("生成子任务失败serviceSubtask的taskid为:{},patid为:{}", serviceSubtask.getTaskid(), serviceSubtask.getPatid());
            PatMedOuthosp pmo = new PatMedOuthosp();
            pmo.setId(patMedOuthosp.getId());
            pmo.setDiagcheckFlag("2");