xiaoyi
6 天以前 05ab6e3f69a5e73624b2573db043f5923e8f7d8b
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryServiceImpl.java
@@ -82,6 +82,8 @@
        workshopService.getWorkshop(createReqVO.getWorkshopId());
        // 校验编码唯一
        validateMachineryCodeUnique(null, createReqVO.getCode());
        // 校验数采设备编号唯一
        validateCollectDeviceCodeUnique(null, createReqVO.getCollectDeviceCode());
        // 插入
        MesDvMachineryDO machinery = BeanUtils.toBean(createReqVO, MesDvMachineryDO.class);
@@ -103,6 +105,8 @@
        workshopService.getWorkshop(updateReqVO.getWorkshopId());
        // 校验编码唯一
        validateMachineryCodeUnique(updateReqVO.getId(), updateReqVO.getCode());
        // 校验数采设备编号唯一
        validateCollectDeviceCodeUnique(updateReqVO.getId(), updateReqVO.getCollectDeviceCode());
        // 更新
        MesDvMachineryDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMachineryDO.class);
@@ -148,6 +152,19 @@
        }
        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);
        }
    }
@@ -278,6 +295,15 @@
            // 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);