From 7efb9dc03ea730388bda987568d0b13dac6d899a Mon Sep 17 00:00:00 2001 From: lakefish <3488815871@qq.com> Date: Tue, 15 Mar 2022 14:46:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E5=A4=9A=E5=9C=B0?= =?UTF-8?q?=E5=8C=BA=E7=89=A9=E8=B5=84=E5=88=86=E9=85=8D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FireCenterController.java | 85 ++++++++++++++++--- 1 file changed, 71 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/peteralbus/controller/FireCenterController.java b/src/main/java/com/peteralbus/controller/FireCenterController.java index 3cb690b..830ddf1 100644 --- a/src/main/java/com/peteralbus/controller/FireCenterController.java +++ b/src/main/java/com/peteralbus/controller/FireCenterController.java @@ -1,7 +1,8 @@ package com.peteralbus.controller; -import com.peteralbus.entity.FireCenter; -import com.peteralbus.entity.FireWeight; +import com.peteralbus.entity.*; +import com.peteralbus.service.EarthquakeInfoService; +import com.peteralbus.service.EstimateService; import com.peteralbus.service.FireCenterService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -18,14 +19,37 @@ public class FireCenterController { FireCenterService fireCenterService; @Autowired EstimateController estimateController; + @Autowired + EstimateService estimateService; + @Autowired + EarthquakeInfoService earthquakeInfoService; @RequestMapping("/getAllFireCenter") public List getAllFireCenter(){ return fireCenterService.getAllFireCenter(); } + + //获取一个地震区域的消防站位置 + public List getOnePlaceAllFireCenter(Long earthquakeId){ + List fireCenters=getAllFireCenter(); + List fireCenterList=new ArrayList<>(); + MapmapParameter=new HashMap<>(); + mapParameter.put("earthquakeId",earthquakeId); + EarthquakeInfo earthquakeInfo=earthquakeInfoService.queryInfoWithLine(mapParameter).get(0); + for(FireCenter fireCenter:fireCenters){ + double distanceTwoPlaces=getDistance(fireCenter.getFireLon(),fireCenter.getFireLat(),earthquakeInfo.getLongitude(),earthquakeInfo.getLatitude()); + List intensityLineList=earthquakeInfo.getIntensityLineList(); + if(distanceTwoPlaces getFireCenterIntensity(){ List FireIntensity=new ArrayList<>(); - List fireCenters= fireCenterService.getAllFireCenter(); + List fireCenters= fireCenterService.getAllFireCenter();//这里需要获取比较新的火点数据 for(FireCenter fireCenter:fireCenters){ FireIntensity.add(estimateController.getPointIntensity(16L, fireCenter.getFireLon(), fireCenter.getFireLat())); } @@ -35,22 +59,36 @@ public class FireCenterController { public FireCenter getOneFireCenter(int id){ return fireCenterService.getAllFireCenter().get(id); } - @RequestMapping("/calculateWeight") - public List getFireCenterWeight(){ - double [][] arr=new double [10][988]; - List FireCenterIntensityArr=getFireCenterIntensity(); -// System.out.println(FireCenterIntensityArr); + @RequestMapping("/findFireCenterNearby") + public List getFireCenterWeight(Long earthquakeId){ + List OnePlaceAllFireCenter=getOnePlaceAllFireCenter(earthquakeId); + List FireCenterIntensityArr=new ArrayList<>(); + for(FireCenter fireCenter:OnePlaceAllFireCenter){ + FireCenterIntensityArr.add(estimateController.getPointIntensity(16L, fireCenter.getFireLon(), fireCenter.getFireLat())); + } + int FireCenterIntensityArSize=FireCenterIntensityArr.size(); + System.out.print("FireCenterIntensityArSize长度为"+FireCenterIntensityArSize); + if(FireCenterIntensityArSize==0){ + return null; + } + Mapmap = new HashMap(); + for(int i=0;i> entrys=new ArrayList<>(arrayStrict.entrySet()); Collections.sort(entrys, new MyComparator()); @@ -116,7 +155,7 @@ public class FireCenterController { int count=0; for(Map.Entry entry:entrys){ topTen.put(entry.getKey(),entry.getValue()); - FireCenter resultFireCenter=getOneFireCenter(entry.getKey()); + FireCenter resultFireCenter=getOneFireCenter(map.get(entry.getKey())); FireWeight fireWeight=new FireWeight(); fireWeight.setFireId(resultFireCenter.getFireId()); fireWeight.setFireLat(resultFireCenter.getFireLat()); @@ -135,4 +174,22 @@ public class FireCenterController { // return topTen; return resultFireWeightLists; } + private static final double EARTH_RADIUS = 6378.137; + public static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) { + // 纬度 + double lat1 = Math.toRadians(latitude1); + double lat2 = Math.toRadians(latitude2); + // 经度 + double lng1 = Math.toRadians(longitude1); + double lng2 = Math.toRadians(longitude2); + // 纬度之差 + double a = lat1 - lat2; + // 经度之差 + double b = lng1 - lng2; + // 计算两点距离的公式 + double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2))); + // 弧长乘地球半径, 返回单位: 千米 + s = s * EARTH_RADIUS; + return s; + } }