update - 完善发送待办时,发起人/历史审批人/抄送人相关的查找比对逻辑

This commit is contained in:
wangli 2024-04-24 11:18:38 +08:00
parent a422b879a9
commit 3b1a178afb
3 changed files with 114 additions and 1 deletions

View File

@ -157,6 +157,7 @@ public class CustomCarbonCopyUserSelectorCmd implements Command<List<BpmnTaskDel
}
break;
case approver:
// 历史真正有同意和驳回动作的人
List<HistoricTaskInstance> taskInstances = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId)
// .includeProcessVariables()
@ -189,7 +190,6 @@ public class CustomCarbonCopyUserSelectorCmd implements Command<List<BpmnTaskDel
}
}
});
// 历史真正有同意和驳回动作的人
break;
case ent_initiator_leader:
case project_initiator_leader:

View File

@ -1,10 +1,16 @@
package cn.axzo.workflow.core.engine.cmd.helper;
import cn.axzo.workflow.common.enums.BpmnFlowNodeType;
import cn.axzo.workflow.common.model.request.bpmn.task.AttachmentDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
import cn.axzo.workflow.common.model.response.bpmn.task.BpmnHistoricTaskInstanceVO;
import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
import cn.axzo.workflow.core.repository.entity.ExtAxHiTaskInst;
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
import cn.axzo.workflow.core.service.converter.BpmnHistoricTaskInstanceConverter;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.Process;
import org.flowable.common.engine.impl.cfg.IdGenerator;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.common.engine.impl.interceptor.CommandContext;
@ -17,6 +23,7 @@ import org.flowable.engine.impl.persistence.entity.AttachmentEntity;
import org.flowable.engine.impl.persistence.entity.CommentEntity;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
import org.flowable.engine.runtime.Execution;
import org.flowable.engine.task.Attachment;
import org.flowable.engine.task.Comment;
@ -26,10 +33,12 @@ import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.service.impl.persistence.entity.HistoricTaskInstanceEntity;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl;
import org.flowable.variable.api.history.HistoricVariableInstance;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -42,6 +51,8 @@ import java.util.stream.Collectors;
import static cn.axzo.workflow.common.constant.BpmnConstants.COMMENT_TYPE_ADVICE;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO;
import static cn.axzo.workflow.common.constant.BpmnConstants.NO_ASSIGNEE;
import static cn.axzo.workflow.common.constant.BpmnConstants.OLD_INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT;
import static cn.axzo.workflow.common.constant.BpmnConstants.TASK_COMPLETE_OPERATION_TYPE;
import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.PROCESSING;
import static cn.axzo.workflow.core.common.code.BpmnTaskRespCode.ASSIGNEE_HAS_BEEN_EXISTS;
@ -353,4 +364,73 @@ public class CustomTaskHelper {
.values());
}
public static List<BpmnTaskDelegateAssigner> getHistoryOperationUsers(CommandContext commandContext, String processInstanceId,
BpmnHistoricTaskInstanceConverter historicTaskInstanceConverter,
String serviceVersion) {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
HistoryService historyService = processEngineConfiguration.getHistoryService();
List<BpmnTaskDelegateAssigner> result = new ArrayList<>();
List<HistoricTaskInstance> taskInstances = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId)
.orderByHistoricTaskInstanceStartTime()
.desc().list();
List<BpmnHistoricTaskInstanceVO> vos = historicTaskInstanceConverter.toVosSkipSystemOperation(taskInstances,
serviceVersion);
Map<String, HistoricVariableInstance> variableInstanceMap =
// 不能使用框架提供的历史变量 API 查询, BUG
historyService.createNativeHistoricVariableInstanceQuery()
.sql("select * from ACT_HI_VARINST t where t.proc_inst_id_= #{processInstanceId}")
.parameter("processInstanceId", processInstanceId)
.list().stream()
.collect(Collectors.toMap(HistoricVariableInstance::getVariableName,
Function.identity(), (s, t) -> s));
vos.forEach(vo -> {
HistoricVariableInstance assginerSnapshot =
variableInstanceMap.getOrDefault(INTERNAL_TASK_RELATION_ASSIGNEE_INFO + vo.getTaskId(),
null);
if (Objects.isNull(assginerSnapshot)) {
assginerSnapshot =
variableInstanceMap.getOrDefault(OLD_INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT + vo.getTaskId(), null);
}
if (Objects.nonNull(assginerSnapshot)) {
BpmnTaskDelegateAssigner assigner = BpmnTaskDelegateAssigner.toObjectCompatible(assginerSnapshot.getValue());
if (Objects.nonNull(assigner) && !Objects.equals(assigner.buildAssigneeId(), NO_ASSIGNEE)) {
result.add(assigner);
}
}
});
return result;
}
public static List<BpmnTaskDelegateAssigner> getAllCarbonUsers(CommandContext commandContext, String processInstanceId, String processDefinitionId) {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
Process process = ProcessDefinitionUtil.getProcess(processDefinitionId);
List<String> taskDefinitionKeys = process.getFlowElements().stream()
.filter(i -> Objects.equals(BpmnMetaParserHelper.getNodeType(i).orElse(null), BpmnFlowNodeType.NODE_CARBON_COPY))
.map(FlowElement::getId)
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(taskDefinitionKeys)) {
return Collections.emptyList();
}
List<HistoricVariableInstance> variableInstances = processEngineConfiguration.getHistoryService().createHistoricVariableInstanceQuery()
.variableNameLike(INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT)
.processInstanceId(processInstanceId)
.list();
if (CollectionUtils.isEmpty(variableInstances)) {
return Collections.emptyList();
}
List<BpmnTaskDelegateAssigner> result = new ArrayList<>();
taskDefinitionKeys.forEach(j -> {
variableInstances.stream()
.filter(i -> Objects.equals(i.getVariableName(), INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT + j))
.findFirst().ifPresent(i -> {
result.addAll((List<BpmnTaskDelegateAssigner>) i.getValue());
});
});
return result;
}
}

