From 2ce6aa8eee18b7436cfe144614074494cb11b551 Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期一, 17 二月 2025 16:36:20 +0800 Subject: [PATCH] 巡检时计算巡检距离 --- pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/inspect/InspectSv.java | 20 +++++ pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoOp/OpeInspectMapper.java | 11 ++ pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/inspect/InspectCtrl.java | 59 ++++++++++++++ pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoOp/OpeTrackMapper.java | 8 ++ pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voOp/VoTrackPoint.java | 25 ++++++ pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoOp/OpeInspect.java | 25 +++-- pipIrr-platform/pipIrr-global/src/main/resources/mapper/OpeTrackMapper.xml | 5 + pipIrr-platform/pipIrr-global/src/main/resources/mapper/OpeInspectMapper.xml | 44 ++++++++--- pipIrr-platform/pipIrr-global/src/main/resources/application-global.yml | 2 9 files changed, 175 insertions(+), 24 deletions(-) diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoOp/OpeInspectMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoOp/OpeInspectMapper.java index 3e5c041..e12d201 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoOp/OpeInspectMapper.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoOp/OpeInspectMapper.java @@ -4,6 +4,7 @@ import com.dy.pipIrrGlobal.pojoOp.OpeInspect; import com.dy.pipIrrGlobal.voOp.VoInspect; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; import java.util.Map; @@ -11,7 +12,7 @@ /** * @author ZhuBaoMin * @date 2024-09-24 10:07 - * @LastEditTime 2024-09-24 10:07 + * @LastEditTime 2025-02-17 15:11 * @Description */ @@ -42,4 +43,12 @@ * @return */ List<VoInspect> getInspects(Map<String, Object> params); + + /** + * 鏇存柊鎸囧畾宸℃璁板綍鐨勫贰妫�璺濈 + * @param inspectId + * @param distance + * @return + */ + int updateInspectDistance(@Param("inspectId") Long inspectId, @Param("distance")Double distance ); } \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoOp/OpeTrackMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoOp/OpeTrackMapper.java index c1e7004..03494f7 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoOp/OpeTrackMapper.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoOp/OpeTrackMapper.java @@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.dy.pipIrrGlobal.pojoOp.OpeTrack; +import com.dy.pipIrrGlobal.voOp.VoTrackPoint; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -40,4 +41,11 @@ * @return */ List<OpeTrack> selectByInspectId(Long inspectId); + + /** + * 鑾峰彇鎸囧畾宸℃ID涓嬬殑鍏ㄩ儴杞ㄨ抗鐐� + * @param inspectId + * @return + */ + List<VoTrackPoint> getTrackPointsById(Long inspectId); } \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoOp/OpeInspect.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoOp/OpeInspect.java index 85b2b9c..aa99102 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoOp/OpeInspect.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoOp/OpeInspect.java @@ -15,8 +15,8 @@ /** * @author ZhuBaoMin * @date 2024-09-24 10:07 - * @LastEditTime 2024-09-24 10:07 - * @Description + * @LastEditTime 2025-02-17 15:14 + * @Description 娣诲姞宸℃璺濈瀛楁 */ /** * 宸℃琛� @@ -32,28 +32,33 @@ public static final long serialVersionUID = 202409241013001L; /** - * 涓婚敭 - */ + * 涓婚敭 + */ @JSONField(serializeUsing= ObjectWriterImplToString.class) @TableId(type = IdType.INPUT) private Long id; /** - * 宸℃鍛業D - */ + * 宸℃鍛業D + */ @JSONField(serializeUsing= ObjectWriterImplToString.class) @NotNull(message = "宸℃鍛業D涓嶈兘涓虹┖") private Long inspectorId; /** - * 寮�濮嬪贰妫�鏃堕棿 - */ + * 寮�濮嬪贰妫�鏃堕棿 + */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date startTime; /** - * 缁撴潫宸℃鏃堕棿 - */ + * 缁撴潫宸℃鏃堕棿 + */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date stopTime; + + /** + * 宸℃璺濈 + */ + private Double inspectDistance; } \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voOp/VoTrackPoint.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voOp/VoTrackPoint.java new file mode 100644 index 0000000..4a618db --- /dev/null +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voOp/VoTrackPoint.java @@ -0,0 +1,25 @@ +package com.dy.pipIrrGlobal.voOp; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author ZhuBaoMin + * @date 2025-02-17 15:23 + * @LastEditTime 2025-02-17 15:23 + * @Description 宸℃鐐瑰璞★紝璁$畻宸℃璺濈浣跨敤 + */ + +@Data +public class VoTrackPoint { + /** + * 缁忓害 + */ + private BigDecimal lng; + + /** + * 绾害 + */ + private BigDecimal lat; +} diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/application-global.yml b/pipIrr-platform/pipIrr-global/src/main/resources/application-global.yml index 0473a51..42b6d29 100644 --- a/pipIrr-platform/pipIrr-global/src/main/resources/application-global.yml +++ b/pipIrr-platform/pipIrr-global/src/main/resources/application-global.yml @@ -78,7 +78,7 @@ pipIrr: global: - dev: false #鏄惁寮�鍙戦樁娈碉紝true鎴杅alse + dev: true #鏄惁寮�鍙戦樁娈碉紝true鎴杅alse dsName: ym #寮�鍙戦樁娈碉紝璁剧疆涓存椂鐨勬暟鎹簱鍚嶇О nginx: root: E:/apps/pipIrr/nginx-1.27.0 diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/OpeInspectMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/OpeInspectMapper.xml index 44bb383..088784e 100644 --- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/OpeInspectMapper.xml +++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/OpeInspectMapper.xml @@ -8,10 +8,11 @@ <result column="inspector_id" jdbcType="BIGINT" property="inspectorId" /> <result column="start_time" jdbcType="TIMESTAMP" property="startTime" /> <result column="stop_time" jdbcType="TIMESTAMP" property="stopTime" /> + <result column="inspect_distance" jdbcType="FLOAT" property="inspectDistance" /> </resultMap> <sql id="Base_Column_List"> <!--@mbg.generated--> - id, inspector_id, start_time, stop_time + id, inspector_id, start_time, stop_time, inspect_distance </sql> <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> <!--@mbg.generated--> @@ -28,9 +29,9 @@ <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoOp.OpeInspect"> <!--@mbg.generated--> insert into ope_inspect (id, inspector_id, start_time, - stop_time) + stop_time, inspect_distance) values (#{id,jdbcType=BIGINT}, #{inspectorId,jdbcType=BIGINT}, #{startTime,jdbcType=TIMESTAMP}, - #{stopTime,jdbcType=TIMESTAMP}) + #{stopTime,jdbcType=TIMESTAMP}, #{inspectDistance,jdbcType=FLOAT}) </insert> <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoOp.OpeInspect"> <!--@mbg.generated--> @@ -48,6 +49,9 @@ <if test="stopTime != null"> stop_time, </if> + <if test="inspectDistance != null"> + inspect_distance, + </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null"> @@ -61,6 +65,9 @@ </if> <if test="stopTime != null"> #{stopTime,jdbcType=TIMESTAMP}, + </if> + <if test="inspectDistance != null"> + #{inspectDistance,jdbcType=FLOAT}, </if> </trim> </insert> @@ -77,6 +84,9 @@ <if test="stopTime != null"> stop_time = #{stopTime,jdbcType=TIMESTAMP}, </if> + <if test="inspectDistance != null"> + inspect_distance = #{inspectDistance,jdbcType=FLOAT}, + </if> </set> where id = #{id,jdbcType=BIGINT} </update> @@ -85,10 +95,12 @@ update ope_inspect set inspector_id = #{inspectorId,jdbcType=BIGINT}, start_time = #{startTime,jdbcType=TIMESTAMP}, - stop_time = #{stopTime,jdbcType=TIMESTAMP} + stop_time = #{stopTime,jdbcType=TIMESTAMP}, + inspect_distance = #{inspectDistance,jdbcType=FLOAT} where id = #{id,jdbcType=BIGINT} </update> -<!-- 鏌ヨ鎬绘暟 --> + + <!-- 鏌ヨ鎬绘暟 --> <select id="getInspectsCount" resultType="java.lang.Long"> SELECT count(*) @@ -109,15 +121,16 @@ AND oi.start_time BETWEEN #{timeStart} AND #{timeStop} </if> </where> - </select> -<!-- 鏌ヨ鍒楄〃 --> + </select> + + <!-- 鏌ヨ鍒楄〃 --> <select id="getInspects" resultType="com.dy.pipIrrGlobal.voOp.VoInspect"> SELECT - oi.inspector_id AS inspectorId, - ba_user.`name` AS inspectorName, - oi.id AS inspectId, - oi.start_time AS startTime, - oi.stop_time AS stopTime + oi.inspector_id AS inspectorId, + ba_user.`name` AS inspectorName, + oi.id AS inspectId, + oi.start_time AS startTime, + oi.stop_time AS stopTime FROM `ope_inspect` oi INNER JOIN `ba_user` ON oi.inspector_id = ba_user.id <where> @@ -141,4 +154,11 @@ </if> </trim> </select> + + <!--鏇存柊鎸囧畾宸℃璁板綍鐨勫贰妫�璺濈--> + <update id="updateInspectDistance"> + UPDATE ope_inspect + SET inspect_distance = #{distance} + WHERE id = #{inspectId} + </update> </mapper> \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/OpeTrackMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/OpeTrackMapper.xml index 6231a5d..977af0a 100644 --- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/OpeTrackMapper.xml +++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/OpeTrackMapper.xml @@ -119,4 +119,9 @@ locate_time AS locateTime FROM ope_track WHERE inspect_id = #{inspectId} </select> + + <!--鑾峰彇鎸囧畾宸℃ID涓嬬殑鍏ㄩ儴杞ㄨ抗鐐�--> + <select id="getTrackPointsById" resultType="com.dy.pipIrrGlobal.voOp.VoTrackPoint"> + SELECT lng, lat FROM ope_track WHERE inspect_id = #{inspectId} + </select> </mapper> \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/inspect/InspectCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/inspect/InspectCtrl.java index 2e97c7f..6279278 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/inspect/InspectCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/inspect/InspectCtrl.java @@ -12,6 +12,7 @@ import com.dy.pipIrrGlobal.pojoOp.OpeInspect; import com.dy.pipIrrGlobal.pojoOp.OpeTrack; import com.dy.pipIrrGlobal.voOp.VoInspect; +import com.dy.pipIrrGlobal.voOp.VoTrackPoint; import jakarta.validation.Valid; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -23,6 +24,7 @@ import java.util.Date; import java.util.List; import java.util.Objects; +import java.util.Optional; /** * @author ZhuBaoMin @@ -39,6 +41,9 @@ private InspectSv inspectSv; private final IDLongGenerator idLongGenerator; + + // 鍦扮悆鍗婂緞锛屽崟浣嶏細鍗冪背 + private static final double EARTH_RADIUS = 6371.0; public InspectCtrl(IDLongGenerator idLongGenerator) { this.idLongGenerator = idLongGenerator; @@ -104,6 +109,11 @@ if(rec == null || rec == 0) { return BaseResponseUtils.buildErrorMsg("宸℃杞ㄨ抗娣诲姞澶辫触"); } + + Double distance = Optional.ofNullable(getInspectDistance(inspectId)).orElse(0.0); + if(distance > 0) { + inspectSv.updateInspectDistance(inspectId, distance); + } }else { // 璇ュ贰妫�宸蹭笂浼犺繃璁板綍锛岀画浼� if(stopTime != null) { @@ -122,6 +132,10 @@ if(rec == null || rec == 0) { return BaseResponseUtils.buildErrorMsg("宸℃杞ㄨ抗娣诲姞澶辫触"); } + } + Double distance = Optional.ofNullable(getInspectDistance(inspectId)).orElse(0.0); + if(distance > 0) { + inspectSv.updateInspectDistance(inspectId, distance); } } } @@ -150,4 +164,49 @@ return BaseResponseUtils.buildException(e.getMessage()); } } + + /** + * 鏍规嵁宸℃ID鑾峰彇杞ㄨ抗鎬昏窛绂� + * @param inspectId + * @return + */ + public double getInspectDistance(Long inspectId) { + List<VoTrackPoint> points = inspectSv.getTrackPointsById(inspectId); + if(points == null || points.size() == 0) { + return 0.0; + } + + double totalDistance = calculateTotalDistance(points); + return totalDistance; + } + + // 璁$畻杞ㄨ抗鐨勬�昏窛绂� + public static double calculateTotalDistance(List<VoTrackPoint> points) { + double totalDistance = 0.0; + + for (int i = 0; i < points.size() - 1; i++) { + VoTrackPoint currentPoint = points.get(i); + VoTrackPoint nextPoint = points.get(i + 1); + + double distance = haversine( currentPoint.getLat().doubleValue(), currentPoint.getLng().doubleValue(), nextPoint.getLat().doubleValue(), nextPoint.getLng().doubleValue()); + + totalDistance += distance; + } + + return totalDistance; + } + + // Haversine鍏紡璁$畻涓や釜缁忕含搴︾偣涔嬮棿鐨勮窛绂� + public static double haversine(double lat1, double lon1, double lat2, double lon2) { + double dLat = Math.toRadians(lat2 - lat1); + double dLon = Math.toRadians(lon2 - lon1); + + double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * + Math.sin(dLon / 2) * Math.sin(dLon / 2); + + double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + + return EARTH_RADIUS * c; + } } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/inspect/InspectSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/inspect/InspectSv.java index c857afe..3ced131 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/inspect/InspectSv.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/inspect/InspectSv.java @@ -7,6 +7,7 @@ import com.dy.pipIrrGlobal.pojoOp.OpeInspect; import com.dy.pipIrrGlobal.pojoOp.OpeTrack; import com.dy.pipIrrGlobal.voOp.VoInspect; +import com.dy.pipIrrGlobal.voOp.VoTrackPoint; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.common.utils.PojoUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -99,4 +100,23 @@ rsVo.obj = inspects; return rsVo; } + + /** + * 鑾峰彇鎸囧畾宸℃ID涓嬬殑鍏ㄩ儴杞ㄨ抗鐐� + * @param inspectId + * @return + */ + public List<VoTrackPoint> getTrackPointsById(Long inspectId) { + return opeTrackMapper.getTrackPointsById(inspectId); + } + + /** + * 鏇存柊鎸囧畾宸℃璁板綍鐨勫贰妫�璺濈 + * @param inspectId + * @param distance + * @return + */ + public int updateInspectDistance(Long inspectId, double distance ) { + return opeInspectMapper.updateInspectDistance(inspectId, distance); + } } -- Gitblit v1.8.0