|
@@ -1,30 +1,33 @@
|
|
|
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 cn.hutool.core.util.StrUtil;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.bus.config.OSSConfig;
|
|
|
+import com.jpsoft.bus.modules.bus.dto.StationStatusDTO;
|
|
|
+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.dto.Sort;
|
|
|
+import com.jpsoft.bus.modules.common.utils.CommonUtil;
|
|
|
import com.jpsoft.bus.modules.common.utils.JwtUtil;
|
|
|
+import com.jpsoft.bus.modules.common.utils.OSSUtil;
|
|
|
+import com.jpsoft.bus.modules.common.utils.PojoUtils;
|
|
|
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;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-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.bind.annotation.*;
|
|
|
+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 +42,30 @@ public class DriverApiController {
|
|
|
@Value("${jwt.secret}")
|
|
|
private String jwtSecret;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ShiftInfoService shiftInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BaiduService baiduService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GpsService gpsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PassengerInfoService passengerInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StationInfoService stationInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RouteInfoService routeInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DriverRecordInfoService driverRecordInfoService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private DriverInfoService driverInfoService;
|
|
|
|
|
@@ -62,16 +86,17 @@ public class DriverApiController {
|
|
|
if (vehicleInfo == null){
|
|
|
throw new Exception("车牌号或激活码错误");
|
|
|
}
|
|
|
- if ("1".equals(vehicleInfo.getStatus())){
|
|
|
+ /*if ("1".equals(vehicleInfo.getStatus())){
|
|
|
throw new Exception("此车辆已被激活");
|
|
|
- }
|
|
|
+ }*/
|
|
|
vehicleInfo.setStatus("1");
|
|
|
vehicleInfoService.update(vehicleInfo);
|
|
|
|
|
|
- String token = JwtUtil.createToken(jwtSecret, vehicleInfo.getId(), DateTime.now().plusHours(6).toDate());
|
|
|
+ String token = JwtUtil.createToken(jwtSecret, vehicleInfo.getId(), DateTime.now().plusDays(30).toDate());
|
|
|
|
|
|
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 +145,323 @@ 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 = "photoBase64Data", value = "照片base64编码", required = true, paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "token", value = "令牌", paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form")
|
|
|
+ })
|
|
|
+ public MessageResult<DriverRecordInfo> driverAttendance(String driverId, String photoBase64Data, String recordTime, String token, @RequestAttribute String subject) {
|
|
|
+ MessageResult<DriverRecordInfo> 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.uploadBase64(photoBase64Data,driverId+".jpg",ossConfig);
|
|
|
+ // 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.setData(driverRecordInfo);
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setCode(200);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("findLastAttendanceRecord")
|
|
|
+ @ApiOperation(value="查询司机今日最后考勤打卡")
|
|
|
+ public MessageResult<DriverRecordInfo> findLastAttendanceRecord(@RequestAttribute String subject,Long driverId){
|
|
|
+ MessageResult<DriverRecordInfo> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ VehicleInfo vehicleInfo = vehicleInfoService.get(subject);
|
|
|
+
|
|
|
+ Date startTime = DateTime.now().withTimeAtStartOfDay().toDate();
|
|
|
+
|
|
|
+ DriverRecordInfo driverRecordInfo = driverRecordInfoService.findLastAttendanceRecord(driverId,vehicleInfo.getLicensePlateNumber(),startTime);
|
|
|
+
|
|
|
+ //todo 填写具体代码
|
|
|
+ messageResult.setData(driverRecordInfo);
|
|
|
+ messageResult.setResult(true);
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ log.error(ex.getMessage(),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());
|
|
|
+
|
|
|
+ //当前站点
|
|
|
+ StationInfo currentStation = stationInfoService.get(shiftInfo.getCurrentStationId());
|
|
|
+
|
|
|
+ StationStatusDTO stationStatusDTO = gpsService.queryStation(vehicleInfo.getId());
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("startStationId",startStation.getId());
|
|
|
+ map.put("startStationName",startStation.getName());
|
|
|
+ map.put("endStationId",endStation.getId());
|
|
|
+ map.put("endStationName",endStation.getName());
|
|
|
+ map.put("currentStationId",currentStation.getId());
|
|
|
+ map.put("currentStationName",currentStation.getName());
|
|
|
+ map.put("nextStationId",stationStatusDTO.getNextStationId());
|
|
|
+ map.put("nextStationName",stationStatusDTO.getNextStationName());
|
|
|
+
|
|
|
+ messageResult.setData(map);
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setCode(200);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("passengerFaceRegister")
|
|
|
+ @ApiOperation(value = "乘客刷脸登记")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "personId", value = "乘客在设备上的id", required = true, paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "recordTime", value = "登记时间", required = true, paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "photoBase64Data", value = "照片base64编码", required = true, paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "token", value = "令牌", paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form")
|
|
|
+ })
|
|
|
+ public MessageResult<Map> passengerFaceRegister(String personId, String photoBase64Data, String recordTime,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);
|
|
|
+ String retFileUrl = OSSUtil.uploadBase64(photoBase64Data,personId+".jpg",ossConfig);
|
|
|
+
|
|
|
+
|
|
|
+ passengerInfoService.passengerFace(vehicleInfo,shiftInfo,retFileUrl,recordTime,shiftInfo.getCurrentStationId(),personId);
|
|
|
+
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setCode(200);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("busShiftTicketList")
|
|
|
+ @ApiOperation(value = "车辆班次购票情况列表")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "token", value = "令牌", paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "type", value = "1:未购票,2:待下车,3:待补票,4:全部", required = true, paramType = "form")
|
|
|
+ })
|
|
|
+ public MessageResult<Map> busShiftNoTicket(String token, @RequestAttribute String subject,@RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,@RequestParam(value = "pageSize", defaultValue = "20") int pageSize,String type) {
|
|
|
+ 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);
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ searchParams.put("vehicleShiftId",shiftInfo.getId());
|
|
|
+ searchParams.put("status","1");
|
|
|
+ //未购票
|
|
|
+ if ("1".equals(type)){
|
|
|
+ searchParams.put("payStatus","0");
|
|
|
+ }
|
|
|
+ //待下车
|
|
|
+ if ("2".equals(type)){
|
|
|
+ searchParams.put("notPayStatus","0");
|
|
|
+ searchParams.put("downStationId",shiftInfo.getCurrentStationId());
|
|
|
+ }
|
|
|
+ //待补票
|
|
|
+ if ("3".equals(type)){
|
|
|
+ searchParams.put("payStatus","2");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("create_time","desc"));
|
|
|
+ Page<PassengerInfo> page = passengerInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
+
|
|
|
+
|
|
|
+ messageResult.setData(PojoUtils.pageWrapper(page));
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setCode(200);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
}
|