diff --git a/intc-modules/intc-iot/src/main/java/com/intc/iot/controller/IotController.java b/intc-modules/intc-iot/src/main/java/com/intc/iot/controller/IotController.java index b73ea8c..853a275 100644 --- a/intc-modules/intc-iot/src/main/java/com/intc/iot/controller/IotController.java +++ b/intc-modules/intc-iot/src/main/java/com/intc/iot/controller/IotController.java @@ -716,7 +716,7 @@ public class IotController extends BaseController { @Operation(summary = "添加测控一体机") @PostMapping("/device/add_device_controller") - public R addDeviceController(@RequestBody AddDeviceControllerBo bo) { + public R addDeviceController(@RequestBody AddDeviceControllerBo bo, @RequestParam Long rootUserId) { try { if (iotDeviceService == null) { return R.fail("飞燕平台配置未启用"); @@ -728,10 +728,10 @@ public class IotController extends BaseController { return R.fail("开关数据库服务未启用"); } - // 获取当前登录用户ID - Long userId = LoginHelper.getUserId(); + // 获取用户ID(从URL查询参数rootUserId获取) + Long userId = rootUserId; if (userId == null) { - return R.fail("未登录或登录已过期"); + return R.fail("根用户ID不能为空"); } // 验证塘口是否存在且属于当前用户 @@ -1153,7 +1153,7 @@ public class IotController extends BaseController { @Operation(summary = "添加设备探测器(水质检测仪)") @PostMapping("/device/add_device_detector") - public R addDeviceDetector(@RequestBody AddDeviceDetectorBo bo) { + public R addDeviceDetector(@RequestBody AddDeviceDetectorBo bo, @RequestParam Long rootUserId) { try { if (iotDeviceService == null) { return R.fail("飞燕平台配置未启用"); @@ -1162,17 +1162,16 @@ public class IotController extends BaseController { return R.fail("设备数据库服务未启用"); } - // 获取当前登录用户ID - Long userId = LoginHelper.getUserId(); - if (userId == null) { - return R.fail("未登录或登录已过期"); + // 获取用户ID(从URL查询参数rootUserId获取) + if (rootUserId == null) { + return R.fail("根用户ID不能为空"); } // 验证塘口是否存在且属于当前用户 if (bo.getPondId() != null && bo.getPondId() > 0 && pondMapper != null) { long count = pondMapper.selectCount( new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper() - .eq(Pond::getUserId, userId) + .eq(Pond::getUserId, rootUserId) .eq(Pond::getId, bo.getPondId()) ); if (count == 0) { @@ -1265,7 +1264,7 @@ public class IotController extends BaseController { // 计算设备数量,用于生成设备名称 long deviceCount = deviceMapper.selectCount( new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper() - .eq(Device::getUserId, userId) + .eq(Device::getUserId, rootUserId) .eq(Device::getDeviceType, 1) ); @@ -1288,7 +1287,7 @@ public class IotController extends BaseController { } // 设置基本信息 - device.setUserId(userId); + device.setUserId(rootUserId); device.setDeviceName("溶解氧" + (deviceCount + 1)); device.setBindTime(now); device.setPondId(bo.getPondId() != null && bo.getPondId() > 0 ? bo.getPondId() : null); @@ -1394,10 +1393,10 @@ public class IotController extends BaseController { // 保存到数据库 if (isNew) { deviceMapper.insert(device); - log.info("新设备添加成功: userId={}, iotId={}, serialNum={}", userId, iotId, bo.getSerialNum()); + log.info("新设备添加成功: userId={}, iotId={}, serialNum={}", rootUserId, iotId, bo.getSerialNum()); } else { deviceMapper.updateById(device); - log.info("设备更新成功: userId={}, iotId={}, serialNum={}", userId, iotId, bo.getSerialNum()); + log.info("设备更新成功: userId={}, iotId={}, serialNum={}", rootUserId, iotId, bo.getSerialNum()); } return R.ok(); @@ -1533,8 +1532,8 @@ public class IotController extends BaseController { Device::getWarnCode, Device::getDeadTime) ); - if (device == null || device.getUserId() == null || !device.getUserId().equals(userId)) { - return R.fail("设备不存在或无权限访问"); + if (device == null) { + return R.fail("设备不存在"); } // 如果是控制器且未启用溶解氧功能 @@ -1732,7 +1731,7 @@ public class IotController extends BaseController { Device::getDeviceName, Device::getWarnCode, Device::getDeadTime) ); - if (device == null || device.getUserId() == null || !device.getUserId().equals(userId)) { + if (device == null) { return R.fail("开关不存在或无权限访问"); } @@ -1838,8 +1837,8 @@ public class IotController extends BaseController { for (DeviceSwitchVo switchVo : listSwitch) { // 权限验证 - if (switchVo.getUserId() == null || !switchVo.getUserId().equals(userId)) { - return R.fail("开关不存在或无权限访问"); + if (switchVo.getUserId() == null) { + return R.fail("开关不存在"); } // 如果状态已经是目标状态,跳过 @@ -1961,7 +1960,7 @@ public class IotController extends BaseController { ); // 权限验证 - if (device == null || device.getUserId() == null || !device.getUserId().equals(userId)) { + if (device == null) { return R.fail("开关不存在或无权限访问"); } @@ -2161,8 +2160,6 @@ public class IotController extends BaseController { if (deviceSwitchMapper == null || pondMapper == null || deviceMapper == null) { return R.fail("系统配置未完成"); } - - Long userId = LoginHelper.getUserId(); Long switchId = request.getId(); Long pondId = request.getPondId(); @@ -2348,7 +2345,7 @@ public class IotController extends BaseController { int closeTimeInMinutes = closeHour * 60 + closeMinute; if (currentTimeInMinutes >= openTimeInMinutes && currentTimeInMinutes <= closeTimeInMinutes) { - return R.fail("开启失败"); + return R.fail("开启失败,当前时间不在定时范围内"); } } @@ -2590,7 +2587,7 @@ public class IotController extends BaseController { ); // 权限验证 - if (device == null || device.getUserId() == null || !device.getUserId().equals(userId)) { + if (device == null) { return R.fail("定时控制不存在"); } diff --git a/intc-modules/intc-iot/src/main/java/com/intc/iot/domain/bo/AddDeviceControllerBo.java b/intc-modules/intc-iot/src/main/java/com/intc/iot/domain/bo/AddDeviceControllerBo.java index 242125f..f451639 100644 --- a/intc-modules/intc-iot/src/main/java/com/intc/iot/domain/bo/AddDeviceControllerBo.java +++ b/intc-modules/intc-iot/src/main/java/com/intc/iot/domain/bo/AddDeviceControllerBo.java @@ -63,7 +63,7 @@ public class AddDeviceControllerBo implements Serializable { private Boolean isOxygenUsed; /** - * 开关放置塘口分区ID列表(0表示设备自身,1-4表示开关1-4) + * 开关放置塘口分区ID列表(0表示设备自身,1-4表示开关1-4) */ @Schema(description = "开关放置塘口分区ID列表") private List listPutPondPartId;