| | |
| | | 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.bpm.api.task.BpmProcessInstanceApi; |
| | | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| | | import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; |
| | | 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; |
| | |
| | | */ |
| | | private static final String PROJECT_APPROVE_BIZ_TYPE = "mes_pd_project_approve"; |
| | | |
| | | /** |
| | | * 设计项目审批的 BPM 流程定义 Key |
| | | */ |
| | | private static final String PROJECT_APPROVE_PROCESS_KEY = "mes-pd-project-audit"; |
| | | |
| | | @Resource |
| | | private MesPdProjectMapper projectMapper; |
| | | |
| | | @Resource |
| | | private BpmProcessInstanceApi bpmProcessInstanceApi; |
| | | |
| | | @Resource |
| | | @Lazy |
| | |
| | | } |
| | | // 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); |
| | |
| | | approvalConfigApi.validateApprovalEnabledAndGetApprovers(PROJECT_APPROVE_BIZ_TYPE); |
| | | // 4. 状态置为审批中,并清空上一轮审核结果 |
| | | projectMapper.submitAndResetAuditInfo(id, MesPdProjectStatusEnum.APPROVING.getStatus()); |
| | | // 5. 创建 BPM 流程实例,使审批出现在「协同办公 - 我的流程」 |
| | | bpmProcessInstanceApi.createProcessInstance(getLoginUserId(), |
| | | new BpmProcessInstanceCreateReqDTO() |
| | | .setProcessDefinitionKey(PROJECT_APPROVE_PROCESS_KEY) |
| | | .setBusinessKey(String.valueOf(id))); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateProjectAuditStatus(Long id, Integer bpmStatus, String reason) { |
| | | // BPM 审批结果映射为项目状态:通过=待归档 / 不通过=待审核(可修改后重新提交) |
| | | Integer status; |
| | | if (BpmTaskStatusEnum.APPROVE.getStatus().equals(bpmStatus)) { |
| | | status = MesPdProjectStatusEnum.AUDIT.getStatus(); |
| | | } else if (BpmTaskStatusEnum.REJECT.getStatus().equals(bpmStatus)) { |
| | | status = MesPdProjectStatusEnum.UPLOAD.getStatus(); |
| | | } else { |
| | | // 设计项目没有「已取消」状态,其余 BPM 结果(如撤消)忽略 |
| | | log.warn("[updateProjectAuditStatus] 忽略不支持的 BPM 状态({}),projectId={}", bpmStatus, id); |
| | | return; |
| | | } |
| | | if (projectMapper.updateAuditStatusByBpm(id, status, reason) != 1) { |
| | | log.warn("[updateProjectAuditStatus] 设计项目({}) 不处于审批中状态,忽略 BPM 结果({})", id, bpmStatus); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | @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; |
| | | } |
| | | |
| | | /** |
| | | * 生成审核单号(使用编码规则) |
| | | */ |