Detour.java
4.07 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
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.bsth.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
/**
* 绕改道实体类
* 对应数据库表 bsth_c_detour
*/
@Entity
@Table(name = "bsth_c_detour")
@DynamicInsert
@DynamicUpdate
@JsonIgnoreProperties(ignoreUnknown = true)
public class Detour {
// 主键
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonIgnore
private Integer id;
// 线路
private Integer line;
// 版本号
@JsonIgnore
private Integer versions;
// 上下行
private Integer direction;
// 起点编码
@JsonIgnore
private String startStationCode;
@Transient
private int startIdx;
// 终点编码
@JsonIgnore
private String terminalStationCode;
@Transient
private int terminalIdx;
// 路段wgs84点位
@JsonIgnore
private String points;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getLine() {
return line;
}
public void setLine(Integer line) {
this.line = line;
}
public Integer getVersions() {
return versions;
}
public void setVersions(Integer versions) {
this.versions = versions;
}
public Integer getDirection() {
return direction;
}
public void setDirection(Integer direction) {
this.direction = direction;
}
public String getStartStationCode() {
return startStationCode;
}
public void setStartStationCode(String startStationCode) {
this.startStationCode = startStationCode;
}
public int getStartIdx() {
return startIdx;
}
public void setStartIdx(int startIdx) {
this.startIdx = startIdx;
}
public String getTerminalStationCode() {
return terminalStationCode;
}
public void setTerminalStationCode(String terminalStationCode) {
this.terminalStationCode = terminalStationCode;
}
public int getTerminalIdx() {
return terminalIdx;
}
public void setTerminalIdx(int terminalIdx) {
this.terminalIdx = terminalIdx;
}
public String getPoints() {
return points;
}
public void setPoints(String points) {
this.points = points;
}
/**
* 将 points 字段转换为 List<Point> 格式
* 第一个点位和最后一个点位的 isStation 为 true
* @return List<Point>
*/
public List<Point> getList() {
List<Point> pointList = new ArrayList<>();
if (points == null || points.isEmpty()) {
return pointList;
}
// 按照逗号分割 points 字符串,得到每个点位的字符串
String[] pointStrings = points.split(",");
int length = pointStrings.length;
// 遍历每个点位字符串
for (int i = 0; i < length; i++) {
String pointString = pointStrings[i].trim();
if (pointString.isEmpty()) {
continue;
}
// 按照空格分割得到经度和纬度
String[] coords = pointString.split(" ");
if (coords.length != 2) {
continue;
}
try {
// 创建 Point 对象,设置经纬度
Point point = new Point();
point.setLon(Double.parseDouble(coords[0]));
point.setLat(Double.parseDouble(coords[1]));
// 第一个点位和最后一个点位的 isStation 为 true
if (i == 0 || i == length - 1) {
point.setStation(true);
}
pointList.add(point);
} catch (NumberFormatException e) {
// 忽略格式错误的点位
}
}
return pointList;
}
}