From 21ce122193e2fb57d206dbfca59e8d2ab2114fd0 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期一, 23 三月 2026 17:12:56 +0800
Subject: [PATCH] 新增病区与科室组合

---
 smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java |  311 +++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 249 insertions(+), 62 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java
index dd95a3d..6d833d5 100644
--- a/smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java
@@ -1,20 +1,26 @@
 package com.smartor.service.impl;
 
-import java.util.*;
-
-import com.ruoyi.common.core.domain.entity.SysDept;
-import com.ruoyi.common.core.domain.entity.SysUserDept;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.DtoConversionUtils;
-import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.smartor.domain.*;
+import com.smartor.domain.entity.ServiceSubtaskEntity;
 import com.smartor.mapper.*;
+import com.smartor.service.IPatMedOuthospService;
 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;
 import org.springframework.util.CollectionUtils;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.time.LocalDate;
+import java.time.Period;
+import java.time.ZoneId;
+import java.time.temporal.ChronoUnit;
+import java.util.*;
 
 /**
  * 鎮h�呴棬璇婅褰昐ervice涓氬姟灞傚鐞�
@@ -29,7 +35,7 @@
     private PatMedOuthospMapper patMedOuthospMapper;
 
     @Autowired
-    private SysUserDeptMapper sysUserDeptMapper;
+    private DataSource dataSource;
 
     @Autowired
     private ServiceSubtaskMapper serviceSubtaskMapper;
@@ -39,6 +45,9 @@
 
     @Autowired
     private ServiceTaskdiagMapper serviceTaskdiagMapper;
+
+    @Autowired
+    private ServiceTaskdeptMapper serviceTaskdeptMapper;
 
     @Autowired
     private PatArchiveMapper patArchiveMapper;
@@ -52,7 +61,8 @@
      */
     @Override
     public PatMedOuthosp selectPatMedOuthospById(Long id) {
-        return patMedOuthospMapper.selectPatMedOuthospById(id);
+//        return patMedOuthospMapper.selectPatMedOuthospById(id);
+        return null;
     }
 
     /**
@@ -63,33 +73,195 @@
      */
     @Override
     public List<PatMedOuthosp> selectPatMedOuthospList(PatMedOuthosp patMedOuthosp) {
-        List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.selectPatMedOuthospList(patMedOuthosp);
-        return patMedOuthosps;
+        PatMedOuthospQueryReq patMedOuthospQueryReq = DtoConversionUtils.sourceToTarget(patMedOuthosp, PatMedOuthospQueryReq.class);
+        List<PatMedOuthosp> patMedOuthospQueryResps = patMedOuthospMapper.callSpQueryOuthosp(patMedOuthospQueryReq);
+        if (patMedOuthosp.getPageNum() != null) {
+            for (PatMedOuthosp patMedOuthosp1 : patMedOuthospQueryResps) {
+                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.setSex(patArchive.getSex());
+                    patMedOuthosp1.setTelcode(patArchive.getTelcode());
+                    patMedOuthosp1.setIdcardno(patArchive.getIdcardno());
+                }
+                ServiceSubtaskEntity serviceSubtaskVO = new ServiceSubtaskEntity();
+                serviceSubtaskVO.setPatid(patMedOuthosp1.getPatid());
+                List<Long> sendstates = new ArrayList<>();
+                sendstates.add(1L);
+                sendstates.add(2L);
+                sendstates.add(3L);
+                serviceSubtaskVO.setSendstates(sendstates);
+                serviceSubtaskVO.setServiceType("3");
+                List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskBySendstate(serviceSubtaskVO);
+                if (!CollectionUtils.isEmpty(serviceSubtaskList)) patMedOuthosp1.setServerState("1");
+            }
+        }
+        return patMedOuthospQueryResps;
+    }
+
+    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;
     }
 
     /**
      * 鏂板鎮h�呴棬璇婅褰�
+     * 鏍规嵁 admitdate 璺敱鍒板搴斿垎琛紱鑻ュ垎琛ㄤ笉瀛樺湪鍒欏啓鍏ヤ富琛�
      *
      * @param patMedOuthosp 鎮h�呴棬璇婅褰�
      * @return 缁撴灉
      */
     @Override
     public int insertPatMedOuthosp(PatMedOuthosp patMedOuthosp) {
+        if (patMedOuthosp.getAdmitdate() != null) {
+            log.error("闂ㄦ�ュ氨璇婃椂闂翠笉鑳戒负绌�");
+            return 0;
+        }
         patMedOuthosp.setCreateTime(DateUtils.getNowDate());
         patMedOuthosp.setUpdateTime(DateUtils.getNowDate());
-        return patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp);
+        patMedOuthosp.setGuid(UUID.randomUUID().toString());
+        //闇�瑕佹彃鍏ュ埌鍝釜琛紝鏍规嵁灏辫瘖鏃堕棿鐨勬棩鏈熸潵瀹氾紝濡傛灉鏍规嵁灏辫瘖鏃堕棿鏉ョ‘瀹氱殑琛ㄤ笉瀛樺湪锛屽垯瀛樺湪pat_med_outhosp琛ㄤ腑
+        String targetTable = resolveTargetTable(patMedOuthosp.getAdmitdate());
+        if (targetTable != null) {
+            log.info("[insert] 璺敱鍒板垎琛�: {}", targetTable);
+            return patMedOuthospMapper.insertIntoTable(targetTable, patMedOuthosp);
+        }
+        return 0;
     }
 
     /**
      * 淇敼鎮h�呴棬璇婅褰�
+     * 鏍规嵁 admitdate 璺敱鍒板搴斿垎琛紱鑻ュ垎琛ㄤ笉瀛樺湪鍒欐敼涓昏〃
      *
      * @param patMedOuthosp 鎮h�呴棬璇婅褰�
      * @return 缁撴灉
      */
     @Override
     public int updatePatMedOuthosp(PatMedOuthosp patMedOuthosp) {
-        patMedOuthosp.setUpdateTime(DateUtils.getNowDate());
-        return patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp);
+        if (patMedOuthosp.getSerialnum() == null) {
+            log.error("娴佹按鍙蜂笉鑳戒负绌�");
+            return 0;
+        }
+        PatMedOuthospQueryReq patMedOuthospQueryReq = new PatMedOuthospQueryReq();
+        patMedOuthospQueryReq.setSerialnum(patMedOuthosp.getSerialnum());
+        patMedOuthospQueryReq.setGuid(patMedOuthosp.getGuid());
+        patMedOuthospQueryReq.setOuthospno(patMedOuthosp.getOuthospno());
+        List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.callSpQueryOuthosp(patMedOuthospQueryReq);
+
+        if (patMedOuthosps == null || patMedOuthosps.size() == 0) {
+            insertPatMedOuthosp(patMedOuthosp);
+        } else {
+            patMedOuthosp.setUpdateTime(DateUtils.getNowDate());
+            String targetTable = resolveTargetTable(patMedOuthosp.getAdmitdate());
+            if (targetTable != null) {
+                log.info("[update] 璺敱鍒板垎琛�: {}", targetTable);
+                return patMedOuthospMapper.updateInTable(targetTable, patMedOuthosp);
+            }
+        }
+        return 0;
+    }
+
+    /**
+     * 鏍规嵁 create_time 鎺ㄧ畻鐩爣鍒嗚〃鍚嶏紝涓庡缓琛ㄧ瓥鐣ヤ繚鎸佷竴鑷�
+     * <ul>
+     *   <li>6浣嶅悗缂�锛圷YYYMM锛夆啋 鎸夋湀鍒嗚〃</li>
+     *   <li>8浣嶅悗缂�锛圷YYYMMdd锛夆啋 鎸夊搴﹀垎琛紝瀛e害鍚庣紑鍥哄畾涓� 0103/0406/0709/1012</li>
+     *   <li>4浣嶅悗缂�锛圷YYY锛�    鈫� 鎸夊勾鍒嗚〃</li>
+     * </ul>
+     * 鎺ㄧ畻鍑鸿〃鍚嶅悗鏍¢獙琛ㄦ槸鍚﹀瓨鍦紝涓嶅瓨鍦ㄨ繑鍥� null锛堝洖钀戒富琛級
+     *
+     * @param createTime 鍒涘缓鏃堕棿锛屼负 null 鏃惰繑鍥� null
+     * @return 鐩爣鍒嗚〃鍚嶏紝鎴� null
+     */
+    private String resolveTargetTable(java.util.Date createTime) {
+        if (createTime == null) return null;
+        List<String> allTables = patMedOuthospMapper.getAllOuthospTableNames();
+        if (allTables == null || allTables.isEmpty()) return null;
+
+        // 鍒ゆ柇褰撳墠鍒嗚〃鍚庣紑闀垮害锛堜互绗竴寮犺〃涓哄噯锛�
+        String sample = allTables.get(0);
+        String suffix = sample.replaceFirst("pat_med_outhosp_", "");
+        int suffixLen = suffix.length();
+
+        java.util.Calendar cal = java.util.Calendar.getInstance();
+        cal.setTime(createTime);
+        int year = cal.get(java.util.Calendar.YEAR);
+        int month = cal.get(java.util.Calendar.MONTH) + 1; // 1-based
+
+        String targetTable;
+        if (suffixLen == 4) {
+            // 鎸夊勾
+            targetTable = "pat_med_outhosp_" + year;
+        } else if (suffixLen == 6) {
+            // 鎸夋湀
+            targetTable = String.format("pat_med_outhosp_%d%02d", year, month);
+        } else {
+            // 鎸夊搴︼紙8浣嶅悗缂�锛屽 20260103锛�
+            String quarterSuffix;
+            if (month <= 3) quarterSuffix = "0103";
+            else if (month <= 6) quarterSuffix = "0406";
+            else if (month <= 9) quarterSuffix = "0709";
+            else quarterSuffix = "1012";
+            targetTable = "pat_med_outhosp_" + year + quarterSuffix;
+        }
+
+        boolean exists = allTables.contains(targetTable);
+
+        log.info("[璺敱] createTime={} 鈫� 鐩爣琛�={} exists={}", createTime, targetTable, exists);
+        return exists ? targetTable : "pat_med_outhosp";
     }
 
     /**
@@ -100,7 +272,8 @@
      */
     @Override
     public int deletePatMedOuthospByIds(Long[] ids) {
-        return patMedOuthospMapper.deletePatMedOuthospByIds(ids);
+//        return patMedOuthospMapper.deletePatMedOuthospByIds(ids);
+        return 0;
     }
 
     /**
@@ -111,22 +284,26 @@
      */
     @Override
     public int deletePatMedOuthospById(Long id) {
-        return patMedOuthospMapper.deletePatMedOuthospById(id);
+//        return patMedOuthospMapper.deletePatMedOuthospById(id);
+        return 0;
     }
 
     @Override
     public PatMedRes selectPatMedOuthospCount(PatMedReq patMedReq) {
-//        // 鑾峰彇褰撳墠鐧婚檰浜虹殑閮ㄩ棬鏉冮檺
-//        if (CollectionUtils.isEmpty(patMedReq.getDeptcodeList())) {
-//            Long userId = SecurityUtils.getUserId();
-//            List<SysDept> sysDepts = sysUserDeptMapper.selectDeptListByUserId(userId);
-//            List<String> deptCode = new ArrayList<>();
-//            for (SysDept sysDept : sysDepts) {
-//                deptCode.add(sysDept.getDeptId().toString());
-//            }
-//            patMedReq.setDeptcodeList(deptCode);
-//        }
-        return patMedOuthospMapper.selectPatMedOuthospCount(patMedReq);
+        //鑾峰彇闂ㄨ瘖鐥呬汉淇℃伅锛屽苟缁熻浜烘暟鍜屼汉娆�
+        PatMedOuthospQueryReq req = new PatMedOuthospQueryReq();
+        String deptcodes = CollectionUtils.isEmpty(patMedReq.getDeptcodeList()) ? null : String.join(",", patMedReq.getDeptcodeList());
+        req.setBeginAdmitdate(patMedReq.getStartDate());
+        req.setEndAdmitdate(patMedReq.getEndDate());
+        req.setDeptcode(deptcodes);
+        req.setOrgid(patMedReq.getOrgid());
+//        req.setCampusid(patMedReq.getCampusid());
+        Long count = patMedOuthospMapper.callSpQueryOuthospCount(req);
+
+        //鏌ヨ闅忚浜烘鍜屼汉鏁�
+        PatMedRes patMedRes = serviceSubtaskMapper.selectVisitCount(patMedReq);
+        patMedRes.setRc(count == null ? 0 : count.intValue());
+        return patMedRes;
     }
 
     @Override
