Explorar o código

BUG修复 加入设备状态,修正重复添加水位问题

qinguocai hai 1 ano
pai
achega
6307f5c4dc

+ 8 - 1
ruoyi-system/src/main/java/com/ruoyi/system/domain/SiteInfo.java

@@ -97,7 +97,14 @@ public class SiteInfo implements Serializable {
      * 远程摄像头密码
      */
     private String videoPwd;
-    
+
+
+    /**
+     * 远程设备状态 0.离线 1.在线
+     */
+    private Integer deviceStatus;
+
+
 
 }
 

+ 5 - 2
ruoyi-system/src/main/java/com/ruoyi/system/dto/SiteRealTimeDTO.java

@@ -2,8 +2,6 @@ package com.ruoyi.system.dto;
 
 import lombok.Data;
 
-import javax.validation.constraints.NotBlank;
-import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 
 /**
@@ -33,6 +31,11 @@ public class SiteRealTimeDTO implements Serializable {
     private String siteStatus;
 
 
+    /**
+     * 设备状态 0.离线 1.在线
+     */
+    private Integer deviceStatus;
+
     /**
      * 下次测流时间
      */

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SiteInfoMapper.java

@@ -29,6 +29,10 @@ public interface SiteInfoMapper {
      */
     SiteInfo queryBySiteCode(String siteCode);
 
+
+
+    List<SiteInfo> queryAll();
+
     /**
      * 查询指定行数据
      *

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/DirectiveService.java

@@ -3,10 +3,14 @@ package com.ruoyi.system.service;
 
 import com.ruoyi.system.dto.ManualMeasureDTO;
 
+import java.util.Date;
+
 public interface DirectiveService {
 
     boolean manualMeasure(ManualMeasureDTO manualMeasureDTO);
 
     boolean taskStop(Long siteId, Long action);
 
+    void queryHeartbeat(Date data);
+
 }

+ 1 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/ReportDataService.java

@@ -5,9 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.system.domain.*;
 import com.ruoyi.system.dto.SiteRealTimeDTO;
 
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
+
 
 
 public interface ReportDataService {

+ 30 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DirectiveServiceImpl.java

@@ -1,12 +1,15 @@
 package com.ruoyi.system.service.impl;
 
 
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.json.JSONUtil;
 import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.system.domain.HeartBeat;
 import com.ruoyi.system.domain.SiteInfo;
 import com.ruoyi.system.domain.TaskNotice;
 import com.ruoyi.system.domain.TaskResult;
 import com.ruoyi.system.dto.ManualMeasureDTO;
+import com.ruoyi.system.mapper.HeartBeatMapper;
 import com.ruoyi.system.mapper.SiteInfoMapper;
 import com.ruoyi.system.mapper.TaskNoticeMapper;
 import com.ruoyi.system.mapper.TaskResultMapper;
@@ -18,6 +21,7 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 
 
 /**
@@ -40,6 +44,9 @@ public class DirectiveServiceImpl implements DirectiveService {
     @Resource
     private TaskResultMapper taskResultMapper;
 
+    @Resource
+    private HeartBeatMapper heartBeatMapper;
+
     @Override
     public boolean manualMeasure(ManualMeasureDTO manualMeasureDTO) {
         SiteInfo siteInfo = siteInfoMapper.queryById(manualMeasureDTO.getSiteId());
@@ -130,6 +137,29 @@ public class DirectiveServiceImpl implements DirectiveService {
     }
 
 
+    @Override
+    public void queryHeartbeat(Date data){
+        List<SiteInfo> siteInfoList = siteInfoMapper.queryAll();
+        Date tenMinutesAgo = DateUtil.offsetMinute(data, - 10);  // 减去10分钟
+        String formattedTime = DateUtil.format(tenMinutesAgo, "yyyy-MM-dd HH:mm:ss");
+        for (SiteInfo siteInfo : siteInfoList) {
+            List<HeartBeat> heartBeatList = heartBeatMapper.queryBysiteIdTime(siteInfo.getSiteId(), formattedTime, DateUtil.format(data, "yyyy-MM-dd HH:mm:ss"));
+            if (heartBeatList.isEmpty()) {
+                if (siteInfo.getDeviceStatus() == 1) {
+                    TaskNotice taskNotice = new TaskNotice();
+                    taskNotice.setStartId(0L);
+                    taskNotice.setRemark("设备离线");
+                    taskNotice.setCreateTime(new Date());
+                    taskNotice.setSiteId(siteInfo.getSiteId());
+                    taskNoticeMapper.insert(taskNotice);
+                    siteInfo.setDeviceStatus(0);
+                    siteInfoMapper.update(siteInfo);
+                }
+            }
+        }
+    }
+
+
 
 
 

+ 1 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ReportDataServiceImpl.java

@@ -87,6 +87,7 @@ public class ReportDataServiceImpl implements ReportDataService {
         }
         siteRealTimeDTO.setSiteName(siteInfo.getSiteName());
         siteRealTimeDTO.setSiteId(siteId);
+        siteRealTimeDTO.setDeviceStatus(siteInfo.getDeviceStatus());
         //查询状态
         TaskResult taskResult = taskResultMapper.queryBySiteIdOne(siteId);
         if (taskResult == null){

+ 10 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SaveDataServiceImpl.java

@@ -108,7 +108,17 @@ public class SaveDataServiceImpl implements SaveDataService {
                 log.error("查询站点失败入库失败 站码:{}",heartBeat.getId());
                 return;
             }
+            if (siteInfo.getDeviceStatus() == 0){
+                TaskNotice taskNotice = new TaskNotice();
+                taskNotice.setStartId(0L);
+                taskNotice.setRemark("设备上线");
+                taskNotice.setCreateTime(new Date());
+                taskNotice.setSiteId(siteInfo.getSiteId());
+                taskNoticeMapper.insert(taskNotice);
+            }
+            siteInfo.setDeviceStatus(1);
             heartBeat.setSiteId(siteInfo.getSiteId());
+            siteInfoMapper.update(siteInfo);
             heartBeatMapper.insert(heartBeat);
             log.info("insert heartbeat:{}",heartBeat);
         } catch (Exception e) {

+ 1 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SiteServiceImpl.java

@@ -49,6 +49,7 @@ public class SiteServiceImpl implements SiteService {
             siteInfo.setSiteId(0L);
             siteInfo.setCreatTime(new Date());
             siteInfo.setIsDel(0);
+            siteInfo.setDeviceStatus(0);
             return siteInfoMapper.insert(siteInfo) > 0;
         } catch (Exception e){
             log.error("新增站点错误", e);

+ 35 - 0
ruoyi-system/src/main/java/com/ruoyi/system/task/DeviceStatusTask.java

@@ -0,0 +1,35 @@
+package com.ruoyi.system.task;
+
+import com.ruoyi.system.service.DirectiveService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.Date;
+
+@Slf4j
+@Component
+public class DeviceStatusTask {
+
+
+   @Resource
+   private DirectiveService directiveService;
+
+    /**
+     * 每10分钟执行 查询心跳信息
+     */
+    @Async
+    @Scheduled(cron = "0 */1 * * * ?")
+    public void queryHeartBeat() {
+        log.info("开始查询心跳");
+        directiveService.queryHeartbeat(new Date());
+    }
+
+
+
+}
+
+
+

