Commit e03644e8793e46b7654ae2ccfc51e302978d12e5

Authored by 王通
1 parent 24f7efab

1.加入电子前置围栏能力(应对终点多次进入的情况)

src/main/java/com/bsth/controller/GeoPremiseController.java 0 → 100644
  1 +package com.bsth.controller;
  2 +
  3 +import com.bsth.common.ResponseCode;
  4 +import com.bsth.entity.GeoPremise;
  5 +import com.bsth.service.GeoPremiseService;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.web.bind.annotation.RequestMapping;
  8 +import org.springframework.web.bind.annotation.RequestMethod;
  9 +import org.springframework.web.bind.annotation.RestController;
  10 +
  11 +import java.util.HashMap;
  12 +import java.util.Map;
  13 +
  14 +/**
  15 + * @author Hill
  16 + */
  17 +@RestController
  18 +@RequestMapping("/api/geopremise")
  19 +public class GeoPremiseController extends BaseController<GeoPremise, Integer> {
  20 +
  21 + @Autowired
  22 + private GeoPremiseService geoPremiseService;
  23 +
  24 + @Override
  25 + @RequestMapping(method = RequestMethod.POST)
  26 + public Map<String, Object> save(GeoPremise geoPremise) {
  27 + Map<String, Object> result = new HashMap<>();
  28 + try {
  29 + result.putAll(geoPremiseService.save(geoPremise));
  30 + result.put("status", ResponseCode.SUCCESS);
  31 + } catch (Exception e) {
  32 + result.put("status", ResponseCode.ERROR);
  33 + }
  34 +
  35 + return result;
  36 + }
  37 +}
src/main/java/com/bsth/entity/GeoPremise.java 0 → 100644
  1 +package com.bsth.entity;
  2 +
  3 +import javax.persistence.*;
  4 +
  5 +/**
  6 + * @author Hill
  7 + */
  8 +@Entity
  9 +@Table(name = "bsth_f_geo_premise")
  10 +public class GeoPremise {
  11 +
  12 + @Id
  13 + private Integer id;
  14 +
  15 + private String name;
  16 +
  17 + /**
  18 + * 线路代码
  19 + */
  20 + private String lineCode;
  21 +
  22 + /**
  23 + * 上下行
  24 + * 0上行 1下行
  25 + */
  26 + private int upDown;
  27 +
  28 + /**
  29 + * 站点编码
  30 + */
  31 + private String stationCode;
  32 +
  33 + /**
  34 + * 坐标
  35 + */
  36 + private String coords;
  37 +
  38 + public Integer getId() {
  39 + return id;
  40 + }
  41 +
  42 + public void setId(Integer id) {
  43 + this.id = id;
  44 + }
  45 +
  46 + public String getName() {
  47 + return name;
  48 + }
  49 +
  50 + public void setName(String name) {
  51 + this.name = name;
  52 + }
  53 +
  54 + public String getLineCode() {
  55 + return lineCode;
  56 + }
  57 +
  58 + public void setLineCode(String lineCode) {
  59 + this.lineCode = lineCode;
  60 + }
  61 +
  62 + public int getUpDown() {
  63 + return upDown;
  64 + }
  65 +
  66 + public void setUpDown(int upDown) {
  67 + this.upDown = upDown;
  68 + }
  69 +
  70 + public String getStationCode() {
  71 + return stationCode;
  72 + }
  73 +
  74 + public void setStationCode(String stationCode) {
  75 + this.stationCode = stationCode;
  76 + }
  77 +
  78 + public String getCoords() {
  79 + return coords;
  80 + }
  81 +
  82 + public void setCoords(String coords) {
  83 + this.coords = coords;
  84 + }
  85 +}
src/main/java/com/bsth/repository/GeoPremiseRepository.java 0 → 100644
  1 +package com.bsth.repository;
  2 +
  3 +import com.bsth.entity.GeoPremise;
  4 +import org.springframework.stereotype.Repository;
  5 +
  6 +/**
  7 + * @author Hill
  8 + */
  9 +@Repository
  10 +public interface GeoPremiseRepository extends BaseRepository<GeoPremise, Integer> {
  11 +
  12 +}
src/main/java/com/bsth/service/GeoPremiseService.java 0 → 100644
  1 +package com.bsth.service;
  2 +
  3 +import com.bsth.entity.GeoPremise;
  4 +
  5 +/**
  6 + * @author Hill
  7 + */
  8 +public interface GeoPremiseService extends BaseService<GeoPremise, Integer> {
  9 +
  10 +}
