From 7eb4c98f4d96bebf28685d801e7b978d6c3d251e Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期四, 24 七月 2025 22:23:40 +0800
Subject: [PATCH] 代码提交

---
 smartor/src/main/java/com/smartor/mapper/HNGatherPatArchiveMapper.java                       |   24 ++
 smartor/src/main/resources/mapper/smartor/HNGatherPatArchiveMapper.xml                       |  123 +++++++----
 ruoyi-admin/src/main/resources/application-hn.yml                                            |    4 
 smartor/src/main/resources/mapper/smartor/ShardingMapper.xml                                 |   31 ++
 smartor/src/main/java/com/smartor/mapper/PatArchiveMapper.java                               |    3 
 smartor/src/main/java/com/smartor/mapper/SysUserRole2Mapper.java                             |   65 +++++
 ruoyi-admin/src/main/resources/application.yml                                               |    2 
 smartor/src/main/java/com/smartor/domain/PatMedOuthosp.java                                  |   14 -
 smartor/src/main/resources/mapper/smartor/PatArchiveMapper.xml                               |   11 
 smartor/src/main/resources/mapper/smartor/PatMedInhospMapper.xml                             |    2 
 smartor/src/main/java/com/smartor/mapper/ShardingMapper.java                                 |   30 ++
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/HNGatherPatArchiveController.java |   38 ++
 ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java               |    1 
 smartor/src/main/java/com/smartor/service/impl/HNGatherPatArchiveServiceImpl.java            |  188 +++++++++++-----
 ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/HospitalFilterInterceptor.java |   22 +
 smartor/src/main/resources/mapper/smartor/SysUserMapper.xml                                  |    2 
 smartor/src/main/resources/mapper/smartor/SysUserRole2Mapper.xml                             |   53 ++++
 17 files changed, 480 insertions(+), 133 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/HNGatherPatArchiveController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/HNGatherPatArchiveController.java
index 6b3a9ed..da5b443 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/HNGatherPatArchiveController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/HNGatherPatArchiveController.java
@@ -24,7 +24,13 @@
 
 import javax.servlet.http.HttpServletResponse;
 import java.lang.reflect.Array;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.Date;
 import java.util.List;
