浏览代码

* 桩孔实时指标更新逻辑

chen.cheng 4 月之前
父节点
当前提交
8c78c29908
共有 15 个文件被更改,包括 173 次插入54 次删除
  1. 4 2
      bd-park/park-backend/park-collect/src/main/java/com/huashe/park/collect/event/MachineRealtimeEventListener.java
  2. 67 0
      bd-park/park-backend/park-collect/src/main/java/com/huashe/park/collect/schedule/SyncMachineStatJob.java
  3. 0 32
      bd-park/park-backend/park-collect/src/main/java/com/huashe/park/collect/schedule/SyncSignalCtlPlanStatJob.java
  4. 3 6
      bd-park/park-backend/park-collect/src/main/resources/application-schedule.yml
  5. 1 4
      bd-park/park-backend/park-collect/src/main/resources/application.yml
  6. 1 1
      bd-park/park-backend/park-collect/src/main/resources/mybatis/mybatis-config.xml
  7. 24 0
      bd-park/park-backend/park-common/src/main/java/com/huashe/park/common/DateTimeUtil.java
  8. 15 1
      bd-park/park-backend/park-common/src/main/java/com/huashe/park/common/job/schedule/TriggerTaskSupport.java
  9. 6 5
      bd-park/park-backend/park-core/src/main/java/com/huashe/park/core/mapper/PileHoleIndexRealtimeMapper.java
  10. 2 0
      bd-park/park-backend/park-core/src/main/java/com/huashe/park/core/service/IPileHoleIndexRealtimeService.java
  11. 9 1
      bd-park/park-backend/park-core/src/main/java/com/huashe/park/core/service/impl/PileHoleIndexRealtimeServiceImpl.java
  12. 2 2
      bd-park/park-backend/park-core/src/main/resources/mapper/cons/MachineProcessResultMapper.xml
  13. 8 0
      bd-park/park-backend/park-core/src/main/resources/mapper/cons/PileHoleIndexRealtimeMapper.xml
  14. 11 0
      bd-park/park-backend/park-core/src/main/resources/mapper/cons/PileMachineInfoMapper.xml
  15. 20 0
      bd-park/park-backend/park-domain/src/main/java/com/huashe/park/domain/entity/PileMachineInfo.java

+ 4 - 2
bd-park/park-backend/park-collect/src/main/java/com/huashe/park/collect/event/MachineRealtimeEventListener.java

@@ -44,9 +44,9 @@ public class MachineRealtimeEventListener {
         }
         PileHoleIndexRealtime pileHoleIndexRealtime = new PileHoleIndexRealtime();
         pileHoleIndexRealtime.setHoleId(consPileHoleInfo.getId());
+        pileHoleIndexRealtime.setMachineId(pileMachineInfo.getId());
         pileHoleIndexRealtime.setHoleByteKey(consPileHoleInfo.getByteId());
         pileHoleIndexRealtime.setMachineByteKey(pileMachineInfo.getByteId());
-        pileHoleIndexRealtime.setMachineId(pileMachineInfo.getId());
 
         pileHoleIndexRealtime.setCurrent(event.getMessage().getCurrent());
         pileHoleIndexRealtime.setDepth(event.getMessage().getPileLength());
