Kaynağa Gözat

子系统模拟数据

huangyan 2 ay önce
ebeveyn
işleme
cf5c084542

+ 1 - 0
cmd/server/main.go

@@ -7,6 +7,7 @@ import (
 	"city_chips/pkg/http"
 	"city_chips/pkg/log"
 	"fmt"
+
 	"go.uber.org/zap"
 )
 

+ 32 - 36
internal/handler/accesscontrol.go

@@ -1,11 +1,13 @@
 package handler
 
 import (
+	"city_chips/internal/model"
 	"city_chips/internal/service"
-	"encoding/json"
+	"city_chips/pkg/helper/resp"
 	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/spf13/viper"
+	"math/rand"
 	"time"
 )
 
@@ -23,42 +25,36 @@ func NewAccessControlHandler(handler *Handler, accessControlService service.Acce
 	}
 }
 
-// GetAccessControl SSE实时推送消息
-func (h *AccessControlHandler) GetAccessControl(c *gin.Context) {
-	// 设置响应头
-	c.Header("Content-Type", "text/event-stream")
-	c.Header("Cache-Control", "no-cache")
-	c.Header("Connection", "keep-alive")
-	// 监听客户端断开连接
-	conn := true
-	notify := c.Writer.CloseNotify()
-	type Response struct {
-		RequestId string `protobuf:"bytes,1,opt,name=requestId,proto3" json:"requestId,omitempty"`
-		Code      int32  `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
-		Msg       string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
-		Data      any    `json:"data"`
+// GetAccessControl 出入口控制
+func (h *AccessControlHandler) GetAccessControl(ctx *gin.Context) {
+	m := make(map[string]any)
+	var deviceRanking []model.DeviceRanking
+	var device []model.Device
+
+	for i := 0; i < 10; i++ {
+		name := fmt.Sprintf("设备名称%v", i+1)
+		ranking := model.DeviceRanking{
+			Id:         i + 1,
+			DeviceName: name,
+			Value:      rand.Intn(100),
+		}
+		deviceRanking = append(deviceRanking, ranking)
 	}
-	var response Response
-	count := 0
-	for conn {
-		select {
-		case <-notify:
-			conn = false
-			fmt.Println("断开连接")
-			return
-		default:
-			count = count + 1
-			sprintf := fmt.Sprintf("循环次数%v", count)
-			response.Code = 200
-			response.Msg = "查询成功"
-			response.Data = sprintf
-			res, _ := json.Marshal(&response)
-			fmt.Fprintf(c.Writer, "data: %s\n\n", string(res))
-			c.Writer.Flush()
-			time.Sleep(5 * time.Second)
+	for i := 0; i < 10; i++ {
+		name := fmt.Sprintf("设备%v", i+1)
+		m2 := model.Device{
+			Id:    i + 1,
+			Name:  name,
+			State: rand.Intn(2),
+			Date:  time.Now().Format("2006-01-02 15:04:05"),
 		}
-		getString := h.conf.GetString("lifang.baseUrl.Login")
-		h.logger.Info("测试配置文件")
-		fmt.Println(getString)
+		device = append(device, m2)
 	}
+	m["Online"] = rand.Intn(100)       //在线
+	m["Offline"] = rand.Intn(100)      //离线
+	m["DeviceRanking"] = deviceRanking //设备排名
+	m["Out"] = rand.Intn(100)          //出
+	m["Into"] = rand.Intn(100)         //入
+	m["DeviceList"] = device           //设备列表
+	resp.HandleSuccess(ctx, m)
 }

+ 246 - 1
internal/handler/hikvision.go

@@ -1,14 +1,18 @@
 package handler
 
 import (
+	"city_chips/internal/model"
 	"city_chips/internal/service"
 	"city_chips/pkg/helper/resp"
 	"encoding/json"
 	"fmt"
+	"math/rand"
+	"strconv"
+	"time"
+
 	"github.com/gin-gonic/gin"
 	"github.com/spf13/viper"
 	"github.com/tidwall/gjson"
-	"strconv"
 )
 
 type HikvisionHandler struct {
@@ -25,6 +29,247 @@ func NewHikvisionHandler(handler *Handler, hikvisionService service.HikvisionSer
 	}
 }
 
+// GetMonitor 获取视频监控
+func (h *HikvisionHandler) GetMonitor(ctx *gin.Context) {
+	m := make(map[string]any)
+	LicensePlateRecognition := make(map[string]any)
+	Blacklist := make(map[string]any)
+	var monitor []model.Monitor
+	for i := 0; i < 7; i++ {
+		name := fmt.Sprintf("周%v", i+1)
+		LicensePlateRecognition[name] = rand.Intn(100)
+		Blacklist[name] = rand.Intn(100)
+	}
+	for i := 0; i < 10; i++ {
+		name := fmt.Sprintf("监控设备%v", i+1)
+		m2 := model.Monitor{
+			Id:   i + 1,
+			Name: name,
+		}
+		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                             //监控列表
+	resp.HandleSuccess(ctx, m)
+}
+
+// GetInvade 获取入侵检测
+func (h *HikvisionHandler) GetInvade(ctx *gin.Context) {
+	m := make(map[string]any)
+	AlarmTrend24Hour := make(map[string]any)
+	var realTime []model.RealTimeInspection
+	for i := 0; i < 24; i++ {
+		name := fmt.Sprintf("%v时", i+1)
+		AlarmTrend24Hour[name] = rand.Intn(100)
+	}
+	for i := 0; i < 10; i++ {
+		name := fmt.Sprintf("巡检事件%v", i+1)
+		Location := fmt.Sprintf("位置%v", i+1)
+		inspection := model.RealTimeInspection{
+			Id:       i + 1,
+			Name:     name,
+			Location: Location,
+			Event:    name,
+		}
+		realTime = append(realTime, inspection)
+	}
+
+	m["DeviceAlerts"] = rand.Intn(100)       //设备预警
+	m["LowRiskWarning"] = rand.Intn(100)     //低危预警
+	m["MediumRiskWarning"] = rand.Intn(100)  //中危预警
+	m["HighRiskWarning"] = rand.Intn(1000)   //高危预警
+	m["HighRiskWarning"] = rand.Intn(1000)   //高危预警
+	m["OverHazardWarning"] = rand.Intn(1000) //超危预警
+	m["EventRisk"] = rand.Intn(100)          //事件风险
+	m["AlarmRisk"] = rand.Intn(100)          //告警风险
+	m["trend"] = rand.Intn(100)              //圆环中间百分比
+	m["realTime"] = realTime                 //实时巡检
+	m["AlarmTrend24Hour"] = AlarmTrend24Hour //24小时告警趋势
+	resp.HandleSuccess(ctx, m)
+}
+
+// GetElectronicInspections 电子巡查
+func (h *HikvisionHandler) GetElectronicInspections(ctx *gin.Context) {
+	m := make(map[string]any)
+	Inspect := make(map[string]any)
+	var device []model.Device
+	var realTime []model.RealTimeInspection
+
+	for i := 0; i < 24; i++ {
+		name := fmt.Sprintf("%v时", i+1)
+		Inspect[name] = rand.Intn(100)
+	}
+	for i := 0; i < 10; i++ {
+		name := fmt.Sprintf("设备%v", i+1)
+		m2 := model.Device{
+			Id:    i + 1,
+			Name:  name,
+			State: rand.Intn(2),
+			Date:  time.Now().Format("2006-01-02 15:04:05"),
+		}
+		device = append(device, m2)
+	}
+	for i := 0; i < 10; i++ {
+		name := fmt.Sprintf("巡检事件%v", i+1)
+		Location := fmt.Sprintf("位置%v", i+1)
+		inspection := model.RealTimeInspection{
+			Id:       i + 1,
+			Name:     name,
+			Location: Location,
+			Event:    name,
+		}
+		realTime = append(realTime, inspection)
+	}
+	m["TodayTotal"] = rand.Intn(100)       //今日总数
+	m["InspectionPoints"] = rand.Intn(100) //巡检点数
+	m["InspectionPlan"] = rand.Intn(100)   //巡检计划
+	m["InspectTheLine"] = rand.Intn(1000)  //巡检线路
+	m["Inspect"] = Inspect                 //巡检统计
+	m["realTime"] = realTime               //实时巡检
+	m["DeviceList"] = device               //设备列表
+	resp.HandleSuccess(ctx, m)
+}
+
+// 访客系统
+func (h *HikvisionHandler) GetVisitor(ctx *gin.Context) {
+	m := make(map[string]any)
+	PersonnelAllocation := make(map[string]any)
+	var visitor []model.Visitor
+	for i := 0; i < 10; i++ {
+		name := fmt.Sprintf("人员%v", i+1)
+		address := fmt.Sprintf("地址%v", i+1)
+		m2 := model.Visitor{
+			Id:    i + 1,
+			Name:  name,
+			State: rand.Intn(2),
+			Date:  time.Now().Format("2006-01-02 15:04:05"),
+		}
+		PersonnelAllocation[address] = rand.Intn(100)
+		visitor = append(visitor, m2)
+	}
+
+	m["Area"] = rand.Intn(100)                     //总建筑面积
+	m["Test"] = rand.Intn(100)                     //测试
+	m["DeviceList"] = visitor                      //访客列表
+	m["PersonnelAllocation"] = PersonnelAllocation //外地人员分配
+	resp.HandleSuccess(ctx, m)
+}
+
+// 客流统计
+func (h *HikvisionHandler) GetPassenger(ctx *gin.Context) {
+	m := make(map[string]any)
+	Type1 := make(map[string]any)
+	Type2 := make(map[string]any)
+	Type3 := make(map[string]any)
+	Type4 := make(map[string]any)
+	rankings := make(map[string]any)
+	customers := make(map[string]any)
+	var event []model.RealTimeInspection
+	for i := 0; i < 7; i++ {
+		sprintf := fmt.Sprintf("2025-5-%v", i+1)
+		ranking := fmt.Sprintf("类型-%v", i+1)
+		rankings[ranking] = rand.Intn(100)
+		Type1[sprintf] = rand.Intn(100)
+		Type2[sprintf] = rand.Intn(100)
+		Type3[sprintf] = rand.Intn(100)
+		Type4[sprintf] = rand.Intn(100)
+	}
+	for i := 0; i < 3; i++ {
+		sprintf := fmt.Sprintf("客群-%v", i+1)
+		customers[sprintf] = rand.Intn(100)
+	}
+	for i := 0; i < 10; i++ {
+		sprintf := fmt.Sprintf("安全事件-%v", i+1)
+		location := fmt.Sprintf("位置-%v", i+1)
+		inspection := model.RealTimeInspection{
+			Id:       i + 1,
+			Name:     sprintf,
+			Location: location,
+			Event:    time.Now().Format("2006-01-02 15:04:05"),
+		}
+		event = append(event, inspection)
+	}
+	m["SecurityLevel"] = rand.Intn(500)    //安全等级
+	m["NetworkEquipment"] = rand.Intn(100) //网络设备
+	m["Normal"] = rand.Intn(100)           //正常
+	m["Fault"] = rand.Intn(100)            //故障
+	m["Offline"] = rand.Intn(100)          //离线
+	m["Type1"] = Type1                     //客流监控type1
+	m["Type2"] = Type2                     //客流监控type2
+	m["Type3"] = Type3                     //客流监控type3
+	m["Type4"] = Type4                     //客流监控type4
+	m["Rankings"] = rankings               //指标区排行榜
+	m["Customers"] = customers             //客群分析统计
+	m["Customers"] = customers             //客群分析统计
+	m["Event"] = event                     //安全事件列表
+	resp.HandleSuccess(ctx, m)
+}
+
+// 门禁系统
+func (h *HikvisionHandler) GetAccess(ctx *gin.Context) {
+	m := make(map[string]any)
+	invasio1 := make(map[string]any)
+	invasio2 := make(map[string]any)
+	DailyTotal := make(map[string]any)
+	Cumulative := make(map[string]any)
+	var devices []model.RealTimeInspection
+	var alarmList []model.AlarmList
+	for i := 0; i < 7; i++ {
+		sprintf := fmt.Sprintf("2025-5-%v", i+1)
+		invasio1[sprintf] = rand.Intn(100)
+		invasio2[sprintf] = rand.Intn(100)
+	}
+	for i := 0; i < 24; i++ {
+		sprintf := fmt.Sprintf("%v时", i+1)
+		DailyTotal[sprintf] = rand.Intn(100)
+		Cumulative[sprintf] = rand.Intn(100)
+	}
+	for i := 0; i < 10; i++ {
+		sprintf := fmt.Sprintf("设备-%v", i+1)
+		location := fmt.Sprintf("位置-%v", i+1)
+		inspection := model.RealTimeInspection{
+			Id:       i + 1,
+			Name:     sprintf,
+			Location: location,
+			Event:    time.Now().Format("2006-01-02 15:04:05"),
+		}
+		alarm := model.AlarmList{
+			Id:           i + 1,
+			AlarmContent: fmt.Sprintf("设备-%v", i+1),
+			Location:     location,
+			State:        rand.Intn(2),
+			Date:         time.Now().Format("2006-01-02 15:04:05"),
+		}
+
+		devices = append(devices, inspection)
+		alarmList = append(alarmList, alarm)
+	}
+
+	m["DeviceCount"] = rand.Intn(500) //设备总数
+	m["Online"] = rand.Intn(100)      //在线
+	m["Abnormal"] = rand.Intn(100)    //异常
+	m["Fault"] = rand.Intn(100)       //故障
+	m["Offline"] = rand.Intn(100)     //离线
+	m["Invasio1"] = invasio1          //入侵事件1
+	m["Invasio2"] = invasio2          //入侵事件2
+	m["DailyTotal"] = DailyTotal      //每日统计
+	m["Cumulative"] = Cumulative      //累计统计
+	m["AlarmList"] = alarmList        //实时告警与通知
+	resp.HandleSuccess(ctx, m)
+}
+
 //	GetHikvisionMonitoring 获取视频监控流{
 //		   "cameraIndexCode": "748d84750e3a4a5bbad3cd4af9ed5101",
 //		   "streamType": 0,

+ 5 - 0
internal/model/accesscontrol.go

@@ -5,6 +5,11 @@ import "gorm.io/gorm"
 type AccessControl struct {
 	gorm.Model
 }
+type DeviceRanking struct {
+	Id         int    `json:"Id"`
+	DeviceName string `json:"DeviceName"`
+	Value      int    `json:"Value"`
+}
 
 func (m *AccessControl) TableName() string {
 	return "access_control"

+ 29 - 0
internal/model/hikvision.go

@@ -5,6 +5,35 @@ import "gorm.io/gorm"
 type Hikvision struct {
 	gorm.Model
 }
+type Monitor struct {
+	Id   int    `json:"Id"`
+	Name string `json:"Name"`
+}
+type RealTimeInspection struct {
+	Id       int    `json:"Id"`
+	Name     string `json:"Name"`     //名称
+	Location string `json:"Location"` //位置
+	Event    string `json:"Event"`    //事件-列3
+}
+type Device struct {
+	Id    int    `json:"Id"`
+	Name  string `json:"Name"`  //名称
+	State int    `json:"State"` //状态
+	Date  string `json:"Date"`  //事件-列3
+}
+type Visitor struct {
+	Id    int    `json:"Id"`
+	Name  string `json:"Name"`  //名称
+	State int    `json:"State"` //状态
+	Date  string `json:"Date"`  //事件-列3
+}
+type AlarmList struct {
+	Id           int    `json:"Id"`
+	AlarmContent string `json:"AlarmContent"` //告警内容
+	Location     string `json:"Location"`     //位置
+	State        int    `json:"State"`        //状态
+	Date         string `json:"Date"`         //时间
+}
 
 func (m *Hikvision) TableName() string {
 	return "hikvision"

+ 1 - 1
internal/repository/energy.go

@@ -2,7 +2,7 @@ package repository
 
 import (
 	"city_chips/internal/model"
-	
+	"context"
 )
 
 type EnergyRepository interface {

+ 8 - 1
internal/server/http.go

@@ -4,6 +4,7 @@ import (
 	"city_chips/internal/handler"
 	"city_chips/internal/middleware"
 	"city_chips/pkg/log"
+
 	"github.com/gin-gonic/gin"
 )
 
@@ -28,7 +29,7 @@ func NewServerHTTP(
 	//出入口控制系统
 	Access := r.Group("/Access")
 	{
-		Access.GET("/test", accessHandler.GetAccessControl)
+		Access.GET("/count", accessHandler.GetAccessControl)
 	}
 	//海康威视
 	Hikvision := r.Group("/Hikvision")
@@ -36,6 +37,12 @@ func NewServerHTTP(
 		Hikvision.GET("/getMonitoring", hikvision.GetHikvisionMonitoring)
 		Hikvision.GET("/controlling", hikvision.Gimbalcontrol)
 		Hikvision.GET("/visitorInfo", hikvision.VisitorInfoCount)
+		Hikvision.GET("/monitor", hikvision.GetMonitor)
+		Hikvision.GET("/invade", hikvision.GetInvade)
+		Hikvision.GET("/endpoint", hikvision.GetElectronicInspections)
+		Hikvision.GET("/visitor", hikvision.GetVisitor)
+		Hikvision.GET("/passenger", hikvision.GetPassenger)
+		Hikvision.GET("/access", hikvision.GetAccess)
 	}
 	//会议系统
 	Conference := r.Group("/Conference")