问题
在监听器中,根据业务赋值给任务对应办理人
delegateTask.setAssignee(“xxx”);
但是在对该任务负责人进行查询历史任务的时候缺查询不到已经执行了的数据
而对应的ACT_HI_TASKINST也没有对应负责人的数据
解决代码示例
package cn.inther.oa.activiti.controller;
import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
/**
* @author Kevin
* @date 2023/5/14 11:08
* @description 自定义任务监听器类
**/
@Component
public class MyTaskListener implements TaskListener, ApplicationContextAware {
private static TaskService taskService;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
taskService = applicationContext.getBean(TaskService.class);
}
/**
* Create:任务创建后触发
* Assignment:任务分配后触发
* Delete:任务完成后触发
* ALL:所有事件发生都触发
* @param delegateTask
*/
@Override
public void notify(DelegateTask delegateTask) {
if (delegateTask.getName().equals("经理审批")){
// 指定任务负责人
// 这样使用会查不到任务历史
// delegateTask.setAssignee("kevin1");
// 需要如下使用
taskService.setAssignee(delegateTask.getId(),"kevin1");
}
if (delegateTask.getName().equals("人事审批")){
// 指定任务负责人
// 需要如下使用
taskService.setAssignee(delegateTask.getId(),"kevin2");
}
}
}