package com.stylefeng.guns.modular.system.service.impl;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.stylefeng.guns.modular.system.dao.CarMapper;
|
import com.stylefeng.guns.modular.system.model.Car;
|
import com.stylefeng.guns.modular.system.model.Driver;
|
import com.stylefeng.guns.modular.system.service.ICarService;
|
import com.stylefeng.guns.modular.system.service.IDispatchService;
|
import com.stylefeng.guns.modular.system.service.IDriverService;
|
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.List;
|
import java.util.Map;
|
|
|
@Service
|
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarService {
|
|
@Resource
|
private CarMapper carMapper;
|
|
@Autowired
|
private IDispatchService dispatchService;
|
|
@Autowired
|
private IDriverService driverService;
|
|
|
/**
|
* 获取车辆列表
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryCarList(Integer uid) throws Exception {
|
Integer companyId = dispatchService.selectById(uid).getCompanyId();
|
return carMapper.queryCarList(companyId);
|
}
|
|
|
/**
|
* 获取车辆详情
|
* @param id
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public Map<String, Object> queryCarInfo(Integer id) throws Exception {
|
Map<String, Object> map = carMapper.queryCarInfo(id);
|
List<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().eq("authState", 2)
|
.ne("flag", 3).eq("carId", map.get("id")));
|
if (drivers.isEmpty()){
|
throw new Exception("该车辆还未绑定司机");
|
}
|
StringBuffer sb = new StringBuffer();
|
for (Driver driver : drivers) {
|
sb.append(driver.getName() + "-" + driver.getPhone() + "/");
|
}
|
map.put("driver", sb.substring(0, sb.length() - 1));
|
return map;
|
}
|
|
|
/**
|
* 重新绑定/解绑 车辆司机关系
|
* @param id
|
* @param driverId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil rebindDriver(Integer id, Integer driverId) throws Exception {
|
if(null == driverId){//解除绑定
|
List<Driver> drivers = driverService.queryByCarId(id);
|
if(drivers.size() == 0){
|
return ResultUtil.error("车辆还未绑定司机");
|
}
|
for(Driver driver : drivers){
|
driver.setCarId(null);
|
}
|
driverService.updateAllColumnBatchById(drivers);
|
return ResultUtil.success();
|
}
|
|
Driver driver = driverService.selectById(driverId);
|
driver.setCarId(id);
|
driverService.updateById(driver);
|
return ResultUtil.success();
|
}
|
}
|