ai_summary.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. package ai_summary
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type AiSummary struct {
  8. AiSummaryId int `orm:"column(ai_summary_id);pk"` // ai纪要id
  9. SaDocId int // 文档ID
  10. OriginContent string // 原始内容
  11. SummaryContent string // 纪要内容
  12. ClassifyId int // 分类id
  13. SysUserId int // 创建人ID
  14. SysUserRealName string // 创建人姓名
  15. Title string // 文档标题
  16. CreateTime time.Time // 创建时间
  17. ModifyTime time.Time // 更新时间
  18. OpenaiFileName string // 文件名称
  19. OpenaiFilePath string // 文件路径
  20. OriginTitle string // 原文标题
  21. Sort int // 排序字段,越小越靠前,默认值:10
  22. }
  23. type AiSummaryItems struct {
  24. AiSummaryId int `orm:"column(ai_summary_id);pk"` // ai纪要id
  25. SaDocId int // 文档ID
  26. OriginContent string // 原始内容
  27. OriginTitle string // 原文标题
  28. SummaryContent string // 纪要内容
  29. ClassifyId int // 分类id
  30. SysUserId int // 创建人ID
  31. SysUserRealName string // 创建人姓名
  32. Title string // 文档标题
  33. CreateTime string // 创建时间
  34. ModifyTime string // 更新时间
  35. OpenaiFileName string // 文件名称
  36. OpenaiFilePath string // 文件路径
  37. Sort int // 排序字段,越小越靠前,默认值:10
  38. ParentIds string
  39. }
  40. func GetAiChatTopicList(sysUserId int) (item []*AiSummary, err error) {
  41. sql := ` SELECT * FROM ai_summary WHERE classify_id=? ORDER BY create_time DESC `
  42. o := orm.NewOrm()
  43. _, err = o.Raw(sql, sysUserId).QueryRows(&item)
  44. return
  45. }
  46. // GetAiSummaryById 根据纪要id获取详情
  47. func GetAiSummaryById(aiSummaryId int) (sandboxInfo *AiSummary, err error) {
  48. o := orm.NewOrm()
  49. sql := `select * from ai_summary where ai_summary_id = ? `
  50. err = o.Raw(sql, aiSummaryId).QueryRow(&sandboxInfo)
  51. return
  52. }
  53. // GetAiSummaryById 根据纪要id获取详情
  54. func GetAiSummaryItemById(aiSummaryId int) (sandboxInfo *AiSummaryItems, err error) {
  55. o := orm.NewOrm()
  56. sql := `select * from ai_summary where ai_summary_id = ? `
  57. err = o.Raw(sql, aiSummaryId).QueryRow(&sandboxInfo)
  58. return
  59. }
  60. // DelAiSummaryById 根据纪要id删除纪要
  61. func DelAiSummaryById(aiSummaryId int) (err error) {
  62. o := orm.NewOrm()
  63. sql := `delete from ai_summary where ai_summary_id = ? `
  64. _, err = o.Raw(sql, aiSummaryId).Exec()
  65. return
  66. }
  67. func MoveAiSummary(aiSummaryId, classifyId int) (err error) {
  68. o := orm.NewOrm()
  69. sql := ` UPDATE ai_summary
  70. SET
  71. classify_id = ?
  72. WHERE ai_summary_id = ?`
  73. _, err = o.Raw(sql, classifyId, aiSummaryId).Exec()
  74. return
  75. }
  76. // GetFirstAiSummaryByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  77. func GetFirstAiSummaryByClassifyId(classifyId int) (item *AiSummary, err error) {
  78. o := orm.NewOrm()
  79. sql := ` SELECT * FROM ai_summary WHERE classify_id=? order by sort asc,ai_summary_id asc limit 1`
  80. err = o.Raw(sql, classifyId).QueryRow(&item)
  81. return
  82. }
  83. // Update
  84. func (aiSummary *AiSummary) Update(cols []string) (err error) {
  85. o := orm.NewOrm()
  86. _, err = o.Update(aiSummary, cols...)
  87. return
  88. }
  89. // UpdateSandboxSortByClassifyId 根据纪要id更新排序
  90. func UpdateAiSummarySortByClassifyId(classifyId, nowSort, prevAiSummaryId int, updateSort string) (err error) {
  91. o := orm.NewOrm()
  92. sql := ` update ai_summary set sort = ` + updateSort + ` WHERE classify_id=? AND `
  93. if prevAiSummaryId > 0 {
  94. sql += ` (sort > ? or (ai_summary_id > ` + fmt.Sprint(prevAiSummaryId) + ` and sort = ` + fmt.Sprint(nowSort) + `))`
  95. }
  96. _, err = o.Raw(sql, classifyId, nowSort).Exec()
  97. return
  98. }
  99. func GetAiSummaryListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*AiSummaryItems, err error) {
  100. o := orm.NewOrm()
  101. sql := ` SELECT * FROM ai_summary WHERE 1=1 `
  102. if condition != "" {
  103. sql += condition
  104. }
  105. sql += " ORDER BY create_time DESC LIMIT ?,? "
  106. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
  107. return
  108. }
  109. func GetAiSummaryListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  110. o := orm.NewOrm()
  111. sql := ` SELECT COUNT(1) AS count FROM ai_summary WHERE 1=1 `
  112. if condition != "" {
  113. sql += condition
  114. }
  115. err = o.Raw(sql, pars).QueryRow(&count)
  116. return
  117. }
  118. func AddAiSummary(item *AiSummary) (lastId int64, err error) {
  119. o := orm.NewOrm()
  120. lastId, err = o.Insert(item)
  121. return
  122. }
  123. type AddAiSummaryReq struct {
  124. SaDocId int // 文档ID
  125. OriginContent string // 原始内容
  126. SummaryContent string // 纪要内容
  127. ClassifyId int // 分类id
  128. Title string // 文档标题
  129. OpenaiFileName string // 文件名称
  130. OpenaiFilePath string // 文件路径
  131. OriginTitle string // 原文标题
  132. }
  133. type GenerateAiSummaryReq struct {
  134. AiChatTopicId int `description:"主题id"`
  135. OriginContent string // 原始内容
  136. OpenaiFileId []string `description:"openai返回的文件id"`
  137. Model string `description:"模型名称"`
  138. Prompt string `description:"提示词"`
  139. SaDocId int // 文档ID
  140. }
  141. // GetAiSummaryMaxSort 获取ai纪要下最大的排序数
  142. func GetAiSummaryMaxSort(classifyId int) (sort int, err error) {
  143. o := orm.NewOrm()
  144. sql := `SELECT Max(sort) AS sort FROM ai_summary WHERE parent_id=? `
  145. err = o.Raw(sql, classifyId).QueryRow(&sort)
  146. return
  147. }
  148. type AiSummaryAddResp struct {
  149. AiSummaryId int
  150. UniqueCode string // 唯一编码
  151. ParentId int
  152. }
  153. type AiSummaryDetailResp struct {
  154. *AiSummaryItems
  155. SaDocTitle string `description:"文档库标题"`
  156. SaDocClassifyId int `description:"文档库分类id"`
  157. }