package com.stylefeng.guns.modular.system.service.impl;
|
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.stylefeng.guns.modular.system.dao.CarModelMapper;
|
import com.stylefeng.guns.modular.system.dao.DriverMapper;
|
import com.stylefeng.guns.modular.system.dao.LineShiftDriverMapper;
|
import com.stylefeng.guns.modular.system.dao.LineShiftMapper;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import com.stylefeng.guns.modular.system.util.DateUtil;
|
import com.stylefeng.guns.modular.system.util.ResultUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
|
|
@Service
|
public class DriverServiceImpl extends ServiceImpl<DriverMapper, Driver> implements IDriverService {
|
|
@Resource
|
private DriverMapper driverMapper;
|
|
@Autowired
|
private DateUtil dateUtil;
|
|
@Resource
|
private LineShiftMapper lineShiftMapper;
|
|
@Resource
|
private LineShiftDriverMapper lineShiftDriverMapper;
|
|
@Resource
|
private CarModelMapper carModelMapper;
|
|
@Autowired
|
private IOrderCrossCityService orderCrossCityService;
|
|
@Autowired
|
private IDriverService driverService;
|
|
@Autowired
|
private IReassignService reassignService;
|
|
@Autowired
|
private IOrderPrivateCarService orderPrivateCarService;
|
|
@Autowired
|
private IDispatchService dispatchService;
|
|
|
|
|
/**
|
* 获取预约了给定排班的司机列表
|
* @param lineShiftId
|
* @param time
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryLineShiftDriver(Integer lineShiftId, String time, Integer lineShiftDriverId, Integer driverId) throws Exception {
|
List<Map<String, Object>> datas = new ArrayList<>();
|
Map<String, Date> date = dateUtil.getStartAndEndDate(time);
|
List<Map<String, Object>> list = lineShiftMapper.queryInfo(lineShiftId, date.get("startTime"));
|
int num = 0;
|
List<OrderCrossCity> orderCrossCities = orderCrossCityService.queryByLineShiftDriverId(lineShiftDriverId, 2, 3, 4, 5, 11);
|
for(OrderCrossCity occ : orderCrossCities){
|
num += occ.getPeopleNumber();
|
}
|
for(Map<String, Object> map : list){
|
if(null != driverId && Integer.valueOf(map.get("driverId").toString()).compareTo(driverId) == 0){
|
continue;
|
}
|
LineShiftDriver lineShiftDriver = lineShiftDriverMapper.selectById(map.get("id").toString());
|
if(lineShiftDriver.getLaveSeat() < num){
|
continue;
|
}
|
Map<String, Object> map1 = new HashMap<>();
|
map1.put("id", map.get("driverId"));
|
map1.put("name", map.get("driver"));
|
datas.add(map1);
|
}
|
return datas;
|
}
|
|
|
/**
|
* 获取没有预约给定日期班次的司机
|
* @param lineShiftId
|
* @param time
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryNotInLineShiftDriver(Integer lineShiftId, String time) throws Exception {
|
Map<String, Date> date = dateUtil.getStartAndEndDate(time);
|
return lineShiftDriverMapper.queryNotInLineShiftDriver(lineShiftId, date.get("startTime"));
|
}
|
|
|
/**
|
* 调度端帮司机进行预约排班数据
|
* @param lineShiftId
|
* @param time
|
* @param driverId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil addDriverForLineShift(Integer lineShiftId, String time, Integer driverId) throws Exception {
|
Map<String, Date> date = dateUtil.getStartAndEndDate(time);
|
LineShift lineShift = lineShiftMapper.selectById(lineShiftId);
|
List<LineShiftDriver> lineShiftDrivers = lineShiftDriverMapper.query(lineShiftId, null, date.get("startTime"));
|
if(lineShift.getCarNum() == lineShiftDrivers.size()){
|
return ResultUtil.error("班次已经预约满了");
|
}
|
List<LineShiftDriver> startTime = lineShiftDriverMapper.query(lineShiftId, driverId, date.get("startTime"));
|
if(startTime.size() > 0){
|
return ResultUtil.runErr("司机已经预约了该班次");
|
}
|
|
//添加预约班次数据
|
Driver driver = driverService.selectById(driverId);
|
if(driver.getCarId() == null){
|
return ResultUtil.error("司机还没绑定车辆");
|
}
|
CarModel carModel = carModelMapper.queryByCarId(driver.getCarId());
|
LineShiftDriver lineShiftDriver = new LineShiftDriver();
|
lineShiftDriver.setLineShiftId(lineShiftId);
|
lineShiftDriver.setDriverId(driverId);
|
lineShiftDriver.setDay(date.get("startTime"));
|
lineShiftDriver.setLaveSeat(carModel.getSeat() - 1);
|
String seat = "";
|
for(int i = 1; i < carModel.getSeat(); i++){
|
seat += i + ",";
|
}
|
lineShiftDriver.setLaveSeatNumber(seat.substring(0, seat.length() - 1));
|
lineShiftDriver.setTotalSeat(carModel.getSeat() - 1);
|
lineShiftDriver.setInserTime(new Date());
|
lineShiftDriverMapper.insert(lineShiftDriver);
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 获取改派司机列表
|
* @param reassignId
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryReassignDriver(Integer reassignId, Integer uid) throws Exception {
|
Reassign reassign = reassignService.selectById(reassignId);
|
Integer companyId = dispatchService.selectById(uid).getCompanyId();
|
List<Map<String, Object>> list = null;
|
if(reassign.getOrderType() == 1){//专车
|
OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(reassign.getOrderId());
|
list = driverMapper.queryReassignDriverPrivateCar(companyId, orderPrivateCar.getServerCarModelId());
|
}
|
if(reassign.getOrderType() == 3){//跨城
|
OrderCrossCity orderCrossCity = orderCrossCityService.selectById(reassign.getOrderId());
|
LineShiftDriver lineShiftDriver = lineShiftDriverMapper.selectById(orderCrossCity.getLineShiftDriverId());
|
list = driverMapper.queryReassignDriverCrossCity(companyId, orderCrossCity.getServerCarModelId(), orderCrossCity.getLineId(),
|
lineShiftDriver.getLineShiftId(), orderCrossCity.getTravelTime(), orderCrossCity.getPeopleNumber());
|
}
|
for(int i = 0; i < list.size(); i++){
|
if(Integer.valueOf(list.get(i).get("id").toString()).compareTo(reassign.getOriginalDriverId()) == 0){
|
list.remove(i);
|
}
|
}
|
return list;
|
}
|
|
|
/**
|
* 获取所有没有服务的司机
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryAllDriver(Integer uid) throws Exception {
|
Integer companyId = dispatchService.selectById(uid).getCompanyId();
|
return driverMapper.queryAllDriver(companyId);
|
}
|
|
|
/**
|
* 根据车辆id获取司机
|
* @param carId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Driver> queryByCarId(Integer carId) throws Exception {
|
return driverMapper.queryByCarId(carId);
|
}
|
}
|