From cf8a3d3f84fb01a744208eda383c4cc46a770a47 Mon Sep 17 00:00:00 2001 From: DB <2502523450@qq.com> Date: Thu, 19 Oct 2023 19:44:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=9F=8E=E6=A8=A1=E5=9D=97-=E9=80=9A?= =?UTF-8?q?=E7=94=A8=E7=B3=BB=E7=BB=9F=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../abstracts/AbstractLoginInfoBuild.java | 43 +++ .../com/cpop/core/base/entity/Permission.java | 20 ++ .../entity/loginInfo/MallStaffLoginInfo.java | 37 +++ .../com/cpop/core/base/enums/UserType.java | 6 +- .../com/cpop/core/config/SecurityConfig.java | 34 ++- .../core/filter/JwtAuthenticationFilter.java | 11 + .../MiniProgramAuthenticationProvider.java | 3 +- .../gateway/sys/SysAuthenticationFilter.java | 63 +++++ .../sys/SysAuthenticationProvider.java | 44 +++ .../gateway/sys/SysAuthenticationToken.java | 72 +++++ .../core/gateway/sys/SysLoginInfoBuild.java | 126 +++++++++ .../core/handler/LoginFailureHandler.java | 5 +- .../core/handler/LoginSuccessHandler.java | 7 +- .../java/com/cpop/core/mapper/CoreMapper.java | 2 +- .../com/cpop/core/service/CoreService.java | 13 +- .../core/service/impl/CoreServiceImpl.java | 41 ++- .../impl/OamStaffDetailsServiceImpl.java | 19 +- .../com/cpop/core/utils/SecurityUtils.java | 23 +- .../src/main/resources/mapper/CoreMapper.xml | 10 +- .../com/cpop/generator/CpopGenerator.java | 8 +- Cpop-Mall/Cpop-Mall-Web/pom.xml | 2 +- .../cpop/mall/web/CpopMallWebApplication.java | 6 +- .../src/main/resources/application-dev.yml | 16 +- .../src/main/resources/application.yml | 2 +- Cpop-Mall/pom.xml | 4 + .../controller/MallRoleController.java | 133 +++++++++ .../business/controller/StaffController.java | 106 +++++++ .../cpop/mall/business/entity/RoleBrand.java | 50 ++++ .../com/cpop/mall/business/entity/Staff.java | 62 ++++ .../mall/business/mapper/RoleBrandMapper.java | 14 + .../mall/business/mapper/StaffMapper.java | 14 + .../business/service/RoleBrandService.java | 26 ++ .../mall/business/service/StaffService.java | 14 + .../service/impl/RoleBrandServiceImpl.java | 46 +++ .../service/impl/StaffServiceImpl.java | 18 ++ .../cpop/mall/business/vo/MallRolePageVo.java | 81 ++++++ .../main/resources/mapper/RoleBrandMapper.xml | 7 + .../src/main/resources/mapper/StaffMapper.xml | 7 + Cpop-System/pom.xml | 23 ++ .../com/cpop/system/business/bo/MenuBo.java | 109 +++++++ .../cpop/system/business/bo/MenuListBo.java | 33 +++ .../com/cpop/system/business/bo/RoleBo.java | 72 +++++ .../cpop/system/business/bo/RolePageBo.java | 34 +++ .../cpop/system/business/bo/RoleStatusBo.java | 38 +++ .../business/controller/LoginController.java | 64 +++++ .../business/controller/MenuController.java | 117 ++++++++ .../business/controller/RoleController.java | 139 +++++++++ .../com/cpop/system/business/entity/Menu.java | 102 +++++++ .../com/cpop/system/business/entity/Role.java | 68 +++++ .../cpop/system/business/entity/RoleMenu.java | 40 +++ .../system/business/mapper/MenuMapper.java | 14 + .../system/business/mapper/RoleMapper.java | 14 + .../business/mapper/RoleMenuMapper.java | 14 + .../system/business/service/LoginService.java | 32 +++ .../system/business/service/MenuService.java | 69 +++++ .../business/service/RoleMenuService.java | 14 + .../system/business/service/RoleService.java | 63 +++++ .../service/impl/LoginServiceImpl.java | 90 ++++++ .../service/impl/MenuServiceImpl.java | 266 ++++++++++++++++++ .../service/impl/RoleMenuServiceImpl.java | 18 ++ .../service/impl/RoleServiceImpl.java | 157 +++++++++++ .../system/business/vo/LoginUserInfoVo.java | 70 +++++ .../cpop/system/business/vo/MenuRouteVo.java | 145 ++++++++++ .../com/cpop/system/business/vo/MenuVo.java | 117 ++++++++ .../cpop/system/business/vo/RolePageVo.java | 76 +++++ .../com/cpop/system/business/vo/RoleVo.java | 59 ++++ .../src/main/resources/application-system.yml | 1 + .../src/main/resources/mapper/MenuMapper.xml | 7 + .../src/main/resources/mapper/RoleMapper.xml | 7 + .../main/resources/mapper/RoleMenuMapper.xml | 7 + pom.xml | 6 + 71 files changed, 3227 insertions(+), 53 deletions(-) create mode 100644 Cpop-Core/src/main/java/com/cpop/core/abstracts/AbstractLoginInfoBuild.java create mode 100644 Cpop-Core/src/main/java/com/cpop/core/base/entity/Permission.java create mode 100644 Cpop-Core/src/main/java/com/cpop/core/base/entity/loginInfo/MallStaffLoginInfo.java create mode 100644 Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysAuthenticationFilter.java create mode 100644 Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysAuthenticationProvider.java create mode 100644 Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysAuthenticationToken.java create mode 100644 Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysLoginInfoBuild.java create mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/business/controller/MallRoleController.java create mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/business/controller/StaffController.java create mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/business/entity/RoleBrand.java create mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/business/entity/Staff.java create mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/business/mapper/RoleBrandMapper.java create mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/business/mapper/StaffMapper.java create mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/business/service/RoleBrandService.java create mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/business/service/StaffService.java create mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/RoleBrandServiceImpl.java create mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/StaffServiceImpl.java create mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/business/vo/MallRolePageVo.java create mode 100644 Cpop-Mall/src/main/resources/mapper/RoleBrandMapper.xml create mode 100644 Cpop-Mall/src/main/resources/mapper/StaffMapper.xml create mode 100644 Cpop-System/pom.xml create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/bo/MenuBo.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/bo/MenuListBo.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/bo/RoleBo.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/bo/RolePageBo.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/bo/RoleStatusBo.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/controller/LoginController.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/controller/MenuController.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/controller/RoleController.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/entity/Menu.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/entity/Role.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/entity/RoleMenu.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/mapper/MenuMapper.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/mapper/RoleMapper.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/mapper/RoleMenuMapper.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/service/LoginService.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/service/MenuService.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/service/RoleMenuService.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/service/RoleService.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/service/impl/LoginServiceImpl.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/service/impl/MenuServiceImpl.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/service/impl/RoleMenuServiceImpl.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/service/impl/RoleServiceImpl.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/vo/LoginUserInfoVo.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/vo/MenuRouteVo.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/vo/MenuVo.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/vo/RolePageVo.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/vo/RoleVo.java create mode 100644 Cpop-System/src/main/resources/application-system.yml create mode 100644 Cpop-System/src/main/resources/mapper/MenuMapper.xml create mode 100644 Cpop-System/src/main/resources/mapper/RoleMapper.xml create mode 100644 Cpop-System/src/main/resources/mapper/RoleMenuMapper.xml diff --git a/Cpop-Core/src/main/java/com/cpop/core/abstracts/AbstractLoginInfoBuild.java b/Cpop-Core/src/main/java/com/cpop/core/abstracts/AbstractLoginInfoBuild.java new file mode 100644 index 0000000..9853571 --- /dev/null +++ b/Cpop-Core/src/main/java/com/cpop/core/abstracts/AbstractLoginInfoBuild.java @@ -0,0 +1,43 @@ +package com.cpop.core.abstracts; + +import com.cpop.core.base.entity.LoginUser; +import com.cpop.core.base.enums.UserType; +import com.cpop.core.base.table.SysUser; +import com.cpop.core.gateway.sys.SysLoginInfoBuild; + +import java.util.Set; + +/** + * @author DB + * @createTime 2023/10/19 11:26 + * @description + */ +public abstract class AbstractLoginInfoBuild { + + /** + * @descriptions 构建用户信息 + * @author DB + * @date 2023/10/19 12:50 + * @param userType 用户类型 + * @return: com.cpop.core.abstracts.AbstractLoginInfoBuild + */ + public static AbstractLoginInfoBuild getInstance(UserType userType){ + switch (userType){ + //系统用户 + case OAM_USER: + case MALL_USER: + return new SysLoginInfoBuild(); + //小程序用户 + case MINI_USER: + return new SysLoginInfoBuild(); + default: + return new SysLoginInfoBuild(); + } + } + + /** + * 构建用户 + */ + public abstract LoginUser buildLoginUser(SysUser user); + +} diff --git a/Cpop-Core/src/main/java/com/cpop/core/base/entity/Permission.java b/Cpop-Core/src/main/java/com/cpop/core/base/entity/Permission.java new file mode 100644 index 0000000..5378d53 --- /dev/null +++ b/Cpop-Core/src/main/java/com/cpop/core/base/entity/Permission.java @@ -0,0 +1,20 @@ +package com.cpop.core.base.entity; + +/** + * 权限组 + */ +public class Permission { + + /** + * 权限 + */ + private String permission; + + public String getPermission() { + return permission; + } + + public void setPermission(String permission) { + this.permission = permission; + } +} \ No newline at end of file diff --git a/Cpop-Core/src/main/java/com/cpop/core/base/entity/loginInfo/MallStaffLoginInfo.java b/Cpop-Core/src/main/java/com/cpop/core/base/entity/loginInfo/MallStaffLoginInfo.java new file mode 100644 index 0000000..344c08d --- /dev/null +++ b/Cpop-Core/src/main/java/com/cpop/core/base/entity/loginInfo/MallStaffLoginInfo.java @@ -0,0 +1,37 @@ +package com.cpop.core.base.entity.loginInfo; + +import com.cpop.core.base.table.SysUser; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * @author DB + * @createTime 2023/10/19 13:10 + * @description 商城管理员工登陆信息 + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = true) +public class MallStaffLoginInfo extends SysUser { + + /** + * 员工id(mallStaffId) + */ + private String id; + + /** + * 姓名 + */ + private String name; + + /** + * 用户id + */ + private String userId; + + /** + * 角色id + */ + private String roleId; +} diff --git a/Cpop-Core/src/main/java/com/cpop/core/base/enums/UserType.java b/Cpop-Core/src/main/java/com/cpop/core/base/enums/UserType.java index 1f67e0e..1cb1b92 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/base/enums/UserType.java +++ b/Cpop-Core/src/main/java/com/cpop/core/base/enums/UserType.java @@ -16,7 +16,11 @@ public enum UserType { /** * 小程序用户 */ - MINI_USER(1, "mini:loginUser:"); + MINI_USER(1, "mini:loginUser:"), + /** + * 商城用户 + */ + MALL_USER(2, "mall:loginUser:"); /** * code diff --git a/Cpop-Core/src/main/java/com/cpop/core/config/SecurityConfig.java b/Cpop-Core/src/main/java/com/cpop/core/config/SecurityConfig.java index 530fad5..14601e2 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/config/SecurityConfig.java +++ b/Cpop-Core/src/main/java/com/cpop/core/config/SecurityConfig.java @@ -7,6 +7,8 @@ import com.cpop.core.filter.RepeatableFilter; import com.cpop.core.gateway.miniProgram.MiniProgramAuthenticationFilter; import com.cpop.core.gateway.miniProgram.MiniProgramAuthenticationProvider; import com.cpop.core.gateway.oam.OamUsernamePasswordAuthenticationFilter; +import com.cpop.core.gateway.sys.SysAuthenticationFilter; +import com.cpop.core.gateway.sys.SysAuthenticationProvider; import com.cpop.core.handler.*; import com.cpop.core.service.impl.OamStaffDetailsServiceImpl; import com.cpop.core.utils.JwtUtils; @@ -101,8 +103,7 @@ public class SecurityConfig implements WebMvcConfigurer { }) //异常处理器 .exceptionHandling(exceptionHandling -> { - exceptionHandling.authenticationEntryPoint(jwtAuthenticationEntryPoint) - .accessDeniedHandler(jwtAccessDeniedHandler); + exceptionHandling.authenticationEntryPoint(jwtAuthenticationEntryPoint).accessDeniedHandler(jwtAccessDeniedHandler); }) //自定义认证管理器 .authenticationManager(authenticationManager()) @@ -110,7 +111,9 @@ public class SecurityConfig implements WebMvcConfigurer { .addFilterBefore(repeatableFilter, UsernamePasswordAuthenticationFilter.class) // 添加 JWT 过滤器,JWT 过滤器在退出认证过滤器之前 .addFilterBefore(authFilter(), LogoutFilter.class) - .addFilterAt(oamLoginFilter(http.getSharedObject(AuthenticationManager.class)), UsernamePasswordAuthenticationFilter.class) + //.addFilterAt(oamLoginFilter(http.getSharedObject(AuthenticationManager.class)), UsernamePasswordAuthenticationFilter.class) + //系统登陆 + .addFilterAt(sysAuthenticationFilter(http.getSharedObject(AuthenticationManager.class)), UsernamePasswordAuthenticationFilter.class) //小程序认证 .addFilterAt(miniProgramAuthenticationFilter(http.getSharedObject(AuthenticationManager.class)), UsernamePasswordAuthenticationFilter.class); return http.build(); @@ -146,6 +149,27 @@ public class SecurityConfig implements WebMvcConfigurer { return authProvider; } + /** + * @Description: 小程序登陆认证方式(可自定义其他模式) + * @param authenticationManager 认证管理器 + * @return MiniProgramAuthenticationFilter + * @author DB + * @Date: 2023/8/24 0024 10:43 + */ + @Bean + public SysAuthenticationFilter sysAuthenticationFilter(AuthenticationManager authenticationManager) { + SysAuthenticationFilter filter = new SysAuthenticationFilter(); + filter.setAuthenticationManager(authenticationManager); + filter.setAuthenticationSuccessHandler(loginSuccessHandler); + filter.setAuthenticationFailureHandler(loginFailureHandler); + return filter; + } + + @Bean + public SysAuthenticationProvider sysAuthenticationProvider() { + return new SysAuthenticationProvider(); + } + /** * @Description: 小程序登陆认证方式(可自定义其他模式) * @param authenticationManager 认证管理器 @@ -172,8 +196,8 @@ public class SecurityConfig implements WebMvcConfigurer { * @return AuthenticationManager */ @Bean - public AuthenticationManager authenticationManager(){ - return new ProviderManager(Arrays.asList(authenticationProvider(), miniProgramAuthenticationProvider())); + public AuthenticationManager authenticationManager() { + return new ProviderManager(Arrays.asList(authenticationProvider(), miniProgramAuthenticationProvider(), sysAuthenticationProvider())); } /** diff --git a/Cpop-Core/src/main/java/com/cpop/core/filter/JwtAuthenticationFilter.java b/Cpop-Core/src/main/java/com/cpop/core/filter/JwtAuthenticationFilter.java index 994c8ef..ffc8358 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/filter/JwtAuthenticationFilter.java +++ b/Cpop-Core/src/main/java/com/cpop/core/filter/JwtAuthenticationFilter.java @@ -7,6 +7,8 @@ import com.cpop.common.utils.ip.IpUtils; import com.cpop.core.base.entity.LoginUser; import com.cpop.core.base.enums.UserType; import com.cpop.core.gateway.miniProgram.MiniProgramAuthenticationToken; +import com.cpop.core.gateway.sys.SysAuthenticationToken; +import com.cpop.core.service.CoreService; import com.cpop.core.service.RedisService; import com.cpop.core.service.impl.OamStaffDetailsServiceImpl; import com.cpop.core.utils.JwtUtils; @@ -39,6 +41,9 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { @Autowired private OamStaffDetailsServiceImpl oamStaffDetailsService; + @Autowired + private CoreService coreService; + @Autowired private RedisService redisService; @@ -95,6 +100,8 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { break; case MINI_USER: break; + case MALL_USER: + loginUser = coreService.loadUser(username, userType); default: } return loginUser; @@ -118,6 +125,10 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { MiniProgramAuthenticationToken miniProgramAuthenticationToken = new MiniProgramAuthenticationToken(username, loginUser); SecurityContextHolder.getContext().setAuthentication(miniProgramAuthenticationToken); break; + case MALL_USER: + //构建通用系统用户登陆 + SysAuthenticationToken sysAuthenticationToken = new SysAuthenticationToken(username, loginUser,null); + SecurityContextHolder.getContext().setAuthentication(sysAuthenticationToken); default: } diff --git a/Cpop-Core/src/main/java/com/cpop/core/gateway/miniProgram/MiniProgramAuthenticationProvider.java b/Cpop-Core/src/main/java/com/cpop/core/gateway/miniProgram/MiniProgramAuthenticationProvider.java index 92e4487..ef15272 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/gateway/miniProgram/MiniProgramAuthenticationProvider.java +++ b/Cpop-Core/src/main/java/com/cpop/core/gateway/miniProgram/MiniProgramAuthenticationProvider.java @@ -22,8 +22,7 @@ public class MiniProgramAuthenticationProvider implements AuthenticationProvider //TODO:此处添加小程序认证失败返回 throw new RockBladeAuthenticationException("测试抛异常", UserType.MINI_USER); //设置用户详情 LoginUser loginUser = new LoginUser(); - loginUser.setUserName(username) - .setUserType(UserType.MINI_USER); + loginUser.setUserName(username).setUserType(UserType.MINI_USER); MiniProgramAuthenticationToken result = new MiniProgramAuthenticationToken(username, loginUser); result.setDetails(loginUser); return result; diff --git a/Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysAuthenticationFilter.java b/Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysAuthenticationFilter.java new file mode 100644 index 0000000..2cb660f --- /dev/null +++ b/Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysAuthenticationFilter.java @@ -0,0 +1,63 @@ +package com.cpop.core.gateway.sys; + +import com.cpop.core.base.enums.UserType; +import com.cpop.core.gateway.miniProgram.MiniProgramAuthenticationToken; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.security.authentication.AbstractAuthenticationToken; +import org.springframework.security.authentication.AuthenticationServiceException; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +/** + * @author DB + * @createTime 2023/10/19 9:27 + * @description + */ +public class SysAuthenticationFilter extends AbstractAuthenticationProcessingFilter { + + public SysAuthenticationFilter() { + super(new AntPathRequestMatcher("/login", "POST")); + } + + @Override + public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException { + if (!"POST".equals(request.getMethod())) { + throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); + } + //读取表单 + ObjectMapper mapper = new ObjectMapper(); + InputStream inputStream; + Map authenticationBean; + try { + inputStream = request.getInputStream(); + authenticationBean = mapper.readValue(inputStream, Map.class); + } catch (IOException e) { + throw new RuntimeException(e); + } + String principal = (String) authenticationBean.get("username"); + String password = (String) authenticationBean.get("password"); + UserType userType = UserType.valueOf(authenticationBean.get("userType").toString()); + principal = principal.trim(); + //传递信息 + HashMap credentials = new HashMap<>(2); + credentials.put("password", password); + credentials.put("userType", userType); + SysAuthenticationToken authRequest = new SysAuthenticationToken(principal, credentials); + this.setDetails(request, authRequest); + return this.getAuthenticationManager().authenticate(authRequest); + } + + protected void setDetails(HttpServletRequest request, AbstractAuthenticationToken authRequest) { + authRequest.setDetails(this.authenticationDetailsSource.buildDetails(request)); + } +} diff --git a/Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysAuthenticationProvider.java b/Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysAuthenticationProvider.java new file mode 100644 index 0000000..d1cab99 --- /dev/null +++ b/Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysAuthenticationProvider.java @@ -0,0 +1,44 @@ +package com.cpop.core.gateway.sys; + +import com.cpop.core.base.entity.LoginUser; +import com.cpop.core.base.enums.UserType; +import com.cpop.core.gateway.miniProgram.MiniProgramAuthenticationToken; +import com.cpop.core.service.CoreService; +import com.cpop.core.utils.PasswordEncoder; +import com.cpop.core.utils.SpringUtils; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Map; + +/** + * @author DB + * @createTime 2023/10/19 9:36 + * @description + */ +public class SysAuthenticationProvider implements AuthenticationProvider { + + @Override + public Authentication authenticate(Authentication authentication) throws AuthenticationException { + // 这个获取表单输入中返回的用户名; + String principal = (String) authentication.getPrincipal(); + // 这个是表单中输入的密码与用户类型 + Map credentials = (Map) authentication.getCredentials(); + UserType userType = (UserType) credentials.get("userType"); + //认证用户名密码 + LoginUser loginUser = SpringUtils.getBean(CoreService.class).loadUser(principal, userType); + //账号密码校验 + SpringUtils.getBean(PasswordEncoder.class).matches((String) credentials.get("password"), loginUser.getUser().getPassword()); + SysAuthenticationToken result = new SysAuthenticationToken(principal, loginUser); + result.setDetails(loginUser); + return result; + } + + @Override + public boolean supports(Class authentication) { + //providerManager会遍历所有;securityConfig中注册的provider集合;根据此方法返回true或false来决定由哪个provider;去校验请求过来的authentication + return (SysAuthenticationToken.class.isAssignableFrom(authentication)); + } +} diff --git a/Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysAuthenticationToken.java b/Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysAuthenticationToken.java new file mode 100644 index 0000000..8e15480 --- /dev/null +++ b/Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysAuthenticationToken.java @@ -0,0 +1,72 @@ +package com.cpop.core.gateway.sys; + +import org.springframework.security.authentication.AbstractAuthenticationToken; +import org.springframework.security.core.GrantedAuthority; + +import java.util.Collection; + +/** + * @author DB + * @createTime 2023/10/19 9:35 + * @description + */ +public class SysAuthenticationToken extends AbstractAuthenticationToken { + + private final Object principal; + private Object credentials; + + /** + * This constructor can be safely used by any code that wishes to create a + * UsernamePasswordAuthenticationToken, as the {@link #isAuthenticated()} + * will return false. + * + */ + public SysAuthenticationToken(Object principal, Object credentials) { + super(null); + this.principal = principal; + this.credentials = credentials; + setAuthenticated(false); + } + + /** + * This constructor should only be used by AuthenticationManager or + * AuthenticationProvider implementations that are satisfied with + * producing a trusted (i.e. {@link #isAuthenticated()} = true) + * authentication token. + * + * @param principal 第一个参数 + * @param credentials 第二个参数 + * @param authorities 认证 + */ + public SysAuthenticationToken(Object principal, Object credentials, Collection authorities) { + super(authorities); + this.principal = principal; + this.credentials = credentials; + // must use super, as we override + super.setAuthenticated(true); + } + + @Override + public Object getCredentials() { + return this.credentials; + } + + @Override + public Object getPrincipal() { + return this.principal; + } + + @Override + public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { + if (isAuthenticated) { + throw new IllegalArgumentException("Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead"); + } + super.setAuthenticated(false); + } + + @Override + public void eraseCredentials() { + super.eraseCredentials(); + credentials = null; + } +} diff --git a/Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysLoginInfoBuild.java b/Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysLoginInfoBuild.java new file mode 100644 index 0000000..6e0e082 --- /dev/null +++ b/Cpop-Core/src/main/java/com/cpop/core/gateway/sys/SysLoginInfoBuild.java @@ -0,0 +1,126 @@ +package com.cpop.core.gateway.sys; + +import com.cpop.common.constant.Constants; +import com.cpop.common.utils.bean.BeanUtils; +import com.cpop.core.abstracts.AbstractLoginInfoBuild; +import com.cpop.core.base.entity.LoginUser; +import com.cpop.core.base.entity.Permission; +import com.cpop.core.base.entity.loginInfo.MallStaffLoginInfo; +import com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo; +import com.cpop.core.base.exception.CpopAuthenticationException; +import com.cpop.core.base.table.SysUser; +import com.mybatisflex.core.row.DbChain; +import com.mybatisflex.core.row.Row; +import com.mybatisflex.core.row.RowUtil; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * @author DB + * @createTime 2023/10/19 11:30 + * @description + */ +public class SysLoginInfoBuild extends AbstractLoginInfoBuild { + + @Override + public LoginUser buildLoginUser(SysUser sysUser) { + switch (sysUser.getUserType()) { + case OAM_USER: + return getOamStaffLoginInfo(sysUser); + case MALL_USER: + return getMallStaffLoginInfo(sysUser); + default: + return null; + } + } + + /** + * @descriptions Oam员工信息 + * @author DB + * @date 2023/10/19 13:21 + * @param sysUser 系统用户 + * @return: com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo + */ + private LoginUser getOamStaffLoginInfo(SysUser sysUser) { + //构建登陆员工信息 + OamStaffLoginInfo staffLoginInfo = BeanUtils.mapToClass(sysUser, OamStaffLoginInfo.class); + staffLoginInfo.setUserId(sysUser.getId()); + //员工 + if (!staffLoginInfo.getUserName().equals(Constants.SUPER_ADMIN)) { + Row row = DbChain.table("cp_oam_staff") + .select() + .where("user_id = ?", staffLoginInfo.getUserId()) + .one(); + staffLoginInfo.setDeptId(row.getString("deptId")); + staffLoginInfo.setRoleId(row.getString("roleId")); + staffLoginInfo.setName(row.getString("name")); + staffLoginInfo.setStaffType(row.getInt("staffType")); + staffLoginInfo.setId(row.getString("id")); + }else { + staffLoginInfo.setName(Constants.SUPER_ADMIN); + } + return new LoginUser(staffLoginInfo, getPermissionSet(sysUser.getUserName(), staffLoginInfo.getRoleId())); + } + + /** + * @descriptions Mall员工信息 + * @author DB + * @date 2023/10/19 13:21 + * @param sysUser 系统用户 + * @return: com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo + */ + private LoginUser getMallStaffLoginInfo(SysUser sysUser) { + //构建登陆员工信息 + MallStaffLoginInfo staffLoginInfo = BeanUtils.mapToClass(sysUser, MallStaffLoginInfo.class); + staffLoginInfo.setUserId(sysUser.getId()); + //构建员工 + if (!staffLoginInfo.getUserName().equals(Constants.SUPER_ADMIN)) { + Row row = DbChain.table("cp_mall_staff") + .select("cms.id", "cms.name", "cms.user_id") + .select("cmrb.role_id") + .from("cp_mall_staff").as("cms") + .leftJoin("cp_mall_role_brand").as("cmrb").on("cmrb.id = cms.role_brand_id") + .where("cms.user_id = ?", staffLoginInfo.getUserId()) + .and("cms.is_delete = 0") + .one(); + if (row == null) { + throw new CpopAuthenticationException("获取登陆用户信息失败,请核实!"); + } + staffLoginInfo.setRoleId(row.getString("roleId")); + staffLoginInfo.setName(row.getString("name")); + staffLoginInfo.setId(row.getString("id")); + } else { + staffLoginInfo.setName(Constants.SUPER_ADMIN); + } + return new LoginUser(staffLoginInfo, getPermissionSet(sysUser.getUserName(), staffLoginInfo.getRoleId())); + } + + private Set getPermissionSet(String username, String roleId) { + //获取权限 + Set permissionSet = new HashSet<>(); + if (Constants.SUPER_ADMIN.equals(username)) { + permissionSet.add(Constants.ALL_PERMISSION); + } + else { + //查询员工信息 + List list = DbChain.table("cp_sys_menu") + .select("pom.permission") + .from("cp_sys_menu").as("pom") + .leftJoin("cp_sys_role_menu").as("porm").on("porm.menu_id = pom.id") + .where("pom.type in (1,2)") + .and("porm.role_id = ?", roleId) + .and("pom.permission is not null") + .list(); + if (list.isEmpty()) { + permissionSet = new HashSet<>(); + } else { + List permissions = RowUtil.toEntityList(list, Permission.class); + permissionSet = permissions.stream().map(Permission::getPermission).collect(Collectors.toSet()); + } + } + return permissionSet; + } +} diff --git a/Cpop-Core/src/main/java/com/cpop/core/handler/LoginFailureHandler.java b/Cpop-Core/src/main/java/com/cpop/core/handler/LoginFailureHandler.java index 4b150a9..4786d45 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/handler/LoginFailureHandler.java +++ b/Cpop-Core/src/main/java/com/cpop/core/handler/LoginFailureHandler.java @@ -42,8 +42,7 @@ public class LoginFailureHandler implements AuthenticationFailureHandler { LoginForm loginFormBo = JSONObject.parseObject(jsonString, LoginForm.class); //构建用户信息 LoginUser loginUser = new LoginUser(); - loginUser.setUserName(loginFormBo.getUsername()) - .setIpAddr(IpUtils.getIpAddr(httpServletRequest)); + loginUser.setUserName(loginFormBo.getUsername()).setIpAddr(IpUtils.getIpAddr(httpServletRequest)); String errorMessage = "用户名或密码错误"; R result; //自定义认证异常,可以从这里获取到想要的参数 @@ -52,7 +51,7 @@ public class LoginFailureHandler implements AuthenticationFailureHandler { errorMessage = e.getMessage(); } result = R.fail(errorMessage); - if (loginUser.getUserType() == UserType.OAM_USER) { + if (loginUser.getUserType() == UserType.OAM_USER || loginUser.getUserType() == UserType.MINI_USER) { //添加登录失败日志 coreService.insertOperationLog(Constants.FAIL, OperationLogEnum.SYSTEM_LOGIN, loginUser, errorMessage); } diff --git a/Cpop-Core/src/main/java/com/cpop/core/handler/LoginSuccessHandler.java b/Cpop-Core/src/main/java/com/cpop/core/handler/LoginSuccessHandler.java index 12e7c80..686850e 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/handler/LoginSuccessHandler.java +++ b/Cpop-Core/src/main/java/com/cpop/core/handler/LoginSuccessHandler.java @@ -45,8 +45,8 @@ public class LoginSuccessHandler implements AuthenticationSuccessHandler { ServletOutputStream outputStream = httpServletResponse.getOutputStream(); LoginSuccess loginSuccessVo = new LoginSuccess(); LoginUser loginUser; - if (null != authentication.getPrincipal()) { - loginUser = (LoginUser) authentication.getPrincipal(); + if (null != authentication.getCredentials()) { + loginUser = (LoginUser) authentication.getCredentials(); } else { loginUser = (LoginUser) authentication.getDetails(); } @@ -72,8 +72,9 @@ public class LoginSuccessHandler implements AuthenticationSuccessHandler { private void multipleLogin(LoginUser loginUser){ switch (loginUser.getUserType()) { case OAM_USER: + case MALL_USER: //更新登录地址 - coreService.updateSysUserLoginIp(loginUser.getIpAddr(), loginUser.getUsername()); + coreService.updateSysUserLoginIp(loginUser.getIpAddr(), loginUser.getUsername(), loginUser.getUserType()); //添加登录成功日志 coreService.insertOperationLog(Constants.SUCCESS, OperationLogEnum.SYSTEM_LOGIN, loginUser, MessageUtils.message("i18n_login_success")); //将登录成功用户存入缓存 diff --git a/Cpop-Core/src/main/java/com/cpop/core/mapper/CoreMapper.java b/Cpop-Core/src/main/java/com/cpop/core/mapper/CoreMapper.java index c5798e3..5bb9e86 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/mapper/CoreMapper.java +++ b/Cpop-Core/src/main/java/com/cpop/core/mapper/CoreMapper.java @@ -42,7 +42,7 @@ public interface CoreMapper { * @author DB * @Date: 2023/8/28 0028 13:49 */ - void updateSysUserLoginIp(String ipAddr, String username); + void updateSysUserLoginIp(String ipAddr, String username, UserType userType); /** * @Description: 加载参数缓存数据 diff --git a/Cpop-Core/src/main/java/com/cpop/core/service/CoreService.java b/Cpop-Core/src/main/java/com/cpop/core/service/CoreService.java index b4b914f..618e663 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/service/CoreService.java +++ b/Cpop-Core/src/main/java/com/cpop/core/service/CoreService.java @@ -6,6 +6,7 @@ import com.cpop.core.base.enums.UserType; import com.cpop.core.base.table.SysConfig; import com.cpop.core.base.table.SysOperationLog; import com.cpop.core.base.table.SysUser; +import org.springframework.security.core.userdetails.UserDetails; /** * @author DB @@ -50,7 +51,7 @@ public interface CoreService { * @author DB * @Date: 2023/8/28 0028 13:48 */ - void updateSysUserLoginIp(String ipAddr, String username); + void updateSysUserLoginIp(String ipAddr, String username, UserType userType); /** * 根据键名查询参数配置信息 @@ -108,4 +109,14 @@ public interface CoreService { * @return void */ void removeSysUserById(String id); + + /** + * @descriptions 根据用户名与用户类型获取用户信息 + * @author DB + * @date 2023/10/19 9:57 + * @param userName 用户名 + * @param userType 用户类型 + * @return 登陆用户 + */ + LoginUser loadUser(String userName, UserType userType); } diff --git a/Cpop-Core/src/main/java/com/cpop/core/service/impl/CoreServiceImpl.java b/Cpop-Core/src/main/java/com/cpop/core/service/impl/CoreServiceImpl.java index b3edb80..28ef615 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/service/impl/CoreServiceImpl.java +++ b/Cpop-Core/src/main/java/com/cpop/core/service/impl/CoreServiceImpl.java @@ -1,6 +1,10 @@ package com.cpop.core.service.impl; +import com.cpop.common.constant.Constants; +import com.cpop.common.utils.bean.BeanUtils; +import com.cpop.core.abstracts.AbstractLoginInfoBuild; import com.cpop.core.base.entity.LoginUser; +import com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo; import com.cpop.core.base.enums.OperationLogEnum; import com.cpop.core.base.enums.UserType; import com.cpop.core.base.exception.ServiceException; @@ -12,12 +16,19 @@ import com.cpop.core.service.CoreService; import com.cpop.core.utils.MessageUtils; import com.cpop.core.utils.SecurityUtils; import com.cpop.core.utils.uuid.IdUtils; +import com.mybatisflex.core.row.DbChain; +import com.mybatisflex.core.row.Row; +import com.mybatisflex.core.row.RowUtil; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; /** * @author DB @@ -102,8 +113,8 @@ public class CoreServiceImpl implements CoreService { * @Date: 2023/8/28 0028 13:48 */ @Override - public void updateSysUserLoginIp(String ipAddr, String username) { - coreMapper.updateSysUserLoginIp(ipAddr, username); + public void updateSysUserLoginIp(String ipAddr, String username, UserType userType) { + coreMapper.updateSysUserLoginIp(ipAddr, username, userType); } /** @@ -193,4 +204,30 @@ public class CoreServiceImpl implements CoreService { public void removeSysUserById(String id) { coreMapper.removeSysUserById(id); } + + /** + * @descriptions 根据用户名与用户类型获取用户信息 + * @author DB + * @date 2023/10/19 9:57 + * @param username 用户名 + * @param userType 用户类型 + * @return 登陆用户 + */ + @Override + public LoginUser loadUser(String username, UserType userType) { + //统一获取系统用户信息 + SysUser sysUser = this.getSysUser(username, userType); + if (sysUser == null) { + throw new UsernameNotFoundException(MessageUtils.message("i18n_alert_accountOrPwdError")); + } + //构建登陆用户信息 + AbstractLoginInfoBuild instance = AbstractLoginInfoBuild.getInstance(userType); + LoginUser loginUser = instance.buildLoginUser(sysUser); + loginUser.setUserId(sysUser.getId()) + .setUserType(userType) + .setUserName(username) + .setLoginTime(System.currentTimeMillis()) + .setStatus(sysUser.getStatus()); + return loginUser; + } } diff --git a/Cpop-Core/src/main/java/com/cpop/core/service/impl/OamStaffDetailsServiceImpl.java b/Cpop-Core/src/main/java/com/cpop/core/service/impl/OamStaffDetailsServiceImpl.java index 755b1df..c3955c7 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/service/impl/OamStaffDetailsServiceImpl.java +++ b/Cpop-Core/src/main/java/com/cpop/core/service/impl/OamStaffDetailsServiceImpl.java @@ -3,6 +3,7 @@ package com.cpop.core.service.impl; import com.cpop.common.constant.Constants; import com.cpop.common.utils.bean.BeanUtils; import com.cpop.core.base.entity.LoginUser; +import com.cpop.core.base.entity.Permission; import com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo; import com.cpop.core.base.enums.UserType; import com.cpop.core.base.table.SysUser; @@ -92,22 +93,4 @@ public class OamStaffDetailsServiceImpl implements UserDetailsService { return loginUser; } - /** - * 内部自用类 - */ - public class Permission { - - /** - * 权限 - */ - private String permission; - - public String getPermission() { - return permission; - } - - public void setPermission(String permission) { - this.permission = permission; - } - } } diff --git a/Cpop-Core/src/main/java/com/cpop/core/utils/SecurityUtils.java b/Cpop-Core/src/main/java/com/cpop/core/utils/SecurityUtils.java index 23fa51b..3284b16 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/utils/SecurityUtils.java +++ b/Cpop-Core/src/main/java/com/cpop/core/utils/SecurityUtils.java @@ -1,8 +1,13 @@ package com.cpop.core.utils; +import com.alibaba.fastjson.JSONObject; import com.cpop.core.base.entity.LoginUser; +import com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo; +import com.cpop.core.base.enums.UserType; +import com.cpop.core.service.RedisService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @@ -37,11 +42,25 @@ public class SecurityUtils { if (authentication == null) { return null; } - if (null != authentication.getPrincipal()) { - return (LoginUser) authentication.getPrincipal(); + if (null != authentication.getCredentials()) { + return (LoginUser) authentication.getCredentials(); } else { return (LoginUser) authentication.getDetails(); } } + /** + * @descriptions 获取登陆员工信息 + * @author DB + * @date 2023/09/21 16:00 + * @return com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo + */ + public JSONObject getLoginStaffInfo() { + //获取当前登录用户信息 + LoginUser loginUser = SecurityUtils.getInstance().getLoginUser(); + //获取缓存信息 + JSONObject jsonObject = SpringUtils.getBean(RedisService.class).getCacheObject(loginUser.getUserType().getKey() + loginUser.getUsername()); + return jsonObject.getJSONObject("user"); + } + } diff --git a/Cpop-Core/src/main/resources/mapper/CoreMapper.xml b/Cpop-Core/src/main/resources/mapper/CoreMapper.xml index 2ad6051..3e0dafe 100644 --- a/Cpop-Core/src/main/resources/mapper/CoreMapper.xml +++ b/Cpop-Core/src/main/resources/mapper/CoreMapper.xml @@ -22,6 +22,9 @@ login_ip = #{ipAddr} WHERE user_name = #{username} + + AND user_type = #{userType} + @@ -49,8 +52,9 @@ is_delete = 0 AND user_name = #{username} - AND - user_type = #{userType} + + AND user_type = #{userType} + @@ -103,7 +107,7 @@ config_name = #{configName}, - + config_value = #{config_value}, diff --git a/Cpop-Generator/src/main/java/com/cpop/generator/CpopGenerator.java b/Cpop-Generator/src/main/java/com/cpop/generator/CpopGenerator.java index 27f28cc..93a032f 100644 --- a/Cpop-Generator/src/main/java/com/cpop/generator/CpopGenerator.java +++ b/Cpop-Generator/src/main/java/com/cpop/generator/CpopGenerator.java @@ -25,7 +25,7 @@ public class CpopGenerator { /** * 数据库 URL */ - private static final String URL = "jdbc:mysql://localhost:3306/cpop-union?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8"; + private static final String URL = "jdbc:mysql://localhost:3306/cpop-dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8"; /** * 数据库用户名 @@ -39,17 +39,17 @@ public class CpopGenerator { /** * 输出路径 */ - private static final String EXPORT_URL = "/Cpop-Oam"; + private static final String EXPORT_URL = "/Cpop-Mall"; /** * 模块 */ - private static final String EXPORT_ITEM = "oam"; + private static final String EXPORT_ITEM = "mall"; /** * 表前缀 */ - private static final String TABLE_PREFIX = "cp_oam_"; + private static final String TABLE_PREFIX = "cp_mall_"; /** * 主入口 diff --git a/Cpop-Mall/Cpop-Mall-Web/pom.xml b/Cpop-Mall/Cpop-Mall-Web/pom.xml index ee01563..29bffac 100644 --- a/Cpop-Mall/Cpop-Mall-Web/pom.xml +++ b/Cpop-Mall/Cpop-Mall-Web/pom.xml @@ -14,7 +14,7 @@ jar - + com.cpop Cpop-Mall diff --git a/Cpop-Mall/Cpop-Mall-Web/src/main/java/com/cpop/mall/web/CpopMallWebApplication.java b/Cpop-Mall/Cpop-Mall-Web/src/main/java/com/cpop/mall/web/CpopMallWebApplication.java index 63e20a0..f4168eb 100644 --- a/Cpop-Mall/Cpop-Mall-Web/src/main/java/com/cpop/mall/web/CpopMallWebApplication.java +++ b/Cpop-Mall/Cpop-Mall-Web/src/main/java/com/cpop/mall/web/CpopMallWebApplication.java @@ -1,9 +1,13 @@ package com.cpop.mall.web; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; -@SpringBootApplication +@SpringBootApplication(scanBasePackages = {"com.cpop.**"}) +@MapperScan("com.cpop.**.mapper") +@EnableAsync public class CpopMallWebApplication { public static void main(String[] args) { diff --git a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-dev.yml b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-dev.yml index b57810a..ae1093b 100644 --- a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-dev.yml +++ b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-dev.yml @@ -17,7 +17,7 @@ spring: application: name: Cpop-Mall-Dev datasource: - url: jdbc:mysql://localhost:3306/cpop-union?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + url: jdbc:mysql://localhost:3306/cpop-dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root password: root #redis配置 @@ -49,7 +49,7 @@ spring: database: cpop-union server: - port: 9420 + port: 9430 servlet: context-path: /Cpop-Mall @@ -72,9 +72,15 @@ knife4j: license-url: https://stackoverflow.com/ terms-of-service-url: https://api.jamboxsys.com group: - #系统 - system: + #商城 + Mall: group-name: Mall api-rule: package api-rule-resources: - - com.cpop.mall \ No newline at end of file + - com.cpop.mall + #系统 + System: + group-name: System + api-rule: package + api-rule-resources: + - com.cpop.system \ No newline at end of file diff --git a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml index f7b16ec..22a3169 100644 --- a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml +++ b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml @@ -31,7 +31,7 @@ spring: max-file-size: 1024MB max-request-size: 300MB profiles: - active: dev,mall + active: dev,mall,system datasource: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver diff --git a/Cpop-Mall/pom.xml b/Cpop-Mall/pom.xml index 1c52ea0..b5574b6 100644 --- a/Cpop-Mall/pom.xml +++ b/Cpop-Mall/pom.xml @@ -19,6 +19,10 @@ com.cpop Cpop-Core + + com.cpop + Cpop-System + diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/MallRoleController.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/MallRoleController.java new file mode 100644 index 0000000..8599566 --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/MallRoleController.java @@ -0,0 +1,133 @@ +package com.cpop.mall.business.controller; + +import com.cpop.core.annontation.OperationLog; +import com.cpop.core.base.R; +import com.cpop.core.base.enums.OperationLogEnum; +import com.cpop.mall.business.service.RoleBrandService; +import com.cpop.mall.business.vo.MallRolePageVo; +import com.cpop.system.business.bo.MenuListBo; +import com.cpop.system.business.bo.RoleBo; +import com.cpop.system.business.bo.RolePageBo; +import com.cpop.system.business.bo.RoleStatusBo; +import com.cpop.system.business.service.MenuService; +import com.cpop.system.business.service.RoleService; +import com.cpop.system.business.vo.MenuVo; +import com.cpop.system.business.vo.RolePageVo; +import com.mybatisflex.core.paginate.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @author DB + * @createTime 2023/10/19 18:14 + * @description + */ +@RestController +@Api(tags = "商城角色定制模块") +@RequestMapping("/mallRole") +public class MallRoleController { + + @Autowired + private RoleBrandService roleBrandService; + + @Autowired + private RoleService roleService; + + @Autowired + private MenuService menuService; + + /** + * @descriptions 查询商城角色分页列表 + * @author DB + * @date 2023/09/10 16:51 + * @param bo 请求参数 + * @return R> + */ + @PreAuthorize("@aps.hasPermission('system:role:list')") + @ApiOperation("查询商城角色分页列表") + @GetMapping("/getMallRolePageList") + public R> getMallRolePageList(RolePageBo bo) { + Page pageVo = roleBrandService.getMallRolePageList(bo); + return R.ok(pageVo); + } + + /** + * @descriptions 新增角色 + * @author DB + * @date 2023/10/12 10:48 + * @param bo 请求参数 + * @return: com.cpop.core.base.R + */ + @PreAuthorize("@aps.hasPermission('system:role:insert')") + @OperationLog(operationLogEnumType = OperationLogEnum.INSERT_OAM_ROLE) + @ApiOperation("新增商城角色") + @PostMapping("/insertSysRole") + public R insertSysRole(@RequestBody @Validated RoleBo bo) { + roleService.insertSysRole(bo); + return R.ok(); + } + + /** + * @Description: 获取系统菜单树列表 + * @return: R> + * @Author: DB + * @Date: 2023/5/10 14:39 + **/ + @ApiOperation("获取菜单树列表") + @GetMapping("/getSysMenuTreeList") + public R> getSysMenuTreeList() { + List list = menuService.getSysMenuTreeList(new MenuListBo()); + //过滤掉没有权限的数据 + return R.ok(list); + } + + /** + * @descriptions 修改角色 + * @author DB + * @date 2023/09/10 17:45 + * @param bo 请求参数 + * @return com.jambox.core.base.R + */ + @PreAuthorize("@aps.hasPermission('system:role:update')") + @OperationLog(operationLogEnumType = OperationLogEnum.UPDATE_OAM_ROLE) + @ApiOperation("修改商城角色") + @PutMapping("/updateSysRole") + public R updateSysRole(@RequestBody @Validated RoleBo bo) { + roleService.updateSysRole(bo); + return R.ok(); + } + + /** + * 删除系统角色表 + */ + @PreAuthorize("@aps.hasPermission('system:role:remove')") + @OperationLog(operationLogEnumType = OperationLogEnum.REMOVE_OAM_ROLE) + @ApiOperation("删除商城角色表") + @DeleteMapping("/removeSysRole/{id}") + public R removeSysRole(@PathVariable String id) { + roleService.removeSysRole(id); + return R.ok(); + } + + /** + * @Description: 设置角色状态 + * @param bo 请求参数 + * @return: R + * @Author: DB + * @Date: 2023/5/9 14:13 + **/ + @PreAuthorize("@aps.hasPermission('system:role:update')") + @OperationLog(operationLogEnumType = OperationLogEnum.UPDATE_OAM_ROLE) + @ApiOperation("设置商城角色状态") + @PutMapping("/setSysRoleStatus") + public R setSysRoleStatus(@RequestBody @Validated RoleStatusBo bo) { + roleService.setSysRoleStatus(bo); + return R.ok(); + } +} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/StaffController.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/StaffController.java new file mode 100644 index 0000000..d88db4d --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/StaffController.java @@ -0,0 +1,106 @@ +package com.cpop.mall.business.controller; + +import com.mybatisflex.core.paginate.Page; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.beans.factory.annotation.Autowired; +import com.cpop.mall.business.entity.Staff; +import com.cpop.mall.business.service.StaffService; +import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import java.io.Serializable; +import java.util.List; + +/** + * 员工表 控制层。 + * + * @author DB + * @since 2023-10-19 + */ +@RestController +@Api(tags = "商城员工管理接口") +@RequestMapping("/staff") +public class StaffController { + + @Autowired + private StaffService staffService; + + /** + * 添加员工表。 + * + * @param staff 员工表 + * @return {@code true} 添加成功,{@code false} 添加失败 + */ + @PostMapping("/save") + @ApiOperation("保存员工表") + public boolean save(@RequestBody @ApiParam("员工表") Staff staff) { + return staffService.save(staff); + } + + /** + * 根据主键删除员工表。 + * + * @param id 主键 + * @return {@code true} 删除成功,{@code false} 删除失败 + */ + @DeleteMapping("/remove/{id}") + @ApiOperation("根据主键员工表") + public boolean remove(@PathVariable @ApiParam("员工表主键") Serializable id) { + return staffService.removeById(id); + } + + /** + * 根据主键更新员工表。 + * + * @param staff 员工表 + * @return {@code true} 更新成功,{@code false} 更新失败 + */ + @PutMapping("/update") + @ApiOperation("根据主键更新员工表") + public boolean update(@RequestBody @ApiParam("员工表主键") Staff staff) { + return staffService.updateById(staff); + } + + /** + * 查询所有员工表。 + * + * @return 所有数据 + */ + @GetMapping("/list") + @ApiOperation("查询所有员工表") + public List list() { + return staffService.list(); + } + + /** + * 根据员工表主键获取详细信息。 + * + * @param id 员工表主键 + * @return 员工表详情 + */ + @GetMapping("/getInfo/{id}") + @ApiOperation("根据主键获取员工表") + public Staff getInfo(@PathVariable @ApiParam("员工表主键") Serializable id) { + return staffService.getById(id); + } + + /** + * 分页查询员工表。 + * + * @param page 分页对象 + * @return 分页对象 + */ + @GetMapping("/page") + @ApiOperation("分页查询员工表") + public Page page(@ApiParam("分页信息") Page page) { + return staffService.page(page); + } + +} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/RoleBrand.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/RoleBrand.java new file mode 100644 index 0000000..90affb7 --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/RoleBrand.java @@ -0,0 +1,50 @@ +package com.cpop.mall.business.entity; + +import com.cpop.core.base.entity.BaseEntity; +import com.cpop.core.base.entity.BaseInsertListener; +import com.cpop.core.base.entity.BaseUpdateListener; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.Table; +import java.io.Serializable; +import java.time.LocalDateTime; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +/** + * 商城-角色-品牌id 实体类。 + * + * @author DB + * @since 2023-10-19 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@Table(value = "cp_mall_role_brand", onInsert = BaseInsertListener.class, onUpdate = BaseUpdateListener.class, mapperGenerateEnable = false) +public class RoleBrand extends BaseEntity implements Serializable { + + /** + * 主键 + */ + @Id + private String id; + + /** + * 角色id + */ + private String roleId; + + /** + * 校区id + */ + private String brandId; + + + + + +} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/Staff.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/Staff.java new file mode 100644 index 0000000..cd6b712 --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/Staff.java @@ -0,0 +1,62 @@ +package com.cpop.mall.business.entity; + +import com.cpop.core.base.entity.BaseEntity; +import com.cpop.core.base.entity.BaseInsertListener; +import com.cpop.core.base.entity.BaseUpdateListener; +import com.mybatisflex.annotation.Column; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.Table; +import java.io.Serializable; +import java.time.LocalDateTime; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +/** + * 员工表 实体类。 + * + * @author DB + * @since 2023-10-19 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@Table(value = "cp_mall_staff", onInsert = BaseInsertListener.class, onUpdate = BaseUpdateListener.class, mapperGenerateEnable = false) +public class Staff extends BaseEntity implements Serializable { + + /** + * 主键 + */ + @Id + private String id; + + /** + * 姓名 + */ + private String name; + + /** + * 用户id + */ + private String userId; + + /** + * 角色-品牌-id + */ + private String roleBrandId; + + + + + + /** + * 逻辑删除(0否1是) + */ + @Column(isLogicDelete = true) + private Boolean isDelete; + +} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/mapper/RoleBrandMapper.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/mapper/RoleBrandMapper.java new file mode 100644 index 0000000..2be8996 --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/mapper/RoleBrandMapper.java @@ -0,0 +1,14 @@ +package com.cpop.mall.business.mapper; + +import com.mybatisflex.core.BaseMapper; +import com.cpop.mall.business.entity.RoleBrand; + +/** + * 商城-角色-品牌id 映射层。 + * + * @author DB + * @since 2023-10-19 + */ +public interface RoleBrandMapper extends BaseMapper { + +} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/mapper/StaffMapper.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/mapper/StaffMapper.java new file mode 100644 index 0000000..a0ebbcd --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/mapper/StaffMapper.java @@ -0,0 +1,14 @@ +package com.cpop.mall.business.mapper; + +import com.mybatisflex.core.BaseMapper; +import com.cpop.mall.business.entity.Staff; + +/** + * 员工表 映射层。 + * + * @author DB + * @since 2023-10-19 + */ +public interface StaffMapper extends BaseMapper { + +} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/RoleBrandService.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/RoleBrandService.java new file mode 100644 index 0000000..63d4277 --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/RoleBrandService.java @@ -0,0 +1,26 @@ +package com.cpop.mall.business.service; + +import com.cpop.mall.business.vo.MallRolePageVo; +import com.cpop.system.business.bo.RolePageBo; +import com.cpop.system.business.vo.RolePageVo; +import com.mybatisflex.core.paginate.Page; +import com.mybatisflex.core.service.IService; +import com.cpop.mall.business.entity.RoleBrand; + +/** + * 商城-角色-品牌id 服务层。 + * + * @author DB + * @since 2023-10-19 + */ +public interface RoleBrandService extends IService { + + /** + * @descriptions 查询商城角色分页列表 + * @author DB + * @date 2023/09/10 16:51 + * @param bo 请求参数 + * @return R> + */ + Page getMallRolePageList(RolePageBo bo); +} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/StaffService.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/StaffService.java new file mode 100644 index 0000000..cecb294 --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/StaffService.java @@ -0,0 +1,14 @@ +package com.cpop.mall.business.service; + +import com.mybatisflex.core.service.IService; +import com.cpop.mall.business.entity.Staff; + +/** + * 员工表 服务层。 + * + * @author DB + * @since 2023-10-19 + */ +public interface StaffService extends IService { + +} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/RoleBrandServiceImpl.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/RoleBrandServiceImpl.java new file mode 100644 index 0000000..0c47ae4 --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/RoleBrandServiceImpl.java @@ -0,0 +1,46 @@ +package com.cpop.mall.business.service.impl; + +import com.cpop.core.base.entity.PageDomain; +import com.cpop.core.utils.sql.SqlUtils; +import com.cpop.mall.business.vo.MallRolePageVo; +import com.cpop.system.business.bo.RolePageBo; +import com.cpop.system.business.vo.RolePageVo; +import com.mybatisflex.core.paginate.Page; +import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.spring.service.impl.ServiceImpl; +import com.cpop.mall.business.entity.RoleBrand; +import com.cpop.mall.business.mapper.RoleBrandMapper; +import com.cpop.mall.business.service.RoleBrandService; +import org.springframework.stereotype.Service; + +import static com.cpop.mall.business.entity.table.RoleBrandTableDef.ROLE_BRAND; + +/** + * 商城-角色-品牌id 服务层实现。 + * + * @author DB + * @since 2023-10-19 + */ +@Service("roleBrandService") +public class RoleBrandServiceImpl extends ServiceImpl implements RoleBrandService { + + /** + * @descriptions 查询商城角色分页列表 + * @author DB + * @date 2023/09/10 16:51 + * @param bo 请求参数 + * @return R> + */ + @Override + public Page getMallRolePageList(RolePageBo bo) { + //获取分页参数 + PageDomain pageDomain = SqlUtils.getInstance().getPageDomain(); + this.mapper.paginateAs(pageDomain.getPageNum(),pageDomain.getPageSize(), + QueryWrapper.create() + .select(ROLE_BRAND.ALL_COLUMNS) + + ,RolePageVo.class); + + return null; + } +} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/StaffServiceImpl.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/StaffServiceImpl.java new file mode 100644 index 0000000..57c1aba --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/StaffServiceImpl.java @@ -0,0 +1,18 @@ +package com.cpop.mall.business.service.impl; + +import com.mybatisflex.spring.service.impl.ServiceImpl; +import com.cpop.mall.business.entity.Staff; +import com.cpop.mall.business.mapper.StaffMapper; +import com.cpop.mall.business.service.StaffService; +import org.springframework.stereotype.Service; + +/** + * 员工表 服务层实现。 + * + * @author DB + * @since 2023-10-19 + */ +@Service("staffService") +public class StaffServiceImpl extends ServiceImpl implements StaffService { + +} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/MallRolePageVo.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/MallRolePageVo.java new file mode 100644 index 0000000..787e348 --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/MallRolePageVo.java @@ -0,0 +1,81 @@ +package com.cpop.mall.business.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.mybatisflex.annotation.Column; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.List; + +/** + * @author DB + * @createTime 2023/10/19 18:28 + * @description + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "Role分页返回对象") +public class MallRolePageVo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @ApiModelProperty("主键") + private String id; + + /** + * 角色id + */ + @ApiModelProperty("角色id") + private String roleId; + + /** + * 角色名称 + */ + @ApiModelProperty("角色名称") + private String roleName; + + /** + * 角色值 + */ + @ApiModelProperty("角色值") + private String roleValue; + + /** + * 状态 + */ + @ApiModelProperty("状态") + private Boolean status; + + /** + * 备注 + */ + @ApiModelProperty("备注") + private String remark; + + /** + * 排序 + */ + @ApiModelProperty("排序") + private Integer orderNo; + + /** + * 更新时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8") + @ApiModelProperty("更新时间") + private Timestamp updateTime; + + /** + * 角色所属菜单id集合 + */ + @ApiModelProperty("角色所属菜单id集合") + @Column(ignore = true) + private List menuIds; +} diff --git a/Cpop-Mall/src/main/resources/mapper/RoleBrandMapper.xml b/Cpop-Mall/src/main/resources/mapper/RoleBrandMapper.xml new file mode 100644 index 0000000..b7daa32 --- /dev/null +++ b/Cpop-Mall/src/main/resources/mapper/RoleBrandMapper.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/Cpop-Mall/src/main/resources/mapper/StaffMapper.xml b/Cpop-Mall/src/main/resources/mapper/StaffMapper.xml new file mode 100644 index 0000000..8ed58b4 --- /dev/null +++ b/Cpop-Mall/src/main/resources/mapper/StaffMapper.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/Cpop-System/pom.xml b/Cpop-System/pom.xml new file mode 100644 index 0000000..1aacead --- /dev/null +++ b/Cpop-System/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + + com.cpop + Cpop-Union + 1.0.0 + ../pom.xml + + Cpop-System + Cpop-System + Cpop-System + + + + + com.cpop + Cpop-Core + + + + diff --git a/Cpop-System/src/main/java/com/cpop/system/business/bo/MenuBo.java b/Cpop-System/src/main/java/com/cpop/system/business/bo/MenuBo.java new file mode 100644 index 0000000..16af257 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/bo/MenuBo.java @@ -0,0 +1,109 @@ +package com.cpop.system.business.bo; + + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + + +/** + * 系统菜单表Bo + * + * @author DB.lost + * @since 2023-05-10 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "SysMenu对象", description = "系统菜单表") +public class MenuBo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 菜单ID + */ + @ApiModelProperty("菜单ID") + private String id; + + /** + * 父级菜单ID + */ + @ApiModelProperty("父级菜单ID") + private String parentMenu; + + /** + * 菜单名称 + */ + @ApiModelProperty("菜单名称") + private String name; + + /** + * 菜单图标 + */ + @ApiModelProperty(value = "菜单图标") + private String icon; + + /** + * 菜单路由,父菜单为空 + */ + @ApiModelProperty("菜单路由,父菜单为空") + private String component; + + /** + * 标记菜单的状态 0:禁用 1:启用(根据权限正常显示) + */ + @NotNull(message = "状态不能为空") + @ApiModelProperty(value = "标记菜单的状态 0:禁用 1:启用(根据权限正常显示)", required = true) + private Boolean status; + + /** + * 菜单类型,0:目录,1:菜单,2:按钮 + */ + @NotNull(message = "菜单类型不能为空") + @ApiModelProperty(value = "菜单类型,0:目录,1:菜单,2:按钮", required = true) + private Integer type; + + /** + * 权限 + */ + @ApiModelProperty("权限") + private String permission; + + /** + * 重定向路径,一级菜单有值 + */ + @ApiModelProperty("重定向路径,一级菜单有值") + private String redirect; + + /** + * 排序,值越小越靠前,一级菜单有值 + */ + @NotNull(message = "排序不能为空") + @ApiModelProperty(value = "排序,值越小越靠前,一级菜单有值", required = true) + private Integer orderNo; + + /** + * 路由地址 + */ + @ApiModelProperty(value = "路由地址") + private String path; + + /** + * 标题 + */ + @NotBlank(message = "标题不能为空") + @ApiModelProperty(value = "标题", required = true) + private String title; + + /** + * 隐藏菜单 + */ + @ApiModelProperty("隐藏菜单") + private Boolean hideMenu; + +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/bo/MenuListBo.java b/Cpop-System/src/main/java/com/cpop/system/business/bo/MenuListBo.java new file mode 100644 index 0000000..34fbb5b --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/bo/MenuListBo.java @@ -0,0 +1,33 @@ +package com.cpop.system.business.bo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * Description: + * date: 2023/4/25 18:01 + * @author ST + */ +@Data +@Accessors(chain = true) +@ApiModel(description = "菜单传入对象") +public class MenuListBo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 标题 + */ + @ApiModelProperty(value = "标题") + private String title; + + /** + * 标记菜单的状态 0:禁用 1:启用(根据权限正常显示) + */ + @ApiModelProperty(value = "标记菜单的状态 0:禁用 1:启用(根据权限正常显示)") + private Boolean status; +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/bo/RoleBo.java b/Cpop-System/src/main/java/com/cpop/system/business/bo/RoleBo.java new file mode 100644 index 0000000..68a94dd --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/bo/RoleBo.java @@ -0,0 +1,72 @@ +package com.cpop.system.business.bo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +/** + * 系统角色表Bo + * + * @author DB.lost + * @since 2023-05-10 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "SysRole对象", description = "系统角色表") +public class RoleBo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @ApiModelProperty("主键") + private String id; + + /** + * 角色名称 + */ + @NotBlank(message = "角色名称不能为空") + @ApiModelProperty("角色名称") + private String roleName; + + /** + * 角色值 + */ + @NotBlank(message = "角色值不能为空") + @ApiModelProperty("角色值") + private String roleValue; + + /** + * 状态 + */ + @NotNull(message = "状态不能为空") + @ApiModelProperty("状态") + private Boolean status; + + /** + * 备注 + */ + @ApiModelProperty("备注") + private String remark; + + /** + * 排序 + */ + @NotNull(message = "排序不能为空") + @ApiModelProperty("排序") + private Integer orderNo; + + /** + * 菜单集合 + */ + @ApiModelProperty("菜单集合") + private List menuIds; + +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/bo/RolePageBo.java b/Cpop-System/src/main/java/com/cpop/system/business/bo/RolePageBo.java new file mode 100644 index 0000000..050daa8 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/bo/RolePageBo.java @@ -0,0 +1,34 @@ +package com.cpop.system.business.bo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * Description: + * date: 2023/5/9 13:58 + * + * @Author DB + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "SysRole分页对象") +public class RolePageBo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 角色名称 + */ + @ApiModelProperty("角色名称") + private String roleName; + + /** + * 状态 + */ + @ApiModelProperty("状态") + private Boolean status; +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/bo/RoleStatusBo.java b/Cpop-System/src/main/java/com/cpop/system/business/bo/RoleStatusBo.java new file mode 100644 index 0000000..e33c45b --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/bo/RoleStatusBo.java @@ -0,0 +1,38 @@ +package com.cpop.system.business.bo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * Description: + * date: 2023/5/9 14:12 + * + * @Author DB + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "SysRole状态对象", description = "修改角色状态") +public class RoleStatusBo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @NotBlank(message = "id不能为空") + @ApiModelProperty(value = "主键",required = true) + private String id; + + /** + * 状态 + */ + @NotNull(message = "状态不能为空") + @ApiModelProperty(value = "状态", required = true) + private Boolean status; +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/controller/LoginController.java b/Cpop-System/src/main/java/com/cpop/system/business/controller/LoginController.java new file mode 100644 index 0000000..419bcd2 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/controller/LoginController.java @@ -0,0 +1,64 @@ +package com.cpop.system.business.controller; + +import com.cpop.core.base.R; +import com.cpop.system.business.service.LoginService; +import com.cpop.system.business.vo.LoginUserInfoVo; +import com.cpop.system.business.vo.MenuRouteVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @author DB + * @createTime 2023/09/10 11:13 + * @description 系统登陆 + */ +@Api(tags = "系统登录模块") +@RestController +public class LoginController { + + @Autowired + private LoginService loginService; + + /** + * @author LOST.yuan + * @Description 获取登录用户详情 + * @date 14:52 2022/9/7 + * @return {@link R} + **/ + @GetMapping("/getUserInfo") + @ApiOperation("获取登录用户详情") + public R getUserInfo() { + return R.ok(loginService.getUserInfo()); + } + + /** + * @author LOST.yuan + * @Description 获取权限码 + * @date 14:52 2022/9/7 + * @return {@link List} + **/ + @ApiOperation("获取权限码") + @GetMapping("/getPermCode") + public R> getPermCode(){ + List list = loginService.getPermCode(); + return R.ok(list); + } + + /** + * @author LOST.yuan + * @Description 获取菜单列表 + * @date 14:52 2022/9/7 + * @return {@link R>} + **/ + @ApiOperation("获取菜单列表") + @GetMapping("/getMenuList") + public R> getMenuList(){ + List list = loginService.getSysMenuList(); + return R.ok(list); + } +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/controller/MenuController.java b/Cpop-System/src/main/java/com/cpop/system/business/controller/MenuController.java new file mode 100644 index 0000000..3b3caf1 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/controller/MenuController.java @@ -0,0 +1,117 @@ +package com.cpop.system.business.controller; + +import com.cpop.core.annontation.OperationLog; +import com.cpop.core.base.R; +import com.cpop.core.base.enums.OperationLogEnum; +import com.cpop.system.business.bo.MenuBo; +import com.cpop.system.business.bo.MenuListBo; +import com.cpop.system.business.vo.MenuVo; +import com.mybatisflex.core.paginate.Page; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.beans.factory.annotation.Autowired; +import com.cpop.system.business.entity.Menu; +import com.cpop.system.business.service.MenuService; +import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import java.io.Serializable; +import java.util.List; + +/** + * 系统菜单表 控制层。 + * + * @author DB + * @since 2023-10-19 + */ +@RestController +@Api(tags = "系统菜单表接口") +@RequestMapping("/menu") +public class MenuController { + + @Autowired + private MenuService menuService; + + /** + * @descriptions 获取系统菜单树列表 + * @author DB + * @date 2023/09/07 15:48 + * @param bo 请求参数 + * @return com.jambox.core.base.R> + */ + @PreAuthorize("@aps.hasPermission('system:menu:list')") + @ApiOperation("获取系统菜单树列表") + @GetMapping("/getSysMenuTreeList") + public R> getSysMenuTreeList(MenuListBo bo) { + List list = menuService.getSysMenuTreeList(bo); + return R.ok(list); + } + + /** + * @descriptions 获取目录与菜单树 + * @author DB + * @date 2023/09/07 17:41 + * @return com.jambox.core.base.R> + */ + @ApiOperation("获取目录与菜单树") + @GetMapping("/getDirectoryAndMenuTreeList") + public R> getDirectoryAndMenuTreeList() { + List list = menuService.getDirectoryAndMenuTreeList(); + return R.ok(list); + } + + /** + * @descriptions 新增系统菜单 + * @author DB + * @date 2023/09/07 17:45 + * @param bo 请求参数 + * @return com.jambox.core.base.R + */ + @PreAuthorize("@aps.hasPermission('system:menu:insert')") + @OperationLog(operationLogEnumType = OperationLogEnum.INSERT_OAM_MENU) + @ApiOperation("新增系统菜单") + @PostMapping("/insertSysMenu") + public R insertSysMenu(@RequestBody @Validated MenuBo bo) { + menuService.insertSysMenu(bo); + return R.ok(); + } + + /** + * @Description: 修改系统菜单表 + * @param bo 请求参数 + * @Author: DB + * @Date: 2023/5/10 16:01 + **/ + @PreAuthorize("@aps.hasPermission('system:menu:update')") + @OperationLog(operationLogEnumType = OperationLogEnum.UPDATE_OAM_MENU) + @ApiOperation("修改系统菜单") + @PutMapping("/updateSysMenu") + public R updateSysMenu(@RequestBody @Validated MenuBo bo) { + menuService.updateSysMenu(bo); + return R.ok(); + } + + /** + * @Description: 删除系统菜单表 + * @param id 主键id + * @Author: DB + * @Date: 2023/5/10 16:01 + **/ + @PreAuthorize("@aps.hasPermission('system:menu:remove')") + @OperationLog(operationLogEnumType = OperationLogEnum.REMOVE_OAM_MENU) + @ApiOperation("删除系统菜单") + @DeleteMapping("/removeSysMenu/{id}") + public R removeSysMenu(@PathVariable String id) { + menuService.removeSysMenu(id); + return R.ok(); + } + +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/controller/RoleController.java b/Cpop-System/src/main/java/com/cpop/system/business/controller/RoleController.java new file mode 100644 index 0000000..710fc13 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/controller/RoleController.java @@ -0,0 +1,139 @@ +package com.cpop.system.business.controller; + +import com.cpop.core.annontation.OperationLog; +import com.cpop.core.base.R; +import com.cpop.core.base.enums.OperationLogEnum; +import com.cpop.system.business.bo.MenuListBo; +import com.cpop.system.business.bo.RoleBo; +import com.cpop.system.business.bo.RolePageBo; +import com.cpop.system.business.bo.RoleStatusBo; +import com.cpop.system.business.service.MenuService; +import com.cpop.system.business.vo.MenuVo; +import com.cpop.system.business.vo.RolePageVo; +import com.mybatisflex.core.paginate.Page; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.beans.factory.annotation.Autowired; +import com.cpop.system.business.entity.Role; +import com.cpop.system.business.service.RoleService; +import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import java.io.Serializable; +import java.util.List; + +/** + * 系统角色表 控制层。 + * + * @author DB + * @since 2023-10-19 + */ +@RestController +@Api(tags = "系统角色表接口") +@RequestMapping("/role") +public class RoleController { + + @Autowired + private RoleService roleService; + + @Autowired + private MenuService menuService; + + /** + * @descriptions 查询系统角色分页列表 + * @author DB + * @date 2023/09/10 16:51 + * @param bo 请求参数 + * @return R> + */ + @PreAuthorize("@aps.hasPermission('system:role:list')") + @ApiOperation("查询系统角色分页列表") + @GetMapping("/getSysRolePageList") + public R> getSysRolePageList(RolePageBo bo) { + Page pageVo = roleService.getSysRolePageList(bo); + return R.ok(pageVo); + } + + /** + * @descriptions 新增角色 + * @author DB + * @date 2023/10/12 10:48 + * @param bo 请求参数 + * @return: com.cpop.core.base.R + */ + @PreAuthorize("@aps.hasPermission('system:role:insert')") + @OperationLog(operationLogEnumType = OperationLogEnum.INSERT_OAM_ROLE) + @ApiOperation("新增角色") + @PostMapping("/insertSysRole") + public R insertSysRole(@RequestBody @Validated RoleBo bo) { + roleService.insertSysRole(bo); + return R.ok(); + } + + /** + * @Description: 获取系统菜单树列表 + * @return: R> + * @Author: DB + * @Date: 2023/5/10 14:39 + **/ + @ApiOperation("获取菜单树列表") + @GetMapping("/getSysMenuTreeList") + public R> getSysMenuTreeList() { + List list = menuService.getSysMenuTreeList(new MenuListBo()); + //过滤掉没有权限的数据 + return R.ok(list); + } + + /** + * @descriptions 修改角色 + * @author DB + * @date 2023/09/10 17:45 + * @param bo 请求参数 + * @return com.jambox.core.base.R + */ + @PreAuthorize("@aps.hasPermission('system:role:update')") + @OperationLog(operationLogEnumType = OperationLogEnum.UPDATE_OAM_ROLE) + @ApiOperation("修改角色") + @PutMapping("/updateSysRole") + public R updateSysRole(@RequestBody @Validated RoleBo bo) { + roleService.updateSysRole(bo); + return R.ok(); + } + + /** + * 删除系统角色表 + */ + @PreAuthorize("@aps.hasPermission('system:role:remove')") + @OperationLog(operationLogEnumType = OperationLogEnum.REMOVE_OAM_ROLE) + @ApiOperation("删除系统角色表") + @DeleteMapping("/removeSysRole/{id}") + public R removeSysRole(@PathVariable String id) { + roleService.removeSysRole(id); + return R.ok(); + } + + /** + * @Description: 设置角色状态 + * @param bo 请求参数 + * @return: R + * @Author: DB + * @Date: 2023/5/9 14:13 + **/ + @PreAuthorize("@aps.hasPermission('system:role:update')") + @OperationLog(operationLogEnumType = OperationLogEnum.UPDATE_OAM_ROLE) + @ApiOperation("设置角色状态") + @PutMapping("/setSysRoleStatus") + public R setSysRoleStatus(@RequestBody @Validated RoleStatusBo bo) { + roleService.setSysRoleStatus(bo); + return R.ok(); + } + +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/entity/Menu.java b/Cpop-System/src/main/java/com/cpop/system/business/entity/Menu.java new file mode 100644 index 0000000..69cb3f5 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/entity/Menu.java @@ -0,0 +1,102 @@ +package com.cpop.system.business.entity; + +import com.cpop.core.base.entity.BaseEntity; +import com.cpop.core.base.entity.BaseInsertListener; +import com.cpop.core.base.entity.BaseUpdateListener; +import com.cpop.core.base.enums.UserType; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.Table; +import java.io.Serializable; +import java.time.LocalDateTime; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +/** + * 系统菜单表 实体类。 + * + * @author DB + * @since 2023-10-19 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@Table(value = "cp_sys_menu", onInsert = BaseInsertListener.class, onUpdate = BaseUpdateListener.class, mapperGenerateEnable = false) +public class Menu extends BaseEntity implements Serializable { + + /** + * 菜单ID + */ + @Id + private String id; + + /** + * 父级菜单ID + */ + private String parentMenu; + + /** + * 菜单名称 + */ + private String name; + + /** + * 菜单图标 + */ + private String icon; + + /** + * 菜单路由,父菜单为空 + */ + private String component; + + /** + * 标记菜单的状态 0:禁用 1:正常(根据权限正常显示) + */ + private Boolean status; + + /** + * 菜单类型,0:目录,1:菜单,2:按钮 + */ + private Integer type; + + /** + * 权限 + */ + private String permission; + + /** + * 重定向路径,一级菜单有值 + */ + private String redirect; + + /** + * 排序,值越小越靠前,一级菜单有值 + */ + private Integer orderNo; + + /** + * 路由地址 + */ + private String path; + + /** + * 标题 + */ + private String title; + + /** + * 隐藏菜单 + */ + private Boolean hideMenu; + + /** + * 菜单模块 + */ + private String userType; + +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/entity/Role.java b/Cpop-System/src/main/java/com/cpop/system/business/entity/Role.java new file mode 100644 index 0000000..8412f09 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/entity/Role.java @@ -0,0 +1,68 @@ +package com.cpop.system.business.entity; + +import com.cpop.core.base.entity.BaseEntity; +import com.cpop.core.base.entity.BaseInsertListener; +import com.cpop.core.base.entity.BaseUpdateListener; +import com.cpop.core.base.enums.UserType; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.Table; +import java.io.Serializable; +import java.time.LocalDateTime; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +/** + * 系统角色表 实体类。 + * + * @author DB + * @since 2023-10-19 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@Table(value = "cp_sys_role", onInsert = BaseInsertListener.class, onUpdate = BaseUpdateListener.class, mapperGenerateEnable = false) +public class Role extends BaseEntity implements Serializable { + + /** + * 主键 + */ + @Id + private String id; + + /** + * 角色名称 + */ + private String roleName; + + /** + * 角色值 + */ + private String roleValue; + + /** + * 状态(1启用;0停用) + */ + private Boolean status; + + /** + * 备注 + */ + private String remark; + + /** + * 排序 + */ + private Integer orderNo; + + /** + * 用户类型 + */ + private UserType userType; + + +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/entity/RoleMenu.java b/Cpop-System/src/main/java/com/cpop/system/business/entity/RoleMenu.java new file mode 100644 index 0000000..c1b2b22 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/entity/RoleMenu.java @@ -0,0 +1,40 @@ +package com.cpop.system.business.entity; + +import com.cpop.core.base.entity.BaseEntity; +import com.cpop.core.base.entity.BaseInsertListener; +import com.cpop.core.base.entity.BaseUpdateListener; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.Table; +import java.io.Serializable; +import java.time.LocalDateTime; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +/** + * 系统-角色-菜单表 实体类。 + * + * @author DB + * @since 2023-10-19 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@Table(value = "cp_sys_role_menu", onInsert = BaseInsertListener.class, onUpdate = BaseUpdateListener.class, mapperGenerateEnable = false) +public class RoleMenu extends BaseEntity implements Serializable { + + /** + * 角色id + */ + private String roleId; + + /** + * 菜单id + */ + private String menuId; + +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/mapper/MenuMapper.java b/Cpop-System/src/main/java/com/cpop/system/business/mapper/MenuMapper.java new file mode 100644 index 0000000..1836b0a --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/mapper/MenuMapper.java @@ -0,0 +1,14 @@ +package com.cpop.system.business.mapper; + +import com.mybatisflex.core.BaseMapper; +import com.cpop.system.business.entity.Menu; + +/** + * 系统菜单表 映射层。 + * + * @author DB + * @since 2023-10-19 + */ +public interface MenuMapper extends BaseMapper { + +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/mapper/RoleMapper.java b/Cpop-System/src/main/java/com/cpop/system/business/mapper/RoleMapper.java new file mode 100644 index 0000000..4c6451d --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/mapper/RoleMapper.java @@ -0,0 +1,14 @@ +package com.cpop.system.business.mapper; + +import com.mybatisflex.core.BaseMapper; +import com.cpop.system.business.entity.Role; + +/** + * 系统角色表 映射层。 + * + * @author DB + * @since 2023-10-19 + */ +public interface RoleMapper extends BaseMapper { + +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/mapper/RoleMenuMapper.java b/Cpop-System/src/main/java/com/cpop/system/business/mapper/RoleMenuMapper.java new file mode 100644 index 0000000..5c4a431 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/mapper/RoleMenuMapper.java @@ -0,0 +1,14 @@ +package com.cpop.system.business.mapper; + +import com.mybatisflex.core.BaseMapper; +import com.cpop.system.business.entity.RoleMenu; + +/** + * 系统-角色-菜单表 映射层。 + * + * @author DB + * @since 2023-10-19 + */ +public interface RoleMenuMapper extends BaseMapper { + +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/service/LoginService.java b/Cpop-System/src/main/java/com/cpop/system/business/service/LoginService.java new file mode 100644 index 0000000..8b01978 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/service/LoginService.java @@ -0,0 +1,32 @@ +package com.cpop.system.business.service; + +import com.cpop.system.business.vo.LoginUserInfoVo; +import com.cpop.system.business.vo.MenuRouteVo; + +import java.util.List; + +/** + * 系统登陆 + */ +public interface LoginService { + + /** + * 获取登录用户详情 + * + * @return 系统用户登陆信息 + */ + LoginUserInfoVo getUserInfo(); + + /** + * 获取权限码 + */ + List getPermCode(); + + /** + * @Description: 获取菜单列表 + * @return: List + * @Author: DB + * @Date: 2023/5/11 9:16 + **/ + List getSysMenuList(); +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/service/MenuService.java b/Cpop-System/src/main/java/com/cpop/system/business/service/MenuService.java new file mode 100644 index 0000000..bfefb95 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/service/MenuService.java @@ -0,0 +1,69 @@ +package com.cpop.system.business.service; + +import com.cpop.system.business.bo.MenuBo; +import com.cpop.system.business.bo.MenuListBo; +import com.cpop.system.business.vo.MenuRouteVo; +import com.cpop.system.business.vo.MenuVo; +import com.mybatisflex.core.service.IService; +import com.cpop.system.business.entity.Menu; + +import java.util.List; + +/** + * 系统菜单表 服务层。 + * + * @author DB + * @since 2023-10-19 + */ +public interface MenuService extends IService { + + + /** + * @descriptions 获取菜单路由 + * @author DB + * @date 2023/10/19 16:32 + * @return: java.util.List + */ + List getSysMenuList(); + + /** + * @descriptions 获取系统菜单树列表 + * @author DB + * @date 2023/09/07 15:53 + * @param bo 请求参数 + * @return java.util.List + */ + List getSysMenuTreeList(MenuListBo bo); + + /** + * @descriptions 获取目录与菜单树 + * @author DB + * @date 2023/09/07 17:42 + * @return java.util.List + */ + List getDirectoryAndMenuTreeList(); + + /** + * @descriptions 新增系统菜单 + * @author DB + * @date 2023/09/07 17:50 + * @param bo 请求参数 + */ + void insertSysMenu(MenuBo bo); + + /** + * @Description: 修改系统菜单表 + * @param bo 请求参数 + * @Author: DB + * @Date: 2023/5/10 16:01 + **/ + void updateSysMenu(MenuBo bo); + + /** + * @Description: 删除系统菜单表 + * @param id 主键id + * @Author: DB + * @Date: 2023/5/10 16:01 + **/ + void removeSysMenu(String id); +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/service/RoleMenuService.java b/Cpop-System/src/main/java/com/cpop/system/business/service/RoleMenuService.java new file mode 100644 index 0000000..24257a9 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/service/RoleMenuService.java @@ -0,0 +1,14 @@ +package com.cpop.system.business.service; + +import com.mybatisflex.core.service.IService; +import com.cpop.system.business.entity.RoleMenu; + +/** + * 系统-角色-菜单表 服务层。 + * + * @author DB + * @since 2023-10-19 + */ +public interface RoleMenuService extends IService { + +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/service/RoleService.java b/Cpop-System/src/main/java/com/cpop/system/business/service/RoleService.java new file mode 100644 index 0000000..591ecd4 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/service/RoleService.java @@ -0,0 +1,63 @@ +package com.cpop.system.business.service; + +import com.cpop.system.business.bo.RoleBo; +import com.cpop.system.business.bo.RolePageBo; +import com.cpop.system.business.bo.RoleStatusBo; +import com.cpop.system.business.vo.RolePageVo; +import com.mybatisflex.core.paginate.Page; +import com.mybatisflex.core.service.IService; +import com.cpop.system.business.entity.Role; + +/** + * 系统角色表 服务层。 + * + * @author DB + * @since 2023-10-19 + */ +public interface RoleService extends IService { + + /** + * @descriptions + * @author DB + * @date 2023/10/19 17:13 + * @param bo 请求参数 + * @return: com.mybatisflex.core.paginate.Page + */ + Page getSysRolePageList(RolePageBo bo); + + /** + * @descriptions + * @author DB + * @date 2023/10/19 17:13 + * @param bo 请求参数 + * @return: void + */ + void insertSysRole(RoleBo bo); + + /** + * @descriptions + * @author DB + * @date 2023/10/19 17:14 + * @param bo 请求参数 + * @return: void + */ + void updateSysRole(RoleBo bo); + + /** + * @descriptions + * @author DB + * @date 2023/10/19 17:14 + * @param id 主键 + * @return: void + */ + void removeSysRole(String id); + + /** + * @descriptions + * @author DB + * @date 2023/10/19 17:14 + * @param bo 请求参数 + * @return: void + */ + void setSysRoleStatus(RoleStatusBo bo); +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/service/impl/LoginServiceImpl.java b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/LoginServiceImpl.java new file mode 100644 index 0000000..9fd4e03 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/LoginServiceImpl.java @@ -0,0 +1,90 @@ +package com.cpop.system.business.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.cpop.common.constant.Constants; +import com.cpop.core.base.entity.LoginUser; +import com.cpop.core.service.RedisService; +import com.cpop.core.utils.SecurityUtils; +import com.cpop.system.business.entity.Menu; +import com.cpop.system.business.service.LoginService; +import com.cpop.system.business.service.MenuService; +import com.cpop.system.business.vo.LoginUserInfoVo; +import com.cpop.system.business.vo.MenuRouteVo; +import com.mybatisflex.core.query.QueryWrapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static com.cpop.system.business.entity.table.MenuTableDef.MENU; +import static com.cpop.system.business.entity.table.RoleMenuTableDef.ROLE_MENU; +import static com.cpop.system.business.entity.table.RoleTableDef.ROLE; + +/** + * @author DB + * @createTime 2023/09/10 11:19 + * @description + */ +@Service("oamLoginService") +public class LoginServiceImpl implements LoginService { + + @Autowired + private MenuService menuService; + + /** + * @author LOST.yuan + * @Description 获取用户信息 + * @date 23:01 2022/9/26 + * @return {@link String} + **/ + @Override + public LoginUserInfoVo getUserInfo() { + //获取当前登录用户信息 + LoginUser loginUser = SecurityUtils.getInstance().getLoginUser(); + //获取申请员工信息 + JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginStaffInfo(); + return new LoginUserInfoVo() + .setUserId(loginUser.getUserId()) + .setUsername(loginUser.getUsername()) + .setRealName(loginStaffInfo.getString("name")) + .setAvatar(loginStaffInfo.getString("avatar")) + .setPermissions(loginUser.getPermissions()) + .setRoles(Collections.singleton("Cpop")) + //TODO:不同用户根页面不一样,可能后面调整 + .setHomePath(""); + } + + /** + * @author LOST.yuan + * @Description 获取权限码 + * @date 17:30 2022/10/19 + * @return {@link List} + **/ + @Override + public List getPermCode() { + //获取当前用户所属角色以及菜单信息 + LoginUser loginUser = SecurityUtils.getInstance().getLoginUser(); + JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginStaffInfo(); + if (Constants.SUPER_ADMIN.equals(loginUser.getUsername())){ + return new ArrayList(Collections.singleton(Constants.ALL_PERMISSION)); + } + List list = menuService.list(QueryWrapper.create() + .leftJoin(ROLE_MENU).on(ROLE_MENU.MENU_ID.eq(MENU.ID)) + .leftJoin(ROLE).on(ROLE.ID.eq(ROLE_MENU.ROLE_ID)) + .where(MENU.TYPE.in(1, 2)) + .and(MENU.PERMISSION.ne("")) + .and(ROLE.ID.eq(loginStaffInfo.getString("roleId")))); + return list.stream().map(Menu::getPermission).collect(Collectors.toList()); + } + + /** + * 获取菜单列表 + */ + @Override + public List getSysMenuList() { + return menuService.getSysMenuList(); + } +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/service/impl/MenuServiceImpl.java b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/MenuServiceImpl.java new file mode 100644 index 0000000..26c7801 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/MenuServiceImpl.java @@ -0,0 +1,266 @@ +package com.cpop.system.business.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.cpop.common.constant.Constants; +import com.cpop.common.utils.StringUtils; +import com.cpop.common.utils.bean.BeanUtils; +import com.cpop.core.base.entity.LoginUser; +import com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo; +import com.cpop.core.utils.SecurityUtils; +import com.cpop.core.utils.SpringUtils; +import com.cpop.system.business.bo.MenuBo; +import com.cpop.system.business.bo.MenuListBo; +import com.cpop.system.business.vo.MenuRouteVo; +import com.cpop.system.business.vo.MenuVo; +import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.spring.service.impl.ServiceImpl; +import com.cpop.system.business.entity.Menu; +import com.cpop.system.business.mapper.MenuMapper; +import com.cpop.system.business.service.MenuService; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static com.cpop.system.business.entity.table.MenuTableDef.MENU; +import static com.cpop.system.business.entity.table.RoleMenuTableDef.ROLE_MENU; +import static com.cpop.system.business.entity.table.RoleTableDef.ROLE; + +/** + * 系统菜单表 服务层实现。 + * + * @author DB + * @since 2023-10-19 + */ +@Service("menuService") +public class MenuServiceImpl extends ServiceImpl implements MenuService { + + /** + * @descriptions 获取系统菜单树列表 + * @author DB + * @date 2023/10/19 14:39 + * @return: java.util.List + */ + @Override + public List getSysMenuList() { + //获取用户信息 + LoginUser user = SecurityUtils.getInstance().getLoginUser(); + //获取申请员工信息 + JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginStaffInfo(); + //超级管理员 + if (Constants.SUPER_ADMIN.equals(user.getUsername())) { + //获取菜单 + List list = this.listAs(QueryWrapper.create() + .where(MENU.TYPE.in(0, 1)) + //构建公共菜单与特有菜单 + .and(MENU.USER_TYPE.in("COMMON", user.getUserType())) + .orderBy(MENU.ORDER_NO.asc()), + MenuRouteVo.class); + return buildMenuRouteTree(list); + } else { + return buildMenuRouteTree(this.listAs(QueryWrapper.create() + .select(MENU.ALL_COLUMNS) + .leftJoin(ROLE_MENU).on(ROLE_MENU.MENU_ID.eq(MENU.ID)) + .leftJoin(ROLE).on(ROLE.ID.eq(ROLE_MENU.ROLE_ID)) + .where(MENU.STATUS.eq(1)) + .and(MENU.TYPE.in(0, 1)) + .and(MENU.NAME.ne(Constants.HIDE_MENU)) + .and(ROLE_MENU.ROLE_ID.eq(loginStaffInfo.getString("roleId"))) + //构建公共菜单与特有菜单 + .and(MENU.USER_TYPE.in("COMMON", user.getUserType())) + .orderBy(MENU.ORDER_NO.asc()), + MenuRouteVo.class)); + } + } + + @Override + public List getSysMenuTreeList(MenuListBo bo) { + //获取用户信息 + LoginUser user = SecurityUtils.getInstance().getLoginUser(); + return buildMenuTree(this.listAs(QueryWrapper.create() + //状态不为空 + .and(MENU.STATUS.eq(bo.getStatus())) + //标题不为空 + .and(MENU.TITLE.like(bo.getTitle())) + //构建公共菜单与特有菜单 + .and(MENU.USER_TYPE.in("COMMON", user.getUserType())) + .orderBy(MENU.ORDER_NO.asc()), MenuVo.class)); + } + + @Override + public List getDirectoryAndMenuTreeList() { + //只读取启用的菜单 + return buildMenuTree(this.listAs(QueryWrapper.create() + .where(MENU.TYPE.in(0, 1)) + .orderBy(MENU.ORDER_NO.asc()) + , MenuVo.class)); + } + + /** + * @descriptions 构建菜单树 + * @author DB + * @date 2023/09/07 16:36 + * @param menus 菜单集合 + * @return java.util.List + */ + private List buildMenuTree(List menus) { + List returnList = new ArrayList(); + if (menus.isEmpty()) { + return menus; + } + //构建根节点 + List tempList = menus.stream() + .filter(s -> StringUtils.isBlank(s.getParentMenu())).collect(Collectors.toList()); + for (MenuVo menu : tempList) { + MenuVo menuVo = recursionFn(menus, menu); + returnList.add(menuVo); + } + return returnList; + } + + /** + * @descriptions 递归列表 + * @author DB + * @date 2023/09/07 16:36 + * @param list 递归集合 + * @param menu 菜单 + * @return com.jambox.OAMtem.business.vo.OAMMenuVo + */ + private MenuVo recursionFn(List list, MenuVo menu) { + // 得到子节点列表 + List childList = new ArrayList(); + for (MenuVo menuNode : list) { + if (null != menuNode.getParentMenu() && menuNode.getParentMenu().equals(menu.getId())) { + childList.add(recursionFn(list, menuNode)); + } + } + if (!childList.isEmpty()){ + menu.setChildren(childList); + } + return menu; + } + + @Override + public void insertSysMenu(MenuBo bo) { + Menu entity = new Menu(); + BeanUtils.copyBeanProp(entity, bo); + //设置菜单名 + if (StringUtils.isNotBlank(bo.getPath())){ + String[] split = bo.getPath().split("/"); + String name = StringUtils.getMethodName(split[split.length - 1].replace("/", "")); + entity.setName(name); + } + //设置组件 + if (StringUtils.isBlank(bo.getComponent())){ + entity.setComponent("LAYOUT"); + } + //获取当前用户 + entity.setUserType(SecurityUtils.getInstance().getLoginUser().getUserType().toString()); + this.save(entity); + } + + @Override + public void updateSysMenu(MenuBo bo) { + Menu entity = new Menu(); + BeanUtils.copyBeanProp(entity, bo); + //设置菜单名 + if (StringUtils.isNotBlank(bo.getPath())){ + String[] split = bo.getPath().split("/"); + String toUpperCaseString = split[split.length - 1]; + if (toUpperCaseString.contains(":")) { + toUpperCaseString = split[split.length - 2]; + } + String name = StringUtils.getMethodName(toUpperCaseString.replace("/", "")); + entity.setName(name); + } + //设置组件 + if (StringUtils.isBlank(bo.getComponent())){ + entity.setComponent("LAYOUT"); + } + this.updateById(entity); + } + + @Override + public void removeSysMenu(String id) { + //查询所有 + List list = this.list(); + //递归获取当前菜单及其下属子菜单 + List removeIds = new ArrayList<>(); + recursionRemove(list, id, removeIds); + removeIds.add(id); + this.removeByIds(removeIds); + } + + /** + * @Description: 递归要删除的菜单集合 + * @param list 菜单集合 + * @param id id + * @param removeIds 删除id集合 + * @Author: DB + * @Date: 2023/5/10 15:27 + **/ + private void recursionRemove(List list, String id, List removeIds) { + //过滤出删除根菜单 + List sonMenu = list.stream().filter(s -> null != s.getParentMenu()&& s.getParentMenu().equals(id)).collect(Collectors.toList()); + if (!sonMenu.isEmpty()) { + sonMenu.forEach(item -> { + recursionRemove(list, item.getId(), removeIds); + removeIds.add(item.getId()); + }); + } + } + + /** + * @Description: 构建菜单路由树 + * @param menus 菜单集合 + * @return: List + * @Author: DB + * @Date: 2023/5/11 9:21 + **/ + private List buildMenuRouteTree(List menus) { + if (menus.isEmpty()){ + return menus; + } + //构建内部类 + menus.forEach(item->{ + MenuRouteVo.Meta meta = item.new Meta(); + meta.setIcon(item.getIcon()); + meta.setOrderNo(item.getOrderNo()); + meta.setTitle(item.getTitle()); + meta.setHideMenu(item.getHideMenu()); + item.setMeta(meta); + }); + //构建根节点 + List tempList = menus.stream() + .filter(s -> StringUtils.isBlank(s.getParentMenu())).collect(Collectors.toList()); + List menuRoutes = new ArrayList<>(); + for (MenuRouteVo menu : tempList) { + MenuRouteVo menuVo = recursionMenuRoute(menus, menu); + //设置是否需要隐藏子内部菜单 + menuVo.getMeta().setHideChildrenInMenu(null != menuVo.getChildren() && menuVo.getChildren().size() == 1 && menuVo.getChildren().get(0).getHideMenu()); + menuRoutes.add(menuVo); + } + return BeanUtils.mapToList(menuRoutes, MenuRouteVo.class); + } + + /** + * @Description: 递归列表 + * @param list 菜单集合 + * @param menu 菜单 + * @return: MenuRouteVo + * @Author: DB + * @Date: 2023/5/11 9:22 + **/ + private MenuRouteVo recursionMenuRoute(List list, MenuRouteVo menu) { + // 得到子节点列表 + List childList = new ArrayList(); + for (MenuRouteVo menuNode : list) { + if (StringUtils.isNotBlank(menuNode.getParentMenu()) && menuNode.getParentMenu().equals(menu.getId())) { + childList.add(recursionMenuRoute(list, menuNode)); + } + } + menu.setChildren(childList); + return menu; + } +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/service/impl/RoleMenuServiceImpl.java b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/RoleMenuServiceImpl.java new file mode 100644 index 0000000..bc64115 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/RoleMenuServiceImpl.java @@ -0,0 +1,18 @@ +package com.cpop.system.business.service.impl; + +import com.mybatisflex.spring.service.impl.ServiceImpl; +import com.cpop.system.business.entity.RoleMenu; +import com.cpop.system.business.mapper.RoleMenuMapper; +import com.cpop.system.business.service.RoleMenuService; +import org.springframework.stereotype.Service; + +/** + * 系统-角色-菜单表 服务层实现。 + * + * @author DB + * @since 2023-10-19 + */ +@Service("roleMenuService") +public class RoleMenuServiceImpl extends ServiceImpl implements RoleMenuService { + +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/service/impl/RoleServiceImpl.java b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/RoleServiceImpl.java new file mode 100644 index 0000000..941b888 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/RoleServiceImpl.java @@ -0,0 +1,157 @@ +package com.cpop.system.business.service.impl; + +import com.cpop.common.constant.Constants; +import com.cpop.common.utils.StringUtils; +import com.cpop.common.utils.bean.BeanUtils; +import com.cpop.core.base.entity.LoginUser; +import com.cpop.core.base.entity.PageDomain; +import com.cpop.core.utils.SecurityUtils; +import com.cpop.core.utils.SpringUtils; +import com.cpop.core.utils.sql.SqlUtils; +import com.cpop.system.business.bo.RoleBo; +import com.cpop.system.business.bo.RolePageBo; +import com.cpop.system.business.bo.RoleStatusBo; +import com.cpop.system.business.entity.RoleMenu; +import com.cpop.system.business.service.RoleMenuService; +import com.cpop.system.business.vo.RolePageVo; +import com.mybatisflex.core.paginate.Page; +import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.spring.service.impl.ServiceImpl; +import com.cpop.system.business.entity.Role; +import com.cpop.system.business.mapper.RoleMapper; +import com.cpop.system.business.service.RoleService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static com.cpop.system.business.entity.table.RoleMenuTableDef.ROLE_MENU; +import static com.cpop.system.business.entity.table.RoleTableDef.ROLE; + +/** + * 系统角色表 服务层实现。 + * + * @author DB + * @since 2023-10-19 + */ +@Service("roleService") +public class RoleServiceImpl extends ServiceImpl implements RoleService { + + /** + * @descriptions + * @author DB + * @date 2023/10/19 17:13 + * @param bo 请求参数 + * @return: com.mybatisflex.core.paginate.Page + */ + @Override + public Page getSysRolePageList(RolePageBo bo) { + //获取当前用户 + LoginUser loginUser = SecurityUtils.getInstance().getLoginUser(); + PageDomain pageDomain = SqlUtils.getInstance().getPageDomain(); + Page page = this.mapper.paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), + QueryWrapper.create() + .select(ROLE.ALL_COLUMNS) + .where(ROLE.ROLE_VALUE.ne(Constants.SUPER_ADMIN_VALUE)) + .and(ROLE.ROLE_NAME.like(bo.getRoleName())) + .and(ROLE.STATUS.eq(bo.getStatus())) + .and(ROLE.USER_TYPE.eq(loginUser.getUserType())) + .orderBy(ROLE.ORDER_NO.asc()) + , RolePageVo.class); + if (!page.getRecords().isEmpty()) { + //根据角色查询中间表 + List roleMenuList = SpringUtils.getBean(RoleMenuService.class).list(QueryWrapper.create() + .where(ROLE_MENU.ROLE_ID.in(page.getRecords().stream().map(RolePageVo::getId).collect(Collectors.toSet())))); + page.getRecords().forEach(item -> { + List filterMenuIds = roleMenuList.stream() + .filter(s -> StringUtils.equals(s.getRoleId(), item.getId())) + .map(RoleMenu::getMenuId).collect(Collectors.toList()); + item.setMenuIds(filterMenuIds); + }); + } + return page; + } + + /** + * @descriptions + * @author DB + * @date 2023/10/19 17:13 + * @param bo 请求参数 + * @return: void + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void insertSysRole(RoleBo bo) { + Role role = BeanUtils.mapToClass(bo, Role.class); + this.save(role); + //将菜单信息录入中间表 + if (!bo.getMenuIds().isEmpty()) { + List roleMenus = new ArrayList<>(); + bo.getMenuIds().forEach(item -> { + RoleMenu roleMenu = new RoleMenu(); + roleMenu.setMenuId(item); + roleMenu.setRoleId(role.getId()); + roleMenus.add(roleMenu); + }); + SpringUtils.getBean(RoleMenuService.class).saveBatch(roleMenus); + } + } + + /** + * @descriptions + * @author DB + * @date 2023/10/19 17:14 + * @param bo 请求参数 + * @return: void + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void updateSysRole(RoleBo bo) { + Role entity = new Role(); + BeanUtils.copyBeanProp(entity, bo); + this.updateById(entity); + //将菜单信息录入中间表 + if (!bo.getMenuIds().isEmpty()) { + //先删后存 + RoleMenuService sysRoleMenuService = SpringUtils.getBean(RoleMenuService.class); + sysRoleMenuService.remove(QueryWrapper.create() + .where(ROLE_MENU.ROLE_ID.eq(entity.getId()))); + List roleMenus = new ArrayList<>(); + bo.getMenuIds().forEach(item -> { + RoleMenu roleMenu = new RoleMenu(); + roleMenu.setMenuId(item); + roleMenu.setRoleId(entity.getId()); + roleMenus.add(roleMenu); + }); + sysRoleMenuService.saveBatch(roleMenus); + } + } + + /** + * @descriptions + * @author DB + * @date 2023/10/19 17:14 + * @param id 主键 + * @return: void + */ + @Override + public void removeSysRole(String id) { + this.removeById(id); + //删除相关联菜单 + SpringUtils.getBean(RoleMenuService.class).remove(QueryWrapper.create().where(ROLE_MENU.ROLE_ID.eq(id))); + } + + /** + * @descriptions + * @author DB + * @date 2023/10/19 17:14 + * @param bo 请求参数 + * @return: void + */ + @Override + public void setSysRoleStatus(RoleStatusBo bo) { + this.updateById(BeanUtils.mapToClass(bo, Role.class)); + } +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/vo/LoginUserInfoVo.java b/Cpop-System/src/main/java/com/cpop/system/business/vo/LoginUserInfoVo.java new file mode 100644 index 0000000..16d4a34 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/vo/LoginUserInfoVo.java @@ -0,0 +1,70 @@ +package com.cpop.system.business.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Set; + +/** + * 登录用户的基本信息 + * 用于记录到token的信息使用 + * @author Gewj + * + */ +@Data +@Accessors(chain = true) +@ApiModel +public class LoginUserInfoVo { + + /** + * 用户id + */ + @ApiModelProperty("用户id") + private String userId; + + /** + * 头像 + */ + @ApiModelProperty("头像") + private String avatar; + + /** + * 登录用户名 + */ + @ApiModelProperty("登录用户名") + private String username; + + /** + * 真实姓名 + */ + @ApiModelProperty("真实姓名") + private String realName; + + /** + * 介绍 + */ + @ApiModelProperty("介绍") + private String desc; + + /** + * 用户首页路由 + */ + @ApiModelProperty("用户首页路由") + private String homePath; + + /** + * 权限信息 + */ + @ApiModelProperty("权限信息") + private Set permissions; + + /** + * 角色 + */ + @ApiModelProperty("角色") + private Set roles; + +} + diff --git a/Cpop-System/src/main/java/com/cpop/system/business/vo/MenuRouteVo.java b/Cpop-System/src/main/java/com/cpop/system/business/vo/MenuRouteVo.java new file mode 100644 index 0000000..00dd51c --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/vo/MenuRouteVo.java @@ -0,0 +1,145 @@ +package com.cpop.system.business.vo; + +import com.mybatisflex.annotation.Column; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.List; + +/** + * Description: + * date: 2023/5/11 9:14 + * + * @author DB + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "Menu对象", description = "") +public class MenuRouteVo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 菜单ID + */ + @ApiModelProperty("菜单ID") + private String id; + + /** + * 父级菜单ID + */ + @ApiModelProperty("父级菜单ID") + private String parentMenu; + + /** + * 菜单名 + */ + @ApiModelProperty("菜单名") + private String name; + + /** + * 菜单图标 + */ + @ApiModelProperty("菜单图标") + private String icon; + + /** + * 菜单路由,父菜单为空 + */ + @ApiModelProperty("菜单路由,父菜单为空") + private String component; + + /** + * 标记菜单的状态 0:禁用 1:正常(根据权限正常显示) + */ + @ApiModelProperty("标记菜单的状态 0:禁用 1:正常(根据权限正常显示)") + private Boolean status; + + /** + * 用户类型,1管理员,2审计管理员,3安全管理员,4普通用户 + */ + @ApiModelProperty("用户类型,1管理员,2审计管理员,3安全管理员,4普通用户") + private String type; + + /** + * 权限 + */ + @ApiModelProperty("权限") + private String permission; + + /** + * 重定向路径,一级菜单有值 + */ + @ApiModelProperty("重定向路径,一级菜单有值") + private String redirect; + + /** + * 排序,值越小越靠前,一级菜单有值 + */ + @ApiModelProperty("排序,值越小越靠前,一级菜单有值") + private Integer orderNo; + + /** + * 子菜单集 + */ + @Column(ignore = true) + @ApiModelProperty("子菜单集") + private List children; + + /** + * 路由地址 + */ + @ApiModelProperty("路由地址") + private String path; + + /** + * 标题 + */ + @ApiModelProperty("标题") + private String title; + + /** + * 隐藏菜单 + */ + @ApiModelProperty("隐藏菜单") + private Boolean hideMenu; + + /** + * 内部定义类 + */ + @Column(ignore = true) + @ApiModelProperty("内部定义类") + private Meta meta; + + /** + * 内部类 + */ + @Data + public class Meta { + + /** + * 标题 + */ + private String title; + /** + * 图标 + */ + private String icon; + /** + * 排序 + */ + private Integer orderNo; + /** + * 隐藏菜单 + */ + private Boolean hideMenu; + + /** + * 隐藏子类菜单 + */ + private Boolean hideChildrenInMenu; + } +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/vo/MenuVo.java b/Cpop-System/src/main/java/com/cpop/system/business/vo/MenuVo.java new file mode 100644 index 0000000..3faa660 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/vo/MenuVo.java @@ -0,0 +1,117 @@ +package com.cpop.system.business.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.List; + +/** + * 系统菜单表Vo输出 + * + * @author DB.lost + * @since 2023-05-10 + */ +@Data +@Accessors(chain = true) +@ApiModel(description = "菜单返回对象") +public class MenuVo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 菜单ID + */ + @ApiModelProperty(value = "菜单ID") + private String id; + + /** + * 父级菜单ID + */ + @ApiModelProperty(value = "父级菜单ID") + private String parentMenu; + + /** + * 菜单名称 + */ + @ApiModelProperty(value = "菜单名称") + private String name; + + /** + * 菜单图标 + */ + @ApiModelProperty(value = "菜单图标") + private String icon; + + /** + * 菜单路由,父菜单为空 + */ + @ApiModelProperty(value = "菜单路由,父菜单为空") + private String component; + + /** + * 标记菜单的状态 0:禁用 1:启用(根据权限正常显示) + */ + @ApiModelProperty(value = "标记菜单的状态 0:禁用 1:启用(根据权限正常显示)") + private Boolean status; + + /** + * 权限 + */ + @ApiModelProperty(value = "权限") + private String permission; + + /** + * 重定向路径,一级菜单有值 + */ + @ApiModelProperty(value = "重定向路径,一级菜单有值") + private String redirect; + + /** + * 排序,值越小越靠前,一级菜单有值 + */ + @ApiModelProperty(value = "排序,值越小越靠前,一级菜单有值") + private Integer orderNo; + + /** + * 路由地址 + */ + @ApiModelProperty(value = "路由地址") + private String path; + + /** + * 标题 + */ + @ApiModelProperty(value = "标题") + private String title; + + /** + * 子菜单集 + */ + @ApiModelProperty(value = "子菜单集") + private List children; + + /** + * 更新时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8") + @ApiModelProperty(value = "更新时间") + private LocalDateTime updateTime; + + /** + * 菜单类型,0:目录,1:菜单,2:按钮 + */ + @ApiModelProperty(value = "菜单类型,0:目录,1:菜单,2:按钮") + private Integer type; + + /** + * 隐藏菜单 + */ + @ApiModelProperty(value = "隐藏菜单") + private Boolean hideMenu; + +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/vo/RolePageVo.java b/Cpop-System/src/main/java/com/cpop/system/business/vo/RolePageVo.java new file mode 100644 index 0000000..5325933 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/vo/RolePageVo.java @@ -0,0 +1,76 @@ +package com.cpop.system.business.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.mybatisflex.annotation.Column; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.List; + +/** + * Description: + * date: 2023/5/9 14:21 + * + * @Author DB + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "Role分页返回对象") +public class RolePageVo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @ApiModelProperty("主键") + private String id; + + /** + * 角色名称 + */ + @ApiModelProperty("角色名称") + private String roleName; + + /** + * 角色值 + */ + @ApiModelProperty("角色值") + private String roleValue; + + /** + * 状态 + */ + @ApiModelProperty("状态") + private Boolean status; + + /** + * 备注 + */ + @ApiModelProperty("备注") + private String remark; + + /** + * 排序 + */ + @ApiModelProperty("排序") + private Integer orderNo; + + /** + * 更新时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8") + @ApiModelProperty("更新时间") + private Timestamp updateTime; + + /** + * 角色所属菜单id集合 + */ + @ApiModelProperty("角色所属菜单id集合") + @Column(ignore = true) + private List menuIds; +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/vo/RoleVo.java b/Cpop-System/src/main/java/com/cpop/system/business/vo/RoleVo.java new file mode 100644 index 0000000..0d9690e --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/vo/RoleVo.java @@ -0,0 +1,59 @@ +package com.cpop.system.business.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * 系统角色表Vo输出 + * + * @author DB.lost + * @since 2023-05-10 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "SysRole对象", description = "角色信息") +public class RoleVo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @ApiModelProperty("主键") + private String id; + + /** + * 角色名称 + */ + @ApiModelProperty("角色名称") + private String roleName; + + /** + * 角色值 + */ + @ApiModelProperty("角色值") + private String roleValue; + + /** + * 状态 0:禁用 1:正常 + */ + @ApiModelProperty("状态 0:禁用 1:正常") + private Boolean status; + + /** + * 备注 + */ + @ApiModelProperty("备注") + private String remark; + + /** + * 排序 + */ + @ApiModelProperty("排序") + private Integer orderNo; + +} diff --git a/Cpop-System/src/main/resources/application-system.yml b/Cpop-System/src/main/resources/application-system.yml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Cpop-System/src/main/resources/application-system.yml @@ -0,0 +1 @@ + diff --git a/Cpop-System/src/main/resources/mapper/MenuMapper.xml b/Cpop-System/src/main/resources/mapper/MenuMapper.xml new file mode 100644 index 0000000..d952451 --- /dev/null +++ b/Cpop-System/src/main/resources/mapper/MenuMapper.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/Cpop-System/src/main/resources/mapper/RoleMapper.xml b/Cpop-System/src/main/resources/mapper/RoleMapper.xml new file mode 100644 index 0000000..f11a3d1 --- /dev/null +++ b/Cpop-System/src/main/resources/mapper/RoleMapper.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/Cpop-System/src/main/resources/mapper/RoleMenuMapper.xml b/Cpop-System/src/main/resources/mapper/RoleMenuMapper.xml new file mode 100644 index 0000000..5704ac0 --- /dev/null +++ b/Cpop-System/src/main/resources/mapper/RoleMenuMapper.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/pom.xml b/pom.xml index 39cd6d2..5cee2f9 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,7 @@ Cpop-Jambox/Cpop-Jambox-Web Cpop-Mall Cpop-Mall/Cpop-Mall-Web + Cpop-System @@ -117,6 +118,11 @@ Cpop-Mall ${cpop.version} + + com.cpop + Cpop-System + ${cpop.version} + com.zaxxer