longz
2026-06-04 da780b14b8db78043d2c0f27d3bfd73111e6d550
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
package com.stylefeng.guns.modular.crossCity.server.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.crossCity.dao.DriverSelfTripMapper;
import com.stylefeng.guns.modular.crossCity.dao.LineMapper;
import com.stylefeng.guns.modular.crossCity.model.DriverSelfTrip;
import com.stylefeng.guns.modular.crossCity.model.Line;
import com.stylefeng.guns.modular.crossCity.server.ILineService;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
@Service
public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements ILineService {
 
    @Resource
    private LineMapper lineMapper;
 
    @Resource
    private DriverSelfTripMapper driverSelfTripMapper;
 
 
    /**
     * 根据站点id获取线路
     * @param startId
     * @param endId
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryLines(Integer startId, Integer endId, Integer driverId) throws Exception {
        List<Map<String, Object>> list1 = lineMapper.queryLines(startId, 1);
        List<Map<String, Object>> list2 = lineMapper.queryLines(endId, 2);
        List<Map<String, Object>> list = new ArrayList<>();
        for(Map<String, Object> map1 : list1){
            Integer id1 = Integer.valueOf(map1.get("id").toString());
            for(Map<String, Object> map2 : list2){
                Integer id2 = Integer.valueOf(map2.get("id").toString());
                if(id1 == id2){
                    map1.put("startAddress", map1.get("siteName"));
                    map1.put("endAddress", map2.get("siteName"));
                    list.add(map1);
                }
            }
        }
        if(null != driverId){
            List<Map<String, Object>> lists = new ArrayList<>();
            List<Map<String, Object>> list3 = lineMapper.scanCodeQueryLines(driverId);
            for(Map<String, Object> map1 : list){
                Integer id2 = Integer.valueOf(map1.get("id").toString());
                for(Map<String, Object> map : list3){
                    Integer id1 = Integer.valueOf(map.get("id").toString());
                    if(id1 == id2){
                        lists.add(map1);
                    }
                }
            }
            list = lists;
        }
        return list;
    }
 
 
    /**
     * 扫码获取司机的所有线路
     * @param driverId
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> scanCodeQueryLines(Integer driverId) throws Exception {
        return lineMapper.scanCodeQueryLines(driverId);
    }
 
    /**
     * 根据司机id查询当前时间之后发车的城际线路
     */
    @Override
    public List<Map<String, Object>> queryFutureLinesByDriver(Integer driverId) throws Exception {
        if (driverId == null) {
            return new ArrayList<>();
        }
        return lineMapper.queryFutureLinesByDriver(driverId);
    }
 
    /**
     * 根据起始站点和终点站点查询第一条线路的目的地列表
     */
    @Override
    public List<Map<String, Object>> queryFirstLineDestinations(Integer startId, Integer endId) throws Exception {
        if (startId != null && endId != null && startId < 0 && endId < 0) {
            Integer startTripId = Math.abs(startId) / 10;
            Integer startFlag = Math.abs(startId) % 10;
            Integer endTripId = Math.abs(endId) / 10;
            Integer endFlag = Math.abs(endId) % 10;
            if (startTripId > 0 && endTripId > 0 && startTripId.equals(endTripId) && startFlag == 1 && endFlag == 2) {
                DriverSelfTrip selfTrip = driverSelfTripMapper.selectById(startTripId);
                if (selfTrip == null || selfTrip.getState() == null || selfTrip.getState() != 1 || ToolUtil.isEmpty(selfTrip.getDestJson())) {
                    return new ArrayList<>();
                }
                JSONArray array = JSON.parseArray(selfTrip.getDestJson());
                if (array == null || array.size() == 0) {
                    return new ArrayList<>();
                }
                List<Map<String, Object>> result = new ArrayList<>();
                for (int i = 0; i < array.size(); i++) {
                    JSONObject item = array.getJSONObject(i);
                    if (item == null || item.getDouble("endLon") == null || item.getDouble("endLat") == null) {
                        continue;
                    }
                    Map<String, Object> destination = new HashMap<>();
                    destination.put("id", 0 - (startTripId * 1000 + i + 1));
                    destination.put("lineId", 0 - startTripId);
                    destination.put("name", item.getString("endAddress"));
                    destination.put("fenceType", 1);
                    destination.put("coordinate", item.getDouble("endLon") + "," + item.getDouble("endLat") + ";3000");
                    destination.put("defaultPointLon", item.getDouble("endLon"));
                    destination.put("defaultPointLat", item.getDouble("endLat"));
                    destination.put("price5", item.getBigDecimal("price"));
                    destination.put("price7", item.getBigDecimal("price"));
                    destination.put("state", 1);
                    destination.put("isMain", i == 0 ? 1 : 2);
                    Map<String, Object> fenceInfo = new HashMap<>();
                    fenceInfo.put("fenceType", destination.get("fenceType"));
                    fenceInfo.put("coordinate", destination.get("coordinate"));
                    fenceInfo.put("defaultPointLon", destination.get("defaultPointLon"));
                    fenceInfo.put("defaultPointLat", destination.get("defaultPointLat"));
                    destination.put("fenceInfo", fenceInfo);
                    result.add(destination);
                }
                return result;
            }
        }
 
        List<Map<String, Object>> lines = queryLines(startId, endId, null);
        if (lines == null || lines.size() <= 0) {
            return new ArrayList<>();
        }
        Map<String, Object> firstLine = lines.get(0);
        if (firstLine == null || firstLine.get("id") == null) {
            return new ArrayList<>();
        }
        Integer lineId = Integer.valueOf(firstLine.get("id").toString());
        List<Map<String, Object>> destinations = lineMapper.queryLineDestinations(lineId);
        if (destinations == null || destinations.size() <= 0) {
            return new ArrayList<>();
        }
        for (Map<String, Object> destination : destinations) {
            Map<String, Object> fenceInfo = new HashMap<>();
            fenceInfo.put("fenceType", destination.get("fenceType"));
            fenceInfo.put("coordinate", destination.get("coordinate"));
            fenceInfo.put("defaultPointLon", destination.get("defaultPointLon"));
            fenceInfo.put("defaultPointLat", destination.get("defaultPointLat"));
            destination.put("fenceInfo", fenceInfo);
        }
        return destinations;
    }
}