fix: 手持菜单权限API
This commit is contained in:
@@ -16,11 +16,13 @@ import org.nl.common.utils.RsaUtils;
|
||||
import org.nl.common.utils.dto.CurrentUser;
|
||||
import org.nl.config.RsaProperties;
|
||||
import org.nl.config.language.LangProcess;
|
||||
import org.nl.system.service.menu.ISysMenuService;
|
||||
import org.nl.system.service.role.ISysRoleService;
|
||||
import org.nl.system.service.secutiry.dto.AuthUserDto;
|
||||
import org.nl.system.service.user.ISysUserService;
|
||||
import org.nl.system.service.user.dao.SysUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -30,6 +32,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
@@ -44,6 +47,8 @@ public class MobileAuthorizationController {
|
||||
private ISysUserService userService;
|
||||
@Autowired
|
||||
private ISysRoleService roleService;
|
||||
@Autowired
|
||||
private ISysMenuService menuService;
|
||||
|
||||
@PostMapping(value = "/login")
|
||||
@SaIgnore
|
||||
@@ -94,4 +99,10 @@ public class MobileAuthorizationController {
|
||||
|
||||
return ResponseEntity.ok(authInfo);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/authority")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> queryAuthority(@RequestBody Map<String, String> param) {
|
||||
return new ResponseEntity<>(menuService.queryAuthority(param), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,4 +158,10 @@ public interface ISysMenuService extends IService<SysMenu> {
|
||||
*/
|
||||
List<Map> getMenusByRole(String roleId, String systemType, String category);
|
||||
|
||||
/**
|
||||
* 手持菜单权限
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> queryAuthority(Map<String, String> param);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.nl.system.service.menu.dao.mapper;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -80,4 +81,6 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||
* @return /
|
||||
*/
|
||||
String findAllChild(String pid);
|
||||
|
||||
JSONArray queryPdaAuthority(String accountId, String component, String pid);
|
||||
}
|
||||
|
||||
@@ -99,4 +99,42 @@
|
||||
) t3
|
||||
where childId != '0'
|
||||
</select>
|
||||
<select id="queryPdaAuthority" resultType="com.alibaba.fastjson.JSONArray">
|
||||
SELECT
|
||||
max( sys_user.user_id ) AS accountId,
|
||||
max( sys_user.username ) AS username,
|
||||
max( sys_roles_menus.menu_id ) AS menu_id,
|
||||
max( sys_menu.component ) AS component,
|
||||
max( sys_menu.title ) AS title,
|
||||
max( sys_menu.path ) AS path,
|
||||
max( sys_menu.component_name ) AS component_name
|
||||
FROM
|
||||
sys_user sys_user
|
||||
LEFT JOIN sys_users_roles sys_users_roles ON sys_users_roles.user_id = sys_user.user_id
|
||||
LEFT JOIN sys_role sys_role ON sys_role.role_id = sys_users_roles.role_id
|
||||
LEFT JOIN sys_roles_menus sys_roles_menus ON sys_roles_menus.role_id = sys_role.role_id
|
||||
LEFT JOIN sys_menu sys_menu ON sys_menu.menu_id = sys_roles_menus.menu_id
|
||||
WHERE
|
||||
sys_menu.component_name LIKE 'RF%'
|
||||
and sys_menu.is_pc = '0'
|
||||
AND sys_menu.hidden = 0
|
||||
<if test="accountId != null">
|
||||
AND sys_user.user_id = #{accountId}
|
||||
</if>
|
||||
<if test="component != null">
|
||||
AND sys_menu.component = #{component}
|
||||
</if>
|
||||
<if test="pid != null">
|
||||
AND sys_menu.pid = #{pid}
|
||||
</if>
|
||||
GROUP BY
|
||||
sys_menu.menu_id,
|
||||
sys_menu.title,
|
||||
sys_menu.component,
|
||||
sys_menu.path,
|
||||
sys_menu.title,
|
||||
sys_menu.component_name,
|
||||
sys_menu.menu_sort
|
||||
ORDER BY sys_menu.menu_sort
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.nl.system.service.menu.impl;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -464,4 +466,42 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
baseMapper.getMenusByRole(systemType,category);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAuthority(Map<String, String> param) {
|
||||
String accountId = SecurityUtils.getCurrentUserId();
|
||||
JSONObject returnjo = new JSONObject();
|
||||
if (StrUtil.isEmpty(accountId)) {
|
||||
returnjo.put("code", "0");
|
||||
returnjo.put("desc", "用户id不能为空!");
|
||||
returnjo.put("result", new JSONArray());
|
||||
}
|
||||
//查询一级
|
||||
JSONArray pa = baseMapper.queryPdaAuthority(accountId, "0", null);
|
||||
if(ObjectUtil.isEmpty(pa)){
|
||||
throw new BadRequestException("当前用户无菜单权限!");
|
||||
}
|
||||
JSONObject result = new JSONObject();
|
||||
for (int i = 0; i < pa.size(); i++) {
|
||||
JSONObject res = pa.getJSONObject(i);
|
||||
//查询二级
|
||||
JSONArray secondResults = baseMapper.queryPdaAuthority(accountId, "1", res.getString("menu_id"));
|
||||
//查询三级
|
||||
JSONArray roleTree = new JSONArray();
|
||||
for (int j = 0; j < secondResults.size(); j++) {
|
||||
JSONObject row = secondResults.getJSONObject(j);
|
||||
String menu_id = row.getString("menu_id");
|
||||
JSONArray ThirdResults = baseMapper.queryPdaAuthority(accountId, "2", menu_id);
|
||||
row.put("sonTree", ThirdResults);
|
||||
roleTree.add(row);
|
||||
}
|
||||
res.put("sonTree", roleTree);
|
||||
result.put("rf_menu" + ("188".equals(res.getString("menu_id"))?1:0), res);
|
||||
}
|
||||
|
||||
returnjo.put("code", "1");
|
||||
returnjo.put("desc", "查询成功!");
|
||||
returnjo.put("result", result);
|
||||
return returnjo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user