+
+import static com.ruoyi.framework.datasource.DynamicDataSourceContextHolder.log;
 
 /**
  * 娌冲崡閲囬泦鎮h�呬俊鎭帴鍙ontroller
@@ -45,12 +51,32 @@
     //@PreAuthorize("@ss.hasPermi('smartor:patouthosp:list')")
     @PostMapping("/selectGatherList")
     @ApiOperation("娌冲崡鏁版嵁閲囬泦")
-    public Integer selectUserList(@RequestBody SysUser sysUser) {
-//        Integer integer = ihnGatherPatArchiveService.selectUserList(null);
-//        Integer deptInt = ihnGatherPatArchiveService.selectDeptList(null);
-//        Integer icdInt = ihnGatherPatArchiveService.selectIcd10List(null);
-        Integer integer = ihnGatherPatArchiveService.selectPatMedInhospList(new PatMedInhosp());
-        return integer;
+    public Integer selectUserList(@RequestBody PatMedInhosp patMedInhosp) {
+//        Integer sd = ihnGatherPatArchiveService.selectDeptList(null);
+//        Integer su = ihnGatherPatArchiveService.selectUserList(null);
+//        Integer icd = ihnGatherPatArchiveService.selectIcd10List(null);
+
+        log.info("寮�濮嬫寜澶╁悓姝ョ敤鎴锋暟鎹紝鏃堕棿鑼冨洿: {} 鍒� {}", patMedInhosp.getStartOutHospTime(), patMedInhosp.getEndOutHospTime());
+
+        LocalDate startDate = patMedInhosp.getStartOutHospTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+        LocalDate endDate = patMedInhosp.getEndOutHospTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+
+        Integer po = null;
+        // 寰幆澶勭悊姣忎竴澶�
+        for (LocalDate currentDate = startDate; !currentDate.isAfter(endDate); currentDate = currentDate.plusDays(1)) {
+            PatMedInhosp dailyCondition = new PatMedInhosp();
+            LocalDateTime dayStart = currentDate.atStartOfDay();
+            LocalDateTime dayEnd = currentDate.atTime(23, 59, 59);
+            dailyCondition.setStartOutHospTime(Date.from(dayStart.atZone(ZoneId.systemDefault()).toInstant()));
+            dailyCondition.setEndOutHospTime(Date.from(dayEnd.atZone(ZoneId.systemDefault()).toInstant()));
+            Integer pi = ihnGatherPatArchiveService.selectPatMedInhospList(dailyCondition);
+
+            PatMedOuthosp patMedOuthosp = new PatMedOuthosp();
+            patMedOuthosp.setBeginTime(Date.from(dayStart.atZone(ZoneId.systemDefault()).toInstant()));
+            patMedOuthosp.setEndTime(Date.from(dayEnd.atZone(ZoneId.systemDefault()).toInstant()));
+            po = ihnGatherPatArchiveService.selectPatMedOuthospList(patMedOuthosp);
+        }
+        return po;
     }
 
 }
diff --git a/ruoyi-admin/src/main/resources/application-hn.yml b/ruoyi-admin/src/main/resources/application-hn.yml
index 3610632..2bba942 100644
--- a/ruoyi-admin/src/main/resources/application-hn.yml
+++ b/ruoyi-admin/src/main/resources/application-hn.yml
@@ -17,7 +17,7 @@
       slave:
         # 浠庢暟鎹簮寮�鍏�/榛樿鍏抽棴(鍏徃)
         enabled: true
-        url: jdbc:postgresql://10.10.13.108:5432/hdr
+        url: jdbc:postgresql://10.10.13.108:5432/hdr?socketTimeout=300000
         username: mbsjjk
         password: sjjk@2025
         driver-class-name: org.postgresql.Driver
@@ -47,7 +47,7 @@
       #      validationQuery: SELECT 1 FROM DUAL
       validationQuery: SELECT 1
       testWhileIdle: true
-      testOnBorrow: false
+      testOnBorrow: true
       testOnReturn: false
       webStatFilter:
         enabled: true
diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml
index 04e1cc9..e942c14 100644
--- a/ruoyi-admin/src/main/resources/application.yml
+++ b/ruoyi-admin/src/main/resources/application.yml
@@ -74,7 +74,7 @@
     # 鍥介檯鍖栬祫婧愭枃浠惰矾寰�
     basename: i18n/messages
   profiles:
-    active: druid
+    active: hn
   # 鏂囦欢涓婁紶
   servlet:
     multipart:
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java
index 7840141..36695a2 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java
@@ -5,6 +5,7 @@
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.ThreadPoolExecutor;
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/HospitalFilterInterceptor.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/HospitalFilterInterceptor.java
index cc3dbe2..a80f3bd 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/HospitalFilterInterceptor.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/HospitalFilterInterceptor.java
@@ -67,11 +67,29 @@
      * 淇敼 SQL锛屾敞鍏� orgid 鏉′欢
      *
      * @param originalSql 鍘熷 SQL
-     * @param orgId       褰撳墠鍖婚櫌 ID
+     * @param orgid       褰撳墠鍖婚櫌 ID
      * @return 淇敼鍚庣殑 SQL
      */
     private String modifySqlWithOrgId(String originalSql, String orgid) {
-        if (originalSql.contains("insert into") || originalSql.contains("INSERT INTO") || originalSql.contains("from sys_menu") || originalSql.contains("sys_job") || originalSql.contains("update sys_menu") || originalSql.contains("information_schema.tables") || originalSql.contains("information_schema.columns") || originalSql.contains("gen_table") || originalSql.toUpperCase().contains("ORGID IS NULL") || originalSql.toUpperCase().contains("FROM CRYXX") || originalSql.toUpperCase().contains("FROM MZXX") || originalSql.toUpperCase().contains("FROM JBXX") || originalSql.toUpperCase().contains("FROM BMXX")) {
+        if (originalSql.contains("insert into")
+                || originalSql.contains("INSERT INTO")
+                || originalSql.contains("from sys_menu")
+                || originalSql.contains("sys_job")
+                || originalSql.contains("update sys_menu")
+                || originalSql.contains("information_schema.tables")
+                || originalSql.contains("information_schema.columns")
+                || originalSql.contains("gen_table")
+                || originalSql.toUpperCase().contains("ORGID IS NULL")
+                || originalSql.toUpperCase().contains("FROM CRYXX")
+                || originalSql.toUpperCase().contains("FROM MZXX")
+                || originalSql.toUpperCase().contains("FROM JBXX")
+                || originalSql.toUpperCase().contains("FROM BMXX")
+                || originalSql.toUpperCase().contains("FROM HZJBXX")
+                || originalSql.toUpperCase().contains("RENAME TABLE")
+                || originalSql.toUpperCase().contains("FROM YHYKSXX")
+                || originalSql.toUpperCase().contains("FROM YHYJSXX")
+                || originalSql.toUpperCase().contains("ALTER TABLE")
+                || originalSql.toUpperCase().contains("CREATE TABLE")) {
             return originalSql;
         }
         // 鎻愬彇 orgid 鐨� WHERE 瀛愬彞
diff --git a/smartor/src/main/java/com/smartor/domain/PatMedOuthosp.java b/smartor/src/main/java/com/smartor/domain/PatMedOuthosp.java
index ba5e435..be557d9 100644
--- a/smartor/src/main/java/com/smartor/domain/PatMedOuthosp.java
+++ b/smartor/src/main/java/com/smartor/domain/PatMedOuthosp.java
@@ -220,18 +220,4 @@
     private String idcardno;
 
 
-    /**
-     * 灏辫瘖寮�濮嬫椂闂�
-     */
-    @ApiModelProperty(value = "灏辫瘖寮�濮嬫椂闂�")
-    @JsonFormat(pattern = "yyyy-MM-dd")
-    private Date starttime;
-
-    /**
-     * 灏辫瘖缁撴潫鏃堕棿
-     */
-    @ApiModelProperty(value = "灏辫瘖缁撴潫鏃堕棿")
-    @JsonFormat(pattern = "yyyy-MM-dd")
-    private Date endtime;
-
 }
diff --git a/smartor/src/main/java/com/smartor/mapper/HNGatherPatArchiveMapper.java b/smartor/src/main/java/com/smartor/mapper/HNGatherPatArchiveMapper.java
index 064c568..db9557a 100644
--- a/smartor/src/main/java/com/smartor/mapper/HNGatherPatArchiveMapper.java
+++ b/smartor/src/main/java/com/smartor/mapper/HNGatherPatArchiveMapper.java
@@ -3,9 +3,12 @@
 import com.ruoyi.common.annotation.DataSource;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.domain.entity.SysUserDept;
+import com.ruoyi.common.core.domain.entity.SysUserRole;
 import com.ruoyi.common.enums.DataSourceType;
 import com.smartor.domain.*;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -28,6 +31,22 @@
     public List<PatArchive> selectPatArchiveList(PatArchive patArchive);
 
     /**
+     * 鐢ㄦ埛涓庤鑹蹭俊鎭�
+     *
+     * @param sysUser
+     * @return
+     */
+    public SysUserRole yhyjsxx(SysUser sysUser);
+
+    /**
+     * 鐢ㄦ埛涓庣瀹や俊鎭�
+     *
+     * @param sysUser
+     * @return
+     */
+    public SysUserDept yhyksxx(SysUser sysUser);
+
+    /**
      * 鍑哄叆闄俊鎭�
      *
      * @param patMedInhosp
@@ -36,6 +55,11 @@
     public List<PatMedInhosp> selectPatMedInhospList(PatMedInhosp patMedInhosp);
 
     public Long selectPatMedInhospListCount(PatMedInhosp patMedInhosp);
+
+    List<PatArchive> selectPatArchiveListByLastId(@Param("lastRowNumber") long lastRowNumber, @Param("ps") int ps);
+
+    List<PatMedInhosp> selectPatMedInhospListByLastId(@Param("lastRowNumber") long lastRowNumber, @Param("ps") int ps);
+
     public Long selectPatArchiveCount(PatMedInhosp patMedInhosp);
 
     /**
diff --git a/smartor/src/main/java/com/smartor/mapper/PatArchiveMapper.java b/smartor/src/main/java/com/smartor/mapper/PatArchiveMapper.java
index 0fe819f..294b5a3 100644
--- a/smartor/src/main/java/com/smartor/mapper/PatArchiveMapper.java
+++ b/smartor/src/main/java/com/smartor/mapper/PatArchiveMapper.java
@@ -4,6 +4,7 @@
 import com.smartor.domain.PatArchiveOthreInfo;
 import com.smartor.domain.PatArchiveReq;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -23,6 +24,8 @@
      */
     public PatArchive selectPatArchiveByPatid(Long patid);
 
+    List<PatArchive> selectPatArchiveByPatnos(@Param("patnos") List<String> patnos);
+
     /**
      * 鏌ヨ鎮h�呮。妗堝垪琛�
      *
diff --git a/smartor/src/main/java/com/smartor/mapper/ShardingMapper.java b/smartor/src/main/java/com/smartor/mapper/ShardingMapper.java
new file mode 100644
index 0000000..f919cb0
--- /dev/null
+++ b/smartor/src/main/java/com/smartor/mapper/ShardingMapper.java
@@ -0,0 +1,30 @@
+package com.smartor.mapper;
+
+import com.smartor.domain.PatArchive;
+import com.smartor.domain.PatArchiveOthreInfo;
+import com.smartor.domain.PatArchiveReq;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 鎮h�呮。妗圡apper鎺ュ彛
+ *
+ * @author smartor
+ * @date 2023-03-04
+ */
+@Mapper
+public interface ShardingMapper {
+    long getTableCount(@Param("tableName") String tableName);
+
+    Long getMaxId(@Param("tableName") String tableName);
+
+    void renameTable(@Param("oldName") String oldName, @Param("newName") String newName);
+
+    void createLikeTable(@Param("newTableName") String newTableName, @Param("templateTableName") String templateTableName);
+
+    void setAutoIncrement(@Param("tableName") String tableName, @Param("value") long value);
+
+
+}
diff --git a/smartor/src/main/java/com/smartor/mapper/SysUserRole2Mapper.java b/smartor/src/main/java/com/smartor/mapper/SysUserRole2Mapper.java
new file mode 100644
index 0000000..faf1a55
--- /dev/null
+++ b/smartor/src/main/java/com/smartor/mapper/SysUserRole2Mapper.java
@@ -0,0 +1,65 @@
+package com.smartor.mapper;
+
+import com.ruoyi.common.core.domain.entity.SysUserRole;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 鐢ㄦ埛涓庤鑹插叧鑱旇〃 鏁版嵁灞�
+ *
+ * @author ruoyi
+ */
+@Mapper
+public interface SysUserRole2Mapper
+{
+    /**
+     * 閫氳繃鐢ㄦ埛ID鍒犻櫎鐢ㄦ埛鍜岃鑹插叧鑱�
+     *
+     * @param userId 鐢ㄦ埛ID
+     * @return 缁撴灉
+     */
+    public int deleteUserRoleByUserId(Long userId);
+
+    /**
+     * 鎵归噺鍒犻櫎鐢ㄦ埛鍜岃鑹插叧鑱�
+     *
+     * @param ids 闇�瑕佸垹闄ょ殑鏁版嵁ID
+     * @return 缁撴灉
+     */
+    public int deleteUserRole(Long[] ids);
+
+    /**
+     * 閫氳繃瑙掕壊ID鏌ヨ瑙掕壊浣跨敤鏁伴噺
+     *
+     * @param roleId 瑙掕壊ID
+     * @return 缁撴灉
+     */
+    public int countUserRoleByRoleId(Long roleId);
+
+    /**
+     * 鎵归噺鏂板鐢ㄦ埛瑙掕壊淇℃伅
+     *
+     * @param userRoleList 鐢ㄦ埛瑙掕壊鍒楄〃
+     * @return 缁撴灉
+     */
+    public int batchUserRole(List<SysUserRole> userRoleList);
+
+    /**
+     * 鍒犻櫎鐢ㄦ埛鍜岃鑹插叧鑱斾俊鎭�
+     *
+     * @param userRole 鐢ㄦ埛鍜岃鑹插叧鑱斾俊鎭�
+     * @return 缁撴灉
+     */
+    public int deleteUserRoleInfo(SysUserRole userRole);
+
+    /**
+     * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛瑙掕壊
+     *
+     * @param roleId 瑙掕壊ID
+     * @param userIds 闇�瑕佸垹闄ょ殑鐢ㄦ埛鏁版嵁ID
+     * @return 缁撴灉
+     */
+    public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
+}
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 06e766b..2b4c671 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;
@@ -65,62 +52,84 @@
     @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 patArchiveCount = hnGatherPatArchiveMapper.selectPatArchiveCount(null);
-        Long patOffst = (patArchiveCount + 1000 - 1) / 1000;
-        PatArchive patArchive = new PatArchive();
-        Long patSize = 0L;
-        for (int i = 0; i <= patOffst; i++) {
-            patArchive.setPs(1000);
-            patArchive.setPn(1000 * i);
+        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 (patArchives != null && !patArchives.isEmpty()) {
-                patArchiveMapper.insertPatArchive(patArchives);
+            if (CollectionUtils.isEmpty(patArchives)) {
+                //绌轰簡鐩存帴涓㈡帀
+                continue;
             }
-            patSize = patSize + patArchives.size();
+            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);
         }
-        log.info("patArchives澶勭悊缁撴潫涓�鍏�:{}", patSize);
-
-
-        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);
-            for (PatMedInhosp pm : patMedInhospList) {
-                String patno = pm.getPatno();
-                PatArchive pa = new PatArchive();
-                //鍏堝幓鎴戜滑鑷繁鐨勮〃閲岄�氳繃patno鏌ヨ璇ユ偅鑰呮槸鍚﹀瓨鍦�
-                pa.setPatientno(patno);
-                List<PatArchive> patArchives = patArchiveMapper.selectPatArchiveList(pa);
-                if (CollectionUtils.isEmpty(patArchives)) {
-                    continue;
-                } else {
-                    //鐩存帴灏唒atid鏀惧埌鍑哄叆闄㈣〃涓�
-                    pm.setPatid(patArchives.get(0).getId());
-                }
-            }
-            if (patMedInhospList != null && !patMedInhospList.isEmpty()) {
-                patMedInhospMapper.insertPatMedInhospBatch(patMedInhospList);
-            }
-        }
-        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 {
+                patArchiveMapper.insertPatArchiveSingle(patArchives.get(0));
+                patMedOuthosp1.setPatid(patArchives.get(0).getId());
+            }
+            i = patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp1);
+        }
 
         return i;
     }
