LsStationRouteController.java
11.3 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
package com.bsth.controller;
import com.bsth.common.ResponseCode;
import com.bsth.entity.LsSectionRoute;
import com.bsth.entity.LsStationRoute;
import com.bsth.service.LsStationRouteService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
* @author Hill
*/
@RestController
@RequestMapping("/api/lsstationroute")
public class LsStationRouteController extends BaseController<LsStationRoute, Integer> {
private static final Logger log = LoggerFactory.getLogger(LsStationRouteController.class);
@Autowired
private LsStationRouteService lsStationRouteService;
@Autowired
private ObjectMapper mapper;
@RequestMapping(value = "/findAllByParams", method = RequestMethod.GET)
public Iterable<LsStationRoute> findAllByParams(@RequestParam Map<String, Object> params) {
return lsStationRouteService.findAllByParams(params);
}
@RequestMapping(value = "/findPageByParams", method = RequestMethod.GET)
public Page<LsStationRoute> findPageByParams(@RequestParam Map<String, Object> params) {
int page = params.get("page") == null ? 0 : Integer.parseInt(params.get("page").toString());
int size = params.get("size") == null ? 10 : Integer.parseInt(params.get("size").toString());
String order = params.get("order").toString(), direction = params.get("direction").toString();
return super.list(params, page, size, order, direction);
}
@RequestMapping(value = "/findRoutes" , method = RequestMethod.GET)
public Map<String, Object> findRoutes(@RequestParam Map<String, Object> map) {
map.put("destroy_eq", 0);
if (map.get("line.id_eq") == null || map.get("versions_eq") == null) {
throw new IllegalArgumentException("需正确传入线路、版本参数");
}
return lsStationRouteService.findRoutes(map);
}
@RequestMapping(value = "/findStationRoutes" , method = RequestMethod.GET)
public List<LsStationRoute> findStationRoutes(@RequestParam Map<String, Object> map) {
map.put("destroy_eq", 0);
if (map.get("line.id_eq") == null || map.get("versions_eq") == null) {
throw new IllegalArgumentException("需正确传入线路、版本参数");
}
return lsStationRouteService.findStationRoutes(map);
}
/**
* @Description :TODO(查询站点的下一个缓存站点)
*/
@RequestMapping(value = "/findCurrentAndNext" , method = RequestMethod.GET)
public List<LsStationRoute> findCurrentAndNext(Integer id) {
return lsStationRouteService.findCurrentAndNext(id);
}
/**
* @param id
* @throws
* @Description: TODO(批量撤销站点)
*/
@RequestMapping(value = "/destroy", method = RequestMethod.POST)
public Map<String, Object> destroy(Integer id) {
Map<String, Object> result = new HashMap<>();
try {
lsStationRouteService.batchDestroy(Arrays.asList(id));
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
result.put("msg", e.getMessage());
log.error("", e);
}
return result;
}
/**
* @param ids
* @throws
* @Description: TODO(批量撤销站点)
*/
@RequestMapping(value = "/batchDestroy", method = RequestMethod.POST)
public Map<String, Object> batchDestroy(@RequestParam(value = "ids[]") List<Integer> ids) {
Map<String, Object> result = new HashMap<>();
try {
lsStationRouteService.batchDestroy(ids);
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
result.put("msg", e.getMessage());
log.error("", e);
}
return result;
}
/**
* @param ids
* @throws
* @Description: TODO(批量恢复撤销站点)
*/
@RequestMapping(value = "/batchRecover", method = RequestMethod.POST)
public Map<String, Object> batchRecover(@RequestParam(value = "ids[]") List<Integer> ids) {
Map<String, Object> result = new HashMap<>();
try {
lsStationRouteService.batchRecover(ids);
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
result.put("msg", e.getMessage());
log.error("", e);
}
return result;
}
/**
* 保存线路某个版本下的站点路由
* 常规使用在选择已有站点生成线路路由的情况
* @param map
* @return
*/
@RequestMapping(value="addStationRoutes" , method = RequestMethod.POST)
public Map<String, Object> addStationRoutes(@RequestBody Map<String, Object> map) {
Map<String, Object> result = new HashMap<>();
try {
if (map.get("lineId") == null || map.get("versions") == null || map.get("directions") == null) {
throw new IllegalArgumentException("需正确传入线路、方向、版本参数");
}
Integer versions = Integer.parseInt(map.get("versions").toString()), directions = Integer.parseInt(map.get("directions").toString()), lineId = Integer.parseInt(map.get("lineId").toString());
String stationIdsStr = map.get("stationIds").toString();
List<Integer> stationIds = new ArrayList<>();
for (String stationId : stationIdsStr.split(",")) {
stationIds.add(Integer.parseInt(stationId));
}
result.putAll(lsStationRouteService.addStationRoutes(lineId, versions, directions, stationIds));
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
log.error("", e);
}
return result;
}
/**
* 保存线路某个版本下单行的站点和路段路由
* 常规使用在根据百度地图生成数据或者模板导入的批量保存
* @param map
* @return
*/
@RequestMapping(value="addRoutes" , method = RequestMethod.POST)
public Map<String, Object> addRoutes(@RequestBody Map<String, Object> map) {
Map<String, Object> result = new HashMap<>();
try {
if (map.get("lineId") == null || map.get("versions") == null || map.get("directions") == null) {
throw new IllegalArgumentException("需正确传入线路、方向、版本参数");
}
Integer versions = Integer.parseInt(map.get("versions").toString()), directions = Integer.parseInt(map.get("directions").toString()), lineId = Integer.parseInt(map.get("lineId").toString());
List<LsStationRoute> stationRoutes = mapper.convertValue(map.get("stationRoutes"), mapper.constructType(mapper.getTypeFactory().constructParametricType(List.class, LsStationRoute.class)));
List<LsSectionRoute> sectionRoutes = mapper.convertValue(map.get("sectionRoutes"), mapper.constructType(mapper.getTypeFactory().constructParametricType(List.class, LsSectionRoute.class)));
result.putAll(lsStationRouteService.addRoutes(lineId, versions, directions, stationRoutes, sectionRoutes));
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
log.error("", e);
}
return result;
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Map<String, Object> add(LsStationRoute stationRoute) {
Map<String, Object> result = new HashMap<>();
try {
lsStationRouteService.add(stationRoute);
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
result.put("msg", e.getMessage());
log.error("", e);
}
return result;
}
@RequestMapping(value = "/modify", method = RequestMethod.POST)
public Map<String, Object> modify(LsStationRoute stationRoute) {
Map<String, Object> result = new HashMap<>();
try {
lsStationRouteService.modify(stationRoute);
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
result.put("msg", e.getMessage());
log.error("", e);
}
return result;
}
@RequestMapping(value = "/exchangeDirection", method = RequestMethod.POST)
public Map<String, Object> exchangeDirection(int lineId, int version) {
Map<String, Object> result = new HashMap<>();
try {
lsStationRouteService.exchangeDirection(lineId, version);
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
result.put("msg", e.getMessage());
log.error("", e);
}
return result;
}
@RequestMapping(value = "/modifyDistance", method = RequestMethod.POST)
public Map<String, Object> modifyDistance(@RequestParam Map<String, Object> params) {
Map<String, Object> result = new HashMap<>();
try {
List<Integer> ids = new ArrayList<>();
List<Double> distances = new ArrayList<>();
for (Map.Entry<String, Object> entry : params.entrySet()) {
String key = entry.getKey(), value = String.valueOf(entry.getValue());
ids.add(Integer.parseInt(key.split("_")[1]));
distances.add(Double.parseDouble(value) / 1000);
}
if (ids.size() == 0) {
throw new IllegalArgumentException("不合法的参数");
}
lsStationRouteService.modifyDistance(ids, distances);
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
result.put("msg", e.getMessage());
log.error("", e);
}
return result;
}
@RequestMapping(value = "/circularRouteHandle", method = RequestMethod.POST)
public Map<String, Object> circularRouteHandle(Integer lineId, Integer version) {
Map<String, Object> result = new HashMap<>();
try {
lsStationRouteService.circularRouteHandle(lineId, version);
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
result.put("msg", e.getMessage());
log.error("", e);
}
return result;
}
@RequestMapping(value = "/analyzeRoutes")
public Map<String, Object> analyzeRoutes(Integer lineId, Integer version, Integer direction) {
Map<String, Object> result = new HashMap<>();
try {
result.putAll(lsStationRouteService.analyzeRoutes(lineId, version, direction));
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
result.put("msg", e.getMessage());
log.error("", e);
}
return result;
}
}