| | |
| | | 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 |
| | |
| | | @Resource |
| | | @Lazy |
| | | private MesMdWorkshopService workshopService; |
| | | @Resource |
| | | @Lazy |
| | | private cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService workstationService; |
| | | @Resource |
| | | private MesWmBarcodeService barcodeService; |
| | | @Resource |
| | |
| | | |
| | | @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. 参数校验 |
| | |
| | | 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 { |
| | |
| | | respVO.getFailureCodes().put(key, "设备编码已存在"); |
| | | } |
| | | }); |
| | | // 记录导入结果汇总,供 @LogRecord 的 success 文案引用 |
| | | OperateLogUtils.putImportSummary(respVO.getCreateCodes(), respVO.getUpdateCodes(), respVO.getFailureCodes()); |
| | | return respVO; |
| | | } |
| | | |