promote_train_record.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package rag
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "time"
  6. )
  7. type PromoteTrainRecord struct {
  8. Id int `gorm:"id;primaryKey"`
  9. Title string `gorm:"title"`
  10. Llm string `gorm:"llm"`
  11. Source int `gorm:"source" description:"来源,0:公众号文章,1:eta报告"`
  12. WechatArticleId int `gorm:"wechat_article_id"`
  13. TemplatePromote string `gorm:"template_promote"`
  14. PromoteSendTime time.Time `gorm:"promote_send_time"`
  15. AigcContent string `gorm:"aigc_content"`
  16. AigcSendTime time.Time `gorm:"aigc_send_time"`
  17. IsDeleted bool `gorm:"is_deleted"`
  18. CreatedTime time.Time `gorm:"created_time"`
  19. UpdateTime time.Time `gorm:"update_time"`
  20. }
  21. func (p *PromoteTrainRecord) ToView() *PromoteTrainRecordView {
  22. return &PromoteTrainRecordView{
  23. Id: p.Id,
  24. Title: p.Title,
  25. Llm: p.Llm,
  26. Source: p.Source,
  27. WechatArticleId: p.WechatArticleId,
  28. TemplatePromote: p.TemplatePromote,
  29. PromoteSendTime: p.PromoteSendTime.Format(utils.FormatDateTime),
  30. AigcContent: p.AigcContent,
  31. AigcSendTime: p.AigcSendTime.Format(utils.FormatDateTime),
  32. }
  33. }
  34. type PromoteTrainRecordView struct {
  35. Id int
  36. Title string
  37. Llm string
  38. Source int
  39. WechatArticleId int
  40. TemplatePromote string
  41. PromoteSendTime string
  42. AigcContent string
  43. AigcSendTime string
  44. }
  45. func (p *PromoteTrainRecord) TableName() string {
  46. return "promote_train_record"
  47. }
  48. func (p *PromoteTrainRecord) SaveContent() error {
  49. return global.DbMap[utils.DbNameAI].Create(p).Error
  50. }
  51. func DeleteContent(id int) error {
  52. return global.DbMap[utils.DbNameAI].Model(&PromoteTrainRecord{}).Where("id = ?", id).Update("is_deleted", true).Error
  53. }
  54. func GetRecordList(wechatArticleId, source int) (list []*PromoteTrainRecordView, err error) {
  55. var ormList []PromoteTrainRecord
  56. err = global.DbMap[utils.DbNameAI].Model(&PromoteTrainRecord{}).Where("wechat_article_id = ? AND source = ? and is_deleted=?", wechatArticleId, source, false).Order(`created_time DESC`).Find(&ormList).Error
  57. if err != nil {
  58. return
  59. }
  60. for _, item := range ormList {
  61. list = append(list, item.ToView())
  62. }
  63. return
  64. }