版权声明:如果觉得文章对你有用,转载不需要联系作者,但请注明出处 https://blog.csdn.net/jinxin70/article/details/83830864
Activity Workflow修改流程处理人的bug,流程里配置了assignment监听。
修改审核人,业务代码里面需要调用工作流的taskService.setAssignee(String taskId, String userId)方法。
这个方法内部是命令模式,最终执行到TaskEntity.setAssignee(String assignee, boolean dispatchAssignmentEvent, boolean dispatchUpdateEvent)
public void setAssignee(String assignee, boolean dispatchAssignmentEvent, boolean dispatchUpdateEvent) {
CommandContext commandContext = Context.getCommandContext();
if (assignee==null && this.assignee==null) {
// ACT-1923: even if assignee is unmodified and null, this should be stored in history.
if (commandContext!=null) {
commandContext
.getHistoryManager()
.recordTaskAssigneeChange(id, assignee);
}
return;
}
this.assignee = assignee;
// if there is no command context, then it means that the user is calling the
// setAssignee outside a service method. E.g. while creating a new task.
if (commandContext!=null) {
commandContext
.getHistoryManager()
.recordTaskAssigneeChange(id, assignee);
if (assignee != null && processInstanceId != null) {
getProcessInstance().involveUser(assignee, IdentityLinkType.PARTICIPANT);
}
if(!StringUtils.equals(initialAssignee, assignee)) {
fireEvent(TaskListener.EVENTNAME_ASSIGNMENT);
initialAssignee = assignee;
}
if(commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
if(dispatchAssignmentEvent) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_ASSIGNED, this));
}
if(dispatchUpdateEvent) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, this));
}
}
}
}
跟踪源码发现28~31行,会判断分配的人是不是原来的人,如果有变更,不是原来的人,就重新触发assginment事件。
这就是为什么修改审核人会触发流程节点的assingment事件的原因。
既然工作流代码里面这样写了,在assingment事件的实现里面就不能创建问题跟踪之类的信息,否则每改一次,都会生成一个新的。
节点创建最适合用的监听事件是create。这样修改的时候,重新assign就不会触发监听。