From b546994ced2db809d4efe9a7a338892c4df27e75 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期五, 16 六月 2023 17:43:47 +0800
Subject: [PATCH] 1

---
 src/main/java/com/yssh/service/IWarningAnalyseService.java         |    3 
 src/main/java/com/yssh/service/impl/WarningAnalyseServiceImpl.java |   20 +++
 src/main/java/com/yssh/utils/CalculateUtils.java                   |   84 ++++++++++++++++
 src/main/java/com/yssh/entity/Report.java                          |  144 ++++++++++++++++++++++++++++
 4 files changed, 246 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/yssh/entity/Report.java b/src/main/java/com/yssh/entity/Report.java
new file mode 100644
index 0000000..905c81b
--- /dev/null
+++ b/src/main/java/com/yssh/entity/Report.java
@@ -0,0 +1,144 @@
+package com.yssh.entity;
+
+import com.yssh.utils.CalculateUtils;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.text.SimpleDateFormat;
+
+/**
+ * 鎶ュ憡
+ * @author WWW
+ * @date 2023-06-18
+ */
+public class Report {
+    @ApiModelProperty(value = "鐐逛綅鍚嶇О")
+    private String name;
+
+    @ApiModelProperty(value = "缁忓害")
+    private double lon;
+
+    @ApiModelProperty(value = "绾害")
+    private double lat;
+
+    @ApiModelProperty(value = "鏁板��")
+    private double value;
+
+    @ApiModelProperty(value = "鏃堕棿")
+    private String time;
+
+    @ApiModelProperty(value = "500m鑼冨洿鏈�澶у��")
+    private double max;
+
+    @ApiModelProperty(value = "璺濈")
+    private double dis;
+
+    @ApiModelProperty(value = "鏂瑰悜")
+    private String dir;
+
+    public Report() {
+    }
+
+    public Report(String name, double lon, double lat, double value, String time, double max, double dis, String dir) {
+        this.name = name;
+        this.lon = lon;
+        this.lat = lat;
+        this.value = value;
+        this.time = time;
+        this.max = max;
+        this.dis = dis;
+        this.dir = dir;
+    }
+
+    /**
+     * 璁$畻鐢熸垚鎶ュ憡
+     */
+    public static Report calcReport(WarningDetail wd, DistanceSuYuan suYuan) {
+        String[] sirs = wd.getSuYuanId().split("_");
+        int x = Integer.parseInt(sirs[0]);
+        int y = Integer.parseInt(sirs[1]);
+        double lon = CalculateUtils.getLon(x, y);
+        double lat = CalculateUtils.getLat(x, y);
+
+        String time = CalculateUtils.getYearMonthDayHour(wd.getCreateTime());
+
+        double max = suYuan.getVocsValue();
+
+        String[] sirs2=suYuan.getId().split("_");
+        int x2 = Integer.parseInt(sirs2[0]);
+        int y2 = Integer.parseInt(sirs2[1]);
+        double lon2 = CalculateUtils.getLon(x2, y2);
+        double lat2 = CalculateUtils.getLat(x2, y2);
+
+        double dis = CalculateUtils.getDistance2(lon, lat, lon2, lat2);
+        double dis1 = CalculateUtils.getDistance1(lon, lat, lon2, lat2);
+        double angle = CalculateUtils.getAngle(lon, lat, lon2, lat2);
+
+        String dir = "";
+
+        return new Report(wd.getLocationName(), lon, lat, wd.getValue(), time, max, dis, dir);
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public double getLon() {
+        return lon;
+    }
+
+    public void setLon(double lon) {
+        this.lon = lon;
+    }
+
+    public double getLat() {
+        return lat;
+    }
+
+    public void setLat(double lat) {
+        this.lat = lat;
+    }
+
+    public double getValue() {
+        return value;
+    }
+
+    public void setValue(double value) {
+        this.value = value;
+    }
+
+    public String getTime() {
+        return time;
+    }
+
+    public void setTime(String time) {
+        this.time = time;
+    }
+
+    public double getMax() {
+        return max;
+    }
+
+    public void setMax(double max) {
+        this.max = max;
+    }
+
+    public double getDis() {
+        return dis;
+    }
+
+    public void setDis(double dis) {
+        this.dis = dis;
+    }
+
+    public String getDir() {
+        return dir;
+    }
+
+    public void setDir(String dir) {
+        this.dir = dir;
+    }
+}
diff --git a/src/main/java/com/yssh/service/IWarningAnalyseService.java b/src/main/java/com/yssh/service/IWarningAnalyseService.java
index 0897a48..7ea0b2b 100644
--- a/src/main/java/com/yssh/service/IWarningAnalyseService.java
+++ b/src/main/java/com/yssh/service/IWarningAnalyseService.java
@@ -5,6 +5,7 @@
 import java.util.Map;
 
 import com.yssh.entity.Qxsh;
+import com.yssh.entity.Report;
 import com.yssh.entity.WarningDetail;
 import com.yssh.entity.vo.WarningVo;
 
@@ -30,5 +31,5 @@
 
 	Map<String, List<Double>> select3Hours();
 
-	List<WarningVo> getAlarmAndWarnByTime(Date begin, Date end);
+	List<Report> getAlarmAndWarnByTime(Date begin, Date end);
 }
diff --git a/src/main/java/com/yssh/service/impl/WarningAnalyseServiceImpl.java b/src/main/java/com/yssh/service/impl/WarningAnalyseServiceImpl.java
index afb8bf4..28381b2 100644
--- a/src/main/java/com/yssh/service/impl/WarningAnalyseServiceImpl.java
+++ b/src/main/java/com/yssh/service/impl/WarningAnalyseServiceImpl.java
@@ -368,7 +368,7 @@
     }
 
     @Override
