StationRouteServiceImpl.java
20.7 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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
package com.bsth.service.impl;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bsth.common.ResponseCode;
import com.bsth.entity.Line;
import com.bsth.entity.Station;
import com.bsth.entity.StationRoute;
import com.bsth.repository.LineRepository;
import com.bsth.repository.SectionRouteRepository;
import com.bsth.repository.StationRepository;
import com.bsth.repository.StationRouteRepository;
import com.bsth.service.StationRouteService;
import com.bsth.util.FTPClientUtils;
/**
*
* @ClassName: StationRouteServiceImpl(站点路由service业务层实现类)
*
* @Extends : BaseService
*
* @Description: TODO(站点路由service业务层)
*
* @Author bsth@lq
*
* @Date 2016年5月03日 上午9:21:17
*
* @Version 公交调度系统BS版 0.1
*
*/
@Service
public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integer> implements StationRouteService{
@Autowired
private StationRouteRepository repository;
@Autowired
private SectionRouteRepository routeRepository;
@Autowired
private LineRepository lineRepository;
@Autowired
private StationRepository stationRepository;
/**
* @Description :TODO(查询树站点与路段数据)
*
* @param map <line.id_eq:线路ID; directions_eq:方向>
*
* @return List<Map<String, Object>>
*/
@Override
public List<Map<String, Object>> findPoints(Map<String, Object> map) {
// 线路ID
Integer line = map.get("line.id_eq").equals("") ? null : Integer.parseInt(map.get("line.id_eq").toString());
// 方向
Integer directions = map.get("directions_eq").equals("") ? null : Integer.parseInt(map.get("directions_eq").toString());
// 查询站点
List<Object[]> stationList = repository.findPoints(line, directions);
// 查询路段
List<Object[]> sectionList = routeRepository.getSectionRoute(line, directions);
return treeListMap(stationList,sectionList);
}
public List<Map<String, Object>> treeListMap(List<Object[]> stationList,List<Object[]> sectionList) {
List<Map<String, Object>> resultList= new ArrayList<Map<String, Object>>();
// 站点孩子节点
List<Map<String, Object>> staitonChildren= new ArrayList<Map<String, Object>>();
if(stationList.size()>0) {
for(int i = 0 ; i < stationList.size(); i++) {
Map<String, Object> tempM = new HashMap<String, Object>();
// 站点路由ID
tempM.put("stationRouteId", stationList.get(i)[0]);
// 站点路由线路ID
tempM.put("stationRouteLine", stationList.get(i)[1]);
// 站点路由站点ID
tempM.put("stationRouteStation", stationList.get(i)[2]);
// 站点路由站点名称
tempM.put("stationRouteStationName", stationList.get(i)[3]);
// 站点路由站点序号
tempM.put("stationRouteStationRouteCode", stationList.get(i)[4]);
// 站点路由线路编码
tempM.put("stationRouteLineCode", stationList.get(i)[5]);
// 站点路由站点类型
tempM.put("stationRouteStationMark", stationList.get(i)[6]);
// 站点路由出站的序号
tempM.put("stationRouteOutStationNmber", stationList.get(i)[7]);
// 站点路由站点方向
tempM.put("stationRouteDirections", stationList.get(i)[8]);
// 站点路由站点到站距离
tempM.put("stationRouteDistances", stationList.get(i)[9]);
// 站点路由到站时间
tempM.put("stationRouteToTime", stationList.get(i)[10]);
// 站点路由站点首班时间
tempM.put("stationRouteFirstTime", stationList.get(i)[11]);
// 站点路由站点末班时间
tempM.put("stationRouteEndTime", stationList.get(i)[12]);
// 站点路由站点说明
tempM.put("stationRouteDescriptions", stationList.get(i)[13]);
// 站点路由版本
tempM.put("stationRouteVersions", stationList.get(i)[14]);
// 站点ID
tempM.put("stationId", stationList.get(i)[15]);
// 站点编码
tempM.put("stationStationCod", stationList.get(i)[16]);
// 站点名称
tempM.put("stationStationName", stationList.get(i)[17]);
// 路段编码
tempM.put("stationRoadCoding", stationList.get(i)[18]);
// 原坐标类型
tempM.put("stationDbType", stationList.get(i)[19]);
// 中心点(百度坐标)
tempM.put("stationBJwpoints", stationList.get(i)[20]);
// 中心点(WGS经度)
tempM.put("stationGLonx", stationList.get(i)[21]);
// 中心点(WGS纬度)
tempM.put("stationGLaty", stationList.get(i)[22]);
// 城建坐标x
tempM.put("stationx", stationList.get(i)[23]);
// 城建坐标y
tempM.put("stationy", stationList.get(i)[24]);
// 站点图形类型
tempM.put("stationShapesType", stationList.get(i)[25]);
// 站点圆半径
tempM.put("stationRadius", stationList.get(i)[26]);
// 站点图形WGS坐标
tempM.put("stationGPolygonGrid", stationList.get(i)[27]);
// 站点图形百度坐标
tempM.put("stationBPolygonGrid", stationList.get(i)[28]);
// 是否撤销
tempM.put("stationDestroy", stationList.get(i)[29]);
// 站点版本
tempM.put("stationVersions", stationList.get(i)[30]);
// 站点说明
tempM.put("stationDescriptions", stationList.get(i)[31]);
tempM.put("name", stationList.get(i)[17]);
tempM.put("text", stationList.get(i)[17]);
tempM.put("icon", "fa fa-bus");
tempM.put("pId", 200);
tempM.put("id", i+1);
tempM.put("groupType", "3");
tempM.put("chaildredType", "station");
tempM.put("enable", true);
staitonChildren.add(tempM);
}
}
// 路段孩子节点
List<Map<String, Object>> sectionChildren = new ArrayList<Map<String, Object>>();
if(sectionList.size()>0) {
for(int i = 0 ; i<sectionList.size() ; i++){
Map<String, Object> tempM = new HashMap<String, Object>();
// 路段路由ID
tempM.put("sectionrouteId",sectionList.get(i)[0]);
// 路段路由线路ID
tempM.put("sectionrouteLine",sectionList.get(i)[1]);
// 路段路由线路编码
tempM.put("sectionrouteLineCode",sectionList.get(i)[2]);
// 路段路由路段ID
tempM.put("sectionrouteSection",sectionList.get(i)[3]);
// 路段路由路段编码
tempM.put("sectionrouteSectionCode",sectionList.get(i)[4]);
tempM.put("sectionrouteCode",sectionList.get(i)[5]);
tempM.put("sectionrouteDirections",sectionList.get(i)[6]);
// 路段ID
tempM.put("sectionId",sectionList.get(i)[7]);
// 路段编码
tempM.put("sectionCode",sectionList.get(i)[8]);
// 路段名称
tempM.put("sectionName",sectionList.get(i)[9]);
// 道路编码
tempM.put("sectionCrosesRoad",sectionList.get(i)[10]);
// 终点站
tempM.put("sectionEndNode",sectionList.get(i)[11]);
// 起始节点
tempM.put("sectionStartNode",sectionList.get(i)[12]);
// 中间节点
tempM.put("sectionMiddleNode",sectionList.get(i)[13]);
// 路段类型
tempM.put("sectionType",sectionList.get(i)[14]);
// 路段折线图形城建坐标
tempM.put("sectionCsectionVector",sectionList.get(i)[15]);
// 路段折线图形百度坐标
tempM.put("sectionBsectionVector",sectionList.get(i)[16]);
// 路段折线图形WGS坐标
tempM.put("sectionGsectionVector",sectionList.get(i)[17]);
// 道路编码
tempM.put("sectionRoadCoding",sectionList.get(i)[18]);
// 路段距离
tempM.put("sectionDistance",sectionList.get(i)[19]);
// 路段时间
tempM.put("sectionTime",sectionList.get(i)[20]);
// 路段原坐标类型
tempM.put("sectiondbType",sectionList.get(i)[21]);
// 限速
tempM.put("sectionSpeedLimet",sectionList.get(i)[22]);
// 是否撤销
tempM.put("destroy",sectionList.get(i)[23]);
// 版本号
tempM.put("versions",sectionList.get(i)[24]);
// 说明
tempM.put("descriptions",sectionList.get(i)[25]);
tempM.put("name", sectionList.get(i)[9]);
tempM.put("text", sectionList.get(i)[9]);
tempM.put("icon", null);
tempM.put("pId", 300);
tempM.put("id", (i+1)*1000);
tempM.put("groupType", "3");
tempM.put("chaildredType", "section");
tempM.put("enable", true);
sectionChildren.add(tempM);
}
}
// 站点与路段孩子节点
List<Map<String, Object>> childrenTwo = new ArrayList<Map<String, Object>>();
// 站点节点
Map<String, Object> childrenStationMap = new HashMap<String, Object>();
childrenStationMap.put("children", staitonChildren);
childrenStationMap.put("container", "pjax-container");
childrenStationMap.put("enable", true);
childrenStationMap.put("groupType", "2");
childrenStationMap.put("chaildredType", null);
childrenStationMap.put("icon", null);
childrenStationMap.put("id", 200);
childrenStationMap.put("name", "站点");
childrenStationMap.put("pId", 100);
childrenStationMap.put("text", "站点");
childrenTwo.add(childrenStationMap);
// 路段节点
Map<String, Object> childrenSectionMap = new HashMap<String, Object>();
childrenSectionMap.put("children", sectionChildren);
childrenSectionMap.put("container", "pjax-container");
childrenSectionMap.put("enable", true);
childrenSectionMap.put("groupType", "2");
childrenSectionMap.put("chaildredType", null);
childrenSectionMap.put("icon", null);
childrenSectionMap.put("id", 300);
childrenSectionMap.put("name", "路段");
childrenSectionMap.put("pId", 100);
childrenSectionMap.put("text", "路段");
childrenTwo.add(childrenSectionMap);
// 站点与路段
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("children", childrenTwo);
resultMap.put("container", "pjax-container");
resultMap.put("enable", true);
resultMap.put("groupType", "1");
resultMap.put("chaildredType", null);
resultMap.put("icon", null);
resultMap.put("id", 100);
resultMap.put("name", "站点与路段");
resultMap.put("pId", null);
resultMap.put("text", "站点与路段");
resultList.add(resultMap);
return resultList;
}
@Override
public Map<String, Object> systemQuote(Map<String, Object> map) {
Map<String, Object> resultmap = new HashMap<>();
try{
StationRoute route = new StationRoute();
Integer lineId = map.get("lineId").equals("") ? null : Integer.parseInt(map.get("lineId").toString());
Integer stationId = map.get("stationId").equals("") ? null : Integer.parseInt(map.get("stationId").toString());
Line line = lineRepository.findOne(lineId);
Station station = stationRepository.findOne(stationId);
route.setLine(line);
route.setStation(station);
//baseRepository.save(t);
resultmap.put("status", ResponseCode.SUCCESS);
}catch(Exception e){
resultmap.put("status", ResponseCode.ERROR);
logger.error("save erro.", e);
}
return resultmap;
}
/**
* @Description :TODO(查询线路某方向下的站点序号与类型)
*
* @param map <lineId:线路ID; direction:方向;stationRouteCode:站点编码>
*
* @return List<Map<String, Object>>
*/
@Override
public List<Map<String, Object>> findUpStationRouteCode(Map<String, Object> map) {
Integer lineId = map.get("lineId").equals("") ? null : Integer.parseInt(map.get("lineId").toString());
Integer direction = map.get("direction").equals("") ? null : Integer.parseInt(map.get("direction").toString());
Integer stationRouteCode = map.get("stationRouteCode").equals("") ? null : Integer.parseInt(map.get("stationRouteCode").toString());
List<Object[]> reslutList = repository.findUpStationRouteCode(lineId, direction, stationRouteCode);
List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
if(reslutList.size()>0) {
for(int i = 0 ; i <reslutList.size() ;i++){
Map<String, Object> tempM = new HashMap<String, Object>();
tempM.put("stationRouteCode", reslutList.get(i)[0]);
tempM.put("stationRouteMarke", reslutList.get(i)[1]);
list.add(tempM);
}
}
return list;
}
/**
* @Description :TODO(查询线路某方向下所有站点的中心百度坐标)
*
* @param map <lineId:线路ID; direction:方向>
*
* @return List<Map<String, Object>>
*/
@Override
public List<Map<String, Object>> getStationRouteCenterPoints(Map<String, Object> map) {
List<Map<String, Object>> resultList = new ArrayList<Map<String,Object>>();
// 线路ID
Integer lineId = map.get("lineId").equals("") ? null : Integer.parseInt(map.get("lineId").toString());
// 方向
Integer direction = map.get("direction").equals("") ? null : Integer.parseInt(map.get("direction").toString());
List<Object[]> list = repository.getSelectStationRouteCenterPoints(lineId, direction);
if(list.size()>0) {
for(int i = 0;i<list.size();i++) {
Map<String, Object> tempM = new HashMap<String,Object>();
tempM.put("bJwpoints", list.get(i));
resultList.add(tempM);
}
}
return resultList;
}
/**
* @Description :TODO(撤销站点)
*
* @param map <lineId:线路ID; destroy:是否撤销(0:否;1:是)>
*
* @return Map<String, Object> <SUCCESS ; ERROR>
*/
@Override
public Map<String, Object> stationRouteIsDestroy(Map<String, Object> map) {
Map<String, Object> resultMap = new HashMap<String,Object>();
try {
Integer stationRouteId = map.get("stationRouteId").equals("") ? 0 : Integer.parseInt(map.get("stationRouteId").toString());
Integer destroy = map.get("destroy").equals("") ? 0 : Integer.parseInt(map.get("destroy").toString());
repository.stationRouteIsDestroyUpd(stationRouteId, destroy);
resultMap.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
resultMap.put("status", ResponseCode.ERROR);
logger.error("save erro.", e);
}
return resultMap;
}
/**
* @Description : TODO(根据线路ID生成行单)
*
* @param map <lineId:线路ID>
*
* @return Map<String, Object> <SUCCESS ; ERROR>
*/
@Override
public Map<String, Object> usingSingle(Map<String, Object> map) {
Map<String, Object> resultMap = new HashMap<String,Object>();
try {
// 获取线路ID
Integer lineId = map.get("lineId").equals("") ? 0 : Integer.parseInt(map.get("lineId").toString());
Line line = lineRepository.findOne(lineId);
List<Object[]> objects = repository.usingSingle(lineId);
String stationRStr = "";
// windows下的文本文件换行符
// String enterStr = "\r\n";
// linux/unix下的文本文件换行符
String enterStr = "\r";
if(objects.size()>0) {
for(int i = 0; i<objects.size();i++) {
// 经度
String lng = objects.get(i)[0].toString();
// 纬度
String lat = " " + objects.get(i)[1].toString();
// 站点类型
String stationMake = objects.get(i)[3].toString();
if(stationMake.equals("E")) {
stationMake = " " + "2";
}else {
stationMake =" " + "1";
}
// 站点序号
String stationNo = " " + objects.get(i)[4].toString();
// 站点编码
String stationCode = " " + objects.get(i)[5].toString();
double tempd = Double.parseDouble(objects.get(i)[6].toString())*1000;
// 站点距离
String staitondistance = " " + String.valueOf((int) tempd);
// 限速
String sleepStr = " " + "60";
// 站点名称
String staitonName = " " + objects.get(i)[7].toString();
stationRStr = stationRStr + lng + lat + stationMake + stationNo + stationCode + staitondistance + sleepStr + staitonName + enterStr;
}
}
System.out.println(stationRStr);
FTPClientUtils ftpClientUtils = new FTPClientUtils();
// ip
String url = "222.66.0.205";
// ftp端口
int port = 21;
// 用户名
String username = "transport";
// 密码
String password = "transport123";
// 路径
String path = "down/";
// 文件名
String filename = line.getLineCode() + ".txt";
String versions = "2";
stationRStr = line.getName() + " " +versions + enterStr + stationRStr;
InputStream input = new ByteArrayInputStream(stationRStr.getBytes("utf-8"));
boolean b = ftpClientUtils.uploadFile(url, port, username, password, path, filename, input);
resultMap.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
resultMap.put("status", ResponseCode.ERROR);
logger.error("save erro.", e);
}
return resultMap;
}
@Override
public List<Map<String, Object>> findStationRouteInfo(Map<String, Object> map) {
// 获取线路ID
Integer id = map.get("id").equals("") ? 0 : Integer.parseInt(map.get("id").toString());
List<Object[]> objects = repository.findStationRouteInfo(id);
List<Map<String, Object>> resultList = new ArrayList<Map<String,Object>>();
int len = objects.size();
if(objects.size()>0) {
for(int i = 0 ; i < len; i++) {
Map<String, Object> tempM = new HashMap<String,Object>();
tempM.put("stationRouteLine", objects.get(i)[0]);
tempM.put("stationRouteStation", objects.get(i)[1]);
tempM.put("stationRouteCode", objects.get(i)[2]);
tempM.put("stationRouteLIneCode", objects.get(i)[3]);
tempM.put("stationRouteStationMark", objects.get(i)[4]);
tempM.put("stationOutStationNmber", objects.get(i)[5]);
tempM.put("stationRoutedirections", objects.get(i)[6]);
tempM.put("stationRouteDistances", objects.get(i)[7]);
tempM.put("stationRouteToTime", objects.get(i)[8]);
tempM.put("staitonRouteFirstTime", objects.get(i)[9]);
tempM.put("stationRouteEndTime", objects.get(i)[10]);
tempM.put("stationRouteDescriptions", objects.get(i)[11]);
tempM.put("stationRouteDestroy", objects.get(i)[12]);
tempM.put("stationRouteVersions", objects.get(i)[13]);
tempM.put("stationRouteCreateBy", objects.get(i)[14]);
tempM.put("stationRouteCreateDate", objects.get(i)[15]);
tempM.put("stationRouteUpdateBy", objects.get(i)[16]);
tempM.put("stationRouteUpdateDate", objects.get(i)[17]);
tempM.put("stationId", objects.get(i)[18]);
tempM.put("stationCode", objects.get(i)[19]);
tempM.put("stationName", objects.get(i)[20]);
tempM.put("stationRoadCoding", objects.get(i)[21]);
tempM.put("stationDbType", objects.get(i)[22]);
tempM.put("stationJwpoints", objects.get(i)[23]);
tempM.put("stationGlonx", objects.get(i)[24]);
tempM.put("stationGlaty", objects.get(i)[25]);
tempM.put("stationX", objects.get(i)[26]);
tempM.put("stationY", objects.get(i)[27]);
tempM.put("stationBPolyonGrid", objects.get(i)[28]);
tempM.put("stationGPloyonGrid", objects.get(i)[29]);
tempM.put("stationDestroy", objects.get(i)[30]);
tempM.put("stationRadius", objects.get(i)[31]);
tempM.put("stationShapesType", objects.get(i)[32]);
tempM.put("stationVersions", objects.get(i)[33]);
tempM.put("sttationDescriptions", objects.get(i)[34]);
tempM.put("stationCreateBy", objects.get(i)[35]);
tempM.put("stationCreateDate", objects.get(i)[36]);
tempM.put("stationUpdateBy", objects.get(i)[37]);
tempM.put("stationUpdateDate", objects.get(i)[38]);
tempM.put("stationRouteId", objects.get(i)[39]);
resultList.add(tempM);
}
}
return resultList;
}
}