Forráskód Böngészése

获取根目录资源信息,获取子目录资源信息

huangyan 3 hete
szülő
commit
8eb6d89206

+ 2 - 0
config/local.yml

@@ -51,6 +51,8 @@ hikvision:
     doorSearch: "/artemis/api/resource/v2/door/search" #查询门禁点列表v2
     doorStates: "/artemis/api/acs/v1/door/states" #查询门禁设备状态接口
     eventLogs: "/artemis/api/scpms/v2/eventLogs/searches" #入侵报警事件日志查询
+    regionsRoot: "/artemis/api/resource/v1/regions/root" #获取区域树接口
+    regionsSubRegions: "/artemis/api/resource/v2/regions/subRegions" #根据区域编号获取下一级区域列表v2
 
 #会议系统
 conference:

+ 2 - 2
internal/handler/hikvision.go

@@ -355,8 +355,8 @@ func (h *HikvisionHandler) Gimbalcontrol(ctx *gin.Context) {
 		resp.HandleError(ctx, 1203, "设备编码不能为空", nil)
 		return
 	}
-	resp.HandleSuccess(ctx, "操作成功")
-	return
+	// resp.HandleSuccess(ctx, "操作成功")
+	// return
 	hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.controlling"), m, 15)
 
 	if err != nil {

+ 42 - 1
internal/model/hikvision.go

@@ -1,6 +1,9 @@
 package model
 
-import "gorm.io/gorm"
+import (
+	"gorm.io/gorm"
+	"time"
+)
 
 type Hikvision struct {
 	gorm.Model
@@ -174,6 +177,44 @@ type EventLogs struct {
 	} `json:"data"`
 }
 
+// RegionsRoot 区域根节点
+type RegionsRoot struct {
+	Code string `json:"code"`
+	Msg  string `json:"msg"`
+	Data struct {
+		IndexCode       string `json:"indexCode"`
+		Name            string `json:"name"`
+		ParentIndexCode string `json:"parentIndexCode"`
+		TreeCode        string `json:"treeCode"`
+	} `json:"data"`
+}
+
+// RegionsSubRegions 根据区域编号获取下一级区域列表
+type RegionsSubRegions struct {
+	Code string `json:"code"`
+	Msg  string `json:"msg"`
+	Data struct {
+		Total    int `json:"total"`
+		PageNo   int `json:"pageNo"`
+		PageSize int `json:"pageSize"`
+		List     []struct {
+			IndexCode         string    `json:"indexCode"`
+			Name              string    `json:"name"`
+			ParentIndexCode   string    `json:"parentIndexCode"`
+			Available         bool      `json:"available"`
+			Leaf              bool      `json:"leaf"`
+			CascadeCode       string    `json:"cascadeCode"`
+			CascadeType       int       `json:"cascadeType"`
+			CatalogType       int       `json:"catalogType"`
+			ExternalIndexCode string    `json:"externalIndexCode"`
+			Sort              int       `json:"sort"`
+			RegionPath        string    `json:"regionPath"`
+			CreateTime        time.Time `json:"createTime"`
+			UpdateTime        time.Time `json:"updateTime"`
+		} `json:"list"`
+	} `json:"data"`
+}
+
 var ResourceType = map[string]string{
 	"region":                "区域",
 	"acsDevice":             "门禁控制器",

+ 1 - 1
internal/model/intelligentbuildingcontrol.go

@@ -15,7 +15,7 @@ type Point struct {
 	Id         int64  `json:"id" gorm:"column:id;primaryKey;autoIncrement;comment:点位ID"`
 	FullPath   string `json:"full_path" gorm:"column:full_path;type:varchar(255);comment:点位全路径"`
 	DeviceType string `json:"device_type" gorm:"column:device_type;type:varchar(50);comment:设备类型"`
-	BuildingId string `json:"building_id" gorm:"column:building_id;type:varchar(50);comment:所属楼宇ID"`
+	Building   string `json:"building" gorm:"column:building;type:varchar(50);comment:所属楼宇ID"`
 	Floor      string `json:"floor" gorm:"column:floor;type:varchar(50);comment:楼层"`
 	Section    string `json:"section" gorm:"column:section;type:varchar(50);comment:区域"`
 	DeviceName string `json:"device_name" gorm:"column:device_name;type:varchar(100);comment:设备名称"`

+ 50 - 0
internal/service/hikvision.go

@@ -5,6 +5,7 @@ import (
 	"city_chips/internal/repository"
 	"encoding/json"
 	"errors"
+
 	"github.com/spf13/viper"
 	"github.com/zxbit2011/hikvisionOpenAPIGo"
 )
@@ -64,3 +65,52 @@ func (s *hikvisionService) DeviceResource(Device string) (error, model.DeviceRes
 	}
 	return nil, deviceResource
 }
+
+// GetRegionsRoot 获取根目录资源信息
+func (s *hikvisionService) GetRegionsRoot(Device string) (error, model.RegionsRoot) {
+	var regionsRoot model.RegionsRoot
+	hikvision, err := s.Hikvision(s.conf.GetString("hikvision.api.regionsRoot"), nil, 15)
+	if err != nil {
+		return errors.New("获取根目录资源失败"), regionsRoot
+	}
+	if hikvision.Code != "0" {
+		return errors.New("获取根目录资源失败"), regionsRoot
+	}
+	marshalString, err := json.Marshal(hikvision)
+	if err != nil {
+		return errors.New("json序列化失败"), regionsRoot
+	}
+	err = json.Unmarshal(marshalString, &regionsRoot)
+	if err != nil {
+		return errors.New("json反序列化失败"), regionsRoot
+	}
+	return nil, regionsRoot
+}
+
+// GetRegionsSubRegions 获取子目录资源信息
+func (s *hikvisionService) GetRegionsSubRegions(Device string) (error, model.RegionsSubRegions) {
+	var regionsSubRegions model.RegionsSubRegions
+	m := make(map[string]string)
+	m["pageNo"] = "1"
+	m["pageSize"] = s.conf.GetString("hikvision.pageSize")
+	m["parentIndexCode"] = "0"
+	m["resourceType"] = "0"
+	m["cascadeFlag"] = "0"
+
+	hikvision, err := s.Hikvision(s.conf.GetString("hikvision.api.regionsSubRegions"), m, 15)
+	if err != nil {
+		return errors.New("获取子目录资源信息失败"), regionsSubRegions
+	}
+	if hikvision.Code != "0" {
+		return errors.New("获取子目录资源信息失败"), regionsSubRegions
+	}
+	marshalString, err := json.Marshal(hikvision)
+	if err != nil {
+		return errors.New("json序列化失败"), regionsSubRegions
+	}
+	err = json.Unmarshal(marshalString, &regionsSubRegions)
+	if err != nil {
+		return errors.New("json反序列化失败"), regionsSubRegions
+	}
+	return nil, regionsSubRegions
+}