权限管理代码

This commit is contained in:
likehai 2023-10-26 02:11:57 +08:00
parent 361378885b
commit 35a0ef83bd
6 changed files with 386 additions and 379 deletions

View File

@ -1,6 +1,7 @@
package com.god.web.controller.system;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@ -28,8 +29,7 @@ import com.god.system.service.ISysMenuService;
*/
@RestController
@RequestMapping("/system/menu")
public class SysMenuController extends BaseController
{
public class SysMenuController extends BaseController {
@Autowired
private ISysMenuService menuService;
@ -38,8 +38,7 @@ public class SysMenuController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('system:menu:list')")
@GetMapping("/list")
public AjaxResult list(SysMenu menu)
{
public AjaxResult list(SysMenu menu) {
List<SysMenu> menus = menuService.selectMenuList(menu, getUserId());
return success(menus);
}
@ -49,8 +48,7 @@ public class SysMenuController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('system:menu:query')")
@GetMapping(value = "/{menuId}")
public AjaxResult getInfo(@PathVariable Long menuId)
{
public AjaxResult getInfo(@PathVariable Long menuId) {
return success(menuService.selectMenuById(menuId));
}
@ -58,8 +56,7 @@ public class SysMenuController extends BaseController
* 获取菜单下拉树列表
*/
@GetMapping("/treeselect")
public AjaxResult treeselect(SysMenu menu)
{
public AjaxResult treeselect(SysMenu menu) {
List<SysMenu> menus = menuService.selectMenuList(menu, getUserId());
return success(menuService.buildMenuTreeSelect(menus));
}
@ -68,8 +65,7 @@ public class SysMenuController extends BaseController
* 加载对应角色菜单列表树
*/
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId)
{
public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) {
List<SysMenu> menus = menuService.selectMenuList(getUserId());
AjaxResult ajax = AjaxResult.success();
ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId));
@ -83,14 +79,10 @@ public class SysMenuController extends BaseController
@PreAuthorize("@ss.hasPermi('system:menu:add')")
@Log(title = "菜单管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody SysMenu menu)
{
if (!menuService.checkMenuNameUnique(menu))
{
public AjaxResult add(@Validated @RequestBody SysMenu menu) {
if (!menuService.checkMenuNameUnique(menu)) {
return error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
}
else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath()))
{
} else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath())) {
return error("新增菜单'" + menu.getMenuName() + "'失败地址必须以http(s)://开头");
}
menu.setCreateBy(getUsername());
@ -103,18 +95,12 @@ public class SysMenuController extends BaseController
@PreAuthorize("@ss.hasPermi('system:menu:edit')")
@Log(title = "菜单管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysMenu menu)
{
if (!menuService.checkMenuNameUnique(menu))
{
public AjaxResult edit(@Validated @RequestBody SysMenu menu) {
if (!menuService.checkMenuNameUnique(menu)) {
return error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
}
else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath()))
{
} else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath())) {
return error("修改菜单'" + menu.getMenuName() + "'失败地址必须以http(s)://开头");
}
else if (menu.getMenuId().equals(menu.getParentId()))
{
} else if (menu.getMenuId().equals(menu.getParentId())) {
return error("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
}
menu.setUpdateBy(getUsername());
@ -127,14 +113,11 @@ public class SysMenuController extends BaseController
@PreAuthorize("@ss.hasPermi('system:menu:remove')")
@Log(title = "菜单管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{menuId}")
public AjaxResult remove(@PathVariable("menuId") Long menuId)
{
if (menuService.hasChildByMenuId(menuId))
{
public AjaxResult remove(@PathVariable("menuId") Long menuId) {
if (menuService.hasChildByMenuId(menuId)) {
return warn("存在子菜单,不允许删除");
}
if (menuService.checkMenuExistRole(menuId))
{
if (menuService.checkMenuExistRole(menuId)) {
return warn("菜单已分配,不允许删除");
}
return toAjax(menuService.deleteMenuById(menuId));

View File

@ -8,6 +8,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import com.god.common.utils.http.HttpSeverGet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.god.common.constant.Constants;
@ -25,14 +27,15 @@ import com.god.system.mapper.SysRoleMapper;
import com.god.system.mapper.SysRoleMenuMapper;
import com.god.system.service.ISysMenuService;
import javax.servlet.http.HttpServletRequest;
/**
* 菜单 业务层处理
*
* @author god
*/
@Service
public class SysMenuServiceImpl implements ISysMenuService
{
public class SysMenuServiceImpl implements ISysMenuService {
public static final String PREMISSION_STRING = "perms[\"{0}\"]";
@Autowired
@ -44,6 +47,9 @@ public class SysMenuServiceImpl implements ISysMenuService
@Autowired
private SysRoleMenuMapper roleMenuMapper;
@Autowired
private HttpServletRequest request;
/**
* 根据用户查询系统菜单列表
*
@ -51,8 +57,7 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 菜单列表
*/
@Override
public List<SysMenu> selectMenuList(Long userId)
{
public List<SysMenu> selectMenuList(Long userId) {
return selectMenuList(new SysMenu(), userId);
}
@ -63,16 +68,16 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 菜单列表
*/
@Override
public List<SysMenu> selectMenuList(SysMenu menu, Long userId)
{
public List<SysMenu> selectMenuList(SysMenu menu, Long userId) {
List<SysMenu> menuList = null;
// 管理员显示所有菜单信息
if (SysUser.isAdmin(userId))
{
if (SysUser.isAdmin(userId)) {
menuList = menuMapper.selectMenuList(menu);
}
else
{
} else {
// menu.setPortNum(HttpSeverGet.getPort(request));
// if(StringUtils.isNull(menu.getDistinctionNum())){
// menu.setDistinctionNum("0");
// }
menu.getParams().put("userId", userId);
menuList = menuMapper.selectMenuListByUserId(menu);
}
@ -86,14 +91,11 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 权限列表
*/
@Override
public Set<String> selectMenuPermsByUserId(Long userId)
{
public Set<String> selectMenuPermsByUserId(Long userId) {
List<String> perms = menuMapper.selectMenuPermsByUserId(userId);
Set<String> permsSet = new HashSet<>();
for (String perm : perms)
{
if (StringUtils.isNotEmpty(perm))
{
for (String perm : perms) {
if (StringUtils.isNotEmpty(perm)) {
permsSet.addAll(Arrays.asList(perm.trim().split(",")));
}
}
@ -107,14 +109,11 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 权限列表
*/
@Override
public Set<String> selectMenuPermsByRoleId(Long roleId)
{
public Set<String> selectMenuPermsByRoleId(Long roleId) {
List<String> perms = menuMapper.selectMenuPermsByRoleId(roleId);
Set<String> permsSet = new HashSet<>();
for (String perm : perms)
{
if (StringUtils.isNotEmpty(perm))
{
for (String perm : perms) {
if (StringUtils.isNotEmpty(perm)) {
permsSet.addAll(Arrays.asList(perm.trim().split(",")));
}
}
@ -128,15 +127,11 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 菜单列表
*/
@Override
public List<SysMenu> selectMenuTreeByUserId(Long userId)
{
public List<SysMenu> selectMenuTreeByUserId(Long userId) {
List<SysMenu> menus = null;
if (SecurityUtils.isAdmin(userId))
{
if (SecurityUtils.isAdmin(userId)) {
menus = menuMapper.selectMenuTreeAll();
}
else
{
} else {
menus = menuMapper.selectMenuTreeByUserId(userId);
}
return getChildPerms(menus, 0);
@ -149,8 +144,7 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 选中菜单列表
*/
@Override
public List<Long> selectMenuListByRoleId(Long roleId)
{
public List<Long> selectMenuListByRoleId(Long roleId) {
SysRole role = roleMapper.selectRoleById(roleId);
return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly());
}
@ -162,11 +156,9 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 路由列表
*/
@Override
public List<RouterVo> buildMenus(List<SysMenu> menus)
{
public List<RouterVo> buildMenus(List<SysMenu> menus) {
List<RouterVo> routers = new LinkedList<RouterVo>();
for (SysMenu menu : menus)
{
for (SysMenu menu : menus) {
RouterVo router = new RouterVo();
router.setHidden("1".equals(menu.getVisible()));
router.setName(getRouteName(menu));
@ -175,14 +167,11 @@ public class SysMenuServiceImpl implements ISysMenuService
router.setQuery(menu.getQuery());
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
List<SysMenu> cMenus = menu.getChildren();
if (StringUtils.isNotEmpty(cMenus) && UserConstants.TYPE_DIR.equals(menu.getMenuType()))
{
if (StringUtils.isNotEmpty(cMenus) && UserConstants.TYPE_DIR.equals(menu.getMenuType())) {
router.setAlwaysShow(true);
router.setRedirect("noRedirect");
router.setChildren(buildMenus(cMenus));
}
else if (isMenuFrame(menu))
{
} else if (isMenuFrame(menu)) {
router.setMeta(null);
List<RouterVo> childrenList = new ArrayList<RouterVo>();
RouterVo children = new RouterVo();
@ -193,9 +182,7 @@ public class SysMenuServiceImpl implements ISysMenuService
children.setQuery(menu.getQuery());
childrenList.add(children);
router.setChildren(childrenList);
}
else if (menu.getParentId().intValue() == 0 && isInnerLink(menu))
{
} else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) {
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
router.setPath("/");
List<RouterVo> childrenList = new ArrayList<RouterVo>();
@ -220,22 +207,18 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 树结构列表
*/
@Override
public List<SysMenu> buildMenuTree(List<SysMenu> menus)
{
public List<SysMenu> buildMenuTree(List<SysMenu> menus) {
List<SysMenu> returnList = new ArrayList<SysMenu>();
List<Long> tempList = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList());
for (Iterator<SysMenu> iterator = menus.iterator(); iterator.hasNext();)
{
for (Iterator<SysMenu> iterator = menus.iterator(); iterator.hasNext(); ) {
SysMenu menu = (SysMenu) iterator.next();
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(menu.getParentId()))
{
if (!tempList.contains(menu.getParentId())) {
recursionFn(menus, menu);
returnList.add(menu);
}
}
if (returnList.isEmpty())
{
if (returnList.isEmpty()) {
returnList = menus;
}
return returnList;
@ -248,8 +231,7 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 下拉树结构列表
*/
@Override
public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus)
{
public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus) {
List<SysMenu> menuTrees = buildMenuTree(menus);
return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
}
@ -261,8 +243,7 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 菜单信息
*/
@Override
public SysMenu selectMenuById(Long menuId)
{
public SysMenu selectMenuById(Long menuId) {
return menuMapper.selectMenuById(menuId);
}
@ -273,8 +254,7 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 结果
*/
@Override
public boolean hasChildByMenuId(Long menuId)
{
public boolean hasChildByMenuId(Long menuId) {
int result = menuMapper.hasChildByMenuId(menuId);
return result > 0;
}
@ -286,8 +266,7 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 结果
*/
@Override
public boolean checkMenuExistRole(Long menuId)
{
public boolean checkMenuExistRole(Long menuId) {
int result = roleMenuMapper.checkMenuExistRole(menuId);
return result > 0;
}
@ -299,8 +278,9 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 结果
*/
@Override
public int insertMenu(SysMenu menu)
{
public int insertMenu(SysMenu menu) {
//端口赋值
menu.setPortNum(HttpSeverGet.getPort(request));
return menuMapper.insertMenu(menu);
}
@ -311,8 +291,7 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 结果
*/
@Override
public int updateMenu(SysMenu menu)
{
public int updateMenu(SysMenu menu) {
return menuMapper.updateMenu(menu);
}
@ -323,8 +302,7 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 结果
*/
@Override
public int deleteMenuById(Long menuId)
{
public int deleteMenuById(Long menuId) {
return menuMapper.deleteMenuById(menuId);
}
@ -335,12 +313,10 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 结果
*/
@Override
public boolean checkMenuNameUnique(SysMenu menu)
{
public boolean checkMenuNameUnique(SysMenu menu) {
Long menuId = StringUtils.isNull(menu.getMenuId()) ? -1L : menu.getMenuId();
SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId());
if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue())
{
if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue()) {
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
@ -352,12 +328,10 @@ public class SysMenuServiceImpl implements ISysMenuService
* @param menu 菜单信息
* @return 路由名称
*/
public String getRouteName(SysMenu menu)
{
public String getRouteName(SysMenu menu) {
String routerName = StringUtils.capitalize(menu.getPath());
// 非外链并且是一级目录类型为目录
if (isMenuFrame(menu))
{
if (isMenuFrame(menu)) {
routerName = StringUtils.EMPTY;
}
return routerName;
@ -369,23 +343,19 @@ public class SysMenuServiceImpl implements ISysMenuService
* @param menu 菜单信息
* @return 路由地址
*/
public String getRouterPath(SysMenu menu)
{
public String getRouterPath(SysMenu menu) {
String routerPath = menu.getPath();
// 内链打开外网方式
if (menu.getParentId().intValue() != 0 && isInnerLink(menu))
{
if (menu.getParentId().intValue() != 0 && isInnerLink(menu)) {
routerPath = innerLinkReplaceEach(routerPath);
}
// 非外链并且是一级目录类型为目录
if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType())
&& UserConstants.NO_FRAME.equals(menu.getIsFrame()))
{
&& UserConstants.NO_FRAME.equals(menu.getIsFrame())) {
routerPath = "/" + menu.getPath();
}
// 非外链并且是一级目录类型为菜单
else if (isMenuFrame(menu))
{
else if (isMenuFrame(menu)) {
routerPath = "/";
}
return routerPath;
@ -397,19 +367,13 @@ public class SysMenuServiceImpl implements ISysMenuService
* @param menu 菜单信息
* @return 组件信息
*/
public String getComponent(SysMenu menu)
{
public String getComponent(SysMenu menu) {
String component = UserConstants.LAYOUT;
if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu))
{
if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) {
component = menu.getComponent();
}
else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu))
{
} else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu)) {
component = UserConstants.INNER_LINK;
}
else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu))
{
} else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) {
component = UserConstants.PARENT_VIEW;
}
return component;
@ -421,8 +385,7 @@ public class SysMenuServiceImpl implements ISysMenuService
* @param menu 菜单信息
* @return 结果
*/
public boolean isMenuFrame(SysMenu menu)
{
public boolean isMenuFrame(SysMenu menu) {
return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType())
&& menu.getIsFrame().equals(UserConstants.NO_FRAME);
}
@ -433,8 +396,7 @@ public class SysMenuServiceImpl implements ISysMenuService
* @param menu 菜单信息
* @return 结果
*/
public boolean isInnerLink(SysMenu menu)
{
public boolean isInnerLink(SysMenu menu) {
return menu.getIsFrame().equals(UserConstants.NO_FRAME) && StringUtils.ishttp(menu.getPath());
}
@ -444,8 +406,7 @@ public class SysMenuServiceImpl implements ISysMenuService
* @param menu 菜单信息
* @return 结果
*/
public boolean isParentView(SysMenu menu)
{
public boolean isParentView(SysMenu menu) {
return menu.getParentId().intValue() != 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType());
}
@ -456,15 +417,12 @@ public class SysMenuServiceImpl implements ISysMenuService
* @param parentId 传入的父节点ID
* @return String
*/
public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId)
{
public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId) {
List<SysMenu> returnList = new ArrayList<SysMenu>();
for (Iterator<SysMenu> iterator = list.iterator(); iterator.hasNext();)
{
for (Iterator<SysMenu> iterator = list.iterator(); iterator.hasNext(); ) {
SysMenu t = (SysMenu) iterator.next();
// 根据传入的某个父节点ID,遍历该父节点的所有子节点
if (t.getParentId() == parentId)
{
if (t.getParentId() == parentId) {
recursionFn(list, t);
returnList.add(t);
}
@ -478,15 +436,12 @@ public class SysMenuServiceImpl implements ISysMenuService
* @param list 分类表
* @param t 子节点
*/
private void recursionFn(List<SysMenu> list, SysMenu t)
{
private void recursionFn(List<SysMenu> list, SysMenu t) {
// 得到子节点列表
List<SysMenu> childList = getChildList(list, t);
t.setChildren(childList);
for (SysMenu tChild : childList)
{
if (hasChild(list, tChild))
{
for (SysMenu tChild : childList) {
if (hasChild(list, tChild)) {
recursionFn(list, tChild);
}
}
@ -495,15 +450,12 @@ public class SysMenuServiceImpl implements ISysMenuService
/**
* 得到子节点列表
*/
private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t)
{
private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t) {
List<SysMenu> tlist = new ArrayList<SysMenu>();
Iterator<SysMenu> it = list.iterator();
while (it.hasNext())
{
while (it.hasNext()) {
SysMenu n = (SysMenu) it.next();
if (n.getParentId().longValue() == t.getMenuId().longValue())
{
if (n.getParentId().longValue() == t.getMenuId().longValue()) {
tlist.add(n);
}
}
@ -513,8 +465,7 @@ public class SysMenuServiceImpl implements ISysMenuService
/**
* 判断是否有子节点
*/
private boolean hasChild(List<SysMenu> list, SysMenu t)
{
private boolean hasChild(List<SysMenu> list, SysMenu t) {
return getChildList(list, t).size() > 0;
}
@ -523,8 +474,7 @@ public class SysMenuServiceImpl implements ISysMenuService
*
* @return 替换后的内链域名
*/
public String innerLinkReplaceEach(String path)
{
public String innerLinkReplaceEach(String path) {
return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, "."},
new String[]{"", "", "", "/"});
}

View File

@ -25,10 +25,26 @@
<result property="updateTime" column="update_time"/>
<result property="updateBy" column="update_by"/>
<result property="remark" column="remark"/>
<result property="portNum" column="port_num"/>
<result property="distinctionNum" column="distinction_num"/>
</resultMap>
<sql id="selectMenuVo">
select menu_id, menu_name, parent_id, order_num, path, component, `query`, is_frame, is_cache, menu_type, visible, status, ifnull(perms,'') as perms, icon, create_time
select menu_id,
menu_name,
parent_id,
order_num,
path,
component,
`query`,
is_frame,
is_cache,
menu_type,
visible,
status,
ifnull(perms, '') as perms,
icon,
create_time
from sys_menu
</sql>
@ -44,18 +60,41 @@
<if test="status != null and status != ''">
AND status = #{status}
</if>
<if test="portNum != null and portNum != ''">
AND port_num = #{portNum}
</if>
<if test="distinctionNum != null and distinctionNum != ''">
AND distinction_num = #{distinctionNum}
</if>
</where>
order by parent_id, order_num
</select>
<select id="selectMenuTreeAll" resultMap="SysMenuResult">
select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
from sys_menu m where m.menu_type in ('M', 'C') and m.status = 0
select distinct m.menu_id,
m.parent_id,
m.menu_name,
m.path,
m.component,
m.`query`,
m.visible,
m.status,
ifnull(m.perms, '') as perms,
m.is_frame,
m.is_cache,
m.menu_type,
m.icon,
m.order_num,
m.create_time
from sys_menu m
where m.menu_type in ('M', 'C')
and m.status = 0
order by m.parent_id, m.order_num
</select>
<select id="selectMenuListByUserId" parameterType="SysMenu" resultMap="SysMenuResult">
select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status,
ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id
left join sys_user_role ur on rm.role_id = ur.role_id
@ -70,17 +109,40 @@
<if test="status != null and status != ''">
AND m.status = #{status}
</if>
<if test="portNum != null and portNum != ''">
AND m.port_num = #{portNum}
</if>
<if test="distinctionNum != null and distinctionNum != ''">
AND m.distinction_num = #{distinctionNum}
</if>
order by m.parent_id, m.order_num
</select>
<select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult">
select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
select distinct m.menu_id,
m.parent_id,
m.menu_name,
m.path,
m.component,
m.`query`,
m.visible,
m.status,
ifnull(m.perms, '') as perms,
m.is_frame,
m.is_cache,
m.menu_type,
m.icon,
m.order_num,
m.create_time
from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id
left join sys_user_role ur on rm.role_id = ur.role_id
left join sys_role ro on ur.role_id = ro.role_id
left join sys_user u on ur.user_id = u.user_id
where u.user_id = #{userId} and m.menu_type in ('M', 'C') and m.status = 0 AND ro.status = 0
where u.user_id = #{userId}
and m.menu_type in ('M', 'C')
and m.status = 0
AND ro.status = 0
order by m.parent_id, m.order_num
</select>
@ -90,7 +152,8 @@
left join sys_role_menu rm on m.menu_id = rm.menu_id
where rm.role_id = #{roleId}
<if test="menuCheckStrictly">
and m.menu_id not in (select m.parent_id from sys_menu m inner join sys_role_menu rm on m.menu_id = rm.menu_id and rm.role_id = #{roleId})
and m.menu_id not in (select m.parent_id from sys_menu m inner join sys_role_menu rm on m.menu_id =
rm.menu_id and rm.role_id = #{roleId})
</if>
order by m.parent_id, m.order_num
</select>
@ -108,14 +171,17 @@
left join sys_role_menu rm on m.menu_id = rm.menu_id
left join sys_user_role ur on rm.role_id = ur.role_id
left join sys_role r on r.role_id = ur.role_id
where m.status = '0' and r.status = '0' and ur.user_id = #{userId}
where m.status = '0'
and r.status = '0'
and ur.user_id = #{userId}
</select>
<select id="selectMenuPermsByRoleId" parameterType="Long" resultType="String">
select distinct m.perms
from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id
where m.status = '0' and rm.role_id = #{roleId}
where m.status = '0'
and rm.role_id = #{roleId}
</select>
<select id="selectMenuById" parameterType="Long" resultMap="SysMenuResult">
@ -124,7 +190,9 @@
</select>
<select id="hasChildByMenuId" resultType="Integer">
select count(1) from sys_menu where parent_id = #{menuId}
select count(1)
from sys_menu
where parent_id = #{menuId}
</select>
<select id="checkMenuNameUnique" parameterType="SysMenu" resultMap="SysMenuResult">
@ -173,6 +241,8 @@
<if test="icon != null and icon != ''">icon,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="portNum != null and portNum != ''">port_num,</if>
<if test="distinctionNum != null and distinctionNum != ''">distinction_num,</if>
create_time
)values(
<if test="menuId != null and menuId != 0">#{menuId},</if>
@ -191,12 +261,16 @@
<if test="icon != null and icon != ''">#{icon},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="portNum != null and portNum != ''">#{portNum},</if>
<if test="distinctionNum != null and distinctionNum != ''">#{distinctionNum},</if>
sysdate()
)
</insert>
<delete id="deleteMenuById" parameterType="Long">
delete from sys_menu where menu_id = #{menuId}
delete
from sys_menu
where menu_id = #{menuId}
</delete>
</mapper>

View File

@ -341,7 +341,7 @@ export default {
queryParams: {
pageNum: 1,
pageSize: 10,
distinctionNum: 1406,
distinctionNum: 91406,
roleName: undefined,
roleKey: undefined,
status: undefined
@ -579,7 +579,7 @@ export default {
/** 提交按钮 */
submitForm: function() {
this.$refs['form'].validate(valid => {
this.form.distinctionNum = 1406
this.form.distinctionNum = 91406
if (valid) {
if (this.form.roleId != undefined) {
this.form.menuIds = this.getMenuAllCheckedKeys()

View File

@ -80,7 +80,7 @@ export default {
queryParams: {
pageNum: 1,
pageSize: 10,
distinctionNum: 1406,
distinctionNum: 91406,
roleId: undefined,
userName: undefined,
phonenumber: undefined

View File

@ -407,7 +407,7 @@ export default {
queryParams: {
pageNum: 1,
pageSize: 10,
distinctionNum: 1406,
distinctionNum: 91406,
userName: undefined,
phonenumber: undefined,
status: undefined,
@ -607,7 +607,7 @@ export default {
/** 提交按钮 */
submitForm: function() {
this.$refs["form"].validate(valid => {
this.form.distinctionNum = 1406
this.form.distinctionNum = 91406
if (valid) {
if (this.form.userId != undefined) {
updateUser(this.form).then(response => {