StationServiceImpl.java
4.26 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
package com.bsth.service.impl;
import com.bsth.entity.Station;
import com.bsth.entity.search.CustomerSpecs;
import com.bsth.repository.*;
import com.bsth.service.StationService;
import com.bsth.util.CoordinateConverter;
import com.bsth.util.CoordinateConverter.Location;
import com.bsth.util.CustomBeanUtils;
import com.bsth.util.Geo.GeoUtils;
import com.bsth.util.Geo.Point;
import com.bsth.util.GeoConverter;
import org.geolatte.geom.codec.Wkt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @ClassName: StationServiceImpl(站点service业务层实现类)
*
* @Extends : BaseService
*
* @Description: TODO(站点service业务层)
*
* @Author bsth@lq
*
* @Date 2016年05月03日 上午9:21:17
*
* @Version 公交调度系统BS版 0.1
*
*/
@Service
public class StationServiceImpl extends BaseServiceImpl<Station, Integer> implements StationService {
@Autowired
private StationRepository stationRepository;
@Autowired
private LsStationRouteRepository lsStationRouteRepository;
@Autowired
private LineRepository lineRepository;
@Autowired
private SectionRepository sectionRepository;
@Autowired
private LsSectionRouteRepository lsSectionRouteRepository;
@Autowired
LineVersionsRepository lineVersionsRepository;
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public long findLatestStationId() {
return stationRepository.findLatestStationId();
}
/**
* 新增站点
* @param station
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void add(Station station) {
centerPoint(station);
stationRepository.save(station);
}
/**
* @Description :TODO(更新站点保存)
*
* @param station
*
* @return Map<String, Object> <SUCCESS ; ERROR>
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void modify(Station station) {
centerPoint(station);
Station station1 = stationRepository.findById(station.getId()).get();
CustomBeanUtils.copyPropertiesIgnoredNull(station, station1);
stationRepository.save(station1);
}
/**
* @Description :TODO(根据坐标点匹配数据库中的站点)
* 将匹配站点的名称赋值到新的站点
*/
@Override
public void matchStation(List<Station> stations) {
Map<String, Object> param = new HashMap<>();
param.put("destroy_eq", 0);
List<Station> stations1 = stationRepository.findAll(new CustomerSpecs<>(param));
for (Station s : stations) {
Location location = CoordinateConverter.LocationMake(s.getCenterPointWkt());
Point point = new Point(location.getLng(), location.getLat());
double minDistance = Double.MAX_VALUE, matchDistance = 60;
Station target = null;
for (Station s1 : stations1) {
Location location1 = CoordinateConverter.LocationMake(s1.getCenterPoint().toString());
Point point1 = new Point(location1.getLng(), location1.getLat());
double distance = GeoUtils.getDistance(point, point1);
if (distance <= matchDistance) {
target = s1;
break;
}
if (distance < minDistance) {
target = s1;
}
}
s.setId(target.getId());
s.setStationCode(target.getStationCode());
s.setStationName(target.getStationName());
}
}
@Override
public List<Station> findStationByName(String stationName) {
String query = "SELECT id,station_code,station_name,ST_AsText(center_point) center_point_wkt,pass_lines,ew_direction,sn_direction FROM bsth_c_station WHERE station_name LIKE CONCAT(?,'%')";
return jdbcTemplate.query(query, new Object[]{ stationName }, BeanPropertyRowMapper.newInstance(Station.class));
}
/**
* 存在wkt 则转换wkt为geo信息
* @param station
*/
private void centerPoint(Station station) {
// 中心点坐标信息
String wkt = station.getCenterPointWkt();
if (!StringUtils.isEmpty(wkt)) {
org.geolatte.geom.Point baidu = (org.geolatte.geom.Point) Wkt.fromWkt(wkt);
org.geolatte.geom.Point wgs = GeoConverter.pointBd2wgs(wkt);
station.setCenterPoint(baidu);
station.setCenterPointWgs(wgs);
}
}
}