You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 rivejä
2.9 KiB
85 rivejä
2.9 KiB
package com.example.demo.controller;
|
|
|
|
import com.example.demo.entity.Holiday;
|
|
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.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @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/holidayEx.bpmn").name("请假申请流程").key("holidayex").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();
|
|
Holiday holiday = new Holiday();
|
|
holiday.setNum(7f);
|
|
Map<String,Object> map = new HashMap<>();
|
|
map.put("holiday",holiday);
|
|
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holidayex",map);
|
|
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<Task> testbpmn = taskService.createTaskQuery().processDefinitionKey("holidayex").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;
|
|
}
|
|
}
|
|
|