Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangxinjiang
yifu-mvp
Commits
0a753235
Commit
0a753235
authored
Jun 14, 2022
by
fangxinjiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化
parent
b7e2939d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
245 additions
and
1 deletion
+245
-1
CommonConstants.java
...ud.plus.v1/yifu/common/core/constant/CommonConstants.java
+1
-0
Common.java
.../com/yifu.cloud.plus.v1/yifu/common/core/util/Common.java
+1
-1
TreeUtil.java
.../com/yifu.cloud.plus.v1/yifu/admin/api/util/TreeUtil.java
+134
-0
MenuTree.java
...va/com/yifu.cloud.plus.v1/yifu/admin/api/vo/MenuTree.java
+60
-0
TreeNode.java
...va/com/yifu.cloud.plus.v1/yifu/admin/api/vo/TreeNode.java
+49
-0
No files found.
yifu-common/yifu-common-core/src/main/java/com/yifu.cloud.plus.v1/yifu/common/core/constant/CommonConstants.java
View file @
0a753235
...
...
@@ -129,4 +129,5 @@ public interface CommonConstants {
*/
String
DOWN_LINE
=
"_"
;
String
EXIST_ENTITY
=
"已存在唯一性的数据"
;
}
yifu-common/yifu-common-core/src/main/java/com/yifu.cloud.plus.v1/yifu/common/core/util/Common.java
View file @
0a753235
...
...
@@ -36,7 +36,7 @@ public class Common {
}
public
static
boolean
isNotNull
(
String
obj
)
{
if
(
null
==
obj
||
""
.
equals
(
obj
)
||
"undefined"
.
equals
(
obj
)){
if
(
null
!=
obj
||
!
""
.
equals
(
obj
)
||
!
"undefined"
.
equals
(
obj
)){
return
true
;
}
return
false
;
...
...
yifu-upms/yifu-upms-api/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/api/util/TreeUtil.java
0 → 100644
View file @
0a753235
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
admin
.
api
.
util
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysMenu
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.vo.MenuTree
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.vo.TreeNode
;
import
lombok.experimental.UtilityClass
;
import
java.util.ArrayList
;
import
java.util.List
;
@UtilityClass
public
class
TreeUtil
{
/**
* 两层循环实现建树
*
* @param treeNodes 传入的树节点列表
* @return
*/
public
<
T
extends
TreeNode
>
List
<
T
>
bulid
(
List
<
T
>
treeNodes
,
Object
root
)
{
List
<
T
>
trees
=
new
ArrayList
<>();
for
(
T
treeNode
:
treeNodes
)
{
if
(
root
.
equals
(
treeNode
.
getParentId
()))
{
trees
.
add
(
treeNode
);
}
for
(
T
it
:
treeNodes
)
{
if
(
it
.
getParentId
()
==
treeNode
.
getId
())
{
if
(
treeNode
.
getChildren
()
==
null
)
{
treeNode
.
setChildren
(
new
ArrayList
<>());
}
if
(
treeNode
.
getSubMenus
()
==
null
)
{
treeNode
.
setSubMenus
(
new
ArrayList
<>());
}
treeNode
.
add
(
it
);
}
}
}
return
trees
;
}
/**
* 使用递归方法建树
*
* @param treeNodes
* @return
*/
public
<
T
extends
TreeNode
>
List
<
T
>
buildByRecursive
(
List
<
T
>
treeNodes
,
Object
root
)
{
List
<
T
>
trees
=
new
ArrayList
<
T
>();
for
(
T
treeNode
:
treeNodes
)
{
if
(
root
.
equals
(
treeNode
.
getParentId
()))
{
trees
.
add
(
findChildren
(
treeNode
,
treeNodes
));
}
}
return
trees
;
}
/**
* 递归查找子节点
*
* @param treeNodes
* @return
*/
public
<
T
extends
TreeNode
>
T
findChildren
(
T
treeNode
,
List
<
T
>
treeNodes
)
{
for
(
T
it
:
treeNodes
)
{
if
(
treeNode
.
getId
()
==
it
.
getParentId
())
{
if
(
treeNode
.
getChildren
()
==
null
)
{
treeNode
.
setChildren
(
new
ArrayList
<>());
}
treeNode
.
add
(
findChildren
(
it
,
treeNodes
));
}
}
return
treeNode
;
}
/**
* 通过sysMenu创建树形节点
*
* @param menus
* @param root
* @return
*/
public
List
<
MenuTree
>
bulidTree
(
List
<
SysMenu
>
menus
,
int
root
)
{
List
<
MenuTree
>
trees
=
new
ArrayList
<>();
MenuTree
node
;
for
(
SysMenu
menu
:
menus
)
{
node
=
new
MenuTree
();
node
.
setId
(
String
.
valueOf
(
menu
.
getMenuId
()));
node
.
setParentId
(
String
.
valueOf
(
menu
.
getParentId
()));
node
.
setName
(
menu
.
getName
());
node
.
setPath
(
menu
.
getPath
());
node
.
setCode
(
menu
.
getPermission
());
node
.
setLabel
(
menu
.
getName
());
node
.
setIcon
(
menu
.
getIcon
());
node
.
setKeepAlive
(
menu
.
getKeepAlive
());
trees
.
add
(
node
);
}
return
TreeUtil
.
bulid
(
trees
,
root
);
}
/**
* 两层循环实现建树
* @author fxj
* @param treeNodes 传入的树节点列表
* @return
*/
public
<
T
extends
TreeNode
>
List
<
T
>
bulidByRoot
(
List
<
T
>
treeNodes
,
Object
root
)
{
List
<
T
>
trees
=
new
ArrayList
<>();
for
(
T
treeNode
:
treeNodes
)
{
if
(
root
.
equals
(
treeNode
.
getId
()))
{
trees
.
add
(
treeNode
);
}
for
(
T
it
:
treeNodes
)
{
if
(
it
.
getParentId
()
==
treeNode
.
getId
())
{
if
(
treeNode
.
getChildren
()
==
null
)
{
treeNode
.
setChildren
(
new
ArrayList
<>());
}
if
(
treeNode
.
getSubMenus
()
==
null
)
{
treeNode
.
setSubMenus
(
new
ArrayList
<>());
}
treeNode
.
add
(
it
);
}
}
}
return
trees
;
}
}
yifu-upms/yifu-upms-api/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/api/vo/MenuTree.java
0 → 100644
View file @
0a753235
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
admin
.
api
.
vo
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysMenu
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.util.Map
;
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
public
class
MenuTree
extends
TreeNode
{
private
String
id
;
private
String
icon
;
private
String
name
;
private
String
parentId
;
private
boolean
spread
=
false
;
private
String
path
;
private
String
authority
;
private
String
redirect
;
private
String
keepAlive
;
private
String
code
;
private
String
type
;
private
String
label
;
private
Integer
sort
;
private
String
url
;
private
Map
<
String
,
Object
>
extra
;
public
MenuTree
()
{
}
public
MenuTree
(
String
id
,
String
name
,
String
parentId
)
{
this
.
id
=
id
;
this
.
parentId
=
parentId
;
this
.
name
=
name
;
this
.
label
=
name
;
}
public
MenuTree
(
String
id
,
String
name
,
MenuTree
parent
)
{
this
.
id
=
id
;
this
.
parentId
=
parent
.
getId
();
this
.
name
=
name
;
this
.
label
=
name
;
}
public
MenuTree
(
SysMenu
menuVo
)
{
this
.
id
=
String
.
valueOf
(
menuVo
.
getMenuId
());
this
.
parentId
=
String
.
valueOf
(
menuVo
.
getParentId
());
this
.
icon
=
menuVo
.
getIcon
();
this
.
name
=
menuVo
.
getName
();
this
.
path
=
menuVo
.
getPath
();
this
.
type
=
menuVo
.
getType
();
this
.
label
=
menuVo
.
getName
();
this
.
sort
=
menuVo
.
getSortOrder
();
this
.
keepAlive
=
menuVo
.
getKeepAlive
();
this
.
url
=
""
;
this
.
authority
=
menuVo
.
getPermission
();
}
}
yifu-upms/yifu-upms-api/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/api/vo/TreeNode.java
0 → 100644
View file @
0a753235
/**
* Copyright © 2017yifu. All rights reserved.
*
* @Title: TreeNode.java
* @Prject: worfuplus
* @Package: com.worfu.web.bo
* @author: Administrator
* @date: 2017年7月26日 上午11:44:49
* @version: V1.0
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
admin
.
api
.
vo
;
import
lombok.Data
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 树形节点
* @author: FANG
* @createDate: 2017年7月26日 上午11:44:49
*/
@Data
public
class
TreeNode
{
private
String
id
;
private
String
label
;
private
String
disabled
;
protected
String
parentId
;
protected
List
<
TreeNode
>
children
=
new
ArrayList
<
TreeNode
>();
protected
List
<
TreeNode
>
subMenus
=
new
ArrayList
<
TreeNode
>();
public
void
add
(
TreeNode
node
)
{
children
.
add
(
node
);
subMenus
.
add
(
node
);
}
}
\ No newline at end of file
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