luodangjia
2024-12-10 31ce6be2d56798d9509e6d90335999064351f7f3
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
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.modular.crossCity.model.OrderCrossCity;
import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
import com.stylefeng.guns.modular.system.dao.DriverMapper;
import com.stylefeng.guns.modular.system.dao.DriverServiceMapper;
import com.stylefeng.guns.modular.system.model.Company;
import com.stylefeng.guns.modular.system.model.Driver;
import com.stylefeng.guns.modular.system.model.DriverService;
import com.stylefeng.guns.modular.system.service.ICompanyCityService;
import com.stylefeng.guns.modular.system.service.IDriverService;
import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil;
import com.stylefeng.guns.modular.system.util.GeodesyUtil;
import com.stylefeng.guns.modular.system.util.RedisUtil;
import com.stylefeng.guns.modular.system.warpper.BaseWarpper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
@Service
public class DriverServiceImpl extends ServiceImpl<DriverMapper, Driver> implements IDriverService {
 
    @Resource
    private DriverMapper driverMapper;
 
    @Resource
    private DriverServiceMapper driverServiceMapper;
 
    @Autowired
    private RedisUtil redisUtil;
 
    @Autowired
    private GDMapElectricFenceUtil gdMapElectricFenceUtil;
 
    @Autowired
    private ICompanyCityService companyCityService;
 
    @Autowired
    private GeodesyUtil geodesyUtil;
 
 
 
    /**
     * 获取distance公里内空闲司机数量
     * @param type  业务类型(1=专车,2=出租车,3=城际,4=小件物流-同城,5=小件物流-跨城,6=包车)
     * @param lon
     * @param lat
     * @return
     * @throws Exception
     */
    @Override
    public List<Driver> queryIdleDriver(Integer type, Double lon, Double lat, Double distance, Integer companyId) throws Exception {
        List<Driver> drivers = driverMapper.queryIdleDriver(type, companyId);
        List<Driver> list = new ArrayList<>();
        for(Driver driver : drivers){
            String value = redisUtil.getValue("DRIVER" + String.valueOf(driver.getId()));
            if(null != value){
//                Map<String, String> distance1 = gdMapElectricFenceUtil.getDistance(lon + "," + lat, value, 0);//计算距离
                Map<String, Double> distance1 = geodesyUtil.getDistance(lon + "," + lat, value);
                double d = Double.valueOf(distance1.get("WGS84")).doubleValue();
                if(d < (distance * 1000)){
                    list.add(driver);
                }
            }
        }
        return list;
    }
 
    @Autowired
    private IOrderCrossCityService crossCityService;
 
    /**
     * 获取给定车型且空闲的司机
     * @param type
     * @param serverCarModelId
     * @param lon
     * @param lat
     * @param distance
     * @param companyId
     * @return
     * @throws Exception
     */
    @Override
    public List<Driver> queryIdleDriver(Integer type, Integer serverCarModelId, Double lon, Double lat, Double distance, Integer companyId) throws Exception {
        System.err.println("type"+type+"serverCarModelId"+serverCarModelId);
        List<Driver> drivers = driverMapper.queryIdleDriver_(type, serverCarModelId, companyId);
        System.err.println("当前获取的司机:"+drivers);
 
        List<Driver> list = new ArrayList<>();
        for(Driver driver : drivers){
            List<OrderCrossCity> orderCrossCities = crossCityService.selectList(new EntityWrapper<OrderCrossCity>().eq("state", 2).eq("driverId", driver.getId()));
            if (orderCrossCities!=null&& !orderCrossCities.isEmpty()){
                continue;
            }
 
            String value = redisUtil.getValue("DRIVER" + String.valueOf(driver.getId()));
            if(null != value){
//                Map<String, String> distance1 = gdMapElectricFenceUtil.getDistance(lon + "," + lat, value, 0);//计算距离
                Map<String, Double> distance1 = geodesyUtil.getDistance(lon + "," + lat, value);
                double d = Double.valueOf(distance1.get("WGS84")).doubleValue();
                if(d < (distance * 1000)){
                    list.add(driver);
                }
            }
        }
        System.err.println("符合距离的司机:"+list);
        return list;
    }
 
 
    /**
     * 根据订单id获取司机数据
     * @param orderId
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> queryOrderDriver(Integer orderId, Integer orderType) throws Exception {
        return driverMapper.queryOrderDriver(orderId, orderType);
    }
 
 
    /**
     * 获取司机详情
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> queryDriverInfo(Integer id) throws Exception {
        Map<String, Object> map = driverMapper.queryDriverInfo(id);
        return map;
    }
 
 
    /**
     * 获取司机的业务类型
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public List<BaseWarpper> queryBusiness(Integer uid) throws Exception {
        List<DriverService> list = driverServiceMapper.queryBusiness(uid, null);
        List<BaseWarpper> maps = new ArrayList<>();
        for (DriverService d : list){
            if(d.getType() == 4 || d.getType() == 5 ||d.getType() == 6){
                continue;
            }
            BaseWarpper baseWarpper = new BaseWarpper();
            baseWarpper.setId(d.getType());
            switch (d.getType()){
                case 1:
                    baseWarpper.setName("专车");
                    break;
                case 2:
                    baseWarpper.setName("出租车");
                    break;
                case 3:
                    baseWarpper.setName("跨城");
                    break;
                case 7:
                    baseWarpper.setName("接送机");
                    break;
            }
            maps.add(baseWarpper);
        }
        return maps;
    }
}