|
@@ -1,18 +1,18 @@
|
|
|
package com.jpsoft.bus.modules.driver.controller;
|
|
|
|
|
|
-import com.jpsoft.bus.modules.bus.entity.DriverInfo;
|
|
|
-import com.jpsoft.bus.modules.bus.entity.ShiftInfo;
|
|
|
-import com.jpsoft.bus.modules.bus.entity.VehicleInfo;
|
|
|
-import com.jpsoft.bus.modules.bus.service.DriverInfoService;
|
|
|
-import com.jpsoft.bus.modules.bus.service.ShiftInfoService;
|
|
|
-import com.jpsoft.bus.modules.bus.service.VehicleInfoService;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.jpsoft.bus.config.OSSConfig;
|
|
|
+import com.jpsoft.bus.modules.bus.entity.*;
|
|
|
+import com.jpsoft.bus.modules.bus.service.*;
|
|
|
import com.jpsoft.bus.modules.common.dto.MessageResult;
|
|
|
import com.jpsoft.bus.modules.common.utils.JwtUtil;
|
|
|
+import com.jpsoft.bus.modules.common.utils.OSSUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.bouncycastle.crypto.signers.ECDSASigner;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -21,10 +21,10 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* @author 墨鱼_mo
|
|
@@ -39,9 +39,21 @@ public class DriverApiController {
|
|
|
@Value("${jwt.secret}")
|
|
|
private String jwtSecret;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ShiftInfoService shiftInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StationInfoService stationInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RouteInfoService routeInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DriverRecordInfoService driverRecordInfoService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private DriverInfoService driverInfoService;
|
|
|
|
|
@@ -72,6 +84,7 @@ public class DriverApiController {
|
|
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
map.put("token",token);
|
|
|
+ map.put("vehicleInfo",vehicleInfo);
|
|
|
messageResult.setResult(true);
|
|
|
messageResult.setCode(200);
|
|
|
messageResult.setData(map);
|
|
@@ -120,4 +133,194 @@ public class DriverApiController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("driverAttendance")
|
|
|
+ @ApiOperation(value = "司机考勤")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "driverId", value = "司机id", required = true, paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "recordTime", value = "考勤时间", required = true, paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "photoFile", value = "员工照片", required = true, paramType = "form", dataType = "__file"),
|
|
|
+ @ApiImplicitParam(name = "token", value = "令牌", paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form")
|
|
|
+ })
|
|
|
+ public MessageResult<Map> driverAttendance(String driverId, MultipartFile photoFile, String recordTime, String token, @RequestAttribute String subject) {
|
|
|
+ MessageResult<Map> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ VehicleInfo vehicleInfo = vehicleInfoService.get(subject);
|
|
|
+ if (vehicleInfo == null){
|
|
|
+ throw new Exception("当前车辆不存在");
|
|
|
+ }
|
|
|
+ DriverInfo driverInfo = driverInfoService.get(driverId);
|
|
|
+ if (driverInfo == null){
|
|
|
+ throw new Exception("当前司机不存在");
|
|
|
+ }
|
|
|
+ String retFileUrl = OSSUtil.upload(ossConfig, "/faceImage", driverInfo.getName(), photoFile.getInputStream());
|
|
|
+ DriverRecordInfo driverRecordInfo = new DriverRecordInfo();
|
|
|
+ driverRecordInfo.setId(UUID.randomUUID().toString());
|
|
|
+ driverRecordInfo.setDriverId(driverInfo.getId());
|
|
|
+ driverRecordInfo.setLicensePlateNumber(vehicleInfo.getLicensePlateNumber());
|
|
|
+ driverRecordInfo.setRecordTime(DateUtil.parse(recordTime,"yyyy-MM-dd HH:mm:ss"));
|
|
|
+ driverRecordInfo.setPlace(vehicleInfo.getLatestAddress());
|
|
|
+ driverRecordInfo.setLatitude(vehicleInfo.getLatitude());
|
|
|
+ driverRecordInfo.setLongitude(vehicleInfo.getLongitude());
|
|
|
+ driverRecordInfo.setImageUrl(retFileUrl);
|
|
|
+ driverRecordInfo.setCreateTime(new Date());
|
|
|
+ driverRecordInfoService.insert(driverRecordInfo);
|
|
|
+
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setCode(200);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("busRouteInfo")
|
|
|
+ @ApiOperation(value = "车辆线路信息")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "token", value = "令牌", paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form")
|
|
|
+ })
|
|
|
+ public MessageResult<Map> busRouteInfo(String token, @RequestAttribute String subject) {
|
|
|
+ MessageResult<Map> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ VehicleInfo vehicleInfo = vehicleInfoService.get(subject);
|
|
|
+ if (vehicleInfo == null){
|
|
|
+ throw new Exception("当前车辆不存在");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(vehicleInfo.getRouteId())){
|
|
|
+ throw new Exception("当前车辆还未分配线路");
|
|
|
+ }
|
|
|
+ RouteInfo routeInfo = routeInfoService.get(vehicleInfo.getRouteId());
|
|
|
+ if (routeInfo == null){
|
|
|
+ throw new Exception("线路错误");
|
|
|
+ }
|
|
|
+ //始发站
|
|
|
+ List<StationInfo> startStationInfoList = stationInfoService.findByRouteIdAndClassify(routeInfo.getId(),1);
|
|
|
+ if (startStationInfoList.size() != 1){
|
|
|
+ throw new Exception("线路的始发站配置错误");
|
|
|
+ }
|
|
|
+ //终点站
|
|
|
+ List<StationInfo> endStationInfoList = stationInfoService.findByRouteIdAndClassify(routeInfo.getId(),3);
|
|
|
+ if (endStationInfoList.size() != 1){
|
|
|
+ throw new Exception("线路的终点站配置错误");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("startStationId",startStationInfoList.get(0).getId());
|
|
|
+ map.put("startStationName",startStationInfoList.get(0).getName());
|
|
|
+ map.put("endStationId",endStationInfoList.get(0).getId());
|
|
|
+ map.put("endStationName",endStationInfoList.get(0).getName());
|
|
|
+
|
|
|
+ messageResult.setData(map);
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setCode(200);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("createShift")
|
|
|
+ @ApiOperation(value = "开班")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "token", value = "令牌", paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "driverId", value = "司机id", required = true, paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "startStationId", value = "始发站id", required = true, paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "endStationId", value = "终点站id", required = true, paramType = "form")
|
|
|
+
|
|
|
+ })
|
|
|
+ public MessageResult<Map> createShift(String driverId,String startStationId,String endStationId ,String token, @RequestAttribute String subject) {
|
|
|
+ MessageResult<Map> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ VehicleInfo vehicleInfo = vehicleInfoService.get(subject);
|
|
|
+ if (vehicleInfo == null){
|
|
|
+ throw new Exception("当前车辆不存在");
|
|
|
+ }
|
|
|
+ DriverInfo driverInfo = driverInfoService.get(driverId);
|
|
|
+ if (driverInfo == null){
|
|
|
+ throw new Exception("司机不存在");
|
|
|
+ }
|
|
|
+ //始发站
|
|
|
+ StationInfo start = stationInfoService.get(startStationId);
|
|
|
+ //终点站
|
|
|
+ StationInfo end = stationInfoService.get(endStationId);
|
|
|
+ if (start == null || end == null){
|
|
|
+ throw new Exception("站点错误");
|
|
|
+ }
|
|
|
+ if (!start.getRouteId().equals(vehicleInfo.getRouteId()) || !end.getRouteId().equals(vehicleInfo.getRouteId())){
|
|
|
+ throw new Exception("站点错误");
|
|
|
+ }
|
|
|
+ shiftInfoService.createShift(vehicleInfo,driverId,startStationId,endStationId);
|
|
|
+
|
|
|
+
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setCode(200);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("busShiftInfo")
|
|
|
+ @ApiOperation(value = "车辆班次信息")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "token", value = "令牌", paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form")
|
|
|
+ })
|
|
|
+ public MessageResult<Map> busShiftInfo(String token, @RequestAttribute String subject) {
|
|
|
+ MessageResult<Map> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ VehicleInfo vehicleInfo = vehicleInfoService.get(subject);
|
|
|
+ if (vehicleInfo == null){
|
|
|
+ throw new Exception("当前车辆不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ShiftInfo> shiftInfoList = shiftInfoService.findByVehicleIdAndStatus(vehicleInfo.getId(),"1");
|
|
|
+ if (shiftInfoList.size() == 0){
|
|
|
+ throw new Exception("车辆没有相关班次信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ ShiftInfo shiftInfo = shiftInfoList.get(0);
|
|
|
+ //始发站
|
|
|
+ StationInfo startStation = stationInfoService.get(shiftInfo.getStartStationId());
|
|
|
+ //终点站
|
|
|
+ StationInfo endStation = stationInfoService.get(shiftInfo.getEndStationId());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ /*map.put("startStationId",startStationInfoList.get(0).getId());
|
|
|
+ map.put("startStationName",startStationInfoList.get(0).getName());
|
|
|
+ map.put("endStationId",endStationInfoList.get(0).getId());
|
|
|
+ map.put("endStationName",endStationInfoList.get(0).getName());*/
|
|
|
+
|
|
|
+ messageResult.setData(map);
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setCode(200);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+
|
|
|
}
|