package ai_summary import ( "errors" "eta/eta_api/models/ai_summary" "eta/eta_api/models/system" "eta/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 && err.Error() != utils.ErrNoRow() { 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 && err.Error() != utils.ErrNoRow() { 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 && err.Error() != utils.ErrNoRow() { 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 { //childrenArr := make([]*ai_summary.AiSummaryClassifyItems, 0) //v.Children = childrenArr } } } else { //childrenArr := make([]*ai_summary.AiSummaryClassifyItems, 0) //node.Children = childrenArr } } 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 err.Error() == utils.ErrNoRow() { 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 GetAiSummaryClassifyByIsShowMe(classifyList []*ai_summary.AiSummaryClassifyItems, classifyId, adminId int) (list []*ai_summary.AiSummaryClassifyItems, err error) { aiSummaryList, err := ai_summary.GetAiSummaryInfoByAdminId(adminId) if err != nil { return } existClassify := make(map[int]struct{}) for _, v := range aiSummaryList { existClassify[v.AiSummaryClassifyId] = struct{}{} } for _, v := range classifyList { if v.AiSummaryId > 0 { v.ClassifyName = v.Title list = append(list, v) } } classifyAll, err := ai_summary.GetAiSummaryClassifyAllIncludeParent() if err != nil { return } classifyTree := aiSummaryClassifyTree(classifyAll, classifyId) list = append(list, GetClassifyListRemoveNoAiSummary(classifyTree, existClassify)...) return } func aiSummaryClassifyTree(classifyList []*ai_summary.AiSummaryClassifyItems, classifyId int) (list []*ai_summary.AiSummaryClassifyItems) { for _, v := range classifyList { if v.ParentId == classifyId { list = append(list, v) v.Children = aiSummaryClassifyTree(classifyList, v.AiSummaryClassifyId) } } return } // GetClassifyListRemoveNoAiSummary 去除没有表格的分类 func GetClassifyListRemoveNoAiSummary(classifyList []*ai_summary.AiSummaryClassifyItems, aiSummaryExistClassifyId map[int]struct{}) []*ai_summary.AiSummaryClassifyItems { res := make([]*ai_summary.AiSummaryClassifyItems, 0) for _, classify := range classifyList { if _, ok := aiSummaryExistClassifyId[classify.AiSummaryClassifyId]; ok { classify.Children = []*ai_summary.AiSummaryClassifyItems{} res = append(res, classify) continue } classify.Children = append([]*ai_summary.AiSummaryClassifyItems{}, GetClassifyListRemoveNoAiSummary(classify.Children, aiSummaryExistClassifyId)...) if len(classify.Children) > 0 { classify.Children = []*ai_summary.AiSummaryClassifyItems{} res = append(res, classify) } } return res }