package com.stylefeng.guns.modular.crossCity.controller; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import com.stylefeng.guns.modular.crossCity.server.ILineShiftDriverService; import com.stylefeng.guns.modular.crossCity.warpper.DriverShiftListWarpper; import com.stylefeng.guns.modular.crossCity.warpper.LineShiftItemWarpper; import com.stylefeng.guns.modular.crossCity.warpper.OtherDriverShiftWarpper; import com.stylefeng.guns.modular.crossCity.warpper.ScanOrderDetailWarpper; import com.stylefeng.guns.modular.crossCity.warpper.AddSelfTripWarpper; import com.stylefeng.guns.modular.system.service.IDriverService; import com.stylefeng.guns.modular.system.util.ResultUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.Date; import java.util.List; import java.util.Map; /** * 【202601】城际专线排班控制器 */ @Api @RestController @RequestMapping("/api/crossCity") public class CrossCityShiftController { @Autowired private ILineShiftDriverService lineShiftDriverService; @Autowired private IDriverService driverService; /** * 【202601】获取司机城际专线排班列表 * @param date 日期(yyyy-MM-dd),默认当天 * @param request * @return */ @ResponseBody @PostMapping("/queryDriverShiftList") @ApiOperation(value = "【202601】获取司机城际专线排班列表", tags = {"司机端-首页"}, notes = "获取司机在指定日期的城际专线排班信息,支持7天日期选择") @ApiImplicitParams({ @ApiImplicitParam(value = "日期(yyyy-MM-dd),默认当天", name = "date", required = false, dataType = "String"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil queryDriverShiftList(String date, HttpServletRequest request) { try { Integer driverId = driverService.getUserIdFormRedis(request); if (null == driverId) { return ResultUtil.tokenErr(); } if (StringUtils.isNotBlank(date)) { ResultUtil driverShiftListWarpperResultUtil = validateDate(date); if (driverShiftListWarpperResultUtil.getCode().equals(ResultUtil.ERROR)) { return driverShiftListWarpperResultUtil; } } DriverShiftListWarpper result = lineShiftDriverService.queryDriverShiftList(driverId, date); return ResultUtil.success(result); } catch (Exception e) { e.printStackTrace(); return ResultUtil.runErr(); } } /** * 【202604】获取司机本人排班列表 * @param request * @return */ @ResponseBody @PostMapping("/queryMyDriverShiftList") @ApiOperation(value = "【202604】获取司机本人排班列表", tags = {"司机端-首页"}, notes = "date为空查今天及之后,不为空仅查当天,支持分页") @ApiImplicitParams({ @ApiImplicitParam(value = "日期(yyyy-MM-dd),默认无", name = "date", required = false, dataType = "String"), @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"), @ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> queryMyDriverShiftList(String date, int pageNum, int size, HttpServletRequest request) { try { Integer driverId = driverService.getUserIdFormRedis(request); if (null == driverId) { return ResultUtil.tokenErr(); } List result = lineShiftDriverService.queryMyDriverShiftList(driverId, date, pageNum, size); return ResultUtil.success(result); } catch (Exception e) { e.printStackTrace(); return ResultUtil.runErr(); } } /** * 【202604】根据司机排班ID查询同班次其他司机信息 * @param request * @return */ @ResponseBody @GetMapping("/queryOtherDriverShiftListWithShiftId") @ApiOperation(value = "【202604】查询同班次其他司机信息", tags = {"司机端-首页"}, notes = "根据driverShiftId查询同lineShiftId且同day的其他司机信息") @ApiImplicitParams({ @ApiImplicitParam(value = "司机排班记录ID", name = "driverShiftId", required = true, dataType = "long"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> queryOtherDriverShiftListWithShiftId(long driverShiftId, HttpServletRequest request) { try { Integer driverId = driverService.getUserIdFormRedis(request); if (null == driverId) { return ResultUtil.tokenErr(); } List result = lineShiftDriverService.queryOtherDriverShiftListWithShiftId(driverShiftId); return ResultUtil.success(result); } catch (Exception e) { e.printStackTrace(); return ResultUtil.runErr(); } } /** * 【202604】新增司机自主行程 */ @ResponseBody @PostMapping("/addSelfTrip") @ApiOperation(value = "【202604】新增司机自主行程", tags = {"司机端-首页"}, notes = "新增司机自主行程并写入排班主表") @ApiImplicitParams({ @ApiImplicitParam(value = "出发日期(yyyy-MM-dd)", name = "day", required = true, dataType = "String"), @ApiImplicitParam(value = "出发时间(HH:mm)", name = "startTime", required = true, dataType = "String"), @ApiImplicitParam(value = "座位数", name = "seat", required = true, dataType = "int"), @ApiImplicitParam(value = "出发城市编码", name = "startCityCode", required = false, dataType = "String"), @ApiImplicitParam(value = "出发城市名称", name = "startCityName", required = false, dataType = "String"), @ApiImplicitParam(value = "出发地地址", name = "startAddress", required = true, dataType = "String"), @ApiImplicitParam(value = "出发地经度", name = "startLon", required = true, dataType = "double"), @ApiImplicitParam(value = "出发地纬度", name = "startLat", required = true, dataType = "double"), @ApiImplicitParam(value = "目的地JSON数组(每项需包含endCityCode/endCityName/endAddress/endLon/endLat/price)", name = "destJson", required = true, dataType = "String"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> addSelfTrip(AddSelfTripWarpper warpper, HttpServletRequest request) { try { Integer driverId = driverService.getUserIdFormRedis(request); if (null == driverId) { return ResultUtil.tokenErr(); } return lineShiftDriverService.addSelfTrip(driverId, warpper); } catch (Exception e) { e.printStackTrace(); return ResultUtil.runErr(); } } /** * 验证日期有效性 * @param dateStr * @return */ public ResultUtil validateDate(String dateStr) { // 解析日期 Date targetDate = DateUtil.parse(dateStr, "yyyy-MM-dd"); Date today = DateUtil.beginOfDay(new Date()); // 今天 00:00:00 // 1. 不能是今天之前的日期 if (targetDate.before(today)) { return ResultUtil.error("日期不能早于今天"); } // 2. 必须在7天内(包含今天,即今天 + 6天) long daysBetween = DateUtil.between(today, targetDate, DateUnit.DAY); if (daysBetween > 6) { // 今天是第1天,所以差值最大为6 return ResultUtil.error("只能查询7天内的排班信息"); } return ResultUtil.success(); } /** * 【202601】获取班次详情 * @param lineShiftDriverId 司机排班记录ID * @return 扫码下单详情 */ @ResponseBody @RequestMapping(value = "/getDetail", method = RequestMethod.GET) @ApiOperation(value = "【202601】获取扫码下单详情", tags = {"用户端-跨城"}, notes = "根据扫码内容获取下单页面详情数据,包含司机信息、线路信息、站点信息等") @ApiImplicitParam(value = "司机排班记录ID", name = "lineShiftDriverId", required = true, dataType = "int") public ResultUtil getDetail(Integer lineShiftDriverId) { try { return lineShiftDriverService.getDetail(lineShiftDriverId); } catch (Exception e) { e.printStackTrace(); return ResultUtil.runErr(); } } }