给菜单增加系统类型,并增加根据用户和系统类型返回菜单树的接口
This commit is contained in:
parent
cc0f108d2b
commit
4063d1c3c7
|
|
@ -69,8 +69,8 @@ public class SysMenu extends BaseEntity
|
||||||
/** 子菜单 */
|
/** 子菜单 */
|
||||||
private List<SysMenu> children = new ArrayList<SysMenu>();
|
private List<SysMenu> children = new ArrayList<SysMenu>();
|
||||||
|
|
||||||
// /** 系统类型 */
|
/** 系统类型 */
|
||||||
// private String systemType;
|
private String systemType;
|
||||||
|
|
||||||
public Long getMenuId()
|
public Long getMenuId()
|
||||||
{
|
{
|
||||||
|
|
@ -239,13 +239,13 @@ public class SysMenu extends BaseEntity
|
||||||
this.children = children;
|
this.children = children;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public String getSystemType() {
|
public String getSystemType() {
|
||||||
// return systemType;
|
return systemType;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public void setSystemType(String systemType) {
|
public void setSystemType(String systemType) {
|
||||||
// this.systemType = systemType;
|
this.systemType = systemType;
|
||||||
// }
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
@ -268,7 +268,7 @@ public class SysMenu extends BaseEntity
|
||||||
.append("updateBy", getUpdateBy())
|
.append("updateBy", getUpdateBy())
|
||||||
.append("updateTime", getUpdateTime())
|
.append("updateTime", getUpdateTime())
|
||||||
.append("remark", getRemark())
|
.append("remark", getRemark())
|
||||||
// .append("systemType", getSystemType())
|
.append("systemType", getSystemType())
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import com.bonus.common.log.enums.OperaType;
|
||||||
import com.bonus.common.security.annotation.InnerAuth;
|
import com.bonus.common.security.annotation.InnerAuth;
|
||||||
import com.bonus.common.security.annotation.RequiresPermissionsOrInnerAuth;
|
import com.bonus.common.security.annotation.RequiresPermissionsOrInnerAuth;
|
||||||
import com.bonus.system.api.domain.SysMenu;
|
import com.bonus.system.api.domain.SysMenu;
|
||||||
|
import com.bonus.system.domain.UserMenuParams;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
@ -188,4 +189,22 @@ public class SysMenuController extends BaseController
|
||||||
}
|
}
|
||||||
return error("系统异常");
|
return error("系统异常");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当前登录用户 指定系统类型(大屏,后台或APP)的 菜单树信息
|
||||||
|
* @return 路由信息
|
||||||
|
*/
|
||||||
|
@GetMapping("getRouters/{systemType}")
|
||||||
|
public AjaxResult getRoutersBySystemType(@PathVariable("systemType")Long systemType) {
|
||||||
|
try{
|
||||||
|
|
||||||
|
Long userId = SecurityUtils.getUserId();
|
||||||
|
UserMenuParams userMenuParams = new UserMenuParams(userId, systemType);
|
||||||
|
List<SysMenu> menus = menuService.selectMenuTreeByUserIdAndSystemType(userMenuParams);
|
||||||
|
return success(menuService.buildMenus(menus));
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.toString(),e);
|
||||||
|
}
|
||||||
|
return error("系统异常");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.bonus.system.domain;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wangvivi
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class UserMenuParams {
|
||||||
|
private Long userId;
|
||||||
|
private Long systemType;
|
||||||
|
|
||||||
|
UserMenuParams(){}
|
||||||
|
|
||||||
|
public UserMenuParams(Long userId, Long systemType){
|
||||||
|
this.userId = userId;
|
||||||
|
this.systemType = systemType;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package com.bonus.system.mapper;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.bonus.system.api.domain.SysMenu;
|
import com.bonus.system.api.domain.SysMenu;
|
||||||
|
import com.bonus.system.domain.UserMenuParams;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -66,6 +67,15 @@ public interface SysMenuMapper
|
||||||
*/
|
*/
|
||||||
public List<SysMenu> selectMenuTreeByUserId(Long userId);
|
public List<SysMenu> selectMenuTreeByUserId(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户ID查询菜单
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param systemType 系统类型
|
||||||
|
* @return 菜单列表
|
||||||
|
*/
|
||||||
|
public List<SysMenu> selectMenuTreeByUserIdAndSystemType(UserMenuParams userMenuParamse);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色ID查询菜单树信息
|
* 根据角色ID查询菜单树信息
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.bonus.system.api.domain.SysMenu;
|
import com.bonus.system.api.domain.SysMenu;
|
||||||
|
import com.bonus.system.domain.UserMenuParams;
|
||||||
import com.bonus.system.domain.vo.RouterVo;
|
import com.bonus.system.domain.vo.RouterVo;
|
||||||
import com.bonus.system.domain.vo.TreeSelect;
|
import com.bonus.system.domain.vo.TreeSelect;
|
||||||
|
|
||||||
|
|
@ -55,6 +56,13 @@ public interface ISysMenuService
|
||||||
*/
|
*/
|
||||||
public List<SysMenu> selectMenuTreeByUserId(Long userId);
|
public List<SysMenu> selectMenuTreeByUserId(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户ID和系统类型查询菜单树信息
|
||||||
|
* @param userMenuParams 用户ID和系统类型
|
||||||
|
* @return 菜单列表
|
||||||
|
*/
|
||||||
|
public List<SysMenu> selectMenuTreeByUserIdAndSystemType(UserMenuParams userMenuParams);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色ID查询菜单树信息
|
* 根据角色ID查询菜单树信息
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.bonus.system.api.domain.SysMenu;
|
import com.bonus.system.api.domain.SysMenu;
|
||||||
|
import com.bonus.system.domain.UserMenuParams;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.bonus.common.core.constant.Constants;
|
import com.bonus.common.core.constant.Constants;
|
||||||
|
|
@ -132,6 +133,22 @@ public class SysMenuServiceImpl implements ISysMenuService
|
||||||
return getChildPerms(menus, 0);
|
return getChildPerms(menus, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysMenu> selectMenuTreeByUserIdAndSystemType(UserMenuParams userMenuParams){
|
||||||
|
|
||||||
|
List<SysMenu> menus = null;
|
||||||
|
if (SecurityUtils.isAdmin(userMenuParams.getUserId()))
|
||||||
|
{
|
||||||
|
menus = menuMapper.selectMenuTreeAll();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
menus = menuMapper.selectMenuTreeByUserIdAndSystemType(userMenuParams);
|
||||||
|
}
|
||||||
|
return getChildPerms(menus, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色ID查询菜单树信息
|
* 根据角色ID查询菜单树信息
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,11 @@
|
||||||
<result property="updateTime" column="update_time" />
|
<result property="updateTime" column="update_time" />
|
||||||
<result property="updateBy" column="update_by" />
|
<result property="updateBy" column="update_by" />
|
||||||
<result property="remark" column="remark" />
|
<result property="remark" column="remark" />
|
||||||
<!-- <result property="systemType" column="system_type"/>-->
|
<result property="systemType" column="system_type"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectMenuVo">
|
<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, system_type
|
||||||
from sys_menu
|
from sys_menu
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
|
@ -85,6 +85,17 @@
|
||||||
order by m.parent_id, m.order_num
|
order by m.parent_id, m.order_num
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectMenuTreeByUserIdAndSystemType" parameterType="com.bonus.system.domain.UserMenuParams" 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
|
||||||
|
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 AND FIND_IN_SET(#{systemType}, m.system_type)
|
||||||
|
order by m.parent_id, m.order_num
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="selectMenuListByRoleId" resultType="Long">
|
<select id="selectMenuListByRoleId" resultType="Long">
|
||||||
select m.menu_id
|
select m.menu_id
|
||||||
from sys_menu m
|
from sys_menu m
|
||||||
|
|
@ -151,7 +162,7 @@
|
||||||
<if test="icon !=null and icon != ''">icon = #{icon},</if>
|
<if test="icon !=null and icon != ''">icon = #{icon},</if>
|
||||||
<if test="remark != null and remark != ''">remark = #{remark},</if>
|
<if test="remark != null and remark != ''">remark = #{remark},</if>
|
||||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||||
<!-- <if test="systemType != null and systemType != ''">system_type = #{systemType},</if>-->
|
<if test="systemType != null and systemType != ''">system_type = #{systemType},</if>
|
||||||
update_time = sysdate()
|
update_time = sysdate()
|
||||||
</set>
|
</set>
|
||||||
where menu_id = #{menuId}
|
where menu_id = #{menuId}
|
||||||
|
|
@ -175,7 +186,7 @@
|
||||||
<if test="icon != null and icon != ''">icon,</if>
|
<if test="icon != null and icon != ''">icon,</if>
|
||||||
<if test="remark != null and remark != ''">remark,</if>
|
<if test="remark != null and remark != ''">remark,</if>
|
||||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||||
<!-- <if test="systemType != null and systemType != ''">system_type,</if>-->
|
<if test="systemType != null and systemType != ''">system_type,</if>
|
||||||
create_time
|
create_time
|
||||||
)values(
|
)values(
|
||||||
<if test="menuId != null and menuId != 0">#{menuId},</if>
|
<if test="menuId != null and menuId != 0">#{menuId},</if>
|
||||||
|
|
@ -194,7 +205,7 @@
|
||||||
<if test="icon != null and icon != ''">#{icon},</if>
|
<if test="icon != null and icon != ''">#{icon},</if>
|
||||||
<if test="remark != null and remark != ''">#{remark},</if>
|
<if test="remark != null and remark != ''">#{remark},</if>
|
||||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||||
<!-- <if test="systemType != null and systemType != ''">#{systemType},</if>-->
|
<if test="systemType != null and systemType != ''">#{systemType},</if>
|
||||||
sysdate()
|
sysdate()
|
||||||
)
|
)
|
||||||
</insert>
|
</insert>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue