| | |
| | | @Lazy |
| | | private MesMdWorkshopService workshopService; |
| | | @Resource |
| | | @Lazy |
| | | private cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService workstationService; |
| | | @Resource |
| | | private MesWmBarcodeService barcodeService; |
| | | @Resource |
| | | @Lazy |
| | |
| | | throw exception(DV_MACHINERY_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | |
| | | // 2. 批量加载设备类型和车间,构建编码到实体的映射 |
| | | // 2. 批量加载设备类型、车间和工作站,构建编码到实体的映射 |
| | | List<MesDvMachineryTypeDO> allTypes = machineryTypeService.getMachineryTypeList( |
| | | new cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.type.MesDvMachineryTypeListReqVO()); |
| | | Map<String, MesDvMachineryTypeDO> typeCodeMap = allTypes.stream() |
| | |
| | | cn.iocoder.yudao.framework.common.enums.CommonStatusEnum.ENABLE.getStatus()); |
| | | Map<String, MesMdWorkshopDO> workshopCodeMap = allWorkshops.stream() |
| | | .collect(Collectors.toMap(MesMdWorkshopDO::getCode, w -> w, (a, b) -> a)); |
| | | List<cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkstationDO> allWorkstations = |
| | | workstationService.getWorkstationListByStatus( |
| | | cn.iocoder.yudao.framework.common.enums.CommonStatusEnum.ENABLE.getStatus()); |
| | | Map<String, cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkstationDO> workstationCodeMap = |
| | | allWorkstations.stream().collect(Collectors.toMap( |
| | | cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkstationDO::getCode, |
| | | w -> w, (a, b) -> a)); |
| | | |
| | | // 3. 遍历,逐个创建 or 更新 |
| | | MesDvMachineryImportRespVO respVO = MesDvMachineryImportRespVO.builder() |
| | |
| | | return; |
| | | } |
| | | |
| | | // 3.4 判断:创建 or 更新 |
| | | // 3.4 校验工作站编码(可选) |
| | | Long workstationId = null; |
| | | if (StrUtil.isNotBlank(importItem.getWorkstationCode())) { |
| | | cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkstationDO workstation = |
| | | workstationCodeMap.get(importItem.getWorkstationCode()); |
| | | if (workstation == null) { |
| | | respVO.getFailureCodes().put(key, "工作站编码[" + importItem.getWorkstationCode() + "]不存在"); |
| | | return; |
| | | } |
| | | workstationId = workstation.getId(); |
| | | } |
| | | |
| | | // 3.5 判断:创建 or 更新 |
| | | MesDvMachineryDO existMachinery = machineryMapper.selectByCode(importItem.getCode()); |
| | | if (existMachinery == null) { |
| | | // 3.4.1 创建 |
| | | // 3.5.1 创建 |
| | | MesDvMachineryDO machinery = BeanUtils.toBean(importItem, MesDvMachineryDO.class); |
| | | machinery.setMachineryTypeId(machineryType.getId()); |
| | | machinery.setWorkshopId(workshop.getId()); |
| | | machinery.setWorkstationId(workstationId); |
| | | machineryMapper.insert(machinery); |
| | | // 自动生成条码 |
| | | barcodeService.autoGenerateBarcode(BarcodeBizTypeEnum.MACHINERY.getValue(), |
| | | machinery.getId(), machinery.getCode(), machinery.getName()); |
| | | respVO.getCreateCodes().add(importItem.getCode()); |
| | | } else if (updateSupport) { |
| | | // 3.4.2 更新 |
| | | // 3.5.2 更新 |
| | | MesDvMachineryDO updateObj = BeanUtils.toBean(importItem, MesDvMachineryDO.class); |
| | | updateObj.setId(existMachinery.getId()); |
| | | updateObj.setMachineryTypeId(machineryType.getId()); |
| | | updateObj.setWorkshopId(workshop.getId()); |
| | | updateObj.setWorkstationId(workstationId); |
| | | machineryMapper.updateById(updateObj); |
| | | respVO.getUpdateCodes().add(importItem.getCode()); |
| | | } else { |