diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java index 38cf6d5..817ab7b 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java @@ -378,7 +378,11 @@ public class CsDeviceServiceImpl implements ICsDeviceService { Thread.sleep(1000); List modelList = objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid)); if (CollUtil.isEmpty(modelList)){ - throwExceptionAndLog(AccessResponseEnum.MODEL_ERROR, logDto); + try { + throwExceptionAndLog(AccessResponseEnum.MODEL_ERROR, logDto); + } catch (Exception e) { + throw new BusinessException(e.getMessage()); + } } List list = csDataSetService.getDataSetData(modelList.get(0).getModelId()); list.forEach(item->{ @@ -388,7 +392,12 @@ public class CsDeviceServiceImpl implements ICsDeviceService { po.setStatus(1); po.setClDid(item.getClDev()); po.setDeviceId(vo.getId()); - csLinePoList.add(po); + //防止主键重复 + QueryWrapper qw = new QueryWrapper(); + qw.eq("line_id",po.getLineId()); + if(csLineService.getBaseMapper().selectList(qw).isEmpty()){ + csLinePoList.add(po); + } }); csLineService.saveBatch(csLinePoList); //2.生成装置和模板的关系表 @@ -419,7 +428,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService { logDto.setResult(0); logDto.setFailReason(e.getMessage()); csLogsFeignClient.addUserLog(logDto); - throw new BusinessException(e.getMessage()); + throw new BusinessException(CommonResponseEnum.FAIL); } return "success"; } catch (BusinessException e) { @@ -469,7 +478,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService { throwExceptionAndLog(AccessResponseEnum.DEV_MODEL_NOT_FIND, logDto); } String devModel = dictData.getCode(); - zhiLianRegister(nDid,"PQV-500"); + zhiLianRegister(nDid,devModel); } private DeviceLogDTO createLogDto(String operate) {