RoadSpeedServiceImpl.java
6.25 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
package com.bsth.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONArray;
import com.bsth.common.ResponseCode;
import com.bsth.entity.RoadSpeed;
import com.bsth.repository.RoadSpeedRepository;
import com.bsth.service.RoadSpeedService;
import com.bsth.util.TransGPS;
import com.bsth.util.TransGPS.Location;
@Service
public class RoadSpeedServiceImpl extends BaseServiceImpl<RoadSpeed, Integer> implements RoadSpeedService {
@Autowired
private RoadSpeedRepository repository;
@Override
public Map<String, Object> update(Map<String, Object> map) {
Map<String, Object> resultMap = new HashMap<String, Object>();
try {
int id = Integer.parseInt(map.get("id").toString());
String name = map.get("name").toString();
double speed = Double.valueOf(map.get("speed").toString());
String speedStartDate = map.get("speedStartDate").toString();
String speedEndDate = map.get("speedEndDate").toString();
int isStart = Integer.parseInt(map.get("isStart").toString());
String sectionJSON = map.get("bRoadVector").toString();
// 原始线状图形坐标集合
String sectionsBpoints = "";
// WGS线状图形坐标集合
String sectionsWJPpoints = "";
if(!sectionJSON.equals("")) {
// 转换成JSON数组
JSONArray sectionsArray = JSONArray.parseArray(sectionJSON);
// 遍历
for(int s = 0 ;s<sectionsArray.size();s++) {
String pointsLngStr = sectionsArray.getJSONObject(s).get("lng").toString();
String pointsLatStr = sectionsArray.getJSONObject(s).get("lat").toString();
String WGSLngStr = "";
String WGSLatStr = "";
Location resultPoint = FromBDPointToWGSPoint(pointsLngStr,pointsLatStr);
WGSLngStr = String.valueOf(resultPoint.getLng());
WGSLatStr = String.valueOf(resultPoint.getLat());
if(s==0) {
sectionsBpoints = pointsLngStr + " " + pointsLatStr;
sectionsWJPpoints = WGSLngStr + " " + WGSLatStr;
}else {
sectionsBpoints = sectionsBpoints + "," + pointsLngStr + " " + pointsLatStr;
sectionsWJPpoints = sectionsWJPpoints + "," + WGSLngStr + " " + WGSLatStr;
}
}
}
// WGS坐标点集合
String gRoadVector = "LINESTRING(" + sectionsWJPpoints +")";
// 原坐标点集合
String bRoadVector = "LINESTRING(" + sectionsBpoints + ")";
repository.update(id,name,gRoadVector,bRoadVector,speed,speedStartDate,speedEndDate,isStart);
resultMap.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
resultMap.put("status", ResponseCode.ERROR);
logger.error("save erro.", e);
}
return resultMap;
}
@Override
public Map<String, Object> roadSpeedSave(Map<String, Object> map) {
Map<String, Object> resultMap = new HashMap<String, Object>();
try {
String name = map.get("name").toString();
double speed = Double.valueOf(map.get("speed").toString());
String speedStartDate = map.get("speedStartDate").toString();
String speedEndDate = map.get("speedEndDate").toString();
int isStart = Integer.parseInt(map.get("isStart").toString());
String sectionJSON = map.get("bRoadVector").toString();
// 原始线状图形坐标集合
String sectionsBpoints = "";
// WGS线状图形坐标集合
String sectionsWJPpoints = "";
if(!sectionJSON.equals("")) {
// 转换成JSON数组
JSONArray sectionsArray = JSONArray.parseArray(sectionJSON);
// 遍历
for(int s = 0 ;s<sectionsArray.size();s++) {
String pointsLngStr = sectionsArray.getJSONObject(s).get("lng").toString();
String pointsLatStr = sectionsArray.getJSONObject(s).get("lat").toString();
String WGSLngStr = "";
String WGSLatStr = "";
Location resultPoint = FromBDPointToWGSPoint(pointsLngStr,pointsLatStr);
WGSLngStr = String.valueOf(resultPoint.getLng());
WGSLatStr = String.valueOf(resultPoint.getLat());
if(s==0) {
sectionsBpoints = pointsLngStr + " " + pointsLatStr;
sectionsWJPpoints = WGSLngStr + " " + WGSLatStr;
}else {
sectionsBpoints = sectionsBpoints + "," + pointsLngStr + " " + pointsLatStr;
sectionsWJPpoints = sectionsWJPpoints + "," + WGSLngStr + " " + WGSLatStr;
}
}
}
// WGS坐标点集合
String gRoadVector = "LINESTRING(" + sectionsWJPpoints +")";
// 原坐标点集合
String bRoadVector = "LINESTRING(" + sectionsBpoints + ")";
repository.roadSpeedSave(name,gRoadVector,bRoadVector,speed,speedStartDate,speedEndDate,isStart);
resultMap.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
resultMap.put("status", ResponseCode.ERROR);
logger.error("save erro.", e);
}
return resultMap;
}
/** 百度坐标转WGS坐标 */
public Location FromBDPointToWGSPoint(String bLonx,String bLatx) {
double lng = Double.parseDouble(bLonx);
double lat = Double.parseDouble(bLatx);
Location bdLoc = TransGPS.LocationMake(lng, lat);
Location location = TransGPS.bd_decrypt(bdLoc);
Location WGSPoint = TransGPS.transformFromGCJToWGS(location);
return WGSPoint;
}
@Override
public RoadSpeed findId(Integer id) {
List<Object[]> listObc = repository.findById(id);
Object rsObj[] = listObc.get(0);
RoadSpeed rs = new RoadSpeed();
String id1 = rsObj[0].toString();
rs.setId(Integer.parseInt(id1));
rs.setName(rsObj[1].toString());
rs.setbRoadVector(rsObj[2].toString());
rs.setgRoadVector(rsObj[3].toString());
rs.setSpeed(Double.valueOf(rsObj[4].toString()));
rs.setSpeedStartDate(rsObj[5].toString());
rs.setSpeedEndDate(rsObj[6].toString());
rs.setIsStart(Integer.parseInt(rsObj[7].toString()));
if (rsObj[8] != null) {
rs.setLine(rsObj[8].toString());
}
return rs;
}
@Override
public List<RoadSpeed> allRoadSpeed() {
List<RoadSpeed> list = new ArrayList<>();
/*Iterator<RoadSpeed> itr = repository.findAll().iterator();
while (itr.hasNext()){
RoadSpeed aRoadSpeed = itr.next();
System.out.println("aRoadSpeed");
list.add(aRoadSpeed);
}*/
return list;
}
}