按钮权限优化
This commit is contained in:
parent
7dfc8a9e16
commit
adca2c007d
@ -53,14 +53,24 @@ public class BaseActionController {
|
||||
|
||||
@OperLog(operModul = "功能按钮管理", operType = "查询", operDesc = "查询菜单下的按钮权限CODE")
|
||||
@ApiOperation(value = "查询菜单下的按钮权限CODE", notes = "查询菜单下的按钮权限CODE", httpMethod="POST")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "menuId", value = "menuId", paramType = "form"),
|
||||
})
|
||||
@ApiImplicitParam(name = "menuId", value = "menuId", paramType = "body")
|
||||
@PostMapping("/codeList")
|
||||
public Result<Set<String>> getMenuCode(@ApiIgnore @RequestBody Map<String,Object> map) {
|
||||
return Result.success(baseActionService.getMenuCode(MapUtils.getString(map,"menuId")));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户查询自身菜单按钮权限列表
|
||||
* @return
|
||||
*/
|
||||
@OperLog(operModul = "功能按钮管理", operType = "查询", operDesc = "用户查询自身菜单按钮权限列表")
|
||||
@ApiOperation(value = "用户查询自身菜单按钮权限列表", notes = "用户查询自身菜单按钮权限列表" , httpMethod="POST")
|
||||
@ApiImplicitParam(name = "menuId", value = "菜单ID", paramType = "body", required = true, dataType = "Long")
|
||||
@PostMapping(value = "/queryBySelf")
|
||||
public Result<Set<String>> queryBySelf(@ApiIgnore @RequestBody Map<String,Object> map) {
|
||||
return Result.success(baseActionService.queryBySelf(MapUtils.getLong(map,"menuId")));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param baseAction
|
||||
|
||||
@ -27,9 +27,9 @@ public interface BaseActionMapper extends BaseMapper<BaseAction> {
|
||||
|
||||
List<EntityMap> getComapnyUserActionList(Map<String, Object> param);
|
||||
|
||||
Set<String> getActionCodes(@Param("accountType") Integer accountType);
|
||||
List<BaseAction> getActionCodes(@Param("accountType") Integer accountType);
|
||||
|
||||
Set<String> getActionCodeByRole(@Param("roleId") Long roleId);
|
||||
List<BaseAction> getActionCodeByRole(@Param("roleId") Long roleId);
|
||||
|
||||
Set<String> getMenuCode(@Param("menuId") String menuId);
|
||||
|
||||
|
||||
@ -39,14 +39,14 @@
|
||||
|
||||
</select>
|
||||
|
||||
<select id="getActionCodes" resultType="java.lang.String">
|
||||
SELECT action_code FROM base_action WHERE EXISTS(
|
||||
<select id="getActionCodes" resultType="com.zhgd.xmgl.modules.basicdata.entity.BaseAction">
|
||||
SELECT * FROM base_action WHERE status = 1 AND EXISTS(
|
||||
SELECT * FROM base_menu WHERE EXISTS(
|
||||
SELECT module_id FROM base_module WHERE module_type = #{accountType}))
|
||||
</select>
|
||||
|
||||
<select id="getActionCodeByRole" resultType="java.lang.String">
|
||||
SELECT * FROM base_action WHERE EXISTS(
|
||||
<select id="getActionCodeByRole" resultType="com.zhgd.xmgl.modules.basicdata.entity.BaseAction">
|
||||
SELECT * FROM base_action WHERE status = 1 AND EXISTS(
|
||||
SELECT * FROM base_menu WHERE EXISTS(
|
||||
SELECT menu_id FROM system_role_menu WHERE role_id = #{roleId}))
|
||||
</select>
|
||||
|
||||
@ -24,6 +24,8 @@ public interface IBaseActionService extends IService<BaseAction> {
|
||||
|
||||
Set<String> getMenuCode(String menuId);
|
||||
|
||||
Set<String> queryBySelf(Long menuId);
|
||||
|
||||
void addBaseAction(BaseAction baseAction);
|
||||
|
||||
void editBaseAction(BaseAction baseAction);
|
||||
|
||||
@ -1,19 +1,26 @@
|
||||
package com.zhgd.xmgl.modules.basicdata.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zhgd.jeecg.common.execption.OpenAlertException;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.BaseAction;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.SystemUserRole;
|
||||
import com.zhgd.xmgl.modules.basicdata.mapper.BaseActionMapper;
|
||||
import com.zhgd.xmgl.modules.basicdata.mapper.SystemUserRoleMapper;
|
||||
import com.zhgd.xmgl.modules.basicdata.service.IBaseActionService;
|
||||
import com.zhgd.xmgl.security.SecurityUser;
|
||||
import com.zhgd.xmgl.security.SecurityUtil;
|
||||
import com.zhgd.xmgl.util.MessageUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description: 系统资源-功能操作
|
||||
@ -26,6 +33,9 @@ import java.util.Set;
|
||||
public class BaseActionServiceImpl extends ServiceImpl<BaseActionMapper, BaseAction> implements IBaseActionService {
|
||||
@Autowired
|
||||
private BaseActionMapper baseActionMapper;
|
||||
|
||||
@Autowired
|
||||
private SystemUserRoleMapper systemUserRoleMapper;
|
||||
// @Autowired
|
||||
// private IBaseAuthorityService baseAuthorityService;
|
||||
|
||||
@ -43,6 +53,24 @@ public class BaseActionServiceImpl extends ServiceImpl<BaseActionMapper, BaseAct
|
||||
return baseActionMapper.getMenuCode(menuId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> queryBySelf(Long menuId) {
|
||||
SecurityUser user = SecurityUtil.getUser();
|
||||
Set<String> actionCodes = new HashSet<>();
|
||||
if (user.isManager()) {
|
||||
actionCodes = baseActionMapper.getActionCodes(user.getAccountType()).stream().filter(a -> a.getMenuId().equals(menuId))
|
||||
.map(a -> a.getActionCode()).collect(Collectors.toSet());
|
||||
} else {
|
||||
SystemUserRole systemUserRole = systemUserRoleMapper.selectOne(Wrappers.<SystemUserRole>lambdaQuery().eq(SystemUserRole::getUserId, user.getUserId()));
|
||||
if (systemUserRole != null) {
|
||||
Long roleId = systemUserRole.getRoleId();
|
||||
actionCodes = baseActionMapper.getActionCodeByRole(roleId).stream().filter(a -> a.getMenuId().equals(menuId))
|
||||
.map(a -> a.getActionCode()).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
return actionCodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBaseAction(BaseAction aciton) {
|
||||
if (aciton.getPriority() == null) {
|
||||
|
||||
@ -17,6 +17,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @program: devManage
|
||||
@ -48,12 +49,12 @@ public class MyUserDetailsImpl implements UserDetailsService {
|
||||
}
|
||||
Set<String> actionCodes = new HashSet<>();
|
||||
if (user.getIsManager()) {
|
||||
actionCodes = baseActionMapper.getActionCodes(user.getAccountType());
|
||||
actionCodes = baseActionMapper.getActionCodes(user.getAccountType()).stream().map(a -> a.getActionCode()).collect(Collectors.toSet());
|
||||
} else {
|
||||
SystemUserRole systemUserRole = systemUserRoleMapper.selectOne(Wrappers.<SystemUserRole>lambdaQuery().eq(SystemUserRole::getUserId, user.getUserId()));
|
||||
if (systemUserRole != null) {
|
||||
Long roleId = systemUserRole.getRoleId();
|
||||
actionCodes = baseActionMapper.getActionCodeByRole(roleId);
|
||||
actionCodes = baseActionMapper.getActionCodeByRole(roleId).stream().map(a -> a.getActionCode()).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
Collection<? extends GrantedAuthority> grantedAuthorityList = AuthorityUtils
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user