liu
18 小时以前 1f7c36424e8f48a5917ac6c77e2e47979c469a28
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pd/project/MesPdProjectServiceImpl.java
@@ -7,8 +7,7 @@
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO;
import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum;
import cn.iocoder.yudao.module.bpm.service.definition.BpmCategoryService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
import cn.iocoder.yudao.module.mes.service.common.bpm.MesBpmProcessService;
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;
@@ -80,10 +79,7 @@
    private BpmProcessInstanceApi processInstanceApi;
    @Resource
    private BpmCategoryService bpmCategoryService;
    @Resource
    private BpmProcessDefinitionService bpmProcessDefinitionService;
    private MesBpmProcessService mesBpmProcessService;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -238,40 +234,7 @@
    @Override
    public List<Map<String, Object>> getProjectApproveProcessDefinitionList() {
        // 1. 校验分类是否存在
        List<BpmCategoryDO> categories = bpmCategoryService.getCategoryListByCode(
                Collections.singletonList(BPM_PROCESS_DEFINITION_CATEGORY_CODE));
        if (CollUtil.isEmpty(categories)) {
            throw exception(PD_PROJECT_BPM_CATEGORY_NOT_EXISTS);
        }
        // 2. 获取分类下的流程定义信息
        List<BpmProcessDefinitionInfoDO> definitionInfoList = bpmProcessDefinitionService
                .getProcessDefinitionInfoListByCategory(BPM_PROCESS_DEFINITION_CATEGORY_CODE);
        if (CollUtil.isEmpty(definitionInfoList)) {
            return Collections.emptyList();
        }
        // 3. 过滤激活状态,保留最新版本
        Map<String, ProcessDefinition> latestVersionMap = new HashMap<>();
        for (BpmProcessDefinitionInfoDO info : definitionInfoList) {
            ProcessDefinition pd = bpmProcessDefinitionService.getProcessDefinition(info.getProcessDefinitionId());
            if (pd == null || pd.isSuspended()) {
                continue;
            }
            ProcessDefinition existing = latestVersionMap.get(pd.getKey());
            if (existing == null || pd.getVersion() > existing.getVersion()) {
                latestVersionMap.put(pd.getKey(), pd);
            }
        }
        // 4. 返回流程定义列表
        List<Map<String, Object>> result = new ArrayList<>();
        for (ProcessDefinition pd : latestVersionMap.values()) {
            Map<String, Object> item = new HashMap<>();
            item.put("id", pd.getId());
            item.put("key", pd.getKey());
            item.put("name", pd.getName());
            result.add(item);
        }
        return result;
        return mesBpmProcessService.getApproveProcessDefinitionList(BPM_PROCESS_DEFINITION_CATEGORY_CODE);
    }
    @Override
@@ -343,6 +306,32 @@
        return projectMapper.selectList(new QueryWrapper<MesPdProjectDO>().lambda().eq(MesPdProjectDO::getProductCode,productCode).eq(MesPdProjectDO::getStatus, MesPdProjectStatusEnum.ARCHIVE.getStatus()));
    }
    @Override
    public Map<Long, Integer> getPendingAuditCountMap(Collection<Long> projectIds) {
        if (CollUtil.isEmpty(projectIds)) {
            return Collections.emptyMap();
        }
        // 1. 批量查出这些项目下的所有资料
        List<MesPdDocumentDO> documents = documentService.getDocumentListByProjectIds(projectIds);
        if (CollUtil.isEmpty(documents)) {
            return Collections.emptyMap();
        }
        // 2. 资料ID -> 项目ID
        Map<Long, Long> documentProjectIdMap = convertMap(documents, MesPdDocumentDO::getId, MesPdDocumentDO::getProjectId);
        // 3. 批量查出所有待审核记录(auditStatus=0)
        List<MesPdDocumentAuditDO> pendingAudits =
                documentAuditMapper.selectPendingAuditListByDocumentIds(documentProjectIdMap.keySet());
        // 4. 按项目统计待审核文件数
        Map<Long, Integer> result = new HashMap<>();
        for (MesPdDocumentAuditDO audit : pendingAudits) {
            Long projectId = documentProjectIdMap.get(audit.getDocumentId());
            if (projectId != null) {
                result.merge(projectId, 1, Integer::sum);
            }
        }
        return result;
    }
    private void validateProjectInitiate(MesPdProjectDO project) {
        if (!MesPdProjectStatusEnum.INITIATE.getStatus().equals(project.getStatus())) {
            throw exception(PD_PROJECT_NOT_INITIATE);