InoutCarparkServiceImpl.java
8.85 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
package com.bsth.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.bsth.common.ResponseCode;
import com.bsth.data.BasicData;
import com.bsth.entity.*;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.repository.*;
import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
import com.bsth.service.InoutCarparkService;
import com.bsth.service.gps.GpsService;
import com.bsth.util.CoordinateConverter;
import com.bsth.util.CustomBeanUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author Hill
*/
@Service
public class InoutCarparkServiceImpl extends BaseServiceImpl<LsInoutSectionRoute, Long> implements InoutCarparkService {
private final static Logger logger = LoggerFactory.getLogger(InoutCarparkServiceImpl.class);
@Autowired
private LsStationRouteRepository lsStationRouteRepository;
@Autowired
private CarParkRepository carParkRepository;
@Autowired
private LsInoutSectionRouteRepository lsInoutSectionRouteRepository;
@Autowired
private SectionRepository sectionRepository;
@Autowired
LineRepository lineRepository;
@Autowired
private ScheduleRealInfoRepository scheduleRealInfoRepository;
@Autowired
private GpsService gpsService;
@Autowired
private LineVersionsRepository lineVersionsRepository;
@Override
public Map<String, Object> getStartEndByLine(int lineId, int version) {
Map<String, Object> result = new HashMap<>(), data = new HashMap<>();
result.put("code", 0);
result.put("msg", "");
result.put("data", data);
List<LsStationRoute> upRoutes = lsStationRouteRepository.findByLineVersion(lineId, version, 0), downRoutes = lsStationRouteRepository.findByLineVersion(lineId, version, 1);
CarPark carPark = carParkRepository.findByLineId(lineId);
if (carPark == null) {
result.put("code", 500);
result.put("msg", "线路标准信息中无相应的停车场信息");
return result;
}
if (upRoutes.size() < 2) {
result.put("code", 500);
result.put("msg", "线路上行站级少于2");
return result;
}
LsStationRoute upFirst = upRoutes.get(0), upLast = upRoutes.get(upRoutes.size() - 1);
LsStationRoute downFirst = downRoutes.get(0), downLast = downRoutes.get(downRoutes.size() - 1);
// 环线或双环线只需提取一个起点站
if (upFirst.getStationCode().equals(upLast.getStationCode())) {
data.put("start", new LsStationRoute[]{ upFirst });
data.put("end", new LsStationRoute[]{ upFirst });
} else {
if (downRoutes.size() < 2) {
result.put("code", 500);
result.put("msg", "非环线线路下行站级少于2");
return result;
}
data.put("start", new LsStationRoute[]{ upFirst, downFirst });
data.put("end", new LsStationRoute[]{ upLast, downLast });
}
data.put("carpark", carPark);
return result;
}
@Override
public Map<String, Object> getRouteByStartEnd(int lineId, int version, String start, String end) {
Map<String, Object> result = new HashMap<>(), data = new HashMap<>();
result.put("code", 0);
result.put("msg", "");
result.put("data", data);
data.put("routes", lsInoutSectionRouteRepository.getRouteByStartEnd(lineId, version, start, end));
return result;
}
/**
* 添加进出场路段和路由
*/
@Override
@Transactional
public void add(LsInoutSectionRoute sectionRoute) {
Section section = sectionRoute.getSection();
Line line = lineRepository.findById(sectionRoute.getLine().getId()).get();
Integer version = lineVersionsRepository.findCurrentVersion(line.getId());
boolean isPresent = sectionRepository.findById(section.getId()).isPresent();
sectionRoute.setLineCode(line.getLineCode());
if (sectionRoute.getVersions() < version) {
throw new IllegalArgumentException("历史版本不可变更");
}
// 路段坐标信息
if (!isPresent) {
SectionServiceImpl.centerLine(section);
}
lsInoutSectionRouteRepository.updateSectiouRouteCode(sectionRoute);
if (!isPresent) {
sectionRepository.save(section);
}
lsInoutSectionRouteRepository.save(sectionRoute);
}
/** 百度坐标转WGS坐标 */
public CoordinateConverter.Location FromBDPointToWGSPoint(String bLonx, String bLatx) {
double lng = Double.parseDouble(bLonx);
double lat = Double.parseDouble(bLatx);
CoordinateConverter.Location bdLoc = CoordinateConverter.LocationMake(lng, lat);
CoordinateConverter.Location location = CoordinateConverter.bd_decrypt(bdLoc);
CoordinateConverter.Location WGSPoint = CoordinateConverter.transformFromGCJToWGS(location);
return WGSPoint;
}
@Transactional(rollbackFor = RuntimeException.class)
@Override
public void modify(LsInoutSectionRoute sectionRoute) {
Section section = sectionRoute.getSection();
LsInoutSectionRoute sectionRoute1 = lsInoutSectionRouteRepository.findById(sectionRoute.getId()).get();
Section section1 = sectionRepository.findById(section.getId()).get();
Integer version = lineVersionsRepository.findCurrentVersion(sectionRoute1.getLine().getId());
if (sectionRoute1.getVersions() < version) {
throw new IllegalArgumentException("历史版本不可变更");
}
SectionServiceImpl.centerLine(section);
lsInoutSectionRouteRepository.updateSectiouRouteCode(sectionRoute);
CustomBeanUtils.copyPropertiesIgnoredNull(sectionRoute, sectionRoute1);
CustomBeanUtils.copyPropertiesIgnoredNull(section, section1);
sectionRepository.save(section1);
lsInoutSectionRouteRepository.save(sectionRoute1);
}
@Override
@Transactional
public Map<String, Object> destroy(Map<String, Object> map) {
Map<String, Object> resultMap = new HashMap<String, Object>();
try {
Integer id = Integer.valueOf(map.get("id").toString());
if(map.get("status") == null || Integer.parseInt(map.get("status").toString()) != 0) {
lsInoutSectionRouteRepository.destroy(id);
}
resultMap.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
resultMap.put("status", ResponseCode.ERROR);
logger.error("destroy erro.", e);
}
return resultMap;
}
@Override
@Transactional(rollbackFor = RuntimeException.class)
public void pathPlaningByHistory(long schId, int versions) {
LsInoutSectionRoute sectionRoute = new LsInoutSectionRoute();
ScheduleRealInfo scheduleRealInfo = scheduleRealInfoRepository.findById(schId).get();
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm");
DateTime start = formatter.parseDateTime(scheduleRealInfo.getRealExecDate() + scheduleRealInfo.getFcsjActual());
DateTime end = formatter.parseDateTime(scheduleRealInfo.getRealExecDate() + scheduleRealInfo.getZdsjActual());
if (start.isAfter(end)) {
end = end.plusDays(1);
}
Map<String, Object> map = gpsService.history(new String[]{ scheduleRealInfo.getClZbh() }, start.getMillis() / 1000 - 20, end.getMillis() / 1000 + 20);
List<Map<String, Object>> list = (List<Map<String, Object>>)map.get("list");
StringBuilder sb = new StringBuilder("LINESTRING(");
for (Map<String, Object> m : list) {
Map<String, Object> m1 = new HashMap<>();
Float lng = (Float)m.get("lon"), lat = (Float)m.get("lat");
if (lng == 0 || lat == 0) {
continue;
}
sb.append(lng).append(" ").append(lat).append(",");
}
sb.deleteCharAt(sb.length() - 1).append(")");
Integer sectionId = sectionRepository.findLatestSectionId() + 1;
Line line = new Line();Section section = new Section();
sectionRoute.setLine(line);
sectionRoute.setSection(section);
line.setId(Integer.parseInt(scheduleRealInfo.getXlBm()));
line.setLineCode(scheduleRealInfo.getXlBm());
section.setId(sectionId);
section.setSectionCode(sectionId.toString());
section.setSectionName(scheduleRealInfo.getQdzName() + "-" + scheduleRealInfo.getZdzName());
section.setBsectionVectorWkt(sb.toString());
section.setSectionTime(0.);
section.setSectionDistance(0.);
section.setSpeedLimit(60.);
sectionRoute.setSectionCode(sectionId.toString());
sectionRoute.setSectionrouteCode(1);
sectionRoute.setStart(scheduleRealInfo.getQdzName());
sectionRoute.setEnd(scheduleRealInfo.getZdzName());
sectionRoute.setDirections(3);
sectionRoute.setDestroy(0);
sectionRoute.setVersions(versions);
lsInoutSectionRouteRepository.destroy(scheduleRealInfo.getXlBm(), versions, scheduleRealInfo.getQdzName(), scheduleRealInfo.getZdzName());
add(sectionRoute);
}
}