ai_summary.go 7.9 KB

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