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

---
 smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java |  108 ++++++++++++-----------------------------------------
 1 files changed, 25 insertions(+), 83 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java
index ef267bf..66c5a2e 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java
@@ -8,10 +8,12 @@
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.exception.base.BaseException;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.DtoConversionUtils;
 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 com.smartor.service.IServiceExternalService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
@@ -64,6 +66,8 @@
     private PatMedInspectionItemMapper patMedInspectionItemMapper;
     @Autowired
     private Icd10Mapper icd10Mapper;
+    @Autowired
+    private IPatMedOuthospService patMedOuthospService;
     @Autowired
     private PatMedOuthospMapper patMedOuthospMapper;
     @Autowired
@@ -223,13 +227,13 @@
         if (CollectionUtils.isNotEmpty(sysDepts)) {
             sysDept = sysDepts.get(0);
         }
-        if(ObjectUtils.isEmpty(sysUser)){
+        if (ObjectUtils.isEmpty(sysUser)) {
             log.error("ServiceExternalServiceImpl---addUserDeptInfo 鎵句笉鍒板搴旂殑鐢ㄦ埛 username: {}", externalUserDeptInfo.getYongHuDLM());
             return false;
-        }else if(ObjectUtils.isEmpty(sysDept)){
+        } else if (ObjectUtils.isEmpty(sysDept)) {
             log.error("ServiceExternalServiceImpl---addUserDeptInfo 鎵句笉鍒板搴旂殑绉戝 hisDeptId: {}", externalUserDeptInfo.getKeShiID());
             return false;
-        }else {
+        } else {
             SysUserDept sysUserDept = new SysUserDept();
             sysUserDept.setDelFlag(0L);
             sysUserDept.setUserId(sysUser.getUserId());
@@ -271,19 +275,18 @@
                 log.info("ServiceExternalServiceImpl---addUserDeptInfo鏄惁淇敼鎴愬姛03锛歿}", i);
             }
             //鏇存柊sys-user deptId
-            if(StringUtils.isNotEmpty(externalUserDeptInfo.getKeShiID())){
+            if (StringUtils.isNotEmpty(externalUserDeptInfo.getKeShiID())) {
                 sysUser.setDeptId(Long.valueOf(externalUserDeptInfo.getKeShiID()));
                 //鏌ヨ鐢ㄦ埛绉戝鍏崇郴
                 SysUserDept sysUserDeptTemp = new SysUserDept();
                 sysUserDeptTemp.setUserId(sysUser.getUserId());
                 sysUserDeptTemp.setOrgid(externalUserDeptInfo.getZuZhiJGID());
                 List<SysUserDept> sysUserDepts = sysUserDeptMapper.selectSysUserDeptList(sysUserDeptTemp);
-                List<String> userDepts = sysUserDepts.stream().map(SysUserDept::getDeptCode).
-                        distinct().collect(Collectors.toList());
+                List<String> userDepts = sysUserDepts.stream().map(SysUserDept::getDeptCode).distinct().collect(Collectors.toList());
                 //鍜宷ueryHospUserInfoList閲囬泦鐨勬暟鎹牸寮忎繚鎸佷竴鑷�
                 List<List<String>> userDeptsList = new ArrayList<>();
-                if(!userDepts.isEmpty()){
-                    for(String userDept: userDepts){
+                if (!userDepts.isEmpty()) {
+                    for (String userDept : userDepts) {
                         List<String> uDept = new ArrayList<>();
                         uDept.add(userDept);
                         userDeptsList.add(uDept);
@@ -579,7 +582,7 @@
             // 4-闈炲尰鍢辩闄� 5-姝讳骸 9-鍏朵粬 10-浠嬪叆瀹� 20-鎵嬫湳瀹�
             String liYuanQxdm = ObjectUtils.isNotEmpty(JiuZhenXX.get("LiYuanQXDM")) ? JiuZhenXX.get("LiYuanQXDM").toString() : null;
             //鍒ゆ柇鐥呬汉鏄惁姝讳骸
-            if(ObjectUtils.isNotEmpty(liYuanQxdm) &&("5").equals(liYuanQxdm)){
+            if (ObjectUtils.isNotEmpty(liYuanQxdm) && ("5").equals(liYuanQxdm)) {
                 deathFlag = true;
             }
         }
@@ -625,7 +628,7 @@
         }
 
         patMedInhosp1.setInhospstate("1");
-        if(deathFlag){
+        if (deathFlag) {
             //鐥呬汉姝讳骸鏃犻』闅忚
             patMedInhosp1.setFuflag("1");
             //鏇存柊鐥呬汉 notrequiredFlag
@@ -1032,6 +1035,7 @@
      * 绗竴鏉★紙鎬ヨ瘖绉戝鐨勶級璁板綍缂哄皯鈥滃嚭闄㈡椂闂粹�濓紝瀵艰嚧璇ヨ褰曞湪缁熻涓缁堟樉绀轰负鈥滃湪闄⑩�濓紝
      * 鑰岀浜屾潯锛堣浆鍏ョ瀹ょ殑锛夎褰曟槸瀹屾暣鐨勩�傛垜浠渶瑕侀噰闆� JZ_ZY_LiQiang鎺ュ彛鐨勬暟鎹紝
      * 閲岄潰鐨勭鎶㈡椂闂存潵鍙嶅~绗竴鏉¤褰曠殑鈥滃嚭闄㈡椂闂粹�濓紝浠庤�屼慨姝g涓�鏉¤褰曠殑鐘舵�併��
+     *
      * @param dataMap
      * @return
      */
@@ -1051,7 +1055,7 @@
         List<PatMedInhosp> patMedInhospList = patMedInhospMapper.selectPatMedInhospList(patMedInhosp);
         PatMedInhosp patMedInhosp1 = null;
         if (CollectionUtils.isNotEmpty(patMedInhospList)) patMedInhosp1 = patMedInhospList.get(0);
-        if(ObjectUtils.isNotEmpty(patMedInhosp1)){
+        if (ObjectUtils.isNotEmpty(patMedInhosp1)) {
             if (ObjectUtils.isNotEmpty(JiuZhenXX.get("LiQiangSJ"))) {
                 try {
                     SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -1066,16 +1070,15 @@
                 }
             }
             return true;
-        }else {
+        } else {
             log.error("ServiceExternalServiceImpl---editRescueFinishedOutHospInfo鐨勬病鏈夋壘鍒板搴旂殑鍑洪櫌璁板綍锛歿}", dataMap);
             return false;
         }
     }
+
     @Override
     public Boolean addFinshJZInfo(Map dataMap) {
         log.info("ServiceExternalServiceImpl---addFinshJZInfo鐨勬柊澧炵殑鍊间负锛歿}", dataMap);
-        //鍏堝琛ㄨ繘琛岀淮鎶�
-        tableMaintenance();
 
         Map yeWuXX = (Map) dataMap.get("YeWuXX");
         Map XiaoXiTou = (Map) dataMap.get("XiaoXiTou");
@@ -1114,10 +1117,10 @@
 
         PatArchive patArchive = addPatArchive(externalInHospPatientInfo, null, null);
 
-        PatMedOuthosp patMedOuthosp = new PatMedOuthosp();
-        patMedOuthosp.setOuthospno(externalInHospPatientInfo.getBingAnHao());
-        patMedOuthosp.setSerialnum(externalInHospPatientInfo.getJiuZhenYWID());
-        List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.selectPatMedOuthospList(patMedOuthosp);
+        PatMedOuthospQueryReq patMedOuthospreq = new PatMedOuthospQueryReq();
+        patMedOuthospreq.setOuthospno(externalInHospPatientInfo.getBingAnHao());
+        patMedOuthospreq.setSerialnum(externalInHospPatientInfo.getJiuZhenYWID());
+        List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.callSpQueryOuthosp(patMedOuthospreq);
         for (PatMedOuthosp patMedOuthosp1 : patMedOuthosps) {
             PatArchive pa = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp1.getPatid());
             if (patArchive.getBirthdate() != null) {
@@ -1133,6 +1136,7 @@
             }
         }
 
+        PatMedOuthosp patMedOuthosp = DtoConversionUtils.sourceToTarget(patMedOuthospreq, PatMedOuthosp.class);
         patMedOuthosp.setPatid(patArchive.getId());
         patMedOuthosp.setPatno(externalInHospPatientInfo.getBingAnHao());
         patMedOuthosp.setPatname(externalInHospPatientInfo.getXingMing());
@@ -1175,7 +1179,7 @@
                 //涓嶉渶瑕侀暱鏈熶换鍔¢殢璁匡紝鐢卞尰鐢熻嚜宸卞幓闅忚锛堜附姘翠腑鍖婚櫌棣栨鎻愬嚭锛�
                 patMedOuthosp.setFuflag("1");
             }
-            i = patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp);
+            i = patMedOuthospService.updatePatMedOuthosp(patMedOuthosp);
         } else {
             patMedOuthosp.setCreateTime(new Date());
             patMedOuthosp.setUpdateTime(new Date());
@@ -1183,76 +1187,14 @@
                 //涓嶉渶瑕侀暱鏈熶换鍔¢殢璁�
                 patMedOuthosp.setFuflag("1");
             }
-            i = patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp);
-        }
+            i = patMedOuthospService.insertPatMedOuthosp(patMedOuthosp);
 
-//        //鍏堥�氳繃韬唤璇佸拰绉戝鏌ヨ璇ユ偅鑰呮槸鍚︽湁闇�瑕侀殢璁跨殑(鏅畞鎻愬嚭鏉ョ殑)
-//        if (patMedOuthosp.getOrgid().equals("47255004333112711A1001") && StringUtils.isNotEmpty(patMedOuthosp.getIdcardno()) && StringUtils.isNotEmpty(patMedOuthosp.getDeptcode())) {
-//            ServiceSubtaskVO serviceSubtaskVO = new ServiceSubtaskVO();
-//            serviceSubtaskVO.setSfzh(patMedOuthosp.getIdcardno());
-//            serviceSubtaskVO.setDeptcode(patMedOuthosp.getDeptcode());
-//            serviceSubtaskVO.setSendstate(2L);
-//            List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
-//            if (CollectionUtils.isNotEmpty(serviceSubtaskList)) {
-//                for (ServiceSubtask serviceSubtask : serviceSubtaskList) {
-//                    serviceSubtask.setSendstate(6L);
-//                    serviceSubtask.setRemark("鎮h�呭凡缁忓洖鏉ュ璇�");
-//                    serviceSubtask.setUpdateTime(new Date());
-//                    serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
-//                }
-//            }
-//        }
+        }
 
         if (i > 0) {
             return true;
         }
         return false;
-    }
-
-
-    public void tableMaintenance() {
-        // 1. 鍒ゆ柇琛ㄦ暟鎹噺
-        int count = patMedOuthospMapper.countPatMedOuthosp();
-        if (count > 3000000) {
-            // 2. 鍐疯棌琛ㄥ苟鏂板缓
-            String timeSuffix = new SimpleDateFormat("yyyyMM").format(new Date());
-            String oldName = "pat_med_outhosp";
-            String newName = oldName + "_" + timeSuffix;
-
-            // 鍐疯棌
-            patMedOuthospMapper.renameTable(oldName, newName);
-
-            // 3. 璁$畻鎵�鏈夎〃鐨勬渶澶d
-            List<String> tableNames = patMedOuthospMapper.getAllOuthospTableNames();
-            long maxId = 0;
-            for (String tableName : tableNames) {
-                Long tableMaxId = patMedOuthospMapper.getMaxIdFromTable(tableName);
-                if (tableMaxId != null && tableMaxId > maxId) {
-                    maxId = tableMaxId;
-                }
-            }
-
-            // 4. 鏂板缓(姝ゆ椂鍙墿鍐疯〃锛孭atMedOuthosp娌′簡锛岄渶瑕佹柊寤轰竴涓�)
-            patMedOuthospMapper.createPatMedOuthosp(newName, oldName);
-
-            //5.璁剧疆鏂拌〃鑷涓婚敭
-            patMedOuthospMapper.createPatMedOuthospAutoAdd(oldName);
-            //6. 璁剧疆鏂拌〃鑷璧峰鍊�
-            patMedOuthospMapper.setAutoIncrement(oldName, maxId + 1);
-
-            // 7. 鏇存柊/鏂板缓瑙嗗浘
-            // 閲嶆柊鑾峰彇鎵�鏈夎〃鍚嶏紙鍖呭惈鍒氭柊寤虹殑涓昏〃锛�
-            List<String> allTables = patMedOuthospMapper.getAllOuthospTableNames();
-            StringBuilder sb = new StringBuilder();
-            sb.append("CREATE OR REPLACE VIEW v_pat_med_outhosp AS ");
-            for (int i = 0; i < allTables.size(); i++) {
-                sb.append("SELECT * FROM ").append(allTables.get(i));
-                if (i < allTables.size() - 1) {
-                    sb.append(" UNION ALL ");
-                }
-            }
-            patMedOuthospMapper.createOrReplaceView(sb.toString());
-        }
     }
 
     @Override

--
Gitblit v1.9.3