|
|
@ -267,21 +267,17 @@ public class HandDetectorServiceImpl implements HandDetectorService { |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@TenantIgnore |
|
|
@TenantIgnore |
|
|
public void dataMigrate(HandDetectorSaveReqVO migrateReqVO) { |
|
|
public void dataMigrate(HandDetectorSaveReqVO migrateReqVO) { |
|
|
// 1. --- 输入校验 ---
|
|
|
|
|
|
if (CollectionUtils.isEmpty(migrateReqVO.getIdList()) || migrateReqVO.getTenantId() == null) { |
|
|
if (CollectionUtils.isEmpty(migrateReqVO.getIdList()) || migrateReqVO.getTenantId() == null) { |
|
|
// 如果没有提供设备ID或目标租户ID,则直接返回或抛出异常
|
|
|
|
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 2. --- 数据准备 ---
|
|
|
|
|
|
// 一次性查询出所有待迁移的设备实体
|
|
|
// 一次性查询出所有待迁移的设备实体
|
|
|
List<HandDetectorDO> devicesToMigrate = handDetectorMapper.selectByIds(migrateReqVO.getIdList()); |
|
|
List<HandDetectorDO> devicesToMigrate = handDetectorMapper.selectByIds(migrateReqVO.getIdList()); |
|
|
if (CollectionUtils.isEmpty(devicesToMigrate)) { |
|
|
if (CollectionUtils.isEmpty(devicesToMigrate)) { |
|
|
// 如果根据ID没有查到任何设备,直接返回
|
|
|
|
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 获取旧的租户ID(假设一批迁移的设备都来自同一个租户)
|
|
|
|
|
|
|
|
|
// 获取旧的租户ID
|
|
|
Integer oldTenantId = devicesToMigrate.get(0).getTenantId(); |
|
|
Integer oldTenantId = devicesToMigrate.get(0).getTenantId(); |
|
|
// 新的租户ID
|
|
|
// 新的租户ID
|
|
|
Integer newTenantId = migrateReqVO.getTenantId(); |
|
|
Integer newTenantId = migrateReqVO.getTenantId(); |
|
|
@ -296,7 +292,6 @@ public class HandDetectorServiceImpl implements HandDetectorService { |
|
|
.map(HandDetectorDO::getSn) |
|
|
.map(HandDetectorDO::getSn) |
|
|
.toList(); |
|
|
.toList(); |
|
|
|
|
|
|
|
|
// 3. --- 数据库更新 ---
|
|
|
|
|
|
// 遍历设备列表,更新租户ID并清空特定于旧租户的关联数据
|
|
|
// 遍历设备列表,更新租户ID并清空特定于旧租户的关联数据
|
|
|
for (HandDetectorDO device : devicesToMigrate) { |
|
|
for (HandDetectorDO device : devicesToMigrate) { |
|
|
device.setTenantId(newTenantId); |
|
|
device.setTenantId(newTenantId); |
|
|
|