@@ -138,6 +147,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;
     }
 
@@ -148,5 +184,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);
+        }
+    }
 }
 
+
diff --git a/smartor/src/main/resources/mapper/smartor/HNGatherPatArchiveMapper.xml b/smartor/src/main/resources/mapper/smartor/HNGatherPatArchiveMapper.xml
index 5592a9f..ac28143 100644
--- a/smartor/src/main/resources/mapper/smartor/HNGatherPatArchiveMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/HNGatherPatArchiveMapper.xml
@@ -4,6 +4,28 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.smartor.mapper.HNGatherPatArchiveMapper">
 
+
+    <resultMap type="com.ruoyi.common.core.domain.entity.SysUserDept" id="SysUserDeptResult">
+        <result property="id" column="id"/>
+        <result property="orgid" column="orgid"/>
+        <result property="userId" column="user_id"/>
+        <result property="deptId" column="dept_id"/>
+        <result property="delFlag" column="del_flag"/>
+        <result property="deptCode" column="dept_code"/>
+        <result property="deptName" column="dept_name"/>
+        <result property="deptType" column="dept_type"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateTime" column="update_time"/>
+    </resultMap>
+
+
+    <resultMap type="com.ruoyi.common.core.domain.entity.SysUserRole" id="SysUserRoleResult">
+        <result property="userId" column="user_id"/>
+        <result property="roleId" column="role_id"/>
+        <result property="orgid" column="orgid"/>
+    </resultMap>
+
+
     <resultMap type="com.smartor.domain.PatArchive" id="PatArchiveResult">
         <result property="id" column="id"/>
         <result property="patientno" column="patientno"/>
