package com.stylefeng.guns.modular.system.service.impl;
|
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.stylefeng.guns.modular.system.dao.CarBrandMapper;
|
import com.stylefeng.guns.modular.system.dao.CarMapper;
|
import com.stylefeng.guns.modular.system.dao.CarModelMapper;
|
import com.stylefeng.guns.modular.system.dao.CompanyMapper;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.ICarService;
|
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 javax.servlet.http.HttpServletRequest;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
|
@Service
|
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarService {
|
|
@Resource
|
private CarMapper carMapper;
|
|
@Resource
|
private CarBrandMapper carBrandMapper;
|
|
@Resource
|
private CarModelMapper carModelMapper;
|
|
@Resource
|
private CompanyMapper companyMapper;
|
|
@Autowired
|
private IDriverService driverService;
|
|
|
|
|
/**
|
* 获取自己的车辆数据及空闲车辆
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public Map<String, Object> queryCars(Integer uid) throws Exception {
|
Driver driver = driverService.selectById(uid);
|
List<Map<String, Object>> list = carMapper.queryIdleData(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : (
|
driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1));
|
Map<String, Object> map = new HashMap<>();
|
map.put("list", list);
|
Map<String, Object> map1 = driverService.queryInfo(uid);
|
if(null == map1.get("licensePlate")){
|
map.put("car", "");
|
}else{
|
map.put("car", map1.get("licensePlate") + "-" + map1.get("brand") + " " + map1.get("carColor"));
|
}
|
return map;
|
}
|
|
|
/**
|
* 判断车辆是否被绑定
|
* @param id
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public boolean idle(Integer id) throws Exception {
|
Car car = this.selectById(id);
|
List<Map<String, Object>> list = carMapper.queryIdleData(car.getFranchiseeId() != null && car.getFranchiseeId() != 0 ? car.getFranchiseeId() : (
|
car.getCompanyId() != null && car.getCompanyId() != 0 ? car.getCompanyId() : 1));
|
for(Map<String, Object> map : list){
|
Integer carId = Integer.valueOf(String.valueOf(map.get("id")));
|
if(carId.compareTo(id) == 0){
|
return true;
|
}
|
}
|
return false;
|
}
|
|
|
/**
|
* 获取所有车辆品牌
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryAllBrand() throws Exception {
|
return carBrandMapper.queryAllBrand();
|
}
|
|
|
/**
|
* 查询型号
|
* @param brandId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryCarModel(Integer brandId) throws Exception {
|
return carModelMapper.query(brandId);
|
}
|
|
|
/**
|
* 添加车辆
|
* @param modelId
|
* @param color
|
* @param licensePlate
|
* @param time
|
* @param drivingLicensePhoto
|
* @param carPhoto
|
* @param insurancePhoto
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil addCar(Integer modelId, String color, String licensePlate, Date time, String drivingLicensePhoto,
|
String carPhoto, String insurancePhoto, Integer uid) throws Exception {
|
|
Car query = carMapper.query(licensePlate);
|
if(null != query){
|
return ResultUtil.error("车牌号已经使用");
|
}
|
Car car = new Car();
|
car.setCarModelId(modelId);
|
CarModel carModel = carModelMapper.selectById(modelId);
|
car.setCarBrandId(carModel.getBrandId());
|
car.setCarColor(color);
|
car.setCarLicensePlate(licensePlate);
|
car.setAnnualInspectionTime(time);
|
car.setDrivingLicensePhoto(drivingLicensePhoto);
|
car.setCarPhoto(carPhoto);
|
car.setInsurancePhoto(insurancePhoto);
|
car.setCreateBy(uid);
|
|
Driver driver = driverService.selectById(uid);
|
car.setCompanyId(driver.getCompanyId());
|
car.setFranchiseeId(driver.getFranchiseeId());
|
car.setInsertTime(new Date());
|
car.setState(1);
|
car.setAddType(1);
|
car.setAddObjectId(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : (
|
driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1));
|
Company company = companyMapper.selectById(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : (
|
driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1));
|
car.setIsPlatCar(company.getType() == 1 ? 1 : 2);
|
this.insert(car);
|
return ResultUtil.success();
|
}
|
}
|