captureUintDao.go 4.6 KB

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