@@ -151,21 +328,19 @@
         for (PatMedOuthosp patMedOuthosp1 : patMedOuthosps) {
             PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp1.getPatid());
 
-            //璇ユ偅鑰呮湁鍙兘鎻愬墠鏉ュ璇婁簡锛岄偅浠栧悗闈㈢殑鏈瀹ょ殑閫氱煡灏卞彲浠ヤ笉鐢ㄥ啀鍙戠煭淇′簡
-            ServiceSubtaskVO serviceSubtaskVO = new ServiceSubtaskVO();
-            if (StringUtils.isNotEmpty(patMedOuthosp1.getDeptcode())) {
-                serviceSubtaskVO.setDeptcode(patMedOuthosp1.getDeptcode());
-                serviceSubtaskVO.setSfzh(patArchive.getIdcardno());
-                serviceSubtaskVO.setType("3");
-                serviceSubtaskVO.setSendstate(2L);
-                serviceSubtaskVO.setPreachform("4");
-                List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
-                if (!CollectionUtils.isEmpty(serviceSubtaskList)) {
-                    for (ServiceSubtask serviceSubtask : serviceSubtaskList) {
-                        serviceSubtask.setSendstate(6L);
-                        serviceSubtask.setRemark("宸插洖鏉ュ璇婏紝鏃犻渶鍐嶈繘琛岀煭淇¢�氱煡");
-                        serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
-                    }
+            //鏍规嵁鎮h�呯瀹わ紝鑾峰彇璇ョ柧鐥呯殑闀挎湡浠诲姟
+            ServiceTaskdept serviceTaskdept = new ServiceTaskdept();
+            serviceTaskdept.setLongtask(1L);
+            serviceTaskdept.setDeptCode(patMedOuthosp1.getDeptcode());
+            serviceTaskdept.setServiceType("3");
+            List<ServiceTaskdept> serviceTaskdeptList = serviceTaskdeptMapper.selectServiceTaskdeptList(serviceTaskdept);
+            if (org.apache.commons.collections4.CollectionUtils.isEmpty(serviceTaskdeptList) || serviceTaskdeptList.size() == 0) {
+                patMedOuthosp1.setDeptcheckFlag("2");
+                patMedOuthosp1.setRemark("閫氳繃閮ㄩ棬,娌℃湁鎵惧埌闂ㄨ瘖闅忚浠诲姟ID");
+                updatePatMedOuthosp(patMedOuthosp1);
+            } else {
+                for (ServiceTaskdept serviceTaskdept1 : serviceTaskdeptList) {
+                    writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedOuthosp1, patArchive, 1);
                 }
             }
 
@@ -177,11 +352,11 @@
             //濡傛灉閮ㄩ棬妯℃澘涓虹┖锛堝皢deptIsNull璁剧疆涓簍rue锛�
             if (org.apache.commons.collections4.CollectionUtils.isEmpty(serviceTaskdiags) || serviceTaskdiags.size() == 0) {
                 patMedOuthosp1.setDiagcheckFlag("2");
-                patMedOuthosp1.setRemark("閫氳繃icd10,娌℃湁鎵惧埌闅忚浠诲姟ID");
-                patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp1);
+                patMedOuthosp1.setRemark("閫氳繃icd10,娌℃湁鎵惧埌闂ㄨ瘖闅忚浠诲姟ID");
+                updatePatMedOuthosp(patMedOuthosp1);
             } else {
                 for (ServiceTaskdiag serviceTaskdept1 : serviceTaskdiags) {
-                    writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedOuthosp1, patArchive);
+                    writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedOuthosp1, patArchive, 2);
                 }
             }
 
