Преглед на файлове

Merge remote-tracking branch 'origin/debug' into debug

Roc преди 1 година
родител
ревизия
ee3f26374d
променени са 3 файла, в които са добавени 183 реда и са изтрити 26 реда
  1. 109 25
      controllers/sandbox/sandbox.go
  2. 40 0
      models/sandbox/sand_box_classify.go
  3. 34 1
      services/sandbox/sandbox.go

+ 109 - 25
controllers/sandbox/sandbox.go

@@ -853,50 +853,48 @@ func (this *SandboxController) SandboxClassifyItems() {
 		return
 	}
 
-	rootList, err := sandbox.GetSandboxClassifyByParentId(sandboxClassifyId)
+	rootList, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
 		return
 	}
 
-	classifyAll, err := sandbox.GetSandboxClassifyByParentId(sandboxClassifyId)
+	classifyAll, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
 		return
 	}
 
-	sandboxAll, err := sandbox.GetSandboxItemsByClassifyId(sandboxClassifyId)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取数据失败,Err:" + err.Error()
-		return
-	}
+	//sandboxAll, err := sandbox.GetSandboxItemsByClassifyId(sandboxClassifyId)
+	//if err != nil && err.Error() != utils.ErrNoRow() {
+	//	br.Msg = "获取失败"
+	//	br.ErrMsg = "获取数据失败,Err:" + err.Error()
+	//	return
+	//}
 
-	sandListMap := make(map[int][]*sandbox.SandboxClassifyItems)
-	for _, v := range sandboxAll {
-		if _, ok := sandListMap[v.SandboxClassifyId]; !ok {
-			list := make([]*sandbox.SandboxClassifyItems, 0)
-			list = append(list, v)
-			sandListMap[v.SandboxClassifyId] = list
-		} else {
-			sandListMap[v.SandboxClassifyId] = append(sandListMap[v.SandboxClassifyId], v)
-		}
-	}
+	//sandListMap := make(map[int][]*sandbox.SandboxClassifyItems)
+	//for _, v := range sandboxAll {
+	//	if _, ok := sandListMap[v.SandboxClassifyId]; !ok {
+	//		list := make([]*sandbox.SandboxClassifyItems, 0)
+	//		list = append(list, v)
+	//		sandListMap[v.SandboxClassifyId] = list
+	//	} else {
+	//		sandListMap[v.SandboxClassifyId] = append(sandListMap[v.SandboxClassifyId], v)
+	//	}
+	//}
 
 	nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
 	for k := range rootList {
 		rootNode := rootList[k]
-		sandboxService.SandboxClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
+		sandboxService.SandboxClassifyItemsMakeTreeV2(this.SysUser, classifyAll, rootNode)
 		nodeAll = append(nodeAll, rootNode)
 	}
-	//for k := range nodeAll {
-	//
-	//}
-	newAll := sandboxService.SandboxItemsMakeTree(nodeAll, sandListMap, sandboxClassifyId)
 
-	resp.AllNodes = newAll
+	//newAll := sandboxService.SandboxItemsMakeTree(nodeAll, sandListMap, sandboxClassifyId)
+
+	resp.AllNodes = nodeAll
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
@@ -1738,4 +1736,90 @@ func (this *SandboxController) SandboxMove() {
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "移动成功"
-}
+}
+
+//// SandboxClassifyItems
+//// @Title 获取所有沙盘分类接口-包含沙盘-先分类后沙盘区分,暂时弃用
+//// @Description 获取所有沙盘分类接口-包含沙盘
+//// @Param   IsShowMe   query   bool  true       "是否只看我的,true、false"
+//// @Success 200 {object} data_manage.ChartClassifyListResp
+//// @router /classify/list [get]
+//func (this *SandboxController) SandboxClassifyItems() {
+//	br := new(models.BaseResponse).Init()
+//	defer func() {
+//		this.Data["json"] = br
+//		this.ServeJSON()
+//	}()
+//
+//	resp := new(sandbox.SandboxClassifyListResp)
+//	sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
+//
+//	isShowMe, _ := this.GetBool("IsShowMe")
+//	if isShowMe {
+//		errMsg, err := sandboxService.GetSandboxClassifyListForMe(*this.SysUser, resp, sandboxClassifyId)
+//		if err != nil {
+//			br.Msg = errMsg
+//			br.ErrMsg = err.Error()
+//			return
+//		}
+//		// 移除没有权限的图表
+//		//allNodes := sandboxService.HandleNoPermissionSandbox(resp.AllNodes, nil)
+//		//resp.AllNodes = allNodes
+//
+//		br.Ret = 200
+//		br.Success = true
+//		br.Msg = "获取成功"
+//		br.Data = resp
+//		fmt.Println("source my classify")
+//		return
+//	}
+//
+//	rootList, err := sandbox.GetSandboxClassifyByParentId(sandboxClassifyId)
+//	if err != nil && err.Error() != utils.ErrNoRow() {
+//		br.Msg = "获取失败"
+//		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+//		return
+//	}
+//
+//	classifyAll, err := sandbox.GetSandboxClassifyByParentId(sandboxClassifyId)
+//	if err != nil && err.Error() != utils.ErrNoRow() {
+//		br.Msg = "获取失败"
+//		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+//		return
+//	}
+//
+//	sandboxAll, err := sandbox.GetSandboxItemsByClassifyId(sandboxClassifyId)
+//	if err != nil && err.Error() != utils.ErrNoRow() {
+//		br.Msg = "获取失败"
+//		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+//		return
+//	}
+//
+//	sandListMap := make(map[int][]*sandbox.SandboxClassifyItems)
+//	for _, v := range sandboxAll {
+//		if _, ok := sandListMap[v.SandboxClassifyId]; !ok {
+//			list := make([]*sandbox.SandboxClassifyItems, 0)
+//			list = append(list, v)
+//			sandListMap[v.SandboxClassifyId] = list
+//		} else {
+//			sandListMap[v.SandboxClassifyId] = append(sandListMap[v.SandboxClassifyId], v)
+//		}
+//	}
+//
+//	nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
+//	for k := range rootList {
+//		rootNode := rootList[k]
+//		sandboxService.SandboxClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
+//		nodeAll = append(nodeAll, rootNode)
+//	}
+//	//for k := range nodeAll {
+//	//
+//	//}
+//	newAll := sandboxService.SandboxItemsMakeTree(nodeAll, sandListMap, sandboxClassifyId)
+//
+//	resp.AllNodes = newAll
+//	br.Ret = 200
+//	br.Success = true
+//	br.Msg = "获取成功"
+//	br.Data = resp
+//}

