ai_summary.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. func GetAiSummaryById(aiSummaryId int) (sandboxInfo *AiSummary, err error) {
  41. sql := `select * from ai_summary where ai_summary_id = ? `
  42. err = global.DEFAULT_DmSQL.Raw(sql, aiSummaryId).First(&sandboxInfo).Error
  43. return
  44. }
  45. func GetAiSummaryItemById(aiSummaryId int) (sandboxInfo *AiSummaryItems, err error) {
  46. sql := `select * from ai_summary where ai_summary_id = ? `
  47. err = global.DEFAULT_DmSQL.Raw(sql, aiSummaryId).First(&sandboxInfo).Error
  48. return
  49. }
  50. func DelAiSummaryById(aiSummaryId int) (err error) {
  51. sql := `delete from ai_summary where ai_summary_id = ? `
  52. err = global.DEFAULT_DmSQL.Exec(sql, aiSummaryId).Error
  53. return
  54. }
  55. func MoveAiSummary(aiSummaryId, classifyId int) (err error) {
  56. sql := `UPDATE ai_summary SET classify_id = ? WHERE ai_summary_id = ?`
  57. err = global.DEFAULT_DmSQL.Exec(sql, classifyId, aiSummaryId).Error
  58. return
  59. }
  60. func GetFirstAiSummaryByClassifyId(classifyId int) (item *AiSummary, err error) {
  61. sql := ` SELECT * FROM ai_summary WHERE classify_id=? order by sort asc,ai_summary_id asc limit 1`
  62. err = global.DEFAULT_DmSQL.Raw(sql, classifyId).First(&item).Error
  63. return
  64. }
  65. func (aiSummary *AiSummary) Update(cols []string) (err error) {
  66. err = global.DEFAULT_DmSQL.Select(cols).Updates(aiSummary).Error
  67. return
  68. }
  69. func UpdateAiSummarySortByClassifyId(classifyId, nowSort, prevAiSummaryId int, updateSort string) (err error) {
  70. sql := ` update ai_summary set sort = ` + updateSort + ` WHERE classify_id=? AND `
  71. if prevAiSummaryId > 0 {
  72. sql += ` (sort > ? or (ai_summary_id > ` + fmt.Sprint(prevAiSummaryId) + ` and sort = ` + fmt.Sprint(nowSort) + `))`
  73. }
  74. err = global.DEFAULT_DmSQL.Exec(sql, classifyId, nowSort).Error
  75. return
  76. }
  77. func GetAiSummaryListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*AiSummaryItems, err error) {
  78. sql := ` SELECT * FROM ai_summary WHERE 1=1 `
  79. if condition != "" {
  80. sql += condition
  81. }
  82. sql += " ORDER BY create_time DESC LIMIT ?,? "
  83. pars = append(pars, startSize)
  84. pars = append(pars, pageSize)
  85. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&item).Error
  86. return
  87. }
  88. func GetAiSummaryListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  89. sql := ` SELECT COUNT(1) AS count FROM ai_summary WHERE 1=1 `
  90. if condition != "" {
  91. sql += condition
  92. }
  93. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
  94. return
  95. }
  96. func AddAiSummary(item *AiSummary) (lastId int64, err error) {
  97. err = global.DEFAULT_DmSQL.Create(item).Error
  98. lastId = int64(item.AiSummaryId)
  99. return
  100. }
  101. type AddAiSummaryReq struct {
  102. SaDocId int // 文档ID
  103. OriginContent string // 原始内容
  104. SummaryContent string // 纪要内容
  105. ClassifyId int // 分类id
  106. Title string // 文档标题
  107. OpenaiFileName string // 文件名称
  108. OpenaiFilePath string // 文件路径
  109. OriginTitle string // 原文标题
  110. }
  111. type GenerateAiSummaryReq struct {
  112. AiChatTopicId int `description:"主题id"`
  113. OriginContent string // 原始内容
  114. OpenaiFileId []string `description:"openai返回的文件id"`
  115. Model string `description:"模型名称"`
  116. Prompt string `description:"提示词"`
  117. SaDocId int // 文档ID
  118. }
  119. func GetAiSummaryMaxSort(classifyId int) (sort int, err error) {
  120. sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM ai_summary WHERE parent_id=? `
  121. err = global.DEFAULT_DmSQL.Raw(sql, classifyId).Scan(&sort).Error
  122. return
  123. }
  124. type AiSummaryAddResp struct {
  125. AiSummaryId int
  126. UniqueCode string // 唯一编码
  127. ParentId int
  128. }
  129. type AiSummaryDetailResp struct {
  130. *AiSummaryItems
  131. SaDocTitle string `description:"文档库标题"`
  132. SaDocClassifyId int `description:"文档库分类id"`
  133. }
  134. func GetSummaryCountByCondition(condition string, pars []interface{}) (count int, err error) {
  135. sql := ` SELECT COUNT(1) AS count FROM ai_summary WHERE 1=1 `
  136. if condition != "" {
  137. sql += condition
  138. }
  139. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
  140. return
  141. }