fix: 塘口绑定设备bug修复。
This commit is contained in:
@@ -442,14 +442,10 @@ public class PondController extends BaseController {
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public R<Void> selectDeviceOrSwitch(
|
public R<Void> selectDeviceOrSwitch(
|
||||||
@Validated @RequestBody PondSelectDeviceOrSwitchBo request) {
|
@Validated @RequestBody PondSelectDeviceOrSwitchBo request) {
|
||||||
|
|
||||||
// 获取当前登录用户ID
|
|
||||||
Long userId = LoginHelper.getUserId();
|
|
||||||
|
|
||||||
// 查询塘口信息并验证权限
|
// 查询塘口信息并验证权限
|
||||||
Pond pond = pondMapper.selectById(request.getPondId());
|
Pond pond = pondMapper.selectById(request.getPondId());
|
||||||
if (pond == null || !pond.getUserId().equals(userId)) {
|
if (pond == null) {
|
||||||
return R.fail("塘口不存在或无权限访问");
|
return R.fail("塘口不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理空列表
|
// 处理空列表
|
||||||
@@ -898,19 +894,19 @@ public class PondController extends BaseController {
|
|||||||
.eq(LinkedCtrl::getDeviceId, request.getId())
|
.eq(LinkedCtrl::getDeviceId, request.getId())
|
||||||
.select(LinkedCtrl::getId)
|
.select(LinkedCtrl::getId)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!linkedCtrls.isEmpty()) {
|
if (!linkedCtrls.isEmpty()) {
|
||||||
List<Long> linkedCtrlIds = linkedCtrls.stream()
|
List<Long> linkedCtrlIds = linkedCtrls.stream()
|
||||||
.map(LinkedCtrl::getId)
|
.map(LinkedCtrl::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 2. 解除关联的开关绑定
|
// 2. 解除关联的开关绑定
|
||||||
deviceSwitchMapper.update(null,
|
deviceSwitchMapper.update(null,
|
||||||
new LambdaUpdateWrapper<DeviceSwitch>()
|
new LambdaUpdateWrapper<DeviceSwitch>()
|
||||||
.set(DeviceSwitch::getLinkedCtrlId, null)
|
.set(DeviceSwitch::getLinkedCtrlId, null)
|
||||||
.in(DeviceSwitch::getLinkedCtrlId, linkedCtrlIds)
|
.in(DeviceSwitch::getLinkedCtrlId, linkedCtrlIds)
|
||||||
);
|
);
|
||||||
|
|
||||||
// 3. 删除联动控制记录
|
// 3. 删除联动控制记录
|
||||||
linkedCtrlMapper.delete(
|
linkedCtrlMapper.delete(
|
||||||
new LambdaQueryWrapper<LinkedCtrl>()
|
new LambdaQueryWrapper<LinkedCtrl>()
|
||||||
|
|||||||
Reference in New Issue
Block a user