DispatchNoteController.java
7.5 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
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.DateTimeUtils;
import com.sunyo.wlpt.dispatch.utils.GetUUID;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author 子诚
* Description:
* 时间:2020/4/24 20:30
*/
@CrossOrigin
@Api(value = "调度记录信息,业务", tags = "业务管理——车辆调度记录信息")
@RequestMapping("dispatch/dispatchNote")
@RestController
public class DispatchNoteController {
@Autowired
private DispatchNoteService dispatchNoteService;
@Autowired
private VehicleInfoService vehicleInfoService;
@ApiOperation("分页查询,调度记录信息列表")
@GetMapping("/selectDispatchNoteList")
public ResultJson<PageInfo> selectDispatchNoteList(
@ApiParam(name = "userName", value = "用户姓名", required = false)
@RequestParam(value = "userName", required = false) String userName,
@ApiParam(name = "userMobile", value = "用户联系方式", required = false)
@RequestParam(value = "userMobile", required = false) String userMobile,
@ApiParam(name = "dispatchType", value = "业务类型", required = false)
@RequestParam(value = "dispatchType", required = false) String dispatchType,
@ApiParam(name = "gmtCreate", value = "任务创建时间", required = false)
@RequestParam(value = "gmtCreate", required = false) Date gmtCreate,
@ApiParam(name = "endTime", value = "任务结束时间", required = false)
@RequestParam(value = "endTime", required = false) Date endTime,
@ApiParam(name = "status", value = "调度记录表状态:1.完成状态;2.执行状态;3、取消(撤销)状态", required = false)
@RequestParam(value = "status", required = false) String status,
@ApiParam(name = "pageNum", value = "第几页,默认为第一页", required = false)
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@ApiParam(name = "pageSize", value = "每页数量,默认10条", required = false)
@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.记录状态
*/
//获取参数,用户姓名
dispatchNote.setUserName(userName);
//获取参数,用户联系方式
dispatchNote.setUserMobile(userMobile);
//获取参数,业务类型
dispatchNote.setDispatchType(dispatchType);
//获取参数,创建时间
dispatchNote.setGmtCreate(gmtCreate);
//获取参数,记录表状态
dispatchNote.setStatus(status);
//获取参数,任务结束(完成)时间
dispatchNote.setEndTime(endTime);
PageInfo pageInfo = dispatchNoteService.selectDispatchNoteList(dispatchNote, pageNum, pageSize);
if (pageInfo.getTotal() > 0) {
result.setCode("200");
result.setData(pageInfo);
result.setMsg("查询调度记录,成功");
} else {
result.setCode("400");
result.setMsg("查询调度记录,失败");
}
return result;
}
@ApiOperation("删除调度记录信息")
@DeleteMapping("/deleteDispatchNote")
public ResultJson<DispatchNote> deleteDispatchNote(@RequestBody DispatchNote dispatchNote) {
ResultJson<DispatchNote> result = new ResultJson<>();
/**
* 如果调度记录为执行状态("2")
* 如果调度记录为待执行状态("4")
* 则将对应车辆的状态,修改为空闲状态("1"),并设置开始空闲时间
*/
String status2 = "2";
String status4 = "4";
if (status2.equals(dispatchNote.getStatus()) || status4.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.setCode("200");
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.setCode("200");
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.setCode("200");
result.setMsg("添加调度记录信息,成功");
} else {
result.setCode("400");
result.setMsg("添加调度记录信息,失败");
}
return result;
}
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
}