TaskController.java
13.9 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
package vion.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import vion.Global;
import vion.enums.ResultEnum;
import vion.model.*;
import vion.service.*;
import vion.service.impl.UserServiceImpl;
import vion.utils.ResultUtil;
import vion.vo.FaultLogVO;
import vion.vo.ProductVO;
import vion.vo.TaskVO;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping(Global.BASE_URL)
@Slf4j
public class TaskController {
@Autowired
private ITaskTempSerrvice taskTempSerrvice;
@Autowired
private ITaskSerrvice taskSerrvice;
@Autowired
private IFileSerrvice fileSerrvice;
@Autowired
private IFaultLogSerrvice faultLogSerrvice;
@Autowired
private FileController fileController;
@Autowired
private IStoreSerrvice storeSerrvice;
@Autowired
private UserController userController;
@Autowired
private IUserSerrvice iUserSerrvice;
@GetMapping("/tasks")
@ResponseBody
public Object gettaskList(@RequestParam(name = "accountId",required=false)Integer account_id,
@RequestParam(name = "storeId",required=false)Integer store_id,
@RequestParam(name = "faultType",required=false)Integer fault_type,
@RequestParam(name = "status",required=false)Integer status,
@RequestParam(name = "startdate",required=false)
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date startdate,
@RequestParam(name = "enddate",required=false)
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date enddate,
@RequestParam(name = "pageNum")Integer pageNum,
@RequestParam(name = "pageSize")Integer pageSize){
//pageNum当前页,pageSize每页条数
Page page= PageHelper.startPage(pageNum,pageSize);
QueryWrapper<Task> wrapper=new QueryWrapper<>();
if(store_id!=null){
wrapper.eq("store_id",store_id);
}
if(account_id!=null)
wrapper.eq("account_id",account_id);
if(fault_type!=null)
wrapper.eq("fault_type",fault_type);
if(status!=null)
wrapper.eq("status",status);
if(startdate!=null)
wrapper.between("repair_date",startdate,enddate);
List<Task> taskList=taskSerrvice.list(wrapper);
List<Store> storeList=storeSerrvice.list();
List<TaskVO> taskVOS=new ArrayList<>();
TaskVO taskVO;
for(Task task:taskList){
taskVO=new TaskVO();
taskVO.setStoreName(storeList.stream().filter(store -> store.getId().equals(task.getStoreId())).collect(Collectors.toList()).get(0).getName());
taskVO.setId(task.getId());
taskVO.setStoreId(task.getStoreId());
taskVO.setRepairDate(task.getRepairDate());
taskVO.setFaultType(task.getFaultType());
taskVO.setFaultDescription(task.getFaultDescription());
taskVO.setRepairPeople(task.getRepairPeople());
taskVO.setRepairPhone(task.getRepairPhone());
taskVO.setStatus(task.getStatus());
taskVO.setFaultReason(task.getFaultReason());
taskVO.setSolveDate(task.getSolveDate());
taskVO.setSolveType(task.getSolveType());
taskVO.setSolveDescription(task.getSolveDescription());
taskVO.setCreateUser(task.getCreateUser());
taskVO.setActiveUser(task.getActiveUser());
taskVO.setCreateTime(task.getCreateTime());
taskVO.setModifyTime(task.getModifyTime());
taskVO.setRemark(task.getRemark());
taskVO.setAccountId(task.getAccountId());
taskVOS.add(taskVO);
}
taskVOS.sort(Comparator.comparing(TaskVO::getId));
PageInfo pageInfo=new PageInfo<>(page);
pageInfo.setList(taskVOS);
if (pageInfo != null) {
return ResultUtil.success(pageInfo);
} else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@GetMapping("/task")
@ResponseBody
public Object getTaskByID(@RequestParam(name = "taskId")Integer task_id){
Task task=taskSerrvice.getById(task_id);
List<File> files=fileController.getFileList(task.getStoreId(),task.getId());
TaskVO taskVO=new TaskVO();
taskVO.setId(task.getId());
taskVO.setStoreId(task.getStoreId());
taskVO.setRepairDate(task.getRepairDate());
taskVO.setFaultType(task.getFaultType());
taskVO.setFaultDescription(task.getFaultDescription());
taskVO.setRepairPeople(task.getRepairPeople());
taskVO.setRepairPhone(task.getRepairPhone());
taskVO.setStatus(task.getStatus());
taskVO.setFaultReason(task.getFaultReason());
taskVO.setSolveDate(task.getSolveDate());
taskVO.setSolveType(task.getSolveType());
taskVO.setSolveDescription(task.getSolveDescription());
taskVO.setCreateUser(task.getCreateUser());
taskVO.setActiveUser(task.getActiveUser());
taskVO.setCreateTime(task.getCreateTime());
taskVO.setModifyTime(task.getModifyTime());
taskVO.setRemark(task.getRemark());
taskVO.setAccountId(task.getAccountId());
taskVO.setFileList(files);
if (taskVO != null) {
return ResultUtil.success(taskVO);
} else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@PostMapping("/tasks")
@ResponseBody
public Object saveOrUpdate(@RequestBody TaskVO data,@RequestAttribute String userid) {
try {
User user=Global.USERNAME_MAP.get(userid);
Task task=new Task();
task.setAccountId(data.getAccountId());
task.setStoreId(data.getStoreId());
task.setFaultType(data.getFaultType());
task.setFaultDescription(data.getFaultDescription());
task.setRepairDate(data.getRepairDate());
task.setRepairPeople(data.getRepairPeople());
task.setRepairPhone(data.getRepairPhone());
task.setStatus(data.getStatus());
if(task.getId()==null){
task.setCreateUser(user.getId());
}
task.setActiveUser(data.getActiveUser());
if(data.getTasktempId()!=null){
//得到预处理工单
TaskTemp taskTemp= taskTempSerrvice.getById(data.getTasktempId());
//更新预处理工单状态
taskTemp.setStatus(2);//状态(1待确认、2已确认)
taskTemp.setModifyTime(new Date());
taskTemp.setOperator(data.getActiveUser());
taskTemp.setStoreId(data.getStoreId());
taskTemp.setModifyTime(new Date());
taskTempSerrvice.saveOrUpdate(taskTemp);
//根据预处理工单更新附件的门店ID
fileSerrvice.lambdaUpdate()
.setSql("store_id="+data.getStoreId())
.eq(File::getSourceId,data.getId())
.update();
}
if(data.getId()==null){
//添加新工单
Task work=taskSerrvice.saveAndReturn(task);
if(data.getFileList()!=null){
//添加新工单的附件信息
if(work!=null){
File file;
for(File fileModel:data.getFileList()){
file=new File();
file.setId(fileModel.getId());
file.setStoreId(work.getStoreId());
file.setSourceId(work.getId());
file.setSourceType(3);//1项目、2工单预处理,3工单操作,4巡检
file.setName(fileModel.getName());
file.setUrl(fileModel.getUrl());
file.setType(fileModel.getType());
fileSerrvice.saveOrUpdate(file);
}
}
}
//添加工单处理日志
FaultLog faultLog=new FaultLog();
faultLog.setTaskId(work.getId());
faultLog.setStoreId(work.getStoreId());
faultLog.setOperator(user.getId());
faultLog.setContent("创建工单");
faultLog.setRemark("");
faultLogSerrvice.saveOrUpdate(faultLog);
//发送钉钉提醒
User activeUser= iUserSerrvice.getById(work.getActiveUser());
userController.sendMessage(activeUser.getUserid(),work.getId());
}
else{
task.setId(data.getId());
task.setSolveDate(data.getSolveDate());
task.setFaultReason(data.getFaultReason());
task.setSolveType(data.getSolveType());
task.setSolveDescription(data.getSolveDescription());
task.setRemark(data.getRemark());
taskSerrvice.saveOrUpdate(task);
//根据状态判断是否要添加工单处理日志(//状态:0待确认1进行中2已完成3挂起)
if(data.getStatus()==1){
FaultLog faultLog=new FaultLog();
faultLog.setTaskId(data.getId());
faultLog.setStoreId(data.getStoreId());
faultLog.setOperator(user.getId());
faultLog.setContent("工单正在处理中");
faultLog.setRemark(data.getSolveDescription());
faultLogSerrvice.saveOrUpdate(faultLog);
}
if(data.getStatus()==2){
FaultLog faultLog=new FaultLog();
faultLog.setTaskId(data.getId());
faultLog.setStoreId(data.getStoreId());
faultLog.setOperator(user.getId());
faultLog.setContent("工单处理完成");
faultLog.setRemark(data.getSolveDescription());
faultLogSerrvice.saveOrUpdate(faultLog);
}
if(data.getStatus()==3){
FaultLog faultLog=new FaultLog();
faultLog.setTaskId(data.getId());
faultLog.setStoreId(data.getStoreId());
faultLog.setOperator(user.getId());
faultLog.setContent("工单挂起");
faultLog.setRemark(data.getSolveDescription());
faultLogSerrvice.saveOrUpdate(faultLog);
}
//判断是否要添加工单处理文件
if(data.getFileList()!=null){
//添加新工单的附件信息
for(File fileModel:data.getFileList()){
File file=new File();
file.setId(fileModel.getId());
file.setStoreId(data.getStoreId());
file.setSourceId(data.getId());
file.setSourceType(3);//1项目、2工单预处理,3工单操作,4巡检
file.setName(fileModel.getName());
file.setUrl(fileModel.getUrl());
file.setType(fileModel.getType());
fileSerrvice.saveOrUpdate(file);
}
//判断是否有要删除的文件信息
}
}
return ResultUtil.success();
}catch (Exception e) {
return e.getMessage();
}
}
@GetMapping("/faultLogs")
@ResponseBody
public Object getFaultLogByID(@RequestParam(name = "storeId")Integer store_id,
@RequestParam(name = "taskId")Integer task_id){
List<FaultLog> faultLogs=faultLogSerrvice.list(Wrappers.<FaultLog>lambdaQuery()
.eq(FaultLog::getStoreId,store_id)
.eq(FaultLog::getTaskId,task_id));
if (faultLogs != null) {
return ResultUtil.success(faultLogs);
} else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@PostMapping("/faultLogs")
@ResponseBody
public Object saveAddFaultLog(@RequestBody FaultLogVO data,@RequestAttribute String userid) {
try {
User user=Global.USERNAME_MAP.get(userid);
FaultLog faultLog=new FaultLog();
faultLog.setTaskId(data.getTaskId());
faultLog.setStoreId(data.getStoreId());
faultLog.setOperator(user.getId());
faultLog.setContent(data.getContent());
faultLog.setRemark(data.getRemark());
faultLogSerrvice.saveOrUpdate(faultLog);
if(data.getFilename()!=null){
//添加文件附件
File file=new File();
file.setStoreId(data.getStoreId());
file.setSourceId(data.getTaskId());
file.setSourceType(3);//1项目、2工单预处理,3工单操作,4巡检
file.setName(data.getFilename());
file.setUrl(data.getFileurl());
file.setType(1);
//fileDao.addFile(file);
fileSerrvice.save(file);
}
return ResultUtil.success();
}catch (Exception e) {
// return ResultUtil.error(ResultEnum.SELECT_ERROR);
return e.getMessage().toString();
}
}
}