@@ -57,13 +57,15 @@ public class MachineRealtimeEventListener {
         pileHoleIndexRealtime.setStatus(CONS_STATUS_02.getCode());
         int cnt = pileHoleIndexRealtimeService.updatePileHoleIndexRealtimeByHoleIdAndMachineId(pileHoleIndexRealtime);
         if (!(cnt > 0)) {
-            String dateFromMills = DateTimeUtil.getDateFromMills(event.getMessage().getStartTime());
+            String dateFromMills = DateTimeUtil.getDateFromMills(event.getMessage().getDataTime());
             pileHoleIndexRealtime.setStartTime(DateTimeUtil.parseDate(dateFromMills));
             pileHoleIndexRealtimeService.insertPileHoleIndexRealtime(pileHoleIndexRealtime);
         }
         pileMachineInfoService.updatePileMachineInfo(new PileMachineInfo() {
             {
                 setId(pileMachineInfo.getId());
+                setLat(consPileHoleInfo.getLat());
+                setLng(consPileHoleInfo.getLng());
                 setStatus(MachineStatus.MACHINE_STATUS_00.getCode());
             }
         });

+ 67 - 0
bd-park/park-backend/park-collect/src/main/java/com/huashe/park/collect/schedule/SyncMachineStatJob.java

@@ -0,0 +1,67 @@
+package com.huashe.park.collect.schedule;
+
+import java.util.List;
+
+import com.huashe.park.common.ByteArrayUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.scheduling.support.CronTrigger;
+import org.springframework.stereotype.Component;
+
+import com.huashe.park.common.consts.enums.MachineStatus;
+import com.huashe.park.common.job.schedule.TriggerTaskSupport;
+import com.huashe.park.core.service.IPileHoleIndexRealtimeService;
+import com.huashe.park.core.service.IPileMachineInfoService;
+import com.huashe.park.domain.entity.PileMachineInfo;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@Component
+@ConditionalOnProperty(prefix = "huashe.job.sync-machine-status", name = "enabled", havingValue = "true")
+public class SyncMachineStatJob extends TriggerTaskSupport {
+
+    @Value("${huashe.job.sync-machine-status.desc}")
+    private String jobDesc;
+
+    @Override
+    @Value("${huashe.job.sync-machine-status.cron}")
+    public CronTrigger setTrigger(String cron) {
+        super.trigger = new CronTrigger(cron);
+        return super.trigger;
+    }
+
+    @Autowired
+    private IPileMachineInfoService machineInfoService;
+
+    @Autowired
+    private IPileHoleIndexRealtimeService pileHoleIndexRealtimeService;
+
+    @Override
+    public String jobName() {
+        return jobDesc;
+    }
+
+    @Override
+    public void scheduledJob() {
+        List<PileMachineInfo> pileMachineInfos = machineInfoService.selectPileMachineInfoList(new PileMachineInfo() {
+            {
+                setStatus(MachineStatus.MACHINE_STATUS_00.getCode());
+            }
+        });
+        for (PileMachineInfo pileMachineInfo : pileMachineInfos) {
+            try {
+                int constructingPileHoleCnt = pileHoleIndexRealtimeService
+                    .cntMachineConstructingPileHole(pileMachineInfo.getId());
+                if (constructingPileHoleCnt < 1) {
+                    pileMachineInfo.setStatus(MachineStatus.MACHINE_STATUS_01.getCode());
+                    machineInfoService.updatePileMachineInfo(pileMachineInfo);
+                }
+            }
+            catch (Exception e) {
+                log.error("同步状态失败", e);
+            }
+        }
+    }
+}

+ 0 - 32
bd-park/park-backend/park-collect/src/main/java/com/huashe/park/collect/schedule/SyncSignalCtlPlanStatJob.java

@@ -1,32 +0,0 @@
-package com.huashe.park.collect.schedule;
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.scheduling.support.CronTrigger;
-import org.springframework.stereotype.Component;
-
-import com.huashe.park.common.job.schedule.TriggerTaskSupport;
-
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-@Component
-@ConditionalOnProperty(prefix = "huashe.job.sync-signal-ctl-stat-job", name = "enabled", havingValue = "true")
-public class SyncSignalCtlPlanStatJob extends TriggerTaskSupport {
-
-    @Value("${huashe.job.sync-signal-ctl-stat-job.desc}")
-    private String jobDesc;
-
-    @Override
-    @Value("${huashe.job.sync-signal-ctl-stat-job.cron}")
-    public CronTrigger setTrigger(String cron) {
-        super.trigger = new CronTrigger(cron);
-        return super.trigger;
-    }
-
-    @Override
-    public void scheduledJob() {
-        log.info("{} 启动", jobDesc);
-    }
-
-}

+ 3 - 6
bd-park/park-backend/park-collect/src/main/resources/application-schedule.yml

@@ -1,10 +1,7 @@
 huashe:
   job:
-    sync-:
+    sync-machine-status:
       enabled: true
-      cron: 0/10 * * * * ?
+      cron: 0 0/2 * * * ?
       batchSize: 50
-      desc: 信控状态同步job
-      cfg:
-        timeout-threshold: 5
-        thread-num: 3
+      desc: 施工器械状态job

+ 1 - 4
bd-park/park-backend/park-collect/src/main/resources/application.yml

@@ -112,7 +112,4 @@ id:
 logging:
   level:
     com.ruoyi: debug
-    com.huashe: debug
-date:
-  time:
-    zone: GMT+8:00
+    com.huashe: debug

+ 1 - 1
bd-park/park-backend/park-collect/src/main/resources/mybatis/mybatis-config.xml

@@ -10,7 +10,7 @@
         <!-- 允许JDBC 支持自动生成主键 -->
         <setting name="useGeneratedKeys" value="true"/>
         <!-- 配置默认的执行器.SIMPLE就是普通执行器;REUSE执行器会重用预处理语句(prepared statements);BATCH执行器将重用语句并执行批量更新 -->
-        <setting name="defaultExecutorType" value="BATCH"/>
+        <setting name="defaultExecutorType" value="SIMPLE"/>
         <!-- 指定 MyBatis 所用日志的具体实现 -->
         <setting name="logImpl" value="SLF4J"/>
         <!-- 使用驼峰命名法转换字段 -->

+ 24 - 0
bd-park/park-backend/park-common/src/main/java/com/huashe/park/common/DateTimeUtil.java

@@ -322,6 +322,30 @@ public class DateTimeUtil {
     }
 
     /**
+     * Minus minute string.
+     *
+     * @param minutes the minute num
+     * @param formatRegx the format regx
+     * @return the string
+     */
+    public static String minusMinute(Long minutes, String formatRegx) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatRegx);
+        LocalDateTime now = LocalDateTime.now();
+        now = now.minusMinutes(minutes);
+        return now.format(formatter);
+    }
+
+    /**
+     * Minus minute string.
+     *
+     * @param minutes the minutes
+     * @return the string
+     */
+    public static String minusMinute(Long minutes) {
+        return minusMinute(minutes, DateFormatter.yyyyMMddHHmmss);
+    }
+
+    /**
      * Days of range list.
      *
      * @param startDate the start date

+ 15 - 1
bd-park/park-backend/park-common/src/main/java/com/huashe/park/common/job/schedule/TriggerTaskSupport.java

@@ -1,8 +1,11 @@
 package com.huashe.park.common.job.schedule;
 
+import org.slf4j.Logger;
 import org.springframework.scheduling.support.CronTrigger;
 
 public abstract class TriggerTaskSupport implements ITriggerTask {
+    private static final Logger log = org.slf4j.LoggerFactory.getLogger(TriggerTaskSupport.class);
+
     public CronTrigger trigger;
 
     /**
@@ -31,6 +34,8 @@ public abstract class TriggerTaskSupport implements ITriggerTask {
         return this.getClass().getSimpleName().toLowerCase();
     }
 
+    public abstract String jobName();
+
     /**
      * 获取 run 方法
      *
@@ -38,7 +43,16 @@ public abstract class TriggerTaskSupport implements ITriggerTask {
      */
     @Override
     public Runnable getTask() {
-        return this::scheduledJob;
+        return () -> {
+            try {
+                log.info(">>>>>>>>>>>>>{}启动<<<<<<<<<<<<<<<<< ", jobName());
+                scheduledJob();
+                log.info(">>>>>>>>>>>>>{}结束<<<<<<<<<<<<<<<<< ", jobName());
+            }
+            catch (Exception e) {
+                log.info("定时任务{}执行异常", jobName(), e);
+            }
+        };
     }
 
     @Override

