StationRouteRepository.java
19 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
package com.bsth.repository;
import java.util.List;
import java.util.Map;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.bsth.entity.Line;
import com.bsth.entity.StationRoute;
/**
*
* @Interface: StationRouteRepository(站点路由Repository数据持久层接口)
*
* @Extends : BaseRepository
*
* @Description: TODO(站点路由Repository数据持久层接口)
*
* @Author bsth@lq
*
* @Date 2016年5月03日 上午9:21:17
*
* @Version 公交调度系统BS版 0.1
*
*/
@Repository
public interface StationRouteRepository extends BaseRepository<StationRoute, Integer> {
@Query(value = "SELECT a.`stationRoute.id`," +
"a.`stationRoute.line`," +
"a.`stationRoute.station`," +
"a.`stationRoute.stationName`," +
"a.`stationRoute.stationRouteCode`," +
"a.`stationRoute.lineCode`," +
"a.`stationRoute.stationMark`," +
"a.`stationRoute.outStationNmber`," +
"a.`stationRoute.directions`," +
"a.`stationRoute.distances`," +
"a.`stationRoute.toTime`," +
"a.`stationRoute.firstTime`," +
"a.`stationRoute.endTime`," +
"a.`stationRoute.descriptions`," +
"a.`stationRoute.versions`," +
"a.stationShapesType," +
"a.stationRadius," +
"a.stationGPloyonGrid, " +
"a.stationBPolyonGrid," +
"b.id AS 'station.id'," +
"b.station_code AS 'station.stationCod'," +
"b.db_type AS 'station.dbType'," +
"b.b_jwpoints AS 'station.bJwpoints'," +
"b.g_lonx AS 'station.gLonx'," +
"b.g_lonx AS 'station.gLaty'," +
"b.descriptions AS 'station.descriptions' FROM (" +
"SELECT r.id AS 'stationRoute.id'," +
" ST_AsText(r.b_polygon_grid) as stationBPolyonGrid," +
" ST_AsText(r.g_polygon_grid) AS stationGPloyonGrid, " +
" r.radius AS stationRadius," +
" r.shapes_type AS stationShapesType," +
" r.line AS 'stationRoute.line'," +
"r.station AS 'stationRoute.station'," +
"r.station_name AS 'stationRoute.stationName'," +
"r.station_route_code as 'stationRoute.stationRouteCode'," +
"r.line_code AS 'stationRoute.lineCode'," +
"r.station_mark AS 'stationRoute.stationMark'," +
"r.out_station_nmber AS 'stationRoute.outStationNmber'," +
"r.directions AS 'stationRoute.directions'," +
"r.distances AS 'stationRoute.distances'," +
"r.to_time AS 'stationRoute.toTime'," +
"r.first_time AS 'stationRoute.firstTime'," +
"r.end_time AS 'stationRoute.endTime'," +
"r.descriptions AS 'stationRoute.descriptions'," +
"r.versions AS 'stationRoute.versions' FROM bsth_c_stationroute r WHERE r.line = ?1 and r.directions = ?2 and r.destroy=0) a " +
"LEFT JOIN bsth_c_station b " +
"ON a.`stationRoute.station` = b.id ORDER BY a.`stationRoute.stationRouteCode` ASC", nativeQuery=true)
List<Object[]> findPoints(int line,int directions);
@Query("select r from StationRoute r where r.line.id=?1 and r.destroy=0 order by r.directions ASC ,r.stationRouteCode ASC")
// @Query(value = "SELECT * from bsth_c_stationroute line = ?1 and destroy=0 bsth_c_station ORDER BY directions ASC, stationRouteCode ASC", nativeQuery=true)
List<StationRoute> findStationExport(int line);
/**
* @Description :TODO(查询线路某方向下的站点序号与类型)
*
* @param map <lineId:线路ID; direction:方向;stationRouteCode:站点编码>
*
* @return List<Map<String, Object>>
*/
@Query(value = "select t.station_route_code,t.station_mark from bsth_c_stationroute t where " +
" t.station_route_code =(" +
"select MAX(station_route_code) as stationRouteCode from bsth_c_stationroute r WHERE " +
"r.line=?1 and r.directions =?2 and station_route_code< ?3 and r.destroy = 0 ) and t.line=?1 and t.directions = ?2 AND t.destroy = 0", nativeQuery=true)
List<Object[]> findUpStationRouteCode(Integer lineId,Integer direction,Integer stationRouteCode);
/**
* @Description :TODO(查询下个站点)
*
* @param map <lineCode:线路编码; direction:方向;stationRouteCode:站点编码>
*
* @return List<Map<String, Object>>
*/
@Query(value = "SELECT a.stationRouteName," +
" a.stationRouteId, "+
" b.station_code AS stationCode," +
" b.b_jwpoints AS stationJwpoints," +
" b.g_lonx AS stationGlonx," +
" b.g_laty AS stationGlaty" +
" FROM ( SELECT s.id AS stationRouteId," +
" s.station_name AS stationRouteName, s.station AS stationId FROM bsth_c_ls_stationroute s WHERE s.station_route_code =(" +
"select MIN(station_route_code) as stationRouteCode from bsth_c_ls_stationroute r WHERE " +
"r.line_code=?1 and r.directions =?2 and station_route_code > ?3 and r.destroy = 0 ) and s.line_code=?1 and s.directions = ?2 AND s.destroy = 0) a " +
" LEFT JOIN bsth_c_station b ON a.stationId = b.id", nativeQuery=true)
List<Object[]> findDownStationRoute(String lineCode,Integer direction,Integer stationRouteCode);
/**
* @Description :TODO(站点中心点坐标查询)
*
* @param map <lineId:线路ID; direction:方向>
*
* @return List<Object[]>
*/
@Query(value = "SELECT s.b_jwpoints,r.station_name,r.station_route_code FROM (" +
"SELECT b.station,b.station_route_code,b.station_name FROM bsth_c_stationroute b where b.line =?1 and b.directions = ?2 and b.destroy=0) r " +
"LEFT JOIN bsth_c_station s on r.station = s.id order by r.station_route_code asc", nativeQuery=true)
List<Object[]> getSelectStationRouteCenterPoints(Integer lineId,Integer direction);
/**
* @Description :TODO(撤销站点)
*
* @param map <lineId:线路ID; destroy:是否撤销(0:否;1:是)>
*/
@Transactional
@Modifying
@Query(value="UPDATE bsth_c_stationroute SET " +
"destroy = ?2 WHERE id = ?1", nativeQuery=true)
public void stationRouteIsDestroyUpd(Integer stationRouteId, Integer destroy);
/**
* @Description : TODO(根据线路ID生成行单)
*
* @param lineId:线路ID
*
* @return List<Object[]>:{[0]:g_lonx(GPS经度);[1]:g_laty(GPS纬度);[2]:b_jwpoints(百度经纬度坐标)
*
* [3]:station_mark(站点类型);[4]:station_route_code(站点序号);[5]:code(站点编码);
*
* [6]:distances(站点距离);[7]:station_name(站点名称);[8]:directions(方向)}
*/
// @Query(value = "SELECT * FROM ("+
// "SELECT b.g_lonx," +
// "b.g_laty,b.b_jwpoints," +
// "a.station_mark," +
// "a.station_route_code," +
// "b.station_code," +
// "a.distances,"+
// "b.station_name," +
// "a.directions FROM (SELECT " +
// "s.station_mark," +
// "s.station_route_code," +
// "s.directions," +
// "s.distances,"+
// "s.station FROM bsth_c_stationroute s where s.line = ?1 and s.destroy=0) a " +
// "LEFT JOIN bsth_c_station b " +
// " on a.station = b.id ORDER BY a.directions ASC ) k ORDER BY k.directions,k.station_route_code ASC", nativeQuery=true)
@Query(value = "SELECT * FROM ("+
"SELECT b.g_lonx," +
"b.g_laty,b.b_jwpoints," +
"a.station_mark," +
"a.station_route_code," +
"a.station_code," +
"a.distances,"+
"a.station_name," +
"a.directions FROM " +
" bsth_c_stationroute a , bsth_c_station b " +
" where a.line = ?1 and a.destroy=0 and a.station = b.id ) k ORDER BY k.directions,k.station_route_code ASC", nativeQuery=true)
List<Object[]> usingSingle(Integer lineId);
/**
* @Description : TODO(根据站点路由Id查询详情)
*
* @param id:站点路由ID
*
* @return List<Object[]>
*/
@Query(value = "SELECT a.stationRouteLine," +
" a.stationRouteStation," +
" a.stationRouteCode," +
" a.stationRouteLIneCode," +
" a.stationRouteStationMark," +
" a.stationOutStationNmber," +
" a.stationRoutedirections," +
" a.stationRouteDistances," +
" a.stationRouteToTime," +
" a.staitonRouteFirstTime," +
" a.stationRouteEndTime," +
" a.stationRouteDescriptions," +
" a.stationRouteDestroy," +
" a.stationRouteVersions," +
" a.stationRouteName," +
" a.stationBPolyonGrid," +
" a.stationGPloyonGrid, " +
" a.stationRadius," +
" a.stationShapesType," +
" b.id AS stationId," +
" b.station_code AS stationCode," +
" b.db_type AS stationDbType," +
" b.b_jwpoints AS stationJwpoints," +
" b.g_lonx AS stationGlonx," +
" b.g_laty AS stationGlaty," +
" a.stationRouteId " +
" FROM ( SELECT s.id AS stationRouteId," +
" ST_AsText(s.b_polygon_grid) as stationBPolyonGrid," +
" ST_AsText(s.g_polygon_grid) AS stationGPloyonGrid, " +
" s.radius AS stationRadius," +
" s.shapes_type AS stationShapesType," +
" s.line AS stationRouteLine," +
" s.station as stationRouteStation," +
" s.station_name AS stationRouteName," +
" s.station_route_code as stationRouteCode," +
" s.line_code AS stationRouteLIneCode," +
" s.station_mark AS stationRouteStationMark," +
" s.out_station_nmber AS stationOutStationNmber," +
" s.directions AS stationRoutedirections," +
" s.distances AS stationRouteDistances," +
" s.to_time AS stationRouteToTime," +
" s.first_time AS staitonRouteFirstTime," +
" s.end_time AS stationRouteEndTime," +
" s.descriptions AS stationRouteDescriptions," +
" s.destroy AS stationRouteDestroy," +
" s.versions AS stationRouteVersions FROM bsth_c_stationroute s WHERE s.id = ?1 ) a " +
" LEFT JOIN bsth_c_station b ON a.stationRouteStation = b.id", nativeQuery=true)
List<Object[]> findStationRouteInfo(Integer id);
/**
* @Description : TODO(根据站点路由Id查询详情)
*
* @param id:站点路由ID
*
* @return List<Object[]>
*/
@Query(value = "SELECT a.stationRouteLine," +
" a.stationRouteStation," +
" a.stationRouteCode," +
" a.stationRouteLIneCode," +
" a.stationRouteStationMark," +
" a.stationOutStationNmber," +
" a.stationRoutedirections," +
" a.stationRouteDistances," +
" a.stationRouteToTime," +
" a.staitonRouteFirstTime," +
" a.stationRouteEndTime," +
" a.stationRouteDescriptions," +
" a.stationRouteDestroy," +
" a.stationRouteVersions," +
" a.stationRouteName," +
" a.stationBPolyonGrid," +
" a.stationGPloyonGrid, " +
" a.stationRadius," +
" a.stationShapesType," +
" b.id AS stationId," +
" b.station_code AS stationCode," +
" b.db_type AS stationDbType," +
" b.b_jwpoints AS stationJwpoints," +
" b.g_lonx AS stationGlonx," +
" b.g_laty AS stationGlaty," +
" a.stationRouteId" +
" FROM ( SELECT s.id AS stationRouteId," +
" ST_AsText(s.b_polygon_grid) as stationBPolyonGrid," +
" ST_AsText(s.g_polygon_grid) AS stationGPloyonGrid, " +
" s.radius AS stationRadius," +
" s.shapes_type AS stationShapesType," +
" s.line AS stationRouteLine," +
" s.station as stationRouteStation," +
" s.station_name AS stationRouteName," +
" s.station_route_code as stationRouteCode," +
" s.line_code AS stationRouteLIneCode," +
" s.station_mark AS stationRouteStationMark," +
" s.out_station_nmber AS stationOutStationNmber," +
" s.directions AS stationRoutedirections," +
" s.distances AS stationRouteDistances," +
" s.to_time AS stationRouteToTime," +
" s.first_time AS staitonRouteFirstTime," +
" s.end_time AS stationRouteEndTime," +
" s.descriptions AS stationRouteDescriptions," +
" s.destroy AS stationRouteDestroy," +
" s.versions AS stationRouteVersions FROM bsth_c_stationroute s WHERE s.line = ?1 and s.directions = ?2 and s.destroy = 0) a " +
" LEFT JOIN bsth_c_station b ON a.stationRouteStation = b.id order by a.stationRouteCode", nativeQuery=true)
List<Object[]> getStationRouteList(Integer lineId, Integer dir);
List<StationRoute> findByLine(Line line);
@EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
@Query("select s from StationRoute s where s.destroy=0")
List<StationRoute> findAllEffective();
@EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
@Override
Page<StationRoute> findAll(Specification<StationRoute> spec, Pageable pageable);
@EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
@Override
List<StationRoute> findAll(Specification<StationRoute> spec);
@EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
@Override
List<StationRoute> findAll(Specification<StationRoute> spec, Sort sort);
@EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
@Override
@Query(value = "select r from StationRoute r where r.destroy=0")
List<StationRoute> findAll();
@Query("select sr.station.id as stationid, sr.stationName as stationname from StationRoute sr where sr.line.id=?1 and sr.directions=?2")
List<Map<String, Object>> findStations(Integer xlid, Integer xldir);
@Query("select r from StationRoute r where r.lineCode=?1 and r.directions=?2 and r.destroy=0 order by r.stationRouteCode")
List<StationRoute> findByLine(String lineCode, int updown);
@Query("select r from StationRoute r where r.line.id=?1 and r.directions=?2 and r.destroy=0 order by r.stationRouteCode")
List<StationRoute> findByLine(Integer lineId, Integer dir);
@EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
@Query("select s from StationRoute s where s.destroy=0 and s.lineCode=?1")
List<StationRoute> findByLineCode(String lineCode);
@Query("SELECT new map(" +
"lineCode as lineCode,directions as directions,stationName as stationName,stationCode as stationCode," +
"line.linePlayType as linePlayType,s.stationMark as stationMark) " +
"FROM " +
"StationRoute s " +
"WHERE " +
"s.destroy = 0 " +
"and s.lineCode in(select lineCode from Line where inUse = 1) " +
"ORDER BY " +
"lineCode,directions,stationRouteCode")
List<Map<String, String>> findLineWithYgcAndInuse();
@Query("SELECT new map(" +
"lineCode as lineCode,directions as directions,stationName as stationName,stationCode as stationCode," +
"line.linePlayType as linePlayType,s.stationMark as stationMark) " +
"FROM " +
"StationRoute s " +
"WHERE " +
"s.destroy = 0 " +
"ORDER BY " +
"lineCode,directions,stationRouteCode")
List<Map<String, String>> findAllLineWithYgc();
@Query("SELECT new map(" +
"lineCode as lineCode,directions as directions,stationName as stationName,stationCode as stationCode," +
"line.linePlayType as linePlayType,s.stationMark as stationMark) " +
"FROM " +
"StationRoute s " +
"WHERE " +
"s.destroy = 0 and s.lineCode = ?1 " +
"ORDER BY " +
"lineCode,directions,stationRouteCode")
List<Map<String, String>> findLineWithYgcByLine(String lineCode);
@Modifying
@Query(value="update bsth_c_stationroute set directions = case directions when 1 then 0 when 0 then 1 end where line = ?1 ", nativeQuery=true)
public void stationRouteDir(Integer line);
@Modifying
@Query(value="update bsth_c_stationroute set distances =?2 where id = ?1 ", nativeQuery=true)
public void upddis(Integer id,Double dis);
@Modifying
@Query(value="UPDATE bsth_c_stationroute set station_route_code = (station_route_code+10) where line = ?1 and directions = ?2 and station_route_code >=?3 and destroy = 0", nativeQuery=true)
public void stationUpdStationRouteCode(Integer line,Integer dir,Integer routeCod);
/**
* 更新路线前撤销线路原有站点
*
* @param line
* @param dir
*/
@Modifying
@Query(value="UPDATE bsth_c_stationroute set destroy = 1 where line = ?1 and directions = ?2", nativeQuery=true)
public void stationRouteUpdDestroy(Integer line,Integer dir);
@Modifying
@Query(value="UPDATE bsth_c_stationroute set destroy = 1 where id = ?1", nativeQuery=true)
public void stationRouteIsDestroyUpdBatch(Integer ids);
/**
*
*
* @param line
* @param dir
*/
@Modifying
@Query(value="insert into (select * from bsth_c_stationroute_cache where line = ?1 and directions = ?2) bsth_c_stationroute", nativeQuery=true)
public void batchAddStationRoute(Integer line,Integer dir);
// 更具线路批量撤销
@Modifying
@Query(value="UPDATE StationRoute sr set sr.destroy = 1 where sr.line.id = ?1 and sr.lineCode = ?2")
void batchUpdate(Integer lineId, String lineCode);
// 批量删除
@Modifying
@Query(value="delete from StationRoute sr where sr.line.id = ?1 and sr.lineCode = ?2")
void batchDelete(Integer lineId, String lineCode);
/**
* @Description :TODO(站点添加)
*/
@Transactional
@Modifying
@Query(value="INSERT INTO bsth_c_stationroute (line, line_code, station, station_code, station_name, station_route_code, b_polygon_grid, g_polygon_grid, radius, shapes_type, station_mark, directions, distances, to_time, destroy, versions) " +
" VALUES(?1,?2,?3,?4,?5,?6,ST_GeomFromText(?7),ST_GeomFromText(?8),?9,?10,?11,?12,?13,?14,?15,?16)", nativeQuery=true)
public void stationRouteAdd(Integer line, String line_code, Integer station, String station_code, String station_name, Integer station_route_code,
String b_polygon_grid, String g_polygon_grid, Integer radius, String shapes_type,
String station_mark ,Integer directions, double distances,double to_time, Integer destroy, Integer versions);
/**
* @Description :TODO(站点更新)
*/
@Transactional
@Modifying
@Query(value="UPDATE bsth_c_stationroute SET " +
"line = ?1 , " +
"station = ?2 , " +
"station_code = ?3 , " +
"station_name = ?4 , " +
"line_code = ?5 , " +
"b_polygon_grid = ST_GeomFromText(?6) , " +
"g_polygon_grid = ST_GeomFromText(?7) , " +
"radius = ?8 , " +
"shapes_type = ?9 , " +
"station_route_code = ?10 , " +
"station_mark = ?11 , " +
"destroy = ?12 , " +
"directions = ?13 , " +
"distances = ?14 , " +
"to_time = ?15 , " +
"versions = ?16 " +
" WHERE id = ?17 ", nativeQuery=true)
public void stationRouteUpdate(Integer line, Integer station, String station_code, String station_name, String line_code,
String b_polygon_grid, String g_polygon_grid, Integer radius, String shapes_type, Integer station_route_code,
String station_mark, Integer destroy ,Integer directions, double distances,double to_time, Integer versions, Integer id);
}