feat(REQ-4624) - 调整获取审批模版文档的接口列表
This commit is contained in:
parent
89364d1f54
commit
c3ccfef057
@ -7,6 +7,8 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 流程关联文档搜索入参模型
|
||||
*
|
||||
@ -22,6 +24,7 @@ public class DocQueryDTO {
|
||||
|
||||
/**
|
||||
* 流程实例 ID
|
||||
* 该参数与 processDefinitionKey 二选一, 如果有值,则优先使用实例 ID,仅查询实例下使用的文档
|
||||
*/
|
||||
@ApiModelProperty(value = "流程实例 ID")
|
||||
private String processInstanceId;
|
||||
@ -32,6 +35,13 @@ public class DocQueryDTO {
|
||||
@ApiModelProperty(value = "流程定义 KEY(业务 ID)")
|
||||
private String processDefinitionKey;
|
||||
|
||||
/**
|
||||
* 流程定义 KEY 列表(业务 ID 列表)
|
||||
* 当选择使用 processDefinitionKey/s 时,则查询模板对应默认的文档列表
|
||||
*/
|
||||
@ApiModelProperty(value = "流程定义 KEY 列表(业务 ID 列表)")
|
||||
private List<String> processDefinitionKeys;
|
||||
|
||||
/**
|
||||
* 租户 ID,对应工作台 ID
|
||||
*/
|
||||
|
||||
@ -27,6 +27,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
@ -52,6 +53,7 @@ public class CustomGetModelDocsCmd implements Command<List<DocBaseVO>> {
|
||||
* eg. we1:1:202504021034000000001 or we1
|
||||
*/
|
||||
private String processDefinitionId;
|
||||
private List<String> getProcessDefinitionIds;
|
||||
private String tenantId;
|
||||
private Boolean filterEnable = true;
|
||||
/**
|
||||
@ -84,9 +86,10 @@ public class CustomGetModelDocsCmd implements Command<List<DocBaseVO>> {
|
||||
this.extAxReModelService = extAxReModelService;
|
||||
}
|
||||
|
||||
public CustomGetModelDocsCmd(String processInstanceId, String processDefinitionId, String tenantId, ExtAxModelDocMapper extAxModelDocMapper, ExtAxReModelService extAxReModelService) {
|
||||
public CustomGetModelDocsCmd(String processInstanceId, String processDefinitionId, List<String> processDefinitionIds, String tenantId, ExtAxModelDocMapper extAxModelDocMapper, ExtAxReModelService extAxReModelService) {
|
||||
this.processInstanceId = processInstanceId;
|
||||
this.processDefinitionId = processDefinitionId;
|
||||
this.getProcessDefinitionIds = processDefinitionIds;
|
||||
this.tenantId = tenantId;
|
||||
this.extAxModelDocMapper = extAxModelDocMapper;
|
||||
this.extAxReModelService = extAxReModelService;
|
||||
@ -107,7 +110,8 @@ public class CustomGetModelDocsCmd implements Command<List<DocBaseVO>> {
|
||||
check();
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
|
||||
RepositoryService repositoryService = processEngineConfiguration.getRepositoryService();
|
||||
ProcessDefinition processDefinition;
|
||||
|
||||
List<ProcessDefinition> processDefinitions = new ArrayList<>();
|
||||
List<Long> enableDocIds = new ArrayList<>();
|
||||
if (StringUtils.hasText(processInstanceId)) {
|
||||
HistoryService historyService = processEngineConfiguration.getHistoryService();
|
||||
@ -129,37 +133,66 @@ public class CustomGetModelDocsCmd implements Command<List<DocBaseVO>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(instance.getProcessDefinitionId()).singleResult();
|
||||
processDefinitions.add(repositoryService.createProcessDefinitionQuery().processDefinitionId(instance.getProcessDefinitionId()).singleResult());
|
||||
} else {
|
||||
List<ProcessDefinition> definitions = repositoryService.createProcessDefinitionQuery()
|
||||
.processDefinitionKey(parseProcessDefinitionKey())
|
||||
.list();
|
||||
List<ProcessDefinition> definitions = new ArrayList<>();
|
||||
if (StringUtils.hasText(processDefinitionId)) {
|
||||
definitions.addAll(repositoryService.createProcessDefinitionQuery()
|
||||
.processDefinitionKey(parseProcessDefinitionKey(processDefinitionId))
|
||||
.list());
|
||||
} else {
|
||||
List<String> definitionIds = getProcessDefinitionIds.stream().filter(StringUtils::hasText).map(this::parseProcessDefinitionKey).collect(Collectors.toList());
|
||||
definitions.addAll(repositoryService.createNativeProcessDefinitionQuery()
|
||||
.sql("SELECT * FROM ACT_RE_PROCDEF WHERE KEY_ IN " + definitionIds.stream().map(i -> "'" + i + "'").collect(Collectors.joining(",", "(", ")")))
|
||||
.list());
|
||||
}
|
||||
|
||||
|
||||
if (CollectionUtils.isEmpty(definitions)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
Optional<ProcessDefinition> first = definitions.stream().filter(i -> i.getTenantId().equals(tenantId))
|
||||
.max(Comparator.comparing(ProcessDefinition::getVersion));
|
||||
if (first.isPresent()) {
|
||||
processDefinition = first.get();
|
||||
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
|
||||
Model model = commandExecutor.execute(new CustomGetModelByDefinitionIdCmd(processDefinition.getId()));
|
||||
BpmnModelExtVO modelStatus = extAxReModelService.getStatusByModelId(model.getId());
|
||||
if (Objects.equals(0, modelStatus.getStatus())) {
|
||||
processDefinition = definitions.stream().filter(i -> i.getTenantId().equals(NO_TENANT_ID)).max(Comparator.comparing(ProcessDefinition::getVersion)).get();
|
||||
// 按 key 分组,每组取 version 最大的 ProcessDefinition
|
||||
Map<String, List<ProcessDefinition>> maxVersionMap = definitions.stream()
|
||||
// .filter(i -> i.getTenantId().equals(tenantId))
|
||||
.collect(Collectors.groupingBy(
|
||||
ProcessDefinition::getKey,
|
||||
Collectors.toList()));
|
||||
|
||||
maxVersionMap.forEach((k, definitionList) -> {
|
||||
Optional<ProcessDefinition> first = definitionList.stream().filter(i -> Objects.equals(i.getKey(), k)).filter(i -> i.getTenantId().equals(tenantId)).findFirst();
|
||||
if (first.isPresent()) {
|
||||
ProcessDefinition processDefinition = first.get();
|
||||
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
|
||||
Model model = commandExecutor.execute(new CustomGetModelByDefinitionIdCmd(processDefinition.getId()));
|
||||
BpmnModelExtVO modelStatus = extAxReModelService.getStatusByModelId(model.getId());
|
||||
if (Objects.equals(0, modelStatus.getStatus())) {
|
||||
processDefinitions.add(definitions.stream()
|
||||
.filter(i -> Objects.equals(i.getKey(), k))
|
||||
.filter(i -> i.getTenantId().equals(NO_TENANT_ID))
|
||||
.max(Comparator.comparing(ProcessDefinition::getVersion)).get());
|
||||
}
|
||||
} else {
|
||||
processDefinitions.add(first.orElseGet(() -> definitions.stream()
|
||||
.filter(i -> Objects.equals(i.getKey(), k))
|
||||
.filter(i -> i.getTenantId().equals(NO_TENANT_ID))
|
||||
.max(Comparator.comparing(ProcessDefinition::getVersion)).get()));
|
||||
}
|
||||
} else {
|
||||
processDefinition = first.orElseGet(() -> definitions.stream().filter(i -> i.getTenantId().equals(NO_TENANT_ID)).max(Comparator.comparing(ProcessDefinition::getVersion)).get());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ExtAxModelDoc query = new ExtAxModelDoc();
|
||||
query.setModelKey(processDefinition.getKey());
|
||||
if (Objects.equals(Boolean.TRUE, filterEnable)) {
|
||||
query.setStatus(filterEnable);
|
||||
List<ExtAxModelDoc> docs = new ArrayList<>();
|
||||
if (!CollectionUtils.isEmpty(processDefinitions)) {
|
||||
for (ProcessDefinition processDefinition : processDefinitions) {
|
||||
ExtAxModelDoc query = new ExtAxModelDoc();
|
||||
query.setModelKey(processDefinition.getKey());
|
||||
if (Objects.equals(Boolean.TRUE, filterEnable)) {
|
||||
query.setStatus(filterEnable);
|
||||
}
|
||||
query.setTenantId(processDefinition.getTenantId());
|
||||
query.setTempFile(false);
|
||||
docs.addAll(extAxModelDocMapper.selectList(buildQueryWrapper(query)));
|
||||
}
|
||||
}
|
||||
query.setTenantId(processDefinition.getTenantId());
|
||||
query.setTempFile(false);
|
||||
List<ExtAxModelDoc> docs = extAxModelDocMapper.selectList(buildQueryWrapper(query));
|
||||
|
||||
if (filterSelect) {
|
||||
docs = docs.stream().filter(i -> enableDocIds.contains(i.getId())).collect(Collectors.toList());
|
||||
@ -167,7 +200,7 @@ public class CustomGetModelDocsCmd implements Command<List<DocBaseVO>> {
|
||||
return BeanMapper.copyList(docs, DocBaseVO.class, (s, t) -> t.setFileType(FileTypeEnum.valueOfType(s.getFileType())));
|
||||
}
|
||||
|
||||
private String parseProcessDefinitionKey() {
|
||||
private String parseProcessDefinitionKey(String processDefinitionId) {
|
||||
if (StringUtils.hasText(processDefinitionId)) {
|
||||
return processDefinitionId.split(":")[0];
|
||||
}
|
||||
@ -175,7 +208,7 @@ public class CustomGetModelDocsCmd implements Command<List<DocBaseVO>> {
|
||||
}
|
||||
|
||||
private void check() {
|
||||
if (!StringUtils.hasText(processInstanceId) && !StringUtils.hasText(processDefinitionId)) {
|
||||
if (!StringUtils.hasText(processInstanceId) && (!StringUtils.hasText(processDefinitionId)) && CollectionUtils.isEmpty(getProcessDefinitionIds)) {
|
||||
throw new WorkflowEngineException(MODEL_FILE_QUERY_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ public class ExtAxModelDocServiceImpl implements ExtAxModelDocService {
|
||||
public List<DocBaseVO> docList(DocQueryDTO dto) {
|
||||
CommandExecutor commandExecutor = springProcessEngineConfiguration.getCommandExecutor();
|
||||
return commandExecutor.execute(new CustomGetModelDocsCmd(dto.getProcessInstanceId(),
|
||||
dto.getProcessDefinitionKey(), dto.getTenantId(), extAxModelDocMapper, extAxReModelService));
|
||||
dto.getProcessDefinitionKey(), dto.getProcessDefinitionKeys(), dto.getTenantId(), extAxModelDocMapper, extAxReModelService));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -511,7 +511,7 @@ public class BpmnProcessModelController implements ProcessModelApi {
|
||||
@Operation(summary = "根据业务 ID 获取模型文档列表,自动适配公共模板和代运营")
|
||||
@PostMapping(value = "/doc/list")
|
||||
public CommonResponse<List<DocBaseVO>> docList(@Validated @RequestBody DocQueryDTO dto) {
|
||||
if (!StringUtils.hasText(dto.getProcessInstanceId()) && !StringUtils.hasText(dto.getProcessDefinitionKey())) {
|
||||
if (!StringUtils.hasText(dto.getProcessInstanceId()) && (!StringUtils.hasText(dto.getProcessDefinitionKey()) && CollectionUtils.isEmpty(dto.getProcessDefinitionKeys()))) {
|
||||
throw new WorkflowEngineException(MODEL_FILE_QUERY_ERROR);
|
||||
}
|
||||
return success(modelDocService.docList(dto));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user