|
@@ -76,7 +76,10 @@ public class IotDeviceService {
|
|
|
* @param iotDevicePara
|
|
* @param iotDevicePara
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Object save(IotDevicePara iotDevicePara) {
|
|
public Object save(IotDevicePara iotDevicePara) {
|
|
|
|
|
+ //校验sn
|
|
|
|
|
+ checkDeviceSn(iotDevicePara.getSn());
|
|
|
IotDevice iotDevice = new IotDevice();
|
|
IotDevice iotDevice = new IotDevice();
|
|
|
iotDevice.setProductId(iotDevicePara.getProductId());
|
|
iotDevice.setProductId(iotDevicePara.getProductId());
|
|
|
iotDevice.setName(iotDevicePara.getName());
|
|
iotDevice.setName(iotDevicePara.getName());
|
|
@@ -192,6 +195,7 @@ public class IotDeviceService {
|
|
|
if (Objects.isNull(iotProduct)) {
|
|
if (Objects.isNull(iotProduct)) {
|
|
|
throw new BusinessException("产品编码[" + deviceImportExcelVo.getCode() + "]产品不存在");
|
|
throw new BusinessException("产品编码[" + deviceImportExcelVo.getCode() + "]产品不存在");
|
|
|
}
|
|
}
|
|
|
|
|
+ checkDeviceSn(deviceImportExcelVo.getSn());
|
|
|
deviceImportExcelVo.setProductId(iotProduct.getId());
|
|
deviceImportExcelVo.setProductId(iotProduct.getId());
|
|
|
}
|
|
}
|
|
|
//入库
|
|
//入库
|
|
@@ -227,4 +231,17 @@ public class IotDeviceService {
|
|
|
Optional.ofNullable(deviceVoC).ifPresent(product -> cacheService.setKey(String.format(CacheConstant.DEVICE_CACHE, guid), product));
|
|
Optional.ofNullable(deviceVoC).ifPresent(product -> cacheService.setKey(String.format(CacheConstant.DEVICE_CACHE, guid), product));
|
|
|
return deviceVoC;
|
|
return deviceVoC;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 校验设备sn是否唯一
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param sn
|
|
|
|
|
+ */
|
|
|
|
|
+ private void checkDeviceSn(String sn) {
|
|
|
|
|
+ IotDevice iotDevice = iotDeviceMapper.selectOne(new LambdaQueryWrapper<IotDevice>()
|
|
|
|
|
+ .eq(IotDevice::getSn, sn).eq(IotDevice::getDelFlag, Global.UN_DEL).last("limit 1"));
|
|
|
|
|
+ if (Objects.nonNull(iotDevice)) {
|
|
|
|
|
+ throw new BusinessException("当前设备【" + iotDevice.getSn() + "】已存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|