设备和传感器的名称和编号两个属性都不能一样

master
yangxiaozhong 6 days ago
parent df1cbe260c
commit a616ef04bd

@ -85,6 +85,16 @@ public class IotDeviceController extends BaseController {
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody IotDeviceBo bo) {
String deviceCode = bo.getDeviceCode();
String name = bo.getName();
IotDeviceVo deviceVo = iotDeviceService.queryByDeviceCode(deviceCode);
IotDeviceVo deviceVo1 = iotDeviceService.queryByDeviceName(name);
if (deviceVo!=null && deviceVo.getDeviceCode() != null){
return R.fail("设备编号已存在");
}
if (deviceVo1!=null && deviceVo1.getName() != null){
return R.fail("设备名称已存在");
}
return toAjax(iotDeviceService.insertByBo(bo));
}
@ -96,6 +106,11 @@ public class IotDeviceController extends BaseController {
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody IotDeviceBo bo) {
String deviceCode = bo.getDeviceCode();
IotDeviceVo deviceVo = iotDeviceService.queryByDeviceCode(deviceCode);
if (deviceVo!=null && deviceVo.getDeviceCode() != null){
return R.fail("设备编号已存在");
}
return toAjax(iotDeviceService.updateByBo(bo));
}

@ -93,6 +93,16 @@ public class IotSensorController extends BaseController {
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody IotSensorBo bo) {
String code = bo.getCode();
String name = bo.getName();
IotSensorVo iotSensorVo = iotSensorService.queryByCode(code);
IotSensorVo iotSensorVo1 = iotSensorService.queryByName(name);
if (iotSensorVo!=null && iotSensorVo.getCode()!=null){
return R.fail("传感器代号已存在");
}
if (iotSensorVo1!=null && iotSensorVo1.getName()!=null){
return R.fail("传感器名称已存在");
}
return toAjax(iotSensorService.insertByBo(bo));
}
@ -104,6 +114,16 @@ public class IotSensorController extends BaseController {
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody IotSensorBo bo) {
String code = bo.getCode();
String name = bo.getName();
IotSensorVo iotSensorVo = iotSensorService.queryByCode(code);
IotSensorVo iotSensorVo1 = iotSensorService.queryByName(name);
if (iotSensorVo!=null && iotSensorVo.getCode()!=null){
return R.fail("传感器已存在");
}
if (iotSensorVo1!=null && iotSensorVo1.getName()!=null){
return R.fail("传感器已存在");
}
return toAjax(iotSensorService.updateByBo(bo));
}

@ -70,4 +70,6 @@ public interface IIotDeviceService {
IotDeviceVo queryByDeviceCode(String deviceCode);
void updateStatusByBo(IotDevice iotDeviceBo);
IotDeviceVo queryByDeviceName(String name);
}

@ -69,4 +69,6 @@ public interface IIotSensorService {
List<IotSensorVo> queryByNoBound(IotSensorBo bo);
IotSensorVo queryByCode(String sensorCode);
IotSensorVo queryByName(String name);
}

@ -226,4 +226,9 @@ public class IotDeviceServiceImpl implements IIotDeviceService {
public void updateStatusByBo(IotDevice iotDevice) {
baseMapper.updateById(iotDevice);
}
@Override
public IotDeviceVo queryByDeviceName(String name) {
return baseMapper.selectVoOne(new LambdaQueryWrapper<IotDevice>().eq(IotDevice::getName, name));
}
}

@ -139,12 +139,15 @@ public class IotSensorServiceImpl implements IIotSensorService {
//TODO 做一些业务上的校验,判断是否需要校验
}
//查询传感器是否被使用,被使用则不能删除:当device_bound不为空的时候代表该设备被使用中无法删除
QueryWrapper<IotSensor> wrapper = new QueryWrapper<>();
wrapper.isNotNull("device_bound");
List<IotSensorVo> iotSensorVos = baseMapper.selectVoList(wrapper);
if (iotSensorVos != null && iotSensorVos.size() > 0){
return false;
for (Long id : ids) {
QueryWrapper<IotSensor> wrapper = new QueryWrapper<>();
wrapper.isNotNull("device_bound").eq("id", id);
List<IotSensorVo> iotSensorVos = baseMapper.selectVoList(wrapper);
if (iotSensorVos != null && iotSensorVos.size() > 0){
return false;
}
}
return baseMapper.deleteByIds(ids) > 0;
}
@ -159,6 +162,11 @@ public class IotSensorServiceImpl implements IIotSensorService {
return baseMapper.selectVoOne(new LambdaQueryWrapper<IotSensor>().eq(IotSensor::getCode, sensorCode));
}
@Override
public IotSensorVo queryByName(String name) {
return baseMapper.selectVoOne(new LambdaQueryWrapper<IotSensor>().eq(IotSensor::getName, name));
}
private LambdaQueryWrapper<IotSensor> buildQueryWrapper1(IotSensorBo bo) {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<IotSensor> lqw = Wrappers.lambdaQuery();

Loading…
Cancel
Save