ai_summary.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package ai_summary
  2. import (
  3. "errors"
  4. "eta/eta_api/models/ai_summary"
  5. "eta/eta_api/models/system"
  6. "eta/eta_api/utils"
  7. "strconv"
  8. )
  9. // GetAiSummaryClassifyListForMe 获取我创建的纪要
  10. func GetAiSummaryClassifyListForMe(adminInfo system.Admin, resp *ai_summary.AiSummaryClassifyListResp, ai_summaryClassifyId int) (errMsg string, err error) {
  11. rootList, err := ai_summary.GetAiSummaryClassifyByParentId(ai_summaryClassifyId)
  12. if err != nil && err.Error() != utils.ErrNoRow() {
  13. errMsg = "获取失败"
  14. return
  15. }
  16. for k := range rootList {
  17. rootList[k].UniqueCode = strconv.Itoa(rootList[k].AiSummaryClassifyId) + "_" + strconv.Itoa(rootList[k].AiSummaryId)
  18. }
  19. classifyAll, err := ai_summary.GetAiSummaryClassifyByParentId(ai_summaryClassifyId)
  20. if err != nil && err.Error() != utils.ErrNoRow() {
  21. errMsg = "获取失败"
  22. return
  23. }
  24. for k := range classifyAll {
  25. classifyAll[k].UniqueCode = strconv.Itoa(classifyAll[k].AiSummaryClassifyId) + "_" + strconv.Itoa(classifyAll[k].AiSummaryId)
  26. }
  27. ai_summaryAll, err := ai_summary.GetAiSummaryInfoByAdminId(adminInfo.AdminId)
  28. if err != nil && err.Error() != utils.ErrNoRow() {
  29. errMsg = "获取失败"
  30. return
  31. }
  32. for k := range ai_summaryAll {
  33. ai_summaryAll[k].UniqueCode = strconv.Itoa(ai_summaryAll[k].AiSummaryClassifyId) + "_" + strconv.Itoa(ai_summaryAll[k].AiSummaryId)
  34. }
  35. sandListMap := make(map[int][]*ai_summary.AiSummaryClassifyItems)
  36. for _, v := range ai_summaryAll {
  37. if _, ok := sandListMap[v.AiSummaryClassifyId]; !ok {
  38. list := make([]*ai_summary.AiSummaryClassifyItems, 0)
  39. list = append(list, v)
  40. sandListMap[v.AiSummaryClassifyId] = list
  41. } else {
  42. sandListMap[v.AiSummaryClassifyId] = append(sandListMap[v.AiSummaryClassifyId], v)
  43. }
  44. }
  45. nodeAll := make([]*ai_summary.AiSummaryClassifyItems, 0)
  46. for k := range rootList {
  47. rootNode := rootList[k]
  48. AiSummaryClassifyItemsMakeTree(&adminInfo, classifyAll, rootNode)
  49. nodeAll = append(nodeAll, rootNode)
  50. }
  51. newAll := AiSummaryItemsMakeTree(nodeAll, sandListMap, ai_summaryClassifyId)
  52. resp.AllNodes = newAll
  53. return
  54. }
  55. func aiSummaryClassifyHaveChild(allNode []*ai_summary.AiSummaryClassifyItems, node *ai_summary.AiSummaryClassifyItems) (childs []*ai_summary.AiSummaryClassifyItems, yes bool) {
  56. for _, v := range allNode {
  57. if v.ParentId == node.AiSummaryClassifyId {
  58. childs = append(childs, v)
  59. }
  60. }
  61. if len(childs) > 0 {
  62. yes = true
  63. }
  64. return
  65. }
  66. func AiSummaryClassifyItemsMakeTree(sysUser *system.Admin, allNode []*ai_summary.AiSummaryClassifyItems, node *ai_summary.AiSummaryClassifyItems) {
  67. childs, _ := aiSummaryClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
  68. if len(childs) > 0 {
  69. node.Children = append(node.Children, childs[0:]...) //添加子节点
  70. for _, v := range childs { //查询子节点的子节点,并添加到子节点
  71. _, has := aiSummaryClassifyHaveChild(allNode, v)
  72. if has {
  73. AiSummaryClassifyItemsMakeTree(sysUser, allNode, v) //递归添加节点
  74. } else {
  75. childrenArr := make([]*ai_summary.AiSummaryClassifyItems, 0)
  76. v.Children = childrenArr
  77. }
  78. }
  79. } else {
  80. childrenArr := make([]*ai_summary.AiSummaryClassifyItems, 0)
  81. node.Children = childrenArr
  82. }
  83. }
  84. func AiSummaryItemsMakeTree(allNode []*ai_summary.AiSummaryClassifyItems, sandListMap map[int][]*ai_summary.AiSummaryClassifyItems, sandboxClassifyId int) (nodeAll []*ai_summary.AiSummaryClassifyItems) {
  85. for k := range allNode {
  86. if len(allNode[k].Children) > 0 {
  87. AiSummaryItemsMakeTree(allNode[k].Children, sandListMap, sandboxClassifyId)
  88. allNode = append(allNode, sandListMap[allNode[k].ParentId]...)
  89. nodeAll = allNode
  90. } else if k == len(allNode)-1 {
  91. allNode = append(allNode, sandListMap[allNode[k].ParentId]...)
  92. nodeAll = allNode
  93. }
  94. }
  95. if len(allNode) == 0 {
  96. nodeAll = append(nodeAll, sandListMap[sandboxClassifyId]...)
  97. }
  98. return
  99. }
  100. func AiSummaryClassifyItemsMakeTreeV2(sysUser *system.Admin, allNode []*ai_summary.AiSummaryClassifyItems, node *ai_summary.AiSummaryClassifyItems) {
  101. childs, _ := aiSummaryClassifyHaveChildV2(allNode, node) //判断节点是否有子节点并返回
  102. if len(childs) > 0 {
  103. node.Children = append(node.Children, childs[0:]...) //添加子节点
  104. for _, v := range childs { //查询子节点的子节点,并添加到子节点
  105. _, has := aiSummaryClassifyHaveChildV2(allNode, v)
  106. if has {
  107. AiSummaryClassifyItemsMakeTreeV2(sysUser, allNode, v) //递归添加节点
  108. } else {
  109. //childrenArr := make([]*ai_summary.AiSummaryClassifyItems, 0)
  110. //v.Children = childrenArr
  111. }
  112. }
  113. } else {
  114. //childrenArr := make([]*ai_summary.AiSummaryClassifyItems, 0)
  115. //node.Children = childrenArr
  116. }
  117. }
  118. func aiSummaryClassifyHaveChildV2(allNode []*ai_summary.AiSummaryClassifyItems, node *ai_summary.AiSummaryClassifyItems) (childs []*ai_summary.AiSummaryClassifyItems, yes bool) {
  119. for _, v := range allNode {
  120. if v.ParentId == node.AiSummaryClassifyId && node.AiSummaryId == 0 {
  121. childs = append(childs, v)
  122. }
  123. }
  124. if len(childs) > 0 {
  125. yes = true
  126. }
  127. return
  128. }
  129. // SharePrompt
  130. func SharePrompt(promptId int, adminId int) (err error) {
  131. //判断当前登录者是否有共享的权限
  132. prompt, err := ai_summary.GetAiPromptById(promptId)
  133. if err != nil {
  134. if err.Error() == utils.ErrNoRow() {
  135. err = errors.New("当前目录下的提示词不存在")
  136. return
  137. }
  138. err = errors.New("目录下的提示词查询出错:" + err.Error())
  139. return
  140. }
  141. if prompt.SysAdminId != adminId {
  142. err = errors.New("该提示词不是本人创建")
  143. return
  144. }
  145. //判断当前的共享状态
  146. if prompt.IsShare > 0 {
  147. prompt.IsShare = 0
  148. err = prompt.Update([]string{"IsShare"})
  149. if err != nil {
  150. err = errors.New(err.Error())
  151. return
  152. }
  153. } else {
  154. prompt.IsShare = 1
  155. err = prompt.Update([]string{"IsShare"})
  156. if err != nil {
  157. err = errors.New(err.Error())
  158. return
  159. }
  160. }
  161. return
  162. }