Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
govdna
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
开发共享交流平台
govdna
Commits
e22b7f1c
Commit
e22b7f1c
authored
Aug 17, 2018
by
刘弈臻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
菜单增删改查
parent
b50749bd
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
150 additions
and
12 deletions
+150
-12
MenuController.java
...com/govmade/modules/system/controller/MenuController.java
+30
-6
MenuDao.java
src/main/java/com/govmade/modules/system/dao/MenuDao.java
+16
-0
MenuEntity.java
...in/java/com/govmade/modules/system/entity/MenuEntity.java
+15
-0
MenuService.java
.../java/com/govmade/modules/system/service/MenuService.java
+8
-1
MenuServiceImpl.java
.../govmade/modules/system/service/impl/MenuServiceImpl.java
+40
-5
MenuDao.xml
src/main/resources/mapper/system/MenuDao.xml
+41
-0
No files found.
src/main/java/com/govmade/modules/system/controller/MenuController.java
View file @
e22b7f1c
package
com
.
govmade
.
modules
.
system
.
controller
;
import
java.util.Map
;
import
java.util.Set
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.govmade.common.utils.PageTreeUtils
;
import
com.govmade.common.utils.R
;
import
com.govmade.common.validator.Assert
;
import
com.govmade.modules.basic.controller.AbstractController
;
import
com.govmade.modules.system.entity.MenuEntity
;
import
com.govmade.modules.system.service.MenuService
;
...
...
@@ -28,15 +35,15 @@ public class MenuController extends AbstractController {
private
MenuService
menuService
;
/**
*
菜单列表
*
所有菜单数据树结构
*/
@GetMapping
(
"/list"
)
public
R
list
(
Map
<
String
,
Object
>
params
)
{
menuService
.
queryPage
(
params
);
return
null
;
@GetMapping
(
"/listTree"
)
public
R
listTree
(
@RequestParam
Map
<
String
,
Object
>
params
)
{
PageTreeUtils
page
=
menuService
.
queryPage
(
params
);
return
R
.
ok
().
put
(
"page"
,
page
);
}
/**
* 保存或更新用户
*/
...
...
@@ -48,6 +55,7 @@ public class MenuController extends AbstractController {
return
R
.
error
(
menu
.
getName
()
+
" 已存在!"
);
}
}
menuService
.
save
(
menu
);
return
R
.
ok
();
}
...
...
@@ -61,4 +69,20 @@ public class MenuController extends AbstractController {
public
R
info
(
@PathVariable
(
"id"
)
Long
id
)
{
return
R
.
ok
().
put
(
"menu"
,
menuService
.
queryById
(
id
));
}
/**
* 批量删除菜单
*
* @param ids
* @return
*/
@DeleteMapping
(
"/delete"
)
public
R
deleteArea
(
@RequestBody
Set
<
Long
>
ids
)
{
Assert
.
isNull
(
ids
,
"删除项不能为空"
);
menuService
.
deleteBatch
(
ids
);
return
R
.
ok
();
}
}
src/main/java/com/govmade/modules/system/dao/MenuDao.java
View file @
e22b7f1c
package
com
.
govmade
.
modules
.
system
.
dao
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
com.baomidou.mybatisplus.mapper.BaseMapper
;
import
com.govmade.modules.system.entity.MenuEntity
;
...
...
@@ -15,4 +21,14 @@ import com.govmade.modules.system.entity.MenuEntity;
@Mapper
public
interface
MenuDao
extends
BaseMapper
<
MenuEntity
>
{
/**
* 批量删除或删除
*/
void
deleteBatch
(
@Param
(
"ids"
)
Set
<
Long
>
ids
);
/**
* 查询树形数据
*/
List
<
MenuEntity
>
listTree
(
@Param
(
"params"
)
Map
<
String
,
Object
>
params
);
}
src/main/java/com/govmade/modules/system/entity/MenuEntity.java
View file @
e22b7f1c
package
com
.
govmade
.
modules
.
system
.
entity
;
import
java.util.List
;
import
com.baomidou.mybatisplus.annotations.TableField
;
import
com.baomidou.mybatisplus.annotations.TableName
;
import
com.govmade.modules.basic.entity.BaseEntity
;
...
...
@@ -32,6 +35,9 @@ public class MenuEntity extends BaseEntity<Long> {
private
Long
moduleId
;
private
Long
weight
;
@TableField
(
exist
=
false
)
private
List
<
MenuEntity
>
children
;
public
Long
getPid
()
{
return
pid
;
...
...
@@ -104,4 +110,13 @@ public class MenuEntity extends BaseEntity<Long> {
public
void
setWeight
(
Long
weight
)
{
this
.
weight
=
weight
;
}
public
List
<
MenuEntity
>
getChildren
()
{
return
children
;
}
public
void
setChildren
(
List
<
MenuEntity
>
children
)
{
this
.
children
=
children
;
}
}
src/main/java/com/govmade/modules/system/service/MenuService.java
View file @
e22b7f1c
...
...
@@ -2,8 +2,10 @@ package com.govmade.modules.system.service;
import
java.util.Map
;
import
java.util.Set
;
import
com.baomidou.mybatisplus.service.IService
;
import
com.govmade.common.utils.PageTreeUtils
;
import
com.govmade.common.utils.PageUtils
;
import
com.govmade.modules.system.entity.MenuEntity
;
...
...
@@ -17,7 +19,7 @@ import com.govmade.modules.system.entity.MenuEntity;
public
interface
MenuService
extends
IService
<
MenuEntity
>
{
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
);
Page
Tree
Utils
queryPage
(
Map
<
String
,
Object
>
params
);
/**
* 保存或修改菜单
...
...
@@ -30,4 +32,9 @@ public interface MenuService extends IService<MenuEntity> {
Integer
checkMenu
(
String
name
);
MenuEntity
queryById
(
Long
id
);
/**
* 删除菜单
*/
void
deleteBatch
(
Set
<
Long
>
ids
);
}
src/main/java/com/govmade/modules/system/service/impl/MenuServiceImpl.java
View file @
e22b7f1c
...
...
@@ -2,16 +2,21 @@ package com.govmade.modules.system.service.impl;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
org.springframework.stereotype.Service
;
import
com.baomidou.mybatisplus.mapper.EntityWrapper
;
import
com.baomidou.mybatisplus.service.impl.ServiceImpl
;
import
com.google.common.collect.Lists
;
import
com.govmade.common.utils.PageTreeUtils
;
import
com.govmade.common.utils.PageUtils
;
import
com.govmade.modules.system.dao.MenuDao
;
import
com.govmade.modules.system.entity.MenuEntity
;
import
com.govmade.modules.system.service.MenuService
;
import
cn.hutool.core.util.StrUtil
;
/**
* 系统管理 - 菜单设置
*
...
...
@@ -24,11 +29,36 @@ public class MenuServiceImpl extends ServiceImpl<MenuDao, MenuEntity> implements
@Override
public
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
)
{
// TODO Auto-generated method stub
//this.baseMapper.selectPage();
return
null
;
}
public
PageTreeUtils
queryPage
(
Map
<
String
,
Object
>
params
)
{
String
name
=
(
String
)
params
.
get
(
"name"
);
int
currPage
=
Integer
.
parseInt
((
String
)
params
.
get
(
"currPage"
));
int
pageSize
=
Integer
.
parseInt
((
String
)
params
.
get
(
"pageSize"
));
int
start
=
(
currPage
-
1
)*
pageSize
;
params
.
put
(
"name2"
,
name
);
params
.
put
(
"pageSize2"
,
pageSize
);
params
.
put
(
"start"
,
start
);
List
<
MenuEntity
>
allList
=
this
.
baseMapper
.
listTree
(
params
);
List
<
MenuEntity
>
list
=
buildAreaTree
(
allList
,
0L
);
int
totalCount
=
super
.
selectCount
(
new
EntityWrapper
<
MenuEntity
>().
like
(
StrUtil
.
isNotBlank
(
name
),
"name"
,
name
)
.
eq
(
"pid"
,
0
).
eq
(
"state"
,
1
));
return
new
PageTreeUtils
(
list
,
totalCount
,
pageSize
,
currPage
);
}
/**
*递归方法
*/
private
List
<
MenuEntity
>
buildAreaTree
(
List
<
MenuEntity
>
menuList
,
Long
id
)
{
List
<
MenuEntity
>
mList
=
Lists
.
newArrayList
();
for
(
MenuEntity
menu
:
menuList
)
{
if
(
id
==
menu
.
getPid
())
{
menu
.
setChildren
(
buildAreaTree
(
menuList
,
menu
.
getId
()));
mList
.
add
(
menu
);
}
}
return
mList
;
}
/**
* 获取所有菜单列表
...
...
@@ -56,5 +86,10 @@ public class MenuServiceImpl extends ServiceImpl<MenuDao, MenuEntity> implements
public
MenuEntity
queryById
(
Long
id
)
{
return
super
.
selectById
(
id
);
}
@Override
public
void
deleteBatch
(
Set
<
Long
>
ids
)
{
this
.
baseMapper
.
deleteBatch
(
ids
);
}
}
src/main/resources/mapper/system/MenuDao.xml
0 → 100644
View file @
e22b7f1c
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.govmade.modules.system.dao.MenuDao"
>
<!-- 批量删除 -->
<update
id=
"deleteBatch"
>
UPDATE system_menus SET state =${@com.govmade.common.utils.Constant@STATE_DELETE} WHERE id IN
<foreach
collection=
"ids"
item=
"id"
open=
"("
close=
")"
separator=
","
>
#{id}
</foreach>
</update>
<!-- 查询树形数据-->
<select
id=
"listTree"
resultType=
"MenuEntity"
>
SELECT * FROM system_menus AS t
INNER JOIN (
SELECT id AS id2 FROM system_menus
WHERE
pid = 0
AND state =1
<if
test=
"params.name2 != null and params.name2 !=''"
>
AND NAME LIKE CONCAT('%',#{params.name2},'%')
</if>
LIMIT #{params.start},#{params.pageSize2}
) AS t2 ON t.root_id = t2.id2 AND t.state=1
UNION ALL(SELECT *, 0 AS id2 FROM system_menus
WHERE
pid = 0
AND state =1
<if
test=
"params.name2 != null and params.name2 !=''"
>
AND NAME LIKE CONCAT('%',#{params.name2},'%')
</if>
LIMIT #{params.start},#{params.pageSize2}
)
ORDER BY id
</select>
</mapper>
\ 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