|
@@ -697,4 +697,83 @@ func (this *AiPredictModelClassifyController) FrameworkList() {
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "获取成功"
|
|
|
+}
|
|
|
+
|
|
|
+// Tree
|
|
|
+// @Title 纯分类列表(不包含预测标的和模型框架)
|
|
|
+// @Description 纯分类列表
|
|
|
+// @Success 200 {object} aiPredictModel.AiPredictModelClassifyTreeResp
|
|
|
+// @router /classify/tree [get]
|
|
|
+func (this *AiPredictModelClassifyController) TreeList() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ if br.ErrMsg == "" {
|
|
|
+ br.IsSendEmail = false
|
|
|
+ }
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+
|
|
|
+ // 获取所有分类
|
|
|
+ classifyOb := new(aiPredictModel.AiPredictModelClassify)
|
|
|
+ classifies, e := classifyOb.GetItemsByCondition("", make([]interface{}, 0), []string{}, fmt.Sprintf("%s ASC, %s ASC", classifyOb.Cols().Sort, classifyOb.Cols().PrimaryId))
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取分类列表失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建父子关系映射
|
|
|
+ classifyMap := make(map[int]*aiPredictModel.AiPredictModelClassifyTreeItem)
|
|
|
+ childrenMap := make(map[int][]*aiPredictModel.AiPredictModelClassifyTreeItem)
|
|
|
+
|
|
|
+ // 第一遍遍历,构建基础节点和映射关系
|
|
|
+ for _, v := range classifies {
|
|
|
+ item := &aiPredictModel.AiPredictModelClassifyTreeItem{
|
|
|
+ ClassifyId: v.AiPredictModelClassifyId,
|
|
|
+ ClassifyName: v.ClassifyName,
|
|
|
+ ParentId: v.ParentId,
|
|
|
+ Level: v.Level,
|
|
|
+ Sort: v.Sort,
|
|
|
+ UniqueCode: v.UniqueCode,
|
|
|
+ Children: make([]*aiPredictModel.AiPredictModelClassifyTreeItem, 0),
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果是英文版本,使用英文名称
|
|
|
+ if this.Lang == utils.EnLangVersion {
|
|
|
+ item.ClassifyName = v.ClassifyNameEn
|
|
|
+ }
|
|
|
+
|
|
|
+ classifyMap[v.AiPredictModelClassifyId] = item
|
|
|
+ childrenMap[v.ParentId] = append(childrenMap[v.ParentId], item)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建树形结构
|
|
|
+ resp := new(aiPredictModel.AiPredictModelClassifyTreeResp)
|
|
|
+ resp.List = make([]*aiPredictModel.AiPredictModelClassifyTreeItem, 0)
|
|
|
+
|
|
|
+ // 获取顶级分类(ParentId = 0的节点)
|
|
|
+ if topLevelNodes, exists := childrenMap[0]; exists {
|
|
|
+ resp.List = topLevelNodes
|
|
|
+ // 递归构建子树
|
|
|
+ for _, node := range topLevelNodes {
|
|
|
+ buildSubTree(node, childrenMap)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Data = resp
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+}
|
|
|
+
|
|
|
+// buildSubTree 递归构建子树
|
|
|
+func buildSubTree(node *aiPredictModel.AiPredictModelClassifyTreeItem, childrenMap map[int][]*aiPredictModel.AiPredictModelClassifyTreeItem) {
|
|
|
+ if children, exists := childrenMap[node.ClassifyId]; exists {
|
|
|
+ node.Children = children
|
|
|
+ // 递归处理每个子节点
|
|
|
+ for _, child := range children {
|
|
|
+ buildSubTree(child, childrenMap)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|