Commit f022c7c04ce15d63b5eb9597904eb647e99dbc9e
1 parent
5a575970
1.
Showing
3 changed files
with
78 additions
and
1 deletions
src/main/java/com/bsth/controller/realcontrol/AdminUtilsController.java
| ... | ... | @@ -9,6 +9,7 @@ import com.bsth.common.Setting; |
| 9 | 9 | import com.bsth.data.BasicData; |
| 10 | 10 | import com.bsth.security.SsoConfig; |
| 11 | 11 | import com.bsth.service.SectionService; |
| 12 | +import com.bsth.service.StationService; | |
| 12 | 13 | import com.bsth.service.schedule.utils.SpringUtils; |
| 13 | 14 | import com.bsth.util.MailUtils; |
| 14 | 15 | import com.fasterxml.jackson.core.JsonProcessingException; |
| ... | ... | @@ -81,6 +82,9 @@ public class AdminUtilsController { |
| 81 | 82 | @Autowired |
| 82 | 83 | private SectionService sectionService; |
| 83 | 84 | |
| 85 | + @Autowired | |
| 86 | + private StationService stationService; | |
| 87 | + | |
| 84 | 88 | /** |
| 85 | 89 | * 出现重复班次的车辆 |
| 86 | 90 | * |
| ... | ... | @@ -375,7 +379,7 @@ public class AdminUtilsController { |
| 375 | 379 | } |
| 376 | 380 | |
| 377 | 381 | @RequestMapping("/section/translateWgs2Bd") |
| 378 | - public String translateWgs2Bd() { | |
| 382 | + public String translateWgs2Bd1() { | |
| 379 | 383 | Map<String, Object> result = new HashMap<>(); |
| 380 | 384 | try { |
| 381 | 385 | sectionService.translateWgs2Bd(); |
| ... | ... | @@ -386,4 +390,17 @@ public class AdminUtilsController { |
| 386 | 390 | |
| 387 | 391 | return "error"; |
| 388 | 392 | } |
| 393 | + | |
| 394 | + @RequestMapping("/station/translateWgs2Bd") | |
| 395 | + public String translateWgs2Bd2() { | |
| 396 | + Map<String, Object> result = new HashMap<>(); | |
| 397 | + try { | |
| 398 | + stationService.translateWgs2Bd(); | |
| 399 | + return "success"; | |
| 400 | + } catch (Exception e) { | |
| 401 | + e.printStackTrace(); | |
| 402 | + } | |
| 403 | + | |
| 404 | + return "error"; | |
| 405 | + } | |
| 389 | 406 | } |
| 390 | 407 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/service/StationService.java
src/main/java/com/bsth/service/impl/StationServiceImpl.java
| ... | ... | @@ -12,12 +12,16 @@ import com.bsth.util.Geo.Point; |
| 12 | 12 | import com.bsth.util.GeoConverter; |
| 13 | 13 | import org.geolatte.geom.codec.Wkt; |
| 14 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | +import org.springframework.jdbc.core.BatchPreparedStatementSetter; | |
| 15 | 16 | import org.springframework.jdbc.core.BeanPropertyRowMapper; |
| 16 | 17 | import org.springframework.jdbc.core.JdbcTemplate; |
| 17 | 18 | import org.springframework.stereotype.Service; |
| 18 | 19 | import org.springframework.transaction.annotation.Transactional; |
| 19 | 20 | import org.springframework.util.StringUtils; |
| 20 | 21 | |
| 22 | +import java.sql.PreparedStatement; | |
| 23 | +import java.sql.SQLException; | |
| 24 | +import java.util.ArrayList; | |
| 21 | 25 | import java.util.HashMap; |
| 22 | 26 | import java.util.List; |
| 23 | 27 | import java.util.Map; |
| ... | ... | @@ -127,6 +131,26 @@ public class StationServiceImpl extends BaseServiceImpl<Station, Integer> implem |
| 127 | 131 | return jdbcTemplate.query(query, new Object[]{ stationName }, BeanPropertyRowMapper.newInstance(Station.class)); |
| 128 | 132 | } |
| 129 | 133 | |
| 134 | + @Override | |
| 135 | + public void translateWgs2Bd() { | |
| 136 | + String query = "SELECT id, ST_AsText(center_point_wgs) center_point_wgs_wkt FROM bsth_c_station"; | |
| 137 | + List<Station> stations = jdbcTemplate.query(query, BeanPropertyRowMapper.newInstance(Station.class)); | |
| 138 | + List<Station> stations1 = new ArrayList<>(); | |
| 139 | + StationBatchPreparedStatementSetter preparedStatementSetter = new StationBatchPreparedStatementSetter(); | |
| 140 | + preparedStatementSetter.setStations(stations1); | |
| 141 | + for (int i = 0;i < stations.size();i++) { | |
| 142 | + stations1.add(stations.get(i)); | |
| 143 | + if (i != 0 && i % 2000 == 0) { | |
| 144 | + jdbcTemplate.batchUpdate("UPDATE bsth_c_station SET b_jwpoints = ?, center_point = ST_GeomFromText(?) WHERE id = ?", preparedStatementSetter); | |
| 145 | + stations1.clear(); | |
| 146 | + } | |
| 147 | + } | |
| 148 | + if (stations1.size() > 0) { | |
| 149 | + jdbcTemplate.batchUpdate("UPDATE bsth_c_station SET b_jwpoints = ?, center_point = ST_GeomFromText(?) WHERE id = ?", preparedStatementSetter); | |
| 150 | + stations1.clear(); | |
| 151 | + } | |
| 152 | + } | |
| 153 | + | |
| 130 | 154 | /** |
| 131 | 155 | * 存在wkt 则转换wkt为geo信息 |
| 132 | 156 | * @param station |
| ... | ... | @@ -141,4 +165,35 @@ public class StationServiceImpl extends BaseServiceImpl<Station, Integer> implem |
| 141 | 165 | station.setCenterPointWgs(wgs); |
| 142 | 166 | } |
| 143 | 167 | } |
| 168 | + | |
| 169 | + final static class StationBatchPreparedStatementSetter implements BatchPreparedStatementSetter { | |
| 170 | + | |
| 171 | + private List<Station> stations; | |
| 172 | + | |
| 173 | + @Override | |
| 174 | + public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 175 | + Station station = stations.get(i); | |
| 176 | + ps.setString(1, CoordinateConverter.transformFromWGSToBD(CoordinateConverter.LocationMake(station.getCenterPointWgsWkt())).toString()); | |
| 177 | + ps.setString(2, String.format("POINT(%s)", CoordinateConverter.transformFromWGSToBD(CoordinateConverter.LocationMake(station.getCenterPointWgsWkt())).toString())); | |
| 178 | + ps.setInt(3, station.getId()); | |
| 179 | + } | |
| 180 | + | |
| 181 | + @Override | |
| 182 | + public int getBatchSize() { | |
| 183 | + return stations.size(); | |
| 184 | + } | |
| 185 | + | |
| 186 | + public List<Station> getStations() { | |
| 187 | + return stations; | |
| 188 | + } | |
| 189 | + | |
| 190 | + public void setStations(List<Station> stations) { | |
| 191 | + this.stations = stations; | |
| 192 | + } | |
| 193 | + } | |
| 194 | + | |
| 195 | + public static void main(String[] args) { | |
| 196 | + String coordinates = "43.97675 36.19718"; | |
| 197 | + System.out.println(CoordinateConverter.transformFromWGSToBD(CoordinateConverter.LocationMake(coordinates)).toString()); | |
| 198 | + } | |
| 144 | 199 | } |
| 145 | 200 | \ No newline at end of file | ... | ... |