luo
2024-01-31 d2d6e44f8c8996586e8a2265f46e0f6f9446edaf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
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.core.util.ToolUtil;
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 org.springframework.util.StringUtils;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
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.queryIdleDataByDriverId(uid);
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
 
        if(null == driver.getCarId()){
            map.put("car", "");
            map.put("authState", 0);
        }else{
           Car map1 = carMapper.selectById(driver.getCarId());
            map.put("authState", map1.getAuthState());
            map.put("car", map1.getCarLicensePlate() + "-" +carBrandMapper.selectById(map1.getCarBrandId()).getName() + " " + map1.getCarColor());
        }
        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 drivingLicenseNumber, String drivingLicensePhoto, String drivingLicenseEndTime,
                             String carPhoto, String insurancePhoto, String commercialInsuranceTime, Integer uid,Integer id, String peopleAndCarsPhone, Integer language
                                ,String otherBrand,String otherModel) throws Exception {
 
        Car query = carMapper.query(licensePlate);
        if(id==null){
            if(null != query){
                return ResultUtil.error(language == 1 ? "车牌号已经使用" : language == 2 ? "Plate number is already in use" : "Le numéro de plaque est déjà utilisé");
            }
        }else{
            if(null != query && !id.equals(query.getId())){
                return ResultUtil.error(language == 1 ? "车牌号已经使用" : language == 2 ? "Plate number is already in use" : "Le numéro de plaque est déjà utilisé");
            }
        }
 
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Car car = new Car();
        car.setPeopleAndCarsPhone(peopleAndCarsPhone);
        //
        if (!StringUtils.isEmpty(otherBrand)){
            List<CarBrand> carBrandList = carBrandMapper.selectList(new EntityWrapper<CarBrand>().eq("name", otherBrand).eq("state",1));
            if (carBrandList.isEmpty()){
                CarBrand carBrand = new CarBrand();
                carBrand.setState(1);
                carBrand.setInsertTime(new Date());
                carBrand.setName(otherBrand);
                carBrand.setRemark("1");
                Integer insert = carBrandMapper.insert(carBrand);
                car.setCarBrandId(insert);
            }else {
//                CarModel carModel = carModelMapper.selectById(modelId);
                car.setCarBrandId(carBrandList.get(0).getId());
            }
        }else {
            CarModel carModel = carModelMapper.selectById(modelId);
            car.setCarBrandId(carModel.getBrandId());
        }
        //
        if (!StringUtils.isEmpty(otherModel)){
            List<CarModel> carModels = carModelMapper.selectList(new EntityWrapper<CarModel>().eq("name", otherModel).eq("brandId", car.getCarBrandId()).eq("state",1));
            if (carModels.isEmpty()){
            CarModel carModel = new CarModel();
            carModel.setName(otherModel);
            carModel.setState(1);
            carModel.setInsertTime(new Date());
                carModel.setSeat(5);
            carModel.setBrandId(car.getCarBrandId());
                carModel.setRemark("1");
                carModelMapper.insert(carModel);
//            carModel.setSeat();
            }else {
                car.setCarModelId(carModels.get(0).getId());
            }
        }else {
            car.setCarModelId(modelId);
        }
 
        //
        car.setCarColor(color);
        car.setCarLicensePlate(licensePlate);
        car.setAnnualInspectionTime(time);
        car.setDrivingLicenseNumber(drivingLicenseNumber);
        car.setDrivingLicensePhoto(drivingLicensePhoto);
        if(ToolUtil.isNotEmpty(drivingLicenseEndTime)){
            car.setDrivingLicenseEndTime(sdf.parse(drivingLicenseEndTime));
        }
        car.setCarPhoto(carPhoto);
        car.setInsurancePhoto(insurancePhoto);
        if(ToolUtil.isNotEmpty(commercialInsuranceTime)){
            car.setCommercialInsuranceTime(sdf.parse(commercialInsuranceTime));
        }
        Driver driver = driverService.selectById(uid);
        car.setCompanyId(driver.getCompanyId());
        car.setFranchiseeId(driver.getFranchiseeId());
        car.setInsertTime(new Date());
        car.setState(1);
        car.setAuthState(1);
        car.setAddType(1);
        car.setDriverId(uid);
        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.insertOrUpdate(car);
        //判断司机是否已经关联车辆,未关联车辆默认关联当前车辆
        if(driver.getCarId()==null){
            driver.setCarId(car.getId());
            driverService.updateById(driver);
        }
        return ResultUtil.success();
    }
}