RealMapServiceImpl.java
14.1 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
package com.bsth.service.realcontrol.impl;
import com.bsth.common.ResponseCode;
import com.bsth.controller.realcontrol.dto.StationSpatialData;
import com.bsth.entity.CarPark;
import com.bsth.service.realcontrol.RealMapService;
import com.bsth.service.realcontrol.dto.SectionRouteCoords;
import com.bsth.util.CoordinateConverter;
import com.google.common.base.Splitter;
import com.google.common.collect.ArrayListMultimap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* Created by panzhao on 2016/11/23.
*/
@Service
public class RealMapServiceImpl implements RealMapService {
@Autowired
JdbcTemplate jdbcTemplate;
Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
public Map<String, Object> stationSpatialData(String idx) {
Map<String, Object> rs = new HashMap();
try {
List<String> idArray = Splitter.on(",").splitToList(idx);
//拼接in语句
String inStr = "";
for (String code : idArray) {
inStr += (",'" + code + "'");
}
inStr = " (" + inStr.substring(1) + ")";
String sql = "select r.LINE_CODE,r.STATION_NAME,r.STATION_CODE,r.STATION_MARK,r.DIRECTIONS,r.DISTANCES,r.TO_TIME, r.VERSIONS,ST_X(s.CENTER_POINT_WGS) G_LONX,ST_Y(s.CENTER_POINT_WGS) G_LATY,r.RADIUS,r.SHAPED_TYPE shapes_type,ST_AsText(r.BUFFER_POLYGON_WGS) as G_POLYGON_GRID, r.STATION_ROUTE_CODE from bsth_c_stationroute r inner join bsth_c_station s on r.station=s.id where r.line_code in " + inStr + " and r.destroy=0";
List<StationSpatialData> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(StationSpatialData.class));
rs.put("status", ResponseCode.SUCCESS);
rs.put("list", list);
} catch (Exception e) {
logger.error("", e);
rs.put("status", ResponseCode.ERROR);
rs.put("msg", "查询站点空间数据出现异常!");
}
return rs;
}
@Override
public Map<String, Object> stationVersionSpatialData(String idx) {
Map<String, Object> rs = new HashMap();
try {
//拼接in语句
List<String> idArray = Splitter.on(",").splitToList(idx);
StringBuffer inStr = new StringBuffer();
for (String code : idArray) {
inStr.append(",'");
inStr.append(code);
inStr.append("'");
}
String inStrs = " (" + inStr.toString().substring(1) + ")";
String sql = "select r.LINE_CODE,r.STATION_NAME,r.STATION_CODE,r.STATION_MARK,r.DIRECTIONS,r.DISTANCES,r.TO_TIME, r.VERSIONS,ST_X(s.CENTER_POINT_WGS) G_LONX,ST_Y(s.CENTER_POINT_WGS) G_LATY,r.RADIUS,r.SHAPED_TYPE shapes_type,ST_AsText(r.BUFFER_POLYGON_WGS) as G_POLYGON_GRID, r.STATION_ROUTE_CODE from bsth_c_ls_stationroute r inner join bsth_c_station s on r.station=s.id where r.line_code in " + inStrs + " and r.destroy=0";
List<StationSpatialData> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(StationSpatialData.class));
rs.put("status", ResponseCode.SUCCESS);
rs.put("list", list);
} catch (Exception e) {
logger.error("", e);
rs.put("status", ResponseCode.ERROR);
rs.put("msg", "查询站点空间数据出现异常!");
}
return rs;
}
@Override
public Map<String, Object> carParkSpatialData() {
Map<String, Object> rs = new HashMap();
try {
String sql = "select ID, AREA,PARK_CODE,PARK_NAME,ST_AsText(G_PARK_POINT) as G_PARK_POINT,G_CENTER_POINT,RADIUS,SHAPES_TYPE from bsth_c_car_park WHERE destroy=0 and shapes_type='d'";
List<CarPark> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(CarPark.class));
rs.put("status", ResponseCode.SUCCESS);
rs.put("list", list);
} catch (Exception e) {
logger.error("", e);
rs.put("status", ResponseCode.ERROR);
rs.put("msg", "查询停车场空间数据出现异常!");
}
return rs;
}
@Override
public Map<String, Object> findRouteByLine(String idx) {
Map<String, Object> rs = new HashMap<>();
StringBuilder inCond = new StringBuilder("(");
List<String> codeList = Splitter.on(",").splitToList(idx);
for(String lineCode : codeList){
inCond.append("'" + lineCode + "',");
}
inCond.deleteCharAt(inCond.length() - 1).append(")");
String sql = "SELECT r.ID,r.LINE_CODE,r.SECTION_CODE,r.SECTIONROUTE_CODE,r.DIRECTIONS,s.SECTION_NAME,ST_AsText(s.GSECTION_VECTOR) GSECTION_VECTOR,s.SECTION_DISTANCE,s.SECTION_TIME,r.versions FROM bsth_c_sectionroute r INNER JOIN bsth_c_section s on r.section_code=s.section_code WHERE r.line_code in "+inCond.toString()+" and r.destroy=0 order by sectionroute_code";
List<SectionRouteCoords> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(SectionRouteCoords.class));
//排序
Collections.sort(list, new Comparator<SectionRouteCoords>() {
@Override
public int compare(SectionRouteCoords o1, SectionRouteCoords o2) {
return Integer.parseInt(o1.getSectionrouteCode()) - Integer.parseInt(o2.getSectionrouteCode());
}
});
ArrayListMultimap<String, SectionRouteCoords> listMultimap = ArrayListMultimap.create();
for (SectionRouteCoords sr : list) {
//按lineCode 分组
listMultimap.put(sr.getLineCode(), sr);
}
//坐标转换
Map<String, Object> subMap;
Set<String> ks = listMultimap.keySet();
List<SectionRouteCoords> sublist;
List<String> upList,downList;
String vectorStr = "";
for(String k : ks){
subMap = new HashMap<>();
sublist = listMultimap.get(k);
upList = new ArrayList<>();
downList = new ArrayList<>();
for(SectionRouteCoords sr : sublist){
vectorStr = sr.getGsectionVector();
vectorStr = vectorStr.substring(11, vectorStr.length() - 2);
if (sr.getDirections() == 0)
upList.add(vectorStr);
else
downList.add(vectorStr);
}
subMap.put("up", upList);
//subMap.put("upJoins", jointCoords(upList));
subMap.put("down", downList);
subMap.put("up_bd", multiWgsToBd(upList));
subMap.put("down_bd", multiWgsToBd(downList));
subMap.put("up_gcj", multiWgsToGcj(upList));
subMap.put("down_gcj", multiWgsToGcj(downList));
rs.put(k, subMap);
}
return rs;
}
@Override
public Map<String, Object> findRouteAndVersionByLine(String idx) {
Map<String, Object> rs = new HashMap<>();
StringBuilder inCond = new StringBuilder("(");
List<String> codeList = Splitter.on(",").splitToList(idx);
for(String lineCode : codeList){
inCond.append("'" + lineCode + "',");
}
inCond.deleteCharAt(inCond.length() - 1).append(")");
String sql = "SELECT r.ID,r.LINE_CODE,r.SECTION_CODE,r.SECTIONROUTE_CODE,r.DIRECTIONS,s.SECTION_NAME,ST_AsText(s.GSECTION_VECTOR) GSECTION_VECTOR,s.SECTION_DISTANCE,s.SECTION_TIME,r.versions FROM bsth_c_ls_sectionroute r INNER JOIN bsth_c_section s on r.section_code=s.section_code WHERE r.line_code in "+inCond.toString()+" and r.destroy=0 order by sectionroute_code";
List<SectionRouteCoords> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(SectionRouteCoords.class));
//排序
Collections.sort(list, new Comparator<SectionRouteCoords>() {
@Override
public int compare(SectionRouteCoords o1, SectionRouteCoords o2) {
return Integer.parseInt(o1.getSectionrouteCode()) - Integer.parseInt(o2.getSectionrouteCode());
}
});
ArrayListMultimap<String, SectionRouteCoords> listMultimap = ArrayListMultimap.create();
for (SectionRouteCoords sr : list) {
//按lineCode 分组
listMultimap.put(sr.getLineCode()+"_"+sr.getVersions(), sr);
}
//坐标转换
Map<String, Object> subMap;
Set<String> ks = listMultimap.keySet();
List<SectionRouteCoords> sublist;
List<String> upList,downList;
String vectorStr = "";
for(String k : ks){
subMap = new HashMap<>();
sublist = listMultimap.get(k);
upList = new ArrayList<>();
downList = new ArrayList<>();
for(SectionRouteCoords sr : sublist){
vectorStr = sr.getGsectionVector();
vectorStr = vectorStr.substring(11, vectorStr.length() - 2);
if (sr.getDirections() == 0)
upList.add(vectorStr);
else
downList.add(vectorStr);
}
subMap.put("up", upList);
//subMap.put("upJoins", jointCoords(upList));
subMap.put("down", downList);
subMap.put("up_bd", multiWgsToBd(upList));
subMap.put("down_bd", multiWgsToBd(downList));
subMap.put("up_gcj", multiWgsToGcj(upList));
subMap.put("down_gcj", multiWgsToGcj(downList));
rs.put(k, subMap);
}
return rs;
}
@Override
public Map<String, Object> findRouteAndStationByLine(String lineCode) {
Map<String, Object> rs = new HashMap<>();
try {
//查询路段信息
String sql = "select r.LINE_CODE,r.SECTION_CODE,r.SECTIONROUTE_CODE,s.SECTION_NAME,ST_AsText(s.GSECTION_VECTOR) as GSECTION_VECTOR, r.DIRECTIONS from bsth_c_sectionroute r INNER JOIN bsth_c_section s on r.section=s.id where r.line_code=? and r.destroy=0";
List<Map<String, Object>> secList = jdbcTemplate.queryForList(sql, lineCode);
rs.put("section", secList);
//查询站点信息
sql = "select r.STATION_NAME,r.STATION_ROUTE_CODE,r.LINE_CODE,r.STATION_CODE,r.STATION_MARK,ST_X(s.CENTER_POINT_WGS) G_LONX,ST_Y(s.CENTER_POINT_WGS) G_LATY, r.DIRECTIONS from bsth_c_stationroute r INNER JOIN bsth_c_station s on r.station=s.id and r.line_code=? and r.destroy=0";
List<Map<String, Object>> stationList = jdbcTemplate.queryForList(sql, lineCode);
rs.put("station", stationList);
rs.put("status", ResponseCode.SUCCESS);
} catch (DataAccessException e) {
logger.error("", e);
rs.put("status", ResponseCode.ERROR);
}
return rs;
}
@Override
public Map<String, Object> multiSectionRoute(String codeIdx) {
Map<String, Object> rs = new HashMap<>();
try {
List<String> idArray = Splitter.on(",").splitToList(codeIdx);
//拼接in语句
String inStr = "";
for (String code : idArray) {
inStr += (",'" + code + "'");
}
inStr = " (" + inStr.substring(1) + ")";
String sql = "SELECT r.LINE_CODE,r.SECTION_CODE,r.SECTIONROUTE_CODE,s.SECTION_NAME,ST_AsText (s.GSECTION_VECTOR) AS GSECTION_VECTOR,r.DIRECTIONS FROM bsth_c_sectionroute r INNER JOIN bsth_c_section s ON r.section = s.id WHERE r.line_code in " + inStr + " AND r.destroy = 0 order by r.line_code, r.directions,r.sectionroute_code";
List<Map<String, Object>> secList = jdbcTemplate.queryForList(sql);
rs.put("section", secList);
rs.put("status", ResponseCode.SUCCESS);
} catch (DataAccessException e) {
logger.error("", e);
rs.put("status", ResponseCode.ERROR);
}
return rs;
}
@Override
public Map<String, Object> multiRouteByLine(String codeStr) {
List<String> codeArray = Splitter.on(",").splitToList(codeStr);
Map<String, Object> rs = new HashMap<>();
for(String code : codeArray){
rs.put(code + "_route" ,findRouteByLine(code));
}
return rs;
}
/**
* wgs 坐标数组转 百度
*
* @param list
* @return
*/
private List<String> multiWgsToBd(List<String> list) {
List<String> bdList = new ArrayList<>();
StringBuilder itemStr;
String[] subArr, cds;
CoordinateConverter.Location location;
for (String item : list) {
subArr = item.split(",");
itemStr = new StringBuilder();
for (String coord : subArr) {
cds = coord.split(" ");
//城建转经纬度
//Map<String, Double> map = JWDUtil.ConvertSHToJW(Double.parseDouble(cds[0]), Double.parseDouble(cds[1]));
location = CoordinateConverter.bd_encrypt(CoordinateConverter.transformFromWGSToGCJ(CoordinateConverter.LocationMake(Double.parseDouble(cds[0]), Double.parseDouble(cds[1]))));
itemStr.append(location.getLng() + " " + location.getLat() + ",");
}
bdList.add(itemStr.substring(0, itemStr.length() - 1));
}
return bdList;
}
/**
* wgs 坐标数组转 Gcj
*
* @param list
* @return
*/
private List<String> multiWgsToGcj(List<String> list) {
List<String> gcjList = new ArrayList<>();
StringBuilder itemStr;
String[] subArr, cds;
CoordinateConverter.Location location;
for (String item : list) {
subArr = item.split(",");
itemStr = new StringBuilder();
for (String coord : subArr) {
cds = coord.split(" ");
location = CoordinateConverter.transformFromWGSToGCJ(CoordinateConverter.LocationMake(Double.parseDouble(cds[0]), Double.parseDouble(cds[1])));
itemStr.append(location.getLng() + " " + location.getLat() + ",");
}
gcjList.add(itemStr.substring(0, itemStr.length() - 1));
}
return gcjList;
}
}