From 38ec874ec093ba977c05911429fc04540a1c032a Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期五, 25 七月 2025 10:10:04 +0800
Subject: [PATCH] 代码提交

---
 smartor/src/main/java/com/smartor/service/impl/HNGatherPatArchiveServiceImpl.java |  168 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 134 insertions(+), 34 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/service/impl/HNGatherPatArchiveServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/HNGatherPatArchiveServiceImpl.java
index 8c42b45..2cb62f0 100644
--- a/smartor/src/main/java/com/smartor/service/impl/HNGatherPatArchiveServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/HNGatherPatArchiveServiceImpl.java
@@ -2,38 +2,19 @@
 
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysUser;
-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.core.domain.entity.SysUserDept;
+import com.ruoyi.common.core.domain.entity.SysUserRole;
 import com.ruoyi.common.utils.StringUtils;
 import com.smartor.domain.*;
 import com.smartor.mapper.*;
 import com.smartor.service.IHNGatherPatArchiveService;
-import com.smartor.service.IPatArchiveService;
-import com.smartor.service.IPatMedInhospService;
-import com.smartor.service.IPatMedPhysicalService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.ObjectUtils;
-import org.apache.poi.hssf.usermodel.HSSFDateUtil;
-import org.apache.poi.ss.usermodel.DataFormatter;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.multipart.MultipartFile;
 
