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
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.UPExgMsgReportDriverInfoClient;
import com.ruoyi.dataInterchange.api.vo.UPExgMsgReportDriverInfoVo;
import com.ruoyi.system.api.model.Driver;
import com.ruoyi.system.api.model.Enterprise;
import com.ruoyi.system.mapper.DriverMapper;
import com.ruoyi.system.service.IDriverService;
import com.ruoyi.system.service.IEnterpriseService;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author zhibing.pu
 * @Date 2025/3/17 16:26
 */
@Service
public class DriverServiceImpl extends ServiceImpl<DriverMapper, Driver> implements IDriverService {
    
    @Resource
    private UPExgMsgReportDriverInfoClient upExgMsgReportDriverInfoClient;
    
    @Resource
    private IDriverService driverService;
    
    @Resource
    private IEnterpriseService enterpriseService;
    
    
    /**
     * 定时任务获取新驾驶员数据
     */
    @Override
    public void taskSaveNewDriver() {
        Driver driver = driverService.getOne(new LambdaQueryWrapper<Driver>().eq(Driver::getStatus, 1).orderByDesc(Driver::getUpdateTime).last(" limit 0, 1"));
        Long createTime = -1L;
        if (null != driver) {
            createTime = driver.getUpdateTime().toEpochSecond(ZoneOffset.ofHours(8));
        }
        List<UPExgMsgReportDriverInfoVo> list = upExgMsgReportDriverInfoClient.getUPExgMsgReportDriverInfoListIsAfterCreateTime(createTime).getData();
        if (null == list || list.isEmpty()) {
            return;
        }
        List<Enterprise> list1 = enterpriseService.list();
        List<Driver> driverList = new ArrayList<>();
        for (UPExgMsgReportDriverInfoVo vo : list) {
            driver = new Driver();
            driver.setName(vo.getDriverName());
            driver.setDrivingLicenseNumber(vo.getDriverId());
            driver.setCertification(vo.getLicence());
            driver.setOrgName(vo.getOrgName());
            Enterprise enterprise = list1.stream().filter(s -> s.getCode().equals(vo.getInferiorPlatformId().toString())).findFirst().get();
            driver.setEnterpriseId(enterprise.getId());
            driver.setContractingCompany(enterprise.getName());
            driver.setStatus(1);
            driver.setFlag(1);
            driver.setUpdateTime(LocalDateTime.now());
            driverList.add(driver);
        }
        this.saveBatch(driverList);
    }
}