| | |
| | | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.operatelog.core.util.OperateLogUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.MesDvMachineryImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.MesDvMachineryImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.MesDvMachineryPageReqVO; |
| | |
| | | import cn.iocoder.yudao.module.mes.service.dv.repair.MesDvRepairService; |
| | | import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkshopService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.barcode.MesWmBarcodeService; |
| | | import com.mzt.logapi.starter.annotation.LogRecord; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | | import static cn.iocoder.yudao.module.mes.enums.LogRecordConstants.*; |
| | | |
| | | /** |
| | | * MES 设备台账 Service 实现类 |
| | | * |
| | | * @author 芋道源码 |
| | | * @author 超级管理员 |
| | | */ |
| | | @Service |
| | | @Validated |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @LogRecord(type = MES_DV_MACHINERY_TYPE, subType = MES_DV_MACHINERY_IMPORT_SUB_TYPE, bizNo = "0", |
| | | success = MES_DV_MACHINERY_IMPORT_SUCCESS) |
| | | public MesDvMachineryImportRespVO importMachineryList(List<MesDvMachineryImportExcelVO> importMachineryList, |
| | | boolean updateSupport) { |
| | | // 1. 参数校验 |
| | |
| | | |
| | | // 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); |
| | |
| | | respVO.getFailureCodes().put(key, "设备编码已存在"); |
| | | } |
| | | }); |
| | | // 记录导入结果汇总,供 @LogRecord 的 success 文案引用 |
| | | OperateLogUtils.putImportSummary(respVO.getCreateCodes(), respVO.getUpdateCodes(), respVO.getFailureCodes()); |
| | | return respVO; |
| | | } |
| | | |