package com.dsh.course.service.impl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.dsh.course.entity.Car;
|
import com.dsh.course.entity.CarModel;
|
import com.dsh.course.feignClient.activity.CompanyClient;
|
import com.dsh.course.feignClient.activity.model.CompanyInfoRes;
|
import com.dsh.course.feignClient.driver.DriverClient;
|
import com.dsh.course.feignClient.driver.model.DriverInfoRes;
|
import com.dsh.course.mapper.CarBrandMapper;
|
import com.dsh.course.mapper.CarMapper;
|
import com.dsh.course.mapper.CarModelMapper;
|
import com.dsh.course.model.dto.CarServerRes;
|
import com.dsh.course.model.vo.BaseWarpper;
|
import com.dsh.course.model.vo.CarInfoRes;
|
import com.dsh.course.service.ICarService;
|
import com.dsh.guns.modular.system.util.ResultUtil;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
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 DriverClient driverClient;
|
|
@Resource
|
private CarBrandMapper carBrandMapper;
|
|
@Resource
|
private CarModelMapper carModelMapper;
|
|
@Resource
|
private CompanyClient companyClient;
|
|
|
|
@Override
|
public CarInfoRes queryCarById(Integer id) {
|
return this.baseMapper.queryCarById(id);
|
}
|
|
|
/**
|
* 获取自己的车辆数据及空闲车辆
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public Map<String, Object> queryCars(Integer uid) throws Exception {
|
DriverInfoRes driver = driverClient.getDriver(uid);
|
List<BaseWarpper> list = this.baseMapper.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);
|
if(null != driver.getId()){
|
CarInfoRes carInfoRes = queryCarById(driver.getId());
|
map.put("car", carInfoRes.getCarLicensePlate() + "-" + carInfoRes.getCarBrandName() + " " + carInfoRes.getCarColor());
|
}else{
|
map.put("car", "");
|
}
|
return map;
|
}
|
|
|
/**
|
* 判断车辆是否被绑定
|
* @param id
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public boolean idle(Integer id) throws Exception {
|
Car car = this.baseMapper.selectById(id);
|
List<BaseWarpper> list = this.baseMapper.queryIdleData(car.getFranchiseeId() != null && car.getFranchiseeId() != 0 ? car.getFranchiseeId() : (
|
car.getCompanyId() != null && car.getCompanyId() != 0 ? car.getCompanyId() : 1));
|
for(BaseWarpper map : list){
|
Integer carId = map.getId();
|
if(carId.compareTo(id) == 0){
|
return true;
|
}
|
}
|
return false;
|
}
|
|
|
/**
|
* 获取所有车辆品牌
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryAllBrand(Integer language) throws Exception {
|
return carBrandMapper.queryAllBrand(language);
|
}
|
|
|
/**
|
* 查询型号
|
* @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 = this.baseMapper.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);
|
|
DriverInfoRes driver = driverClient.getDriver(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));
|
CompanyInfoRes company = companyClient.queryById(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.baseMapper.insert(car);
|
return ResultUtil.success();
|
}
|
|
@Override
|
public List<BaseWarpper> queryIdleData(Integer companyId) throws Exception {
|
return this.baseMapper.queryIdleData(companyId);
|
}
|
|
@Override
|
public CarServerRes getCarServer(String carId) {
|
return this.baseMapper.getCarServer(carId);
|
|
}
|
}
|