captureUintDao.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package dao
  2. import (
  3. "time"
  4. )
  5. //CaptureUint 抓拍单元
  6. type CaptureUint struct {
  7. ID int `gorm:"primary_key" json:"id"` //编号
  8. CaptureName string `gorm:"type:varchar(64)" json:"captureName"` //设备名称
  9. CaptureSN string `gorm:"type:varchar(60)" json:"captureSn"` //设备序列号
  10. PointId int `gorm:"type:int" json:"pointId"` //卡口ID
  11. LampPoleId int `gorm:"type:int" json:"lampPoleId"` //灯杆ID
  12. WayName string `gorm:"type:varchar(64)" json:"wayName"` //道路名称
  13. CaptureDirection int `gorm:"type:int" json:"captureDirection"` //灯杆sn
  14. InstallTime time.Time `gorm:"type:date" json:"installTime"` //安装时间
  15. TerrainClearance float32 `gorm:"type:float(10,1);default 0.0" json:"terrainClearance"` //离地高度(米)
  16. CaptureLane string `gorm:"type:varchar(120)" json:"captureLane"` //抓拍车道
  17. VidiconPixel int `gorm:"type:int" json:"vidiconPixel"` //相机像素
  18. VidiconSpecification string `gorm:"type:varchar(255)" json:"vidiconSpecification"` //相机规格
  19. RadarCount int `gorm:"type:int" json:"radarCount"` //雷达数量
  20. RadarSpecification string `gorm:"type:varchar(255)" json:"radar_specification"` //雷达规格
  21. SuggestSpeed int `gorm:"type:int" json:"suggestSpeed"` //雷达数量
  22. FillLightCount int `gorm:"type:int" json:"fillLightCount"` //补光灯数量
  23. FillLightSpecification string `gorm:"type:varchar(255)" json:"fillLightSpecification"` //补光灯规格
  24. PowerSpecification string `gorm:"type:varchar(255)" json:"powerSpecification"` //电源规格
  25. CaptureIp string `gorm:"type:varchar(60)" json:"captureIp"` //ip
  26. CapturePort int `gorm:"type:int" json:"capturePort"` //端口
  27. GatewayId int `gorm:"type:int" json:"gatewayId"` //网关ID
  28. GatewayName string `gorm:"type:varchar(80)" json:"gatewayName"` //网关名称
  29. GatewaySN string `gorm:"type:varchar(30)" json:"gatewaySn"` //网关编码
  30. TenantId string `gorm:"type:varchar(12)" json:"tenantId"` //租户ID
  31. CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
  32. CreateUser string `gorm:"type:varchar(30)" json:"createUser"` //新增记录操作用户ID
  33. UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"` //修改时间
  34. UpdateUser string `gorm:"type:varchar(30)" json:"updateUser"` //修改用户
  35. IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
  36. }
  37. func (CaptureUint) TableName() string {
  38. return "t_dev_capture_uint"
  39. }
  40. func (c CaptureUint) IsExistedBySN() bool {
  41. var count = 0
  42. _ = Db.Debug().Model(&c).Where("capture_sn = ? and is_deleted = ?",
  43. c.CaptureSN, c.IsDeleted).Count(&count).Error
  44. return count > 0
  45. }
  46. func (c *CaptureUint) Create() error {
  47. return Db.Debug().Model(&c).Save(&c).Error
  48. }
  49. func (c *CaptureUint) Update() error {
  50. return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
  51. }
  52. func (c *CaptureUint) GetDevice() error {
  53. err := Db.Debug().Model(&c).Where(" id = ? ", c.ID).First(&c).Error
  54. return err
  55. }
  56. func (c CaptureUint) GetDevices(offset, limit int) ([]CaptureUint, error) {
  57. var Captures []CaptureUint
  58. db := Db.Debug().Model(&c)
  59. if c.CaptureSN != "" {
  60. db = db.Where("capture_name like ? or capture_sn like ?", "%"+c.CaptureSN+"%", "%"+c.CaptureSN+"%")
  61. }
  62. err := db.Where("is_deleted = 0").Offset(offset).Limit(limit).Find(&Captures).Error
  63. return Captures, err
  64. }
  65. func (c *CaptureUint) Delete() error {
  66. return Db.Debug().Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime,
  67. "update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
  68. }
  69. func (c CaptureUint) GetAllDevices() ([]*CaptureUint, error) {
  70. var Captures []*CaptureUint
  71. err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&Captures).Error
  72. return Captures, err
  73. }