12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package dao
- //网关下挂载的设备串口设备,如485接口的设备,数据来自设备上报
- type CameraDevice struct {
- ID string `gorm:"type:varchar(32);primary_key"` //设备ID,DID
- Name string `gorm:"type:varchar(64)"` //设备名称
- GID string `gorm:"type:varchar(32)"` //网关ID
- IP string `gorm:"type:varchar(40)"` //ip
- SN string `gorm:"type:varchar(64)"` //设备序列号
- Brand string `gorm:"type:varchar(24)"` //设备品牌
- Model string `gorm:"type:varchar(32)"` //设备型号
- DevType int `gorm:"type:int"` //3摄象机,4一键报警(带视频)
- User string `gorm:"type:varchar(32)"` //onvif用户名
- Password string `gorm:"type:varchar(64)"` //onvif密码
- RtmpServer string `gorm:"type:varchar(256)"` //流地址
- WebServer string `gorm:"type:varchar(256)"` //web地址
- Event string `gorm:"type:varchar(128)"` //需要订阅的事件主题
- Gb28181 bool `gorm:"type:bool"` //国标28181,是否已开启GB28181
- Tenant string `gorm:"type:varchar(8)"` //租户ID
- State int `gorm:"type:int"` //1启用,0禁用
- LcModel
- }
- func (CameraDevice) TableName() string {
- return "t_device_camera"
- }
- func (c CameraDevice) Delete() error {
- return G_db.Model(&c).Updates(map[string]interface{}{"state": 0}).Error
- }
- func (c CameraDevice) IsExistedByCode() (bool, error) {
- var count = 0
- err := G_db.Model(&c).Where(" id = ? ", c.ID).Count(&count).Error
- return count > 0, err
- }
- func (c CameraDevice) SaveFromWeb() error {
- has, err := c.IsExistedByCode()
- if err != nil {
- return err
- }
- if has { //更新
- return G_db.Model(&c).Updates(map[string]interface{}{"name": c.Name, "g_id": c.GID,
- "dev_type": c.DevType, "tenant": c.Tenant, "state": c.State}).Error
- } else { //插入
- return G_db.Create(&c).Error
- }
- }
|