TaskController.java
7.03 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.liaochong.myexcel.core.DefaultExcelBuilder;
import com.github.liaochong.myexcel.core.watermark.Watermark;
import com.github.liaochong.myexcel.utils.WatermarkUtil;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import vion.config.FaultTypeConverter;
import vion.config.UserNameConverter;
import vion.dto.TaskDTO;
import vion.model.FaultLog;
import vion.model.Task;
import vion.service.IFaultLogService;
import vion.service.ITaskService;
import vion.utils.excel.AttachmentExportUtil;
import vion.vo.TaskVO;
import vion.vo.UserVO;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
@Slf4j
public class TaskController {
private final ITaskService taskService;
private final IFaultLogService faultLogService;
private final UserNameConverter userNameConverter;
private final FaultTypeConverter faultTypeConverter;
@GetMapping("/tasks")
@SaCheckPermission(value = "task:list", orRole = "admin")
public Page<TaskVO> getTaskList(TaskDTO data) {
return taskService.getTaskList(data);
}
@GetMapping("/task")
@SaCheckPermission(value = "task:query", orRole = "admin")
public TaskVO getTaskById(Long taskId) {
return taskService.getTaskById(taskId);
}
@PostMapping("/tasks")
@SaCheckPermission(value = "task:editAndSave", orRole = "admin")
public Long saveOrUpdate(TaskDTO data) {
return taskService.circTask(data);
}
@PostMapping("/task/{id}")
@SaCheckPermission(value = "task:edit", orRole = "admin")
public String updById(@PathVariable Long id, TaskDTO data) {
return taskService.updById(id, data);
}
@GetMapping("/faultLogs")
@SaCheckPermission(value = "task:log:list", orRole = "admin")
public List<FaultLog> getFaultLogById(Long storeId, Long taskId) {
List<FaultLog> faultLogList = faultLogService.lambdaQuery()
.eq(FaultLog::getStoreId, storeId)
.eq(FaultLog::getTaskId, taskId)
.orderByAsc(FaultLog::getCreateTime)
.list();
TaskVO taskVO = taskService.getTaskById(taskId);
// 进行中的任务,在最后追加一条当前处理人正在处理的记录,仅做显示用
if (taskVO.getStatus() == 2) {
FaultLog faultLog = new FaultLog();
faultLog.setOperator(taskVO.getActiveUser());
faultLog.setContent("工单正在处理中");
faultLog.setCreateTime(new Date());
faultLogList.add(faultLog);
}
return faultLogList;
}
@PostMapping("/task/batchIns")
@SaCheckPermission(value = "task:batchIns", orRole = "admin")
public String batchIns(@RequestBody List<TaskDTO> data) {
return taskService.batchIns(data);
}
@GetMapping("/task/export")
@SaCheckPermission(value = "task:export", orRole = "admin")
public void taskExport(TaskDTO data, HttpServletResponse response) {
UserVO user = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
data.setPageSize(30000);
Page<TaskVO> voPage = taskService.getTaskList(data);
try (DefaultExcelBuilder<TaskVO> defaultExcelBuilder = DefaultExcelBuilder.of(TaskVO.class)) {
Workbook workbook = defaultExcelBuilder
.binding(userNameConverter, faultTypeConverter)
.build(voPage.getRecords());
// 水印添加指定字体,并在服务器上安装 SimSun 字体,解决中文字体变成方块的问题
Watermark watermark = new Watermark();
watermark.setText(user.getUsername() + "-" + user.getPhone());
watermark.setFont(new Font("SimSun", Font.PLAIN, 16));
WatermarkUtil.addWatermark(workbook, watermark);
AttachmentExportUtil.export(workbook, StrUtil.format("任务列表_{}", DateUtil.formatDateTime(new Date())), response);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@GetMapping("/task/uuid/{uuid}")
public TaskVO getTaskByUuid(@PathVariable String uuid) {
return taskService.getTaskByUuid(uuid);
}
/**
* 转发工单,把工单转发给某人查看工单详情
*
* @param taskId 工单id
* @param forwardUser 转发人
* @return java.lang.String
*/
@GetMapping("/task/forward")
@SaCheckPermission(value = "task:forward", orRole = "admin")
public String forwardTask(Long taskId, String forwardUser) {
return taskService.forwardTask(taskId, forwardUser);
}
/**
* 催办工单,催办工单给当前处理人
*
* @param taskId 工单id
* @param remark 备注
* @return java.lang.String
*/
@GetMapping("/task/urge")
@SaCheckPermission(value = "task:urge", orRole = "admin")
public String urgeTask(Long taskId, String remark) {
return taskService.urgeTask(taskId, remark);
}
@GetMapping("/task/peopleAnal")
@SaCheckPermission(value = "task:peopleAnal", orRole = "admin")
public List<Map<String, Object>> peopleAnalysis(@DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
@DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
Integer source,
@RequestParam(required = false) List<Long> userIds) {
return taskService.peopleAnalysis(startDate, endDate, source, userIds);
}
@GetMapping("/task/proAnal")
@SaCheckPermission(value = "task:proAnal", orRole = "admin")
public List<Map<String, Object>> proAnalysis(@DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
@DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
Integer source,
@RequestParam(required = false) List<Long> userIds) {
return taskService.proAnalysis(startDate, endDate, source, userIds);
}
@GetMapping("/task/summaryAnal")
@SaCheckPermission(value = "task:summaryAnal", orRole = "admin")
public Map<String, Map<String, List<Task>>> summaryAnalysis(@DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
@DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
Integer source) {
return taskService.summaryAnalysis(startDate, endDate, source);
}
}