fllmoyu 4 years ago
parent
commit
1704499c39

+ 5 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/dto/NearbyStationDTO.java

@@ -1,5 +1,6 @@
 package com.jpsoft.bus.modules.bus.dto;
 
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.util.List;
@@ -15,6 +16,10 @@ public class NearbyStationDTO {
 
     private String stationId;
 
+    private Double longitude;
+
+    private Double latitude;
+
     private Integer distance;
 
     private List<NearbyShiftDTO> nearbyShiftDTOList;

+ 1 - 0
web/src/main/java/com/jpsoft/bus/config/WebMvcConfig.java

@@ -89,6 +89,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
 				.excludePathPatterns("/mobile/passengerApi/passengerRemindList")
 				.excludePathPatterns("/mobile/passengerApi/passengerShiftRemindList")
 				.excludePathPatterns("/mobile/passengerApi/helpCenterList")
+				.excludePathPatterns("/mobile/passengerApi/vehicleStationDis")
 
 
 		;

+ 99 - 0
web/src/main/java/com/jpsoft/bus/modules/mobile/controller/PassengerApiController.java

@@ -952,6 +952,8 @@ public class PassengerApiController {
 
             nearbyStationDTO.setStationId(stationInfo.getId());
             nearbyStationDTO.setStationName(stationInfo.getName());
+            nearbyStationDTO.setLatitude(stationInfo.getLatitude());
+            nearbyStationDTO.setLongitude(stationInfo.getLongitude());
 
             for (int n = 0; n < 2; n++) {
                 String startStationId = stationInfoList1.get(0).getId();
@@ -1128,6 +1130,103 @@ public class PassengerApiController {
         return messageResult;
     }
 
+    @PostMapping("vehicleStationDis")
+    @ApiOperation(value = "站点车辆距离")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "routeId", value = "线路id", required = true, paramType = "form"),
+            @ApiImplicitParam(name = "startStationId", value = "开始站点id", required = true, paramType = "form"),
+            @ApiImplicitParam(name = "currentStationId", value = "当前站点id", required = true, paramType = "form")
+    })
+    public MessageResult<String> vehicleStationDis(String routeId, String startStationId,String currentStationId) {
+        MessageResult<String> messageResult = new MessageResult<>();
+
+        try {
+
+            if (StringUtils.isBlank(routeId) || StringUtils.isBlank(startStationId)) {
+                throw new Exception("参数错误");
+            }
+
+            List<StationInfo> stationInfoList = stationInfoService.findByRouteId(routeId);
+            //是否顺路
+            Boolean tmp = true;
+            if (!startStationId.equals(stationInfoList.get(0).getId())){
+                tmp = false;
+            }
+
+            List<ShiftInfo> shiftInfoList = shiftInfoService.findByRouteIdAndStatusAndStartStationId(routeId,"1",startStationId);
+            //查询的当前站
+            StationInfo currentStation = stationInfoService.get(currentStationId);
+
+            String des = null;
+            if (shiftInfoList.size()>0){
+                String vehicleId = "";
+                int n = 1000;
+                for (ShiftInfo shiftInfo : shiftInfoList){
+                    //班次当前站
+                    StationInfo stationInfo = stationInfoService.get(shiftInfo.getCurrentStationId());
+                    int stationInfoIndex = stationInfoList.indexOf(stationInfo);
+
+                    int currentStationIndex = stationInfoList.indexOf(currentStation);
+                    if (tmp){
+                        if (stationInfoIndex<=currentStationIndex){
+                          int  m = currentStationIndex - stationInfoIndex;
+                            if (m<n){
+                                n = m;
+                                vehicleId = shiftInfo.getVehicleId();
+                            }
+                        }
+
+                    }
+                    if (!tmp){
+                        if (stationInfoIndex >= currentStationIndex){
+                            int  m = stationInfoIndex - currentStationIndex;
+                            if (m<n){
+                                n = m;
+                                vehicleId = shiftInfo.getVehicleId();
+                            }
+                        }
+                    }
+
+                }
+
+                if (StringUtils.isNotBlank(vehicleId)){
+                    //车辆
+                    VehicleInfo vehicleInfo = vehicleInfoService.get(vehicleId);
+                    //距离
+                    GlobalCoordinates source = new GlobalCoordinates(Double.valueOf(vehicleInfo.getLatitude()), Double.valueOf(vehicleInfo.getLongitude()));
+                    GlobalCoordinates target = new GlobalCoordinates(Double.valueOf(currentStation.getLatitude()), Double.valueOf(currentStation.getLongitude()));
+
+                    double meter1 = CommonUtil.getDistanceMeter(source, target, Ellipsoid.Sphere);
+
+                    int intMeter = (new Double(meter1)).intValue();
+                    //距离详情
+                    String distanceStr = null;
+                    if (intMeter >= 1000) {
+                        distanceStr = intMeter / 1000 + "公里";
+                    } else {
+                        distanceStr = intMeter + "米";
+                    }
+                    des = n + "站 "+ distanceStr;
+                }
+            }
+
+            messageResult.setData(des);
+            messageResult.setCode(200);
+            messageResult.setResult(true);
+
+
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+            messageResult.setCode(400);
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
+
+
+
 
     @PostMapping("routeList")
     @ApiOperation(value = "乘客查询线路列表")