微调
This commit is contained in:
@@ -41,28 +41,28 @@ public class AuthController extends BaseController {
|
||||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
@RequestMapping("/login")
|
||||
public HttpResult<Token> login() {
|
||||
Token token = new Token();
|
||||
token.setAccessToken("bqddxxwqmfncffacvbpkuxvwvqrhln");
|
||||
HttpResult<Token> result = new HttpResult<>();
|
||||
result.setMessage("成功");
|
||||
result.setCode("A0000");
|
||||
result.setData(token);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/logout")
|
||||
public HttpResult<String> logout() {
|
||||
HttpResult<String> result = new HttpResult<>();
|
||||
result.setMessage("成功");
|
||||
result.setCode("A0000");
|
||||
result.setData("退出成功");
|
||||
return result;
|
||||
}
|
||||
// @RequestMapping("/login")
|
||||
// public HttpResult<Token> login() {
|
||||
// Token token = new Token();
|
||||
// token.setAccessToken("bqddxxwqmfncffacvbpkuxvwvqrhln");
|
||||
// HttpResult<Token> result = new HttpResult<>();
|
||||
// result.setMessage("成功");
|
||||
// result.setCode("A0000");
|
||||
// result.setData(token);
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// @RequestMapping("/logout")
|
||||
// public HttpResult<String> logout() {
|
||||
// HttpResult<String> result = new HttpResult<>();
|
||||
// result.setMessage("成功");
|
||||
// result.setCode("A0000");
|
||||
// result.setData("退出成功");
|
||||
// return result;
|
||||
// }
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.AUTHENTICATE)
|
||||
@PostMapping("/login1")
|
||||
@PostMapping("/login")
|
||||
@ApiOperation("登录")
|
||||
public HttpResult<Object> login(@RequestBody SysUserParam.LoginParam param) {
|
||||
String methodDescribe = getMethodDescribe("login");
|
||||
@@ -83,7 +83,7 @@ public class AuthController extends BaseController {
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_SERIOUS, operateType = OperateType.LOGOUT)
|
||||
@ApiOperation("注销登录")
|
||||
@PostMapping("/logout1")
|
||||
@PostMapping("/logout")
|
||||
public HttpResult<Object> logout(HttpServletRequest request) {
|
||||
String methodDescribe = getMethodDescribe("logout");
|
||||
LogUtil.njcnDebug(log, "{},注销登录", methodDescribe);
|
||||
|
||||
@@ -38,12 +38,6 @@ public interface UserValidMessage {
|
||||
|
||||
String SORT_NOT_NULL = "排序不能为空,请检查sort参数";
|
||||
|
||||
String PATH_NOT_BLANK = "路径不能为空,请检查path参数";
|
||||
|
||||
String COMPONENT_NOT_BLANK = "组件地址不能为空,请检查component参数";
|
||||
|
||||
String PATH_FORMAT_ERROR = "路径格式错误,请检查path参数";
|
||||
|
||||
String TYPE_NOT_BLANK = "类型不能为空,请检查type参数";
|
||||
|
||||
String PARAM_FORMAT_ERROR = "参数值非法";
|
||||
|
||||
@@ -17,7 +17,10 @@ public enum UserResponseEnum {
|
||||
EXISTS_CHILDREN_NOT_UPDATE("A010008", "该菜单下存在子节点,无法将菜单修改为按钮"),
|
||||
EXISTS_CHILDREN_NOT_DELETE("A010007", "该节点下存在子节点,无法删除"),
|
||||
SUPER_ADMINSTRATOR_ROLE_CANNOT_UPDATE("A010009", "禁止修改超级管理员角色"),
|
||||
SUPER_ADMINSTRATOR_ROLE_CANNOT_DELETE("A010009", "禁止删除超级管理员角色"),;
|
||||
SUPER_ADMINSTRATOR_ROLE_CANNOT_DELETE("A010009", "禁止删除超级管理员角色"),
|
||||
SUPER_ADMIN_CANNOT_DELETE("A010010", "禁止删除超级管理员用户"),
|
||||
COMPONENT_NOT_BLANK("A010011", "组件地址不能为空"),
|
||||
FUNCTION_PATH_FORMAT_ERROR("A010012", "路由地址格式错误");
|
||||
|
||||
private String code;
|
||||
private String message;
|
||||
|
||||
@@ -12,7 +12,6 @@ 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;
|
||||
@@ -28,6 +27,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
@@ -149,15 +149,15 @@ public class SysFunctionController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/getButton")
|
||||
@ApiOperation("获取按钮")
|
||||
public HttpResult<ButtonVO> getButton(HttpServletRequest request) {
|
||||
public HttpResult<Map<String, List<String>>> 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);
|
||||
// }
|
||||
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");
|
||||
Map<String, List<String>> map = sysFunctionService.getButtonByUserId(userId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, map, methodDescribe);
|
||||
}
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
|
||||
@@ -18,5 +18,12 @@ public interface SysFunctionMapper extends MPJBaseMapper<SysFunction> {
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<MenuVO> getMenuByUserId(String userId);
|
||||
|
||||
/*
|
||||
* 根据用户id获取按钮列表
|
||||
* @param userId 用户id
|
||||
* @return 按钮列表
|
||||
*/
|
||||
List<SysFunction> getButtonByUserId(String userId);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,19 +4,28 @@
|
||||
|
||||
|
||||
<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
|
||||
SELECT distinct 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)
|
||||
AND a.type in (0)
|
||||
</select>
|
||||
|
||||
<select id="getButtonByUserId" resultType="com.njcn.gather.user.user.pojo.po.SysFunction">
|
||||
select distinct a.*
|
||||
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 (1)
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Null;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
@@ -32,12 +33,12 @@ public class SysFunctionParam {
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty("路径")
|
||||
@NotBlank(message = UserValidMessage.PATH_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.FUNCTION_URL, message = UserValidMessage.PATH_FORMAT_ERROR)
|
||||
// @NotBlank(message = UserValidMessage.PATH_NOT_BLANK)
|
||||
// @Pattern(regexp = PatternRegex.FUNCTION_URL, message = UserValidMessage.PATH_FORMAT_ERROR)
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty("组件地址")
|
||||
@NotBlank(message = UserValidMessage.COMPONENT_NOT_BLANK)
|
||||
// @NotBlank(message = UserValidMessage.COMPONENT_NOT_BLANK)
|
||||
private String component;
|
||||
|
||||
@ApiModelProperty("图标")
|
||||
|
||||
@@ -3,9 +3,9 @@ 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;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
@@ -75,6 +75,11 @@ public interface ISysFunctionService extends IService<SysFunction> {
|
||||
*/
|
||||
List<SysFunction> getMenuByUserId(String userId);
|
||||
|
||||
//ButtonVO getButtonByUserId(String userId);
|
||||
/**
|
||||
* 根据用户id获取按钮
|
||||
* @param userId 用户id
|
||||
* @return 按钮
|
||||
*/
|
||||
Map<String, List<String>> getButtonByUserId(String userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -50,11 +50,4 @@ public interface ISysRoleService extends IService<SysRole> {
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> simpleList();
|
||||
|
||||
/**
|
||||
* 判断角色id是否有相关联的资源和组件
|
||||
*
|
||||
* @param ids 角色id
|
||||
*/
|
||||
// boolean selectRelevance(List<String> ids);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.njcn.gather.user.user.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.gather.user.pojo.constant.FunctionConst;
|
||||
@@ -15,15 +17,14 @@ 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 com.njcn.gather.user.user.service.ISysUserRoleService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -36,6 +37,7 @@ import java.util.stream.Collectors;
|
||||
public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFunction> implements ISysFunctionService {
|
||||
|
||||
private final ISysRoleFunctionService sysRoleFunctionService;
|
||||
private final ISysUserRoleService sysUserRoleService;
|
||||
|
||||
@Override
|
||||
public List<SysFunction> getFunctionTreeByKeyword(String keyword) {
|
||||
@@ -116,21 +118,6 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
|
||||
return allFunctions.stream().filter(fun -> Objects.equals(FunctionConst.FATHER_PID, fun.getPid())).peek(funS -> funS.setChildren(getChildrenList(funS, allFunctions))).sorted(Comparator.comparingInt(SysFunction::getSort)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public SysFunction getFunctionById(String id) {
|
||||
// return this.lambdaQuery().eq(SysFunction::getId, id).one();
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public List<SysFunction> getButtonsById(String id) {
|
||||
// List<Integer> typeList = Arrays.asList(FunctionConst.TYPE_MENU, FunctionConst.TYPE_BUTTON);
|
||||
// return this.lambdaQuery()
|
||||
// .eq(SysFunction::getPid, id)
|
||||
// .in(SysFunction::getType, typeList)
|
||||
// .eq(SysFunction::getState, DataStateEnum.ENABLE.getCode())
|
||||
// .orderByAsc(SysFunction::getSort).list();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<SysFunction> getMenuByUserId(String userId) {
|
||||
List<MenuVO> menu = this.baseMapper.getMenuByUserId(userId);
|
||||
@@ -148,6 +135,20 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
|
||||
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 Map<String, List<String>> getButtonByUserId(String userId) {
|
||||
List<SysFunction> sysFunctions = this.baseMapper.getButtonByUserId(userId);
|
||||
|
||||
Map<String, List<String>> buttonMap = new HashMap<>();
|
||||
sysFunctions.stream().collect(Collectors.groupingBy(SysFunction::getPid)).forEach((k, v) -> {
|
||||
SysFunction fatherFunction = this.getById(k);
|
||||
if (ObjectUtil.isNotNull(fatherFunction)) {
|
||||
buttonMap.put(fatherFunction.getCode(), v.stream().map(SysFunction::getCode).collect(Collectors.toList()));
|
||||
}
|
||||
});
|
||||
return buttonMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据当前分类找出子类,递归找出子类的子类
|
||||
@@ -162,6 +163,14 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
|
||||
* 名称 && 路径做唯一判断
|
||||
*/
|
||||
private void checkFunctionParam(SysFunctionParam functionParam, boolean isExcludeSelf) {
|
||||
if (functionParam.getType().equals(FunctionConst.TYPE_MENU)) {
|
||||
if (StrUtil.isBlank(functionParam.getComponent())) {
|
||||
throw new BusinessException(UserResponseEnum.COMPONENT_NOT_BLANK);
|
||||
}
|
||||
if (StrUtil.isBlank(functionParam.getPath()) || !Pattern.matches(PatternRegex.FUNCTION_URL, functionParam.getPath())) {
|
||||
throw new BusinessException(UserResponseEnum.FUNCTION_PATH_FORMAT_ERROR);
|
||||
}
|
||||
}
|
||||
LambdaQueryWrapper<SysFunction> functionLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// 同一个pid下,名称、编码、路径、组件地址不能重复
|
||||
functionLambdaQueryWrapper.eq(SysFunction::getName, functionParam.getName()).eq(SysFunction::getCode, functionParam.getCode()).eq(SysFunction::getPath, functionParam.getPath()).eq(SysFunction::getComponent, functionParam.getComponent()).eq(SysFunction::getPid, functionParam.getPid()).eq(SysFunction::getState, DataStateEnum.ENABLE.getCode());
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.njcn.gather.user.user.mapper.SysUserMapper;
|
||||
import com.njcn.gather.user.user.pojo.param.SysUserParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysRole;
|
||||
import com.njcn.gather.user.user.pojo.po.SysUser;
|
||||
import com.njcn.gather.user.user.service.ISysRoleService;
|
||||
import com.njcn.gather.user.user.service.ISysUserRoleService;
|
||||
import com.njcn.gather.user.user.service.ISysUserService;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
@@ -41,6 +42,7 @@ import java.util.stream.Collectors;
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
|
||||
|
||||
private final ISysUserRoleService sysUserRoleService;
|
||||
private final ISysRoleService sysRoleService;
|
||||
|
||||
@Override
|
||||
public Page<SysUser> listUser(SysUserParam.SysUserQueryParam queryParam) {
|
||||
@@ -166,6 +168,14 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
|
||||
@Override
|
||||
public boolean deleteUser(List<String> ids) {
|
||||
for (String id : ids) {
|
||||
List<SysRole> sysRoles = sysUserRoleService.listRoleByUserId(id);
|
||||
for (SysRole sysRole : sysRoles) {
|
||||
if (sysRole.getType().equals(RoleConst.TYPE_SUPER_ADMINISTRATOR)) {
|
||||
throw new BusinessException(UserResponseEnum.SUPER_ADMIN_CANNOT_DELETE); // 超级管理员角色不能删除
|
||||
}
|
||||
}
|
||||
}
|
||||
// 删除用户角色关联数据
|
||||
sysUserRoleService.deleteUserRoleByUserIds(ids);
|
||||
return this.lambdaUpdate()
|
||||
|
||||
Reference in New Issue
Block a user