Pu Zhibing
2024-12-13 73b750200f25df08aa64124da49e7461f9de6653
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
package com.stylefeng.guns.modular.crossCity.server.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.crossCity.dao.*;
import com.stylefeng.guns.modular.crossCity.model.*;
import com.stylefeng.guns.modular.crossCity.server.ILineService;
import com.stylefeng.guns.modular.system.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.*;
 
 
@Service
public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements ILineService {
 
    @Resource
    private LineMapper lineMapper;
 
    @Resource
    private LineShiftMapper lineShiftMapper;
 
    @Resource
    private LineShiftDriverMapper lineShiftDriverMapper;
 
    @Autowired
    private DateUtil dateUtil;
 
 
    /**
     * 扫码获取司机的所有线路
     * @param driverId
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> scanCodeQueryLines(Integer driverId) throws Exception {
        return lineMapper.scanCodeQueryLines(driverId);
    }
 
 
    /**
     * 获取线路对应的排班数据
     * @param lineId
     * @param time
     * @param driverId
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryLineShiftInfo(Integer lineId, String time, Integer driverId) throws Exception {
        List<LineShift> lineShifts = lineShiftMapper.queryByLineId(lineId);
        Map<String, Date> date = dateUtil.getStartAndEndDate(time);
        Calendar s = Calendar.getInstance();
        s.setTime(new Date());
        long timeInMillis = s.getTimeInMillis();
        List<Map<String, Object>> list = new ArrayList<>();
        for(LineShift lineShift : lineShifts){
            Map<String, Object> map = new HashMap<>();
            map.put("id", lineShift.getId());
            map.put("time", lineShift.getStartTime() + "-" + lineShift.getEndTime());
            List<LineShiftDriver> lineShiftDriver = lineShiftDriverMapper.queryByDriver(lineShift.getId(), driverId, date.get("startTime"));
            s.set(Calendar.HOUR_OF_DAY, Integer.valueOf(lineShift.getEndTime().split(":")[0]));
            s.set(Calendar.MINUTE, Integer.valueOf(lineShift.getEndTime().split(":")[1]));
            long timeInMillis1 = s.getTimeInMillis();
            if(lineShiftDriver.size() == 0 && timeInMillis > timeInMillis1){
                map.put("state", 1);//不可预约
            }
            if(lineShiftDriver.size() > 0){
                map.put("state", 2);//已预约
            }
            map.put("state", 3);//未预约
            list.add(map);
        }
        return list;
    }
 
 
 
 
    @Resource
    private SiteMapper siteMapper;
 
    @Resource
    private TLineSiteMapper tLineSiteMapper;
    /**
     * 根据站点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.compareTo(id2) == 0){
                    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.compareTo(id2) == 0){
                        lists.add(map1);
                    }
                }
            }
 
            for (Map<String, Object> stringObjectMap : lists) {
                Line id = lineMapper.selectById(stringObjectMap.get("id").toString());
                List<TLineSite> start = tLineSiteMapper.selectList(new EntityWrapper<TLineSite>().eq("lineId", id.getId()).eq("type", 1));
                List<TLineSite> end = tLineSiteMapper.selectList(new EntityWrapper<TLineSite>().eq("lineId", id.getId()).eq("type", 2));
 
                Site startSite = siteMapper.selectById(start.get(0).getSiteId());
                Site endSite = siteMapper.selectById(end.get(0).getSiteId());
 
                stringObjectMap.put("startSiteName",startSite.getName());
                stringObjectMap.put("endSiteName",endSite.getName());
                stringObjectMap.put("startCityName",startSite.getCity());
                stringObjectMap.put("endCityName",endSite.getCity());
//                stringObjectMap.put("city",endSite.getCity());
                stringObjectMap.put("startCityId",startSite.getId());
                stringObjectMap.put("endCityId",endSite.getId());
 
 
 
            }
 
 
 
            return lists;
//            list = lists;
        }
        return list;
    }
}