DispatchNoteController.java
6.2 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
package com.sunyo.wlpt.dispatch.controller;
import com.github.pagehelper.PageInfo;
import com.sunyo.wlpt.dispatch.domain.DispatchNote;
import com.sunyo.wlpt.dispatch.domain.VehicleInfo;
import com.sunyo.wlpt.dispatch.response.ResultJson;
import com.sunyo.wlpt.dispatch.service.DispatchNoteService;
import com.sunyo.wlpt.dispatch.service.VehicleInfoService;
import com.sunyo.wlpt.dispatch.utils.GetUUID;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
/**
* @author 子诚
* Description:
* 时间:2020/4/24 20:30
*/
@Api("调度记录信息,业务")
@RequestMapping("dispatchNote")
@RestController
public class DispatchNoteController {
@Autowired
private DispatchNoteService dispatchNoteService;
@Autowired
private VehicleInfoService vehicleInfoService;
/**
* 获取,调度记录信息列表
*/
@GetMapping("/selectDispatchNoteList")
public ResultJson<PageInfo> selectDispatchNoteList(
@RequestParam(value = "userName", required = false) String userName,
@RequestParam(value = "userMobile", required = false) String userMobile,
@RequestParam(value = "dispatchType", required = false) String dispatchType,
@RequestParam(value = "gmtCreate", required = false) Date gmtCreate,
@RequestParam(value = "endTime", required = false) Date endTime,
@RequestParam(value = "status", required = false) String status,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
ResultJson<PageInfo> result = new ResultJson<>();
DispatchNote dispatchNote = new DispatchNote();
/**
* 用户端查询,需要四个参数:
* 1.用户姓名(前端必填);2.用户电话(前端必填);3.业务类型;4.创建时间
*
* 管理员端查询,需要六个参数(没有必填):
* 1.用户姓名;2.用户电话;3.创建时间;4.完成时间
* 5.业务类型;6.记录状态
*/
if ("".equals(userName)) {
//获取参数,用户姓名
dispatchNote.setUserName(userName);
}
if ("".equals(userMobile)) {
//获取参数,用户联系方式
dispatchNote.setUserMobile(userMobile);
}
if ("".equals(dispatchType)) {
//获取参数,业务类型
dispatchNote.setDispatchType(dispatchType);
}
if (null != gmtCreate) {
//获取参数,创建时间
dispatchNote.setGmtCreate(gmtCreate);
}
if ("".equals(status)) {
//获取参数,记录表状态
dispatchNote.setStatus(status);
}
if (null != endTime) {
//获取参数,任务结束(完成)时间
dispatchNote.setEndTime(endTime);
}
PageInfo pageInfo = dispatchNoteService.selectDispatchNoteList(dispatchNote, pageNum, pageSize);
if (pageInfo.getTotal() > 0) {
result.setData(pageInfo);
result.setMsg("查询调度记录,成功");
} else {
result.setCode("400");
result.setMsg("查询调度记录,失败");
}
return result;
}
@ApiOperation("删除调度记录信息")
@DeleteMapping("/updateDispatchNote")
public ResultJson<DispatchNote> deleteDispatchNote(@RequestBody DispatchNote dispatchNote) {
ResultJson<DispatchNote> result = new ResultJson<>();
/**
* 如果调度记录为执行状态("2")
* 则将对应车辆的状态,修改为空闲状态("1"),并设置开始空闲时间
*/
String status = "2";
if (status.equals(dispatchNote.getStatus())) {
String licensePlateNumber = dispatchNote.getLicensePlateNumber();
//根据车牌号查询到车辆信息
VehicleInfo vehicleInfo = vehicleInfoService.selectByLPN(licensePlateNumber);
//设置车辆信息表,为空闲状态(1)
vehicleInfo.setVehicleStatus("1");
//设置车辆信息,开始空闲时间
vehicleInfo.setFreetime(new Date());
//根据主键,选择性修改
vehicleInfoService.updateByPrimaryKeySelective(vehicleInfo);
}
int num = dispatchNoteService.deleteByPrimaryKey(dispatchNote.getId());
if (num > 0) {
result.setMsg("删除调度记录信息,成功");
} else {
result.setCode("400");
result.setMsg("删除调度记录信息,失败");
}
return result;
}
@ApiOperation("编辑调度记录信息")
@PutMapping("/updateDispatchNote")
public ResultJson<DispatchNote> updateDispatchNote(@RequestBody DispatchNote dispatchNote) {
ResultJson<DispatchNote> result = new ResultJson<>();
//设置调度记录,操作类型,修改(2)
dispatchNote.setOperation("2");
int num = dispatchNoteService.updateByPrimaryKeySelective(dispatchNote);
if (num > 0) {
result.setMsg("修改调度记录信息,成功");
} else {
result.setCode("400");
result.setMsg("修改调度记录信息,失败");
}
return result;
}
@ApiOperation("增加调度记录信息")
@PostMapping("/insertDispatchNote")
public ResultJson<DispatchNote> insertDispatchNote(@RequestBody DispatchNote dispatchNote) {
ResultJson<DispatchNote> result = new ResultJson<>();
//设置调度记录,id值(uuid)
dispatchNote.setId(GetUUID.getuuid());
//设置调度记录,车辆数量为1辆
dispatchNote.setVehicleNumber(1);
//设置调度记录,操作类型,新增(1)
dispatchNote.setOperation("1");
int num = dispatchNoteService.insertSelective(dispatchNote);
if (num > 0) {
result.setMsg("添加调度记录信息,成功");
} else {
result.setCode("400");
result.setMsg("添加调度记录信息,失败");
}
return result;
}
}