添加了获取地震附近医院的接口

main
PeterAlbus 3 years ago
parent bc8e55acfe
commit 04c643f9c3

@ -1,17 +1,24 @@
package com.peteralbus.controller;
import com.peteralbus.entity.Distance;
import com.peteralbus.entity.EarthquakeInfo;
import com.peteralbus.entity.Hospital;
import com.peteralbus.entity.IntensityLine;
import com.peteralbus.service.EarthquakeInfoService;
import com.peteralbus.service.HospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The type Hospital controller.
*
* @author PeterAlbus
*/
@CrossOrigin
@ -22,6 +29,20 @@ public class HospitalController {
* The Hospital service.
*/
HospitalService hospitalService;
/**
* The Earthquake info service.
*/
EarthquakeInfoService earthquakeInfoService;
/**
* Sets earthquake info service.
*
* @param earthquakeInfoService the earthquake info service
*/
public void setEarthquakeInfoService(EarthquakeInfoService earthquakeInfoService)
{
this.earthquakeInfoService = earthquakeInfoService;
}
/**
* Sets hospital service.
@ -44,6 +65,33 @@ public class HospitalController {
return hospitalService.findAllHospital();
}
/**
* Find hospital nearby list.
*
* @param earthquakeId the earthquake id
* @return the list
*/
@RequestMapping("/findHospitalNearby")
public List<Hospital> findHospitalNearby(Long earthquakeId)
{
List<Hospital> hospitals=hospitalService.findAllHospital();
List<Hospital> hospitalList=new ArrayList<>();
Map<String, Object> mapParameter = new HashMap<String, Object>();
mapParameter.put("earthquakeId",earthquakeId);
EarthquakeInfo earthquakeInfo=earthquakeInfoService.queryInfoWithLine(mapParameter).get(0);
for (Hospital hospital : hospitals)
{
double distanceTwoPlaces = getDistance(hospital.getLon(), hospital.getLat(), earthquakeInfo.getLongitude(), earthquakeInfo.getLatitude());
List<IntensityLine> intensityLineList=earthquakeInfo.getIntensityLineList();
if(distanceTwoPlaces<intensityLineList.get(intensityLineList.size()-1).getLongRadius())
{
hospitalList.add(hospital);
}
}
return hospitalList;
}
/**
* Calculate distance distance.
*
@ -114,7 +162,6 @@ public class HospitalController {
* @param latitude2 the latitude 2
* @return the distance 2
*/
public static double getDistance2(double longitude1, double latitude1, double longitude2, double latitude2)
{
//Haversine公式的最终实现方式可以有多种比如借助转角度的函数atan2

@ -30,27 +30,6 @@ public class GeoUtil
return "china";
}
return "unknown";
/*
* 93.00308916641167 46.33557176688004
86.37301672326446 50.38751980406519
73.6806350895496 43.12858377050971
71.94791968712168 36.56117850620303
80.4163170843829 28.375889044457423
94.0975257616471 25.95490015099189
97.03126325207795 25.2466929117808
106.21940281130414 18.50325287154198
108.03561240396455 1.7904217579092063
115.08923186524542 2.5672899629108006
121.00126550556921 11.536691305966007
124.25692768695644 24.364585545502848
122.9104187262468 33.58930644637152
123.50186921321631 37.35578847985431
132.32258204239037 43.32300574916736
136.11484957724633 48.08471692521181
123.4737832533535 54.98049753905599
114.27833315710531 50.57789552466974
103.71424276778035 44.6553865942794
* */
}
/**
@ -118,8 +97,7 @@ public class GeoUtil
double radLat2 = rad(lat2);
double a = radLat1 - radLat2;
double b = rad(lng1) - rad(lng2);
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s = s * EARTH_RADIUS;
s = Math.round(s * 10000d) / 10000d;
//double len=s/EARTH_SEA;

Loading…
Cancel
Save