@@ -307,22 +329,16 @@
     </resultMap>
 
     <sql id="selectPatArchiveVo">
-        select id,
-               notrequired_flag,
+        select notrequired_flag,
                notrequiredreason,
                patientno,
-               filter_drname,
-               filter_drcode,
                patid_his,
-               age_unit,
-               age_unit2,
                sd_flag,
                name,
                sex,
                idcardno,
                birthdate,
                age,
-               age2,
                nation,
                native_place,
                place_of_residence,
@@ -335,15 +351,7 @@
                idcardtype,
                orgid,
                openid,
-               del_flag,
-               update_by,
-               update_time,
-               create_by,
-               create_time,
-               isupload,
-               pattype,
                viptype,
-               upload_time,
                care_facilities,
                case_path,
                degree_of_education,
@@ -351,10 +359,29 @@
                income,
                medicare_type,
                care_person,
-               guid,
                case_person_age
         from hzjbxx
     </sql>
+
+
+    <select id="yhyjsxx" parameterType="com.ruoyi.common.core.domain.entity.SysUser" resultMap="SysUserRoleResult">
+        select user_id, role_id, orgid
+        FROM yhyjsxx
+        <where>
+            <if test="hisUserId != null ">and user_id = #{hisUserId}</if>
+        </where>
+    </select>
+
+    <select id="yhyksxx" parameterType="com.ruoyi.common.core.domain.entity.SysUser" resultMap="SysUserDeptResult">
+        select user_id, user_code, dept_type,department_id as
+        dept_id,dept_name,deptparent,del_flag,orgid,create_time,create_by,update_time,update_by
+        FROM yhyksxx
+        <where>
+            user_id != 'admin'
+            <if test="hisUserId != null ">and user_id = #{hisUserId}</if>
+        </where>
+    </select>
+
 
     <select id="selectPatArchiveList" parameterType="com.smartor.domain.PatArchive" resultMap="PatArchiveResult">
         <include refid="selectPatArchiveVo"/>
