package ai_summary import ( "errors" "eta_gn/eta_api/models/ai_summary" "eta_gn/eta_api/models/system" "eta_gn/eta_api/utils" "strconv" ) // GetAiSummaryClassifyListForMe 获取我创建的纪要 func GetAiSummaryClassifyListForMe(adminInfo system.Admin, resp *ai_summary.AiSummaryClassifyListResp, ai_summaryClassifyId int) (errMsg string, err error) { rootList, err := ai_summary.GetAiSummaryClassifyByParentId(ai_summaryClassifyId) if err != nil && !utils.IsErrNoRow(err) { errMsg = "获取失败" return } for k := range rootList { rootList[k].UniqueCode = strconv.Itoa(rootList[k].AiSummaryClassifyId) + "_" + strconv.Itoa(rootList[k].AiSummaryId) } classifyAll, err := ai_summary.GetAiSummaryClassifyByParentId(ai_summaryClassifyId) if err != nil && !utils.IsErrNoRow(err) { errMsg = "获取失败" return } for k := range classifyAll { classifyAll[k].UniqueCode = strconv.Itoa(classifyAll[k].AiSummaryClassifyId) + "_" + strconv.Itoa(classifyAll[k].AiSummaryId) } ai_summaryAll, err := ai_summary.GetAiSummaryInfoByAdminId(adminInfo.AdminId) if err != nil && !utils.IsErrNoRow(err) { errMsg = "获取失败" return } for k := range ai_summaryAll { ai_summaryAll[k].UniqueCode = strconv.Itoa(ai_summaryAll[k].AiSummaryClassifyId) + "_" + strconv.Itoa(ai_summaryAll[k].AiSummaryId) } sandListMap := make(map[int][]*ai_summary.AiSummaryClassifyItems) for _, v := range ai_summaryAll { if _, ok := sandListMap[v.AiSummaryClassifyId]; !ok { list := make([]*ai_summary.AiSummaryClassifyItems, 0) list = append(list, v) sandListMap[v.AiSummaryClassifyId] = list } else { sandListMap[v.AiSummaryClassifyId] = append(sandListMap[v.AiSummaryClassifyId], v) } } nodeAll := make([]*ai_summary.AiSummaryClassifyItems, 0) for k := range rootList { rootNode := rootList[k] AiSummaryClassifyItemsMakeTree(&adminInfo, classifyAll, rootNode) nodeAll = append(nodeAll, rootNode) } newAll := AiSummaryItemsMakeTree(nodeAll, sandListMap, ai_summaryClassifyId) resp.AllNodes = newAll return } func aiSummaryClassifyHaveChild(allNode []*ai_summary.AiSummaryClassifyItems, node *ai_summary.AiSummaryClassifyItems) (childs []*ai_summary.AiSummaryClassifyItems, yes bool) { for _, v := range allNode { if v.ParentId == node.AiSummaryClassifyId { childs = append(childs, v) } } if len(childs) > 0 { yes = true } return } func AiSummaryClassifyItemsMakeTree(sysUser *system.Admin, allNode []*ai_summary.AiSummaryClassifyItems, node *ai_summary.AiSummaryClassifyItems) { childs, _ := aiSummaryClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回 if len(childs) > 0 { node.Children = append(node.Children, childs[0:]...) //添加子节点 for _, v := range childs { //查询子节点的子节点,并添加到子节点 _, has := aiSummaryClassifyHaveChild(allNode, v) if has { AiSummaryClassifyItemsMakeTree(sysUser, allNode, v) //递归添加节点 } else { childrenArr := make([]*ai_summary.AiSummaryClassifyItems, 0) v.Children = childrenArr } } } else { childrenArr := make([]*ai_summary.AiSummaryClassifyItems, 0) node.Children = childrenArr } } func AiSummaryItemsMakeTree(allNode []*ai_summary.AiSummaryClassifyItems, sandListMap map[int][]*ai_summary.AiSummaryClassifyItems, sandboxClassifyId int) (nodeAll []*ai_summary.AiSummaryClassifyItems) { for k := range allNode { if len(allNode[k].Children) > 0 { AiSummaryItemsMakeTree(allNode[k].Children, sandListMap, sandboxClassifyId) allNode = append(allNode, sandListMap[allNode[k].ParentId]...) nodeAll = allNode } else if k == len(allNode)-1 { allNode = append(allNode, sandListMap[allNode[k].ParentId]...) nodeAll = allNode } } if len(allNode) == 0 { nodeAll = append(nodeAll, sandListMap[sandboxClassifyId]...) } return } func AiSummaryClassifyItemsMakeTreeV2(sysUser *system.Admin, allNode []*ai_summary.AiSummaryClassifyItems, node *ai_summary.AiSummaryClassifyItems) { childs, _ := aiSummaryClassifyHaveChildV2(allNode, node) //判断节点是否有子节点并返回 if len(childs) > 0 { node.Children = append(node.Children, childs[0:]...) //添加子节点 for _, v := range childs { //查询子节点的子节点,并添加到子节点 _, has := aiSummaryClassifyHaveChildV2(allNode, v) if has { AiSummaryClassifyItemsMakeTreeV2(sysUser, allNode, v) //递归添加节点 } else { } } } else { } } func aiSummaryClassifyHaveChildV2(allNode []*ai_summary.AiSummaryClassifyItems, node *ai_summary.AiSummaryClassifyItems) (childs []*ai_summary.AiSummaryClassifyItems, yes bool) { for _, v := range allNode { if v.ParentId == node.AiSummaryClassifyId && node.AiSummaryId == 0 { childs = append(childs, v) } } if len(childs) > 0 { yes = true } return } // SharePrompt func SharePrompt(promptId int, adminId int) (err error) { //判断当前登录者是否有共享的权限 prompt, err := ai_summary.GetAiPromptById(promptId) if err != nil { if utils.IsErrNoRow(err) { err = errors.New("当前目录下的提示词不存在") return } err = errors.New("目录下的提示词查询出错:" + err.Error()) return } if prompt.SysAdminId != adminId { err = errors.New("该提示词不是本人创建") return } //判断当前的共享状态 if prompt.IsShare > 0 { prompt.IsShare = 0 err = prompt.Update([]string{"IsShare"}) if err != nil { err = errors.New(err.Error()) return } } else { prompt.IsShare = 1 err = prompt.Update([]string{"IsShare"}) if err != nil { err = errors.New(err.Error()) return } } return } func GetSummaryClassifyChildIds(classifyId int, classifymap map[int]*ai_summary.AiSummaryClassifyItems, childIds *[]int) { for _, item := range classifymap { if item.ParentId == classifyId { *childIds = append(*childIds, item.AiSummaryClassifyId) GetSummaryClassifyChildIds(item.AiSummaryClassifyId, classifymap, childIds) } } } func GetSummaryParentIds(classifyId int, classifymap map[int]*ai_summary.AiSummaryClassifyItems, parentIds *[]int) { if item, ok := classifymap[classifyId]; ok { if item.ParentId == 0 { return } *parentIds = append(*parentIds, item.ParentId) GetSummaryParentIds(item.ParentId, classifymap, parentIds) } }