| | |
| | | package cn.iocoder.yudao.module.mes.service.pd.project; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pd.project.vo.MesPdProjectImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pd.project.vo.MesPdProjectImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pd.project.vo.MesPdProjectPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pd.project.vo.MesPdProjectSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pd.document.MesPdDocumentDO; |
| | |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
| | |
| | | } |
| | | // 2. 校验该项目下所有资料审核记录均已审核(不存在待审核的记录) |
| | | List<MesPdDocumentDO> documents = documentService.getDocumentListByProjectId(id); |
| | | if (CollUtil.isEmpty(documents)) { |
| | | throw exception(PD_PROJECT_NO_DOCUMENT); |
| | | } |
| | | List<Long> documentIds = documents.stream().map(MesPdDocumentDO::getId).toList(); |
| | | if (documentAuditMapper.existsPendingAuditByDocumentIds(documentIds)) { |
| | | throw exception(PD_PROJECT_AUDIT_NOT_FINISHED); |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public MesPdProjectImportRespVO importProjectList(List<MesPdProjectImportExcelVO> importList, |
| | | boolean updateSupport) { |
| | | // 1. 校验非空 |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(PD_PROJECT_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | |
| | | // 2. 逐行处理 |
| | | MesPdProjectImportRespVO respVO = MesPdProjectImportRespVO.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.getTaskCode(), "第 " + currentIndex + " 行"); |
| | | if (StrUtil.isBlank(importItem.getTaskCode())) { |
| | | respVO.getFailureCodes().put(key, "任务编码不能为空"); |
| | | return; |
| | | } |
| | | if (StrUtil.isBlank(importItem.getTaskName())) { |
| | | respVO.getFailureCodes().put(key, "任务名称不能为空"); |
| | | return; |
| | | } |
| | | // 2.1 判断:创建 or 更新 |
| | | MesPdProjectDO existProject = projectMapper.selectByTaskCode(importItem.getTaskCode()); |
| | | if (existProject == null) { |
| | | // 2.1.1 新增(复用 create 的状态初始化逻辑) |
| | | MesPdProjectDO project = MesPdProjectDO.builder() |
| | | .taskCode(importItem.getTaskCode()) |
| | | .taskName(importItem.getTaskName()) |
| | | .productCode(importItem.getProductCode()) |
| | | .productName(importItem.getProductName()) |
| | | .version(importItem.getVersion()) |
| | | .status(MesPdProjectStatusEnum.INITIATE.getStatus()) |
| | | .chiefDesigner(importItem.getChiefDesigner()) |
| | | .reviewer(importItem.getReviewer()) |
| | | .planFinishTime(importItem.getPlanFinishTime()) |
| | | .remark(importItem.getRemark()) |
| | | .build(); |
| | | projectMapper.insert(project); |
| | | respVO.getCreateCodes().add(importItem.getTaskCode()); |
| | | } else if (updateSupport) { |
| | | // 2.1.2 更新(仅待发布状态可更新) |
| | | if (ObjUtil.notEqual(MesPdProjectStatusEnum.INITIATE.getStatus(), existProject.getStatus())) { |
| | | respVO.getFailureCodes().put(key, "仅待发布状态的设计项目可更新"); |
| | | return; |
| | | } |
| | | MesPdProjectDO updateObj = MesPdProjectDO.builder() |
| | | .id(existProject.getId()) |
| | | .taskCode(importItem.getTaskCode()) |
| | | .taskName(importItem.getTaskName()) |
| | | .productCode(importItem.getProductCode()) |
| | | .productName(importItem.getProductName()) |
| | | .version(importItem.getVersion()) |
| | | .chiefDesigner(importItem.getChiefDesigner()) |
| | | .reviewer(importItem.getReviewer()) |
| | | .planFinishTime(importItem.getPlanFinishTime()) |
| | | .remark(importItem.getRemark()) |
| | | .build(); |
| | | projectMapper.updateById(updateObj); |
| | | respVO.getUpdateCodes().add(importItem.getTaskCode()); |
| | | } else { |
| | | respVO.getFailureCodes().put(key, "任务编码已存在"); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | /** |
| | | * 生成审核单号(使用编码规则) |
| | | */ |