update - 调整加签过程中的待办处理,以及审批人的信息

This commit is contained in:
wangli 2023-12-09 17:40:55 +08:00
parent 23ba69e75e
commit e2adae85cc
5 changed files with 64 additions and 13 deletions

View File

@ -0,0 +1,42 @@
package cn.axzo.workflow.core.engine.cmd;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.UserTask;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import java.io.Serializable;
/**
* TODO
*
* @author wangli
* @since 2023/12/9 16:37
*/
public class CustomEventAssignment implements Command<Void>, Serializable {
private String processDefinitionId;
private String taskDefinitionKey;
private TaskEntity task;
public CustomEventAssignment(String processDefinitionId, String taskDefinitionKey, TaskEntity task) {
this.processDefinitionId = processDefinitionId;
this.taskDefinitionKey = taskDefinitionKey;
this.task = task;
}
@Override
public Void execute(CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(processDefinitionId);
UserTask flowElement = (UserTask) bpmnModel.getFlowElement(taskDefinitionKey);
processEngineConfiguration.getListenerNotificationHelper().executeTaskListeners(flowElement, task,
TaskListener.EVENTNAME_ASSIGNMENT);
return null;
}
}

View File

@ -19,7 +19,7 @@ public class TimeBasedIdGenerator implements IdGenerator {
private static final long MAX_SEQUENCE = ~(-1L << SEQUENCE_BITS);
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
private static final AtomicLong sequence = new AtomicLong(1);
private static final AtomicLong sequence = new AtomicLong(0);
private static volatile String lastTimestamp = "";
@Override

View File

@ -25,6 +25,7 @@ public class EngineTaskEventListener implements TaskListener {
@Resource
ObjectProvider<List<BpmnTaskEventListener>> taskEventListeners;
@Override
public void notify(DelegateTask delegateTask) {
log.info("Task.notify {}", delegateTask.getId());

View File

@ -21,6 +21,7 @@ import cn.axzo.workflow.common.model.response.bpmn.task.BpmnTaskInstanceVO;
import cn.axzo.workflow.common.model.response.bpmn.task.BpmnTaskTodoPageItemVO;
import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
import cn.axzo.workflow.core.engine.cmd.CustomEventAssignment;
import cn.axzo.workflow.core.engine.event.MessagePushEventBuilder;
import cn.axzo.workflow.core.engine.event.MessagePushEventImpl;
import cn.axzo.workflow.core.engine.event.MessagePushEventType;
@ -326,11 +327,12 @@ public class BpmnProcessTaskServiceImpl implements BpmnProcessTaskService {
saveAttachment(dto.getAttachmentList(), instance.getId(), task.getId());
// 完成任务审批通过
taskService.complete(task.getId(), runtimeService.getVariables(task.getExecutionId()));
// } else {
// //加签子任务 没有executionId
// taskService.complete(task.getId());
// }
if (StringUtils.hasLength(task.getExecutionId())) {
taskService.complete(task.getId(), runtimeService.getVariables(task.getExecutionId()));
} else {
//加签子任务 没有executionId
taskService.complete(task.getId());
}
//add by zuoqinbo 处理加签任务分为向前加签和向后加签
String parentTaskId = task.getParentTaskId();
@ -391,6 +393,7 @@ public class BpmnProcessTaskServiceImpl implements BpmnProcessTaskService {
activityListSnapshot, List.class);
taskAssignerListSnapshot.addAll(newTargetAssignerList);
runtimeService.setVariable(taskEntity.getProcessInstanceId(), activityListSnapshot, taskAssignerListSnapshot);
// 向前加签
BpmnTaskDelegateAssigner assigner =
(BpmnTaskDelegateAssigner) runtimeService.getVariable(taskEntity.getProcessInstanceId(),
@ -433,19 +436,19 @@ public class BpmnProcessTaskServiceImpl implements BpmnProcessTaskService {
task.setDescription(parentTask.getDescription());
task.setTenantId(parentTask.getTenantId());
task.setName(parentTask.getName());
task.setAssignee(assigner.buildAssigneeId());
task.setParentTaskId(parentTaskId);
task.setProcessDefinitionId(parentTask.getProcessDefinitionId());
task.setProcessInstanceId(parentTask.getProcessInstanceId());
task.setTaskDefinitionKey(parentTask.getTaskDefinitionKey());
task.setTaskDefinitionId(parentTask.getTaskDefinitionId());
task.setExecutionId(parentTask.getExecutionId());
// task.setExecutionId(idGenerator.getNextId());
task.setPriority(parentTask.getPriority());
task.setCreateTime(new Date());
log.info("流程加签父任务:{},正在创建加签子任务:{},", parentTaskId, JSONUtil.toJsonStr(Lists.newArrayList(task)));
taskService.saveTask(task);
taskService.setAssignee(task.getId(), assigner.buildAssigneeId());
taskService.setVariable(task.getId(), INTERNAL_TASK_RELATION_ASSIGNEE_INFO + task.getId(),
assigner);
springProcessEngineConfiguration.getCommandExecutor().execute(new CustomEventAssignment(parentTask.getProcessDefinitionId(), parentTask.getTaskDefinitionKey(), task));
}
return task;
}
@ -552,7 +555,7 @@ public class BpmnProcessTaskServiceImpl implements BpmnProcessTaskService {
Map<String, List<Attachment>> attachmentByTaskIdMap =
taskService.getProcessInstanceAttachments(processInstanceId).stream()
.collect(Collectors.groupingBy(Attachment::getTaskId));
.collect(Collectors.groupingBy(Attachment::getTaskId));
BpmnProcessInstanceResultEnum processBusinessStatus = valueOfStatus(instance.getBusinessStatus());
for (BpmnHistoricTaskInstanceVO vo : vos) {

View File

@ -3,6 +3,7 @@ package cn.axzo.workflow.server.controller.listener.task;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
import cn.axzo.workflow.core.listener.BpmnTaskEventListener;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.task.service.delegate.DelegateTask;
@ -10,6 +11,7 @@ import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
@ -28,13 +30,16 @@ import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_TASK_RELAT
@Component
public class SnapshotBpmnTaskTaskEventListener implements BpmnTaskEventListener, Ordered {
@Resource
private RuntimeService runtimeService;
@Override
public void onAssigned(DelegateTask delegateTask) {
if (log.isDebugEnabled()) {
log.debug("SnapshotBpmnTaskTaskEventListener#onAssigned...");
}
List<BpmnTaskDelegateAssigner> assignerList =
(List<BpmnTaskDelegateAssigner>) delegateTask.getVariable(INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT + delegateTask.getTaskDefinitionKey());
List<BpmnTaskDelegateAssigner> assignerList = runtimeService.getVariable(delegateTask.getProcessInstanceId(),
INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT + delegateTask.getTaskDefinitionKey(),
List.class);
if (CollectionUtils.isEmpty(assignerList)) {
// 加签
TaskService taskService = CommandContextUtil.getProcessEngineConfiguration().getTaskService();