|
@@ -106,6 +106,9 @@ public class MonitorDeviceServiceImpl extends ServiceImpl<MonitorDeviceMapper, M
|
|
|
if (this.getByDeviceCode(monitorDevice.getDeviceCode())) {
|
|
|
throw new CommonException("设备编码已注册使用:{}", monitorDevice.getDeviceCode());
|
|
|
}
|
|
|
+ if (this.getByDeviceName(monitorDevice.getDeviceName())) {
|
|
|
+ throw new CommonException("设备名已注册使用:{}", monitorDevice.getDeviceName());
|
|
|
+ }
|
|
|
// 保存设备
|
|
|
boolean save = this.save(monitorDevice);
|
|
|
// 召唤设备默认参数
|
|
@@ -115,7 +118,7 @@ public class MonitorDeviceServiceImpl extends ServiceImpl<MonitorDeviceMapper, M
|
|
|
renKeService.callParamIds(Integer.parseInt(monitorDevice.getDeviceCode()));
|
|
|
} catch (NumberFormatException e) {
|
|
|
// 如果设备编码不能解析为整数,抛出异常或记录日志
|
|
|
- throw new CommonException("设备编码解析失败,无法发送配置参数。设备编码: " + monitorDevice.getDeviceCode(), e);
|
|
|
+ throw new CommonException("设备编码解析失败,无法发送配置参数。设备编码: " + monitorDevice.getDeviceCode(), e + "请输入整数编码");
|
|
|
}
|
|
|
} else {
|
|
|
throw new CommonException("设备保存失败,设备编码: " + monitorDevice.getDeviceCode());
|
|
@@ -124,6 +127,12 @@ public class MonitorDeviceServiceImpl extends ServiceImpl<MonitorDeviceMapper, M
|
|
|
monitorDeviceCache.cacheDevice(monitorDevice.getDeviceCode(), monitorDevice.getModelName());
|
|
|
}
|
|
|
|
|
|
+ private boolean getByDeviceName(String deviceName) {
|
|
|
+ List<MonitorDevice> devices = this.list(new LambdaQueryWrapper<MonitorDevice>()
|
|
|
+ .eq(MonitorDevice::getDeviceName, deviceName).eq(MonitorDevice::getDeleteFlag,CommonDeleteFlagEnum.NOT_DELETE));
|
|
|
+ return !devices.isEmpty();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private boolean getByDeviceCode(String deviceCode) {
|
|
|
List<MonitorDevice> devices = this.list(new QueryWrapper<MonitorDevice>().like("device_code", deviceCode));
|
|
@@ -135,6 +144,13 @@ public class MonitorDeviceServiceImpl extends ServiceImpl<MonitorDeviceMapper, M
|
|
|
@Override
|
|
|
public void edit(MonitorDeviceEditParam monitorDeviceEditParam) {
|
|
|
MonitorDevice monitorDevice = this.queryEntity(monitorDeviceEditParam.getId());
|
|
|
+ // 检查设备编码是否已注册
|
|
|
+ if (this.getByDeviceCode(monitorDeviceEditParam.getDeviceCode())) {
|
|
|
+ throw new CommonException("设备编码已注册使用:{}", monitorDeviceEditParam.getDeviceCode());
|
|
|
+ }
|
|
|
+ if (this.getByDeviceName(monitorDeviceEditParam.getDeviceName())) {
|
|
|
+ throw new CommonException("设备名已注册使用:{}", monitorDeviceEditParam.getDeviceName());
|
|
|
+ }
|
|
|
BeanUtil.copyProperties(monitorDeviceEditParam, monitorDevice);
|
|
|
this.updateById(monitorDevice);
|
|
|
}
|