-    public List<WarningVo> getAlarmAndWarnByTime(Date begin, Date end) {
+    public List<Report> getAlarmAndWarnByTime(Date begin, Date end) {
         String startTime = ymdhms.format(begin);
         String endTime = ymdhms.format(end);
 
@@ -379,10 +379,22 @@
         List<WarningDetail> rsBj = warningDetailMapper.selectByTimeForBj(startTime, endTime);
         if (null != rsBj && rsBj.size() > 0) rs.addAll(rsBj);
 
-        List<WarningVo> list = new ArrayList<>();
+        List<Report> list = new ArrayList<>();
         for (WarningDetail wd : rs) {
-            String time = ymdh.format(wd.getCreateTime());
-            list.add(new WarningVo(wd.getLocationName(), wd.getSuYuanId(), 0.0, 0.0, wd.getValue(), time));
+            //String time = ymdh.format(wd.getCreateTime());
+            //list.add(new WarningVo(wd.getLocationName(), wd.getSuYuanId(), 0.0, 0.0, wd.getValue(), time));
+
+            int rows = suYuanMapper.isTableExists(wd.getTableName());
+
+            DistanceSuYuan suYuan = null;
+            if (rows > 0) {
+                MonitorPointPosition point = commonService.select3dCheckPointByName(wd.getLocationName());
+                List<String> ids3d = CalculateUtils.aloneCrosswiseExtend(point, 50);
+                suYuan = suYuanMapper.getSuYuan500Max(wd.getTableName(), ids3d);
+            }
+
+            Report report = Report.calcReport(wd, suYuan);
+            list.add(report);
         }
 
         return list;
diff --git a/src/main/java/com/yssh/utils/CalculateUtils.java b/src/main/java/com/yssh/utils/CalculateUtils.java
index 4f494c3..45193a1 100644
--- a/src/main/java/com/yssh/utils/CalculateUtils.java
+++ b/src/main/java/com/yssh/utils/CalculateUtils.java
@@ -1,12 +1,95 @@
 package com.yssh.utils;
 
+import java.text.SimpleDateFormat;
 import java.util.*;
 
 import com.yssh.entity.MonitorPointPosition;
+import org.geotools.geometry.DirectPosition2D;
+import org.geotools.referencing.CRS;
+import org.geotools.referencing.GeodeticCalculator;
+import org.geotools.referencing.crs.DefaultGeographicCRS;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
 
 public class CalculateUtils {
+	private final static SimpleDateFormat ymdh = new SimpleDateFormat("yyyyMMddHH");
 
 	/**
+	 * 鑾峰彇骞存湀鏃ユ椂
+	 */
+	public static String getYearMonthDayHour(Date date) {
+		return ymdh.format(date);
+	}
+
+	/**
+	 * 榛樿鍦扮悆鍗婂緞,璧ら亾鍗婂緞(鍗曚綅m)
+	 */
+	private final static double EARTH_RADIUS1 = 6371000;
+
+	/**
+	 * 杞寲涓哄姬搴�(rad)
+	 */
+	private static double rad(double d)
+	{
+		return d * Math.PI / 180.0;
+	}
+
+	/**
+	 * 璁$畻璺濈1
+	 */
+	public static double getDistance1(double lon1, double lat1, double lon2, double lat2) {
+		double radLat1 = rad(lat1);
+		double radLat2 = rad(lat2);
+		double a = radLat1 - radLat2;
+		double b = rad(lon1) - rad(lon2);
+		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_RADIUS1;
+
+		return Math.round(s * 100) / 100;
+	}
+
+	/**
+	 * 璁$畻璺濈2
+	 */
+	public static double getDistance2(double x1, double y1, double x2, double y2) {
+		// 84鍧愭爣绯绘瀯閫燝eodeticCalculator
+		GeodeticCalculator geodeticCalculator = new GeodeticCalculator(DefaultGeographicCRS.WGS84);
+
+		// 璧风偣缁忕含搴�
+		geodeticCalculator.setStartingGeographicPoint(x1, y1);
+
+		// 鏈偣缁忕含搴�
+		geodeticCalculator.setDestinationGeographicPoint(x2, y2);
+
+		// 璁$畻璺濈锛屽崟浣嶏細绫�
+		double distance = geodeticCalculator.getOrthodromicDistance();
+
+		return Math.round(distance * 100) / 100;
+	}
+
+	/**
+	 * 璁$畻瑙掑害
+	 */
+	public static double getAngle(double x1, double y1, double x2, double y2) {
+		try {
+			CoordinateReferenceSystem crs = CRS.decode("EPSG:4326");
+			DirectPosition2D p1 = new DirectPosition2D(crs, x1, y1);
+			DirectPosition2D p2 = new DirectPosition2D(crs, x2, y2);
+
+			GeodeticCalculator gc = new GeodeticCalculator();
+			gc.setStartingGeographicPoint(p1);
+			gc.setDestinationGeographicPoint(p2);
+
+			double angle = gc.getAzimuth();
+
+			return Math.round(angle * 100) / 100;
+		} catch (Exception ex) {
+			return 0;
+		}
+	}
+
+	/**
+	 * 璁$畻缁忓害
 	 * @param @param  x
 	 * @param @param  y
 	 * @param @return 鍙傛暟
@@ -24,6 +107,7 @@
 	}
 
 	/**
+	 * 璁$畻缁村害
 	 * @param @param  x
 	 * @param @param  y
 	 * @param @return 鍙傛暟

--
Gitblit v1.9.3