美文网首页
activiti任务管理

activiti任务管理

作者: lv_shun | 来源:发表于2020-05-26 22:21 被阅读0次

获取任务服务

 TaskService taskService = processEngine.getTaskService();

任务属性

Task接口表示流程中的任务,实现类为TaskEntityImpl,对应表ACT_RU_TASK.
属性包括:

  • id 主键
  • reversion 该数据的版本
  • owner 任务拥有人
  • assignee 被指定需要执行任务的人
  • delegationState 任务被委派状态
  • parentTaskId 父任务的id
  • name 任务名称
  • description 任务描述
  • priority 任务优先级 默认50
  • createTime 任务创建时间
  • dulDate 预定时间
  • executionId 该任务对应执行流id
  • processDefinitionId 任务对应流程定义id
  • claimTime 任务提醒时间

任务创建

TaskService taskService = processEngine.getTaskService();
       Task task = taskService.newTask();
        taskService.saveTask(task);
        Task task2 = taskService.newTask("taskId");
        taskService.saveTask(task2);

任务删除

 taskService.deleteTask(task.getId());
        taskService.deleteTask(task2.getId(),true); //集联删除
        List<String> list = new ArrayList<>();
        list.add(task.getId());
        list.add(task2.getId());
        taskService.deleteTasks(list);  //多任务删除
        taskService.deleteTasks(list,true); //多任务集联删除

设置用户候选组

和流程设置权限类似,也是通过ACT_RU_IDENTITYLINK表来关联任务和用户/用户组.

设置任务持有人

taskService. setOwner(taskId, userId)
  List<Task> list1 = taskService.createTaskQuery().taskOwner(userID).list();//查询

设置任务代理人

taskService.setAssignee(taskId, userId);
        List<Task> list2 = taskService.createTaskQuery().taskAssignee(userId).list();//查询

添加任务的权限数据

  • addUserIdentityLink(String taskId,String userId,String identityLinkType) 给任务设置用户权限
  • addGroupIdentityLink(String taskId,String groupId,String identityLinkType) 给任务设置用户组权限

identityLinkType 可以设置的值:

  • CANDIDATE 等同于addCandidateUser
  • OWNER 等同于setOwner
  • ASSIGNEE 等同于setAssignee

删除用户组权限

void deleteUserIdentityLink(String taskId, String userId, String identityLinkType);
//删除用户任务权限数据
    void deleteGroupIdentityLink(String taskId, String groupId, String identityLinkType);
//删除用户组任务权限数据

  void deleteCandidateGroup(String taskId, String groupId);
//删除任务候选用户组数据
void deleteCandidateUser(String taskId, String userId);
//删除任务候选用户数据

任务参数

activiti参数分为流程参数和任务参数

设置参数

activiti中的参数保存在ACT_RU_VARIABLE表中.
设置参数方法:

taskService.setVariable(task.getId(),"var1","value1");
taskService.setVariable(task.getId(), "Student",new Student("xiaoming"));

其中第三个参数为参数值.默认类型时Object
参数支持的基本数据类型:

  • Boolean
  • Date
  • Double
  • Integer
  • Long
  • Null
  • Short
  • String
    除了基本数据类型外,还是支持自定义对象,前提是自定义对象必须实现Serializable接口.这个对象会以外键关联的方式将值保存在ACT_GE_BYTEARRAY表中.

获取参数

taskService.getVariable(task.getId(),"var1");
Student student = (Student) taskService.getVariable(task.getId(), "Student");

参数作用域

TaskService.setVariable和TaskService.setVariableLocal作用域不同,但是在activiti7中,没看出差别.

多参数设置

 Map<String,Object> map = new HashMap<>();
        map.put("vara","valuea");
        map.put("varb","valueb");
        taskService.setVariables(task.getId(),map);

附件管理(7.0版本目测对Attachment对象已经弃用)

TaskService提供了附件API,通过Attachment对象完成

Attachment对象

Attachment对象提供了获取附件各种属性的接口.实现类是AttachmentEntityImpl,对应实体AttachmentEntity.对应属性:

  • id 主键
  • revision 附件数据的版本
  • name 附件名称
  • description 附件描述
  • type 附件类型
  • taskId 对应任务id
  • processInstanceId 流程实例id
  • url 附件的url
  • contentId 附件流保存的id,通过外键关联ACT_GE_BYTEARRAY表

附件添加

  • 通过url形式添加
 String attachmentType = "File"; //文件类型 自定义
 String taskId = task.getId();   //任务id
 String processInstanceId = "";  //流程实例id
 String attachmentName = "xxxFileName";  //附件名称
 String attachmentDesc = "desc"; //附件描述
 String url = "http://www.baidu.com";    //附件url
        taskService.createAttachment(attachmentType,taskId,processInstanceId,attachmentName,attachmentDesc,url);
  • 通过文件流形式
 String attachmentType = "File"; //文件类型 自定义
 String taskId = task.getId();   //任务id
 String processInstanceId = "";  //流程实例id
 String attachmentName = "xxxFileName";  //附件名称
 String attachmentDesc = "desc"; //附件描述
 InputStream fis ;    //文件流
        taskService.createAttachment(attachmentType,taskId,processInstanceId,attachmentName,attachmentDesc, fis);

附件查询

  • 通过流程实例id获取
List<Attachment> attachments = taskService.getProcessInstanceAttachments(processInstanceId);
  • 通过任务id获取
List<Attachment> attachmentList = taskService.getTaskAttachments(task.getId());
  • 通过附件id获取
 String attachmentId = "";
 taskService.getAttachmentContent(attachmentId);

删除附件

taskService.deleteAttachment(attachmentId);

任务评论和事件记录(7.0版本对comment对象弃用)

任务评论会对应到ACT_HI_COMMENT表中.接口为comment.实现类为CommentEntityImpl.评论表会保存两种类型的数据:任务评论和部分事件记录.

comment对象

comment实例表示评论表里的一条记录,CommentEntityImpl实际上实现两个接口:Event和Comment.如果以Event接口返回,则可以认为返回的事件的记录,如果Comment返回则认为是任务评论
CommentEntityImpl主要属性:

  • id 主键
  • type 数据类型 两种类型:event和comment
  • userId 产生数据的用户id
  • time 创建事件
  • taskId 任务id
  • processInstanceId 流程实例id
  • action 数据的操作标识
  • message 评论内容
  • fullMessage 数据信息

评论添加和查询

        taskService.addComment(taskId,processInstanceId,"同意");
        taskService.getTaskComments(task.getId());

任务事件查询

taskService.getTaskEvents(task.getId());

事件包括任务的所有操作,不只是添加评论.

评论和事件查询

  • getComment(String commentId) 根据评论id获取评论对象
  • getTaskComments(String taskId) 根据任务id获取所有评论对象
  • getTaskEvents(String taskId) 根据任务id获取所有任务事件记录
  • getProcessInstanceComments(String processInstanceId) 根据流程实例id获取所有评论

任务声明和完成

TaskService.claim方法对任务指定任务代理人,和setAssignee区别是claim方法指派之后,再次指派会报错.
TaskService.complete方法完成任务,方法提供传递参数.

相关文章

网友评论

      本文标题:activiti任务管理

      本文链接:https://www.haomeiwen.com/subject/oujbvqtx.html