动态权限接口

This commit is contained in:
haoxr 2020-09-15 13:22:30 +08:00
parent a3bc6a1bcd
commit 1370634c91
7 changed files with 39 additions and 31 deletions

View File

@ -71,8 +71,8 @@ public class SysMenuController {
map.put("checkedKeys", checkedKeys); map.put("checkedKeys", checkedKeys);
return Result.success(map); return Result.success(map);
} }
}else if(mode.equals(3)){ } else if (mode.equals(3)) {
list = iSysMenuService.listForRoute(); list = iSysMenuService.listForRouter();
} else { } else {
list = iSysMenuService.list(baseQuery); list = iSysMenuService.list(baseQuery);
} }
@ -83,29 +83,28 @@ public class SysMenuController {
@ApiImplicitParam(name = "id", value = "菜单id", required = true, paramType = "path", dataType = "Integer") @ApiImplicitParam(name = "id", value = "菜单id", required = true, paramType = "path", dataType = "Integer")
@GetMapping("/{id}") @GetMapping("/{id}")
public Result detail(@PathVariable Integer id) { public Result detail(@PathVariable Integer id) {
SysMenu sysMenu = iSysMenuService.getById(id); SysMenu menu = iSysMenuService.getById(id);
return Result.success(sysMenu); return Result.success(menu);
} }
@ApiOperation(value = "新增菜单", httpMethod = "POST") @ApiOperation(value = "新增菜单", httpMethod = "POST")
@ApiImplicitParam(name = "sysMenu", value = "实体JSON对象", required = true, paramType = "body", dataType = "SysMenu") @ApiImplicitParam(name = "menu", value = "实体JSON对象", required = true, paramType = "body", dataType = "SysMenu")
@PostMapping @PostMapping
public Result add(@RequestBody SysMenu sysMenu) { public Result add(@RequestBody SysMenu menu) {
boolean status = iSysMenuService.save(sysMenu); boolean status = iSysMenuService.save(menu);
return Result.status(status); return Result.status(status);
} }
@ApiOperation(value = "修改菜单", httpMethod = "PUT") @ApiOperation(value = "修改菜单", httpMethod = "PUT")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "菜单id", required = true, paramType = "path", dataType = "Integer"), @ApiImplicitParam(name = "id", value = "菜单id", required = true, paramType = "path", dataType = "Integer"),
@ApiImplicitParam(name = "sysMenu", value = "实体JSON对象", required = true, paramType = "body", dataType = "SysMenu") @ApiImplicitParam(name = "menu", value = "实体JSON对象", required = true, paramType = "body", dataType = "SysMenu")
}) })
@PutMapping(value = "/{id}") @PutMapping(value = "/{id}")
public Result update( public Result update(
@PathVariable Integer id, @PathVariable Integer id,
@RequestBody SysMenu sysMenu) { @RequestBody SysMenu menu) {
sysMenu.setUpdateTime(new Date()); boolean status = iSysMenuService.updateById(menu);
boolean status = iSysMenuService.updateById(sysMenu);
return Result.status(status); return Result.status(status);
} }

View File

@ -1,15 +1,16 @@
package com.youlai.admin.domain.entity; package com.youlai.admin.domain.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.youlai.common.core.entity.BaseEntity; import com.youlai.common.core.entity.BaseEntity;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
@Data @Data
public class SysMenu extends BaseEntity { @JsonInclude(JsonInclude.Include.NON_EMPTY)
public class SysMenu extends BaseEntity {
@TableId @TableId
private Integer id; private Integer id;
@ -32,6 +33,10 @@ public class SysMenu extends BaseEntity {
private String perms; private String perms;
private String redirect;
private Integer type;
@TableField(exist = false) @TableField(exist = false)
private List<Integer> roles; private List<Integer> roles;

View File

@ -22,6 +22,8 @@ public class MenuVO extends BaseEntity {
private Integer status; private Integer status;
private String component;
private String path; private String path;
private String perms; private String perms;

View File

@ -22,5 +22,5 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
@Result(id=true, column="id", property="id"), @Result(id=true, column="id", property="id"),
@Result(property = "roles",column="id",many = @Many(select="com.youlai.admin.mapper.SysRoleMenuMapper.listByMenuId")) @Result(property = "roles",column="id",many = @Many(select="com.youlai.admin.mapper.SysRoleMenuMapper.listByMenuId"))
}) })
List<SysMenu> listForRoute(); List<SysMenu> listForRouter();
} }

