package cn.iocoder.yudao.module.mes.service.common.bpm;
|
|
import cn.hutool.core.collection.CollUtil;
|
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.service.definition.BpmCategoryService;
|
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
|
import jakarta.annotation.Resource;
|
import lombok.extern.slf4j.Slf4j;
|
import org.flowable.engine.repository.ProcessDefinition;
|
import org.springframework.stereotype.Service;
|
import org.springframework.validation.annotation.Validated;
|
|
import java.util.*;
|
|
/**
|
* MES 模块的通用 BPM 流程处理 Service 实现类
|
*/
|
@Service
|
@Validated
|
@Slf4j
|
public class MesBpmProcessServiceImpl implements MesBpmProcessService {
|
|
@Resource
|
private BpmCategoryService bpmCategoryService;
|
@Resource
|
private BpmProcessDefinitionService bpmProcessDefinitionService;
|
|
@Override
|
public List<Map<String, Object>> getApproveProcessDefinitionList(String categoryCode) {
|
// 1. 校验分类是否存在
|
List<BpmCategoryDO> categories = bpmCategoryService.getCategoryListByCode(
|
Collections.singletonList(categoryCode));
|
if (CollUtil.isEmpty(categories)) {
|
log.warn("[getApproveProcessDefinitionList] BPM 流程分类 {} 不存在", categoryCode);
|
return Collections.emptyList();
|
}
|
|
// 2. 获取分类下的流程定义信息
|
List<BpmProcessDefinitionInfoDO> definitionInfoList = bpmProcessDefinitionService
|
.getProcessDefinitionInfoListByCategory(categoryCode);
|
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;
|
}
|
|
}
|