article_kb_mapping.go 932 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package rag
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "gorm.io/gorm/clause"
  6. "time"
  7. )
  8. type ArticleKbMapping struct {
  9. Id int `gorm:"id;primaryKey"`
  10. WechatArticleId int
  11. Source int
  12. KbId string
  13. CreatedTime time.Time
  14. UpdateTime time.Time
  15. }
  16. func (a *ArticleKbMapping) TableName() string {
  17. return "article_kb_mapping"
  18. }
  19. func GetArticleKbMapping(articleId, source int) (articleKbMapping *ArticleKbMapping, err error) {
  20. err = global.DbMap[utils.DbNameAI].Where("wechat_article_id = ? AND source = ? ", articleId, source).First(&articleKbMapping).Error
  21. return
  22. }
  23. func CreateArticleKbMapping(articleKbMapping ArticleKbMapping) (err error) {
  24. db := global.DbMap[utils.DbNameAI]
  25. db.Clauses(
  26. clause.OnConflict{
  27. DoNothing: true,
  28. Columns: []clause.Column{{Name: "wechat_article_id"}},
  29. },
  30. )
  31. err = global.DbMap[utils.DbNameAI].Create(&articleKbMapping).Error
  32. return
  33. }