View File

@ -10,15 +10,18 @@ import cn.axzo.workflow.common.model.response.bpmn.process.BpmnProcessInstanceVO
import cn.axzo.workflow.common.model.response.mq.MessagePushDTO;
import cn.axzo.workflow.core.common.context.NoticeOperationContext;
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
import cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper;
import cn.axzo.workflow.core.engine.event.MessagePushEvent;
import cn.axzo.workflow.core.listener.AbstractBpmnEventListener;
import cn.axzo.workflow.core.listener.BpmnMessagePushEventListener;
import cn.axzo.workflow.core.service.BpmnProcessInstanceService;
import cn.axzo.workflow.core.service.converter.BpmnHistoricTaskInstanceConverter;
import cn.hutool.json.JSONUtil;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.Process;
import org.flowable.engine.HistoryService;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.springframework.beans.factory.annotation.Value;
@ -92,6 +95,10 @@ public class RocketMqMessagePushEventListener extends AbstractBpmnEventListener<
private HistoryService historyService;
@Value("${sendMq:true}")
private Boolean sendMQ;
@Resource
private BpmnHistoricTaskInstanceConverter historicTaskInstanceConverter;
@Resource
private String serviceVersion;
private static final List<String> REMOVE_KEYS = Lists.newArrayList(
INTERNAL_INITIATOR,
@ -161,9 +168,19 @@ public class RocketMqMessagePushEventListener extends AbstractBpmnEventListener<
.ifPresent(buttonConf -> {
BpmnProcessInstanceVO instance = getContext().getInstanceVO(() -> getBpmnProcessInstanceVO(event));
if (bpmnTaskDelegateAssigner.comparePersonIdToOther(instance.getInitiator())) {
// 发起人
buttons.addAll(buttonConf.getInitiator());
}
// 当前审批人
buttons.addAll(buttonConf.getCurrent());
if (isHistoryOperationUser(instance, bpmnTaskDelegateAssigner)) {
buttons.addAll(buttonConf.getHistory());
}
if (isCarbonUsers(instance, bpmnTaskDelegateAssigner)) {
buttons.addAll(buttonConf.getCarbonCopy());
}
});
}
dto.setButtons(buttons);
@ -176,6 +193,22 @@ public class RocketMqMessagePushEventListener extends AbstractBpmnEventListener<
}
}
private boolean isHistoryOperationUser(BpmnProcessInstanceVO instance, BpmnTaskDelegateAssigner bpmnTaskDelegateAssigner) {
if (Objects.isNull(bpmnTaskDelegateAssigner) || Objects.isNull(instance)) {
return false;
}
List<BpmnTaskDelegateAssigner> users = CustomTaskHelper.getHistoryOperationUsers(CommandContextUtil.getCommandContext(), instance.getId(), historicTaskInstanceConverter, serviceVersion);
return users.stream().anyMatch(bpmnTaskDelegateAssigner::comparePersonIdToOther);
}
private boolean isCarbonUsers(BpmnProcessInstanceVO instance, BpmnTaskDelegateAssigner bpmnTaskDelegateAssigner) {
if (Objects.isNull(bpmnTaskDelegateAssigner) || Objects.isNull(instance)) {
return false;
}
List<BpmnTaskDelegateAssigner> users = CustomTaskHelper.getAllCarbonUsers(CommandContextUtil.getCommandContext(), instance.getId(), instance.getProcessDefinitionId());
return users.stream().anyMatch(bpmnTaskDelegateAssigner::comparePersonIdToOther);
}
@Override
public void onPendingComplete(MessagePushEvent event) {
if (Objects.isNull(event.getNoticeConfig())