mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-23 05:00:25 +08:00
动态权限接口
This commit is contained in:
parent
a3bc6a1bcd
commit
1370634c91
@ -71,8 +71,8 @@ public class SysMenuController {
|
||||
map.put("checkedKeys", checkedKeys);
|
||||
return Result.success(map);
|
||||
}
|
||||
}else if(mode.equals(3)){
|
||||
list = iSysMenuService.listForRoute();
|
||||
} else if (mode.equals(3)) {
|
||||
list = iSysMenuService.listForRouter();
|
||||
} else {
|
||||
list = iSysMenuService.list(baseQuery);
|
||||
}
|
||||
@ -83,29 +83,28 @@ public class SysMenuController {
|
||||
@ApiImplicitParam(name = "id", value = "菜单id", required = true, paramType = "path", dataType = "Integer")
|
||||
@GetMapping("/{id}")
|
||||
public Result detail(@PathVariable Integer id) {
|
||||
SysMenu sysMenu = iSysMenuService.getById(id);
|
||||
return Result.success(sysMenu);
|
||||
SysMenu menu = iSysMenuService.getById(id);
|
||||
return Result.success(menu);
|
||||
}
|
||||
|
||||
@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
|
||||
public Result add(@RequestBody SysMenu sysMenu) {
|
||||
boolean status = iSysMenuService.save(sysMenu);
|
||||
public Result add(@RequestBody SysMenu menu) {
|
||||
boolean status = iSysMenuService.save(menu);
|
||||
return Result.status(status);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改菜单", httpMethod = "PUT")
|
||||
@ApiImplicitParams({
|
||||
@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}")
|
||||
public Result update(
|
||||
@PathVariable Integer id,
|
||||
@RequestBody SysMenu sysMenu) {
|
||||
sysMenu.setUpdateTime(new Date());
|
||||
boolean status = iSysMenuService.updateById(sysMenu);
|
||||
@RequestBody SysMenu menu) {
|
||||
boolean status = iSysMenuService.updateById(menu);
|
||||
return Result.status(status);
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
package com.youlai.admin.domain.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.youlai.common.core.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SysMenu extends BaseEntity {
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
public class SysMenu extends BaseEntity {
|
||||
|
||||
@TableId
|
||||
private Integer id;
|
||||
@ -32,6 +33,10 @@ public class SysMenu extends BaseEntity {
|
||||
|
||||
private String perms;
|
||||
|
||||
private String redirect;
|
||||
|
||||
private Integer type;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<Integer> roles;
|
||||
|
||||
|
@ -22,6 +22,8 @@ public class MenuVO extends BaseEntity {
|
||||
|
||||
private Integer status;
|
||||
|
||||
private String component;
|
||||
|
||||
private String path;
|
||||
|
||||
private String perms;
|
||||
|
@ -22,5 +22,5 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||
@Result(id=true, column="id", property="id"),
|
||||
@Result(property = "roles",column="id",many = @Many(select="com.youlai.admin.mapper.SysRoleMenuMapper.listByMenuId"))
|
||||
})
|
||||
List<SysMenu> listForRoute();
|
||||
List<SysMenu> listForRouter();
|
||||
}
|
||||
|
@ -16,5 +16,5 @@ public interface ISysMenuService extends IService<SysMenu> {
|
||||
|
||||
List<TreeSelectVO> listForTreeSelect(LambdaQueryWrapper<SysMenu> baseQuery);
|
||||
|
||||
List listForRoute();
|
||||
List listForRouter();
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import com.youlai.admin.domain.vo.RouterVO;
|
||||
import com.youlai.admin.domain.vo.TreeSelectVO;
|
||||
import com.youlai.admin.mapper.SysMenuMapper;
|
||||
import com.youlai.admin.service.ISysMenuService;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -37,8 +36,8 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public List listForRoute() {
|
||||
List<SysMenu> menuList = this.baseMapper.listForRoute();
|
||||
public List listForRouter() {
|
||||
List<SysMenu> menuList = this.baseMapper.listForRouter();
|
||||
List<RouterVO> list = recursionForRoutes(AdminConstant.ROOT_MENU_ID, menuList);
|
||||
return list;
|
||||
}
|
||||
@ -51,20 +50,23 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
.forEach(menu -> {
|
||||
RouterVO routerVO = new RouterVO();
|
||||
routerVO.setName(menu.getName());
|
||||
routerVO.setPath(menu.getPath());
|
||||
String component = StrUtil.isNotBlank(menu.getComponent()) ? menu.getComponent() : "Layout";
|
||||
routerVO.setComponent(component);
|
||||
RouterVO.Meta meta = routerVO.new Meta(
|
||||
if (parentId == AdminConstant.ROOT_MENU_ID) {
|
||||
routerVO.setAlwaysShow(Boolean.TRUE);
|
||||
routerVO.setPath("/" + menu.getPath());
|
||||
} 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.getIcon(),
|
||||
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);
|
||||
routerVO.setChildren(children);
|
||||
list.add(routerVO);
|
||||
|
@ -20,8 +20,8 @@ public class AdminApplicationTests {
|
||||
private ISysMenuService iSysMenuService;
|
||||
|
||||
@Test
|
||||
public void testlistForRoute() {
|
||||
List list = iSysMenuService.listForRoute();
|
||||
public void testlistForRouter() {
|
||||
List list = iSysMenuService.listForRouter();
|
||||
Assert.isTrue(list.size()>0);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user