+ 40 - 0
models/sandbox/sand_box_classify.go

@@ -187,3 +187,43 @@ func (sandboxClassify *SandboxClassify) Update(cols []string) (err error) {
 	_, err = o.Update(sandboxClassify, cols...)
 	return
 }
+
+// GetSandboxClassifyAndInfoByParentId
+func GetSandboxClassifyAndInfoByParentId(parentId int) (items []*SandboxClassifyItems, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT
+	0 AS sandbox_id,
+	sandbox_classify_id,
+	sandbox_classify_name,
+	parent_id,
+	create_time,
+	modify_time,
+	sys_user_id,
+	sys_user_real_name AS sys_user_name,
+	sort,
+	level 
+FROM
+	sandbox_classify 
+WHERE
+	parent_id = ? UNION ALL
+SELECT
+	sandbox_id,
+	sandbox_classify_id,
+	name AS sandbox_classify_name,
+	0 AS parent_id,
+	create_time,
+	modify_time,
+	sys_user_id,
+	sys_user_name,
+	sort,
+	0 AS level 
+FROM
+	sandbox 
+WHERE
+	sandbox_classify_id = ? 
+ORDER BY
+	sort ASC,
+	sandbox_classify_id ASC`
+	_, err = o.Raw(sql, parentId, parentId).QueryRows(&items)
+	return
+}

+ 34 - 1
services/sandbox/sandbox.go

@@ -817,4 +817,37 @@ func SandboxClassifyHaveChild(allNode []*sandbox.SandboxClassifyItems, node *san
 		yes = true
 	}
 	return
-}
+}
+
+func SandboxClassifyItemsMakeTreeV2(sysUser *system.Admin, allNode []*sandbox.SandboxClassifyItems, node *sandbox.SandboxClassifyItems) {
+
+	childs, _ := sandboxClassifyHaveChildV2(allNode, node) //判断节点是否有子节点并返回
+	if len(childs) > 0 {
+
+		node.Children = append(node.Children, childs[0:]...) //添加子节点
+		for _, v := range childs {                           //查询子节点的子节点,并添加到子节点
+			_, has := sandboxClassifyHaveChildV2(allNode, v)
+			if has {
+				SandboxClassifyItemsMakeTreeV2(sysUser, allNode, v) //递归添加节点
+			} else {
+				childrenArr := make([]*sandbox.SandboxClassifyItems, 0)
+				v.Children = childrenArr
+			}
+		}
+	} else {
+		childrenArr := make([]*sandbox.SandboxClassifyItems, 0)
+		node.Children = childrenArr
+	}
+}
+
+func sandboxClassifyHaveChildV2(allNode []*sandbox.SandboxClassifyItems, node *sandbox.SandboxClassifyItems) (childs []*sandbox.SandboxClassifyItems, yes bool) {
+	for _, v := range allNode {
+		if v.ParentId == node.SandboxClassifyId && node.SandboxId == 0 {
+			childs = append(childs, v)
+		}
+	}
+	if len(childs) > 0 {
+		yes = true
+	}
+	return
+}