...
|
...
|
@@ -6,12 +6,14 @@ 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.apache.ibatis.annotations.Update;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
...
|
...
|
@@ -22,7 +24,7 @@ import static java.util.stream.Collectors.toList; |
|
|
* Description:调度车辆
|
|
|
* 时间:2020/4/21 16:44
|
|
|
*/
|
|
|
@Api(value = "调度车辆业务")
|
|
|
@Api(value = "调度车辆业务", tags = "业务——我要调度车辆")
|
|
|
@RequestMapping("dispatch")
|
|
|
@RestController
|
|
|
public class DispatchController {
|
...
|
...
|
@@ -33,27 +35,36 @@ public class DispatchController { |
|
|
@Autowired
|
|
|
private DispatchNoteService dispatchNoteService;
|
|
|
|
|
|
@ApiOperation(value = "我要调度车辆")
|
|
|
@ApiOperation(value = "我要调度车辆", notes = "我要调度车辆")
|
|
|
@PostMapping("/dispatch")
|
|
|
public ResultJson<VehicleInfo> dispatch(@RequestBody DispatchNote req) {
|
|
|
public ResultJson dispatch(@RequestBody DispatchNote req) {
|
|
|
//返回前端的
|
|
|
ResultJson<VehicleInfo> result = new ResultJson<>();
|
|
|
ResultJson result = new ResultJson<>();
|
|
|
|
|
|
/**
|
|
|
* 1.获取到用户的需求
|
|
|
*/
|
|
|
Integer vehicleNumber = req.getVehicleNumber();
|
|
|
String vehicleType = req.getVehicleType();
|
|
|
|
|
|
VehicleInfo vehicleInfo = new VehicleInfo();
|
|
|
// 匹配车辆条件,车辆状态为空闲(1)
|
|
|
String vehicleStatus = "1";
|
|
|
vehicleInfo.setVehicleStatus("1");
|
|
|
// 匹配车辆条件,车辆类型
|
|
|
vehicleInfo.setVehicleType(req.getVehicleType());
|
|
|
|
|
|
// 2.根据用户的需求(车辆类型、数量进行匹配)
|
|
|
List<VehicleInfo> vehicleInfoList = vehicleInfoService.dispatchVehicle(vehicleType, vehicleStatus);
|
|
|
List<VehicleInfo> vehicleInfoList = vehicleInfoService.dispatchVehicle(vehicleInfo);
|
|
|
|
|
|
for(int i=0;i<vehicleInfoList.size(); i++){
|
|
|
System.out.println(vehicleInfoList.get(i));
|
|
|
}
|
|
|
// 3.对查询出来的结果进行匹配
|
|
|
if (vehicleInfoList.size() >= vehicleNumber) {
|
|
|
//取出前(需求)个
|
|
|
List<VehicleInfo> needList = vehicleInfoList.stream()
|
|
|
.limit(vehicleNumber)
|
|
|
.collect(toList());
|
|
|
|
|
|
for (int i = 0; i < needList.size(); i++) {
|
|
|
/**
|
|
|
* 1、通知车牌号为 XX 的车被调用,任务地点:场站位置;业务类型:XXXX
|
...
|
...
|
@@ -72,16 +83,20 @@ public class DispatchController { |
|
|
//2.修改车辆状态
|
|
|
needList.get(i).setVehicleStatus("2");
|
|
|
// 将车辆状态设置为执行状态
|
|
|
vehicleInfoService.updateByPrimaryKey(needList.get(i));
|
|
|
vehicleInfoService.updateByPrimaryKeySelective(needList.get(i));
|
|
|
/**
|
|
|
* 3.生成调度表业务
|
|
|
*/
|
|
|
// 生成调度记录表
|
|
|
DispatchNote dispatchNote = new DispatchNote();
|
|
|
//记录表,设置id
|
|
|
dispatchNote.setId(GetUUID.getuuid());
|
|
|
//记录表,设置用户的姓名
|
|
|
dispatchNote.setUserName(req.getUserName());
|
|
|
//记录表,设置用户的联系方式
|
|
|
dispatchNote.setUserMobile(req.getUserMobile());
|
|
|
//记录表,设置车牌号
|
|
|
dispatchNote.setLicensePlateNumber(needList.get(i).getLicensePlateNumber());
|
|
|
//记录表,设置调度业务类型
|
|
|
dispatchNote.setDispatchType(req.getDispatchType());
|
|
|
//记录表,设置场站位置
|
...
|
...
|
@@ -92,11 +107,13 @@ public class DispatchController { |
|
|
dispatchNote.setVehicleType(req.getVehicleType());
|
|
|
//记录表,设置记录状态为执行状态(2)
|
|
|
dispatchNote.setStatus("2");
|
|
|
//记录表,设置创建时间
|
|
|
dispatchNote.setGmtCreate(new Date());
|
|
|
// 生成调度记录表
|
|
|
dispatchNoteService.insertSelective(dispatchNote);
|
|
|
}
|
|
|
//车辆匹配成功,返回车辆信息
|
|
|
result.setData((VehicleInfo) needList);
|
|
|
result.setData(needList);
|
|
|
result.setCode("200");
|
|
|
result.setMsg("车辆调度成功!");
|
|
|
} else {
|
...
|
...
|
@@ -141,7 +158,7 @@ public class DispatchController { |
|
|
dispatchNoteService.updateByPrimaryKeySelective(req);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("取消调度车辆")
|
|
|
@ApiOperation(value = "取消调度车辆", notes = "判断了多种情况下,取消调度车辆")
|
|
|
@PutMapping("/cancel")
|
|
|
public ResultJson cancel(@RequestBody DispatchNote req) {
|
|
|
ResultJson<DispatchNote> result = new ResultJson<>();
|
...
|
...
|
|