meta_info.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package message
  2. import (
  3. logger "eta/eta_mini_ht_api/common/component/log"
  4. "eta/eta_mini_ht_api/models"
  5. "gorm.io/gorm"
  6. "time"
  7. )
  8. type StatusType string
  9. type SourceType string
  10. type MetaType string
  11. const (
  12. UserNoticeType MetaType = "USER_NOTICE"
  13. SysUserNoticeType MetaType = "SYS_USER_NOTICE"
  14. InitStatusType StatusType = "INIT"
  15. PendingStatusType StatusType = "PENDING"
  16. FinishStatusType StatusType = "FINISH"
  17. FailedStatusType StatusType = "FAILED"
  18. ReportSourceType SourceType = "REPORT"
  19. VideoSourceType SourceType = "VIDEO"
  20. AudioSourceType SourceType = "AUDIO"
  21. RefundSourceType SourceType = "REFUND"
  22. )
  23. // MetaInfo 表示 meta_infos 表的模型
  24. type MetaInfo struct {
  25. Id int `gorm:"primaryKey;autoIncrement;column:id"`
  26. Meta string `gorm:"column:meta"`
  27. From string `gorm:"column:from"`
  28. To string `gorm:"column:to"`
  29. SourceType SourceType `gorm:"column:source_type;type:enum('REPORT','VIDEO','AUDIO','REFUND')"`
  30. MetaType MetaType `gorm:"column:meta_type;type:enum('USER_NOTICE')"`
  31. Status StatusType `gorm:"column:status;type:enum('INIT','PENDING','FINISH','FAILED')"`
  32. CreatedTime time.Time
  33. UpdatedTime time.Time
  34. }
  35. type MetaData struct {
  36. SourceId int `json:"reportId"`
  37. AuthorId int `json:"AuthorId"`
  38. AuthorName string `json:"authorName"`
  39. PublishedTime string `json:"publishedTime"`
  40. }
  41. type RefundMetaData struct {
  42. RealName string `json:"realName,omitempty"`
  43. ProductOrderNo string `json:"productOrderNo,omitempty"`
  44. Result string `json:"result,omitempty"`
  45. }
  46. func (mt *MetaInfo) BeforeCreate(_ *gorm.DB) (err error) {
  47. mt.CreatedTime = time.Now()
  48. mt.Status = InitStatusType
  49. return nil
  50. }
  51. func CreateMetaInfo(metaInfo MetaInfo) (err error) {
  52. db := models.Main()
  53. return db.Create(&metaInfo).Error
  54. }
  55. func GetInitMetaInfos() (list []MetaInfo) {
  56. db := models.Main()
  57. err := db.Where("status = ?", InitStatusType).Order("id asc").Limit(100).Find(&list).Error
  58. if err != nil {
  59. logger.Error("获取meta数据失败:%v", err)
  60. return []MetaInfo{}
  61. }
  62. return list
  63. }
  64. func PendingMetaInfo(id int) bool {
  65. return updateStatus(id, PendingStatusType)
  66. }
  67. func FinishMetaInfo(id int) bool {
  68. return updateStatus(id, FinishStatusType)
  69. }
  70. func FailedMetaInfo(id int) bool {
  71. return updateStatus(id, FailedStatusType)
  72. }
  73. func updateStatus(id int, status StatusType) bool {
  74. db := models.Main()
  75. err := db.Model(&MetaInfo{}).Where("id = ?", id).Update("status", status).Error
  76. if err != nil {
  77. logger.Error("更新meta数据失败:%v", err)
  78. return false
  79. }
  80. return true
  81. }