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; } } 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(); } } ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/LeakPointCalculation.java
文件已删除 ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/Point3D.java
文件已删除 ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/testService.java
文件已删除 ard-work/src/main/java/com/ruoyi/utils/tube/GeoPoint.java
文件名从 ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/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; } ard-work/src/main/java/com/ruoyi/utils/tube/MyLatLng.java
文件名从 ard-work/src/main/java/com/ruoyi/alarm/tubeAlarm/service/impl/MyLatLng.java 修改 @@ -1,4 +1,4 @@ package com.ruoyi.alarm.tubeAlarm.service.impl; package com.ruoyi.utils.tube; import lombok.Data; 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; } } 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> 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