+ 1 - 1
ruoyi-system/src/main/resources/mapper/BerthingFloatConfigMapper.xml

@@ -80,7 +80,7 @@
                 and is_del = #{isDel}
             </if>
             <if test="wlevel != null">
-                and wlevel = #{wlevel}
+                and ROUND(wlevel,2) = #{wlevel}
             </if>
             <if test="timespan != null">
                 and timespan = #{timespan}

+ 1 - 1
ruoyi-system/src/main/resources/mapper/BerthingTimeConfigMapper.xml

@@ -93,7 +93,7 @@
                 and is_del = #{isDel}
             </if>
             <if test="wlevel != null">
-                and wlevel = #{wlevel}
+                and ROUND(wlevel, 2) = #{wlevel}
             </if>
             <if test="times != null and times != ''">
                 and times = #{times}

+ 25 - 10
ruoyi-system/src/main/resources/mapper/SiteInfoMapper.xml

@@ -22,12 +22,13 @@
         <result property="videoUser" column="video_user" jdbcType="VARCHAR"/>
         <result property="videoPwd" column="video_pwd" jdbcType="VARCHAR"/>
         <result property="videoPort" column="video_port" jdbcType="VARCHAR"/>
+        <result property="deviceStatus" column="device_status" jdbcType="INTEGER"/>
     </resultMap>
 
     <!--查询单个-->
     <select id="queryById" resultMap="SiteInfoMap">
         select
-            site_id, id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port
+            site_id, id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port, device_status
         from site_info
         where site_id = #{siteId}
     </select>
@@ -35,15 +36,25 @@
     <!--查询单个-->
     <select id="queryBySiteCode" resultMap="SiteInfoMap">
         select
-            site_id, id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port
+            site_id, id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port, device_status
         from site_info
         where id = #{siteCode} and is_del = 0
     </select>
 
+
+
+    <!--查询单个-->
+    <select id="queryAll" resultMap="SiteInfoMap">
+        select
+            site_id, id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port, device_status
+        from site_info
+        where is_del = 0
+    </select>
+
     <!--查询指定行数据-->
     <select id="queryAllByLimit" resultMap="SiteInfoMap">
         select