@@ -369,7 +396,7 @@
             <if test="uploadTime != null ">and upload_time = #{uploadTime}</if>
             <if test="viptype != null ">and viptype = #{viptype}</if>
             <if test="pattype != null ">and pattype = #{pattype}</if>
-            <if test="patientno != null ">and patientno = #{patientno}</if>
+            <if test="patientno != null ">and patientno = CAST(#{patientno} AS INTEGER)</if>
             <if test="patidHis != null ">and patid_his = #{patidHis}</if>
             <if test="sdFlag != null ">and sd_flag = #{sdFlag}</if>
             <if test="ageUnit != null ">and age_unit = #{ageUnit}</if>
@@ -389,7 +416,6 @@
             <if test="filterDrname != null ">and filter_drname = #{filterDrname}</if>
             <if test="filterDrcode != null ">and filter_drcode = #{filterDrcode}</if>
         </where>
-        limit #{ps} OFFSET #{pn}
     </select>
 
 
@@ -397,6 +423,26 @@
         select count(*)
         FROM cryxx
     </select>
+
+    <select id="selectPatArchiveListByLastId" resultMap="PatArchiveResult">
+        SELECT *
+        FROM (
+                 SELECT *,
+                        ROW_NUMBER() OVER (ORDER BY patid_his) as row_num
+                 FROM hzjbxx
+             ) a
+        WHERE row_num > #{lastRowNumber} LIMIT #{ps}
+    </select>
+
+    <select id="selectPatMedInhospListByLastId" resultMap="PatMedInhospResult">
+        SELECT *
+        FROM (SELECT *,
+                     ROW_NUMBER() OVER (ORDER BY patno) as row_num
+              FROM cryxx
+             ) a
+        WHERE row_num > #{lastRowNumber} LIMIT #{ps}
+    </select>
+
     <select id="selectPatArchiveCount" parameterType="com.smartor.domain.PatMedInhosp" resultType="Long">
         select count(*)
         FROM hzjbxx
@@ -449,17 +495,18 @@
         FROM
         cryxx b
         <where>
-            <if test="startOutHospTime != null ">and date_format(b.endtime,'%y%m%d') &gt;=
-                date_format(#{startOutHospTime},'%y%m%d')
+
+            <if test="startOutHospTime != null ">and to_char(b.endtime,'YYMMDD') &gt;=
+                to_char(#{startOutHospTime}::date,'YYMMDD')
             </if>
-            <if test="endOutHospTime != null ">and date_format(b.endtime,'%y%m%d') &lt;=
-                date_format(#{endOutHospTime},'%y%m%d')
+            <if test="endOutHospTime != null ">and to_char(b.endtime,'YYMMDD') &lt;=
+                to_char(#{endOutHospTime}::date,'YYMMDD')
             </if>
-            <if test="startInHospTime != null ">and date_format(b.starttime,'%y%m%d') &gt;=
-                date_format(#{startInHospTime},'%y%m%d')
+            <if test="startInHospTime != null ">and to_char(b.starttime,'YYMMDD') &gt;=
+                to_char(#{startInHospTime}::date,'%y%m%d')
             </if>
-            <if test="endInHospTime != null ">and date_format(b.starttime,'%y%m%d') &lt;=
-                date_format(#{endInHospTime},'%y%m%d')
+            <if test="endInHospTime != null ">and to_char(b.starttime,'YYMMDD') &lt;=
+                to_char(#{endInHospTime}::date,'YYMMDD')
             </if>
             <if test="inhospno != null ">and b.inhospno = #{inhospno}</if>
             <if test="fuflag != null ">and b.fuflag = #{fuflag}</if>
@@ -472,7 +519,6 @@
             <if test="outWayName != null ">and b.out_way_name = #{outWayName}</if>
             <if test="orgid != null ">and b.orgid = #{orgid}</if>
         </where>
-        limit #{ps} OFFSET #{pn}
     </select>
 
 
@@ -507,19 +553,14 @@
         mainsuit
         from mzxx
         <where>
-            <if test="deptname != null  and deptname != ''">and deptname like concat('%', #{deptname}, '%')</if>
-            <if test="drname != null  and drname != ''">and drname like concat('%', #{drname}, '%')</if>
-            <if test="patname != null  and patname != ''">and patname like concat('%', #{patname}, '%')</if>
-            <if test="beginTime != null ">and date_format( admitdate,'%y%m%d') &gt;=
-                date_format(#{beginTime},'%y%m%d')
+
+            <if test="beginTime != null ">and to_char( admitdate,'YYMMDD') &gt;=
+                to_char(#{beginTime}::date,'YYMMDD')
             </if>
-            <if test="endTime != null ">and date_format( admitdate,'%y%m%d') &lt;=
-                date_format(#{endTime},'%y%m%d')
+            <if test="endTime != null ">and to_char( admitdate,'YYMMDD') &lt;=
+                to_char(#{endTime}::date,'YYMMDD')
             </if>
-            <if test="patid != null ">and patid = #{patid}</if>
-            <if test="patno != null ">and patno = #{patno}</if>
-            <if test="outhospno != null  and outhospno != ''">and outhospno = #{outhospno}</if>
-            <if test="diagcheckFlag != null  and diagcheckFlag != ''">and diagcheck_flag = #{diagcheckFlag}</if>
+
         </where>
     </select>
 
@@ -585,12 +626,6 @@
             </if>
             <if test="phonenumber != null and phonenumber != ''">
                 AND u.phonenumber like concat('%', #{phonenumber}, '%')
-            </if>
-            <if test="params.beginTime != null and params.beginTime != ''"><!-- 寮�濮嬫椂闂存绱� -->
-                AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
-            </if>
-            <if test="params.endTime != null and params.endTime != ''"><!-- 缁撴潫鏃堕棿妫�绱� -->
-                AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
             </if>
         </where>
     </select>
diff --git a/smartor/src/main/resources/mapper/smartor/PatArchiveMapper.xml b/smartor/src/main/resources/mapper/smartor/PatArchiveMapper.xml
index d26ad2d..1ea6f47 100644
--- a/smartor/src/main/resources/mapper/smartor/PatArchiveMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/PatArchiveMapper.xml
@@ -266,6 +266,15 @@
         where id = #{id} and del_flag=0
     </select>
 
+    <select id="selectPatArchiveByPatnos" resultMap="PatArchiveResult">
+        SELECT id, patientno
+        FROM pat_archive
+        WHERE patientno IN
+        <foreach item="patno" collection="patnos" open="(" separator="," close=")">
+            #{patno}
+        </foreach>
+    </select>
+
     <insert id="insertPatArchiveSingle" parameterType="com.smartor.domain.PatArchive" useGeneratedKeys="true"
             keyProperty="id">
         insert into pat_archive
@@ -369,7 +378,7 @@
         </trim>
     </insert>
 
-    <insert id="insertPatArchive">
+    <insert id="insertPatArchive" useGeneratedKeys="true" keyProperty="id">
         insert into
         pat_archive(name,viptype,sex,idcardno,birthdate,place_of_residence,age,age2,sourcefrom,archivetime,archiveby,telcode,relativetelcode,idcardtype,orgid,openid,dduserid,update_by,update_time
         ,create_by,create_time,isupload,upload_time,pattype,nation,birthplace,native_place,patientno,patid_his,sd_flag,age_unit,age_unit2,notrequired_flag,notrequiredreason,care_facilities,case_path,
diff --git a/smartor/src/main/resources/mapper/smartor/PatMedInhospMapper.xml b/smartor/src/main/resources/mapper/smartor/PatMedInhospMapper.xml
index 28364e0..1e6df5d 100644
--- a/smartor/src/main/resources/mapper/smartor/PatMedInhospMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/PatMedInhospMapper.xml
@@ -558,7 +558,7 @@
     </insert>
 
 
-    <insert id="insertPatMedInhospBatch" parameterType="java.util.List">
+    <insert id="insertPatMedInhospBatch" parameterType="java.util.List"  useGeneratedKeys="true" keyProperty="item.inhospid">
         insert into pat_med_inhosp (
         serialnum, hospitalname, hospitalcode, hospitaldistrictcode, hospitaldistrictname,
         icd10code, diagname, starttime, endtime, deptcode, deptname, roomno, bed_no,
diff --git a/smartor/src/main/resources/mapper/smartor/ShardingMapper.xml b/smartor/src/main/resources/mapper/smartor/ShardingMapper.xml
new file mode 100644
index 0000000..3bba44f
--- /dev/null
+++ b/smartor/src/main/resources/mapper/smartor/ShardingMapper.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.smartor.mapper.ShardingMapper">
+    <select id="getTableCount" resultType="long">
+        SELECT count(*)
+        FROM ${tableName}
+    </select>
+
+    <select id="getMaxId" resultType="long">
+        SELECT max(id)
+        FROM ${tableName}
+    </select>
+
+    <update id="renameTable">
+        RENAME
+        TABLE
+        ${oldName}
+        TO
+        ${newName}
+    </update>
+
+    <update id="createLikeTable">
+        CREATE TABLE ${newTableName} LIKE ${templateTableName}
+    </update>
+
+    <update id="setAutoIncrement">
+        ALTER TABLE ${tableName} AUTO_INCREMENT = #{value}
+    </update>
+</mapper>
diff --git a/smartor/src/main/resources/mapper/smartor/SysUserMapper.xml b/smartor/src/main/resources/mapper/smartor/SysUserMapper.xml
index 515c620..a5369ee 100644
--- a/smartor/src/main/resources/mapper/smartor/SysUserMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/SysUserMapper.xml
@@ -310,7 +310,7 @@
     </insert>
 
 
-    <insert id="batchUser">
+    <insert id="batchUser" useGeneratedKeys="true" keyProperty="userId">
         insert into sys_user(
         user_id, dept_id, user_name, nick_name, email, avatar, phonenumber, sex, password, status, create_by, remark,
         user_type, dept_info, hosp_info, searchscope, id_card, title, job_phone, birthday, his_user_id, guid, orgid,
diff --git a/smartor/src/main/resources/mapper/smartor/SysUserRole2Mapper.xml b/smartor/src/main/resources/mapper/smartor/SysUserRole2Mapper.xml
new file mode 100644
index 0000000..f77a682
--- /dev/null
+++ b/smartor/src/main/resources/mapper/smartor/SysUserRole2Mapper.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.smartor.mapper.SysUserRole2Mapper">
+
+    <resultMap type="SysUserRole" id="SysUserRoleResult">
+        <result property="userId" column="user_id"/>
+        <result property="roleId" column="role_id"/>
+        <result property="guid" column="guid"/>
+        <result property="orgid" column="orgid"/>
+    </resultMap>
+
+    <delete id="deleteUserRoleByUserId" parameterType="Long">
+        delete
+        from sys_user_role
+        where user_id = #{userId}
+    </delete>
+
+    <select id="countUserRoleByRoleId" resultType="Integer">
+        select count(1)
+        from sys_user_role
+        where role_id = #{roleId}
+    </select>
+
+    <delete id="deleteUserRole" parameterType="Long">
+        delete from sys_user_role where user_id in
+        <foreach collection="array" item="userId" open="(" separator="," close=")">
+            #{userId}
+        </foreach>
+    </delete>
+
+    <insert id="batchUserRole">
+        insert into sys_user_role(user_id, role_id,guid,orgid) values
+        <foreach item="item" index="index" collection="list" separator=",">
+            (#{item.userId},#{item.roleId},#{item.guid},#{item.orgid})
+        </foreach>
+    </insert>
+
+    <delete id="deleteUserRoleInfo" parameterType="SysUserRole">
+        delete
+        from sys_user_role
+        where user_id = #{userId}
+          and role_id = #{roleId}
+    </delete>
+
+    <delete id="deleteUserRoleInfos">
+        delete from sys_user_role where role_id=#{roleId} and user_id in
+        <foreach collection="userIds" item="userId" open="(" separator="," close=")">
+            #{userId}
+        </foreach>
+    </delete>
+</mapper>

--
Gitblit v1.9.3