wechat_article_abstract.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package rag
  2. import (
  3. "database/sql"
  4. "eta/eta_api/global"
  5. "eta/eta_api/utils"
  6. "fmt"
  7. "time"
  8. )
  9. type WechatArticleAbstract struct {
  10. WechatArticleAbstractId int `gorm:"column:wechat_article_abstract_id;type:int(9) UNSIGNED;primaryKey;not null;" description:"wechat_article_abstract_id"`
  11. WechatArticleId int `gorm:"column:wechat_article_id;type:int(9) UNSIGNED;comment:关联的微信报告id;default:0;" description:"关联的微信报告id"`
  12. Content string `gorm:"column:content;type:longtext;comment:摘要内容;" description:"content"` // 摘要内容
  13. Version int `gorm:"column:version;type:int(10) UNSIGNED;comment:版本号;default:1;" description:"版本号"`
  14. VectorKey string `gorm:"column:vector_key;type:varchar(255);comment:向量key标识;" json:"vector_key"` // 向量key标识
  15. ModifyTime time.Time `gorm:"column:modify_time;type:datetime;default:NULL;" description:"modify_time"`
  16. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:NULL;" description:"create_time"`
  17. }
  18. // TableName get sql table name.获取数据库表名
  19. func (m *WechatArticleAbstract) TableName() string {
  20. return "wechat_article_abstract"
  21. }
  22. // WechatArticleAbstractColumns get sql column name.获取数据库列名
  23. var WechatArticleAbstractColumns = struct {
  24. WechatArticleAbstractID string
  25. WechatArticleID string
  26. Content string
  27. Version string
  28. ModifyTime string
  29. CreateTime string
  30. }{
  31. WechatArticleAbstractID: "wechat_article_abstract_id",
  32. WechatArticleID: "wechat_article_id",
  33. Content: "content",
  34. Version: "version",
  35. ModifyTime: "modify_time",
  36. CreateTime: "create_time",
  37. }
  38. func (m *WechatArticleAbstract) Create() (err error) {
  39. err = global.DbMap[utils.DbNameAI].Create(&m).Error
  40. return
  41. }
  42. func (m *WechatArticleAbstract) Update(updateCols []string) (err error) {
  43. err = global.DbMap[utils.DbNameAI].Select(updateCols).Updates(&m).Error
  44. return
  45. }
  46. func (m *WechatArticleAbstract) GetById(id int) (item *WechatArticleAbstract, err error) {
  47. err = global.DbMap[utils.DbNameAI].Where(fmt.Sprintf("%s = ?", WechatArticleAbstractColumns.WechatArticleAbstractID), id).First(&item).Error
  48. return
  49. }
  50. // GetByWechatArticleId
  51. // @Description: 根据报告id获取摘要
  52. // @author: Roc
  53. // @receiver m
  54. // @datetime 2025-03-07 10:00:59
  55. // @param id int
  56. // @return item *WechatArticleAbstract
  57. // @return err error
  58. func (m *WechatArticleAbstract) GetByWechatArticleId(id int) (item *WechatArticleAbstract, err error) {
  59. err = global.DbMap[utils.DbNameAI].Where(fmt.Sprintf("%s = ?", WechatArticleAbstractColumns.WechatArticleID), id).Order(fmt.Sprintf(`%s DESC`, WechatArticleAbstractColumns.WechatArticleAbstractID)).First(&item).Error
  60. return
  61. }
  62. func (m *WechatArticleAbstract) GetListByPlatformCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*WechatArticleAndPlatform, err error) {
  63. if field == "" {
  64. field = "*"
  65. }
  66. sqlStr := fmt.Sprintf(`SELECT %s FROM %s AS a
  67. JOIN wechat_platform AS b ON a.wechat_platform_id=b.wechat_platform_id
  68. JOIN wechat_platform AS b ON a.wechat_platform_id=b.wechat_platform_id
  69. WHERE 1=1 AND a.is_deleted=0 %s order by a.article_create_time DESC,a.wechat_article_id DESC LIMIT ?,?`, field, m.TableName(), condition)
  70. pars = append(pars, startSize, pageSize)
  71. err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Find(&items).Error
  72. return
  73. }
  74. func (m *WechatArticleAbstract) GetCountByPlatformCondition(condition string, pars []interface{}) (total int, err error) {
  75. var intNull sql.NullInt64
  76. sqlStr := fmt.Sprintf(`SELECT COUNT(1) total FROM %s AS a
  77. JOIN wechat_platform AS b ON a.wechat_platform_id=b.wechat_platform_id
  78. WHERE 1=1 AND a.is_deleted=0 %s`, m.TableName(), condition)
  79. err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Scan(&intNull).Error
  80. if err == nil && intNull.Valid {
  81. total = int(intNull.Int64)
  82. }
  83. return
  84. }
  85. func (m *WechatArticleAbstract) GetPageListByPlatformCondition(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*WechatArticleAndPlatform, err error) {
  86. total, err = m.GetCountByPlatformCondition(condition, pars)
  87. if err != nil {
  88. return
  89. }
  90. if total > 0 {
  91. items, err = m.GetListByPlatformCondition(`a.wechat_article_id,a.wechat_platform_id,a.fake_id,a.title,a.link,a.cover_url,a.description,a.country,a.province,a.city,a.article_create_time,a.modify_time,a.create_time,b.nickname,b.round_head_img`, condition, pars, startSize, pageSize)
  92. }
  93. return
  94. }