article_kb_mapping.go 879 B

12345678910111213141516171819202122232425262728293031323334353637
  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. KbId string
  12. CreatedTime time.Time
  13. UpdateTime time.Time
  14. }
  15. func (a *ArticleKbMapping) TableName() string {
  16. return "article_kb_mapping"
  17. }
  18. func GetArticleKbMapping(articleId int) (articleKbMapping *ArticleKbMapping, err error) {
  19. err = global.DbMap[utils.DbNameAI].Where("wechat_article_id = ?", articleId).First(&articleKbMapping).Error
  20. return
  21. }
  22. func CreateArticleKbMapping(articleKbMapping ArticleKbMapping) (err error) {
  23. db := global.DbMap[utils.DbNameAI]
  24. db.Clauses(
  25. clause.OnConflict{
  26. DoNothing: true,
  27. Columns: []clause.Column{{Name: "wechat_article_id"}},
  28. },
  29. )
  30. err = global.DbMap[utils.DbNameAI].Create(&articleKbMapping).Error
  31. return
  32. }