[关闭]
@ruoli 2016-08-16T10:06:46.000000Z 字数 1798 阅读 3281

Activiti环节任意跳跃

Activiti


  1. package test;
  2. /**
  3. * @author: Ruoli
  4. */
  5. import org.activiti.engine.ManagementService;
  6. import org.activiti.engine.ProcessEngine;
  7. import org.activiti.engine.ProcessEngines;
  8. import org.activiti.engine.impl.interceptor.Command;
  9. import org.activiti.engine.impl.interceptor.CommandContext;
  10. import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
  11. import org.activiti.engine.impl.pvm.process.ActivityImpl;
  12. import org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl;
  13. import org.junit.Test;
  14. /**
  15. * 流程中任意跳跃
  16. * @author Administrator
  17. *
  18. */
  19. public class JumpActivityCmd implements Command<Object> {
  20. private String activityId;
  21. private String processInstanceId;
  22. private String jumpOrigin;
  23. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  24. public JumpActivityCmd(){}
  25. public JumpActivityCmd(String processInstanceId, String activityId) {
  26. this(processInstanceId, activityId, "jump");
  27. }
  28. /**
  29. *
  30. * @param processInstanceId 流程实例ID
  31. * @param activityId 跳转目标环节KEY
  32. * @param jumpOrigin 自动完成环节的意见
  33. */
  34. public JumpActivityCmd(String processInstanceId, String activityId, String jumpOrigin) {
  35. this.activityId = activityId;
  36. this.processInstanceId = processInstanceId;
  37. this.jumpOrigin = jumpOrigin;
  38. }
  39. public Object execute(CommandContext commandContext) {
  40. ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
  41. executionEntity.destroyScope(jumpOrigin);
  42. ProcessDefinitionImpl processDefinition = executionEntity.getProcessDefinition();
  43. ActivityImpl activity = processDefinition.findActivity(activityId);
  44. executionEntity.executeActivity(activity);
  45. return executionEntity;
  46. }
  47. @Test
  48. public void testname() {
  49. ManagementService managementService=processEngine.getManagementService();
  50. //第一个参数 流程实例ID,
  51. //第二个参数 跳转目标环节KEY
  52. //第三个参数 自动完成环节的意见
  53. Command<Object> cmdCommand=new JumpActivityCmd("1201","usertask2","强制跳转");
  54. managementService.executeCommand(cmdCommand);
  55. }
  56. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注