longz
2026-06-04 da780b14b8db78043d2c0f27d3bfd73111e6d550
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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<DriverShiftListWarpper> queryDriverShiftList(String date, HttpServletRequest request) {
        try {
            Integer driverId = driverService.getUserIdFormRedis(request);
            if (null == driverId) {
                return ResultUtil.tokenErr();
            }
            if (StringUtils.isNotBlank(date)) {
                ResultUtil<DriverShiftListWarpper> 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<List<LineShiftItemWarpper>> queryMyDriverShiftList(String date, int pageNum, int size, HttpServletRequest request) {
        try {
            Integer driverId = driverService.getUserIdFormRedis(request);
            if (null == driverId) {
                return ResultUtil.tokenErr();
            }
            List<LineShiftItemWarpper> 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<List<OtherDriverShiftWarpper>> queryOtherDriverShiftListWithShiftId(long driverShiftId, HttpServletRequest request) {
        try {
            Integer driverId = driverService.getUserIdFormRedis(request);
            if (null == driverId) {
                return ResultUtil.tokenErr();
            }
            List<OtherDriverShiftWarpper> 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<Map<String, Object>> 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<DriverShiftListWarpper> 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<ScanOrderDetailWarpper> getDetail(Integer lineShiftDriverId) {
        try {
            return lineShiftDriverService.getDetail(lineShiftDriverId);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
}