From e5b23b9797083fbbbbe530ce76ffa3723bc3422f Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: Thu, 08 Jun 2023 16:12:58 +0800
Subject: [PATCH] 增加管线泄露报警点高层算法
---
/dev/null | 220 --------------------
ard-work/src/main/java/com/ruoyi/utils/tube/GeoPoint.java | 3
ard-work/src/main/resources/mapper/alarm/ArdAlarmTubeMapper.xml | 37 ++-
ard-work/src/main/java/com/ruoyi/alarm/globalAlarm/service/GlobalAlarmServiceImpl.java | 18 +
ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/domain/ArdAlarmTube.java | 154 +------------
ard-work/src/main/java/com/ruoyi/utils/tube/MyLatLng.java | 2
ruoyi-admin/src/main/resources/application.yml | 1
ard-work/src/main/java/com/ruoyi/utils/tube/TubeTools.java | 218 +++++++++++++++++++
8 files changed, 283 insertions(+), 370 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/globalAlarm/service/GlobalAlarmServiceImpl.java b/ard-work/src/main/java/com/ruoyi/alarm/globalAlarm/service/GlobalAlarmServiceImpl.java
index bf0c6cd..5b9a23f 100644
--- a/ard-work/src/main/java/com/ruoyi/alarm/globalAlarm/service/GlobalAlarmServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/alarm/globalAlarm/service/GlobalAlarmServiceImpl.java
@@ -11,13 +11,19 @@
import com.ruoyi.alarmpoints.tube.domain.ArdTubesDetails;
import com.ruoyi.alarmpoints.tube.mapper.ArdTubesDetailsMapper;
import com.ruoyi.alarmpoints.tube.mapper.ArdTubesMapper;
+import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.UUID;
+import com.ruoyi.utils.tube.GeoPoint;
+import com.ruoyi.utils.tube.TubeTools;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
+
+import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;
/**
* @ClassName: globalAlarmServiceImpl
@@ -27,6 +33,7 @@
* @Version: 1.0
**/
@Service
+@Slf4j(topic = "mqtt")
public class GlobalAlarmServiceImpl implements IGlobalAlarmService {
@Resource
ArdAlarmStealelecMapper ardAlarmStealelecMapper;
@@ -67,8 +74,19 @@
ardAlarmTube.setColor(ardTubes.getColor());
ardAlarmTube.setPipeDiameter(ardTubes.getPipeDiameter());
ardAlarmTube.setTubeType(ardTubes.getType());
+ GeoPoint geoPoint = TubeTools.CalculateCoordinates(ardTubesDetails, ardAlarmTube.getPosition());
+ if(StringUtils.isNotNull(geoPoint))
+ {
+ ardAlarmTube.setLongitude(geoPoint.getLongitude());
+ ardAlarmTube.setLatitude(geoPoint.getLatitude());
+ ardAlarmTube.setAltitude(geoPoint.getAltitude());
+ }
}
int i = ardAlarmTubeService.insertArdAlarmTube(ardAlarmTube);
+ if(i>0)
+ {
+ log.info("入库成功:"+ardAlarmTube.toString());
+ }
break;
}
}
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/domain/ArdAlarmTube.java b/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/domain/ArdAlarmTube.java
index 0912d84..d3a1e74 100644
--- a/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/domain/ArdAlarmTube.java
+++ b/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/domain/ArdAlarmTube.java
@@ -2,6 +2,8 @@
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import lombok.ToString;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
@@ -13,6 +15,8 @@
* @author 刘苏义
* @date 2023-06-06
*/
+@Data
+@ToString
public class ArdAlarmTube extends BaseEntity
{
private static final long serialVersionUID = 1L;
@@ -46,7 +50,19 @@
/** 位置 */
@Excel(name = "位置")
- private String position;
+ private Integer position;
+
+ /** 经度 */
+ @Excel(name = "经度")
+ private Double longitude;
+
+ /** 纬度 */
+ @Excel(name = "纬度")
+ private Double latitude;
+
+ /** 高层 */
+ @Excel(name = "高层")
+ private Double altitude;
/** 类型GXALARM */
@Excel(name = "类型GXALARM")
@@ -70,141 +86,5 @@
@Excel(name = "查看时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date viewTime;
- public void setId(String id)
- {
- this.id = id;
- }
- public String getId()
- {
- return id;
- }
- public void setHost(String host)
- {
- this.host = host;
- }
-
- public String getHost()
- {
- return host;
- }
- public void setTubeId(String tubeId)
- {
- this.tubeId = tubeId;
- }
-
- public String getTubeId()
- {
- return tubeId;
- }
- public void setTubeName(String tubeName)
- {
- this.tubeName = tubeName;
- }
-
- public String getTubeName()
- {
- return tubeName;
- }
- public void setTubeType(String tubeType)
- {
- this.tubeType = tubeType;
- }
-
- public String getTubeType()
- {
- return tubeType;
- }
- public void setPipeDiameter(String pipeDiameter)
- {
- this.pipeDiameter = pipeDiameter;
- }
-
- public String getPipeDiameter()
- {
- return pipeDiameter;
- }
- public void setColor(String color)
- {
- this.color = color;
- }
-
- public String getColor()
- {
- return color;
- }
- public void setPosition(String position)
- {
- this.position = position;
- }
-
- public String getPosition()
- {
- return position;
- }
- public void setType(String type)
- {
- this.type = type;
- }
-
- public String getType()
- {
- return type;
- }
- public void setAlarmType(String alarmType)
- {
- this.alarmType = alarmType;
- }
-
- public String getAlarmType()
- {
- return alarmType;
- }
- public void setAlarmTime(Date alarmTime)
- {
- this.alarmTime = alarmTime;
- }
-
- public Date getAlarmTime()
- {
- return alarmTime;
- }
- public void setWatcher(String watcher)
- {
- this.watcher = watcher;
- }
-
- public String getWatcher()
- {
- return watcher;
- }
- public void setViewTime(Date viewTime)
- {
- this.viewTime = viewTime;
- }
-
- public Date getViewTime()
- {
- return viewTime;
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
- .append("id", getId())
- .append("host", getHost())
- .append("tubeId", getTubeId())
- .append("tubeName", getTubeName())
- .append("tubeType", getTubeType())
- .append("pipeDiameter", getPipeDiameter())
- .append("color", getColor())
- .append("position", getPosition())
- .append("type", getType())
- .append("alarmType", getAlarmType())
- .append("alarmTime", getAlarmTime())
- .append("watcher", getWatcher())
- .append("createTime", getCreateTime())
- .append("viewTime", getViewTime())
- .toString();
- }
}
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/LeakPointCalculation.java b/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/LeakPointCalculation.java
deleted file mode 100644
index 05a6225..0000000
--- a/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/LeakPointCalculation.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.ruoyi.alarm.tubeAlarm.service.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class LeakPointCalculation {
- public static void main(String[] args) {
- // 假设有三段管线
- List<Point3D> pipeline = new ArrayList<>();
- pipeline.add(new Point3D(124.925198285, 46.68693001, 147.5)); // 第一段管线的起点坐标
- pipeline.add(new Point3D(124.925490653, 46.687071291, 148.2)); // 第一段管线的终点坐标和高程
- pipeline.add(new Point3D(124.926401943, 46.686812672, 143.5)); // 第二段管线的终点坐标和高程
- pipeline.add(new Point3D(124.926981879, 46.686644854, 147.4)); // 第三段管线的终点坐标和高程
-
- double leakPointDistance = 100.0; // 泄漏点相对于管线起点的长度
-
- // 1. 确定泄漏点所在的管线段
- Point3D startPoint = null;
- Point3D endPoint = null;
- double accumulatedLength = 0.0;
- for (int i = 0; i < pipeline.size() - 1; i++) {
- startPoint = pipeline.get(i);
- endPoint = pipeline.get(i + 1);
- double segmentLength = calculateDistance(startPoint, endPoint);
- accumulatedLength += segmentLength;
- if (accumulatedLength >= leakPointDistance) {
- break;
- }
- }
-
- // 2. 计算泄漏点在所在管线段上的相对位置
- double relativePosition = (accumulatedLength - leakPointDistance) / calculateDistance(startPoint, endPoint);
-
- // 3. 计算泄漏点的坐标
- double x = startPoint.getX() + (endPoint.getX() - startPoint.getX()) * relativePosition;
- double y = startPoint.getY() + (endPoint.getY() - startPoint.getY()) * relativePosition;
- double z = startPoint.getZ() + (endPoint.getZ() - startPoint.getZ()) * relativePosition;
-
- Point3D leakPoint = new Point3D(x, y, z);
- System.out.println("泄漏点坐标:" + leakPoint);
- }
-
- // 计算两个点之间的距离
- private static double calculateDistance(Point3D point1, Point3D point2) {
- double dx = point2.getX() - point1.getX();
- double dy = point2.getY() - point1.getY();
- double dz = point2.getZ() - point1.getZ();
- return Math.sqrt(dx * dx + dy * dy + dz * dz);
- }
-}
\ No newline at end of file
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/Point3D.java b/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/Point3D.java
deleted file mode 100644
index 7629d0e..0000000
--- a/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/Point3D.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.ruoyi.alarm.tubeAlarm.service.impl;
-
-import lombok.AllArgsConstructor;
-import lombok.Data;
-
-/**
- * @Description:
- * @ClassName: Point3D
- * @Author: 刘苏义
- * @Date: 2023年06月07日15:12
- * @Version: 1.0
- **/
-@Data
-@AllArgsConstructor
-public class Point3D {
- private double x;
- private double y;
- private double z;
-}
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/testService.java b/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/testService.java
deleted file mode 100644
index 7f7ff27..0000000
--- a/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/testService.java
+++ /dev/null
@@ -1,220 +0,0 @@
-package com.ruoyi.alarm.tubeAlarm.service.impl;
-
-import com.ruoyi.alarmpoints.tube.domain.ArdTubesDetails;
-import com.ruoyi.alarmpoints.tube.mapper.ArdTubesDetailsMapper;
-import com.ruoyi.device.hiksdk.util.hikSdkUtil.GisUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
-import java.util.*;
-import java.util.List;
-
-
-/**
- * @Description:
- * @ClassName: testService
- * @Author: 刘苏义
- * @Date: 2023年06月06日15:20
- * @Version: 1.0
- **/
-@Service
-@Slf4j
-public class testService {
-
- @Resource
- ArdTubesDetailsMapper ardTubesDetailsMapper;
-
- // 计算两个点之间的距离
- public static double calculateDistance(double x1, double y1, double z1, double x2, double y2, double z2) {
- double deltaX = x2 - x1;
- double deltaY = y2 - y1;
- double deltaZ = z2 - z1;
- double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
- return distance;
- }
-
- @PostConstruct
- public void getlist() {
- Integer alarmPointDistance = 100;
- ArdTubesDetails atd = new ArdTubesDetails();
- atd.setReelNumber("10");
- List<ArdTubesDetails> ardTubesDetails = ardTubesDetailsMapper.selectArdTubesDetailsList(atd);
- TreeMap<Integer, Double> distanceMap = new TreeMap<>();
- // 创建自定义的Comparator对象,按照InflectionPointNumber字段进行排序
- Comparator<ArdTubesDetails> comparator = Comparator.comparingInt(person -> Integer.parseInt(person.getInflectionPointNumber()));
- // 使用Collections.sort方法进行排序
- Collections.sort(ardTubesDetails, comparator);
- /*起点坐标*/
- Double x = ardTubesDetails.get(0).getLongitude();
- Double y = ardTubesDetails.get(0).getLatitude();
- TreeMap<Integer, Object> pointMap = new TreeMap<>();
- Double tempX = x;
- Double tempY = y;
- Double tempD = 0.0;
- for (ArdTubesDetails ardtd : ardTubesDetails) {
- double distance = GisUtil.getDistance(tempX, tempY, ardtd.getLongitude(), ardtd.getLatitude());
- tempD += distance;
- distanceMap.put(Integer.parseInt(ardtd.getInflectionPointNumber()), tempD);
- pointMap.put(Integer.parseInt(ardtd.getInflectionPointNumber()), ardtd);
- tempX = ardtd.getLongitude();
- tempY = ardtd.getLatitude();
- }
-
-
- /*按顺序比对距离,找到该距离属于哪个拐点之后*/
- int num = 1;//拐点序号
- Double distanceDiff = 0.0;//与拐点距离差
- Double distanceA = 0.0;
- Double distanceB = 0.0;
- while (distanceB < alarmPointDistance) {
- num++;
- distanceA = distanceMap.get(num-1);
- distanceB = distanceMap.get(num);
- }
- log.info("报警点在拐点" + (num - 1) + "与" + (num) + "之间");
- /*获取当前报警点所在的2个拐点的坐标*/
- ArdTubesDetails point1 = (ArdTubesDetails) pointMap.get(num - 1);
- double x0 = point1.getLongitude();
- double y0 = point1.getLatitude();
- double z0 = point1.getAltitude();
- ArdTubesDetails point2 = (ArdTubesDetails) pointMap.get(num);
- double x1 = point2.getLongitude();
- double y1 = point2.getLatitude();
- double z1 = point2.getAltitude();
- /*计算报警点坐标*/
- double ABdistance = GisUtil.getDistance(x0, y0, x1, y1);
- double Bdistance = z1 > z0 ? z1 - z0 : z0 - z1;
- double angleC = Math.atan(Bdistance / ABdistance);
- log.info("对边与邻边对应角的弧度:" + angleC + " 度");
- // 将弧度转换为角度
- double angleDeg = Math.toDegrees(angleC);
- log.info("对边与邻边对应角的角度:" + angleDeg + " 度");
-
- /*报警所在的2个拐点,起点高于终端*/
- if(z0>z1)
- {
- distanceDiff = alarmPointDistance - distanceA;
- GeoPoint aPoint = new GeoPoint(x0, y0);
- GeoPoint bPoint = new GeoPoint(x1, y1);
- double sp = Math.sin(angleC) * distanceDiff;
- log.info("水平距离:" + sp + " 米");
- GeoPoint geoPoint = caculateRawGeoPoint(aPoint, bPoint, sp);
- log.info(geoPoint.toString());
- /*计算高层*/
- double ACdistance = GisUtil.getDistance(geoPoint.getLongitude(), geoPoint.getLatitude(),x1, y1);
- // 求解斜边的长度
- double hypotenuse = ACdistance * Math.tan(angleC) + z1;
- log.info("C点高层:" + hypotenuse + " 米");
- }
- else
- {
- distanceDiff = alarmPointDistance - distanceA;
- GeoPoint aPoint = new GeoPoint(x0, y0);
- GeoPoint bPoint = new GeoPoint(x1, y1);
- double sp = Math.sin(angleC) * distanceDiff;
- log.info("水平距离:" + sp + " 米");
- GeoPoint geoPoint = caculateRawGeoPoint(aPoint, bPoint, sp);
- log.info(geoPoint.toString());
- /*计算高层*/
- double ACdistance = GisUtil.getDistance(x0, y0, geoPoint.getLongitude(), geoPoint.getLatitude());
- // 求解斜边的长度
- double hypotenuse = ACdistance * Math.tan(angleC) + z0;
- log.info("C点高层:" + hypotenuse + " 米");
- }
-
- }
-
-
- //判断2个线段的斜率
- public static void main(String[] args) {
- // 假设给定的三个坐标点 A、B、C
- double x1 = 124.925490653;
- double y1 = 46.687071291;
- double x2 = 124.9255455011709;
- double y2 = 46.68705572539618;
- double x3 = 124.926401943;
- double y3 = 46.686812672;
- // 计算斜率
- double slope1 = (y2 - y1) / (x2 - x1);
- double slope2 = (y3 - y2) / (x3 - x2);
-
- // 设置斜率差值的阈值
- double threshold = 0.0000001;
-
- // 检查斜率是否相等
- if (Math.abs(slope1 - slope2) < threshold) {
- log.info("这三个点共线");
- } else {
- log.info("这三个点不共线");
- }
- }
-
- /**
- * 已知WGS84坐标系 A 点,B点, X 在AB 弧线上, 且是最短的这条, AX距离已知,求X点坐标.
- *
- * @param aPoint
- * @param bPoint
- * @param distance_ax_in_meter
- * @return
- */
- public static GeoPoint caculateRawGeoPoint(GeoPoint aPoint, GeoPoint bPoint, double distance_ax_in_meter) {
- MyLatLng a = new MyLatLng(aPoint.getLongitude(), aPoint.getLatitude());
- MyLatLng b = new MyLatLng(bPoint.getLongitude(), bPoint.getLatitude());
- double angle = getAngle(a, b); //getAngle(a,x)==getAngle(a,b)
- MyLatLng x = getMyLatLng(a, distance_ax_in_meter / 1000.0, angle);
- GeoPoint xPoint = new GeoPoint(x.m_Longitude, x.m_Latitude);
- return xPoint;
- }
- public static GeoPoint caculateRawGeoPoint1(GeoPoint aPoint, GeoPoint bPoint, double distance_ax_in_meter) {
- MyLatLng a = new MyLatLng(aPoint.getLongitude(), aPoint.getLatitude());
- MyLatLng b = new MyLatLng(bPoint.getLongitude(), bPoint.getLatitude());
- double angle = getAngle(a, b);
- MyLatLng x = getMyLatLng(a, (360-distance_ax_in_meter) / 1000.0, angle);
- GeoPoint xPoint = new GeoPoint(x.m_Longitude, x.m_Latitude);
- return xPoint;
- }
- /**
- * 求B点经纬度
- *
- * @param A 已知点的经纬度,
- * @param distanceInKM AB两地的距离 单位km
- * @param angle AB连线与正北方向的夹角(0~360)
- * @return B点的经纬度
- */
- public static MyLatLng getMyLatLng(MyLatLng A, double distanceInKM, double angle) {
-
- double dx = distanceInKM * 1000 * Math.sin(Math.toRadians(angle));
- double dy = distanceInKM * 1000 * Math.cos(Math.toRadians(angle));
-
- double bjd = (dx / A.Ed + A.m_RadLo) * 180. / Math.PI;
- double bwd = (dy / A.Ec + A.m_RadLa) * 180. / Math.PI;
- return new MyLatLng(bjd, bwd);
- }
-
- /**
- * 获取AB连线与正北方向的角度
- *
- * @param A A点的经纬度
- * @param B B点的经纬度
- * @return AB连线与正北方向的角度(0~360)
- */
- public static double getAngle(MyLatLng A, MyLatLng B) {
- double dx = (B.m_RadLo - A.m_RadLo) * A.Ed;
- double dy = (B.m_RadLa - A.m_RadLa) * A.Ec;
- double angle = 0.0;
- angle = Math.atan(Math.abs(dx / dy)) * 180. / Math.PI;
- double dLo = B.m_Longitude - A.m_Longitude;
- double dLa = B.m_Latitude - A.m_Latitude;
- if (dLo > 0 && dLa <= 0) {
- angle = (90. - angle) + 90;
- } else if (dLo <= 0 && dLa < 0) {
- angle = angle + 180.;
- } else if (dLo < 0 && dLa >= 0) {
- angle = (90. - angle) + 270;
- }
- return angle;
- }
-
-}
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/GeoPoint.java b/ard-work/src/main/java/com/ruoyi/utils/tube/GeoPoint.java
similarity index 83%
rename from ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/GeoPoint.java
rename to ard-work/src/main/java/com/ruoyi/utils/tube/GeoPoint.java
index 8138933..1e97f1f 100644
--- a/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/GeoPoint.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/tube/GeoPoint.java
@@ -1,4 +1,4 @@
-package com.ruoyi.alarm.tubeAlarm.service.impl;
+package com.ruoyi.utils.tube;
import lombok.AllArgsConstructor;
import lombok.Data;
@@ -15,4 +15,5 @@
public class GeoPoint {
Double longitude;
Double latitude;
+ Double altitude;
}
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/MyLatLng.java b/ard-work/src/main/java/com/ruoyi/utils/tube/MyLatLng.java
similarity index 95%
rename from ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/MyLatLng.java
rename to ard-work/src/main/java/com/ruoyi/utils/tube/MyLatLng.java
index 549d7b9..d905512 100644
--- a/ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/MyLatLng.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/tube/MyLatLng.java
@@ -1,4 +1,4 @@
-package com.ruoyi.alarm.tubeAlarm.service.impl;
+package com.ruoyi.utils.tube;
import lombok.Data;
diff --git a/ard-work/src/main/java/com/ruoyi/utils/tube/TubeTools.java b/ard-work/src/main/java/com/ruoyi/utils/tube/TubeTools.java
new file mode 100644
index 0000000..24f018f
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/utils/tube/TubeTools.java
@@ -0,0 +1,218 @@
+package com.ruoyi.utils.tube;
+
+import com.ruoyi.alarmpoints.tube.domain.ArdTubesDetails;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.TreeMap;
+
+/**
+ * @ClassName TubeTools
+ * @Description: 管线计算工具
+ * @Author 刘苏义
+ * @Date 2023/6/6 19:29
+ * @Version 1.0
+ */
+@Service
+@Slf4j
+public class TubeTools {
+ public static void main(String[] args) {
+ // 假设给定的三个坐标点 A、B、C
+ double x1 = 124.939903268;
+ double y1 = 46.684520056;
+ double x2 = 124.94049634327537;
+ double y2 = 46.68442539350505;
+ double x3 = 124.940552075;
+ double y3 = 46.684416498;
+
+ double distance = getDistance(x1, y1, x3, y3);
+ log.debug("总距离:" + distance);
+ double distance1 = getDistance(x1, y1, x2, y2);
+ log.debug("距离起点距离:" + distance1);
+ double distance2 = getDistance(x2, y2, x3, y3);
+ log.debug("距离终点距离:" + distance2);
+ // 计算斜率
+ double slope1 = (y2 - y1) / (x2 - x1);
+ double slope2 = (y3 - y2) / (x3 - x2);
+
+ // 设置斜率差值的阈值
+ double threshold = 0.000001;
+
+ // 检查斜率是否相等
+ if (Math.abs(slope1 - slope2) < threshold) {
+ log.debug("这三个点共线");
+ } else {
+ log.debug("这三个点不共线");
+ }
+ }
+
+ /**
+ * @描述 计算坐标
+ * @参数 [ardTubesDetails, alarmPointDistance]
+ * @返回值 void
+ * @创建人 刘苏义
+ * @创建时间 2023/6/8 14:38
+ * @修改人和其它信息
+ */
+ public static GeoPoint CalculateCoordinates(List<ArdTubesDetails> ardTubesDetails, Integer alarmPointDistance) {
+
+ try {
+ Comparator<ArdTubesDetails> comparator = Comparator.comparingInt(person -> Integer.parseInt(person.getInflectionPointNumber())); // 使用Collections.sort方法进行排序
+ Collections.sort(ardTubesDetails, comparator);
+ double x = ardTubesDetails.get(0).getLongitude();
+ double y = ardTubesDetails.get(0).getLatitude();
+ TreeMap<Integer, Double> distanceMap = new TreeMap<>();
+ TreeMap<Integer, Object> tubeMap = new TreeMap<>();
+ double distance = 0.0;
+ for (ArdTubesDetails atd : ardTubesDetails) {
+ distance += getDistance(x, y, atd.getLongitude(), atd.getLatitude());
+ distanceMap.put(Integer.parseInt(atd.getInflectionPointNumber()), distance);
+ tubeMap.put(Integer.parseInt(atd.getInflectionPointNumber()), atd);
+ x = atd.getLongitude();
+ y = atd.getLatitude();
+ }
+ Integer num = 0;
+ double tempDistance = 0.0;
+ while (tempDistance < alarmPointDistance) {
+ num++;
+ tempDistance = distanceMap.get(num);
+ }
+ log.debug("报警点在拐点" + (num - 1) + "-" + num + "之间,总距离" + (tempDistance - distanceMap.get(num - 1)));
+ ArdTubesDetails point1 = (ArdTubesDetails) tubeMap.get(num - 1);
+ double x0 = point1.getLongitude();
+ double y0 = point1.getLatitude();
+ double z0 = point1.getAltitude();
+ ArdTubesDetails point2 = (ArdTubesDetails) tubeMap.get(num);
+ double x1 = point2.getLongitude();
+ double y1 = point2.getLatitude();
+ double z1 = point2.getAltitude();
+ /*计算报警点坐标*/
+ double d = alarmPointDistance - distanceMap.get(num - 1);
+ GeoPoint aPoint = new GeoPoint(x0, y0, z0);
+ GeoPoint bPoint = new GeoPoint(x1, y1, z1);
+ GeoPoint geoPoint = caculateRawGeoPoint(aPoint, bPoint, d);
+ double height = interpolateHeight(aPoint, bPoint, geoPoint);
+ geoPoint.setAltitude(height);
+ log.debug("计算结果:" + geoPoint);
+ return geoPoint;
+ }
+ catch (Exception ex)
+ {
+ log.error("管线报警点坐标计算异常:"+ex.getMessage());
+ return null;
+ }
+
+ }
+
+ // 线性插值计算任意点的高度
+ private static double interpolateHeight(GeoPoint startPoint, GeoPoint endPoint, GeoPoint alarmPoint) {
+ double startX = startPoint.getLongitude();
+ double startY = startPoint.getLatitude();
+ double startZ = startPoint.getAltitude();
+ double endX = endPoint.getLongitude();
+ double endY = endPoint.getLatitude();
+ double endZ = endPoint.getAltitude();
+ // 目标点的坐标
+ double targetX = alarmPoint.getLongitude();
+ double targetY = alarmPoint.getLatitude();
+ double distance = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2));
+ double targetDistance = Math.sqrt(Math.pow(targetX - startX, 2) + Math.pow(targetY - startY, 2));
+ double t = targetDistance / distance;
+ double targetHeight = startZ + t * (endZ - startZ);
+ return targetHeight;
+ }
+
+ /**
+ * 已知WGS84坐标系 A 点,B点, X 在AB 弧线上, 且是最短的这条, AX距离已知,求X点坐标.
+ *
+ * @param aPoint
+ * @param bPoint
+ * @param distance_ax_in_meter
+ * @return
+ */
+ private static GeoPoint caculateRawGeoPoint(GeoPoint aPoint, GeoPoint bPoint, double distance_ax_in_meter) {
+ MyLatLng a = new MyLatLng(aPoint.getLongitude(), aPoint.getLatitude());
+ MyLatLng b = new MyLatLng(bPoint.getLongitude(), bPoint.getLatitude());
+ double angle = getAngle(a, b);
+ //double angle = GisUtil.getNorthAngle(a.getM_Longitude(),a.getM_Latitude(), b.getM_Longitude(),b.getM_Latitude());
+ MyLatLng x = getMyLatLng(a, distance_ax_in_meter / 1000.0, angle);
+ GeoPoint xPoint = new GeoPoint(x.m_Longitude, x.m_Latitude, 0.0);
+ return xPoint;
+ }
+
+ /**
+ * 求B点经纬度
+ *
+ * @param A 已知点的经纬度,
+ * @param distanceInKM AB两地的距离 单位km
+ * @param angle AB连线与正北方向的夹角(0~360)
+ * @return B点的经纬度
+ */
+ private static MyLatLng getMyLatLng(MyLatLng A, double distanceInKM, double angle) {
+
+ double dx = distanceInKM * 1000 * Math.sin(Math.toRadians(angle));
+ double dy = distanceInKM * 1000 * Math.cos(Math.toRadians(angle));
+
+ double bjd = (dx / A.Ed + A.m_RadLo) * 180. / Math.PI;
+ double bwd = (dy / A.Ec + A.m_RadLa) * 180. / Math.PI;
+ return new MyLatLng(bjd, bwd);
+ }
+
+ /**
+ * 获取AB连线与正北方向的角度
+ *
+ * @param A A点的经纬度
+ * @param B B点的经纬度
+ * @return AB连线与正北方向的角度(0~360)
+ */
+ private static double getAngle(MyLatLng A, MyLatLng B) {
+ double dx = (B.m_RadLo - A.m_RadLo) * A.Ed;
+ double dy = (B.m_RadLa - A.m_RadLa) * A.Ec;
+ double angle = 0.0;
+ angle = Math.atan(Math.abs(dx / dy)) * 180. / Math.PI;
+ double dLo = B.m_Longitude - A.m_Longitude;
+ double dLa = B.m_Latitude - A.m_Latitude;
+ if (dLo > 0 && dLa <= 0) {
+ angle = (90. - angle) + 90;
+ } else if (dLo <= 0 && dLa < 0) {
+ angle = angle + 180.;
+ } else if (dLo < 0 && dLa >= 0) {
+ angle = (90. - angle) + 270;
+ }
+ return angle;
+ }
+
+ private static final double EARTH_RADIUS = 6378.137; // 6378.137为地球半径(单位:千米)
+
+ /**
+ * 根据经纬度,计算两点间的距离
+ *
+ * @param longitude1 第一个点的经度
+ * @param latitude1 第一个点的纬度
+ * @param longitude2 第二个点的经度
+ * @param latitude2 第二个点的纬度
+ * @return 返回距离 单位千米
+ */
+ private 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;
+ //System.out.println("距离"+s);
+ return s * 1000;
+ }
+
+}
diff --git a/ard-work/src/main/resources/mapper/alarm/ArdAlarmTubeMapper.xml b/ard-work/src/main/resources/mapper/alarm/ArdAlarmTubeMapper.xml
index 14e49fe..07e5183 100644
--- a/ard-work/src/main/resources/mapper/alarm/ArdAlarmTubeMapper.xml
+++ b/ard-work/src/main/resources/mapper/alarm/ArdAlarmTubeMapper.xml
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.alarm.tubeAlarm.mapper.ArdAlarmTubeMapper">
-
+
<resultMap type="ArdAlarmTube" id="ArdAlarmTubeResult">
<result property="id" column="id" />
<result property="host" column="host" />
@@ -18,18 +18,21 @@
<result property="alarmTime" column="alarm_time" />
<result property="watcher" column="watcher" />
<result property="createTime" column="create_time" />
+ <result property="longitude" column="longitude" />
+ <result property="latitude" column="latitude" />
+ <result property="altitude" column="altitude" />
<result property="viewTime" column="view_time" />
</resultMap>
<sql id="selectArdAlarmTubeVo">
- select id, host, tube_id, tube_name, tube_type, pipe_diameter, color, position, type, alarm_type, alarm_time, watcher, create_time, view_time from ard_alarm_tube
+ select id, host, tube_id, tube_name, tube_type, pipe_diameter, color, position, type, alarm_type, alarm_time, watcher, create_time, longitude, latitude, altitude, view_time from ard_alarm_tube
</sql>
<select id="selectArdAlarmTubeList" parameterType="ArdAlarmTube" resultMap="ArdAlarmTubeResult">
<include refid="selectArdAlarmTubeVo"/>
- <where>
+ <where>
<if test="host != null and host != ''"> and host = #{host}</if>
- <if test="tubeId != null "> and tube_id = #{tubeId}</if>
+ <if test="tubeId != null and tubeId != ''"> and tube_id = #{tubeId}</if>
<if test="tubeName != null and tubeName != ''"> and tube_name like '%'||#{tubeName}||'%'</if>
<if test="tubeType != null and tubeType != ''"> and tube_type = #{tubeType}</if>
<if test="pipeDiameter != null and pipeDiameter != ''"> and pipe_diameter = #{pipeDiameter}</if>
@@ -39,15 +42,18 @@
<if test="alarmType != null and alarmType != ''"> and alarm_type = #{alarmType}</if>
<if test="alarmTime != null "> and alarm_time = #{alarmTime}</if>
<if test="watcher != null and watcher != ''"> and watcher = #{watcher}</if>
+ <if test="longitude != null and longitude != ''"> and longitude = #{longitude}</if>
+ <if test="latitude != null and latitude != ''"> and latitude = #{latitude}</if>
+ <if test="altitude != null and altitude != ''"> and altitude = #{altitude}</if>
<if test="viewTime != null "> and view_time = #{viewTime}</if>
</where>
</select>
-
+
<select id="selectArdAlarmTubeById" parameterType="String" resultMap="ArdAlarmTubeResult">
<include refid="selectArdAlarmTubeVo"/>
where id = #{id}
</select>
-
+
<insert id="insertArdAlarmTube" parameterType="ArdAlarmTube">
insert into ard_alarm_tube
<trim prefix="(" suffix=")" suffixOverrides=",">
@@ -64,8 +70,11 @@
<if test="alarmTime != null">alarm_time,</if>
<if test="watcher != null">watcher,</if>
<if test="createTime != null">create_time,</if>
+ <if test="longitude != null">longitude,</if>
+ <if test="latitude != null">latitude,</if>
+ <if test="altitude != null">altitude,</if>
<if test="viewTime != null">view_time,</if>
- </trim>
+ </trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="host != null">#{host},</if>
@@ -80,8 +89,11 @@
<if test="alarmTime != null">#{alarmTime},</if>
<if test="watcher != null">#{watcher},</if>
<if test="createTime != null">#{createTime},</if>
+ <if test="longitude != null">#{longitude},</if>
+ <if test="latitude != null">#{latitude},</if>
+ <if test="altitude != null">#{altitude},</if>
<if test="viewTime != null">#{viewTime},</if>
- </trim>
+ </trim>
</insert>
<update id="updateArdAlarmTube" parameterType="ArdAlarmTube">
@@ -99,6 +111,9 @@
<if test="alarmTime != null">alarm_time = #{alarmTime},</if>
<if test="watcher != null">watcher = #{watcher},</if>
<if test="createTime != null">create_time = #{createTime},</if>
+ <if test="longitude != null">longitude = #{longitude},</if>
+ <if test="latitude != null">latitude = #{latitude},</if>
+ <if test="altitude != null">altitude = #{altitude},</if>
<if test="viewTime != null">view_time = #{viewTime},</if>
</trim>
where id = #{id}
@@ -109,7 +124,7 @@
</delete>
<delete id="deleteArdAlarmTubeByIds" parameterType="String">
- delete from ard_alarm_tube where id in
+ delete from ard_alarm_tube where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml
index b069583..b54f333 100644
--- a/ruoyi-admin/src/main/resources/application.yml
+++ b/ruoyi-admin/src/main/resources/application.yml
@@ -36,6 +36,7 @@
# 日志配置
logging:
level:
+ com.ruoyi.utils.tube: debug
com.ruoyi.inspect: info
org.springframework: warn
--
Gitblit v1.9.3