| | |
| | | for (SysUserDept sud : sysUserDept) { |
| | | if (usersTemp.size() > 0) { |
| | | sud.setUserId(usersTemp.get(0).getUserId()); |
| | | SysDept sysDeptTemp = sysDept2Mapper.selectDeptByCode(sud.getDeptCode()); |
| | | if (sysDeptTemp != null) |
| | | sud.setDeptId(sysDeptTemp.getDeptId()); |
| | | sysUserDeptMapper.insertSysUserDept(sud); |
| | | } |
| | | } |
| | |
| | | log.info("selectDeptList的采集到的数量为:{}", sysDepts.size()); |
| | | 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("已设置新表 '{}' 的自增ID起始值为 {}", tableName, maxId + 1); |
| | | |
| | | log.info("表 '{}' 的分表操作完成!", tableName); |
| | | } |
| | | } |
| | | |
| | | } |