+ 6 - 5
bd-park/park-backend/park-core/src/main/java/com/huashe/park/core/mapper/PileHoleIndexRealtimeMapper.java

@@ -1,17 +1,17 @@
 package com.huashe.park.core.mapper;
 
-import com.huashe.park.domain.entity.PileHoleIndexRealtime;
-
 import java.util.List;
 
+import com.huashe.park.domain.entity.PileHoleIndexRealtime;
+import org.apache.ibatis.annotations.Param;
+
 /**
  * 桩点最新指标Mapper接口
  * 
  * @author ruoyi
  * @date 2025-02-28
  */
-public interface PileHoleIndexRealtimeMapper 
-{
+public interface PileHoleIndexRealtimeMapper {
     /**
      * 查询桩点最新指标
      * 
@@ -44,7 +44,6 @@ public interface PileHoleIndexRealtimeMapper
      */
     public int updatePileHoleIndexRealtime(PileHoleIndexRealtime pileHoleIndexRealtime);
 
-
     public int updatePileHoleIndexRealtimeByHoleIdAndMachineId(PileHoleIndexRealtime pileHoleIndexRealtime);
 
     /**
@@ -62,4 +61,6 @@ public interface PileHoleIndexRealtimeMapper
      * @return 结果
      */
     public int deletePileHoleIndexRealtimeByIds(Long[] ids);
+
+    public int selectMachineConstingPileHole(@Param("machineId") Long machineId, @Param("startTime") String startTime);
 }

+ 2 - 0
bd-park/park-backend/park-core/src/main/java/com/huashe/park/core/service/IPileHoleIndexRealtimeService.java

@@ -60,4 +60,6 @@ public interface IPileHoleIndexRealtimeService {
      * @return 结果
      */
     public int deletePileHoleIndexRealtimeById(Long id);
+
+    public int cntMachineConstructingPileHole(Long machineId);
 }

+ 9 - 1
bd-park/park-backend/park-core/src/main/java/com/huashe/park/core/service/impl/PileHoleIndexRealtimeServiceImpl.java

@@ -5,6 +5,7 @@ import java.util.List;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import com.huashe.park.common.DateTimeUtil;
 import com.huashe.park.core.mapper.PileHoleIndexRealtimeMapper;
 import com.huashe.park.core.service.IPileHoleIndexRealtimeService;
 import com.huashe.park.domain.entity.PileHoleIndexRealtime;
@@ -65,7 +66,7 @@ public class PileHoleIndexRealtimeServiceImpl implements IPileHoleIndexRealtimeS
     }
 
     @Override
