add - 新增处理审批按钮权限的逻辑

This commit is contained in:
wangli 2023-11-29 11:22:45 +08:00
parent 2528b0cfb5
commit 9688485af4
4 changed files with 36 additions and 9 deletions

View File

@ -1,6 +1,7 @@
package cn.axzo.workflow.common.model.response.bpmn.process;
import cn.axzo.workflow.common.enums.BpmnFlowNodeMode;
import cn.axzo.workflow.common.model.request.bpmn.BpmnButtonConf;
import lombok.Data;
import lombok.experimental.Accessors;
@ -34,5 +35,10 @@ public class ProcessNodeDetailVO {
*/
private String formKey;
/**
* 按钮配置信息,内部已计算兜底配置
*/
private BpmnButtonConf buttonConf;
}

View File

@ -18,6 +18,7 @@ import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.Process;
import org.flowable.bpmn.model.ReceiveTask;
import org.flowable.bpmn.model.ServiceTask;
import org.flowable.bpmn.model.Task;
import org.flowable.bpmn.model.UserTask;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
@ -90,9 +91,11 @@ public final class BpmnMetaParserHelper {
}
public static Optional<BpmnButtonConf> getButtonConfig(Process process) {
List<ExtensionElement> elements = process.getExtensionElements().getOrDefault(CONFIG_BUTTON,
Collections.emptyList());
if (CollectionUtils.isEmpty(elements)) {
return parseButtonConfig(process.getExtensionElements().getOrDefault(CONFIG_BUTTON, Collections.emptyList()));
}
private static Optional<BpmnButtonConf> parseButtonConfig(List<ExtensionElement> elements) {
if (CollectionUtils.isEmpty(elements) || CollectionUtils.isEmpty(elements.get(0).getChildElements())) {
return Optional.empty();
}
BpmnButtonConf conf = new BpmnButtonConf();
@ -112,6 +115,26 @@ public final class BpmnMetaParserHelper {
return Optional.of(conf);
}
public static Optional<BpmnButtonConf> getButtonConfig(Process process, String taskDefinitionKey) {
if (StringUtils.hasLength(taskDefinitionKey)) {
Task task = (Task) process.getFlowElement(taskDefinitionKey);
if (Objects.isNull(task)) {
return getButtonConfig(process);
} else {
Optional<BpmnButtonConf> optConfig =
parseButtonConfig(task.getExtensionElements().getOrDefault(CONFIG_BUTTON,
Collections.emptyList()));
if (optConfig.isPresent()) {
return optConfig;
} else {
return getButtonConfig(process);
}
}
} else {
return getButtonConfig(process);
}
}
private static void buildButtonMetaInfo(List<ExtensionElement> v, List<BpmnButtonMetaInfo> buttonMetaInfos) {
v.get(0).getChildElements().get(CONFIG_BUTTON_META).forEach(i -> {
BpmnButtonMetaInfo buttonMetaInfo = new BpmnButtonMetaInfo();

View File

@ -18,6 +18,7 @@ import cn.axzo.workflow.common.model.response.bpmn.process.ProcessNodeDetailVO;
import cn.axzo.workflow.core.common.enums.BpmnProcessTaskResultEnum;
import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
import cn.axzo.workflow.core.common.utils.BpmnCollectionUtils;
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
import cn.axzo.workflow.core.service.BpmnProcessDefinitionService;
import cn.axzo.workflow.core.service.BpmnProcessInstanceService;
import cn.axzo.workflow.core.service.converter.BpmnHistoricProcessInstanceConverter;
@ -558,10 +559,13 @@ public class BpmnProcessInstanceServiceImpl implements BpmnProcessInstanceServic
}
List<FlowElement> flowElements = forecastService.performProcessForecasting(processInstanceId, instance);
BpmnModel bpmnModel = repositoryService.getBpmnModel(instance.getProcessDefinitionId());
List<ProcessNodeDetailVO> resultList = new ArrayList<>(flowElements.size() + 1);
flowElements.stream().filter(i -> (i instanceof UserTask || i instanceof ReceiveTask || i instanceof ServiceTask))
.forEach(i -> {
ProcessNodeDetailVO node = new ProcessNodeDetailVO();
BpmnMetaParserHelper.getButtonConfig(bpmnModel.getMainProcess(), i.getId())
.ifPresent(node::setButtonConf);
if (i instanceof UserTask) {
UserTask userTask = (UserTask) i;
node.setId(userTask.getId())

View File

@ -76,7 +76,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -533,9 +532,6 @@ public class BpmnProcessTaskServiceImpl implements BpmnProcessTaskService {
Map<String, List<Attachment>> attachmentByTaskIdMap = taskService.getProcessInstanceAttachments(processInstanceId).stream()
.collect(Collectors.groupingBy(Attachment::getTaskId));
Set<String> taskDefinitionKeys = new HashSet<>();
int count = 0;
BpmnProcessInstanceResultEnum processBusinessStatus = valueOfStatus(instance.getBusinessStatus());
for (BpmnHistoricTaskInstanceVO vo : vos) {
vo.setResult(processBusinessStatus);
@ -543,7 +539,6 @@ public class BpmnProcessTaskServiceImpl implements BpmnProcessTaskService {
// 只有拒绝时, 为指定的 taskId 设置过拒绝变量
vo.setResult((BpmnProcessInstanceResultEnum) instance.getProcessVariables().getOrDefault(TASK_COMPLETE_OPERATION_TYPE + vo.getTaskId(), APPROVED));
}
taskDefinitionKeys.add(vo.getTaskDefinitionKey());
List<Comment> taskComments = commentByTaskIdMap.getOrDefault(vo.getTaskId(), Collections.emptyList());
Optional<Comment> advice = taskComments.stream().filter(i -> Objects.equals(i.getUserId(),
@ -583,7 +578,6 @@ public class BpmnProcessTaskServiceImpl implements BpmnProcessTaskService {
(BpmnTaskDelegateAssigner) assginerSnapshot.getValue() : null;
vo.setAssignee(Objects.isNull(assigner) ? "" : assigner.getAssignee());
vo.setAssigneeSnapshot(assigner);
count++;
}
return vos;
}