qixiaoning
2025-07-08 84d2ef9760af0a4a4aa933937294400b3caa291d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package models
 
import "errors"
 
//设备的行政区域 (设备是平台才会去获取行政区域-中间三位编码为200)
type VssDomainUnit struct {
    PublicID              string             `gorm:"column:publicId;not null;unique;" json:"publicId"`  //(字符串)   国标资源通道20位id (用于请求视频、控制等操作)
    DevPubID              string             `gorm:"column:devPubId" json:"devPubId"`  //(字符串)      通道的设备id
    ResType               int                `gorm:"column:resType" json:"resType"`   //(数字)     1-通道资源 2-资源组
    Name                  string             `gorm:"column:name;" json:"name"`      //(字符串)   资源名称
    ParentID              string             `gorm:"column:parentId" json:"parentId"`  //(字符串)      父节点id
    TotalNum              int                `gorm:"column:totalNum" json:"totalNum"`  //(数字) 资源组下总的数量
    OnlineNum             int                `gorm:"column:onlineNum" json:"onlineNum"` //(数字) 资源组下总的在线数量
}
 
func (VssDomainUnit) TableName() string {
    return "VSSDomainUnitTbl"
}
 
func (v *VssDomainUnit) Insert() (bool,error) {
    result := db.Table(v.TableName()).Create(&v)
    if result.Error != nil {
        return false, result.Error
    }
    if result.RowsAffected > 0 {
        return true, nil
    }
    return false, errors.New("新增失败")
}
 
func (v *VssDomainUnit) Update() (bool,error) {
    result := db.Table(v.TableName()).Save(&v)
    if result.Error != nil {
        return false, result.Error
    }
    if result.RowsAffected > 0 {
        return true, nil
    }
    return false, errors.New("更新失败")
}
 
func (v *VssDomainUnit) Exist(publicId string) bool {
    dbSelect := db.Table(v.TableName()).Where("publicId=?", publicId).First(&v)
    if dbSelect.Error != nil || dbSelect.RowsAffected ==0 {
        return false
    }
    return true
}
 
func (v *VssDomainUnit) FindAll() (list []VssDomainUnit, err error) {
    err = db.Table(v.TableName()).Find(&list).Error
    if err != nil {
        return []VssDomainUnit{}, err
    }
    return list,nil
}
 
func (v *VssDomainUnit) FindAllMap() map[string]VssDomainUnit {
    m := make(map[string]VssDomainUnit)
    list, _ := v.FindAll()
    for _, u := range list {
        m[u.PublicID] = u
    }
    return m
}