From 8693389614f1c4e69343eadfb660a02b67de426f Mon Sep 17 00:00:00 2001 From: chen <1251790704@qq.com> Date: Fri, 19 Aug 2022 18:17:42 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=9D=83=E9=99=90=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/aop/annotation/LogAnnotation.java | 8 +++----- .../iasf/common/aop/aspect/SysLogAspect.java | 6 ++---- .../iasf/mapper/SysPermissionMapper.java | 4 ++++ .../iasf/mapper/xml/SysPermissionMapper.xml | 14 +++++++++++++ .../iasf/service/PermissionService.java | 2 ++ .../service/impl/PermissionServiceImpl.java | 20 +++++++++++++++++++ .../iasf/service/impl/UserServiceImpl.java | 10 +++++++--- .../com/huoran/iasf/vo/resp/LoginRespVO.java | 5 +++-- src/main/resources/application-dev.yml | 9 +++++++++ 9 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/huoran/iasf/mapper/xml/SysPermissionMapper.xml diff --git a/src/main/java/com/huoran/iasf/common/aop/annotation/LogAnnotation.java b/src/main/java/com/huoran/iasf/common/aop/annotation/LogAnnotation.java index bd48f94..14eb5c0 100644 --- a/src/main/java/com/huoran/iasf/common/aop/annotation/LogAnnotation.java +++ b/src/main/java/com/huoran/iasf/common/aop/annotation/LogAnnotation.java @@ -1,7 +1,5 @@ package com.huoran.iasf.common.aop.annotation; -import java.lang.annotation.*; - /** * LogAnnotation * @@ -9,9 +7,9 @@ import java.lang.annotation.*; * @version V1.0 * @date 2022年7月28日 */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@Documented +// @Target(ElementType.METHOD) +// @Retention(RetentionPolicy.RUNTIME) +// @Documented public @interface LogAnnotation { /** * 模块 diff --git a/src/main/java/com/huoran/iasf/common/aop/aspect/SysLogAspect.java b/src/main/java/com/huoran/iasf/common/aop/aspect/SysLogAspect.java index f296d55..c0f8d5c 100644 --- a/src/main/java/com/huoran/iasf/common/aop/aspect/SysLogAspect.java +++ b/src/main/java/com/huoran/iasf/common/aop/aspect/SysLogAspect.java @@ -10,11 +10,9 @@ import com.huoran.iasf.service.HttpSessionService; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Component; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -27,8 +25,8 @@ import java.lang.reflect.Method; * @version V1.0 * @date 2022年7月28日 */ -@Aspect -@Component +// @Aspect +// @Component @Slf4j public class SysLogAspect { @Lazy diff --git a/src/main/java/com/huoran/iasf/mapper/SysPermissionMapper.java b/src/main/java/com/huoran/iasf/mapper/SysPermissionMapper.java index b2f7701..0e99662 100644 --- a/src/main/java/com/huoran/iasf/mapper/SysPermissionMapper.java +++ b/src/main/java/com/huoran/iasf/mapper/SysPermissionMapper.java @@ -2,6 +2,9 @@ package com.huoran.iasf.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.huoran.iasf.entity.SysPermission; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * 菜单权限 Mapper @@ -12,4 +15,5 @@ import com.huoran.iasf.entity.SysPermission; */ public interface SysPermissionMapper extends BaseMapper { + List selectRoleMenu(@Param("roleIds") String roleIds); } \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/mapper/xml/SysPermissionMapper.xml b/src/main/java/com/huoran/iasf/mapper/xml/SysPermissionMapper.xml new file mode 100644 index 0000000..f873d32 --- /dev/null +++ b/src/main/java/com/huoran/iasf/mapper/xml/SysPermissionMapper.xml @@ -0,0 +1,14 @@ + + + + + + diff --git a/src/main/java/com/huoran/iasf/service/PermissionService.java b/src/main/java/com/huoran/iasf/service/PermissionService.java index 87e76e1..aadae58 100644 --- a/src/main/java/com/huoran/iasf/service/PermissionService.java +++ b/src/main/java/com/huoran/iasf/service/PermissionService.java @@ -84,4 +84,6 @@ public interface PermissionService extends IService { * @param vo vo */ void updatePermission(SysPermission vo); + + List permissionList(String id); } diff --git a/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java index dd700db..7bdcee7 100644 --- a/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java @@ -1,6 +1,8 @@ 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.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.huoran.iasf.common.exception.BusinessException; @@ -98,6 +100,24 @@ public class PermissionServiceImpl extends ServiceImpl permissionList(String userId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("user_id",userId); + List 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 list = sysPermissionMapper.selectRoleMenu(roleIds); + return build(list); + } + @Override public void updatePermission(SysPermission vo) { sysPermissionMapper.updateById(vo); diff --git a/src/main/java/com/huoran/iasf/service/impl/UserServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/UserServiceImpl.java index 63b3fb3..e267149 100644 --- a/src/main/java/com/huoran/iasf/service/impl/UserServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/UserServiceImpl.java @@ -31,7 +31,6 @@ import com.huoran.iasf.vo.req.ExcelImpUserReq; import com.huoran.iasf.vo.req.UserListReq; import com.huoran.iasf.vo.req.UserRoleOperationReqVO; 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.UserOwnRoleRespVO; import lombok.extern.slf4j.Slf4j; @@ -132,11 +131,11 @@ public class UserServiceImpl extends ServiceImpl impleme if (!allowMultipleLogin) { httpSessionService.abortUserById(sysUser.getId()); } - List menus = permissionService.permissionTreeList(sysUser.getId()); + List menus = permissionService.permissionList(sysUser.getId()); String token = httpSessionService.createTokenAndUser(sysUser, roleService.getRoleNames(sysUser.getId()), permissionService.getPermissionsByUserId(sysUser.getId())); respVO.setAccessToken(token); - respVO.setList(menus); + respVO.setPermissionList(menus); return respVO; } @@ -655,6 +654,11 @@ public class UserServiceImpl extends ServiceImpl impleme SysUser vo = new SysUser(); vo.setSalt(PasswordUtils.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.setStatus(1); vo.setCreateWhere(1); diff --git a/src/main/java/com/huoran/iasf/vo/resp/LoginRespVO.java b/src/main/java/com/huoran/iasf/vo/resp/LoginRespVO.java index a38c181..0f62d01 100644 --- a/src/main/java/com/huoran/iasf/vo/resp/LoginRespVO.java +++ b/src/main/java/com/huoran/iasf/vo/resp/LoginRespVO.java @@ -1,5 +1,6 @@ package com.huoran.iasf.vo.resp; +import com.huoran.iasf.entity.SysPermission; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -22,6 +23,6 @@ public class LoginRespVO { private String id; @ApiModelProperty(value = "电话") private String phone; - @ApiModelProperty(value = "用户所拥有的菜单权限(前后端分离返回给前端控制菜单和按钮的显示和隐藏)") - private List list; + @ApiModelProperty(value = "用户所拥有的菜单权限") + private List permissionList; } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 9ba3bf3..3208f92 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -9,6 +9,15 @@ spring: password: HuoRan@2021 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 +# 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: host: localhost # Redis服务器地址 database: 0 # Redis数据库索引(默认为0)