Ver código fonte

Merge branch 'feature/eta1.7.0_yongyi' of eta_server/eta_api into master

xyxie 1 ano atrás
pai
commit
f27d6e87b2

+ 25 - 1
controllers/data_manage/yongyi_data.go

@@ -38,9 +38,33 @@ func (this *EdbInfoController) YongyiClassify() {
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
 		return
 	}
+	//组装一级分类
+	rootMap := make(map[int][]*data_manage.BaseFromYongyiClassifyItems)
+	list := make([]*data_manage.BaseFromYongyiClassifyItems, 0)
+	for _, classify := range classifyAll {
+		if classify.ParentId == 0 {
+			if _, ok := rootMap[classify.ClassifyId]; !ok {
+				rootMap[classify.ClassifyId] = make([]*data_manage.BaseFromYongyiClassifyItems, 0)
+				list = append(list, classify)
+			}
+		} else {
+			child, ok := rootMap[classify.ParentId]
+			if ok {
+				child = append(child, classify)
+				rootMap[classify.ParentId] = child
+			}
+		}
+	}
 
+	for k, v := range list {
+		child, ok := rootMap[v.ClassifyId]
+		if ok {
+			list[k].Children = child
+		}
+	}
+	//组装二级分类
 	var ret data_manage.BaseFromYongyiClassifyResp
-	ret.List = classifyAll
+	ret.List = list
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 2 - 1
models/data_manage/base_from_yongyi_classify.go

@@ -67,6 +67,7 @@ type BaseFromYongyiClassifyItems struct {
 	ParentId        int    `description:"父级id"`
 	Level           int    `description:"层级"`
 	Sort            int    `description:"排序字段,越小越靠前,默认值:10"`
+	Children        []*BaseFromYongyiClassifyItems
 }
 
 type BaseFromYongyiClassifyNameItems struct {
@@ -101,7 +102,7 @@ func GetBaseFromYongyiClassifyByParentId(parentId int) (items []*BaseFromYongyiC
 // GetAllBaseFromYongyiClassify 获取所有的分类列表数据
 func GetAllBaseFromYongyiClassify() (items []*BaseFromYongyiClassifyItems, err error) {
 	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT * FROM base_from_yongyi_classify order by sort asc,classify_id asc`
+	sql := ` SELECT * FROM base_from_yongyi_classify order by parent_id asc, sort asc,classify_id asc`
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }