|
@@ -2,6 +2,7 @@ package com.xy.service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xy.annotation.Lock;
|
|
@@ -57,6 +58,8 @@ public class DeviceRegisterServiceImpl extends ServiceImpl<DeviceRegisterMapper,
|
|
|
|
|
|
private MqttConfig mqttConfig;
|
|
|
|
|
|
+ private DeviceSysinfoServiceImpl deviceSysinfoService;
|
|
|
+
|
|
|
@PostMapping("save")
|
|
|
@ApiOperation("添加")
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -184,4 +187,36 @@ public class DeviceRegisterServiceImpl extends ServiceImpl<DeviceRegisterMapper,
|
|
|
List<DeviceRegister> list = list(lambdaQueryWrapper);
|
|
|
return R.ok(copy(DeviceRegisterDto.Vo.class, list));
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation("修改")
|
|
|
+ @PostMapping("update")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R update(@RequestBody @Validated DeviceRegisterDto.Update update) {
|
|
|
+ //校验
|
|
|
+ String deviceSn = update.getDeviceSn();
|
|
|
+ Long deviceId = update.getDeviceId();
|
|
|
+ if (Emptys.check(deviceSn)) {
|
|
|
+ DeviceRegister deviceRegister = getById(deviceId);
|
|
|
+ if (!deviceSn.equals(deviceRegister.getDeviceSn())) {
|
|
|
+ long count = count(new LambdaQueryWrapper<DeviceRegister>().eq(DeviceRegister::getDeviceSn, deviceSn));
|
|
|
+ if (count > 0) {
|
|
|
+ return R.fail("sn号已被绑定");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //修改注册登记
|
|
|
+ DeviceRegister deviceRegister = copy(DeviceRegister.class, update);
|
|
|
+ updateById(deviceRegister);
|
|
|
+ //修改其他表
|
|
|
+ if (Emptys.check(deviceSn)) {
|
|
|
+ //修改系统信息
|
|
|
+ deviceSysinfoService.updateById(new DeviceSysinfo().setDeviceId(deviceId).setDeviceSn(deviceSn));
|
|
|
+ //修改mqtt认证
|
|
|
+ LambdaUpdateWrapper<MqttUser> mqttUserLambdaUpdateWrapper = new LambdaUpdateWrapper<MqttUser>()
|
|
|
+ .set(MqttUser::getSn, deviceSn)
|
|
|
+ .eq(MqttUser::getDeviceId, deviceId);
|
|
|
+ mqttUserService.update(mqttUserLambdaUpdateWrapper);
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
}
|