| | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.qc.indicator.vo.MesQcIndicatorImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.qc.indicator.vo.MesQcIndicatorImportRespVO; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | /** |
| | | * MES 质检指标 Service 实现类 |
| | |
| | | return convertMap(indicators, MesQcIndicatorDO::getId); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MesQcIndicatorImportRespVO importIndicatorList(List<MesQcIndicatorImportExcelVO> importList, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(QC_INDICATOR_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesQcIndicatorImportRespVO respVO = MesQcIndicatorImportRespVO.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 = StrUtil.blankToDefault(importItem.getCode(), "第 " + currentIndex + " 行"); |
| | | if (StrUtil.isBlank(importItem.getCode())) { |
| | | respVO.getFailureCodes().put(key, "检测项编码不能为空"); |
| | | return; |
| | | } |
| | | if (StrUtil.isBlank(importItem.getName())) { |
| | | respVO.getFailureCodes().put(key, "检测项名称不能为空"); |
| | | return; |
| | | } |
| | | if (importItem.getType() == null) { |
| | | respVO.getFailureCodes().put(key, "检测项类型不能为空"); |
| | | return; |
| | | } |
| | | if (importItem.getResultType() == null) { |
| | | respVO.getFailureCodes().put(key, "结果值类型不能为空"); |
| | | return; |
| | | } |
| | | MesQcIndicatorDO exist = indicatorMapper.selectByCode(importItem.getCode()); |
| | | if (exist == null) { |
| | | MesQcIndicatorDO indicator = BeanUtils.toBean(importItem, MesQcIndicatorDO.class); |
| | | indicator.setId(null); |
| | | indicatorMapper.insert(indicator); |
| | | respVO.getCreateCodes().add(importItem.getCode()); |
| | | } else if (updateSupport) { |
| | | MesQcIndicatorDO updateObj = BeanUtils.toBean(importItem, MesQcIndicatorDO.class); |
| | | updateObj.setId(exist.getId()); |
| | | updateObj.setCode(exist.getCode()); |
| | | indicatorMapper.updateById(updateObj); |
| | | respVO.getUpdateCodes().add(importItem.getCode()); |
| | | } else { |
| | | respVO.getFailureCodes().put(key, "检测项编码已存在"); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |