فهرست منبع

change:
1. 添加刷新设备信息接口
2. 添加定时刷新设备信息功能

kindring 2 سال پیش
والد
کامیت
7a9b7008f0

+ 30 - 1
src/main/java/com/genersoft/iot/vmp/gb28181/task/SipRunner.java

@@ -13,6 +13,9 @@ import com.genersoft.iot.vmp.service.IMediaServerService;
 import com.genersoft.iot.vmp.service.IPlatformService;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
+import com.genersoft.iot.vmp.vmanager.gb28181.device.DeviceQuery;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.core.annotation.Order;
@@ -30,6 +33,7 @@ import java.util.Map;
 @Component
 @Order(value=14)
 public class SipRunner implements CommandLineRunner {
+    private final static Logger logger = LoggerFactory.getLogger(SipRunner.class);
 
     @Autowired
     private IVideoManagerStorage storager;
@@ -57,8 +61,9 @@ public class SipRunner implements CommandLineRunner {
 
     @Override
     public void run(String... args) throws Exception {
-        List<Device> deviceList = deviceService.getAllOnlineDevice();
 
+        // 设备状态检查
+        List<Device> deviceList = deviceService.getAllOnlineDevice();
         for (Device device : deviceList) {
             if (deviceService.expire(device)){
                 deviceService.offline(device.getDeviceId(), "注册已过期");
@@ -66,6 +71,10 @@ public class SipRunner implements CommandLineRunner {
                 deviceService.online(device);
             }
         }
+
+
+
+
         // 重置cseq计数
         redisCatchStorage.resetAllCSEQ();
         // 清理redis
@@ -111,5 +120,25 @@ public class SipRunner implements CommandLineRunner {
                 }
             }
         }
+
+        // 每隔10分钟检查一次设备是否过期
+        new Thread(()->{
+            while (true) {
+                try {
+                    Thread.sleep(1000 * 60 * 10);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+                logger.info("[定时任务] 检查设备是否过期");
+                List<Device> deviceList1 = deviceService.getAllOnlineDevice();
+                for (Device device : deviceList1) {
+                    if (deviceService.expire(device)){
+                        deviceService.offline(device.getDeviceId(), "注册已过期");
+                    }
+                }
+                // todo 检查是否有异常推流
+                //  logger.info("[定时任务] 检查是否有异常推流");
+            }
+        }).start();
     }
 }

+ 17 - 0
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java

@@ -182,6 +182,23 @@ public class DeviceQuery {
 		return storager.queryLibraryList();
 	}
 
+	@Operation(summary = "刷新设备状态")
+	@GetMapping("/refresh")
+	public int refreshDevice(){
+		logger.info("[web api] /refresh 刷新设备状态");
+		List<Device> deviceList = deviceService.getAllOnlineDevice();
+		for (Device device : deviceList) {
+			if (deviceService.expire(device)){
+				logger.info("设备注册已过期,强制离线,设备id:"+device.getDeviceId());
+				deviceService.offline(device.getDeviceId(), "注册已过期");
+			}else {
+				deviceService.online(device);
+			}
+		}
+		return 1;
+	}
+
+
 	@Operation(summary = "ai库具体信息获取")
 	@Parameter(name = "libraryId", description = "lib库id", required = true)
 	@GetMapping("/libInfo/{libraryId}")

+ 17 - 1
web_src/src/components/DeviceList.vue

@@ -5,8 +5,10 @@
       <div class="page-header-btn">
         <el-button icon="el-icon-plus" size="mini" style="margin-right: 1rem;" type="primary" @click="add">添加设备
         </el-button>
+<!--        <el-button icon="el-icon-refresh-right" circle size="mini" :loading="getDeviceListLoading"-->
+<!--                   @click="getDeviceList()"></el-button>-->
         <el-button icon="el-icon-refresh-right" circle size="mini" :loading="getDeviceListLoading"
-                   @click="getDeviceList()"></el-button>
+                   @click="refreshDevice()"></el-button>
       </div>
     </div>
     <!--设备列表-->
@@ -175,6 +177,20 @@ export default {
         this.getDeviceListLoading = false;
       });
     },
+    refreshDevice(){
+      console.log('refresh device');
+      // 调用接口刷新设备数据
+      this.$axios.axios({
+        method: 'get',
+        url: `/api/device/query/devices/refresh`
+      }).then( (res)=> {
+        if (res.data.code === 0) {
+          this.getDeviceList();
+        }
+      }).catch( (error)=> {
+        console.error(error);
+      });
+    },
     deleteDevice: function (row) {
       let msg = "确定删除此设备?"
       if (row.online !== 0) {