StationController.java
4.1 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
package com.bsth.controller;
import com.bsth.common.ResponseCode;
import com.bsth.entity.Line;
import com.bsth.entity.LsSectionRoute;
import com.bsth.entity.LsStationRoute;
import com.bsth.entity.Station;
import com.bsth.repository.StationRepository;
import com.bsth.service.StationService;
import com.bsth.util.GetUIDAndCode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
*
* @ClassName: StationController(站点控制器)
*
* @Extends : BaseController
*
* @Description: TODO(站点控制层)
*
* @Author bsth@lq
*
* @Date 2016年05月03日 上午9:21:17
*
* @Version 公交调度系统BS版 0.1
*
*/
@RestController
@RequestMapping("station")
public class StationController extends BaseController<Station, Integer> {
@Autowired
private StationService service;
@Autowired
StationRepository stationRepository;
private ObjectMapper mapper = new ObjectMapper();
/** 日志记录器 */
private static final Logger log = LoggerFactory.getLogger(StationController.class);
/**
* @Description :TODO(根据坐标点匹配数据库中的站点)
*/
@RequestMapping(value="matchStation")
public Map<String, Object> matchStation(@RequestBody List<Station> stations) {
Map<String, Object> result = new HashMap<>();
try {
service.matchStation(stations);
result.put("status", ResponseCode.SUCCESS);
result.put("data", stations);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
log.error("", e);
}
return result;
}
/**
* 保存线路某个版本下单行的站点和路段路由
* 常规使用在根据百度地图生成数据或者模板导入的批量保存
* @param map
* @return
*/
@RequestMapping(value="saveRoutes" , method = RequestMethod.POST)
public Map<String, Object> saveRoutes(@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(service.saveRoutes(lineId, versions, directions, stationRoutes, sectionRoutes));
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
log.error("", e);
}
return result;
}
/**
* 更新站点、站点路由信息
* @param stationRoute
* @return
*/
@RequestMapping(value="stationUpdate" , method = RequestMethod.POST)
public Map<String, Object> stationUpdate(LsStationRoute stationRoute) {
Map<String, Object> result = new HashMap<>();
try {
service.stationUpdate(stationRoute);
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
throw new RuntimeException(e);
}
return result;
}
/**
* @Description :TODO(查询站点编码)
*
* @return int <stationCode站点编码>
*/
@RequestMapping(value="getStationCode" , method = RequestMethod.GET)
public long getStationCode() {
return stationRepository.stationMaxId() + 1;
}
/**
* 根据站名模糊搜索站点信息
* @param stationName
* @return 站点列表
*/
@RequestMapping(value="getStationByName" , method = RequestMethod.GET)
public List<Station> getStationByName(String stationName) {
return service.getStationByName(stationName);
}
}