DtServiceImpl.java
2.09 KB
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
package com.bsth.service.ttinfo.impl;
import com.bsth.entity.ttinfo.ScheduleDt;
import com.bsth.repository.ttinfo.DtRepository;
import com.bsth.service.impl.BaseServiceImpl;
import com.bsth.service.ttinfo.DtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class DtServiceImpl extends BaseServiceImpl<ScheduleDt, Integer> implements DtService {
@Autowired
private DtRepository dtRepository;
@Override
public Map<String, Object> listGroup() {
//防止后期加入新的地铁线路
List<Map> list = dtRepository.listGroup();
// 需将读取到的数据按照 "线路 - 上下行 - 站点" 的结构进行保存
Map<String, Object> lineMap = new HashMap<>(); // 储存线路
List<Map> directionList = new ArrayList<>();// 储存方向
if (list != null) {
String currentLine = null;
for (Map item : list) {
String lineKey = item.get("line").toString();
String directionKey = item.get("direction").toString();
if (lineKey != null && !lineKey.isEmpty()) {
// 如果线路发生变化,先将 directionList 保存到 lineMap 中,然后清空 directionList
if (currentLine != null && !currentLine.equals(lineKey)) {
lineMap.put(currentLine, directionList);
directionList = new ArrayList<>();
}
currentLine = lineKey;
// 将当前方向数据放入 directionList
if (directionKey != null && !directionKey.isEmpty()) {
directionList.add(item);
}
}
}
// 循环结束后,将最后一组数据存入 lineMap
if (currentLine != null) {
lineMap.put(currentLine, directionList);
}
}
return lineMap;
}
}