captureOverSpeedDao.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package dao
  2. import (
  3. "errors"
  4. "gorm.io/gorm"
  5. "iot_manager_service/app/operation/model"
  6. "iot_manager_service/util/common"
  7. )
  8. type CaptureOverSpeed struct {
  9. ID int `gorm:"comment:ID" json:"id"`
  10. CaptureSn string `gorm:"comment:抓拍单元SN" json:"code"`
  11. Time common.Time `gorm:"comment:抓拍时间;type:datetime" json:"time"`
  12. Vtype int `gorm:"comment:车类型" json:"vtype"`
  13. Plate string `gorm:"comment:车牌号" json:"plate"`
  14. Speed int `gorm:"comment:速度" json:"speed"`
  15. Sflag int `gorm:"comment:速度比率" json:"sflag"`
  16. }
  17. func (c CaptureOverSpeed) TableName() string {
  18. return "data_capture_over_speed"
  19. }
  20. // GetMaxIdAndUpDateTime 得到最大同步 ID
  21. func (c CaptureOverSpeed) GetMaxIdAndUpDateTime() (int64, string) {
  22. var captureOverSpeed CaptureOverSpeed
  23. err := Db.Debug().Model(&c).Last(&captureOverSpeed).Error
  24. if err != nil {
  25. return 0, ""
  26. }
  27. return int64(captureOverSpeed.ID), captureOverSpeed.Time.String()
  28. }
  29. // BatchCreate 批量插入
  30. func (c CaptureOverSpeed) BatchCreate(his []CaptureOverSpeed) error {
  31. return Db.Debug().Model(&c).CreateInBatches(his, 1000).Error
  32. }
  33. // Gets 记录列表
  34. func (c CaptureOverSpeed) Gets(captureSn string, req model.RequestCaptureOverSpeed) ([]CaptureOverSpeed, int64, error) {
  35. //fmt.Printf("size = %v \n", size)
  36. //fmt.Printf("current = %v \n", current)
  37. var list []CaptureOverSpeed
  38. db := Db.Debug().Model(&c).Where(&CaptureOverSpeed{CaptureSn: captureSn})
  39. db.Where("time between ? and ?", req.StartTime+" 00:00:00", req.EndTime+" 23:59:59")
  40. var count int64
  41. db.Count(&count)
  42. db = db.Scopes(common.Paginate(req.Current, req.Size))
  43. err := db.Order("id desc").Find(&list).Error
  44. if errors.Is(err, gorm.ErrRecordNotFound) {
  45. err = nil
  46. }
  47. //fmt.Printf("count = %v", count)
  48. return list, count, err
  49. }