-import java.io.FileOutputStream;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.*;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.stream.Collectors;
 
 /**
  * 鎮h�呮。妗圫ervice涓氬姟灞傚鐞�
@@ -51,7 +32,13 @@
     private SysUser2Mapper sysUser2Mapper;
 
     @Autowired
+    private SysUserRole2Mapper sysUserRoleMapper;
+
+    @Autowired
     private SysDept2Mapper sysDept2Mapper;
+
+    @Autowired
+    private SysUserDeptMapper sysUserDeptMapper;
 
     @Autowired
     private Icd10Mapper icd10Mapper;
@@ -62,34 +49,90 @@
     @Autowired
     private PatMedInhospMapper patMedInhospMapper;
 
+    @Autowired
+    private PatArchiveMapper patArchiveMapper;
+
+    @Autowired
+    private ThreadPoolTaskExecutor taskExecutor;
+
+    @Autowired
+    private ShardingMapper shardingMapper;
+
+    private static final long SHARDING_THRESHOLD = 5_000_000L;
+    private static final String PAT_ARCHIVE_TABLE = "pat_archive";
+    private static final String PAT_MED_INHOSP_TABLE = "pat_med_inhosp";
+
 
     @Override
     public List<PatArchive> selectPatArchiveList(PatArchive patArchive) {
         return hnGatherPatArchiveMapper.selectPatArchiveList(patArchive);
     }
 
+//    @Override
+//    public Integer selectPatMedInhospList(PatMedInhosp patMedInhosp) {
+//        // 寮傛鎵ц鏁翠釜鏁版嵁鍚屾浠诲姟
+//        taskExecutor.execute(() -> {
+//            log.info("寮�濮嬫墽琛屾暟鎹悓姝ヤ换鍔�...");
+//            syncPatArchivesInOrder(); // 鍏堝悓姝ユ偅鑰�
+//            syncPatMedInhosp();       // 鍐嶅悓姝ュ嚭鍏ラ櫌
+//            log.info("鏁版嵁鍚屾浠诲姟鎻愪氦瀹屾瘯銆�");
+//        });
+//        return 0; // 杩斿洖0琛ㄧず浠诲姟宸叉彁浜ゅ埌鍚庡彴鎵ц
+//    }
+
+
     @Override
     public Integer selectPatMedInhospList(PatMedInhosp patMedInhosp) {
-        Long count = hnGatherPatArchiveMapper.selectPatMedInhospListCount(null);
-        Long aa = (count + 1000 - 1) / 1000;
-        //杩涜鍒嗛〉鏌ヨ
-        for (int i = 0; i <= aa; i++) {
-            patMedInhosp.setPs(1000);
-            patMedInhosp.setPn(1000 * i);
-            List<PatMedInhosp> patMedInhospList = hnGatherPatArchiveMapper.selectPatMedInhospList(patMedInhosp);
-            if (patMedInhospList != null && !patMedInhospList.isEmpty()) {
-                patMedInhospMapper.insertPatMedInhospBatch(patMedInhospList);
+        List<PatMedInhosp> patMedInhospList = hnGatherPatArchiveMapper.selectPatMedInhospList(patMedInhosp);
+        for (PatMedInhosp pm : patMedInhospList) {
+            PatArchive patArchive = new PatArchive();
+            patArchive.setPatientno(pm.getPatno());
+            List<PatArchive> patArchives = hnGatherPatArchiveMapper.selectPatArchiveList(patArchive);
+            if (CollectionUtils.isEmpty(patArchives)) {
+                //绌轰簡鐩存帴涓㈡帀
+                continue;
             }
+            PatArchive pa = new PatArchive();
+            pa.setPatientno(patArchives.get(0).getPatientno());
+            List<PatArchive> patArchives1 = patArchiveMapper.selectPatArchiveList(pa);
+            if (CollectionUtils.isNotEmpty(patArchives1)) {
+                pm.setPatid(patArchives1.get(0).getId());
+            } else {
+                patArchiveMapper.insertPatArchiveSingle(patArchives.get(0));
+                pm.setPatid(patArchives.get(0).getId());
+            }
+            patMedInhospMapper.insertPatMedInhosp(pm);
         }
-
-        return null;
+        return 0;
     }
+
 
     @Override
     public Integer selectPatMedOuthospList(PatMedOuthosp patMedOuthosp) {
         List<PatMedOuthosp> patMedOuthosps = hnGatherPatArchiveMapper.selectPatMedOuthospList(patMedOuthosp);
         log.info("selectPatMedOuthospList鐨勯噰闆嗗埌鐨勬暟閲忎负锛歿}", patMedOuthosps.size());
-        int i = patMedOuthospMapper.batchPatMedOuthosp(patMedOuthosps);
+        Integer i = null;
+        for (PatMedOuthosp patMedOuthosp1 : patMedOuthosps) {
+            //鑾峰彇鎮h�呭熀鏈俊鎭�
+            PatArchive patArchive = new PatArchive();
+            patArchive.setPatientno(patMedOuthosp1.getPatno());
+            List<PatArchive> patArchives = hnGatherPatArchiveMapper.selectPatArchiveList(patArchive);
+
+            //鏍规嵁patno鍒ゆ柇鏈湴鎮h�呭熀鏈俊鎭槸鍚﹀瓨鍦�
+            PatArchive pa = new PatArchive();
+            pa.setPatientno(patMedOuthosp1.getPatno());
+            List<PatArchive> patArchives1 = patArchiveMapper.selectPatArchiveList(pa);
+            if (CollectionUtils.isNotEmpty(patArchives1)) {
+                patMedOuthosp1.setPatid(patArchives1.get(0).getId());
+            } else {
+                if (CollectionUtils.isEmpty(patArchives)) {
+                    continue;
+                }
+                patArchiveMapper.insertPatArchiveSingle(patArchives.get(0));
+                patMedOuthosp1.setPatid(patArchives.get(0).getId());
+            }
+            i = patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp1);
+        }
 
         return i;
     }
@@ -107,6 +150,33 @@
         List<SysUser> sysUserList = hnGatherPatArchiveMapper.selectUserList(sysUser);
         log.info("sysUserList鐨勯噰闆嗗埌鐨勬暟閲忎负锛歿}", sysUserList.size());
         int i = sysUser2Mapper.batchUser(sysUserList);
+        for (SysUser sysUser1 : sysUserList) {
+            log.info("sysUser1鐨処D涓猴細{}", sysUser1.getUserId());
+            log.info("sysUser1鐨凥ISUSERID涓猴細{}", sysUser1.getHisUserId());
+            //鏂板鐢ㄦ埛涓庤鑹�
+            SysUserRole yhyjsxx = hnGatherPatArchiveMapper.yhyjsxx(sysUser1);
+            if (yhyjsxx == null) continue;
+            yhyjsxx.setUserId(sysUser1.getUserId());
+            List<SysUserRole> userRoleList = new ArrayList<>();
+            userRoleList.add(yhyjsxx);
+            sysUserRoleMapper.batchUserRole(userRoleList);
+
+            //鏂板鐢ㄦ埛涓庨儴闂�
+            if (StringUtils.isEmpty(sysUser1.getHisUserId())) continue;
+            SysUserDept sysUserDept = hnGatherPatArchiveMapper.yhyksxx(sysUser1);
+            if (Objects.isNull(sysUserDept) || sysUserDept.getDeptId() == null) continue;
+            SysDept dept = new SysDept();
+            dept.setHisDeptId(sysUserDept.getDeptId().toString());
+            List<SysDept> sysDepts = sysDept2Mapper.selectDeptList(dept);
+            if (CollectionUtils.isNotEmpty(sysDepts)) {
+                sysUserDept.setDeptId(sysDepts.get(0).getDeptId());
+                sysUserDept.setDeptCode(sysDepts.get(0).getDeptCode());
+            }
+            sysUserDept.setUserId(sysUser1.getUserId());
+            sysUserDeptMapper.insertSysUserDept(sysUserDept);
+
+        }
+
         return i;
     }
 
@@ -117,5 +187,35 @@
         int i = sysDept2Mapper.batchDept(sysDepts);
         return i;
     }
+
+
+    /**
+     * 妫�鏌ュ苟鎵ц鍒嗚〃鐨勬牳蹇冩柟娉�
+     *
+     * @param tableName 瑕佹鏌ョ殑琛ㄥ悕
+     */
+    private synchronized void checkAndShard(String tableName) {
+        long currentCount = shardingMapper.getTableCount(tableName);
+
+        if (currentCount >= SHARDING_THRESHOLD) {
+            log.warn("琛� '{}' 宸茶揪鍒板垎琛ㄩ槇鍊� {}锛屽噯澶囨墽琛屽垎琛ㄦ搷浣�...", tableName, SHARDING_THRESHOLD);
+
+            String newTableName = tableName + "_" + java.time.LocalDate.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyy_MM"));
+            Long maxId = shardingMapper.getMaxId(tableName);
+            if (maxId == null) maxId = 0L;
+
+            shardingMapper.renameTable(tableName, newTableName);
+            log.info("宸插皢琛� '{}' 閲嶅懡鍚嶄负 '{}'", tableName, newTableName);
+
+            shardingMapper.createLikeTable(tableName, newTableName);
+            log.info("宸插垱寤烘柊琛� '{}'", tableName);
+
+            shardingMapper.setAutoIncrement(tableName, maxId + 1);
+            log.info("宸茶缃柊琛� '{}' 鐨勮嚜澧濱D璧峰鍊间负 {}", tableName, maxId + 1);
+
+            log.info("琛� '{}' 鐨勫垎琛ㄦ搷浣滃畬鎴愶紒", tableName);
+        }
+    }
 }
 
+

--
Gitblit v1.9.3