| | |
| | | |
| | | 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.defect.vo.MesQcDefectImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.qc.defect.vo.MesQcDefectImportRespVO; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | /** |
| | | * MES 缺陷类型 Service 实现类 |
| | | * |
| | | * @author 芋道源码 |
| | | * @author 超级管理员 |
| | | */ |
| | | @Service |
| | | @Validated |
| | |
| | | return defectMapper.selectByIds(ids); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MesQcDefectImportRespVO importDefectList(List<MesQcDefectImportExcelVO> importList, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(QC_DEFECT_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesQcDefectImportRespVO respVO = MesQcDefectImportRespVO.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.getLevel() == null) { |
| | | respVO.getFailureCodes().put(key, "缺陷等级不能为空"); |
| | | return; |
| | | } |
| | | MesQcDefectDO exist = defectMapper.selectByCode(importItem.getCode()); |
| | | if (exist == null) { |
| | | MesQcDefectDO defect = BeanUtils.toBean(importItem, MesQcDefectDO.class); |
| | | defect.setId(null); |
| | | defectMapper.insert(defect); |
| | | respVO.getCreateCodes().add(importItem.getCode()); |
| | | } else if (updateSupport) { |
| | | MesQcDefectDO updateObj = BeanUtils.toBean(importItem, MesQcDefectDO.class); |
| | | updateObj.setId(exist.getId()); |
| | | updateObj.setCode(exist.getCode()); |
| | | defectMapper.updateById(updateObj); |
| | | respVO.getUpdateCodes().add(importItem.getCode()); |
| | | } else { |
| | | respVO.getFailureCodes().put(key, "缺陷编码已存在"); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |