| | |
| | | |
| | | 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.dv.subject.vo.MesDvSubjectImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.subject.vo.MesDvSubjectImportRespVO; |
| | | 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 subjectMapper.selectByIds(ids); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MesDvSubjectImportRespVO importSubjectList(List<MesDvSubjectImportExcelVO> importList, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(DV_SUBJECT_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesDvSubjectImportRespVO respVO = MesDvSubjectImportRespVO.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; |
| | | } |
| | | try { |
| | | MesDvSubjectSaveReqVO saveReqVO = BeanUtils.toBean(importItem, MesDvSubjectSaveReqVO.class); |
| | | saveReqVO.setType(ObjUtil.defaultIfNull(importItem.getType(), 1)); |
| | | saveReqVO.setStatus(ObjUtil.defaultIfNull(importItem.getStatus(), CommonStatusEnum.ENABLE.getStatus())); |
| | | MesDvSubjectDO exist = subjectMapper.selectByCode(importItem.getCode()); |
| | | if (exist == null) { |
| | | createSubject(saveReqVO); |
| | | respVO.getCreateCodes().add(saveReqVO.getCode()); |
| | | } else if (updateSupport) { |
| | | saveReqVO.setId(exist.getId()); |
| | | updateSubject(saveReqVO); |
| | | respVO.getUpdateCodes().add(saveReqVO.getCode()); |
| | | } else { |
| | | respVO.getFailureCodes().put(key, "项目编码已存在:" + importItem.getCode()); |
| | | } |
| | | } catch (ServiceException e) { |
| | | respVO.getFailureCodes().put(key, e.getMessage()); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |