update - 调整工作流内部的一些逻辑
This commit is contained in:
parent
af90d68ea1
commit
e83715ae84
@ -25,8 +25,12 @@ public interface BpmConstants {
|
||||
String INTERNAL_PROCESS_TYPE_CANCEL = "_INTERNAL_PROCESS_TYPE_CANCEL";
|
||||
String INTERNAL_PROCESS_TYPE_REJECT = "_INTERNAL_PROCESS_TYPE_REJECT";
|
||||
String INTERNAL_SPECIFY_NEXT_APPROVER = "_INTERNAL_SPECIFY_NEXT_APPROVER";
|
||||
String INTERNAL_TASK_RELATION_ASSIGNEE_INFO = "[_ASSIGNEE_INFO_]";
|
||||
// String INTERNAL_TASK_RELATION_ASSIGNEE_INFO = "[_ASSIGNEE_INFO_]";
|
||||
// 用于多实例审批时,保存计算出来的审批人
|
||||
String INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO = "[_ASSIGNEE_LIST_INFO_]";
|
||||
// 单任务节点,
|
||||
String INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT = "[_ASSIGNEE_INFO_SNAPSHOT_]";
|
||||
String INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT = "[_ASSIGNEE_LIST_INFO_SNAPSHOT_]";
|
||||
|
||||
|
||||
String PROCESS_PREFIX = "Flowable";
|
||||
|
||||
@ -35,7 +35,6 @@ public class BpmnTaskAuditDTO {
|
||||
/**
|
||||
* 下级审批人
|
||||
*/
|
||||
@ApiModelProperty(value = "下级审批人", notes = "可为空,定义选择审批人,如果不为空,则覆盖下一级任务的审核人")
|
||||
@NotNull(message = "下级审批不能为空", groups = ValidGroup.Insert.class)
|
||||
@ApiModelProperty(value = "下级审批人信息", notes = "可为空,定义选择审批人,如果不为空,则覆盖下一级任务的审核人")
|
||||
private BpmnTaskDelegateAssigner nextApprover;
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package cn.axzo.workflow.common.model.response.bpmn.task;
|
||||
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
@ -29,8 +30,7 @@ public class BpmnTaskInstanceVO {
|
||||
@ApiModelProperty(value = "任务归属人")
|
||||
private String owner;
|
||||
@ApiModelProperty(value = "任务审批人")
|
||||
// TODO 调整审批人
|
||||
private String assignee;
|
||||
private BpmnTaskDelegateAssigner assigner;
|
||||
@ApiModelProperty(value = "任务创建时间")
|
||||
private Date createTime;
|
||||
@ApiModelProperty(value = "租户")
|
||||
|
||||
@ -38,6 +38,7 @@ import java.util.stream.Collectors;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.AND_SIGN_EXPRESSION;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.BPM_ALLOW_SKIP_USER_TASK;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.END_EVENT_ID;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.OR_SIGN_EXPRESSION;
|
||||
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.CONVERTOR_META_DATA_FORMAT_ERROR;
|
||||
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.CONVERTOR_UNKNOW_NODE_TYPE;
|
||||
@ -373,7 +374,7 @@ public class BpmTransformUtil {
|
||||
MultiInstanceLoopCharacteristics multiInstanceLoopCharacteristics =
|
||||
new MultiInstanceLoopCharacteristics();
|
||||
// 审批人集合参数
|
||||
multiInstanceLoopCharacteristics.setInputDataItem(userTask.getId() + "_assigneeList");
|
||||
multiInstanceLoopCharacteristics.setInputDataItem(INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO + userTask.getId());
|
||||
// 迭代集合
|
||||
multiInstanceLoopCharacteristics.setElementVariable("assigneeName");
|
||||
// 并行
|
||||
|
||||
@ -11,22 +11,22 @@ public interface BpmTaskEventListener extends Ordered {
|
||||
/**
|
||||
* 用户任务已创建,未指派审核人
|
||||
*/
|
||||
void onCreated(DelegateTask delegateTask);
|
||||
default void onCreated(DelegateTask delegateTask) {}
|
||||
|
||||
/**
|
||||
* 用户任务已指派审核人
|
||||
*/
|
||||
void onAssigned(DelegateTask delegateTask);
|
||||
default void onAssigned(DelegateTask delegateTask) {}
|
||||
|
||||
/**
|
||||
* 用户任务已通过
|
||||
* <p>
|
||||
* 仅审核通过一个用户任务时触发, 如果任务是拒绝了, 则直接走实例取消事件
|
||||
*/
|
||||
void onCompleted(DelegateTask delegateTask);
|
||||
default void onCompleted(DelegateTask delegateTask) {}
|
||||
|
||||
/**
|
||||
* 用户任务已删除
|
||||
*/
|
||||
void onDeleted(DelegateTask delegateTask);
|
||||
default void onDeleted(DelegateTask delegateTask) {}
|
||||
}
|
||||
|
||||
@ -27,7 +27,6 @@ public interface BpmnTaskConverter extends EntityConverter<BpmnTaskInstanceVO, T
|
||||
@Mapping(target = "taskDefinitionKey", source = "taskDefinitionKey")
|
||||
@Mapping(target = "name", source = "name")
|
||||
@Mapping(target = "owner", source = "owner")
|
||||
@Mapping(target = "assignee", source = "assignee")
|
||||
@Mapping(target = "createTime", source = "createTime")
|
||||
@Mapping(target = "tenantId", source = "tenantId")
|
||||
@Mapping(target = "formKey", source = "formKey")
|
||||
|
||||
@ -21,9 +21,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.BPM_ALLOW_SKIP_USER_TASK;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_SPECIFY_NEXT_APPROVER;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT;
|
||||
|
||||
|
||||
/**
|
||||
@ -43,9 +42,9 @@ public class EngineExecutionStartListener implements ExecutionListener {
|
||||
public void notify(DelegateExecution execution) {
|
||||
log.info("execution Start: {}", JSON.toJSONString(execution));
|
||||
String currentActivityId = execution.getCurrentActivityId();
|
||||
String variable = INTERNAL_TASK_RELATION_ASSIGNEE_INFO + currentActivityId;
|
||||
String variable = INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO + currentActivityId;
|
||||
List usersValue = (List) execution.getVariable(variable);
|
||||
if (usersValue == null) {
|
||||
if (CollectionUtils.isEmpty(usersValue)) {
|
||||
Process mainProcess = repositoryService.getBpmnModel(execution.getProcessDefinitionId()).getMainProcess();
|
||||
UserTask userTask = (UserTask) mainProcess.getFlowElement(currentActivityId);
|
||||
|
||||
@ -67,11 +66,6 @@ public class EngineExecutionStartListener implements ExecutionListener {
|
||||
for (BpmnTaskDelegateAssigner user : assigners) {
|
||||
assigneeIdList.add(user.buildAssigneeId());
|
||||
}
|
||||
|
||||
if (!userTask.hasMultiInstanceLoopCharacteristics()) {
|
||||
userTask.setAssignee("${assigneeUserId}");
|
||||
execution.setVariable("assigneeUserId", assigneeIdList.get(0));
|
||||
}
|
||||
// 审批人为空并且当前节点设置了自动跳过条件
|
||||
} else if (StringUtils.hasLength(userTask.getSkipExpression())) {
|
||||
// 自动通过的默认引擎参数必须设置为 true
|
||||
@ -79,10 +73,20 @@ public class EngineExecutionStartListener implements ExecutionListener {
|
||||
// 设置当前 UserTask 使用的 skip 表达式
|
||||
execution.setTransientVariable(BPM_ALLOW_SKIP_USER_TASK, true);
|
||||
}
|
||||
execution.setVariable(variable, assigneeIdList);
|
||||
// FIXME 这里的快照并不通用, 未考虑多人审批的情况
|
||||
execution.setVariable(INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT + currentActivityId,
|
||||
execution.getVariable(INTERNAL_SPECIFY_NEXT_APPROVER));
|
||||
|
||||
// UserTask 非多实例
|
||||
if (!userTask.hasMultiInstanceLoopCharacteristics()) {
|
||||
userTask.setAssignee(assigneeIdList.get(0));
|
||||
// remove by wangli, 暂时去除审批人变量, 通过上面直接赋值
|
||||
// execution.setVariable("assigneeUserId", assigneeIdList.get(0));
|
||||
|
||||
} else {
|
||||
// UserTask 多实例, 该变量用于引擎
|
||||
execution.setVariable(variable, assigneeIdList);
|
||||
}
|
||||
// 将当次审批节点下计算出来的人存储起来,方便后续对 task 保持审批人快照
|
||||
execution.setVariable(INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT + currentActivityId,
|
||||
assigners);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -246,10 +246,12 @@ public class BpmnProcessInstanceServiceImpl implements BpmnProcessInstanceServic
|
||||
}
|
||||
|
||||
dto.getVariables().put(INTERNAL_INITIATOR, dto.getInitiator());
|
||||
BpmnTaskDelegateAssigner nextApprover = dto.getNextApprover();
|
||||
nextApprover.setTenantId(StringUtils.isNotBlank(nextApprover.getTenantId()) ? nextApprover.getTenantId() :
|
||||
dto.getInitiator().getTenantId());
|
||||
dto.getVariables().put(INTERNAL_SPECIFY_NEXT_APPROVER, nextApprover);
|
||||
if (Objects.nonNull(dto.getNextApprover())) {
|
||||
BpmnTaskDelegateAssigner nextApprover = dto.getNextApprover();
|
||||
nextApprover.setTenantId(StringUtils.isNotBlank(nextApprover.getTenantId()) ? nextApprover.getTenantId() :
|
||||
dto.getInitiator().getTenantId());
|
||||
dto.getVariables().put(INTERNAL_SPECIFY_NEXT_APPROVER, nextApprover);
|
||||
}
|
||||
|
||||
// 创建流程实例
|
||||
// 设置流程实例的开始人,参考https://wenku.baidu.com/view/5538062e7a563c1ec5da50e2524de518964bd3f9.html
|
||||
|
||||
@ -44,6 +44,7 @@ import org.flowable.task.api.history.HistoricTaskInstanceQuery;
|
||||
import org.flowable.task.service.history.NativeHistoricTaskInstanceQuery;
|
||||
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
|
||||
import org.flowable.variable.api.history.HistoricVariableInstance;
|
||||
import org.flowable.variable.api.persistence.entity.VariableInstance;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@ -71,7 +72,6 @@ import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_END_USER_ID
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_END_USER_NAME;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_PROCESS_TYPE_REJECT;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_SPECIFY_NEXT_APPROVER;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.MULTI_INSTANCE_LOOP_COUNTER;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.NUMBER_OF_INSTANCES;
|
||||
@ -478,7 +478,13 @@ public class BpmnTaskServiceImpl implements BpmnTaskService {
|
||||
if (StringUtils.hasLength(tenantId)) {
|
||||
query.taskTenantId(tenantId);
|
||||
}
|
||||
return bpmnTaskConverter.toVos(query.list());
|
||||
List<BpmnTaskInstanceVO> vos = bpmnTaskConverter.toVos(query.list());
|
||||
List<String> snapshotTaskIds =
|
||||
vos.stream().map(i -> INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT + i.getTaskId()).collect(Collectors.toList());
|
||||
Map<String, VariableInstance> instanceMap = runtimeService.getVariableInstances(processInstanceId,
|
||||
snapshotTaskIds);
|
||||
vos.forEach(i -> i.setAssigner((BpmnTaskDelegateAssigner) instanceMap.get(INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT + i.getTaskId()).getValue()));
|
||||
return vos;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -535,18 +541,13 @@ public class BpmnTaskServiceImpl implements BpmnTaskService {
|
||||
if (Objects.isNull(dto.getTargetAssigner())) {
|
||||
taskService.setAssignee(task.getId(), "");
|
||||
runtimeService.removeVariable(task.getProcessInstanceId(), INTERNAL_SPECIFY_NEXT_APPROVER);
|
||||
runtimeService.removeVariable(task.getProcessInstanceId() + task.getTaskDefinitionKey(),
|
||||
INTERNAL_TASK_RELATION_ASSIGNEE_INFO);
|
||||
runtimeService.removeVariable(task.getProcessInstanceId() + task.getTaskDefinitionKey(),
|
||||
runtimeService.removeVariable(task.getProcessInstanceId() + task.getId(),
|
||||
INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT);
|
||||
} else {
|
||||
runtimeService.setVariable(task.getProcessInstanceId(), INTERNAL_SPECIFY_NEXT_APPROVER,
|
||||
dto.getTargetAssigner());
|
||||
runtimeService.setVariable(task.getProcessInstanceId(),
|
||||
INTERNAL_TASK_RELATION_ASSIGNEE_INFO + task.getTaskDefinitionKey(),
|
||||
dto.getTargetAssigner().buildAssigneeId());
|
||||
runtimeService.setVariable(task.getProcessInstanceId(),
|
||||
INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT + task.getTaskDefinitionKey(),
|
||||
INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT + task.getId(),
|
||||
dto.getTargetAssigner());
|
||||
|
||||
taskService.setAssignee(task.getId(), dto.getTargetAssigner().buildAssigneeId());
|
||||
|
||||
@ -6,9 +6,11 @@ import cn.axzo.workflow.core.deletage.BpmTaskDelegate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_SPECIFY_NEXT_APPROVER;
|
||||
@ -29,6 +31,69 @@ public class BpmnDefaultTaskDelegateImpl implements BpmTaskDelegate {
|
||||
Optional.ofNullable(delegateTask.getVariables().get(INTERNAL_SPECIFY_NEXT_APPROVER)).ifPresent(next -> {
|
||||
assigners.add((BpmnTaskDelegateAssigner) next);
|
||||
});
|
||||
|
||||
if (CollectionUtils.isEmpty(assigners)) {
|
||||
if (Objects.equals("NODE1694773129716_0.9426625492049914_1", delegateTask.getTaskDefinitionKey())) {
|
||||
// 或签
|
||||
BpmnTaskDelegateAssigner assigner1 = new BpmnTaskDelegateAssigner();
|
||||
assigner1.setAssignee("1");
|
||||
assigner1.setAssigneeType("5");
|
||||
assigner1.setAssignerName("或签人1");
|
||||
assigner1.setPersonId("100001");
|
||||
assigner1.setTenantId("296");
|
||||
assigners.add(assigner1);
|
||||
} else if (Objects.equals("NODE1695291557658_0.7106808048056956_1", delegateTask.getTaskDefinitionKey())) {
|
||||
// 会签节点
|
||||
BpmnTaskDelegateAssigner assigner1 = new BpmnTaskDelegateAssigner();
|
||||
assigner1.setAssignee("1");
|
||||
assigner1.setAssigneeType("5");
|
||||
assigner1.setAssignerName("会签人1");
|
||||
assigner1.setPersonId("100001");
|
||||
assigner1.setTenantId("296");
|
||||
assigners.add(assigner1);
|
||||
|
||||
BpmnTaskDelegateAssigner assigner2 = new BpmnTaskDelegateAssigner();
|
||||
assigner2.setAssignee("2");
|
||||
assigner2.setAssigneeType("5");
|
||||
assigner2.setAssignerName("会签人2");
|
||||
assigner2.setPersonId("100002");
|
||||
assigner2.setTenantId("296");
|
||||
assigners.add(assigner2);
|
||||
|
||||
BpmnTaskDelegateAssigner assigner3 = new BpmnTaskDelegateAssigner();
|
||||
assigner3.setAssignee("3");
|
||||
assigner3.setAssigneeType("5");
|
||||
assigner3.setAssignerName("会签人3");
|
||||
assigner3.setPersonId("100003");
|
||||
assigner3.setTenantId("296");
|
||||
assigners.add(assigner3);
|
||||
|
||||
BpmnTaskDelegateAssigner assigner4 = new BpmnTaskDelegateAssigner();
|
||||
assigner4.setAssignee("4");
|
||||
assigner4.setAssigneeType("5");
|
||||
assigner4.setAssignerName("会签人4");
|
||||
assigner4.setPersonId("100004");
|
||||
assigner4.setTenantId("296");
|
||||
assigners.add(assigner4);
|
||||
} else if (Objects.equals("NODE1694770290894_0.4227607475273871_1", delegateTask.getTaskDefinitionKey())) {
|
||||
// 或签节点
|
||||
BpmnTaskDelegateAssigner assigner1 = new BpmnTaskDelegateAssigner();
|
||||
assigner1.setAssignee("1");
|
||||
assigner1.setAssigneeType("5");
|
||||
assigner1.setAssignerName("或签人1");
|
||||
assigner1.setPersonId("100001");
|
||||
assigner1.setTenantId("296");
|
||||
assigners.add(assigner1);
|
||||
|
||||
BpmnTaskDelegateAssigner assigner2 = new BpmnTaskDelegateAssigner();
|
||||
assigner2.setAssignee("2");
|
||||
assigner2.setAssigneeType("5");
|
||||
assigner2.setAssignerName("或签人2");
|
||||
assigner2.setPersonId("100001");
|
||||
assigner2.setTenantId("296");
|
||||
assigners.add(assigner2);
|
||||
}
|
||||
}
|
||||
return assigners;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,17 @@
|
||||
package cn.axzo.workflow.server.controller.listener;
|
||||
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
|
||||
import cn.axzo.workflow.core.listener.BpmTaskEventListener;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.task.service.delegate.DelegateTask;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT;
|
||||
|
||||
/**
|
||||
* 自定义实现的流程监听器, 实现了 Ordered 接口
|
||||
@ -13,7 +22,7 @@ import org.flowable.task.service.delegate.DelegateTask;
|
||||
* @since 2023/9/25 18:50
|
||||
*/
|
||||
@Slf4j
|
||||
//@Component
|
||||
@Component
|
||||
public class CustomBpmTaskTaskEventListener implements BpmTaskEventListener {
|
||||
@Override
|
||||
public void onCreated(DelegateTask delegateTask) {
|
||||
@ -22,6 +31,17 @@ public class CustomBpmTaskTaskEventListener implements BpmTaskEventListener {
|
||||
|
||||
@Override
|
||||
public void onAssigned(DelegateTask delegateTask) {
|
||||
List<BpmnTaskDelegateAssigner> assignerList =
|
||||
(List<BpmnTaskDelegateAssigner>) delegateTask.getVariable(INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT + delegateTask.getTaskDefinitionKey());
|
||||
if (CollectionUtils.isEmpty(assignerList)) {
|
||||
return;
|
||||
}
|
||||
// identityId_identityType
|
||||
String assignee = delegateTask.getAssignee();
|
||||
assignerList.stream().filter(i -> Objects.equals(assignee, i.buildAssigneeId())).findFirst().ifPresent(i -> {
|
||||
// 保存每个 taskId 的审批人
|
||||
delegateTask.setVariable(INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT + delegateTask.getId(), i);
|
||||
});
|
||||
log.info("task assigned...");
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package cn.axzo.workflow.server.controller.listener;
|
||||
|
||||
import cn.axzo.framework.rocketmq.Event;
|
||||
import cn.axzo.framework.rocketmq.EventProducer;
|
||||
import cn.axzo.workflow.common.enums.ProcessInstanceEventEnum;
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
|
||||
import cn.axzo.workflow.common.model.response.mq.ProcessInstanceDTO;
|
||||
import cn.axzo.workflow.core.listener.BpmProcessEventListener;
|
||||
@ -19,7 +20,11 @@ import org.springframework.stereotype.Component;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_INITIATOR;
|
||||
import static cn.axzo.workflow.common.enums.ProcessInstanceEventEnum.*;
|
||||
import static cn.axzo.workflow.common.enums.ProcessInstanceEventEnum.PROCESS_INSTANCE_CANCELLED;
|
||||
import static cn.axzo.workflow.common.enums.ProcessInstanceEventEnum.PROCESS_INSTANCE_COMPLETED;
|
||||
import static cn.axzo.workflow.common.enums.ProcessInstanceEventEnum.PROCESS_INSTANCE_CREATED;
|
||||
import static cn.axzo.workflow.common.enums.ProcessInstanceEventEnum.PROCESS_INSTANCE_REJECTED;
|
||||
import static cn.axzo.workflow.common.enums.ProcessInstanceEventEnum.PROCESS_INSTANCE_STARTED;
|
||||
|
||||
|
||||
/**
|
||||
@ -61,13 +66,7 @@ public class RocketMqBpmProcessEventListener implements BpmProcessEventListener
|
||||
.setBusinessKey(((ExecutionEntityImpl) event.getEntity()).getBusinessKey())
|
||||
.setBusinessProcessInstanceName(((ExecutionEntityImpl) event.getEntity()).getName());
|
||||
log.info("RocketMqBpmProcessEventListener#onCreated MQ.Data: {}", JSON.toJSONString(dto));
|
||||
eventProducer.send(Event.builder()
|
||||
.shardingKey(event.getProcessInstanceId())
|
||||
.eventCode(PROCESS_INSTANCE_CREATED.getEventCode())
|
||||
.targetId(event.getProcessInstanceId())
|
||||
.targetType(PROCESS_INSTANCE_CREATED.getTag())
|
||||
.data(dto)
|
||||
.build());
|
||||
sendMessageQueue(dto, PROCESS_INSTANCE_CREATED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -95,13 +94,7 @@ public class RocketMqBpmProcessEventListener implements BpmProcessEventListener
|
||||
.setBusinessKey(((ExecutionEntityImpl) event.getEntity()).getProcessInstance().getBusinessKey())
|
||||
.setBusinessProcessInstanceName(((ExecutionEntityImpl) event.getEntity()).getProcessInstance().getName());
|
||||
log.info("RocketMqBpmProcessEventListener#onStarted MQ.Data: {}", JSON.toJSONString(dto));
|
||||
eventProducer.send(Event.builder()
|
||||
.shardingKey(((ExecutionEntityImpl) event.getEntity()).getProcessInstanceId())
|
||||
.eventCode(PROCESS_INSTANCE_STARTED.getEventCode())
|
||||
.targetId(((ExecutionEntityImpl) event.getEntity()).getProcessInstanceId())
|
||||
.targetType(PROCESS_INSTANCE_STARTED.getTag())
|
||||
.data(dto)
|
||||
.build());
|
||||
sendMessageQueue(dto, PROCESS_INSTANCE_STARTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -129,13 +122,7 @@ public class RocketMqBpmProcessEventListener implements BpmProcessEventListener
|
||||
.setBusinessProcessInstanceName(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getName())
|
||||
.setCancelReason(String.valueOf(event.getCause()));
|
||||
log.info("RocketMqBpmProcessEventListener#onCancelled MQ.Data: {}", JSON.toJSONString(dto));
|
||||
eventProducer.send(Event.builder()
|
||||
.shardingKey(event.getProcessInstanceId())
|
||||
.eventCode(PROCESS_INSTANCE_CANCELLED.getEventCode())
|
||||
.targetId(event.getProcessInstanceId())
|
||||
.targetType(PROCESS_INSTANCE_CANCELLED.getTag())
|
||||
.data(dto)
|
||||
.build());
|
||||
sendMessageQueue(dto, PROCESS_INSTANCE_CANCELLED);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,13 +155,7 @@ public class RocketMqBpmProcessEventListener implements BpmProcessEventListener
|
||||
.setBusinessProcessInstanceName(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getName())
|
||||
.setCancelReason(String.valueOf(event.getCause()));
|
||||
log.info("RocketMqBpmProcessEventListener#onRejected MQ.Data: {}", JSON.toJSONString(dto));
|
||||
eventProducer.send(Event.builder()
|
||||
.shardingKey(event.getProcessInstanceId())
|
||||
.eventCode(PROCESS_INSTANCE_REJECTED.getEventCode())
|
||||
.targetId(event.getProcessInstanceId())
|
||||
.targetType(PROCESS_INSTANCE_REJECTED.getTag())
|
||||
.data(dto)
|
||||
.build());
|
||||
sendMessageQueue(dto, PROCESS_INSTANCE_REJECTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -184,7 +165,7 @@ public class RocketMqBpmProcessEventListener implements BpmProcessEventListener
|
||||
JSON.toJSONString(event));
|
||||
}
|
||||
Deployment deployment =
|
||||
repositoryService.createDeploymentQuery().deploymentId(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getDeploymentId())
|
||||
repositoryService.createDeploymentQuery().deploymentId(((ExecutionEntityImpl) event.getEntity()).getDeploymentId())
|
||||
.singleResult();
|
||||
ProcessInstanceDTO dto = new ProcessInstanceDTO()
|
||||
.setType(PROCESS_INSTANCE_COMPLETED)
|
||||
@ -192,20 +173,25 @@ public class RocketMqBpmProcessEventListener implements BpmProcessEventListener
|
||||
.setProcessInstanceId(event.getProcessInstanceId())
|
||||
.setCurrentElementKey("取消流程实例无节点信息")
|
||||
.setProcessDefinitionId(event.getProcessDefinitionId())
|
||||
.setProcessDefinitionKey(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getProcessDefinitionKey())
|
||||
.setProcessDefinitionVersion(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getProcessDefinitionVersion())
|
||||
.setInitiator(((FlowableProcessCancelledEventImpl) event).getExecution().getVariable(INTERNAL_INITIATOR, BpmnTaskDelegateAssigner.class))
|
||||
.setVariables(((FlowableProcessCancelledEventImpl) event).getExecution().getVariables())
|
||||
.setStartTime(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getStartTime())
|
||||
.setTenantId(((FlowableProcessCancelledEventImpl) event).getExecution().getTenantId())
|
||||
.setBusinessKey(((FlowableProcessCancelledEventImpl) event).getExecution().getProcessInstanceBusinessKey())
|
||||
.setBusinessProcessInstanceName(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getName());
|
||||
.setProcessDefinitionKey(((ExecutionEntityImpl) event.getEntity()).getProcessDefinitionKey())
|
||||
.setProcessDefinitionVersion(((ExecutionEntityImpl) event.getEntity()).getProcessDefinitionVersion())
|
||||
.setInitiator(((ExecutionEntityImpl) event.getEntity()).getVariable(INTERNAL_INITIATOR,
|
||||
BpmnTaskDelegateAssigner.class))
|
||||
.setVariables(((ExecutionEntityImpl) event.getEntity()).getVariables())
|
||||
.setStartTime(((ExecutionEntityImpl) event.getEntity()).getStartTime())
|
||||
.setTenantId(((ExecutionEntityImpl) event.getEntity()).getTenantId())
|
||||
.setBusinessKey(((ExecutionEntityImpl) event.getEntity()).getProcessInstanceBusinessKey())
|
||||
.setBusinessProcessInstanceName(((ExecutionEntityImpl) event.getEntity()).getName());
|
||||
log.info("RocketMqBpmProcessEventListener#onCompleted MQ.Data: {}", JSON.toJSONString(dto));
|
||||
sendMessageQueue(dto, PROCESS_INSTANCE_COMPLETED);
|
||||
}
|
||||
|
||||
private void sendMessageQueue(ProcessInstanceDTO dto, ProcessInstanceEventEnum eventEnum) {
|
||||
eventProducer.send(Event.builder()
|
||||
.shardingKey(event.getProcessInstanceId())
|
||||
.eventCode(PROCESS_INSTANCE_COMPLETED.getEventCode())
|
||||
.targetId(event.getProcessInstanceId())
|
||||
.targetType(PROCESS_INSTANCE_COMPLETED.getTag())
|
||||
.shardingKey(dto.getProcessInstanceId())
|
||||
.eventCode(eventEnum.getEventCode())
|
||||
.targetId(dto.getProcessInstanceId())
|
||||
.targetType(eventEnum.getTag())
|
||||
.data(dto)
|
||||
.build());
|
||||
}
|
||||
|
||||
@ -17,8 +17,11 @@ import org.springframework.stereotype.Component;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_INITIATOR;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_SPECIFY_NEXT_APPROVER;
|
||||
import static cn.axzo.workflow.common.enums.ProcessTaskEventEnum.*;
|
||||
import static cn.axzo.workflow.common.constant.BpmConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT;
|
||||
import static cn.axzo.workflow.common.enums.ProcessTaskEventEnum.PROCESS_TASK_ASSIGNED;
|
||||
import static cn.axzo.workflow.common.enums.ProcessTaskEventEnum.PROCESS_TASK_COMPLETED;
|
||||
import static cn.axzo.workflow.common.enums.ProcessTaskEventEnum.PROCESS_TASK_CREATED;
|
||||
import static cn.axzo.workflow.common.enums.ProcessTaskEventEnum.PROCESS_TASK_DELETED;
|
||||
|
||||
|
||||
/**
|
||||
@ -94,7 +97,7 @@ public class RocketMqBpmTaskEventListener implements BpmTaskEventListener {
|
||||
.setCurrentElementName(delegateTask.getName())
|
||||
.setProcessDefinitionId(delegateTask.getProcessDefinitionId())
|
||||
.setInitiator(delegateTask.getVariable(INTERNAL_INITIATOR, BpmnTaskDelegateAssigner.class))
|
||||
.setApprover(delegateTask.getVariable(INTERNAL_SPECIFY_NEXT_APPROVER, BpmnTaskDelegateAssigner.class))
|
||||
.setApprover(delegateTask.getVariable(INTERNAL_TASK_RELATION_ASSIGNEE_INFO_SNAPSHOT + delegateTask.getId(), BpmnTaskDelegateAssigner.class))
|
||||
.setVariables(delegateTask.getVariables())
|
||||
.setStartTime(delegateTask.getCreateTime())
|
||||
.setTenantId(delegateTask.getTenantId());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user