From 4cfc8a1a6797d8d5914be796d4bfa7bcf4cfd751 Mon Sep 17 00:00:00 2001 From: wangwei_123 <1255324804@qq.com> Date: Mon, 26 Jan 2026 16:03:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E6=8C=81=E8=A1=A8=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E7=A7=9F=E6=88=B7=20redis=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/hand/controller/admin/HandDetectorController.java | 4 +++- .../yudao/module/hand/service/impl/HandDetectorServiceImpl.java | 7 +------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandDetectorController.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandDetectorController.java index f9d4714..5275b2a 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandDetectorController.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandDetectorController.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.hand.controller.admin; import cn.iocoder.yudao.framework.security.core.LoginUser; +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.module.hand.dal.HandDetectorDO; import cn.iocoder.yudao.module.hand.service.HandDetectorService; import cn.iocoder.yudao.module.hand.util.RedisKeyUtil; @@ -139,7 +140,8 @@ public class HandDetectorController { if (null == loginUser) { throw exception(HAND_DETECTOR_REDIS_NOT_EXISTS); } - String tenantDeviceHashKey = RedisKeyUtil.getTenantDeviceHashKey(loginUser.getTenantId()); + Long tenantId = TenantContextHolder.getTenantId(); + String tenantDeviceHashKey = RedisKeyUtil.getTenantDeviceHashKey(tenantId); Map handData = handDetectorService.getHandData(tenantDeviceHashKey); return CommonResult.success(handData); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/HandDetectorServiceImpl.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/HandDetectorServiceImpl.java index 1d1164d..8479829 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/HandDetectorServiceImpl.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/HandDetectorServiceImpl.java @@ -267,21 +267,17 @@ public class HandDetectorServiceImpl implements HandDetectorService { @Transactional(rollbackFor = Exception.class) @TenantIgnore public void dataMigrate(HandDetectorSaveReqVO migrateReqVO) { - // 1. --- 输入校验 --- if (CollectionUtils.isEmpty(migrateReqVO.getIdList()) || migrateReqVO.getTenantId() == null) { - // 如果没有提供设备ID或目标租户ID,则直接返回或抛出异常 return; } - // 2. --- 数据准备 --- // 一次性查询出所有待迁移的设备实体 List devicesToMigrate = handDetectorMapper.selectByIds(migrateReqVO.getIdList()); if (CollectionUtils.isEmpty(devicesToMigrate)) { - // 如果根据ID没有查到任何设备,直接返回 return; } - // 获取旧的租户ID(假设一批迁移的设备都来自同一个租户) + // 获取旧的租户ID Integer oldTenantId = devicesToMigrate.get(0).getTenantId(); // 新的租户ID Integer newTenantId = migrateReqVO.getTenantId(); @@ -296,7 +292,6 @@ public class HandDetectorServiceImpl implements HandDetectorService { .map(HandDetectorDO::getSn) .toList(); - // 3. --- 数据库更新 --- // 遍历设备列表,更新租户ID并清空特定于旧租户的关联数据 for (HandDetectorDO device : devicesToMigrate) { device.setTenantId(newTenantId);