作者 王勇

修改调度车辆方法

... ... @@ -34,6 +34,13 @@
</dependency>
<!-- SpringBoot end -->
<!-- Security start -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- Security end -->
<!-- SpringCloud start -->
<dependency>
<groupId>org.springframework.cloud</groupId>
... ... @@ -110,12 +117,21 @@
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.22</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.22</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
... ...
package com.sunyo.wlpt.dispatch.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
/**
* @author 子诚
* Description:SpringSecurity 权限配置框架
* 时间:2020/4/27 9:57
*/
@EnableWebSecurity
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
//首页所有人可以访问,功能页只有对应的权限才能访问
http.authorizeRequests()
.antMatchers("/").permitAll();
http.csrf().disable();
}
}
... ...
... ... @@ -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<>();
... ...
... ... @@ -9,6 +9,7 @@ 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 io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
... ... @@ -19,7 +20,7 @@ import java.util.Date;
* Description:
* 时间:2020/4/24 20:30
*/
@Api("调度记录信息,业务")
@Api(value = "调度记录信息,业务", tags = "业务管理——车辆调度记录信息")
@RequestMapping("dispatchNote")
@RestController
public class DispatchNoteController {
... ... @@ -28,18 +29,24 @@ public class DispatchNoteController {
@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();
... ...
... ... @@ -7,6 +7,7 @@ import com.sunyo.wlpt.dispatch.service.DriverInfoService;
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.web.bind.annotation.*;
... ... @@ -15,7 +16,7 @@ import org.springframework.web.bind.annotation.*;
* Description:
* 时间:2020/4/26 14:04
*/
@Api("驾驶员信息管理")
@Api(value = "驾驶员信息管理", tags = "业务管理——驾驶员信息管理")
@RequestMapping("/driverInfo")
@RestController
public class DriverInfoController {
... ... @@ -26,11 +27,17 @@ public class DriverInfoController {
@ApiOperation("获取驾驶员列表")
@GetMapping("/selectDriverInfoList")
public ResultJson<PageInfo> selectDriverInfoList(
@ApiParam(name = "driverName", value = "驾驶员姓名", required = false)
@RequestParam(value = "driverName", required = false) String driverName,
@ApiParam(name = "driverMobile", value = "驾驶员联系方式", required = false)
@RequestParam(value = "driverMobile", required = false) String driverMobile,
@ApiParam(name = "driverCompany", value = "驾驶员所属公司", required = false)
@RequestParam(value = "driverCompany", required = false) String driverCompany,
@ApiParam(name = "driverStatus", value = "驾驶员状态:驾驶员状态:1.空闲状态;2.执行状态;3.轮休状态;.请假状态", required = false)
@RequestParam(value = "driverStatus", required = false) String driverStatus,
@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<>();
DriverInfo driverInfo = new DriverInfo();
... ...
... ... @@ -7,6 +7,7 @@ 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 io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
... ... @@ -17,7 +18,7 @@ import java.util.Date;
* Description:
* 时间:2020/4/24 17:03
*/
@Api("车辆信息")
@Api(value = "车辆信息", tags = "业务管理——车辆信息管理")
@RequestMapping("vehicleInfo")
@RestController
public class VehicleInfoController {
... ... @@ -27,11 +28,17 @@ public class VehicleInfoController {
@ApiOperation("获取车辆列表")
@GetMapping("/selectVehicleInfoList")
public ResultJson<PageInfo> selectVehicleInfoList(
@ApiParam(name = "vehicleStatus", value = "车辆状态:1.空闲状态;2.执行状态;3、在修状态;4.损坏未修状态;5.保养状态", required = false)
@RequestParam(value = "vehicleStatus", required = false) String vehicleStatus,
@ApiParam(name = "vehicleType", value = "车辆类型", required = false)
@RequestParam(value = "vehicleType", required = false) String vehicleType,
@ApiParam(name = "licensePlateNumber", value = "车牌号", required = false)
@RequestParam(value = "licensePlateNumber", required = false) String licensePlateNumber,
@ApiParam(name = "vehicleCompany", value = "车辆所属公司", required = false)
@RequestParam(value = "vehicleCompany", required = false) String vehicleCompany,
@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<>();
... ...
... ... @@ -23,7 +23,7 @@ public class DispatchNote implements Serializable {
/**
* 调度记录编号uuid
*/
private String id = UUID.randomUUID().toString().replaceAll("-", "");
private String id;
/**
* 用户姓名
... ...
... ... @@ -21,7 +21,7 @@ public class DriverInfo implements Serializable {
/**
* 驾驶员信息编号uuid
*/
private String id = UUID.randomUUID().toString().replaceAll("-", "");
private String id;
/**
* 驾驶员姓名
... ...
... ... @@ -25,7 +25,7 @@ public class VehicleInfo implements Serializable {
/**
* 车辆信息编号uuid
*/
private String id = UUID.randomUUID().toString().replaceAll("-", "");
private String id;
/**
* 车牌号码
... ... @@ -84,7 +84,7 @@ public class VehicleInfo implements Serializable {
/**
* 车辆优先级(1,最好,2次之)
*/
private Integer priority;
private Integer priority = 2;
/**
* 车辆所属公司名称
... ...
... ... @@ -15,10 +15,13 @@ import org.apache.ibatis.annotations.Param;
@Mapper
public interface VehicleInfoMapper {
/**
* 调度车辆方法
* @param record
* @return
*/
List<VehicleInfo> dispatchVehicle(@Param("vehicleType") String vehicleType, @Param("vehicleStatus") String vehicleStatus);
List<VehicleInfo> dispatchVehicle(VehicleInfo record);
/**
* 分页查询,车辆列表
... ...
... ... @@ -3,6 +3,7 @@ package com.sunyo.wlpt.dispatch.response;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @author 子诚
... ... @@ -26,6 +27,7 @@ public class ResultJson<T> implements Serializable {
* 响应数据
*/
private T data;
/**
* JWT令牌
*/
... ...
... ... @@ -16,11 +16,10 @@ public interface VehicleInfoService {
/**
* 调度车辆方法
*
* @param vehicleType
* @param vehicleStatus
* @param vehicleInfo
* @return
*/
List<VehicleInfo> dispatchVehicle(String vehicleType, String vehicleStatus);
List<VehicleInfo> dispatchVehicle(VehicleInfo vehicleInfo);
/**
... ...
... ... @@ -30,8 +30,9 @@ public class VehicleInfoServiceImpl implements VehicleInfoService {
* @return List<VehicleInfo>
*/
@Override
public List<VehicleInfo> dispatchVehicle(String vehicleType, String vehicleStatus) {
return vehicleInfoMapper.dispatchVehicle(vehicleType, vehicleStatus);
public List<VehicleInfo> dispatchVehicle(VehicleInfo vehicleInfo) {
List<VehicleInfo> vehicleInfoList = vehicleInfoMapper.dispatchVehicle(vehicleInfo);
return vehicleInfoMapper.dispatchVehicle(vehicleInfo);
}
/**
... ...
... ... @@ -7,6 +7,10 @@ spring:
name: dispatch-system
profiles:
active: dev
security:
user:
name: admin
password: 123456
# 链路追踪配置
zipkin:
base-url: http://192.168.1.63:9411
... ... @@ -76,6 +80,10 @@ eureka:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
hostname: ${spring.cloud.client.ip-address}
metadata-map:
user:
name: "admin"
passwoed: "123456"
client:
healthcheck:
enabled: true
... ...
... ... @@ -39,12 +39,20 @@
where license_plate_number = #{licensePlateNumber,jdbcType=VARCHAR}
</select>
<select id="dispatchVehicle" resultType="com.sunyo.wlpt.dispatch.domain.VehicleInfo">
<!-- 调度车辆SQL语句 -->
<select id="dispatchVehicle" parameterType="com.sunyo.wlpt.dispatch.domain.VehicleInfo"
resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from vehicle_info
where vehicle_status = #{vehicleStatus}
and vehicle_type =#{vehicleType}
<where>
<if test="vehicleStatus != null and vehicleStatus != ''">
vehicle_status = #{vehicleStatus,jdbcType=VARCHAR}
</if>
<if test="vehicleType != null and vehicleType != ''">
and vehicle_type = #{vehicleType,jdbcType=VARCHAR}
</if>
</where>
order by freetime,priority
</select>
... ...