Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
0ae7c188
Commit
0ae7c188
authored
Apr 08, 2017
by
fsn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加对菜单的排序
parent
48d36cc7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
41 deletions
+81
-41
src/main/java/com/stylefeng/guns/common/node/MenuNode.java
+75
-29
src/main/java/com/stylefeng/guns/modular/system/dao/mapping/MenuDao.xml
+6
-12
No files found.
src/main/java/com/stylefeng/guns/common/node/MenuNode.java
View file @
0ae7c188
package
com
.
stylefeng
.
guns
.
common
.
node
;
package
com
.
stylefeng
.
guns
.
common
.
node
;
import
com.stylefeng.guns.core.util.ToolUtil
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
com.stylefeng.guns.core.util.ToolUtil
;
/**
/**
* @Description 菜单的节点
* @author fengshuonan
* @author fengshuonan
* @Description 菜单的节点
* @date 2016年12月6日 上午11:34:17
* @date 2016年12月6日 上午11:34:17
*/
*/
public
class
MenuNode
{
public
class
MenuNode
implements
Comparable
{
/**
/**
* 节点id
* 节点id
...
@@ -34,6 +35,11 @@ public class MenuNode {
...
@@ -34,6 +35,11 @@ public class MenuNode {
private
Integer
levels
;
private
Integer
levels
;
/**
/**
* 按钮的排序
*/
private
Integer
num
;
/**
* 节点的url
* 节点的url
*/
*/
private
String
url
;
private
String
url
;
...
@@ -123,10 +129,42 @@ public class MenuNode {
...
@@ -123,10 +129,42 @@ public class MenuNode {
this
.
children
=
children
;
this
.
children
=
children
;
}
}
public
Integer
getNum
()
{
return
num
;
}
public
void
setNum
(
Integer
num
)
{
this
.
num
=
num
;
}
@Override
public
String
toString
()
{
return
"MenuNode{"
+
"id="
+
id
+
", parentId="
+
parentId
+
", name='"
+
name
+
'\''
+
", levels="
+
levels
+
", num="
+
num
+
", url='"
+
url
+
'\''
+
", icon='"
+
icon
+
'\''
+
", children="
+
children
+
", linkedList="
+
linkedList
+
'}'
;
}
@Override
public
int
compareTo
(
Object
o
)
{
MenuNode
menuNode
=
(
MenuNode
)
o
;
Integer
num
=
menuNode
.
getNum
();
if
(
num
==
null
)
{
num
=
0
;
}
return
this
.
num
.
compareTo
(
num
);
}
/**
/**
* @Description 构建整个菜单树
* 构建整个菜单树
* @param list
*
* 需要被构建的节点集合
* @author fengshuonan
* @author fengshuonan
*/
*/
public
void
buildNodeTree
(
List
<
MenuNode
>
nodeList
)
{
public
void
buildNodeTree
(
List
<
MenuNode
>
nodeList
)
{
...
@@ -139,13 +177,14 @@ public class MenuNode {
...
@@ -139,13 +177,14 @@ public class MenuNode {
}
}
/**
/**
* @Description 查询子节点的集合
* 查询子节点的集合
*
* @author fengshuonan
* @author fengshuonan
*/
*/
public
List
<
MenuNode
>
findChildNodes
(
List
<
MenuNode
>
nodeList
,
Integer
parentId
)
{
public
List
<
MenuNode
>
findChildNodes
(
List
<
MenuNode
>
nodeList
,
Integer
parentId
)
{
if
(
nodeList
==
null
&&
parentId
==
null
)
if
(
nodeList
==
null
&&
parentId
==
null
)
return
null
;
return
null
;
for
(
Iterator
<
MenuNode
>
iterator
=
nodeList
.
iterator
();
iterator
.
hasNext
();
)
{
for
(
Iterator
<
MenuNode
>
iterator
=
nodeList
.
iterator
();
iterator
.
hasNext
();
)
{
MenuNode
node
=
(
MenuNode
)
iterator
.
next
();
MenuNode
node
=
(
MenuNode
)
iterator
.
next
();
// 根据传入的某个父节点ID,遍历该父节点的所有子节点
// 根据传入的某个父节点ID,遍历该父节点的所有子节点
if
(
node
.
getParentId
()
!=
0
&&
parentId
==
node
.
getParentId
())
{
if
(
node
.
getParentId
()
!=
0
&&
parentId
==
node
.
getParentId
())
{
...
@@ -156,7 +195,8 @@ public class MenuNode {
...
@@ -156,7 +195,8 @@ public class MenuNode {
}
}
/**
/**
* @Description 遍历一个节点的子节点
* 遍历一个节点的子节点
*
* @author fengshuonan
* @author fengshuonan
*/
*/
public
void
recursionFn
(
List
<
MenuNode
>
nodeList
,
MenuNode
node
,
Integer
pId
)
{
public
void
recursionFn
(
List
<
MenuNode
>
nodeList
,
MenuNode
node
,
Integer
pId
)
{
...
@@ -178,7 +218,8 @@ public class MenuNode {
...
@@ -178,7 +218,8 @@ public class MenuNode {
}
}
/**
/**
* @Description 得到子节点列表
* 得到子节点列表
*
* @author fengshuonan
* @author fengshuonan
*/
*/
private
List
<
MenuNode
>
getChildList
(
List
<
MenuNode
>
list
,
MenuNode
node
)
{
private
List
<
MenuNode
>
getChildList
(
List
<
MenuNode
>
list
,
MenuNode
node
)
{
...
@@ -193,22 +234,15 @@ public class MenuNode {
...
@@ -193,22 +234,15 @@ public class MenuNode {
return
nodeList
;
return
nodeList
;
}
}
@Override
public
String
toString
()
{
return
"MenuNode [id="
+
id
+
", parentId="
+
parentId
+
", name="
+
name
+
", url="
+
url
+
", children="
+
children
+
"]"
;
}
/**
/**
* 清除掉按钮级别的资源
* 清除掉按钮级别的资源
* @param nodes
*
* @return
* @date 2017年2月19日 下午11:04:11
* @date 2017年2月19日 下午11:04:11
*/
*/
public
static
List
<
MenuNode
>
clearBtn
(
List
<
MenuNode
>
nodes
)
{
public
static
List
<
MenuNode
>
clearBtn
(
List
<
MenuNode
>
nodes
)
{
ArrayList
<
MenuNode
>
noBtns
=
new
ArrayList
<
MenuNode
>();
ArrayList
<
MenuNode
>
noBtns
=
new
ArrayList
<
MenuNode
>();
for
(
MenuNode
node
:
nodes
)
{
for
(
MenuNode
node
:
nodes
)
{
if
(
node
.
getLevels
()
<
3
)
{
if
(
node
.
getLevels
()
<
3
)
{
noBtns
.
add
(
node
);
noBtns
.
add
(
node
);
}
}
}
}
...
@@ -217,13 +251,13 @@ public class MenuNode {
...
@@ -217,13 +251,13 @@ public class MenuNode {
/**
/**
* 清除不包含子节点的节点
* 清除不包含子节点的节点
* @return
*
* @date 2017年2月19日 下午11:18:19
* @date 2017年2月19日 下午11:18:19
*/
*/
public
static
List
<
MenuNode
>
clearNoChild
(
List
<
MenuNode
>
nodes
)
{
public
static
List
<
MenuNode
>
clearNoChild
(
List
<
MenuNode
>
nodes
)
{
ArrayList
<
MenuNode
>
results
=
new
ArrayList
<
MenuNode
>();
ArrayList
<
MenuNode
>
results
=
new
ArrayList
<
MenuNode
>();
for
(
MenuNode
node
:
nodes
)
{
for
(
MenuNode
node
:
nodes
)
{
if
(
ToolUtil
.
isNotEmpty
(
node
.
getChildren
()))
{
if
(
ToolUtil
.
isNotEmpty
(
node
.
getChildren
()))
{
results
.
add
(
node
);
results
.
add
(
node
);
}
}
}
}
...
@@ -232,12 +266,24 @@ public class MenuNode {
...
@@ -232,12 +266,24 @@ public class MenuNode {
/**
/**
* 构建菜单列表
* 构建菜单列表
* @return
*
* @date 2017年2月19日 下午11:18:19
* @date 2017年2月19日 下午11:18:19
*/
*/
public
static
List
<
MenuNode
>
buildTitle
(
List
<
MenuNode
>
nodes
)
{
public
static
List
<
MenuNode
>
buildTitle
(
List
<
MenuNode
>
nodes
)
{
List
<
MenuNode
>
clearBtn
=
clearBtn
(
nodes
);
List
<
MenuNode
>
clearBtn
=
clearBtn
(
nodes
);
new
MenuNode
().
buildNodeTree
(
clearBtn
);
new
MenuNode
().
buildNodeTree
(
clearBtn
);
return
clearNoChild
(
clearBtn
);
List
<
MenuNode
>
menuNodes
=
clearNoChild
(
clearBtn
);
//对菜单排序
Collections
.
sort
(
menuNodes
);
//对菜单的子菜单进行排序
for
(
MenuNode
menuNode
:
menuNodes
)
{
if
(
menuNode
.
getChildren
()
!=
null
&&
menuNode
.
getChildren
().
size
()
>
0
)
{
Collections
.
sort
(
menuNode
.
getChildren
());
}
}
return
menuNodes
;
}
}
}
}
src/main/java/com/stylefeng/guns/modular/system/dao/mapping/MenuDao.xml
View file @
0ae7c188
...
@@ -4,24 +4,17 @@
...
@@ -4,24 +4,17 @@
<sql
id=
"Base_Column_List"
>
<sql
id=
"Base_Column_List"
>
id, code, pcode, alias, name, icon, url, num, levels, path,
id, code, pcode, name, icon, url, num, levels,
tips, status,
tips, status,isopen
isopen,
istemplate, version
</sql>
<sql
id=
"Blob_Column_List"
>
source
</sql>
</sql>
<select
id=
"selectMenus"
resultType=
"map"
>
<select
id=
"selectMenus"
resultType=
"map"
>
select
select
<include
refid=
"Base_Column_List"
/>
<include
refid=
"Base_Column_List"
/>
,
<include
refid=
"Blob_Column_List"
/>
from _menu
from _menu
where status = 1
<if
test=
"condition != null and condition != ''"
>
<if
test=
"condition != null and condition != ''"
>
where
name = #{condition}
and
name = #{condition}
</if>
</if>
</select>
</select>
...
@@ -134,7 +127,8 @@
...
@@ -134,7 +127,8 @@
) AS parentId,
) AS parentId,
m1.NAME as name,
m1.NAME as name,
m1.url as url,
m1.url as url,
m1.levels as levels
m1.levels as levels,
m1.num as num
FROM
FROM
_menu m1
_menu m1
LEFT JOIN _menu m2 ON m1.pcode = m2. CODE
LEFT JOIN _menu m2 ON m1.pcode = m2. CODE
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment