liujie
2025-08-20 f9bbbfeabe3d2690679cef7583ac1c42912706db
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
package com.stylefeng.guns.modular.crossCity.server.impl;
 
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.crossCity.dao.LineMapper;
import com.stylefeng.guns.modular.crossCity.model.Line;
import com.stylefeng.guns.modular.crossCity.server.ILineService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
 
@Service
public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements ILineService {
 
    @Resource
    private LineMapper lineMapper;
 
 
    /**
     * 根据站点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>> list4 = lineMapper.queryLines(endId, 3);
        if(!CollectionUtils.isEmpty(list4)){
            List<Integer> stopoverIds = new ArrayList<>();
            for (Map<String, Object> stopoverStation : list4) {
                Integer stopoverId = Integer.valueOf(stopoverStation.get("id").toString());
                stopoverIds.add(stopoverId);
            }
            stopoverIds = stopoverIds.stream().distinct().collect(Collectors.toList());
            // 查询经停站的终点
            List<Map<String, Object>> endList = lineMapper.queryLinesByStopoverIds(stopoverIds,2);
            list2.addAll(endList);
        }
        list2 = list2.stream().distinct().collect(Collectors.toList());
        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);
    }
}