From 1047eb13d0f722dc54ab9d70aecae1a834d7c24a Mon Sep 17 00:00:00 2001 From: mengqiang <> Date: Wed, 3 Feb 2021 23:26:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 + sso-auth-center-service/.gitignore | 52 + sso-auth-center-service/README.md | 3 + sso-auth-center-service/pom.xml | 220 +++ .../sso-auth-center-admin/pom.xml | 84 + .../com/sso/AuthCenterAdminApplication.java | 25 + .../java/com/sso/aspect/LogPrintlnAspect.java | 89 + .../controller/admin/CaptchaController.java | 35 + .../sso/controller/admin/DeptController.java | 106 + .../sso/controller/admin/LoginController.java | 57 + .../controller/admin/LoginLogController.java | 42 + .../sso/controller/admin/MenuController.java | 105 + .../sso/controller/admin/RoleController.java | 118 ++ .../controller/admin/SystemController.java | 143 ++ .../admin/SystemMgmtController.java | 84 + .../sso/controller/admin/UserController.java | 196 ++ .../admin/UserOnlineController.java | 75 + .../admin/UserProfileController.java | 83 + .../controller/getway/OpenApiController.java | 65 + .../java/com/sso/security/SecurityConfig.java | 147 ++ .../filter/TokenAuthenticationFilter.java | 47 + .../handle/AuthenticationEntryPointImpl.java | 38 + .../handle/LogoutSuccessHandlerImpl.java | 45 + .../src/main/resources/application.properties | 2 + .../src/main/resources/banner.txt | 23 + .../config/application-dev.properties | 104 + .../src/main/resources/logback-spring.xml | 55 + sso-auth-center-service/sso-business/pom.xml | 34 + .../java/com/sso/dao/dto/RoleCountDTO.java | 24 + .../com/sso/dao/dto/SsoOnlineUserDTO.java | 109 + .../java/com/sso/dao/dto/SsoUserDeptDTO.java | 36 + .../java/com/sso/dao/dto/SsoUserMgmtDTO.java | 91 + .../java/com/sso/dao/dto/SsoUserRoleDTO.java | 36 + .../main/java/com/sso/dao/entity/SsoDept.java | 84 + .../com/sso/dao/entity/SsoDeptTreePath.java | 34 + .../java/com/sso/dao/entity/SsoLoginLog.java | 84 + .../main/java/com/sso/dao/entity/SsoMenu.java | 119 ++ .../com/sso/dao/entity/SsoOnlineUser.java | 87 + .../main/java/com/sso/dao/entity/SsoRole.java | 84 + .../java/com/sso/dao/entity/SsoRoleMenu.java | 50 + .../java/com/sso/dao/entity/SsoSystem.java | 110 ++ .../com/sso/dao/entity/SsoSystemManager.java | 69 + .../main/java/com/sso/dao/entity/SsoUser.java | 113 ++ .../java/com/sso/dao/entity/SsoUserDept.java | 49 + .../java/com/sso/dao/entity/SsoUserRole.java | 49 + .../com/sso/dao/entity/SsoUserSystem.java | 69 + .../com/sso/dao/mapper/SsoDeptMapper.java | 113 ++ .../sso/dao/mapper/SsoDeptTreePathMapper.java | 61 + .../com/sso/dao/mapper/SsoLoginLogMapper.java | 91 + .../com/sso/dao/mapper/SsoMenuMapper.java | 112 ++ .../sso/dao/mapper/SsoOnlineUserMapper.java | 111 ++ .../com/sso/dao/mapper/SsoRoleMapper.java | 112 ++ .../com/sso/dao/mapper/SsoRoleMenuMapper.java | 86 + .../dao/mapper/SsoSystemManagerMapper.java | 100 + .../com/sso/dao/mapper/SsoSystemMapper.java | 128 ++ .../com/sso/dao/mapper/SsoUserDeptMapper.java | 85 + .../com/sso/dao/mapper/SsoUserMapper.java | 159 ++ .../com/sso/dao/mapper/SsoUserRoleMapper.java | 121 ++ .../sso/dao/mapper/SsoUserSystemMapper.java | 95 + .../java/com/sso/dao/query/LoginLogQuery.java | 89 + .../java/com/sso/dao/query/SsoDeptQuery.java | 117 ++ .../java/com/sso/dao/query/SsoMenuQuery.java | 117 ++ .../java/com/sso/dao/query/SsoRoleQuery.java | 127 ++ .../sso/dao/query/SystemMgmtPageQuery.java | 129 ++ .../com/sso/dao/query/UserOnlineQuery.java | 87 + .../java/com/sso/dao/query/UserPageQuery.java | 129 ++ .../main/java/com/sso/model/bo/SysCodeBO.java | 30 + .../com/sso/model/bo/dept/DeptDeleteBO.java | 29 + .../com/sso/model/bo/dept/DeptIdQueryBO.java | 24 + .../com/sso/model/bo/dept/DeptMgmtTreeBO.java | 34 + .../com/sso/model/bo/dept/DeptSaveBO.java | 63 + .../com/sso/model/bo/dept/DeptUpdateBO.java | 67 + .../com/sso/model/bo/getway/ApplyAuthBO.java | 45 + .../com/sso/model/bo/getway/GetWayReqBO.java | 49 + .../java/com/sso/model/bo/login/LoginBO.java | 42 + .../model/bo/login/LoginLogListPageBO.java | 41 + .../com/sso/model/bo/menu/MenuDeleteBO.java | 30 + .../com/sso/model/bo/menu/MenuSaveBO.java | 102 + .../com/sso/model/bo/menu/MenuTreeBO.java | 33 + .../com/sso/model/bo/menu/MenuUpdateBO.java | 30 + .../sso/model/bo/platform/SystemDeleteBO.java | 26 + .../bo/platform/SystemMgmtListPageBO.java | 54 + .../model/bo/platform/SystemMgmtRemoveBO.java | 35 + .../model/bo/platform/SystemMgmtSaveBO.java | 41 + .../model/bo/platform/SystemMgmtStatusBO.java | 33 + .../sso/model/bo/platform/SystemSaveBO.java | 62 + .../sso/model/bo/platform/SystemSortBO.java | 26 + .../sso/model/bo/platform/SystemUpdateBO.java | 33 + .../bo/platform/SystemUpdateSecretBO.java | 40 + .../com/sso/model/bo/role/RoleDeleteBO.java | 28 + .../sso/model/bo/role/RoleListOptionBO.java | 30 + .../com/sso/model/bo/role/RoleListPageBO.java | 40 + .../sso/model/bo/role/RoleRemoveUserBO.java | 34 + .../com/sso/model/bo/role/RoleSaveBO.java | 64 + .../com/sso/model/bo/role/RoleUpdateBO.java | 28 + .../java/com/sso/model/bo/user/UserAddBO.java | 90 + .../sso/model/bo/user/UserBatchDeleteBO.java | 32 + .../com/sso/model/bo/user/UserDeleteBO.java | 32 + .../com/sso/model/bo/user/UserDetailBO.java | 31 + .../com/sso/model/bo/user/UserListPageBO.java | 60 + .../model/bo/user/UserOnlineListPageBO.java | 31 + .../sso/model/bo/user/UserPlatformAddBO.java | 48 + .../com/sso/model/bo/user/UserRestPwdBO.java | 30 + .../sso/model/bo/user/UserSystemRemoveBO.java | 36 + .../com/sso/model/bo/user/UserUpdateBO.java | 84 + .../model/bo/user/UserUpdateProfileBO.java | 55 + .../sso/model/bo/user/UserUpdatePwdBO.java | 39 + .../com/sso/model/vo/captcha/CaptchaVO.java | 31 + .../com/sso/model/vo/dept/DeptDetailVO.java | 74 + .../sso/model/vo/dept/DeptMgmtTreeNodeVO.java | 87 + .../model/vo/dept/DeptOptionTreeNodeVO.java | 57 + .../com/sso/model/vo/dept/DeptOptionVO.java | 33 + .../com/sso/model/vo/getway/ApplyAuthVO.java | 112 ++ .../sso/model/vo/getway/MenuTreeAuthVO.java | 86 + .../sso/model/vo/getway/SysLoginCacheVO.java | 40 + .../sso/model/vo/login/LoginLogPageVO.java | 63 + .../com/sso/model/vo/login/LoginMenuVO.java | 137 ++ .../com/sso/model/vo/login/LoginTokenVO.java | 37 + .../sso/model/vo/login/LoginUserInfoVO.java | 46 + .../com/sso/model/vo/menu/MenuDetailVO.java | 114 ++ .../model/vo/menu/MenuOptionTreeNodeVO.java | 57 + .../com/sso/model/vo/menu/MenuTreeNodeVO.java | 124 ++ .../sso/model/vo/platform/SystemDetailVO.java | 93 + .../sso/model/vo/platform/SystemListVO.java | 64 + .../model/vo/platform/SystemMgmtPageVO.java | 86 + .../com/sso/model/vo/role/RoleDetailVO.java | 78 + .../com/sso/model/vo/role/RoleOptionVO.java | 29 + .../com/sso/model/vo/role/RolePageVO.java | 73 + .../com/sso/model/vo/user/UserDetailVO.java | 89 + .../sso/model/vo/user/UserOnlinePageVO.java | 113 ++ .../sso/model/vo/user/UserOnlineSysVO.java | 37 + .../com/sso/model/vo/user/UserOptionVO.java | 44 + .../com/sso/model/vo/user/UserPageVO.java | 93 + .../com/sso/model/vo/user/UserProfileVO.java | 98 + .../com/sso/service/admin/CaptchaService.java | 24 + .../com/sso/service/admin/DeptService.java | 77 + .../sso/service/admin/FileUploadService.java | 37 + .../sso/service/admin/LoginLogService.java | 26 + .../com/sso/service/admin/MenuService.java | 71 + .../com/sso/service/admin/RoleService.java | 74 + .../sso/service/admin/SystemMgmtService.java | 49 + .../com/sso/service/admin/SystemService.java | 76 + .../sso/service/admin/UserOnlineService.java | 34 + .../com/sso/service/admin/UserService.java | 124 ++ .../admin/impl/CaptchaServiceImpl.java | 92 + .../service/admin/impl/DeptServiceImpl.java | 362 ++++ .../admin/impl/FileUploadServiceImpl.java | 133 ++ .../admin/impl/LoginLogServiceImpl.java | 102 + .../service/admin/impl/MenuServiceImpl.java | 297 +++ .../service/admin/impl/RoleServiceImpl.java | 391 ++++ .../admin/impl/SystemMgmtServiceImpl.java | 152 ++ .../service/admin/impl/SystemServiceImpl.java | 401 ++++ .../admin/impl/UserOnlineServiceImpl.java | 212 ++ .../service/admin/impl/UserServiceImpl.java | 767 ++++++++ .../admin/login/PermissionService.java | 57 + .../service/admin/login/SsoLoginService.java | 222 +++ .../admin/login/SysPermissionService.java | 136 ++ .../login/UserAccountAuthServiceImpl.java | 65 + .../com/sso/service/base/SsoTokenService.java | 315 +++ .../sso/service/base/SysConfigService.java | 37 + .../sso/service/base/SystemCacheService.java | 71 + .../com/sso/service/getway/ApiClient.java | 205 ++ .../sso/service/getway/ApplyAuthService.java | 25 + .../getway/impl/ApplyAuthServiceImpl.java | 188 ++ .../mapper/mybatis/SsoDeptMapper.xml | 319 +++ .../mapper/mybatis/SsoDeptTreePathMapper.xml | 57 + .../mapper/mybatis/SsoLoginLogMapper.xml | 259 +++ .../mapper/mybatis/SsoMenuMapper.xml | 418 ++++ .../mapper/mybatis/SsoOnlineUserMapper.xml | 312 +++ .../mapper/mybatis/SsoRoleMapper.xml | 297 +++ .../mapper/mybatis/SsoRoleMenuMapper.xml | 123 ++ .../mapper/mybatis/SsoSystemManagerMapper.xml | 276 +++ .../mapper/mybatis/SsoSystemMapper.xml | 394 ++++ .../mapper/mybatis/SsoUserDeptMapper.xml | 136 ++ .../mapper/mybatis/SsoUserMapper.xml | 453 +++++ .../mapper/mybatis/SsoUserRoleMapper.xml | 179 ++ .../mapper/mybatis/SsoUserSystemMapper.xml | 224 +++ sso-auth-center-service/sso-common/pom.xml | 120 ++ .../com/sso/common/annotation/OpenApi.java | 25 + .../sso/common/annotation/OpenApiService.java | 14 + .../sso/common/constant/CacheConstants.java | 65 + .../sso/common/constant/MimeTypeConstant.java | 53 + .../sso/common/constant/NumberConstant.java | 17 + .../com/sso/common/constant/SsoConstants.java | 80 + .../constant/SsoPermissionConstants.java | 29 + .../common/constant/UserLoginConstants.java | 27 + .../com/sso/common/enums/DelFlagEnum.java | 24 + .../com/sso/common/enums/DeptStatusEnum.java | 24 + .../com/sso/common/enums/LoginStatusEnum.java | 26 + .../com/sso/common/enums/MenuStatusEnum.java | 24 + .../com/sso/common/enums/MenuTypeEnum.java | 35 + .../com/sso/common/enums/SignTypeEnum.java | 49 + .../common/enums/SystemManagerStatusEnum.java | 24 + .../sso/common/enums/SystemStatusEnum.java | 49 + .../enums/exception/ApiExceptionEnum.java | 41 + .../enums/exception/DeptResStatusEnum.java | 46 + .../common/enums/exception/EnumInterface.java | 21 + .../enums/exception/MenuResStatusEnum.java | 39 + .../enums/exception/RoleResStatusEnum.java | 41 + .../enums/exception/SysResStatusEnum.java | 49 + .../enums/exception/SystemResStatusEnum.java | 42 + .../enums/exception/UserResStatusEnum.java | 44 + .../common/enums/system/BusinessStatus.java | 18 + .../sso/common/enums/system/BusinessType.java | 58 + .../sso/common/enums/system/OperatorType.java | 23 + .../common/enums/system/RoleStatusEnum.java | 24 + .../common/enums/system/UserStatusEnum.java | 31 + .../sso/common/exception/BaseException.java | 36 + .../common/exception/BusinessException.java | 37 + .../com/sso/common/model/BaseOperateBO.java | 19 + .../sso/common/model/login/LoginResultVO.java | 169 ++ .../sso/common/model/login/LoginUserVO.java | 71 + .../sso/common/model/page/BasePageModel.java | 66 + .../sso/common/model/page/BasePageQuery.java | 89 + .../sso/common/model/result/ResultModel.java | 77 + .../common/model/result/ResultPageModel.java | 94 + .../com/sso/common/utils/FileUploadUtils.java | 97 + .../com/sso/common/utils/JsonSerializer.java | 44 + .../com/sso/common/utils/ObjectUtils.java | 103 + .../java/com/sso/common/utils/PageUtils.java | 83 + .../com/sso/common/utils/SecurityUtils.java | 109 + .../com/sso/common/utils/ServletUtils.java | 91 + .../com/sso/common/utils/SsoSignUtil.java | 84 + .../com/sso/common/utils/StringUtils.java | 305 +++ .../com/sso/common/utils/SystemClock.java | 46 + .../java/com/sso/common/utils/UUIDUtil.java | 34 + .../com/sso/common/utils/ValidateUtils.java | 40 + .../sso/common/utils/bean/BeanCopierUtil.java | 70 + .../sso/common/utils/ip/IpAddressUtils.java | 80 + .../java/com/sso/common/utils/ip/IpUtils.java | 194 ++ .../sso/common/utils/sign/RSASignUtils.java | 133 ++ .../common/utils/sign/SignContentUtil.java | 67 + .../sso/common/utils/tree/ListToTreeUtil.java | 68 + .../sso/common/utils/tree/TreeParentNode.java | 41 + sso-auth-center-service/sso-framework/pom.xml | 65 + .../sso/framework/advice/ExceptionAdvice.java | 91 + .../com/sso/framework/config/JedisConfig.java | 57 + .../sso/framework/config/ResourcesConfig.java | 50 + .../config/captcha/CaptchaConfig.java | 87 + .../config/captcha/KaptchaTextCreator.java | 65 + .../config/datasource/DataSourceConfig.java | 98 + .../config/property/RedisConfigProperty.java | 45 + .../config/property/SysConfigProperty.java | 121 ++ .../context/ApplicationContextHelper.java | 40 + .../sso/framework/gateway/ApiContainer.java | 15 + .../com/sso/framework/gateway/ApiModel.java | 39 + .../com/sso/framework/gateway/ApiScanner.java | 113 ++ .../com/sso/framework/redis/RedisCache.java | 848 ++++++++ .../com/sso/framework/redis/RedisLock.java | 104 + .../framework/redis/client/RedisClient.java | 39 + .../redis/client/RedisClientInvoker.java | 22 + .../framework/redis/impl/RedisCacheImpl.java | 1746 +++++++++++++++++ 252 files changed, 24728 insertions(+) create mode 100644 README.md create mode 100644 sso-auth-center-service/.gitignore create mode 100644 sso-auth-center-service/README.md create mode 100755 sso-auth-center-service/pom.xml create mode 100755 sso-auth-center-service/sso-auth-center-admin/pom.xml create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/AuthCenterAdminApplication.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/aspect/LogPrintlnAspect.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/CaptchaController.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/DeptController.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/LoginController.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/LoginLogController.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/MenuController.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/RoleController.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/SystemController.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/SystemMgmtController.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/UserController.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/UserOnlineController.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/UserProfileController.java create mode 100644 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/getway/OpenApiController.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/SecurityConfig.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/filter/TokenAuthenticationFilter.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/handle/AuthenticationEntryPointImpl.java create mode 100755 sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/handle/LogoutSuccessHandlerImpl.java create mode 100644 sso-auth-center-service/sso-auth-center-admin/src/main/resources/application.properties create mode 100644 sso-auth-center-service/sso-auth-center-admin/src/main/resources/banner.txt create mode 100644 sso-auth-center-service/sso-auth-center-admin/src/main/resources/config/application-dev.properties create mode 100644 sso-auth-center-service/sso-auth-center-admin/src/main/resources/logback-spring.xml create mode 100755 sso-auth-center-service/sso-business/pom.xml create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/RoleCountDTO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoOnlineUserDTO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoUserDeptDTO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoUserMgmtDTO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoUserRoleDTO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoDept.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoDeptTreePath.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoLoginLog.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoMenu.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoOnlineUser.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoRole.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoRoleMenu.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoSystem.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoSystemManager.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUser.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUserDept.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUserRole.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUserSystem.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoDeptMapper.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoDeptTreePathMapper.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoLoginLogMapper.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoMenuMapper.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoOnlineUserMapper.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoRoleMapper.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoRoleMenuMapper.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoSystemManagerMapper.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoSystemMapper.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserDeptMapper.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserMapper.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserRoleMapper.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserSystemMapper.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/LoginLogQuery.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SsoDeptQuery.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SsoMenuQuery.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SsoRoleQuery.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SystemMgmtPageQuery.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/UserOnlineQuery.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/UserPageQuery.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/SysCodeBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptDeleteBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptIdQueryBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptMgmtTreeBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptSaveBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptUpdateBO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/getway/ApplyAuthBO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/getway/GetWayReqBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/login/LoginBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/login/LoginLogListPageBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuDeleteBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuSaveBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuTreeBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuUpdateBO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemDeleteBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtListPageBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtRemoveBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtSaveBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtStatusBO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemSaveBO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemSortBO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemUpdateBO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemUpdateSecretBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleDeleteBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleListOptionBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleListPageBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleRemoveUserBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleSaveBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleUpdateBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserAddBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserBatchDeleteBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserDeleteBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserDetailBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserListPageBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserOnlineListPageBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserPlatformAddBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserRestPwdBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserSystemRemoveBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserUpdateBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserUpdateProfileBO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserUpdatePwdBO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/captcha/CaptchaVO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptDetailVO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptMgmtTreeNodeVO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptOptionTreeNodeVO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptOptionVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/getway/ApplyAuthVO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/getway/MenuTreeAuthVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/getway/SysLoginCacheVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginLogPageVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginMenuVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginTokenVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginUserInfoVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/menu/MenuDetailVO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/menu/MenuOptionTreeNodeVO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/menu/MenuTreeNodeVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/platform/SystemDetailVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/platform/SystemListVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/platform/SystemMgmtPageVO.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/role/RoleDetailVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/role/RoleOptionVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/role/RolePageVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserDetailVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserOnlinePageVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserOnlineSysVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserOptionVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserPageVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserProfileVO.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/CaptchaService.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/DeptService.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/FileUploadService.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/LoginLogService.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/MenuService.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/RoleService.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/SystemMgmtService.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/SystemService.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/UserOnlineService.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/UserService.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/CaptchaServiceImpl.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/DeptServiceImpl.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/FileUploadServiceImpl.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/LoginLogServiceImpl.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/MenuServiceImpl.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/RoleServiceImpl.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/SystemMgmtServiceImpl.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/SystemServiceImpl.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/UserOnlineServiceImpl.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/UserServiceImpl.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/PermissionService.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/SsoLoginService.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/SysPermissionService.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/UserAccountAuthServiceImpl.java create mode 100755 sso-auth-center-service/sso-business/src/main/java/com/sso/service/base/SsoTokenService.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/base/SysConfigService.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/base/SystemCacheService.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/getway/ApiClient.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/getway/ApplyAuthService.java create mode 100644 sso-auth-center-service/sso-business/src/main/java/com/sso/service/getway/impl/ApplyAuthServiceImpl.java create mode 100644 sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoDeptMapper.xml create mode 100644 sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoDeptTreePathMapper.xml create mode 100644 sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoLoginLogMapper.xml create mode 100644 sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoMenuMapper.xml create mode 100644 sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoOnlineUserMapper.xml create mode 100644 sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoRoleMapper.xml create mode 100644 sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoRoleMenuMapper.xml create mode 100644 sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoSystemManagerMapper.xml create mode 100644 sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoSystemMapper.xml create mode 100644 sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserDeptMapper.xml create mode 100644 sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserMapper.xml create mode 100644 sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserRoleMapper.xml create mode 100644 sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserSystemMapper.xml create mode 100755 sso-auth-center-service/sso-common/pom.xml create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/annotation/OpenApi.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/annotation/OpenApiService.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/CacheConstants.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/MimeTypeConstant.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/NumberConstant.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/SsoConstants.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/SsoPermissionConstants.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/UserLoginConstants.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/DelFlagEnum.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/DeptStatusEnum.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/LoginStatusEnum.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/MenuStatusEnum.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/MenuTypeEnum.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/SignTypeEnum.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/SystemManagerStatusEnum.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/SystemStatusEnum.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/ApiExceptionEnum.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/DeptResStatusEnum.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/EnumInterface.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/MenuResStatusEnum.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/RoleResStatusEnum.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/SysResStatusEnum.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/SystemResStatusEnum.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/UserResStatusEnum.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/BusinessStatus.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/BusinessType.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/OperatorType.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/RoleStatusEnum.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/UserStatusEnum.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/exception/BaseException.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/exception/BusinessException.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/BaseOperateBO.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/login/LoginResultVO.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/login/LoginUserVO.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/page/BasePageModel.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/page/BasePageQuery.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/result/ResultModel.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/result/ResultPageModel.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/FileUploadUtils.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/JsonSerializer.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ObjectUtils.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/PageUtils.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/SecurityUtils.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ServletUtils.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/SsoSignUtil.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/StringUtils.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/SystemClock.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/UUIDUtil.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ValidateUtils.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/bean/BeanCopierUtil.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ip/IpAddressUtils.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ip/IpUtils.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/sign/RSASignUtils.java create mode 100644 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/sign/SignContentUtil.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/tree/ListToTreeUtil.java create mode 100755 sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/tree/TreeParentNode.java create mode 100755 sso-auth-center-service/sso-framework/pom.xml create mode 100644 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/advice/ExceptionAdvice.java create mode 100644 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/JedisConfig.java create mode 100755 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/ResourcesConfig.java create mode 100755 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/captcha/CaptchaConfig.java create mode 100755 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/captcha/KaptchaTextCreator.java create mode 100755 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/datasource/DataSourceConfig.java create mode 100644 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/property/RedisConfigProperty.java create mode 100755 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/property/SysConfigProperty.java create mode 100644 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/context/ApplicationContextHelper.java create mode 100644 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/gateway/ApiContainer.java create mode 100644 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/gateway/ApiModel.java create mode 100644 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/gateway/ApiScanner.java create mode 100644 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/RedisCache.java create mode 100644 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/RedisLock.java create mode 100644 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/client/RedisClient.java create mode 100644 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/client/RedisClientInvoker.java create mode 100644 sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/impl/RedisCacheImpl.java diff --git a/README.md b/README.md new file mode 100644 index 0000000..415bbde --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ + +程序员小强-统一认证中心 + +sso-auth-center-service 统一认证中心服务端项目 + +sso-auth-center-vue 页面后台(vue) \ No newline at end of file diff --git a/sso-auth-center-service/.gitignore b/sso-auth-center-service/.gitignore new file mode 100644 index 0000000..0c44257 --- /dev/null +++ b/sso-auth-center-service/.gitignore @@ -0,0 +1,52 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# Maven +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties + +# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) +!/.mvn/wrapper/maven-wrapper.jar + +# Eclipse +.classpath +.project +.settings/ + +# Intellij +.idea/ +*.iml +*.iws + +# Mac +.DS_Store + +/D:/ +/logs/ diff --git a/sso-auth-center-service/README.md b/sso-auth-center-service/README.md new file mode 100644 index 0000000..f776ebd --- /dev/null +++ b/sso-auth-center-service/README.md @@ -0,0 +1,3 @@ +# sso-auth-center + +统一认证中心服务端 diff --git a/sso-auth-center-service/pom.xml b/sso-auth-center-service/pom.xml new file mode 100755 index 0000000..df01345 --- /dev/null +++ b/sso-auth-center-service/pom.xml @@ -0,0 +1,220 @@ + + + 4.0.0 + + com.sso + sso-auth-center-service + 1.0.0 + + sso-auth-center-service + 程序员小强-统一认证中心 + + + sso-auth-center + sso-framework + sso-business + sso-common + + pom + + + 1.0.0 + UTF-8 + UTF-8 + 1.8 + 2.1.17.RELEASE + 1.18.10 + 30.0-jre + 1.21 + 3.1.1 + 1.3.2 + 1.2.4 + 2.3.2 + 1.2.75 + 5.5.0 + 2.5 + 1.3.3 + 3.17 + 0.9.1 + 3.2.0 + 5.4.3 + 6.0.20.Final + true + + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + ${mybatis.boot.version} + + + + + com.alibaba + druid-spring-boot-starter + ${druid.version} + + + + redis.clients + jedis + ${jedis.version} + + + + + commons-io + commons-io + ${commons.io.version} + + + + + commons-fileupload + commons-fileupload + ${commons.fileupload.version} + + + + + org.apache.poi + poi-ooxml + ${poi.version} + + + + + com.alibaba + fastjson + ${fastjson.version} + + + + + io.jsonwebtoken + jjwt + ${jwt.version} + + + + + com.github.penggle + kaptcha + ${kaptcha.version} + + + + + com.google.guava + guava + ${guava.version} + + + + + eu.bitwalker + UserAgentUtils + ${bitwalker.version} + + + + org.projectlombok + lombok + ${lombok.version} + + + + cn.hutool + hutool-all + ${hutool-all.version} + + + + + org.hibernate + hibernate-validator + ${hibernate-validator.version} + + + + + com.sso + sso-framework + ${sso-auth-center.version} + + + + + com.sso + sso-business + ${sso-auth-center.version} + + + + + com.sso + sso-common + ${sso-auth-center.version} + + + + + + + + + + + + sso-auth-center + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + + + repo + http://mvn.taofen8.com/artifactory/repo + + true + always + + + + + + + taofen8.repo + taofen8 Repository + http://mvn.taofen8.com/artifactory/local + + + taofen8.repo + taofen8 Repository + http://mvn.taofen8.com/artifactory/snapshot + + + + diff --git a/sso-auth-center-service/sso-auth-center-admin/pom.xml b/sso-auth-center-service/sso-auth-center-admin/pom.xml new file mode 100755 index 0000000..59e875e --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/pom.xml @@ -0,0 +1,84 @@ + + + + com.sso + sso-auth-center-service + 1.0.0 + + 4.0.0 + jar + sso-auth-center + + + web服务入口 + + + + + + taofen8.repo + http://mvn.taofen8.com/artifactory/repo + + true + always + + + + + + + + + + org.springframework.boot + spring-boot-devtools + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + mysql + mysql-connector-java + + + + + com.sso + sso-business + + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.1.RELEASE + + true + true + + + + + repackage + + + + + + + + + diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/AuthCenterAdminApplication.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/AuthCenterAdminApplication.java new file mode 100755 index 0000000..f33891c --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/AuthCenterAdminApplication.java @@ -0,0 +1,25 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +/** + * 统一认证中心服务端 - 启动类 + * + * @author 程序员小强 + */ +@EnableTransactionManagement +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class}) +public class AuthCenterAdminApplication { + + public static void main(String[] args) { + SpringApplication.run(AuthCenterAdminApplication.class, args); + } +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/aspect/LogPrintlnAspect.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/aspect/LogPrintlnAspect.java new file mode 100755 index 0000000..d6da22c --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/aspect/LogPrintlnAspect.java @@ -0,0 +1,89 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.aspect; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.slf4j.MDC; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.lang.reflect.Method; + +/** + * controller 日志打印 + * + * @author 程序员小强 + */ +@Slf4j +@Aspect +@Component +public class LogPrintlnAspect { + + /** + * 配置织入点 + */ + @Pointcut("execution(public * com.sso.controller.admin..*.*(..))") + public void allMethod() { + } + + @Around("allMethod()") + public Object doAround(ProceedingJoinPoint call) throws Throwable { + MethodSignature signature = (MethodSignature) call.getSignature(); + Method method = signature.getMethod(); + + String[] classNameArray = method.getDeclaringClass().getName().split("\\."); + String methodName = classNameArray[classNameArray.length - 1] + "." + method.getName(); + + String params = buildParamsDefault(call); + + long start = System.currentTimeMillis(); + Object result = null; + try { + MDC.put("logId", String.format("[%s]", RandomStringUtils.randomAlphanumeric(10))); + log.info("[ {} ] requestParam: {}", methodName, params); + result = call.proceed(); + return result; + } finally { + log.info("[ {} ] runTime: {} ms", methodName, (System.currentTimeMillis() - start)); + } + } + + private String buildParamsDefault(ProceedingJoinPoint call) { + StringBuilder params = new StringBuilder(" ["); + for (int i = 0; i < call.getArgs().length; i++) { + Object obj = call.getArgs()[i]; + if (null != obj) { + if (obj instanceof HttpServletRequest) { + continue; + } + if (obj instanceof HttpServletResponse) { + continue; + } + String str = obj.toString(); + if (obj.getClass() != String.class) { + str = ToStringBuilder.reflectionToString(obj, ToStringStyle.JSON_STYLE); + } + if (i != call.getArgs().length - 1) { + params.append(str).append(","); + } else { + params.append(str).append(" ]"); + } + } + if (params.length() == 1) { + params.append("]"); + } + } + return params.toString(); + } +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/CaptchaController.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/CaptchaController.java new file mode 100755 index 0000000..16575cd --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/CaptchaController.java @@ -0,0 +1,35 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.controller.admin; + +import com.sso.common.model.result.ResultModel; +import com.sso.service.admin.CaptchaService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; + +/** + * 验证码操作处理 + * + * @author 程序员小强 + */ +@Slf4j +@RestController +public class CaptchaController { + + @Autowired + private CaptchaService captchaService; + + /** + * 生成验证码 + */ + @RequestMapping("/captchaImage") + public ResultModel getCode(HttpServletResponse response) { + return ResultModel.success(captchaService.genCode(response)); + } +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/DeptController.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/DeptController.java new file mode 100755 index 0000000..7d3a0fd --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/DeptController.java @@ -0,0 +1,106 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.controller.admin; + + +import com.sso.common.model.result.ResultModel; +import com.sso.common.utils.SecurityUtils; +import com.sso.model.bo.SysCodeBO; +import com.sso.model.bo.dept.DeptDeleteBO; +import com.sso.model.bo.dept.DeptMgmtTreeBO; +import com.sso.model.bo.dept.DeptSaveBO; +import com.sso.model.bo.dept.DeptUpdateBO; +import com.sso.model.vo.dept.DeptDetailVO; +import com.sso.service.admin.DeptService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +/** + * 部门管理接口 + * + * @author 程序员小强 + */ +@RestController +@RequestMapping("/dept") +public class DeptController { + + @Autowired + private DeptService deptService; + + /** + * 部门管理页-部门树 + * + * @param treeBO + */ + @GetMapping("/listDeptMgmtTree") + @PreAuthorize("@ss.hasPermission('dept:listDeptMgmtTree')") + public ResultModel listDeptMgmtTree(@Valid DeptMgmtTreeBO treeBO) { + return ResultModel.success(deptService.listDeptMgmtTree(treeBO)); + } + + /** + * 部门下拉-部门树 + * + * @param sysCodeBO + */ + @RequestMapping("/listDeptOptionTree") + public ResultModel listDeptOptionTree(@Valid SysCodeBO sysCodeBO) { + return ResultModel.success(deptService.listDeptOptionTree(sysCodeBO.getSysCode())); + } + + /** + * 部门详情 + * + * @param deptId + */ + @RequestMapping("/detail/{deptId}") + public ResultModel getDeptDetail(@PathVariable Long deptId) { + return ResultModel.success(deptService.getDeptDetail(deptId)); + } + + /** + * 添加部门 + * + * @param saveBO + */ + @PostMapping("/add") + @PreAuthorize("@ss.hasPermission('dept:add')") + public ResultModel addDept(@Valid @RequestBody DeptSaveBO saveBO) { + saveBO.setOperateBy(SecurityUtils.getOperateName()); + deptService.addDept(saveBO); + return ResultModel.success(); + } + + /** + * 修改部门 + * + * @param updateBO + */ + @PutMapping("/update") + @PreAuthorize("@ss.hasPermission('dept:update')") + public ResultModel updateDept(@Valid @RequestBody DeptUpdateBO updateBO) { + updateBO.setOperateBy(SecurityUtils.getOperateName()); + deptService.updateDept(updateBO); + return ResultModel.success(); + } + + /** + * 删除部门 + * + * @param deptId 部门ID + */ + @DeleteMapping("/delete/{deptId}") + @PreAuthorize("@ss.hasPermission('dept:delete')") + public ResultModel deleteDept(@PathVariable Long deptId) { + DeptDeleteBO deptDeleteBO = new DeptDeleteBO(); + deptDeleteBO.setDeptId(deptId); + deptDeleteBO.setOperateBy(SecurityUtils.getOperateName()); + deptService.deleteDept(deptDeleteBO); + return ResultModel.success(); + } +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/LoginController.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/LoginController.java new file mode 100755 index 0000000..f1ec2ce --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/LoginController.java @@ -0,0 +1,57 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.controller.admin; + + +import com.sso.common.model.result.ResultModel; +import com.sso.model.bo.login.LoginBO; +import com.sso.model.vo.login.LoginTokenVO; +import com.sso.model.vo.login.LoginUserInfoVO; +import com.sso.service.admin.login.SsoLoginService; +import com.sso.service.admin.login.SysPermissionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.validation.Valid; + +/** + * 登录验证 + * + * @author 程序员小强 + */ +@RestController +public class LoginController { + + @Autowired + private SsoLoginService ssoLoginService; + + @Autowired + private SysPermissionService permissionService; + + /** + * 登录方法 + * + * @param loginBO 登录信息 + * @return 结果 + */ + @PostMapping("/login") + public ResultModel login(@Valid @RequestBody LoginBO loginBO) { + return ResultModel.success(ssoLoginService.login(loginBO)); + } + + /** + * 获取用户信息 + * + * @return 用户信息 + */ + @GetMapping("getUserInfo") + public ResultModel getInfo() { + LoginUserInfoVO userInfo = permissionService.getLoginUserInfo(); + return ResultModel.success(userInfo); + } +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/LoginLogController.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/LoginLogController.java new file mode 100755 index 0000000..699ff48 --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/LoginLogController.java @@ -0,0 +1,42 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.controller.admin; + + +import com.sso.common.model.result.ResultPageModel; +import com.sso.model.bo.login.LoginLogListPageBO; +import com.sso.model.vo.login.LoginLogPageVO; +import com.sso.service.admin.LoginLogService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.validation.Valid; + +/** + * 登录日志管理接口 + * + * @author 程序员小强 + */ +@RestController +@RequestMapping("/login/log") +public class LoginLogController { + + @Autowired + private LoginLogService loginLogService; + + /** + * 登录日志分页列表 + * + * @param pageBO + */ + @PreAuthorize("@ss.hasPermission('login:log:listPage')") + @RequestMapping("/listPage") + public ResultPageModel listPage(@Valid LoginLogListPageBO pageBO) { + return loginLogService.listPageUser(pageBO); + } + +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/MenuController.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/MenuController.java new file mode 100755 index 0000000..0d73eef --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/MenuController.java @@ -0,0 +1,105 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.controller.admin; + +import com.sso.common.model.result.ResultModel; +import com.sso.common.utils.SecurityUtils; +import com.sso.model.bo.menu.MenuDeleteBO; +import com.sso.model.bo.menu.MenuSaveBO; +import com.sso.model.bo.menu.MenuTreeBO; +import com.sso.model.bo.menu.MenuUpdateBO; +import com.sso.model.vo.menu.MenuDetailVO; +import com.sso.service.admin.MenuService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +/** + * 菜单管理接口 + * + * @author 程序员小强 + */ +@RestController +@RequestMapping("/menu") +public class MenuController { + + @Autowired + private MenuService menuService; + + /** + * 菜单管理页-菜单树 + * + * @param treeBO + */ + @GetMapping("/listMenuTree") + @PreAuthorize("@ss.hasPermission('menu:listMenuTree')") + public ResultModel listDeptMgmtTree(@Valid MenuTreeBO treeBO) { + return ResultModel.success(menuService.listMenuTree(treeBO)); + } + + /** + * 菜单管理页-菜单树下拉列表 + * + * @param treeBO + */ + @GetMapping("/listMenuOptionTree") + public ResultModel listMenuOptionTree(@Valid MenuTreeBO treeBO) { + return ResultModel.success(menuService.listMenuOptionTree(treeBO)); + } + + /** + * 菜单详情 + * + * @param menuId + */ + @RequestMapping("/detail/{menuId}") + public ResultModel getMenuDetail(@PathVariable Long menuId) { + return ResultModel.success(menuService.getMenuDetail(menuId)); + } + + /** + * 添加菜单 + * + * @param saveBO + */ + @PostMapping("/add") + @PreAuthorize("@ss.hasPermission('menu:add')") + public ResultModel addDept(@Valid @RequestBody MenuSaveBO saveBO) { + saveBO.setOperateBy(SecurityUtils.getOperateName()); + menuService.addMenu(saveBO); + return ResultModel.success(); + } + + /** + * 修改菜单 + * + * @param updateBO + */ + @PutMapping("/update") + @PreAuthorize("@ss.hasPermission('menu:update')") + public ResultModel updateMenu(@Valid @RequestBody MenuUpdateBO updateBO) { + updateBO.setOperateBy(SecurityUtils.getOperateName()); + menuService.updateMenu(updateBO); + return ResultModel.success(); + } + + /** + * 删除菜单 + * + * @param menuId 菜单ID + */ + @DeleteMapping("/delete/{menuId}") + @PreAuthorize("@ss.hasPermission('menu:delete')") + public ResultModel deleteMenu(@PathVariable Long menuId) { + MenuDeleteBO deptDeleteBO = new MenuDeleteBO(); + deptDeleteBO.setMenuId(menuId); + deptDeleteBO.setOperateBy(SecurityUtils.getOperateName()); + menuService.deleteMenu(deptDeleteBO); + return ResultModel.success(); + } + +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/RoleController.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/RoleController.java new file mode 100755 index 0000000..d8191bd --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/RoleController.java @@ -0,0 +1,118 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.controller.admin; + + +import com.sso.common.model.result.ResultModel; +import com.sso.common.model.result.ResultPageModel; +import com.sso.common.utils.SecurityUtils; +import com.sso.model.bo.role.*; +import com.sso.model.vo.role.RoleDetailVO; +import com.sso.model.vo.role.RolePageVO; +import com.sso.service.admin.RoleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +/** + * 角色接口 + * + * @author 程序员小强 + */ +@RestController +@RequestMapping("/role") +public class RoleController { + + @Autowired + private RoleService roleService; + + /** + * 角色分页列表 + * + * @param pageBO + */ + @RequestMapping("/listPage") + @PreAuthorize("@ss.hasPermission('role:listPage')") + public ResultPageModel listPage(@Valid RoleListPageBO pageBO) { + return roleService.listPageRole(pageBO); + } + + /** + * 角色-下拉选项列表 + * + * @param optionBO + */ + @RequestMapping("/listOption") + public ResultModel listRoleOption(@Valid RoleListOptionBO optionBO) { + return ResultModel.success(roleService.listRoleOption(optionBO)); + } + + /** + * 角色详情 + * + * @param roleId + */ + @RequestMapping("/detail/{roleId}") + public ResultModel getDeptDetail(@PathVariable Long roleId) { + return ResultModel.success(roleService.getDeptDetail(roleId)); + } + + /** + * 添加角色 + * + * @param saveBO + */ + @PostMapping("/add") + @PreAuthorize("@ss.hasPermission('role:add')") + public ResultModel addRole(@Valid @RequestBody RoleSaveBO saveBO) { + saveBO.setOperateBy(SecurityUtils.getOperateName()); + roleService.addRole(saveBO); + return ResultModel.success(); + } + + /** + * 修改角色 + * + * @param updateBO + */ + @PutMapping("/update") + @PreAuthorize("@ss.hasPermission('role:update')") + public ResultModel updateRole(@Valid @RequestBody RoleUpdateBO updateBO) { + updateBO.setOperateBy(SecurityUtils.getOperateName()); + roleService.updateRole(updateBO); + return ResultModel.success(); + } + + /** + * 删除角色 + * + * @param roleId 角色ID + */ + @DeleteMapping("/delete/{roleId}") + @PreAuthorize("@ss.hasPermission('role:delete')") + public ResultModel deleteDept(@PathVariable Long roleId) { + RoleDeleteBO deptDeleteBO = new RoleDeleteBO(); + deptDeleteBO.setRoleId(roleId); + deptDeleteBO.setOperateBy(SecurityUtils.getOperateName()); + roleService.deleteRole(deptDeleteBO); + return ResultModel.success(); + } + + /** + * 移除角色用户绑定关系 + * + * @param removeUserBO + */ + @PutMapping("/removeUser") + @PreAuthorize("@ss.hasPermission('role:removeUser')") + public ResultModel removeUserRole(@Valid @RequestBody RoleRemoveUserBO removeUserBO) { + removeUserBO.setOperateBy(SecurityUtils.getOperateName()); + roleService.removeUserRole(removeUserBO); + return ResultModel.success(); + } + +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/SystemController.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/SystemController.java new file mode 100755 index 0000000..eaadbbe --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/SystemController.java @@ -0,0 +1,143 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.controller.admin; + +import com.sso.common.model.result.ResultModel; +import com.sso.common.utils.SecurityUtils; +import com.sso.model.bo.platform.*; +import com.sso.model.vo.platform.SystemDetailVO; +import com.sso.service.admin.FileUploadService; +import com.sso.service.admin.SystemService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.validation.Valid; + +/** + * 目标系统平台相关接口 + * + * @author 程序员小强 + */ +@RestController +@RequestMapping("/system") +public class SystemController { + + @Autowired + private SystemService systemService; + + @Resource + private FileUploadService fileUploadService; + + /** + * 我的平台列表 + * + * @return 系统列表 + */ + @GetMapping("/myList") + public ResultModel myList() { + return ResultModel.success(systemService.listMySystem()); + } + + /** + * 我的平台-排序 + * + * @return 系统列表 + */ + @PostMapping("/sortMy") + public ResultModel sortMySystem(@Valid @RequestBody SystemSortBO sortBO) { + systemService.sortMySystem(sortBO); + return ResultModel.success(); + } + + /** + * 系统平台详情 + * + * @param sysCode + * @return 系统平台详情 + */ + @GetMapping("/getDetailBySysCode") + @PreAuthorize("@ss.hasPermission('system:getDetailBySysCode')") + public ResultModel getDetailBySysCode(String sysCode) { + return ResultModel.success(systemService.getDetailBySysCode(sysCode)); + } + + /** + * 平台管理-列表 + * + * @return 平台列表 + */ + @GetMapping("/mgmtList") + @PreAuthorize("@ss.hasPermission('system:mgmtList')") + public ResultModel list() { + return ResultModel.success(systemService.listMyMgmtSystem()); + } + + /** + * 新增-目标系统 + * + * @param saveBO + */ + @PostMapping("/add") + @PreAuthorize("@ss.hasPermission('system:add')") + public ResultModel addSystem(@Valid @RequestBody SystemSaveBO saveBO) { + saveBO.setOperateBy(SecurityUtils.getOperateName()); + systemService.addSystem(saveBO); + return ResultModel.success(); + } + + /** + * 修改-目标系统 + * + * @param updateBO + */ + @PutMapping("/update") + @PreAuthorize("@ss.hasPermission('system:update')") + public ResultModel updateSystem(@Valid @RequestBody SystemUpdateBO updateBO) { + updateBO.setOperateBy(SecurityUtils.getOperateName()); + systemService.updateSystem(updateBO); + return ResultModel.success(); + } + + /** + * 添加或修改-秘钥 + * + * @param updateBO + */ + @PutMapping("/updateSecret") + @PreAuthorize("@ss.hasPermission('system:updateSecret')") + public ResultModel updateSecret(@Valid @RequestBody SystemUpdateSecretBO updateBO) { + updateBO.setOperateBy(SecurityUtils.getOperateName()); + systemService.updateSystemSecret(updateBO); + return ResultModel.success(); + } + + /** + * 修改系统图标 + */ + @PostMapping("/uploadIcon/{sysId}") + public ResultModel uploadIcon(@PathVariable("sysId") Long sysId, @RequestParam("iconFile") MultipartFile iconFile) { + String operateName = SecurityUtils.getOperateName(); + return ResultModel.success(fileUploadService.uploadSystemIcon(sysId, operateName, iconFile)); + } + + /** + * 删除-目标系统 + * + * @param sysId 系统ID + */ + @DeleteMapping("/delete/{sysId}") + @PreAuthorize("@ss.hasPermission('system:delete')") + public ResultModel deleteSystem(@PathVariable Long sysId) { + SystemDeleteBO deptDeleteBO = new SystemDeleteBO(); + deptDeleteBO.setSysId(sysId); + deptDeleteBO.setOperateBy(SecurityUtils.getOperateName()); + systemService.deleteSystem(deptDeleteBO); + return ResultModel.success(); + } + +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/SystemMgmtController.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/SystemMgmtController.java new file mode 100755 index 0000000..d1ca336 --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/SystemMgmtController.java @@ -0,0 +1,84 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.controller.admin; + +import com.sso.common.model.result.ResultModel; +import com.sso.common.model.result.ResultPageModel; +import com.sso.common.utils.SecurityUtils; +import com.sso.model.bo.platform.SystemMgmtListPageBO; +import com.sso.model.bo.platform.SystemMgmtRemoveBO; +import com.sso.model.bo.platform.SystemMgmtSaveBO; +import com.sso.model.bo.platform.SystemMgmtStatusBO; +import com.sso.model.vo.platform.SystemMgmtPageVO; +import com.sso.service.admin.SystemMgmtService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +/** + * 系统管理员相关操作 + * + * @author 程序员小强 + */ +@RestController +@RequestMapping("/systemMgmt") +public class SystemMgmtController { + + @Autowired + private SystemMgmtService systemMgmtService; + + /** + * 系统管理员-用户分页列表 + * + * @param pageBO + * @return 用户 + */ + @RequestMapping("/listPage") + @PreAuthorize("@ss.hasPermission('systemMgmt:updateSystemMgmt')") + public ResultPageModel listPage(@Valid SystemMgmtListPageBO pageBO) { + return systemMgmtService.listPageSysMgmtUser(pageBO); + } + + /** + * 新增-管理员权限 + * + * @param addBO + */ + @PostMapping("/add") + @PreAuthorize("@ss.hasPermission('systemMgmt:updateSystemMgmt')") + public ResultModel addSystemMgmt(@Valid @RequestBody SystemMgmtSaveBO addBO) { + addBO.setOperateBy(SecurityUtils.getOperateName()); + systemMgmtService.addSystemMgmt(addBO); + return ResultModel.success(); + } + + /** + * 修改-管理员权限账号状态 + * + * @param addBO + */ + @PutMapping("/updateStatus") + @PreAuthorize("@ss.hasPermission('systemMgmt:updateSystemMgmt')") + public ResultModel updateStatus(@Valid @RequestBody SystemMgmtStatusBO addBO) { + addBO.setOperateBy(SecurityUtils.getOperateName()); + systemMgmtService.updateStatus(addBO); + return ResultModel.success(); + } + + /** + * 移除-用户管理员权限 + * + * @param removeBO + */ + @RequestMapping("/remove") + @PreAuthorize("@ss.hasPermission('systemMgmt:updateSystemMgmt')") + public ResultModel removeUserSystemMgmt(@Valid @RequestBody SystemMgmtRemoveBO removeBO) { + removeBO.setOperateBy(SecurityUtils.getOperateName()); + systemMgmtService.removeUserSystemMgmt(removeBO); + return ResultModel.success(); + } +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/UserController.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/UserController.java new file mode 100755 index 0000000..1cd7ea8 --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/UserController.java @@ -0,0 +1,196 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.controller.admin; + + +import com.sso.common.model.login.LoginUserVO; +import com.sso.common.model.result.ResultModel; +import com.sso.common.model.result.ResultPageModel; +import com.sso.common.utils.SecurityUtils; +import com.sso.model.bo.user.*; +import com.sso.model.vo.user.UserDetailVO; +import com.sso.model.vo.user.UserOptionVO; +import com.sso.model.vo.user.UserPageVO; +import com.sso.model.vo.user.UserProfileVO; +import com.sso.service.admin.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +/** + * 用户管理接口 + * + * @author 程序员小强 + */ +@RestController +@RequestMapping("/user") +public class UserController { + + @Autowired + private UserService userService; + + /** + * 用户分页列表 + * + * @param pageBO + */ + @PreAuthorize("@ss.hasPermission('user:listPage')") + @RequestMapping("/listPage") + public ResultPageModel listPage(@Valid UserListPageBO pageBO) { + return userService.listPageUser(pageBO); + } + + /** + * 用户详情 + * + * @param detailBO 用户ID + */ + @RequestMapping("/detail") + public ResultModel getUserDetail(@Valid @RequestBody UserDetailBO detailBO) { + return ResultModel.success(userService.getUserDetail(detailBO)); + } + + /** + * 个人详情 + */ + @RequestMapping("/profile") + public ResultModel getUserProfile() { + LoginUserVO loginUser = SecurityUtils.getLoginUser(); + return ResultModel.success(userService.getUserProfile(loginUser.getUserId())); + } + + /** + * 根据手机号查询用户 + * + * @param phone 手机号 + */ + @RequestMapping("/getUserByPhone/{phone}") + public ResultModel getUserByPhone(@PathVariable String phone) { + return ResultModel.success(userService.getUserByPhone(phone)); + } + + /** + * 根据用户名查询用户 + * + * @param username 用户名 + */ + @RequestMapping("/getUserByUserName/{username}") + public ResultModel getByPhone(@PathVariable String username) { + return ResultModel.success(userService.getUserByUserName(username)); + } + + /** + * 根据-关键字搜索用户 + * + * @param keywords 关键字模糊 + */ + @RequestMapping("/listUserOption") + public ResultModel listUserOption(@RequestParam(required = false) String keywords) { + return ResultModel.success(userService.listUserOption(keywords)); + } + + /** + * 添加用户 + * + * @param addBO + */ + @PostMapping("/add") + @PreAuthorize("@ss.hasPermission('user:add')") + public ResultModel addUser(@Valid @RequestBody UserAddBO addBO) { + addBO.setOperateBy(SecurityUtils.getOperateName()); + userService.addUser(addBO); + return ResultModel.success(); + } + + /** + * 添加用户系统关系 + * + * @param addBO + */ + @PostMapping("/addUserPlatformRelation") + public ResultModel addUserPlatformRelation(@Valid @RequestBody UserPlatformAddBO addBO) { + addBO.setOperateBy(SecurityUtils.getOperateName()); + userService.addUserPlatformRelation(addBO); + return ResultModel.success(); + } + + /** + * 修改用户 + * + * @param updateBO + */ + @PutMapping("/update") + @PreAuthorize("@ss.hasPermission('user:update')") + public ResultModel updateUser(@Valid @RequestBody UserUpdateBO updateBO) { + updateBO.setOperateBy(SecurityUtils.getOperateName()); + userService.updateUser(updateBO); + return ResultModel.success(); + } + + /** + * 移除用户与系统关系 + * + * @param removeBO + */ + @RequestMapping("/removeUserSystem") + @PreAuthorize("@ss.hasPermission('user:removeUserSystem')") + public ResultModel removeUserSystem(@Valid @RequestBody UserSystemRemoveBO removeBO) { + removeBO.setOperateBy(SecurityUtils.getOperateName()); + userService.removeUserSystem(removeBO); + return ResultModel.success(); + } + + /** + * 修改个人信息 + * + * @param updateBO + */ + @PutMapping("/updateProfile") + public ResultModel updateProfile(@Valid @RequestBody UserUpdateProfileBO updateBO) { + updateBO.setOperateBy(SecurityUtils.getOperateName()); + userService.updateProfile(updateBO); + return ResultModel.success(); + } + + /** + * 修改个人密码 + * + * @param updateBO + */ + @PutMapping("/updatePwd") + public ResultModel updatePwd(@Valid @RequestBody UserUpdatePwdBO updateBO) { + updateBO.setOperateBy(SecurityUtils.getOperateName()); + userService.updatePwd(updateBO); + return ResultModel.success(); + } + + /** + * 重置密码 + * + * @param restPwdBO + */ + @PutMapping("/resetPwd") + @PreAuthorize("@ss.hasPermission('user:resetPwd')") + public ResultModel resetPwd(@Valid @RequestBody UserRestPwdBO restPwdBO) { + restPwdBO.setOperateBy(SecurityUtils.getOperateName()); + userService.resetPwd(restPwdBO); + return ResultModel.success(); + } + + /** + * 删除用户 + * + * @param deleteBO + */ + @RequestMapping("/delete") + @PreAuthorize("@ss.hasPermission('user:delete')") + public ResultModel deleteUser(@Valid @RequestBody UserDeleteBO deleteBO) { + deleteBO.setOperateBy(SecurityUtils.getOperateName()); + userService.deleteUser(deleteBO); + return ResultModel.success(); + } +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/UserOnlineController.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/UserOnlineController.java new file mode 100755 index 0000000..f3f4a3a --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/UserOnlineController.java @@ -0,0 +1,75 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.controller.admin; + + +import com.sso.common.model.result.ResultModel; +import com.sso.common.model.result.ResultPageModel; +import com.sso.common.utils.SecurityUtils; +import com.sso.model.bo.user.UserOnlineListPageBO; +import com.sso.model.vo.user.UserOnlinePageVO; +import com.sso.model.vo.user.UserOnlineSysVO; +import com.sso.service.admin.UserOnlineService; +import com.sso.service.base.SsoTokenService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.validation.Valid; + +/** + * 在线用户管理接口 + * + * @author 程序员小强 + */ +@Slf4j +@RestController +@RequestMapping("/user/online") +public class UserOnlineController { + + @Resource + private SsoTokenService ssoTokenService; + @Resource + private UserOnlineService userOnlineService; + + /** + * 在线用户分页列表 + * + * @param pageBO + */ + @PreAuthorize("@ss.hasPermission('user:online:listPage')") + @RequestMapping("/listPage") + public ResultPageModel listPage(@Valid UserOnlineListPageBO pageBO) { + return userOnlineService.listPageUser(pageBO); + } + + /** + * 查看用户已登录的子系统 + * + * @param userId 用户ID + */ + @PreAuthorize("@ss.hasPermission('user:online:listOnlineSys')") + @RequestMapping("/listOnlineSys/{userId}") + public ResultPageModel listOnlineSys(@PathVariable Long userId) { + return ResultPageModel.success(userOnlineService.listOnlineSys(userId)); + } + + /** + * 强退认证中心+所有已登录子系统 + * + * @param userId 用户ID + */ + @PreAuthorize("@ss.hasPermission('user:online:retreatUser')") + @RequestMapping("/retreatUser/{userId}") + public ResultModel retreatUser(@PathVariable Long userId) { + ssoTokenService.logoOutUser(userId); + log.info("[ 强退用户 ] >> userId:{}, operateBy:{}", userId, SecurityUtils.getOperateName()); + return ResultModel.success(); + } + +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/UserProfileController.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/UserProfileController.java new file mode 100755 index 0000000..7cf411d --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/admin/UserProfileController.java @@ -0,0 +1,83 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.controller.admin; + + +import com.sso.common.model.login.LoginUserVO; +import com.sso.common.model.result.ResultModel; +import com.sso.common.utils.SecurityUtils; +import com.sso.model.bo.user.UserUpdateProfileBO; +import com.sso.model.bo.user.UserUpdatePwdBO; +import com.sso.model.vo.user.UserProfileVO; +import com.sso.service.admin.FileUploadService; +import com.sso.service.admin.UserService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.validation.Valid; + +/** + * 用户-个人详情接口 + * + * @author 程序员小强 + */ +@Slf4j +@RestController +@RequestMapping("/user/profile") +public class UserProfileController { + + @Autowired + private UserService userService; + + @Resource + private FileUploadService fileUploadService; + + /** + * 个人详情 + */ + @RequestMapping("/detail") + public ResultModel getUserProfile() { + LoginUserVO loginUser = SecurityUtils.getLoginUser(); + return ResultModel.success(userService.getUserProfile(loginUser.getUserId())); + } + + /** + * 修改个人信息 + * + * @param updateBO + */ + @PutMapping("/update") + public ResultModel updateProfile(@Valid @RequestBody UserUpdateProfileBO updateBO) { + updateBO.setOperateBy(SecurityUtils.getOperateName()); + userService.updateProfile(updateBO); + return ResultModel.success(); + } + + /** + * 修改个人密码 + * + * @param updateBO + */ + @PutMapping("/updatePwd") + public ResultModel updatePwd(@Valid @RequestBody UserUpdatePwdBO updateBO) { + updateBO.setOperateBy(SecurityUtils.getOperateName()); + userService.updatePwd(updateBO); + return ResultModel.success(); + } + + /** + * 个人-头像上传 + */ + @PostMapping("/avatar") + public ResultModel avatar(@RequestParam("avatarFile") MultipartFile avatarFile) { + LoginUserVO loginUser = SecurityUtils.getLoginUser(); + String operateName = SecurityUtils.getOperateName(); + return ResultModel.success(fileUploadService.uploadUserAvatar(loginUser.getUserId(), operateName, avatarFile)); + } + +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/getway/OpenApiController.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/getway/OpenApiController.java new file mode 100644 index 0000000..757f114 --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/controller/getway/OpenApiController.java @@ -0,0 +1,65 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.controller.getway; + +import com.alibaba.fastjson.JSON; +import com.sso.common.model.result.ResultModel; +import com.sso.common.utils.SystemClock; +import com.sso.model.bo.getway.GetWayReqBO; +import com.sso.service.getway.ApiClient; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.RandomStringUtils; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.util.WebUtils; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.Map; + +/** + * 统一网关 + */ +@Slf4j +@RestController +@RequestMapping("/open") +public class OpenApiController { + + @Autowired + private ApiClient apiClient; + + /** + * 统一网关入口 + * + * @author 程序员小强 + */ + @PostMapping("/gateway") + public ResultModel gateway(@Valid GetWayReqBO reqBO, + HttpServletRequest request) throws Throwable { + Map mapParams = WebUtils.getParametersStartingWith(request, ""); + //日志ID (请求的唯一标识+5位随机数) + MDC.put("logId", String.format("[%s-%s]", reqBO.getApiRequestId(), RandomStringUtils.randomAlphanumeric(5))); + + log.info("[ 统一认证开放接口 start ] >> method={} mapParams = {}", reqBO.getMethod(), mapParams); + long start = SystemClock.millisClock().now(); + + //校验请求时间戳间隔 + apiClient.checkTimestamp(reqBO, mapParams); + + //验签 + apiClient.checkSign(reqBO, mapParams); + + //请求接口 + ResultModel result = apiClient.invoke(reqBO); + + log.info("[ 统一认证开放接口 end ] >> method={},result = {}, times = {} ms", reqBO.getMethod(), JSON.toJSONString(result), (SystemClock.millisClock().now() - start)); + + return result; + } + +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/SecurityConfig.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/SecurityConfig.java new file mode 100755 index 0000000..24ce51c --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/SecurityConfig.java @@ -0,0 +1,147 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.security; + +import com.sso.security.filter.TokenAuthenticationFilter; +import com.sso.security.handle.AuthenticationEntryPointImpl; +import com.sso.security.handle.LogoutSuccessHandlerImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpMethod; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.security.web.authentication.logout.LogoutFilter; +import org.springframework.web.filter.CorsFilter; + +import javax.annotation.Resource; + +/** + * spring security配置 + * + * @author 程序员小强 + */ +@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + /** + * 自定义用户认证逻辑 + */ + @Resource + private UserDetailsService userDetailsService; + /** + * 认证失败处理类 + */ + @Autowired + private AuthenticationEntryPointImpl unauthorizedHandler; + /** + * 退出处理类 + */ + @Autowired + private LogoutSuccessHandlerImpl logoutSuccessHandler; + /** + * token认证过滤器 + */ + @Autowired + private TokenAuthenticationFilter tokenAuthenticationFilter; + /** + * 跨域过滤器 + */ + @Autowired + private CorsFilter corsFilter; + + /** + * 解决 无法直接注入 AuthenticationManager + * + * @return + * @throws Exception + */ + @Bean + @Override + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + + /** + * Security 配置 + * 规则如下: + * anyRequest -> 匹配所有请求路径 + * access -> SpringEl表达式结果为true时可以访问 + * anonymous -> 匿名可以访问 + * denyAll -> 用户不能访问 + * fullyAuthenticated -> 用户完全认证可以访问(非remember-me下自动登录) + * hasAnyAuthority -> 如果有参数,参数表示权限,则其中任何一个权限可以访问 + * hasAnyRole -> 如果有参数,参数表示角色,则其中任何一个角色可以访问 + * hasAuthority -> 如果有参数,参数表示权限,则其权限可以访问 + * hasIpAddress -> 如果有参数,参数表示IP地址,如果用户IP和参数匹配,则可以访问 + * hasRole -> 如果有参数,参数表示角色,则其角色可以访问 + * permitAll -> 用户可以任意访问 + * rememberMe -> 允许通过remember-me登录的用户访问 + * authenticated -> 用户登录后可访问 + */ + @Override + protected void configure(HttpSecurity httpSecurity) throws Exception { + httpSecurity + // CSRF禁用,因为不使用session + .csrf().disable() + // 认证失败处理类 + .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and() + // 基于token,所以不需要session + .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() + // 过滤请求 + .authorizeRequests() + // 对于登录login 验证码captchaImage 允许匿名访问 + .antMatchers("/**/login", "/**/captchaImage").anonymous() + .antMatchers( + HttpMethod.GET, + "/*.html", + "/**/*.html", + "/**/*.css", + "/**/*.js", + "/**/*.ico" + ).permitAll() + .antMatchers("/profile/**").anonymous() + .antMatchers("/**/webjars/**").anonymous() + .antMatchers("/**/api-docs").anonymous() + .antMatchers("/**/druid/**").anonymous() + //开放接口不拦截-内部有验签 + .antMatchers("/open/gateway").anonymous() + // 除上面外的所有请求全部需要鉴权认证 + .anyRequest().authenticated() + .and() + .headers().frameOptions().disable(); + // 退出登录处理器 + httpSecurity.logout().logoutUrl("/**/logout").logoutSuccessHandler(logoutSuccessHandler); + // 添加账号校验 filter + httpSecurity.addFilterBefore(tokenAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); + // 添加CORS filter + httpSecurity.addFilterBefore(corsFilter, TokenAuthenticationFilter.class); + // 登出 + httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class); + } + + + /** + * 强散列哈希加密实现 + */ + @Bean + public BCryptPasswordEncoder bCryptPasswordEncoder() { + return new BCryptPasswordEncoder(); + } + + /** + * 身份-认证接口 + */ + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder()); + } +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/filter/TokenAuthenticationFilter.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/filter/TokenAuthenticationFilter.java new file mode 100755 index 0000000..4a92fc9 --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/filter/TokenAuthenticationFilter.java @@ -0,0 +1,47 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.security.filter; + +import com.sso.common.model.login.LoginResultVO; +import com.sso.common.utils.ObjectUtils; +import com.sso.common.utils.SecurityUtils; +import com.sso.service.base.SsoTokenService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * token过滤器 验证token有效性 + * + * @author 程序员小强 + */ +@Component +public class TokenAuthenticationFilter extends OncePerRequestFilter { + + @Autowired + private SsoTokenService ssoTokenService; + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) + throws ServletException, IOException { + LoginResultVO loginResultVO = ssoTokenService.getLoginUser(request); + if (ObjectUtils.isNotNull(loginResultVO) && ObjectUtils.isNull(SecurityUtils.getAuthentication())) { + ssoTokenService.renewTokenByAdminWeb(loginResultVO); + UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginResultVO, null, loginResultVO.getAuthorities()); + authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); + SecurityContextHolder.getContext().setAuthentication(authenticationToken); + } + chain.doFilter(request, response); + } +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/handle/AuthenticationEntryPointImpl.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/handle/AuthenticationEntryPointImpl.java new file mode 100755 index 0000000..d1c4d37 --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/handle/AuthenticationEntryPointImpl.java @@ -0,0 +1,38 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.security.handle; + +import com.alibaba.fastjson.JSON; +import com.sso.common.enums.exception.SysResStatusEnum; +import com.sso.common.model.result.ResultModel; +import com.sso.common.utils.ServletUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; + +/** + * 认证失败处理类 返回未授权 + * + * @author 程序员小强 + */ +@Slf4j +@Component +public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, Serializable { + + private static final long serialVersionUID = -6355792444057575911L; + + @Override + public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) { + int code = SysResStatusEnum.UNAUTHORIZED.getCode(); + String msg = String.format("请求访问:%s,认证失败,无法访问系统资源", request.getRequestURI()); + log.error("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI()); + ServletUtils.renderString(response, JSON.toJSONString(ResultModel.error(code, msg))); + } +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/handle/LogoutSuccessHandlerImpl.java b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/handle/LogoutSuccessHandlerImpl.java new file mode 100755 index 0000000..315a537 --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/java/com/sso/security/handle/LogoutSuccessHandlerImpl.java @@ -0,0 +1,45 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.security.handle; + +import com.alibaba.fastjson.JSON; +import com.sso.common.enums.exception.SysResStatusEnum; +import com.sso.common.model.login.LoginResultVO; +import com.sso.common.model.result.ResultModel; +import com.sso.common.utils.ServletUtils; +import com.sso.service.base.SsoTokenService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.core.Authentication; +import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; +import org.springframework.util.ObjectUtils; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * 自定义退出处理类 返回成功 + * + * @author 程序员小强 + */ +@Configuration +public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler { + + @Autowired + private SsoTokenService ssoTokenService; + + /** + * 用户退出处理 + */ + @Override + public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { + LoginResultVO loginResultVO = ssoTokenService.getLoginUser(request); + if (!ObjectUtils.isEmpty(loginResultVO)) { + //用户退出处理 + ssoTokenService.logoOutUser(loginResultVO); + } + ServletUtils.renderString(response, JSON.toJSONString(ResultModel.error(SysResStatusEnum.SUCCESS.getCode(), "退出成功"))); + } +} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/resources/application.properties b/sso-auth-center-service/sso-auth-center-admin/src/main/resources/application.properties new file mode 100644 index 0000000..311dce8 --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/resources/application.properties @@ -0,0 +1,2 @@ + +spring.profiles.active=dev diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/resources/banner.txt b/sso-auth-center-service/sso-auth-center-admin/src/main/resources/banner.txt new file mode 100644 index 0000000..ed86f98 --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/resources/banner.txt @@ -0,0 +1,23 @@ +${AnsiColor.BRIGHT_RED} +---------------------------------------- + _______ _______ _______ +( ____ \( ____ \( ___ ) +| ( \/| ( \/| ( ) | +| (_____ | (_____ | | | | +(_____ )(_____ )| | | | + ) | ) || | | | +/\____) |/\____) || (___) | +\_______)\_______)(_______) + +---------------------------------------- +${AnsiColor.GREEN} +Application Env: ${spring.profiles.active} +Application Port: ${server.port} +Root Log Level: ${logging.level.root} +Project Log Level: ${logging.level.com.sso} +Spring Boot Version: ${spring-boot.version} +${AnsiColor.BRIGHT_RED} +温馨提示: +编码千万行,注释第一行。 +代码不规范,复盘两行泪。 +${AnsiColor.GREEN} diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/resources/config/application-dev.properties b/sso-auth-center-service/sso-auth-center-admin/src/main/resources/config/application-dev.properties new file mode 100644 index 0000000..557deae --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/resources/config/application-dev.properties @@ -0,0 +1,104 @@ +server.port=9901 + +#日志配置 +logging.level.root=info +logging.level.com.sso=info +logging.level.org.springframework=warn +#日志文件路径 +log.root.path=${user.home}/logs/sso-auth-center + +# jackson时间格式化(解决时区问题) +spring.jackson.time-zone=GMT+8 +spring.jackson.date-format=yyyy-MM-dd HH:mm:ss + + +#redis 基础配置 +# Redis数据库索引(默认为0) +spring.redis.database=0 +# Redis服务器地址 +spring.redis.host=localhost +# Redis服务器连接密码(默认为空) +spring.redis.password=123456 +# Redis服务器连接端口 +spring.redis.port=6379 +# 连接超时时间(毫秒) +spring.redis.timeout=0 + +#redis 连接池配置 +#池中最大链接数 +spring.redis.pool-config.max-total=256 +# 连接池中的最大空闲连接 +spring.redis.pool-config.max-idle=128 +# 连接池中的最小空闲连接 +spring.redis.pool-config.min-idle=8 +# 连接池最大阻塞等待时间(使用负值表示没有限制) +spring.redis.pool-config.max-wait-millis=1000 +# 调用者获取链接时,是否检测当前链接有效性 +spring.redis.pool-config.test-on-borrow=false +# 向链接池中归还链接时,是否检测链接有效性 +spring.redis.pool-config.test-on-return=false +# 调用者获取链接时,是否检测空闲超时, 如果超时,则会被移除- +spring.redis.pool-config.test-while-idle=true +# 空闲链接检测线程一次运行检测多少条链接 +spring.redis.pool-config.num-tests-per-eviction-run=8 +#空闲链接检测线程检测周期。如果为负值,表示不运行检测线程。(单位:毫秒,默认为-1) +spring.redis.pool-config.time-between-eviction-runs-millis=60000 +#配置一个连接在池中最小生存的时间,单位是毫秒 +spring.redis.pool-config.min-evictable-idle-time-millis=300000 + + +# 管理后台系统模块数据源 +spring.datasource.admin.url=jdbc:mysql://localhost:3306/my-sso?useUnicode=true&characterEncoding=utf8&autoReconnect=true&serverTimezone=Asia/Shanghai&allowMultiQueries=true +spring.datasource.admin.username=root +spring.datasource.admin.password=123456 +spring.datasource.admin.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.admin.initial-size=5 +spring.datasource.admin.max-active=20 +spring.datasource.admin.max-wait=60000 +spring.datasource.admin.min-evictable-idle-time-millis=30000 +spring.datasource.admin.min-idle=5 +spring.datasource.admin.test-on-borrow=false +spring.datasource.admin.test-on-return=false +spring.datasource.admin.test-while-idle=true +spring.datasource.admin.time-between-eviction-runs-millis=60000 +spring.datasource.admin.validation-query=SELECT 1 FROM DUAL + +# 验证码类型: math-数组计算;char-字符验证 +sys.config.captchaType=math +# token配置 +# 令牌自定义标识 +sys.config.tokenHeader=Authorization +# 令牌密钥 +sys.config.tokenSecret=abcdefghijklmnopqrstuvwxyz +#认证中心系统编码 +sys.config.authSsoSysCode=auth-test +# 超级管理员用户(用户ID|用户名) +sys.config.supperAdminUser=1000|admin + +# 令牌有效期(默认180分钟) +sys.config.tokenExpireTime=180 +#统一认证中心登录地址 +sys.config.ssoLoginUrl=http://www.myauth.com:9528/login + +#文件上传目录 +# 文件路径 示例( Windows配置D:/xqiang/uploadPath,Linux配置 /home/xqiang/uploadPath) +sys.config.fileProfile=/Users/mengqiang/files/upload + + + +# 开发环境配置 +# 应用的访问路径 +server.servlet.context-path=/api/ +# tomcat的URI编码 +server.tomcat.uri-encoding=UTF-8 +# tomcat最大线程数,默认为200 +server.tomcat.max-threads=800 +# Tomcat启动初始化的线程数,默认值25 +server.tomcat.min-spare-threads=30 + +# Spring配置 +# 文件上传 +# 单个文件大小 +spring.servlet.multipart.max-file-size=10MB +# 设置总上传的文件大小 +spring.servlet.multipart.max-request-size=20MB diff --git a/sso-auth-center-service/sso-auth-center-admin/src/main/resources/logback-spring.xml b/sso-auth-center-service/sso-auth-center-admin/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..b5e6edd --- /dev/null +++ b/sso-auth-center-service/sso-auth-center-admin/src/main/resources/logback-spring.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + ${log.pattern} + + + + + + ${log.path}/sso-auth-center.log + + + + ${log.path}/sso-auth-center.log.%d{yyyy-MM-dd} + + 40 + + + ${log.pattern} + + + + 20MB + + + + + + + + + + + + + + + + + + diff --git a/sso-auth-center-service/sso-business/pom.xml b/sso-auth-center-service/sso-business/pom.xml new file mode 100755 index 0000000..b5fc1dd --- /dev/null +++ b/sso-auth-center-service/sso-business/pom.xml @@ -0,0 +1,34 @@ + + + + com.sso + sso-auth-center-service + 1.0.0 + + 4.0.0 + + sso-business + + + system系统模块 + + + + + + + com.sso + sso-common + + + + + com.sso + sso-framework + + + + + diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/RoleCountDTO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/RoleCountDTO.java new file mode 100644 index 0000000..5913081 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/RoleCountDTO.java @@ -0,0 +1,24 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 角色统计 + * + * @author 程序员小强 + */ +@Data +public class RoleCountDTO implements Serializable { + private static final long serialVersionUID = -9112752803214125220L; + + private Long roleId; + + private Integer count; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoOnlineUserDTO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoOnlineUserDTO.java new file mode 100644 index 0000000..a9b61bd --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoOnlineUserDTO.java @@ -0,0 +1,109 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 登录日志实体类 + * + * @author 程序员小强 + * @date 2021-01-23 10:45:22 + */ +@Data +public class SsoOnlineUserDTO implements Serializable { + + private static final long serialVersionUID = -8922037654548424632L; + + /** + * 用户ID + */ + private Long userId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 手机号码 + */ + private String phone; + + /** + * 密码 + */ + private String password; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 请求标识 + */ + private String requestId; + + /** + * 来源IP + */ + private String sourceIp; + + /** + * 来源地址 + */ + private String sourceAddress; + + /** + * 浏览器 + */ + private String browserName; + + /** + * 操作系统 + */ + private String operateSystem; + + /** + * 登录状态 0-成功;1-失败 + */ + private Integer status; + + /** + * 登录时间戳 + */ + private Long loginTime; + + /** + * 主动退出时间戳 + */ + private Long loginOutTime; + + /** + * 失效时间戳 + */ + private Long expireTime; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoUserDeptDTO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoUserDeptDTO.java new file mode 100644 index 0000000..5541ceb --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoUserDeptDTO.java @@ -0,0 +1,36 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 部门实体类 + * + * @author 程序员小强 + */ +@Data +public class SsoUserDeptDTO implements Serializable { + + private static final long serialVersionUID = -2778006438843424841L; + + /** + * 用户ID + */ + private Long userId; + + /** + * 部门ID + */ + private Long deptId; + + /** + * 部门名称 + */ + private String deptName; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoUserMgmtDTO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoUserMgmtDTO.java new file mode 100644 index 0000000..a776dc3 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoUserMgmtDTO.java @@ -0,0 +1,91 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 用户-系统管理 + * + * @author 程序员小强 + * @date 2021-01-02 17:20:41 + */ +@Data +public class SsoUserMgmtDTO implements Serializable { + + private static final long serialVersionUID = -7065547317808718215L; + + + private Long id; + + /** + * 用户ID + */ + private Long userId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 用户性别 0-男;1-女;2-未知 + */ + private Integer sex; + + /** + * 手机号码 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + /** + * 用户状态 0-正常;1-停用 + */ + private Integer userStatus; + + /** + * 关系状态 0-正常;1-停用 + */ + private Integer relationStatus; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoUserRoleDTO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoUserRoleDTO.java new file mode 100644 index 0000000..5a80a63 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/dto/SsoUserRoleDTO.java @@ -0,0 +1,36 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 用户角色 + * + * @author 程序员小强 + * @date 2020-12-27 18:07:20 + */ +@Data +public class SsoUserRoleDTO implements Serializable { + + private static final long serialVersionUID = 219537171519448483L; + /** + * 用户ID + */ + private Long userId; + + /** + * 角色id多个逗号分隔 + */ + private String roleIds; + + /** + * 角色名称多个逗号分隔 + */ + private String roleNames; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoDept.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoDept.java new file mode 100644 index 0000000..ee020b1 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoDept.java @@ -0,0 +1,84 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 部门实体类 + * + * @author 程序员小强 + * @date 2020-12-27 18:07:20 + */ +@Data +public class SsoDept implements Serializable { + + private static final long serialVersionUID = 4501341919143820458L; + + /** + * 部门ID + */ + private Long deptId; + + /** + * 部门名称 + */ + private String deptName; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 父部门ID + */ + private Long deptParentId; + + /** + * 顺序 + */ + private Integer sortNum; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 删除标志 0-正常;1-删除 + */ + private Integer delFlag; + + /** + * 备注 + */ + private String remarks; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoDeptTreePath.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoDeptTreePath.java new file mode 100644 index 0000000..0d106c0 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoDeptTreePath.java @@ -0,0 +1,34 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.entity; + +import lombok.Data; + +import java.io.Serializable; + + +/** + * 部门祖先/后代关系实体类 + * + * @author 程序员小强 + * @date 2020-12-27 18:07:20 + */ +@Data +public class SsoDeptTreePath implements Serializable { + + private static final long serialVersionUID = -8794488706755626248L; + + /** + * 祖先 + */ + private Long ancestor; + + /** + * 后代 + */ + private Long descendant; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoLoginLog.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoLoginLog.java new file mode 100644 index 0000000..e17a00e --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoLoginLog.java @@ -0,0 +1,84 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 登录日志实体类 + * + * @author 程序员小强 + * @date 2021-01-23 10:45:22 + */ +@Data +public class SsoLoginLog implements Serializable { + + private static final long serialVersionUID = -7814417622883518147L; + + /** + * ID + */ + private Long id; + + /** + * 请求标识 + */ + private String requestId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 来源IP + */ + private String sourceIp; + + /** + * 来源地址 + */ + private String sourceAddress; + + /** + * 浏览器 + */ + private String browserName; + + /** + * 操作系统 + */ + private String operateSystem; + + /** + * 登录状态 0-成功;1-失败 + */ + private Integer status; + + /** + * 登录时间戳 + */ + private Long loginTime; + + /** + * 返回结果 + */ + private String operateMsg; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoMenu.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoMenu.java new file mode 100644 index 0000000..967c46c --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoMenu.java @@ -0,0 +1,119 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 菜单权限实体类 + * + * @author 程序员小强 + * @date 2021-01-08 18:01:08 + */ +@Data +public class SsoMenu implements Serializable { + + private static final long serialVersionUID = -1115470419419879842L; + + /** + * 菜单ID + */ + private Long menuId; + + /** + * 菜单名称 + */ + private String menuName; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 菜单类型(M目录 C菜单 F按钮) + */ + private String menuType; + + /** + * 父菜单ID + */ + private Long menuParentId; + + /** + * 显示顺序 + */ + private Integer sortNum; + + /** + * 菜单路由地址 + */ + private String path; + + /** + * 菜单图标 + */ + private String icon; + + /** + * 组件路径 + */ + private String component; + + /** + * 权限标识,多个|分隔 + */ + private String permissions; + + /** + * 使用类型 0-授权访问;1-开放访问; + */ + private Integer useType; + + /** + * 是否显示 0-显示;1-隐藏 + */ + private Integer visible; + + /** + * 菜单状态 0-正常;1停用 + */ + private Integer status; + + /** + * 删除标志 0-正常;1-删除 + */ + private Integer delFlag; + + /** + * 备注 + */ + private String remarks; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoOnlineUser.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoOnlineUser.java new file mode 100644 index 0000000..8650c3e --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoOnlineUser.java @@ -0,0 +1,87 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 在线用户实体类 + * + * @author 程序员小强 + */ +@Data +public class SsoOnlineUser implements Serializable { + + private static final long serialVersionUID = 4271347681726609352L; + + /** + * ID + */ + private Long id; + + /** + * 请求标识 + */ + private String requestId; + + /** + * 用户ID + */ + private Long userId; + + /** + * 来源IP + */ + private String sourceIp; + + /** + * 来源地址 + */ + private String sourceAddress; + + /** + * 浏览器 + */ + private String browserName; + + /** + * 操作系统 + */ + private String operateSystem; + + /** + * 登录时间戳 + */ + private Long loginTime; + + /** + * 主动退出时间戳 + */ + private Long loginOutTime; + + /** + * 失效时间戳 + */ + private Long expireTime; + + /** + * 返回结果 + */ + private String operateMsg; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoRole.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoRole.java new file mode 100644 index 0000000..21c61ea --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoRole.java @@ -0,0 +1,84 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 角色信息实体类 + * + * @author 程序员小强 + * @date 2021-01-07 15:56:40 + */ +@Data +public class SsoRole implements Serializable { + + private static final long serialVersionUID = -9193130704066823912L; + + /** + * 角色ID + */ + private Long roleId; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 角色名称 + */ + private String roleName; + + /** + * 角色标识key + */ + private String roleKey; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 显示顺序 + */ + private Integer sortNum; + + /** + * 备注 + */ + private String remarks; + + /** + * 删除标志 0-正常;1-删除 + */ + private Integer delFlag; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoRoleMenu.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoRoleMenu.java new file mode 100644 index 0000000..68f81d6 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoRoleMenu.java @@ -0,0 +1,50 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 角色和菜单关系实体类 + * + * @author 程序员小强 + * @date 2021-01-08 18:01:08 + */ +@Data +public class SsoRoleMenu implements Serializable { + + private static final long serialVersionUID = -8633658293267783613L; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 角色ID + */ + private Long roleId; + + /** + * 菜单ID + */ + private Long menuId; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoSystem.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoSystem.java new file mode 100644 index 0000000..1995774 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoSystem.java @@ -0,0 +1,110 @@ +/** + * haifenbb.com + * Copyright (C) 2019-2020 All Rights Reserved. + */ +package com.sso.dao.entity; + +import lombok.Data; + +import java.io.Serializable; + + +/** + * 目标系统实体类 + * + * @author 程序员小强 + * @date 2020-12-27 10:59:43 + */ +@Data +public class SsoSystem implements Serializable { + + private static final long serialVersionUID = -4911126816387035L; + + /** + * 系统平台ID + */ + private Long sysId; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 系统名称 + */ + private String sysName; + + /** + * 系统权限编码 + */ + private String sysGrantCode; + + /** + * 系统链接 + */ + private String sysUrl; + + /** + * 系统图标 + */ + private String sysIcon; + + /** + * 系统环境 0-测试 1-beta 2-生产 + */ + private Integer sysEnv; + + /** + * 排序,数字越小排在越前面 + */ + private Integer sortNum; + + /** + * 签名类型 0-无;1-MD5;2-RSA; + */ + private Integer signType; + + /** + * 网关验签公钥 + */ + private String publicKey; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 备注 + */ + private String remarks; + + + /** + * 删除标志 0-正常;1-删除 + */ + private Integer delFlag; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private String createTime; + + /** + * 更新时间 + */ + private String updateTime; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoSystemManager.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoSystemManager.java new file mode 100644 index 0000000..b1de787 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoSystemManager.java @@ -0,0 +1,69 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 平台管理员关系实体类 + * + * @author 程序员小强 + * @date 2021-01-16 10:22:57 + */ +@Data +public class SsoSystemManager implements Serializable { + + private static final long serialVersionUID = 8221382605127103730L; + + /** + * ID + */ + private Long id; + + /** + * 用户ID + */ + private Long userId; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 状态 0-启用;1-停用 + */ + private Integer status; + + /** + * 删除标志 0-正常;1-删除 + */ + private Integer delFlag; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUser.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUser.java new file mode 100644 index 0000000..43d333e --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUser.java @@ -0,0 +1,113 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 用户实体类 + * + * @author 程序员小强 + * @date 2021-01-02 17:20:41 + */ +@Data +public class SsoUser implements Serializable { + + private static final long serialVersionUID = -3634941666611687795L; + + /** + * 用户ID + */ + private Long userId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 密码 + */ + private String password; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 用户性别 0-男;1-女;2-未知 + */ + private Integer sex; + + /** + * 手机号码 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + /** + * 头像 + */ + private String avatar; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 最后登录IP + */ + private String loginIp; + + /** + * 最后登录时间 + */ + private Date lastLoginTime; + + /** + * 删除标志 0-正常;1-删除 + */ + private Integer delFlag; + + /** + * 备注 + */ + private String remarks; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUserDept.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUserDept.java new file mode 100644 index 0000000..9df84cc --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUserDept.java @@ -0,0 +1,49 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 用户部门关系实体类 + * + * @author 程序员小强 + * @date 2021-01-02 17:20:41 + */ +@Data +public class SsoUserDept implements Serializable { + + private static final long serialVersionUID = -8391256763118936557L; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 用户ID + */ + private Long userId; + + /** + * 部门ID + */ + private Long deptId; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUserRole.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUserRole.java new file mode 100644 index 0000000..9f02497 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUserRole.java @@ -0,0 +1,49 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 用户和角色关联实体类 + * + * @author 程序员小强 + * @date 2021-01-08 15:41:48 + */ +@Data +public class SsoUserRole implements Serializable { + + private static final long serialVersionUID = -3171194295603566556L; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 用户ID + */ + private Long userId; + + /** + * 角色ID + */ + private Long roleId; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUserSystem.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUserSystem.java new file mode 100644 index 0000000..d8632dc --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/entity/SsoUserSystem.java @@ -0,0 +1,69 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 用户与目标系统关系实体类 + * + * @author 程序员小强 + * @date 2021-01-10 22:22:34 + */ +@Data +public class SsoUserSystem implements Serializable { + + private static final long serialVersionUID = -6154959745933571133L; + + /** + * 自增ID + */ + private Long id; + + /** + * 用户ID + */ + private Long userId; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 显示顺序 + */ + private Integer sortNum; + + /** + * 删除标志 0-正常;1-删除 + */ + private Integer delFlag; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoDeptMapper.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoDeptMapper.java new file mode 100644 index 0000000..4fa610e --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoDeptMapper.java @@ -0,0 +1,113 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.mapper; + + +import com.sso.dao.dto.SsoUserDeptDTO; +import com.sso.dao.entity.SsoDept; +import com.sso.dao.query.SsoDeptQuery; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 部门基础mapper + * + * @author 程序员小强 + * @date 2020-12-27 18:07:20 + */ +public interface SsoDeptMapper { + + /** + * 根据 部门ID 查询 + * + * @param deptId 部门ID + * @return 部门实体 + */ + SsoDept getByDeptId(Long deptId); + + /** + * 根据 系统编码与用户ID 查询 + * + * @param sysCode 用户ID + * @param userIdList 用户ID + * @return 部门实体 + */ + List getDeptBySysCodeAndUserIdList(@Param("sysCode") String sysCode, @Param("userIdList") List userIdList); + + /** + * 新增 + * + * @param ssoDept 部门实体 + * @return 新增的行数 + */ + int insert(SsoDept ssoDept); + + /** + * 动态参数新增 + * + * @param ssoDept 部门实体 + * @return 新增的行数 + */ + int insertSelective(SsoDept ssoDept); + + /** + * 根据自增主键编辑 + * + * @param ssoDept 部门实体 + * @return 编辑的行数 + */ + int updateByDeptId(SsoDept ssoDept); + + /** + * 更新所有父级的状态 + * + * @param ssoDept + * @return 编辑的行数 + */ + int updateAllParentStatus(SsoDept ssoDept); + + /** + * 根据自增主键动态参数编辑 + * + * @param ssoDept 部门实体 + * @return 编辑的行数 + */ + int updateByDeptIdSelective(SsoDept ssoDept); + + /** + * 根据条件-查询 + * + * @param query 过滤条件 + * @return 统计数 + */ + List listByCondition(SsoDeptQuery query); + + /** + * 根据条件统计 + * + * @param query 过滤条件 + * @return 统计数 + */ + int countByCondition(SsoDeptQuery query); + + /** + * 根据父部门ID与状态统计 + * + * @param deptParentId + * @param status + * @return 统计数 + */ + int countByDeptParentIdAndStatus(@Param("deptParentId") Long deptParentId, @Param("status") Integer status); + + /** + * 根据 系统编码 统计 + * + * @param syCode + * @return 统计数 + */ + int countBySysCode(@Param("sysCode") String syCode); + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoDeptTreePathMapper.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoDeptTreePathMapper.java new file mode 100644 index 0000000..af1c8bf --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoDeptTreePathMapper.java @@ -0,0 +1,61 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.mapper; + +import com.sso.dao.entity.SsoDept; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 部门祖先/后代关系 + * + * @author 程序员小强 + * @date 2020-12-27 18:07:20 + */ +public interface SsoDeptTreePathMapper { + + /** + * 插入新节点 + * + * @param deptId + * @param deptParentId + * @return 行数 + */ + int insertBatch(@Param("deptId") Long deptId, @Param("deptParentId") Long deptParentId); + + /** + * 删除叶子节点 + * + * @param deptId + * @return 行数 + */ + int deleteLeaf(Long deptId); + + /** + * 删除子树 + * + * @param deptId + * @return 行数 + */ + int deleteChildTree(Long deptId); + + /** + * 查询所有祖先 + * + * @param deptId + * @return 部门列表 + */ + List getAllParent(Long deptId); + + /** + * 查询所有后代 + * + * @param deptId + * @return 部门列表 + */ + List getAllChild(Long deptId); + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoLoginLogMapper.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoLoginLogMapper.java new file mode 100644 index 0000000..ff9fb01 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoLoginLogMapper.java @@ -0,0 +1,91 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.mapper; + +import com.sso.dao.entity.SsoLoginLog; +import com.sso.dao.query.LoginLogQuery; + +import java.util.List; + +/** + * 登录日志基础mapper接口 + * + * @author 程序员小强 + * @date 2021-01-23 10:45:22 + */ +public interface SsoLoginLogMapper { + + /** + * 根据 requestId 查询接口 + * + * @param requestId 自增主键 + * @return 登录日志实体 + * @date 20-01-19 10:45:22 + */ + SsoLoginLog getByRequestId(String requestId); + + /** + * 统计 + * + * @param query + * @return 统计值 + */ + int countByCondition(LoginLogQuery query); + + /** + * 查询列表 + * + * @param query + * @return 日志列表 + */ + List listPageByCondition(LoginLogQuery query); + + /** + * 新增接口 + * + * @param ssoLoginLog 登录日志实体 + * @return 新增的行数 + * @date 2021-01-23 10:45:22 + */ + int insert(SsoLoginLog ssoLoginLog); + + /** + * 动态参数新增接口 + * + * @param ssoLoginLog 登录日志实体 + * @return 新增的行数 + * @date 2021-01-23 10:45:22 + */ + int insertSelective(SsoLoginLog ssoLoginLog); + + /** + * 根据自增主键删除接口 + * + * @param id 自增主键主键 + * @return 删除的行数 + * @date 2021-01-23 10:45:22 + */ + int deleteByPrimaryKey(Long id); + + /** + * 根据自增主键编辑接口 + * + * @param ssoLoginLog 登录日志实体 + * @return 编辑的行数 + * @date 2021-01-23 10:45:22 + */ + int updateByPrimaryKey(SsoLoginLog ssoLoginLog); + + /** + * 根据自增主键动态参数编辑接口 + * + * @param ssoLoginLog 登录日志实体 + * @return 编辑的行数 + * @date 2021-01-23 10:45:22 + */ + int updateByPrimaryKeySelective(SsoLoginLog ssoLoginLog); + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoMenuMapper.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoMenuMapper.java new file mode 100644 index 0000000..2a3e0f2 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoMenuMapper.java @@ -0,0 +1,112 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.mapper; + +import com.sso.dao.entity.SsoMenu; +import com.sso.dao.query.SsoMenuQuery; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 菜单权限基础mapper + * + * @author 程序员小强 + * @date 2021-01-08 18:03:31 + */ +public interface SsoMenuMapper { + + /** + * 根据 menuId 查询 + * + * @param menuId 自增主键 + * @return 菜单权限 + */ + SsoMenu getByMenuId(Long menuId); + + /** + * 根据系统编码与角色名称查询 + * + * @param sysCode 系统编码 + * @param menuName 菜单名称 + * @return 角色信息 + */ + SsoMenu getBySysCodeAndName(@Param("sysCode") String sysCode, @Param("menuName") String menuName); + + /** + * 根据系统编码查询-未删除-并且启用的菜单 + * + * @param sysCode + * @return 权限集 + */ + List getEnableMenuListBySysCode(@Param("sysCode") String sysCode); + + /** + * 根据系统编码与用户ID查询权限查询-未删除-并且启用的菜单 + * + * @param sysCode + * @param userId + * @return 权限集 + */ + List getMenuListBySysCodeAndUserId(@Param("sysCode") String sysCode, @Param("userId") Long userId); + + /** + * 根据条件统计 + * + * @param query 过滤条件 + * @return 统计数 + */ + int countByCondition(SsoMenuQuery query); + + /** + * 根据条件-查询 + * + * @param query 过滤条件 + * @return 统计数 + */ + List listByCondition(SsoMenuQuery query); + + /** + * 新增 + * + * @param ssoMenu 菜单权限 + * @return 新增的行数 + */ + int insert(SsoMenu ssoMenu); + + /** + * 动态参数新增 + * + * @param ssoMenu 菜单权限 + * @return 新增的行数 + */ + int insertSelective(SsoMenu ssoMenu); + + /** + * 根据 菜单ID 编辑 + * + * @param ssoMenu 菜单权限 + * @return 编辑的行数 + */ + int updateByMenuId(SsoMenu ssoMenu); + + /** + * 根据 菜单ID 动态参数编辑 + * + * @param ssoMenu 菜单权限 + * @return 编辑的行数 + */ + int updateByMenuIdSelective(SsoMenu ssoMenu); + + /** + * 根据 系统编码 统计 + * + * @param syCode + * @return 统计数 + */ + int countBySysCode(@Param("sysCode") String syCode); + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoOnlineUserMapper.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoOnlineUserMapper.java new file mode 100644 index 0000000..1a8b669 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoOnlineUserMapper.java @@ -0,0 +1,111 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.mapper; + +import com.sso.dao.dto.SsoOnlineUserDTO; +import com.sso.dao.entity.SsoOnlineUser; +import com.sso.dao.query.UserOnlineQuery; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 在线用户基础mapper接口 + * + * @author 程序员小强 + * @date 2021-01-30 + */ +public interface SsoOnlineUserMapper { + + /** + * 根据 requestId 查询接口 + * + * @param requestId 请求标识 + * @return 在线用户实体 + * @date 2021-01-30 11:47:18 + */ + SsoOnlineUser getByRequestId(String requestId); + + /** + * 新增接口 + * + * @param ssoOnlineUser 在线用户实体 + * @return 新增的行数 + * @date 2021-01-30 11:47:18 + */ + int insert(SsoOnlineUser ssoOnlineUser); + + /** + * 动态参数新增接口 + * + * @param ssoOnlineUser 在线用户实体 + * @return 新增的行数 + * @date 2021-01-30 11:47:18 + */ + int insertSelective(SsoOnlineUser ssoOnlineUser); + + /** + * 根据自增主键删除接口 + * + * @param id 自增主键主键 + * @return 删除的行数 + * @date 2021-01-30 11:47:18 + */ + int deleteByPrimaryKey(Long id); + + /** + * 根据自增主键编辑接口 + * + * @param ssoOnlineUser 在线用户实体 + * @return 编辑的行数 + * @date 2021-01-30 11:47:18 + */ + int updateByPrimaryKey(SsoOnlineUser ssoOnlineUser); + + /** + * 根据自增主键动态参数编辑接口 + * + * @param ssoOnlineUser 在线用户实体 + * @return 编辑的行数 + * @date 2021-01-30 11:47:18 + */ + int updateByPrimaryKeySelective(SsoOnlineUser ssoOnlineUser); + + /** + * 统计 + * + * @param query + * @return 统计值 + */ + int countByCondition(UserOnlineQuery query); + + /** + * 查询列表 + * + * @param query + * @return 日志列表 + */ + List listPageByCondition(UserOnlineQuery query); + + /** + * 根据请求标识-刷新效期时间 + * + * @param requestId + * @param expireTime + * @return + */ + int refreshExpireTimeByRequestId(@Param("requestId") String requestId, @Param("expireTime") Long expireTime); + + /** + * 退出时-根据请求标识-更新效期时间 + * + * @param requestId + * @param expireTime + * @param loginOutTime + * @return + */ + int updateByLogoOut(@Param("requestId") String requestId, @Param("expireTime") Long expireTime, @Param("loginOutTime") Long loginOutTime); + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoRoleMapper.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoRoleMapper.java new file mode 100644 index 0000000..5835c65 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoRoleMapper.java @@ -0,0 +1,112 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.mapper; + +import com.sso.dao.entity.SsoRole; +import com.sso.dao.query.SsoRoleQuery; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 角色信息mapper + * + * @author 程序员小强 + * @date 2021-01-07 15:56:40 + */ +public interface SsoRoleMapper { + + /** + * 根据 角色ID 查询 + * + * @param roleId 角色ID + * @return 角色信息 + */ + SsoRole getByRoleId(Long roleId); + + /** + * 根据系统编码与角色名称查询 + * + * @param sysCode 系统编码 + * @param roleName 角色名称 + * @return 角色信息 + */ + SsoRole getBySysCodeAndName(@Param("sysCode") String sysCode, @Param("roleName") String roleName); + + /** + * 根据系统编码与角色key查询 + * + * @param sysCode 系统编码 + * @param roleKey 角色名称 + * @return 角色信息 + */ + SsoRole getBySysCodeAndRoleKey(@Param("sysCode") String sysCode, @Param("roleKey") String roleKey); + + /** + * 根据 系统编码 与 用户ID查询角色key + * + * @param sysCode 系统编码 + * @param userId 用户ID + * @return 角色信息 + */ + List getRoleKeyBySysCodeAndUserId(@Param("sysCode") String sysCode, @Param("userId") Long userId); + + /** + * 根据条件统计 + * + * @param query 过滤条件 + * @return 统计数 + */ + int countByCondition(SsoRoleQuery query); + + /** + * 根据条件-查询 + * + * @param query 过滤条件 + * @return 统计数 + */ + List listPageByCondition(SsoRoleQuery query); + + /** + * 新增 + * + * @param ssoRole 角色信息实体 + * @return 新增的行数 + */ + int insert(SsoRole ssoRole); + + /** + * 动态参数新增 + * + * @param ssoRole 角色信息实体 + * @return 新增的行数 + */ + int insertSelective(SsoRole ssoRole); + + /** + * 根据自增主键编辑 + * + * @param ssoRole 角色信息 + * @return 编辑的行数 + */ + int updateByRoleId(SsoRole ssoRole); + + /** + * 根据自增主键动态参数编辑 + * + * @param ssoRole 角色信息 + * @return 编辑的行数 + */ + int updateByRoleIdSelective(SsoRole ssoRole); + + /** + * 根据 系统编码 统计 + * + * @param syCode + * @return 统计数 + */ + int countBySysCode(@Param("sysCode") String syCode); + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoRoleMenuMapper.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoRoleMenuMapper.java new file mode 100644 index 0000000..84413dd --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoRoleMenuMapper.java @@ -0,0 +1,86 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.mapper; + + +import com.sso.dao.entity.SsoRoleMenu; + +import java.util.List; + +/** + * 角色和菜单关系基础mapper + * + * @author 程序员小强 + * @date 2021-01-08 18:03:32 + */ +public interface SsoRoleMenuMapper { + + /** + * 根据自增主键id查询 + * + * @param roleId 角色ID + * @return 角色和菜单关系 + */ + List getMenuIdListByRoleId(Long roleId); + + /** + * 批量新增 + * + * @param list + * @return 新增的行数 + */ + int batchSave(List list); + + + /** + * 新增 + * + * @param ssoRoleMenu 角色和菜单关系 + * @return 新增的行数 + */ + int insert(SsoRoleMenu ssoRoleMenu); + + /** + * 动态参数新增 + * + * @param ssoRoleMenu 角色和菜单关系 + * @return 新增的行数 + */ + int insertSelective(SsoRoleMenu ssoRoleMenu); + + /** + * 根据 roleId 删除 + * + * @param roleId 角色ID + * @return 删除的行数 + */ + int deleteByRoleId(Long roleId); + + /** + * 根据 menuId 删除 + * + * @param menuId 菜单ID + * @return 删除的行数 + */ + int deleteByMenuId(Long menuId); + + /** + * 根据自增主键编辑 + * + * @param ssoRoleMenu 角色和菜单关系 + * @return 编辑的行数 + */ + int updateByPrimaryKey(SsoRoleMenu ssoRoleMenu); + + /** + * 根据自增主键动态参数编辑 + * + * @param ssoRoleMenu 角色和菜单关系 + * @return 编辑的行数 + */ + int updateByPrimaryKeySelective(SsoRoleMenu ssoRoleMenu); + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoSystemManagerMapper.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoSystemManagerMapper.java new file mode 100644 index 0000000..b14237f --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoSystemManagerMapper.java @@ -0,0 +1,100 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.mapper; + + +import com.sso.dao.dto.SsoUserMgmtDTO; +import com.sso.dao.entity.SsoSystemManager; +import com.sso.dao.query.SystemMgmtPageQuery; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 平台管理员关系基础mapper + * + * @author 程序员小强 + * @date 2021-01-16 10:22:57 + */ +public interface SsoSystemManagerMapper { + + /** + * 根据自增主键id查询 + * + * @param id 自增主键 + * @return SsoSystemManager + * @date 2021-01-16 10:22:57 + */ + SsoSystemManager getById(Long id); + + /** + * 根据-系统编码和用户ID查询 + * + * @param sysCode 自增主键 + * @param userId 自增主键 + * @return SsoSystemManager + * @date 2021-01-16 10:22:57 + */ + SsoSystemManager getBySysCodeAndUserId(@Param("sysCode") String sysCode, @Param("userId") Long userId); + + /** + * 根据-自增主键id统计 + * + * @param sysCode 自增主键 + * @param userId 自增主键 + * @return SsoSystemManager + * @date 2021-01-16 10:22:57 + */ + int countBySysCodeAndUserId(@Param("sysCode") String sysCode, @Param("userId") Long userId); + + /** + * 统计-平台管理员用户 + * + * @param query 用户 + * @return 用户集合 + */ + int countSysMgmtUser(SystemMgmtPageQuery query); + + /** + * 查询平台管理员用户列表 + * + * @param query 用户 + * @return 用户集合 + */ + List listPageSysMgmtUser(SystemMgmtPageQuery query); + + /** + * 新增 + * + * @param ssoSystemManager + * @return 新增的行数 + */ + int insert(SsoSystemManager ssoSystemManager); + + /** + * 动态参数新增 + * + * @param ssoSystemManager + * @return 新增的行数 + */ + int insertSelective(SsoSystemManager ssoSystemManager); + + /** + * 根据 自增ID 编辑 + * + * @param ssoSystemManager + * @return 编辑的行数 + */ + int updateById(SsoSystemManager ssoSystemManager); + + /** + * 根据用户ID与系统编码更新 + * + * @param ssoSystemManager + * @return 编辑的行数 + */ + int updateBySysCodeAndUserId(SsoSystemManager ssoSystemManager); + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoSystemMapper.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoSystemMapper.java new file mode 100644 index 0000000..97fc478 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoSystemMapper.java @@ -0,0 +1,128 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.mapper; + + +import com.sso.dao.entity.SsoSystem; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 目标系统基础mapper + * + * @author 程序员小强 + * @date 2020-12-27 10:59:43 + */ +public interface SsoSystemMapper { + + /** + * 根据系统编码-查询 + * + * @param sysId 系统ID + * @return 目标系统实体 + */ + SsoSystem getBySysId(@Param("sysId") Long sysId); + + /** + * 根据系统编码-查询 + * + * @param sysCode 系统编码 + * @return 目标系统实体 + */ + SsoSystem getBySysCode(@Param("sysCode") String sysCode); + + /** + * 根据系统编码集-查询 + * + * @param sysCodeList 系统编码集 + * @return 目标系统实体 + */ + List getBySysCodeList(@Param("sysCodeList") List sysCodeList); + + /** + * 根据状态查询 + * + * @param statusList + * @return 目标系统实体 + */ + List listByStatusList(@Param("statusList") List statusList); + + /** + * 根据用户ID查询-管理员权限的系统 + * + * @param userId + * @return 目标系统实体 + */ + List listMySystemByAdmin(@Param("userId") Long userId, @Param("statusList") List statusList); + + /** + * 根据用户ID查询-拥有跳转权限的系统 + * + * @param userId + * @return 目标系统实体 + */ + List listMySystemByUserId(@Param("userId") Long userId); + + /** + * 根据用户ID查询-拥有管理权限的系统平台 + * + * @param userId + * @return 目标系统实体 + */ + List listSystemMgmtByUserId(@Param("userId") Long userId); + + /** + * 新增 + * + * @param ssoSystem 目标系统实体 + * @return 新增的行数 + */ + int insert(SsoSystem ssoSystem); + + /** + * 动态参数新增 + * + * @param ssoSystem 目标系统实体 + * @return 新增的行数 + */ + int insertSelective(SsoSystem ssoSystem); + + /** + * 根据 sysId 编辑 + * + * @param ssoSystem 目标系统实体 + * @return 编辑的行数 + */ + int updateBySysId(SsoSystem ssoSystem); + + /** + * 根据 sysId 修改秘钥属性 + * + * @param ssoSystem 目标系统实体 + * @return 编辑的行数 + */ + int updateSecretBySysId(SsoSystem ssoSystem); + + /** + * 修改图标 + * + * @param sysId 系统ID + * @param sysIcon 头像地址 + * @param updateBy 最后修改人 + * @return 编辑的行数 + */ + int updateIconBySysId(@Param("sysId") Long sysId, @Param("sysIcon") String sysIcon, @Param("updateBy") String updateBy); + + /** + * 根据自增主键动态参数编辑 + * + * @param ssoSystem 目标系统实体 + * @return 编辑的行数 + */ + int updateBySysIdSelective(SsoSystem ssoSystem); + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserDeptMapper.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserDeptMapper.java new file mode 100644 index 0000000..cb6cd5a --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserDeptMapper.java @@ -0,0 +1,85 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.mapper; + +import com.sso.dao.entity.SsoUserDept; +import org.apache.ibatis.annotations.Param; + +/** + * 用户部门关系基础mapper + * + * @author 程序员小强 + * @date 2021-01-02 17:20:41 + */ +public interface SsoUserDeptMapper { + + /** + * 根据 系统编码与用户ID 查询 + * + * @param sysCode 系统编码 + * @param userId 用户ID + * @return 用户部门关系实体 + */ + SsoUserDept getDeptBySysCodeAndUserId(@Param("sysCode") String sysCode, @Param("userId") Long userId); + + /** + * 新增 + * + * @param ssoUserDept 用户部门关系实体 + * @return 新增的行数 + */ + int insert(SsoUserDept ssoUserDept); + + /** + * 动态参数新增 + * + * @param ssoUserDept 用户部门关系实体 + * @return 新增的行数 + */ + int insertSelective(SsoUserDept ssoUserDept); + + /** + * 根据 系统编码与 用户ID 删除 + * + * @param sysCode 系统编码 + * @param userId 用户ID + * @return 删除的行数 + */ + int deleteBySysCodeAndUserId(@Param("sysCode") String sysCode, @Param("userId") Long userId); + + /** + * 根据 系统编码与 部门ID 删除 + * + * @param sysCode 系统编码 + * @param deptId 部门ID + * @return 删除的行数 + */ + int deleteBySysCodeAndDeptId(@Param("sysCode") String sysCode, @Param("deptId") Long deptId); + + /** + * 根据自增主键编辑 + * + * @param ssoUserDept 用户部门关系实体 + * @return 编辑的行数 + */ + int updateByPrimaryKey(SsoUserDept ssoUserDept); + + /** + * 根据自增主键动态参数编辑 + * + * @param ssoUserDept 用户部门关系实体 + * @return 编辑的行数 + */ + int updateByPrimaryKeySelective(SsoUserDept ssoUserDept); + + /** + * 根据部门ID统计 + * + * @param deptId + * @return 统计行数 + */ + int countByDeptId(Long deptId); + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserMapper.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserMapper.java new file mode 100644 index 0000000..411b729 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserMapper.java @@ -0,0 +1,159 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.mapper; + + +import com.sso.dao.entity.SsoUser; +import com.sso.dao.query.UserPageQuery; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; +import java.util.List; + +/** + * 用户基础mapper + * + * @author 程序员小强 + * @date 2021-01-02 17:20:41 + */ +public interface SsoUserMapper { + + /** + * 根据 userId 查询 + * + * @param userId 用户ID + * @return 用户信息 + */ + SsoUser getByUserId(Long userId); + + /** + * 根据用户名-查询 + * + * @param userName 用户 + * @return 用户 + */ + SsoUser getByUserName(String userName); + + /** + * 根据手机号-查询 + * + * @param phone 用户手机号 + * @return 用户 + */ + SsoUser getByPhone(String phone); + + /** + * 根据邮箱-查询 + * + * @param email 用户邮箱 + * @return 用户 + */ + SsoUser getByEmail(String email); + + /** + * 根据手机号或用户名-查询 + * + * @param keywords 关键字 + * @param limit + * @return 用户 + */ + List listByPhoneOrUserNameLike(@Param("keywords") String keywords, @Param("limit") Integer limit); + + /** + * 统计用户 + * + * @param query 用户 + * @return 用户集合 + */ + int countByCondition(UserPageQuery query); + + /** + * 查询用户列表 + * + * @param query 用户 + * @return 用户集合 + */ + List listPageByCondition(UserPageQuery query); + + /** + * 根据自增主键id查询 + * + * @param id 自增主键 + * @return 用户实体 + */ + SsoUser selectByPrimaryKey(Long id); + + /** + * 新增 + * + * @param ssoUser 用户实体 + * @return 新增的行数 + */ + int insert(SsoUser ssoUser); + + /** + * 动态参数新增 + * + * @param ssoUser 用户实体 + * @return 新增的行数 + */ + int insertSelective(SsoUser ssoUser); + + /** + * 根据 用户ID 编辑 + * + * @param ssoUser 用户实体 + * @return 编辑的行数 + */ + int updateByUserId(SsoUser ssoUser); + + /** + * 修改个人信息 + * + * @param ssoUser 用户实体 + * @return 编辑的行数 + */ + int updateProfileByUserId(SsoUser ssoUser); + + /** + * 更新 + * + * @param userId 用户userId + * @param loginIp 用户loginIp + * @param lastLoginTime 登录时间 + * @return 编辑的行数 + */ + int updateLastLogin(@Param("userId") Long userId, @Param("loginIp") String loginIp, @Param("lastLoginTime") Date lastLoginTime); + + /** + * 修改密码 + * + * @param userId 用户ID + * @param password 密码 + * @param updateBy 最后修改人 + * @return 编辑的行数 + */ + int updatePwd(@Param("userId") Long userId, @Param("password") String password, @Param("updateBy") String updateBy); + + /** + * 修改头像 + * + * @param userId 用户ID + * @param avatar 头像地址 + * @param updateBy 最后修改人 + * @return 编辑的行数 + */ + int updateAvatar(@Param("userId") Long userId, @Param("avatar") String avatar, @Param("updateBy") String updateBy); + + /** + * 根据自增主键动态参数编辑 + * + * @param ssoUser 用户实体 + * @return 编辑的行数 + */ + int updateByUserIdSelective(SsoUser ssoUser); + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserRoleMapper.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserRoleMapper.java new file mode 100644 index 0000000..5aac727 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserRoleMapper.java @@ -0,0 +1,121 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.mapper; + +import com.sso.dao.dto.RoleCountDTO; +import com.sso.dao.dto.SsoUserRoleDTO; +import com.sso.dao.entity.SsoUserRole; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 用户和角色关联基础mapper + * + * @author 程序员小强 + * @date 2021-01-08 15:41:48 + */ +public interface SsoUserRoleMapper { + + /** + * 根据自增主键id查询 + * + * @param id 自增主键 + * @return 用户和角色关联实体 + */ + SsoUserRole selectByPrimaryKey(Long id); + + /** + * 根据系统编码 与用户ID 查询角色ID + * + * @param sysCode + * @param userId + * @return 角色ID集 + */ + List getRoleIdListBySysCodeAndUserId(@Param("sysCode") String sysCode, @Param("userId") Long userId); + + /** + * 根据 系统编码与用户ID 查询 + * + * @param sysCode 用户ID + * @param userIdList 用户ID + * @return 部门实体 + */ + List getRoleBySysCodeAndUserIdList(@Param("sysCode") String sysCode, @Param("userIdList") List userIdList); + + /** + * 新增 + * + * @param ssoUserRole 用户和角色关联实体 + * @return 新增的行数 + */ + int insert(SsoUserRole ssoUserRole); + + /** + * 动态参数新增 + * + * @param ssoUserRole 用户和角色关联实体 + * @return 新增的行数 + */ + int insertSelective(SsoUserRole ssoUserRole); + + /** + * 批量新增 + * + * @param list + * @return + */ + int batchSave(List list); + + /** + * 根据用户ID删除 + * + * @param sysCode 系统编码 + * @param userId 用户ID + * @return 删除的行数 + */ + int deleteBySysCodeAndUserId(@Param("sysCode") String sysCode, @Param("userId") Long userId); + + /** + * 根据用户ID删除 + * + * @param roleId 角色ID + * @param userId 用户ID + * @return 删除的行数 + */ + int deleteByRoleIdAndUserId(@Param("roleId") Long roleId, @Param("userId") Long userId); + + /** + * 根据自增主键编辑 + * + * @param ssoUserRole 用户和角色关联实体 + * @return 编辑的行数 + */ + int updateByPrimaryKey(SsoUserRole ssoUserRole); + + /** + * 根据自增主键动态参数编辑 + * + * @param ssoUserRole 用户和角色关联实体 + * @return 编辑的行数 + */ + int updateByPrimaryKeySelective(SsoUserRole ssoUserRole); + + /** + * 根据 角色ID 统计 + * + * @param roleId 角色ID + * @return 统计数 + */ + int countByRoleId(Long roleId); + + /** + * 根据 角色ID 统计 + * + * @param roleIdList 角色ID集 + * @return 统计数 + */ + List countByRoleIdList(@Param("roleIdList") List roleIdList); +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserSystemMapper.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserSystemMapper.java new file mode 100644 index 0000000..6aeddaa --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/mapper/SsoUserSystemMapper.java @@ -0,0 +1,95 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.mapper; + +import com.sso.dao.entity.SsoUserSystem; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 用户与目标系统关系基础mapper接口 + * + * @author 程序员小强 + * @date 2021-01-10 22:22:34 + */ +public interface SsoUserSystemMapper { + + /** + * 根据用户ID与 系统编码查询 + * + * @param userId 用户ID + * @param sysCode 系统编码 + * @return 用户与目标系统关系实体 + */ + SsoUserSystem getByUserIdAndSysCode(@Param("userId") Long userId, @Param("sysCode") String sysCode); + + /** + * 根据用户ID集 与 系统编码查询 + * + * @param userIdList 用户ID集 + * @param sysCode 系统编码 + * @return 用户与目标系统关系实体 + */ + List listBySysCodeAndUserIdList(@Param("sysCode") String sysCode, @Param("userIdList") List userIdList); + + /** + * 新增接口 + * + * @param ssoUserSystem 用户与目标系统关系实体 + * @return 新增的行数 + */ + int insert(SsoUserSystem ssoUserSystem); + + /** + * 动态参数新增接口 + * + * @param ssoUserSystem 用户与目标系统关系实体 + * @return 新增的行数 + */ + int insertSelective(SsoUserSystem ssoUserSystem); + + /** + * 根据自增主键删除接口 + * + * @param id 自增主键主键 + * @return 删除的行数 + */ + int deleteByPrimaryKey(Long id); + + /** + * 根据自增主键编辑接口 + * + * @param ssoUserSystem 用户与目标系统关系实体 + * @return 编辑的行数 + */ + int updateById(SsoUserSystem ssoUserSystem); + + /** + * 根据自增主键动态参数编辑接口 + * + * @param ssoUserSystem 用户与目标系统关系实体 + * @return 编辑的行数 + */ + int updateByIdSelective(SsoUserSystem ssoUserSystem); + + /** + * 根据自增主键动态参数编辑接口 + * + * @param ssoUserSystem 用户与目标系统关系实体 + * @return 编辑的行数 + */ + int updateBySysCodeAndUserIdSelective(SsoUserSystem ssoUserSystem); + + /** + * 根据 系统编码 统计 + * + * @param syCode + * @return 统计数 + */ + int countBySysCode(@Param("sysCode") String syCode); + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/LoginLogQuery.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/LoginLogQuery.java new file mode 100755 index 0000000..60f6807 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/LoginLogQuery.java @@ -0,0 +1,89 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.query; + +import com.sso.common.model.page.BasePageQuery; + +/** + * 登录日志分页查询bo + * + * @author 程序员小强 + */ +public class LoginLogQuery extends BasePageQuery { + + private static final long serialVersionUID = -7137359307341275655L; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 用户登录名 + */ + private String usernameLike; + + /** + * 登录状态 0-成功;1-失败 + */ + private Integer status; + + /** + * 登录开始时间 + */ + private Long loginStartTime; + + /** + * 登录截止时间 + */ + private Long loginEndTime; + + + public String getSysCode() { + return sysCode; + } + + public LoginLogQuery setSysCode(String sysCode) { + this.sysCode = sysCode; + return this; + } + + public String getUsernameLike() { + return usernameLike; + } + + public LoginLogQuery setUsernameLike(String usernameLike) { + this.usernameLike = usernameLike; + return this; + } + + public Integer getStatus() { + return status; + } + + public LoginLogQuery setStatus(Integer status) { + this.status = status; + return this; + } + + public Long getLoginStartTime() { + return loginStartTime; + } + + public LoginLogQuery setLoginStartTime(Long loginStartTime) { + this.loginStartTime = loginStartTime; + return this; + } + + public Long getLoginEndTime() { + return loginEndTime; + } + + public LoginLogQuery setLoginEndTime(Long loginEndTime) { + this.loginEndTime = loginEndTime; + return this; + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SsoDeptQuery.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SsoDeptQuery.java new file mode 100755 index 0000000..ba5c281 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SsoDeptQuery.java @@ -0,0 +1,117 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.query; + +import com.sso.common.model.page.BasePageQuery; + +/** + * 部门查询 + * mapper 层 xml 入参 + * + * @author 程序员小强 + */ +public class SsoDeptQuery extends BasePageQuery { + + private static final long serialVersionUID = 9032669004611549658L; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 父部门ID + */ + private Long deptParentId; + + /** + * 需要排除的-部门ID + */ + private Long excludeDeptId; + + /** + * 部门名称 + */ + private String deptName; + + /** + * 部门右模糊 + */ + private String deptNameLike; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 删除标志 0-正常;1-删除 + */ + private Integer delFlag; + + + public String getSysCode() { + return sysCode; + } + + public SsoDeptQuery setSysCode(String sysCode) { + this.sysCode = sysCode; + return this; + } + + public Long getDeptParentId() { + return deptParentId; + } + + public SsoDeptQuery setDeptParentId(Long deptParentId) { + this.deptParentId = deptParentId; + return this; + } + + public Long getExcludeDeptId() { + return excludeDeptId; + } + + public SsoDeptQuery setExcludeDeptId(Long excludeDeptId) { + this.excludeDeptId = excludeDeptId; + return this; + } + + public String getDeptName() { + return deptName; + } + + public SsoDeptQuery setDeptName(String deptName) { + this.deptName = deptName; + return this; + } + + public String getDeptNameLike() { + return deptNameLike; + } + + public SsoDeptQuery setDeptNameLike(String deptNameLike) { + this.deptNameLike = deptNameLike; + return this; + } + + public Integer getStatus() { + return status; + } + + public SsoDeptQuery setStatus(Integer status) { + this.status = status; + return this; + } + + public Integer getDelFlag() { + return delFlag; + } + + public SsoDeptQuery setDelFlag(Integer delFlag) { + this.delFlag = delFlag; + return this; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SsoMenuQuery.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SsoMenuQuery.java new file mode 100755 index 0000000..d0d2aa7 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SsoMenuQuery.java @@ -0,0 +1,117 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.query; + + +import com.sso.common.model.page.BasePageQuery; + +/** + * 菜单查询 + * mapper 层 xml 入参 + * + * @author 程序员小强 + */ +public class SsoMenuQuery extends BasePageQuery { + + private static final long serialVersionUID = -4210187210718040578L; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 父菜单ID + */ + private Long menuParentId; + + /** + * 需要排除的-菜单ID + */ + private Long excludeMenuId; + + /** + * 菜单名称 + */ + private String menuName; + + /** + * 菜单名称右模糊 + */ + private String menuNameLike; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 删除标志 0-正常;1-删除 + */ + private Integer delFlag; + + public String getSysCode() { + return sysCode; + } + + public SsoMenuQuery setSysCode(String sysCode) { + this.sysCode = sysCode; + return this; + } + + public Long getMenuParentId() { + return menuParentId; + } + + public SsoMenuQuery setMenuParentId(Long menuParentId) { + this.menuParentId = menuParentId; + return this; + } + + public Long getExcludeMenuId() { + return excludeMenuId; + } + + public SsoMenuQuery setExcludeMenuId(Long excludeMenuId) { + this.excludeMenuId = excludeMenuId; + return this; + } + + public String getMenuName() { + return menuName; + } + + public SsoMenuQuery setMenuName(String menuName) { + this.menuName = menuName; + return this; + } + + public String getMenuNameLike() { + return menuNameLike; + } + + public SsoMenuQuery setMenuNameLike(String menuNameLike) { + this.menuNameLike = menuNameLike; + return this; + } + + public Integer getStatus() { + return status; + } + + public SsoMenuQuery setStatus(Integer status) { + this.status = status; + return this; + } + + public Integer getDelFlag() { + return delFlag; + } + + public SsoMenuQuery setDelFlag(Integer delFlag) { + this.delFlag = delFlag; + return this; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SsoRoleQuery.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SsoRoleQuery.java new file mode 100755 index 0000000..491e5bb --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SsoRoleQuery.java @@ -0,0 +1,127 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.query; + + +import com.sso.common.model.page.BasePageModel; +import com.sso.common.model.page.BasePageQuery; + +/** + * 角色查询 + * mapper 层 xml 入参 + * + * @author 程序员小强 + */ +public class SsoRoleQuery extends BasePageQuery { + + private static final long serialVersionUID = 4663369561352780923L; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 需要排除的角色ID + */ + private Long excludeRoleId; + + /** + * 角色名称 + */ + private String roleName; + + /** + * 角色名称 右模糊 + */ + private String roleNameLike; + + /** + * 角色key 右模糊 + */ + private String roleKeyLike; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 删除标志 0-正常;1-删除 + */ + private Integer delFlag; + + public SsoRoleQuery() { + } + + + public SsoRoleQuery(BasePageModel pageModel) { + this.setPage(pageModel.getPage()); + this.setPageSize(pageModel.getPageSize()); + } + + public String getSysCode() { + return sysCode; + } + + public SsoRoleQuery setSysCode(String sysCode) { + this.sysCode = sysCode; + return this; + } + + public Long getExcludeRoleId() { + return excludeRoleId; + } + + public SsoRoleQuery setExcludeRoleId(Long excludeRoleId) { + this.excludeRoleId = excludeRoleId; + return this; + } + + public String getRoleName() { + return roleName; + } + + public SsoRoleQuery setRoleName(String roleName) { + this.roleName = roleName; + return this; + } + + public String getRoleNameLike() { + return roleNameLike; + } + + public SsoRoleQuery setRoleNameLike(String roleNameLike) { + this.roleNameLike = roleNameLike; + return this; + } + + public String getRoleKeyLike() { + return roleKeyLike; + } + + public SsoRoleQuery setRoleKeyLike(String roleKeyLike) { + this.roleKeyLike = roleKeyLike; + return this; + } + + public Integer getStatus() { + return status; + } + + public SsoRoleQuery setStatus(Integer status) { + this.status = status; + return this; + } + + public Integer getDelFlag() { + return delFlag; + } + + public SsoRoleQuery setDelFlag(Integer delFlag) { + this.delFlag = delFlag; + return this; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SystemMgmtPageQuery.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SystemMgmtPageQuery.java new file mode 100755 index 0000000..b412926 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/SystemMgmtPageQuery.java @@ -0,0 +1,129 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.query; + +import com.sso.common.model.page.BasePageQuery; + +/** + * 系统管理员权限-分页查询bo + * + * @author 程序员小强 + */ +public class SystemMgmtPageQuery extends BasePageQuery { + + private static final long serialVersionUID = 7588427768619166745L; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 用户登录名 + */ + private String usernameLike; + + /** + * 用户昵称 + */ + private String nickNameLike; + + /** + * 真实姓名 + */ + private String realNameLike; + + /** + * 手机号码 + */ + private String phoneLike; + + /** + * 用户状态 0-正常;1-停用 + */ + private Integer userStatus; + + /** + * 绑定关系状态 0-正常;1-停用 + */ + private Integer relationStatus; + + /** + * 删除标志 0-正常;1-删除 + */ + private Integer delFlag; + + public String getSysCode() { + return sysCode; + } + + public SystemMgmtPageQuery setSysCode(String sysCode) { + this.sysCode = sysCode; + return this; + } + + public String getUsernameLike() { + return usernameLike; + } + + public SystemMgmtPageQuery setUsernameLike(String usernameLike) { + this.usernameLike = usernameLike; + return this; + } + + public String getNickNameLike() { + return nickNameLike; + } + + public SystemMgmtPageQuery setNickNameLike(String nickNameLike) { + this.nickNameLike = nickNameLike; + return this; + } + + public String getRealNameLike() { + return realNameLike; + } + + public SystemMgmtPageQuery setRealNameLike(String realNameLike) { + this.realNameLike = realNameLike; + return this; + } + + public String getPhoneLike() { + return phoneLike; + } + + public SystemMgmtPageQuery setPhoneLike(String phoneLike) { + this.phoneLike = phoneLike; + return this; + } + + public Integer getUserStatus() { + return userStatus; + } + + public SystemMgmtPageQuery setUserStatus(Integer userStatus) { + this.userStatus = userStatus; + return this; + } + + public Integer getRelationStatus() { + return relationStatus; + } + + public SystemMgmtPageQuery setRelationStatus(Integer relationStatus) { + this.relationStatus = relationStatus; + return this; + } + + public Integer getDelFlag() { + return delFlag; + } + + public SystemMgmtPageQuery setDelFlag(Integer delFlag) { + this.delFlag = delFlag; + return this; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/UserOnlineQuery.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/UserOnlineQuery.java new file mode 100755 index 0000000..e8345f3 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/UserOnlineQuery.java @@ -0,0 +1,87 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.query; + +import com.sso.common.model.page.BasePageQuery; + +/** + * 在线用户分页查询bo + * + * @author 程序员小强 + */ +public class UserOnlineQuery extends BasePageQuery { + + private static final long serialVersionUID = 6745860184771356374L; + + /** + * 用户登录名 + */ + private String usernameLike; + + /** + * 手机号 + */ + private String phoneLike; + + /** + * 效期开始时间 + */ + private Long expireStartTime; + + /** + * 登录开始时间 + */ + private Long loginStartTime; + + /** + * 登录截止时间 + */ + private Long loginEndTime; + + public String getUsernameLike() { + return usernameLike; + } + + public UserOnlineQuery setUsernameLike(String usernameLike) { + this.usernameLike = usernameLike; + return this; + } + + public String getPhoneLike() { + return phoneLike; + } + + public UserOnlineQuery setPhoneLike(String phoneLike) { + this.phoneLike = phoneLike; + return this; + } + + public Long getExpireStartTime() { + return expireStartTime; + } + + public UserOnlineQuery setExpireStartTime(Long expireStartTime) { + this.expireStartTime = expireStartTime; + return this; + } + + public Long getLoginStartTime() { + return loginStartTime; + } + + public UserOnlineQuery setLoginStartTime(Long loginStartTime) { + this.loginStartTime = loginStartTime; + return this; + } + + public Long getLoginEndTime() { + return loginEndTime; + } + + public UserOnlineQuery setLoginEndTime(Long loginEndTime) { + this.loginEndTime = loginEndTime; + return this; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/UserPageQuery.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/UserPageQuery.java new file mode 100755 index 0000000..b50b343 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/dao/query/UserPageQuery.java @@ -0,0 +1,129 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.dao.query; + +import com.sso.common.model.page.BasePageQuery; + +/** + * 用户分页查询bo + * + * @author 程序员小强 + */ +public class UserPageQuery extends BasePageQuery { + + private static final long serialVersionUID = -7892866355117742382L; + + /** + * 用户登录名 + */ + private String usernameLike; + + /** + * 用户昵称 + */ + private String nickNameLike; + + /** + * 真实姓名 + */ + private String realNameLike; + + /** + * 手机号码 + */ + private String phoneLike; + + /** + * 所属部门ID + */ + private Long deptId; + + /** + * 角色ID + */ + private Long roleId; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 删除标志 0-正常;1-删除 + */ + private Integer delFlag; + + public String getUsernameLike() { + return usernameLike; + } + + public UserPageQuery setUsernameLike(String usernameLike) { + this.usernameLike = usernameLike; + return this; + } + + public String getNickNameLike() { + return nickNameLike; + } + + public UserPageQuery setNickNameLike(String nickNameLike) { + this.nickNameLike = nickNameLike; + return this; + } + + public String getRealNameLike() { + return realNameLike; + } + + public UserPageQuery setRealNameLike(String realNameLike) { + this.realNameLike = realNameLike; + return this; + } + + public String getPhoneLike() { + return phoneLike; + } + + public UserPageQuery setPhoneLike(String phoneLike) { + this.phoneLike = phoneLike; + return this; + } + + public Long getDeptId() { + return deptId; + } + + public UserPageQuery setDeptId(Long deptId) { + this.deptId = deptId; + return this; + } + + public Long getRoleId() { + return roleId; + } + + public UserPageQuery setRoleId(Long roleId) { + this.roleId = roleId; + return this; + } + + public Integer getStatus() { + return status; + } + + public UserPageQuery setStatus(Integer status) { + this.status = status; + return this; + } + + public Integer getDelFlag() { + return delFlag; + } + + public UserPageQuery setDelFlag(Integer delFlag) { + this.delFlag = delFlag; + return this; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/SysCodeBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/SysCodeBO.java new file mode 100644 index 0000000..e0d128e --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/SysCodeBO.java @@ -0,0 +1,30 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.model.bo; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + + +/** + * 系统编码参数类 + * + * @author 程序员小强 + * @date 2020-12-27 10:59:43 + */ +@Data +public class SysCodeBO implements Serializable { + + private static final long serialVersionUID = -878095644963838466L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptDeleteBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptDeleteBO.java new file mode 100755 index 0000000..8b61129 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptDeleteBO.java @@ -0,0 +1,29 @@ +package com.sso.model.bo.dept; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 部门删除bo + * + * @author 程序员小强 + */ +@Data +public class DeptDeleteBO extends BaseOperateBO { + + private static final long serialVersionUID = 1912530599252047615L; + + /** + * 部门ID + */ + @NotNull(message = "部门ID不为空") + private Long deptId; + + + public String getLogValue() { + return String.format(" deptId:%d , , operateBy:%s", this.deptId, this.getOperateBy()); + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptIdQueryBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptIdQueryBO.java new file mode 100755 index 0000000..b03eeae --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptIdQueryBO.java @@ -0,0 +1,24 @@ +package com.sso.model.bo.dept; + +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * 部门详情bo + * + * @author 程序员小强 + */ +@Data +public class DeptIdQueryBO implements Serializable { + + private static final long serialVersionUID = -5367920763344359224L; + + /** + * 部门ID + */ + @NotNull(message = "部门ID不为空") + private Long deptId; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptMgmtTreeBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptMgmtTreeBO.java new file mode 100755 index 0000000..26b975f --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptMgmtTreeBO.java @@ -0,0 +1,34 @@ +package com.sso.model.bo.dept; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * 部门树查询 + * + * @author 程序员小强 + */ +@Data +public class DeptMgmtTreeBO implements Serializable { + + private static final long serialVersionUID = 1912530599252047615L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 部门名称 + */ + private String deptNameLike; + + /** + * 状态 -1全部 0-启用;1-停用 + */ + private Integer status; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptSaveBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptSaveBO.java new file mode 100755 index 0000000..167ba44 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptSaveBO.java @@ -0,0 +1,63 @@ +package com.sso.model.bo.dept; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.Max; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +/** + * 部门添加 bo + * + * @author 程序员小强 + */ +@Data +public class DeptSaveBO extends BaseOperateBO { + + private static final long serialVersionUID = 7434128948642870592L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 部门名称 + */ + @NotBlank(message = "部门名称不能为空") + private String deptName; + + /** + * 父部门ID + */ + @NotNull(message = "父部门ID不为空") + private Long deptParentId; + + /** + * 顺序 + */ + @NotNull(message = "顺序不为空") + @Max(value = 1000000000, message = "显示顺序最大长度不能超过{max}") + private Integer sortNum; + + /** + * 状态 0-启用;1-停用 + */ + @NotNull(message = "状态不为空") + private Integer status; + + /** + * 备注 + */ + @Size(max = 200, message = "备注最大长度不超{max}") + private String remarks; + + + public String getLogValue() { + return String.format("sysCode:%s , deptName:%s , operateBy:%s", this.sysCode, this.deptName, this.getOperateBy()); + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptUpdateBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptUpdateBO.java new file mode 100755 index 0000000..8882678 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/dept/DeptUpdateBO.java @@ -0,0 +1,67 @@ +package com.sso.model.bo.dept; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +/** + * 部门修改BO + * + * @author 程序员小强 + */ +@Data +public class DeptUpdateBO extends BaseOperateBO { + + private static final long serialVersionUID = 6373997550677086520L; + + /** + * 部门ID + */ + @NotNull(message = "部门ID不为空") + private Long deptId; + + /** + * 部门名称 + */ + @NotBlank(message = "部门名称不能为空") + private String deptName; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 父部门ID + */ + @NotNull(message = "父部门ID不为空") + private Long deptParentId; + + /** + * 顺序 + */ + @NotNull(message = "顺序不为空") + private Integer sortNum; + + /** + * 状态 0-启用;1-停用 + */ + @NotNull(message = "状态不为空") + private Integer status; + + /** + * 备注 + */ + @Size(max = 200, message = "备注最大长度不超{max}") + private String remarks; + + + public String getLogValue() { + return String.format("sysCode:%s , deptId:%d , deptName:%s , operateBy:%s", this.sysCode, this.deptId, this.deptName, this.getOperateBy()); + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/getway/ApplyAuthBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/getway/ApplyAuthBO.java new file mode 100644 index 0000000..14fefca --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/getway/ApplyAuthBO.java @@ -0,0 +1,45 @@ +package com.sso.model.bo.getway; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 申请认证参数 + * + * @author 程序员小强 + * @version ApplyAuthBO.java + */ +@Data +public class ApplyAuthBO implements Serializable { + + private static final long serialVersionUID = -3755046680856409972L; + + /** + * 退出登录访问地址 + */ + private String loginOutUrl; + + /** + * 菜单类型 + * 1-列表; 2-树形列表 + */ + private String menuType; + + /** + * 跳转url + */ + private String redirectUrl; + + /** + * 登录token + */ + private String ssoToken; + + /** + * 来源IP + */ + private String sourceIp; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/getway/GetWayReqBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/getway/GetWayReqBO.java new file mode 100644 index 0000000..9e23a11 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/getway/GetWayReqBO.java @@ -0,0 +1,49 @@ +package com.sso.model.bo.getway; + + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Pattern; +import java.io.Serializable; + +/** + * GetWay 请求公共参数 + * + * @author 程序员小强 + * @version GetWayReqBO.java + */ +@Data +public class GetWayReqBO implements Serializable { + + private static final long serialVersionUID = 2055965490262675225L; + + /** + * 请求唯一标识 + * 推荐使用UUID,要求唯一性 + */ + @NotBlank(message = "请求标识不能为空") + private String apiRequestId; + + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + @NotBlank(message = "方法名不能为空") + private String method; + + @NotBlank(message = "版本号不能为空") + private String version; + + @NotBlank(message = "签名类型不能为空") + @Pattern(regexp = "[1-3]", message = "签名类型只能为1或2或3") + private String signType; + + @NotBlank(message = "请求时间戳不能为空") + @Pattern(regexp = "^16\\d{11}$", message = "时间戳格式错误") + private String timestamp; + + private String sign; + + private String content; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/login/LoginBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/login/LoginBO.java new file mode 100755 index 0000000..11d5885 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/login/LoginBO.java @@ -0,0 +1,42 @@ +package com.sso.model.bo.login; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * 用户登录对象 + * + * @author 程序员小强 + */ +@Data +public class LoginBO implements Serializable { + + private static final long serialVersionUID = 3516676046779777417L; + + /** + * 用户名 + */ + @NotBlank(message = "用户名不为空") + private String username; + + /** + * 用户密码 + */ + @NotBlank(message = "用户密码不为空") + private String password; + + /** + * 验证码 + */ + @NotBlank(message = "验证码不为空") + private String captchaCode; + + /** + * 请求唯一标识 + */ + @NotBlank(message = "请求唯一标识不为空") + private String requestId; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/login/LoginLogListPageBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/login/LoginLogListPageBO.java new file mode 100755 index 0000000..f2b68ae --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/login/LoginLogListPageBO.java @@ -0,0 +1,41 @@ +package com.sso.model.bo.login; + +import com.sso.common.model.page.BasePageModel; +import lombok.Data; + +/** + * 登录日志分页查询bo + * + * @author 程序员小强 + */ +@Data +public class LoginLogListPageBO extends BasePageModel { + + private static final long serialVersionUID = -3442414830796499182L; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 用户登录名 + */ + private String usernameLike; + + /** + * 登录状态 0-成功;1-失败 + */ + private Integer status; + + /** + * 登录开始时间 + */ + private String loginStartTime; + + /** + * 登录截止时间 + */ + private String loginEndTime; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuDeleteBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuDeleteBO.java new file mode 100755 index 0000000..9c316e2 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuDeleteBO.java @@ -0,0 +1,30 @@ +package com.sso.model.bo.menu; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 菜单删除 bo + * + * @author 程序员小强 + */ +@Data +public class MenuDeleteBO extends BaseOperateBO { + + private static final long serialVersionUID = -8354384638349511426L; + + /** + * 菜单ID + */ + @NotNull(message = "菜单ID不能为空") + private Long menuId; + + + public String getLogValue() { + return String.format("menuId:%d, operateBy:%s", + this.menuId, this.getOperateBy()); + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuSaveBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuSaveBO.java new file mode 100755 index 0000000..841b5d2 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuSaveBO.java @@ -0,0 +1,102 @@ +package com.sso.model.bo.menu; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.Digits; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.List; + +/** + * 菜单添加 bo + * + * @author 程序员小强 + */ +@Data +public class MenuSaveBO extends BaseOperateBO { + + private static final long serialVersionUID = -2219298721551456293L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 菜单名称 + */ + @NotBlank(message = "菜单名称不能为空") + private String menuName; + + /** + * 菜单类型(M目录 C菜单 F按钮) + */ + @NotBlank(message = "菜单类型不能为空") + private String menuType; + + /** + * 父菜单ID + */ + @NotNull(message = "父菜单ID不能为空") + private Long menuParentId; + + /** + * 显示顺序 + */ + @NotNull(message = "显示顺序不能为空") + @Digits(integer = 999999999, fraction = 0, message = "显示顺序最大长度不能超过{integer}") + private Integer sortNum; + + /** + * 菜单路由地址 + */ + private String path; + + /** + * 菜单图标 + */ + private String icon; + + /** + * 组件路径 + */ + private String component; + + /** + * 权限标识,多个|分隔 + */ + @Size(max = 10, message = "权限标识最多不超过{max}") + private List permissionList; + + /** + * 使用类型 0-授权访问;1-开放访问; + */ + private Integer useType; + + /** + * 是否显示 0-显示;1-隐藏 + */ + private Integer visible; + + /** + * 菜单状态 0-正常;1停用 + */ + private Integer status; + + /** + * 备注 + */ + @Size(max = 200, message = "备注最大长度不超{max}") + private String remarks; + + + public String getLogValue() { + return String.format("sysCode:%s , menuName:%s , menuParentId:%d ,permissionList:%s, operateBy:%s", this.sysCode, this.menuName, this.menuParentId, + this.permissionList, this.getOperateBy()); + } + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuTreeBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuTreeBO.java new file mode 100755 index 0000000..2c69e12 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuTreeBO.java @@ -0,0 +1,33 @@ +package com.sso.model.bo.menu; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * 菜单树查询BO + * + * @author 程序员小强 + */ +@Data +public class MenuTreeBO implements Serializable { + + private static final long serialVersionUID = -4094219434105471621L; + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 菜单名称 + */ + private String menuNameLike; + + /** + * 状态 -1全部 0-启用;1-停用 + */ + private Integer status; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuUpdateBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuUpdateBO.java new file mode 100755 index 0000000..fb9b894 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/menu/MenuUpdateBO.java @@ -0,0 +1,30 @@ +package com.sso.model.bo.menu; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 菜单修改 bo + * + * @author 程序员小强 + */ +@Data +public class MenuUpdateBO extends MenuSaveBO { + + private static final long serialVersionUID = 6016756261051760463L; + + /** + * 菜单ID + */ + @NotNull(message = "菜单ID不能为空") + private Long menuId; + + + @Override + public String getLogValue() { + return String.format("menuId:%d,sysCode:%s menuName:%s , menuParentId:%d ,permissionList:%s, operateBy:%s", + this.menuId, this.getSysCode(), this.getMenuName(), this.getMenuParentId(), this.getPermissionList(), this.getOperateBy()); + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemDeleteBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemDeleteBO.java new file mode 100644 index 0000000..9676434 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemDeleteBO.java @@ -0,0 +1,26 @@ +package com.sso.model.bo.platform; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +/** + * 修改平台新增bo + * + * @author 程序员小强 + */ +@Data +public class SystemDeleteBO extends BaseOperateBO { + + private static final long serialVersionUID = 4340162202000538970L; + + /** + * 系统平台ID + */ + private Long sysId; + + + public String getLogValue() { + return String.format("sysId:%d, operateBy:%s", this.sysId, this.getOperateBy()); + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtListPageBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtListPageBO.java new file mode 100755 index 0000000..5203a61 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtListPageBO.java @@ -0,0 +1,54 @@ +package com.sso.model.bo.platform; + +import com.sso.common.model.page.BasePageModel; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * 用户-系统关系分页查询bo + * + * @author 程序员小强 + */ +@Data +public class SystemMgmtListPageBO extends BasePageModel { + + private static final long serialVersionUID = -27397984110384822L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 用户登录名 + */ + private String usernameLike; + + /** + * 用户昵称 + */ + private String nickNameLike; + + /** + * 真实姓名 + */ + private String realNameLike; + + /** + * 手机号码 + */ + private String phoneLike; + + /** + * 用户状态 0-正常;1-停用 + */ + private Integer userStatus; + + /** + * 绑定关系状态 0-正常;1-停用 + */ + private Integer relationStatus; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtRemoveBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtRemoveBO.java new file mode 100755 index 0000000..93fe52c --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtRemoveBO.java @@ -0,0 +1,35 @@ +package com.sso.model.bo.platform; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * 系统管理权限移除BO + * + * @author 程序员小强 + */ +@Data +public class SystemMgmtRemoveBO extends BaseOperateBO { + + private static final long serialVersionUID = 7991373166717611704L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不为空") + private String sysCode; + + /** + * 用户ID + */ + @NotNull(message = "用户ID不为空") + private Long userId; + + public String getLogValue() { + return String.format("sysCode:%s, userId:%s , operateBy:%s", this.sysCode, this.userId, this.getOperateBy()); + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtSaveBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtSaveBO.java new file mode 100755 index 0000000..70b61fb --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtSaveBO.java @@ -0,0 +1,41 @@ +package com.sso.model.bo.platform; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * 系统管理权限-新增BO + * + * @author 程序员小强 + */ +@Data +public class SystemMgmtSaveBO extends BaseOperateBO { + + private static final long serialVersionUID = -3496085022363517714L; + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不为空") + private String sysCode; + + /** + * 用户ID + */ + @NotNull(message = "用户ID不为空") + private Long userId; + + /** + * 状态 + */ + @NotNull(message = "状态不为空") + private Integer status; + + + public String getLogValue() { + return String.format("userId:%d, sysCode:%s , operateBy:%s", this.userId, this.sysCode, this.getOperateBy()); + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtStatusBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtStatusBO.java new file mode 100755 index 0000000..bd72af5 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemMgmtStatusBO.java @@ -0,0 +1,33 @@ +package com.sso.model.bo.platform; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 系统管理权限-新增BO + * + * @author 程序员小强 + */ +@Data +public class SystemMgmtStatusBO extends BaseOperateBO { + + private static final long serialVersionUID = -5187844120648189372L; + + /** + * ID + */ + @NotNull(message = "ID不为空") + private Long id; + + /** + * 状态 + */ + @NotNull(message = "状态不为空") + private Integer status; + + public String getLogValue() { + return String.format("sysId:%d, status:%s , operateBy:%s", this.id, this.status, this.getOperateBy()); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemSaveBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemSaveBO.java new file mode 100644 index 0000000..ab55f67 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemSaveBO.java @@ -0,0 +1,62 @@ +package com.sso.model.bo.platform; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * 目标平台新增bo + * + * @author 程序员小强 + */ +@Data +public class SystemSaveBO extends BaseOperateBO { + + private static final long serialVersionUID = 1163633182173991403L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不为空") + private String sysCode; + + /** + * 系统名称 + */ + @NotBlank(message = "系统名称不为空") + private String sysName; + + /** + * 系统链接 + */ + @NotBlank(message = "系统跳转链接不为空") + private String sysUrl; + + /** + * 系统图标 + */ + private String sysIcon; + + /** + * 系统环境 0-测试 1-beta 2-生产 + */ + @NotNull(message = "系统环境不为空") + private Integer sysEnv; + + /** + * 排序,数字越小排在越前面 + */ + @NotNull(message = "排序不为空") + private Integer sortNum; + + /** + * 备注 + */ + private String remarks; + + public String getLogValue() { + return String.format("sysCode:%s , sysName:%s , operateBy:%s", this.sysCode, this.sysName, this.getOperateBy()); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemSortBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemSortBO.java new file mode 100644 index 0000000..b142737 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemSortBO.java @@ -0,0 +1,26 @@ +package com.sso.model.bo.platform; + +import lombok.Data; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.io.Serializable; +import java.util.List; + +/** + * 目标平台排序bo + * + * @author 程序员小强 + */ +@Data +public class SystemSortBO implements Serializable { + + private static final long serialVersionUID = 2105261198839002918L; + + /** + * 系统编码集合 + */ + @NotNull(message = "系统编码集不为空") + @Size(min = 1, message = "系统编码集不为空") + private List sysCodeList; +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemUpdateBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemUpdateBO.java new file mode 100644 index 0000000..684665b --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemUpdateBO.java @@ -0,0 +1,33 @@ +package com.sso.model.bo.platform; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 修改平台新增bo + * + * @author 程序员小强 + */ +@Data +public class SystemUpdateBO extends SystemSaveBO { + + private static final long serialVersionUID = 1163633182173991403L; + + /** + * 系统平台ID + */ + @NotNull(message = "系统平台ID不为空") + private Long sysId; + + /** + * 状态 + */ + @NotNull(message = "状态不为空") + private Integer status; + + @Override + public String getLogValue() { + return String.format("sysId:%d, sysCode:%s , sysName:%s , operateBy:%s", this.sysId, this.getSysCode(), this.getSysName(), this.getOperateBy()); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemUpdateSecretBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemUpdateSecretBO.java new file mode 100644 index 0000000..04bd9d1 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/platform/SystemUpdateSecretBO.java @@ -0,0 +1,40 @@ +package com.sso.model.bo.platform; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 修改平台新增bo + * + * @author 程序员小强 + */ +@Data +public class SystemUpdateSecretBO extends BaseOperateBO { + + private static final long serialVersionUID = -7361402011394142030L; + + /** + * 系统平台ID + */ + @NotNull(message = "系统平台ID不为空") + private Long sysId; + + /** + * 签名类型 0-无;1-MD5;2-RSA; + */ + @NotNull(message = "签名类型不为空") + private Integer signType; + + /** + * 网关验签公钥 + */ + private String publicKey; + + + public String getLogValue() { + return String.format("sysId:%d, signType:%s , operateBy:%s", this.sysId, this.signType, this.getOperateBy()); + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleDeleteBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleDeleteBO.java new file mode 100755 index 0000000..7352f38 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleDeleteBO.java @@ -0,0 +1,28 @@ +package com.sso.model.bo.role; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 角色删除bo + * + * @author 程序员小强 + */ +@Data +public class RoleDeleteBO extends BaseOperateBO { + + private static final long serialVersionUID = -4350853964122690858L; + + /** + * 角色ID + */ + @NotNull(message = "角色ID不为空") + private Long roleId; + + + public String getLogValue() { + return String.format("roleId:%d , operateBy:%s", this.roleId, this.getOperateBy()); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleListOptionBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleListOptionBO.java new file mode 100755 index 0000000..6165510 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleListOptionBO.java @@ -0,0 +1,30 @@ +package com.sso.model.bo.role; + +import com.sso.common.model.page.BasePageModel; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * 角色-下拉选项查询bo + * + * @author 程序员小强 + */ +@Data +public class RoleListOptionBO extends BasePageModel { + + private static final long serialVersionUID = 8961034980910026149L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 角色名称右模糊 + */ + private String roleNameLike; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleListPageBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleListPageBO.java new file mode 100755 index 0000000..a9853e1 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleListPageBO.java @@ -0,0 +1,40 @@ +package com.sso.model.bo.role; + +import com.sso.common.model.page.BasePageModel; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * 角色分页查询bo + * + * @author 程序员小强 + */ +@Data +public class RoleListPageBO extends BasePageModel { + + private static final long serialVersionUID = -8206942361131504869L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 角色名称 右模糊 + */ + private String roleNameLike; + + /** + * 角色key 右模糊 + */ + private String roleKeyLike; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleRemoveUserBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleRemoveUserBO.java new file mode 100755 index 0000000..31d972b --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleRemoveUserBO.java @@ -0,0 +1,34 @@ +package com.sso.model.bo.role; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 角色删除bo + * + * @author 程序员小强 + */ +@Data +public class RoleRemoveUserBO extends BaseOperateBO { + + private static final long serialVersionUID = -4350853964122690858L; + + /** + * 角色ID + */ + @NotNull(message = "角色ID不为空") + private Long roleId; + + /** + * 用户ID + */ + @NotNull(message = "用户ID不为空") + private Long userId; + + + public String getLogValue() { + return String.format("roleId:%d , userId:%d, operateBy:%s", this.roleId, this.userId, this.getOperateBy()); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleSaveBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleSaveBO.java new file mode 100755 index 0000000..42e2853 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleSaveBO.java @@ -0,0 +1,64 @@ +package com.sso.model.bo.role; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.List; + +/** + * 角色添加 bo + * + * @author 程序员小强 + */ +@Data +public class RoleSaveBO extends BaseOperateBO { + + private static final long serialVersionUID = -2662983486894971210L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 状态 + */ + @NotNull(message = "状态不为空") + private Integer status; + + /** + * 显示顺序 + */ + @NotNull(message = "显示顺序不为空") + private Integer sortNum; + + /** + * 角色名称 + */ + @NotBlank(message = "角色名称不能为空") + private String roleName; + + /** + * 角色key + */ + private String roleKey; + + /** + * 备注 + */ + @Size(max = 200, message = "备注最大长度不超{max}") + private String remarks; + + /** + * 菜单ID集 + */ + private List menuIdList; + + public String getLogValue() { + return String.format("sysCode:%s , roleName:%s , roleKey:%s ,operateBy:%s", this.sysCode, this.roleName, this.roleKey, this.getOperateBy()); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleUpdateBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleUpdateBO.java new file mode 100755 index 0000000..8531be3 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/role/RoleUpdateBO.java @@ -0,0 +1,28 @@ +package com.sso.model.bo.role; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 角色修改 bo + * + * @author 程序员小强 + */ +@Data +public class RoleUpdateBO extends RoleSaveBO { + + private static final long serialVersionUID = -7337969581151948190L; + + /** + * 角色ID + */ + @NotNull(message = "角色ID") + private Long roleId; + + + @Override + public String getLogValue() { + return String.format("sysCode:%s , roleId:%d , roleName:%s , roleKey:%s ,operateBy:%s", this.getSysCode(), roleId, this.getRoleName(), this.getRoleKey(), this.getOperateBy()); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserAddBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserAddBO.java new file mode 100755 index 0000000..accd037 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserAddBO.java @@ -0,0 +1,90 @@ +package com.sso.model.bo.user; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; +import java.util.List; + +/** + * 用户新增bo + * + * @author 程序员小强 + */ +@Data +public class UserAddBO extends BaseOperateBO { + + private static final long serialVersionUID = -8559961404756899677L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 用户登录名 + */ + @NotBlank(message = "用户登录名不为空") + private String username; + + /** + * 密码 + */ + @NotBlank(message = "用户登录密码不为空") + @Size(max = 20, message = "密码最大长度{max}") + private String password; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 所属部门 + */ + private Long deptId; + + /** + * 角色ID集 + */ + private List roleIdList; + + /** + * 用户性别 0-男;1-女;2-未知 + */ + private Integer sex; + + /** + * 手机号码 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 备注 + */ + private String remarks; + + + public String getLogValue() { + return String.format("sysCode:%s , username:%s , realName:%s , phone:%s, deptId:%d , roleIdList:%s , operateBy:%s", + this.sysCode, this.username, this.realName, this.phone, this.deptId, this.roleIdList, this.getOperateBy()); + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserBatchDeleteBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserBatchDeleteBO.java new file mode 100755 index 0000000..15d4a2a --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserBatchDeleteBO.java @@ -0,0 +1,32 @@ +package com.sso.model.bo.user; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; +import java.util.List; + +/** + * 用户删除bo + * + * @author 程序员小强 + */ +@Data +public class UserBatchDeleteBO extends BaseOperateBO { + + private static final long serialVersionUID = 6811621712453725799L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 用户ID + */ + @Size(min = 1, message = "用户ID不为空") + private List userIdList; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserDeleteBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserDeleteBO.java new file mode 100755 index 0000000..b279bb3 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserDeleteBO.java @@ -0,0 +1,32 @@ +package com.sso.model.bo.user; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; +import java.util.List; + +/** + * 用户删除bo + * + * @author 程序员小强 + */ +@Data +public class UserDeleteBO extends BaseOperateBO { + + private static final long serialVersionUID = -6260789437671185007L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 用户ID + */ + @Size(min = 1, message = "用户ID不为空") + private List userIdList; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserDetailBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserDetailBO.java new file mode 100755 index 0000000..c8aa905 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserDetailBO.java @@ -0,0 +1,31 @@ +package com.sso.model.bo.user; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * 用户查询详情bo + * + * @author 程序员小强 + */ +@Data +public class UserDetailBO implements Serializable { + + private static final long serialVersionUID = 8048715426913745373L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 用户ID + */ + @NotNull(message = "用户ID不为空") + private Long userId; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserListPageBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserListPageBO.java new file mode 100755 index 0000000..a5ad126 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserListPageBO.java @@ -0,0 +1,60 @@ +package com.sso.model.bo.user; + +import com.sso.common.model.page.BasePageModel; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * 用户分页查询bo + * + * @author 程序员小强 + */ +@Data +public class UserListPageBO extends BasePageModel { + + private static final long serialVersionUID = 4627460201144477292L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 用户登录名 + */ + private String usernameLike; + + /** + * 用户昵称 + */ + private String nickNameLike; + + /** + * 真实姓名 + */ + private String realNameLike; + + /** + * 手机号码 + */ + private String phoneLike; + + /** + * 所属部门ID + */ + private Long deptId; + + /** + * 角色ID + */ + private Long roleId; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserOnlineListPageBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserOnlineListPageBO.java new file mode 100755 index 0000000..1c52469 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserOnlineListPageBO.java @@ -0,0 +1,31 @@ +package com.sso.model.bo.user; + +import com.sso.common.model.page.BasePageModel; +import lombok.Data; + +/** + * 在线用户分页查询bo + * + * @author 程序员小强 + */ +@Data +public class UserOnlineListPageBO extends BasePageModel { + + private static final long serialVersionUID = 4278605423671971482L; + + /** + * 用户登录名 + */ + private String usernameLike; + + /** + * 登录开始时间 + */ + private String loginStartTime; + + /** + * 登录截止时间 + */ + private String loginEndTime; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserPlatformAddBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserPlatformAddBO.java new file mode 100755 index 0000000..01a353b --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserPlatformAddBO.java @@ -0,0 +1,48 @@ +package com.sso.model.bo.user; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.List; + +/** + * 用户-平台关系-新增bo + * + * @author 程序员小强 + */ +@Data +public class UserPlatformAddBO extends BaseOperateBO { + + private static final long serialVersionUID = -7111999878891732483L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 用户ID + */ + @NotNull(message = "用户ID不为空") + private Long userId; + + /** + * 所属部门 + */ + private Long deptId; + + /** + * 角色ID集 + */ + @Size(min = 1, message = "请至少选择一个角色") + private List roleIdList; + + public String getLogValue() { + return String.format("sysCode:%s , userId:%d, deptId:%d , roleIdList:%s , operateBy:%s", + this.sysCode, this.userId, this.deptId, this.roleIdList, this.getOperateBy()); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserRestPwdBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserRestPwdBO.java new file mode 100755 index 0000000..dd17be7 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserRestPwdBO.java @@ -0,0 +1,30 @@ +package com.sso.model.bo.user; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * 用户重置密码bo + * + * @author 程序员小强 + */ +@Data +public class UserRestPwdBO extends BaseOperateBO { + private static final long serialVersionUID = -3944856451297952013L; + + /** + * 用户ID + */ + @NotNull(message = "用户ID不为空") + private Long userId; + + /** + * 密码 + */ + @NotBlank(message = "密码不能为空") + private String password; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserSystemRemoveBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserSystemRemoveBO.java new file mode 100755 index 0000000..4afff8f --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserSystemRemoveBO.java @@ -0,0 +1,36 @@ +package com.sso.model.bo.user; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * 用户删除bo + * + * @author 程序员小强 + */ +@Data +public class UserSystemRemoveBO extends BaseOperateBO { + + private static final long serialVersionUID = 2060892792625221284L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 用户ID + */ + @NotNull(message = "用户ID不为空") + private Long userId; + + + public String getLogValue() { + return String.format("sysCode:%s , userId:%d, operateBy:%s", + this.sysCode, this.userId, this.getOperateBy()); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserUpdateBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserUpdateBO.java new file mode 100755 index 0000000..b847e35 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserUpdateBO.java @@ -0,0 +1,84 @@ +package com.sso.model.bo.user; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.util.List; + +/** + * 用户修改bo + * + * @author 程序员小强 Profile + */ +@Data +public class UserUpdateBO extends BaseOperateBO { + + private static final long serialVersionUID = -2437911052557089621L; + + /** + * 系统编码 + */ + @NotBlank(message = "系统编码不能为空") + private String sysCode; + + /** + * 用户ID + */ + @NotNull(message = "用户ID不为空") + private Long userId; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 所属部门 + */ + private Long deptId; + + /** + * 角色ID集 + */ + private List roleIdList; + + /** + * 用户性别 + */ + @NotNull(message = "用户性别不为空") + private Integer sex; + + /** + * 手机号码 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + /** + * 状态 0-正常;1-停用 + */ + @NotNull(message = "状态不为空") + private Integer status; + + /** + * 备注 + */ + private String remarks; + + public String getLogValue() { + return String.format("sysCode:%s , userId:%d , realName:%s , phone:%s, deptId:%d , roleIdList:%s , operateBy:%s", + this.sysCode, this.userId, this.realName, this.phone, this.deptId, this.roleIdList, this.getOperateBy()); + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserUpdateProfileBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserUpdateProfileBO.java new file mode 100755 index 0000000..96f9d14 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserUpdateProfileBO.java @@ -0,0 +1,55 @@ +package com.sso.model.bo.user; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 用户修改个人信息 bo + * + * @author 程序员小强 + */ +@Data +public class UserUpdateProfileBO extends BaseOperateBO { + + private static final long serialVersionUID = 6185270826197205522L; + + /** + * 用户ID + */ + @NotNull(message = "用户ID不为空") + private Long userId; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 用户性别 + */ + @NotNull(message = "用户性别不为空") + private Integer sex; + + /** + * 手机号码 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + public String getLogValue() { + return String.format("userId:%d, nickName:%s, realName:%s , phone:%s , sex%d , email:%s , operateBy:%s", + this.userId, this.nickName, this.realName, this.phone, this.sex, this.email, this.getOperateBy()); + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserUpdatePwdBO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserUpdatePwdBO.java new file mode 100755 index 0000000..ef7ba8a --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/bo/user/UserUpdatePwdBO.java @@ -0,0 +1,39 @@ +package com.sso.model.bo.user; + +import com.sso.common.model.BaseOperateBO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +/** + * 用户修改个人密码 bo + * + * @author 程序员小强 + */ +@Data +public class UserUpdatePwdBO extends BaseOperateBO { + + private static final long serialVersionUID = -2947529017224375730L; + + /** + * 用户ID + */ + @NotNull(message = "用户ID不为空") + private Long userId; + + /** + * 旧密码 + */ + @NotBlank(message = "旧密码不为空") + private String oldPassword; + + /** + * 新密码 + */ + @NotBlank(message = "新密码不为空") + @Size(max = 20, message = "密码最大长度{max}") + private String newPassword; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/captcha/CaptchaVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/captcha/CaptchaVO.java new file mode 100644 index 0000000..99cdaf5 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/captcha/CaptchaVO.java @@ -0,0 +1,31 @@ +package com.sso.model.vo.captcha; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 部门详情VO + * + * @author 程序员小强 + */ +@Data +public class CaptchaVO implements Serializable { + + private static final long serialVersionUID = 3727125898241907228L; + + /** + * 请求标识 + */ + private String requestId; + + /** + * 图片验证码-base64格式 + */ + private String base64Img; + + public CaptchaVO(String requestId, String base64Img) { + this.requestId = requestId; + this.base64Img = base64Img; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptDetailVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptDetailVO.java new file mode 100755 index 0000000..2192284 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptDetailVO.java @@ -0,0 +1,74 @@ +package com.sso.model.vo.dept; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 部门详情VO + * + * @author 程序员小强 + */ +@Data +public class DeptDetailVO implements Serializable { + + private static final long serialVersionUID = -8502275028952490758L; + + /** + * 部门ID + */ + private Long deptId; + + /** + * 部门名称 + */ + private String deptName; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 父部门ID + */ + private Long deptParentId; + + /** + * 顺序 + */ + private Integer sortNum; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 备注 + */ + private String remarks; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptMgmtTreeNodeVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptMgmtTreeNodeVO.java new file mode 100755 index 0000000..7f29d51 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptMgmtTreeNodeVO.java @@ -0,0 +1,87 @@ +package com.sso.model.vo.dept; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.sso.common.utils.tree.TreeParentNode; +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * 部门管理树-返回对象 + * + * @author 程序员小强 + */ +@Data +public class DeptMgmtTreeNodeVO implements Serializable, TreeParentNode { + + private static final long serialVersionUID = 8016386138004004340L; + /** + * 部门标识 + */ + private Long deptId; + + /** + * 部门父标识 + */ + private Long deptParentId; + + /** + * 部门名称 + */ + private String deptName; + + /** + * 顺序 + */ + private Integer sortNum; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + private final List children = new ArrayList<>(); + + @JsonIgnore + @Override + public String getTreeNodeId() { + return deptId.toString(); + } + + @JsonIgnore + @Override + public String getParentTreeNodeId() { + return deptParentId.toString(); + } + + @JsonIgnore + @Override + public List getChildTreeNodes() { + return children; + } + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptOptionTreeNodeVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptOptionTreeNodeVO.java new file mode 100755 index 0000000..5d12977 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptOptionTreeNodeVO.java @@ -0,0 +1,57 @@ +package com.sso.model.vo.dept; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.sso.common.utils.tree.TreeParentNode; +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 部门下拉选项树-返回对象 + * + * @author 程序员小强 + */ +@Data +public class DeptOptionTreeNodeVO implements Serializable, TreeParentNode { + + private static final long serialVersionUID = 8930822109458637455L; + + /** + * 部门标识 + */ + private Long deptId; + + /** + * 部门父标识 + */ + private Long deptParentId; + + /** + * 部门名称 + */ + private String deptName; + + private final List children = new ArrayList<>(); + + @JsonIgnore + @Override + public String getTreeNodeId() { + return deptId.toString(); + } + + @JsonIgnore + @Override + public String getParentTreeNodeId() { + return deptParentId.toString(); + } + + @JsonIgnore + @Override + public List getChildTreeNodes() { + return children; + } + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptOptionVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptOptionVO.java new file mode 100755 index 0000000..2c9e71e --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/dept/DeptOptionVO.java @@ -0,0 +1,33 @@ +package com.sso.model.vo.dept; + +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 部门下拉列表VO + * + * @author 程序员小强 + */ +@Data +public class DeptOptionVO implements Serializable { + + private static final long serialVersionUID = 6484839051092507626L; + + /** + * 部门标识 + */ + private String deptId; + /** + * 部门名称 + */ + private String deptName; + + /** + * 部门下拉列表 + */ + private final List children = new ArrayList<>(); + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/getway/ApplyAuthVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/getway/ApplyAuthVO.java new file mode 100644 index 0000000..340d85b --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/getway/ApplyAuthVO.java @@ -0,0 +1,112 @@ +package com.sso.model.vo.getway; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.sso.common.utils.StringUtils; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; +import java.util.Set; + +/** + * 申请认证参数 + * + * @author 程序员小强 + * @version ApplyAuthBO.java + */ +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ApplyAuthVO implements Serializable { + + private static final long serialVersionUID = -3755046680856409972L; + + /** + * 认证结果 + */ + private Boolean authResult; + + /** + * 重定向url(认证结果仅为false时返回) + */ + private String redirectUrl; + + /** + * 用户ID + */ + private Long userId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 头像 + */ + private String avatar; + + /** + * 用户性别 0-男;1-女;2-未知 + */ + private Integer sex; + + /** + * 手机号码 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 系统名称 + */ + private String sysName; + + /** + * 在当前系统下的-权限列表 + */ + private Set permissionList; + + /** + * 在当前系统下的-角色标识 + */ + private List roleKeyList; + + /** + * 在当前系统下的-菜单集 + */ + private List menuList; + + public static ApplyAuthVO authFailNeedLogin(String ssoLoginUrl) { + return authFailNeedLogin(ssoLoginUrl, ""); + } + + public static ApplyAuthVO authFailNeedLogin(String ssoLoginUrl, String targetRedirectUrl) { + ApplyAuthVO authVO = new ApplyAuthVO(); + authVO.setAuthResult(false); + authVO.setRedirectUrl(ssoLoginUrl); + if (StringUtils.isNotBlank(targetRedirectUrl)) { + authVO.setRedirectUrl(ssoLoginUrl + "?redirectUrl=" + targetRedirectUrl); + } + return authVO; + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/getway/MenuTreeAuthVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/getway/MenuTreeAuthVO.java new file mode 100755 index 0000000..73f56f0 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/getway/MenuTreeAuthVO.java @@ -0,0 +1,86 @@ +package com.sso.model.vo.getway; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.sso.common.utils.tree.TreeParentNode; +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 菜单树-返回对象 + * + * @author 程序员小强 + */ +@Data +public class MenuTreeAuthVO implements Serializable, TreeParentNode { + + private static final long serialVersionUID = 104708179051650651L; + + /** + * 菜单ID + */ + private Long menuId; + + /** + * 父菜单ID + */ + private Long menuParentId; + + /** + * 菜单名称 + */ + private String menuName; + + /** + * 菜单类型(M目录 C菜单 F按钮) + */ + private String menuType; + + /** + * 显示顺序 + */ + private Integer sortNum; + + /** + * 菜单路由地址 + */ + private String path; + + /** + * 菜单图标 + */ + private String icon; + + /** + * 组件路径 + */ + private String component; + + /** + * 是否显示 0-显示;1-隐藏 + */ + private Integer visible; + + private final List children = new ArrayList<>(); + + @JsonIgnore + @Override + public String getTreeNodeId() { + return menuId.toString(); + } + + @JsonIgnore + @Override + public String getParentTreeNodeId() { + return menuParentId.toString(); + } + + @JsonIgnore + @Override + public List getChildTreeNodes() { + return children; + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/getway/SysLoginCacheVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/getway/SysLoginCacheVO.java new file mode 100644 index 0000000..980cd8e --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/getway/SysLoginCacheVO.java @@ -0,0 +1,40 @@ +package com.sso.model.vo.getway; + +import com.sso.common.utils.StringUtils; +import lombok.Data; + +import java.io.Serializable; + +/** + * 登录子系统缓存对象 + * + * @author 程序员小强 + */ +@Data +public class SysLoginCacheVO implements Serializable { + private static final long serialVersionUID = 3003483755940745510L; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 退出登录地址 + */ + private String loginOutUrl; + + /** + * 登录时间戳 + */ + private Long loginTime; + + public SysLoginCacheVO() { + } + + public SysLoginCacheVO(String sysCode, String loginOutUrl, Long loginTime) { + this.sysCode = sysCode; + this.loginOutUrl = StringUtils.defaultString(loginOutUrl); + this.loginTime = loginTime; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginLogPageVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginLogPageVO.java new file mode 100644 index 0000000..7feee52 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginLogPageVO.java @@ -0,0 +1,63 @@ +package com.sso.model.vo.login; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 登录日志分页 + * + * @author 程序员小强 + * @date 2021-01-23 10:45:22 + */ +@Data +public class LoginLogPageVO implements Serializable { + + private static final long serialVersionUID = 4602708640932864463L; + + /** + * 请求标识 + */ + private String requestId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 来源IP + */ + private String sourceIp; + + /** + * 来源地址 + */ + private String sourceAddress; + + /** + * 浏览器 + */ + private String browserName; + + /** + * 操作系统 + */ + private String operateSystem; + + /** + * 登录状态 0-成功;1-失败 + */ + private Integer status; + + /** + * 登录时间戳 + */ + private String loginTime; + + /** + * 返回结果 + */ + private String operateMsg; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginMenuVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginMenuVO.java new file mode 100644 index 0000000..c733126 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginMenuVO.java @@ -0,0 +1,137 @@ +/** + * haifenbb.com + * Copyright (C) 2019-2020 All Rights Reserved. + */ +package com.sso.model.vo.login; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.sso.common.utils.tree.TreeParentNode; +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * 菜单权限实体类 + * + * @author 程序员小强 + * @date 2021-01-08 18:01:08 + */ +@Data +public class LoginMenuVO implements Serializable, TreeParentNode { + + private static final long serialVersionUID = -2003959650852088815L; + + /** + * 菜单ID + */ + private Long menuId; + + /** + * 菜单名称 + */ + private String menuName; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 菜单类型(M目录 C菜单 F按钮) + */ + private String menuType; + + /** + * 父菜单ID + */ + private Long menuParentId; + + /** + * 显示顺序 + */ + private Integer sortNum; + + /** + * 菜单路由地址 + */ + private String path; + + /** + * 菜单图标 + */ + private String icon; + + /** + * 组件路径 + */ + private String component; + + /** + * 权限标识,多个|分隔 + */ + private String permissions; + + /** + * 是否显示 0-显示;1-隐藏 + */ + private Integer visible; + + /** + * 菜单状态 0-正常;1停用 + */ + private Integer status; + + /** + * 删除标志 0-正常;1-删除 + */ + private Integer delFlag; + + /** + * 备注 + */ + private String remarks; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + private final List children = new ArrayList<>(); + + @JsonIgnore + @Override + public String getTreeNodeId() { + return menuId.toString(); + } + + @JsonIgnore + @Override + public String getParentTreeNodeId() { + return menuParentId.toString(); + } + + @JsonIgnore + @Override + public List getChildTreeNodes() { + return children; + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginTokenVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginTokenVO.java new file mode 100644 index 0000000..cbe6d55 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginTokenVO.java @@ -0,0 +1,37 @@ +package com.sso.model.vo.login; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 登录token 返回 + * @author 程序员小强 + */ +@Data +public class LoginTokenVO implements Serializable { + + private static final long serialVersionUID = 226785375056951167L; + + /** + * 用户名 + */ + private String username; + + /** + * 请求标识 + */ + private String requestId; + + /** + * token + */ + private String token; + + public LoginTokenVO(String username, String requestId, String token) { + this.username = username; + this.requestId = requestId; + this.token = token; + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginUserInfoVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginUserInfoVO.java new file mode 100644 index 0000000..cd25fe1 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/login/LoginUserInfoVO.java @@ -0,0 +1,46 @@ +/** + * haifenbb.com + * Copyright (C) 2019-2020 All Rights Reserved. + */ +package com.sso.model.vo.login; + +import com.sso.common.model.login.LoginUserVO; +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + + +@Data +public class LoginUserInfoVO implements Serializable { + + private static final long serialVersionUID = -8487394407696680994L; + + private LoginUserVO user; + + private Set roleKeyList; + + private Set permissionList; + + private List menuList; + + public LoginUserInfoVO() { + } + + public LoginUserInfoVO(Set permissionList, List menuList) { + this.permissionList = permissionList; + this.menuList = menuList; + } + + public static LoginUserInfoVO initDefault() { + LoginUserInfoVO result = new LoginUserInfoVO(); + result.setPermissionList(new HashSet<>(0)); + result.setRoleKeyList(new HashSet<>(0)); + result.setMenuList(new ArrayList<>(0)); + return result; + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/menu/MenuDetailVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/menu/MenuDetailVO.java new file mode 100644 index 0000000..b64ff98 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/menu/MenuDetailVO.java @@ -0,0 +1,114 @@ +/** + * haifenbb.com + * Copyright (C) 2019-2020 All Rights Reserved. + */ +package com.sso.model.vo.menu; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * 菜单权限实体类 + * + * @author 程序员小强 + */ +@Data +public class MenuDetailVO implements Serializable { + + private static final long serialVersionUID = 143370666193424604L; + + /** + * 菜单ID + */ + private Long menuId; + + /** + * 菜单名称 + */ + private String menuName; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 菜单类型(M目录 C菜单 F按钮) + */ + private String menuType; + + /** + * 父菜单ID + */ + private Long menuParentId; + + /** + * 显示顺序 + */ + private Integer sortNum; + + /** + * 菜单路由地址 + */ + private String path; + + /** + * 菜单图标 + */ + private String icon; + + /** + * 组件路径 + */ + private String component; + + /** + * 权限标识,多个|分隔 + */ + private List permissionList; + + /** + * 使用类型 0-授权访问;1-开放访问; + */ + private Integer useType; + + /** + * 是否显示 0-显示;1-隐藏 + */ + private Integer visible; + + /** + * 菜单状态 0-正常;1停用 + */ + private Integer status; + + /** + * 备注 + */ + private String remarks; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/menu/MenuOptionTreeNodeVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/menu/MenuOptionTreeNodeVO.java new file mode 100755 index 0000000..57843ad --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/menu/MenuOptionTreeNodeVO.java @@ -0,0 +1,57 @@ +package com.sso.model.vo.menu; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.sso.common.utils.tree.TreeParentNode; +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 菜单树-返回对象 + * + * @author 程序员小强 + */ +@Data +public class MenuOptionTreeNodeVO implements Serializable, TreeParentNode { + + private static final long serialVersionUID = 2794310462077211850L; + + /** + * 菜单ID + */ + private Long menuId; + + /** + * 父菜单ID + */ + private Long menuParentId; + + /** + * 菜单名称 + */ + private String menuName; + + + private final List children = new ArrayList<>(); + + @JsonIgnore + @Override + public String getTreeNodeId() { + return menuId.toString(); + } + + @JsonIgnore + @Override + public String getParentTreeNodeId() { + return menuParentId.toString(); + } + + @JsonIgnore + @Override + public List getChildTreeNodes() { + return children; + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/menu/MenuTreeNodeVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/menu/MenuTreeNodeVO.java new file mode 100755 index 0000000..cc87a91 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/menu/MenuTreeNodeVO.java @@ -0,0 +1,124 @@ +package com.sso.model.vo.menu; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.sso.common.utils.tree.TreeParentNode; +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * 菜单树-返回对象 + * + * @author 程序员小强 + */ +@Data +public class MenuTreeNodeVO implements Serializable, TreeParentNode { + + private static final long serialVersionUID = 5815980115125373089L; + + /** + * 菜单ID + */ + private Long menuId; + + /** + * 父菜单ID + */ + private Long menuParentId; + + /** + * 菜单名称 + */ + private String menuName; + + /** + * 菜单类型(M目录 C菜单 F按钮) + */ + private String menuType; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 显示顺序 + */ + private Integer sortNum; + + /** + * 菜单路由地址 + */ + private String path; + + /** + * 菜单图标 + */ + private String icon; + + /** + * 组件路径 + */ + private String component; + + /** + * 权限标识,多个|分隔 + */ + private String permissions; + + /** + * 使用类型 0-授权访问;1-开放访问; + */ + private Integer useType; + + /** + * 是否显示 0-显示;1-隐藏 + */ + private Integer visible; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + + private final List children = new ArrayList<>(); + + @JsonIgnore + @Override + public String getTreeNodeId() { + return menuId.toString(); + } + + @JsonIgnore + @Override + public String getParentTreeNodeId() { + return menuParentId.toString(); + } + + @JsonIgnore + @Override + public List getChildTreeNodes() { + return children; + } + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/platform/SystemDetailVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/platform/SystemDetailVO.java new file mode 100644 index 0000000..0dad3a5 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/platform/SystemDetailVO.java @@ -0,0 +1,93 @@ +package com.sso.model.vo.platform; + +import lombok.Data; + +import java.io.Serializable; + + +/** + * 目标系统实体类 + * + * @author 程序员小强 + * @date 2020-12-27 10:59:43 + */ +@Data +public class SystemDetailVO implements Serializable { + + private static final long serialVersionUID = -1693062058618507172L; + + /** + * 系统ID + */ + private Long sysId; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 系统名称 + */ + private String sysName; + + /** + * 系统权限编码 + */ + private String sysGrantCode; + + /** + * 系统链接 + */ + private String sysUrl; + + /** + * 系统图标 + */ + private String sysIcon; + + /** + * 系统环境 0-测试 1-beta 2-生产 + */ + private Integer sysEnv; + + /** + * 排序,数字越小排在越前面 + */ + private Integer sortNum; + + /** + * 备注 + */ + private String remarks; + + /** + * 签名类型 + */ + private Integer signType; + + /** + * 网关验签公钥 + */ + private String publicKey; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + private String createBy; + + /** + * 创建时间 + */ + private String createTime; + + private String updateBy; + + /** + * 更新时间 + */ + private String updateTime; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/platform/SystemListVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/platform/SystemListVO.java new file mode 100644 index 0000000..890c326 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/platform/SystemListVO.java @@ -0,0 +1,64 @@ +package com.sso.model.vo.platform; + +import lombok.Data; + +import java.io.Serializable; + + +/** + * 目标系统实体类 + * + * @author 程序员小强 + * @date 2020-12-27 10:59:43 + */ +@Data +public class SystemListVO implements Serializable { + + private static final long serialVersionUID = -2760156351359473263L; + + /** + * 系统平台ID + */ + private Long sysId; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 系统名称 + */ + private String sysName; + + /** + * 排序,数字越小排在越前面 + */ + private Integer sortNum; + + /** + * 系统权限编码 + */ + private String sysGrantCode; + + /** + * 系统链接 + */ + private String sysUrl; + + /** + * 系统图标 + */ + private String sysIcon; + + /** + * 系统环境 0-测试 1-beta 2-生产 + */ + private Integer sysEnv; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/platform/SystemMgmtPageVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/platform/SystemMgmtPageVO.java new file mode 100644 index 0000000..068f559 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/platform/SystemMgmtPageVO.java @@ -0,0 +1,86 @@ +package com.sso.model.vo.platform; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 用户-系统管理 + * + * @author 程序员小强 + * @date 2021-01-02 17:20:41 + */ +@Data +public class SystemMgmtPageVO implements Serializable { + + private static final long serialVersionUID = 1686002027270193343L; + + private Long id; + + /** + * 用户ID + */ + private Long userId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 用户性别 0-男;1-女;2-未知 + */ + private Integer sex; + + /** + * 手机号码 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + /** + * 用户状态 0-正常;1-停用 + */ + private Integer userStatus; + + /** + * 关系状态 0-正常;1-停用 + */ + private Integer relationStatus; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/role/RoleDetailVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/role/RoleDetailVO.java new file mode 100755 index 0000000..dd3b6c3 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/role/RoleDetailVO.java @@ -0,0 +1,78 @@ +package com.sso.model.vo.role; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * 角色添加 bo + * + * @author 程序员小强 + */ +@Data +public class RoleDetailVO implements Serializable { + + private static final long serialVersionUID = 5809339048919552524L; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 角色ID + */ + private Long roleId; + + /** + * 状态 + */ + private Integer status; + + /** + * 显示顺序 + */ + private Integer sortNum; + + /** + * 角色名称 + */ + private String roleName; + + /** + * 角色标识key + */ + private String roleKey; + + /** + * 备注 + */ + private String remarks; + + /** + * 创建者 + */ + private String createBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 修改时间 + */ + private Date updateTime; + + /** + * 菜单ID集 + */ + private List menuIdList; +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/role/RoleOptionVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/role/RoleOptionVO.java new file mode 100644 index 0000000..5b6b9f9 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/role/RoleOptionVO.java @@ -0,0 +1,29 @@ +package com.sso.model.vo.role; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 角色-下拉选项列表返回对象 + * + * @author 程序员小强 + */ +@Data +public class RoleOptionVO implements Serializable { + + private static final long serialVersionUID = 6861288921505856266L; + + /** + * 角色ID + */ + private Long roleId; + + /** + * 角色名称 + */ + private String roleName; + + private Integer status; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/role/RolePageVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/role/RolePageVO.java new file mode 100644 index 0000000..4c5fa78 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/role/RolePageVO.java @@ -0,0 +1,73 @@ +package com.sso.model.vo.role; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 角色分页列表返回对象 + * + * @author 程序员小强 + */ +@Data +public class RolePageVO implements Serializable { + + private static final long serialVersionUID = -6710365268589472423L; + + /** + * 角色ID + */ + private Long roleId; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 角色名称 + */ + private String roleName; + + /** + * 角色标识key + */ + private String roleKey; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 显示顺序 + */ + private Integer sortNum; + + /** + * 使用的用户数 + */ + private Integer userCount; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserDetailVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserDetailVO.java new file mode 100644 index 0000000..8d7682d --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserDetailVO.java @@ -0,0 +1,89 @@ +package com.sso.model.vo.user; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * 用户详情 + * + * @author 程序员小强 + */ +@Data +public class UserDetailVO implements Serializable { + + private static final long serialVersionUID = -8029802544403883540L; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 用户ID + */ + private Long userId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 用户性别 0-男;1-女;2-未知 + */ + private Integer sex; + + /** + * 手机号码 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + /** + * 头像 + */ + private String avatar; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 最后登录IP + */ + private String loginIp; + + /** + * 最后登录时间 + */ + private Date lastLoginTime; + + /** + * 备注 + */ + private String remarks; + + + private Long deptId; + + private List roleIdList; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserOnlinePageVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserOnlinePageVO.java new file mode 100644 index 0000000..ec15d6b --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserOnlinePageVO.java @@ -0,0 +1,113 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.model.vo.user; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 登录日志实体类 + * + * @author 程序员小强 + * @date 2021-01-23 10:45:22 + */ +@Data +public class UserOnlinePageVO implements Serializable { + + private static final long serialVersionUID = -3040345372070636603L; + + /** + * 用户ID + */ + private Long userId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 密码 + */ + private String password; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 手机号码 + */ + private String phone; + + /** + * 请求标识 + */ + private String requestId; + + /** + * 来源IP + */ + private String sourceIp; + + /** + * 来源地址 + */ + private String sourceAddress; + + /** + * 浏览器 + */ + private String browserName; + + /** + * 操作系统 + */ + private String operateSystem; + + /** + * 登录状态 0-成功;1-失败 + */ + private Integer status; + + /** + * 登录时间戳 + */ + private String loginTime; + + /** + * 主动退出时间戳 + */ + private String loginOutTime; + + /** + * 失效时间戳 + */ + private String expireTime; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + /** + * 是否超级管理员用户 + */ + private Boolean supperAdminFlag; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserOnlineSysVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserOnlineSysVO.java new file mode 100644 index 0000000..b8defb6 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserOnlineSysVO.java @@ -0,0 +1,37 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.model.vo.user; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 登录日志实体类 + * + * @author 程序员小强 + * @date 2021-01-23 10:45:22 + */ +@Data +public class UserOnlineSysVO implements Serializable { + + private static final long serialVersionUID = -3040345372070636603L; + + /** + * 系统编码 + */ + private String sysCode; + + /** + * 系统名称 + */ + private String sysName; + + /** + * 登录时间 + */ + private String loginTime; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserOptionVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserOptionVO.java new file mode 100644 index 0000000..accc827 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserOptionVO.java @@ -0,0 +1,44 @@ +package com.sso.model.vo.user; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.io.Serializable; + +/** + * 用户详情 + * + * @author 程序员小强 + */ +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UserOptionVO implements Serializable { + + private static final long serialVersionUID = -2168630461954434904L; + + /** + * 用户ID + */ + private Long userId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 手机号码 + */ + private String phone; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserPageVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserPageVO.java new file mode 100644 index 0000000..e5d85b0 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserPageVO.java @@ -0,0 +1,93 @@ +package com.sso.model.vo.user; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 用户实体类 + * + * @author 程序员小强 + */ +@Data +public class UserPageVO implements Serializable { + + private static final long serialVersionUID = 4387256959848907939L; + + /** + * 用户ID + */ + private Long userId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 密码 + */ + private String password; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 用户性别 0-男;1-女;2-未知 + */ + private Integer sex; + + /** + * 手机号码 + */ + private String phone; + + /** + * 所属部门名称 + */ + private String deptName; + + /** + * 角色名称集 + */ + private String roleNames; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 最后登录时间 + */ + private Date lastLoginTime; + + /** + * 创建者 + */ + private String createBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 是否已绑定系统 + */ + private Boolean sysBindFlag; + + /** + * 是否超级管理员用户 + */ + private Boolean supperAdminFlag; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserProfileVO.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserProfileVO.java new file mode 100644 index 0000000..c197889 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/model/vo/user/UserProfileVO.java @@ -0,0 +1,98 @@ +package com.sso.model.vo.user; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 用户个人中心详情 + * + * @author 程序员小强 + */ +@Data +public class UserProfileVO implements Serializable { + + private static final long serialVersionUID = 3347667088081428127L; + + /** + * 用户ID + */ + private Long userId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 用户性别 0-男;1-女;2-未知 + */ + private Integer sex; + + /** + * 手机号码 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + /** + * 头像 + */ + private String avatar; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + + /** + * 最后登录IP + */ + private String loginIp; + + /** + * 最后登录时间 + */ + private Date lastLoginTime; + + /** + * 备注 + */ + private String remarks; + + /** + * 创建者 + */ + private String createBy; + + /** + * 最后修改者 + */ + private String updateBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/CaptchaService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/CaptchaService.java new file mode 100644 index 0000000..d58e740 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/CaptchaService.java @@ -0,0 +1,24 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.admin; + +import com.sso.model.vo.captcha.CaptchaVO; + +import javax.servlet.http.HttpServletResponse; + +/** + * 验证码接口 + * + * @author 程序员小强 + */ +public interface CaptchaService { + + /** + * 生成验证码 + * + * @param response + */ + CaptchaVO genCode(HttpServletResponse response); +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/DeptService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/DeptService.java new file mode 100755 index 0000000..18dd3ae --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/DeptService.java @@ -0,0 +1,77 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.admin; + +import com.sso.model.bo.dept.DeptDeleteBO; +import com.sso.model.bo.dept.DeptMgmtTreeBO; +import com.sso.model.bo.dept.DeptSaveBO; +import com.sso.model.bo.dept.DeptUpdateBO; +import com.sso.model.vo.dept.DeptDetailVO; +import com.sso.model.vo.dept.DeptMgmtTreeNodeVO; +import com.sso.model.vo.dept.DeptOptionTreeNodeVO; + +import java.util.List; + +/** + * 部门管理接口 + * + * @author 程序员小强 + */ +public interface DeptService { + + /** + * 获取系统下的-部门树 + * + * @param treeBO 查询参数 + * @return 部门树 + * @author 程序员小强 + */ + List listDeptMgmtTree(DeptMgmtTreeBO treeBO); + + /** + * 部门下拉选项树 + * 状态:仅正常+未删除 + * + * @param sysCode 系统编码 + * @return 部门树 + * @author 程序员小强 + */ + List listDeptOptionTree(String sysCode); + + /** + * 部门详情 + * + * @param deptId 部门ID + * @return 部门详情 + * @author 程序员小强 + */ + DeptDetailVO getDeptDetail(Long deptId); + + /** + * 新增部门 + * + * @param saveBO + * @author 程序员小强 + */ + void addDept(DeptSaveBO saveBO); + + /** + * 修改部门 + * + * @param updateBO + * @author 程序员小强 + */ + void updateDept(DeptUpdateBO updateBO); + + /** + * 删除部门(部门逻辑删-用户部门关系物理删) + * + * @param deleteBO + * @author 程序员小强 + */ + void deleteDept(DeptDeleteBO deleteBO); + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/FileUploadService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/FileUploadService.java new file mode 100644 index 0000000..2592e20 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/FileUploadService.java @@ -0,0 +1,37 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.admin; + +import org.springframework.web.multipart.MultipartFile; + +/** + * 文件上传接口 + * 注:目前上传到了本机,建议上传到固定的图片服务器 + * + * @author 程序员小强 + */ +public interface FileUploadService { + + /** + * 上传用户头像 + * + * @param userId 用户ID + * @param operateName 操作者用户名 + * @param avatarFile 图片文件 + * @return 图片地址 + */ + String uploadUserAvatar(Long userId, String operateName, MultipartFile avatarFile); + + /** + * 系统图标Icon + * + * @param sysId 系统ID + * @param operateName 操作者用户名 + * @param iconFile 图片文件 + * @return 图标地址 + */ + String uploadSystemIcon(Long sysId, String operateName, MultipartFile iconFile); + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/LoginLogService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/LoginLogService.java new file mode 100755 index 0000000..defefca --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/LoginLogService.java @@ -0,0 +1,26 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.admin; + +import com.sso.common.model.result.ResultPageModel; +import com.sso.model.bo.login.LoginLogListPageBO; +import com.sso.model.vo.login.LoginLogPageVO; + +/** + * 登录日志接口 + * + * @author 程序员小强 + */ +public interface LoginLogService { + + /** + * 登录日志分页列表 + * + * @param pageBO + * @return 登录日志列表 + */ + ResultPageModel listPageUser(LoginLogListPageBO pageBO); + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/MenuService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/MenuService.java new file mode 100644 index 0000000..0e46ae0 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/MenuService.java @@ -0,0 +1,71 @@ +package com.sso.service.admin; + +import com.sso.model.bo.menu.MenuDeleteBO; +import com.sso.model.bo.menu.MenuSaveBO; +import com.sso.model.bo.menu.MenuTreeBO; +import com.sso.model.bo.menu.MenuUpdateBO; +import com.sso.model.vo.menu.MenuOptionTreeNodeVO; +import com.sso.model.vo.menu.MenuTreeNodeVO; +import com.sso.model.vo.menu.MenuDetailVO; + +import java.util.List; + +/** + * 菜单管理接口 + * + * @author 程序员小强 + */ +public interface MenuService { + + + /** + * 菜单树 + * + * @param treeBO + * @return 菜单树 + */ + List listMenuTree(MenuTreeBO treeBO); + + /** + * 菜单树下拉选项列表 + * 注:只查启用 + * + * @param treeBO + * @return 菜单树 + */ + List listMenuOptionTree(MenuTreeBO treeBO); + + + /** + * 菜单详情 + * + * @param menuId + * @return 菜单详情 + */ + MenuDetailVO getMenuDetail(Long menuId); + + /** + * 新增菜单 + * + * @param saveBO + * @author 程序员小强 + */ + void addMenu(MenuSaveBO saveBO); + + /** + * 修改菜单 + * + * @param updateBO + * @author 程序员小强 + */ + void updateMenu(MenuUpdateBO updateBO); + + /** + * 删除菜单(逻辑删) + * + * @param deleteBO + * @author 程序员小强 + */ + void deleteMenu(MenuDeleteBO deleteBO); + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/RoleService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/RoleService.java new file mode 100644 index 0000000..445f4b7 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/RoleService.java @@ -0,0 +1,74 @@ +package com.sso.service.admin; + +import com.sso.common.model.result.ResultPageModel; +import com.sso.model.bo.role.*; +import com.sso.model.vo.role.RoleDetailVO; +import com.sso.model.vo.role.RoleOptionVO; +import com.sso.model.vo.role.RolePageVO; + +import java.util.List; + +/** + * 角色相关接口 + * + * @author 程序员小强 + */ +public interface RoleService { + + /** + * 分页列表 + * + * @param pageBO + * @return 角色列表 + */ + ResultPageModel listPageRole(RoleListPageBO pageBO); + + /** + * 角色下拉选项列表 + * + * @param optionBO + * @return 角色列表 + */ + List listRoleOption(RoleListOptionBO optionBO); + + /** + * 角色详情 + * + * @param roleId 角色ID + * @return 角色详情 + * @author 程序员小强 + */ + RoleDetailVO getDeptDetail(Long roleId); + + /** + * 新增角色 + * + * @param saveBO + * @author 程序员小强 + */ + void addRole(RoleSaveBO saveBO); + + /** + * 修改角色 + * + * @param updateBO + * @author 程序员小强 + */ + void updateRole(RoleUpdateBO updateBO); + + /** + * 删除角色(逻辑删) + * + * @param deleteBO + * @author 程序员小强 + */ + void deleteRole(RoleDeleteBO deleteBO); + + /** + * 移除角色用户绑定关系 + * + * @param removeUserBO + * @author 程序员小强 + */ + void removeUserRole(RoleRemoveUserBO removeUserBO); +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/SystemMgmtService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/SystemMgmtService.java new file mode 100644 index 0000000..dfd9063 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/SystemMgmtService.java @@ -0,0 +1,49 @@ +package com.sso.service.admin; + + +import com.sso.common.model.result.ResultPageModel; +import com.sso.model.bo.platform.SystemMgmtListPageBO; +import com.sso.model.bo.platform.SystemMgmtRemoveBO; +import com.sso.model.bo.platform.SystemMgmtSaveBO; +import com.sso.model.bo.platform.SystemMgmtStatusBO; +import com.sso.model.vo.platform.SystemMgmtPageVO; + +/** + * 系统管理-数据权限相关接口 + * + * @author 程序员小强 + */ +public interface SystemMgmtService { + + /** + * 系统管理员-用户分页列表 + * + * @param pageBO + * @return 用户 + */ + ResultPageModel listPageSysMgmtUser(SystemMgmtListPageBO pageBO); + + /** + * 新增-管理员权限 + * + * @param saveBO + * @author 程序员小强 + */ + void addSystemMgmt(SystemMgmtSaveBO saveBO); + + /** + * 修改-管理员权限账号状态 + * + * @param saveBO + * @author 程序员小强 + */ + void updateStatus(SystemMgmtStatusBO saveBO); + + /** + * 移除-用户管理员权限 + * + * @param removeBO + * @author 程序员小强 + */ + void removeUserSystemMgmt(SystemMgmtRemoveBO removeBO); +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/SystemService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/SystemService.java new file mode 100644 index 0000000..dc77bc7 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/SystemService.java @@ -0,0 +1,76 @@ +package com.sso.service.admin; + +import com.sso.model.bo.platform.*; +import com.sso.model.vo.platform.SystemDetailVO; +import com.sso.model.vo.platform.SystemListVO; + +import java.util.List; + +/** + * 平台管理相关接口 + * + * @author 程序员小强 + */ +public interface SystemService { + + /** + * 我的平台列表 + * + * @return 系统列表 + */ + List listMySystem(); + + /** + * 我的平台排序 + * + * @param systemSortBO + */ + void sortMySystem(SystemSortBO systemSortBO); + + /** + * 我的平台管理列表 + * + * @return 系统列表 + */ + List listMyMgmtSystem(); + + /** + * 系统平台详情 + * + * @param sysCode + * @return 系统详情 + */ + SystemDetailVO getDetailBySysCode(String sysCode); + + /** + * 新增-目标平台系统 + * + * @param saveBO + * @author 程序员小强 + */ + void addSystem(SystemSaveBO saveBO); + + /** + * 修改-目标平台系统 + * + * @param updateBO + * @author 程序员小强 + */ + void updateSystem(SystemUpdateBO updateBO); + + /** + * 修改-秘钥 + * + * @param updateBO + * @author 程序员小强 + */ + void updateSystemSecret(SystemUpdateSecretBO updateBO); + + /** + * 删除-目标平台系统(逻辑删) + * + * @param deleteBO + * @author 程序员小强 + */ + void deleteSystem(SystemDeleteBO deleteBO); +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/UserOnlineService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/UserOnlineService.java new file mode 100644 index 0000000..dcab96c --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/UserOnlineService.java @@ -0,0 +1,34 @@ +package com.sso.service.admin; + +import com.sso.common.model.result.ResultPageModel; +import com.sso.model.bo.user.UserOnlineListPageBO; +import com.sso.model.vo.user.UserOnlinePageVO; +import com.sso.model.vo.user.UserOnlineSysVO; + +import java.util.List; + +/** + * 在线用户接口 + * + * @author 程序员小强 + */ +public interface UserOnlineService { + + /** + * 在线用户分页列表 + * + * @param pageBO + * @return 用户 + */ + ResultPageModel listPageUser(UserOnlineListPageBO pageBO); + + /** + * 查看用户已登录的子系统 + * + * @param userId + * @return 已登录系统列表 + */ + List listOnlineSys(Long userId); + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/UserService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/UserService.java new file mode 100644 index 0000000..24ce280 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/UserService.java @@ -0,0 +1,124 @@ +package com.sso.service.admin; + +import com.sso.common.model.result.ResultPageModel; +import com.sso.model.bo.user.*; +import com.sso.model.vo.user.UserDetailVO; +import com.sso.model.vo.user.UserOptionVO; +import com.sso.model.vo.user.UserPageVO; +import com.sso.model.vo.user.UserProfileVO; + +import java.util.List; + +/** + * 用户管理接口 + * + * @author 程序员小强 + */ +public interface UserService { + + /** + * 用户分页列表 + * + * @param pageBO + * @return 用户 + */ + ResultPageModel listPageUser(UserListPageBO pageBO); + + /** + * 用户详情 + * + * @param detailBO + * @return 用户详情 + */ + UserDetailVO getUserDetail(UserDetailBO detailBO); + + /** + * 个人中心详情 + * + * @param userId + * @return + */ + UserProfileVO getUserProfile(Long userId); + + /** + * 根据手机号查询用户 + * + * @param phone + * @return 用户 + */ + UserOptionVO getUserByPhone(String phone); + + /** + * 根据用户名查询用户 + * + * @param username + * @return 用户 + */ + UserOptionVO getUserByUserName(String username); + + /** + * 根据用户名或手机号查询用户列表 + * + * @param keywords + * @return 用户 + */ + List listUserOption(String keywords); + + /** + * 添加用户 + * + * @param addBO + */ + void addUser(UserAddBO addBO); + + /** + * 添加用户平台关系 + * + * @param addBO + */ + void addUserPlatformRelation(UserPlatformAddBO addBO); + + /** + * 修改用户 + * + * @param updateBO + */ + void updateUser(UserUpdateBO updateBO); + + /** + * 移除用户与系统关系 + * + * @param removeBO + */ + void removeUserSystem(UserSystemRemoveBO removeBO); + + /** + * 修改个人信息 + * + * @param updateBO + */ + void updateProfile(UserUpdateProfileBO updateBO); + + /** + * 修改个人密码 + * + * @param updateBO + */ + void updatePwd(UserUpdatePwdBO updateBO); + + /** + * 重置密码 + * + * @param restPwdBO + */ + void resetPwd(UserRestPwdBO restPwdBO); + + /** + * 删除用户 + * + * @param deleteBO + */ + void deleteUser(UserDeleteBO deleteBO); + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/CaptchaServiceImpl.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/CaptchaServiceImpl.java new file mode 100644 index 0000000..da7761b --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/CaptchaServiceImpl.java @@ -0,0 +1,92 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.admin.impl; + +import cn.hutool.core.codec.Base64; +import com.google.code.kaptcha.Producer; +import com.sso.common.constant.CacheConstants; +import com.sso.common.constant.SsoConstants; +import com.sso.common.exception.BusinessException; +import com.sso.common.utils.UUIDUtil; +import com.sso.framework.config.property.SysConfigProperty; +import com.sso.framework.redis.RedisCache; +import com.sso.model.vo.captcha.CaptchaVO; +import com.sso.service.admin.CaptchaService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.util.FastByteArrayOutputStream; + +import javax.annotation.Resource; +import javax.imageio.ImageIO; +import javax.servlet.http.HttpServletResponse; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + + +/** + * 验证码接口 + * + * @author 程序员小强 + */ +@Slf4j +@Service +public class CaptchaServiceImpl implements CaptchaService { + + @Resource + private RedisCache redisCache; + + @Resource(name = "captchaProducer") + private Producer captchaProducer; + + @Resource(name = "captchaProducerMath") + private Producer captchaProducerMath; + + @Resource + private SysConfigProperty sysConfigProperty; + + + /** + * 生成验证码 + * + * @param response + */ + @Override + public CaptchaVO genCode(HttpServletResponse response) { + //生成随机请求ID + String requestId = UUIDUtil.getUUID(); + String capStr = null; + String code = null; + BufferedImage image = null; + + // 生成验证码 + if (SsoConstants.CAPTCHA_TYPE_MATH.equals(sysConfigProperty.getCaptchaType())) { + String capText = captchaProducerMath.createText(); + capStr = capText.substring(0, capText.lastIndexOf("@")); + code = capText.substring(capText.lastIndexOf("@") + 1); + image = captchaProducerMath.createImage(capStr); + } else if (SsoConstants.CAPTCHA_TYPE_CHAR.equals(sysConfigProperty.getCaptchaType())) { + capStr = code = captchaProducer.createText(); + image = captchaProducer.createImage(capStr); + } else { + throw new BusinessException("不支持的验证码类型"); + } + + + //验证码5分钟内有效 + String cacheKey = CacheConstants.getCaptchaCodeKey(requestId); + redisCache.set(cacheKey, code, CacheConstants.CAPTCHA_EXPIRE, TimeUnit.MINUTES); + + //转换流 + FastByteArrayOutputStream os = new FastByteArrayOutputStream(); + try { + ImageIO.write(image, "jpg", os); + } catch (IOException e) { + throw new BusinessException("验证码生成错误!"); + } + + return new CaptchaVO(requestId, Base64.encode(os.toByteArray())); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/DeptServiceImpl.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/DeptServiceImpl.java new file mode 100755 index 0000000..cee2a06 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/DeptServiceImpl.java @@ -0,0 +1,362 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.admin.impl; + + +import com.sso.common.enums.DelFlagEnum; +import com.sso.common.enums.DeptStatusEnum; +import com.sso.common.enums.exception.DeptResStatusEnum; +import com.sso.common.enums.exception.SysResStatusEnum; +import com.sso.common.exception.BusinessException; +import com.sso.common.utils.ObjectUtils; +import com.sso.common.utils.bean.BeanCopierUtil; +import com.sso.common.utils.tree.ListToTreeUtil; +import com.sso.dao.entity.SsoDept; +import com.sso.dao.mapper.SsoDeptMapper; +import com.sso.dao.mapper.SsoDeptTreePathMapper; +import com.sso.dao.mapper.SsoUserDeptMapper; +import com.sso.dao.query.SsoDeptQuery; +import com.sso.model.bo.dept.DeptDeleteBO; +import com.sso.model.bo.dept.DeptMgmtTreeBO; +import com.sso.model.bo.dept.DeptSaveBO; +import com.sso.model.bo.dept.DeptUpdateBO; +import com.sso.model.vo.dept.DeptDetailVO; +import com.sso.model.vo.dept.DeptMgmtTreeNodeVO; +import com.sso.model.vo.dept.DeptOptionTreeNodeVO; +import com.sso.service.admin.DeptService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * 部门管理接口实现类 + * + * @author 程序员小强 + */ +@Slf4j +@Service +@Transactional(rollbackFor = Exception.class) +public class DeptServiceImpl implements DeptService { + + @Resource + private SsoDeptMapper ssoDeptMapper; + @Resource + private SsoUserDeptMapper ssoUserDeptMapper; + @Resource + private SsoDeptTreePathMapper ssoDeptTreePathMapper; + + + /** + * 获取部门树列表 + * + * @author 程序员小强 + */ + @Override + public List listDeptMgmtTree(DeptMgmtTreeBO treeBO) { + SsoDeptQuery query = new SsoDeptQuery() + .setSysCode(treeBO.getSysCode()) + .setStatus(treeBO.getStatus()) + .setDeptNameLike(treeBO.getDeptNameLike()) + .setDelFlag(DelFlagEnum.OK.getStatus()); + + List ssoDeptList = ssoDeptMapper.listByCondition(query); + if (CollectionUtils.isEmpty(ssoDeptList)) { + return new ArrayList<>(0); + } + + //转换成树结构 + List treeNodeVOList = BeanCopierUtil.copyList(ssoDeptList, DeptMgmtTreeNodeVO.class); + ListToTreeUtil result = new ListToTreeUtil<>(); + + return result.getTreeListObject(treeNodeVOList); + } + + /** + * 部门下拉选项树 + * 状态:仅正常+未删除 + * + * @param sysCode 系统编码 + * @return 部门树 + * @author 程序员小强 + */ + @Override + public List listDeptOptionTree(String sysCode) { + SsoDeptQuery query = new SsoDeptQuery() + .setSysCode(sysCode) + .setStatus(DeptStatusEnum.OK.getStatus()) + .setDelFlag(DelFlagEnum.OK.getStatus()); + + List ssoDeptList = ssoDeptMapper.listByCondition(query); + + //转换成树结构 + List treeNodeVOList = BeanCopierUtil.copyList(ssoDeptList, DeptOptionTreeNodeVO.class); + ListToTreeUtil result = new ListToTreeUtil<>(); + + return result.getTreeListObject(treeNodeVOList); + } + + /** + * 部门详情BO + * + * @author 程序员小强 + */ + @Override + public DeptDetailVO getDeptDetail(Long deptId) { + SsoDept ssoDept = ssoDeptMapper.getByDeptId(deptId); + + //部门不存在 + if (null == ssoDept) { + log.error("[ 部门不存在 ] >> deptId:{}", deptId); + throw new BusinessException(DeptResStatusEnum.DEPT_NOT_EXISTS); + } + + //部门已删除 + if (DelFlagEnum.DELETED.getStatus().equals(ssoDept.getDelFlag())) { + log.error("[ 部门已删除 ] >> deptId:{}", deptId); + throw new BusinessException(DeptResStatusEnum.ALREADY_DELETE); + } + + return BeanCopierUtil.copy(ssoDept, DeptDetailVO.class); + } + + /** + * 新增部门 + * + * @param saveBO + * @author 程序员小强 + */ + @Override + public void addDept(DeptSaveBO saveBO) { + //部门名称判重 + if (this.checkNameExists(saveBO.getSysCode(), saveBO.getDeptName())) { + log.error("[ 部门名称重复 ] >> {}", saveBO.getLogValue()); + throw new BusinessException(DeptResStatusEnum.REPEAT_NAME, saveBO.getDeptName()); + } + + //校验父部门 + this.checkDeptParent(saveBO.getDeptParentId()); + + SsoDept ssoDept = BeanCopierUtil.copy(saveBO, SsoDept.class); + ssoDept.setCreateBy(saveBO.getOperateBy()); + ssoDept.setUpdateBy(saveBO.getOperateBy()); + + int row = ssoDeptMapper.insertSelective(ssoDept); + if (row == 0) { + log.error("[ 部门新增失败 ] >> {}", saveBO.getLogValue()); + throw new BusinessException(SysResStatusEnum.ADD_FAIL); + } + + // 维护部门关系节点 + ssoDeptTreePathMapper.insertBatch(ssoDept.getDeptId(), ssoDept.getDeptParentId()); + log.info("[ 部门 ] >> [ 新增完成 ] >> {}", saveBO.getLogValue()); + } + + /** + * 修改部门 + * + * @param updateBO + * @author 程序员小强 + */ + @Override + public void updateDept(DeptUpdateBO updateBO) { + //查询旧的部门信息 + SsoDept oldDept = ssoDeptMapper.getByDeptId(updateBO.getDeptId()); + //部门不存在或者已删除 + if (null == oldDept || DelFlagEnum.DELETED.getStatus().equals(oldDept.getDelFlag())) { + log.error("[ 部门不存在或者已删除 ] >> {}", updateBO.getLogValue()); + throw new BusinessException(DeptResStatusEnum.NOT_EXISTS_OR_DELETE); + } + + //父部门不能选自己 + if (updateBO.getDeptId().equals(updateBO.getDeptParentId())) { + log.error("[ 父部门不能选自己 ] >> {}", updateBO.getLogValue()); + throw new BusinessException(DeptResStatusEnum.PARENT_CANNOT_SELF); + } + + //部门名称判重 + if (this.checkNameExists(updateBO.getSysCode(), updateBO.getDeptName(), updateBO.getDeptId())) { + log.error("[ 部门名称重复 ] >> {}", updateBO.getLogValue()); + throw new BusinessException(DeptResStatusEnum.REPEAT_NAME, updateBO.getDeptName()); + } + + //校验父部门 + this.checkDeptParent(updateBO.getDeptParentId()); + + //状态变为停用-校验是否存在未停用的子部门 + if (!oldDept.getStatus().equals(updateBO.getStatus()) && DeptStatusEnum.DISABLE.getStatus().equals(updateBO.getStatus())) { + this.checkHasEnableChild(updateBO.getDeptId()); + } + + SsoDept ssoDept = BeanCopierUtil.copy(updateBO, SsoDept.class); + ssoDept.setUpdateBy(updateBO.getOperateBy()); + int row = ssoDeptMapper.updateByDeptId(ssoDept); + if (row == 0) { + log.error("[ 部门修改失败 ] >> {}", updateBO.getLogValue()); + throw new BusinessException(SysResStatusEnum.UPDATE_FAIL); + } + + //父部门无变化 + if (oldDept.getDeptParentId().equals(updateBO.getDeptParentId())) { + log.info("[ 部门修改完成 ] 上级无变化 >> {}", updateBO.getLogValue()); + return; + } + + //若链路变化-重新建立-祖先后代关系链路 + this.doRestDeptTreePath(updateBO, ssoDept); + + log.info("[ 部门 ] >> [ 修改完成 ] 部门修改完成 >> {}", updateBO.getLogValue()); + } + + /** + * 删除部门(部门逻辑删-用户部门关系物理删) + * + * @param deleteBO + * @author 程序员小强 + */ + @Override + public void deleteDept(DeptDeleteBO deleteBO) { + + //部门下存在子部门 + if (this.isExistChildren(deleteBO.getDeptId())) { + log.error("[ 部门下存在子部门 ] >> {}", deleteBO.getLogValue()); + throw new BusinessException(DeptResStatusEnum.HASH_CHILD_DEPT); + } + + //部门下存在用户 + if (this.isExistUser(deleteBO.getDeptId())) { + log.error("[ 部门下存在用户 ] >> {}", deleteBO.getLogValue()); + throw new BusinessException(DeptResStatusEnum.HASH_CHILD_USER); + } + + SsoDept ssoDept = new SsoDept(); + ssoDept.setDeptId(deleteBO.getDeptId()); + ssoDept.setUpdateBy(deleteBO.getOperateBy()); + ssoDept.setDelFlag(DelFlagEnum.DELETED.getStatus()); + ssoDeptMapper.updateByDeptIdSelective(ssoDept); + log.info("[ 部门 ] >> [ 删除完成 ] >> {}", deleteBO.getLogValue()); + } + + /** + * 重新建立-部门祖先后代关系 + * + * @param updateBO + * @param ssoDept + */ + private void doRestDeptTreePath(DeptUpdateBO updateBO, SsoDept ssoDept) { + //查询当前所有子 + List allChild = ssoDeptTreePathMapper.getAllChild(updateBO.getDeptId()); + + // 删除子树 + ssoDeptTreePathMapper.deleteChildTree(updateBO.getDeptId()); + + // 重新建立部门关系节点 + ssoDeptTreePathMapper.insertBatch(ssoDept.getDeptId(), ssoDept.getDeptParentId()); + + //校验是否存在未停用的子部门 + if (DeptStatusEnum.OK.getStatus().equals(ssoDept.getStatus())) { + //启用部门 > 启用该部门的所有上级部门 + ssoDeptMapper.updateAllParentStatus(ssoDept); + } + + if (CollectionUtils.isEmpty(allChild)) { + return; + } + + for (SsoDept dept : allChild) { + if (dept.getDeptId().equals(updateBO.getDeptId())) { + continue; + } + // 删除子树 + ssoDeptTreePathMapper.deleteChildTree(dept.getDeptId()); + // 重新建立部门关系节点 + ssoDeptTreePathMapper.insertBatch(dept.getDeptId(), dept.getDeptParentId()); + } + log.info("[ 部门 ] >> [ 修改 ] 更新链路 oldChildSize:{} ", allChild.size()); + } + + /** + * 判断是否存在人员 + * + * @author 程序员小强 + */ + private boolean isExistUser(Long deptId) { + if (null == deptId) { + return false; + } + return ssoUserDeptMapper.countByDeptId(deptId) > 0; + } + + /** + * 判断是否存子部门 + * + * @author 程序员小强 + */ + private boolean isExistChildren(Long deptId) { + SsoDeptQuery query = new SsoDeptQuery(); + query.setDeptParentId(deptId); + query.setDelFlag(DelFlagEnum.OK.getStatus()); + return ssoDeptMapper.countByCondition(query) > 0; + } + + /** + * 校验父部门 + * + * @param deptParentId + */ + private void checkDeptParent(Long deptParentId) { + //根部门 + if (deptParentId <= 0) { + return; + } + SsoDept ssoDept = ssoDeptMapper.getByDeptId(deptParentId); + //父部门不存在 + if (null == ssoDept) { + log.error("[ 父部门不存在 ] >> deptParentId:{}", deptParentId); + throw new BusinessException(DeptResStatusEnum.PARENT_NOT_EXISTS); + } + + //父部门已删除 + if (DelFlagEnum.DELETED.getStatus().equals(ssoDept.getDelFlag())) { + log.error("[ 父部门已删除 ] >> deptParentId:{}", deptParentId); + throw new BusinessException(DeptResStatusEnum.PARENT_IS_DELETE); + } + } + + /** + * 校验是否存在启用的子部门 + * + * @param deptParentId + */ + private void checkHasEnableChild(Long deptParentId) { + //该部门包含未停用的子部门 + if (ssoDeptMapper.countByDeptParentIdAndStatus(deptParentId, DeptStatusEnum.OK.getStatus()) > 0) { + throw new BusinessException(DeptResStatusEnum.HASH_ENABLE_CHILD); + } + } + + /** + * 部门名称判重 + * + * @param sysCode + * @param deptName + * @param excludeDeptId 需要排除的部门ID + */ + private boolean checkNameExists(String sysCode, String deptName, Long... excludeDeptId) { + SsoDeptQuery query = new SsoDeptQuery(); + query.setSysCode(sysCode); + query.setDeptName(deptName); + //未删除 + query.setDelFlag(DelFlagEnum.OK.getStatus()); + if (ObjectUtils.isNotNull(excludeDeptId) && excludeDeptId.length > 0) { + query.setExcludeDeptId(excludeDeptId[0]); + } + return ssoDeptMapper.countByCondition(query) > 0; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/FileUploadServiceImpl.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/FileUploadServiceImpl.java new file mode 100644 index 0000000..7ff01ae --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/FileUploadServiceImpl.java @@ -0,0 +1,133 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.admin.impl; + +import com.sso.common.constant.CacheConstants; +import com.sso.common.constant.SsoConstants; +import com.sso.common.exception.BusinessException; +import com.sso.common.model.login.LoginResultVO; +import com.sso.common.utils.FileUploadUtils; +import com.sso.common.utils.StringUtils; +import com.sso.dao.mapper.SsoSystemMapper; +import com.sso.dao.mapper.SsoUserMapper; +import com.sso.framework.config.property.SysConfigProperty; +import com.sso.framework.redis.RedisCache; +import com.sso.service.admin.FileUploadService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; + +/** + * 文件上传接口 + * 注:目前上传到了本机,建议上传到固定的图片服务器 + * + * @author 程序员小强 + */ +@Slf4j +@Service +@Transactional(rollbackFor = Exception.class) +public class FileUploadServiceImpl implements FileUploadService { + + @Autowired + private RedisCache redisCache; + + @Resource + private SsoUserMapper ssoUserMapper; + + @Resource + private SsoSystemMapper ssoSystemMapper; + + /** + * 上传用户头像 + * + * @param userId 用户ID + * @param operateName 操作者用户名 + * @param avatarFile 图片文件 + * @return 图片地址 + */ + @Override + public String uploadUserAvatar(Long userId, String operateName, MultipartFile avatarFile) { + if (avatarFile.isEmpty()) { + throw new BusinessException("头像文件不能为空!"); + } + + String avatar = ""; + try { + avatar = FileUploadUtils.upload(SysConfigProperty.getFileProfile(), SsoConstants.AVATAR_PATH, avatarFile); + } catch (Exception e) { + throw new BusinessException("头像上传失败!"); + } + + if (StringUtils.isBlank(avatar)) { + throw new BusinessException("头像修改失败!"); + } + + //更新用户头像地址 + ssoUserMapper.updateAvatar(userId, avatar, operateName); + + //若用户已登录-刷新当前登录用户-缓存中的头像信息 + this.doUpdateOnlineUserAvatar(userId, avatar); + + log.info("[ 上传用户头像 ] >> userId:{} , operateName:{}", userId, operateName); + return avatar; + } + + /** + * 系统图标Icon + * + * @param sysId 系统ID + * @param operateName 操作者用户名 + * @param iconFile 图片文件 + * @return 图标地址 + */ + @Override + public String uploadSystemIcon(Long sysId, String operateName, MultipartFile iconFile) { + if (iconFile.isEmpty()) { + throw new BusinessException("图标文件不能为空!"); + } + + String sysIcon = ""; + try { + sysIcon = FileUploadUtils.upload(SysConfigProperty.getFileProfile(), SsoConstants.SYSTEM_ICON_PATH, iconFile); + } catch (Exception e) { + throw new BusinessException("系统图标上传失败!"); + } + + if (StringUtils.isBlank(sysIcon)) { + throw new BusinessException("系统图标修改失败!"); + } + + //更新用户头像地址 + ssoSystemMapper.updateIconBySysId(sysId, sysIcon, operateName); + + log.info("[ 上传系统图标Icon ] >> userId:{} , operateName:{}", sysId, operateName); + return sysIcon; + } + + /** + * 若用户已登录-刷新当前登录用户-缓存中的头像信息 + * + * @param userId + * @param avatar + */ + private void doUpdateOnlineUserAvatar(Long userId, String avatar) { + String userIdCacheKey = CacheConstants.getLoginUserIdKey(userId); + //根据unionId查询redis,若用户信息存在 + LoginResultVO lastLoginUser = redisCache.get(userIdCacheKey, LoginResultVO.class); + if (null == lastLoginUser) { + return; + } + + //刷新当前登录用户-缓存中的头像信息 + lastLoginUser.getUser().setAvatar(avatar); + String userTokenCacheKey = CacheConstants.getLoginUserTokenKey(lastLoginUser.getToken()); + redisCache.set(userIdCacheKey, lastLoginUser); + redisCache.set(userTokenCacheKey, lastLoginUser); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/LoginLogServiceImpl.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/LoginLogServiceImpl.java new file mode 100644 index 0000000..f69b43e --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/LoginLogServiceImpl.java @@ -0,0 +1,102 @@ +package com.sso.service.admin.impl; + +import cn.hutool.core.date.DateUtil; +import com.sso.common.model.result.ResultPageModel; +import com.sso.common.utils.StringUtils; +import com.sso.common.utils.bean.BeanCopierUtil; +import com.sso.dao.entity.SsoLoginLog; +import com.sso.dao.mapper.SsoLoginLogMapper; +import com.sso.dao.query.LoginLogQuery; +import com.sso.model.bo.login.LoginLogListPageBO; +import com.sso.model.vo.login.LoginLogPageVO; +import com.sso.service.admin.LoginLogService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * 登录日志接口 + * + * @author 程序员小强 + */ +@Slf4j +@Service +public class LoginLogServiceImpl implements LoginLogService { + + @Resource + private SsoLoginLogMapper ssoLoginLogMapper; + + /** + * 登录日志分页列表 + * + * @param pageBO + * @return 登录日志列表 + */ + @Override + public ResultPageModel listPageUser(LoginLogListPageBO pageBO) { + //构建参数参数 + LoginLogQuery query = this.buildPageQuery(pageBO); + + //统计行数 + int total = ssoLoginLogMapper.countByCondition(query); + if (total <= 0) { + return ResultPageModel.defaultValue(); + } + + //分页查询 + List loginLogList = ssoLoginLogMapper.listPageByCondition(query); + if (CollectionUtils.isEmpty(loginLogList)) { + return ResultPageModel.defaultValue(); + } + + return ResultPageModel.success(this.buildLoginLogPage(loginLogList), total); + } + + /** + * 构建返回列表 + * + * @param loginLogList + * @return + */ + private List buildLoginLogPage(List loginLogList) { + + LoginLogPageVO item = null; + List resultList = new ArrayList<>(); + for (SsoLoginLog ssoLoginLog : loginLogList) { + item = BeanCopierUtil.copy(ssoLoginLog, LoginLogPageVO.class); + //登录时间 + if (!ObjectUtils.isEmpty(ssoLoginLog.getLoginTime()) && ssoLoginLog.getLoginTime() > 0) { + item.setLoginTime(DateUtil.formatDateTime(new Date(ssoLoginLog.getLoginTime()))); + } + resultList.add(item); + } + return resultList; + } + + /** + * 构建查询参数 + * + * @param pageBO + */ + private LoginLogQuery buildPageQuery(LoginLogListPageBO pageBO) { + LoginLogQuery query = new LoginLogQuery() + .setUsernameLike(pageBO.getUsernameLike()) + .setStatus(pageBO.getStatus()); + + if (StringUtils.isNotBlank(pageBO.getLoginStartTime())) { + query.setLoginStartTime(DateUtil.beginOfDay(DateUtil.parseDate(pageBO.getLoginStartTime())).getTime()); + } + if (StringUtils.isNotBlank(pageBO.getLoginEndTime())) { + query.setLoginEndTime(DateUtil.endOfDay(DateUtil.parseDate(pageBO.getLoginEndTime())).getTime()); + } + query.setPage(pageBO.getPage()); + query.setPageSize(pageBO.getPageSize()); + return query; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/MenuServiceImpl.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/MenuServiceImpl.java new file mode 100644 index 0000000..9d4e962 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/MenuServiceImpl.java @@ -0,0 +1,297 @@ +package com.sso.service.admin.impl; + +import com.sso.common.constant.SsoConstants; +import com.sso.common.enums.DelFlagEnum; +import com.sso.common.enums.exception.MenuResStatusEnum; +import com.sso.common.exception.BusinessException; +import com.sso.common.utils.StringUtils; +import com.sso.common.utils.bean.BeanCopierUtil; +import com.sso.common.utils.tree.ListToTreeUtil; +import com.sso.dao.entity.SsoMenu; +import com.sso.dao.mapper.SsoMenuMapper; +import com.sso.dao.mapper.SsoRoleMenuMapper; +import com.sso.dao.query.SsoMenuQuery; +import com.sso.model.bo.menu.MenuDeleteBO; +import com.sso.model.bo.menu.MenuSaveBO; +import com.sso.model.bo.menu.MenuTreeBO; +import com.sso.model.bo.menu.MenuUpdateBO; +import com.sso.model.vo.menu.MenuDetailVO; +import com.sso.model.vo.menu.MenuOptionTreeNodeVO; +import com.sso.model.vo.menu.MenuTreeNodeVO; +import com.sso.service.admin.MenuService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.StringJoiner; + + +/** + * 菜单管理接口 + * + * @author 程序员小强 + */ +@Slf4j +@Service +@Transactional(rollbackFor = Exception.class) +public class MenuServiceImpl implements MenuService { + + @Resource + private SsoMenuMapper ssoMenuMapper; + + @Resource + private SsoRoleMenuMapper ssoRoleMenuMapper; + + /** + * 菜单树 + * + * @param treeBO + * @return 菜单树 + */ + @Override + public List listMenuTree(MenuTreeBO treeBO) { + SsoMenuQuery query = new SsoMenuQuery() + .setSysCode(treeBO.getSysCode()) + .setMenuNameLike(treeBO.getMenuNameLike()) + .setStatus(treeBO.getStatus()) + .setDelFlag(DelFlagEnum.OK.getStatus()); + + List ssoMenuList = ssoMenuMapper.listByCondition(query); + if (CollectionUtils.isEmpty(ssoMenuList)) { + return new ArrayList<>(0); + } + + //转换成树结构 + List treeNodeVOList = BeanCopierUtil.copyList(ssoMenuList, MenuTreeNodeVO.class); + ListToTreeUtil result = new ListToTreeUtil<>(); + + return result.getTreeListObject(treeNodeVOList); + } + + /** + * 菜单树下拉选项列表 + * 注:只查启用 + * + * @param treeBO + * @return 菜单树 + */ + @Override + public List listMenuOptionTree(MenuTreeBO treeBO) { + SsoMenuQuery query = new SsoMenuQuery() + .setSysCode(treeBO.getSysCode()) + .setStatus(treeBO.getStatus()) + .setDelFlag(DelFlagEnum.OK.getStatus()); + + List ssoMenuList = ssoMenuMapper.listByCondition(query); + if (CollectionUtils.isEmpty(ssoMenuList)) { + return new ArrayList<>(0); + } + + //转换成树结构 + List treeNodeVOList = BeanCopierUtil.copyList(ssoMenuList, MenuOptionTreeNodeVO.class); + ListToTreeUtil result = new ListToTreeUtil<>(); + + return result.getTreeListObject(treeNodeVOList); + } + + /** + * 菜单详情 + * + * @param menuId + * @return 菜单详情 + */ + @Override + public MenuDetailVO getMenuDetail(Long menuId) { + SsoMenu ssoMenu = ssoMenuMapper.getByMenuId(menuId); + + //菜单已删除 + if (DelFlagEnum.DELETED.getStatus().equals(ssoMenu.getDelFlag())) { + throw new BusinessException(MenuResStatusEnum.ALREADY_DELETE); + } + + MenuDetailVO result = BeanCopierUtil.copy(ssoMenu, MenuDetailVO.class); + //处理权限 + if (StringUtils.isNotBlank(ssoMenu.getPermissions())) { + result.setPermissionList(Arrays.asList(ssoMenu.getPermissions().split(SsoConstants.SPLIT_ESCAPE))); + } + + return result; + } + + /** + * 新增菜单 + * + * @param saveBO + * @author 程序员小强 + */ + @Override + public void addMenu(MenuSaveBO saveBO) { + + //菜单名称唯一性校验 + this.checkMenuNameUniq(saveBO); + + //执行保存 + this.doInsertMenu(saveBO); + + log.info("[ 菜单 ] >> [ 新增完成 ] >> {}", saveBO.getLogValue()); + } + + /** + * 修改菜单 + * + * @param updateBO + * @author 程序员小强 + */ + @Override + public void updateMenu(MenuUpdateBO updateBO) { + SsoMenu ssoMenu = ssoMenuMapper.getByMenuId(updateBO.getMenuId()); + //菜单已删除 + if (null == ssoMenu || DelFlagEnum.DELETED.getStatus().equals(ssoMenu.getDelFlag())) { + log.error("[ 菜单已删除 ] >> {}", updateBO.getLogValue()); + throw new BusinessException(MenuResStatusEnum.ALREADY_DELETE); + } + + //父菜单不能选自己 + if (updateBO.getMenuId().equals(updateBO.getMenuParentId())) { + log.error("[ 父菜单不能选自己 ] >> {}", updateBO.getLogValue()); + throw new BusinessException(MenuResStatusEnum.PARENT_CANNOT_SELF); + } + + //菜单名称唯一性校验 + this.checkMenuNameUniq(updateBO, updateBO.getMenuId()); + + //执行保存 + this.doUpdateMenu(updateBO); + + log.info("[ 菜单 ] >> [ 修改完成 ] >> {}", updateBO.getLogValue()); + } + + /** + * 删除菜单(逻辑删) + * + * @param deleteBO + * @author 程序员小强 + */ + @Override + public void deleteMenu(MenuDeleteBO deleteBO) { + //菜单下存在子菜单 + if (this.isExistChildren(deleteBO.getMenuId())) { + log.error("[ 菜单下存在子菜单 ] >> {}", deleteBO.getLogValue()); + throw new BusinessException(MenuResStatusEnum.HASH_CHILD_DEPT); + } + + SsoMenu ssoMenu = new SsoMenu(); + ssoMenu.setMenuId(deleteBO.getMenuId()); + ssoMenu.setUpdateBy(deleteBO.getOperateBy()); + //标记菜单为删除态 + ssoMenu.setDelFlag(DelFlagEnum.DELETED.getStatus()); + ssoMenuMapper.updateByMenuIdSelective(ssoMenu); + + //删除菜单角色关系 + ssoRoleMenuMapper.deleteByMenuId(deleteBO.getMenuId()); + + log.info("[ 菜单 ] >> [ 删除完成 ] >> {}", deleteBO.getLogValue()); + } + + + /** + * 判断是否存在子菜单 + * + * @author 程序员小强 + */ + private boolean isExistChildren(Long menuId) { + SsoMenuQuery query = new SsoMenuQuery(); + query.setMenuParentId(menuId); + query.setDelFlag(DelFlagEnum.OK.getStatus()); + return ssoMenuMapper.countByCondition(query) > 0; + } + + /** + * 执行新增菜单 + * + * @param saveBO + */ + private void doInsertMenu(MenuSaveBO saveBO) { + SsoMenu ssoMenu = this.doBuildEditSsoMenu(saveBO); + ssoMenuMapper.insertSelective(ssoMenu); + } + + /** + * 执行修改菜单 + * + * @param updateBO + */ + private void doUpdateMenu(MenuUpdateBO updateBO) { + SsoMenu ssoMenu = this.doBuildEditSsoMenu(updateBO); + ssoMenu.setMenuId(updateBO.getMenuId()); + ssoMenuMapper.updateByMenuId(ssoMenu); + } + + /** + * 校验 系统下-同父级下-菜单名称的 唯一性 + * + * @param saveBO + * @param excludeMenuId 需要排除的菜单ID(修改时用) + */ + private void checkMenuNameUniq(MenuSaveBO saveBO, Long... excludeMenuId) { + if (StringUtils.isEmpty(saveBO.getSysCode()) || StringUtils.isEmpty(saveBO.getMenuName())) { + return; + } + + SsoMenuQuery query = new SsoMenuQuery() + .setSysCode(saveBO.getSysCode()) + .setMenuName(saveBO.getMenuName()) + .setMenuParentId(saveBO.getMenuParentId()) + .setDelFlag(DelFlagEnum.OK.getStatus()); + + //需要排除 + if (!ObjectUtils.isEmpty(excludeMenuId)) { + query.setExcludeMenuId(excludeMenuId[0]); + return; + } + + if (ssoMenuMapper.countByCondition(query) > 0) { + //同一个父级下菜单名称已经存在 + throw new BusinessException(MenuResStatusEnum.MENU_NAME_EXISTS_IN_SAME_PARENT, saveBO.getMenuName()); + } + } + + /** + * 构建SsoMenu 对象 + * + * @param saveBO + * @return + */ + private SsoMenu doBuildEditSsoMenu(MenuSaveBO saveBO) { + SsoMenu ssoMenu = new SsoMenu(); + ssoMenu.setSysCode(saveBO.getSysCode()); + ssoMenu.setMenuName(saveBO.getMenuName()); + ssoMenu.setMenuType(saveBO.getMenuType()); + ssoMenu.setMenuParentId(saveBO.getMenuParentId()); + ssoMenu.setSortNum(saveBO.getSortNum()); + ssoMenu.setPath(saveBO.getPath()); + ssoMenu.setIcon(saveBO.getIcon()); + ssoMenu.setComponent(saveBO.getComponent()); + ssoMenu.setUseType(saveBO.getUseType()); + ssoMenu.setVisible(saveBO.getVisible()); + ssoMenu.setStatus(saveBO.getStatus()); + ssoMenu.setRemarks(saveBO.getRemarks()); + ssoMenu.setCreateBy(saveBO.getOperateBy()); + ssoMenu.setUpdateBy(saveBO.getOperateBy()); + ssoMenu.setPermissions(""); + //权限标识处理 + if (!CollectionUtils.isEmpty(saveBO.getPermissionList())) { + StringJoiner permissions = new StringJoiner(SsoConstants.PERMISSIONS_SPLIT); + saveBO.getPermissionList().forEach(permissions::add); + ssoMenu.setPermissions(permissions.toString()); + } + return ssoMenu; + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/RoleServiceImpl.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/RoleServiceImpl.java new file mode 100644 index 0000000..7f1ed3f --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/RoleServiceImpl.java @@ -0,0 +1,391 @@ +package com.sso.service.admin.impl; + +import com.sso.common.enums.DelFlagEnum; +import com.sso.common.enums.exception.RoleResStatusEnum; +import com.sso.common.exception.BusinessException; +import com.sso.common.model.result.ResultPageModel; +import com.sso.common.utils.StringUtils; +import com.sso.common.utils.bean.BeanCopierUtil; +import com.sso.dao.dto.RoleCountDTO; +import com.sso.dao.entity.SsoRole; +import com.sso.dao.entity.SsoRoleMenu; +import com.sso.dao.mapper.SsoRoleMapper; +import com.sso.dao.mapper.SsoRoleMenuMapper; +import com.sso.dao.mapper.SsoUserRoleMapper; +import com.sso.dao.query.SsoRoleQuery; +import com.sso.model.bo.role.*; +import com.sso.model.vo.role.RoleDetailVO; +import com.sso.model.vo.role.RoleOptionVO; +import com.sso.model.vo.role.RolePageVO; +import com.sso.service.admin.RoleService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 角色相关接口 + * + * @author 程序员小强 + */ +@Slf4j +@Service +@Transactional(rollbackFor = Exception.class) +public class RoleServiceImpl implements RoleService { + + @Resource + private SsoRoleMapper ssoRoleMapper; + @Resource + private SsoRoleMenuMapper ssoRoleMenuMapper; + @Resource + private SsoUserRoleMapper ssoUserRoleMapper; + + /** + * 分页列表 + * + * @param pageBO + * @return 角色列表 + */ + @Override + public ResultPageModel listPageRole(RoleListPageBO pageBO) { + //构建参数参数 + SsoRoleQuery query = new SsoRoleQuery(pageBO) + .setSysCode(pageBO.getSysCode()) + .setRoleNameLike(pageBO.getRoleNameLike()) + .setRoleKeyLike(pageBO.getRoleKeyLike()) + .setStatus(pageBO.getStatus()) + .setDelFlag(DelFlagEnum.OK.getStatus()); + + //统计行数 + int total = ssoRoleMapper.countByCondition(query); + if (total <= 0) { + return ResultPageModel.defaultValue(); + } + + //分页查询 + List roleList = ssoRoleMapper.listPageByCondition(query); + if (CollectionUtils.isEmpty(roleList)) { + return ResultPageModel.defaultValue(); + } + + //提取当前页角色ID + List roleIdList = roleList.stream().map(SsoRole::getRoleId).collect(Collectors.toList()); + + //用户角色使用量统计 + Map userRoleCountMap = this.getUserRoleCountMap(roleIdList); + + return ResultPageModel.success(this.buildRolePageResult(roleList, userRoleCountMap), total); + } + + /** + * 角色下拉选项列表 + * + * @param optionBO + * @return 角色列表 + */ + @Override + public List listRoleOption(RoleListOptionBO optionBO) { + //构建参数参数 + SsoRoleQuery query = new SsoRoleQuery(optionBO) + .setSysCode(optionBO.getSysCode()) + .setRoleNameLike(optionBO.getRoleNameLike()) + //未删除 + .setDelFlag(DelFlagEnum.OK.getStatus()); + + //分页查询 + List roleList = ssoRoleMapper.listPageByCondition(query); + if (CollectionUtils.isEmpty(roleList)) { + return new ArrayList<>(); + } + + return BeanCopierUtil.copyList(roleList, RoleOptionVO.class); + } + + + /** + * 角色详情 + * + * @param roleId 角色ID + * @return 角色详情 + * @author 程序员小强 + */ + @Override + public RoleDetailVO getDeptDetail(Long roleId) { + SsoRole ssoRole = ssoRoleMapper.getByRoleId(roleId); + + //角色已删除 + if (DelFlagEnum.DELETED.getStatus().equals(ssoRole.getDelFlag())) { + throw new BusinessException(RoleResStatusEnum.ALREADY_DELETE); + } + + RoleDetailVO result = BeanCopierUtil.copy(ssoRole, RoleDetailVO.class); + List menuIdList = ssoRoleMenuMapper.getMenuIdListByRoleId(roleId); + if (CollectionUtils.isEmpty(menuIdList)) { + result.setMenuIdList(new ArrayList<>(0)); + return result; + } + result.setMenuIdList(menuIdList); + return result; + } + + /** + * 新增角色 + * + * @param saveBO + * @author 程序员小强 + */ + @Override + public void addRole(RoleSaveBO saveBO) { + + //角色名称判重 + this.checkRoleNameUniq(saveBO.getSysCode(), saveBO.getRoleName()); + + //角色key判重 + this.checkRoleKeyUniq(saveBO.getSysCode(), saveBO.getRoleKey()); + + //执行添加角色 + SsoRole ssoRole = this.doInsertRole(saveBO); + + //添加角色菜单关系 + this.doBatchSaveRoleMenuRelation(saveBO.getSysCode(), ssoRole.getRoleId(), saveBO.getMenuIdList()); + + log.info("[ 角色 ] >> [ 新增完成 ] >> {} ", saveBO.getLogValue()); + + } + + /** + * 修改角色 + * + * @param updateBO + * @author 程序员小强 + */ + @Override + public void updateRole(RoleUpdateBO updateBO) { + + //排除自身-角色名称判重 + this.checkRoleNameUniq(updateBO.getSysCode(), updateBO.getRoleName(), updateBO.getRoleId()); + + //排除自身-角色key判重 + this.checkRoleKeyUniq(updateBO.getSysCode(), updateBO.getRoleKey(), updateBO.getRoleId()); + + //执行-修改角色 + this.doUpdateRole(updateBO); + + //删除角色菜单关系 + ssoRoleMenuMapper.deleteByRoleId(updateBO.getRoleId()); + + //批量添加角色菜单关系 + this.doBatchSaveRoleMenuRelation(updateBO.getSysCode(), updateBO.getRoleId(), updateBO.getMenuIdList()); + + log.info("[ 角色 ] >> [ 修改完成 ] >> {} ", updateBO.getLogValue()); + + } + + /** + * 删除角色(逻辑删) + * + * @param deleteBO + * @author 程序员小强 + */ + @Override + public void deleteRole(RoleDeleteBO deleteBO) { + SsoRole ssoRole = ssoRoleMapper.getByRoleId(deleteBO.getRoleId()); + //该角色不存在 + if (null == ssoRole) { + log.error("[ 该角色不存在 ] >> {} ", deleteBO.getLogValue()); + throw new BusinessException(RoleResStatusEnum.ROLE_NOT_EXISTS); + } + //该角色已经删除 + if (DelFlagEnum.DELETED.getStatus().equals(ssoRole.getDelFlag())) { + log.error("[ 该角色已经删除 ] >> {} ", deleteBO.getLogValue()); + throw new BusinessException(RoleResStatusEnum.ALREADY_DELETE); + } + + //校验是否已经存在用户使用 + if (ssoUserRoleMapper.countByRoleId(deleteBO.getRoleId()) > 0) { + log.error("[ 校验是否已经存在用户使用 ] 不可删除 >> {} ", deleteBO.getLogValue()); + throw new BusinessException(RoleResStatusEnum.ALREADY_BIND_USER); + } + + //标记为删除状态 + SsoRole ssoUpdateRole = new SsoRole(); + ssoUpdateRole.setRoleId(deleteBO.getRoleId()); + ssoUpdateRole.setDelFlag(DelFlagEnum.DELETED.getStatus()); + ssoUpdateRole.setUpdateBy(deleteBO.getOperateBy()); + ssoRoleMapper.updateByRoleIdSelective(ssoUpdateRole); + + //删除角色菜单关系 + ssoRoleMenuMapper.deleteByRoleId(deleteBO.getRoleId()); + log.info("[ 角色 ] >> [ 删除完成 ] >> {} ", deleteBO.getLogValue()); + + } + + /** + * 移除角色用户绑定关系 + * + * @param removeUserBO + * @author 程序员小强 + */ + @Override + public void removeUserRole(RoleRemoveUserBO removeUserBO) { + ssoUserRoleMapper.deleteByRoleIdAndUserId(removeUserBO.getRoleId(), removeUserBO.getUserId()); + log.info("[ 角色 ] >> [ 移除角色用户绑定关系 ] >> {} ", removeUserBO.getLogValue()); + } + + /** + * 执行-添加角色 + * + * @param saveBO + */ + private SsoRole doInsertRole(RoleSaveBO saveBO) { + SsoRole ssoRole = this.buildSsoRole(saveBO); + ssoRoleMapper.insertSelective(ssoRole); + return ssoRole; + } + + /** + * 执行-修改角色 + * + * @param updateBO + */ + private void doUpdateRole(RoleUpdateBO updateBO) { + SsoRole ssoRole = this.buildSsoRole(updateBO); + ssoRole.setRoleId(updateBO.getRoleId()); + ssoRoleMapper.updateByRoleId(ssoRole); + } + + /** + * 批量新增角色菜单关系 + * + * @param sysCode + * @param roleId + * @param menuIdList + */ + private void doBatchSaveRoleMenuRelation(String sysCode, Long roleId, List menuIdList) { + if (CollectionUtils.isEmpty(menuIdList)) { + return; + } + //添加角色菜单关系 + SsoRoleMenu ssoRoleMenu = null; + List ssoRoleMenuList = new ArrayList<>(menuIdList.size()); + for (Long menuId : menuIdList) { + ssoRoleMenu = new SsoRoleMenu(); + ssoRoleMenu.setSysCode(sysCode); + ssoRoleMenu.setRoleId(roleId); + ssoRoleMenu.setMenuId(menuId); + ssoRoleMenuList.add(ssoRoleMenu); + } + ssoRoleMenuMapper.batchSave(ssoRoleMenuList); + log.info("[ 新增角色-批量新增角色菜单关系 ] >> roleId:{} , menuIdSize:{}", roleId, menuIdList.size()); + } + + + /** + * 校验 系统下角色名 唯一性 + * + * @param sysCode 系统编码 + * @param roleName 角色名称 + * @param excludeRoleId 需要排除的角色ID(修改时用) + */ + private void checkRoleNameUniq(String sysCode, String roleName, Long... excludeRoleId) { + if (StringUtils.isEmpty(sysCode) || StringUtils.isEmpty(roleName)) { + return; + } + SsoRole ssoRole = ssoRoleMapper.getBySysCodeAndName(sysCode, roleName); + if (null == ssoRole) { + return; + } + if (!ObjectUtils.isEmpty(excludeRoleId) && ssoRole.getRoleId().equals(excludeRoleId[0])) { + return; + } + log.error("[ 角色名称已经存在 ] >> sysCode:{} , roleName:{} excludeRoleId:{}", sysCode, roleName, excludeRoleId); + //角色名称已经存在 + throw new BusinessException(RoleResStatusEnum.ROLE_NAME_EXISTS, roleName); + } + + /** + * 校验 系统下角色key 唯一性 + * + * @param sysCode 系统编码 + * @param roleKey 角色key + * @param excludeRoleId 需要排除的角色ID(修改时用) + */ + private void checkRoleKeyUniq(String sysCode, String roleKey, Long... excludeRoleId) { + if (StringUtils.isEmpty(sysCode) || StringUtils.isEmpty(roleKey)) { + return; + } + SsoRole ssoRole = ssoRoleMapper.getBySysCodeAndRoleKey(sysCode, roleKey); + if (null == ssoRole) { + return; + } + if (!ObjectUtils.isEmpty(excludeRoleId) && ssoRole.getRoleId().equals(excludeRoleId[0])) { + return; + } + + log.error("[ 角色key已经存在 ] >> sysCode:{} , roleName:{} excludeRoleId:{}", sysCode, roleKey, excludeRoleId); + //角色 key 已经存在 + throw new BusinessException(RoleResStatusEnum.KEY_NAME_EXISTS, roleKey); + } + + /** + * 构建角色分页结果集 + * + * @param roleList + * @param userRoleCountMap + * @return + */ + private List buildRolePageResult(List roleList, Map userRoleCountMap) { + RolePageVO itemVo = null; + List resultList = new ArrayList<>(roleList.size()); + for (SsoRole ssoRole : roleList) { + itemVo = BeanCopierUtil.copy(ssoRole, RolePageVO.class); + itemVo.setUserCount(userRoleCountMap.getOrDefault(ssoRole.getRoleId(), 0)); + resultList.add(itemVo); + } + return resultList; + } + + /** + * 用户角色关系 + * + * @param roleIdList + */ + private Map getUserRoleCountMap(List roleIdList) { + if (CollectionUtils.isEmpty(roleIdList)) { + return new HashMap<>(0); + } + List countByRoleList = ssoUserRoleMapper.countByRoleIdList(roleIdList); + if (CollectionUtils.isEmpty(countByRoleList)) { + return new HashMap<>(0); + } + return countByRoleList.stream().collect(Collectors.toMap(RoleCountDTO::getRoleId, RoleCountDTO::getCount, (k1, k2) -> k1)); + } + + /** + * 构建 SsoRole 对象 + * + * @param saveBO + * @return + */ + private SsoRole buildSsoRole(RoleSaveBO saveBO) { + SsoRole ssoRole = new SsoRole(); + ssoRole.setSysCode(saveBO.getSysCode()); + ssoRole.setRoleName(saveBO.getRoleName()); + ssoRole.setRoleKey(saveBO.getRoleKey()); + ssoRole.setStatus(saveBO.getStatus()); + ssoRole.setSortNum(saveBO.getSortNum()); + ssoRole.setRemarks(saveBO.getRemarks()); + ssoRole.setCreateBy(saveBO.getOperateBy()); + ssoRole.setUpdateBy(saveBO.getOperateBy()); + return ssoRole; + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/SystemMgmtServiceImpl.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/SystemMgmtServiceImpl.java new file mode 100644 index 0000000..0c70dce --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/SystemMgmtServiceImpl.java @@ -0,0 +1,152 @@ +package com.sso.service.admin.impl; + +import com.sso.common.enums.DelFlagEnum; +import com.sso.common.exception.BusinessException; +import com.sso.common.model.result.ResultPageModel; +import com.sso.common.utils.bean.BeanCopierUtil; +import com.sso.dao.dto.SsoUserMgmtDTO; +import com.sso.dao.entity.SsoSystemManager; +import com.sso.dao.mapper.SsoSystemManagerMapper; +import com.sso.dao.query.SystemMgmtPageQuery; +import com.sso.model.bo.platform.SystemMgmtListPageBO; +import com.sso.model.bo.platform.SystemMgmtRemoveBO; +import com.sso.model.bo.platform.SystemMgmtSaveBO; +import com.sso.model.bo.platform.SystemMgmtStatusBO; +import com.sso.model.vo.platform.SystemMgmtPageVO; +import com.sso.service.admin.SystemMgmtService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; +import java.util.List; + + +/** + * 系统管理-数据权限相关接口 + * + * @author 程序员小强 + */ +@Slf4j +@Service +@Transactional(rollbackFor = Exception.class) +public class SystemMgmtServiceImpl implements SystemMgmtService { + + @Resource + private SsoSystemManagerMapper ssoSystemManagerMapper; + + /** + * 系统管理员-用户分页列表 + * + * @param pageBO + * @return 用户 + */ + @Override + public ResultPageModel listPageSysMgmtUser(SystemMgmtListPageBO pageBO) { + //构建参数参数 + SystemMgmtPageQuery query = this.buildUserPageQuery(pageBO); + + //统计行数 + int total = ssoSystemManagerMapper.countSysMgmtUser(query); + if (total <= 0) { + return ResultPageModel.defaultValue(); + } + + + //分页查询 + List userList = ssoSystemManagerMapper.listPageSysMgmtUser(query); + if (CollectionUtils.isEmpty(userList)) { + return ResultPageModel.defaultValue(); + } + + return ResultPageModel.success(BeanCopierUtil.copyList(userList, SystemMgmtPageVO.class), total); + } + + /** + * 新增-管理员权限 + * + * @param saveBO + * @author 程序员小强 + */ + @Override + public void addSystemMgmt(SystemMgmtSaveBO saveBO) { + int count = ssoSystemManagerMapper.countBySysCodeAndUserId(saveBO.getSysCode(), saveBO.getUserId()); + if (count > 0) { + log.error("[ 该用户管理权限关系已经存在 ] >> {} ", saveBO.getLogValue()); + throw new BusinessException("该用户管理权限关系已经存在"); + } + + SsoSystemManager saveEntity = new SsoSystemManager(); + saveEntity.setUserId(saveBO.getUserId()); + saveEntity.setStatus(saveBO.getStatus()); + saveEntity.setSysCode(saveBO.getSysCode()); + saveEntity.setCreateBy(saveBO.getOperateBy()); + saveEntity.setUpdateBy(saveBO.getOperateBy()); + ssoSystemManagerMapper.insertSelective(saveEntity); + log.info("[ 新增-管理员权限完成 ] >> {} ", saveBO.getLogValue()); + + } + + /** + * 修改-管理员权限账号状态 + * + * @param saveBO + * @author 程序员小强 + */ + @Override + public void updateStatus(SystemMgmtStatusBO saveBO) { + SsoSystemManager updateEntity = new SsoSystemManager(); + updateEntity.setId(saveBO.getId()); + updateEntity.setStatus(saveBO.getStatus()); + ssoSystemManagerMapper.updateById(updateEntity); + log.info("[ 修改-管理员权限账号状态完成 ] >> {} ", saveBO.getLogValue()); + } + + /** + * 移除管理员权限 + * + * @param removeBO + * @author 程序员小强 + */ + @Override + public void removeUserSystemMgmt(SystemMgmtRemoveBO removeBO) { + int count = ssoSystemManagerMapper.countBySysCodeAndUserId(removeBO.getSysCode(), removeBO.getUserId()); + if (count <= 0) { + log.error("[ 该用户管理权限不存在或已移除 ] >> {} ", removeBO.getLogValue()); + throw new BusinessException("该用户管理权限不存在或已移除"); + } + + SsoSystemManager updateEntity = new SsoSystemManager(); + updateEntity.setUserId(removeBO.getUserId()); + updateEntity.setSysCode(removeBO.getSysCode()); + updateEntity.setDelFlag(DelFlagEnum.DELETED.getStatus()); + updateEntity.setUpdateBy(removeBO.getOperateBy()); + ssoSystemManagerMapper.updateBySysCodeAndUserId(updateEntity); + log.info("[ 移除-管理员权限完成 ] >> {} ", removeBO.getLogValue()); + + } + + /** + * 构建查询参数 + * + * @param pageBO + * @return + */ + private SystemMgmtPageQuery buildUserPageQuery(SystemMgmtListPageBO pageBO) { + SystemMgmtPageQuery query = new SystemMgmtPageQuery() + .setSysCode(pageBO.getSysCode()) + .setUsernameLike(pageBO.getUsernameLike()) + .setNickNameLike(pageBO.getNickNameLike()) + .setRealNameLike(pageBO.getRealNameLike()) + .setPhoneLike(pageBO.getPhoneLike()) + .setUserStatus(pageBO.getUserStatus()) + .setRelationStatus(pageBO.getRelationStatus()) + //未删除 + .setDelFlag(DelFlagEnum.OK.getStatus()); + + query.setPage(pageBO.getPage()); + query.setPageSize(pageBO.getPageSize()); + return query; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/SystemServiceImpl.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/SystemServiceImpl.java new file mode 100644 index 0000000..addac07 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/SystemServiceImpl.java @@ -0,0 +1,401 @@ +package com.sso.service.admin.impl; + +import com.sso.common.constant.SsoConstants; +import com.sso.common.constant.SsoPermissionConstants; +import com.sso.common.enums.DelFlagEnum; +import com.sso.common.enums.SystemManagerStatusEnum; +import com.sso.common.enums.SystemStatusEnum; +import com.sso.common.enums.exception.SysResStatusEnum; +import com.sso.common.enums.exception.SystemResStatusEnum; +import com.sso.common.exception.BusinessException; +import com.sso.common.model.BaseOperateBO; +import com.sso.common.model.login.LoginResultVO; +import com.sso.common.model.login.LoginUserVO; +import com.sso.common.utils.SecurityUtils; +import com.sso.common.utils.StringUtils; +import com.sso.common.utils.bean.BeanCopierUtil; +import com.sso.dao.entity.SsoSystem; +import com.sso.dao.entity.SsoSystemManager; +import com.sso.dao.entity.SsoUserSystem; +import com.sso.dao.mapper.*; +import com.sso.framework.config.property.SysConfigProperty; +import com.sso.model.bo.platform.*; +import com.sso.model.vo.platform.SystemDetailVO; +import com.sso.model.vo.platform.SystemListVO; +import com.sso.service.admin.SystemService; +import com.sso.service.admin.login.PermissionService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * 平台管理相关接口 + * + * @author 程序员小强 + */ +@Slf4j +@Service +@Transactional(rollbackFor = Exception.class) +public class SystemServiceImpl implements SystemService { + + @Resource + private PermissionService permissionService; + @Resource + private SsoSystemMapper ssoSystemMapper; + @Resource + private SsoDeptMapper ssoDeptMapper; + @Resource + private SsoMenuMapper ssoMenuMapper; + @Resource + private SsoRoleMapper ssoRoleMapper; + @Resource + private SsoUserSystemMapper ssoUserSystemMapper; + @Resource + private SsoSystemManagerMapper ssoSystemManagerMapper; + @Resource + private SysConfigProperty sysConfigProperty; + + /** + * 我的平台列表 + * + * @return 系统列表 + */ + @Override + public List listMySystem() { + //当前登录用户 + LoginUserVO loginUser = SecurityUtils.getLoginUser(); + + List systemList = null; + //管理员拥有所有权限 + if (SsoPermissionConstants.ADMIN_USER_SET.contains(loginUser.getUsername())) { + systemList = ssoSystemMapper.listMySystemByAdmin(loginUser.getUserId(), SystemStatusEnum.getEnableStatusList()); + } else { + systemList = ssoSystemMapper.listMySystemByUserId(loginUser.getUserId()); + } + + if (CollectionUtils.isEmpty(systemList)) { + return new ArrayList<>(0); + } + + SystemListVO item = null; + List systemResList = new ArrayList<>(); + for (SsoSystem ssoSystem : systemList) { + //认证中心系统-不加入跳转 + if (ssoSystem.getSysCode().equals(sysConfigProperty.getAuthSsoSysCode())) { + continue; + } + item = BeanCopierUtil.copy(ssoSystem, SystemListVO.class); + systemResList.add(item); + } + return systemResList; + } + + /** + * 我的平台排序 + * + * @param systemSortBO + */ + @Override + public void sortMySystem(SystemSortBO systemSortBO) { + //当前登录用户 + LoginResultVO loginUser = SecurityUtils.getLoginUserResult(); + + int i = 0; + SsoUserSystem operateSystem = null; + for (String sysCode : systemSortBO.getSysCodeList()) { + i++; + operateSystem = new SsoUserSystem(); + operateSystem.setCreateBy(loginUser.getOperateName()); + operateSystem.setUpdateBy(loginUser.getOperateName()); + operateSystem.setSortNum(i); + SsoUserSystem ssoUserSystem = ssoUserSystemMapper.getByUserIdAndSysCode(loginUser.getUser().getUserId(), sysCode); + if (null != ssoUserSystem) { + operateSystem.setId(ssoUserSystem.getId()); + //更新排序值 + ssoUserSystemMapper.updateByIdSelective(operateSystem); + } else { + //新增用户平台关系 + operateSystem.setUserId(loginUser.getUser().getUserId()); + operateSystem.setSysCode(sysCode); + ssoUserSystemMapper.insertSelective(operateSystem); + } + } + } + + /** + * 平台管理列表 + * + * @return 系统列表 + */ + @Override + public List listMyMgmtSystem() { + //当前登录用户 + LoginResultVO loginUser = SecurityUtils.getLoginUserResult(); + + List systemList = null; + //管理员拥有所有权限 + if (SsoPermissionConstants.ADMIN_USER_SET.contains(loginUser.getUsername())) { + systemList = ssoSystemMapper.listMySystemByAdmin(loginUser.getUser().getUserId(), SystemStatusEnum.getAllStatusList()); + } + //认证中心管理员-角色拥有所有权限 + else if (loginUser.getRoleKeyList().contains(SsoPermissionConstants.ADMIN_ROLE_KEY)) { + systemList = ssoSystemMapper.listMySystemByAdmin(loginUser.getUser().getUserId(), SystemStatusEnum.getAllStatusList()); + } else { + //查询用户平台管理权限 + systemList = ssoSystemMapper.listSystemMgmtByUserId(loginUser.getUser().getUserId()); + } + + if (CollectionUtils.isEmpty(systemList)) { + return new ArrayList<>(0); + } + + return BeanCopierUtil.copyList(systemList, SystemListVO.class); + } + + /** + * 根据系统平台编码查询 + * + * @param sysCode + * @return 系统详情 + */ + @Override + public SystemDetailVO getDetailBySysCode(String sysCode) { + SsoSystem ssoSystem = ssoSystemMapper.getBySysCode(sysCode); + //系统不存在 + if (null == ssoSystem) { + throw new BusinessException(SysResStatusEnum.SYS_NOT_FOUND); + } + //当前用户无修改秘钥权限-为了安全则隐藏秘钥值 + if (!permissionService.hasPermission(SsoConstants.UPDATE_SECRET_KEY)) { + ssoSystem.setPublicKey(""); + } + return BeanCopierUtil.copy(ssoSystem, SystemDetailVO.class); + } + + /** + * 新增-目标平台系统 + * + * @param saveBO + * @author 程序员小强 + */ + @Override + public void addSystem(SystemSaveBO saveBO) { + //获取登录用户 + LoginUserVO loginUser = SecurityUtils.getLoginUser(); + + //校验系统编码唯一性 + this.checkSysCodeUniq(saveBO.getSysCode()); + + //构建ssoSystem + SsoSystem ssoSystem = this.buildSsoSystem(saveBO); + //默认正常状态 + ssoSystem.setStatus(SystemStatusEnum.ENABLE.getStatus()); + + //新增 + ssoSystemMapper.insertSelective(ssoSystem); + + //若非管理员-管理员拥有所有权限 + if (SsoPermissionConstants.ADMIN_USER_SET.contains(loginUser.getUsername())) { + log.info("[ 平台新增完成 ] >> {}", saveBO.getLogValue()); + return; + } + + //为新增该平台用户-添加用户与当前系统关系 + this.addUserSystemRelation(saveBO.getSysCode(), loginUser.getUserId(), saveBO); + //为新增该平台用户-添加系统管理权限 + this.addSystemMgmt(saveBO.getSysCode(), loginUser.getUserId(), saveBO); + log.info("[ 平台新增完成 ] 非管理员-已添加管理权限 >> {}", saveBO.getLogValue()); + } + + /** + * 修改-目标平台系统 + * + * @param updateBO + * @author 程序员小强 + */ + @Override + public void updateSystem(SystemUpdateBO updateBO) { + //查询旧系统信息 + SsoSystem oldSsoSystem = ssoSystemMapper.getBySysId(updateBO.getSysId()); + if (null == oldSsoSystem) { + throw new BusinessException(SystemResStatusEnum.SYS_NOT_EXISTS); + } + //修改系统编码 + if (!updateBO.getSysCode().equals(oldSsoSystem.getSysCode())) { + //校验-旧系统编码是否已经引用 + this.checkSysCodeIsUse(oldSsoSystem.getSysCode()); + } + + //校验系统编码唯一性 + this.checkSysCodeUniq(updateBO.getSysCode(), updateBO.getSysId()); + + //构建ssoSystem + SsoSystem ssoSystem = this.buildSsoSystem(updateBO); + ssoSystem.setSysId(updateBO.getSysId()); + ssoSystem.setStatus(updateBO.getStatus()); + + //修改平台 + ssoSystemMapper.updateBySysId(ssoSystem); + log.info("[ 平台修改完成 ] >> {}", updateBO.getLogValue()); + + } + + /** + * 修改-秘钥 + * + * @param updateBO + * @author 程序员小强 + */ + @Override + public void updateSystemSecret(SystemUpdateSecretBO updateBO) { + SsoSystem ssoSystem = new SsoSystem(); + ssoSystem.setSysId(updateBO.getSysId()); + ssoSystem.setSignType(updateBO.getSignType()); + ssoSystem.setPublicKey(StringUtils.dealBlankDefault(updateBO.getPublicKey(), "")); + ssoSystem.setUpdateBy(updateBO.getOperateBy()); + //修改平台 + ssoSystemMapper.updateSecretBySysId(ssoSystem); + log.info("[ 平台修改秘钥完成 ] >> {} ", updateBO.getLogValue()); + + } + + /** + * 删除-目标平台系统(逻辑删) + * + * @param deleteBO + * @author 程序员小强 + */ + @Override + public void deleteSystem(SystemDeleteBO deleteBO) { + SsoSystem ssoSystem = ssoSystemMapper.getBySysId(deleteBO.getSysId()); + if (null == ssoSystem) { + throw new BusinessException(SystemResStatusEnum.SYS_NOT_EXISTS); + } + + if (DelFlagEnum.DELETED.getStatus().equals(ssoSystem.getDelFlag())) { + throw new BusinessException(SystemResStatusEnum.ALREADY_DELETE, ssoSystem.getSysName()); + } + + //校验是否已经引用 + this.checkSysCodeIsUse(ssoSystem.getSysCode()); + + //标记为删除态 + SsoSystem deleteSystem = new SsoSystem(); + deleteSystem.setSysId(deleteBO.getSysId()); + deleteSystem.setDelFlag(DelFlagEnum.DELETED.getStatus()); + deleteSystem.setUpdateBy(deleteBO.getOperateBy()); + ssoSystemMapper.updateBySysIdSelective(deleteSystem); + log.info("[ 平台删除完成 ] >> sysId:{} , operateBy:{}", deleteBO.getSysId(), deleteBO.getOperateBy()); + } + + /** + * 校验 系统编码 唯一性 + * + * @param sysCode 系统编码 + * @param excludeSysId 需要排除的sysId(修改时用) + */ + private void checkSysCodeUniq(String sysCode, Long... excludeSysId) { + if (StringUtils.isEmpty(sysCode)) { + return; + } + SsoSystem ssoSystem = ssoSystemMapper.getBySysCode(sysCode); + if (null == ssoSystem) { + return; + } + if (!ObjectUtils.isEmpty(excludeSysId) && ssoSystem.getSysId().equals(excludeSysId[0])) { + return; + } + + log.error("[ 系统编码已经存在 ] >> sysCode:{}", sysCode); + //系统编码已经存在 + throw new BusinessException(SystemResStatusEnum.SYS_CODE_EXISTS, sysCode); + } + + /** + * 校验系统是否已经在使用 + */ + private void checkSysCodeIsUse(String sysCode) { + if (StringUtils.isBlank(sysCode)) { + return; + } + + //用户 + if (ssoUserSystemMapper.countBySysCode(sysCode) > 0) { + throw new BusinessException(SystemResStatusEnum.ALREADY_BIND_USER); + } + + //菜单 + if (ssoMenuMapper.countBySysCode(sysCode) > 0) { + throw new BusinessException(SystemResStatusEnum.ALREADY_BIND_MENU); + } + + //角色 + if (ssoRoleMapper.countBySysCode(sysCode) > 0) { + throw new BusinessException(SystemResStatusEnum.ALREADY_BIND_ROLE); + } + + //部门 + if (ssoDeptMapper.countBySysCode(sysCode) > 0) { + throw new BusinessException(SystemResStatusEnum.ALREADY_BIND_DEPT); + } + } + + /** + * 添加用户-系统关系 + * + * @param sysCode + * @param userId + * @param operateBO + */ + public void addUserSystemRelation(String sysCode, Long userId, BaseOperateBO operateBO) { + SsoUserSystem ssoUserSystem = ssoUserSystemMapper.getByUserIdAndSysCode(userId, sysCode); + if (null != ssoUserSystem) { + log.error("[ 该用户与系统-关系已经存在 ] >> sysCode:{} , userId:{}, operateBy:{}", sysCode, userId, operateBO.getOperateBy()); + return; + } + + SsoUserSystem userSystem = new SsoUserSystem(); + userSystem.setUserId(userId); + userSystem.setSysCode(sysCode); + userSystem.setCreateBy(operateBO.getOperateBy()); + userSystem.setUpdateBy(operateBO.getOperateBy()); + ssoUserSystemMapper.insertSelective(userSystem); + } + + public void addSystemMgmt(String sysCode, Long userId, BaseOperateBO operateBO) { + int count = ssoSystemManagerMapper.countBySysCodeAndUserId(sysCode, userId); + if (count > 0) { + log.error("[ 该用户管理权限关系已经存在 ] >> sysCode:{} , userId:{}, operateBy:{}", sysCode, userId, operateBO.getOperateBy()); + return; + } + SsoSystemManager saveEntity = new SsoSystemManager(); + saveEntity.setUserId(userId); + saveEntity.setStatus(SystemManagerStatusEnum.OK.getStatus()); + saveEntity.setSysCode(sysCode); + saveEntity.setCreateBy(operateBO.getOperateBy()); + saveEntity.setUpdateBy(operateBO.getOperateBy()); + ssoSystemManagerMapper.insertSelective(saveEntity); + log.info("[ 新增平台-管理员权限完成 ] >> sysCode:{} , userId:{}, operateBy:{}", sysCode, userId, operateBO.getOperateBy()); + } + + private SsoSystem buildSsoSystem(SystemSaveBO saveBO) { + SsoSystem ssoSystem = new SsoSystem(); + ssoSystem.setSysCode(saveBO.getSysCode()); + ssoSystem.setSysGrantCode(saveBO.getSysCode()); + ssoSystem.setSysName(saveBO.getSysName()); + ssoSystem.setSysUrl(saveBO.getSysUrl()); + ssoSystem.setSysIcon(saveBO.getSysIcon()); + ssoSystem.setSysEnv(saveBO.getSysEnv()); + ssoSystem.setSortNum(saveBO.getSortNum()); + ssoSystem.setRemarks(saveBO.getRemarks()); + ssoSystem.setCreateBy(saveBO.getOperateBy()); + ssoSystem.setUpdateBy(saveBO.getOperateBy()); + return ssoSystem; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/UserOnlineServiceImpl.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/UserOnlineServiceImpl.java new file mode 100644 index 0000000..ba2a31e --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/UserOnlineServiceImpl.java @@ -0,0 +1,212 @@ +package com.sso.service.admin.impl; + +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.sso.common.constant.CacheConstants; +import com.sso.common.model.login.LoginResultVO; +import com.sso.common.model.result.ResultPageModel; +import com.sso.common.utils.ObjectUtils; +import com.sso.common.utils.StringUtils; +import com.sso.common.utils.bean.BeanCopierUtil; +import com.sso.dao.dto.SsoOnlineUserDTO; +import com.sso.dao.entity.SsoSystem; +import com.sso.dao.mapper.SsoOnlineUserMapper; +import com.sso.dao.mapper.SsoSystemMapper; +import com.sso.dao.query.UserOnlineQuery; +import com.sso.framework.redis.RedisCache; +import com.sso.model.bo.user.UserOnlineListPageBO; +import com.sso.model.vo.getway.SysLoginCacheVO; +import com.sso.model.vo.user.UserOnlinePageVO; +import com.sso.model.vo.user.UserOnlineSysVO; +import com.sso.service.admin.UserOnlineService; +import com.sso.service.base.SysConfigService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * 登录日志接口 + * + * @author 程序员小强 + */ +@Slf4j +@Service +public class UserOnlineServiceImpl implements UserOnlineService { + + @Autowired + private RedisCache redisCache; + @Resource + private SsoSystemMapper ssoSystemMapper; + @Resource + private SysConfigService sysConfigService; + @Resource + private SsoOnlineUserMapper ssoOnlineUserMapper; + + /** + * 在线用户分页列表 + * + * @param pageBO + * @return 用户 + */ + @Override + public ResultPageModel listPageUser(UserOnlineListPageBO pageBO) { + //构建参数 + UserOnlineQuery query = this.buildPageQuery(pageBO); + + //统计行数 + int total = ssoOnlineUserMapper.countByCondition(query); + + if (total <= 0) { + return ResultPageModel.defaultValue(); + } + + //分页查询 + List onlineUserList = ssoOnlineUserMapper.listPageByCondition(query); + if (CollectionUtils.isEmpty(onlineUserList)) { + return ResultPageModel.defaultValue(); + } + + return ResultPageModel.success(this.buildOnlineUserPage(onlineUserList), total); + } + + /** + * 查看用户已登录的子系统 + * + * @param userId + * @return 已登录系统列表 + */ + @Override + public List listOnlineSys(Long userId) { + if (null == userId) { + return new ArrayList<>(0); + } + + //登录缓存用户信息 + LoginResultVO loginUser = + redisCache.get(CacheConstants.getLoginUserIdKey(userId), LoginResultVO.class); + if (ObjectUtils.isNull(loginUser)) { + return new ArrayList<>(0); + } + + //登录缓存用户token信息 + Map userCacheMap = + redisCache.hgetAll(CacheConstants.getLoginUserTokenKey(loginUser.getToken()), String.class); + if (ObjectUtils.isEmpty(userCacheMap)) { + return new ArrayList<>(0); + } + + //构建子系统集 + List sysCodeList = new ArrayList<>(); + for (Map.Entry userCache : userCacheMap.entrySet()) { + if (userCache.getKey().equals(loginUser.getToken())) { + continue; + } + sysCodeList.add(userCache.getKey()); + } + + return this.buildUserOnlineSysList(sysCodeList, userCacheMap); + } + + /** + * 构建返回列表 + * + * @param onlineUserList + * @return + */ + private List buildOnlineUserPage(List onlineUserList) { + UserOnlinePageVO pageItem = null; + Long supperAdminUserId = sysConfigService.getSupperAdminUserId(); + List resultList = new ArrayList<>(); + for (SsoOnlineUserDTO onlineUser : onlineUserList) { + pageItem = BeanCopierUtil.copy(onlineUser, UserOnlinePageVO.class); + pageItem.setSupperAdminFlag(onlineUser.getUserId().equals(supperAdminUserId)); + //登录时间 + if (ObjectUtils.isNotNull(onlineUser.getLoginTime()) && onlineUser.getLoginTime() > 0) { + pageItem.setLoginTime(DateUtil.formatDateTime(new Date(onlineUser.getLoginTime()))); + } + //主动退出时间 + if (ObjectUtils.isNotNull(onlineUser.getLoginOutTime()) && onlineUser.getLoginOutTime() > 0) { + pageItem.setLoginOutTime(DateUtil.formatDateTime(new Date(onlineUser.getLoginOutTime()))); + } + //失效时间 + if (ObjectUtils.isNotNull(onlineUser.getExpireTime()) && onlineUser.getExpireTime() > 0) { + pageItem.setExpireTime(DateUtil.formatDateTime(new Date(onlineUser.getExpireTime()))); + } + resultList.add(pageItem); + } + return resultList; + } + + /** + * 构建查询参数 + * + * @param pageBO + */ + private UserOnlineQuery buildPageQuery(UserOnlineListPageBO pageBO) { + UserOnlineQuery query = new UserOnlineQuery() + //效期大于当前时间 + .setExpireStartTime(System.currentTimeMillis()) + .setUsernameLike(pageBO.getUsernameLike()); + + if (StringUtils.isNotBlank(pageBO.getLoginStartTime())) { + query.setLoginStartTime(DateUtil.beginOfDay(DateUtil.parseDate(pageBO.getLoginStartTime())).getTime()); + } + + if (StringUtils.isNotBlank(pageBO.getLoginEndTime())) { + query.setLoginEndTime(DateUtil.endOfDay(DateUtil.parseDate(pageBO.getLoginEndTime())).getTime()); + } + query.setPage(pageBO.getPage()); + query.setPageSize(pageBO.getPageSize()); + return query; + } + + /** + * 构建用户已经登录的子系统列表 + * + * @param sysCodeList + * @param userCacheMap + */ + private List buildUserOnlineSysList(List sysCodeList, Map userCacheMap) { + if (CollectionUtils.isEmpty(sysCodeList)) { + return new ArrayList<>(0); + } + + List systemList = ssoSystemMapper.getBySysCodeList(sysCodeList); + if (CollectionUtils.isEmpty(systemList)) { + return new ArrayList<>(0); + } + + UserOnlineSysVO onlineSysVO = null; + List resultList = new ArrayList<>(systemList.size()); + for (SsoSystem ssoSystem : systemList) { + onlineSysVO = new UserOnlineSysVO(); + onlineSysVO.setSysCode(ssoSystem.getSysCode()); + onlineSysVO.setSysName(ssoSystem.getSysName()); + onlineSysVO.setLoginTime(this.getLoginSysTime(ssoSystem.getSysCode(), userCacheMap)); + resultList.add(onlineSysVO); + } + return resultList; + } + + /** + * 从缓存中解析-登录子系统的时间 + */ + private String getLoginSysTime(String sysCode, Map userCacheMap) { + String cacheValue = userCacheMap.getOrDefault(sysCode, "{}"); + if (StringUtils.isBlank(cacheValue)) { + return ""; + } + SysLoginCacheVO loginCache = JSON.parseObject(cacheValue, SysLoginCacheVO.class); + if (ObjectUtils.isNull(loginCache) || ObjectUtils.isNull(loginCache.getLoginTime())) { + return ""; + } + return DateUtil.formatDateTime(new Date(loginCache.getLoginTime())); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/UserServiceImpl.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/UserServiceImpl.java new file mode 100644 index 0000000..a02f23b --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/impl/UserServiceImpl.java @@ -0,0 +1,767 @@ +package com.sso.service.admin.impl; + +import com.sso.common.constant.SsoConstants; +import com.sso.common.enums.DelFlagEnum; +import com.sso.common.enums.exception.UserResStatusEnum; +import com.sso.common.exception.BusinessException; +import com.sso.common.model.BaseOperateBO; +import com.sso.common.model.result.ResultPageModel; +import com.sso.common.utils.SecurityUtils; +import com.sso.common.utils.StringUtils; +import com.sso.common.utils.bean.BeanCopierUtil; +import com.sso.dao.dto.SsoUserDeptDTO; +import com.sso.dao.dto.SsoUserRoleDTO; +import com.sso.dao.entity.*; +import com.sso.dao.mapper.*; +import com.sso.dao.query.UserPageQuery; +import com.sso.model.bo.user.*; +import com.sso.model.vo.user.UserDetailVO; +import com.sso.model.vo.user.UserOptionVO; +import com.sso.model.vo.user.UserPageVO; +import com.sso.model.vo.user.UserProfileVO; +import com.sso.service.admin.UserService; +import com.sso.service.base.SysConfigService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * 用户管理接口 + * + * @author 程序员小强 + */ +@Slf4j +@Service +@Transactional(rollbackFor = Exception.class) +public class UserServiceImpl implements UserService { + + @Resource + private SsoUserMapper ssoUserMapper; + @Resource + private SsoDeptMapper ssoDeptMapper; + @Resource + private SsoUserDeptMapper ssoUserDeptMapper; + @Resource + private SsoUserRoleMapper ssoUserRoleMapper; + @Resource + private SysConfigService sysConfigService; + @Resource + private SsoUserSystemMapper ssoUserSystemMapper; + @Resource + private SsoSystemManagerMapper ssoSystemManagerMapper; + + /** + * 用户分页列表 + * + * @param pageBO + * @return 用户 + */ + @Override + public ResultPageModel listPageUser(UserListPageBO pageBO) { + //构建参数参数 + UserPageQuery query = this.buildUserPageQuery(pageBO); + + //统计行数 + int total = ssoUserMapper.countByCondition(query); + if (total <= 0) { + return ResultPageModel.defaultValue(); + } + + //分页查询用户 + List userList = ssoUserMapper.listPageByCondition(query); + if (CollectionUtils.isEmpty(userList)) { + return ResultPageModel.defaultValue(); + } + + //提取用户ID + List userIdList = userList.stream().map(SsoUser::getUserId).collect(Collectors.toList()); + + //用户系统关系 + Map userSystemMap = this.getUserSystemMap(pageBO.getSysCode(), userIdList); + + //用户部门关系Map + Map userDeptMap = this.getUserDeptMap(pageBO.getSysCode(), userIdList); + + //用户角色关系Map + Map userRoleMap = this.getUserRolesMap(pageBO.getSysCode(), userIdList); + + //组装结果返回 + return ResultPageModel.success(this.buildUserListResult(userList, userSystemMap, userDeptMap, userRoleMap), total); + } + + /** + * 用户详情 + * + * @param detailBO + * @return 用户详情 + */ + @Override + public UserDetailVO getUserDetail(UserDetailBO detailBO) { + SsoUser ssoUser = ssoUserMapper.getByUserId(detailBO.getUserId()); + if (null == ssoUser) { + throw new BusinessException(UserResStatusEnum.USER_NOT_EXISTS); + } + + UserDetailVO result = BeanCopierUtil.copy(ssoUser, UserDetailVO.class); + result.setSysCode(detailBO.getSysCode()); + + //所属部门 + SsoUserDept ssoUserDept = ssoUserDeptMapper.getDeptBySysCodeAndUserId(detailBO.getSysCode(), detailBO.getUserId()); + if (null != ssoUserDept) { + result.setDeptId(ssoUserDept.getDeptId()); + } + + //用户角色 + List roleIdList = ssoUserRoleMapper.getRoleIdListBySysCodeAndUserId(detailBO.getSysCode(), detailBO.getUserId()); + if (!CollectionUtils.isEmpty(roleIdList)) { + result.setRoleIdList(roleIdList); + } else { + result.setRoleIdList(new ArrayList<>(0)); + } + return result; + } + + /** + * 个人中心详情 + * + * @param userId + * @return + */ + @Override + public UserProfileVO getUserProfile(Long userId) { + SsoUser ssoUser = ssoUserMapper.getByUserId(userId); + if (null == ssoUser) { + throw new BusinessException(UserResStatusEnum.USER_NOT_EXISTS); + } + + return BeanCopierUtil.copy(ssoUser, UserProfileVO.class); + } + + /** + * 根据手机号查询用户 + * + * @param phone + * @return 用户 + */ + @Override + public UserOptionVO getUserByPhone(String phone) { + SsoUser ssoUser = ssoUserMapper.getByPhone(phone); + if (null == ssoUser) { + return null; + } + return BeanCopierUtil.copy(ssoUser, UserOptionVO.class); + } + + /** + * 根据用户名查询用户 + * + * @param username + * @return 用户 + */ + @Override + public UserOptionVO getUserByUserName(String username) { + SsoUser ssoUser = ssoUserMapper.getByUserName(username); + if (null == ssoUser) { + return null; + } + return BeanCopierUtil.copy(ssoUser, UserOptionVO.class); + } + + /** + * 根据用户名或手机号查询用户列表 + * + * @param keywords + * @return 用户 + */ + @Override + public List listUserOption(String keywords) { + List userList = ssoUserMapper.listByPhoneOrUserNameLike(keywords, SsoConstants.OPTION_LIMIT); + if (CollectionUtils.isEmpty(userList)) { + return new ArrayList<>(); + } + + return BeanCopierUtil.copyList(userList, UserOptionVO.class); + } + + /** + * 添加用户 + * + * @param addBO + */ + @Override + public void addUser(UserAddBO addBO) { + //校验用户名唯一性 + this.checkUserNameUniq(addBO.getUsername()); + + //校验手机号唯一性 + this.checkPhoneUniq(addBO.getPhone()); + + //校验邮箱唯一性 + this.checkEmailUniq(addBO.getEmail()); + + //执行新增用户 + SsoUser ssoUser = this.doInsertUser(addBO); + + //添加用户与当前系统关系 + this.addUserSystemRelation(addBO.getSysCode(), ssoUser.getUserId(), addBO); + + //新增用户部门关系 + this.doInsertUserDeptRelation(addBO.getSysCode(), ssoUser.getUserId(), addBO.getDeptId()); + + //新增用户角色关系 + this.doInsertUserRoleRelation(addBO.getSysCode(), ssoUser.getUserId(), addBO.getRoleIdList()); + + log.info("[ 用户 ] >> [ 新增完成 ] >> {}", addBO.getLogValue()); + } + + /** + * 添加用户平台关系 + * + * @param addBO + */ + @Override + public void addUserPlatformRelation(UserPlatformAddBO addBO) { + //删除原先的部门关系 + ssoUserDeptMapper.deleteBySysCodeAndUserId(addBO.getSysCode(), addBO.getUserId()); + //删除原先的用户角色关系 + ssoUserRoleMapper.deleteBySysCodeAndUserId(addBO.getSysCode(), addBO.getUserId()); + + //添加用户与当前系统关系 + this.addUserSystemRelation(addBO.getSysCode(), addBO.getUserId(), addBO); + + //新增用户部门关系 + this.doInsertUserDeptRelation(addBO.getSysCode(), addBO.getUserId(), addBO.getDeptId()); + + //新增用户角色关系 + this.doInsertUserRoleRelation(addBO.getSysCode(), addBO.getUserId(), addBO.getRoleIdList()); + + log.info("[ 用户 ] >> [ 添加用户平台关系完成 ] >> {}", addBO.getLogValue()); + } + + /** + * 修改用户 + * + * @param updateBO + */ + @Override + public void updateUser(UserUpdateBO updateBO) { + //校验超管账号不可修改 + this.checkSupperAdminUser(updateBO.getUserId()); + + //排除自身-校验手机号唯一性 + this.checkPhoneUniq(updateBO.getPhone(), updateBO.getUserId()); + + //排除自身-校验邮箱唯一性 + this.checkEmailUniq(updateBO.getEmail(), updateBO.getUserId()); + + //执行修改用户 + SsoUser ssoUser = this.doUpdateUser(updateBO); + + //删除原先的部门关系 + ssoUserDeptMapper.deleteBySysCodeAndUserId(updateBO.getSysCode(), updateBO.getUserId()); + //删除原先的用户角色关系 + ssoUserRoleMapper.deleteBySysCodeAndUserId(updateBO.getSysCode(), updateBO.getUserId()); + + //新增用户部门关系 + this.doInsertUserDeptRelation(updateBO.getSysCode(), ssoUser.getUserId(), updateBO.getDeptId()); + + //新增用户角色关系 + this.doInsertUserRoleRelation(updateBO.getSysCode(), ssoUser.getUserId(), updateBO.getRoleIdList()); + + //添加了部门或者角色情况下-为用户建立与当前平台的关系 + if (!CollectionUtils.isEmpty(updateBO.getRoleIdList()) || null != updateBO.getDeptId()) { + //添加用户与当前系统关系 + this.addUserSystemRelation(updateBO.getSysCode(), ssoUser.getUserId(), updateBO); + } + + log.info("[ 用户 ] >> [ 修改平台关系完成 ] >> {}", updateBO.getLogValue()); + } + + /** + * 移除用户与系统关系 + * + * @param removeBO + */ + @Override + public void removeUserSystem(UserSystemRemoveBO removeBO) { + //删除用户系统权限 + this.doDeleteUserSystem(removeBO.getSysCode(), removeBO.getUserId(), removeBO); + + //删除部门关系 + ssoUserDeptMapper.deleteBySysCodeAndUserId(removeBO.getSysCode(), removeBO.getUserId()); + + //删除用户角色关系 + ssoUserRoleMapper.deleteBySysCodeAndUserId(removeBO.getSysCode(), removeBO.getUserId()); + + //删除用户管理员权限 + this.doDeleteUserSystemManager(removeBO.getSysCode(), removeBO.getUserId(), removeBO); + + log.info("[ 用户 ] >> [ 移除用户与系统关系 ] >> {}", removeBO.getLogValue()); + } + + /** + * 修改个人信息 + * + * @param updateBO + */ + @Override + public void updateProfile(UserUpdateProfileBO updateBO) { + //排除自身-校验手机号唯一性 + this.checkPhoneUniq(updateBO.getPhone(), updateBO.getUserId()); + + //排除自身-校验邮箱唯一性 + this.checkEmailUniq(updateBO.getEmail(), updateBO.getUserId()); + + //执行修改用户个人信息 + this.doUpdateUserProfile(updateBO); + + log.info("[ 用户 ] >> [ 修改个人信息 ] >> {}", updateBO.getLogValue()); + + } + + /** + * 修改个人密码 + * + * @param updateBO + */ + @Override + public void updatePwd(UserUpdatePwdBO updateBO) { + SsoUser ssoUser = ssoUserMapper.getByUserId(updateBO.getUserId()); + if (null == ssoUser) { + return; + } + if (DelFlagEnum.DELETED.getStatus().equals(ssoUser.getDelFlag())) { + return; + } + //修改密码失败,旧密码错误 + if (!SecurityUtils.matchesPassword(updateBO.getOldPassword(), ssoUser.getPassword())) { + throw new BusinessException(UserResStatusEnum.OLD_PWD_ERROR); + } + //新密码不能与旧密码相同 + if (SecurityUtils.matchesPassword(updateBO.getNewPassword(), ssoUser.getPassword())) { + throw new BusinessException(UserResStatusEnum.OLD_PWD_EVAL_NEW_PWD); + } + + String newPassword = SecurityUtils.encryptPassword(updateBO.getNewPassword()); + ssoUserMapper.updatePwd(updateBO.getUserId(), newPassword, updateBO.getOperateBy()); + + log.info("[ 用户 ] >> [ 修改个人密码 ] >> userId:{}", updateBO.getUserId()); + } + + /** + * 重置密码 + * + * @param restPwdBO + */ + @Override + public void resetPwd(UserRestPwdBO restPwdBO) { + //校验超管账号不可修改 + this.checkSupperAdminUser(restPwdBO.getUserId()); + + SsoUser ssoUser = new SsoUser(); + ssoUser.setUserId(restPwdBO.getUserId()); + ssoUser.setPassword(SecurityUtils.encryptPassword(restPwdBO.getPassword())); + ssoUser.setUpdateBy(restPwdBO.getOperateBy()); + ssoUserMapper.updateByUserIdSelective(ssoUser); + + log.info("[ 用户 ] >> [ 重置密码 ] >> userId:{} , operateBy:{}", restPwdBO.getUserId(), restPwdBO.getOperateBy()); + + } + + /** + * 删除用户 + * + * @param deleteBO + */ + @Override + public void deleteUser(UserDeleteBO deleteBO) { + for (Long userId : deleteBO.getUserIdList()) { + //校验超管账号不可删除 + this.checkSupperAdminUser(userId); + + SsoUser ssoUser = ssoUserMapper.getByUserId(userId); + if (null == ssoUser) { + return; + } + if (DelFlagEnum.DELETED.getStatus().equals(ssoUser.getDelFlag())) { + return; + } + + //标记用户为删除状态 + this.doDeleteUser(deleteBO, userId); + + //删除用户系统权限 + this.doDeleteUserSystem(deleteBO.getSysCode(), userId, deleteBO); + + //删除部门关系 + ssoUserDeptMapper.deleteBySysCodeAndUserId(deleteBO.getSysCode(), userId); + + //删除用户角色关系 + ssoUserRoleMapper.deleteBySysCodeAndUserId(deleteBO.getSysCode(), userId); + + //删除用户管理员权限 + this.doDeleteUserSystemManager(deleteBO.getSysCode(), userId, deleteBO); + + log.info("[ 用户 ] >> [ 删除用户 ] >> userId:{} , operateBy:{}", userId, deleteBO.getOperateBy()); + } + } + + /** + * 添加用户-系统关系 + * + * @param sysCode + * @param userId + * @param operateBO + */ + public void addUserSystemRelation(String sysCode, Long userId, BaseOperateBO operateBO) { + SsoUserSystem ssoUserSystem = ssoUserSystemMapper.getByUserIdAndSysCode(userId, sysCode); + if (null != ssoUserSystem) { + return; + } + + SsoUserSystem userSystem = new SsoUserSystem(); + userSystem.setUserId(userId); + userSystem.setSysCode(sysCode); + userSystem.setCreateBy(operateBO.getOperateBy()); + userSystem.setUpdateBy(operateBO.getOperateBy()); + ssoUserSystemMapper.insertSelective(userSystem); + } + + /** + * 标记为用户删除态 + * + * @param deleteBO + */ + private void doDeleteUser(UserDeleteBO deleteBO, Long userId) { + SsoUser ssoUser = new SsoUser(); + ssoUser.setUserId(userId); + ssoUser.setDelFlag(DelFlagEnum.DELETED.getStatus()); + ssoUser.setUpdateBy(deleteBO.getOperateBy()); + ssoUserMapper.updateByUserIdSelective(ssoUser); + } + + /** + * 删除用户系统关系 + * + * @param operateBO + */ + private void doDeleteUserSystem(String sysCode, Long userId, BaseOperateBO operateBO) { + SsoUserSystem ssoUserSystem = new SsoUserSystem(); + ssoUserSystem.setUserId(userId); + ssoUserSystem.setSysCode(sysCode); + ssoUserSystem.setUpdateBy(operateBO.getOperateBy()); + ssoUserSystem.setDelFlag(DelFlagEnum.DELETED.getStatus()); + ssoUserSystemMapper.updateBySysCodeAndUserIdSelective(ssoUserSystem); + } + + /** + * 删除用户管理权限关系 + * + * @param operateBO + */ + private void doDeleteUserSystemManager(String sysCode, Long userId, BaseOperateBO operateBO) { + SsoSystemManager updateEntity = new SsoSystemManager(); + updateEntity.setUserId(userId); + updateEntity.setSysCode(sysCode); + updateEntity.setDelFlag(DelFlagEnum.DELETED.getStatus()); + updateEntity.setUpdateBy(operateBO.getOperateBy()); + ssoSystemManagerMapper.updateBySysCodeAndUserId(updateEntity); + } + + /** + * 新增用户部门关系记录 + */ + private void doInsertUserDeptRelation(String sysCode, Long userId, Long deptId) { + if (null == userId || null == deptId) { + return; + } + SsoUserDept ssoUserDept = new SsoUserDept(); + ssoUserDept.setSysCode(sysCode); + ssoUserDept.setUserId(userId); + ssoUserDept.setDeptId(deptId); + ssoUserDeptMapper.insert(ssoUserDept); + } + + /** + * 新增用户角色关系记录 + */ + private void doInsertUserRoleRelation(String sysCode, Long userId, List roleIdList) { + if (null == userId || CollectionUtils.isEmpty(roleIdList)) { + return; + } + + SsoUserRole ssoUserRole = null; + List saveList = new ArrayList<>(roleIdList.size()); + for (Long roleId : roleIdList) { + ssoUserRole = new SsoUserRole(); + ssoUserRole.setSysCode(sysCode); + ssoUserRole.setUserId(userId); + ssoUserRole.setRoleId(roleId); + saveList.add(ssoUserRole); + } + + if (CollectionUtils.isEmpty(saveList)) { + return; + } + + ssoUserRoleMapper.batchSave(saveList); + } + + /** + * 组装结果集 + * + * @param userList + * @param userDeptMap + * @return + */ + private List buildUserListResult(List userList, + Map userSystemMap, + Map userDeptMap, Map userRoleMap) { + UserPageVO pageItem = null; + List resultList = new ArrayList<>(userList.size()); + Long supperAdminUserId = sysConfigService.getSupperAdminUserId(); + for (SsoUser ssoUser : userList) { + pageItem = BeanCopierUtil.copy(ssoUser, UserPageVO.class); + pageItem.setDeptName(userDeptMap.getOrDefault(ssoUser.getUserId(), "")); + pageItem.setRoleNames(userRoleMap.getOrDefault(ssoUser.getUserId(), "")); + pageItem.setSupperAdminFlag(ssoUser.getUserId().equals(supperAdminUserId)); + pageItem.setSysBindFlag(false); + if (userSystemMap.containsKey(ssoUser.getUserId())) { + pageItem.setSysBindFlag(true); + //修改添加人为-本系统的关键建立人 + SsoUserSystem ssoUserSystem = userSystemMap.get(ssoUser.getUserId()); + pageItem.setCreateBy(ssoUserSystem.getCreateBy()); + pageItem.setCreateTime(ssoUserSystem.getCreateTime()); + } + resultList.add(pageItem); + } + return resultList; + } + + /** + * 用户部门关系Map + * + * @param userIdList + */ + private Map getUserDeptMap(String sysCode, List userIdList) { + if (StringUtils.isEmpty(sysCode) || CollectionUtils.isEmpty(userIdList)) { + return new HashMap<>(0); + } + List deptByUserIdList = ssoDeptMapper.getDeptBySysCodeAndUserIdList(sysCode, userIdList); + if (CollectionUtils.isEmpty(deptByUserIdList)) { + return new HashMap<>(0); + } + return deptByUserIdList.stream().collect(Collectors.toMap(SsoUserDeptDTO::getUserId, SsoUserDeptDTO::getDeptName, (k1, k2) -> k1)); + } + + + /** + * 用户角色关系Map + * + * @param userIdList + */ + private Map getUserRolesMap(String sysCode, List userIdList) { + if (StringUtils.isEmpty(sysCode) || CollectionUtils.isEmpty(userIdList)) { + return new HashMap<>(0); + } + List roleList = ssoUserRoleMapper.getRoleBySysCodeAndUserIdList(sysCode, userIdList); + if (CollectionUtils.isEmpty(roleList)) { + return new HashMap<>(0); + } + return roleList.stream().collect(Collectors.toMap(SsoUserRoleDTO::getUserId, SsoUserRoleDTO::getRoleNames, (k1, k2) -> k1)); + } + + + /** + * 用户系统关系Map + * + * @param userIdList + */ + private Map getUserSystemMap(String sysCode, List userIdList) { + if (StringUtils.isEmpty(sysCode) || CollectionUtils.isEmpty(userIdList)) { + return new HashMap<>(0); + } + List systemList = ssoUserSystemMapper.listBySysCodeAndUserIdList(sysCode, userIdList); + if (CollectionUtils.isEmpty(systemList)) { + return new HashMap<>(0); + } + return systemList.stream().collect(Collectors.toMap(SsoUserSystem::getUserId, Function.identity(), (k1, k2) -> k1)); + } + + + /** + * 执行新增用户 + * + * @param addBO + */ + private SsoUser doInsertUser(UserAddBO addBO) { + SsoUser ssoUser = new SsoUser(); + ssoUser.setUsername(addBO.getUsername()); + ssoUser.setNickName(addBO.getNickName()); + ssoUser.setRealName(addBO.getRealName()); + ssoUser.setSex(addBO.getSex()); + ssoUser.setPhone(addBO.getPhone()); + ssoUser.setEmail(addBO.getEmail()); + ssoUser.setStatus(addBO.getStatus()); + ssoUser.setRemarks(addBO.getRemarks()); + ssoUser.setCreateBy(addBO.getOperateBy()); + ssoUser.setUpdateBy(addBO.getOperateBy()); + //密码加密处理 + ssoUser.setPassword(SecurityUtils.encryptPassword(addBO.getPassword())); + ssoUserMapper.insertSelective(ssoUser); + return ssoUser; + } + + /** + * 执行修改用户 + * + * @param updateBO + */ + private SsoUser doUpdateUser(UserUpdateBO updateBO) { + SsoUser ssoUser = new SsoUser(); + ssoUser.setUserId(updateBO.getUserId()); + ssoUser.setNickName(StringUtils.dealBlankDefault(updateBO.getNickName(), "")); + ssoUser.setRealName(StringUtils.dealBlankDefault(updateBO.getRealName(), "")); + ssoUser.setSex(updateBO.getSex()); + ssoUser.setStatus(updateBO.getStatus()); + ssoUser.setPhone(StringUtils.dealBlankDefault(updateBO.getPhone(), "")); + ssoUser.setEmail(StringUtils.dealBlankDefault(updateBO.getEmail(), "")); + ssoUser.setRemarks(StringUtils.dealBlankDefault(updateBO.getRemarks(), "")); + ssoUser.setUpdateBy(updateBO.getOperateBy()); + ssoUserMapper.updateByUserId(ssoUser); + return ssoUser; + } + + + /** + * 执行修改用户个人信息 + * + * @param updateBO + */ + private void doUpdateUserProfile(UserUpdateProfileBO updateBO) { + SsoUser ssoUser = new SsoUser(); + ssoUser.setUserId(updateBO.getUserId()); + ssoUser.setNickName(StringUtils.dealBlankDefault(updateBO.getNickName(), "")); + ssoUser.setRealName(StringUtils.dealBlankDefault(updateBO.getRealName(), "")); + ssoUser.setSex(updateBO.getSex()); + ssoUser.setPhone(StringUtils.dealBlankDefault(updateBO.getPhone(), "")); + ssoUser.setEmail(StringUtils.dealBlankDefault(updateBO.getEmail(), "")); + ssoUser.setUpdateBy(updateBO.getOperateBy()); + ssoUserMapper.updateProfileByUserId(ssoUser); + } + + /** + * 校验用户名唯一性 + * + * @param username 用户名 + * @param excludeUserId 需要排除的用户ID + */ + private void checkUserNameUniq(String username, Long... excludeUserId) { + if (StringUtils.isEmpty(username)) { + return; + } + SsoUser ssoUser = ssoUserMapper.getByUserName(username); + if (null == ssoUser) { + return; + } + if (!ObjectUtils.isEmpty(excludeUserId) && ssoUser.getUserId().equals(excludeUserId[0])) { + return; + } + //用户名已经存在 + throw new BusinessException(UserResStatusEnum.USER_NAME_EXISTS, username); + } + + /** + * 校验手机号唯一性 + * + * @param phone 手机号 + * @param excludeUserId 需要排除的用户ID + */ + private void checkPhoneUniq(String phone, Long... excludeUserId) { + if (StringUtils.isEmpty(phone)) { + return; + } + SsoUser ssoUser = ssoUserMapper.getByPhone(phone); + if (null == ssoUser) { + return; + } + if (!ObjectUtils.isEmpty(excludeUserId) && ssoUser.getUserId().equals(excludeUserId[0])) { + return; + } + //手机号已经存在 + throw new BusinessException(UserResStatusEnum.PHONE_EXISTS, phone); + } + + /** + * 校验邮箱唯一性 + * + * @param email 邮箱地址 + * @param excludeUserId 需要排除的用户ID + */ + private void checkEmailUniq(String email, Long... excludeUserId) { + if (StringUtils.isEmpty(email)) { + return; + } + SsoUser ssoUser = ssoUserMapper.getByEmail(email); + if (null == ssoUser) { + return; + } + if (!ObjectUtils.isEmpty(excludeUserId) && ssoUser.getUserId().equals(excludeUserId[0])) { + return; + } + //邮箱已经存在 + throw new BusinessException(UserResStatusEnum.EMAIL_EXISTS, email); + } + + /** + * 超级管理员账户,不可操作 + * + * @param userId + */ + private void checkSupperAdminUser(Long userId) { + if (null == userId) { + return; + } + Long supperAdminUserId = sysConfigService.getSupperAdminUserId(); + if (null == supperAdminUserId) { + return; + } + if (supperAdminUserId.equals(userId)) { + throw new BusinessException(UserResStatusEnum.SUPPER_ADMIN_USER); + } + } + + + /** + * 构建查询参数 + * + * @param pageBO + * @return + */ + private UserPageQuery buildUserPageQuery(UserListPageBO pageBO) { + UserPageQuery query = new UserPageQuery() + .setUsernameLike(pageBO.getUsernameLike()) + .setNickNameLike(pageBO.getNickNameLike()) + .setRealNameLike(pageBO.getRealNameLike()) + .setPhoneLike(pageBO.getPhoneLike()) + .setDeptId(pageBO.getDeptId()) + .setRoleId(pageBO.getRoleId()) + .setStatus(pageBO.getStatus()) + //未删除 + .setDelFlag(DelFlagEnum.OK.getStatus()); + + query.setPage(pageBO.getPage()); + query.setPageSize(pageBO.getPageSize()); + return query; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/PermissionService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/PermissionService.java new file mode 100755 index 0000000..e9f1c60 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/PermissionService.java @@ -0,0 +1,57 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.admin.login; + +import com.sso.common.constant.SsoPermissionConstants; +import com.sso.common.model.login.LoginResultVO; +import com.sso.common.utils.ObjectUtils; +import com.sso.common.utils.ServletUtils; +import com.sso.common.utils.StringUtils; +import com.sso.service.base.SsoTokenService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.Set; + +/** + * 自定义权限实现,ss取自SpringSecurity首字母 + * + * @author 程序员小强 + */ +@Service("ss") +public class PermissionService { + + @Autowired + private SsoTokenService ssoTokenService; + + /** + * 验证用户是否具备某权限 + * + * @param permission 权限字符串,示例:user:add + * @return 用户是否具备某权限 + */ + public boolean hasPermission(String permission) { + if (StringUtils.isEmpty(permission)) { + return false; + } + LoginResultVO loginUser = ssoTokenService.getLoginUser(ServletUtils.getRequest()); + if (ObjectUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissionList())) { + return false; + } + return hasPermissions(loginUser.getPermissionList(), permission); + } + + /** + * 判断是否包含权限 + * + * @param permissions 权限列表 + * @param permission 权限字符串 + * @return 用户是否具备某权限 + */ + private boolean hasPermissions(Set permissions, String permission) { + return permissions.contains(SsoPermissionConstants.ALL_PERMISSION) || permissions.contains(StringUtils.trim(permission)); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/SsoLoginService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/SsoLoginService.java new file mode 100755 index 0000000..bb44f84 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/SsoLoginService.java @@ -0,0 +1,222 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.admin.login; + +import com.sso.common.constant.CacheConstants; +import com.sso.common.enums.LoginStatusEnum; +import com.sso.common.enums.exception.SysResStatusEnum; +import com.sso.common.exception.BusinessException; +import com.sso.common.model.login.LoginResultVO; +import com.sso.common.utils.ServletUtils; +import com.sso.common.utils.StringUtils; +import com.sso.common.utils.ip.IpAddressUtils; +import com.sso.common.utils.ip.IpUtils; +import com.sso.dao.entity.SsoLoginLog; +import com.sso.dao.entity.SsoOnlineUser; +import com.sso.dao.mapper.SsoLoginLogMapper; +import com.sso.dao.mapper.SsoOnlineUserMapper; +import com.sso.dao.mapper.SsoUserMapper; +import com.sso.framework.redis.RedisCache; +import com.sso.model.bo.login.LoginBO; +import com.sso.model.vo.login.LoginTokenVO; +import com.sso.service.base.SsoTokenService; +import eu.bitwalker.useragentutils.UserAgent; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.authentication.*; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.Date; + +/** + * 登录校验方法 + * + * @author 程序员小强 + */ +@Slf4j +@Component +public class SsoLoginService { + + @Resource + private RedisCache redisCache; + + @Resource + private SsoUserMapper ssoUserMapper; + + @Resource + private SsoTokenService tokenService; + + @Resource + private SsoLoginLogMapper ssoLoginLogMapper; + + @Resource + private SsoOnlineUserMapper ssoOnlineUserMapper; + + @Resource + private AuthenticationManager authenticationManager; + + /** + * 登录验证 + * + * @param loginBO 登录 + * @return 结果 + */ + public LoginTokenVO login(LoginBO loginBO) { + + //验证码校验 + this.checkCaptcha(loginBO); + + //账号校验(账密,状态) + LoginResultVO loginResult = this.doCheckAccount(loginBO); + + //本次请求唯一标识 + loginResult.setRequestId(loginBO.getRequestId()); + + // 生成token + String token = tokenService.createToken(loginResult); + + //记录最后登录时间 + ssoUserMapper.updateLastLogin(loginResult.getUser().getUserId(), loginResult.getSourceIp(), new Date(loginResult.getLoginTime())); + + //记录登录日志 + this.doAddLoginSuccessLog(loginResult); + + //记录在线用户记录 + this.doSaveOnlineUserRecord(loginResult); + + return new LoginTokenVO(loginBO.getUsername(), loginBO.getRequestId(), token); + } + + /** + * 记录登录日志 + */ + private void doAddLoginFailLog(LoginBO loginBO, String operateMsg) { + doAddLoginLog(loginBO.getRequestId(), LoginStatusEnum.FAIL, loginBO.getUsername(), System.currentTimeMillis(), operateMsg); + } + + /** + * 记录登录日志 + */ + private void doAddLoginSuccessLog(LoginResultVO loginResult) { + doAddLoginLog(loginResult.getRequestId(), LoginStatusEnum.SUCCESS, loginResult.getUsername(), loginResult.getLoginTime(), ""); + } + + /** + * 记录登录日志 + */ + private SsoLoginLog doAddLoginLog(String requestId, LoginStatusEnum statusEnum, String username, Long loginTime, String operateMsg) { + SsoLoginLog loginLog = new SsoLoginLog(); + loginLog.setRequestId(requestId); + //用户登录名 + loginLog.setUsername(username); + //IP地址 + String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); + //来源IP + loginLog.setSourceIp(StringUtils.dealBlankDefault(ip, "")); + //来源地址 + loginLog.setSourceAddress(StringUtils.dealBlankDefault(IpAddressUtils.getRealAddressByIP(ip), "")); + //登录浏览器相关 + UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); + //浏览器 + loginLog.setBrowserName(StringUtils.dealBlankDefault(userAgent.getBrowser().getName(), "")); + //操作系统 + loginLog.setOperateSystem(StringUtils.dealBlankDefault(userAgent.getOperatingSystem().getName(), "")); + + //登录状态 0-成功;1-失败 + loginLog.setStatus(statusEnum.getStatus()); + //登录时间戳 + loginLog.setLoginTime(loginTime); + //返回结果 + loginLog.setOperateMsg(StringUtils.dealBlankDefault(operateMsg, "")); + ssoLoginLogMapper.insertSelective(loginLog); + return loginLog; + } + + /** + * 记录在线用户记录 + * + * @param loginResult + */ + private void doSaveOnlineUserRecord(LoginResultVO loginResult) { + SsoOnlineUser ssoOnlineUser = new SsoOnlineUser(); + ssoOnlineUser.setRequestId(loginResult.getRequestId()); + ssoOnlineUser.setUserId(loginResult.getUser().getUserId()); + ssoOnlineUser.setSourceIp(loginResult.getSourceIp()); + ssoOnlineUser.setSourceAddress(loginResult.getSourceAddress()); + ssoOnlineUser.setBrowserName(loginResult.getBrowserName()); + ssoOnlineUser.setOperateSystem(loginResult.getOperateSystem()); + ssoOnlineUser.setLoginTime(loginResult.getLoginTime()); + ssoOnlineUser.setExpireTime(loginResult.getExpireTime()); + ssoOnlineUserMapper.insertSelective(ssoOnlineUser); + } + + /** + * 账号校验 + * + * @param loginBO + */ + private LoginResultVO doCheckAccount(LoginBO loginBO) { + //用户验证 + try { + UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(loginBO.getUsername(), loginBO.getPassword()); + //该方法会去调用UserDetailsServiceImpl.loadUserByUsername + Authentication authentication = authenticationManager.authenticate(authToken); + return (LoginResultVO) authentication.getPrincipal(); + } catch (Exception e) { + if (e instanceof UsernameNotFoundException || e instanceof BadCredentialsException) { + log.info("用户名或密码错误 username:{}", loginBO.getUsername()); + //记录登录日志 + this.doAddLoginFailLog(loginBO, SysResStatusEnum.USER_PASSWORD_NOT_MATCH.getMsg()); + //用户名或密码错误 + throw new BusinessException(SysResStatusEnum.USER_PASSWORD_NOT_MATCH); + } else if (e instanceof DisabledException || e instanceof InternalAuthenticationServiceException) { + log.info("用户已停用 username:{}", loginBO.getUsername()); + //记录登录日志 + this.doAddLoginFailLog(loginBO, SysResStatusEnum.USER_DISABLE.getMsg()); + //用户已停用 + throw new BusinessException(SysResStatusEnum.USER_DISABLE); + } else if (e instanceof AuthenticationException) { + log.info("用户名或密码错误 username:{}", loginBO.getUsername()); + //记录登录日志 + this.doAddLoginFailLog(loginBO, SysResStatusEnum.USER_NAME_NOT_EXISTS.getMsg()); + //用户已停用 + throw new BusinessException(SysResStatusEnum.USER_NAME_NOT_EXISTS); + } else { + //记录登录日志 + this.doAddLoginFailLog(loginBO, SysResStatusEnum.SYSTEM_ERROR.getMsg()); + log.info("[ 登录异常 ] username:{} >> ", loginBO.getUsername(), e); + //其它登录失败 + throw new BusinessException(SysResStatusEnum.SYSTEM_ERROR); + } + } + } + + /** + * 校验验证码 + * + * @param loginBO + */ + private void checkCaptcha(LoginBO loginBO) { + String verifyKey = CacheConstants.getCaptchaCodeKey(loginBO.getRequestId()); + String captcha = redisCache.get(verifyKey); + //验证码已失效 + if (captcha == null) { + //记录登录日志 + this.doAddLoginFailLog(loginBO, SysResStatusEnum.CAPTCHA_EXPIRE.getMsg()); + throw new BusinessException(SysResStatusEnum.CAPTCHA_EXPIRE); + } + //仅一次有效,使用后作废 + redisCache.del(verifyKey); + //验证码错误 + if (!loginBO.getCaptchaCode().equalsIgnoreCase(captcha)) { + //记录登录日志 + this.doAddLoginFailLog(loginBO, SysResStatusEnum.CAPTCHA_ERROR.getMsg()); + throw new BusinessException(SysResStatusEnum.CAPTCHA_ERROR); + } + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/SysPermissionService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/SysPermissionService.java new file mode 100755 index 0000000..973db8f --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/SysPermissionService.java @@ -0,0 +1,136 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.admin.login; + +import com.sso.common.constant.SsoConstants; +import com.sso.common.constant.SsoPermissionConstants; +import com.sso.common.enums.MenuTypeEnum; +import com.sso.common.model.login.LoginResultVO; +import com.sso.common.model.login.LoginUserVO; +import com.sso.common.utils.ServletUtils; +import com.sso.common.utils.StringUtils; +import com.sso.common.utils.bean.BeanCopierUtil; +import com.sso.common.utils.tree.ListToTreeUtil; +import com.sso.dao.entity.SsoMenu; +import com.sso.dao.mapper.SsoMenuMapper; +import com.sso.dao.mapper.SsoRoleMapper; +import com.sso.framework.config.property.SysConfigProperty; +import com.sso.model.vo.login.LoginMenuVO; +import com.sso.model.vo.login.LoginUserInfoVO; +import com.sso.service.base.SsoTokenService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; +import java.util.*; + +/** + * 用户权限处理 + * + * @author 程序员小强 + */ +@Component +public class SysPermissionService { + + @Autowired + private SsoTokenService ssoTokenService; + + @Resource + private SsoMenuMapper ssoMenuMapper; + @Resource + private SsoRoleMapper ssoRoleMapper; + @Resource + private SysConfigProperty sysConfigProperty; + + + /** + * 获取登录用户信息 + * + * @return + */ + public LoginUserInfoVO getLoginUserInfo() { + LoginResultVO loginResultVO = ssoTokenService.getLoginUser(ServletUtils.getRequest()); + LoginUserVO user = loginResultVO.getUser(); + user.setPassword(""); + + //菜单权限 + LoginUserInfoVO userInfo = this.getMenuPermission(user); + //用户信息 + userInfo.setUser(user); + //角色Key + userInfo.setRoleKeyList(this.getRolePermission(user)); + return userInfo; + } + + /** + * 获取角色数据权限 + * + * @param user 用户信息 + * @return 角色权限信息 + */ + public Set getRolePermission(LoginUserVO user) { + Set roles = new HashSet<>(); + // 管理员拥有所有权限 + if (SsoPermissionConstants.ADMIN_USER_SET.contains(user.getUsername())) { + roles.add("**"); + } else { + roles.addAll(ssoRoleMapper.getRoleKeyBySysCodeAndUserId(sysConfigProperty.getAuthSsoSysCode(), user.getUserId())); + } + return roles; + } + + /** + * 获取菜单数据权限 + * + * @param user 用户信息 + * @return 菜单权限信息 + */ + public LoginUserInfoVO getMenuPermission(LoginUserVO user) { + return this.getMenuPermissionByUser(sysConfigProperty.getAuthSsoSysCode(), user); + } + + public LoginUserInfoVO getMenuPermissionByUser(String sysCode, LoginUserVO user) { + Set permissionList; + List menuList; + + //管理员拥有所有权限 + if (SsoPermissionConstants.ADMIN_USER_SET.contains(user.getUsername())) { + permissionList = Collections.singleton(SsoPermissionConstants.ALL_PERMISSION); + menuList = ssoMenuMapper.getEnableMenuListBySysCode(sysCode); + //转换成树结构 + List treeNodeVOList = BeanCopierUtil.copyList(menuList, LoginMenuVO.class); + ListToTreeUtil result = new ListToTreeUtil<>(); + return new LoginUserInfoVO(permissionList, result.getTreeListObject(treeNodeVOList)); + } + + //非管理员-根据角色查询权限 + menuList = ssoMenuMapper.getMenuListBySysCodeAndUserId(sysCode, user.getUserId()); + if (CollectionUtils.isEmpty(menuList)) { + return LoginUserInfoVO.initDefault(); + } + + LoginMenuVO menuVO = null; + List menuResList = new ArrayList<>(menuList.size()); + //权限标识集 + permissionList = new HashSet<>(menuList.size()); + for (SsoMenu menu : menuList) { + if (StringUtils.isNotBlank(menu.getPermissions())) { + permissionList.addAll(Arrays.asList(menu.getPermissions().split(SsoConstants.SPLIT_ESCAPE))); + } + //菜单 + if (MenuTypeEnum.isMenu(menu.getMenuType())) { + menuVO = BeanCopierUtil.copy(menu, LoginMenuVO.class); + menuResList.add(menuVO); + } + } + //菜单转换成树结构 + List treeNodeVOList = BeanCopierUtil.copyList(menuResList, LoginMenuVO.class); + ListToTreeUtil result = new ListToTreeUtil<>(); + return new LoginUserInfoVO(permissionList, result.getTreeListObject(treeNodeVOList)); + } + + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/UserAccountAuthServiceImpl.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/UserAccountAuthServiceImpl.java new file mode 100755 index 0000000..c50297a --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/admin/login/UserAccountAuthServiceImpl.java @@ -0,0 +1,65 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.admin.login; + +import com.sso.common.enums.DelFlagEnum; +import com.sso.common.enums.system.UserStatusEnum; +import com.sso.common.model.login.LoginResultVO; +import com.sso.common.model.login.LoginUserVO; +import com.sso.common.utils.bean.BeanCopierUtil; +import com.sso.dao.entity.SsoUser; +import com.sso.dao.mapper.SsoUserMapper; +import com.sso.model.vo.login.LoginUserInfoVO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.AccountExpiredException; +import org.springframework.security.authentication.DisabledException; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * 用户登录认证-验证处理 + * + * @author 程序员小强 + */ +@Slf4j +@Service +public class UserAccountAuthServiceImpl implements UserDetailsService { + + @Resource + private SsoUserMapper ssoUserMapper; + @Autowired + private SysPermissionService permissionService; + + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + SsoUser user = ssoUserMapper.getByUserName(username); + if (null == user) { + log.info("登录用户:{} 不存在.", username); + throw new UsernameNotFoundException("登录用户不存在"); + } else if (DelFlagEnum.DELETED.getStatus().equals(user.getDelFlag())) { + log.info("登录用户:{} 已被删除.", username); + throw new AccountExpiredException("用户已被删除"); + } else if (UserStatusEnum.DISABLE.getStatus().equals(user.getStatus())) { + log.info("登录用户:{} 已被停用.", username); + throw new DisabledException("用户已停用"); + } + + return createLoginUser(user); + } + + public UserDetails createLoginUser(SsoUser user) { + LoginUserVO loginUserVO = BeanCopierUtil.copy(user, LoginUserVO.class); + LoginUserInfoVO menuPermission = permissionService.getMenuPermission(loginUserVO); + LoginResultVO loginResultVO = new LoginResultVO(loginUserVO, menuPermission.getPermissionList()); + loginResultVO.setRoleKeyList(permissionService.getRolePermission(loginUserVO)); + return loginResultVO; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/base/SsoTokenService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/base/SsoTokenService.java new file mode 100755 index 0000000..8186873 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/base/SsoTokenService.java @@ -0,0 +1,315 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.base; + +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSON; +import com.sso.common.constant.CacheConstants; +import com.sso.common.constant.UserLoginConstants; +import com.sso.common.model.login.LoginResultVO; +import com.sso.common.utils.ObjectUtils; +import com.sso.common.utils.ServletUtils; +import com.sso.common.utils.StringUtils; +import com.sso.common.utils.UUIDUtil; +import com.sso.common.utils.ip.IpAddressUtils; +import com.sso.common.utils.ip.IpUtils; +import com.sso.dao.mapper.SsoOnlineUserMapper; +import com.sso.framework.config.property.SysConfigProperty; +import com.sso.framework.redis.RedisCache; +import com.sso.model.vo.getway.SysLoginCacheVO; +import eu.bitwalker.useragentutils.UserAgent; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; + +/** + * token验证处理 + * + * @author 程序员小强 + */ +@Slf4j +@Component +public class SsoTokenService { + protected static final long MILLIS_SECOND = 1000; + protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; + private static final Long MILLIS_MINUTE_TEN = 20 * 60 * 1000L; + + @Autowired + private RedisCache redisCache; + + @Resource + private SsoOnlineUserMapper ssoOnlineUserMapper; + + @Autowired + private SysConfigProperty sysConfigProperty; + + /** + * 根据HttpServletRequest 获取用户 + * + * @return 用户信息 + */ + public LoginResultVO getLoginUser(HttpServletRequest request) { + //获取请求携带的令牌 + String token = this.getTokenByHeader(request); + //获取不到token-未登录 + if (StringUtils.isEmpty(token)) { + return null; + } + return this.getUserByToken(token); + } + + /** + * 根据token 查询用户 + * + * @param token + * @return 用户信息 + */ + public LoginResultVO getUserByToken(String token) { + if (StringUtils.isBlank(token)) { + return null; + } + + //toke缓存key + String tokenCacheKey = CacheConstants.getLoginUserTokenKey(token); + return redisCache.hGet(tokenCacheKey, token, LoginResultVO.class); + } + + /** + * 根据userId 查询用户 + * + * @param userId + * @return 用户信息 + */ + public LoginResultVO getUserByUserId(Long userId) { + if (null == userId) { + return null; + } + + String userIdCacheKey = CacheConstants.getLoginUserIdKey(userId); + //根据unionId查询redis,若用户信息存在 + return redisCache.get(userIdCacheKey, LoginResultVO.class); + } + + /** + * 用户退出 + * 清除token记录 + */ + public void logoOutUser(Long userId) { + if (ObjectUtils.isNull(userId)) { + return; + } + //登录缓存用户信息 + LoginResultVO loginUser = redisCache.get(CacheConstants.getLoginUserIdKey(userId), LoginResultVO.class); + if (ObjectUtils.isNull(loginUser)) { + return; + } + this.logoOutUser(loginUser); + } + + /** + * 用户退出 + * 清除token记录 + */ + public void logoOutUser(LoginResultVO loginResultVO) { + if (null == loginResultVO) { + return; + } + if (StringUtils.isEmpty(loginResultVO.getToken())) { + return; + } + if (null == loginResultVO.getUser()) { + return; + } + + String userTokenKey = CacheConstants.getLoginUserTokenKey(loginResultVO.getToken()); + + //若已登录子系统-则退出所有子系统 + this.loginOutChildSysByToken(loginResultVO.getToken()); + + //清除token记录 + redisCache.del(userTokenKey); + + //清除用户记录 + String userIdKey = CacheConstants.getLoginUserIdKey(loginResultVO.getUser().getUserId()); + redisCache.del(userIdKey); + + //更新在线用户记录截止时间 + this.updateOnlineUserExpire(loginResultVO); + } + + /** + * 更新在线用户记录截止时间 + * + * @param loginResultVO + */ + private void updateOnlineUserExpire(LoginResultVO loginResultVO) { + long expireTime = loginResultVO.getExpireTime(); + long currentTimeMillis = System.currentTimeMillis(); + //还未截止-则改为当前时间 + if (expireTime > currentTimeMillis) { + expireTime = currentTimeMillis; + } + //效期截止 + ssoOnlineUserMapper.updateByLogoOut(loginResultVO.getRequestId(), expireTime, currentTimeMillis); + } + + /** + * 创建令牌 + * + * @param loginResultVO 用户信息 + * @return 令牌 + */ + public String createToken(LoginResultVO loginResultVO) { + String token = UUIDUtil.getUUID(); + loginResultVO.setToken(token); + this.setUserAgent(loginResultVO); + //创建token + this.doCreateToken(loginResultVO); + return token; + } + + /** + * 验证令牌有效期, + * 相差不足20分钟,自动刷新 token续期 + * + * @param loginResult + * @return 令牌 + */ + public void renewTokenByAdminWeb(LoginResultVO loginResult) { + String token = loginResult.getToken(); + long expireTime = loginResult.getExpireTime(); + long currentTime = System.currentTimeMillis(); + + //若效期时间不足20分钟则进行续期 + if (expireTime - currentTime > MILLIS_MINUTE_TEN) { + return; + } + + String userIdCacheKey = CacheConstants.getLoginUserIdKey(loginResult.getUser().getUserId()); + LoginResultVO lastLoginUser = redisCache.get(userIdCacheKey, LoginResultVO.class); + + if (null == lastLoginUser || !token.equals(lastLoginUser.getToken())) { + return; + } + + //若token一致-则效期延长 + loginResult.setExpireTime(loginResult.getLoginTime() + sysConfigProperty.getTokenExpireTime() * MILLIS_MINUTE); + String userTokenCacheKey = CacheConstants.getLoginUserTokenKey(loginResult.getToken()); + redisCache.set(userIdCacheKey, loginResult, sysConfigProperty.getTokenExpireTime(), TimeUnit.MINUTES); + redisCache.hSet(userTokenCacheKey, loginResult.getToken(), loginResult, sysConfigProperty.getTokenExpireTime(), TimeUnit.MINUTES); + + //刷新登录记录表效期 + if (StringUtils.isNotBlank(lastLoginUser.getRequestId())) { + ssoOnlineUserMapper.refreshExpireTimeByRequestId(lastLoginUser.getRequestId(), loginResult.getExpireTime()); + } + } + + /** + * 创建令牌-并指定有效期 + * + * @param loginResultVO 登录信息 + */ + public void doCreateToken(LoginResultVO loginResultVO) { + loginResultVO.setLoginTime(System.currentTimeMillis()); + loginResultVO.setExpireTime(loginResultVO.getLoginTime() + sysConfigProperty.getTokenExpireTime() * MILLIS_MINUTE); + + String userIdCacheKey = CacheConstants.getLoginUserIdKey(loginResultVO.getUser().getUserId()); + //根据unionId查询redis,若用户信息存在 + LoginResultVO lastLoginUser = redisCache.get(userIdCacheKey, LoginResultVO.class); + if (ObjectUtils.isNotNull(lastLoginUser)) { + //若已登录子系统-则退出所有子系统 + this.loginOutChildSysByToken(lastLoginUser.getToken()); + //删除同一用户,旧的token信息,避免目标系统申请认证直接刷新token信息 + redisCache.del(CacheConstants.getLoginUserTokenKey(lastLoginUser.getToken())); + //更新在线用户记录截止时间 + this.updateOnlineUserExpire(lastLoginUser); + } + + String userTokenCacheKey = CacheConstants.getLoginUserTokenKey(loginResultVO.getToken()); + redisCache.set(userIdCacheKey, loginResultVO, sysConfigProperty.getTokenExpireTime(), TimeUnit.MINUTES); + redisCache.hSet(userTokenCacheKey, loginResultVO.getToken(), loginResultVO, sysConfigProperty.getTokenExpireTime(), TimeUnit.MINUTES); + } + + /** + * 根据token-查询已经登录的子系统 + * 依次登出子系统 + * + * @param token + */ + private void loginOutChildSysByToken(String token) { + String userTokenKey = CacheConstants.getLoginUserTokenKey(token); + //key:系统编码 sysCode , value:系统退出地址 + Map loginSystemMap = redisCache.hgetAll(userTokenKey, String.class); + if (ObjectUtils.isEmpty(loginSystemMap)) { + return; + } + + CompletableFuture.runAsync(() -> this.loginOutChildSysAsync(token, loginSystemMap)); + } + + /** + * 异步调用-子系统退出接口 + * + * @param token + * @param loginSystemMap + */ + private void loginOutChildSysAsync(String token, Map loginSystemMap) { + for (Map.Entry map : loginSystemMap.entrySet()) { + String key = map.getKey(); + String value = map.getValue(); + if (key.equals(token)) { + continue; + } + if (StringUtils.isBlank(value)) { + continue; + } + SysLoginCacheVO loginCache = JSON.parseObject(value, SysLoginCacheVO.class); + if (StringUtils.isBlank(loginCache.getLoginOutUrl())) { + continue; + } + log.info("[ 登出子系统 ] >> sysCode:{},logoOutUrl:{}", key, loginCache.getLoginOutUrl()); + HttpUtil.get(loginCache.getLoginOutUrl()); + } + } + + /** + * 设置用户代理信息 + * + * @param loginResultVO 登录信息 + */ + public void setUserAgent(LoginResultVO loginResultVO) { + //IP地址相关 + String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); + loginResultVO.setSourceIp(ip); + loginResultVO.setSourceAddress(IpAddressUtils.getRealAddressByIP(ip)); + + //登录浏览器相关 + UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); + //浏览器名称 + loginResultVO.setBrowserName(userAgent.getBrowser().getName()); + //操作系统名称 + loginResultVO.setOperateSystem(userAgent.getOperatingSystem().getName()); + } + + /** + * 获取请求token + * + * @param request + * @return token + */ + private String getTokenByHeader(HttpServletRequest request) { + String token = request.getHeader(sysConfigProperty.getTokenHeader()); + if (StringUtils.isNotEmpty(token) && token.startsWith(UserLoginConstants.TOKEN_PREFIX)) { + token = token.replace(UserLoginConstants.TOKEN_PREFIX, ""); + } + return token; + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/base/SysConfigService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/base/SysConfigService.java new file mode 100644 index 0000000..40e1b77 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/base/SysConfigService.java @@ -0,0 +1,37 @@ +package com.sso.service.base; + +import com.sso.common.constant.SsoConstants; +import com.sso.common.utils.StringUtils; +import com.sso.framework.config.property.SysConfigProperty; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * 获取配置参数公共接口 + * + * @author 程序员小强 + */ +@Slf4j +@Component +public class SysConfigService { + + @Resource + private SysConfigProperty sysConfigProperty; + + /** + * 获取系统管理员用户ID + */ + public Long getSupperAdminUserId() { + String supperAdminUser = sysConfigProperty.getSupperAdminUser(); + if (StringUtils.isBlank(supperAdminUser)) { + return null; + } + String[] splitUser = supperAdminUser.split(SsoConstants.SPLIT_ESCAPE); + if (splitUser.length < 1) { + return null; + } + return Long.parseLong(splitUser[0]); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/base/SystemCacheService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/base/SystemCacheService.java new file mode 100644 index 0000000..9c546be --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/base/SystemCacheService.java @@ -0,0 +1,71 @@ +package com.sso.service.base; + +import com.sso.common.constant.CacheConstants; +import com.sso.common.utils.StringUtils; +import com.sso.dao.entity.SsoSystem; +import com.sso.dao.mapper.SsoSystemMapper; +import com.sso.framework.redis.RedisCache; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.concurrent.TimeUnit; + +@Service +public class SystemCacheService { + + @Autowired + private RedisCache redisCache; + + @Resource + private SsoSystemMapper ssoSystemMapper; + + /** + * 获取系统配置 - 有缓存,优先获取缓存内容 + * + * @param sysCode + */ + public SsoSystem getBySysCode(String sysCode) { + if (StringUtils.isBlank(sysCode)) { + return null; + } + + String systemCaptchaKey = CacheConstants.getSystemCaptchaKey(sysCode); + + //查询缓存 + SsoSystem systemFromCache = redisCache.get(systemCaptchaKey, SsoSystem.class); + if (null != systemFromCache) { + return systemFromCache; + } + + //默认720分钟=12小时(配置不经常改变) + int expireMinutes = CacheConstants.SYSTEM_CONFIG_CACHE_EXPIRE; + + SsoSystem systemFromDb = ssoSystemMapper.getBySysCode(sysCode); + if (null == systemFromDb) { + //数据库不存在-也缓存 -> 防止缓存穿透 + systemFromDb = new SsoSystem(); + //失效时间设置短一点 + expireMinutes = CacheConstants.CAPTCHA_EXPIRE_FIVE; + } + //缓存到redis + redisCache.set(systemCaptchaKey, systemFromDb, expireMinutes, TimeUnit.MINUTES); + + return systemFromDb; + } + + /** + * 移除配置缓存 + *

+ * 使用场景-编辑系统配置之后 + * + * @param sysCode + */ + public void removeSystemCache(String sysCode) { + if (StringUtils.isBlank(sysCode)) { + return; + } + String systemCaptchaKey = CacheConstants.getSystemCaptchaKey(sysCode); + redisCache.del(systemCaptchaKey); + } +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/getway/ApiClient.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/getway/ApiClient.java new file mode 100644 index 0000000..e3f7eb5 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/getway/ApiClient.java @@ -0,0 +1,205 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.getway; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sso.common.enums.SignTypeEnum; +import com.sso.common.enums.exception.ApiExceptionEnum; +import com.sso.common.exception.BusinessException; +import com.sso.common.model.result.ResultModel; +import com.sso.common.utils.SsoSignUtil; +import com.sso.common.utils.ValidateUtils; +import com.sso.common.utils.sign.RSASignUtils; +import com.sso.common.utils.sign.SignContentUtil; +import com.sso.dao.entity.SsoSystem; +import com.sso.framework.context.ApplicationContextHelper; +import com.sso.framework.gateway.ApiContainer; +import com.sso.framework.gateway.ApiModel; +import com.sso.model.bo.getway.GetWayReqBO; +import com.sso.service.base.SystemCacheService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.lang.reflect.InvocationTargetException; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Map; + +/** + * Api请求客户端 + * + * @author 程序员小强 + */ +@Slf4j +@Service +public class ApiClient { + + /** + * jackson 序列化工具类 + */ + private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); + + /** + * 时间最大间隔毫秒数 + * 5分钟 + */ + private static final Long TIMESTAMP_MAX_BETWEEN = 300000L; + + /** + * Api本地容器 + */ + private final ApiContainer apiContainer; + + public ApiClient(ApiContainer apiContainer) { + this.apiContainer = apiContainer; + } + + @Autowired + private SystemCacheService systemCacheService; + + + /** + * 校验时间戳 + * + * @param reqBO + * @param paramMap + */ + public void checkTimestamp(GetWayReqBO reqBO, Map paramMap) { + long timestamp = Long.parseLong(reqBO.getTimestamp()); + long betweenTime = System.currentTimeMillis() - timestamp; + + //间隔不能超过5分钟 + if (Math.abs(betweenTime) > TIMESTAMP_MAX_BETWEEN) { + throw new BusinessException("请求时间间隔超时"); + } + } + + /** + * 验签 + * + * @author 程序员小强 + */ + public void checkSign(GetWayReqBO reqBO, Map paramMap) { + SsoSystem ssoSystem = systemCacheService.getBySysCode(reqBO.getSysCode()); + if (null == ssoSystem) { + throw new BusinessException("系统不存在"); + } + + //未配置公钥-不验签 + if (SignTypeEnum.EMPTY.getValue().equals(ssoSystem.getSignType()) || + StringUtils.isBlank(ssoSystem.getPublicKey())) { + log.warn("[ 未配置公钥或已配置不验签 ] >> sysCode:{}", ssoSystem.getSysCode()); + return; + } + + SignTypeEnum signValueType = SignTypeEnum.getByValue(reqBO.getSignType()); + if (null == signValueType) { + //签名类型不存在 + throw new BusinessException(ApiExceptionEnum.SIGN_TYPE_NOT_EXIST); + } + + log.info("signType:{}, 验签参数 {}", reqBO.getSignType(), paramMap); + switch (signValueType) { + case MD5: + //MD5 签名校验 + this.checkMd5Sign(paramMap, ssoSystem.getPublicKey()); + break; + case RSA: + //RSA 签名校验 + this.checkRsaSign(paramMap, ssoSystem.getPublicKey()); + break; + default: + throw new BusinessException(ApiExceptionEnum.SIGN_TYPE_NOT_EXIST); + } + } + + /** + * Api调用方法 + * + * @param reqBO 请求参数 + * @author 程序员小强 + */ + public ResultModel invoke(GetWayReqBO reqBO) throws Throwable { + //获取api方法 + ApiModel apiModel = apiContainer.get(reqBO.getMethod()); + + if (null == apiModel) { + log.info("[ API方法不存在 ] >> method = {}", reqBO.getMethod()); + throw new BusinessException(ApiExceptionEnum.API_NOT_EXIST); + } + + //获得spring bean + Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName()); + if (null == bean) { + log.warn("[ API方法不存在 ] >> method = {}, beanName = {}", reqBO.getMethod(), apiModel.getBeanName()); + throw new BusinessException(ApiExceptionEnum.API_NOT_EXIST); + } + + // 处理业务参数 + // 忽略JSON字符串中存在,而在Java中不存在的属性 + JSON_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + Object result = JSON_MAPPER.readValue(StringUtils.isBlank(reqBO.getContent()) ? "{}" : reqBO.getContent(), Class.forName(apiModel.getParamName())); + + //校验业务参数 + ValidateUtils.validate(result); + + //执行对应方法 + try { + Object obj = apiModel.getMethod().invoke(bean, reqBO.getSysCode(), result); + return ResultModel.success(obj); + } catch (Exception e) { + if (e instanceof InvocationTargetException) { + throw ((InvocationTargetException) e).getTargetException(); + } + log.info("[ invoke ] 异常 ", e); + throw new BusinessException(ApiExceptionEnum.SYSTEM_ERROR); + } + } + + /** + * 校验MD5签名 + * + * @param paramMap + * @param publicKey + */ + private void checkMd5Sign(Map paramMap, String publicKey) { + //生成Md5签名 + String sign = SsoSignUtil.getMd5Sign(paramMap, Arrays.asList("signType", "sign"), publicKey); + //入参中的签名 + String requestSign = (String) paramMap.get("sign"); + if (!sign.equals(requestSign)) { + log.info("[ MD5验签失败 ] >> sign:{}, requestSign:{} , params = {}", sign, requestSign, paramMap); + throw new BusinessException(ApiExceptionEnum.INVALID_SIGN); + } + } + + /** + * 校验RSA 签名 + * + * @param paramMap + * @param publicKey + */ + private void checkRsaSign(Map paramMap, String publicKey) { + try { + String sign = (String) paramMap.get("sign"); + //拼接生成签名的参数 + String signContent = SignContentUtil.getSignContent(paramMap, Arrays.asList("sign", "signType")); + log.info("[ RSA 验签内容 ] >> signContent:{},sign:{}", signContent, sign); + boolean verify = RSASignUtils.verify(signContent.getBytes(StandardCharsets.UTF_8), publicKey, sign); + if (!verify) { + log.info("[ RSA 验签失败 ] >> signContent:{},sign:{}", signContent, sign); + throw new BusinessException(ApiExceptionEnum.INVALID_SIGN); + } + } catch (Exception e) { + log.error("[ RSA 验签异常 ] >> paramMap = {}, error = {}", paramMap, ExceptionUtils.getStackTrace(e)); + throw new BusinessException(ApiExceptionEnum.INVALID_SIGN); + } + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/getway/ApplyAuthService.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/getway/ApplyAuthService.java new file mode 100644 index 0000000..794da31 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/getway/ApplyAuthService.java @@ -0,0 +1,25 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.getway; + +import com.sso.common.annotation.OpenApi; +import com.sso.model.bo.getway.ApplyAuthBO; +import com.sso.model.vo.getway.ApplyAuthVO; + +/** + * 申请认证开放接口 + * + * @author 程序员小强 + */ +public interface ApplyAuthService { + + /** + * 申请认证开放接口 + * + * @param authBO + */ + @OpenApi(method = "com.sso.applyAuth", desc = "申请认证") + ApplyAuthVO applyAuth(String sysCode, ApplyAuthBO authBO); +} diff --git a/sso-auth-center-service/sso-business/src/main/java/com/sso/service/getway/impl/ApplyAuthServiceImpl.java b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/getway/impl/ApplyAuthServiceImpl.java new file mode 100644 index 0000000..287d41a --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/java/com/sso/service/getway/impl/ApplyAuthServiceImpl.java @@ -0,0 +1,188 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.service.getway.impl; + +import com.sso.common.annotation.OpenApiService; +import com.sso.common.constant.CacheConstants; +import com.sso.common.constant.SsoConstants; +import com.sso.common.enums.MenuTypeEnum; +import com.sso.common.exception.BusinessException; +import com.sso.common.model.login.LoginResultVO; +import com.sso.common.model.login.LoginUserVO; +import com.sso.common.utils.StringUtils; +import com.sso.common.utils.bean.BeanCopierUtil; +import com.sso.common.utils.tree.ListToTreeUtil; +import com.sso.dao.entity.SsoMenu; +import com.sso.dao.entity.SsoSystem; +import com.sso.dao.mapper.SsoMenuMapper; +import com.sso.dao.mapper.SsoOnlineUserMapper; +import com.sso.dao.mapper.SsoRoleMapper; +import com.sso.framework.config.property.SysConfigProperty; +import com.sso.framework.redis.RedisCache; +import com.sso.model.bo.getway.ApplyAuthBO; +import com.sso.model.vo.getway.ApplyAuthVO; +import com.sso.model.vo.getway.MenuTreeAuthVO; +import com.sso.model.vo.getway.SysLoginCacheVO; +import com.sso.service.base.SystemCacheService; +import com.sso.service.getway.ApplyAuthService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.math.NumberUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; + +import javax.annotation.Resource; +import java.util.*; +import java.util.concurrent.TimeUnit; + +/** + * 申请认证开放接口 + * + * @author 程序员小强 + */ +@Slf4j +@Service +@OpenApiService +public class ApplyAuthServiceImpl implements ApplyAuthService { + + @Autowired + private RedisCache redisCache; + @Resource + private SsoMenuMapper ssoMenuMapper; + @Resource + private SsoRoleMapper ssoRoleMapper; + @Resource + private SsoOnlineUserMapper ssoOnlineUserMapper; + @Autowired + private SystemCacheService systemCacheService; + @Autowired + private SysConfigProperty sysConfigProperty; + + private static final Integer MENU_TYPE_TREE = 2; + + /** + * 申请认证开放接口 + * + * @param authBO + */ + @Override + public ApplyAuthVO applyAuth(String sysCode, ApplyAuthBO authBO) { + //根据sysCode查询目标系统跳转地址 + SsoSystem system = systemCacheService.getBySysCode(sysCode); + if (system == null) { + throw new BusinessException("系统不存在"); + } + + //入参token为空,说明未登录,返回扫码授权url + if (StringUtils.isEmpty(authBO.getSsoToken())) { + log.info("[ 认证失败 ] >> token 为空 ,返回认证中心登录地址 "); + return ApplyAuthVO.authFailNeedLogin(sysConfigProperty.getSsoLoginUrl()); + } + + //toke缓存key + String tokenCacheKey = CacheConstants.getLoginUserTokenKey(authBO.getSsoToken()); + LoginResultVO loginUserInfo = redisCache.hGet(tokenCacheKey, authBO.getSsoToken(), LoginResultVO.class); + //根据token获取redis缓存数据,取不到,说明token已经过期 + if (loginUserInfo == null || ObjectUtils.isEmpty(loginUserInfo.getUser())) { + log.info("[ 认证失败 ] >> token 已失效或不存在 ,返回认证中心登录地址 "); + String targetRedirectUrl = StringUtils.isNoneBlank(authBO.getRedirectUrl()) ? authBO.getRedirectUrl() : system.getSysUrl(); + return ApplyAuthVO.authFailNeedLogin(sysConfigProperty.getSsoLoginUrl(), targetRedirectUrl); + } + + //构建返回信息 + ApplyAuthVO result = this.buildApplyUserAuth(system, loginUserInfo); + //角色key标识集 + result.setRoleKeyList(ssoRoleMapper.getRoleKeyBySysCodeAndUserId(sysCode, result.getUserId())); + + //构建菜单与权限信息 + this.buildMenuAndPermission(sysCode, result, authBO, result.getUserId()); + + //token有效-认证后 刷新token有效时间 + String userIdCacheKey = CacheConstants.getLoginUserIdKey(result.getUserId()); + loginUserInfo.setExpireTime(System.currentTimeMillis() + sysConfigProperty.getTokenExpireTime() * 1000); + //记录用户-注册的子系统 + redisCache.hSet(tokenCacheKey, sysCode, new SysLoginCacheVO(sysCode, authBO.getLoginOutUrl(), System.currentTimeMillis())); + //刷新用户缓存有效期 + redisCache.set(userIdCacheKey, loginUserInfo, sysConfigProperty.getTokenExpireTime(), TimeUnit.MINUTES); + //刷新token有效期 + redisCache.hSet(tokenCacheKey, loginUserInfo.getToken(), loginUserInfo, sysConfigProperty.getTokenExpireTime(), TimeUnit.MINUTES); + + //刷新登录记录表效期 + if (StringUtils.isNotBlank(loginUserInfo.getRequestId())) { + ssoOnlineUserMapper.refreshExpireTimeByRequestId(loginUserInfo.getRequestId(), loginUserInfo.getExpireTime()); + } + + log.info("[ 认证成功 ] >> sysCode:{} , ssoToken:{} ", sysCode, authBO.getSsoToken()); + return result; + } + + /** + * 构建菜单与权限返回信息 + * + * @param result + * @param authBO + * @param userId + */ + private void buildMenuAndPermission(String sysCode, ApplyAuthVO result, ApplyAuthBO authBO, Long userId) { + //根据用户查询拥有的菜单权限 + List menuList = ssoMenuMapper.getMenuListBySysCodeAndUserId(sysCode, userId); + if (CollectionUtils.isEmpty(menuList)) { + result.setMenuList(new ArrayList<>(0)); + result.setPermissionList(new HashSet<>(0)); + return; + } + + MenuTreeAuthVO menuVO = null; + List menuResList = new ArrayList<>(menuList.size()); + //权限标识集 + Set permissionList = new HashSet<>(menuList.size()); + for (SsoMenu menu : menuList) { + if (StringUtils.isNotBlank(menu.getPermissions())) { + permissionList.addAll(Arrays.asList(menu.getPermissions().split(SsoConstants.SPLIT_ESCAPE))); + } + //菜单 + if (MenuTypeEnum.isMenu(menu.getMenuType())) { + menuVO = BeanCopierUtil.copy(menu, MenuTreeAuthVO.class); + menuResList.add(menuVO); + } + } + + result.setMenuList(menuResList); + result.setPermissionList(permissionList); + + //非树结构返回 + if (!MENU_TYPE_TREE.equals(NumberUtils.toInt(authBO.getMenuType(), 0))) { + return; + } + + //树结构返回 >> 转换成树返回 + ListToTreeUtil treeUtil = new ListToTreeUtil<>(); + result.setMenuList(treeUtil.getTreeListObject(result.getMenuList())); + } + + /** + * 构建用户基本认证信息 + * + * @param loginUserInfo + */ + private ApplyAuthVO buildApplyUserAuth(SsoSystem system, LoginResultVO loginUserInfo) { + LoginUserVO user = loginUserInfo.getUser(); + ApplyAuthVO result = new ApplyAuthVO(); + result.setSysCode(system.getSysCode()); + result.setSysName(system.getSysName()); + result.setAuthResult(true); + result.setUserId(user.getUserId()); + result.setUsername(user.getUsername()); + result.setNickName(user.getNickName()); + result.setRealName(user.getRealName()); + result.setAvatar(user.getAvatar()); + result.setSex(user.getSex()); + result.setPhone(user.getPhone()); + result.setEmail(user.getEmail()); + return result; + } + +} diff --git a/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoDeptMapper.xml b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoDeptMapper.xml new file mode 100644 index 0000000..a65b291 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoDeptMapper.xml @@ -0,0 +1,319 @@ + + + + + + + + + + + + + + + + + + + + + dept_id, + dept_name, + sys_code, + dept_parent_id, + sort_num, + status, + del_flag, + remarks, + create_by, + update_by, + create_time, + update_time + + + + a.dept_id, + a.dept_name, + a.sys_code, + a.dept_parent_id, + a.sort_num, + a.status, + a.del_flag, + a.remarks, + a.create_by, + a.update_by, + a.create_time, + a.update_time + + + + + + + + INSERT INTO sso_dept + ( + dept_id, + dept_name, + sys_code, + dept_parent_id, + sort_num, + status, + del_flag, + remarks, + create_by, + update_by, + create_time, + update_time + ) + values + ( + #{deptId,jdbcType=BIGINT}, + #{deptName,jdbcType=VARCHAR}, + #{sysCode,jdbcType=VARCHAR}, + #{deptParentId,jdbcType=BIGINT}, + #{sortNum,jdbcType=INTEGER}, + #{status,jdbcType=INTEGER}, + #{delFlag,jdbcType=INTEGER}, + #{remarks,jdbcType=VARCHAR}, + #{createBy,jdbcType=VARCHAR}, + #{updateBy,jdbcType=VARCHAR}, + #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP} + ) + + + + INSERT INTO sso_dept + + + dept_id, + + + dept_name, + + + sys_code, + + + dept_parent_id, + + + sort_num, + + + status, + + + del_flag, + + + remarks, + + + create_by, + + + update_by, + + + create_time, + + + update_time, + + + + + #{deptId,jdbcType=BIGINT}, + + + #{deptName,jdbcType=VARCHAR}, + + + #{sysCode,jdbcType=VARCHAR}, + + + #{deptParentId,jdbcType=BIGINT}, + + + #{sortNum,jdbcType=INTEGER}, + + + #{status,jdbcType=INTEGER}, + + + #{delFlag,jdbcType=INTEGER}, + + + #{remarks,jdbcType=VARCHAR}, + + + #{createBy,jdbcType=VARCHAR}, + + + #{updateBy,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + + + + + UPDATE sso_dept + SET + dept_name = #{deptName,jdbcType=VARCHAR}, + dept_parent_id = #{deptParentId,jdbcType=BIGINT}, + sort_num = #{sortNum,jdbcType=INTEGER}, + status = #{status,jdbcType=INTEGER}, + remarks = #{remarks,jdbcType=VARCHAR}, + update_by = #{updateBy,jdbcType=VARCHAR} + WHERE dept_id = #{deptId,jdbcType=BIGINT} + + + + + UPDATE sso_dept a + INNER JOIN sso_dept_tree_path t ON a.dept_id = t.ancestor AND a.dept_id != #{deptId,jdbcType=BIGINT} + SET + status = #{status,jdbcType=INTEGER}, + update_by = #{updateBy,jdbcType=VARCHAR} + WHERE t.descendant = #{deptId,jdbcType=BIGINT} + + + + UPDATE sso_dept + + + dept_name = #{deptName,jdbcType=VARCHAR}, + + + sys_code = #{sysCode,jdbcType=VARCHAR}, + + + dept_parent_id = #{deptParentId,jdbcType=BIGINT}, + + + sort_num = #{sortNum,jdbcType=INTEGER}, + + + status = #{status,jdbcType=INTEGER}, + + + del_flag = #{delFlag,jdbcType=INTEGER}, + + + remarks = #{remarks,jdbcType=VARCHAR}, + + + create_by = #{createBy,jdbcType=VARCHAR}, + + + update_by = #{updateBy,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + WHERE dept_id = #{deptId,jdbcType=BIGINT} + + + + + + + + + + + diff --git a/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoDeptTreePathMapper.xml b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoDeptTreePathMapper.xml new file mode 100644 index 0000000..6ebf400 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoDeptTreePathMapper.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + ancestor, + descendant + + + + + INSERT INTO sso_dept_tree_path (ancestor,descendant) + SELECT t.ancestor,#{deptId,jdbcType=BIGINT} FROM sso_dept_tree_path AS t + WHERE t.descendant = #{deptParentId,jdbcType=BIGINT} + UNION ALL + SELECT #{deptId,jdbcType=BIGINT},#{deptId,jdbcType=BIGINT} + + + + + DELETE FROM + sso_dept_tree_path WHERE descendant = #{deptId,jdbcType=BIGINT} + + + + + DELETE FROM + sso_dept_tree_path + WHERE descendant + IN (SELECT a.dept_id from (SELECT descendant dept_id FROM sso_dept_tree_path WHERE ancestor = + #{deptId,jdbcType=BIGINT}) a ) + + + + + + + + + diff --git a/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoLoginLogMapper.xml b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoLoginLogMapper.xml new file mode 100644 index 0000000..a9a5663 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoLoginLogMapper.xml @@ -0,0 +1,259 @@ + + + + + + + + + + + + + + + + + + + + + id, + request_id, + username, + source_ip, + source_address, + browser_name, + operate_system, + status, + login_time, + operate_msg, + create_time, + update_time + + + + + + + + + + INSERT INTO sso_login_log + ( + id, + request_id, + username, + source_ip, + source_address, + browser_name, + operate_system, + status, + login_time, + operate_msg, + create_time, + update_time + ) + values + ( + #{id,jdbcType=BIGINT}, + #{requestId,jdbcType=VARCHAR}, + #{username,jdbcType=VARCHAR}, + #{sourceIp,jdbcType=VARCHAR}, + #{sourceAddress,jdbcType=VARCHAR}, + #{browserName,jdbcType=VARCHAR}, + #{operateSystem,jdbcType=VARCHAR}, + #{status,jdbcType=INTEGER}, + #{loginTime,jdbcType=BIGINT}, + #{operateMsg,jdbcType=VARCHAR}, + #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP} + ) + + + + INSERT INTO sso_login_log + + + id, + + + request_id, + + + username, + + + source_ip, + + + source_address, + + + browser_name, + + + operate_system, + + + status, + + + login_time, + + + operate_msg, + + + create_time, + + + update_time, + + + + + #{id,jdbcType=BIGINT}, + + + #{requestId,jdbcType=VARCHAR}, + + + #{username,jdbcType=VARCHAR}, + + + #{sourceIp,jdbcType=VARCHAR}, + + + #{sourceAddress,jdbcType=VARCHAR}, + + + #{browserName,jdbcType=VARCHAR}, + + + #{operateSystem,jdbcType=VARCHAR}, + + + #{status,jdbcType=INTEGER}, + + + #{loginTime,jdbcType=BIGINT}, + + + #{operateMsg,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + + + + DELETE FROM sso_login_log + WHERE id = #{id,jdbcType=BIGINT} + + + + UPDATE sso_login_log + SET + request_id = #{requestId,jdbcType=VARCHAR}, + username = #{username,jdbcType=VARCHAR}, + source_ip = #{sourceIp,jdbcType=VARCHAR}, + source_address = #{sourceAddress,jdbcType=VARCHAR}, + browser_name = #{browserName,jdbcType=VARCHAR}, + operate_system = #{operateSystem,jdbcType=VARCHAR}, + status = #{status,jdbcType=INTEGER}, + login_time = #{loginTime,jdbcType=BIGINT}, + operate_msg = #{operateMsg,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP} + WHERE id = #{id,jdbcType=BIGINT} + + + + UPDATE sso_login_log + + + request_id = #{requestId,jdbcType=VARCHAR}, + + + username = #{username,jdbcType=VARCHAR}, + + + source_ip = #{sourceIp,jdbcType=VARCHAR}, + + + source_address = #{sourceAddress,jdbcType=VARCHAR}, + + + browser_name = #{browserName,jdbcType=VARCHAR}, + + + operate_system = #{operateSystem,jdbcType=VARCHAR}, + + + status = #{status,jdbcType=INTEGER}, + + + login_time = #{loginTime,jdbcType=BIGINT}, + + + operate_msg = #{operateMsg,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + WHERE id = #{id,jdbcType=BIGINT} + + diff --git a/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoMenuMapper.xml b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoMenuMapper.xml new file mode 100644 index 0000000..4d53909 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoMenuMapper.xml @@ -0,0 +1,418 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + menu_id, + menu_name, + sys_code, + menu_type, + menu_parent_id, + sort_num, + path, + icon, + component, + permissions, + use_type, + visible, + status, + del_flag, + remarks, + create_by, + update_by, + create_time, + update_time + + + + a.menu_id, + a.menu_name, + a.sys_code, + a.menu_type, + a.menu_parent_id, + a.sort_num, + a.path, + a.icon, + a.component, + a.permissions, + a.use_type, + a.visible, + a.status, + a.del_flag, + a.remarks, + a.create_by, + a.update_by, + a.create_time, + a.update_time + + + + + + + + + + + + + + + + INSERT INTO sso_menu + ( + menu_id, + menu_name, + sys_code, + menu_type, + menu_parent_id, + sort_num, + path, + icon, + component, + permissions, + use_type, + visible, + status, + del_flag, + remarks, + create_by, + update_by + ) + values + ( + #{menuId,jdbcType=BIGINT}, + #{menuName,jdbcType=VARCHAR}, + #{sysCode,jdbcType=VARCHAR}, + #{menuType,jdbcType=VARCHAR}, + #{menuParentId,jdbcType=BIGINT}, + #{sortNum,jdbcType=INTEGER}, + #{path,jdbcType=VARCHAR}, + #{icon,jdbcType=VARCHAR}, + #{component,jdbcType=VARCHAR}, + #{permissions,jdbcType=VARCHAR}, + #{useType,jdbcType=INTEGER}, + #{visible,jdbcType=INTEGER}, + #{status,jdbcType=INTEGER}, + #{delFlag,jdbcType=INTEGER}, + #{remarks,jdbcType=VARCHAR}, + #{createBy,jdbcType=VARCHAR}, + #{updateBy,jdbcType=VARCHAR} + ) + + + + INSERT INTO sso_menu + + + menu_name, + + + sys_code, + + + menu_type, + + + menu_parent_id, + + + sort_num, + + + path, + + + icon, + + + component, + + + permissions, + + + use_type, + + + visible, + + + status, + + + del_flag, + + + remarks, + + + create_by, + + + update_by, + + + create_time, + + + update_time, + + + + + #{menuName,jdbcType=VARCHAR}, + + + #{sysCode,jdbcType=VARCHAR}, + + + #{menuType,jdbcType=VARCHAR}, + + + #{menuParentId,jdbcType=BIGINT}, + + + #{sortNum,jdbcType=INTEGER}, + + + #{path,jdbcType=VARCHAR}, + + + #{icon,jdbcType=VARCHAR}, + + + #{component,jdbcType=VARCHAR}, + + + #{permissions,jdbcType=VARCHAR}, + + + #{useType,jdbcType=INTEGER}, + + + #{visible,jdbcType=INTEGER}, + + + #{status,jdbcType=INTEGER}, + + + #{delFlag,jdbcType=INTEGER}, + + + #{remarks,jdbcType=VARCHAR}, + + + #{createBy,jdbcType=VARCHAR}, + + + #{updateBy,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + + + + UPDATE sso_menu + SET + menu_name = #{menuName,jdbcType=VARCHAR}, + menu_type = #{menuType,jdbcType=VARCHAR}, + menu_parent_id = #{menuParentId,jdbcType=BIGINT}, + sort_num = #{sortNum,jdbcType=INTEGER}, + path = #{path,jdbcType=VARCHAR}, + icon = #{icon,jdbcType=VARCHAR}, + component = #{component,jdbcType=VARCHAR}, + permissions = #{permissions,jdbcType=VARCHAR}, + use_type = #{useType,jdbcType=INTEGER}, + visible = #{visible,jdbcType=INTEGER}, + status = #{status,jdbcType=INTEGER}, + remarks = #{remarks,jdbcType=VARCHAR}, + update_by = #{updateBy,jdbcType=VARCHAR} + WHERE menu_id = #{menuId,jdbcType=BIGINT} + + + + UPDATE sso_menu + + + menu_name = #{menuName,jdbcType=VARCHAR}, + + + sys_code = #{sysCode,jdbcType=VARCHAR}, + + + menu_type = #{menuType,jdbcType=VARCHAR}, + + + menu_parent_id = #{menuParentId,jdbcType=BIGINT}, + + + sort_num = #{sortNum,jdbcType=INTEGER}, + + + path = #{path,jdbcType=VARCHAR}, + + + icon = #{icon,jdbcType=VARCHAR}, + + + component = #{component,jdbcType=VARCHAR}, + + + permissions = #{permissions,jdbcType=VARCHAR}, + + + use_type = #{userType,jdbcType=INTEGER}, + + + visible = #{visible,jdbcType=INTEGER}, + + + status = #{status,jdbcType=INTEGER}, + + + del_flag = #{delFlag,jdbcType=INTEGER}, + + + remarks = #{remarks,jdbcType=VARCHAR}, + + + update_by = #{updateBy,jdbcType=VARCHAR}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + WHERE menu_id = #{menuId,jdbcType=BIGINT} + + + + + diff --git a/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoOnlineUserMapper.xml b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoOnlineUserMapper.xml new file mode 100644 index 0000000..7f0623f --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoOnlineUserMapper.xml @@ -0,0 +1,312 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id, + request_id, + user_id, + source_ip, + source_address, + browser_name, + operate_system, + login_time, + login_out_time, + expire_time, + create_time, + update_time + + + + + + INSERT INTO sso_online_user + ( + id, + request_id, + user_id, + source_ip, + source_address, + browser_name, + operate_system, + login_time, + login_out_time, + expire_time, + create_time, + update_time + ) + values + ( + #{id,jdbcType=BIGINT}, + #{requestId,jdbcType=VARCHAR}, + #{userId,jdbcType=BIGINT}, + #{sourceIp,jdbcType=VARCHAR}, + #{sourceAddress,jdbcType=VARCHAR}, + #{browserName,jdbcType=VARCHAR}, + #{operateSystem,jdbcType=VARCHAR}, + #{loginTime,jdbcType=BIGINT}, + #{loginOutTime,jdbcType=BIGINT}, + #{expireTime,jdbcType=BIGINT}, + #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP} + ) + + + + INSERT INTO sso_online_user + + + id, + + + request_id, + + + user_id, + + + source_ip, + + + source_address, + + + browser_name, + + + operate_system, + + + login_time, + + + login_out_time, + + + expire_time, + + + create_time, + + + update_time, + + + + + #{id,jdbcType=BIGINT}, + + + #{requestId,jdbcType=VARCHAR}, + + + #{userId,jdbcType=BIGINT}, + + + #{sourceIp,jdbcType=VARCHAR}, + + + #{sourceAddress,jdbcType=VARCHAR}, + + + #{browserName,jdbcType=VARCHAR}, + + + #{operateSystem,jdbcType=VARCHAR}, + + + #{loginTime,jdbcType=BIGINT}, + + + #{loginOutTime,jdbcType=BIGINT}, + + + #{expireTime,jdbcType=BIGINT}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + + + + DELETE FROM sso_online_user + WHERE id = #{id,jdbcType=BIGINT} + + + + UPDATE sso_online_user + SET + request_id = #{requestId,jdbcType=VARCHAR}, + user_id = #{userId,jdbcType=BIGINT}, + source_ip = #{sourceIp,jdbcType=VARCHAR}, + source_address = #{sourceAddress,jdbcType=VARCHAR}, + browser_name = #{browserName,jdbcType=VARCHAR}, + operate_system = #{operateSystem,jdbcType=VARCHAR}, + login_time = #{loginTime,jdbcType=BIGINT}, + login_out_time = #{loginOutTime,jdbcType=BIGINT}, + expire_time = #{expireTime,jdbcType=BIGINT}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP} + WHERE id = #{id,jdbcType=BIGINT} + + + + UPDATE sso_online_user + + + request_id = #{requestId,jdbcType=VARCHAR}, + + + user_id = #{userId,jdbcType=BIGINT}, + + + source_ip = #{sourceIp,jdbcType=VARCHAR}, + + + source_address = #{sourceAddress,jdbcType=VARCHAR}, + + + browser_name = #{browserName,jdbcType=VARCHAR}, + + + operate_system = #{operateSystem,jdbcType=VARCHAR}, + + + login_time = #{loginTime,jdbcType=BIGINT}, + + + login_out_time = #{loginOutTime,jdbcType=BIGINT}, + + + expire_time = #{expireTime,jdbcType=BIGINT}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + WHERE id = #{id,jdbcType=BIGINT} + + + + + + + + UPDATE sso_online_user + SET + expire_time = #{expireTime,jdbcType=BIGINT} + WHERE request_id = #{requestId,jdbcType=VARCHAR} + + + + UPDATE sso_online_user + SET + expire_time = #{expireTime,jdbcType=BIGINT}, + login_out_time = #{loginOutTime,jdbcType=BIGINT} + WHERE request_id = #{requestId,jdbcType=VARCHAR} + + + diff --git a/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoRoleMapper.xml b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoRoleMapper.xml new file mode 100644 index 0000000..9eea846 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoRoleMapper.xml @@ -0,0 +1,297 @@ + + + + + + + + + + + + + + + + + + + + + role_id, + sys_code, + role_name, + role_key, + status, + sort_num, + del_flag, + remarks, + create_by, + update_by, + create_time, + update_time + + + + + + + + + + + + + + + + + INSERT INTO sso_role + ( + role_id, + sys_code, + role_name, + role_key, + status, + sort_num, + del_flag, + remarks, + create_by, + update_by + ) + values + ( + #{roleId,jdbcType=BIGINT}, + #{sysCode,jdbcType=VARCHAR}, + #{roleName,jdbcType=VARCHAR}, + #{roleKey,jdbcType=VARCHAR}, + #{status,jdbcType=INTEGER}, + #{sortNum,jdbcType=INTEGER}, + #{delFlag,jdbcType=INTEGER}, + #{remarks,jdbcType=VARCHAR}, + #{createBy,jdbcType=VARCHAR}, + #{updateBy,jdbcType=VARCHAR} + ) + + + + INSERT INTO sso_role + + + role_id, + + + sys_code, + + + role_name, + + + role_key, + + + status, + + + sort_num, + + + del_flag, + + + remarks, + + + create_by, + + + update_by, + + + create_time, + + + update_time, + + + + + #{roleId,jdbcType=BIGINT}, + + + #{sysCode,jdbcType=VARCHAR}, + + + #{roleName,jdbcType=VARCHAR}, + + + #{roleKey,jdbcType=VARCHAR}, + + + #{status,jdbcType=INTEGER}, + + + #{sortNum,jdbcType=INTEGER}, + + + #{delFlag,jdbcType=INTEGER}, + + + #{remarks,jdbcType=VARCHAR}, + + + #{createBy,jdbcType=VARCHAR}, + + + #{updateBy,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + + + + UPDATE sso_role + SET + role_name = #{roleName,jdbcType=VARCHAR}, + role_key = #{roleKey,jdbcType=VARCHAR}, + status = #{status,jdbcType=INTEGER}, + sort_num = #{sortNum,jdbcType=INTEGER}, + remarks = #{remarks,jdbcType=VARCHAR}, + update_by = #{updateBy,jdbcType=VARCHAR} + WHERE role_id = #{roleId,jdbcType=BIGINT} + + + + UPDATE sso_role + + + sys_code = #{sysCode,jdbcType=VARCHAR}, + + + role_name = #{roleName,jdbcType=VARCHAR}, + + + role_key = #{roleKey,jdbcType=VARCHAR}, + + + status = #{status,jdbcType=INTEGER}, + + + sort_num = #{sortNum,jdbcType=INTEGER}, + + + del_flag = #{delFlag,jdbcType=INTEGER}, + + + remarks = #{remarks,jdbcType=VARCHAR}, + + + create_by = #{createBy,jdbcType=VARCHAR}, + + + update_by = #{updateBy,jdbcType=VARCHAR}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + WHERE role_id = #{roleId,jdbcType=BIGINT} + + + + + + diff --git a/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoRoleMenuMapper.xml b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoRoleMenuMapper.xml new file mode 100644 index 0000000..84c19c3 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoRoleMenuMapper.xml @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + sys_code, + role_id, + menu_id, + create_time, + update_time + + + + + + + INSERT INTO sso_role_menu + ( + sys_code, + role_id, + menu_id + ) + VALUES + + ( + #{item.sysCode,jdbcType=VARCHAR}, + #{item.roleId,jdbcType=BIGINT}, + #{item.menuId,jdbcType=BIGINT} + ) + + + + + INSERT INTO sso_role_menu + ( + sys_code, + role_id, + menu_id + ) + values + ( + #{sysCode,jdbcType=VARCHAR}, + #{roleId,jdbcType=BIGINT}, + #{menuId,jdbcType=BIGINT} + ) + + + + INSERT INTO sso_role_menu + + + sys_code, + + + role_id, + + + menu_id, + + + + + #{sysCode,jdbcType=VARCHAR}, + + + #{roleId,jdbcType=BIGINT}, + + + #{menuId,jdbcType=BIGINT}, + + + + + + DELETE FROM sso_role_menu + WHERE role_id = #{roleId,jdbcType=BIGINT} + + + + DELETE FROM sso_role_menu + WHERE menu_id = #{menuId,jdbcType=BIGINT} + + + + UPDATE sso_role_menu + SET + sys_code = #{sysCode,jdbcType=VARCHAR}, + role_id = #{roleId,jdbcType=BIGINT}, + menu_id = #{menuId,jdbcType=BIGINT} + WHERE id = #{id,jdbcType=BIGINT} + + + + UPDATE sso_role_menu + + + sys_code = #{sysCode,jdbcType=VARCHAR}, + + + role_id = #{roleId,jdbcType=BIGINT}, + + + menu_id = #{menuId,jdbcType=BIGINT}, + + + WHERE id = #{id,jdbcType=BIGINT} + + + diff --git a/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoSystemManagerMapper.xml b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoSystemManagerMapper.xml new file mode 100644 index 0000000..1403a2e --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoSystemManagerMapper.xml @@ -0,0 +1,276 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id, + user_id, + sys_code, + status, + del_flag, + create_by, + update_by, + create_time, + update_time + + + + + + + + + + + + + + INSERT INTO sso_system_manager + ( + id, + user_id, + sys_code, + status, + del_flag, + create_by, + update_by, + create_time, + update_time + ) + values + ( + #{id,jdbcType=BIGINT}, + #{userId,jdbcType=BIGINT}, + #{sysCode,jdbcType=VARCHAR}, + #{status,jdbcType=INTEGER}, + #{delFlag,jdbcType=INTEGER}, + #{createBy,jdbcType=VARCHAR}, + #{updateBy,jdbcType=VARCHAR}, + #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP} + ) + + + + INSERT INTO sso_system_manager + + + id, + + + user_id, + + + sys_code, + + + status, + + + del_flag, + + + create_by, + + + update_by, + + + create_time, + + + update_time, + + + + + #{id,jdbcType=BIGINT}, + + + #{userId,jdbcType=BIGINT}, + + + #{sysCode,jdbcType=VARCHAR}, + + + #{status,jdbcType=INTEGER}, + + + #{delFlag,jdbcType=INTEGER}, + + + #{createBy,jdbcType=VARCHAR}, + + + #{updateBy,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + + + + UPDATE sso_system_manager + + + status = #{status,jdbcType=INTEGER}, + + + del_flag = #{delFlag,jdbcType=INTEGER}, + + + update_by = #{updateBy,jdbcType=VARCHAR}, + + + WHERE id = #{id,jdbcType=BIGINT} + + + + UPDATE sso_system_manager + + + status = #{status,jdbcType=INTEGER}, + + + del_flag = #{delFlag,jdbcType=INTEGER}, + + + update_by = #{updateBy,jdbcType=VARCHAR}, + + + WHERE del_flag = 0 + AND user_id = #{userId,jdbcType=BIGINT} + AND sys_code = #{sysCode,jdbcType=VARCHAR} + + + diff --git a/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoSystemMapper.xml b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoSystemMapper.xml new file mode 100644 index 0000000..1b13068 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoSystemMapper.xml @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + sys_id, + sys_code, + sys_name, + sys_grant_code, + sys_url, + sys_icon, + sys_env, + sort_num, + remarks, + sign_type, + public_key, + status, + del_flag, + create_by, + update_by, + create_time, + update_time + + + a.sys_id, + a.sys_code, + a.sys_name, + a.sys_grant_code, + a.sys_url, + a.sys_icon, + a.sys_env, + a.sort_num, + a.remarks, + a.sign_type, + a.public_key, + a.status, + a.del_flag, + a.create_by, + a.update_by, + a.create_time, + a.update_time + + + + + + + + + + + + + + + + + + INSERT INTO sso_system + ( + sys_id, + sys_code, + sys_name, + sys_grant_code, + sys_url, + sys_icon, + sys_env, + sort_num, + remarks, + sign_type, + public_key, + status, + del_flag, + create_by, + update_by + ) + values + ( + #{sysId,jdbcType=BIGINT}, + #{sysCode,jdbcType=VARCHAR}, + #{sysName,jdbcType=VARCHAR}, + #{sysGrantCode,jdbcType=VARCHAR}, + #{sysUrl,jdbcType=VARCHAR}, + #{sysIcon,jdbcType=VARCHAR}, + #{sysEnv,jdbcType=INTEGER}, + #{sortNum,jdbcType=INTEGER}, + #{remarks,jdbcType=VARCHAR}, + #{signType,jdbcType=INTEGER}, + #{publicKey,jdbcType=VARCHAR}, + #{status,jdbcType=INTEGER}, + #{delFlag,jdbcType=INTEGER}, + #{createBy,jdbcType=VARCHAR}, + #{updateBy,jdbcType=VARCHAR} + ) + + + + INSERT INTO sso_system + + + sys_id, + + + sys_code, + + + sys_name, + + + sys_grant_code, + + + sys_url, + + + sys_icon, + + + sys_env, + + + sort_num, + + + remarks, + + + sign_type, + + + public_key, + + + status, + + + del_flag, + + + create_by, + + + update_by, + + + + + #{sysId,jdbcType=BIGINT}, + + + #{sysCode,jdbcType=VARCHAR}, + + + #{sysName,jdbcType=VARCHAR}, + + + #{sysGrantCode,jdbcType=VARCHAR}, + + + #{sysUrl,jdbcType=VARCHAR}, + + + #{sysIcon,jdbcType=VARCHAR}, + + + #{sysEnv,jdbcType=INTEGER}, + + + #{sortNum,jdbcType=INTEGER}, + + + #{remarks,jdbcType=VARCHAR}, + + + #{signType,jdbcType=INTEGER}, + + + #{publicKey,jdbcType=VARCHAR}, + + + #{status,jdbcType=INTEGER}, + + + #{delFlag,jdbcType=INTEGER}, + + + #{createBy,jdbcType=VARCHAR}, + + + #{updateBy,jdbcType=VARCHAR}, + + + + + + UPDATE sso_system + SET + sys_code = #{sysCode,jdbcType=VARCHAR}, + sys_name = #{sysName,jdbcType=VARCHAR}, + sys_grant_code = #{sysGrantCode,jdbcType=VARCHAR}, + sys_url = #{sysUrl,jdbcType=VARCHAR}, + sys_icon = #{sysIcon,jdbcType=VARCHAR}, + sys_env = #{sysEnv,jdbcType=INTEGER}, + sort_num = #{sortNum,jdbcType=INTEGER}, + remarks = #{remarks,jdbcType=VARCHAR}, + status = #{status,jdbcType=INTEGER}, + update_by = #{updateBy,jdbcType=VARCHAR} + WHERE sys_id = #{sysId,jdbcType=BIGINT} + + + + UPDATE sso_system + SET + sign_type = #{signType,jdbcType=INTEGER}, + public_key = #{publicKey,jdbcType=VARCHAR}, + update_by = #{updateBy,jdbcType=VARCHAR} + WHERE sys_id = #{sysId,jdbcType=BIGINT} + + + + UPDATE sso_system + SET + sys_icon = #{sysIcon,jdbcType=VARCHAR}, + update_by = #{updateBy,jdbcType=VARCHAR} + WHERE sys_id = #{sysId,jdbcType=BIGINT} + + + + UPDATE sso_system + + + sys_code = #{sysCode,jdbcType=VARCHAR}, + + + sys_name = #{sysName,jdbcType=VARCHAR}, + + + sys_grant_code = #{sysGrantCode,jdbcType=VARCHAR}, + + + sys_url = #{sysUrl,jdbcType=VARCHAR}, + + + sys_icon = #{sysIcon,jdbcType=VARCHAR}, + + + sys_env = #{sysEnv,jdbcType=INTEGER}, + + + sort_num = #{sort,jdbcType=INTEGER}, + + + remarks = #{remarks,jdbcType=VARCHAR}, + + + sign_type = #{signType,jdbcType=INTEGER}, + + + public_key = #{publicKey,jdbcType=VARCHAR}, + + + status = #{status,jdbcType=INTEGER}, + + + del_flag = #{delFlag,jdbcType=INTEGER}, + + + update_by = #{updateBy,jdbcType=VARCHAR}, + + + WHERE sys_id = #{sysId,jdbcType=BIGINT} + + + diff --git a/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserDeptMapper.xml b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserDeptMapper.xml new file mode 100644 index 0000000..c01c120 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserDeptMapper.xml @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + sys_code, + user_id, + dept_id, + create_time, + update_time + + + + + + INSERT INTO sso_user_dept + ( + sys_code, + user_id, + dept_id + ) + values + ( + #{sysCode,jdbcType=VARCHAR}, + #{userId,jdbcType=BIGINT}, + #{deptId,jdbcType=BIGINT} + ) + + + + INSERT INTO sso_user_dept + + + sys_code, + + + user_id, + + + dept_id, + + + create_time, + + + update_time, + + + + + #{sysCode,jdbcType=VARCHAR}, + + + #{userId,jdbcType=BIGINT}, + + + #{deptId,jdbcType=BIGINT}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + + + + DELETE FROM sso_user_dept + WHERE sys_code = #{sysCode,jdbcType=VARCHAR} + AND user_id = #{userId,jdbcType=BIGINT} + + + + DELETE FROM sso_user_dept + WHERE sys_code = #{sysCode,jdbcType=VARCHAR} + AND dept_id = #{deptId,jdbcType=BIGINT} + + + + UPDATE sso_user_dept + SET + sys_code = #{sysCode,jdbcType=VARCHAR}, + user_id = #{userId,jdbcType=BIGINT}, + dept_id = #{deptId,jdbcType=BIGINT}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP} + WHERE id = #{id,jdbcType=BIGINT} + + + + UPDATE sso_user_dept + + + sys_code = #{sysCode,jdbcType=VARCHAR}, + + + user_id = #{userId,jdbcType=BIGINT}, + + + dept_id = #{deptId,jdbcType=BIGINT}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + WHERE id = #{id,jdbcType=BIGINT} + + + + + diff --git a/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserMapper.xml b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserMapper.xml new file mode 100644 index 0000000..dc9c0dd --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserMapper.xml @@ -0,0 +1,453 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + user_id, + username, + password, + nick_name, + real_name, + sex, + phone, + email, + avatar, + status, + login_ip, + last_login_time, + del_flag, + remarks, + create_by, + update_by, + create_time, + update_time + + + + a.user_id, + a.username, + a.password, + a.nick_name, + a.real_name, + a.sex, + a.phone, + a.email, + a.avatar, + a.status, + a.login_ip, + a.last_login_time, + a.del_flag, + a.remarks, + a.create_by, + a.update_by, + a.create_time, + a.update_time + + + + + + + + + + + + + + + + + + + + INSERT INTO sso_user + ( + user_id, + username, + password, + nick_name, + real_name, + sex, + phone, + email, + avatar, + status, + login_ip, + last_login_time, + del_flag, + remarks, + create_by, + update_by, + create_time, + update_time + ) + values + ( + #{userId,jdbcType=BIGINT}, + #{username,jdbcType=VARCHAR}, + #{password,jdbcType=VARCHAR}, + #{nickName,jdbcType=VARCHAR}, + #{realName,jdbcType=VARCHAR}, + #{sex,jdbcType=INTEGER}, + #{phone,jdbcType=VARCHAR}, + #{email,jdbcType=VARCHAR}, + #{avatar,jdbcType=VARCHAR}, + #{status,jdbcType=INTEGER}, + #{loginIp,jdbcType=VARCHAR}, + #{lastLoginTime,jdbcType=TIMESTAMP}, + #{delFlag,jdbcType=INTEGER}, + #{remarks,jdbcType=VARCHAR}, + #{createBy,jdbcType=VARCHAR}, + #{updateBy,jdbcType=VARCHAR}, + #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP} + ) + + + + INSERT INTO sso_user + + + user_id, + + + username, + + + password, + + + nick_name, + + + real_name, + + + sex, + + + phone, + + + email, + + + avatar, + + + status, + + + login_ip, + + + last_login_time, + + + del_flag, + + + remarks, + + + create_by, + + + update_by, + + + create_time, + + + update_time, + + + + + #{userId,jdbcType=BIGINT}, + + + #{username,jdbcType=VARCHAR}, + + + #{password,jdbcType=VARCHAR}, + + + #{nickName,jdbcType=VARCHAR}, + + + #{realName,jdbcType=VARCHAR}, + + + #{sex,jdbcType=INTEGER}, + + + #{phone,jdbcType=VARCHAR}, + + + #{email,jdbcType=VARCHAR}, + + + #{avatar,jdbcType=VARCHAR}, + + + #{status,jdbcType=INTEGER}, + + + #{loginIp,jdbcType=VARCHAR}, + + + #{lastLoginTime,jdbcType=TIMESTAMP}, + + + #{delFlag,jdbcType=INTEGER}, + + + #{remarks,jdbcType=VARCHAR}, + + + #{createBy,jdbcType=VARCHAR}, + + + #{updateBy,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + + + + UPDATE sso_user + SET + nick_name = #{nickName,jdbcType=VARCHAR}, + real_name = #{realName,jdbcType=VARCHAR}, + sex = #{sex,jdbcType=INTEGER}, + phone = #{phone,jdbcType=VARCHAR}, + email = #{email,jdbcType=VARCHAR}, + status = #{status,jdbcType=INTEGER}, + remarks = #{remarks,jdbcType=VARCHAR}, + update_by = #{updateBy,jdbcType=VARCHAR} + WHERE user_id = #{userId,jdbcType=BIGINT} + + + + UPDATE sso_user + SET + nick_name = #{nickName,jdbcType=VARCHAR}, + real_name = #{realName,jdbcType=VARCHAR}, + sex = #{sex,jdbcType=INTEGER}, + phone = #{phone,jdbcType=VARCHAR}, + email = #{email,jdbcType=VARCHAR}, + update_by = #{updateBy,jdbcType=VARCHAR} + WHERE user_id = #{userId,jdbcType=BIGINT} + + + + UPDATE sso_user + SET + login_ip = #{loginIp,jdbcType=VARCHAR}, + last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP} + WHERE user_id = #{userId,jdbcType=BIGINT} + + + + UPDATE sso_user + SET + password = #{password,jdbcType=VARCHAR}, + update_by = #{updateBy,jdbcType=VARCHAR} + WHERE user_id = #{userId,jdbcType=BIGINT} + + + + UPDATE sso_user + SET + avatar = #{avatar,jdbcType=VARCHAR} + WHERE user_id = #{userId,jdbcType=BIGINT} + + + + UPDATE sso_user + + + username = #{username,jdbcType=VARCHAR}, + + + password = #{password,jdbcType=VARCHAR}, + + + nick_name = #{nickName,jdbcType=VARCHAR}, + + + real_name = #{realName,jdbcType=VARCHAR}, + + + sex = #{sex,jdbcType=INTEGER}, + + + phone = #{phone,jdbcType=VARCHAR}, + + + email = #{email,jdbcType=VARCHAR}, + + + avatar = #{avatar,jdbcType=VARCHAR}, + + + status = #{status,jdbcType=INTEGER}, + + + login_ip = #{loginIp,jdbcType=VARCHAR}, + + + last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP}, + + + del_flag = #{delFlag,jdbcType=INTEGER}, + + + remarks = #{remarks,jdbcType=VARCHAR}, + + + update_by = #{updateBy,jdbcType=VARCHAR}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + WHERE user_id = #{userId,jdbcType=BIGINT} + + + diff --git a/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserRoleMapper.xml b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserRoleMapper.xml new file mode 100644 index 0000000..2a5d7c7 --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserRoleMapper.xml @@ -0,0 +1,179 @@ + + + + + + + + + + + + + + sys_code, + user_id, + role_id, + create_time, + update_time + + + + + + + + + + + + INSERT INTO sso_user_role + ( + sys_code, + user_id, + role_id + ) + values + ( + #{sysCode,jdbcType=VARCHAR}, + #{userId,jdbcType=BIGINT}, + #{roleId,jdbcType=BIGINT} + ) + + + + INSERT INTO sso_user_role + + + sys_code, + + + user_id, + + + role_id, + + + create_time, + + + update_time, + + + + + #{sysCode,jdbcType=VARCHAR}, + + + #{userId,jdbcType=BIGINT}, + + + #{roleId,jdbcType=BIGINT}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + + + + + INSERT INTO sso_user_role + ( + sys_code, + user_id, + role_id + ) + VALUES + + ( + #{item.sysCode,jdbcType=VARCHAR}, + #{item.userId,jdbcType=BIGINT}, + #{item.roleId,jdbcType=BIGINT} + ) + + + + + DELETE FROM sso_user_role + WHERE sys_code = #{sysCode,jdbcType=VARCHAR} + AND user_id = #{userId,jdbcType=BIGINT} + + + + DELETE FROM sso_user_role + WHERE role_id = #{roleId,jdbcType=BIGINT} + AND user_id = #{userId,jdbcType=BIGINT} + + + + UPDATE sso_user_role + SET + sys_code = #{sysCode,jdbcType=VARCHAR}, + user_id = #{userId,jdbcType=BIGINT}, + role_id = #{roleId,jdbcType=BIGINT} + WHERE id = #{id,jdbcType=BIGINT} + + + + UPDATE sso_user_role + + + sys_code = #{sysCode,jdbcType=VARCHAR}, + + + user_id = #{userId,jdbcType=BIGINT}, + + + role_id = #{roleId,jdbcType=BIGINT}, + + + WHERE id = #{id,jdbcType=BIGINT} + + + + + diff --git a/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserSystemMapper.xml b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserSystemMapper.xml new file mode 100644 index 0000000..fd6114d --- /dev/null +++ b/sso-auth-center-service/sso-business/src/main/resources/mapper/mybatis/SsoUserSystemMapper.xml @@ -0,0 +1,224 @@ + + + + + + + + + + + + + + + + + + id, + user_id, + sys_code, + sort_num, + del_flag, + create_by, + update_by, + create_time, + update_time + + + + + + + + INSERT INTO sso_user_system + ( + id, + user_id, + sys_code, + sort_num, + del_flag, + create_by, + update_by, + create_time, + update_time + ) + values + ( + #{id,jdbcType=BIGINT}, + #{userId,jdbcType=BIGINT}, + #{sysCode,jdbcType=VARCHAR}, + #{sortNum,jdbcType=INTEGER}, + #{delFlag,jdbcType=INTEGER}, + #{createBy,jdbcType=VARCHAR}, + #{updateBy,jdbcType=VARCHAR}, + #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP} + ) + + + + INSERT INTO sso_user_system + + + id, + + + user_id, + + + sys_code, + + + sort_num, + + + del_flag, + + + create_by, + + + update_by, + + + create_time, + + + update_time, + + + + + #{id,jdbcType=BIGINT}, + + + #{userId,jdbcType=BIGINT}, + + + #{sysCode,jdbcType=VARCHAR}, + + + #{sortNum,jdbcType=INTEGER}, + + + #{delFlag,jdbcType=INTEGER}, + + + #{createBy,jdbcType=VARCHAR}, + + + #{updateBy,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + + + + DELETE FROM sso_user_system + WHERE id = #{id,jdbcType=BIGINT} + + + + UPDATE sso_user_system + SET + user_id = #{userId,jdbcType=BIGINT}, + sys_code = #{sysCode,jdbcType=VARCHAR}, + sort_num = #{sortNum,jdbcType=INTEGER}, + del_flag = #{delFlag,jdbcType=INTEGER}, + create_by = #{createBy,jdbcType=VARCHAR}, + update_by = #{updateBy,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP} + WHERE id = #{id,jdbcType=BIGINT} + + + + UPDATE sso_user_system + + + user_id = #{userId,jdbcType=BIGINT}, + + + sys_code = #{sysCode,jdbcType=VARCHAR}, + + + sort_num = #{sortNum,jdbcType=INTEGER}, + + + del_flag = #{delFlag,jdbcType=INTEGER}, + + + create_by = #{createBy,jdbcType=VARCHAR}, + + + update_by = #{updateBy,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + WHERE id = #{id,jdbcType=BIGINT} + + + + UPDATE sso_user_system + + + sort_num = #{sortNum,jdbcType=INTEGER}, + + + del_flag = #{delFlag,jdbcType=INTEGER}, + + + create_by = #{createBy,jdbcType=VARCHAR}, + + + update_by = #{updateBy,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + WHERE del_flag = 0 + AND sys_code = #{sysCode,jdbcType=VARCHAR} + AND user_id = #{userId,jdbcType=BIGINT} + + + + + + diff --git a/sso-auth-center-service/sso-common/pom.xml b/sso-auth-center-service/sso-common/pom.xml new file mode 100755 index 0000000..2d4a71b --- /dev/null +++ b/sso-auth-center-service/sso-common/pom.xml @@ -0,0 +1,120 @@ + + + + com.sso + sso-auth-center-service + 1.0.0 + + 4.0.0 + + sso-common + + + common通用工具 + + + + + + + org.springframework + spring-context-support + + + + + org.springframework + spring-web + + + + + org.springframework.boot + spring-boot-starter-security + + + + + javax.validation + validation-api + + + + + org.apache.commons + commons-lang3 + + + + + com.fasterxml.jackson.core + jackson-databind + + + + + com.alibaba + fastjson + + + + + com.google.guava + guava + + + + + commons-io + commons-io + + + + + commons-fileupload + commons-fileupload + + + + + org.apache.poi + poi-ooxml + + + + + + io.jsonwebtoken + jjwt + + + + + eu.bitwalker + UserAgentUtils + + + + + javax.servlet + javax.servlet-api + + + + cn.hutool + hutool-all + + + + org.projectlombok + lombok + + + + org.hibernate + hibernate-validator + + + diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/annotation/OpenApi.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/annotation/OpenApi.java new file mode 100644 index 0000000..b3d8dbb --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/annotation/OpenApi.java @@ -0,0 +1,25 @@ +package com.sso.common.annotation; + +import java.lang.annotation.*; + +/** + * 开放接口注解 + * + * @author 程序员小强 + */ +@Documented +@Inherited +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface OpenApi { + + /** + * api 方法名 + */ + String method(); + + /** + * 方法描述 + */ + String desc() default ""; +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/annotation/OpenApiService.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/annotation/OpenApiService.java new file mode 100644 index 0000000..81c2284 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/annotation/OpenApiService.java @@ -0,0 +1,14 @@ +package com.sso.common.annotation; + +import java.lang.annotation.*; + +/** + * 开放接口实现类注解 + * + * @author 程序员小强 + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface OpenApiService { +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/CacheConstants.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/CacheConstants.java new file mode 100755 index 0000000..cdabb75 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/CacheConstants.java @@ -0,0 +1,65 @@ +package com.sso.common.constant; + +/** + * 通用常量信息 + * + * @author 程序员小强 + */ +public class CacheConstants { + + /** + * 验证码 redis key + */ + private static final String CAPTCHA_CODE_KEY = "captcha_cache_key:"; + + /** + * 验证码有效期(5分钟) + */ + public static final Integer CAPTCHA_EXPIRE = 5; + + /** + * 验证码有效期(5分钟) + */ + public static final Integer CAPTCHA_EXPIRE_FIVE = 5; + + /** + * 登录用户 redis key + */ + private static final String LOGIN_TOKEN_CACHE_KEY = "login_tokens:"; + + /** + * 登录用户 redis key + */ + private static final String LOGIN_USER_ID_CACHE_KEY = "login_user_id:"; + + /** + * 系统平台配置 缓存key + */ + private static final String SYSTEM_CONFIG_CACHE_KEY = "sso_admin_system_cache_key:"; + + /** + * 注册子系统缓存key + */ + private static final String REGISTER_SYS_CACHE_KEY = "register_sys:"; + + /** + * 系统平台-缓存有效期(720分钟)12小时 + */ + public static final Integer SYSTEM_CONFIG_CACHE_EXPIRE = 720; + + public static String getCaptchaCodeKey(String requestId) { + return CacheConstants.CAPTCHA_CODE_KEY + requestId; + } + + public static String getSystemCaptchaKey(String sysCode) { + return CacheConstants.SYSTEM_CONFIG_CACHE_KEY + sysCode; + } + + public static String getLoginUserIdKey(Long userId) { + return CacheConstants.LOGIN_USER_ID_CACHE_KEY + userId; + } + + public static String getLoginUserTokenKey(String token) { + return CacheConstants.LOGIN_TOKEN_CACHE_KEY + token; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/MimeTypeConstant.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/MimeTypeConstant.java new file mode 100755 index 0000000..9928cdc --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/MimeTypeConstant.java @@ -0,0 +1,53 @@ +package com.sso.common.constant; + +/** + * 媒体类型工具类 + * + * @author 程序员小强 + */ +public class MimeTypeConstant { + + public static final String IMAGE_PNG = "image/png"; + + public static final String IMAGE_JPG = "image/jpg"; + + public static final String IMAGE_JPEG = "image/jpeg"; + + public static final String IMAGE_BMP = "image/bmp"; + + public static final String IMAGE_GIF = "image/gif"; + + public static final String[] IMAGE_EXTENSION = {"bmp", "gif", "jpg", "jpeg", "png"}; + + public static final String[] FLASH_EXTENSION = {"swf", "flv"}; + + public static final String[] MEDIA_EXTENSION = {"swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg", + "asf", "rm", "rmvb"}; + + public static final String[] DEFAULT_ALLOWED_EXTENSION = { + // 图片 + "bmp", "gif", "jpg", "jpeg", "png", + // word excel powerpoint + "doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt", + // 压缩文件 + "rar", "zip", "gz", "bz2", + // pdf + "pdf"}; + + public static String geByPrefix(String prefix) { + switch (prefix) { + case IMAGE_PNG: + return "png"; + case IMAGE_JPG: + return "jpg"; + case IMAGE_JPEG: + return "jpeg"; + case IMAGE_BMP: + return "bmp"; + case IMAGE_GIF: + return "gif"; + default: + return ""; + } + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/NumberConstant.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/NumberConstant.java new file mode 100644 index 0000000..c1f8200 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/NumberConstant.java @@ -0,0 +1,17 @@ +package com.sso.common.constant; + + +/** + * 数字常量 + * + * @author 程序员小强 + */ +public class NumberConstant { + + public static final Integer ZERO = 0; + public static final Integer ONE = 1; + public static final Integer TWO = 2; + public static final Integer THREE = 3; + public static final Integer THEN = 10; + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/SsoConstants.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/SsoConstants.java new file mode 100755 index 0000000..b104091 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/SsoConstants.java @@ -0,0 +1,80 @@ +package com.sso.common.constant; + +/** + * 通用常量信息 + * + * @author 程序员小强 + */ +public class SsoConstants { + + /** + * 下拉选项,默认限制长度 + */ + public static final Integer OPTION_LIMIT = 10; + + /** + * 分隔符 | + */ + public static final String SPLIT_ESCAPE = "\\|"; + + /** + * 分隔符 | + */ + public static final String PERMISSIONS_SPLIT = "|"; + + /** + * 验证码类型-math + */ + public static final String CAPTCHA_TYPE_MATH = "math"; + + /** + * 验证码类型-char + */ + public static final String CAPTCHA_TYPE_CHAR = "char"; + + /** + * UTF-8 字符集 + */ + public static final String UTF8 = "UTF-8"; + + /** + * GBK 字符集 + */ + public static final String GBK = "GBK"; + + /** + * http请求 + */ + public static final String HTTP = "http://"; + + /** + * https请求 + */ + public static final String HTTPS = "https://"; + + /** + * 通用成功标识 + */ + public static final String SUCCESS = "0"; + + /** + * 修改秘钥权限 key + */ + public static final String UPDATE_SECRET_KEY = "system:updateSecret"; + + /** + * 资源映射路径 前缀 + */ + public static final String RESOURCE_PREFIX = "/profile"; + + /** + * 获取头像上传路径 + */ + public static final String AVATAR_PATH = "/avatar"; + + /** + * 平台头像上传路径 + */ + public static final String SYSTEM_ICON_PATH = "/sysIcon"; + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/SsoPermissionConstants.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/SsoPermissionConstants.java new file mode 100755 index 0000000..cefddce --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/SsoPermissionConstants.java @@ -0,0 +1,29 @@ +package com.sso.common.constant; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * 权限相关常量信息 + * + * @author 程序员小强 + */ +public class SsoPermissionConstants { + + /** + * 所有权限标识 + */ + public static final String ALL_PERMISSION = "**"; + + /** + * 认证中心管理员角色-权限标识 + */ + public static final String ADMIN_ROLE_KEY = "admin"; + + /** + * 管理员账户名 + */ + public static final Set ADMIN_USER_SET = new HashSet<>(Collections.singletonList("admin")); + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/UserLoginConstants.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/UserLoginConstants.java new file mode 100755 index 0000000..c95dea6 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/constant/UserLoginConstants.java @@ -0,0 +1,27 @@ +package com.sso.common.constant; + +/** + * 通用常量信息 + * + * @author 程序员小强 + */ +public class UserLoginConstants { + + + /** + * 令牌 + */ + public static final String TOKEN = "token"; + + /** + * 令牌前缀 + */ + public static final String TOKEN_PREFIX = "Bearer "; + + /** + * 令牌前缀 + */ + public static final String LOGIN_USER_KEY = "login_user_key"; + + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/DelFlagEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/DelFlagEnum.java new file mode 100755 index 0000000..fc82313 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/DelFlagEnum.java @@ -0,0 +1,24 @@ +package com.sso.common.enums; + +import lombok.Getter; + +/** + * 数据删除状态 + * + * @author 程序员小强 + */ +@Getter +public enum DelFlagEnum { + + OK(0, "正常"), + DELETED(1, "删除"); + + private Integer status; + private String desc; + + DelFlagEnum(Integer status, String desc) { + this.status = status; + this.desc = desc; + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/DeptStatusEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/DeptStatusEnum.java new file mode 100755 index 0000000..b89289e --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/DeptStatusEnum.java @@ -0,0 +1,24 @@ +package com.sso.common.enums; + +import lombok.Getter; + +/** + * 部门状态-枚举 + * + * @author 程序员小强 + */ +@Getter +public enum DeptStatusEnum { + + OK(0, "正常"), + DISABLE(1, "停用"); + + private Integer status; + private String desc; + + DeptStatusEnum(Integer status, String desc) { + this.status = status; + this.desc = desc; + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/LoginStatusEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/LoginStatusEnum.java new file mode 100755 index 0000000..c050e99 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/LoginStatusEnum.java @@ -0,0 +1,26 @@ +package com.sso.common.enums; + +import lombok.Getter; + +/** + * 登录状态枚举 + * + * @author 程序员小强 + */ +@Getter +public enum LoginStatusEnum { + + /** + * 系统状态 + */ + SUCCESS(0, "成功"), + FAIL(1, "失败"); + + private final Integer status; + private final String desc; + + LoginStatusEnum(Integer status, String desc) { + this.status = status; + this.desc = desc; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/MenuStatusEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/MenuStatusEnum.java new file mode 100755 index 0000000..fb1febb --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/MenuStatusEnum.java @@ -0,0 +1,24 @@ +package com.sso.common.enums; + +import lombok.Getter; + +/** + * 菜单状态-枚举 + * + * @author 程序员小强 + */ +@Getter +public enum MenuStatusEnum { + + OK(0, "正常"), + DISABLE(1, "停用"); + + private Integer status; + private String desc; + + MenuStatusEnum(Integer status, String desc) { + this.status = status; + this.desc = desc; + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/MenuTypeEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/MenuTypeEnum.java new file mode 100755 index 0000000..0f23ef6 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/MenuTypeEnum.java @@ -0,0 +1,35 @@ +package com.sso.common.enums; + +import lombok.Getter; + +/** + * 菜单类型-枚举 + * + * @author 程序员小强 + */ +@Getter +public enum MenuTypeEnum { + + /** + * 菜单类型枚举 + */ + FOLDER("M", "目录"), + MENU("C", "菜单"), + FUNCTION("F", "按钮"); + + private final String type; + private final String desc; + + MenuTypeEnum(String type, String desc) { + this.type = type; + this.desc = desc; + } + + public static boolean isMenu(String type) { + if (FOLDER.type.equals(type)) { + return true; + } + return MENU.type.equals(type); + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/SignTypeEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/SignTypeEnum.java new file mode 100755 index 0000000..621e64d --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/SignTypeEnum.java @@ -0,0 +1,49 @@ +package com.sso.common.enums; + +import lombok.Getter; +import org.apache.commons.lang3.math.NumberUtils; + +/** + * 签名类型 + * + * @author 程序员小强 + */ +@Getter +public enum SignTypeEnum { + + /** + * 无 + */ + EMPTY(0), + /** + * md5 + */ + MD5(1), + /** + * rsa + */ + RSA(2), + ; + private final Integer value; + + SignTypeEnum(Integer value) { + this.value = value; + } + + public static SignTypeEnum getByValue(String value) { + int intValue = NumberUtils.toInt(value); + if (intValue == 0) { + return null; + } + return getByValue(intValue); + } + + public static SignTypeEnum getByValue(Integer value) { + for (SignTypeEnum signTypeEnum : SignTypeEnum.values()) { + if (value.equals(signTypeEnum.getValue())) { + return signTypeEnum; + } + } + return EMPTY; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/SystemManagerStatusEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/SystemManagerStatusEnum.java new file mode 100755 index 0000000..a1d8ed0 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/SystemManagerStatusEnum.java @@ -0,0 +1,24 @@ +package com.sso.common.enums; + +import lombok.Getter; + +/** + * 平台管理员关系表-枚举 + * + * @author 程序员小强 + */ +@Getter +public enum SystemManagerStatusEnum { + + OK(0, "正常"), + DISABLE(1, "停用"); + + private Integer status; + private String desc; + + SystemManagerStatusEnum(Integer status, String desc) { + this.status = status; + this.desc = desc; + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/SystemStatusEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/SystemStatusEnum.java new file mode 100755 index 0000000..2cf470b --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/SystemStatusEnum.java @@ -0,0 +1,49 @@ +package com.sso.common.enums; + +import lombok.Getter; + +import java.util.ArrayList; +import java.util.List; + +/** + * 系统状态枚举 + * + * @author 程序员小强 + */ +@Getter +public enum SystemStatusEnum { + + /** + * 系统状态 + */ + ENABLE(0, "正常"), + DISABLE(1, "停用"); + + private Integer status; + private String desc; + + SystemStatusEnum(Integer status, String desc) { + this.status = status; + this.desc = desc; + } + + /** + * 启用的状态集 + */ + public static List getEnableStatusList() { + List statusList = new ArrayList<>(); + statusList.add(ENABLE.getStatus()); + return statusList; + } + + /** + * 所有状态集 + */ + public static List getAllStatusList() { + List statusList = new ArrayList<>(); + for (SystemStatusEnum statusEnum : SystemStatusEnum.values()) { + statusList.add(statusEnum.getStatus()); + } + return statusList; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/ApiExceptionEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/ApiExceptionEnum.java new file mode 100644 index 0000000..8f48fcd --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/ApiExceptionEnum.java @@ -0,0 +1,41 @@ +package com.sso.common.enums.exception; + +/** + * 异常枚举 + * + * @author 程序员小强 + */ +public enum ApiExceptionEnum implements EnumInterface { + + /** + * api异常枚举 + */ + API_NOT_EXIST(9001, "API方法不存在"), + INVALID_PUBLIC_PARAM(9002, "无效公共参数 >> {0}"), + INVALID_REQUEST_ERROR(9003, " 请求方式 {0} 错误 ! 请使用 {1} 方式"), + INVALID_PARAM(9004, "无效参数 >> 参数[{0}] >> 原因[{1}]"), + INVALID_SIGN(9005, "无效签名"), + SIGN_TYPE_NOT_EXIST(9001, "签名类型不存在"), + SYSTEM_ERROR(9999, "系统繁忙请稍后再试!"), + ; + + ApiExceptionEnum(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + private Integer code; + + private String msg; + + @Override + public Integer getCode() { + return code; + } + + @Override + public String getMsg() { + return msg; + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/DeptResStatusEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/DeptResStatusEnum.java new file mode 100644 index 0000000..183d016 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/DeptResStatusEnum.java @@ -0,0 +1,46 @@ +package com.sso.common.enums.exception; + +/** + * 部门返回相关 + * 编号300xx + * + * @author 程序员小强 + */ +public enum DeptResStatusEnum implements EnumInterface { + + /** + * 部门操作状态枚举 + */ + REPEAT_NAME(3000, "部门名称{0}已存在"), + ALREADY_DELETE(3001, "部门已删除"), + HASH_CHILD_USER(3002, "部门下存在用户"), + HASH_CHILD_DEPT(3003, "部门下存在子部门"), + DEPT_NOT_EXISTS(3004, "部门不存在"), + PARENT_NOT_EXISTS(3005, "父部门不存在"), + PARENT_IS_DELETE(3006, "父部门已删除"), + NOT_EXISTS_OR_DELETE(3007, "部门不存在或者已删除"), + PARENT_IS_DISABLE(3008, "父部门已停用"), + HASH_ENABLE_CHILD(3009, "该部门包含未停用的子部门"), + PARENT_CANNOT_SELF(3010, "父部门不能选自己"), + ; + + + DeptResStatusEnum(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + private Integer code; + + private String msg; + + @Override + public Integer getCode() { + return code; + } + + @Override + public String getMsg() { + return msg; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/EnumInterface.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/EnumInterface.java new file mode 100644 index 0000000..db3a36e --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/EnumInterface.java @@ -0,0 +1,21 @@ +package com.sso.common.enums.exception; + +/** + * @author 程序员小强 + * @version EnumInterface.java, v 0.1 2019-01-15 20:54 + */ +public interface EnumInterface { + /** + * 获取key + * + * @return + */ + Integer getCode(); + + /** + * 获取value + * + * @return + */ + String getMsg(); +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/MenuResStatusEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/MenuResStatusEnum.java new file mode 100644 index 0000000..89e7177 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/MenuResStatusEnum.java @@ -0,0 +1,39 @@ +package com.sso.common.enums.exception; + +/** + * 菜单返回相关 + * 编号500xx + * + * @author 程序员小强 + */ +public enum MenuResStatusEnum implements EnumInterface { + + /** + * 菜单操作状态枚举 + */ + ALREADY_DELETE(5001, "菜单已删除"), + HASH_CHILD_DEPT(5003, "菜单下存在未删除的子菜单"), + MENU_NAME_EXISTS_IN_SAME_PARENT(5004, "同上级下菜单名称{0}已经存在"), + PARENT_CANNOT_SELF(5005, "父菜单不能选自己"), + ; + + + MenuResStatusEnum(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + private Integer code; + + private String msg; + + @Override + public Integer getCode() { + return code; + } + + @Override + public String getMsg() { + return msg; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/RoleResStatusEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/RoleResStatusEnum.java new file mode 100644 index 0000000..71b56ec --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/RoleResStatusEnum.java @@ -0,0 +1,41 @@ +package com.sso.common.enums.exception; + +/** + * 角色返回相关 + * 编号600xx + * + * @author 程序员小强 + */ +public enum RoleResStatusEnum implements EnumInterface { + + /** + * 角色操作状态枚举 + */ + ALREADY_DELETE(6001, "角色已删除"), + ROLE_NAME_EXISTS(6002, "角色名称{0}已经存在"), + KEY_NAME_EXISTS(6002, "角色标识{0}已经存在"), + ROLE_NOT_EXISTS(6003, "该角色不存在"), + ALREADY_BIND_USER(6004, "该角色已被用户使用"), + + ; + + + RoleResStatusEnum(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + private Integer code; + + private String msg; + + @Override + public Integer getCode() { + return code; + } + + @Override + public String getMsg() { + return msg; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/SysResStatusEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/SysResStatusEnum.java new file mode 100644 index 0000000..bef7529 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/SysResStatusEnum.java @@ -0,0 +1,49 @@ +package com.sso.common.enums.exception; + +/** + * @author 程序员小强 + */ +public enum SysResStatusEnum implements EnumInterface { + + /** + * 系统状态枚举 + */ + SUCCESS(200, "操作成功"), + ERROR(500, "操作失败"), + UNAUTHORIZED(401, "Unauthorized"), + + ADD_FAIL(1000, "新增失败"), + UPDATE_FAIL(1001, "修改失败"), + DELETE_FAIL(1002, "删除失败"), + + LOGIN_SUCCESS(2000, "登录成功"), + CAPTCHA_EXPIRE(2001, "验证码已失效"), + CAPTCHA_ERROR(2002, "验证码错误"), + SYS_NOT_FOUND(2003, "系统不存在"), + USER_PASSWORD_NOT_MATCH(2004, "用户名或密码错误"), + USER_NAME_NOT_EXISTS(2005, "用户名不存在"), + USER_DISABLE(2006, "用户已停用"), + + SYSTEM_ERROR(6000, "网络繁忙,请稍后再试"), + ; + + + SysResStatusEnum(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + private Integer code; + + private String msg; + + @Override + public Integer getCode() { + return code; + } + + @Override + public String getMsg() { + return msg; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/SystemResStatusEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/SystemResStatusEnum.java new file mode 100644 index 0000000..c863276 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/SystemResStatusEnum.java @@ -0,0 +1,42 @@ +package com.sso.common.enums.exception; + +/** + * 目标系统返回相关 + * 编号700xx + * + * @author 程序员小强 + */ +public enum SystemResStatusEnum implements EnumInterface { + + /** + * 目标系统 操作状态枚举 + */ + ALREADY_DELETE(7001, "系统{0}已删除"), + SYS_CODE_EXISTS(7002, "系统编码{0}已经存在"), + SYS_NOT_EXISTS(7003, "该系统不存在"), + ALREADY_BIND_USER(7004, "该系统已被用户引用,不可修改系统编码"), + ALREADY_BIND_DEPT(7005, "该系统已被部门引用,不可修改系统编码"), + ALREADY_BIND_MENU(7006, "该系统已被菜单引用,不可修改系统编码"), + ALREADY_BIND_ROLE(7007, "该系统已被角色引用,不可修改系统编码"), + ; + + + SystemResStatusEnum(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + private Integer code; + + private String msg; + + @Override + public Integer getCode() { + return code; + } + + @Override + public String getMsg() { + return msg; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/UserResStatusEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/UserResStatusEnum.java new file mode 100644 index 0000000..5539b46 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/exception/UserResStatusEnum.java @@ -0,0 +1,44 @@ +package com.sso.common.enums.exception; + +/** + * 用户返回相关 + * 编号400xx + * + * @author 程序员小强 + */ +public enum UserResStatusEnum implements EnumInterface { + + /** + * 用户操作状态枚举 + */ + ALREADY_DELETE(4001, "用户已删除"), + USER_NAME_EXISTS(4002, "登录名{0}已经存在"), + PHONE_EXISTS(4003, "手机号{0}已经存在"), + EMAIL_EXISTS(4004, "邮箱{0}已经存在"), + USER_NOT_EXISTS(4005, "用户不存在"), + OLD_PWD_ERROR(4006, "修改密码失败,旧密码错误"), + OLD_PWD_EVAL_NEW_PWD(4007, "新密码不能与旧密码相同"), + SUPPER_ADMIN_USER(4008, "超级管理员账号不可操作"), + + ; + + + UserResStatusEnum(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + private Integer code; + + private String msg; + + @Override + public Integer getCode() { + return code; + } + + @Override + public String getMsg() { + return msg; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/BusinessStatus.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/BusinessStatus.java new file mode 100755 index 0000000..14d81ac --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/BusinessStatus.java @@ -0,0 +1,18 @@ +package com.sso.common.enums.system; + +/** + * 操作状态 + * + * @author 程序员小强 + */ +public enum BusinessStatus { + /** + * 成功 + */ + SUCCESS, + + /** + * 失败 + */ + FAIL, +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/BusinessType.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/BusinessType.java new file mode 100755 index 0000000..2e750c3 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/BusinessType.java @@ -0,0 +1,58 @@ +package com.sso.common.enums.system; + +/** + * 业务操作类型 + * + * @author 程序员小强 + */ +public enum BusinessType { + /** + * 其它 + */ + OTHER, + + /** + * 新增 + */ + INSERT, + + /** + * 修改 + */ + UPDATE, + + /** + * 删除 + */ + DELETE, + + /** + * 授权 + */ + GRANT, + + /** + * 导出 + */ + EXPORT, + + /** + * 导入 + */ + IMPORT, + + /** + * 强退 + */ + FORCE, + + /** + * 生成代码 + */ + GENCODE, + + /** + * 清空数据 + */ + CLEAN, +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/OperatorType.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/OperatorType.java new file mode 100755 index 0000000..2e3fdc9 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/OperatorType.java @@ -0,0 +1,23 @@ +package com.sso.common.enums.system; + +/** + * 操作人类别 + * + * @author 程序员小强 + */ +public enum OperatorType { + /** + * 其它 + */ + OTHER, + + /** + * 后台用户 + */ + MANAGE, + + /** + * 手机端用户 + */ + MOBILE +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/RoleStatusEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/RoleStatusEnum.java new file mode 100755 index 0000000..91a08c5 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/RoleStatusEnum.java @@ -0,0 +1,24 @@ +package com.sso.common.enums.system; + +import lombok.Getter; + +/** + * 角色状态-枚举 + * + * @author 程序员小强 + */ +@Getter +public enum RoleStatusEnum { + + OK(0, "正常"), + DISABLE(1, "停用"); + + private Integer status; + private String desc; + + RoleStatusEnum(Integer status, String desc) { + this.status = status; + this.desc = desc; + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/UserStatusEnum.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/UserStatusEnum.java new file mode 100755 index 0000000..9630374 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/enums/system/UserStatusEnum.java @@ -0,0 +1,31 @@ +package com.sso.common.enums.system; + +/** + * 用户状态 + * + * @author 程序员小强 + */ +public enum UserStatusEnum { + + /** + * 用户状态 + */ + OK(0, "正常"), + DISABLE(1, "停用"); + + private Integer status; + private String info; + + UserStatusEnum(int status, String info) { + this.status = status; + this.info = info; + } + + public Integer getStatus() { + return status; + } + + public String getInfo() { + return info; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/exception/BaseException.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/exception/BaseException.java new file mode 100644 index 0000000..a5d2342 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/exception/BaseException.java @@ -0,0 +1,36 @@ +package com.sso.common.exception; + +import java.text.MessageFormat; + +/** + * 基础异常 + * + * @author 程序员小强iang + */ +public class BaseException extends RuntimeException { + + protected Integer code; + protected String msg; + + public BaseException() { + super(); + } + + protected BaseException(String message) { + super(message); + } + + protected BaseException(Integer code, String msgFormat, Object... args) { + super(MessageFormat.format(msgFormat, args)); + this.code = code; + this.msg = MessageFormat.format(msgFormat, args); + } + + public String getMsg() { + return this.msg; + } + + public Integer getCode() { + return this.code; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/exception/BusinessException.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/exception/BusinessException.java new file mode 100644 index 0000000..1793095 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/exception/BusinessException.java @@ -0,0 +1,37 @@ +package com.sso.common.exception; + + +import com.sso.common.enums.exception.EnumInterface; + +import java.text.MessageFormat; + +/** + * 业务异常 + * + * @author 程序员小强iang + * @version BusinessException.java + */ +public class BusinessException extends BaseException { + + public BusinessException(String message) { + super(message); + } + + public BusinessException(Integer code, String message) { + super(code, message); + } + + public static BaseException newInstance(String msgFormat, Object... args) { + return new BusinessException(MessageFormat.format(msgFormat, args)); + } + + public BusinessException(EnumInterface enumInterface) { + super(enumInterface.getCode(), enumInterface.getMsg()); + } + + public BusinessException(EnumInterface enumInterface, Object... args) { + super(enumInterface.getCode(), MessageFormat.format(enumInterface.getMsg(), args)); + } + + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/BaseOperateBO.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/BaseOperateBO.java new file mode 100755 index 0000000..c9f6dd7 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/BaseOperateBO.java @@ -0,0 +1,19 @@ +package com.sso.common.model; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 操作基础BO + * + * @author 程序员小强 + */ +@Data +public class BaseOperateBO implements Serializable { + + private static final long serialVersionUID = 4316038518168512167L; + + private String operateBy; + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/login/LoginResultVO.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/login/LoginResultVO.java new file mode 100755 index 0000000..9e75f09 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/login/LoginResultVO.java @@ -0,0 +1,169 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.common.model.login; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.apache.commons.lang3.StringUtils; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Collection; +import java.util.Set; + +/** + * 用户登录信息 + * + * @author 程序员小强 + */ +@Getter +@Setter +@ToString +public class LoginResultVO implements UserDetails { + + private static final long serialVersionUID = 8497926226669977207L; + + /** + * 请求唯一标识 + */ + private String requestId; + + /** + * 用户唯一标识 + */ + private String token; + + /** + * 登录时间 + */ + private Long loginTime; + + /** + * 过期时间 + */ + private Long expireTime; + + /** + * 来源IP + */ + private String sourceIp; + + /** + * 来源地址 + */ + private String sourceAddress; + + /** + * 浏览器 + */ + private String browserName; + + /** + * 操作系统 + */ + private String operateSystem; + + /** + * 权限列表 + */ + private Set permissionList; + + /** + * 角色标识 + */ + private Set roleKeyList; + + /** + * 用户信息 + */ + private LoginUserVO user; + + public LoginResultVO() { + } + + public LoginResultVO(LoginUserVO user, Set permissionList) { + this.user = user; + this.permissionList = permissionList; + } + + /** + * 获取操作人名称 + */ + public String getOperateName() { + if (null == this.user) { + return ""; + } + if (StringUtils.isNotBlank(this.user.getRealName())) { + return this.user.getRealName(); + } + if (StringUtils.isNotBlank(this.user.getUsername())) { + return this.user.getUsername(); + } + if (StringUtils.isNotBlank(this.user.getNickName())) { + return this.user.getNickName(); + } + return ""; + } + + @JsonIgnore + @Override + public String getPassword() { + return user.getPassword(); + } + + @Override + public String getUsername() { + return user.getUsername(); + } + + /** + * 账户是否未过期,过期无法验证 + */ + @JsonIgnore + @Override + public boolean isAccountNonExpired() { + return true; + } + + /** + * 指定用户是否解锁,锁定的用户无法进行身份验证 + * + * @return + */ + @JsonIgnore + @Override + public boolean isAccountNonLocked() { + return true; + } + + /** + * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证 + * + * @return + */ + @JsonIgnore + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + /** + * 是否可用 ,禁用的用户不能身份验证 + * + * @return + */ + @JsonIgnore + @Override + public boolean isEnabled() { + return true; + } + + @Override + public Collection getAuthorities() { + return null; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/login/LoginUserVO.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/login/LoginUserVO.java new file mode 100644 index 0000000..ad32a78 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/login/LoginUserVO.java @@ -0,0 +1,71 @@ +package com.sso.common.model.login; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.io.Serializable; + +/** + * 用户对象 sys_user + * + * @author 程序员小强 + */ +@Getter +@Setter +@ToString +public class LoginUserVO implements Serializable { + + private static final long serialVersionUID = 7849003000148433962L; + + /** + * 用户ID + */ + private Long userId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 密码 + */ + private String password; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 用户性别 0-男;1-女;2-未知 + */ + private Integer sex; + + /** + * 手机号码 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + /** + * 头像 + */ + private String avatar; + + /** + * 状态 0-正常;1-停用 + */ + private Integer status; + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/page/BasePageModel.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/page/BasePageModel.java new file mode 100755 index 0000000..3ec8a53 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/page/BasePageModel.java @@ -0,0 +1,66 @@ +package com.sso.common.model.page; + +import java.io.Serializable; + +/** + * 分页数据 + * + * @author 程序员小强 + */ +public class BasePageModel implements Serializable { + + private static final long serialVersionUID = -7185356231617358802L; + + /** + * 当前页 + */ + private Integer page; + + /** + * 页容量 + */ + private Integer pageSize; + + /** + * 排序列名 + */ + private String sortName; + + /** + * 排序的方向desc或者asc + */ + private String sortBy = "asc"; + + public Integer getPage() { + return page; + } + + public void setPage(Integer page) { + this.page = page == null ? 1 : page; + } + + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize == null ? 10 : pageSize; + } + + public String getSortName() { + return sortName; + } + + public void setSortName(String sortName) { + this.sortName = sortName; + } + + public String getSortBy() { + return sortBy; + } + + public void setSortBy(String sortBy) { + this.sortBy = sortBy; + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/page/BasePageQuery.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/page/BasePageQuery.java new file mode 100755 index 0000000..b99d59d --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/page/BasePageQuery.java @@ -0,0 +1,89 @@ +package com.sso.common.model.page; + +import java.io.Serializable; + +/** + * 分页数据 + * + * @author 程序员小强 + */ +public class BasePageQuery implements Serializable { + + private static final long serialVersionUID = 6467187852112192806L; + + /** + * 当前页 + */ + private Integer page; + + /** + * 页容量 + */ + private Integer pageSize; + + /** + * 开始行 + */ + private Integer startRow; + + /** + * 排序列名 + */ + private String sortName; + + /** + * 排序的方向desc或者asc + */ + private String sortBy = "asc"; + + /** + * 获取开始行 + */ + public Integer getStartRow() { + if (null == page) { + page = 1; + } + if (null == pageSize) { + pageSize = 10; + } + this.startRow = pageSize * (page - 1); + return startRow; + } + + public Integer getPage() { + return page; + } + + public void setPage(Integer page) { + this.page = page == null ? 1 : page; + } + + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize == null ? 10 : pageSize; + } + + public void setStartRow(Integer startRow) { + this.startRow = startRow; + } + + public String getSortName() { + return sortName; + } + + public void setSortName(String sortName) { + this.sortName = sortName; + } + + public String getSortBy() { + return sortBy; + } + + public void setSortBy(String sortBy) { + this.sortBy = sortBy; + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/result/ResultModel.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/result/ResultModel.java new file mode 100644 index 0000000..397af1f --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/result/ResultModel.java @@ -0,0 +1,77 @@ +package com.sso.common.model.result; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.sso.common.enums.exception.SysResStatusEnum; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; + +/** + * 返回统一对象 + * + * @author 程序员小强 + */ +@Getter +@Setter +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ResultModel implements Serializable { + + private static final long serialVersionUID = -296683281215956785L; + + /** + * 状态码 + */ + private Integer code; + + /** + * 返回的的数据 + */ + private T data; + + /** + * 描述 + */ + private String msg; + + + public static ResultModel success() { + return new ResultModel<>(SysResStatusEnum.SUCCESS.getCode(), null, "操作成功"); + } + + /** + * 成功请求 + * code : 200 + * msg : 默认 "" + */ + public static ResultModel success(T data) { + return new ResultModel<>(SysResStatusEnum.SUCCESS.getCode(), data, "操作成功"); + } + + public static ResultModel success(Integer code, T data) { + return new ResultModel<>(code, data, "操作失败"); + } + + public static ResultModel error(SysResStatusEnum exceptionEnum) { + return new ResultModel<>(exceptionEnum.getCode(), null, exceptionEnum.getMsg()); + } + + public static ResultModel error(Integer code, String msg) { + return new ResultModel<>(code, null, msg); + } + + public static ResultModel error(String msg) { + return new ResultModel<>(SysResStatusEnum.ERROR.getCode(), null, msg); + } + + private ResultModel() { + } + + private ResultModel(Integer code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + } + + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/result/ResultPageModel.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/result/ResultPageModel.java new file mode 100755 index 0000000..bdf0fd4 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/model/result/ResultPageModel.java @@ -0,0 +1,94 @@ +package com.sso.common.model.result; + +import com.sso.common.enums.exception.SysResStatusEnum; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 表格分页数据对象 + * + * @author 程序员小强 + */ +@Getter +@Setter +public class ResultPageModel implements Serializable { + + private static final long serialVersionUID = -5317828223300876518L; + + /** + * 消息状态码 + */ + private Integer code; + + /** + * 总记录数 + */ + private long total; + + /** + * 列表数据 + */ + private List data; + + /** + * 消息内容 + */ + private String msg; + + /** + * 表格数据对象 + */ + public ResultPageModel() { + } + + /** + * 分页 + * + * @param list 列表数据 + * @param total 总记录数 + */ + public ResultPageModel(List list, int total) { + this.data = list; + this.total = total; + } + + + /** + * 响应请求分页数据 + */ + public static ResultPageModel defaultValue() { + return success(new ArrayList<>(0), 0); + } + + /** + * 响应请求分页数据 + */ + public static ResultPageModel success(List list) { + return success(list, list.size()); + } + + /** + * 响应请求分页数据 + */ + public static ResultPageModel success(List list, int total) { + ResultPageModel rspData = new ResultPageModel<>(); + rspData.setCode(SysResStatusEnum.SUCCESS.getCode()); + rspData.setMsg("操作成功"); + rspData.setData(list); + rspData.setTotal(total); + return rspData; + } + + public static ResultPageModel error(String msg) { + ResultPageModel rspData = new ResultPageModel(); + rspData.setCode(SysResStatusEnum.ERROR.getCode()); + rspData.setMsg(msg); + rspData.setData(new ArrayList<>(0)); + rspData.setTotal(0); + return rspData; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/FileUploadUtils.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/FileUploadUtils.java new file mode 100644 index 0000000..d8affd9 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/FileUploadUtils.java @@ -0,0 +1,97 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.common.utils; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; +import com.sso.common.constant.MimeTypeConstant; +import com.sso.common.constant.SsoConstants; +import com.sso.common.exception.BusinessException; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FilenameUtils; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; +import java.util.Date; + +/** + * 文件上传工具类 + * + * @author 程序员小强 + */ +@Slf4j +public class FileUploadUtils { + + /** + * 默认大小 50M + */ + public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024; + + /** + * 默认的文件名最大长度 100 + */ + public static final int DEFAULT_FILE_NAME_LENGTH = 100; + + /** + * 上传 + * + * @param rootPath 文件顶级附录 + * @param bizPath 二级业务文件夹 + * @param file 文件内容 + * @return 文件地址 + * @throws IOException + */ + public static String upload(String rootPath, String bizPath, MultipartFile file) throws IOException { + if (null == file) { + throw new BusinessException("文件不为空!"); + } + String originalFilename = file.getOriginalFilename(); + if (StringUtils.isBlank(originalFilename)) { + throw new BusinessException("获取文件名失败!"); + } + int fileNameLength = originalFilename.length(); + if (fileNameLength > DEFAULT_FILE_NAME_LENGTH) { + throw new BusinessException("超过最大长度"); + } + if (file.getSize() > DEFAULT_MAX_SIZE) { + throw new BusinessException("文件大小不能超过 50M"); + } + + //文件后缀 + String fileType = getExtension(file); + String date = DateUtil.format(new Date(), "yyyyMMdd"); + String filePath = String.format("%s%s/%s", rootPath, bizPath, date); + if (!FileUtil.exist(filePath)) { + FileUtil.mkdir(filePath); + } + //文件名 + String fileName = String.format("%s.%s", UUIDUtil.getUUID(), fileType); + //文件全路径名 + String fileFullName = String.format("%s/%s", filePath, fileName); + + log.info("[ 文件上传 ] originalFilename:{} , uploadFileName:{}", originalFilename, fileFullName); + File desc = new File(fileFullName); + file.transferTo(desc); + return String.format("%s%s", SsoConstants.RESOURCE_PREFIX, fileFullName.replace(rootPath, "")); + } + + /** + * 获取文件名的后缀 + * + * @param file 表单文件 + * @return 后缀名 + */ + public static String getExtension(MultipartFile file) { + if (null == file) { + return ""; + } + String extension = FilenameUtils.getExtension(file.getOriginalFilename()); + if (StringUtils.isEmpty(extension) && StringUtils.isNotBlank(file.getContentType())) { + extension = MimeTypeConstant.geByPrefix(file.getContentType()); + } + return extension; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/JsonSerializer.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/JsonSerializer.java new file mode 100644 index 0000000..d66513a --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/JsonSerializer.java @@ -0,0 +1,44 @@ +package com.sso.common.utils; + +import com.alibaba.fastjson.JSON; + +import java.nio.charset.Charset; +import java.util.List; + +/** + * json Serializer util + */ +public class JsonSerializer { + + public static final String UTF_8 = "UTF-8"; + + /** + * @param obj + * @param + * @return + */ + @SuppressWarnings("unchecked") + public static byte[] serialize(T obj) { + return JSON.toJSONString(obj).getBytes(Charset.forName(UTF_8)); + } + + /** + * @param data + * @param clazz + * @param + * @return + */ + public static T deserialize(byte[] data, Class clazz) { + return JSON.parseObject(data, clazz); + } + + /** + * @param data + * @param clazz + * @param + * @return + */ + public static List deserializeList(byte[] data, Class clazz) { + return JSON.parseArray(new String(data), clazz); + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ObjectUtils.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ObjectUtils.java new file mode 100755 index 0000000..68cddcf --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ObjectUtils.java @@ -0,0 +1,103 @@ +package com.sso.common.utils; + +import java.util.Collection; +import java.util.Map; + +/** + * Object工具类 + * + * @author 程序员小强 + */ +public class ObjectUtils { + + /** + * * 判断一个Collection是否为空, 包含List,Set,Queue + * + * @param coll 要判断的Collection + * @return true:为空 false:非空 + */ + public static boolean isEmpty(Collection coll) { + return isNull(coll) || coll.isEmpty(); + } + + /** + * * 判断一个Collection是否非空,包含List,Set,Queue + * + * @param coll 要判断的Collection + * @return true:非空 false:空 + */ + public static boolean isNotEmpty(Collection coll) { + return !isEmpty(coll); + } + + /** + * * 判断一个对象数组是否为空 + * + * @param objects 要判断的对象数组 + * * @return true:为空 false:非空 + */ + public static boolean isEmpty(Object[] objects) { + return isNull(objects) || (objects.length == 0); + } + + /** + * * 判断一个对象数组是否非空 + * + * @param objects 要判断的对象数组 + * @return true:非空 false:空 + */ + public static boolean isNotEmpty(Object[] objects) { + return !isEmpty(objects); + } + + /** + * * 判断一个Map是否为空 + * + * @param map 要判断的Map + * @return true:为空 false:非空 + */ + public static boolean isEmpty(Map map) { + return isNull(map) || map.isEmpty(); + } + + /** + * * 判断一个Map是否为空 + * + * @param map 要判断的Map + * @return true:非空 false:空 + */ + public static boolean isNotEmpty(Map map) { + return !isEmpty(map); + } + + /** + * * 判断一个对象是否为空 + * + * @param object Object + * @return true:为空 false:非空 + */ + public static boolean isNull(Object object) { + return object == null; + } + + /** + * * 判断一个对象是否非空 + * + * @param object Object + * @return true:非空 false:空 + */ + public static boolean isNotNull(Object object) { + return !isNull(object); + } + + /** + * * 判断一个对象是否是数组类型(Java基本型别的数组) + * + * @param object 对象 + * @return true:是数组 false:不是数组 + */ + public static boolean isArray(Object object) { + return isNotNull(object) && object.getClass().isArray(); + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/PageUtils.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/PageUtils.java new file mode 100644 index 0000000..12282c0 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/PageUtils.java @@ -0,0 +1,83 @@ +package com.sso.common.utils; + +import java.util.ArrayList; +import java.util.List; + +/** + * 分页工具类 + * + * @author 程序员小强 + */ +public class PageUtils { + + /** + * 默认第一页 + */ + private static final int PAGE = 1; + + /** + * 默认一页10条 + */ + private static final int PAGE_SIZE = 10; + + + public static Integer getStartRow(Integer pageNo, Integer pageSize) { + if (null == pageNo) { + pageNo = PAGE; + } + if (null == pageSize) { + pageSize = PAGE_SIZE; + } + + return pageSize * (pageNo - 1); + } + + public static Integer getTotalPage(Integer rowCount, Integer pageSize) { + if (null == rowCount) { + rowCount = 0; + } + if (null == pageSize) { + pageSize = PAGE_SIZE; + } + + return (rowCount + pageSize - 1) / pageSize; + } + + public static Integer getOffset(Integer pageSize) { + if (null == pageSize) { + pageSize = PAGE_SIZE; + } + return pageSize; + } + + /** + * list分页 + * + * @param list + * @param pageNo + * @param pageSize + */ + public static List listPage(List list, Integer pageNo, Integer pageSize) { + if (null == list || list.isEmpty()) { + return list; + } + if (null == pageNo) { + pageNo = PAGE; + } + if (null == pageSize) { + pageSize = PAGE_SIZE; + } + int totalCount = list.size(); + pageNo = pageNo - 1; + int fromIndex = pageNo * pageSize; + if (fromIndex > totalCount) { + return new ArrayList<>(0); + } + int toIndex = ((pageNo + 1) * pageSize); + if (toIndex > totalCount) { + toIndex = totalCount; + } + return list.subList(fromIndex, toIndex); + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/SecurityUtils.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/SecurityUtils.java new file mode 100755 index 0000000..072d5df --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/SecurityUtils.java @@ -0,0 +1,109 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.common.utils; + +import com.sso.common.enums.exception.SysResStatusEnum; +import com.sso.common.exception.BusinessException; +import com.sso.common.model.login.LoginResultVO; +import com.sso.common.model.login.LoginUserVO; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +/** + * Security 工具类 + * + * @author 程序员小强 + */ +public class SecurityUtils { + + /** + * 获取用户名 + **/ + public static String getUsername() { + try { + return getLoginUserResult().getUsername(); + } catch (Exception e) { + return ""; + } + } + + /** + * 获取操作人名称 + **/ + public static String getOperateName() { + try { + return getLoginUserResult().getOperateName(); + } catch (Exception e) { + return ""; + } + } + + /** + * 获取用户登录信息 + **/ + public static LoginResultVO getLoginUserResult() { + try { + return (LoginResultVO) getAuthentication().getPrincipal(); + } catch (Exception e) { + throw new BusinessException(SysResStatusEnum.UNAUTHORIZED.getCode(), "获取用户信息异常"); + } + } + + /** + * 获取登录用户基本信息 + **/ + public static LoginUserVO getLoginUser() { + try { + LoginResultVO loginResult = (LoginResultVO) getAuthentication().getPrincipal(); + if (null == loginResult.getUser()) { + throw new BusinessException(SysResStatusEnum.UNAUTHORIZED.getCode(), "获取用户信息异常"); + } + return loginResult.getUser(); + } catch (Exception e) { + throw new BusinessException(SysResStatusEnum.UNAUTHORIZED.getCode(), "获取用户信息异常"); + } + } + + /** + * 获取Authentication + */ + public static Authentication getAuthentication() { + return SecurityContextHolder.getContext().getAuthentication(); + } + + /** + * 生成BCryptPasswordEncoder密码 + * + * @param password 密码 + * @return 加密字符串 + */ + public static String encryptPassword(String password) { + BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + return passwordEncoder.encode(password); + } + + /** + * 判断密码是否相同 + * + * @param rawPassword 真实密码 + * @param encodedPassword 加密后字符 + * @return 结果 + */ + public static boolean matchesPassword(String rawPassword, String encodedPassword) { + BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + return passwordEncoder.matches(rawPassword, encodedPassword); + } + + /** + * 是否为管理员 + * + * @param userId 用户ID + * @return 结果 + */ + public static boolean isAdmin(Long userId) { + return userId != null && 1L == userId; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ServletUtils.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ServletUtils.java new file mode 100755 index 0000000..8ab5e2b --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ServletUtils.java @@ -0,0 +1,91 @@ +package com.sso.common.utils; + +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; + +/** + * 客户端工具类 + * + * @author 程序员小强 + */ +public class ServletUtils { + + /** + * 获取request + */ + public static HttpServletRequest getRequest() { + return getRequestAttributes().getRequest(); + } + + /** + * 获取response + */ + public static HttpServletResponse getResponse() { + return getRequestAttributes().getResponse(); + } + + /** + * 获取session + */ + public static HttpSession getSession() { + return getRequest().getSession(); + } + + public static ServletRequestAttributes getRequestAttributes() { + RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); + return (ServletRequestAttributes) attributes; + } + + /** + * 将字符串渲染到客户端 + * + * @param response 渲染对象 + * @param string 待渲染的字符串 + * @return null + */ + public static String renderString(HttpServletResponse response, String string) { + try { + response.setStatus(200); + response.setContentType("application/json"); + response.setCharacterEncoding("utf-8"); + response.getWriter().print(string); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 是否是Ajax异步请求 + * + * @param request + */ + public static boolean isAjaxRequest(HttpServletRequest request) { + String accept = request.getHeader("accept"); + if (accept != null && accept.indexOf("application/json") != -1) { + return true; + } + + String xRequestedWith = request.getHeader("X-Requested-With"); + if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1) { + return true; + } + + String uri = request.getRequestURI(); + if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml")) { + return true; + } + + String ajax = request.getParameter("__ajax"); + if (StringUtils.inStringIgnoreCase(ajax, "json", "xml")) { + return true; + } + return false; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/SsoSignUtil.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/SsoSignUtil.java new file mode 100644 index 0000000..db768f1 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/SsoSignUtil.java @@ -0,0 +1,84 @@ +package com.sso.common.utils; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.lang3.StringUtils; + +import java.util.*; + +/** + * 统一认证中心 签名工具 + * + * @author 程序员小强 + */ +@Slf4j +public class SsoSignUtil { + + /** + * 生成Md5签名 + * 规则: + * 1.按参数名字母顺序(升序、区分大小写) + * 2.移除不需要加入签名参数 + * 3.待签名串(以&符逐个拼接参数名=参数值而形成) + * 4.拼接秘钥 格式&secret= xxxx + * 5.MD5加密 + * + * @param paramMap 参数Map + * @param removeKeys 需要移除的参数名 + * @param secret 秘钥值 + */ + public static String getMd5Sign(Map paramMap, List removeKeys, String secret) { + try { + //按参数名字母顺序(升序、区分大小写) + TreeMap signParamMap = getTreeMap(paramMap); + //移除签名参数 + removeKeys.forEach(signParamMap::remove); + //待签名串(以&符逐个拼接参数名=参数值而形成) + String content = getSignContent(signParamMap); + + //MD5 方式拼接 &secret + content = content + "&secret=" + secret; + + log.info("[ 加签参数 ] content:{}", content); + //MD5加签 + return DigestUtils.md5Hex(content); + } catch (Exception e) { + throw new RuntimeException("MD5加签异常", e); + } + } + + /** + * 以&符逐个拼接参数名=参数值而形成 + * + * @param sortedParams + */ + public static String getSignContent(Map sortedParams) { + StringBuilder content = new StringBuilder(); + ArrayList keys = new ArrayList<>(sortedParams.keySet()); + Collections.sort(keys); + int index = 0; + + for (Object o : keys) { + String key = (String) o; + String value = sortedParams.get(key); + if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(value)) { + content.append(index == 0 ? "" : "&").append(key).append("=").append(value); + ++index; + } + } + return content.toString(); + } + + /** + * 按参数名字母顺序(升序、区分大小写) + * + * @param paramMap + */ + public static TreeMap getTreeMap(Map paramMap) { + TreeMap signMap = new TreeMap<>(); + for (Map.Entry entry : paramMap.entrySet()) { + signMap.put(entry.getKey(), entry.getValue().toString()); + } + return signMap; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/StringUtils.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/StringUtils.java new file mode 100755 index 0000000..6c616b4 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/StringUtils.java @@ -0,0 +1,305 @@ +package com.sso.common.utils; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * 字符串工具类 + * + * @author 程序员小强 + */ +public class StringUtils extends org.apache.commons.lang3.StringUtils { + + /** + * 空字符串 + */ + private static final String EMPTY = ""; + + /** + * 下划线 + */ + private static final char SEPARATOR = '_'; + + + public static String dealBlankDefault(String value, String defaultValue) { + if (StringUtils.isNotBlank(value)) { + return value; + } + return defaultValue; + } + + /** + * 获取参数不为空值 + * + * @param value defaultValue 要判断的value + * @return value 返回值 + */ + public static T nvl(T value, T defaultValue) { + return value != null ? value : defaultValue; + } + + /** + * * 判断一个字符串是否为空串 + * + * @param str String + * @return true:为空 false:非空 + */ + public static boolean isEmpty(String str) { + return ObjectUtils.isNull(str) || EMPTY.equals(str.trim()); + } + + /** + * * 判断一个字符串是否为非空串 + * + * @param str String + * @return true:非空串 false:空串 + */ + public static boolean isNotEmpty(String str) { + return !isEmpty(str); + } + + /** + * 检查指定的字符串列表是否不为空。 + */ + public static boolean areNotEmpty(String... values) { + boolean result = true; + if (values == null || values.length == 0) { + result = false; + } else { + for (String value : values) { + result &= !isEmpty(value); + } + } + return result; + } + + /** + * 去空格 + */ + public static String trim(String str) { + return (str == null ? "" : str.trim()); + } + + /** + * 截取字符串 + * + * @param str 字符串 + * @param start 开始 + * @return 结果 + */ + public static String substring(final String str, int start) { + if (str == null) { + return EMPTY; + } + + if (start < 0) { + start = str.length() + start; + } + + if (start < 0) { + start = 0; + } + if (start > str.length()) { + return EMPTY; + } + + return str.substring(start); + } + + /** + * 截取字符串 + * + * @param str 字符串 + * @param start 开始 + * @param end 结束 + * @return 结果 + */ + public static String substring(final String str, int start, int end) { + if (str == null) { + return EMPTY; + } + + if (end < 0) { + end = str.length() + end; + } + if (start < 0) { + start = str.length() + start; + } + + if (end > str.length()) { + end = str.length(); + } + + if (start > end) { + return EMPTY; + } + + if (start < 0) { + start = 0; + } + if (end < 0) { + end = 0; + } + + return str.substring(start, end); + } + + /** + * 字符串转set + * + * @param str 字符串 + * @param sep 分隔符 + * @return set集合 + */ + public static final Set str2Set(String str, String sep) { + return new HashSet(str2List(str, sep, true, false)); + } + + /** + * 字符串转list + * + * @param str 字符串 + * @param sep 分隔符 + * @param filterBlank 过滤纯空白 + * @param trim 去掉首尾空白 + * @return list集合 + */ + public static final List str2List(String str, String sep, boolean filterBlank, boolean trim) { + List list = new ArrayList(); + if (StringUtils.isEmpty(str)) { + return list; + } + + // 过滤空白字符串 + if (filterBlank && StringUtils.isBlank(str)) { + return list; + } + String[] split = str.split(sep); + for (String string : split) { + if (filterBlank && StringUtils.isBlank(string)) { + continue; + } + if (trim) { + string = string.trim(); + } + list.add(string); + } + + return list; + } + + /** + * 下划线转驼峰命名 + */ + public static String toUnderScoreCase(String str) { + if (str == null) { + return null; + } + StringBuilder sb = new StringBuilder(); + // 前置字符是否大写 + boolean preCharIsUpperCase = true; + // 当前字符是否大写 + boolean curreCharIsUpperCase = true; + // 下一字符是否大写 + boolean nexteCharIsUpperCase = true; + for (int i = 0; i < str.length(); i++) { + char c = str.charAt(i); + if (i > 0) { + preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1)); + } else { + preCharIsUpperCase = false; + } + + curreCharIsUpperCase = Character.isUpperCase(c); + + if (i < (str.length() - 1)) { + nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1)); + } + + if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) { + sb.append(SEPARATOR); + } else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) { + sb.append(SEPARATOR); + } + sb.append(Character.toLowerCase(c)); + } + + return sb.toString(); + } + + /** + * 是否包含字符串 + * + * @param str 验证字符串 + * @param strs 字符串组 + * @return 包含返回true + */ + public static boolean inStringIgnoreCase(String str, String... strs) { + if (str != null && strs != null) { + for (String s : strs) { + if (str.equalsIgnoreCase(trim(s))) { + return true; + } + } + } + return false; + } + + /** + * 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld + * + * @param name 转换前的下划线大写方式命名的字符串 + * @return 转换后的驼峰式命名的字符串 + */ + public static String convertToCamelCase(String name) { + StringBuilder result = new StringBuilder(); + // 快速检查 + if (name == null || name.isEmpty()) { + // 没必要转换 + return ""; + } else if (!name.contains("_")) { + // 不含下划线,仅将首字母大写 + return name.substring(0, 1).toUpperCase() + name.substring(1); + } + // 用下划线将原始字符串分割 + String[] camels = name.split("_"); + for (String camel : camels) { + // 跳过原始字符串中开头、结尾的下换线或双重下划线 + if (camel.isEmpty()) { + continue; + } + // 首字母大写 + result.append(camel.substring(0, 1).toUpperCase()); + result.append(camel.substring(1).toLowerCase()); + } + return result.toString(); + } + + /** + * 驼峰式命名法 例如:user_name->userName + */ + public static String toCamelCase(String s) { + if (s == null) { + return null; + } + s = s.toLowerCase(); + StringBuilder sb = new StringBuilder(s.length()); + boolean upperCase = false; + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + + if (c == SEPARATOR) { + upperCase = true; + } else if (upperCase) { + sb.append(Character.toUpperCase(c)); + upperCase = false; + } else { + sb.append(c); + } + } + return sb.toString(); + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/SystemClock.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/SystemClock.java new file mode 100644 index 0000000..5beeb8b --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/SystemClock.java @@ -0,0 +1,46 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.common.utils; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; + +/** + * 高并发场景下System.currentTimeMillis()的性能问题的优化 + * 时间戳打印建议使用 + * + * @author 程序员小强 + */ +public class SystemClock { + private static final String THREAD_NAME = "system.clock"; + private static final SystemClock MILLIS_CLOCK = new SystemClock(1); + private final long precision; + private final AtomicLong now; + + private SystemClock(long precision) { + this.precision = precision; + now = new AtomicLong(System.currentTimeMillis()); + scheduleClockUpdating(); + } + + public static SystemClock millisClock() { + return MILLIS_CLOCK; + } + + private void scheduleClockUpdating() { + ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(runnable -> { + Thread thread = new Thread(runnable, THREAD_NAME); + thread.setDaemon(true); + return thread; + }); + scheduler.scheduleAtFixedRate(() -> now.set(System.currentTimeMillis()), precision, precision, TimeUnit.MILLISECONDS); + } + + public long now() { + return now.get(); + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/UUIDUtil.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/UUIDUtil.java new file mode 100755 index 0000000..9dbe069 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/UUIDUtil.java @@ -0,0 +1,34 @@ +package com.sso.common.utils; + +import java.util.Locale; +import java.util.UUID; + +/** + * UUID 工具类 + * + * @author 程序员小强 + */ +public final class UUIDUtil { + + /** + * 获取32位UUID + * + * @author 程序员小强 + */ + public static String getUUID() { + return UUID.randomUUID().toString().replaceAll("-", ""); + } + + /** + * 获取32位大写UUID + * + * @author 程序员小强 + */ + public static String get32UpperCaseUUID() { + return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(Locale.ENGLISH); + } + + private UUIDUtil() { + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ValidateUtils.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ValidateUtils.java new file mode 100644 index 0000000..74fafc2 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ValidateUtils.java @@ -0,0 +1,40 @@ +package com.sso.common.utils; + +import com.google.common.base.CaseFormat; +import com.sso.common.enums.exception.ApiExceptionEnum; +import com.sso.common.exception.BusinessException; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import java.util.Set; + +import static com.google.common.collect.Iterables.getFirst; + +/** + * 业务参数校验 + * + * @author 程序员小强 + */ +public class ValidateUtils { + + private final static Validator VALIDATOR = Validation.buildDefaultValidatorFactory().getValidator(); + + private ValidateUtils() { + } + + public static void validate(T object) { + //执行验证 + Set> constraintViolations = VALIDATOR.validate(object); + //如果有验证信息,则取出包装成异常返回 + ConstraintViolation constraintViolation = getFirst(constraintViolations, null); + if (constraintViolation != null) { + throw new BusinessException(ApiExceptionEnum.INVALID_PARAM, + CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, constraintViolation.getPropertyPath().toString()), + constraintViolation.getMessage()); + } + } + +} + + diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/bean/BeanCopierUtil.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/bean/BeanCopierUtil.java new file mode 100644 index 0000000..34cd419 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/bean/BeanCopierUtil.java @@ -0,0 +1,70 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.common.utils.bean; + +import org.springframework.cglib.beans.BeanCopier; + +import java.util.ArrayList; +import java.util.List; + +/** + * Bean 拷贝 + * + * @author 程序员小强 + * @version BeanCopierUtil.java, v 0.1 2020-10-17 + */ +public class BeanCopierUtil { + + /** + * 对象属性拷贝 + * + * @param source + * @param targetClass + * @param + */ + public static T copy(Object source, Class targetClass) { + T t = null; + try { + t = targetClass.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + throw new RuntimeException("Create new instance of %s failed: %s"); + } + copyProperty(source, t); + return t; + } + + /** + * 对象集合属性拷贝 + * + * @param orig + * @param dest + * @param + */ + public static List copyList(List orig, Class dest) { + try { + List resultList = new ArrayList(); + if (orig == null || orig.size() <= 0) { + return resultList; + } + for (Object o : orig) { + T destObject = dest.newInstance(); + if (o == null) { + continue; + } + copyProperty(o, destObject); + resultList.add(destObject); + } + return resultList; + } catch (Exception e) { + return new ArrayList<>(0); + } + } + + private static void copyProperty(Object source, Object target) { + BeanCopier copier = BeanCopier.create(source.getClass(), target.getClass(), false); + copier.copy(source, target, null); + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ip/IpAddressUtils.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ip/IpAddressUtils.java new file mode 100755 index 0000000..20519bf --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ip/IpAddressUtils.java @@ -0,0 +1,80 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.common.utils.ip; + +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 获取地址类 + * 注:根据IP地址查询所属地 + * + * @author 程序员小强 + */ +public class IpAddressUtils { + private static final Logger log = LoggerFactory.getLogger(IpAddressUtils.class); + + /** + * IP地址查询 + * 太平洋网络IP地址查询接口 + */ + public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp?ip=%s&json=true"; + + /** + * 未知地址 + */ + public static final String UNKNOWN = "XX XX"; + + /** + * 超时毫秒数 10s + */ + public static final int TIME_OUT_MILLISECONDS = 10 * 1000; + + /** + * 根据IP-获取真实地址 + * + * @param ip + */ + public static String getRealAddressByIP(String ip) { + //内网IP + if (IpUtils.internalIp(ip)) { + return "内网IP"; + } + + try { + String response = HttpUtil.get(String.format(IP_URL, ip), TIME_OUT_MILLISECONDS); + if (StringUtils.isEmpty(response)) { + log.error("[ 根据IP-获取地理位置失败 ] >> {}", ip); + return UNKNOWN; + } + JSONObject jsonObject = JSONObject.parseObject(response); + if (null == jsonObject) { + return UNKNOWN; + } + + //省份 + String province = jsonObject.getString("pro"); + //城市 + String city = jsonObject.getString("city"); + + //详细地址 示例:浙江省杭州市 电信 + String addr = jsonObject.getString("addr"); + if (StringUtils.isNoneBlank(addr)) { + addr = addr.replaceAll(province, "") + .replaceAll(city, "").trim(); + return addr; + } + + //示例:浙江省 杭州市 电信 + return String.format("%s %s %s", province, city, addr); + } catch (Exception e) { + log.error("[ 根据IP-获取地理位置异常 ] >> {}", ip); + } + return UNKNOWN; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ip/IpUtils.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ip/IpUtils.java new file mode 100755 index 0000000..5f67bac --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/ip/IpUtils.java @@ -0,0 +1,194 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.common.utils.ip; + +import org.apache.commons.lang3.StringUtils; + +import javax.servlet.http.HttpServletRequest; +import java.net.InetAddress; +import java.net.UnknownHostException; + +/** + * 获取IP方法 + * + * @author 程序员小强 + */ +public class IpUtils { + + public static final String UN_KNOWN = "unKnown"; + + /** + * 获取Ip地址 + * + * @param request + * @return + */ + public static String getIpAddr(HttpServletRequest request) { + String xip = request.getHeader("X-Real-IP"); + String xFor = request.getHeader("X-Forwarded-For"); + if (StringUtils.isNotEmpty(xFor) && !UN_KNOWN.equalsIgnoreCase(xFor)) { + //多次反向代理后会有多个ip值,第一个ip才是真实ip + int index = xFor.indexOf(","); + if (index != -1) { + return xFor.substring(0, index); + } else { + return xFor; + } + } + xFor = xip; + if (StringUtils.isNotEmpty(xFor) && !UN_KNOWN.equalsIgnoreCase(xFor)) { + return xFor; + } + if (StringUtils.isBlank(xFor) || UN_KNOWN.equalsIgnoreCase(xFor)) { + xFor = request.getHeader("Proxy-Client-IP"); + } + if (StringUtils.isBlank(xFor) || UN_KNOWN.equalsIgnoreCase(xFor)) { + xFor = request.getHeader("WL-Proxy-Client-IP"); + } + if (StringUtils.isBlank(xFor) || UN_KNOWN.equalsIgnoreCase(xFor)) { + xFor = request.getHeader("HTTP_CLIENT_IP"); + } + if (StringUtils.isBlank(xFor) || UN_KNOWN.equalsIgnoreCase(xFor)) { + xFor = request.getHeader("HTTP_X_FORWARDED_FOR"); + } + if (StringUtils.isBlank(xFor) || UN_KNOWN.equalsIgnoreCase(xFor)) { + xFor = request.getRemoteAddr(); + } + return xFor; + } + + /** + * 是否内网IP + * + * @param ip + * @return + */ + public static boolean internalIp(String ip) { + byte[] addr = textToNumericFormatV4(ip); + return internalIp(addr) || "127.0.0.1".equals(ip); + } + + private static boolean internalIp(byte[] addr) { + if (null == addr || addr.length < 2) { + return true; + } + final byte b0 = addr[0]; + final byte b1 = addr[1]; + // 10.x.x.x/8 + final byte SECTION_1 = 0x0A; + // 172.16.x.x/12 + final byte SECTION_2 = (byte) 0xAC; + final byte SECTION_3 = (byte) 0x10; + final byte SECTION_4 = (byte) 0x1F; + // 192.168.x.x/16 + final byte SECTION_5 = (byte) 0xC0; + final byte SECTION_6 = (byte) 0xA8; + switch (b0) { + case SECTION_1: + return true; + case SECTION_2: + if (b1 >= SECTION_3 && b1 <= SECTION_4) { + return true; + } + case SECTION_5: + switch (b1) { + case SECTION_6: + return true; + } + default: + return false; + } + } + + /** + * 将IPv4地址转换成字节 + * + * @param text IPv4地址 + * @return byte 字节 + */ + public static byte[] textToNumericFormatV4(String text) { + if (text.length() == 0) { + return null; + } + + byte[] bytes = new byte[4]; + String[] elements = text.split("\\.", -1); + try { + long l; + int i; + switch (elements.length) { + case 1: + l = Long.parseLong(elements[0]); + if ((l < 0L) || (l > 4294967295L)) { + return null; + } + bytes[0] = (byte) (int) (l >> 24 & 0xFF); + bytes[1] = (byte) (int) ((l & 0xFFFFFF) >> 16 & 0xFF); + bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF); + bytes[3] = (byte) (int) (l & 0xFF); + break; + case 2: + l = Integer.parseInt(elements[0]); + if ((l < 0L) || (l > 255L)) { + return null; + } + bytes[0] = (byte) (int) (l & 0xFF); + l = Integer.parseInt(elements[1]); + if ((l < 0L) || (l > 16777215L)) { + return null; + } + bytes[1] = (byte) (int) (l >> 16 & 0xFF); + bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF); + bytes[3] = (byte) (int) (l & 0xFF); + break; + case 3: + for (i = 0; i < 2; ++i) { + l = Integer.parseInt(elements[i]); + if ((l < 0L) || (l > 255L)) { + return null; + } + bytes[i] = (byte) (int) (l & 0xFF); + } + l = Integer.parseInt(elements[2]); + if ((l < 0L) || (l > 65535L)) { + return null; + } + bytes[2] = (byte) (int) (l >> 8 & 0xFF); + bytes[3] = (byte) (int) (l & 0xFF); + break; + case 4: + for (i = 0; i < 4; ++i) { + l = Integer.parseInt(elements[i]); + if ((l < 0L) || (l > 255L)) { + return null; + } + bytes[i] = (byte) (int) (l & 0xFF); + } + break; + default: + return null; + } + } catch (NumberFormatException e) { + return null; + } + return bytes; + } + + public static String getHostIp() { + try { + return InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException e) { + } + return "127.0.0.1"; + } + + public static String getHostName() { + try { + return InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + } + return "未知"; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/sign/RSASignUtils.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/sign/RSASignUtils.java new file mode 100644 index 0000000..047dbfa --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/sign/RSASignUtils.java @@ -0,0 +1,133 @@ +package com.sso.common.utils.sign; + +import sun.misc.BASE64Decoder; +import sun.misc.BASE64Encoder; + +import java.security.KeyFactory; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.Signature; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; + +/** + * RSA 签名工具类 + */ +public class RSASignUtils { + + /** + * 加密算法RSA + */ + private static final String KEY_ALGORITHM = "RSA"; + /** + * 签名算法 + * SHA1WithRSA | MD5withRSA + */ + private static final String SIGNATURE_ALGORITHM = "SHA1WithRSA"; + + /** + * 用私钥对信息生成数字签名 + * + * @param data 数据 + * @param privateKey 私钥(BASE64编码) + * @return + * @throws Exception + */ + public static String sign(Object data, String privateKey) throws Exception { + return sign(data.toString().getBytes(), privateKey); + } + + /** + * 用私钥对信息生成数字签名 + * + * @param data 需要加签数据 + * @param privateKey 私钥(BASE64编码) + * @return + * @throws Exception + */ + public static String sign(byte[] data, String privateKey) throws Exception { + //私钥 key BASE64解密 + byte[] keyBytes = decryptBASE64(privateKey); + // 转换私钥 + PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes); + // 实例化密钥工厂 + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + // 取私钥匙对象 + PrivateKey privateK = keyFactory.generatePrivate(pkcs8KeySpec); + // 实例化Signature + Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM); + // 初始化Signature + signature.initSign(privateK); + // 更新 + signature.update(data); + // 生成签名 + return encryptBASE64(signature.sign()); +// return new String(Base64.encodeBase64(signature.sign())); + + } + + /** + * 校验数字签名 + * + * @param data 已加签的数据 + * @param publicKey 公钥(BASE64编码) + * @param sign 数字签名 + * @return + * @throws Exception + */ + public static boolean verify(Object data, String publicKey, String sign) + throws Exception { + return verify(data.toString().getBytes(), publicKey, sign); + } + + /** + * 校验数字签名 + * + * @param data 已加签的数据 + * @param publicKey 公钥(BASE64编码) + * @param sign 数字签名 + * @return + * @throws Exception + */ + public static boolean verify(byte[] data, String publicKey, String sign) + throws Exception { + //私钥 key BASE64解密 + byte[] keyBytes = decryptBASE64(publicKey); + // 转换公钥材料 + X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); + // 实例化密钥工厂 + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + // 生成公钥 + PublicKey publicK = keyFactory.generatePublic(keySpec); + // 实例化Signature + Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM); + // 初始化Signature + signature.initVerify(publicK); + // 更新 + signature.update(data); + // 验证签名 + return signature.verify(decryptBASE64(sign)); + } + + + /** + * BASE64解密 + * + * @param key + * @throws Exception + */ + public static byte[] decryptBASE64(String key) throws Exception { + return (new BASE64Decoder()).decodeBuffer(key); + } + + /** + * BASE64加密 + * + * @param key + * @throws Exception + */ + public static String encryptBASE64(byte[] key) throws Exception { + return (new BASE64Encoder()).encodeBuffer(key); + } + +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/sign/SignContentUtil.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/sign/SignContentUtil.java new file mode 100644 index 0000000..abc11bf --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/sign/SignContentUtil.java @@ -0,0 +1,67 @@ +package com.sso.common.utils.sign; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +import java.util.*; + +/** + * 统一认证中心 签名工具 + * + * @author 程序员小强 + */ +@Slf4j +public class SignContentUtil { + + /** + * 生成要加签的参数 + * + * @param paramMap + * @param removeKeys + * @return 生成要加签的参数 + */ + public static String getSignContent(Map paramMap, List removeKeys) { + //按参数名字母顺序(升序、区分大小写) + TreeMap signParamMap = getTreeMap(paramMap); + //移除签名参数 + removeKeys.forEach(signParamMap::remove); + + //待签名串(以&符逐个拼接参数名=参数值而形成) + return getSignContent(signParamMap); + } + + /** + * 以&符逐个拼接参数名=参数值而形成 + * + * @param sortedParams + */ + private static String getSignContent(Map sortedParams) { + StringBuilder content = new StringBuilder(); + ArrayList keys = new ArrayList<>(sortedParams.keySet()); + Collections.sort(keys); + int index = 0; + + for (Object o : keys) { + String key = (String) o; + String value = sortedParams.get(key); + if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(value)) { + content.append(index == 0 ? "" : "&").append(key).append("=").append(value); + ++index; + } + } + return content.toString(); + } + + /** + * 按参数名字母顺序(升序、区分大小写) + * + * @param paramMap + */ + private static TreeMap getTreeMap(Map paramMap) { + TreeMap signMap = new TreeMap<>(); + for (Map.Entry entry : paramMap.entrySet()) { + signMap.put(entry.getKey(), entry.getValue().toString()); + } + return signMap; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/tree/ListToTreeUtil.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/tree/ListToTreeUtil.java new file mode 100755 index 0000000..d590df2 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/tree/ListToTreeUtil.java @@ -0,0 +1,68 @@ +package com.sso.common.utils.tree; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * List转树形结构工具类 泛型对象必须继承 + */ +public class ListToTreeUtil { + + /** + * 获取树形结构对象 + */ + public T getTreeObject(List objectList) { + Map objectMap = new HashMap<>(); + + //第一次遍历列表,将列表转成Map + for (T object : objectList) { + objectMap.put(object.getTreeNodeId(), object); + } + + T root = null; + //第二次遍历列表,设置父子关系 + for (T object : objectList) { + //获取当前节点对象的父节点标识 + String key = object.getParentTreeNodeId(); + if (key == null || !objectMap.containsKey(key)) { + root = object; + } else { + //如果包含父节点标识的Key则获取父对象 + T parentObj = objectMap.get(key); + //将当前节点保存入父对象子节点集合中 + parentObj.getChildTreeNodes().add(object); + } + } + return root; + } + + /** + * @param nodes + * @return + */ + public List getTreeListObject(List nodes) { + List result = new ArrayList(); + Map nodeMap = new HashMap<>(); + //第一次遍历列表,将列表转成Map + for (T node : nodes) { + nodeMap.put(node.getTreeNodeId(), node); + } + //第二次遍历列表,设置父子关系 + for (T node : nodes) { + //获取当前节点对象的父节点标识 + String key = node.getParentTreeNodeId(); + if (nodeMap.containsKey(key)) { + //如果包含父节点标识的Key则获取父对象 + T parentObj = nodeMap.get(key); + //将当前节点保存入父对象子节点集合中 + parentObj.getChildTreeNodes().add(node); + } else { + //父节点标识的Key不存在表示当前节点是根节点 + result.add(node); + } + } + return result; + } +} diff --git a/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/tree/TreeParentNode.java b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/tree/TreeParentNode.java new file mode 100755 index 0000000..428a347 --- /dev/null +++ b/sso-auth-center-service/sso-common/src/main/java/com/sso/common/utils/tree/TreeParentNode.java @@ -0,0 +1,41 @@ +package com.sso.common.utils.tree; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +/** + * 通过id/ParentId方式 + * 实现树形结构的List转树形结构的定义接口 + * + * @author 程序员小强 + */ +public interface TreeParentNode { + + /** + * 获取树形结构当前节点的标识 + * 注:不参与 json序列化 + * + * @return + */ + @JSONField(serialize = false) + String getTreeNodeId(); + + /** + * 获取树形结构当前节点父节点的标识 + * 注:不参与 json序列化 + * + * @return + */ + @JSONField(serialize = false) + String getParentTreeNodeId(); + + /** + * 获取树形结构当前节点的所有子节点 + * 注:不参与 json序列化 + * + * @return + */ + @JSONField(serialize = false) + List getChildTreeNodes(); +} diff --git a/sso-auth-center-service/sso-framework/pom.xml b/sso-auth-center-service/sso-framework/pom.xml new file mode 100755 index 0000000..b6db1c3 --- /dev/null +++ b/sso-auth-center-service/sso-framework/pom.xml @@ -0,0 +1,65 @@ + + + + com.sso + sso-auth-center-service + 1.0.0 + + 4.0.0 + sso-framework + + + framework 框架核心 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-starter-aop + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + + + + + com.alibaba + druid-spring-boot-starter + + + + redis.clients + jedis + + + + + com.github.penggle + kaptcha + + + javax.servlet-api + javax.servlet + + + + + + + com.sso + sso-common + + + + diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/advice/ExceptionAdvice.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/advice/ExceptionAdvice.java new file mode 100644 index 0000000..eed7a94 --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/advice/ExceptionAdvice.java @@ -0,0 +1,91 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.framework.advice; + +import cn.hutool.core.date.DateException; +import com.sso.common.exception.BaseException; +import com.sso.common.model.result.ResultModel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.validation.BindException; +import org.springframework.validation.FieldError; +import org.springframework.web.HttpMediaTypeNotSupportedException; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletResponse; +import java.util.Objects; + + +/** + * 全局统一异常处理 + * + * @author 程序员小强 + * @version ExceptionAdvice.java, v 1.0 + */ +@Slf4j +@ControllerAdvice +@EnableAspectJAutoProxy +public class ExceptionAdvice { + + + @CrossOrigin + @ResponseBody + @ExceptionHandler(value = Exception.class) + public ResultModel exceptionHandler(Exception exception, HttpServletResponse response) throws Exception { + ResultModel result = ResultModel.error("系统繁忙,请稍后再试"); + try { + throw exception; + } catch (BaseException e) { + log.error("自定义异常 msg:{}", e.getMessage()); + result = ResultModel.error(e.getMessage()); + } catch (MethodArgumentNotValidException argEx) { + FieldError fieldError = argEx.getBindingResult().getFieldError(); + String errorMsg = String.format("%s >> %s", fieldError.getField(), + fieldError.getDefaultMessage()); + log.error("参数校验异常 >> {}", errorMsg); + result = ResultModel.error(errorMsg); + } catch (BindException argEx) { + FieldError fieldError = argEx.getBindingResult().getFieldError(); + String errorMsg = String.format("%s >> %s", fieldError.getField(), + fieldError.getDefaultMessage()); + log.error("参数校验异常 >> {}", errorMsg); + result = ResultModel.error(errorMsg); + } catch (DateException argex) { + log.error("时间格式化参数校验异常 >> {}", argex.getMessage()); + result = ResultModel.error(argex.getMessage()); + } catch (HttpRequestMethodNotSupportedException e) { + String errorMsg = String.format("请求方式 %s 错误 ! 请使用 %s 方式", e.getMethod(), e.getSupportedHttpMethods()); + result = ResultModel.error(errorMsg); + log.error("请求方式异常 stack= ", e); + } catch (HttpMediaTypeNotSupportedException e) { + String errorMsg = String.format("请求类型 %s 错误 ! 请使用 %s 方式", e.getContentType(), e.getSupportedMediaTypes()); + result = ResultModel.error(errorMsg); + log.error("请求方式异常, {} ", errorMsg); + } catch (AccessDeniedException e) { + log.error("权限不足异常 >> ", e); + result = ResultModel.error("权限不足,请联系管理员授权"); + } catch (HttpMessageNotReadableException e) { + String jsonParseError = "JSON parse error"; + String bodyMissing = "Required request body is missing"; + if (Objects.requireNonNull(e.getMessage()).startsWith(bodyMissing)) { + result = ResultModel.error("参数异常,缺少请求body"); + } else if (Objects.requireNonNull(e.getMessage()).startsWith(jsonParseError)) { + result = ResultModel.error("JSON参数格式化异常"); + } + log.error("参数异常 >> ", e); + } catch (Exception e) { + log.error("未知异常 >> ", e); + } + return result; + } + +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/JedisConfig.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/JedisConfig.java new file mode 100644 index 0000000..490e030 --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/JedisConfig.java @@ -0,0 +1,57 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.framework.config; + +import com.sso.framework.config.property.RedisConfigProperty; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; + +import javax.annotation.Resource; + + +/** + * jedis 配置类 + * + * @author 程序员小强iang + * @version JedisConfig.java, v 1.0 + */ +@Slf4j +@Configuration +public class JedisConfig extends CachingConfigurerSupport { + + @Resource + private RedisConfigProperty redisConfigProperty; + + /** + * 连接池配置 + */ + @Bean(name = "jedisPoolConfig") + @ConfigurationProperties(prefix = "spring.redis.pool-config") + public JedisPoolConfig getRedisConfig() { + return new JedisPoolConfig(); + } + + /** + * jedis 连接池 + */ + @Bean(name = "jedisPool") + public JedisPool jedisPool(@Qualifier(value = "jedisPoolConfig") final JedisPoolConfig jedisPoolConfig) { + log.info("Jedis Pool build start "); + String host = redisConfigProperty.getHost(); + int timeout = redisConfigProperty.getTimeout(); + int port = redisConfigProperty.getPort(); + String password = redisConfigProperty.getPassword(); + int database = redisConfigProperty.getDatabase(); + JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password, database); + log.info("Jedis Pool build success host = {} , port = {} ", host, port); + return jedisPool; + } +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/ResourcesConfig.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/ResourcesConfig.java new file mode 100755 index 0000000..9675659 --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/ResourcesConfig.java @@ -0,0 +1,50 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.framework.config; + +import com.sso.common.constant.SsoConstants; +import com.sso.framework.config.property.SysConfigProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * 通用配置 + * + * @author 程序员小强 + */ +@Configuration +public class ResourcesConfig implements WebMvcConfigurer { + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + /// 文件上传路径 + registry.addResourceHandler(SsoConstants.RESOURCE_PREFIX + "/**").addResourceLocations("file:" + SysConfigProperty.getFileProfile() + "/"); + registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); + } + + /** + * 跨域配置 + */ + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + // 设置访问源地址 + config.addAllowedOrigin("*"); + // 设置访问源请求头 + config.addAllowedHeader("*"); + // 设置访问源请求方法 + config.addAllowedMethod("*"); + // 对接口配置跨域设置 + source.registerCorsConfiguration("/**", config); + return new CorsFilter(source); + } +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/captcha/CaptchaConfig.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/captcha/CaptchaConfig.java new file mode 100755 index 0000000..33efcd5 --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/captcha/CaptchaConfig.java @@ -0,0 +1,87 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.framework.config.captcha; + +import com.google.code.kaptcha.impl.DefaultKaptcha; +import com.google.code.kaptcha.util.Config; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Properties; + +import static com.google.code.kaptcha.Constants.*; + +/** + * 验证码配置 + * + * @author 程序员小强 + */ +@Configuration +public class CaptchaConfig { + + @Bean(name = "captchaProducer") + public DefaultKaptcha getKaptchaBean() { + DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); + Properties properties = new Properties(); + // 是否有边框 默认为true 我们可以自己设置yes,no + properties.setProperty(KAPTCHA_BORDER, "yes"); + // 验证码文本字符颜色 默认为Color.BLACK + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "black"); + // 验证码图片宽度 默认为200 + properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); + // 验证码图片高度 默认为50 + properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); + // 验证码文本字符大小 默认为40 + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "38"); + // KAPTCHA_SESSION_KEY + properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCode"); + // 验证码文本字符长度 默认为5 + properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4"); + // 验证码文本字体样式 默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); + // 图片样式 水纹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy + properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); + Config config = new Config(properties); + defaultKaptcha.setConfig(config); + return defaultKaptcha; + } + + @Bean(name = "captchaProducerMath") + public DefaultKaptcha getKaptchaBeanMath() { + DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); + Properties properties = new Properties(); + // 是否有边框 默认为true 我们可以自己设置yes,no + properties.setProperty(KAPTCHA_BORDER, "yes"); + // 边框颜色 默认为Color.BLACK + properties.setProperty(KAPTCHA_BORDER_COLOR, "105,179,90"); + // 验证码文本字符颜色 默认为Color.BLACK + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "blue"); + // 验证码图片宽度 默认为200 + properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); + // 验证码图片高度 默认为50 + properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); + // 验证码文本字符大小 默认为40 + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "35"); + // KAPTCHA_SESSION_KEY + properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath"); + // 验证码文本生成器 + properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.sso.framework.config.captcha.KaptchaTextCreator"); + // 验证码文本字符间距 默认为2 + properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3"); + // 验证码文本字符长度 默认为5 + properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "6"); + // 验证码文本字体样式 默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); + // 验证码噪点颜色 默认为Color.BLACK + properties.setProperty(KAPTCHA_NOISE_COLOR, "white"); + // 干扰实现类 + properties.setProperty(KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.NoNoise"); + // 图片样式 水纹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy + properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); + Config config = new Config(properties); + defaultKaptcha.setConfig(config); + return defaultKaptcha; + } +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/captcha/KaptchaTextCreator.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/captcha/KaptchaTextCreator.java new file mode 100755 index 0000000..80e0365 --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/captcha/KaptchaTextCreator.java @@ -0,0 +1,65 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.framework.config.captcha; + +import com.google.code.kaptcha.text.impl.DefaultTextCreator; + +import java.util.Random; + +/** + * 验证码文本生成器 + * + * @author 程序员小强 + */ +public class KaptchaTextCreator extends DefaultTextCreator { + private static final String[] CNUMBERS = "0,1,2,3,4,5,6,7,8,9,10".split(","); + + @Override + public String getText() { + Integer result = 0; + Random random = new Random(); + int x = random.nextInt(10); + int y = random.nextInt(10); + StringBuilder suChinese = new StringBuilder(); + int randomoperands = (int) Math.round(Math.random() * 2); + if (randomoperands == 0) { + result = x * y; + suChinese.append(CNUMBERS[x]); + suChinese.append("*"); + suChinese.append(CNUMBERS[y]); + } else if (randomoperands == 1) { + if (!(x == 0) && y % x == 0) { + result = y / x; + suChinese.append(CNUMBERS[y]); + suChinese.append("/"); + suChinese.append(CNUMBERS[x]); + } else { + result = x + y; + suChinese.append(CNUMBERS[x]); + suChinese.append("+"); + suChinese.append(CNUMBERS[y]); + } + } else if (randomoperands == 2) { + if (x >= y) { + result = x - y; + suChinese.append(CNUMBERS[x]); + suChinese.append("-"); + suChinese.append(CNUMBERS[y]); + } else { + result = y - x; + suChinese.append(CNUMBERS[y]); + suChinese.append("-"); + suChinese.append(CNUMBERS[x]); + } + } else { + result = x + y; + suChinese.append(CNUMBERS[x]); + suChinese.append("+"); + suChinese.append(CNUMBERS[y]); + } + suChinese.append("=?@" + result); + return suChinese.toString(); + } +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/datasource/DataSourceConfig.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/datasource/DataSourceConfig.java new file mode 100755 index 0000000..c79237a --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/datasource/DataSourceConfig.java @@ -0,0 +1,98 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.framework.config.datasource; + +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; +import org.apache.ibatis.session.ExecutorType; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.SqlSessionTemplate; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; + +import javax.sql.DataSource; +import java.sql.SQLException; + +/** + * 后台系统数据源 > 配置 + * + * @author 程序员小强 + */ +@Configuration +@MapperScan(basePackages = {"com.sso.dao.mapper"}, sqlSessionTemplateRef = "adminSqlSessionTemplate") +public class DataSourceConfig { + + /** + * 数据源配置 + * 使用的连接池是 DruidDataSource + *

+ * 注解ConfigurationProperties + * 作用就是将全局配置文件中的属性值注入到DruidDataSource 的同名参数 + */ + @Primary + @Bean(name = "adminDataSource") + @Qualifier("adminDataSource") + @ConfigurationProperties(prefix = "spring.datasource.admin") + public DataSource adminDataSource() throws SQLException { + DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); + dataSource.setFilters("stat,wall,slf4j"); + return dataSource; + } + + /** + * 创建 SqlSessionFactory 工厂 + */ + @Primary + @Bean(name = "adminSqlSessionFactory") + public SqlSessionFactory adminSqlSessionFactory(@Qualifier("adminDataSource") DataSource dataSource) throws Exception { + org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(); + //全局映射器启用缓存 + configuration.setCacheEnabled(true); + //使用jdbc的getGeneratedKeys获取数据库自增主键值 + configuration.setUseGeneratedKeys(true); + //配置默认的执行器 + configuration.setDefaultExecutorType(ExecutorType.REUSE); + //configuration.setLogImpl(SLF4JImpl.class); + //使用列别名替换列名 select user as User + configuration.setUseColumnLabel(true); + //设置启用数据库字段下划线映射到java对象的驼峰式命名属性 + configuration.setMapUnderscoreToCamelCase(true); + + SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean(); + sqlSessionFactory.setDataSource(dataSource); + + sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/mybatis/**/*Mapper.xml")); + sqlSessionFactory.setConfiguration(configuration); + + return sqlSessionFactory.getObject(); + } + + /** + * 事务管理 + */ + @Primary + @Bean(name = "adminTransactionManager") + public DataSourceTransactionManager adminTransactionManager(@Qualifier("adminDataSource") DataSource dataSource) { + return new DataSourceTransactionManager(dataSource); + } + + /** + * MyBatis提供的持久层访问模板化的工具 + * 线程安全,可通过构造参数或依赖注入SqlSessionFactory实例 + */ + @Primary + @Bean(name = "adminSqlSessionTemplate") + public SqlSessionTemplate adminSqlSessionTemplate(@Qualifier("adminSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception { + return new SqlSessionTemplate(sqlSessionFactory); + } + +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/property/RedisConfigProperty.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/property/RedisConfigProperty.java new file mode 100644 index 0000000..f91ef9b --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/property/RedisConfigProperty.java @@ -0,0 +1,45 @@ +package com.sso.framework.config.property; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + + +/** + * redis 配置属性类 + * + * @author 程序员小强iang + * @version RedisConfigProperty.java, v 1.0 + */ +@Setter +@Getter +@Component +@ConfigurationProperties(prefix = "spring.redis") +public class RedisConfigProperty { + + /** + * 服务地址 + */ + private String host; + + /** + * 连接密码(默认为空) + */ + private String password; + + /** + * 数据库索引(默认为0) + */ + private int database; + + /** + * 端口 + */ + private int port; + + /** + * 连接超时时间(毫秒) + */ + private int timeout; +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/property/SysConfigProperty.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/property/SysConfigProperty.java new file mode 100755 index 0000000..b522275 --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/config/property/SysConfigProperty.java @@ -0,0 +1,121 @@ +package com.sso.framework.config.property; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * 系统配置属性 + * + * @author 程序员小强 + */ +@Component +@ConfigurationProperties(prefix = "sys.config") +public class SysConfigProperty { + + /** + * 认证中心登录地址 + */ + private String ssoLoginUrl; + + /** + * 验证码类型 + * 可选 math , char + */ + private String captchaType; + + /** + * 令牌自定义标识 + */ + private String tokenHeader; + + /** + * 令牌秘钥 + */ + private String tokenSecret; + + /** + * 认证中心系统编码 + */ + private String authSsoSysCode; + + /** + * 超级管理员用户(用户名|ID) + */ + private String supperAdminUser; + + /** + * 令牌有效期(默认60分钟) + */ + private int tokenExpireTime = 60; + + /** + * 文件上传父路径 + */ + private static String fileProfile; + + + public String getSsoLoginUrl() { + return ssoLoginUrl; + } + + public void setSsoLoginUrl(String ssoLoginUrl) { + this.ssoLoginUrl = ssoLoginUrl; + } + + public String getCaptchaType() { + return captchaType; + } + + public void setCaptchaType(String captchaType) { + this.captchaType = captchaType; + } + + public String getTokenHeader() { + return tokenHeader; + } + + public void setTokenHeader(String tokenHeader) { + this.tokenHeader = tokenHeader; + } + + public String getTokenSecret() { + return tokenSecret; + } + + public void setTokenSecret(String tokenSecret) { + this.tokenSecret = tokenSecret; + } + + public int getTokenExpireTime() { + return tokenExpireTime; + } + + public String getAuthSsoSysCode() { + return authSsoSysCode; + } + + public void setAuthSsoSysCode(String authSsoSysCode) { + this.authSsoSysCode = authSsoSysCode; + } + + public String getSupperAdminUser() { + return supperAdminUser; + } + + public void setSupperAdminUser(String supperAdminUser) { + this.supperAdminUser = supperAdminUser; + } + + public void setTokenExpireTime(int tokenExpireTime) { + this.tokenExpireTime = tokenExpireTime; + } + + public static String getFileProfile() { + return fileProfile; + } + + public void setFileProfile(String fileProfile) { + SysConfigProperty.fileProfile = fileProfile; + } + +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/context/ApplicationContextHelper.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/context/ApplicationContextHelper.java new file mode 100644 index 0000000..b7642ec --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/context/ApplicationContextHelper.java @@ -0,0 +1,40 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.framework.context; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +import java.lang.annotation.Annotation; +import java.util.Map; + +/** + * 从applicationContext中得到Bean 工具类 + * + * @author 程序员小强 + */ +@Component +public class ApplicationContextHelper implements ApplicationContextAware { + private static ApplicationContext context; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) { + context = applicationContext; + } + + public static ApplicationContext getContext() { + return context; + } + + public static Object getBean(String beanName) { + return context != null ? context.getBean(beanName) : null; + } + + public static Map getBeansWithAnnotation(Class var1) { + return context != null ? context.getBeansWithAnnotation(var1) : null; + } + +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/gateway/ApiContainer.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/gateway/ApiContainer.java new file mode 100644 index 0000000..3fdc3b9 --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/gateway/ApiContainer.java @@ -0,0 +1,15 @@ +package com.sso.framework.gateway; + +import org.springframework.stereotype.Service; + +import java.util.HashMap; + +/** + * Api 初始化容器 + * + * @author 程序员小强 + */ +@Service +public class ApiContainer extends HashMap { + +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/gateway/ApiModel.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/gateway/ApiModel.java new file mode 100644 index 0000000..ba06e68 --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/gateway/ApiModel.java @@ -0,0 +1,39 @@ +package com.sso.framework.gateway; + +import lombok.Data; + +import java.io.Serializable; +import java.lang.reflect.Method; + + +/** + * api接口对象 + * + * @author 程序员小强 + */ +@Data +public class ApiModel implements Serializable { + + private static final long serialVersionUID = -1090071353564966615L; + + /** + * 类 spring bean + */ + private String beanName; + + /** + * 方法对象 + */ + private Method method; + + /** + * 业务参数 + */ + private String paramName; + + public ApiModel(String beanName, Method method, String paramName) { + this.beanName = beanName; + this.method = method; + this.paramName = paramName; + } +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/gateway/ApiScanner.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/gateway/ApiScanner.java new file mode 100644 index 0000000..900af77 --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/gateway/ApiScanner.java @@ -0,0 +1,113 @@ +package com.sso.framework.gateway; + +import com.sso.common.annotation.OpenApi; +import com.sso.common.annotation.OpenApiService; +import com.sso.framework.context.ApplicationContextHelper; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.CommandLineRunner; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.stereotype.Component; +import org.springframework.util.ReflectionUtils; + +import javax.annotation.Resource; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Api接口扫描器 + * + * @author 程序员小强 + */ +@Component +public class ApiScanner implements CommandLineRunner { + + private static final Logger LOGGER = LoggerFactory.getLogger(ApiScanner.class); + + /** + * 方法签名拆分正则 + */ + private static final Pattern PATTERN = Pattern.compile("\\s+(.*)\\s+((.*)\\.(.*))\\((.*)\\)", Pattern.DOTALL); + + /** + * 参数分隔符 + */ + private static final String PARAMS_SEPARATOR = ","; + + /** + * 统计扫描次数 + */ + private final AtomicInteger atomicInteger = new AtomicInteger(0); + + @Resource + private ApiContainer apiContainer; + + @Override + public void run(String... var1) throws Exception { + //扫描所有使用@OpeApiService注解的类 + Map openApiServiceBeanMap = ApplicationContextHelper.getBeansWithAnnotation(OpenApiService.class); + + if (null == openApiServiceBeanMap || openApiServiceBeanMap.isEmpty()) { + LOGGER.info("open api service bean map is empty"); + return; + } + + for (Map.Entry map : openApiServiceBeanMap.entrySet()) { + //获取扫描类下所有方法 + Method[] methods = ReflectionUtils.getAllDeclaredMethods(map.getValue().getClass()); + for (Method method : methods) { + atomicInteger.incrementAndGet(); + //找到带有OpenApi 注解的方法 + OpenApi openApi = AnnotationUtils.findAnnotation(method, OpenApi.class); + if (null == openApi) { + continue; + } + //获取业务参数对象 + String paramName = getParamName(method); + if (StringUtils.isBlank(paramName)) { + LOGGER.warn("Api开放接口业务参数缺失 >> method = {}", openApi.method()); + continue; + } + + //组建ApiModel- 放入api容器 + apiContainer.put(openApi.method(), new ApiModel(map.getKey(), method, paramName)); + LOGGER.info("Api开放接口加载成功 >> method = {} , desc={}", openApi.method(), openApi.desc()); + } + } + LOGGER.info("Api开放接口容器加载完毕 >> size = {} loopTimes={}", apiContainer.size(), atomicInteger.get()); + } + + /** + * 获取业务参数对象 + * + * @param method + * @return + */ + private String getParamName(Method method) { + ArrayList result = new ArrayList<>(); + final Matcher matcher = PATTERN.matcher(method.toGenericString()); + if (matcher.find()) { + int groupCount = matcher.groupCount() + 1; + for (int i = 0; i < groupCount; i++) { + result.add(matcher.group(i)); + } + } + + //获取参数部分 + if (result.size() >= 6) { + String[] params = + StringUtils.splitByWholeSeparatorPreserveAllTokens(result.get(5), PARAMS_SEPARATOR); + if (params.length >= 2) { + return params[params.length - 1]; + } + } + return null; + + } + +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/RedisCache.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/RedisCache.java new file mode 100644 index 0000000..56d1d42 --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/RedisCache.java @@ -0,0 +1,848 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.framework.redis; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +/** + * jedis 操作redis 方封装 + *

+ * 大致内容如下,常用的方法 + * 1.string 相关操作 + * 2.set + * 3.list + * 4.hash + * 5.zset + * 6.管道查询Pipeline + * 7.发布订阅 + * + * @author menq + */ +public interface RedisCache { + + /* ------------------ string 类型相关操作--------------------------------*/ + + /** + * 添加数据到redis + * 注意:设置默认过期时间 30 分钟 + * + * @param key + * @param value + */ + Boolean set(String key, Object value); + + /** + * 添加数据到redis + * 自定义过期时间 + * 注:从 Redis 2.6.12 版本开始, SET 在设置操作成功完成时,返回 OK + * + * @param key + * @param value + * @param duration 时间量 + * @param timeUnit 时间单位枚举 + */ + Boolean set(String key, Object value, int duration, TimeUnit timeUnit); + + /** + * 添加数据到redis + * 并设置永不过期 + * 注:一般使用较少,数据过大时尽量不要使用 + * 从 Redis 2.6.12 版本开始, SET 在设置操作成功完成时,返回 OK + * + * @param key + * @param value + */ + Boolean putNeverExpires(String key, Object value); + + /** + * 根据key 获取值 + * + * @param key + * @param clazz 类class + * @return 类对象 + */ + T get(String key, Class clazz); + + /** + * 根据key集合批量获取 + * + * @param keys key集合 + * @param classz 序列化对象 + * @return 类对象 + */ + List mget(List keys, Class classz); + + /** + * 根据key 获取值 + * 返回 key 的值,如果 key 不存在时,返回 nil。 + * 如果 key 不是字符串类型,那么返回一个错误。 + * + * @param key + * @return String + */ + String get(String key); + + /** + * 根据key 获取值 + * + * @param key + * @param clazz 集合泛型对象 + * @return 集合对象 + */ + List getList(String key, Class clazz); + + /** + * 将key 的值设为 value ,当且仅当 key 不存在 + * 默认值是时间戳 默认有效期是 5 分钟 + * + * @param key + * @return 设置成功返回 true 失败返回false + */ + Boolean setNx(String key); + + /** + * 将key 的值设为 value ,当且仅当 key 不存在 + * 注意!!:默认有效期是 5 分钟 + * + * @param key + * @param value 自定义值 + * @return 设置成功返回 true 失败返回false + */ + Boolean setNx(String key, Object value); + + /** + * 将key 的值设为 value ,当且仅当 key 不存在 + * 默认值是时间戳 + * + * @param key + * @param seconds 自定义过期时间秒数 + * @return 设置成功返回 true 失败返回false + */ + Boolean setNx(String key, int seconds); + + /** + * 将key 的值设为 value ,当且仅当 key 不存在 + * 默认时间单位是秒 + * + * @param key + * @param value 自定义 value + * @param seconds 自定义过期时间秒数 + * @return 设置成功返回 true 失败返回false + */ + Boolean setNx(String key, Object value, int seconds); + + /** + * 将key 的值设为 value ,当且仅当 key 不存在 + * 注:常用与分布式锁 + * + * @param key + * @param value + * @param duration 时间量 + * @param timeUnit 时间单位枚举 + * @return 设置成功返回 true 失败返回false + */ + Boolean setNx(String key, Object value, int duration, TimeUnit timeUnit); + + /** + * 设置指定 key 的值,并返回 key 的旧值 + * 返回给定 key 的旧值。 当 key 没有旧值时,即 key 不存在时,返回 null + * 注意!!:默认有效期为 5分钟 + * + * @param key + * @return String + */ + String getSet(String key, String value); + + /** + * 设置指定 key 的值,并返回 key 的旧值 + * 返回给定 key 的旧值。 当 key 没有旧值时,即 key 不存在时,返回 null + * + * @param key + * @return string key 的旧值 + */ + String getSet(String key, String value, int duration, TimeUnit timeUnit); + + /** + * 用于获取指定 key 所储存的字符串值的长度 + * 当 key 储存的不是字符串值时,返回一个错误 + * 当 key 不存在时,返回 0 + * + * @param key + */ + Long getStrLen(String key); + + /** + * key 中储存的数字值增一 (默认增量+1) + * + * @param key + * @return 执行命令之后 key 的值。 + */ + Long incr(String key); + + /** + * key 中储存的数字值增一 (自定义增量值 ) + * + * @param key + * @param value 自定义增量值 + * @return 执行命令之后 key 的值。 + */ + Long incrBy(String key, long value); + + /** + * 为 key 中所储存的值加上指定的浮点数增量值 + * 如果 key 不存在,那么 incrbyfloat 会先将 key 的值设为 0 ,再执行加法操作 + * + * @param key + * @param value 增量值 + * @return 执行命令之后 key 的值 + */ + Double incrByFloat(String key, Double value); + + /** + * 将 key 中储存的数字值减一 + * + * @param key + * @return 执行命令之后 key 的值 + */ + Long decr(String key); + + /** + * 将 key 中储存的数字值减自定义减量 + * + * @param key + * @param value 自定义减量值 + * @return 执行命令之后 key 的值。 + */ + Long decrBy(String key, long value); + + /** + * 用于为指定的 key 追加值 + * + * @param key + * @param value + * @return 追加指定值之后, key 中字符串的长度 + */ + Long append(String key, Object value); + + + /* ------------------ key 相关操作--------------------------------*/ + + /** + * 检查给定 key 是否存在 + * + * @param key + * @return 是否存在 + */ + Boolean exists(String key); + + /** + * 用于设置 key 的过期时间, + * key 过期后将不再可用。单位以秒计 + * + * @param key + * @param seconds + * @return 是否设置成功 + */ + Boolean expire(String key, int seconds); + + /** + * 用于设置 key 的过期时间,key 过期后将不再可用 + * 设置成功返回 1 + * 当 key 不存在或者不能为 key 设置过期时间时返回 + * + * @param key + * @param duration 时间量与单位一起使用 + * @param timeUnit 单位枚举类 + */ + Boolean expire(String key, int duration, TimeUnit timeUnit); + + /** + * 根据key 获取过期时间秒数 + * 不存在时返回负数 + * + * @param key + * @return 剩余过期时间秒数 + * 当 key 不存在时,返回 -2 。 + * 当 key 存在但没有设置剩余生存时间时,返回 -1 + * 否则,以秒为单位,返回 key 的剩余生存时间 + */ + Long getExpiresTtl(String key); + + /** + * 根据key 获取过期时间毫秒数 + * 不存在时返回负数 + * + * @param key + * @return 剩余过期时间毫秒数 + * 当 key 不存在时,返回 -2 + * 当 key 存在但没有设置剩余生存时间时,返回 -1 + * 否则,以毫秒为单位,返回 key 的剩余生存时间 + */ + Long getExpiresPttl(String key); + + /** + * 移除 key 的过期时间,key 将持久保持。 + * 当过期时间移除成功时,返回 1 + * 如果 key 不存在或 key 没有设置过期时间,返回 0 + * + * @param key + */ + Boolean persist(String key); + + /** + * 根据key 获取存储类型 + * + * @param key + * @return 返回 key 的数据类型 + */ + String getType(String key); + + /** + * 用于删除已存在的键。不存在的 key 会被忽略 + * 被删除 key 的数量 + * + * @param key + */ + Long del(String key); + + /* ------------------ set 类型相关操作--------------------------------*/ + + /** + * 向集合添加元素 + * 被添加到集合中的新元素的数量,不包括被忽略的元素。 + * + * @param key + */ + Long sAdd(String key, Object value); + + /** + * 移除集合中元素 + * 被成功移除的元素的数量,不包括被忽略的元素。 + * + * @param key + */ + Long sRem(String key, Object value); + + /** + * 获取集合的成员数 + * 被成功移除的元素的数量,不包括被忽略的元素。 + * + * @param key + * @return 集合的数量。 当集合 key 不存在时,返回 0 。 + */ + Long sCard(String key); + + /** + * 判断 value 元素是否是集合 key 的成员 + * 如果成员元素是集合的成员,返回 1 。 如果成员元素不是集合的成员,或 key 不存在,返回 0 。 + * + * @param key + */ + Boolean sisMember(String key, Object value); + + /** + * 返回集合中的所有成员 + * + * @param key + */ + Set sMembers(String key, Class clazz); + + /** + * 返回集合随机count个值 + * + * @param key + */ + Set sRandMember(String key, Class clazz, int count); + + /** + * 返回给定集合的交集 + * + * @param keys + */ + Set sinter(Set keys, Class clazz); + + /** + * 返回给定集合的并集 + * + * @param keys + */ + Set sunion(Set keys, Class clazz); + + /** + * 返回给定集合的差集 + * + * @param keys + */ + Set sDiff(List keys, Class clazz); + + /** + * 移除并返回集合中的一个随机元素 + * + * @param key + */ + T sPop(String key, Class clazz); + + /* ------------------ list 相关操作--------------------------------*/ + + /** + * Redis Rpush 命令用于将一个或多个值插入到列表的尾部(最右边)。 + *

+ * 如果列表不存在,一个空列表会被创建并执行 RPUSH 操作。 当列表存在但不是列表类型时,返回一个错误。 + *

+ * 注意:在 Redis 2.4 版本以前的 RPUSH 命令,都只接受单个 value 值。 + * + * @param key + * @return 列表的长度。 + */ + Long lRpushObject(String key, Object... value); + + /** + * 移除列表元素 + * 移除列表中与参数 VALUE 相等的元素 + * + * @param key + * @return 被移除元素的数量。 列表不存在时返回 0 + * 根据count值,从列表中删除所有value相等的项 + * (1) count>0 , 删除从左到右,最多count个value相等的项 + * (2) count<0 ,删除从右到左,最多count绝对值个value相等的项 + * (3) count=0 ,删除所有value相等的项 + */ + Long lRem(String key, Object value); + + /** + * 将一个或多个值插入到列表头部 + * 如果 key 不存在,一个空列表会被创建并执行 LPUSH 操作 + * 当 key 存在但不是列表类型时,返回一个错误 + * 注意:在Redis 2.4版本以前的 lpush 命令,都只接受单个 value 值 + * + * @param key + * @return 列表的长度。 + */ + Long lPush(String key, Object value); + + /** + * 通过索引来设置元素的值。 + * 当索引参数超出范围,或对一个空列表进行 LSET 时,返回一个错误。 + * 操作成功返回 ok ,否则返回错误信息。 + * + * @param key + * @return 操作是否成功 + */ + Boolean lset(String key, long index, Object value); + + /** + * 将一个或多个值插入到列表尾部 + * 如果 key 不存在,一个空列表会被创建并执行 RPUSH 操作 + * 当 key 存在但不是列表类型时,返回一个错误 + * + * @param key + * @return 列表的长度。 + */ + Long rpush(String key, Object value); + + /** + * 对一个列表进行修剪(trim) + * 让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除 + * + * @param key + * @param start 保留区间开始下标 + * @param end 保留区间结束下标 + * @return 是否成功 + */ + Boolean lTrim(String key, long start, long end); + + /** + * 用于返回列表的长度 + * 如果列表 key 不存在,则 key 被解释为一个空列表, + * 返回 0 。 如果 key 不是列表类型,返回一个错误 + * + * @param key + * @return list 集大小 + */ + long lLen(String key); + + + /** + * 通过索引获取列表中的元素 + * 如果指定索引值不在列表的区间范围内,返回 null + * 使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。 + * + * @param key + * @param index 集合索引 + * @return 元素信息 + */ + T lIndex(String key, int index, Class clazz); + + /** + * 返回列表中指定区间内的字符串 元素 + * 区间以偏移量 START 和 END 指定。 其中 0 表示列表的第一个元素, 1 表示列表的第二个元素 + * 可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推 + * + * @param key + * @param start 开始位置 + * @param end 结束位置 + * @return 相应对象集合 + */ + List lRange(String key, int start, int end); + + + /** + * 返回列表中指定区间内的元素 + * 区间以偏移量 START 和 END 指定。 其中 0 表示列表的第一个元素, 1 表示列表的第二个元素 + * 可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推 + * + * @param key + * @param clazz + * @param start 开始位置 + * @param end 结束位置 + * @return 相应对象集合 + */ + List lRange(String key, Class clazz, int start, int end); + + /** + * 移除并返回列表的第一个元素 + * + * @param key + * @return 列表的第一个元素。 当列表 key 不存在时,返回 null + */ + T lPop(String key, Class clazz); + + T rPop(String key, Class clazz); + + + /* ------------------ hash 相关操作--------------------------------*/ + + + /** + * 用于查看哈希表的指定字段是否存在 + * + * @param key + * @param field + */ + Boolean hexists(String key, String field); + + /** + * 用于为哈希表中的字段赋值 + * 如果哈希表不存在,一个新的哈希表被创建并进行 HSET 操作 + * 如果字段已经存在于哈希表中,旧值将被覆盖 + * + * @param key + * @param field + * @param value 值 + * 注:仅在field不存在,并成功添加时返回 true, + * field已经存在,会更新内容,但添加状态是false + */ + Boolean hSet(String key, String field, Object value); + + Boolean hSet(String key, String field, Object value, int duration, TimeUnit timeUnit); + + /** + * 用于为哈希表中不存在的的字段赋值 + * 如果哈希表不存在,一个新的哈希表被创建并进行 HSET 操作 + * 如果字段已经存在于哈希表中,操作无效 + * 如果 key 不存在,一个新哈希表被创建并执行 HSETNX 命令 + * 设置成功,返回 1 。 如果给定字段已经存在且没有操作被执行,返回 0 。 + * 注意版本 >= 2.0.0 + * + * @param key + * @param field + * @param value 值 + * @return 是否成功 + */ + Boolean hSetNx(String key, String field, Object value); + + + /** + * key 中HASH储存的数字值增一 (自定义增量值 ) + * + * @param key + * @param field 属性名称 + * @return 执行命令之后 key 的值。 + */ + Long hashIncr(String key, String field); + + /** + * key 中HASH储存的数字值增一 (自定义增量值 ) + * + * @param key + * @param value 自定义增量值 + * @return 执行命令之后 key 的值。 + */ + Long hashIncrBy(String key, String field, long value); + + /** + * key 中HASH储存的数字值增一 (自定义增量值 ) + * + * @param key + * @param value 自定义增量值 + * @return 执行命令之后 key 的值。 + */ + Double hashIncrByFloat(String key, String field, Double value); + + /** + * 获取存储在哈希表中指定字段的值 + * + * @param key + * @param field + * @return 返回给定字段的值。如果给定的字段或 key 不存在时,返回 null + */ + T hGet(String key, String field, Class clazz); + + /** + * 根据key集合批量获取 + * + * @param key key集合 + * @param fields field集合 + * @param classz 序列化对象 + * @return 类对象 + */ + List hmget(String key, List fields, Class classz); + + /** + * 用于删除哈希表 key 中的个指定字段 + * + * @param key + * @param field + * @return 被成功删除字段的数量,不包括被忽略的字段 + */ + Long hdel(String key, String field); + + /** + * 获取hash 大小 + * + * @param key + */ + Long hlen(String key); + + /** + * 获取在哈希表中指定 key 的所有字段和值 + * + * @param key + * @return 以列表形式返回哈希表的字段及字段值。 若 key 不存在,返回空列表。 + */ + Map hgetAll(String key, Class clazz); + + /** + * 获取在哈希表中指定 key 的所有field的值 + * + * @param key + * @return 若 key 不存在,返回空列表。 + */ + List hvals(String key, Class clazz); + + /** + * 返回hash key 对应所有field + * + * @param key + * @return 当 key 不存在时,返回一个空表。 + */ + Set hkeys(String key); + + /** + * 获取Hash下所有数据 + * + * @param hashKey + */ + Map hgetall(String hashKey); + + + /* ------------------ zset 相关操作--------------------------------*/ + + /** + * 添加元素到有序集合,有序集合是按照元素的score进行排列 + * 注意: 在 Redis 2.4 版本以前, ZADD 每次只能添加一个元素 + * 当 key 存在但不是有序集类型时,返回一个错误。 + * + * @param key + * @param obj + * @param score 分值 + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(String key, Object obj, double score); + + /** + * 根据分值批量添加 + */ + void zAddWithMapScore(String key, Map members); + + /** + * 根据key 计算集合中元素的数量 + * + * @param key + * @return 当 key 存在且是有序集类型时,返回有序集的基数。 当 key 不存在时,返回 0 + */ + long zCard(String key); + + /** + * 根据key 计算在有序集合中指定区间分数的成员数 + * + * @param key + * @param minScore 最小排序分值 + * @param maxScore 最大排序分值 + * @return 分数值在 min 和 max 之间的成员的数量。 + */ + Long zCount(String key, double minScore, double maxScore); + + /** + * 返回有序集中,指定区间内的成员 -> 从小到大 + * 其中成员的位置按分数值递增(从小到大)来排序 + *

+ * 具有相同分数值的成员按字典序来排列 + * 注意:下标参数0 为起始 + * 负数下标,以 -1 表示最后一个成员, -2 表示倒数第二个成员,以此类推 + * + * @param key + * @param clazz + * @param start 开始位置 + * @param end 结束位置 + * @return 相应对象集合 + */ + List zRange(String key, Class clazz, int start, int end); + + /** + * 返回有序集中,指定区间内的成员 -> 从大到小 + * 其中成员的位置按分数值递增(从大到小)来排序 + * + * @param key + * @param clazz + * @param start 开始位置 + * @param end 结束位置 + * @return 指定区间内,带有分数值的有序集成员的列表。 + */ + List zRevRange(String key, Class clazz, int start, int end); + + /** + * 通过分数返回有序集合指定区间内的成员 -> 从小到大 + * 有序集成员按分数值递增(从小到大)次序排列 + * + * @param key + * @param clazz + * @param minScore 最小分数 + * @param maxScore 最大分数 + * @return 指定区间内,带有分数值(可选)的有序集成员的列表。 + */ + List zRangeByScore(String key, Class clazz, double minScore, double maxScore); + + /** + * 通过分数返回有序集合指定区间内的成员 -> 从大到小 + * 有序集成员按分数值递增(从大到小)次序排列 + * + * @param key + * @param clazz + * @param minScore 最小分数 + * @param maxScore 最大分数 + * @return 指定区间内,带有分数值(可选)的有序集成员的列表。 + */ + List zRevRangeByScore(String key, Class clazz, double minScore, double maxScore); + + + /** + * 返回有序集中指定成员的排名 + * 按分数值递增(从小到大)顺序排列 + * 排名以 0 为底,也就是说, 分数值最小的成员排名为 0 + * + * @param key + * @param obj 成员对象 + * @return 如果成员是有序集 key 的成员,返回 member 的排名。 + * 如果成员不是有序集 key 的成员,返回空 + */ + Long zRank(String key, Object obj); + + /** + * 返回有序集中指定成员的排名 + * 分数值递减(从大到小)排序 + * 排名以 0 为底,也就是说, 分数值最大的成员排名为 0 + * + * @param key + * @param obj 成员对象 + * @return 如果成员是有序集 key 的成员,返回 member 的排名。 + * 如果成员不是有序集 key 的成员,返回空 + */ + Long zRevRank(String key, Object obj); + + /** + * 移除有序集合中的个成员 + * 名称为key 的有序集合中的元素 obj + * + * @param key + * @param obj 元素 + * @return 被成功移除的成员的数量,不包括被忽略的成员 + */ + Long zRem(String key, Object obj); + + /** + * 移除有序集合中给定的排名区间的所有成员 + * 从排序小的开始删除 + * + * @param start 开始位置 下标 0 开始 + * @param end 结束位置 + * @return 被移除成员的数量 + */ + Long zRemRangeByRank(String key, int start, int end); + + /** + * 移除有序集合中给定的分数区间的所有成员 + * 从排序小的开始删除 + * + * @param startScore 开始分值 + * @param endScore 结束分值 + * @return 被移除成员的数量 + */ + Long zRemRangeByScore(String key, double startScore, double endScore); + + /** + * 返回有序集中,成员的分数值 + * 如果成员元素不是有序集 key 的成员,或 key 不存在,返回 null + * + * @param key + * @param obj 成员对象 + * @return 如果成员是有序集 key 的成员,返回 member 的排名 + * 如果成员不是有序集 key 的成员,返回空 + */ + Double zScore(String key, Object obj); + + Double zIncrBy(String key, Object obj, double score); + + + /* ------------------ 管道批量查询 - Pipeline -相关操作 --------------------------------*/ + + /** + * zset 数据通过分值批量查询 + * + * @param key + * @param tClass + * @param starts + * @param + */ + List zRevRangePipeline(String key, Class tClass, List starts); + + /** + * 通过多个key 批量查询 + */ + List> hGetAllPipeline(List hashKeys); + + /** + * hash 数据 通过多个key 以及 filed 查询 + * + * @param hashKeys + * @param fieldKey + * @return + */ + List hmGetAllPipeline(List hashKeys, String fieldKey); + + /* ------------------ 发布订阅 -相关操作 --------------------------------*/ + + /** + * 发布订阅 + * + * @param key + * @param value + * @return + */ + Long publish(String key, Object value); +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/RedisLock.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/RedisLock.java new file mode 100644 index 0000000..269f4e5 --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/RedisLock.java @@ -0,0 +1,104 @@ +package com.sso.framework.redis; + +import com.sso.framework.redis.client.RedisClient; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.params.SetParams; + +import java.util.Collections; + +/** + * Redis 分布式锁 + * + * @author mennq + */ +@Slf4j +@Component +public class RedisLock { + + private static final Long ONE = 1L; + private static final String DEFAULT_LOCK_VALUE = "1"; + private static final String OK = "OK"; + + /** + * 释放锁 lua + */ + private static final String RELEASE_LUA = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end"; + + @Autowired + private JedisPool jedisPool; + + @Autowired + private RedisClient redisClient; + + /** + * 尝试获取分布式锁 + * + * @param lockKey 锁key + * @param requestId (请求标识)加锁者标识-例如UUID + * @param expireTime 超期时间 毫秒数 + * @return 是否获取锁成功 + */ + public boolean tryGetLock(String lockKey, String requestId, int expireTime) { + return redisClient.invoke(jedisPool, jedis -> { + String result = jedis.set(lockKey, requestId, new SetParams().px(expireTime).nx()); + return OK.equals(result); + } + ); + } + + /** + * 尝试在等待时间范围内 , 获取锁 + * + * @param lockKey 锁key + * @param waitTime 等待时间,单位:秒 + * @param expireTime 锁定有效期,单位:秒 + * @return 是否获取锁成功 + */ + public boolean tryGetLock(String lockKey, String requestId, int waitTime, int expireTime) { + int preTime = 20; + int waitLimit = waitTime * 1000 / preTime; + int waitNum = 0; + + for (; waitNum < waitLimit; waitNum++) { + if (this.tryGetLock(lockKey, requestId, expireTime)) { + return true; + } else { + try { + Thread.sleep(preTime); + } catch (InterruptedException e) { + log.error("[ tryGetLock ] >> Exception ", e); + } + } + } + return false; + } + + /** + * 尝试获取分布式锁 + * + * @param lockKey 锁key + * @param expireTime 超期时间 毫秒数 + * @return 是否获取成功 + */ + public boolean tryGetLock(String lockKey, int expireTime) { + return tryGetLock(lockKey, DEFAULT_LOCK_VALUE, expireTime); + } + + /** + * 释放分布式锁 + * + * @param lockKey 锁key + * @param requestId (请求标识)加锁者标识,必须与加锁时一致-才可以 + * @return 是否释放成功 + */ + public boolean releaseLock(String lockKey, String requestId) { + return redisClient.invoke(jedisPool, jedis -> { + Object result = jedis.eval(RELEASE_LUA, Collections.singletonList(lockKey), Collections.singletonList(requestId)); + return ONE.equals(result); + } + ); + } +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/client/RedisClient.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/client/RedisClient.java new file mode 100644 index 0000000..71311cb --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/client/RedisClient.java @@ -0,0 +1,39 @@ +package com.sso.framework.redis.client; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.exceptions.JedisException; + +import java.io.IOException; + +/** + * redis client 工具 + * + * @author 程序员小强 + */ +@Component +public class RedisClient { + + private static final Logger LOGGER = LoggerFactory.getLogger(RedisClient.class); + + public T invoke(JedisPool pool, RedisClientInvoker clients) { + T obj = null; + Jedis jedis = null; + try { + jedis = pool.getResource(); + obj = clients.invoke(jedis); + } catch (JedisException | IOException ex) { + LOGGER.error(ex.getMessage(), ex); + } finally { + if (jedis != null) { + if (jedis.isConnected()) { + jedis.close(); + } + } + } + return obj; + } +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/client/RedisClientInvoker.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/client/RedisClientInvoker.java new file mode 100644 index 0000000..b62dbf7 --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/client/RedisClientInvoker.java @@ -0,0 +1,22 @@ +package com.sso.framework.redis.client; + +import redis.clients.jedis.Jedis; + +import java.io.IOException; + +/** + * redis client 工具 + * + * @author 程序员小强 + */ +public interface RedisClientInvoker { + + /** + * invoke + * + * @param jedis + * @return + * @throws IOException + */ + T invoke(Jedis jedis) throws IOException; +} diff --git a/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/impl/RedisCacheImpl.java b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/impl/RedisCacheImpl.java new file mode 100644 index 0000000..7a19654 --- /dev/null +++ b/sso-auth-center-service/sso-framework/src/main/java/com/sso/framework/redis/impl/RedisCacheImpl.java @@ -0,0 +1,1746 @@ +/** + * Copyright ( @程序员小强 ) All Rights Reserved. + * 博客地址:https://blog.csdn.net/qq_38011415 + */ +package com.sso.framework.redis.impl; + +import com.alibaba.fastjson.JSONArray; +import com.sso.common.utils.JsonSerializer; +import com.sso.framework.redis.RedisCache; +import com.sso.framework.redis.client.RedisClient; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.Pipeline; +import redis.clients.jedis.Response; + +import java.util.*; +import java.util.concurrent.TimeUnit; + +/** + * jedis 操作redis 方封装 + *

+ * 大致内容如下,常用的方法 + * 1.string 相关操作 + * 2.set + * 3.list + * 4.hash + * 5.zset + * 6.管道查询Pipeline + * 7.发布订阅 + */ +@Component +public class RedisCacheImpl implements RedisCache { + + private static final int ZERO = 0; + private static final int FIVE = 5; + private static final int THIRTY = 30; + private static final String OK = "OK"; + private static final Long LONG_ONE = 1L; + private static final Long LONG_ZERO = 0L; + /** + * 默认失效时间毫秒 5 分钟 + */ + private static final long DEFAULT_CACHE_MILLIS = getMillis(TimeUnit.MINUTES, FIVE); + + @Autowired + private JedisPool jedisPool; + @Autowired + private RedisClient redisClient; + + + /* ------------------ string 类型相关操作--------------------------------*/ + + /** + * 添加数据到redis + * 设置默认过期时间 30 分钟 + * + * @param key + * @param value + */ + @Override + public Boolean set(String key, Object value) { + return set(key, value, THIRTY, TimeUnit.MINUTES); + } + + /** + * 添加数据到redis + * 自定义过期时间 + * 注:从 Redis 2.6.12 版本开始, SET 在设置操作成功完成时,返回 OK + * + * @param key + * @param value + * @param duration 时间量 + * @param timeUnit 时间单位枚举 + */ + @Override + public Boolean set(String key, Object value, int duration, TimeUnit timeUnit) { + validateParam(key, value); + String result = redisClient.invoke(jedisPool, (jedis) -> { + String srtResult = jedis.set(key.getBytes(), JsonSerializer.serialize(value)); + if (duration <= ZERO) { + //默认5 分钟 + jedis.pexpire(key.getBytes(), DEFAULT_CACHE_MILLIS); + } else { + //时间转换成毫秒 + long millis = getMillis(timeUnit, duration); + jedis.pexpire(key.getBytes(), millis); + } + return srtResult; + } + + ); + //是否成功 + return this.isStringEquals(OK, result); + } + + /** + * 添加数据到redis + * 并设置永不过期 + * 注:一般使用较少,数据过大时尽量不要使用 + * 从 Redis 2.6.12 版本开始, SET 在设置操作成功完成时,返回 OK + * + * @param key + * @param value + */ + @Override + public Boolean putNeverExpires(String key, Object value) { + validateParam(key, value); + String result = redisClient.invoke(jedisPool, (jedis) -> { + return jedis.set(key.getBytes(), JsonSerializer.serialize(value)); + } + ); + //是否成功 + return this.isStringEquals(OK, result); + } + + /** + * 根据key 获取值 + * + * @param key + * @param clazz 类class + * @return 类对象 + */ + @Override + public T get(String key, Class clazz) { + validateKeyParam(key); + byte[] result = redisClient.invoke(jedisPool, (jedis) -> jedis.get(key.getBytes())); + if (result == null) { + return null; + } + return JsonSerializer.deserialize(result, clazz); + } + + /** + * 根据key集合批量获取 + * + * @param keys key集合 + * @param classz 序列化对象 + * @return 类对象 + */ + @Override + public List mget(List keys, Class classz) { + if (CollectionUtils.isEmpty(keys)) { + return new ArrayList<>(0); + } + String[] strings = new String[keys.size()]; + keys.toArray(strings); + List result = redisClient.invoke(jedisPool, jedis -> { + List list = jedis.mget(strings); + List resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(list)) { + return new ArrayList(); + } + for (String str : list) { + T t = JsonSerializer.deserialize(str.getBytes(), classz); + resultList.add(t); + } + return resultList; + }); + return result; + } + + + /** + * 根据key 获取值 + * 返回 key 的值,如果 key 不存在时,返回 nil。 + * 如果 key 不是字符串类型,那么返回一个错误。 + * + * @param key + * @return String + */ + @Override + public String get(String key) { + return this.get(key, String.class); + } + + /** + * 根据key 获取值 + * + * @param key + * @param clazz 集合泛型对象 + * @return 集合对象 + */ + @Override + public List getList(String key, Class clazz) { + String str = this.get(key, String.class); + return JSONArray.parseArray(str, clazz); + } + + /** + * 将key 的值设为 value ,当且仅当 key 不存在 + * 默认值是时间戳 默认有效期是 5 分钟 + * + * @param key + * @return 设置成功返回 true 失败返回false + */ + @Override + public Boolean setNx(String key) { + return this.setNx(key, System.currentTimeMillis(), FIVE, TimeUnit.MINUTES); + } + + /** + * 将key 的值设为 value ,当且仅当 key 不存在 + * 默认有效期是 5 分钟 + * + * @param key + * @param value 自定义值 + * @return 设置成功返回 true 失败返回false + */ + @Override + public Boolean setNx(String key, Object value) { + return this.setNx(key, value, FIVE, TimeUnit.MINUTES); + } + + /** + * 将key 的值设为 value ,当且仅当 key 不存在 + * 默认值是时间戳 + * + * @param key + * @param seconds 自定义过期时间秒数 + * @return 设置成功返回 true 失败返回false + */ + @Override + public Boolean setNx(String key, int seconds) { + return this.setNx(key, System.currentTimeMillis(), seconds, TimeUnit.SECONDS); + } + + /** + * 将key 的值设为 value ,当且仅当 key 不存在 + * 默认时间单位是秒 + * + * @param key + * @param value 自定义 value + * @param seconds 自定义过期时间秒数 + * @return 设置成功返回 true 失败返回false + */ + @Override + public Boolean setNx(String key, Object value, int seconds) { + return this.setNx(key, value, seconds, TimeUnit.SECONDS); + } + + /** + * 将key 的值设为 value ,当且仅当 key 不存在 + * 注:常用与分布式锁 + * + * @param key + * @param value + * @param duration 时间量 + * @param timeUnit 时间单位枚举 + * @return 设置成功返回 true 失败返回false + */ + @Override + public Boolean setNx(String key, Object value, int duration, TimeUnit timeUnit) { + validateParam(key, value); + return redisClient.invoke(jedisPool, (jedis) -> { + long result = jedis.setnx(key.getBytes(), JsonSerializer.serialize(value)); + if (result >= 1) { + if (duration <= ZERO) { + //默认5 分钟 + jedis.pexpire(key.getBytes(), DEFAULT_CACHE_MILLIS); + return true; + } else { + //时间转换成毫秒 + long millis = getMillis(timeUnit, duration); + jedis.pexpire(key.getBytes(), millis); + return true; + } + } else { + return false; + } + } + ); + } + + /** + * 设置指定 key 的值,并返回 key 的旧值 + * 返回给定 key 的旧值。 当 key 没有旧值时,即 key 不存在时,返回 null + * 注:默认有效期为 5分钟 + * + * @param key + * @return String + */ + @Override + public String getSet(String key, String value) { + return this.getSet(key, value, FIVE, TimeUnit.MINUTES); + } + + /** + * 设置指定 key 的值,并返回 key 的旧值 + * 返回给定 key 的旧值。 当 key 没有旧值时,即 key 不存在时,返回 null + * + * @param key + * @return string key 的旧值 + */ + @Override + public String getSet(String key, String value, int duration, TimeUnit timeUnit) { + validateParam(key, value); + return redisClient.invoke(jedisPool, (jedis) -> { + String result = jedis.getSet(key, value); + if (duration <= ZERO) { + //设置默认过期时间 5 分钟 + jedis.pexpire(key.getBytes(), DEFAULT_CACHE_MILLIS); + return result; + } else { + //时间转换成毫秒 + long millis = getMillis(timeUnit, duration); + jedis.pexpire(key.getBytes(), millis); + return result; + } + } + ); + } + + /** + * 用于获取指定 key 所储存的字符串值的长度 + * 当 key 储存的不是字符串值时,返回一个错误 + * 当 key 不存在时,返回 0 + * + * @param key + */ + @Override + public Long getStrLen(String key) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> jedis.strlen(key.getBytes())); + } + + /** + * key 中储存的数字值增一 (默认增量+1) + * 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCR 操作 + * 注: + * 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误 + * 本操作的值限制在 64 位(bit)有符号数字表示之内 + * + * @param key + * @return 执行命令之后 key 的值。 + */ + @Override + public Long incr(String key) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> jedis.incr(key.getBytes())); + } + + /** + * key 中储存的数字值增一 (自定义增量值 ) + * 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCR 操作 + * 注: + * 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误 + * 本操作的值限制在 64 位(bit)有符号数字表示之内 + * + * @param key + * @param value 自定义增量值 + * @return 执行命令之后 key 的值。 + */ + @Override + public Long incrBy(String key, long value) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> jedis.incrBy(key.getBytes(), value)); + } + + /** + * 为 key 中所储存的值加上指定的浮点数增量值 + * 如果 key 不存在,那么 incrbyfloat 会先将 key 的值设为 0 ,再执行加法操作 + * + * @param key + * @param value 增量值 + * @return 执行命令之后 key 的值 + */ + @Override + public Double incrByFloat(String key, Double value) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> jedis.incrByFloat(key.getBytes(), value)); + } + + /** + * 将 key 中储存的数字值减一 + *

+ * 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 DECR 操作 + * 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误 + * 本操作的值限制在 64 位(bit)有符号数字表示之内 + * + * @param key + * @return 执行命令之后 key 的值 + */ + @Override + public Long decr(String key) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> jedis.decr(key.getBytes())); + } + + /** + * 将 key 中储存的数字值减自定义减量 + *

+ * 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 DECR 操作 + * 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误 + * 本操作的值限制在 64 位(bit)有符号数字表示之内 + * + * @param key + * @param value 自定义减量值 + * @return 执行命令之后 key 的值。 + */ + @Override + public Long decrBy(String key, long value) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> jedis.decrBy(key.getBytes(), value)); + } + + /** + * 用于为指定的 key 追加值 + *

+ * 如果 key 已经存在并且是一个字符串, APPEND 命令将 value + * 追加到 key 原来的值的末尾。 + * 如果 key 不存在, APPEND 就简单地将给定 key 设为 value + * 就像执行 SET key value 一样 + * + * @param key + * @param value + * @return 追加指定值之后, key 中字符串的长度 + */ + @Override + public Long append(String key, Object value) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> jedis.append(key.getBytes(), JsonSerializer.serialize(value))); + } + + + /* ------------------ key 相关操作--------------------------------*/ + + /** + * 检查给定 key 是否存在 + * + * @param key + * @return 是否存在 + */ + @Override + public Boolean exists(String key) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> jedis.exists(key.getBytes())); + } + + /** + * 用于设置 key 的过期时间, + * key 过期后将不再可用。单位以秒计 + * + * @param key + * @param seconds + * @return 是否设置成功 + */ + @Override + public Boolean expire(String key, int seconds) { + return this.expire(key, seconds, TimeUnit.SECONDS); + } + + /** + * 用于设置 key 的过期时间,key 过期后将不再可用 + * 设置成功返回 1 + * 当 key 不存在或者不能为 key 设置过期时间时返回 0 + *

+ * 时间枚举介绍 + * TimeUnit.DAYS //天 + * TimeUnit.HOURS //小时 + * TimeUnit.MINUTES //分钟 + * TimeUnit.SECONDS //秒 + * TimeUnit.MILLISECONDS //毫秒 + * TimeUnit.NANOSECONDS //毫微秒 + * TimeUnit.MICROSECONDS //微秒 + * + * @param key + * @param duration 时间量与单位一起使用 + * @param timeUnit 单位枚举类 + * @return + */ + @Override + public Boolean expire(String key, int duration, TimeUnit timeUnit) { + validateKeyParam(key); + //时间转换成毫秒 + long millis = getMillis(timeUnit, duration); + Long lResult = redisClient.invoke(jedisPool, (jedis) -> jedis.pexpire(key.getBytes(), millis)); + return this.isLongEquals(LONG_ONE, lResult); + } + + /** + * 根据key 获取过期时间秒数 + * 不存在时返回负数 + * + * @param key + * @return 剩余过期时间秒数 + * 当 key 不存在时,返回 -2 。 + * 当 key 存在但没有设置剩余生存时间时,返回 -1 + * 否则,以秒为单位,返回 key 的剩余生存时间 + */ + @Override + public Long getExpiresTtl(String key) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> jedis.ttl(key.getBytes())); + } + + /** + * 根据key 获取过期时间毫秒数 + * 不存在时返回负数 + * + * @param key + * @return 剩余过期时间毫秒数 + * 当 key 不存在时,返回 -2 + * 当 key 存在但没有设置剩余生存时间时,返回 -1 + * 否则,以毫秒为单位,返回 key 的剩余生存时间 + */ + @Override + public Long getExpiresPttl(String key) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> jedis.pttl(key.getBytes())); + } + + /** + * 移除 key 的过期时间,key 将持久保持。 + * 当过期时间移除成功时,返回 1 + * 如果 key 不存在或 key 没有设置过期时间,返回 0 + * + * @param key + */ + @Override + public Boolean persist(String key) { + validateKeyParam(key); + Long lResult = redisClient.invoke(jedisPool, (jedis) -> jedis.persist(key.getBytes())); + return this.isLongEquals(LONG_ONE, lResult); + } + + /** + * 根据key 获取存储类型 + * + * @param key + * @return 返回 key 的数据类型 + * 数据类型有: + * none (key不存在) + * string (字符串) + * list (列表) + * set (集合) + * zset (有序集) + * hash (哈希表) + */ + @Override + public String getType(String key) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> jedis.type(key.getBytes())); + } + + /** + * 用于删除已存在的键。不存在的 key 会被忽略 + * 被删除 key 的数量 + * + * @param key + */ + @Override + public Long del(String key) { + validateKeyParam(key); + if (exists(key)) { + return redisClient.invoke(jedisPool, (jedis) -> jedis.del(key.getBytes())); + } + return LONG_ZERO; + } + + /** + * 查找所有符合给定模式( pattern)的 key 。 + * 谨慎使用(存在性能问题) + * 会引发Redis锁,并且增加Redis的CPU占用 + * + * @param pattern + * @return 符合给定模式的 key 列表 (Array)。 + */ + public List findKeys(String pattern) { + Assert.hasText(pattern, "查找规则不能为空"); + return redisClient.invoke(jedisPool, jedis -> { + Set sets = jedis.keys(("*" + pattern + "*")); + if (sets != null) { + List list = new ArrayList<>(sets.size()); + list.addAll(sets); + return list; + } + return null; + }); + } + + + /* ------------------ set 类型相关操作--------------------------------*/ + + /** + * 向集合添加元素 + * 被添加到集合中的新元素的数量,不包括被忽略的元素。 + * + * @param key + */ + @Override + public Long sAdd(String key, Object value) { + validateParam(key, value); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.sadd(key.getBytes(), JsonSerializer.serialize(value)); + }); + } + + + /** + * 移除集合中元素 + * 被成功移除的元素的数量,不包括被忽略的元素。 + * + * @param key + */ + @Override + public Long sRem(String key, Object value) { + validateParam(key, value); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.srem(key.getBytes(), JsonSerializer.serialize(value)); + }); + } + + /** + * 获取集合的成员数 + * 被成功移除的元素的数量,不包括被忽略的元素。 + * + * @param key + * @return 集合的数量。 当集合 key 不存在时,返回 0 。 + */ + @Override + public Long sCard(String key) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.scard(key.getBytes()); + }); + } + + /** + * 判断 value 元素是否是集合 key 的成员 + * 如果成员元素是集合的成员,返回 1 。 如果成员元素不是集合的成员,或 key 不存在,返回 0 。 + * + * @param key + */ + @Override + public Boolean sisMember(String key, Object value) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.sismember(key.getBytes(), JsonSerializer.serialize(value)); + }); + } + + /** + * 返回集合中的所有成员 + * + * @param key + */ + @Override + public Set sMembers(String key, Class clazz) { + validateKeyParam(key); + Set result = redisClient.invoke(jedisPool, jedis -> { + Set setResult = jedis.smembers(key.getBytes()); + if (CollectionUtils.isEmpty(setResult)) { + return new HashSet(ZERO); + } + Set set = new HashSet<>(setResult.size()); + for (byte[] bytes : setResult) { + T t = JsonSerializer.deserialize(bytes, clazz); + set.add(t); + } + return set; + }); + return result; + } + + /** + * 返回集合随机count个值 + * + * @param key + */ + @Override + public Set sRandMember(String key, Class clazz, int count) { + validateKeyParam(key); + Set result = redisClient.invoke(jedisPool, jedis -> { + List setResult = jedis.srandmember(key.getBytes(), count); + if (CollectionUtils.isEmpty(setResult)) { + return new HashSet(ZERO); + } + Set set = new HashSet<>(setResult.size()); + for (byte[] bytes : setResult) { + T t = JsonSerializer.deserialize(bytes, clazz); + set.add(t); + } + return set; + }); + return result; + } + + + /** + * 返回给定集合的交集 + * + * @param keys + */ + @Override + public Set sinter(Set keys, Class clazz) { + if (CollectionUtils.isEmpty(keys)) { + return new HashSet(ZERO); + } + String[] strKeys = new String[keys.size()]; + keys.toArray(strKeys); + return redisClient.invoke(jedisPool, jedis -> { + Set setResult = jedis.sinter(strKeys); + if (CollectionUtils.isEmpty(setResult)) { + return new HashSet(ZERO); + } + Set set = new HashSet<>(setResult.size()); + for (String str : setResult) { + T t = JsonSerializer.deserialize(str.getBytes(), clazz); + set.add(t); + } + return set; + }); + } + + /** + * 返回给定集合的并集 + * + * @param keys + */ + @Override + public Set sunion(Set keys, Class clazz) { + if (CollectionUtils.isEmpty(keys)) { + return new HashSet(ZERO); + } + String[] strKeys = new String[keys.size()]; + keys.toArray(strKeys); + return redisClient.invoke(jedisPool, jedis -> { + Set setResult = jedis.sunion(strKeys); + if (CollectionUtils.isEmpty(setResult)) { + return new HashSet(ZERO); + } + Set set = new HashSet<>(setResult.size()); + for (String str : setResult) { + T t = JsonSerializer.deserialize(str.getBytes(), clazz); + set.add(t); + } + return set; + }); + } + + /** + * 返回给定集合的差集 + * + * @param keys + */ + @Override + public Set sDiff(List keys, Class clazz) { + if (CollectionUtils.isEmpty(keys)) { + return new HashSet(ZERO); + } + String[] strKeys = new String[keys.size()]; + keys.toArray(strKeys); + return redisClient.invoke(jedisPool, jedis -> { + Set setResult = jedis.sdiff(strKeys); + if (CollectionUtils.isEmpty(setResult)) { + return new HashSet(ZERO); + } + Set set = new HashSet<>(setResult.size()); + for (String str : setResult) { + T t = JsonSerializer.deserialize(str.getBytes(), clazz); + set.add(t); + } + return set; + }); + } + + /** + * 移除并返回集合中的一个随机元素 + * + * @param key + */ + @Override + public T sPop(String key, Class clazz) { + validateKeyParam(key); + byte[] value = redisClient.invoke(jedisPool, (jedis) -> jedis.spop(key.getBytes())); + if (value != null) { + return JsonSerializer.deserialize(value, clazz); + } + return null; + } + + + + /* ------------------ list 相关操作--------------------------------*/ + + /** + * Redis Rpush 命令用于将一个或多个值插入到列表的尾部(最右边)。 + *

+ * 如果列表不存在,一个空列表会被创建并执行 RPUSH 操作。 当列表存在但不是列表类型时,返回一个错误。 + *

+ * 注意:在 Redis 2.4 版本以前的 RPUSH 命令,都只接受单个 value 值。 + * + * @param key + * @return 列表的长度。 + */ + @Override + public Long lRpushObject(String key, Object... value) { + validateParam(key, value); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.rpush(key.getBytes(), JsonSerializer.serialize(value)); + }); + } + + + /** + * 移除列表元素 + * 移除列表中与参数 VALUE 相等的元素 + * + * @param key + * @return 被移除元素的数量。 列表不存在时返回 0 + * 根据count值,从列表中删除所有value相等的项 + * (1) count>0 , 删除从左到右,最多count个value相等的项 + * (2) count<0 ,删除从右到左,最多count绝对值个value相等的项 + * (3) count=0 ,删除所有value相等的项 + */ + @Override + public Long lRem(String key, Object value) { + validateParam(key, value); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.lrem(key.getBytes(), ZERO, JsonSerializer.serialize(value)); + }); + } + + + /** + * 将一个或多个值插入到列表头部 + * 如果 key 不存在,一个空列表会被创建并执行 LPUSH 操作 + * 当 key 存在但不是列表类型时,返回一个错误 + * 注意:在Redis 2.4版本以前的 lpush 命令,都只接受单个 value 值 + * + * @param key + * @return 列表的长度。 + */ + @Override + public Long lPush(String key, Object value) { + validateParam(key, value); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.lpush(key.getBytes(), JsonSerializer.serialize(value)); + }); + } + + /** + * 通过索引来设置元素的值。 + * 当索引参数超出范围,或对一个空列表进行 LSET 时,返回一个错误。 + * 操作成功返回 ok ,否则返回错误信息。 + * + * @param key + * @return 操作是否成功 + */ + @Override + public Boolean lset(String key, long index, Object value) { + validateParam(key, value); + return redisClient.invoke(jedisPool, jedis -> { + String result = jedis.lset(key.getBytes(), index, JsonSerializer.serialize(value)); + return this.isStringEquals(OK, result); + }); + } + + /** + * 将一个或多个值插入到列表尾部 + * 如果 key 不存在,一个空列表会被创建并执行 RPUSH 操作 + * 当 key 存在但不是列表类型时,返回一个错误 + * + * @param key + * @return 列表的长度。 + */ + @Override + public Long rpush(String key, Object value) { + validateParam(key, value); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.rpush(key.getBytes(), JsonSerializer.serialize(value)); + }); + } + + /** + * 对一个列表进行修剪(trim) + * 让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除 + * + * @param key + * @param start 保留区间开始下标 + * @param end 保留区间结束下标 + * @return 是否成功 + */ + @Override + public Boolean lTrim(String key, long start, long end) { + validateKeyParam(key); + String result = redisClient.invoke(jedisPool, jedis -> { + return jedis.ltrim(key.getBytes(), start, end); + }); + //是否成功 + return this.isStringEquals(OK, result); + } + + /** + * 用于返回列表的长度 + * 如果列表 key 不存在,则 key 被解释为一个空列表, + * 返回 0 。 如果 key 不是列表类型,返回一个错误 + * + * @param key + * @return list 集大小 + */ + @Override + public long lLen(String key) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.llen(key.getBytes()); + }); + } + + + /** + * 通过索引获取列表中的元素 + * 如果指定索引值不在列表的区间范围内,返回 null + * 使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。 + * + * @param key + * @param index 集合索引 + * @return 元素信息 + */ + @Override + public T lIndex(String key, int index, Class clazz) { + validateParam(key, clazz); + T obj = redisClient.invoke(jedisPool, jedis -> { + byte[] result = jedis.lindex(key.getBytes(), index); + if (result == null) { + return null; + } + return JsonSerializer.deserialize(result, clazz); + }); + return obj; + } + + /** + * 返回列表中指定区间内的字符串 元素 + * 区间以偏移量 START 和 END 指定。 其中 0 表示列表的第一个元素, 1 表示列表的第二个元素 + * 可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推 + * + * @param key + * @param start 开始位置 + * @param end 结束位置 + * @return 相应对象集合 + */ + @Override + public List lRange(String key, int start, int end) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, jedis -> { + List strList = jedis.lrange(key, start, end); + if (CollectionUtils.isEmpty(strList)) { + return new ArrayList<>(ZERO); + } + return strList; + }); + + } + + + /** + * 返回列表中指定区间内的元素 + * 区间以偏移量 START 和 END 指定。 其中 0 表示列表的第一个元素, 1 表示列表的第二个元素 + * 可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推 + * + * @param key + * @param clazz + * @param start 开始位置 + * @param end 结束位置 + * @return 相应对象集合 + */ + @Override + public List lRange(String key, Class clazz, int start, int end) { + validateKeyParam(key); + List result = redisClient.invoke(jedisPool, jedis -> { + List set = jedis.lrange(key.getBytes(), start, end); + List list = new ArrayList<>(set.size()); + if (CollectionUtils.isEmpty(set)) { + return new ArrayList(ZERO); + } + for (byte[] bytes : set) { + T t = JsonSerializer.deserialize(bytes, clazz); + list.add(t); + } + return list; + }); + return result; + } + + /** + * 移除并返回列表的第一个元素 + * + * @param key + * @return 列表的第一个元素。 当列表 key 不存在时,返回 null + */ + @Override + public T lPop(String key, Class clazz) { + validateParam(key, clazz); + return redisClient.invoke(jedisPool, jedis -> { + byte[] result = jedis.lpop(key.getBytes()); + if (result == null) { + return null; + } + return JsonSerializer.deserialize(result, clazz); + }); + } + + /** + * 移除并返回列表的最后一个元素 + * + * @param key + * @return 列表的最后一个元素。 当列表不存在时,返回 null + */ + @Override + public T rPop(String key, Class clazz) { + validateParam(key, clazz); + return redisClient.invoke(jedisPool, jedis -> { + byte[] result = jedis.rpop(key.getBytes()); + if (result == null) { + return null; + } + return JsonSerializer.deserialize(result, clazz); + }); + } + + + /* ------------------ hash 相关操作--------------------------------*/ + + /** + * 用于查看哈希表的指定字段是否存在 + * + * @param key + * @param field + */ + @Override + public Boolean hexists(String key, String field) { + validateParam(key, field); + return redisClient.invoke(jedisPool, (jedis) -> jedis.hexists(key.getBytes(), field.getBytes())); + } + + /** + * 用于为哈希表中的字段赋值 + * 如果哈希表不存在,一个新的哈希表被创建并进行 HSET 操作 + * 如果字段已经存在于哈希表中,旧值将被覆盖 + * + * @param key + * @param field + * @param value 值 + * 注:仅在field不存在,并成功添加时返回 true, + * field已经存在,会更新内容,但添加状态是false + */ + @Override + public Boolean hSet(String key, String field, Object value) { + validateKeyParam(key); + Long result = redisClient.invoke(jedisPool, (jedis) -> + jedis.hset(key.getBytes(), field.getBytes(), + JsonSerializer.serialize(value)) + ); + return this.isLongEquals(LONG_ONE, result); + } + + @Override + public Boolean hSet(String key, String field, Object value, int duration, TimeUnit timeUnit) { + validateKeyParam(key); + Long result = redisClient.invoke(jedisPool, (jedis) -> { + Long hashResult = jedis.hset(key.getBytes(), field.getBytes(), + JsonSerializer.serialize(value)); + jedis.pexpire(key.getBytes(), getMillis(timeUnit, duration)); + return hashResult; + } + ); + return this.isLongEquals(LONG_ONE, result); + } + + + /** + * 用于为哈希表中不存在的的字段赋值 + * 如果哈希表不存在,一个新的哈希表被创建并进行 HSET 操作 + * 如果字段已经存在于哈希表中,操作无效 + * 如果 key 不存在,一个新哈希表被创建并执行 HSETNX 命令 + * 设置成功,返回 1 。 如果给定字段已经存在且没有操作被执行,返回 0 。 + * 注意版本 >= 2.0.0 + * + * @param key + * @param field + * @param value 值 + * @return 是否成功 + */ + @Override + public Boolean hSetNx(String key, String field, Object value) { + validateKeyParam(key); + Long result = redisClient.invoke(jedisPool, (jedis) -> + jedis.hsetnx(key.getBytes(), field.getBytes(), + JsonSerializer.serialize(value))); + return this.isLongEquals(LONG_ONE, result); + } + + + /** + * key 中HASH储存的数字值增一 (自定义增量值 ) + * + * @param key + * @param field 属性名称 + * @return 执行命令之后 key 的值。 + */ + @Override + public Long hashIncr(String key, String field) { + return this.hashIncrBy(key, field, 1L); + } + + /** + * key 中HASH储存的数字值增一 (自定义增量值 ) + * + * @param key + * @param value 自定义增量值 + * @return 执行命令之后 key 的值。 + */ + @Override + public Long hashIncrBy(String key, String field, long value) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> + jedis.hincrBy(key.getBytes(), field.getBytes(), value)); + } + + /** + * key 中HASH储存的数字值增一 (自定义增量值 ) + * + * @param key + * @param value 自定义增量值 + * @return 执行命令之后 key 的值。 + */ + @Override + public Double hashIncrByFloat(String key, String field, Double value) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> + jedis.hincrByFloat(key.getBytes(), field.getBytes(), value)); + } + + /** + * 获取存储在哈希表中指定字段的值 + * + * @param key + * @param field + * @return 返回给定字段的值。如果给定的字段或 key 不存在时,返回 null + */ + @Override + public T hGet(String key, String field, Class clazz) { + validateKeyParam(key); + byte[] value = redisClient.invoke(jedisPool, (jedis) -> jedis.hget(key.getBytes(), field.getBytes())); + if (value != null) { + return JsonSerializer.deserialize(value, clazz); + } + return null; + } + + /** + * 根据key集合批量获取 + * + * @param key key集合 + * @param fields field集合 + * @param classz 序列化对象 + * @return 类对象 + */ + @Override + public List hmget(String key, List fields, Class classz) { + if (CollectionUtils.isEmpty(fields)) { + return new ArrayList<>(0); + } + String[] strings = new String[fields.size()]; + fields.toArray(strings); + + List result = redisClient.invoke(jedisPool, jedis -> { + List list = jedis.hmget(key, strings); + + List resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(list)) { + return new ArrayList(); + } + for (String strValue : list) { + if (StringUtils.isNoneBlank(strValue)) { + T t = JsonSerializer.deserialize(strValue.getBytes(), classz); + resultList.add(t); + } + } + + return resultList; + }); + return result; + } + + + /** + * 用于删除哈希表 key 中的个指定字段 + * + * @param key + * @param field + * @return 被成功删除字段的数量,不包括被忽略的字段 + */ + @Override + public Long hdel(String key, String field) { + validateParam(key, field); + return redisClient.invoke(jedisPool, (jedis) -> jedis.hdel(key.getBytes(), field.getBytes())); + } + + + /** + * 获取hash 大小 + * + * @param key + */ + @Override + public Long hlen(String key) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> jedis.hlen(key.getBytes())); + } + + /** + * 获取在哈希表中指定 key 的所有字段和值 + * + * @param key + * @return 以列表形式返回哈希表的字段及字段值。 若 key 不存在,返回空列表。 + */ + @Override + public Map hgetAll(String key, Class clazz) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> { + Map map = jedis.hgetAll(key.getBytes()); + Map resultMap = new HashMap<>(map.size()); + if (map != null) { + for (Map.Entry item : map.entrySet()) { + byte[] newKey = item.getKey(); + T newValue = JsonSerializer.deserialize(item.getValue(), clazz); + resultMap.put(new String(newKey), newValue); + } + return resultMap; + } + return null; + }); + } + + /** + * 获取在哈希表中指定 key 的所有field的值 + * + * @param key + * @return 若 key 不存在,返回空列表。 + */ + @Override + public List hvals(String key, Class clazz) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> { + List byteList = jedis.hvals(key.getBytes()); + List list = new ArrayList<>(byteList.size()); + if (CollectionUtils.isEmpty(byteList)) { + return new ArrayList(ZERO); + } + for (byte[] bytes : byteList) { + T t = JsonSerializer.deserialize(bytes, clazz); + list.add(t); + } + return list; + }); + } + + /** + * 返回hash key 对应所有field + * + * @param key + * @return 当 key 不存在时,返回一个空表。 + */ + @Override + public Set hkeys(String key) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, (jedis) -> { + return jedis.hkeys(key); + }); + } + + /** + * 获取Hash下所有数据 + * + * @param hashKey + */ + @Override + public Map hgetall(String hashKey) { + Map result = redisClient.invoke(jedisPool, jedis -> jedis.hgetAll(hashKey)); + return result; + } + + + + /* ------------------ zset 相关操作--------------------------------*/ + + + /** + * 添加元素到有序集合,有序集合是按照元素的score进行排列 + * 注意: 在 Redis 2.4 版本以前, ZADD 每次只能添加一个元素 + * 当 key 存在但不是有序集类型时,返回一个错误。 + * + * @param key + * @param obj + * @param score 分值 + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + @Override + public Long zAdd(String key, Object obj, double score) { + validateParam(key, obj); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.zadd(key.getBytes(), score, JsonSerializer.serialize(obj)); + }); + } + + /** + * 根据分值批量添加 + */ + @Override + public void zAddWithMapScore(String key, Map members) { + redisClient.invoke(jedisPool, jedis -> { + jedis.zadd(key.getBytes(), members); + return null; + }); + } + + /** + * 根据key 计算集合中元素的数量 + * + * @param key + * @return 当 key 存在且是有序集类型时,返回有序集的基数。 当 key 不存在时,返回 0 + */ + @Override + public long zCard(String key) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.zcard(key.getBytes()); + }); + } + + /** + * 根据key 计算在有序集合中指定区间分数的成员数 + * + * @param key + * @param minScore 最小排序分值 + * @param maxScore 最大排序分值 + * @return 分数值在 min 和 max 之间的成员的数量。 + */ + @Override + public Long zCount(String key, double minScore, double maxScore) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.zcount(key.getBytes(), minScore, maxScore); + }); + } + + /** + * 返回有序集中,指定区间内的成员 -> 从小到大 + * 其中成员的位置按分数值递增(从小到大)来排序 + *

+ * 具有相同分数值的成员按字典序来排列 + * 注意:下标参数0 为起始 + * 负数下标,以 -1 表示最后一个成员, -2 表示倒数第二个成员,以此类推 + * + * @param key + * @param clazz + * @param start 开始位置 + * @param end 结束位置 + * @return 相应对象集合 + */ + @Override + public List zRange(String key, Class clazz, int start, int end) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, jedis -> { + Set set = jedis.zrange(key.getBytes(), start, end); + List list = new ArrayList<>(set.size()); + if (CollectionUtils.isEmpty(set)) { + return new ArrayList(ZERO); + } + for (byte[] bytes : set) { + T t = JsonSerializer.deserialize(bytes, clazz); + list.add(t); + } + return list; + }); + } + + /** + * 返回有序集中,指定区间内的成员 -> 从大到小 + * 其中成员的位置按分数值递增(从大到小)来排序 + * + * @param key + * @param clazz + * @param start 开始位置 + * @param end 结束位置 + * @return 指定区间内,带有分数值的有序集成员的列表。 + */ + @Override + public List zRevRange(String key, Class clazz, int start, int end) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, jedis -> { + Set set = jedis.zrevrange(key.getBytes(), start, end); + List list = new ArrayList<>(set.size()); + if (CollectionUtils.isEmpty(set)) { + return new ArrayList(ZERO); + } + for (byte[] bytes : set) { + T t = JsonSerializer.deserialize(bytes, clazz); + list.add(t); + } + return list; + }); + } + + /** + * 通过分数返回有序集合指定区间内的成员 -> 从小到大 + * 有序集成员按分数值递增(从小到大)次序排列 + * + * @param key + * @param clazz + * @param minScore 最小分数 + * @param maxScore 最大分数 + * @return 指定区间内,带有分数值(可选)的有序集成员的列表。 + */ + @Override + public List zRangeByScore(String key, Class clazz, double minScore, double maxScore) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, jedis -> { + Set set = jedis.zrangeByScore(key.getBytes(), minScore, maxScore); + List list = new ArrayList<>(set.size()); + if (CollectionUtils.isEmpty(set)) { + return new ArrayList(ZERO); + } + for (byte[] bytes : set) { + T t = JsonSerializer.deserialize(bytes, clazz); + list.add(t); + } + return list; + }); + } + + /** + * 通过分数返回有序集合指定区间内的成员 -> 从大到小 + * 有序集成员按分数值递增(从大到小)次序排列 + * + * @param key + * @param clazz + * @param minScore 最小分数 + * @param maxScore 最大分数 + * @return 指定区间内,带有分数值(可选)的有序集成员的列表。 + */ + @Override + public List zRevRangeByScore(String key, Class clazz, double minScore, double maxScore) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, jedis -> { + Set set = jedis.zrevrangeByScore(key.getBytes(), maxScore, minScore); + List list = new ArrayList<>(set.size()); + if (CollectionUtils.isEmpty(set)) { + return new ArrayList(ZERO); + } + for (byte[] bytes : set) { + T t = JsonSerializer.deserialize(bytes, clazz); + list.add(t); + } + return list; + }); + } + + + /** + * 返回有序集中指定成员的排名 + * 按分数值递增(从小到大)顺序排列 + * 排名以 0 为底,也就是说, 分数值最小的成员排名为 0 + * + * @param key + * @param obj 成员对象 + * @return 如果成员是有序集 key 的成员,返回 member 的排名。 + * 如果成员不是有序集 key 的成员,返回空 + */ + @Override + public Long zRank(String key, Object obj) { + validateParam(key, obj); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.zrank(key.getBytes(), JsonSerializer.serialize(obj)); + }); + } + + /** + * 返回有序集中指定成员的排名 + * 分数值递减(从大到小)排序 + * 排名以 0 为底,也就是说, 分数值最大的成员排名为 0 + * + * @param key + * @param obj 成员对象 + * @return 如果成员是有序集 key 的成员,返回 member 的排名。 + * 如果成员不是有序集 key 的成员,返回空 + */ + @Override + public Long zRevRank(String key, Object obj) { + validateParam(key, obj); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.zrevrank(key.getBytes(), JsonSerializer.serialize(obj)); + }); + } + + /** + * 移除有序集合中的个成员 + * 名称为key 的有序集合中的元素 obj + * + * @param key + * @param obj 元素 + * @return 被成功移除的成员的数量,不包括被忽略的成员 + */ + @Override + public Long zRem(String key, Object obj) { + validateParam(key, obj); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.zrem(key.getBytes(), JsonSerializer.serialize(obj)); + }); + } + + /** + * 移除有序集合中给定的排名区间的所有成员 + * 从排序小的开始删除 + * + * @param start 开始位置 下标 0 开始 + * @param end 结束位置 + * @return 被移除成员的数量 + */ + @Override + public Long zRemRangeByRank(String key, int start, int end) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.zremrangeByRank(key.getBytes(), start, end); + }); + } + + /** + * 移除有序集合中给定的分数区间的所有成员 + * 从排序小的开始删除 + * + * @param startScore 开始分值 + * @param endScore 结束分值 + * @return 被移除成员的数量 + */ + @Override + public Long zRemRangeByScore(String key, double startScore, double endScore) { + validateKeyParam(key); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.zremrangeByScore(key.getBytes(), startScore, endScore); + }); + } + + /** + * 返回有序集中,成员的分数值 + * 如果成员元素不是有序集 key 的成员,或 key 不存在,返回 null + * + * @param key + * @param obj 成员对象 + * @return 如果成员是有序集 key 的成员,返回 member 的排名 + * 如果成员不是有序集 key 的成员,返回空 + */ + @Override + public Double zScore(String key, Object obj) { + validateParam(key, obj); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.zscore(key.getBytes(), JsonSerializer.serialize(obj)); + }); + } + + + @Override + public Double zIncrBy(String key, Object obj, double score) { + validateParam(key, obj); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.zincrby(key.getBytes(), score, JsonSerializer.serialize(obj)); + }); + } + + + /* ------------------ 管道批量查询 - Pipeline -相关操作 --------------------------------*/ + + + /** + * 通过分值批量查询 + * + * @param key + * @param tClass + * @param starts + * @param + */ + @Override + public List zRevRangePipeline(String key, Class tClass, List starts) { + List result = redisClient.invoke(jedisPool, jedis -> { + Pipeline pipeline = jedis.pipelined(); + + List>> responseList = new ArrayList<>(); + for (Integer start : starts) { + Response> response = pipeline.zrevrange(key.getBytes(), start, start); + responseList.add(response); + } + pipeline.sync(); + if (CollectionUtils.isEmpty(responseList)) { + return new ArrayList(); + } + List list = new ArrayList<>(responseList.size()); + for (Response> response : responseList) { + for (byte[] bytes : response.get()) { + T t = JsonSerializer.deserialize(bytes, tClass); + list.add(t); + } + } + return list; + }); + return result; + } + + /** + * 通过多个key 批量查询 + */ + @Override + public List> hGetAllPipeline(List hashKeys) { + List> result = redisClient.invoke(jedisPool, jedis -> { + Pipeline pipeline = jedis.pipelined(); + + List>> responseList = new ArrayList<>(); + for (String hashKey : hashKeys) { + responseList.add(pipeline.hgetAll(hashKey)); + } + pipeline.sync(); + if (CollectionUtils.isEmpty(responseList)) { + return new ArrayList<>(); + } + List> list = new ArrayList<>(); + for (Response> response : responseList) { + list.add(response.get()); + } + return list; + }); + return result; + } + + @Override + public List hmGetAllPipeline(List hashKeys, String fieldKey) { + List result = redisClient.invoke(jedisPool, jedis -> { + Pipeline pipeline = jedis.pipelined(); + + List>> responseList = new ArrayList<>(); + for (String hashKey : hashKeys) { + responseList.add(pipeline.hmget(hashKey, fieldKey)); + } + pipeline.sync(); + if (CollectionUtils.isEmpty(responseList)) { + return new ArrayList<>(); + } + List list = new ArrayList<>(); + for (Response> response : responseList) { + if (null != response.get().get(0)) { + list.add(response.get().get(0)); + } + } + return list; + }); + return result; + } + + + /* ------------------ 发布订阅 -相关操作 --------------------------------*/ + + @Override + public Long publish(String key, Object value) { + validateParam(key, value); + return redisClient.invoke(jedisPool, jedis -> { + return jedis.publish(key.getBytes(), JsonSerializer.serialize(value)); + }); + } + + + + /* ------------------ 其它私有方法 -相关操作 --------------------------------*/ + + /** + * 校验参数 + */ + private void validateParam(String key, Object value) { + this.validateKeyParam(key); + Assert.notNull(value, "value不能为空"); + Assert.isInstanceOf(Object.class, value, "value没有实现Object接口,无法序列化"); + } + + /** + * 校验参数 + */ + private void validateKeyParam(String key) { + Assert.hasText(key, "key不能为空"); + Assert.notNull(jedisPool, "jedis连接初始化失败"); + } + + /** + * 判断long值是否相同 + */ + private Boolean isLongEquals(Long valueOne, Long valueTwo) { + if ((null != valueOne) && (null != valueTwo)) { + return valueOne.intValue() == valueTwo.intValue(); + } + return false; + } + + /** + * 判断string值是否相同 + */ + private Boolean isStringEquals(String strOne, String strTwo) { + if ((StringUtils.isNoneBlank(strOne)) && (StringUtils.isNoneBlank(strTwo))) { + return strOne.equals(strTwo); + } + return false; + } + + public synchronized Jedis getRedis() { + return jedisPool.getResource(); + } + + public void setJedisPool(JedisPool jedisPool) { + this.jedisPool = jedisPool; + } + + /** + * 时间秒数计算 + * + * @param timeUnit 单位枚举 + * @param duration 时间量 + * @return 秒数 + */ + public static int getSeconds(TimeUnit timeUnit, int duration) { + return (int) timeUnit.toSeconds(duration); + } + + /** + * 时间毫秒数计算 + * + * @param timeUnit 单位枚举 + * @param duration 时间量 + * @return 毫秒数 + */ + public static long getMillis(TimeUnit timeUnit, int duration) { + return timeUnit.toMillis(duration); + } + +}