src/main/java/com/bsth/service/impl/GeoPremiseServiceImpl.java 0 → 100644
  1 +package com.bsth.service.impl;
  2 +
  3 +import com.bsth.entity.GeoPremise;
  4 +import com.bsth.entity.LsStationRoute;
  5 +import com.bsth.repository.GeoPremiseRepository;
  6 +import com.bsth.repository.LsStationRouteRepository;
  7 +import com.bsth.service.GeoPremiseService;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +import java.util.HashMap;
  12 +import java.util.Map;
  13 +import java.util.Optional;
  14 +
  15 +/**
  16 + * @author Hill
  17 + */
  18 +@Service
  19 +public class GeoPremiseServiceImpl extends BaseServiceImpl<GeoPremise, Integer> implements GeoPremiseService {
  20 +
  21 + @Autowired
  22 + private GeoPremiseRepository geoPremiseRepository;
  23 +
  24 + @Autowired
  25 + private LsStationRouteRepository lsStationRouteRepository;
  26 +
  27 + @Override
  28 + public GeoPremise findById(Integer id) {
  29 + Optional<GeoPremise> optional = geoPremiseRepository.findById(id);
  30 + return optional.isPresent() ? optional.get() : new GeoPremise();
  31 + }
  32 +
  33 + @Override
  34 + public Map<String, Object> save(GeoPremise geoPremise) {
  35 + Map<String, Object> result = new HashMap<>();
  36 + LsStationRoute stationRoute = lsStationRouteRepository.findById(geoPremise.getId()).get();
  37 + geoPremise.setLineCode(stationRoute.getLineCode());
  38 + geoPremise.setUpDown(stationRoute.getDirections());
  39 + geoPremise.setStationCode(stationRoute.getStationCode());
  40 + geoPremise.setName(String.format("%s-%s", stationRoute.getStationName(), stationRoute.getDirections() == 0 ? "上行" : "下行"));
  41 + geoPremiseRepository.save(geoPremise);
  42 +
  43 + return result;
  44 + }
  45 +}
