| | |
| | | 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.system.service.IDriverService; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | | import com.stylefeng.guns.modular.system.util.SystemException; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 【202601】城际专线排班控制器 |
| | |
| | | if (null == driverId) { |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | 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) { |
| | |
| | | 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(); |
| | | } |
| | | } |