微调
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
package com.njcn.gather.user.user.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.constant.SecurityConstants;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.JwtUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.user.user.pojo.param.SysFunctionParam;
|
||||
import com.njcn.gather.user.user.pojo.param.SysRoleParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
import com.njcn.gather.user.user.pojo.vo.ButtonVO;
|
||||
import com.njcn.gather.user.user.service.ISysFunctionService;
|
||||
import com.njcn.gather.user.user.service.ISysRoleFunctionService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
@@ -18,9 +22,11 @@ import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -125,14 +131,35 @@ public class SysFunctionController extends BaseController {
|
||||
// }
|
||||
|
||||
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
// @GetMapping("/getRouteMenu")
|
||||
// @ApiOperation("路由菜单")
|
||||
// public HttpResult<List<SysFunction>> getRouteMenu() {
|
||||
// String methodDescribe = getMethodDescribe("getRouteMenu");
|
||||
// List<SysFunction> list = sysFunctionService.getRouteMenu();
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
// }
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/getMenu")
|
||||
@ApiOperation("获取菜单")
|
||||
public HttpResult<List<SysFunction>> getMenu(HttpServletRequest request) {
|
||||
String methodDescribe = getMethodDescribe("getMenu");
|
||||
String tokenStr = request.getHeader(SecurityConstants.AUTHORIZATION_KEY);
|
||||
if (StrUtil.isNotBlank(tokenStr)) {
|
||||
tokenStr.replace(SecurityConstants.AUTHORIZATION_PREFIX, Strings.EMPTY);
|
||||
String userId = (String) JwtUtil.parseToken(tokenStr).get("userId");
|
||||
List<SysFunction> list = sysFunctionService.getMenuByUserId(userId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/getButton")
|
||||
@ApiOperation("获取按钮")
|
||||
public HttpResult<ButtonVO> getButton(HttpServletRequest request) {
|
||||
String methodDescribe = getMethodDescribe("getButton");
|
||||
// String tokenStr = request.getHeader(SecurityConstants.AUTHORIZATION_KEY);
|
||||
// if (StrUtil.isNotBlank(tokenStr)) {
|
||||
// tokenStr.replace(SecurityConstants.AUTHORIZATION_PREFIX, Strings.EMPTY);
|
||||
// String userId = (String) JwtUtil.parseToken(tokenStr).get("userId");
|
||||
// ButtonVO buttonVO = sysFunctionService.getButtonByUserId(userId);
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, buttonVO, methodDescribe);
|
||||
// }
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/getFunctionsByRoleId")
|
||||
@ApiOperation("获取角色id绑定的菜单(资源)")
|
||||
@@ -154,14 +181,5 @@ public class SysFunctionController extends BaseController {
|
||||
boolean result = sysRoleFunctionService.updateRoleFunction(param.getRoleId(), param.getFunctionIds());
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
// @GetMapping("/userFunctionTree")
|
||||
// @ApiOperation("用户菜单树")
|
||||
// public HttpResult<List<SysFunction>> getUserFunctionTree() {
|
||||
// String methodDescribe = getMethodDescribe("getUserFunctionTree");
|
||||
// List<SysFunction> list = sysFunctionService.getUserFunctionTree();
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.njcn.gather.user.user.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
import com.njcn.gather.user.user.pojo.vo.MenuVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
@@ -9,5 +12,11 @@ import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
*/
|
||||
public interface SysFunctionMapper extends MPJBaseMapper<SysFunction> {
|
||||
|
||||
/**
|
||||
* 根据用户id获取菜单列表
|
||||
* @param userId 用户id
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<MenuVO> getMenuByUserId(String userId);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,5 +3,20 @@
|
||||
<mapper namespace="com.njcn.gather.user.user.mapper.SysFunctionMapper">
|
||||
|
||||
|
||||
<select id="getMenuByUserId" resultType="com.njcn.gather.user.user.pojo.vo.MenuVO">
|
||||
SELECT a.id as id,
|
||||
a.path as path,
|
||||
a.name as name,
|
||||
if(a.pId!= '0', a.component, '') as component,
|
||||
if(a.pId = '0', a.component, '') as redirect,
|
||||
a.icon as icon,
|
||||
a.pId as pId,
|
||||
a.sort as sort
|
||||
FROM sys_function a
|
||||
inner join sys_role_function b on a.id = b.Function_Id
|
||||
inner join sys_user_role c on b.Role_Id = c.Role_Id
|
||||
WHERE c.User_Id = #{userId}
|
||||
AND a.type in (0, 1)
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.njcn.gather.user.user.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.user.user.pojo.param.SysFunctionParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
import com.njcn.gather.user.user.pojo.vo.ButtonVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -68,16 +69,12 @@ public interface ISysFunctionService extends IService<SysFunction> {
|
||||
//List<SysFunction> getButtonsById(String id);
|
||||
|
||||
/**
|
||||
* 获取路由菜单
|
||||
* 根据用户id获取菜单
|
||||
*
|
||||
* @return 路由菜单
|
||||
*/
|
||||
List<SysFunction> getRouteMenu();
|
||||
List<SysFunction> getMenuByUserId(String userId);
|
||||
|
||||
//ButtonVO getButtonByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 获取用户拥有的资源树
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
//List<SysFunction> getUserFunctionTree();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import com.njcn.gather.user.pojo.enums.UserResponseEnum;
|
||||
import com.njcn.gather.user.user.mapper.SysFunctionMapper;
|
||||
import com.njcn.gather.user.user.pojo.param.SysFunctionParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysFunction;
|
||||
import com.njcn.gather.user.user.pojo.vo.MenuVO;
|
||||
import com.njcn.gather.user.user.pojo.vo.MetaVO;
|
||||
import com.njcn.gather.user.user.service.ISysFunctionService;
|
||||
import com.njcn.gather.user.user.service.ISysRoleFunctionService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -130,44 +132,27 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<SysFunction> getRouteMenu() {
|
||||
// List<SysFunction> result = new ArrayList<>();
|
||||
// List<String> functionIds;
|
||||
// if (Objects.equals(RequestUtil.getUsername(), UserType.SUPER_ADMIN)) {
|
||||
// //查询所有菜单
|
||||
// functionIds = this.lambdaQuery().eq(SysFunction::getState, DataStateEnum.ENABLE.getCode()).list().stream().map(SysFunction::getId).distinct().collect(Collectors.toList());
|
||||
// } else {
|
||||
// List<String> roleIdList = sysUserRoleService.listRoleByUserId(RequestUtil.getUserIndex()).stream().map(SysUserRole::getRoleId).distinct().collect(Collectors.toList());
|
||||
// functionIds = sysRoleFunctionService.listRoleFunctionByRoleIds(roleIdList).stream().map(SysRoleFunction::getFunctionId).distinct().collect(Collectors.toList());
|
||||
// }
|
||||
// if (CollectionUtils.isEmpty(functionIds)) {
|
||||
// return result;
|
||||
// }
|
||||
// List<SysFunction> functionList = this.lambdaQuery().eq(SysFunction::getState, DataStateEnum.ENABLE.getCode())
|
||||
// .in(SysFunction::getId, functionIds)
|
||||
// .in(SysFunction::getType, FunctionConst.TYPE_MENU, FunctionConst.TYPE_BUTTON).list();
|
||||
// result = functionList.stream()
|
||||
// .filter(fun -> Objects.equals(FunctionConst.FATHER_PID, fun.getPid().trim()))
|
||||
// .peek(funS -> funS.setChildren(getChildrenList(funS, functionList)))
|
||||
// .sorted(Comparator.comparingInt(SysFunction::getSort))
|
||||
// .collect(Collectors.toList());
|
||||
// //组装驾驶舱
|
||||
// setDriverChildren(result);
|
||||
// 处理tab页
|
||||
// setTab(result);
|
||||
// return result;
|
||||
return Collections.emptyList();
|
||||
public List<SysFunction> getMenuByUserId(String userId) {
|
||||
List<MenuVO> menu = this.baseMapper.getMenuByUserId(userId);
|
||||
menu.stream().forEach(m -> {
|
||||
MetaVO meta = new MetaVO();
|
||||
meta.setIcon(m.getIcon());
|
||||
meta.setTitle(m.getName());
|
||||
meta.setIsLink("");
|
||||
meta.setHide(false);
|
||||
meta.setFull(false);
|
||||
meta.setAffix(false);
|
||||
meta.setKeepAlive(true);
|
||||
m.setMeta(meta);
|
||||
});
|
||||
return menu.stream().filter(fun -> Objects.equals(FunctionConst.FATHER_PID, fun.getPid())).peek(funS -> funS.setChildren(getChildrenList(funS, menu))).sorted(Comparator.comparingInt(SysFunction::getSort)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public List<SysFunction> getUserFunctionTree() {
|
||||
// return Collections.emptyList();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 根据当前分类找出子类,递归找出子类的子类
|
||||
*/
|
||||
private List<SysFunction> getChildrenList(SysFunction currMenu, List<SysFunction> categories) {
|
||||
private <T extends SysFunction> List<SysFunction> getChildrenList(T currMenu, List<? extends SysFunction> categories) {
|
||||
return categories.stream().filter(o -> Objects.equals(o.getPid(), currMenu.getId())).peek(o -> o.setChildren(getChildrenList(o, categories))).sorted(Comparator.comparingInt(SysFunction::getSort)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -219,4 +204,5 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user