Pu Zhibing
2025-03-21 cab404b1a79927964a546a118cf4c171fa0bbfdf
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
package com.ruoyi.system.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.dataInterchange.api.feignClient.UPExgMsgRegisterClient;
import com.ruoyi.dataInterchange.api.model.enums.VehicleColorEnum;
import com.ruoyi.dataInterchange.api.vo.UPExgMsgRegisterVo;
import com.ruoyi.system.api.model.Car;
import com.ruoyi.system.api.model.Driver;
import com.ruoyi.system.api.model.Enterprise;
import com.ruoyi.system.mapper.CarMapper;
import com.ruoyi.system.service.ICarService;
import com.ruoyi.system.service.IDriverService;
import com.ruoyi.system.service.IEnterpriseService;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author zhibing.pu
 * @Date 2025/3/17 11:38
 */
@Service
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarService {
    
    @Resource
    private UPExgMsgRegisterClient upExgMsgRegisterClient;
    
    @Resource
    private IEnterpriseService enterpriseService;
    
    @Resource
    private IDriverService driverService;
    
    
    /**
     * 定时任务存储最新的车辆数据
     */
    @Override
    public void taskSaveNewCar() {
        Car car = this.getOne(new LambdaQueryWrapper<Car>().orderByDesc(Car::getCreateTime).last(" limit 0, 1"));
        Long startTime = -1L;
        if (null != car) {
            startTime = car.getCreateTime().toEpochSecond(ZoneOffset.ofHours(8));
        }
        List<UPExgMsgRegisterVo> list = upExgMsgRegisterClient.getUPExgMsgRegisterListIsAfterCreateTime(startTime).getData();
        if (null == list || list.isEmpty()) {
            return;
        }
        List<Enterprise> list1 = enterpriseService.list();
        List<Car> carList = new ArrayList<>();
        for (UPExgMsgRegisterVo vo : list) {
            car = new Car();
            car.setVehicleNumber(vo.getVehicleNo());
            car.setLicensePlateColor(VehicleColorEnum.getName(vo.getVehicleColor()));
            Enterprise enterprise = list1.stream().filter(s -> s.getCode().equals(vo.getInferiorPlatformId().toString())).findFirst().get();
            car.setEnterpriseId(enterprise.getId());
            Driver driver = driverService.getOne(new LambdaQueryWrapper<Driver>().eq(Driver::getVehicleNumber, vo.getVehicleNo()).eq(Driver::getStatus, 1));
            if (null != driver) {
                car.setDriverId(driver.getId());
            }
            car.setGpsModel(vo.getTerminalModelType());
            car.setGpsImei(vo.getTerminalSIMCode());
            carList.add(car);
        }
        this.saveBatch(carList);
    }
}