Parcourir la source

ai预测模型,分类列表

xyxie il y a 3 jours
Parent
commit
04eaa50570

+ 79 - 0
controllers/data_manage/ai_predict_model/classify.go

@@ -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)
+		}
+	}
 }

+ 16 - 0
models/ai_predict_model/ai_predict_model_classify.go

@@ -489,3 +489,19 @@ func RemoveAiPredictModelClassifyByClassifyIds(classifyIds []int) (err error) {
 	err = o.Exec(sql, classifyIds).Error
 	return
 }
+
+// AiPredictModelClassifyTreeResp 分类树形结构响应
+type AiPredictModelClassifyTreeResp struct {
+	List []*AiPredictModelClassifyTreeItem `description:"分类列表"`
+}
+
+// AiPredictModelClassifyTreeItem 分类树形结构节点
+type AiPredictModelClassifyTreeItem struct {
+	ClassifyId   int                               `description:"分类ID"`
+	ClassifyName string                            `description:"分类名称"`
+	ParentId     int                               `description:"父级ID"`
+	Level        int                               `description:"层级"`
+	Sort         int                               `description:"排序"`
+	UniqueCode   string                            `description:"唯一编码"`
+	Children     []*AiPredictModelClassifyTreeItem `description:"子分类"`
+}

+ 9 - 0
routers/commentsRouter.go

@@ -304,6 +304,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/ai_predict_model:AiPredictModelClassifyController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/ai_predict_model:AiPredictModelClassifyController"],
+        beego.ControllerComments{
+            Method: "TreeList",
+            Router: `/classify/tree`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/ai_predict_model:AiPredictModelFrameworkController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/ai_predict_model:AiPredictModelFrameworkController"],
         beego.ControllerComments{
             Method: "Add",