ai_summary.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package ai_summary
  2. import (
  3. "errors"
  4. "eta_gn/eta_api/models/ai_summary"
  5. "eta_gn/eta_api/models/system"
  6. "eta_gn/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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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. }
  110. }
  111. } else {
  112. }
  113. }
  114. func aiSummaryClassifyHaveChildV2(allNode []*ai_summary.AiSummaryClassifyItems, node *ai_summary.AiSummaryClassifyItems) (childs []*ai_summary.AiSummaryClassifyItems, yes bool) {
  115. for _, v := range allNode {
  116. if v.ParentId == node.AiSummaryClassifyId && node.AiSummaryId == 0 {
  117. childs = append(childs, v)
  118. }
  119. }
  120. if len(childs) > 0 {
  121. yes = true
  122. }
  123. return
  124. }
  125. // SharePrompt
  126. func SharePrompt(promptId int, adminId int) (err error) {
  127. //判断当前登录者是否有共享的权限
  128. prompt, err := ai_summary.GetAiPromptById(promptId)
  129. if err != nil {
  130. if utils.IsErrNoRow(err) {
  131. err = errors.New("当前目录下的提示词不存在")
  132. return
  133. }
  134. err = errors.New("目录下的提示词查询出错:" + err.Error())
  135. return
  136. }
  137. if prompt.SysAdminId != adminId {
  138. err = errors.New("该提示词不是本人创建")
  139. return
  140. }
  141. //判断当前的共享状态
  142. if prompt.IsShare > 0 {
  143. prompt.IsShare = 0
  144. err = prompt.Update([]string{"IsShare"})
  145. if err != nil {
  146. err = errors.New(err.Error())
  147. return
  148. }
  149. } else {
  150. prompt.IsShare = 1
  151. err = prompt.Update([]string{"IsShare"})
  152. if err != nil {
  153. err = errors.New(err.Error())
  154. return
  155. }
  156. }
  157. return
  158. }
  159. func GetSummaryClassifyChildIds(classifyId int, classifymap map[int]*ai_summary.AiSummaryClassifyItems, childIds *[]int) {
  160. for _, item := range classifymap {
  161. if item.ParentId == classifyId {
  162. *childIds = append(*childIds, item.AiSummaryClassifyId)
  163. GetSummaryClassifyChildIds(item.AiSummaryClassifyId, classifymap, childIds)
  164. }
  165. }
  166. }
  167. func GetSummaryParentIds(classifyId int, classifymap map[int]*ai_summary.AiSummaryClassifyItems, parentIds *[]int) {
  168. if item, ok := classifymap[classifyId]; ok {
  169. if item.ParentId == 0 {
  170. return
  171. }
  172. *parentIds = append(*parentIds, item.ParentId)
  173. GetSummaryParentIds(item.ParentId, classifymap, parentIds)
  174. }
  175. }