TaskController.java
3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.bootdo.activiti.controller;
import com.bootdo.activiti.service.ActTaskService;
import com.bootdo.activiti.vo.ProcessVO;
import com.bootdo.activiti.vo.TaskVO;
import com.bootdo.common.utils.PageUtils;
import org.activiti.engine.FormService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.ProcessDefinition;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
/**
*/
@RequestMapping("activiti/task")
@RestController
public class TaskController {
@Autowired
RepositoryService repositoryService;
@Autowired
FormService formService;
@Autowired
TaskService taskService;
@Autowired
ActTaskService actTaskService;
@GetMapping("goto")
public ModelAndView gotoTask(){
return new ModelAndView("act/task/gotoTask");
}
@GetMapping("/gotoList")
PageUtils list(int offset, int limit) {
List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery()
.listPage(offset, limit);
int count = (int) repositoryService.createProcessDefinitionQuery().count();
List<Object> list = new ArrayList<>();
for(ProcessDefinition processDefinition: processDefinitions){
list.add(new ProcessVO(processDefinition));
}
PageUtils pageUtils = new PageUtils(list, count);
return pageUtils;
}
@GetMapping("/form/{procDefId}")
public void startForm(@PathVariable("procDefId") String procDefId ,HttpServletResponse response) throws IOException {
String formKey = actTaskService.getFormKey(procDefId, null);
response.sendRedirect(formKey);
}
@GetMapping("/form/{procDefId}/{taskId}")
public void form(@PathVariable("procDefId") String procDefId,@PathVariable("taskId") String taskId ,HttpServletResponse response) throws IOException {
// 获取流程XML上的表单KEY
String formKey = actTaskService.getFormKey(procDefId, taskId);
response.sendRedirect(formKey+"/"+taskId);
}
@GetMapping("/todo")
ModelAndView todo(){
return new ModelAndView("act/task/todoTask");
}
@GetMapping("/todoList")
List<TaskVO> todoList(){
List<Task> tasks = taskService.createTaskQuery().taskAssignee("admin").list();
List<TaskVO> taskVOS = new ArrayList<>();
for(Task task : tasks){
TaskVO taskVO = new TaskVO(task);
taskVOS.add(taskVO);
}
return taskVOS;
}
/**
* 读取带跟踪的图片
*/
@RequestMapping(value = "/trace/photo/{procDefId}/{execId}")
public void tracePhoto(@PathVariable("procDefId") String procDefId, @PathVariable("execId") String execId, HttpServletResponse response) throws Exception {
InputStream imageStream = actTaskService.tracePhoto(procDefId, execId);
// 输出资源内容到相应对象
byte[] b = new byte[1024];
int len;
while ((len = imageStream.read(b, 0, 1024)) != -1) {
response.getOutputStream().write(b, 0, len);
}
}
}