fix(watch): 添加设备时校验watchNo唯一性,避免数据库唯一约束冲突

This commit is contained in:
2026-06-24 11:00:48 +08:00
parent 6384021c4d
commit c6d12c9c68
@@ -295,6 +295,12 @@ public class WatchDeviceController extends JeecgController<WatchDevice, IWatchDe
@RequiresPermissions("watch:watch_device:add")
@PostMapping(value = "/add")
public Result<String> add(@RequestBody WatchDevice watchDevice) {
// 校验设备编码是否已存在
LambdaQueryWrapper<WatchDevice> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(WatchDevice::getWatchNo, watchDevice.getWatchNo());
if (watchDeviceService.count(queryWrapper) > 0) {
return Result.error("设备编码已存在,请勿重复添加");
}
// 删除开关
LambdaUpdateWrapper<WatchDeviceSwitch> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(WatchDeviceSwitch::getWatchNo, watchDevice.getWatchNo());