meta_info.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package user
  2. import (
  3. "eta_mini_ht_api/models"
  4. "gorm.io/gorm"
  5. "time"
  6. )
  7. type StatusType string
  8. type SourceType string
  9. type MetaType string
  10. const (
  11. UserNoticeType MetaType = "USER_NOTICE"
  12. InitStatusType StatusType = "INIT"
  13. PendingStatusType StatusType = "PENDING"
  14. FinishStatusType StatusType = "FINISH"
  15. FailedStatusType StatusType = "FAILED"
  16. ReportSourceType SourceType = "REPORT"
  17. VideoSourceType SourceType = "VIDEO"
  18. AudioSourceType SourceType = "AUDIO"
  19. )
  20. // MetaInfo 表示 meta_infos 表的模型
  21. type MetaInfo struct {
  22. Id int `gorm:"primaryKey;autoIncrement;column:id"`
  23. Uid string `gorm:"column:uid"`
  24. Meta string `gorm:"column:meta"`
  25. From string `gorm:"column:from"`
  26. To string `gorm:"column:to"`
  27. SourceType SourceType `gorm:"column:source_type;type:enum('REPORT','VIDEO','AUDIO')"`
  28. MetaType MetaType `gorm:"column:meta_type;type:enum('USER_NOTICE')"`
  29. Status StatusType `gorm:"column:status;type:enum('INIT','PENDING','FINISH','FAILED')"`
  30. CreatedTime time.Time
  31. UpdatedTime time.Time
  32. }
  33. func (mt *MetaInfo) BeforeCreate(_ *gorm.DB) (err error) {
  34. mt.CreatedTime = time.Now()
  35. mt.Status = InitStatusType
  36. return nil
  37. }
  38. func CreateMetaInfo(metaInfo MetaInfo) (err error) {
  39. db := models.Main()
  40. return db.Create(&metaInfo).Error
  41. }