StationRouteServiceImpl.java
33.5 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
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
package com.bsth.service.impl;
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;
import com.bsth.util.PackTarGZUtils;
import com.bsth.util.Geo.GeoUtils;
import com.bsth.util.Geo.Point;
import com.bsth.util.db.DBUtils_MS;
import com.google.common.base.Splitter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.*;
/**
*
* @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)[0]);
tempM.put("stationName", list.get(i)[1]);
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 ; NOTDATA>
*/
@Override
public Map<String, Object> usingSingle(Map<String, Object> map) {
// 返回值map
Map<String, Object> resultMap = new HashMap<String,Object>();
try {
// 获取线路ID
Integer lineId = map.get("lineId").equals("") ? 0 : Integer.parseInt(map.get("lineId").toString());
/** 查询线路信息 @param:<lineId:线路ID> */
Line line = lineRepository.findOne(lineId);
/** 查询线路信息下的站点路由信息 @param:<lineId:线路ID> */
List<Object[]> objects = repository.usingSingle(lineId);
if (objects.size()>0) {
/** 获取配置文件里的ftp登录参数 */
Map<String, Object> FTPParamMap = readPropertiesGetFTPParam();
// 压缩文件名
String odlGzFileName = line.getLineCode() + ".txt.gz";
// txt文件名
String textFileName = line.getLineCode() + ".txt";
// 创建一个ftp上传实例
FTPClientUtils clientUtils = new FTPClientUtils();
// IP
String url = FTPParamMap.get("url").toString();
// 端口
int port = Integer.valueOf(FTPParamMap.get("port").toString());
// 用户名
String username = FTPParamMap.get("username").toString();
// 密码
String password = FTPParamMap.get("password").toString();
// 相对路径
String remotePath = FTPParamMap.get("remotePath").toString();
/** 如果已存在相同行单文件名则先删除 */
clientUtils.deleteFtpFile(url, port, username, password, remotePath, odlGzFileName);
clientUtils.deleteFtpFile(url, port, username, password, remotePath, textFileName);
String textStr = "";
boolean tempTag = ishxType(objects);
if(tempTag)
textStr = hxTextFileToFtp(objects,lineId);// 环线行单文件内容
else
textStr = newTextFileToFTP(objects,lineId);/** 双向行单文件内容 @param:<objects:站点路由;lineId:线路ID>*/
/*textStr = line.getName() + "\t" + "2" + "\r" + textStr;*/
textStr = line.getName() + " " + "2" + "\r" + textStr;
InputStream input = new ByteArrayInputStream(textStr.getBytes("gbk"));
/** 生成txt文件,上传ftp */
clientUtils.uploadFile(url, port, username, password, remotePath, textFileName, input);
// 创建打包实例
PackTarGZUtils packTarGZUtils= new PackTarGZUtils();
/** 获取txt文件 */
File textFile = clientUtils.GetFtpFile(url, port, username, password, remotePath, textFileName);
File target = new File(odlGzFileName);
// 将txt文件打包
File targetFile = PackTarGZUtils.compress(textFile, target);
/*clientUtils.testUpLoadFromDisk(targetFile,targetFile.getName());*/
clientUtils.FTPUpLoadFromDisk(targetFile, targetFile.getName(), url, port, username, password, remotePath);
resultMap.put("status", ResponseCode.SUCCESS);
}else {
resultMap.put("status","NOTDATA");
}
} catch (Exception e) {
resultMap.put("status", ResponseCode.ERROR);
logger.error("save erro.", e);
}
return resultMap;
}
public boolean ishxType(List<Object[]> listObj) {
boolean tag = true;
String pointBStr[] = null,pointEStr[] = null;
int numzd = 0;
for(int i =0;i<listObj.size();i++) {
if(listObj.get(i)[3].equals("B") && Integer.valueOf(listObj.get(i)[8].toString())==0)
pointBStr = listObj.get(i)[2].toString().split(" ");
else if(listObj.get(i)[3].equals("E") && Integer.valueOf(listObj.get(i)[8].toString())==0)
pointEStr = listObj.get(i)[2].toString().split(" ");
if(Integer.valueOf(listObj.get(i)[8].toString())==1)
numzd++;
}
Point p1 = new Point(Double.valueOf(pointBStr[0]),Double.valueOf(pointBStr[1]));
Point p2 = new Point(Double.valueOf(pointEStr[0]),Double.valueOf(pointEStr[1]));
if(GeoUtils.getDistance(p1, p2)>100 && numzd>2)
tag = false;
return tag;
}
/**
* @Description : TODO(形成行单文件内容)
*
* @param objects :站点路由信息
*
* {[0]:g_lonx(GPS经度);[1]:g_laty(GPS纬度);[2]:b_jwpoints(百度经纬度坐标)
*
* [3]:station_mark(站点类型);[4]:station_route_code(站点序号);[5]:station_cod(站点编码);
*
* [6]:distances(站点距离);[7]:station_name(站点名称);[8]:directions(方向)}
*
* @param lineId :线路ID
*
* @return String
*/
public String newTextFileToFTP(List<Object[]> objects,Integer lineId) {
// 返回值String
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].equals("") ? "" : objects.get(i)[0].toString();
// 纬度
String lat = objects.get(i)[1].equals("") ? "" : objects.get(i)[1].toString();
lat = "\t" + lat;
// 站点类型
String stationMakeStr = objects.get(i)[3].equals("") ? "" : objects.get(i)[3].toString();
String stationMake = "";
if(stationMakeStr.equals("E")) {
stationMake = "\t2";
}else {
stationMake ="\t1";
}
// 站点序号
String stationNo = objects.get(i)[4].equals("") ? "" : objects.get(i)[4].toString();
stationNo = "\t" + stationNo;
// 站点编码
String stationCode = objects.get(i)[5].equals("") ? "" : objects.get(i)[5].toString();
stationCode = "\t" +stationCode;
double dis = objects.get(i)[6]==null ? 0.0 : Double.parseDouble(objects.get(i)[6].toString())*1000;
String tempDistc = String.valueOf((int) dis);
// 站点距离
String staitondistance = "\t" + tempDistc;
// 站点名称
String stationName = objects.get(i)[7].equals("") ? "" : objects.get(i)[7].toString();
stationName = "\t" +stationName;
// 限速
// String sleepStr = " " + "60";
// 限速
String sleepStr = "";
// 方向
int directions = objects.get(i)[8]==null ? null : Integer.valueOf(objects.get(i)[8].toString());
/** 获取路段路由信息 @pararm:<lineId:线路ID;directions:方向> */
List<Object[]> sobje = routeRepository.sectionRouteVector(lineId,directions);
if(sobje.size()==1) {
double dsleepStr = sobje.get(0)[2] == null ? 60d : Double.valueOf(sobje.get(0)[2].toString());
sleepStr = "\t" + new DecimalFormat("0").format(dsleepStr);
}else if(sobje.size()>1){
/** 这里暂时只根据站点名称去匹配所在路段的限速值 ,如果路段名称"至"之前的地名与站点名称等同,就认为站点在路段上。 */
for(int j =0;j<sobje.size();j++) {
String sectionName = sobje.get(j)[3].toString();
String sectionNameA[] = sectionName.split("至");
if(stationName.equals(sectionNameA[0])){
/*sleepStr = sobje.get(j)[2].toString();*/
double dsleepStrt = sobje.get(0)[2] == null ? 60d : Double.valueOf(sobje.get(j)[2].toString());
sleepStr = "\t" + new DecimalFormat("0").format(dsleepStrt);
}
}
}
stationRStr = stationRStr + lng + lat + stationMake + stationNo + stationCode + staitondistance + sleepStr + stationName + enterStr;
}
}
return stationRStr;
}
public String hxTextFileToFtp(List<Object[]> objects,Integer lineId) {
String restStr = "";
// windows下的文本文件换行符
//String enterStr = "\r\n";
// linux/unix下的文本文件换行符
String enterStr = "\r";
int xh = 1 ;
for(int x =0;x<2;x++) {
for(int i = 0; i<objects.size();i++) {
if(Integer.valueOf(objects.get(i)[8].toString())==0) {
// 经度
String lng = objects.get(i)[0].equals("") ? "" : objects.get(i)[0].toString();
// 纬度
String lat = objects.get(i)[1].equals("") ? "" : objects.get(i)[1].toString();
lat = "\t" + lat;
// 站点类型
String stationMakeStr = objects.get(i)[3].equals("") ? "" : objects.get(i)[3].toString();
String stationMake = "";
if(stationMakeStr.equals("E")) {
stationMake = "\t2";
}else {
stationMake ="\t1";
}
// 站点序号
// String stationNo = objects.get(i)[4].equals("") ? "" : objects.get(i)[4].toString();
String stationNo = "\t" + xh;
// 站点编码
String stationCode = objects.get(i)[5].equals("") ? "" : objects.get(i)[5].toString();
stationCode = "\t" +stationCode;
double dis = objects.get(i)[6]==null ? 0.0 : Double.parseDouble(objects.get(i)[6].toString())*1000;
String tempDistc = String.valueOf((int) dis);
// 站点距离
String staitondistance = "\t" + tempDistc;
// 站点名称
String stationName = objects.get(i)[7].equals("") ? "" : objects.get(i)[7].toString();
stationName = "\t" +stationName;
// 限速
String sleepStr = "";
// 方向
int directions = objects.get(i)[8]==null ? null : Integer.valueOf(objects.get(i)[8].toString());
/** 获取路段路由信息 @pararm:<lineId:线路ID;directions:方向> */
List<Object[]> sobje = routeRepository.sectionRouteVector(lineId,directions);
if(sobje.size()==1) {
double dsleepStr = sobje.get(0)[2] == null ? 60d : Double.valueOf(sobje.get(0)[2].toString());
sleepStr = "\t" + new DecimalFormat("0").format(dsleepStr);
}else if(sobje.size()>1){
/** 这里暂时只根据站点名称去匹配所在路段的限速值 ,如果路段名称"至"之前的地名与站点名称等同,就认为站点在路段上。 */
for(int j =0;j<sobje.size();j++) {
String sectionName = sobje.get(j)[3].toString();
String sectionNameA[] = sectionName.split("至");
if(stationName.equals(sectionNameA[0])){
/*sleepStr = sobje.get(j)[2].toString();*/
double dsleepStrt = sobje.get(0)[2] == null ? 60d : Double.valueOf(sobje.get(j)[2].toString());
sleepStr = "\t" + new DecimalFormat("0").format(dsleepStrt);
}
}
}
xh++;
restStr = restStr + lng + lat + stationMake + stationNo + stationCode + staitondistance + sleepStr + stationName + enterStr;
}
}
}
System.out.println(restStr);
return restStr;
}
public String GetFormPointOnPolylineSeleepLimit(Map<String, Object> p,List<Object[]> listObjArra) {
String sleeplimiV = "";
int size = listObjArra.size();
if(size>0) {
for(int i =0;i<size-1;i++) {
System.out.println(listObjArra.get(i)[3].toString());
List<Map<String, Object>> listM = new ArrayList<Map<String,Object>>();
String bVecotr = listObjArra.get(i)[1].toString();
bVecotr = bVecotr.substring(11,bVecotr.length()-1);
String tempA [] = bVecotr.split(",");
int len = tempA.length;
for(int e = 0; e< len ;e++) {
Map<String, Object> tempM = new HashMap<String,Object>();
String temStr = tempA[e];
String nextTemA[] = temStr.split(" ");
tempM.put("lng", nextTemA[0]);
tempM.put("lat", nextTemA[1]);
listM.add(tempM);
}
if(isPointOnPolyline(p,listM)) {
sleeplimiV = listObjArra.get(i)[2].toString();
}
}
}
return sleeplimiV;
}
public boolean isPointOnPolyline (Map<String, Object> point, List<Map<String, Object>> listMap ){
boolean success = false;
for(int l = 0; l < listMap.size() - 1; l ++){
Map<String, Object> tempM = listMap.get(l);
Map<String, Object> nextTempM = listMap.get(l+1);
if (Double.valueOf(point.get("lng").toString())>= Math.min(Double.valueOf(tempM.get("lng").toString()), Double.valueOf(nextTempM.get("lng").toString())) && Double.valueOf(point.get("lng").toString()) <= Math.max(Double.valueOf(tempM.get("lng").toString()), Double.valueOf(nextTempM.get("lng").toString())) &&
Double.valueOf(point.get("lat").toString()) >= Math.min(Double.valueOf(tempM.get("lat").toString()), Double.valueOf(nextTempM.get("lat").toString())) && Double.valueOf(point.get("lat").toString()) <= Math.max(Double.valueOf(tempM.get("lat").toString()), Double.valueOf(nextTempM.get("lat").toString()))){
double precision = (Double.valueOf(tempM.get("lng").toString()) - Double.valueOf(point.get("lng").toString())) * (Double.valueOf(nextTempM.get("lat").toString()) - Double.valueOf(point.get("lat").toString())) -
(Double.valueOf(nextTempM.get("lng").toString()) - Double.valueOf(tempM.get("lng").toString())) * (Double.valueOf(tempM.get("lat").toString()) - Double.valueOf(nextTempM.get("lat").toString()));
if(precision < 2e-10 && precision > -2e-10){
//实质判断是否接近0
success = true;
}
}
}
return success;
}
/**
* @Description:TOOD(获取FTP登录参数) 这里暂时只做一个map值返回,以后可以作为ftp登录类提出来
*
* @return : Map<String, Object> <url:IP;port:端口;username:用户名;password:密码;remotePath:相对路径>
*/
public Map<String, Object> readPropertiesGetFTPParam(){
// 返回值map
Map<String, Object> resultMap = new HashMap<String, Object>();
Properties env = new Properties();
try {
env.load(DBUtils_MS.class.getClassLoader().getResourceAsStream("ftp.properties"));
resultMap.put("url", env.getProperty("ftp.url"));
resultMap.put("port", env.getProperty("ftp.port"));
resultMap.put("username", env.getProperty("ftp.username"));
resultMap.put("password", env.getProperty("ftp.password"));
resultMap.put("remotePath", env.getProperty("ftp.path"));
} catch (Exception e) {
e.printStackTrace();
}
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;
}
@Override
public Map<String, Object> findByMultiLine(String lineIds) {
Map<String, Object> rs = new HashMap<>();
try{
List<String> idx = Splitter.on(',').splitToList(lineIds);
//路由
List<StationRoute> list = new ArrayList<>();
/**
* in 查询符 无法和 @EntityGraph 同时配合使用,这可能是一个bug
* 暂时只能循环单线路查询
*/
//repository.multiLine(idx)
for(String id : idx){
list.addAll(repository.findByLineCode(id));
}
for(StationRoute sr : list){
sr.setLine(null);
}
//过滤部分字段
/*String jsonStr = JSON.toJSONString(list, new PropertyFilter() {
@Override
public boolean apply(Object object, String name, Object value) {
if(name.equals("line"))
return false;
return true;
}
});*/
rs.put("status", ResponseCode.SUCCESS);
rs.put("list", list);
}catch(Exception e){
logger.error("", e);
rs.put("status", ResponseCode.ERROR);
}
return rs;
}
}