@@ -189,17 +364,25 @@
         return 1;
     }
 
-    private void writeInSubTask(Long taskid, Boolean check, PatMedOuthosp patMedOuthosp, PatArchive patArchive) {
+    /**
+     * @param taskid
+     * @param check
+     * @param patMedOuthosp
+     * @param patArchive
+     * @param type          1 绉戝 2 鐤剧梾
+     */
+    private void writeInSubTask(Long taskid, Boolean check, PatMedOuthosp patMedOuthosp, PatArchive patArchive, Integer type) {
 
         ServiceTask st = new ServiceTask();
         st.setTaskid(taskid);
         st.setSendState(2L);
         List<ServiceTask> serviceTasks = serviceTaskMapper.selectServiceTaskList(st);
         if (org.apache.commons.collections4.CollectionUtils.isEmpty(serviceTasks)) {
-            log.error("璇ユ偅鑰呯柧鐥呴殢璁块暱鏈熶换鍔′笉瀛樺湪,浠诲姟ID涓猴細{}", taskid);
-            patMedOuthosp.setDiagcheckFlag("2");
-            patMedOuthosp.setRemark("璇ユ偅鑰呯柧鐥呴殢璁块暱鏈熶换鍔′笉瀛樺湪,浠诲姟ID涓�:" + taskid);
-            patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp);
+            log.info("璇ユ偅鑰呯柧鐥呴殢璁块暱鏈熶换鍔′笉瀛樺湪,浠诲姟ID涓猴細{}", taskid);
+            if (type == 1) patMedOuthosp.setDiagcheckFlag("2");
+            if (type == 2) patMedOuthosp.setDeptcheckFlag("2");
+            patMedOuthosp.setRemark("璇ユ偅鑰呴棬璇婇殢璁块暱鏈熶换鍔′笉瀛樺湪,浠诲姟ID涓�:" + taskid);
+            updatePatMedOuthosp(patMedOuthosp);
             return;
         }
         ServiceTask serviceTask = serviceTasks.get(0);
@@ -209,12 +392,12 @@
         //鍏堝垽鏂竴涓嬶紝鏄惁闇�瑕佹牎楠�
         if (check) {
             //鍦ㄦ柊澧炰箣鍓嶏紝鍏堥�氳繃鎮h�匢D锛宻endstate=2鏌ヨ涓�涓嬶紝鍦ㄦ墍鏈夐暱鏈熶换鍔′腑锛屾槸涓嶆槸杩樻湁璇ユ偅鑰呭緟鎵ц鐨勪换鍔★紝鏈夌殑璇�,姣旇緝涔嬪墠鐨別ndtime鏄惁灏忎簬褰撳墠鐨別ndtaime,濡傛灉涔嬪墠鐨勫皬浜庣幇鍦ㄧ殑锛屽垯鐩存帴灏嗕箣鍓嶇殑鍋滄帀锛堝師鍥犲啀鍏ラ櫌锛�
-            ServiceSubtaskVO subtask = new ServiceSubtaskVO();
+            ServiceSubtaskEntity subtask = new ServiceSubtaskEntity();
             subtask.setPatid(patArchive.getId());
             subtask.setSendstate(2L);
             subtask.setTaskid(taskid);
             List<ServiceSubtask> selectServiceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(subtask);
-            log.error("璇ユ偅鑰呭緟鎵ц鐨勪换鍔�:{}", selectServiceSubtaskList);
+            log.info("璇ユ偅鑰呭緟鎵ц鐨勪换鍔�:{}", 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())) {
@@ -223,15 +406,14 @@
                     }
 
                     //灏嗕箣鍓嶇殑鍋滄帀
-                    serviceSubtask1.setSendstate(4L);
-                    serviceSubtask1.setRemark("鐤剧梾鎮h�呭啀鍏ラ櫌");
-                    serviceSubtask1.setResult("error");
-//                    serviceSubtask1.setFinishtime(new Date());
+                    serviceSubtask1.setSendstate(6L);
+                    serviceSubtask1.setRemark("鎮h�呭凡缁忓洖闄㈠璇�");
+                    serviceSubtask1.setResult("success");
+                    serviceSubtask1.setFinishtime(new Date());
                     serviceSubtask1.setUpdateBy(serviceTask.getUpdateBy());
                     serviceSubtaskMapper.updateServiceSubtask(serviceSubtask1);
                     //閲嶆柊鏂板瀛愪换鍔�
                     i = serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
-
                 }
             } else {
                 if (StringUtils.isEmpty(serviceSubtask.getPhone())) {
@@ -260,16 +442,19 @@
             //灏哻heck_flag鏀规垚1锛堝凡澶勭悊锛�
             PatMedOuthosp patMedOuthosp1 = new PatMedOuthosp();
             patMedOuthosp1.setId(patMedOuthosp.getId());
-            patMedOuthosp1.setDiagcheckFlag("1");
-            patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp1);
+            if (type == 1) patMedOuthosp1.setDiagcheckFlag("2");
+            if (type == 2) patMedOuthosp1.setDeptcheckFlag("2");
+            updatePatMedOuthosp(patMedOuthosp1);
         } else {
             //鐢熸垚瀛愪换鍔″け璐ワ紝
-            log.error("鐢熸垚瀛愪换鍔″け璐erviceSubtask涓猴細{}", serviceSubtask);
+            log.info("鐢熸垚瀛愪换鍔″け璐erviceSubtask鐨則askid涓猴細{},patid涓猴細{}", serviceSubtask.getTaskid(), serviceSubtask.getPatid());
             PatMedOuthosp pmo = new PatMedOuthosp();
-            pmo.setId(patMedOuthosp.getId());
-            pmo.setDiagcheckFlag("2");
+            pmo.setGuid(patMedOuthosp.getGuid());
+            pmo.setSerialnum(patMedOuthosp.getSerialnum());
+            if (type == 1) pmo.setDiagcheckFlag("2");
+            if (type == 2) pmo.setDeptcheckFlag("2");
             pmo.setRemark("鐢熸垚瀛愪换鍔″け璐�");
-            patMedOuthospMapper.updatePatMedOuthosp(pmo);
+            updatePatMedOuthosp(pmo);
         }
     }
 
@@ -282,6 +467,8 @@
         serviceSubtask.setDrcode(patMedOuthosp.getDrcode());
         serviceSubtask.setDrname(patMedOuthosp.getDrname());
         serviceSubtask.setDeptcode(patMedOuthosp.getDeptcode());
+        serviceSubtask.setInhospid(patMedOuthosp.getId());
+        serviceSubtask.setHospno(patMedOuthosp.getOuthospno());
         serviceSubtask.setDeptname(patMedOuthosp.getDeptname());
         serviceSubtask.setTemplateid(serviceTask.getTemplateid());
         serviceSubtask.setTemplatename(serviceTask.getTemplatename());

--
Gitblit v1.9.3