rag_eta_report.go 6.3 KB

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