src/main/java/com/bsth/service/impl/LsStationRouteServiceImpl.java
@@ -25,10 +25,7 @@ import org.springframework.util.StringUtils; @@ -25,10 +25,7 @@ import org.springframework.util.StringUtils;
25 25
26 import java.sql.PreparedStatement; 26 import java.sql.PreparedStatement;
27 import java.sql.SQLException; 27 import java.sql.SQLException;
28 -import java.util.ArrayList;  
29 -import java.util.HashMap;  
30 -import java.util.List;  
31 -import java.util.Map; 28 +import java.util.*;
32 29
33 /** 30 /**
34 * @author Hill 31 * @author Hill
@@ -357,7 +354,7 @@ public class LsStationRouteServiceImpl extends BaseServiceImpl&lt;LsStationRoute, I @@ -357,7 +354,7 @@ public class LsStationRouteServiceImpl extends BaseServiceImpl&lt;LsStationRoute, I
357 Position start = lineString.getPositionN(i), end = lineString.getPositionN(i + 1); 354 Position start = lineString.getPositionN(i), end = lineString.getPositionN(i + 1);
358 Point point1 = new Point(start.getCoordinate(0), start.getCoordinate(1)); 355 Point point1 = new Point(start.getCoordinate(0), start.getCoordinate(1));
359 Point point2 = new Point(end.getCoordinate(0), end.getCoordinate(1)); 356 Point point2 = new Point(end.getCoordinate(0), end.getCoordinate(1));
360 - int size = (int) (GeoUtils.getDistance(point1, point2) / 5) + 1; 357 + int size = (int) (GeoUtils.getDistance(point1, point2) / 10) + 1;
361 points.add(point1); 358 points.add(point1);
362 if (size > 1) { 359 if (size > 1) {
363 double offsetLon = (point2.getLon() - point1.getLon()) / size; 360 double offsetLon = (point2.getLon() - point1.getLon()) / size;
@@ -377,7 +374,6 @@ public class LsStationRouteServiceImpl extends BaseServiceImpl&lt;LsStationRoute, I @@ -377,7 +374,6 @@ public class LsStationRouteServiceImpl extends BaseServiceImpl&lt;LsStationRoute, I
377 if (indexes.size() == 0 || !indexes.get(indexes.size() - 1).endsWith(String.format("-%d", j))) { 374 if (indexes.size() == 0 || !indexes.get(indexes.size() - 1).endsWith(String.format("-%d", j))) {
378 indexes.add(String.format("%s-%d", stationRoute.getStationCode(), j)); 375 indexes.add(String.format("%s-%d", stationRoute.getStationCode(), j));
379 } 376 }
380 - break;  
381 } 377 }
382 } else { 378 } else {
383 Polygon polygon = stationRoute.getBufferPolygonWgs(); 379 Polygon polygon = stationRoute.getBufferPolygonWgs();
@@ -390,14 +386,13 @@ public class LsStationRouteServiceImpl extends BaseServiceImpl&lt;LsStationRoute, I @@ -390,14 +386,13 @@ public class LsStationRouteServiceImpl extends BaseServiceImpl&lt;LsStationRoute, I
390 if (indexes.size() == 0 || !indexes.get(indexes.size() - 1).endsWith(String.format("-%d", j))) { 386 if (indexes.size() == 0 || !indexes.get(indexes.size() - 1).endsWith(String.format("-%d", j))) {
391 indexes.add(String.format("%s-%d", stationRoute.getStationCode(), j)); 387 indexes.add(String.format("%s-%d", stationRoute.getStationCode(), j));
392 } 388 }
393 - break;  
394 } 389 }
395 } 390 }
396 } 391 }
397 } 392 }
398 } 393 }
399 } 394 }
400 - List<String> specialStations = new ArrayList<>(); 395 + Set<String> specialStations = new LinkedHashSet<>();
401 result.put("data", specialStations); 396 result.put("data", specialStations);
402 for (int i = 0;i < stationRoutes.size();) { 397 for (int i = 0;i < stationRoutes.size();) {
403 if (indexes.size() == 0) { 398 if (indexes.size() == 0) {
@@ -411,7 +406,9 @@ public class LsStationRouteServiceImpl extends BaseServiceImpl&lt;LsStationRoute, I @@ -411,7 +406,9 @@ public class LsStationRouteServiceImpl extends BaseServiceImpl&lt;LsStationRoute, I
411 lastMatch = index; 406 lastMatch = index;
412 i++; 407 i++;
413 } else { 408 } else {
414 - specialStations.add(String.format("%s, %s", index, lastMatch)); 409 + if (!index.equals(lastMatch)) {
  410 + specialStations.add(String.format("%s, %s", index, lastMatch));
  411 + }
415 } 412 }
416 } 413 }
417 if (j == indexes.size()) { 414 if (j == indexes.size()) {
src/main/resources/static/pages/base/stationroute/js/routes-operation.js
@@ -17,6 +17,8 @@ var RoutesOperation = (function () { @@ -17,6 +17,8 @@ var RoutesOperation = (function () {
17 var road_win_show_p; 17 var road_win_show_p;
18 // 被编辑的路段 18 // 被编辑的路段
19 var editPolyline; 19 var editPolyline;
  20 + // 前置站点
  21 + var premise;
20 var styleOptions = { 22 var styleOptions = {
21 strokeColor : "blue", 23 strokeColor : "blue",
22 fillColor : "blue", 24 fillColor : "blue",
@@ -30,6 +32,16 @@ var RoutesOperation = (function () { @@ -30,6 +32,16 @@ var RoutesOperation = (function () {
30 strokeWeight: 2, 32 strokeWeight: 2,
31 strokeOpacity: 0.7 33 strokeOpacity: 0.7
32 } 34 }
  35 + var polygonDmOptions = {
  36 + isOpen : false,
  37 + enableDrawingTool : false,
  38 + drawingToolOptions : {
  39 + anchor : BMAP_ANCHOR_TOP_RIGHT,
  40 + offset : new BMap.Size(5, 5),
  41 + scale : 0.8
  42 + },
  43 + polygonOptions : styleOptions
  44 + }
33 var operation = { 45 var operation = {
34 getAddStationRoute: function () { 46 getAddStationRoute: function () {
35 return addStationRoute; 47 return addStationRoute;
@@ -406,12 +418,20 @@ var RoutesOperation = (function () { @@ -406,12 +418,20 @@ var RoutesOperation = (function () {
406 if(status > 0){ 418 if(status > 0){
407 htm += '<div>' + 419 htm += '<div>' +
408 '<button class="info_win_btn" id="editStation" onclick="RoutesOperation.editStation(' + stationRoute.id+','+stationRoute.directions + ')">修改</button>' + 420 '<button class="info_win_btn" id="editStation" onclick="RoutesOperation.editStation(' + stationRoute.id+','+stationRoute.directions + ')">修改</button>' +
409 - '<button class="info_win_btn" onclick="RoutesOperation.destroyStation('+ stationRoute.id + ','+stationRoute.line.id+','+stationRoute.directions+')">撤销</button>' +  
410 - '<button class="info_win_btn" id="addBetweenStationRoad" onclick="RoutesOperation.addBetweenStationRoad(' + stationRoute.id + ')">添加站点间路段</button>' +  
411 - '</div>'; 421 + '<button class="info_win_btn" onclick="RoutesOperation.destroyStation('+ stationRoute.id + ','+stationRoute.line.id+','+stationRoute.directions+')">撤销</button>';
  422 + if (stationRoute.stationMark == 'E') {
  423 + htm += '<button class="info_win_btn" onclick="RoutesOperation.geoPremise(' + stationRoute.id + ')">前置电子围栏</button></div>';
  424 + } else {
  425 + htm += '<button class="info_win_btn" id="addBetweenStationRoad" onclick="RoutesOperation.addBetweenStationRoad(' + stationRoute.id + ')">添加站点间路段</button></div>';
  426 + }
412 } 427 }
413 // 创建信息窗口 428 // 创建信息窗口
414 var infoWindow = new BMap.InfoWindow(htm, opts); 429 var infoWindow = new BMap.InfoWindow(htm, opts);
  430 + infoWindow.addEventListener('close', function() {
  431 + if (premise) {
  432 + baiduMap.removeOverlay(premise);
  433 + }
  434 + })
415 setTimeout(function () { 435 setTimeout(function () {
416 //开启信息窗口 436 //开启信息窗口
417 baiduMap.openInfoWindow(infoWindow, point); 437 baiduMap.openInfoWindow(infoWindow, point);
@@ -993,6 +1013,83 @@ var RoutesOperation = (function () { @@ -993,6 +1013,83 @@ var RoutesOperation = (function () {
993 }, 1013 },
994 1014
995 /** 1015 /**
  1016 + * 前置电子围栏
  1017 + * @param stationRouteId
  1018 + */
  1019 + geoPremise: function (stationRouteId) {
  1020 + if (premise) {
  1021 + baiduMap.removeOverlay(premise);
  1022 + }
  1023 + RoutesService.findGeoPremise(stationRouteId, function (res) {
  1024 + if (res.id) {
  1025 + var coords = res.coords.split(', '), points = [];
  1026 + for (var i = 0;i < coords.length;i++) {
  1027 + var coordinates = coords[i].split(' ');
  1028 + points.push(new BMap.Point(coordinates[0], coordinates[1]));
  1029 + }
  1030 + premise = new BMap.Polygon(points);
  1031 + premise.cdata = res;
  1032 + premise.enableEditing(true);
  1033 + premise.addEventListener('dblclick', operation.premiseDblclickHandler);
  1034 + baiduMap.addOverlay(premise);
  1035 + } else {
  1036 + layer.confirm('没有电子围栏,是否添加!', {
  1037 + btn : [ '确认', '取消' ]
  1038 + },function () {
  1039 + layer.closeAll();
  1040 + var drawingManager = new BMapLib.DrawingManager(baiduMap, polygonDmOptions);
  1041 + drawingManager.setDrawingMode(BMAP_DRAWING_POLYGON);
  1042 + drawingManager.open();
  1043 + drawingManager.addEventListener('polygoncomplete', function(polygon) {
  1044 + drawingManager.close();
  1045 + baiduMap.removeOverlay(polygon);
  1046 + var points = polygon.getPath();
  1047 + if (points.length < 3) {
  1048 + layer.msg('坐标点不能小于三个,请点击"退出编辑"后重新修改');
  1049 + baiduMap.removeOverlay(polygon);
  1050 +
  1051 + return false;
  1052 + } else {
  1053 + var bufferPolygonWkt = new Array();
  1054 + for(var i = 0;i < points.length;i++) {
  1055 + bufferPolygonWkt.push(points[i].lng + ' ' + points[i].lat)
  1056 + }
  1057 + bufferPolygonWkt.push(points[0].lng + ' ' + points[0].lat)
  1058 + RoutesService.saveGeoPremise({id: stationRouteId, coords: bufferPolygonWkt.join(', ')}, function(res) {
  1059 + if (res.status == 'SUCCESS') {
  1060 + layer.msg('前置电子围栏保存成功!');
  1061 + } else {
  1062 + layer.msg('前置电子围栏保存失败!');
  1063 + }
  1064 + })
  1065 + }
  1066 + });
  1067 +
  1068 + });
  1069 + }
  1070 + })
  1071 + },
  1072 +
  1073 + /**
  1074 + * 前置围栏双击保存
  1075 + */
  1076 + premiseDblclickHandler: function (event) {
  1077 + var points = event.target.getPath(), cdata = event.target.cdata;
  1078 + var bufferPolygonWkt = new Array();
  1079 + for(var i = 0;i < points.length;i++) {
  1080 + bufferPolygonWkt.push(points[i].lng + ' ' + points[i].lat)
  1081 + }
  1082 + bufferPolygonWkt.push(points[0].lng + ' ' + points[0].lat)
  1083 + RoutesService.saveGeoPremise({id: cdata.id, coords: bufferPolygonWkt.join(', ')}, function(res) {
  1084 + if (res.status == 'SUCCESS') {
  1085 + layer.msg('前置电子围栏保存成功!');
  1086 + } else {
  1087 + layer.msg('前置电子围栏保存失败!');
  1088 + }
  1089 + })
  1090 + },
  1091 +
  1092 + /**
996 * 关闭modal时的清理 1093 * 关闭modal时的清理
997 * @param station 1094 * @param station
998 */ 1095 */
@@ -2319,22 +2416,7 @@ var RoutesOperation = (function () { @@ -2319,22 +2416,7 @@ var RoutesOperation = (function () {
2319 2416
2320 /***************************************************drawingmanager*******************************************************/ 2417 /***************************************************drawingmanager*******************************************************/
2321 initStationDrawingManager: function() { 2418 initStationDrawingManager: function() {
2322 - stationDrawingManager = new BMapLib.DrawingManager(baiduMap, {  
2323 - //是否开启绘制模式  
2324 - isOpen : false,  
2325 - //是否显示工具栏  
2326 - enableDrawingTool : false,  
2327 - drawingToolOptions : {  
2328 - //位置  
2329 - anchor : BMAP_ANCHOR_TOP_RIGHT,  
2330 - //偏离值  
2331 - offset : new BMap.Size(5, 5),  
2332 - //工具栏缩放比例  
2333 - scale : 0.8  
2334 - },  
2335 - //线的样式  
2336 - polygonOptions : styleOptions  
2337 - }); 2419 + stationDrawingManager = new BMapLib.DrawingManager(baiduMap, polygonDmOptions);
2338 2420
2339 // 添加绘画完成事件 2421 // 添加绘画完成事件
2340 stationDrawingManager.addEventListener('polygoncomplete', function(polygon) { 2422 stationDrawingManager.addEventListener('polygoncomplete', function(polygon) {
src/main/resources/static/pages/base/stationroute/js/routes-service.js
@@ -335,6 +335,28 @@ var RoutesService = (function(){ @@ -335,6 +335,28 @@ var RoutesService = (function(){
335 $post('/api/lsstationroute/circularRouteHandle', {lineId: lineId, version: version}, function() { 335 $post('/api/lsstationroute/circularRouteHandle', {lineId: lineId, version: version}, function() {
336 callback && callback(); 336 callback && callback();
337 }); 337 });
  338 + },
  339 +
  340 + /**
  341 + * 获取前置电子围栏信息
  342 + * @param id
  343 + * @param callback
  344 + */
  345 + findGeoPremise: function(id, callback) {
  346 + $get('/api/geopremise/' + id, {}, function(res) {
  347 + callback && callback(res);
  348 + })
  349 + },
  350 +
  351 + /**
  352 + * 保存前置电子围栏信息
  353 + * @param params
  354 + * @param callback
  355 + */
  356 + saveGeoPremise: function (params, callback) {
  357 + $post('/api/geopremise/', params, function(res) {
  358 + callback && callback(res);
  359 + })
338 } 360 }
339 }; 361 };
340 362