From 8249bbcc710c42f89c69fb0bd575094acd2e418d Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期五, 17 四月 2026 16:33:27 +0800
Subject: [PATCH] 南华附一上线、首页问题、定时任务问题处理

---
 smartor/src/main/java/com/smartor/service/impl/PatArchiveServiceImpl.java |   71 ++++++++++++++++++++++++++++++++---
 1 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/service/impl/PatArchiveServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/PatArchiveServiceImpl.java
index 6baf3e1..ad67157 100644
--- a/smartor/src/main/java/com/smartor/service/impl/PatArchiveServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/PatArchiveServiceImpl.java
@@ -30,6 +30,10 @@
 import java.io.FileOutputStream;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.Period;
+import java.time.ZoneId;
+import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -650,11 +654,13 @@
 
         List<PatArchive> patArchiveList1 = DtoConversionUtils.sourceToTarget(patArchiveList, PatArchive.class);
         //缁欐偅鑰呰仈绯讳汉璧嬪��
-//        for (PatArchive pa : patArchives) {
         for (PatArchive pa : patArchiveList1) {
             PatArchivecontact patArchivecontact = new PatArchivecontact();
             patArchivecontact.setPatid(pa.getId());
             pa.setPatArchivecontactList(patArchivecontactMapper.selectPatArchivecontactList(patArchivecontact));
+            Map<String, String> map = calculateAge(pa.getBirthdate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), LocalDate.now());
+            pa.setAge(StringUtils.isNotEmpty(map.get("age")) ? Long.valueOf(map.get("age")) : null);
+            pa.setAgeUnit(map.get("ageUnit") != null ? map.get("ageUnit") : "");
         }
 
         return patArchiveList1;
@@ -831,6 +837,7 @@
      * @return
      */
 //    @Override
+
     /**
      * 鑾峰彇鎮h�呬俊鎭�绘暟锛堝幓閲嶏級
      *
@@ -854,7 +861,7 @@
         } else if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 2) {
             // 鏌ョ湅浣忛櫌  1  鏌ョ湅闂ㄨ瘖  2   鏌ョ湅浣撴  3 鏌ョ湅鍑洪櫌 4
 //            count = patArchiveMapper.countPatArchiveInfoByOuthospQC(patArchiveReq);
-            PatMedOuthospQueryReq req=new PatMedOuthospQueryReq();
+            PatMedOuthospQueryReq req = new PatMedOuthospQueryReq();
             String deptcodes = CollectionUtils.isEmpty(patArchiveReq.getLeaveldeptcodes()) ? null : String.join(",", patArchiveReq.getLeaveldeptcodes());
             String leavehospitaldistrictcodes = CollectionUtils.isEmpty(patArchiveReq.getLeavehospitaldistrictcodes()) ? null : String.join(",", patArchiveReq.getLeavehospitaldistrictcodes());
             req.setDeptcode(deptcodes);
@@ -882,7 +889,7 @@
         List<PatArchiveOthreInfo> patArchiveList = new ArrayList<>();
 
         //闂ㄦ�ヨ瘖淇℃伅锛岄噰鐢ㄥ垎琛ㄦ煡璇紙鍏堟煡闂ㄦ�ヨ瘖鐨勫瓨鍌ㄨ繃绋嬶紝鍐嶆煡鎮h�呭熀鏈俊鎭〃锛屽叧鑱旀潯浠讹細patid锛�
-        PatMedOuthospQueryReq req=new PatMedOuthospQueryReq();
+        PatMedOuthospQueryReq req = new PatMedOuthospQueryReq();
         String deptcodes = CollectionUtils.isEmpty(patArchiveReq.getLeaveldeptcodes()) ? null : String.join(",", patArchiveReq.getLeaveldeptcodes());
         String leavehospitaldistrictcodes = CollectionUtils.isEmpty(patArchiveReq.getLeavehospitaldistrictcodes()) ? null : String.join(",", patArchiveReq.getLeavehospitaldistrictcodes());
         req.setDeptcode(deptcodes);
@@ -891,10 +898,10 @@
         req.setDrname(StringUtils.isNotEmpty(patArchiveReq.getDrname()) ? patArchiveReq.getDrname() : null);
         req.setPatname(StringUtils.isNotEmpty(patArchiveReq.getName()) ? patArchiveReq.getName() : null);
         req.setDiagname(StringUtils.isNotEmpty(patArchiveReq.getLeavediagname()) ? patArchiveReq.getLeavediagname() : null);
-        req.setPageNum(patArchiveReq.getPageNum()==null?null:patArchiveReq.getPageNum());
-        req.setPageSize(patArchiveReq.getPageSize()==null?null:patArchiveReq.getPageSize());
+        req.setPageNum(patArchiveReq.getPageNum() == null ? null : patArchiveReq.getPageNum());
+        req.setPageSize(patArchiveReq.getPageSize() == null ? null : patArchiveReq.getPageSize());
         List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.callSpQueryOuthosp(req);
-        for (PatMedOuthosp patMedOuthosp:patMedOuthosps ) {
+        for (PatMedOuthosp patMedOuthosp : patMedOuthosps) {
             PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp.getPatid());
             PatArchiveOthreInfo patArchiveOthreInfo = DtoConversionUtils.sourceToTarget(patArchive, PatArchiveOthreInfo.class);
             patArchiveOthreInfo.setDeptcode(patMedOuthosp.getDeptcode());
@@ -905,5 +912,57 @@
         }
         return patArchiveList;
     }
+
+    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 < 90) {
+            // 灏忎簬 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 < 36) {
+            // 灏忎簬 1 骞达紝鎸夋湀 + 澶╄绠�
+            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 {
+            // 澶т簬 1 骞达紝鎸夊勾 + 鏈堣绠�
+            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;
+    }
 }
 

--
Gitblit v1.9.3