-    public int updatePileHoleIndexRealtimeByHoleIdAndMachineId(PileHoleIndexRealtime pileHoleIndexRealtime){
+    public int updatePileHoleIndexRealtimeByHoleIdAndMachineId(PileHoleIndexRealtime pileHoleIndexRealtime) {
         return pileHoleIndexRealtimeMapper.updatePileHoleIndexRealtimeByHoleIdAndMachineId(pileHoleIndexRealtime);
     }
 
@@ -90,4 +91,11 @@ public class PileHoleIndexRealtimeServiceImpl implements IPileHoleIndexRealtimeS
     public int deletePileHoleIndexRealtimeById(Long id) {
         return pileHoleIndexRealtimeMapper.deletePileHoleIndexRealtimeById(id);
     }
+
+    @Override
+    public int cntMachineConstructingPileHole(Long machineId) {
+        String date = DateTimeUtil.minusMinute(60L);
+        return pileHoleIndexRealtimeMapper.selectMachineConstingPileHole(machineId, date);
+    }
+
 }

+ 2 - 2
bd-park/park-backend/park-core/src/main/resources/mapper/cons/MachineProcessResultMapper.xml

@@ -330,8 +330,8 @@
             <if test="createTime != null">now(),</if>
             <if test="sendStartTime != null">#{sendStartTime},</if>
             <if test="sendEndTime != null">#{sendEndTime},</if>
