rag_eta_report.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package rag
  2. import (
  3. "database/sql"
  4. "eta/eta_api/global"
  5. "eta/eta_api/utils"
  6. "fmt"
  7. "time"
  8. )
  9. // RagEtaReport eta报告
  10. type RagEtaReport struct {
  11. RagEtaReportID int `gorm:"primaryKey;column:rag_eta_report_id" json:"-"`
  12. ReportID int `gorm:"column:report_id" json:"reportId"` // 报告id
  13. ReportChapterID int `gorm:"column:report_chapter_id" json:"reportChapterId"` // 报告章节id
  14. Title string `gorm:"column:title" json:"title"` // 报告标题(完整标题,含期数)
  15. Author string `gorm:"column:author" json:"author"` // 作者
  16. TextContent string `gorm:"column:text_content" json:"textContent"` // 报告内容(去除html)
  17. VectorKey string `gorm:"column:vector_key" json:"vectorKey"` // 向量库的key
  18. PublishTime time.Time `gorm:"column:publish_time" json:"publishTime"` // 发布时间
  19. ModifyTime time.Time `gorm:"column:modify_time" json:"modifyTime"` // 修改时间
  20. CreateTime time.Time `gorm:"column:create_time" json:"createTime"` // 新增时间
  21. }
  22. // TableName get sql table name.获取数据库表名
  23. func (m *RagEtaReport) TableName() string {
  24. return "rag_eta_report"
  25. }
  26. // RagEtaReportColumns get sql column name.获取数据库列名
  27. var RagEtaReportColumns = struct {
  28. RagEtaReportID string
  29. ReportID string
  30. ReportChapterID string
  31. Title string
  32. Author string
  33. TextContent string
  34. VectorKey string
  35. PublishTime string
  36. ModifyTime string
  37. CreateTime string
  38. }{
  39. RagEtaReportID: "rag_eta_report_id",
  40. ReportID: "report_id",
  41. ReportChapterID: "report_chapter_id",
  42. Title: "title",
  43. Author: "author",
  44. TextContent: "text_content",
  45. VectorKey: "vector_key",
  46. PublishTime: "publish_time",
  47. ModifyTime: "modify_time",
  48. CreateTime: "create_time",
  49. }
  50. type RagEtaReportView struct {
  51. RagEtaReportID int `gorm:"primaryKey;column:rag_eta_report_id" json:"-"`
  52. ReportID int `gorm:"column:report_id" json:"reportId"` // 报告id
  53. ReportChapterID int `gorm:"column:report_chapter_id" json:"reportChapterId"` // 报告章节id
  54. Title string `gorm:"column:title" json:"title"` // 报告标题(完整标题,含期数)
  55. Author string `gorm:"column:author" json:"author"` // 作者
  56. TextContent string `gorm:"column:text_content" json:"textContent"` // 报告内容(去除html)
  57. VectorKey string `gorm:"column:vector_key" json:"vectorKey"` // 向量库的key
  58. PublishTime time.Time `gorm:"column:publish_time" json:"publishTime"` // 发布时间
  59. ModifyTime time.Time `gorm:"column:modify_time" json:"modifyTime"` // 修改时间
  60. CreateTime time.Time `gorm:"column:create_time" json:"createTime"` // 新增时间
  61. }
  62. func (m *RagEtaReport) ToView() RagEtaReportView {
  63. var publishTime, modifyTime, createTime string
  64. if !m.PublishTime.IsZero() {
  65. publishTime = m.PublishTime.Format(utils.FormatDateTime)
  66. }
  67. if !m.CreateTime.IsZero() {
  68. createTime = m.CreateTime.Format(utils.FormatDateTime)
  69. }
  70. if !m.ModifyTime.IsZero() {
  71. modifyTime = m.ModifyTime.Format(utils.FormatDateTime)
  72. }
  73. return RagEtaReportView{
  74. RagEtaReportID: 0,
  75. ReportID: 0,
  76. ReportChapterID: 0,
  77. Title: "",
  78. Author: "",
  79. TextContent: "",
  80. VectorKey: "",
  81. PublishTime: time.Time{},
  82. ModifyTime: time.Time{},
  83. CreateTime: time.Time{},
  84. }
  85. }
  86. func (m *RagEtaReport) ListToViewList(list []*RagEtaReport) (RagEtaReportViewList []RagEtaReportView) {
  87. RagEtaReportViewList = make([]RagEtaReportView, 0)
  88. for _, v := range list {
  89. RagEtaReportViewList = append(RagEtaReportViewList, v.ToView())
  90. }
  91. return
  92. }
  93. func (m *RagEtaReport) Create() (err error) {
  94. err = global.DbMap[utils.DbNameAI].Create(&m).Error
  95. return
  96. }
  97. func (m *RagEtaReport) Update(updateCols []string) (err error) {
  98. err = global.DbMap[utils.DbNameAI].Select(updateCols).Updates(&m).Error
  99. return
  100. }
  101. func (m *RagEtaReport) GetById(id int) (item *RagEtaReport, err error) {
  102. err = global.DbMap[utils.DbNameAI].Where(fmt.Sprintf("%s = ?", RagEtaReportColumns.RagEtaReportID), id).First(&item).Error
  103. return
  104. }
  105. func (m *RagEtaReport) GetListByCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*RagEtaReport, err error) {
  106. if field == "" {
  107. field = "*"
  108. }
  109. sqlStr := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 AND is_deleted=0 %s order by article_create_time desc,wechat_article_id desc LIMIT ?,?`, field, m.TableName(), condition)
  110. pars = append(pars, startSize, pageSize)
  111. err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Find(&items).Error
  112. return
  113. }
  114. func (m *RagEtaReport) GetCountByCondition(condition string, pars []interface{}) (total int, err error) {
  115. var intNull sql.NullInt64
  116. sqlStr := fmt.Sprintf(`SELECT COUNT(1) total FROM %s WHERE 1=1 AND is_deleted=0 %s`, m.TableName(), condition)
  117. err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Scan(&intNull).Error
  118. if err == nil && intNull.Valid {
  119. total = int(intNull.Int64)
  120. }
  121. return
  122. }
  123. func (m *RagEtaReport) GetPageListByCondition(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*RagEtaReport, err error) {
  124. total, err = m.GetCountByCondition(condition, pars)
  125. if err != nil {
  126. return
  127. }
  128. if total > 0 {
  129. items, err = m.GetListByCondition(`wechat_article_id,wechat_platform_id,fake_id,title,link,cover_url,description,country,province,city,article_create_time,modify_time,create_time`, condition, pars, startSize, pageSize)
  130. }
  131. return
  132. }