rag_eta_report.go 5.7 KB

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