diff --git a/src/main/java/com/example/demo/controller/HolidayController.java b/src/main/java/com/example/demo/controller/HolidayController.java new file mode 100644 index 0000000..886f49a --- /dev/null +++ b/src/main/java/com/example/demo/controller/HolidayController.java @@ -0,0 +1,78 @@ +package com.example.demo.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.activiti.engine.ProcessEngine; +import org.activiti.engine.RepositoryService; +import org.activiti.engine.RuntimeService; +import org.activiti.engine.TaskService; +import org.activiti.engine.repository.Deployment; +import org.activiti.engine.runtime.ProcessInstance; +import org.activiti.engine.task.Task; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @author yanpeng + * @version 1.0 + * @desc TODO + * @company 北京中经网软件有限公司 + * @date 2020/10/27 14:34 + */ +@RestController +@RequestMapping("holiday") +@Api(tags = "请假工作流接口") +public class HolidayController { + + @Autowired + private ProcessEngine processEngine; + + @ApiOperation(value = "发布工作流") + @GetMapping("deploy") + public void deploy() { + RepositoryService repositoryService = processEngine.getRepositoryService(); + Deployment deploy = repositoryService.createDeployment().addClasspathResource("bpmn/holiday.bpmn").addClasspathResource("bpmn/holiday.png").name("请假申请流程").key("holiday").deploy(); + System.out.println(deploy.getId()); + System.out.println(deploy.getName()); + System.out.println(deploy.getKey()); + } + + @ApiOperation(value = "启动工作流") + @GetMapping("start") + public void start() { + RuntimeService runtimeService = processEngine.getRuntimeService(); + ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holiday"); + System.out.println(processInstance.getProcessDefinitionId()); + System.out.println(processInstance.getId()); + } + + @Autowired + private TaskService taskService; + + @ApiOperation(value = "查询任务") + @GetMapping("query") + public Boolean query() { +// TaskService taskService = processEngine.getTaskService(); + List testbpmn = taskService.createTaskQuery().processDefinitionKey("holiday").list(); + testbpmn.stream().forEach(x->{ + System.out.println(x.getProcessDefinitionId()); + System.out.println(x.getId()); + System.out.println(x.getName()); + System.out.println(x.getAssignee()); + }); + return true; + } + + + @ApiOperation(value = "完成任务") + @GetMapping("ok") + public Boolean ok(String taskid) { + TaskService taskService = processEngine.getTaskService(); + taskService.complete(taskid); + return true; + } +} diff --git a/src/main/java/com/example/demo/controller/WorkFlowController.java b/src/main/java/com/example/demo/controller/WorkFlowController.java index 2551f53..725b111 100644 --- a/src/main/java/com/example/demo/controller/WorkFlowController.java +++ b/src/main/java/com/example/demo/controller/WorkFlowController.java @@ -50,11 +50,13 @@ public class WorkFlowController { System.out.println(processInstance.getId()); } + @Autowired + private TaskService taskService; @ApiOperation(value = "查询任务") @GetMapping("query") public Boolean query() { - TaskService taskService = processEngine.getTaskService(); +// TaskService taskService = processEngine.getTaskService(); List testbpmn = taskService.createTaskQuery().processDefinitionKey("testbpmn").list(); testbpmn.stream().forEach(x->{ System.out.println(x.getProcessDefinitionId()); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7f877c4..34a02d5 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -21,4 +21,4 @@ spring: minimum-idle: 3 maximum-pool-size: 10 max-lifetime: 1800000 - connection-test-query: SELECT 1 + connection-test-query: SELECT 1 \ No newline at end of file diff --git a/src/main/resources/bpmn/holiday.bpmn b/src/main/resources/bpmn/holiday.bpmn new file mode 100644 index 0000000..6edbac0 --- /dev/null +++ b/src/main/resources/bpmn/holiday.bpmn @@ -0,0 +1,107 @@ + + + + + + + + + + + + + =3}]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/bpmn/holiday.png b/src/main/resources/bpmn/holiday.png new file mode 100644 index 0000000..e68b4c7 Binary files /dev/null and b/src/main/resources/bpmn/holiday.png differ diff --git a/src/main/resources/bpmn/holiday.xml b/src/main/resources/bpmn/holiday.xml new file mode 100644 index 0000000..6edbac0 --- /dev/null +++ b/src/main/resources/bpmn/holiday.xml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + =3}]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +