camera.go 2.0 KB

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