cameraDto.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package dao
  2. import "time"
  3. //CameraDevice 网关下挂载的设备, 摄像头
  4. type CameraDevice struct {
  5. ID string `gorm:"type:int;comment '编号';primary_key"`
  6. Name string `gorm:"type:varchar(64);comment '设备名称'"`
  7. GatewayId string `gorm:"type:varchar(32);comment '所属网关'"`
  8. IP string `gorm:"type:varchar(40);null;comment 'IP地址'"`
  9. SN string `gorm:"type:varchar(64);comment '设备序列号'"`
  10. CameraType int `gorm:"type:int;null;comment '摄像机类型 0=枪机,1=球机'"`
  11. Brand int `gorm:"type:int;null; comment '设备品牌'"`
  12. Model int `gorm:"type:int;null; comment '设备型号'"`
  13. GroupId int `gorm:"type:int;null;comment '灯杆分组ID'"`
  14. LampPoleId int `gorm:"type:int;null;comment '归属灯杆 灯杆ID'"`
  15. LampPoleName string `gorm:"type:varchar(64);null;comment '灯杆名称'"`
  16. LampPoleSn string `gorm:"type:varchar(64);null;comment '灯杆sn'"`
  17. LampPoleLocation string `gorm:"type:varchar(255);null;comment '灯杆安装位置'"`
  18. LampLat float64 `gorm:"type:double(17,14);null; comment '经度'"`
  19. LampLng float64 `gorm:"type:double(17,14) null; comment '纬度'"`
  20. RatedPower float32 `gorm:"type:float(8,2) null; comment '功率'"`
  21. MonitorAddress string `gorm:"type:varchar(255);null;comment '监控地址 ip:端口'"`
  22. DevType int `gorm:"type:int;null;comment '3摄像机'"`
  23. Tenant string `gorm:"type:varchar(8);null;comment '租户ID"`
  24. InstallTime time.Time `gorm:"type:date;null;comment '安装时间'"`
  25. CreateTime time.Time `gorm:"type:datetime;null;comment '新增时间'"`
  26. CreateUser string `gorm:"type:varchar(60);null;comment '新增记录操作用户ID'"`
  27. UpdateTime time.Time `gorm:"type:datetime;null;comment '修改时间'"`
  28. UpdateUser string `gorm:"type:varchar(60)"` //修改用户
  29. IsDeleted int `gorm:"type:int"` //是否删除 0=未删除,1=删除
  30. Status int `gorm:"type:int"` //状态 0=正常,1=异常
  31. Tag string `gorm:"type:varchar(255)"` //标签,(备用,逗号区分)
  32. IsEnable int `gorm:"type:int;default 2"` // 启用禁用:1启用,2禁用
  33. StreamId string `gorm:"type:varchar(100)"` // 流id
  34. }
  35. func (CameraDevice) TableName() string {
  36. return "t_dev_camera"
  37. }
  38. func (c CameraDevice) Delete() error {
  39. return GDb.Model(&c).Updates(map[string]interface{}{"state": 0}).Error
  40. }
  41. func (c CameraDevice) IsExistedByCode() (bool, error) {
  42. var count = 0
  43. err := GDb.Model(&c).Where(" id = ? ", c.ID).Count(&count).Error
  44. return count > 0, err
  45. }
  46. func (c CameraDevice) SaveFromWeb() error {
  47. has, err := c.IsExistedByCode()
  48. if err != nil {
  49. return err
  50. }
  51. if has { //更新
  52. return GDb.Model(&c).Updates(map[string]interface{}{"name": c.Name, "gateway_id": c.GatewayId,
  53. "dev_type": c.DevType, "tenant": c.Tenant, "state": c.Status}).Error
  54. } else { //插入
  55. return GDb.Create(&c).Error
  56. }
  57. }
  58. func (c CameraDevice) GetCameraDevice() error {
  59. err := GDb.Model(&c).Where(" id = ? ", c.ID).Scan(&c).Error
  60. return err
  61. }