| | |
| | | package cn.iocoder.yudao.module.mes.service.qc.outsourcetest; |
| | | import java.util.List; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateUtil; |
| | |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.qc.outsourcetest.vo.MesQcOutsourceTestImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.qc.outsourcetest.vo.MesQcOutsourceTestImportRespVO; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | /** |
| | | * MES 委外检测/试验单 Service 实现类 |
| | |
| | | return test; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MesQcOutsourceTestImportRespVO importTestList(List<MesQcOutsourceTestImportExcelVO> importList, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(QC_OUTSOURCE_TEST_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesQcOutsourceTestImportRespVO respVO = MesQcOutsourceTestImportRespVO.builder() |
| | | .createCodes(new ArrayList<>()).updateCodes(new ArrayList<>()) |
| | | .failureCodes(new LinkedHashMap<>()).build(); |
| | | AtomicInteger index = new AtomicInteger(1); |
| | | importList.forEach(importItem -> { |
| | | int currentIndex = index.getAndIncrement(); |
| | | String key = "第 " + currentIndex + " 行"; |
| | | if (StrUtil.isBlank(importItem.getName())) { |
| | | respVO.getFailureCodes().put(key, "单据名称不能为空"); |
| | | return; |
| | | } |
| | | if (importItem.getTestType() == null) { |
| | | respVO.getFailureCodes().put(key, "检测类型不能为空"); |
| | | return; |
| | | } |
| | | if (importItem.getTestDate() == null) { |
| | | respVO.getFailureCodes().put(key, "检测日期不能为空"); |
| | | return; |
| | | } |
| | | Long itemId = null; |
| | | if (StrUtil.isNotBlank(importItem.getItemCode())) { |
| | | cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO item = itemService.getItemByCode(importItem.getItemCode()); |
| | | if (item == null) { |
| | | respVO.getFailureCodes().put(key, "物料不存在:" + importItem.getItemCode()); |
| | | return; |
| | | } |
| | | itemId = item.getId(); |
| | | } |
| | | try { |
| | | MesQcOutsourceTestSaveReqVO createReqVO = BeanUtils.toBean(importItem, MesQcOutsourceTestSaveReqVO.class); |
| | | createReqVO.setItemId(itemId); |
| | | Long id = createTest(createReqVO); |
| | | MesQcOutsourceTestDO created = testMapper.selectById(id); |
| | | respVO.getCreateCodes().add(created != null && StrUtil.isNotBlank(created.getCode()) ? created.getCode() : key); |
| | | } catch (ServiceException e) { |
| | | respVO.getFailureCodes().put(key, e.getMessage()); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |