ai_pormpt.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package ai_summary
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type AiPrompt struct {
  7. AiPromptId int `orm:"column(ai_prompt_id);pk"` // ai纪要提示词id
  8. PromptContent string // 原始内容
  9. SysAdminId int // 创建人ID
  10. SysAdminName string // 创建人姓名
  11. Title string // 文档标题
  12. CreateTime time.Time // 创建时间
  13. ModifyTime time.Time // 更新时间
  14. IsShare int // 是否分享,0:不分享,1:分享
  15. Sort int // 排序
  16. }
  17. type AiPromptItem struct {
  18. AiPromptId int `orm:"column(ai_prompt_id);pk"` // ai纪要提示词id
  19. PromptContent string // 原始内容
  20. SysAdminId int // 创建人ID
  21. SysAdminName string // 创建人姓名
  22. Title string // 文档标题
  23. CreateTime string // 创建时间
  24. ModifyTime string // 更新时间
  25. IsShare int // 是否分享,0:不分享,1:分享
  26. Sort int // 排序
  27. }
  28. func GetAiPromptList(sysUserId, isShare int) (items []*AiPromptItem, err error) {
  29. sql := ``
  30. if isShare == 1 {
  31. sql = ` SELECT * FROM ai_prompt WHERE sys_admin_id=? and is_share=1 ORDER BY sort `
  32. } else {
  33. sql = ` SELECT * FROM ai_prompt WHERE sys_admin_id=? ORDER BY sort `
  34. }
  35. o := orm.NewOrm()
  36. _, err = o.Raw(sql, sysUserId).QueryRows(&items)
  37. return
  38. }
  39. func GetAiPromptShareList() (items []*AiPromptItem, err error) {
  40. sql := ``
  41. sql = ` SELECT * FROM ai_prompt WHERE is_share=1 ORDER BY create_time DESC `
  42. o := orm.NewOrm()
  43. _, err = o.Raw(sql).QueryRows(&items)
  44. return
  45. }
  46. type RespGroupListItem struct {
  47. GroupId int64 `description:"目录id"`
  48. GroupName string `description:"目录名称"`
  49. AdminId int `description:"目录创建者账号ID"`
  50. IsShare int8 `description:"是否共享,0私有,1共享"`
  51. PromptList []*AiPromptItem
  52. }
  53. type AiPromptAddReq struct {
  54. PromptContent string // 原始内容
  55. Title string // 文档标题
  56. }
  57. func AddPropmt(item *AiPrompt) (lastId int64, err error) {
  58. o := orm.NewOrm()
  59. lastId, err = o.Insert(item)
  60. return
  61. }
  62. type AiPromptEditReq struct {
  63. PromptContent string // 原始内容
  64. Title string // 文档标题
  65. AiPromptId int // ai纪要提示词id
  66. }
  67. // Update
  68. func (aiPrompt *AiPrompt) Update(cols []string) (err error) {
  69. o := orm.NewOrm()
  70. _, err = o.Update(aiPrompt, cols...)
  71. return
  72. }
  73. // DelAiSummaryById 根据纪要id删除纪要
  74. func DelAiPromptyId(aiPromptId int) (err error) {
  75. o := orm.NewOrm()
  76. sql := `delete from ai_prompt where ai_prompt_id = ? `
  77. _, err = o.Raw(sql, aiPromptId).Exec()
  78. return
  79. }
  80. func GetAiPromptById(promptId int) (item *AiPrompt, err error) {
  81. o := orm.NewOrm()
  82. sql := `SELECT * FROM ai_prompt WHERE 1=1 AND ai_prompt_id=? `
  83. err = o.Raw(sql, promptId).QueryRow(&item)
  84. return
  85. }
  86. type DeleteAipromptReq struct {
  87. AiPromptId int // ai纪要提示词id
  88. }
  89. type ReqMovePrompt struct {
  90. AiPromptId int `description:"当前被移动的目录里的ppt绑定序号"`
  91. PrevAiPromptId int `description:"上一个目录里的ppt绑定序号,ppt最终在目录中置顶,则传0值"`
  92. NextAiPromptId int `description:"下一个目录里的ppt绑定序号,ppt最终在目录末尾,则传0值"`
  93. }
  94. // GetAiPromptMaxSort 获取ai提示词下最大的排序数
  95. func GetAiPromptMaxSort(adminId int) (sort int, err error) {
  96. o := orm.NewOrm()
  97. sql := `SELECT Max(sort) AS sort FROM ai_prompt WHERE sys_admin_id=? `
  98. err = o.Raw(sql, adminId).QueryRow(&sort)
  99. return
  100. }
  101. // MoveDownPromptBySort 往下移动提示词
  102. func MoveDownPromptBySort(sysAdminId, prevSort, currentSort int) (err error) {
  103. o := orm.NewOrm()
  104. sql := `update ai_prompt set sort = sort - 1 where sys_admin_id = ? and sort <= ? and sort> ? `
  105. _, err = o.Raw(sql, sysAdminId, prevSort, currentSort).Exec()
  106. return
  107. }
  108. // MoveUpPromptBySort 往上移动提示词
  109. func MoveUpPromptBySort(sysAdminId, nextSort, currentSort int) (err error) {
  110. o := orm.NewOrm()
  111. sql := `update ai_prompt set sort = sort + 1 where sys_admin_id = ? and sort >= ? and sort< ?`
  112. _, err = o.Raw(sql, sysAdminId, nextSort, currentSort).Exec()
  113. return
  114. }