| | |
| | | workshopService.getWorkshop(createReqVO.getWorkshopId()); |
| | | // 校验编码唯一 |
| | | validateMachineryCodeUnique(null, createReqVO.getCode()); |
| | | // 校验数采设备编号唯一 |
| | | validateCollectDeviceCodeUnique(null, createReqVO.getCollectDeviceCode()); |
| | | |
| | | // 插入 |
| | | MesDvMachineryDO machinery = BeanUtils.toBean(createReqVO, MesDvMachineryDO.class); |
| | |
| | | workshopService.getWorkshop(updateReqVO.getWorkshopId()); |
| | | // 校验编码唯一 |
| | | validateMachineryCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); |
| | | // 校验数采设备编号唯一 |
| | | validateCollectDeviceCodeUnique(updateReqVO.getId(), updateReqVO.getCollectDeviceCode()); |
| | | |
| | | // 更新 |
| | | MesDvMachineryDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMachineryDO.class); |
| | |
| | | } |
| | | if (ObjUtil.notEqual(machinery.getId(), id)) { |
| | | throw exception(DV_MACHINERY_CODE_DUPLICATE); |
| | | } |
| | | } |
| | | |
| | | private void validateCollectDeviceCodeUnique(Long id, String collectDeviceCode) { |
| | | if (StrUtil.isBlank(collectDeviceCode)) { |
| | | return; |
| | | } |
| | | MesDvMachineryDO machinery = machineryMapper.selectByCollectDeviceCode(collectDeviceCode); |
| | | if (machinery == null) { |
| | | return; |
| | | } |
| | | if (ObjUtil.notEqual(machinery.getId(), id)) { |
| | | throw exception(DV_MACHINERY_COLLECT_CODE_DUPLICATE); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | // 3.5 判断:创建 or 更新 |
| | | MesDvMachineryDO existMachinery = machineryMapper.selectByCode(importItem.getCode()); |
| | | if (StrUtil.isNotBlank(importItem.getCollectDeviceCode())) { |
| | | MesDvMachineryDO collectOwner = machineryMapper.selectByCollectDeviceCode(importItem.getCollectDeviceCode()); |
| | | if (collectOwner != null && (existMachinery == null |
| | | || ObjUtil.notEqual(collectOwner.getId(), existMachinery.getId()))) { |
| | | respVO.getFailureCodes().put(key, "数采设备编号[" + importItem.getCollectDeviceCode() + "]已被设备[" |
| | | + collectOwner.getCode() + "]占用"); |
| | | return; |
| | | } |
| | | } |
| | | if (existMachinery == null) { |
| | | // 3.5.1 创建 |
| | | MesDvMachineryDO machinery = BeanUtils.toBean(importItem, MesDvMachineryDO.class); |