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
package models
 
import "errors"
 
//全部下级设备(平台或摄像机)信息列表
type VssDev struct {
    PublicID         string         `gorm:"column:publicId;not null;unique;" json:"publicId"` //国标设备20位id
     Name             string         `gorm:"column:name" json:"name"`     //资源名称
    IP                 string         `gorm:"column:ip" json:"ip"`        //ip
    Port             int         `gorm:"column:port" json:"port"`    //端口
    Corp             string         `gorm:"column:corp" json:"corp"`    //厂商
    ParentId         string         `gorm:"column:parentId" json:"parentId"`  //父节点id
    UserName         string         `gorm:"column:username" json:"username"`  //设备注册用户名
    Passwd             string         `gorm:"column:passwd" json:"passwd"`      //设备注册密码
    DevMode         string         `gorm:"column:devMode;default:'gb28181';" json:"devMode"`   //设备类型
    Alive             int         `gorm:"column:alive;default:0;" json:"alive"`   //状态 0:不在线 1:在线
}
 
func (VssDev) TableName() string {
    return "VSSDevTbl"
}
 
func (v *VssDev) 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 *VssDev) 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 *VssDev) 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 *VssDev) FindAll() (list []VssDev, err error) {
    err = db.Table(v.TableName()).Find(&list).Error
    if err != nil {
        return []VssDev{}, err
    }
    return list,nil
}