|
@@ -8,12 +8,12 @@ import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"math/rand"
|
|
|
+ "net/http"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"github.com/spf13/viper"
|
|
|
- "github.com/tidwall/gjson"
|
|
|
)
|
|
|
|
|
|
type HikvisionHandler struct {
|
|
@@ -36,6 +36,7 @@ func (h *HikvisionHandler) GetMonitor(ctx *gin.Context) {
|
|
|
LicensePlateRecognition := make(map[string]any)
|
|
|
Blacklist := make(map[string]any)
|
|
|
var monitor []model.Monitor
|
|
|
+ var monitornms []model.MonitorNms
|
|
|
for i := 0; i < 7; i++ {
|
|
|
name := fmt.Sprintf("周%v", i+1)
|
|
|
LicensePlateRecognition[name] = rand.Intn(100)
|
|
@@ -43,25 +44,29 @@ func (h *HikvisionHandler) GetMonitor(ctx *gin.Context) {
|
|
|
}
|
|
|
for i := 0; i < 20; i++ {
|
|
|
m2 := model.Monitor{
|
|
|
- Id: i + 1,
|
|
|
- Name: model.GetRandomItem(model.MonitorDeviceNames),
|
|
|
+ Id: i + 1,
|
|
|
+ State: rand.Intn(2),
|
|
|
+ Location: model.GetRandomItem(model.MJlocations),
|
|
|
+ Name: model.GetRandomItem(model.MonitorDeviceNames),
|
|
|
+ }
|
|
|
+ nms := model.MonitorNms{
|
|
|
+ Id: i + 1,
|
|
|
+ Name: model.GetRandomItem(model.MonitorDeviceNames),
|
|
|
+ InspectResult: rand.Intn(6),
|
|
|
}
|
|
|
monitor = append(monitor, m2)
|
|
|
- }
|
|
|
-
|
|
|
- m["MonitorCount"] = rand.Intn(1000) //摄像头总数
|
|
|
- m["DeviceOnline"] = rand.Intn(1000) //设备在线
|
|
|
- m["DeviceOffline"] = rand.Intn(1000) //设备离线
|
|
|
- m["StorageCapacity"] = rand.Intn(1000) //存储容量
|
|
|
- m["StoreSurplus"] = rand.Intn(1000) //存储剩余
|
|
|
- m["IntrusionDetection"] = rand.Intn(1000) //入侵检测
|
|
|
- m["AbnormalBehavior"] = rand.Intn(1000) //异常行为
|
|
|
- m["LostAlarms"] = rand.Intn(1000) //丢失告警
|
|
|
- m["LicensePlateRecognition"] = LicensePlateRecognition //车牌识别
|
|
|
- m["Blacklist"] = Blacklist //黑名单
|
|
|
- m["CPU"] = rand.Intn(100) //Cpu
|
|
|
- m["RAM"] = rand.Intn(100) //RAM
|
|
|
- m["MonitorList"] = monitor //监控列表
|
|
|
+ monitornms = append(monitornms, nms)
|
|
|
+ }
|
|
|
+ m["MonitorCount"] = rand.Intn(1000) //摄像头总数
|
|
|
+ m["DeviceOnline"] = rand.Intn(1000) //设备在线
|
|
|
+ m["DeviceOffline"] = rand.Intn(1000) //设备离线
|
|
|
+ m["StorageCapacity"] = rand.Intn(1000) //存储容量
|
|
|
+ m["MonitorList"] = monitor //监控列表
|
|
|
+ m["MonitorNms"] = monitornms //监控检测
|
|
|
+ m["ImageIsNormal"] = rand.Intn(1000) //图像正常
|
|
|
+ m["ImageAbnormalities"] = rand.Intn(1000) //图像异常
|
|
|
+ m["DiagnosisFailed"] = rand.Intn(1000) //诊断失败
|
|
|
+ m["NotDetected"] = rand.Intn(1000) //未检测
|
|
|
resp.HandleSuccess(ctx, m)
|
|
|
}
|
|
|
|
|
@@ -289,32 +294,37 @@ func (h *HikvisionHandler) GetHikvisionMonitoring(ctx *gin.Context) {
|
|
|
resp.HandleError(ctx, 1203, "设备编码不能为空", nil)
|
|
|
return
|
|
|
}
|
|
|
- fmt.Println("cameraIndexCode", h.conf.GetString("hikvision.api.previewURLs"))
|
|
|
- hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.previewURLs"), m, 15)
|
|
|
- //返回结果{
|
|
|
- // "code": "0",
|
|
|
- // "msg": "success",
|
|
|
- // "data": {
|
|
|
- // "url": "rtsp://10.2.145.66:655/EUrl/CLJ52BW"
|
|
|
- // }
|
|
|
+ ctx.HTML(http.StatusOK, "index.html", gin.H{
|
|
|
+ "title": "测试",
|
|
|
+ "message": "ws://127.0.0.1/" + cameraIndexCode,
|
|
|
+ })
|
|
|
+ //fmt.Println("cameraIndexCode", h.conf.GetString("hikvision.api.previewURLs"))
|
|
|
+ //hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.previewURLs"), m, 15)
|
|
|
+ ////返回结果{
|
|
|
+ //// "code": "0",
|
|
|
+ //// "msg": "success",
|
|
|
+ //// "data": {
|
|
|
+ //// "url": "rtsp://10.2.145.66:655/EUrl/CLJ52BW"
|
|
|
+ //// }
|
|
|
+ ////}
|
|
|
+ //if err != nil {
|
|
|
+ // h.logger.Error("获取获取监控点资源失败")
|
|
|
+ // resp.HandleError(ctx, 1201, "获取获取监控点资源失败", err)
|
|
|
+ // return
|
|
|
//}
|
|
|
- if err != nil {
|
|
|
- h.logger.Error("获取获取监控点资源失败")
|
|
|
- resp.HandleError(ctx, 1201, "获取获取监控点资源失败", err)
|
|
|
- return
|
|
|
- }
|
|
|
- if hikvision.Code != "0" {
|
|
|
- atoi, _ := strconv.Atoi(hikvision.Code)
|
|
|
- resp.HandleError(ctx, atoi, hikvision.Msg, nil)
|
|
|
- return
|
|
|
- }
|
|
|
- marshalString, err := json.Marshal(hikvision)
|
|
|
- if err != nil {
|
|
|
- resp.HandleError(ctx, 1202, "json序列化失败", nil)
|
|
|
- return
|
|
|
- }
|
|
|
- url := gjson.Get(string(marshalString), "data.url")
|
|
|
- resp.HandleSuccess(ctx, url)
|
|
|
+ //if hikvision.Code != "0" {
|
|
|
+ // atoi, _ := strconv.Atoi(hikvision.Code)
|
|
|
+ // resp.HandleError(ctx, atoi, hikvision.Msg, nil)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //marshalString, err := json.Marshal(hikvision)
|
|
|
+ //if err != nil {
|
|
|
+ // resp.HandleError(ctx, 1202, "json序列化失败", nil)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //url := gjson.Get(string(marshalString), "data.url")
|
|
|
+ //
|
|
|
+ //resp.HandleSuccess(ctx, url)
|
|
|
}
|
|
|
|
|
|
// 视频监控云台控制{
|
|
@@ -584,24 +594,24 @@ func (h *HikvisionHandler) RealTimeInspection(ctx *gin.Context) {
|
|
|
hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.eventLogs"), m, 15)
|
|
|
if err != nil {
|
|
|
h.logger.Error("入侵报警事件日志查询失败")
|
|
|
- resp.HandleError(ctx, 1203, "入侵报警事件日志查询失败", nil)
|
|
|
+ resp.HandleError(ctx, 1203, "入侵报警事件日志查询失败", err)
|
|
|
return
|
|
|
}
|
|
|
if hikvision.Code != "0" {
|
|
|
h.logger.Error("入侵报警事件日志查询失败")
|
|
|
- resp.HandleError(ctx, 1203, "入侵报警事件日志查询失败", nil)
|
|
|
+ resp.HandleError(ctx, 1203, "入侵报警事件日志查询失败", hikvision.Code)
|
|
|
return
|
|
|
}
|
|
|
marshal, err := json.Marshal(hikvision)
|
|
|
if err != nil {
|
|
|
h.logger.Error("json序列化失败")
|
|
|
- resp.HandleError(ctx, 1203, "json序列化失败", nil)
|
|
|
+ resp.HandleError(ctx, 1203, "json序列化失败", err)
|
|
|
return
|
|
|
}
|
|
|
err = json.Unmarshal(marshal, &eventLogs)
|
|
|
if err != nil {
|
|
|
h.logger.Error("json反序列化失败")
|
|
|
- resp.HandleError(ctx, 1203, "json反序列化失败", nil)
|
|
|
+ resp.HandleError(ctx, 1203, "json反序列化失败", err)
|
|
|
return
|
|
|
}
|
|
|
for i, _ := range eventLogs.Data.List {
|