-            site_id, id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port
+            site_id, id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port, device_status
         from site_info
         <where>
             <if test="siteInfoQuery.siteId != null">
@@ -120,23 +131,23 @@
 
     <!--新增所有列-->
     <insert id="insert" keyProperty="siteId" useGeneratedKeys="true">
-        insert into site_info(id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port)
-        values (#{id}, #{siteName}, #{siteType}, #{lon}, #{lat}, #{siteTime}, #{adminRegion}, #{manageUnit}, #{affiliatedUnit}, #{contactName}, #{contactPhone}, #{creatTime}, #{isDel}, #{deviceId}, #{videoUrl}, #{videoUser}, #{videoPwd}, #{videoPort})
+        insert into site_info(id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port, device_status)
+        values (#{id}, #{siteName}, #{siteType}, #{lon}, #{lat}, #{siteTime}, #{adminRegion}, #{manageUnit}, #{affiliatedUnit}, #{contactName}, #{contactPhone}, #{creatTime}, #{isDel}, #{deviceId}, #{videoUrl}, #{videoUser}, #{videoPwd}, #{videoPort}, #{deviceStatus})
     </insert>
 
     <insert id="insertBatch" keyProperty="siteId" useGeneratedKeys="true">
-        insert into site_info(id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port)
+        insert into site_info(id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port, device_status)
         values
         <foreach collection="entities" item="entity" separator=",">
-        (#{entity.id}, #{entity.siteName}, #{entity.siteType}, #{entity.lon}, #{entity.lat}, #{entity.siteTime}, #{entity.adminRegion}, #{entity.manageUnit}, #{entity.affiliatedUnit}, #{entity.contactName}, #{entity.contactPhone}, #{entity.creatTime}, #{entity.isDel}, #{entity.deviceId}, #{entity.videoUrl}, #{entity.videoUser}, #{entity.videoPwd}, #{entity.videoPort})
+        (#{entity.id}, #{entity.siteName}, #{entity.siteType}, #{entity.lon}, #{entity.lat}, #{entity.siteTime}, #{entity.adminRegion}, #{entity.manageUnit}, #{entity.affiliatedUnit}, #{entity.contactName}, #{entity.contactPhone}, #{entity.creatTime}, #{entity.isDel}, #{entity.deviceId}, #{entity.videoUrl}, #{entity.videoUser}, #{entity.videoPwd}, #{entity.videoPort}, #{entity.deviceStatus})
         </foreach>
     </insert>
 
     <insert id="insertOrUpdateBatch" keyProperty="siteId" useGeneratedKeys="true">
-        insert into site_info(id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port)
+        insert into site_info(id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port, device_status)
         values
         <foreach collection="entities" item="entity" separator=",">
-            (#{entity.id}, #{entity.siteName}, #{entity.siteType}, #{entity.lon}, #{entity.lat}, #{entity.siteTime}, #{entity.adminRegion}, #{entity.manageUnit}, #{entity.affiliatedUnit}, #{entity.contactName}, #{entity.contactPhone}, #{entity.creatTime}, #{entity.isDel}, #{entity.deviceId}, #{entity.videoUrl}, #{entity.videoUser}, #{entity.videoPwd}, #{entity.videoPort})
+            (#{entity.id}, #{entity.siteName}, #{entity.siteType}, #{entity.lon}, #{entity.lat}, #{entity.siteTime}, #{entity.adminRegion}, #{entity.manageUnit}, #{entity.affiliatedUnit}, #{entity.contactName}, #{entity.contactPhone}, #{entity.creatTime}, #{entity.isDel}, #{entity.deviceId}, #{entity.videoUrl}, #{entity.videoUser}, #{entity.videoPwd}, #{entity.videoPort}, #{entity.deviceStatus})
         </foreach>
         on duplicate key update
 id = values(id),
@@ -156,7 +167,8 @@ device_id = values(device_id),
 video_url = values(video_url),
 video_user = values(video_user),
 video_pwd = values(video_pwd),
-video_port = values(video_port)
+video_port = values(video_port),
+device_status = values(device_status)
     </insert>
 
     <!--通过主键修改数据-->
@@ -217,6 +229,9 @@ video_port = values(video_port)
             <if test="videoPort != null and videoPort != ''">
                 video_port = #{videoPort},
             </if>
+            <if test="deviceStatus != null">
+                device_status = #{deviceStatus},
+            </if>
         </set>
         where site_id = #{siteId}
     </update>

+ 2 - 0
waterAffairs-admin/src/main/java/com/ruoyi/RuoYiApplication.java

@@ -3,6 +3,7 @@ package com.ruoyi;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 /**
  * 启动程序
@@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  * @author ruoyi
  */
 @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
+@EnableScheduling
 public class RuoYiApplication
 {
     public static void main(String[] args)