-            <if test="pullingStartTime">#{pullingStartTime},</if>
-            <if test="pullingEndTime">#{pullingEndTime},</if>
+            <if test="pullingStartTime != null">#{pullingStartTime},</if>
+            <if test="pullingEndTime!= null">#{pullingEndTime},</if>
         </trim>
         ON DUPLICATE KEY UPDATE
         <trim suffixOverrides=",">

+ 8 - 0
bd-park/park-backend/park-core/src/main/resources/mapper/cons/PileHoleIndexRealtimeMapper.xml

@@ -164,4 +164,12 @@
             #{id}
         </foreach>
     </delete>
+
+
+    <select id="selectMachineConstingPileHole" resultType="Integer">
+        select count(1)
+        from cons_pile_hole_index_realtime
+        where machine_id = #{machineId}
+          and update_time > #{startTime}
+    </select>
 </mapper>

+ 11 - 0
bd-park/park-backend/park-core/src/main/resources/mapper/cons/PileMachineInfoMapper.xml

@@ -20,6 +20,8 @@
         <result property="serverUserName" column="server_user_name"/>
         <result property="serverPassword" column="server_password"/>
         <result property="status" column="status"/>
+        <result property="lng" column="lng"/>
+        <result property="lat" column="lat"/>
         <result property="updateTime" column="update_time"/>
         <result property="createTime" column="create_time"/>
         <result property="createBy" column="create_by"/>
@@ -41,6 +43,8 @@
                server_user_name,
                server_password,
                status,
+               lng,
+               lat,
                update_time,
                create_time,
                create_by,
@@ -54,6 +58,7 @@
             <if test="machineNum != null  and machineNum != ''">and machine_num = #{machineNum}</if>
             <if test="equipment != null  and equipment != ''">and equipment = #{equipment}</if>
             <if test="no != null  and no != ''">and no = #{no}</if>
+            <if test="status != null  and status != ''">and status = #{status}</if>
         </where>
     </select>
 
@@ -84,6 +89,8 @@
             <if test="serverUserName != null">server_user_name,</if>
             <if test="serverPassword != null">server_password,</if>
             <if test="status != null">status,</if>
+            <if test="lng != null">lng,</if>
+            <if test="lat != null">lat,</if>
             <if test="updateTime != null">update_time,</if>
             <if test="createTime != null">create_time,</if>
             <if test="createBy != null">create_by,</if>
@@ -104,6 +111,8 @@
             <if test="serverUserName != null">#{serverUserName},</if>
             <if test="serverPassword != null">#{serverPassword},</if>
             <if test="status != null">#{status},</if>
+            <if test="lng != null">#{lng},</if>
+            <if test="lat != null">#{lat},</if>
             <if test="updateTime != null">#{updateTime},</if>
             <if test="createTime != null">#{createTime},</if>
             <if test="createBy != null">#{createBy},</if>
@@ -128,6 +137,8 @@
             <if test="serverUserName != null">server_user_name = #{serverUserName},</if>
             <if test="serverPassword != null">server_password = #{serverPassword},</if>
             <if test="status != null">status = #{status},</if>
+            <if test="lng != null">lng = #{lng},</if>
+            <if test="lat != null">lat = #{lat},</if>
             <if test="updateTime != null">update_time = #{updateTime},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="createBy != null">create_by = #{createBy},</if>

+ 20 - 0
bd-park/park-backend/park-domain/src/main/java/com/huashe/park/domain/entity/PileMachineInfo.java

@@ -67,6 +67,10 @@ public class PileMachineInfo extends BaseEntity {
 
     private String status;
 
+    private Double lng;
+
+    private Double lat;
+
     public void setId(Long id) {
         this.id = id;
     }
@@ -203,6 +207,22 @@ public class PileMachineInfo extends BaseEntity {
         this.status = status;
     }
 
+    public Double getLng() {
+        return lng;
+    }
+
+    public void setLng(Double lng) {
+        this.lng = lng;
+    }
+
+    public Double getLat() {
+        return lat;
+    }
+
+    public void setLat(Double lat) {
+        this.lat = lat;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("id", getId())