登录权限菜单处理

master
chen 2 years ago
parent e6fc950c7b
commit 8693389614
  1. 8
      src/main/java/com/huoran/iasf/common/aop/annotation/LogAnnotation.java
  2. 6
      src/main/java/com/huoran/iasf/common/aop/aspect/SysLogAspect.java
  3. 4
      src/main/java/com/huoran/iasf/mapper/SysPermissionMapper.java
  4. 14
      src/main/java/com/huoran/iasf/mapper/xml/SysPermissionMapper.xml
  5. 2
      src/main/java/com/huoran/iasf/service/PermissionService.java
  6. 20
      src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java
  7. 10
      src/main/java/com/huoran/iasf/service/impl/UserServiceImpl.java
  8. 5
      src/main/java/com/huoran/iasf/vo/resp/LoginRespVO.java
  9. 9
      src/main/resources/application-dev.yml

@ -1,7 +1,5 @@
package com.huoran.iasf.common.aop.annotation; package com.huoran.iasf.common.aop.annotation;
import java.lang.annotation.*;
/** /**
* LogAnnotation * LogAnnotation
* *
@ -9,9 +7,9 @@ import java.lang.annotation.*;
* @version V1.0 * @version V1.0
* @date 2022年7月28日 * @date 2022年7月28日
*/ */
@Target(ElementType.METHOD) // @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) // @Retention(RetentionPolicy.RUNTIME)
@Documented // @Documented
public @interface LogAnnotation { public @interface LogAnnotation {
/** /**
* 模块 * 模块

@ -10,11 +10,9 @@ import com.huoran.iasf.service.HttpSessionService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature; import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -27,8 +25,8 @@ import java.lang.reflect.Method;
* @version V1.0 * @version V1.0
* @date 2022年7月28日 * @date 2022年7月28日
*/ */
@Aspect // @Aspect
@Component // @Component
@Slf4j @Slf4j
public class SysLogAspect { public class SysLogAspect {
@Lazy @Lazy

@ -2,6 +2,9 @@ package com.huoran.iasf.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huoran.iasf.entity.SysPermission; import com.huoran.iasf.entity.SysPermission;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* 菜单权限 Mapper * 菜单权限 Mapper
@ -12,4 +15,5 @@ import com.huoran.iasf.entity.SysPermission;
*/ */
public interface SysPermissionMapper extends BaseMapper<SysPermission> { public interface SysPermissionMapper extends BaseMapper<SysPermission> {
List<SysPermission> selectRoleMenu(@Param("roleIds") String roleIds);
} }

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.huoran.iasf.mapper.SysPermissionMapper">
<select id="selectRoleMenu" resultType="com.huoran.iasf.entity.SysPermission">
SELECT
ap.*
FROM
sys_role_permission ar
left join sys_permission ap on ar.permission_id = ap.id
where find_in_set(ar.role_id,#{roleIds})
GROUP BY ap.id
</select>
</mapper>

@ -84,4 +84,6 @@ public interface PermissionService extends IService<SysPermission> {
* @param vo vo * @param vo vo
*/ */
void updatePermission(SysPermission vo); void updatePermission(SysPermission vo);
List<SysPermission> permissionList(String id);
} }

@ -1,6 +1,8 @@
package com.huoran.iasf.service.impl; package com.huoran.iasf.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.BusinessException;
@ -98,6 +100,24 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
} }
@Override
public List<SysPermission> permissionList(String userId) {
QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id",userId);
List<SysUserRole> userRoles = userRoleService.list(queryWrapper);
String roleIds = "";
if (ObjectUtil.isNotNull(userRoles)){
for (SysUserRole userRole: userRoles) {
roleIds += userRole.getRoleId() +",";
}
roleIds = roleIds.substring(0,roleIds.length()-1);
}else {
throw new BusinessException(BaseResponseCode.UNAUTHORIZED_ERROR);
}
List<SysPermission> list = sysPermissionMapper.selectRoleMenu(roleIds);
return build(list);
}
@Override @Override
public void updatePermission(SysPermission vo) { public void updatePermission(SysPermission vo) {
sysPermissionMapper.updateById(vo); sysPermissionMapper.updateById(vo);

@ -31,7 +31,6 @@ import com.huoran.iasf.vo.req.ExcelImpUserReq;
import com.huoran.iasf.vo.req.UserListReq; import com.huoran.iasf.vo.req.UserListReq;
import com.huoran.iasf.vo.req.UserRoleOperationReqVO; import com.huoran.iasf.vo.req.UserRoleOperationReqVO;
import com.huoran.iasf.vo.resp.LoginRespVO; import com.huoran.iasf.vo.resp.LoginRespVO;
import com.huoran.iasf.vo.resp.PermissionRespNode;
import com.huoran.iasf.vo.resp.UserListResp; import com.huoran.iasf.vo.resp.UserListResp;
import com.huoran.iasf.vo.resp.UserOwnRoleRespVO; import com.huoran.iasf.vo.resp.UserOwnRoleRespVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -132,11 +131,11 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
if (!allowMultipleLogin) { if (!allowMultipleLogin) {
httpSessionService.abortUserById(sysUser.getId()); httpSessionService.abortUserById(sysUser.getId());
} }
List<PermissionRespNode> menus = permissionService.permissionTreeList(sysUser.getId()); List<SysPermission> menus = permissionService.permissionList(sysUser.getId());
String token = httpSessionService.createTokenAndUser(sysUser, roleService.getRoleNames(sysUser.getId()), permissionService.getPermissionsByUserId(sysUser.getId())); String token = httpSessionService.createTokenAndUser(sysUser, roleService.getRoleNames(sysUser.getId()), permissionService.getPermissionsByUserId(sysUser.getId()));
respVO.setAccessToken(token); respVO.setAccessToken(token);
respVO.setList(menus); respVO.setPermissionList(menus);
return respVO; return respVO;
} }
@ -655,6 +654,11 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
SysUser vo = new SysUser(); SysUser vo = new SysUser();
vo.setSalt(PasswordUtils.getSalt()); vo.setSalt(PasswordUtils.getSalt());
String encode = PasswordUtils.encode("111aaa", vo.getSalt()); String encode = PasswordUtils.encode("111aaa", vo.getSalt());
vo.setRealName(realName);
vo.setPhone(getPhone);
vo.setJobNumber(jobNumber);
vo.setEmail(getEmail);
vo.setUsername(username);
vo.setPassword(encode); vo.setPassword(encode);
vo.setStatus(1); vo.setStatus(1);
vo.setCreateWhere(1); vo.setCreateWhere(1);

@ -1,5 +1,6 @@
package com.huoran.iasf.vo.resp; package com.huoran.iasf.vo.resp;
import com.huoran.iasf.entity.SysPermission;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -22,6 +23,6 @@ public class LoginRespVO {
private String id; private String id;
@ApiModelProperty(value = "电话") @ApiModelProperty(value = "电话")
private String phone; private String phone;
@ApiModelProperty(value = "用户所拥有的菜单权限(前后端分离返回给前端控制菜单和按钮的显示和隐藏)") @ApiModelProperty(value = "用户所拥有的菜单权限")
private List<PermissionRespNode> list; private List<SysPermission> permissionList;
} }

@ -9,6 +9,15 @@ spring:
password: HuoRan@2021 password: HuoRan@2021
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://139.9.47.170:3306/iasf?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2b8 url: jdbc:mysql://139.9.47.170:3306/iasf?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2b8
# hikari:
# connection-timeout: 60000
# validation-timeout: 3000
# idle-timeout: 60000
# login-timeout: 5
# max-lifetime: 60000
# maximum-pool-size: 10
# minimum-idle: 10
# read-only: false
redis: redis:
host: localhost # Redis服务器地址 host: localhost # Redis服务器地址
database: 0 # Redis数据库索引(默认为0) database: 0 # Redis数据库索引(默认为0)

Loading…
Cancel
Save