View File

@ -16,5 +16,5 @@ public interface ISysMenuService extends IService<SysMenu> {
List<TreeSelectVO> listForTreeSelect(LambdaQueryWrapper<SysMenu> baseQuery); List<TreeSelectVO> listForTreeSelect(LambdaQueryWrapper<SysMenu> baseQuery);
List listForRoute(); List listForRouter();
} }

View File

@ -11,7 +11,6 @@ import com.youlai.admin.domain.vo.RouterVO;
import com.youlai.admin.domain.vo.TreeSelectVO; import com.youlai.admin.domain.vo.TreeSelectVO;
import com.youlai.admin.mapper.SysMenuMapper; import com.youlai.admin.mapper.SysMenuMapper;
import com.youlai.admin.service.ISysMenuService; import com.youlai.admin.service.ISysMenuService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@ -37,8 +36,8 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
} }
@Override @Override
public List listForRoute() { public List listForRouter() {
List<SysMenu> menuList = this.baseMapper.listForRoute(); List<SysMenu> menuList = this.baseMapper.listForRouter();
List<RouterVO> list = recursionForRoutes(AdminConstant.ROOT_MENU_ID, menuList); List<RouterVO> list = recursionForRoutes(AdminConstant.ROOT_MENU_ID, menuList);
return list; return list;
} }
@ -51,20 +50,23 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
.forEach(menu -> { .forEach(menu -> {
RouterVO routerVO = new RouterVO(); RouterVO routerVO = new RouterVO();
routerVO.setName(menu.getName()); routerVO.setName(menu.getName());
routerVO.setPath(menu.getPath()); if (parentId == AdminConstant.ROOT_MENU_ID) {
String component = StrUtil.isNotBlank(menu.getComponent()) ? menu.getComponent() : "Layout"; routerVO.setAlwaysShow(Boolean.TRUE);
routerVO.setComponent(component); routerVO.setPath("/" + menu.getPath());
RouterVO.Meta meta = routerVO.new Meta( } else {
routerVO.setPath(menu.getPath());
}
routerVO.setRedirect(menu.getRedirect());
routerVO.setComponent(
StrUtil.isNotBlank(menu.getComponent()) ?
menu.getComponent() :
"Layout");
routerVO.setMeta(routerVO.new Meta(
menu.getName(), menu.getName(),
menu.getIcon(), menu.getIcon(),
menu.getRoles() menu.getRoles()
); ));
routerVO.setMeta(meta);
if (AdminConstant.ROOT_MENU_ID == parentId) {
routerVO.setAlwaysShow(Boolean.TRUE);
routerVO.setRedirect("noRedirect");
}
List<RouterVO> children = recursionForRoutes(menu.getId(), menuList); List<RouterVO> children = recursionForRoutes(menu.getId(), menuList);
routerVO.setChildren(children); routerVO.setChildren(children);
list.add(routerVO); list.add(routerVO);

View File

@ -20,8 +20,8 @@ public class AdminApplicationTests {
private ISysMenuService iSysMenuService; private ISysMenuService iSysMenuService;
@Test @Test
public void testlistForRoute() { public void testlistForRouter() {
List list = iSysMenuService.listForRoute(); List list = iSysMenuService.listForRouter();
Assert.isTrue(list.size()>0); Assert.isTrue(list.size()>0);
} }
} }