123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- 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"
- )
- type HikvisionHandler struct {
- *Handler
- hikvisionService service.HikvisionService
- conf *viper.Viper
- }
- func NewHikvisionHandler(handler *Handler, hikvisionService service.HikvisionService, conf *viper.Viper) *HikvisionHandler {
- return &HikvisionHandler{
- Handler: handler,
- hikvisionService: hikvisionService,
- conf: conf,
- }
- }
- // 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,
- // "protocol": "rtsp",
- // "transmode": 1,
- // "expand": "transcode=0",
- // "streamform": "ps"
- // }
- func (h *HikvisionHandler) GetHikvisionMonitoring(ctx *gin.Context) {
- m := make(map[string]string)
- cameraIndexCode := ctx.Query("cameraIndexCode")
- m["cameraIndexCode"] = cameraIndexCode
- m["streamType"] = "0"
- m["protocol"] = "rtsp"
- m["transmode"] = "1"
- m["expand"] = "transcode=0"
- m["streamform"] = "ps"
- if len(cameraIndexCode) <= 0 || cameraIndexCode == "" {
- resp.HandleError(ctx, 1203, "设备编码不能为空", nil)
- return
- }
- fmt.Println(m)
- resp.HandleSuccess(ctx, "rtsp://10.2.145.66:655/EUrl/CLJ52BW")
- return
- hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.cameras"), 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 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)
- }
- // 视频监控云台控制{
- // "cameraIndexCode": "748d84750e3a4a5bbad3cd4af9ed5101",
- // "action": 1, 0-开始
- //1-停止
- //注:GOTO_PRESET命令下填任意值均可转到预置点,建议填0即可
- // "command": "GOTO_PRESET",
- // "speed": 4,
- // "presetIndex": 20
- //}
- func (h *HikvisionHandler) Gimbalcontrol(ctx *gin.Context) {
- m := make(map[string]string)
- cameraIndexCode := ctx.Query("cameraIndexCode")
- command := ctx.Query("command")
- action := ctx.Query("action")
- speed := ctx.Query("speed")
- presetIndex := ctx.Query("presetIndex")
- m["cameraIndexCode"] = cameraIndexCode
- m["action"] = action
- m["command"] = command
- m["speed"] = speed
- m["presetIndex"] = presetIndex
- if len(cameraIndexCode) <= 0 || len(command) <= 0 || len(action) <= 0 {
- resp.HandleError(ctx, 1203, "设备编码不能为空", nil)
- return
- }
- resp.HandleSuccess(ctx, m)
- return
- hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.controlling"), m, 15)
- 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
- }
- resp.HandleSuccess(ctx, hikvision.Msg)
- }
- // VisitorInfoCount 获取今日访客信息包含:今日来访总人数(已签离人数,未签离人数),预约人数
- func (h *HikvisionHandler) VisitorInfoCount(c *gin.Context) {
- m := make(map[string]string)
- parkId := c.Query("parkId")
- m["parkId"] = parkId
- resp.HandleSuccess(c, "appointmentTotal: 1, notSignOutTotal: 1, signOutTotal: 1, signTotal: 1, orderCount: 1, visitCount: 1, visitCountForTemp: 1, visitCountForOrder: 1, signOutCount: 1, notSignOutCount: 1")
- return
- hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.visitorInfo"), m, 15)
- if err != nil {
- h.logger.Error("获取访客信息失败")
- resp.HandleError(c, 1201, "获取访客信息失败", err)
- return
- }
- if hikvision.Code != "0" {
- atoi, _ := strconv.Atoi(hikvision.Code)
- resp.HandleError(c, atoi, hikvision.Msg, nil)
- return
- }
- resp.HandleSuccess(c, hikvision.Data)
- }
|