├── .gitignore ├── rt-admin-parent ├── rt-admin-common │ ├── src │ │ ├── main │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── igroupes │ │ │ │ ├── rtadmin │ │ │ │ ├── util │ │ │ │ │ ├── VerifyUtil.java │ │ │ │ │ ├── Base64Utils.java │ │ │ │ │ ├── RtAdminUtils.java │ │ │ │ │ ├── UniqueKeyUtils.java │ │ │ │ │ ├── EnumUtils.java │ │ │ │ │ ├── PathUtils.java │ │ │ │ │ ├── ExceptionUtils.java │ │ │ │ │ ├── PageDTOUtil.java │ │ │ │ │ ├── Md5Utils.java │ │ │ │ │ ├── StreamUtils.java │ │ │ │ │ ├── TimeUtils.java │ │ │ │ │ ├── ByteUtils.java │ │ │ │ │ ├── HttpUtils.java │ │ │ │ │ ├── UserUtils.java │ │ │ │ │ ├── SetUtils.java │ │ │ │ │ ├── VerifyCodeUtil.java │ │ │ │ │ ├── FileTypeUtils.java │ │ │ │ │ ├── AtomicFileOutputStream.java │ │ │ │ │ ├── Requires.java │ │ │ │ │ └── SystemPropertyUtils.java │ │ │ │ ├── enums │ │ │ │ │ ├── CodeEnum.java │ │ │ │ │ ├── CodeMessageEnum.java │ │ │ │ │ ├── ResultEnum.java │ │ │ │ │ └── ErrorCode.java │ │ │ │ ├── dto │ │ │ │ │ ├── reponse │ │ │ │ │ │ ├── FileUploadResponse.java │ │ │ │ │ │ ├── UserResponse.java │ │ │ │ │ │ ├── PermissionListResponse.java │ │ │ │ │ │ ├── UserBaseInfoResponse.java │ │ │ │ │ │ ├── FilterRoleResponse.java │ │ │ │ │ │ ├── StatResponse.java │ │ │ │ │ │ ├── UserTreeResponse.java │ │ │ │ │ │ ├── RoleListResponse.java │ │ │ │ │ │ ├── SystemLogListResponse.java │ │ │ │ │ │ └── UserInfoPageResponse.java │ │ │ │ │ ├── request │ │ │ │ │ │ ├── FilterRoleRequest.java │ │ │ │ │ │ ├── PermissionListRequest.java │ │ │ │ │ │ ├── LimitMemberRequest.java │ │ │ │ │ │ ├── StatGetRequest.java │ │ │ │ │ │ ├── RoleMemberAddRequest.java │ │ │ │ │ │ ├── RoleMemberDeleteRequest.java │ │ │ │ │ │ ├── RoleListRequest.java │ │ │ │ │ │ ├── UserBaseInfoRequest.java │ │ │ │ │ │ ├── RoleAddRequest.java │ │ │ │ │ │ ├── RoleUpdateRequest.java │ │ │ │ │ │ ├── PermissionUpdateRequest.java │ │ │ │ │ │ ├── ChangePasswordRequest.java │ │ │ │ │ │ ├── UserInfoPageRequest.java │ │ │ │ │ │ ├── UserUpdateRequest.java │ │ │ │ │ │ ├── RoleMemberUpdateRequest.java │ │ │ │ │ │ ├── UserLoginRequest.java │ │ │ │ │ │ ├── UserRegisterRequest.java │ │ │ │ │ │ ├── SystemLogListRequest.java │ │ │ │ │ │ ├── UserAddRequest.java │ │ │ │ │ │ └── StatRequest.java │ │ │ │ │ ├── PageRequest.java │ │ │ │ │ ├── PageResponse.java │ │ │ │ │ └── UserInfo.java │ │ │ │ ├── vo │ │ │ │ │ ├── PageVO.java │ │ │ │ │ └── ResultVO.java │ │ │ │ ├── file │ │ │ │ │ └── exception │ │ │ │ │ │ ├── RtAdminException.java │ │ │ │ │ │ └── BusinessException.java │ │ │ │ ├── constant │ │ │ │ │ └── RtAdminConstant.java │ │ │ │ └── ExpiryQueue.java │ │ │ │ └── RtThread.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── igroupes │ │ │ └── rtadmin │ │ │ └── util │ │ │ ├── VerifyCodeUtilTest.java │ │ │ ├── RequestPathTrieTest.java │ │ │ └── SetUtilsTest.java │ └── pom.xml ├── rt-admin-file │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── igroupes │ │ │ └── rtadmin │ │ │ └── file │ │ │ ├── core │ │ │ ├── package_info.java │ │ │ ├── FileStoreConfig.java │ │ │ ├── SimpleFileStoreConfig.java │ │ │ ├── QiniuFileStoreConfig.java │ │ │ ├── FileStore.java │ │ │ ├── FileStoreAdapter.java │ │ │ ├── FileStoreFactory.java │ │ │ └── QiuNiuFileStore.java │ │ │ └── exception │ │ │ └── FileStoreException.java │ └── pom.xml ├── rt-admin-service │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── igroupes │ │ │ └── rtadmin │ │ │ ├── service │ │ │ ├── raw │ │ │ │ ├── package_info.java │ │ │ │ ├── FileLogService.java │ │ │ │ ├── SystemLoginSessionService.java │ │ │ │ ├── SystemUserService.java │ │ │ │ ├── SystemPermissionService.java │ │ │ │ ├── SystemRolePermissionService.java │ │ │ │ ├── SystemLogService.java │ │ │ │ ├── SystemUserStatService.java │ │ │ │ ├── SystemRoleService.java │ │ │ │ └── SystemUserRoleService.java │ │ │ ├── ISystemLogService.java │ │ │ ├── IFileService.java │ │ │ ├── IStatService.java │ │ │ ├── IVerifyCodeManager.java │ │ │ ├── IPermissionService.java │ │ │ ├── IUserService.java │ │ │ └── impl │ │ │ │ ├── FileServiceImpl.java │ │ │ │ ├── SystemLogServiceImpl.java │ │ │ │ └── DefaultVerifyCodeManager.java │ │ │ └── config │ │ │ ├── LoginProperties.java │ │ │ ├── ExpiryQueueProperties.java │ │ │ ├── RestTemplateProperties.java │ │ │ ├── RequestProperties.java │ │ │ ├── FileStoreProperties.java │ │ │ └── RestTemplateConfig.java │ └── pom.xml ├── rt-admin-dao │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── igroupes │ │ │ │ └── rtadmin │ │ │ │ ├── mapper │ │ │ │ ├── FileLogMapper.java │ │ │ │ ├── SystemLoginSessionMapper.java │ │ │ │ ├── SystemPermissionMapper.java │ │ │ │ ├── SystemRolePermissionMapper.java │ │ │ │ ├── SystemUserMapper.java │ │ │ │ ├── SystemLogMapper.java │ │ │ │ ├── SystemUserStatMapper.java │ │ │ │ ├── SystemRoleMapper.java │ │ │ │ └── SystemUserRoleMapper.java │ │ │ │ ├── entity │ │ │ │ ├── BaseEntity.java │ │ │ │ ├── SystemUserStatEntity.java │ │ │ │ ├── SystemLoginSessionEntity.java │ │ │ │ ├── FileLogEntity.java │ │ │ │ ├── SystemUserRoleEntity.java │ │ │ │ ├── SystemPermissionEntity.java │ │ │ │ ├── SystemRolePermissionEntity.java │ │ │ │ ├── SystemRoleEntity.java │ │ │ │ ├── SystemLogEntity.java │ │ │ │ └── SystemUserEntity.java │ │ │ │ ├── query │ │ │ │ └── SystemLogQuery.java │ │ │ │ ├── result │ │ │ │ ├── StatResult.java │ │ │ │ └── SystemUserResult.java │ │ │ │ └── config │ │ │ │ └── MybatisPlusConfig.java │ │ │ └── resources │ │ │ └── mapper │ │ │ ├── SystemUserMapper.xml │ │ │ ├── SystemRolePermissionMapper.xml │ │ │ ├── SystemPermissionMapper.xml │ │ │ ├── SystemRoleMapper.xml │ │ │ ├── SystemLogMapper.xml │ │ │ ├── SystemUserRoleMapper.xml │ │ │ └── SystemUserStatMapper.xml │ └── pom.xml ├── rt-admin │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── application.yml │ │ │ │ ├── application-test.yml │ │ │ │ ├── application-prd.yml │ │ │ │ ├── application-dev.yml │ │ │ │ └── logback.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── igroupes │ │ │ │ └── rtadmin │ │ │ │ ├── aop │ │ │ │ ├── SkipLogin.java │ │ │ │ ├── LoginUser.java │ │ │ │ ├── LoginUserArgumentResolver.java │ │ │ │ ├── GlobalExceptionHandler.java │ │ │ │ ├── LimitHandlerInterceptorAdapter.java │ │ │ │ └── LoginUserHandlerInterceptorAdapter.java │ │ │ │ ├── RtAdminApplication.java │ │ │ │ ├── controller │ │ │ │ ├── StatController.java │ │ │ │ ├── FileController.java │ │ │ │ ├── UserController.java │ │ │ │ └── SystemController.java │ │ │ │ ├── filter │ │ │ │ ├── HttpRequestResponseWrapperFilter.java │ │ │ │ ├── HttpResponseWrapper.java │ │ │ │ └── HttpRequestWrapper.java │ │ │ │ └── config │ │ │ │ ├── GlobalCorsConfig.java │ │ │ │ └── WebMvcConfig.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── igroupes │ │ │ └── rtadmin │ │ │ ├── util │ │ │ └── PermissionUtilsTest.java │ │ │ └── controller │ │ │ └── UserControllerTest.java │ └── pom.xml └── pom.xml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | **/target/ 2 | */.idea/ 3 | **/classes/ 4 | **/*.iml 5 | **/logs/ 6 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/VerifyUtil.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | public class VerifyUtil { 4 | } 5 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-file/src/main/java/com/igroupes/rtadmin/file/core/package_info.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.file.core; 2 | /** 3 | * 只是单独模块,不使用spring管理 4 | */ -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/enums/CodeEnum.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.enums; 2 | 3 | public interface CodeEnum { 4 | 5 | T getCode(); 6 | } 7 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/raw/package_info.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service.raw; 2 | 3 | /** 4 | * 直接对应的是mybatis-plus提供的service 5 | */ -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-file/src/main/java/com/igroupes/rtadmin/file/core/FileStoreConfig.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.file.core; 2 | 3 | public abstract class FileStoreConfig { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/Base64Utils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | public class Base64Utils extends org.springframework.util.Base64Utils { 4 | } 5 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/enums/CodeMessageEnum.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.enums; 2 | 3 | public interface CodeMessageEnum extends CodeEnum { 4 | 5 | String getMessage(); 6 | } 7 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/reponse/FileUploadResponse.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.reponse; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class FileUploadResponse { 7 | private String value; 8 | } 9 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/FilterRoleRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class FilterRoleRequest { 7 | private String filter; 8 | } 9 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/enums/ResultEnum.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.enums; 2 | 3 | /** 4 | * 模仿枚举类型(但是枚举类型不能继承) 5 | */ 6 | public interface ResultEnum extends CodeMessageEnum{ 7 | 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/PermissionListRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import com.igroupes.rtadmin.dto.PageRequest; 4 | 5 | public class PermissionListRequest extends PageRequest { 6 | } 7 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/reponse/UserResponse.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.reponse; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class UserResponse { 7 | private String key; 8 | private String token; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/PageRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class PageRequest { 7 | private Integer page; // 起始数据(表示从0开始的页数) 8 | private Integer size; // 每页限制大小 9 | } 10 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/LimitMemberRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import com.igroupes.rtadmin.dto.PageRequest; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class LimitMemberRequest extends PageRequest { 8 | } 9 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/StatGetRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class StatGetRequest { 7 | private String startDate; 8 | private String endDate; 9 | } 10 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/vo/PageVO.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.vo; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class PageVO { 7 | private Integer offset = 0; // 起始数据(表示从0开始的页数) 8 | private Integer limit = 20; // 每页限制大小 9 | } 10 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/RoleMemberAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | @Data 8 | public class RoleMemberAddRequest { 9 | private List ids; 10 | } 11 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/RoleMemberDeleteRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | @Data 8 | public class RoleMemberDeleteRequest { 9 | private List ids; 10 | } 11 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/PageResponse.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class PageResponse { 7 | private Long count; // 总个数 8 | private Long page; // 当前页数 9 | private Long size; // 每页数量 10 | 11 | } 12 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/mapper/FileLogMapper.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.mapper; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.igroupes.rtadmin.entity.FileLogEntity; 6 | 7 | public interface FileLogMapper extends BaseMapper { 8 | } 9 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/RoleListRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import com.igroupes.rtadmin.dto.PageRequest; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class RoleListRequest extends PageRequest{ 8 | private String roleIds; 9 | } 10 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/UserBaseInfoRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class UserBaseInfoRequest { 7 | private String avatar; 8 | private String nickname; 9 | private String signature; 10 | } 11 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/reponse/PermissionListResponse.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.reponse; 2 | 3 | import com.igroupes.rtadmin.dto.PageResponse; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class PermissionListResponse extends PageResponse{ 8 | private String limit; 9 | } 10 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/RoleAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotBlank; 6 | 7 | @Data 8 | public class RoleAddRequest { 9 | @NotBlank 10 | private String name; 11 | private String desc ; 12 | } 13 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/RoleUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotNull; 6 | 7 | @Data 8 | public class RoleUpdateRequest { 9 | @NotNull 10 | private String name; 11 | private String desc ; 12 | } 13 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 通用实体对象 7 | */ 8 | @Data 9 | public class BaseEntity { 10 | private String addTime; 11 | private String updateTime; 12 | private Long addUser; 13 | private Long updateUser; 14 | } 15 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/mapper/SystemLoginSessionMapper.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.mapper; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.igroupes.rtadmin.entity.SystemLoginSessionEntity; 6 | 7 | public interface SystemLoginSessionMapper extends BaseMapper { 8 | } 9 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/PermissionUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotBlank; 6 | 7 | @Data 8 | public class PermissionUpdateRequest { 9 | @NotBlank 10 | private String limit; 11 | @NotBlank 12 | private String api; 13 | } 14 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/ChangePasswordRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotBlank; 6 | 7 | @Data 8 | public class ChangePasswordRequest { 9 | @NotBlank 10 | private String password; 11 | @NotBlank 12 | private String oldPassword; 13 | } 14 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/UserInfoPageRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import com.igroupes.rtadmin.dto.PageRequest; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class UserInfoPageRequest extends PageRequest { 8 | private String filter; // 关键字查询。模糊匹配 ID/名称/登录账号 9 | private String roleIds; // 角色id 10 | } 11 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/query/SystemLogQuery.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.query; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class SystemLogQuery { 7 | private String actionAddr; 8 | private String handlerFilter; 9 | private String startTime; 10 | private String endTime; 11 | private Integer status; 12 | private Long userId; 13 | } 14 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/UserUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class UserUpdateRequest { 7 | private String username; 8 | private String nickname; 9 | private String avatar; 10 | private Long limitId; 11 | private String desc; 12 | private String password; 13 | } 14 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/RoleMemberUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotNull; 6 | import java.util.List; 7 | 8 | @Data 9 | public class RoleMemberUpdateRequest { 10 | @NotNull 11 | private List userIds; 12 | @NotNull 13 | private Long roleId; 14 | } 15 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/reponse/UserBaseInfoResponse.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.reponse; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class UserBaseInfoResponse { 7 | private String avatar; 8 | private String nickname; 9 | private String signature; 10 | private String limit; 11 | private Long parentId; 12 | private String parentNickname; 13 | } 14 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/UserLoginRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotBlank; 6 | 7 | @Data 8 | public class UserLoginRequest { 9 | @NotBlank 10 | private String username; 11 | @NotBlank 12 | private String password; 13 | @NotBlank 14 | private String code; 15 | } 16 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 3 | servlet: 4 | context-path: /rtapi/ 5 | tomcat: 6 | basedir: 7 | /tmp/tomcat/rtadmin 8 | 9 | spring: 10 | profiles: 11 | active: dev #激活环境 12 | servlet: 13 | multipart: 14 | max-file-size: 30MB 15 | max-request-size: 50MB 16 | jackson: 17 | default-property-inclusion: non_null 18 | 19 | 20 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/UserRegisterRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | import org.hibernate.validator.constraints.Length; 5 | 6 | @Data 7 | public class UserRegisterRequest { 8 | @Length(min = 6, message = "用户名长度至少6位") 9 | private String username; 10 | @Length(min = 6, message = "密码长度至少6位") 11 | private String password; 12 | } 13 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-file/src/main/java/com/igroupes/rtadmin/file/core/SimpleFileStoreConfig.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.file.core; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class SimpleFileStoreConfig extends FileStoreConfig { 7 | private String fileStoreDir; // 文件存储目录 8 | private long storeDirMaxBytes; // 存储目录的最大字节大小 9 | private String filePrefixName; // 文件的前缀名 10 | private String downloadUrlPrefix; // 下载的url前缀 11 | } 12 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/reponse/FilterRoleResponse.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.reponse; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | @Data 8 | public class FilterRoleResponse { 9 | private List list; 10 | 11 | @Data 12 | public static class FilterRoleResponseDetail { 13 | private Long id ; 14 | private String name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/ISystemLogService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service; 2 | 3 | import com.igroupes.rtadmin.dto.UserInfo; 4 | import com.igroupes.rtadmin.dto.request.SystemLogListRequest; 5 | import com.igroupes.rtadmin.vo.ResultVO; 6 | 7 | import javax.validation.Valid; 8 | 9 | public interface ISystemLogService { 10 | ResultVO get(UserInfo userInfo, @Valid SystemLogListRequest request); 11 | } 12 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/SystemLogListRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import com.igroupes.rtadmin.dto.PageRequest; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class SystemLogListRequest extends PageRequest{ 8 | private String actionAddr; 9 | private String handlerFilter; 10 | private String startTime; 11 | private String endTime; 12 | private Integer status; 13 | } 14 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/UserAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotBlank; 6 | 7 | @Data 8 | public class UserAddRequest { 9 | @NotBlank 10 | private String username; 11 | private String nickname; 12 | private String avatar; 13 | private String desc; 14 | @NotBlank 15 | private String password; 16 | } 17 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/aop/SkipLogin.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.aop; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.METHOD) 10 | public @interface SkipLogin { 11 | // 用于类被@LoginUser(require=true)修改,通过@SkipLogin表示不用登陆(排除方法) 12 | } 13 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/raw/FileLogService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service.raw; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.igroupes.rtadmin.entity.FileLogEntity; 5 | import com.igroupes.rtadmin.mapper.FileLogMapper; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | public class FileLogService extends ServiceImpl { 10 | } 11 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/file/exception/RtAdminException.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.file.exception; 2 | 3 | import com.igroupes.rtadmin.enums.ErrorCode; 4 | 5 | public class RtAdminException extends BusinessException { 6 | private Integer code; 7 | 8 | public RtAdminException(String message) { 9 | super(message); 10 | } 11 | 12 | public RtAdminException(ErrorCode errorCode) { 13 | super(errorCode); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/mapper/SystemPermissionMapper.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.mapper; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.igroupes.rtadmin.entity.SystemPermissionEntity; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface SystemPermissionMapper extends BaseMapper { 9 | 10 | SystemPermissionEntity getPermissionById(@Param("userId") Long userId); 11 | } 12 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/config/LoginProperties.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Data 8 | @Configuration 9 | @ConfigurationProperties(prefix = "rtadmin.login") 10 | public class LoginProperties { 11 | private Long expireTime; 12 | private String tokenKey; 13 | } 14 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/RtAdminUtils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | public class RtAdminUtils { 4 | private RtAdminUtils() { 5 | } 6 | 7 | public static String parentChain(Long curParentId, String curParentChain) { 8 | Requires.requireNonNull(curParentId, "user id"); 9 | Requires.requireNonBlank(curParentChain, "current parent chain"); 10 | return curParentChain + "-" + curParentId; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/entity/SystemUserStatEntity.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableId; 4 | import com.baomidou.mybatisplus.annotation.TableName; 5 | import lombok.Data; 6 | 7 | @Data 8 | @TableName("system_user_stat") 9 | public class SystemUserStatEntity { 10 | @TableId 11 | private Long id; 12 | private Long userId; 13 | private Integer operate; 14 | private String detail; 15 | } 16 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/UniqueKeyUtils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import java.util.concurrent.ThreadLocalRandom; 4 | 5 | public class UniqueKeyUtils { 6 | private UniqueKeyUtils() { 7 | } 8 | 9 | public static Long getKey(){ 10 | int seed = ThreadLocalRandom.current().nextInt(100); 11 | long key; 12 | key = (TimeUtils.currentElapsedTime() << 24) >>> 8; 13 | key = key | (seed <<56); 14 | return key; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/constant/RtAdminConstant.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.constant; 2 | 3 | public interface RtAdminConstant { 4 | String VERIFY_CODE_COOKIE_KEY = "vc"; 5 | String USER_INFO_REQUEST_ATTRIBUTE_KEY = "request_user_info"; 6 | String SYSTEM_LOG_PATH_HEADER_KEY = "X-ACTION-ADDR"; 7 | // 通用的操作成功与失败编码 8 | int RESULT_SUCCESS = 1; 9 | int RESULT_FAIL = 2; 10 | 11 | Long ADMIN_SUPER_ID = 0L; 12 | 13 | String URL_DECODE_CHARSET = "UTC-8"; 14 | } 15 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/result/StatResult.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.result; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class StatResult { 11 | private String date; 12 | private Integer loginCount; 13 | private Integer registerCount; 14 | private Integer userCount; 15 | private Integer showCount; 16 | private Integer showUserCount; 17 | } 18 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/config/ExpiryQueueProperties.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Data 8 | @Configuration 9 | @ConfigurationProperties(prefix = "rtadmin.expiry-queue") 10 | public class ExpiryQueueProperties { 11 | private Integer verifyCodeInterval; 12 | private Integer verifyCodeTimeout; 13 | } 14 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/entity/SystemLoginSessionEntity.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.entity; 2 | 3 | 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import lombok.Data; 7 | 8 | @Data 9 | @TableName("system_login_session") 10 | public class SystemLoginSessionEntity extends BaseEntity { 11 | @TableId 12 | private Long id; 13 | private Long userId; 14 | private String token; 15 | private Long nextExpireTime; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/raw/SystemLoginSessionService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service.raw; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.igroupes.rtadmin.entity.SystemLoginSessionEntity; 6 | import com.igroupes.rtadmin.mapper.SystemLoginSessionMapper; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | public class SystemLoginSessionService extends ServiceImpl { 11 | } 12 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/resources/mapper/SystemUserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/entity/FileLogEntity.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.entity; 2 | 3 | 4 | import com.baomidou.mybatisplus.annotation.TableName; 5 | import lombok.Data; 6 | 7 | @Data 8 | @TableName("file_log") 9 | public class FileLogEntity extends BaseEntity { 10 | public static final int TYPE_UPLOAD = 1; 11 | public static final int TYPE_DOWNLOAD = 2; 12 | 13 | private String ip; 14 | private String userCert; 15 | private Integer type; 16 | private String failDesc; 17 | private Integer result; 18 | } 19 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/mapper/SystemRolePermissionMapper.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.mapper; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.igroupes.rtadmin.entity.SystemPermissionEntity; 6 | import com.igroupes.rtadmin.entity.SystemRolePermissionEntity; 7 | import org.apache.ibatis.annotations.Param; 8 | 9 | public interface SystemRolePermissionMapper extends BaseMapper { 10 | 11 | SystemPermissionEntity getPermissionById(@Param("roleId") Long roleId); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/mapper/SystemUserMapper.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.mapper; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.igroupes.rtadmin.entity.SystemUserEntity; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | import java.util.List; 9 | 10 | public interface SystemUserMapper extends BaseMapper { 11 | 12 | /** 13 | * 获取用户链 14 | * 15 | * @return 16 | */ 17 | List getUserChain(@Param("parentChain") String parentChain); 18 | } 19 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/result/SystemUserResult.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.result; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class SystemUserResult { 7 | private Long id; 8 | private String username; 9 | private String nickname; 10 | private String avatar; 11 | private Long limitId; 12 | private String desc; 13 | private String addTime; 14 | private String updateTime; 15 | private Long addUser; 16 | private Long parentId; 17 | private String roleName; 18 | private Long roleId; 19 | } 20 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/config/RestTemplateProperties.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Data 8 | @Configuration 9 | @ConfigurationProperties(prefix = "rest-template") 10 | public class RestTemplateProperties { 11 | private int maxTotalConnect; 12 | private int maxConnectPerRoute; 13 | private int connectTimeout; 14 | private int readTimeout; 15 | } 16 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/entity/SystemUserRoleEntity.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableId; 4 | import com.baomidou.mybatisplus.annotation.TableLogic; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import lombok.Data; 7 | 8 | @Data 9 | @TableName("system_user_role") 10 | public class SystemUserRoleEntity extends BaseEntity { 11 | @TableId 12 | private Long id; 13 | private Long userId; 14 | private Long roleId; 15 | @TableLogic // 逻辑删除 16 | private Integer isDel; 17 | } 18 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-file/src/main/java/com/igroupes/rtadmin/file/core/QiniuFileStoreConfig.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.file.core; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class QiniuFileStoreConfig extends FileStoreConfig { 7 | 8 | private String accessKey; 9 | 10 | private String secretKey; 11 | 12 | private String bucket; 13 | 14 | private Integer maxUploadCount; 15 | 16 | private Integer uploadExpireSeconds; 17 | 18 | private Integer downloadExpireSeconds; 19 | 20 | private String bucketDomain; 21 | 22 | private String keyPrefix; // 前綴 23 | } 24 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/config/RequestProperties.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Data 8 | @Configuration 9 | @ConfigurationProperties(prefix = "rtadmin.request") 10 | public class RequestProperties { 11 | private String logRequestTypeFilter; 12 | private String limitExcludePath; 13 | private String logExcludePath; 14 | private String logRecordExcludeField; 15 | } 16 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/entity/SystemPermissionEntity.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableId; 4 | import com.baomidou.mybatisplus.annotation.TableLogic; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import lombok.Data; 7 | 8 | @Data 9 | @TableName("system_perm") 10 | public class SystemPermissionEntity extends BaseEntity { 11 | @TableId 12 | private Long id; 13 | private String limitDetail; 14 | private String api; 15 | @TableLogic // 逻辑删除 16 | private Integer isDel; 17 | } 18 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/reponse/StatResponse.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.reponse; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | @Data 8 | public class StatResponse { 9 | private List list; 10 | 11 | @Data 12 | public static class StatResponseDetail { 13 | private String date; 14 | private Integer loginCount; 15 | private Integer registerCount; 16 | private Integer userCount; 17 | private Integer showCount; 18 | private Integer showUserCount; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/reponse/UserTreeResponse.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.reponse; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | @Data 8 | public class UserTreeResponse { 9 | private String nickname; 10 | private Long id; 11 | private List children; 12 | 13 | public UserTreeResponse(Long id){ 14 | this.id =id; 15 | } 16 | public UserTreeResponse(Long id,String nickname){ 17 | this.id =id; 18 | this.nickname = nickname; 19 | } 20 | public UserTreeResponse(){ 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/entity/SystemRolePermissionEntity.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.entity; 2 | 3 | 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableLogic; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import lombok.Data; 8 | 9 | @Data 10 | @TableName("system_role_perm") 11 | public class SystemRolePermissionEntity extends BaseEntity { 12 | @TableId 13 | private Long id; 14 | private Long permId; 15 | private Long roleId; 16 | @TableLogic // 逻辑删除 17 | private Integer isDel; 18 | } 19 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/config/FileStoreProperties.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Data 8 | @Configuration 9 | @ConfigurationProperties(prefix = "rtadmin.file-store") 10 | public class FileStoreProperties { 11 | private String fileStoreDir; // 文件存储目录 12 | private long storeDirMaxBytes; // 存储目录的最大字节大小 13 | private String downloadUrlPrefix; // 下载的url前缀 14 | private String type; 15 | } 16 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/reponse/RoleListResponse.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.reponse; 2 | 3 | import com.igroupes.rtadmin.dto.PageResponse; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | @Data 8 | public class RoleListResponse extends PageResponse{ 9 | private List list; 10 | 11 | 12 | @Data 13 | public static class RoleListResponseDetail { 14 | private Long id; 15 | private String name; 16 | private String desc; 17 | private String createTime; 18 | private String updateTime; 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/mapper/SystemLogMapper.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.mapper; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 6 | import com.igroupes.rtadmin.entity.SystemLogEntity; 7 | import com.igroupes.rtadmin.query.SystemLogQuery; 8 | import org.apache.ibatis.annotations.Param; 9 | 10 | import java.util.List; 11 | 12 | public interface SystemLogMapper extends BaseMapper { 13 | 14 | List getSystemLogList(Page page , @Param("query") SystemLogQuery query); 15 | } 16 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/aop/LoginUser.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.aop; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target({ElementType.TYPE,ElementType.METHOD}) 10 | public @interface LoginUser { 11 | /** 12 | * true: 表示修饰的类和方法必须登录 13 | * false: 表示不一定要登录,但是会传递用户id,如果方法参数中有com.igroupes.rtadmin.dto.UserInfo对象,在没有登录情况下,赋值为null 14 | * @return 15 | */ 16 | boolean require() default true; 17 | } 18 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/EnumUtils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import com.igroupes.rtadmin.enums.CodeEnum; 4 | 5 | public class EnumUtils { 6 | 7 | /** 8 | * 返回指定编码的'枚举' 9 | * 10 | * @param code 11 | * @return SharedObjTypeEnum 12 | * @throws 13 | */ 14 | public static > T getEnumByCode(Class clazz, E code) { 15 | for (T _enum : clazz.getEnumConstants()){ 16 | if (code == _enum.getCode()){ 17 | return _enum; 18 | } 19 | } 20 | return null; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-file/src/main/java/com/igroupes/rtadmin/file/core/FileStore.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.file.core; 2 | 3 | import java.io.InputStream; 4 | 5 | public interface FileStore { 6 | /** 7 | * 上传文件,返回唯一标识 8 | * @param is 9 | * @return 10 | */ 11 | String uploadFile(InputStream is) ; 12 | 13 | /** 14 | * 根据key删除文件,true:删除成功 15 | * @param key 16 | */ 17 | boolean delete(String key) ; 18 | 19 | /** 20 | * 返回下载地址 21 | * @param key 22 | * @return 23 | */ 24 | String downloadUrl(String key) ; 25 | 26 | InputStream fileStream(String key); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/IFileService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service; 2 | 3 | import com.igroupes.rtadmin.dto.UserInfo; 4 | import com.igroupes.rtadmin.vo.ResultVO; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | 11 | public interface IFileService { 12 | ResultVO uploadImage(UserInfo userInfo, InputStream inputStream, HttpServletRequest request); 13 | 14 | void getImage(String key, HttpServletRequest request, HttpServletResponse response) throws IOException; 15 | } 16 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/entity/SystemRoleEntity.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableId; 4 | import com.baomidou.mybatisplus.annotation.TableLogic; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import lombok.Data; 7 | 8 | @Data 9 | @TableName("system_role") 10 | public class SystemRoleEntity extends BaseEntity { 11 | @TableId 12 | private Long id; 13 | private String name; 14 | private String desc; 15 | private Long parentId; 16 | private String parentChain; 17 | @TableLogic // 逻辑删除 18 | private Integer isDel; 19 | } 20 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/mapper/SystemUserStatMapper.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.igroupes.rtadmin.entity.SystemUserStatEntity; 5 | import com.igroupes.rtadmin.result.StatResult; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | import java.util.List; 9 | 10 | public interface SystemUserStatMapper extends BaseMapper{ 11 | 12 | List getStat(@Param("startDate") String startDate ,@Param("endDate") String endDate); 13 | 14 | 15 | Integer getUserCount(@Param("endDate") String endDate); 16 | } 17 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/resources/mapper/SystemRolePermissionMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/IStatService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service; 2 | 3 | import com.igroupes.rtadmin.dto.UserInfo; 4 | import com.igroupes.rtadmin.dto.request.StatGetRequest; 5 | import com.igroupes.rtadmin.dto.request.StatRequest; 6 | import com.igroupes.rtadmin.vo.ResultVO; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | public interface IStatService { 12 | ResultVO addStat(UserInfo userInfo, HttpServletRequest httpRequest, HttpServletResponse httpResponse, StatRequest request); 13 | 14 | ResultVO getStat(StatGetRequest request); 15 | } 16 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/entity/SystemLogEntity.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.entity; 2 | 3 | 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import lombok.Data; 7 | 8 | @Data 9 | @TableName("system_log") 10 | public class SystemLogEntity extends BaseEntity { 11 | public static final int RESULT_SUCCESS = 1; 12 | public static final int RESULT_FAIL = 2; 13 | @TableId 14 | private Long id; 15 | private String actionAddr; 16 | private Long userId; 17 | private String nickname; 18 | private Integer result; 19 | private String failDesc; 20 | private String detail; 21 | } 22 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/UserInfo.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 包含当前用户的基本信息 7 | */ 8 | @Data 9 | public class UserInfo { 10 | private Long id; 11 | private String username; //登录用户名 12 | private String nickname; 13 | private String avatar; 14 | private String password; 15 | private String salt;//加密密码的盐 16 | private Integer isDel; 17 | private String desc; 18 | private String signature; 19 | private Long parentId; 20 | private String parentChain; 21 | private String addTime; 22 | private String updateTime; 23 | private Long addUser; 24 | private Long updateUser; 25 | } 26 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/reponse/SystemLogListResponse.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.reponse; 2 | 3 | import com.igroupes.rtadmin.dto.PageResponse; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | @Data 9 | public class SystemLogListResponse extends PageResponse { 10 | private List list; 11 | 12 | 13 | @Data 14 | public static class SystemLogListResponseDetail { 15 | private Long id; 16 | private String actionAddr; 17 | private Long handlerId; 18 | private String handlerName; 19 | private Integer result; 20 | private String failDesc; 21 | private String createTime; 22 | private String detail; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/resources/mapper/SystemPermissionMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/RtAdminApplication.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.web.servlet.ServletComponentScan; 6 | import org.springframework.context.annotation.ComponentScan; 7 | import org.springframework.transaction.annotation.EnableTransactionManagement; 8 | 9 | @SpringBootApplication 10 | @EnableTransactionManagement 11 | @ComponentScan(basePackages = "com.igroupes") 12 | @ServletComponentScan(basePackages = "com.igroupes") 13 | public class RtAdminApplication { 14 | public static void main(String[] args) { 15 | SpringApplication.run(RtAdminApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/IVerifyCodeManager.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service; 2 | 3 | import lombok.Data; 4 | 5 | public interface IVerifyCodeManager { 6 | 7 | public VerifyCode genCode(CodeType codeType); 8 | public boolean isRightVerifyCode(Long codeKey, String code); 9 | public String getVerifyCode(Long codeKey); 10 | public void deleteVerifyCode(Long codeKey); 11 | public void close(); // 关闭资源 12 | /** 13 | * T代表code对应的资源,可能是图片 14 | * 15 | * @param 16 | */ 17 | @Data 18 | public class VerifyCode { 19 | private String code; 20 | private T data; 21 | private Long codeId; // 当前校验码的唯一标识 22 | } 23 | 24 | public enum CodeType { 25 | SIMPLE_PICTURE, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/raw/SystemUserService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service.raw; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.igroupes.rtadmin.entity.SystemUserEntity; 6 | import com.igroupes.rtadmin.mapper.SystemUserMapper; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | 12 | @Service 13 | public class SystemUserService extends ServiceImpl { 14 | @Autowired 15 | private SystemUserMapper systemUserMapper; 16 | 17 | public List getUserChain(String parentChain) { 18 | return systemUserMapper.getUserChain(parentChain); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/PathUtils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | public class PathUtils { 6 | private PathUtils() { 7 | } 8 | 9 | public static String normalize(String parentPath, String childPath) { 10 | if (StringUtils.isBlank(parentPath)) { 11 | return childPath; 12 | } 13 | if (StringUtils.isBlank(childPath)) { 14 | return parentPath; 15 | } 16 | if (!parentPath.endsWith("/")) { 17 | parentPath = parentPath + "/"; 18 | } 19 | if (childPath.startsWith("/")) { 20 | return parentPath + childPath.substring(1); 21 | } else { 22 | return parentPath + childPath; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-file/src/main/java/com/igroupes/rtadmin/file/core/FileStoreAdapter.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.file.core; 2 | 3 | import java.io.InputStream; 4 | 5 | public class FileStoreAdapter implements FileStore { 6 | 7 | @Override 8 | public String uploadFile(InputStream is) { 9 | throw new UnsupportedOperationException("upload file"); 10 | } 11 | 12 | @Override 13 | public boolean delete(String key) { 14 | throw new UnsupportedOperationException("delete"); 15 | } 16 | 17 | @Override 18 | public String downloadUrl(String key) { 19 | throw new UnsupportedOperationException("download url"); 20 | } 21 | 22 | @Override 23 | public InputStream fileStream(String key) { 24 | throw new UnsupportedOperationException("file stream"); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/entity/SystemUserEntity.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.entity; 2 | 3 | 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableLogic; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import lombok.Data; 8 | 9 | @Data 10 | @TableName("system_user") 11 | public class SystemUserEntity extends BaseEntity { 12 | @TableId 13 | private Long id; 14 | private String username; //登录用户名 15 | private String nickname; 16 | private String avatar; 17 | private String password; 18 | private String salt;//加密密码的盐 19 | private Long parentId; 20 | private String desc; 21 | private String signature; 22 | private String parentChain; // 父级用户链 23 | @TableLogic // 逻辑删除 24 | private Integer isDel; 25 | } 26 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/test/java/com/igroupes/rtadmin/util/VerifyCodeUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | import javax.imageio.ImageIO; 8 | import java.awt.image.BufferedImage; 9 | import java.io.FileOutputStream; 10 | import java.io.IOException; 11 | import java.io.OutputStream; 12 | 13 | @RunWith(SpringRunner.class) 14 | public class VerifyCodeUtilTest { 15 | 16 | @Test 17 | public void createImage() throws IOException { 18 | Object[] objs = VerifyCodeUtil.createImage(); 19 | BufferedImage image = (BufferedImage) objs[1]; 20 | OutputStream os = new FileOutputStream("d:/1.png"); 21 | ImageIO.write(image, "png", os); 22 | os.close(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/reponse/UserInfoPageResponse.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.reponse; 2 | 3 | import com.igroupes.rtadmin.dto.PageResponse; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | @Data 9 | public class UserInfoPageResponse extends PageResponse { 10 | private List list; 11 | 12 | @Data 13 | public static class UserInfoPageResponseDetail { 14 | private Long id; 15 | private String username; 16 | private String nickname; 17 | private String avatar; 18 | private Long limitId; 19 | private String desc; 20 | private String createTime; 21 | private String updateTime; 22 | private Long parentId; 23 | private String roleName; 24 | private Long roleId; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/test/java/com/igroupes/rtadmin/util/RequestPathTrieTest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class RequestPathTrieTest { 7 | 8 | @Test 9 | public void find() { 10 | RequestPathTrie requestPathTrie = new RequestPathTrie(); 11 | requestPathTrie.addPath("aa/bb/cc/$id","path1"); 12 | requestPathTrie.addPath("aa/bb/cc/$id","path2"); 13 | requestPathTrie.addPath("aa/bb/cc/$id/123","path3"); 14 | // Assert.assertEquals(requestPathTrie.find("/aa/bb/cc/$id"),"path2"); 15 | Assert.assertEquals(requestPathTrie.find("aa/bb/cc/100"),"path2"); 16 | Assert.assertEquals(requestPathTrie.find("aa/bb/cc/100/123"),"path3"); 17 | Assert.assertEquals(requestPathTrie.find("aa/bb/cc/100/1234"),null); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/dto/request/StatRequest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.dto.request; 2 | 3 | import com.igroupes.rtadmin.enums.CodeMessageEnum; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class StatRequest { 8 | private Integer code; 9 | private String detail; 10 | 11 | public enum StatCode implements CodeMessageEnum { 12 | REFRESH_PAGE(100001, "刷新页面"); 13 | 14 | StatCode(Integer code, String message) { 15 | this.code = code; 16 | this.message = message; 17 | } 18 | 19 | private String message; 20 | private Integer code; 21 | 22 | @Override 23 | public String getMessage() { 24 | return message; 25 | } 26 | 27 | @Override 28 | public Integer getCode() { 29 | return code; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/mapper/SystemRoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.mapper; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.igroupes.rtadmin.entity.SystemPermissionEntity; 6 | import com.igroupes.rtadmin.entity.SystemRoleEntity; 7 | import org.apache.ibatis.annotations.Param; 8 | 9 | import java.util.List; 10 | 11 | public interface SystemRoleMapper extends BaseMapper { 12 | /** 13 | * 注意:如果需要查找某一个role的子角色,需要先拼出该角色的完整role-chain 14 | * @param curParentChain 15 | * @return 16 | */ 17 | List getChildPermList(@Param("curParentChain") String curParentChain); 18 | 19 | List getFilterRole(@Param("userId")Long userId, @Param("filter") String filter); 20 | 21 | List getChildRoleList(@Param("curParentChain") String curParentChain); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/raw/SystemPermissionService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service.raw; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.igroupes.rtadmin.entity.SystemPermissionEntity; 6 | import com.igroupes.rtadmin.mapper.SystemPermissionMapper; 7 | import com.igroupes.rtadmin.util.Requires; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | @Service 12 | public class SystemPermissionService extends ServiceImpl { 13 | @Autowired 14 | private SystemPermissionMapper systemPermissionMapper; 15 | 16 | public SystemPermissionEntity getPermissionById(Long userId) { 17 | Requires.requireNonNull(userId, "user id"); 18 | return systemPermissionMapper.getPermissionById(userId); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/mapper/SystemUserRoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.igroupes.rtadmin.entity.SystemRoleEntity; 6 | import com.igroupes.rtadmin.entity.SystemUserRoleEntity; 7 | import com.igroupes.rtadmin.result.SystemUserResult; 8 | import org.apache.ibatis.annotations.Param; 9 | 10 | import java.util.List; 11 | 12 | public interface SystemUserRoleMapper extends BaseMapper { 13 | 14 | SystemRoleEntity getRoleById(@Param("userId") Long userId); 15 | 16 | List getFilterUserPage(Page page , @Param("userId") Long userId, @Param("filter") String filter, @Param("roleIds") String roles); 17 | 18 | void deleteUserList(@Param("userIds") List userIds , @Param("roleId") Long roleId); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/test/java/com/igroupes/rtadmin/util/SetUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import com.google.common.collect.Sets; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | import java.util.HashSet; 10 | 11 | @RunWith(SpringRunner.class) 12 | public class SetUtilsTest { 13 | 14 | @Test 15 | public void intersect(){ 16 | HashSet set1 = Sets.newHashSet(1, 2, 3); 17 | HashSet set2 = Sets.newHashSet(1, 2, 4); 18 | Assert.assertEquals(2,SetUtils.intersect(set1,set2).size()); 19 | Assert.assertEquals(1,SetUtils.diff(set1,set2).size()); 20 | Assert.assertEquals(4,SetUtils.union(set1,set2).size()); 21 | } 22 | 23 | 24 | @Test 25 | public void union(){ 26 | 27 | } 28 | 29 | 30 | @Test 31 | public void diff(){ 32 | 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-file/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rt-admin-parent 7 | com.igroupes 8 | 0.0.1 9 | 10 | 4.0.0 11 | 12 | rt-admin-file 13 | 14 | 15 | 16 | com.igroupes 17 | rt-admin-common 18 | 19 | 20 | 21 | com.qiniu 22 | qiniu-java-sdk 23 | [7.2.0, 7.2.99] 24 | 25 | 26 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/RtThread.java: -------------------------------------------------------------------------------- 1 | package com.igroupes; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | public class RtThread extends Thread { 7 | 8 | private static final Logger LOG = LoggerFactory 9 | .getLogger(RtThread.class); 10 | 11 | private UncaughtExceptionHandler uncaughtExceptionalHandler = new UncaughtExceptionHandler() { 12 | 13 | @Override 14 | public void uncaughtException(Thread t, Throwable e) { 15 | handleException(t.getName(), e); 16 | } 17 | }; 18 | 19 | public RtThread(String threadName) { 20 | super(threadName); 21 | setUncaughtExceptionHandler(uncaughtExceptionalHandler); 22 | } 23 | 24 | /** 25 | * 默认的不可捕获异常处理 26 | * @param thName 27 | * @param e 28 | */ 29 | protected void handleException(String thName, Throwable e) { 30 | LOG.warn("Exception occurred from thread {}", thName, e); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/ExceptionUtils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import com.igroupes.rtadmin.enums.ErrorCode; 4 | import com.igroupes.rtadmin.file.exception.BusinessException; 5 | 6 | import javax.validation.ConstraintViolationException; 7 | 8 | public class ExceptionUtils { 9 | private ExceptionUtils() { 10 | } 11 | 12 | public static BusinessException warp(Exception exception) { 13 | if (exception instanceof BusinessException) { 14 | return (BusinessException) exception; 15 | } else if(exception instanceof ConstraintViolationException) { 16 | ConstraintViolationException ex = (ConstraintViolationException)exception; 17 | ErrorCode ec = ErrorCode.PARAM_ERROR; 18 | ec.setMessage(ex.getMessage()); 19 | return new BusinessException(ec); 20 | }else{ 21 | return new BusinessException(ErrorCode.SYSTEM_ERROR); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/raw/SystemRolePermissionService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service.raw; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.igroupes.rtadmin.entity.SystemPermissionEntity; 6 | import com.igroupes.rtadmin.entity.SystemRolePermissionEntity; 7 | import com.igroupes.rtadmin.mapper.SystemRolePermissionMapper; 8 | import com.igroupes.rtadmin.util.Requires; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | 12 | @Service 13 | public class SystemRolePermissionService extends ServiceImpl { 14 | @Autowired 15 | private SystemRolePermissionMapper systemRolePermissionMapper; 16 | 17 | 18 | public SystemPermissionEntity getPermissionById(Long roleId) { 19 | Requires.requireNonNull(roleId,"role id"); 20 | return systemRolePermissionMapper.getPermissionById(roleId); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/IPermissionService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service; 2 | 3 | import com.igroupes.rtadmin.dto.UserInfo; 4 | import com.igroupes.rtadmin.dto.request.*; 5 | import com.igroupes.rtadmin.vo.ResultVO; 6 | 7 | import javax.validation.Valid; 8 | 9 | public interface IPermissionService { 10 | ResultVO addRole(UserInfo userInfo, RoleAddRequest request); 11 | 12 | ResultVO updateLimit(UserInfo userInfo, Long id, PermissionUpdateRequest request); 13 | 14 | ResultVO getLimitList(UserInfo userInfo, Long roleId, PermissionListRequest request); 15 | 16 | ResultVO deleteRole(UserInfo userInfo, Long roleId); 17 | 18 | ResultVO getRoleList(UserInfo userInfo, @Valid RoleListRequest request); 19 | 20 | ResultVO getFilterRole(UserInfo userInfo,FilterRoleRequest request); 21 | 22 | ResultVO updateRole(UserInfo userInfo, Long roleId, RoleUpdateRequest request); 23 | 24 | ResultVO updateRoleMember(UserInfo userInfo, @Valid RoleMemberUpdateRequest request); 25 | } 26 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/PageDTOUtil.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; 5 | import com.igroupes.rtadmin.dto.PageRequest; 6 | import com.igroupes.rtadmin.dto.PageResponse; 7 | 8 | public class PageDTOUtil { 9 | 10 | 11 | public static void fixPageDTO(PageRequest pageRequest) { 12 | final int DEFAULT_LIMIT = 50; 13 | if (null != pageRequest) { 14 | if (null == pageRequest.getPage() || pageRequest.getPage() < 0) { 15 | pageRequest.setPage(0); 16 | } 17 | if (null == pageRequest.getSize() || pageRequest.getSize() < 0) { 18 | pageRequest.setSize(DEFAULT_LIMIT); 19 | } 20 | 21 | } 22 | } 23 | 24 | public static void setPageResponse(IPage page, PageResponse pageResponse) { 25 | pageResponse.setCount(page.getTotal()); 26 | pageResponse.setPage(page.getCurrent()); 27 | pageResponse.setSize(page.getSize()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/raw/SystemLogService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service.raw; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 6 | import com.igroupes.rtadmin.entity.SystemLogEntity; 7 | import com.igroupes.rtadmin.mapper.SystemLogMapper; 8 | import com.igroupes.rtadmin.query.SystemLogQuery; 9 | import com.igroupes.rtadmin.util.Requires; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | import java.util.List; 14 | 15 | @Service 16 | public class SystemLogService extends ServiceImpl { 17 | @Autowired 18 | private SystemLogMapper systemLogMapper; 19 | 20 | public List getSystemLogList(Page page, SystemLogQuery query) { 21 | Requires.requireNonNull(query.getUserId() , "user id"); 22 | return systemLogMapper.getSystemLogList(page, query); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/test/java/com/igroupes/rtadmin/util/PermissionUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.Set; 6 | 7 | public class PermissionUtilsTest { 8 | @Test 9 | public void apiToPathTrie(){ 10 | String apiDetail = "GET rtapi/system/role/item,GET rtapi/system/role/filter?filter=$term,GET rtapi/system/user/item,POST rtapi/system/user/item,PUT rtapi/system/user/item/$id,DELETE rtapi/system/user/item/$id,GET rtapi/system/user/tree,POST rtapi/system/role/item/$id,PUT rtapi/system/role/item/$id,DELETE rtapi/system/role/item/$id,GET rtapi/system/role/item/$id/limit,PUT rtapi/system/role/item/$id/limit,PUT rtapi/system/role/member,GET rtapi/system/log/item"; 11 | RequestPathTrie> setRequestPathTrie = 12 | PermissionUtils.apiToPathTrie(apiDetail); 13 | Set strings = setRequestPathTrie.find("/rtapi/system/user/item"); 14 | System.out.println(strings); 15 | System.out.println(setRequestPathTrie); 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/file/exception/BusinessException.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.file.exception; 2 | 3 | import com.igroupes.rtadmin.enums.ResultEnum; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class BusinessException extends RuntimeException { 8 | private Integer statusCode; 9 | private Integer code; 10 | 11 | public BusinessException(String message) { 12 | super(message); 13 | } 14 | 15 | public BusinessException(ResultEnum resultEnum) { 16 | super(resultEnum.getMessage()); 17 | this.code = resultEnum.getCode(); 18 | } 19 | 20 | 21 | public BusinessException(Integer statusCode, String message) { 22 | super(message); 23 | this.statusCode = statusCode; 24 | } 25 | 26 | public BusinessException(Integer statusCode, String message, Throwable t) { 27 | super(message,t); 28 | this.statusCode = statusCode; 29 | } 30 | 31 | public BusinessException(String message, Throwable t) { 32 | super(message,t); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/raw/SystemUserStatService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service.raw; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.igroupes.rtadmin.dto.reponse.StatResponse; 5 | import com.igroupes.rtadmin.entity.SystemUserStatEntity; 6 | import com.igroupes.rtadmin.mapper.SystemUserStatMapper; 7 | import com.igroupes.rtadmin.result.StatResult; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.List; 12 | 13 | @Service 14 | public class SystemUserStatService extends ServiceImpl { 15 | @Autowired 16 | private SystemUserStatMapper systemUserStatMapper; 17 | 18 | 19 | public List getStat(String startDate , String endDate) { 20 | return systemUserStatMapper.getStat(startDate,endDate); 21 | } 22 | 23 | public Integer getUserCount(String endDate) { 24 | return systemUserStatMapper.getUserCount(endDate); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/Md5Utils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | 4 | import java.nio.charset.StandardCharsets; 5 | import java.security.MessageDigest; 6 | import java.security.NoSuchAlgorithmException; 7 | 8 | public class Md5Utils { 9 | private Md5Utils() { 10 | } 11 | 12 | 13 | private static ThreadLocal md5Local = new ThreadLocal<>(); 14 | 15 | public static String computeMd5(String k) { 16 | return computeMd5(k.getBytes(StandardCharsets.UTF_8)); 17 | } 18 | 19 | public static String computeMd5(byte[] b) { 20 | MessageDigest md5 = md5Local.get(); 21 | if (md5 == null) { 22 | try { 23 | md5 = MessageDigest.getInstance("MD5"); 24 | md5Local.set(md5); 25 | } catch (NoSuchAlgorithmException e) { 26 | throw new RuntimeException("MD5 not supported", e); 27 | } 28 | } 29 | md5.reset(); 30 | md5.update(b); 31 | return Base64Utils.encodeToString(md5.digest()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-file/src/main/java/com/igroupes/rtadmin/file/exception/FileStoreException.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.file.exception; 2 | 3 | public class FileStoreException extends RuntimeException{ 4 | public FileStoreException(String message) { 5 | super(message); 6 | } 7 | public FileStoreException(String message, Throwable cause) { 8 | super(message, cause); 9 | } 10 | public FileStoreException(Throwable cause) { 11 | super(cause); 12 | } 13 | 14 | public static class FileStoreConfigException extends FileStoreException{ 15 | public FileStoreConfigException(String message) { 16 | super(message); 17 | } 18 | } 19 | 20 | public static class FileStoreKeyException extends FileStoreException{ 21 | public FileStoreKeyException(String message) { 22 | super(message); 23 | } 24 | } 25 | 26 | public static class FileStoreOutOfSizeException extends FileStoreException{ 27 | public FileStoreOutOfSizeException(String message) { 28 | super(message); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-file/src/main/java/com/igroupes/rtadmin/file/core/FileStoreFactory.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.file.core; 2 | 3 | import com.igroupes.rtadmin.file.exception.FileStoreException; 4 | import org.apache.commons.lang3.StringUtils; 5 | 6 | import java.lang.reflect.Constructor; 7 | 8 | public class FileStoreFactory { 9 | private static final FileStoreFactory STORE_FACTORY = new FileStoreFactory(); 10 | 11 | public static FileStoreFactory instance() { 12 | return STORE_FACTORY; 13 | } 14 | 15 | public FileStore fileStore(String className, FileStoreConfig config) { 16 | if(StringUtils.isBlank(className)){ 17 | throw new FileStoreException("className is blank , can't create file store"); 18 | } 19 | 20 | Constructor constructor = null; 21 | try { 22 | Class fileStoreClazz = Class.forName(className); 23 | constructor = fileStoreClazz.getConstructor(FileStoreConfig.class); 24 | return constructor.newInstance(config); 25 | } catch (Exception ex) { 26 | throw new FileStoreException(ex); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rt-admin-parent 7 | com.igroupes 8 | 0.0.1 9 | 10 | 4.0.0 11 | 12 | rt-admin-common 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-validation 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-test 23 | 24 | 25 | com.baomidou 26 | mybatis-plus-extension 27 | 3.2.0 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/controller/StatController.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.controller; 2 | 3 | import com.igroupes.rtadmin.dto.UserInfo; 4 | import com.igroupes.rtadmin.dto.request.StatGetRequest; 5 | import com.igroupes.rtadmin.dto.request.StatRequest; 6 | import com.igroupes.rtadmin.service.IStatService; 7 | import com.igroupes.rtadmin.vo.ResultVO; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import javax.validation.Valid; 14 | 15 | @RestController 16 | @RequestMapping("stat") 17 | public class StatController { 18 | @Autowired 19 | private IStatService statService; 20 | 21 | 22 | @PostMapping("data") 23 | public ResultVO addStat(UserInfo userInfo, HttpServletRequest httpRequest, HttpServletResponse httpResponse, @RequestBody @Valid StatRequest request) { 24 | return statService.addStat(userInfo, httpRequest, httpResponse, request); 25 | } 26 | 27 | @GetMapping("data") 28 | public ResultVO getData(StatGetRequest request) { 29 | return statService.getStat(request); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/vo/ResultVO.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.vo; 2 | 3 | import com.igroupes.rtadmin.enums.ResultEnum; 4 | import lombok.Data; 5 | 6 | /** 7 | * 最终返回对象 8 | * 9 | * @param 10 | */ 11 | @Data 12 | public class ResultVO { 13 | public static int CODE_OK = 0; 14 | private Integer code; 15 | private String msg; 16 | private T data; 17 | 18 | public static ResultVO success(Object object) { 19 | ResultVO resultVO = new ResultVO(); 20 | resultVO.setData(object); 21 | resultVO.setCode(CODE_OK); 22 | return resultVO; 23 | } 24 | 25 | public static ResultVO success() { 26 | return success(null); 27 | } 28 | 29 | 30 | public static ResultVO error(String msg,Integer code) { 31 | ResultVO resultVO = new ResultVO(); 32 | resultVO.setCode(code); 33 | resultVO.setMsg(msg); 34 | return resultVO; 35 | } 36 | 37 | public static ResultVO error(ResultEnum resultEnum) { 38 | ResultVO resultVO = new ResultVO<>(); 39 | resultVO.setCode(resultEnum.getCode()); 40 | resultVO.setMsg(resultEnum.getMessage()); 41 | return resultVO; 42 | } 43 | 44 | 45 | 46 | } -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rt-admin-parent 7 | com.igroupes 8 | 0.0.1 9 | 10 | 4.0.0 11 | 12 | rt-admin-dao 13 | 14 | 15 | 16 | com.igroupes 17 | rt-admin-common 18 | 19 | 20 | 21 | mysql 22 | mysql-connector-java 23 | 24 | 25 | 26 | com.baomidou 27 | mybatis-plus-boot-starter 28 | 29 | 30 | 31 | 32 | com.alibaba 33 | druid 34 | 35 | 36 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/aop/LoginUserArgumentResolver.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.aop; 2 | 3 | import com.igroupes.rtadmin.constant.RtAdminConstant; 4 | import com.igroupes.rtadmin.dto.UserInfo; 5 | import org.springframework.core.MethodParameter; 6 | import org.springframework.web.bind.support.WebDataBinderFactory; 7 | import org.springframework.web.context.request.NativeWebRequest; 8 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 9 | import org.springframework.web.method.support.ModelAndViewContainer; 10 | 11 | public class LoginUserArgumentResolver implements HandlerMethodArgumentResolver { 12 | 13 | 14 | //使用自定义的注解 15 | @Override 16 | public boolean supportsParameter(MethodParameter methodParameter) { 17 | return methodParameter.getParameterType() == UserInfo.class; 18 | } 19 | 20 | //将值注入参数 21 | @Override 22 | public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception { 23 | return nativeWebRequest.getAttribute(RtAdminConstant.USER_INFO_REQUEST_ATTRIBUTE_KEY, NativeWebRequest.SCOPE_REQUEST); 24 | } 25 | 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/filter/HttpRequestResponseWrapperFilter.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.filter; 2 | 3 | import org.springframework.core.annotation.Order; 4 | 5 | import javax.servlet.*; 6 | import javax.servlet.annotation.WebFilter; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.io.IOException; 10 | 11 | /** 12 | * 装饰request,方便获取body 13 | */ 14 | @Order(1) 15 | @WebFilter(urlPatterns = "/*",filterName = "httpRequestWrapperFilter") 16 | public class HttpRequestResponseWrapperFilter implements Filter { 17 | @Override 18 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 19 | ServletRequest requestWrapper = new HttpRequestWrapper((HttpServletRequest) request); 20 | HttpResponseWrapper responseWrapper = new HttpResponseWrapper((HttpServletResponse)response); 21 | chain.doFilter(requestWrapper, responseWrapper); 22 | byte[] content = responseWrapper.getContent(); 23 | if (content.length > 0) { 24 | ServletOutputStream out = response.getOutputStream(); 25 | out.write(content); 26 | out.flush(); 27 | } 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/config/GlobalCorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.cors.CorsConfiguration; 6 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 7 | import org.springframework.web.filter.CorsFilter; 8 | 9 | @Configuration 10 | public class GlobalCorsConfig { 11 | @Bean 12 | public CorsConfiguration corsConfiguration() { 13 | CorsConfiguration corsConfiguration = new CorsConfiguration(); 14 | //实际请求中允许携带的首部字段 15 | corsConfiguration.addAllowedHeader("*"); 16 | //允许那些域跨域访问 17 | corsConfiguration.addAllowedOrigin("*"); 18 | //允许那些请求方法 19 | corsConfiguration.addAllowedMethod("*"); 20 | corsConfiguration.setAllowCredentials(true); 21 | return corsConfiguration; 22 | } 23 | 24 | @Bean 25 | public CorsFilter corsFilter(CorsConfiguration corsConfiguration) { 26 | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); 27 | source.registerCorsConfiguration("/**", corsConfiguration); // 4 28 | return new CorsFilter(source); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/StreamUtils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | 4 | import org.apache.commons.io.IOUtils; 5 | 6 | import java.io.ByteArrayInputStream; 7 | import java.io.ByteArrayOutputStream; 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | 11 | public class StreamUtils { 12 | private StreamUtils() { 13 | } 14 | 15 | /** 16 | * 将流转为支持mark的流,可以重用 17 | * 18 | * @param is 19 | * @return 20 | */ 21 | public static InputStream supportMarkInputStream(InputStream is) throws IOException { 22 | if (is.markSupported()) { 23 | return is; 24 | } 25 | ByteArrayOutputStream baos = null; 26 | byte[] bytes = null; 27 | try { 28 | baos = new ByteArrayOutputStream(); 29 | byte[] buffer = new byte[10 * 1024]; 30 | int len = -1; 31 | while ((len = is.read(buffer)) != -1) { 32 | baos.write(buffer, 0, len); 33 | } 34 | baos.flush(); 35 | bytes = baos.toByteArray(); 36 | }finally { 37 | IOUtils.closeQuietly(is); 38 | IOUtils.closeQuietly(baos); 39 | is = null; 40 | baos = null; 41 | } 42 | return new ByteArrayInputStream(bytes); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/TimeUtils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import java.util.Date; 4 | 5 | public class TimeUtils { 6 | private TimeUtils(){} 7 | /** 8 | * Returns time in milliseconds as does System.currentTimeMillis(), 9 | * but uses elapsed time from an arbitrary epoch more like System.nanoTime(). 10 | * The difference is that if somebody changes the system clock, 11 | * Time.currentElapsedTime will change but nanoTime won't. On the other hand, 12 | * all of ZK assumes that time is measured in milliseconds. 13 | * 14 | * @return The time in milliseconds from some arbitrary point in time. 15 | */ 16 | public static long currentElapsedTime() { 17 | return System.nanoTime() / 1000000; 18 | } 19 | 20 | /** 21 | * Explicitly returns system dependent current wall time. 22 | * @return Current time in msec. 23 | */ 24 | public static long currentWallTime() { 25 | return System.currentTimeMillis(); 26 | } 27 | 28 | /** 29 | * This is to convert the elapsedTime to a Date. 30 | * @return A date object indicated by the elapsedTime. 31 | */ 32 | public static Date elapsedTimeToDate(long elapsedTime) { 33 | long wallTime = currentWallTime() + elapsedTime - currentElapsedTime(); 34 | return new Date(wallTime); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/java/com/igroupes/rtadmin/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.config; 2 | 3 | import com.alibaba.druid.pool.DruidDataSource; 4 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; 5 | import org.mybatis.spring.annotation.MapperScan; 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; 10 | 11 | import javax.sql.DataSource; 12 | 13 | @Configuration 14 | @MapperScan("com.igroupes.rtadmin.mapper") 15 | public class MybatisPlusConfig { 16 | 17 | @Bean 18 | @ConfigurationProperties("spring.datasource.druid" ) 19 | public DataSource dataSource() { 20 | return new DruidDataSource(); 21 | } 22 | 23 | // 配置事物管理器 24 | @Bean(name="transactionManager") 25 | public DataSourceTransactionManager transactionManager(){ 26 | return new DataSourceTransactionManager(dataSource()); 27 | } 28 | 29 | /** 30 | * 分页插件 31 | * @return 32 | */ 33 | @Bean 34 | public PaginationInterceptor paginationInterceptor(){ 35 | PaginationInterceptor page = new PaginationInterceptor(); 36 | page.setDialectType("mysql"); 37 | return page; 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/raw/SystemRoleService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service.raw; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.igroupes.rtadmin.entity.SystemPermissionEntity; 5 | import com.igroupes.rtadmin.entity.SystemRoleEntity; 6 | import com.igroupes.rtadmin.mapper.SystemRoleMapper; 7 | import com.igroupes.rtadmin.util.Requires; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.List; 12 | 13 | @Service 14 | public class SystemRoleService extends ServiceImpl { 15 | 16 | @Autowired 17 | private SystemRoleMapper systemRoleMapper; 18 | 19 | public List getChildPermList(String curParentChain) { 20 | Requires.requireNonBlank(curParentChain, "parent chain"); 21 | return systemRoleMapper.getChildPermList(curParentChain); 22 | } 23 | 24 | public List getFilterRole(Long userId, String filter) { 25 | return systemRoleMapper.getFilterRole(userId , filter); 26 | } 27 | 28 | 29 | public List getChildRoleList(String curParentChain){ 30 | Requires.requireNonBlank(curParentChain, "parent chain"); 31 | return systemRoleMapper.getChildRoleList(curParentChain); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/resources/mapper/SystemRoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 16 | 17 | 26 | 27 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/aop/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.aop; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.igroupes.rtadmin.file.exception.BusinessException; 5 | import com.igroupes.rtadmin.util.ExceptionUtils; 6 | import com.igroupes.rtadmin.util.HttpUtils; 7 | import com.igroupes.rtadmin.vo.ResultVO; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.web.bind.annotation.ControllerAdvice; 10 | import org.springframework.web.bind.annotation.ExceptionHandler; 11 | import org.springframework.web.bind.annotation.ResponseBody; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | 16 | @Slf4j 17 | @ControllerAdvice 18 | public class GlobalExceptionHandler { 19 | 20 | @ExceptionHandler(Exception.class) 21 | @ResponseBody 22 | public ResultVO exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception exception) throws Exception { 23 | log.error("》》》》请求地址:{}",request.getRequestURI()); 24 | log.error("》》》》请求IP:{}", HttpUtils.getIpAddr(request)); 25 | log.error("》》》》请求方式:{}", request.getMethod()); 26 | log.error("》》》》请求参数:{}", JSON.toJSONString(request.getParameterMap())); 27 | log.error("》》》》异常信息:", exception); 28 | 29 | BusinessException businessException = ExceptionUtils.warp(exception); 30 | return ResultVO.error(businessException.getMessage(), businessException.getCode()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/resources/mapper/SystemLogMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/controller/FileController.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.controller; 2 | 3 | import com.igroupes.rtadmin.aop.LoginUser; 4 | import com.igroupes.rtadmin.aop.SkipLogin; 5 | import com.igroupes.rtadmin.dto.UserInfo; 6 | import com.igroupes.rtadmin.service.IFileService; 7 | import com.igroupes.rtadmin.vo.ResultVO; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.*; 10 | import org.springframework.web.multipart.MultipartFile; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import java.io.IOException; 15 | 16 | /** 17 | * 正常情况下,这个接口和file模块是单独放在一个项目中 18 | */ 19 | @RestController 20 | @RequestMapping("file") 21 | @LoginUser 22 | public class FileController { 23 | 24 | @Autowired 25 | private IFileService fileService; 26 | 27 | /** 28 | * 同时上传一个文件,返回url 29 | * 30 | * @param file 31 | * @return 32 | */ 33 | @PostMapping("/image") 34 | public ResultVO uploadImage(UserInfo userInfo, MultipartFile file, HttpServletRequest request) throws IOException { 35 | return fileService.uploadImage(userInfo, file.getInputStream(), request); 36 | } 37 | @SkipLogin 38 | @GetMapping("/image/{key}") 39 | public void getImage(@PathVariable String key, HttpServletRequest request, HttpServletResponse response) throws IOException { 40 | fileService.getImage( key, request, response); 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rt-admin-parent 7 | com.igroupes 8 | 0.0.1 9 | 10 | 4.0.0 11 | 12 | rt-admin 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-web 18 | 19 | 20 | com.igroupes 21 | rt-admin-service 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-test 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-aop 30 | 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-maven-plugin 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rt-admin-parent 7 | com.igroupes 8 | 0.0.1 9 | 10 | 4.0.0 11 | 12 | rt-admin-service 13 | 14 | 15 | 16 | com.igroupes 17 | rt-admin-dao 18 | 19 | 20 | org.springframework 21 | spring-web 22 | 23 | 24 | org.springframework 25 | spring-webmvc 26 | 27 | 28 | com.igroupes 29 | rt-admin-file 30 | 31 | 32 | org.apache.httpcomponents 33 | httpclient 34 | 35 | 36 | javax.validation 37 | validation-api 38 | 39 | 40 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service; 2 | 3 | 4 | import com.igroupes.rtadmin.dto.UserInfo; 5 | import com.igroupes.rtadmin.dto.request.*; 6 | import com.igroupes.rtadmin.vo.ResultVO; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import javax.validation.Valid; 11 | import java.awt.image.BufferedImage; 12 | 13 | public interface IUserService { 14 | ResultVO login(UserLoginRequest request, HttpServletRequest httpRequest, HttpServletResponse httpResponse); 15 | 16 | ResultVO logout(HttpServletRequest request, UserInfo userInfo); 17 | 18 | ResultVO changePassword(HttpServletRequest request, ChangePasswordRequest changePasswordRequest, UserInfo userInfo); 19 | 20 | ResultVO addUser(UserInfo userInfo, UserAddRequest request); 21 | 22 | ResultVO updateUser(UserInfo userInfo, Long userId , UserUpdateRequest request); 23 | 24 | ResultVO deleteUser(UserInfo userInfo, Long id); 25 | 26 | ResultVO getUserList(UserInfo userInfo,UserInfoPageRequest request); 27 | 28 | 29 | ResultVO info(UserInfo userInfo); 30 | 31 | ResultVO updateInfo(UserInfo userInfo, UserBaseInfoRequest request); 32 | 33 | BufferedImage verifyCode(HttpServletRequest request, HttpServletResponse response); 34 | 35 | 36 | boolean isHigherLevel(Long higherId, Long curId); 37 | 38 | ResultVO userTree(UserInfo userInfo); 39 | 40 | ResultVO demoRegister(@Valid UserRegisterRequest request, HttpServletRequest httpRequest, HttpServletResponse httpResponse); 41 | } 42 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/enums/ErrorCode.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.enums; 2 | 3 | public enum ErrorCode implements ResultEnum { 4 | 5 | SYSTEM_ERROR(-1,"系统异常"), 6 | PARAM_ERROR(10007,"参数错误"), 7 | USER_NOT_EXISTS(10020,"用户不存在"), 8 | PASSWORD_ERROR(10021,"密码错误"), 9 | PASSWORD_FORMAT_ERROR(10019,"密码格式错误"), 10 | TOKEN_NOT_EXISTS(10022,"token不存在"), 11 | TOKEN_EXPIRE(10023,"token过期"), 12 | PASSWORD_REPEAT(10024,"新旧密码一致"), 13 | PERMISSION_DENIED(10034,"权限不足"), 14 | CASCADING_DELETION_EXCEPTION(10054,"不能级联删除"), 15 | LIMIT_FORMAT_ERROR(10064,"接口权限格式错误"), 16 | VERIFY_CODE_ERROR(10074,"验证码错误"), 17 | USER_EXISTS(10084,"用户已经存在"), 18 | FILE_UPLOAD_FAIL(10094,"文件上传失败"), 19 | FILE_DOWNLOAD_FAIL(10095,"文件下载失败"), 20 | CONF_FORMAT_EXCEPTION(10200,"配置格式异常"), 21 | FILE_TYPE_ERROR(10100,"文件类型错误"), 22 | ROLE_BIND_USER(10110,"角色已经绑定了用户"), 23 | ROLE_CHILD_EXIST(10112,"存在子角色"), 24 | STAT_CODE_NOT_EXIST(10115,"统计code不存在"), 25 | ; 26 | 27 | ; 28 | ErrorCode(Integer code, String message) { 29 | this.code = code; 30 | this.message = message; 31 | } 32 | 33 | private Integer code; 34 | private String message; 35 | 36 | @Override 37 | public Integer getCode() { 38 | return code; 39 | } 40 | 41 | @Override 42 | public String getMessage() { 43 | return message; 44 | } 45 | 46 | public void setMessage(String message) { 47 | this.message = message; 48 | } 49 | 50 | public void setCode(Integer code) { 51 | this.code = code; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/raw/SystemUserRoleService.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service.raw; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 6 | import com.igroupes.rtadmin.entity.SystemRoleEntity; 7 | import com.igroupes.rtadmin.entity.SystemUserRoleEntity; 8 | import com.igroupes.rtadmin.mapper.SystemUserRoleMapper; 9 | import com.igroupes.rtadmin.result.SystemUserResult; 10 | import com.igroupes.rtadmin.util.Requires; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Service; 13 | 14 | import java.util.List; 15 | 16 | @Service 17 | public class SystemUserRoleService extends ServiceImpl { 18 | @Autowired 19 | private SystemUserRoleMapper systemUserRoleMapper; 20 | 21 | public SystemRoleEntity getRoleById(Long userId) { 22 | Requires.requireNonNull(userId, "user id"); 23 | return systemUserRoleMapper.getRoleById(userId); 24 | } 25 | 26 | 27 | public List getFilterUserList(Page page , Long userId, String filter, String roles) { 28 | Requires.requireNonNull(userId, "user id"); 29 | return systemUserRoleMapper.getFilterUserPage(page,userId, filter, roles); 30 | } 31 | 32 | public void deleteUserList(List userIds, Long roleId) { 33 | Requires.requireNonNull(userIds, "user ids"); 34 | Requires.requireNonNull(roleId, "role id"); 35 | systemUserRoleMapper.deleteUserList(userIds,roleId); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/ByteUtils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | 7 | public class ByteUtils { 8 | private ByteUtils() { 9 | } 10 | 11 | 12 | public static byte[] merge(byte[] b1, byte[] b2) { 13 | if (b1 == null || b1.length == 0) { 14 | return b2; 15 | } 16 | if (b2 == null || b2.length == 0) { 17 | return b1; 18 | } 19 | byte[] b3 = new byte[b1.length + b2.length]; 20 | System.arraycopy(b1, 0, b3, 0, b1.length); 21 | System.arraycopy(b2, 0, b3, b1.length, b2.length); 22 | return b3; 23 | } 24 | 25 | 26 | public static byte[] getByStream(InputStream is) throws IOException { 27 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 28 | int maxCount = 10 * 1024; 29 | byte[] buffer = new byte[maxCount]; 30 | int len = 0; 31 | while ( (len =is.read(buffer)) != -1) { 32 | bos.write(buffer, 0 ,len); 33 | } 34 | return bos.toByteArray(); 35 | } 36 | 37 | public static boolean isSame(byte[] b1, byte[] b2) { 38 | if (b1 == null) { 39 | return b2 == null; 40 | } 41 | if (b2 == null) { 42 | return false; 43 | } 44 | if (b1.length != b2.length) { 45 | return false; 46 | } 47 | for (int i = 0; i < b1.length; i++) { 48 | if (b1[i] != b2[i]) { 49 | return false; 50 | } 51 | } 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/HttpUtils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | public class HttpUtils { 6 | 7 | /** 8 | * 获取用户真实IP地址,不使用request.getRemoteAddr()的原因是有可能用户使用了代理软件方式避免真实IP地址, 9 | * 可是,如果通过了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP值 10 | * 11 | * @return ip 12 | */ 13 | public static String getIpAddr(HttpServletRequest request) { 14 | String ip = request.getHeader("x-forwarded-for"); 15 | if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) { 16 | // 多次反向代理后会有多个ip值,第一个ip才是真实ip 17 | if( ip.indexOf(",")!=-1 ){ 18 | ip = ip.split(",")[0]; 19 | } 20 | } 21 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 22 | ip = request.getHeader("Proxy-Client-IP"); 23 | } 24 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 25 | ip = request.getHeader("WL-Proxy-Client-IP"); 26 | } 27 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 28 | ip = request.getHeader("HTTP_CLIENT_IP"); 29 | } 30 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 31 | ip = request.getHeader("HTTP_X_FORWARDED_FOR"); 32 | } 33 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 34 | ip = request.getHeader("X-Real-IP"); 35 | } 36 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 37 | ip = request.getRemoteAddr(); 38 | } 39 | return ip; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/resources/mapper/SystemUserRoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 15 | 16 | 17 | 34 | 35 | 42 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/filter/HttpResponseWrapper.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.filter; 2 | 3 | import javax.servlet.ServletOutputStream; 4 | import javax.servlet.WriteListener; 5 | import javax.servlet.http.HttpServletResponse; 6 | import javax.servlet.http.HttpServletResponseWrapper; 7 | import java.io.ByteArrayOutputStream; 8 | import java.io.IOException; 9 | 10 | public class HttpResponseWrapper extends HttpServletResponseWrapper { 11 | 12 | private ByteArrayOutputStream buffer; 13 | 14 | private ServletOutputStream out; 15 | 16 | public HttpResponseWrapper(HttpServletResponse httpServletResponse) 17 | { 18 | super(httpServletResponse); 19 | buffer = new ByteArrayOutputStream(); 20 | out = new WrapperOutputStream(buffer); 21 | } 22 | 23 | @Override 24 | public ServletOutputStream getOutputStream() 25 | throws IOException 26 | { 27 | return out; 28 | } 29 | 30 | @Override 31 | public void flushBuffer() 32 | throws IOException 33 | { 34 | if (out != null) 35 | { 36 | out.flush(); 37 | } 38 | } 39 | 40 | public byte[] getContent() 41 | throws IOException 42 | { 43 | flushBuffer(); 44 | return buffer.toByteArray(); 45 | } 46 | 47 | class WrapperOutputStream extends ServletOutputStream 48 | { 49 | private ByteArrayOutputStream bos; 50 | 51 | public WrapperOutputStream(ByteArrayOutputStream bos) 52 | { 53 | this.bos = bos; 54 | } 55 | 56 | @Override 57 | public void write(int b) 58 | throws IOException 59 | { 60 | bos.write(b); 61 | } 62 | 63 | @Override 64 | public boolean isReady() 65 | { 66 | 67 | // TODO Auto-generated method stub 68 | return false; 69 | 70 | } 71 | 72 | @Override 73 | public void setWriteListener(WriteListener arg0) 74 | { 75 | 76 | // TODO Auto-generated method stub 77 | 78 | } 79 | } 80 | 81 | } -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/UserUtils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import com.igroupes.rtadmin.enums.ErrorCode; 4 | import com.igroupes.rtadmin.file.exception.RtAdminException; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.apache.commons.lang3.RandomStringUtils; 7 | import org.apache.commons.lang3.StringUtils; 8 | 9 | import java.util.UUID; 10 | 11 | @Slf4j 12 | public class UserUtils { 13 | 14 | private UserUtils() { 15 | } 16 | 17 | public static String genToken() { 18 | return UUID.randomUUID().toString().toLowerCase().replace("-", ""); 19 | } 20 | 21 | /** 22 | * 23 | * @param password 数据库中的密码 24 | * @param salt 加盐 25 | * @param checkPassword 准备校验的密码 26 | */ 27 | public static void checkPassword(String password,String salt, String checkPassword) { 28 | checkPasswordLength(checkPassword); 29 | if (!genPassword(checkPassword, salt).equals(password)) { 30 | throw new RtAdminException(ErrorCode.PASSWORD_ERROR); 31 | } 32 | } 33 | 34 | public static String genPassword(String password) { 35 | return genPassword(password,genSalt()); 36 | } 37 | 38 | public static String genPassword(String password, String salt) { 39 | if (StringUtils.isBlank(password) || StringUtils.isBlank(salt)) { 40 | throw new IllegalArgumentException("password or salt is blank"); 41 | } 42 | return Md5Utils.computeMd5(password + salt); 43 | } 44 | 45 | 46 | public static void checkPasswordLength(String password) { 47 | if (password.length() > 20 || password.length() < 6) { 48 | log.error("密码长度在[6-20]之间"); 49 | throw new RtAdminException(ErrorCode.PASSWORD_FORMAT_ERROR); 50 | } 51 | } 52 | 53 | public static String genSalt() { 54 | return RandomStringUtils.randomAlphanumeric(8); 55 | } 56 | 57 | 58 | public static void main(String[] args) { 59 | String salt = genSalt(); 60 | System.out.println(salt); 61 | System.out.println(genPassword("admin12345",salt)); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ovine-java-api说明书 2 | 1.后端采用技术:Spring+Springboot+MyBatis-Plus+MySQL 3 | 2.代码使用RESTful设计风格 4 | 5 | ## jar/框架对应版本 6 | - Java: 1.8 7 | - IO: 2.6 8 | - Maven: 3.1 9 | - SpringBoot:2.1.1.RELEASE 10 | - MyBatis-Plus:3.2.0 11 | - beanutils:1.9.1 12 | 13 | ## 本地部署项目 14 | 首先保证本地Java1.8能成功使用,有MySQL数据库 15 | 第一步. GitHub中clone项目 16 | > [源码地址][3] 17 | 18 | 第二步. 使用IDEA、Eclipse、MyEclipse等Java编程软件导入项目 19 | > [IDEA安装步骤][4] 20 | 21 | 第三步. 安装Lombok插件 22 | > [IDEA lombok插件安装][1] 23 | > [Eclipse lombok安装插件][2] 24 | 25 | 第四步. 修改配置文件yml, 26 | > rtadmin.file-store.file-store-dir配置中的文件路径必须存在,否则会报错 27 | 28 | 第五步. 安装MySQL,导入数据库 29 | > [本地部署MySQL][5] 30 | > sql文件与yml配置文件同级 31 | 32 | ## 源码介绍 33 | ### 源码参用多模块形式,将各模块进行分割具体如下 34 | - rt-admin 35 | > 1. aop ----自定义aop和拦截器 36 | GlobalExceptionHandler 异常捕获;LimitHandlerInterceptorAdapter权限拦截器;SystemLogHandlerInterceptorAdapter 系统登录拦截器;LoginUser必须登录注释;SkipLogin不需要登录注释;LoginUserArgumentResolver 引入自定义注释和用户信息注入参数中; LoginUserHandlerInterceptorAdapter注释登录拦截器; 37 | 2. config ---- 配置文件 38 | GlobalCorsConfig 跨域配置; WebMvcConfig 拦截器配置 39 | 3. controller ----Controller层所有接口 40 | 4. filter ----过滤器 41 | - rt-admin-common 42 | > 1. Constant ---项目有关常量 43 | 2. dto ---request、response和UserInfo相关类 44 | 3. enums ---所有枚举 45 | 4. file.exception ---自定义异常 46 | 5. util ---所有工具类(时间、md5等) 47 | 6. vo ---response返回格式 48 | - rt-admin-dao dao层配置 49 | > 1. config ---MyBatis配置 50 | MybatisPlusConfig MyBatis配置;MyMetaObjectHandler 注入值; 51 | 2. entity ---实体类 52 | 3. mapper 53 | 4. query 54 | 5. result 55 | - rt-admin-file ---file文件相关配置 56 | > 57 | 1. core 文件上传,读取相关实现类 58 | 2. exception 异常文件 59 | - rt-admin-service 60 | > 61 | 1. config yml配置参数对应类 62 | 2. service 63 | impl 重新装载service;raw 原生service类 64 | 65 | 66 | [1]: https://jingyan.baidu.com/article/0a52e3f4e53ca1bf63ed725c.html "IDEA lombok插件安装" 67 | [2]: https://www.cnblogs.com/boonya/p/10691466.html "Eclipse安装lombok插件" 68 | [3]: https://github.com/CareyToboo/ovine-java-api/tree/from000 "源码地址" 69 | [4]: https://jingyan.baidu.com/article/25648fc1eb1916d191fd00ed.html "IDEA安装步骤" 70 | [5]: https://jingyan.baidu.com/article/8065f87f527d8223312498af.html "本地MySQL部署" 71 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/SetUtils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import java.util.Collections; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | public class SetUtils { 8 | private SetUtils() { 9 | } 10 | 11 | /** 12 | * 交集 13 | * 14 | * @return 15 | */ 16 | public static Set intersect(Set set1, Set set2) { 17 | if (set1 == null || set2 == null || set1.isEmpty() || set2.isEmpty()) { 18 | return Collections.EMPTY_SET; 19 | } 20 | Set ret = new HashSet<>(); 21 | for (T t : set1) { 22 | if (set2.contains(t)) { 23 | ret.add(t); 24 | } 25 | } 26 | return ret; 27 | } 28 | 29 | /** 30 | * 并集 31 | * 32 | * @return 33 | */ 34 | public static Set union(Set set1, Set set2) { 35 | if (set1 == null || set1.isEmpty()) { 36 | if (set2 == null || set2.isEmpty()) { 37 | return Collections.EMPTY_SET; 38 | } else { 39 | return set2; 40 | } 41 | } 42 | if (set2 == null || set2.isEmpty()) { 43 | if (set1 == null || set1.isEmpty()) { 44 | return Collections.EMPTY_SET; 45 | } else { 46 | return set1; 47 | } 48 | } 49 | 50 | Set ret = set1; 51 | for (T t : set2) { 52 | if (!set1.contains(t)) { 53 | ret.add(t); 54 | } 55 | } 56 | return ret; 57 | } 58 | 59 | /** 60 | * 差集 61 | * set1-set2 , 元素在set1但是不在set2 62 | * 63 | * @return 64 | */ 65 | public static Set diff(Set set1, Set set2) { 66 | if (set1 == null || set1.isEmpty()) { 67 | return Collections.EMPTY_SET; 68 | } 69 | if (set2 == null || set2.isEmpty()) { 70 | if (set1 == null || set1.isEmpty()) { 71 | return Collections.EMPTY_SET; 72 | } else { 73 | return set1; 74 | } 75 | } 76 | 77 | Set ret = new HashSet<>(); 78 | for (T t : set1) { 79 | if (!set2.contains(t)) { 80 | ret.add(t); 81 | } 82 | } 83 | return ret; 84 | } 85 | 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/test/java/com/igroupes/rtadmin/controller/UserControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.controller; 2 | 3 | 4 | import com.alibaba.fastjson.JSON; 5 | import com.google.common.collect.Sets; 6 | import com.igroupes.rtadmin.dto.request.UserLoginRequest; 7 | import com.igroupes.rtadmin.vo.ResultVO; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.springframework.http.HttpEntity; 11 | import org.springframework.http.HttpHeaders; 12 | import org.springframework.http.HttpMethod; 13 | import org.springframework.http.ResponseEntity; 14 | import org.springframework.util.MultiValueMap; 15 | import org.springframework.web.client.RestTemplate; 16 | 17 | 18 | public class UserControllerTest { 19 | private RestTemplate restTemplate; 20 | 21 | @Before 22 | public void setRestTemplate(){ 23 | restTemplate = new RestTemplate(); 24 | } 25 | 26 | 27 | @Test 28 | public void login() { 29 | String url = "http://localhost:8081/rtapi/user/login"; 30 | UserLoginRequest request = new UserLoginRequest(); 31 | request.setPassword("admin12345"); 32 | request.setUsername("admin"); 33 | request.setCode("maPB"); 34 | ResultVO resultVO = restTemplate.postForObject(url, request,ResultVO.class); 35 | System.out.println(JSON.toJSON(resultVO)); 36 | } 37 | @Test 38 | public void verifyCode(){ 39 | String url = "http://localhost:8081/rtapi/user/code"; 40 | ResponseEntity responseEntity = restTemplate 41 | .exchange(url, HttpMethod.GET, null, byte[].class); 42 | } 43 | 44 | @Test 45 | public void info() { 46 | String url = "http://localhost:8081/rtapi/user/info"; 47 | HttpHeaders requestHeaders = new HttpHeaders(); 48 | requestHeaders.add("X-TOKEN", "86417c6d0f9f4071a8142de775df1820"); 49 | HttpEntity requestEntity = new HttpEntity(null, requestHeaders); 50 | ResponseEntity response = restTemplate.exchange(url.toString(), HttpMethod.GET, requestEntity, ResultVO.class); 51 | System.out.println(JSON.toJSON(response.getBody())); 52 | } 53 | 54 | 55 | 56 | public static void main(String[] args) { 57 | Sets.SetView difference = Sets.difference(Sets.newHashSet(1, 2, 3), Sets.newHashSet(1, 3, 4)); 58 | System.out.println(difference); 59 | } 60 | } -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/resources/application-test.yml: -------------------------------------------------------------------------------- 1 | 2 | # mysql 3 | spring: 4 | datasource: 5 | druid: 6 | driver-class-name: com.mysql.cj.jdbc.Driver 7 | url: jdbc:mysql://localhost:3306/rt_admin?prepStmtCacheSize=517&cachePrepStmts=true&autoReconnect=true&characterEncoding=utf-8&allowMultiQueries=true&serverTimezone=UTC&useSSL=false 8 | username: test 9 | password: Suijimima_12 10 | initialSize: 5 11 | minIdle: 5 12 | maxActive: 20 13 | maxWait: 60000 14 | timeBetweenEvictionRunsMillis: 60000 15 | minEvictableIdleTimemaillis: 300000 16 | validationQuery: SELECT 1 17 | testWhileIdle: true 18 | testOnBorrow: false 19 | testOnReturn: false 20 | poolPreparedStatements: true 21 | maxPoolPreparedStatementPerConnectionSize: 20 22 | 23 | 24 | #mybatis 25 | mybatis-plus: 26 | mapper-locations: classpath*:/mapper/**Mapper.xml 27 | #实体扫描,多个package用逗号或者分号分隔 28 | type-aliases-package: com.igroupes.rtadmin.entity 29 | global-config: 30 | db-config: 31 | column-format: "`%s`" 32 | id-type: auto 33 | logic-delete-value: "now()" 34 | logic-not-delete-value: "0" 35 | configuration: 36 | map-underscore-to-camel-case: true 37 | cache-enabled: false 38 | 39 | rest-template: 40 | maxTotalConnect: 100 #连接池的最大连接数 41 | maxConnectPerRoute: 200 #单个主机的最大连接数 42 | connectTimeout: 20000 #连接超时 43 | readTimeout: 30000 # 读超时 44 | 45 | 46 | rtadmin: 47 | login: 48 | # expire-time: 604800000 #7天 49 | expire-time: 604800000 50 | token-key: X-TOKEN 51 | expiry-queue: 52 | verify-code-interval: 300000 # 5分钟,多久分割一个桶 53 | verify-code-timeout: 300000 # 校验码多久过期 54 | request: 55 | limit-exclude-path: /user/(code|logout|login|info|password/) # 不校验权限的路径,正则表示式,剔除根路径 56 | log-request-type-filter: POST|PUT|DELETE # 过滤需要的请求类型,正则表达式 57 | log-exclude-path: /user/password:POST;/stat/data:* # 系统日志排除的路径(如果是通配地址使用$),格式:路径:请求方式,如果请求方式包含多个中间使用逗号隔开(*表示不限制请求方式) 58 | #系统日志不记录日志的字段,格式: 请求路径(如果是通配地址使用$):请求方式,如果请求方式包含多个中间使用逗号隔开(*表示不限制请求方式):字段列表(中间使用逗号隔开),多个请求中间使用 59 | log-record-exclude-field: /user/login:POST:password,code;/system/user/item/$:*:password 60 | 61 | file-store: 62 | type: com.igroupes.rtadmin.file.core.SimpleFileStore # 类全名 63 | file-store-dir: /tmp/file/ 64 | store-dir-max-bytes: 10737418240 65 | download-url-prefix: http://xtr46z.natappfree.cc/rtapi/file/image 66 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/resources/application-prd.yml: -------------------------------------------------------------------------------- 1 | 2 | # mysql 3 | spring: 4 | datasource: 5 | type: com.alibaba.druid.pool.DruidDataSource 6 | druid: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/rt_admin?prepStmtCacheSize=517&cachePrepStmts=true&autoReconnect=true&characterEncoding=utf-8&allowMultiQueries=true&serverTimezone=UTC&useSSL=false 9 | username: xxx 10 | password: xxxx 11 | initialSize: 5 12 | minIdle: 5 13 | maxActive: 20 14 | maxWait: 60000 15 | timeBetweenEvictionRunsMillis: 60000 16 | minEvictableIdleTimemaillis: 300000 17 | validationQuery: SELECT 1 18 | testWhileIdle: true 19 | testOnBorrow: false 20 | testOnReturn: false 21 | poolPreparedStatements: true 22 | maxPoolPreparedStatementPerConnectionSize: 20 23 | 24 | 25 | #mybatis 26 | mybatis-plus: 27 | mapper-locations: classpath*:/mapper/**Mapper.xml 28 | #实体扫描,多个package用逗号或者分号分隔 29 | type-aliases-package: com.igroupes.rtadmin.entity 30 | global-config: 31 | db-config: 32 | column-format: "`%s`" 33 | id-type: auto 34 | logic-delete-value: "now()" 35 | logic-not-delete-value: "0" 36 | configuration: 37 | map-underscore-to-camel-case: true 38 | cache-enabled: false 39 | 40 | rest-template: 41 | maxTotalConnect: 100 #连接池的最大连接数 42 | maxConnectPerRoute: 200 #单个主机的最大连接数 43 | connectTimeout: 20000 #连接超时 44 | readTimeout: 30000 # 读超时 45 | 46 | 47 | rtadmin: 48 | login: 49 | # expire-time: 604800000 #7天 50 | expire-time: 604800000 51 | token-key: X-TOKEN 52 | expiry-queue: 53 | verify-code-interval: 300000 # 5分钟,多久分割一个桶 54 | verify-code-timeout: 300000 # 校验码多久过期 55 | request: 56 | limit-exclude-path: /user/(code|logout|login|info|password/) # 不校验权限的路径,正则表示式,剔除根路径 57 | log-request-type-filter: POST|PUT|DELETE # 过滤需要的请求类型,正则表达式 58 | log-exclude-path: /user/password:POST;/stat/data:* # 系统日志排除的路径(如果是通配地址使用$),格式:路径:请求方式,如果请求方式包含多个中间使用逗号隔开(*表示不限制请求方式) 59 | #系统日志不记录日志的字段,格式: 请求路径(如果是通配地址使用$):请求方式,如果请求方式包含多个中间使用逗号隔开(*表示不限制请求方式):字段列表(中间使用逗号隔开),多个请求中间使用 60 | log-record-exclude-field: /user/login:POST:password,code;/system/user/item/$:*:password 61 | 62 | file-store: 63 | type: com.igroupes.rtadmin.file.core.SimpleFileStore # 类全名 64 | file-store-dir: /tmp/file/ 65 | store-dir-max-bytes: 10737418240 66 | download-url-prefix: http://xtr46z.natappfree.cc/rtapi/file/image 67 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | 2 | # mysql 3 | spring: 4 | datasource: 5 | type: com.alibaba.druid.pool.DruidDataSource 6 | druid: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/rt_admin?prepStmtCacheSize=517&cachePrepStmts=true&autoReconnect=true&characterEncoding=utf-8&allowMultiQueries=true&serverTimezone=UTC&useSSL=false 9 | username: root 10 | password: root 11 | initialSize: 5 12 | minIdle: 5 13 | maxActive: 20 14 | maxWait: 60000 15 | timeBetweenEvictionRunsMillis: 60000 16 | minEvictableIdleTimemaillis: 300000 17 | validationQuery: SELECT 1 18 | testWhileIdle: true 19 | testOnBorrow: false 20 | testOnReturn: false 21 | poolPreparedStatements: true 22 | maxPoolPreparedStatementPerConnectionSize: 20 23 | 24 | #mybatis 25 | mybatis-plus: 26 | mapper-locations: classpath*:/mapper/**Mapper.xml 27 | #实体扫描,多个package用逗号或者分号分隔 28 | type-aliases-package: com.igroupes.rtadmin.entity 29 | global-config: 30 | db-config: 31 | column-format: "`%s`" 32 | id-type: auto 33 | logic-delete-value: "now()" 34 | logic-not-delete-value: "0" 35 | configuration: 36 | map-underscore-to-camel-case: true 37 | cache-enabled: false 38 | 39 | rest-template: 40 | maxTotalConnect: 100 #连接池的最大连接数 41 | maxConnectPerRoute: 200 #单个主机的最大连接数 42 | connectTimeout: 20000 #连接超时 43 | readTimeout: 30000 # 读超时 44 | 45 | 46 | rtadmin: 47 | login: 48 | # expire-time: 604800000 #7天 49 | expire-time: 604800000 50 | token-key: X-TOKEN 51 | expiry-queue: 52 | verify-code-interval: 300000 # 5分钟,多久分割一个桶 53 | verify-code-timeout: 300000 # 校验码多久过期 54 | request: 55 | limit-exclude-path: /user/(code|logout|login|info|password|demo_register)|/stat/data # 不校验权限的路径,正则表示式,剔除根路径 56 | log-request-type-filter: POST|PUT|DELETE # 过滤需要的请求类型,正则表达式 57 | log-exclude-path: /user/password:POST;/stat/data:* # 系统日志排除的路径(如果是通配地址使用$),格式:路径:请求方式,如果请求方式包含多个中间使用逗号隔开(*表示不限制请求方式) 58 | #系统日志不记录日志的字段,格式: 请求路径(如果是通配地址使用$):请求方式,如果请求方式包含多个中间使用逗号隔开(*表示不限制请求方式):字段列表(中间使用逗号隔开),多个请求中间使用 59 | log-record-exclude-field: /user/login:POST:password,code;/system/user/item/$:*:password 60 | 61 | file-store: 62 | type: com.igroupes.rtadmin.file.core.SimpleFileStore # 类全名 63 | file-store-dir: /tmp/file/ 64 | store-dir-max-bytes: 10737418240 65 | download-url-prefix: http://xtr46z.natappfree.cc/rtapi/file/image 66 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/aop/LimitHandlerInterceptorAdapter.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.aop; 2 | 3 | import com.igroupes.rtadmin.config.RequestProperties; 4 | import com.igroupes.rtadmin.constant.RtAdminConstant; 5 | import com.igroupes.rtadmin.dto.UserInfo; 6 | import com.igroupes.rtadmin.entity.SystemPermissionEntity; 7 | import com.igroupes.rtadmin.enums.ErrorCode; 8 | import com.igroupes.rtadmin.file.exception.RtAdminException; 9 | import com.igroupes.rtadmin.service.raw.SystemPermissionService; 10 | import com.igroupes.rtadmin.util.PermissionUtils; 11 | import com.igroupes.rtadmin.util.Requires; 12 | import lombok.extern.slf4j.Slf4j; 13 | import org.apache.commons.lang3.StringUtils; 14 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 15 | 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | import java.util.regex.Pattern; 19 | 20 | @Slf4j 21 | public class LimitHandlerInterceptorAdapter extends HandlerInterceptorAdapter { 22 | private SystemPermissionService systemPermissionService; 23 | private RequestProperties requestProperties; 24 | 25 | public LimitHandlerInterceptorAdapter(SystemPermissionService systemPermissionService, RequestProperties requestProperties) { 26 | this.systemPermissionService = systemPermissionService; 27 | this.requestProperties = requestProperties; 28 | } 29 | 30 | @Override 31 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 32 | if (needLimit(request)) { 33 | UserInfo userInfo = (UserInfo) request.getAttribute(RtAdminConstant.USER_INFO_REQUEST_ATTRIBUTE_KEY); 34 | Requires.requireNonNull(userInfo, "user info"); 35 | Requires.requireNonNull(userInfo.getId(), "user id"); 36 | SystemPermissionEntity permissionDO = systemPermissionService.getPermissionById(userInfo.getId()); 37 | boolean pass = PermissionUtils.limitPass(permissionDO.getApi(), request); 38 | if (!pass) { 39 | throw new RtAdminException(ErrorCode.PERMISSION_DENIED); 40 | } 41 | return super.preHandle(request, response, handler); 42 | } 43 | 44 | return true; 45 | } 46 | 47 | 48 | private boolean needLimit(HttpServletRequest request) { 49 | return StringUtils.isBlank(requestProperties.getLimitExcludePath()) || !Pattern.matches(requestProperties.getLimitExcludePath(), request.getServletPath()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/VerifyCodeUtil.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import java.awt.*; 4 | import java.awt.image.BufferedImage; 5 | import java.util.Random; 6 | import java.util.concurrent.ThreadLocalRandom; 7 | 8 | public class VerifyCodeUtil { 9 | private VerifyCodeUtil() { 10 | } 11 | 12 | // 验证码字符集 13 | private static final char[] chars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 14 | 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; 15 | // 字符数量 16 | private static final int SIZE = 4; 17 | // 干扰线数量 18 | private static final int LINES = 10; 19 | // 宽度 20 | private static final int WIDTH = 90; 21 | // 高度 22 | private static final int HEIGHT = 40; 23 | // 字体大小 24 | private static final int FONT_SIZE = 30; 25 | 26 | /** 27 | * 生成随机验证码及图片 Object[0]:验证码字符串; Object[1]:验证码图片。 28 | */ 29 | public static Object[] createImage() { 30 | StringBuffer sb = new StringBuffer(); 31 | // 1.创建空白图片 32 | BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); 33 | // 2.获取图片画笔 34 | Graphics graphic = image.getGraphics(); 35 | // 3.设置画笔颜色 36 | graphic.setColor(Color.WHITE); 37 | // 4.绘制矩形背景 38 | graphic.fillRect(0, 0, WIDTH, HEIGHT); 39 | // 5.画随机字符 40 | Random ran = new Random(); 41 | for (int i = 0; i < SIZE; i++) { 42 | // 取随机字符索引 43 | int n = ran.nextInt(chars.length); 44 | // 设置随机颜色 45 | graphic.setColor(getRandomColor(150, 150, 150)); 46 | // 设置字体大小 47 | graphic.setFont(new Font(null, Font.BOLD + Font.ITALIC, FONT_SIZE)); 48 | // 画字符 49 | graphic.drawString(chars[n] + "", i * WIDTH / SIZE, HEIGHT * 2 / 3); 50 | // 记录字符 51 | sb.append(chars[n]); 52 | } 53 | // 6.画干扰线 54 | for (int i = 0; i < LINES; i++) { 55 | // 设置随机颜色 56 | graphic.setColor(getRandomColor(255, 255, 255)); 57 | // 随机画线 58 | graphic.drawLine(ran.nextInt(WIDTH), ran.nextInt(HEIGHT), ran.nextInt(WIDTH), ran.nextInt(HEIGHT)); 59 | } 60 | 61 | // 7.返回验证码和图片 62 | 63 | return new Object[]{sb.toString(), image}; 64 | } 65 | 66 | 67 | /** 68 | * 随机取色 69 | */ 70 | private static Color getRandomColor(int r, int g, int b) { 71 | Color color = new Color(ThreadLocalRandom.current().nextInt(r), 72 | ThreadLocalRandom.current().nextInt(g), ThreadLocalRandom.current().nextInt(b)); 73 | return color; 74 | } 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.controller; 2 | 3 | 4 | import com.igroupes.rtadmin.aop.LoginUser; 5 | import com.igroupes.rtadmin.aop.SkipLogin; 6 | import com.igroupes.rtadmin.dto.UserInfo; 7 | import com.igroupes.rtadmin.dto.request.ChangePasswordRequest; 8 | import com.igroupes.rtadmin.dto.request.UserBaseInfoRequest; 9 | import com.igroupes.rtadmin.dto.request.UserLoginRequest; 10 | import com.igroupes.rtadmin.dto.request.UserRegisterRequest; 11 | import com.igroupes.rtadmin.service.IUserService; 12 | import com.igroupes.rtadmin.vo.ResultVO; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.http.MediaType; 15 | import org.springframework.web.bind.annotation.*; 16 | 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpServletResponse; 19 | import javax.validation.Valid; 20 | import java.awt.image.BufferedImage; 21 | 22 | @RestController 23 | @RequestMapping("user") 24 | @LoginUser 25 | public class UserController { 26 | @Autowired 27 | private IUserService userService; 28 | 29 | @SkipLogin 30 | @PostMapping("login") 31 | public ResultVO login(@Valid @RequestBody UserLoginRequest request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) { 32 | return userService.login(request,httpRequest,httpResponse); 33 | } 34 | 35 | @SkipLogin 36 | @RequestMapping(value="code",produces = MediaType.IMAGE_JPEG_VALUE) 37 | public BufferedImage verifyCode(HttpServletRequest request, HttpServletResponse response) { 38 | return userService.verifyCode(request,response); 39 | } 40 | 41 | @PostMapping("logout") 42 | public ResultVO logout(UserInfo userInfo, HttpServletRequest request) { 43 | return userService.logout(request, userInfo); 44 | } 45 | 46 | @GetMapping("info") 47 | public ResultVO info(UserInfo userInfo) { 48 | return userService.info(userInfo); 49 | } 50 | 51 | 52 | @PutMapping("info") 53 | public ResultVO updateInfo(UserInfo userInfo, @Valid @RequestBody UserBaseInfoRequest request) { 54 | return userService.updateInfo(userInfo,request); 55 | } 56 | 57 | /** 58 | * 修改密碼 59 | * 60 | * @param userInfo 61 | * @param request 62 | * @return 63 | */ 64 | @PutMapping("password") 65 | public ResultVO changePassword(HttpServletRequest request, UserInfo userInfo, @Valid @RequestBody ChangePasswordRequest changePasswordRequest) { 66 | return userService.changePassword(request, changePasswordRequest, userInfo); 67 | } 68 | 69 | @SkipLogin 70 | @PostMapping("demo_register") 71 | public ResultVO demoRegister(@Valid @RequestBody UserRegisterRequest request,HttpServletRequest httpRequest, HttpServletResponse httpResponse){ 72 | return userService.demoRegister(request,httpRequest,httpResponse); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/filter/HttpRequestWrapper.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.filter; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import javax.servlet.ReadListener; 6 | import javax.servlet.ServletInputStream; 7 | import javax.servlet.ServletRequest; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletRequestWrapper; 10 | import java.io.*; 11 | import java.nio.charset.Charset; 12 | 13 | @Slf4j 14 | public class HttpRequestWrapper extends HttpServletRequestWrapper { 15 | private final byte[] body; 16 | 17 | public HttpRequestWrapper(HttpServletRequest request) throws IOException { 18 | super(request); 19 | String bodyStr = getBodyString(request); 20 | body = bodyStr.getBytes(Charset.defaultCharset()); 21 | } 22 | 23 | public String getBodyString(final ServletRequest request) { 24 | try { 25 | return inputStream2String(request.getInputStream()); 26 | } catch (IOException e) { 27 | log.error("", e); 28 | throw new RuntimeException(e); 29 | } 30 | } 31 | 32 | public String getBodyString() { 33 | final InputStream inputStream = new ByteArrayInputStream(body); 34 | return inputStream2String(inputStream); 35 | } 36 | 37 | private String inputStream2String(InputStream inputStream) { 38 | StringBuilder sb = new StringBuilder(); 39 | BufferedReader reader = null; 40 | 41 | try { 42 | reader = new BufferedReader(new InputStreamReader(inputStream, Charset.defaultCharset())); 43 | String line; 44 | while ((line = reader.readLine()) != null) { 45 | sb.append(line); 46 | } 47 | } catch (IOException e) { 48 | log.error("", e); 49 | throw new RuntimeException(e); 50 | } finally { 51 | if (reader != null) { 52 | try { 53 | reader.close(); 54 | } catch (IOException e) { 55 | log.error("", e); 56 | } 57 | } 58 | } 59 | 60 | return sb.toString(); 61 | } 62 | 63 | @Override 64 | public BufferedReader getReader() throws IOException { 65 | return new BufferedReader(new InputStreamReader(getInputStream())); 66 | } 67 | 68 | @Override 69 | public ServletInputStream getInputStream() throws IOException { 70 | 71 | final ByteArrayInputStream inputStream = new ByteArrayInputStream(body); 72 | 73 | return new ServletInputStream() { 74 | @Override 75 | public int read() throws IOException { 76 | return inputStream.read(); 77 | } 78 | 79 | @Override 80 | public boolean isFinished() { 81 | return false; 82 | } 83 | 84 | @Override 85 | public boolean isReady() { 86 | return false; 87 | } 88 | 89 | @Override 90 | public void setReadListener(ReadListener readListener) { 91 | } 92 | }; 93 | } 94 | } -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/config/RestTemplateConfig.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.config; 2 | 3 | import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; 4 | import org.apache.http.client.HttpClient; 5 | import org.apache.http.impl.client.HttpClientBuilder; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 8 | import org.springframework.boot.autoconfigure.http.HttpMessageConverters; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.http.client.ClientHttpRequestFactory; 11 | import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; 12 | import org.springframework.http.client.SimpleClientHttpRequestFactory; 13 | import org.springframework.http.converter.HttpMessageConverter; 14 | import org.springframework.http.converter.StringHttpMessageConverter; 15 | import org.springframework.stereotype.Component; 16 | import org.springframework.web.client.RestTemplate; 17 | 18 | import java.nio.charset.StandardCharsets; 19 | import java.util.List; 20 | 21 | @Component 22 | public class RestTemplateConfig { 23 | @Autowired 24 | private RestTemplateProperties configuration; 25 | @Autowired 26 | private HttpMessageConverters httpMessageConverters; 27 | 28 | //创建HTTP客户端工厂 29 | private ClientHttpRequestFactory createFactory() { 30 | if (configuration.getMaxTotalConnect() <= 0) { 31 | SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); 32 | factory.setConnectTimeout(configuration.getConnectTimeout()); 33 | factory.setReadTimeout(configuration.getReadTimeout()); 34 | return factory; 35 | } 36 | HttpClient httpClient = HttpClientBuilder.create().setMaxConnTotal(configuration.getMaxTotalConnect()) 37 | .setMaxConnPerRoute(configuration.getMaxConnectPerRoute()).build(); 38 | HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory( 39 | httpClient); 40 | factory.setConnectTimeout(configuration.getConnectTimeout()); 41 | factory.setReadTimeout(configuration.getReadTimeout()); 42 | return factory; 43 | } 44 | 45 | //初始化RestTemplate,并加入spring的Bean工厂,由spring统一管理 46 | @Bean 47 | @ConditionalOnMissingBean(RestTemplate.class) 48 | public RestTemplate getRestTemplate() { 49 | RestTemplate restTemplate = new RestTemplate(this.createFactory()); 50 | List> converterList = restTemplate.getMessageConverters(); 51 | 52 | //重新设置StringHttpMessageConverter字符集为UTF-8,解决中文乱码问题 53 | HttpMessageConverter converterTarget = null; 54 | for (HttpMessageConverter item : converterList) { 55 | if (StringHttpMessageConverter.class == item.getClass()) { 56 | converterTarget = item; 57 | break; 58 | } 59 | } 60 | if (null != converterTarget) { 61 | converterList.remove(converterTarget); 62 | } 63 | converterList.add(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); 64 | 65 | //加入FastJson转换器 根据使用情况进行操作,此段注释,默认使用jackson 66 | converterList.add(new FastJsonHttpMessageConverter()); 67 | return restTemplate; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/FileTypeUtils.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | import org.apache.commons.io.IOUtils; 4 | import org.apache.commons.lang3.ArrayUtils; 5 | import org.apache.commons.lang3.StringUtils; 6 | 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | 10 | public class FileTypeUtils { 11 | private FileTypeUtils() { 12 | } 13 | 14 | private static final FileType[] BASE_IMAGE_FILE_TYPE = {FileType.JPEG, FileType.PNG, FileType.GIF}; 15 | private static final int FLAG_LENGTH = 30; 16 | 17 | private static String bytesToHexString(byte[] src) { 18 | 19 | StringBuilder stringBuilder = new StringBuilder(); 20 | if (src == null || src.length <= 0) { 21 | return null; 22 | } 23 | for (int i = 0; i < src.length; i++) { 24 | int v = src[i] & 0xFF; 25 | String hv = Integer.toHexString(v); 26 | if (hv.length() < 2) { 27 | stringBuilder.append(0); 28 | } 29 | stringBuilder.append(hv); 30 | } 31 | return stringBuilder.toString(); 32 | } 33 | 34 | 35 | private static String getFileHead(InputStream in) { 36 | byte[] b = new byte[FLAG_LENGTH]; 37 | try { 38 | in.read(b, 0, FLAG_LENGTH); 39 | } catch (IOException io) { 40 | IOUtils.closeQuietly(in); 41 | } 42 | return bytesToHexString(b); 43 | } 44 | 45 | /** 46 | * 判断文件类型 47 | * 48 | * @return 文件类型 49 | */ 50 | public static FileType getType(InputStream in) { 51 | 52 | String fileHead = getFileHead(in); 53 | if (StringUtils.isBlank(fileHead)) { 54 | return null; 55 | } 56 | fileHead = fileHead.toUpperCase(); 57 | FileType[] fileTypes = FileType.values(); 58 | for (FileType type : fileTypes) { 59 | if (fileHead.startsWith(type.getValue())) { 60 | return type; 61 | } 62 | } 63 | return null; 64 | } 65 | 66 | public static boolean isImage(InputStream in) throws IOException { 67 | if (!in.markSupported()) { 68 | throw new IOException("mark/reset not supported"); 69 | } 70 | in.mark(FLAG_LENGTH); 71 | boolean contains = ArrayUtils.contains(BASE_IMAGE_FILE_TYPE, getType(in)); 72 | in.reset(); 73 | 74 | return contains; 75 | } 76 | 77 | 78 | enum FileType { 79 | JPEG("FFD8FF"), 80 | PNG("89504E47"), 81 | GIF("47494638"), 82 | TIFF("49492A00"), 83 | BMP("424D"), 84 | DWG("41433130"), 85 | PSD("38425053"), 86 | RTF("7B5C727466"), 87 | XML("3C3F786D6C"), 88 | HTML("68746D6C3E"), 89 | EML("44656C69766572792D646174653A"), 90 | DBX("CFAD12FEC5FD746F"), 91 | PST("2142444E"), 92 | XLS_DOC("D0CF11E0"), 93 | MDB("5374616E64617264204A"), 94 | WPD("FF575043"), 95 | EPS("252150532D41646F6265"), 96 | PDF("255044462D312E"), 97 | QDF("AC9EBD8F"), 98 | PWL("E3828596"), 99 | ZIP("504B0304"), 100 | RAR("52617221"), 101 | WAV("57415645"), 102 | AVI("41564920"), 103 | RAM("2E7261FD"), 104 | RM("2E524D46"), 105 | MPG("000001BA"), 106 | MOV("6D6F6F76"), 107 | ASF("3026B2758E66CF11"), 108 | MID("4D546864"); 109 | private String value; 110 | 111 | FileType(String value) { 112 | this.value = value; 113 | } 114 | 115 | public String getValue() { 116 | return value; 117 | } 118 | 119 | public void setValue(String value) { 120 | this.value = value; 121 | } 122 | } 123 | 124 | 125 | } 126 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-dao/src/main/resources/mapper/SystemUserStatMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 84 | 85 | 93 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/impl/FileServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service.impl; 2 | 3 | import com.igroupes.rtadmin.constant.RtAdminConstant; 4 | import com.igroupes.rtadmin.dto.UserInfo; 5 | import com.igroupes.rtadmin.dto.reponse.FileUploadResponse; 6 | import com.igroupes.rtadmin.entity.FileLogEntity; 7 | import com.igroupes.rtadmin.enums.ErrorCode; 8 | import com.igroupes.rtadmin.file.core.FileStore; 9 | import com.igroupes.rtadmin.file.exception.RtAdminException; 10 | import com.igroupes.rtadmin.service.IFileService; 11 | import com.igroupes.rtadmin.service.raw.FileLogService; 12 | import com.igroupes.rtadmin.util.FileTypeUtils; 13 | import com.igroupes.rtadmin.util.HttpUtils; 14 | import com.igroupes.rtadmin.util.StreamUtils; 15 | import com.igroupes.rtadmin.vo.ResultVO; 16 | import lombok.extern.slf4j.Slf4j; 17 | import org.apache.commons.lang3.StringUtils; 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.stereotype.Service; 20 | 21 | import javax.servlet.http.HttpServletRequest; 22 | import javax.servlet.http.HttpServletResponse; 23 | import java.io.*; 24 | 25 | @Service 26 | @Slf4j 27 | public class FileServiceImpl implements IFileService { 28 | @Autowired 29 | private FileStore fileStore; 30 | @Autowired 31 | private FileLogService fileLogService; 32 | 33 | @Override 34 | public ResultVO uploadImage(UserInfo userInfo, InputStream inputStream, HttpServletRequest request) { 35 | FileLogEntity fileLogEntity = new FileLogEntity(); 36 | fileLogEntity.setIp(HttpUtils.getIpAddr(request)); 37 | fileLogEntity.setType(FileLogEntity.TYPE_UPLOAD); 38 | fileLogEntity.setUserCert(userInfo.getId().toString()); 39 | try { 40 | inputStream = StreamUtils.supportMarkInputStream(inputStream); 41 | if (!FileTypeUtils.isImage(inputStream)) { 42 | return ResultVO.error(ErrorCode.FILE_TYPE_ERROR); 43 | } 44 | String fileKey = fileStore.uploadFile(inputStream); 45 | FileUploadResponse fileUploadResponse = new FileUploadResponse(); 46 | fileUploadResponse.setValue(fileStore.downloadUrl(fileKey)); 47 | ResultVO ret = ResultVO.success(fileUploadResponse); 48 | fileLogEntity.setResult(RtAdminConstant.RESULT_SUCCESS); 49 | fileLogService.save(fileLogEntity); 50 | return ret; 51 | } catch (Exception ex) { 52 | log.error("exception:", ex); 53 | fileLogEntity.setFailDesc(StringUtils.substring(ex.getMessage(), 0, 250)); 54 | fileLogEntity.setResult(RtAdminConstant.RESULT_FAIL); 55 | fileLogService.save(fileLogEntity); 56 | throw new RtAdminException(ErrorCode.FILE_UPLOAD_FAIL); 57 | } 58 | 59 | } 60 | 61 | @Override 62 | public void getImage( String key, HttpServletRequest request, HttpServletResponse response) throws IOException { 63 | FileLogEntity fileLogEntity = new FileLogEntity(); 64 | fileLogEntity.setIp(HttpUtils.getIpAddr(request)); 65 | fileLogEntity.setType(FileLogEntity.TYPE_DOWNLOAD); 66 | // fileLogEntity.setUserCert(userInfo.getId().toString()); 67 | try { 68 | InputStream inputStream = fileStore.fileStream(key); 69 | OutputStream out = response.getOutputStream(); 70 | byte[] buffer = new byte[10 * 1024]; 71 | while (inputStream.read(buffer) != -1) { 72 | out.write(buffer); 73 | } 74 | fileLogEntity.setResult(RtAdminConstant.RESULT_SUCCESS); 75 | fileLogService.save(fileLogEntity); 76 | } catch (Exception ex) { 77 | log.error("exception:", ex); 78 | fileLogEntity.setFailDesc(StringUtils.substring(ex.getMessage(), 0, 250)); 79 | fileLogEntity.setResult(RtAdminConstant.RESULT_FAIL); 80 | fileLogService.save(fileLogEntity); 81 | throw new RtAdminException(ErrorCode.FILE_DOWNLOAD_FAIL); 82 | } 83 | } 84 | 85 | 86 | 87 | } 88 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.config; 2 | 3 | import com.igroupes.rtadmin.aop.LimitHandlerInterceptorAdapter; 4 | import com.igroupes.rtadmin.aop.LoginUserArgumentResolver; 5 | import com.igroupes.rtadmin.aop.LoginUserHandlerInterceptorAdapter; 6 | import com.igroupes.rtadmin.aop.SystemLogHandlerInterceptorAdapter; 7 | import com.igroupes.rtadmin.file.core.FileStore; 8 | import com.igroupes.rtadmin.file.core.FileStoreFactory; 9 | import com.igroupes.rtadmin.file.core.SimpleFileStoreConfig; 10 | import com.igroupes.rtadmin.service.raw.SystemLogService; 11 | import com.igroupes.rtadmin.service.raw.SystemLoginSessionService; 12 | import com.igroupes.rtadmin.service.raw.SystemPermissionService; 13 | import com.igroupes.rtadmin.service.raw.SystemUserService; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.context.annotation.Bean; 16 | import org.springframework.context.annotation.Configuration; 17 | import org.springframework.http.converter.BufferedImageHttpMessageConverter; 18 | import org.springframework.http.converter.HttpMessageConverter; 19 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 20 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 21 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 22 | 23 | import java.util.List; 24 | 25 | 26 | @Configuration 27 | public class WebMvcConfig implements WebMvcConfigurer { 28 | @Autowired 29 | private LoginProperties loginProperties; 30 | @Autowired 31 | private SystemLoginSessionService systemLoginSessionService; 32 | @Autowired 33 | private SystemUserService systemUserService; 34 | @Autowired 35 | private SystemLogService systemLogService; 36 | @Autowired 37 | private SystemPermissionService systemPermissionService; 38 | @Autowired 39 | private RequestProperties requestProperties; 40 | @Autowired 41 | private FileStoreProperties storeProperties; 42 | 43 | 44 | @Override 45 | public void extendMessageConverters(List> converters) { 46 | converters.add(new BufferedImageHttpMessageConverter()); 47 | } 48 | 49 | //添加自定义的拦截器 50 | @Override 51 | public void addArgumentResolvers(List argumentResolvers) { 52 | LoginUserArgumentResolver loginUserArgumentResolver = new LoginUserArgumentResolver(); 53 | argumentResolvers.add(loginUserArgumentResolver); 54 | } 55 | 56 | @Bean 57 | public LoginUserHandlerInterceptorAdapter loginUserHandlerInterceptorAdapter() { 58 | return new LoginUserHandlerInterceptorAdapter(loginProperties, systemLoginSessionService, systemUserService); 59 | } 60 | 61 | @Bean 62 | public SystemLogHandlerInterceptorAdapter systemLogHandlerInterceptorAdapter() { 63 | return new SystemLogHandlerInterceptorAdapter(systemLogService, requestProperties); 64 | } 65 | 66 | @Bean 67 | public LimitHandlerInterceptorAdapter limitHandlerInterceptorAdapter() { 68 | return new LimitHandlerInterceptorAdapter(systemPermissionService,requestProperties); 69 | } 70 | 71 | @Bean 72 | public FileStore fileStore(){ 73 | SimpleFileStoreConfig simpleFileStoreConfig = new SimpleFileStoreConfig(); 74 | simpleFileStoreConfig.setDownloadUrlPrefix(storeProperties.getDownloadUrlPrefix()); 75 | simpleFileStoreConfig.setFileStoreDir(storeProperties.getFileStoreDir()); 76 | simpleFileStoreConfig.setStoreDirMaxBytes(storeProperties.getStoreDirMaxBytes()); 77 | return FileStoreFactory.instance().fileStore(storeProperties.getType(),simpleFileStoreConfig); 78 | } 79 | 80 | 81 | /** 82 | * 自定义拦截规则 83 | */ 84 | @Override 85 | public void addInterceptors(InterceptorRegistry registry) { 86 | registry.addInterceptor(loginUserHandlerInterceptorAdapter()).addPathPatterns("/**"); 87 | registry.addInterceptor(systemLogHandlerInterceptorAdapter()).addPathPatterns("/**"); 88 | registry.addInterceptor(limitHandlerInterceptorAdapter()).addPathPatterns("/**"); 89 | } 90 | 91 | 92 | } 93 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/aop/LoginUserHandlerInterceptorAdapter.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.aop; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.igroupes.rtadmin.config.LoginProperties; 5 | import com.igroupes.rtadmin.constant.RtAdminConstant; 6 | import com.igroupes.rtadmin.dto.UserInfo; 7 | import com.igroupes.rtadmin.entity.SystemLoginSessionEntity; 8 | import com.igroupes.rtadmin.entity.SystemUserEntity; 9 | import com.igroupes.rtadmin.enums.ErrorCode; 10 | import com.igroupes.rtadmin.file.exception.RtAdminException; 11 | import com.igroupes.rtadmin.service.raw.SystemLoginSessionService; 12 | import com.igroupes.rtadmin.service.raw.SystemUserService; 13 | import org.apache.commons.lang3.StringUtils; 14 | import org.springframework.beans.BeanUtils; 15 | import org.springframework.web.method.HandlerMethod; 16 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 17 | 18 | import javax.servlet.http.HttpServletRequest; 19 | import javax.servlet.http.HttpServletResponse; 20 | 21 | public class LoginUserHandlerInterceptorAdapter extends HandlerInterceptorAdapter { 22 | 23 | private LoginProperties loginProperties; 24 | private SystemLoginSessionService loginSessionService; 25 | private SystemUserService systemUserService; 26 | 27 | public LoginUserHandlerInterceptorAdapter(LoginProperties loginProperties, SystemLoginSessionService loginSessionService, SystemUserService systemUserService) { 28 | this.loginProperties = loginProperties; 29 | this.loginSessionService = loginSessionService; 30 | this.systemUserService = systemUserService; 31 | } 32 | 33 | @Override 34 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 35 | if (!HandlerMethod.class.isAssignableFrom(handler.getClass())) { 36 | return super.preHandle(request, response, handler); 37 | } 38 | HandlerMethod handlerMethod = (HandlerMethod) handler; 39 | String token = request.getHeader(loginProperties.getTokenKey()); 40 | // 获取用户信息 41 | Exception tmpEx = null; 42 | try { 43 | request.setAttribute(RtAdminConstant.USER_INFO_REQUEST_ATTRIBUTE_KEY, getUserInfo(token)); 44 | } catch (Exception ex) { 45 | tmpEx = ex; 46 | } 47 | LoginUser typeAnno = handlerMethod.getBeanType().getAnnotation(LoginUser.class); 48 | // 如果需要登录,但是没有获取到用户信息 49 | if (typeAnno != null) { 50 | SkipLogin skipLogin = handlerMethod.getMethodAnnotation(SkipLogin.class); 51 | if (skipLogin == null && tmpEx != null) { 52 | throw tmpEx; 53 | } 54 | }else{ 55 | LoginUser methodAnno = handlerMethod.getMethodAnnotation(LoginUser.class); 56 | if (methodAnno != null && tmpEx != null) { 57 | throw tmpEx; 58 | } 59 | } 60 | return true; 61 | } 62 | 63 | 64 | private UserInfo getUserInfo(String token) { 65 | SystemLoginSessionEntity loginSessionFind = new SystemLoginSessionEntity(); 66 | if (StringUtils.isBlank(token)) { 67 | throw new RtAdminException(ErrorCode.TOKEN_NOT_EXISTS); 68 | } 69 | loginSessionFind.setToken(token); 70 | SystemLoginSessionEntity loginSession = loginSessionService.getOne(new QueryWrapper<>(loginSessionFind)); 71 | if (loginSession == null) { 72 | throw new RtAdminException(ErrorCode.TOKEN_NOT_EXISTS); 73 | } 74 | if (loginSession.getNextExpireTime() < System.currentTimeMillis()) { 75 | loginSessionService.removeById(loginSession.getId()); 76 | throw new RtAdminException(ErrorCode.TOKEN_EXPIRE); 77 | } 78 | Long userId = loginSession.getUserId(); 79 | UserInfo userInfo = new UserInfo(); 80 | SystemUserEntity user = systemUserService.getById(userId); 81 | if (user == null) { 82 | throw new RtAdminException(ErrorCode.USER_NOT_EXISTS); 83 | } 84 | BeanUtils.copyProperties(user, userInfo); 85 | return userInfo; 86 | } 87 | 88 | 89 | } 90 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/impl/SystemLogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service.impl; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 6 | import com.igroupes.rtadmin.constant.RtAdminConstant; 7 | import com.igroupes.rtadmin.dto.UserInfo; 8 | import com.igroupes.rtadmin.dto.reponse.SystemLogListResponse; 9 | import com.igroupes.rtadmin.dto.request.SystemLogListRequest; 10 | import com.igroupes.rtadmin.entity.SystemLogEntity; 11 | import com.igroupes.rtadmin.enums.ErrorCode; 12 | import com.igroupes.rtadmin.file.exception.RtAdminException; 13 | import com.igroupes.rtadmin.query.SystemLogQuery; 14 | import com.igroupes.rtadmin.service.ISystemLogService; 15 | import com.igroupes.rtadmin.service.raw.SystemLogService; 16 | import com.igroupes.rtadmin.util.PageDTOUtil; 17 | import com.igroupes.rtadmin.vo.ResultVO; 18 | import org.apache.commons.lang3.StringUtils; 19 | import org.springframework.beans.BeanUtils; 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.stereotype.Service; 22 | 23 | import javax.validation.Valid; 24 | import java.net.URLDecoder; 25 | import java.util.List; 26 | import java.util.stream.Collectors; 27 | 28 | @Service 29 | public class SystemLogServiceImpl implements ISystemLogService { 30 | @Autowired 31 | private SystemLogService systemLogService; 32 | 33 | 34 | @Override 35 | public ResultVO get(UserInfo userInfo, @Valid SystemLogListRequest request) { 36 | try { 37 | if (StringUtils.isNotBlank(request.getActionAddr())) { 38 | // roleId经过框架处理,会转为url编码 39 | request.setActionAddr(URLDecoder.decode(request.getActionAddr(), RtAdminConstant.URL_DECODE_CHARSET)); 40 | } 41 | if (StringUtils.isNotBlank(request.getEndTime())) { 42 | request.setEndTime(URLDecoder.decode(request.getEndTime(), RtAdminConstant.URL_DECODE_CHARSET)); 43 | } 44 | if (StringUtils.isNotBlank(request.getStartTime())) { 45 | request.setStartTime(URLDecoder.decode(request.getStartTime(), RtAdminConstant.URL_DECODE_CHARSET)); 46 | } 47 | if (StringUtils.isNotBlank(request.getHandlerFilter())) { 48 | request.setHandlerFilter(URLDecoder.decode(request.getHandlerFilter(), RtAdminConstant.URL_DECODE_CHARSET)); 49 | } 50 | } catch (Exception ex) { 51 | throw new RtAdminException(ErrorCode.PARAM_ERROR); 52 | } 53 | Page page = new Page<>(request.getPage(), request.getSize()); 54 | SystemLogQuery systemLogQuery = new SystemLogQuery(); 55 | BeanUtils.copyProperties(request, systemLogQuery); 56 | systemLogQuery.setUserId(userInfo.getId()); 57 | List systemLogList = systemLogService.getSystemLogList(page, systemLogQuery); 58 | page.setRecords(systemLogList); 59 | return ResultVO.success(getSystemLogListByPage(page)); 60 | } 61 | 62 | private SystemLogListResponse getSystemLogListByPage(IPage systemLogDOPage) { 63 | SystemLogListResponse systemLogListResponse = new SystemLogListResponse(); 64 | PageDTOUtil.setPageResponse(systemLogDOPage, systemLogListResponse); 65 | List list = systemLogDOPage.getRecords().stream().map(record -> { 66 | SystemLogListResponse.SystemLogListResponseDetail detail = new SystemLogListResponse.SystemLogListResponseDetail(); 67 | detail.setCreateTime(record.getAddTime()); 68 | detail.setFailDesc(record.getFailDesc()); 69 | detail.setActionAddr(record.getActionAddr()); 70 | detail.setResult(record.getResult()); 71 | detail.setHandlerId(record.getUserId()); 72 | detail.setHandlerName(record.getNickname()); 73 | detail.setId(record.getId()); 74 | detail.setDetail(record.getDetail()); 75 | return detail; 76 | 77 | }).collect(Collectors.toList()); 78 | systemLogListResponse.setList(list); 79 | return systemLogListResponse; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/AtomicFileOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.util; 2 | 3 | 4 | import org.apache.commons.io.IOUtils; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.*; 9 | 10 | /** 11 | * A FileOutputStream that has the property that it will only show up at its 12 | * destination once it has been entirely written and flushed to disk. While 13 | * being written, it will use a .tmp suffix. 14 | * 15 | * When the output stream is closed, it is flushed, fsynced, and will be moved 16 | * into place, overwriting any file that already exists at that location. 17 | * 18 | * NOTE: on Windows platforms, it will not atomically replace the target 19 | * file - instead the target file is deleted before this one is moved into 20 | * place. 21 | */ 22 | public class AtomicFileOutputStream extends FilterOutputStream { 23 | private static final String TMP_EXTENSION = ".tmp"; 24 | 25 | private final static Logger LOG = LoggerFactory 26 | .getLogger(AtomicFileOutputStream.class); 27 | 28 | private final File origFile; // 原文件对象 29 | private final File tmpFile; // 临时文件对象 30 | 31 | public AtomicFileOutputStream(File f) throws FileNotFoundException { 32 | // Code unfortunately must be duplicated below since we can't assign 33 | // anything 34 | // before calling super 35 | super(new FileOutputStream(new File(f.getParentFile(), f.getName() 36 | + TMP_EXTENSION))); 37 | origFile = f.getAbsoluteFile(); 38 | tmpFile = new File(f.getParentFile(), f.getName() + TMP_EXTENSION) 39 | .getAbsoluteFile(); 40 | } 41 | 42 | /** 43 | * The default write method in FilterOutputStream does not call the write 44 | * method of its underlying input stream with the same arguments. Instead 45 | * it writes the data byte by byte, override it here to make it more 46 | * efficient. 47 | */ 48 | @Override 49 | public void write(byte b[], int off, int len) throws IOException { 50 | out.write(b, off, len); 51 | } 52 | 53 | /** 54 | * 关闭时将tmp文件直接转为原命名文件 55 | * @throws IOException 56 | */ 57 | @Override 58 | public void close() throws IOException { 59 | boolean triedToClose = false, success = false; 60 | try { 61 | flush(); 62 | ((FileOutputStream) out).getFD().sync(); 63 | triedToClose = true; 64 | super.close(); 65 | success = true; 66 | } finally { 67 | if (success) { 68 | boolean renamed = tmpFile.renameTo(origFile); 69 | if (!renamed) { 70 | // On windows, renameTo does not replace. 71 | if (!origFile.delete() || !tmpFile.renameTo(origFile)) { 72 | throw new IOException( 73 | "Could not rename temporary file " + tmpFile 74 | + " to " + origFile); 75 | } 76 | } 77 | } else { 78 | if (!triedToClose) { 79 | // If we failed when flushing, try to close it to not leak 80 | // an FD 81 | IOUtils.closeQuietly(out); 82 | } 83 | // close wasn't successful, try to delete the tmp file 84 | if (!tmpFile.delete()) { 85 | LOG.warn("Unable to delete tmp file " + tmpFile); 86 | } 87 | } 88 | } 89 | } 90 | 91 | /** 92 | * Close the atomic file, but do not "commit" the temporary file on top of 93 | * the destination. This should be used if there is a failure in writing. 94 | */ 95 | public void abort() { 96 | try { 97 | super.close(); 98 | } catch (IOException ioe) { 99 | LOG.warn("Unable to abort file " + tmpFile, ioe); 100 | } 101 | if (!tmpFile.delete()) { 102 | LOG.warn("Unable to delete tmp file during abort " + tmpFile); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/java/com/igroupes/rtadmin/controller/SystemController.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.controller; 2 | 3 | import com.igroupes.rtadmin.aop.LoginUser; 4 | import com.igroupes.rtadmin.dto.UserInfo; 5 | import com.igroupes.rtadmin.dto.request.*; 6 | import com.igroupes.rtadmin.service.IPermissionService; 7 | import com.igroupes.rtadmin.service.ISystemLogService; 8 | import com.igroupes.rtadmin.service.IUserService; 9 | import com.igroupes.rtadmin.util.PageDTOUtil; 10 | import com.igroupes.rtadmin.vo.ResultVO; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | import javax.validation.Valid; 15 | 16 | @RestController 17 | @RequestMapping("system") 18 | @LoginUser 19 | public class SystemController { 20 | @Autowired 21 | private IPermissionService permissionService; 22 | @Autowired 23 | private IUserService userService; 24 | @Autowired 25 | private ISystemLogService systemLogService; 26 | 27 | @GetMapping("log/item") 28 | public ResultVO getLimitList(UserInfo userInfo, @Valid SystemLogListRequest request) { 29 | PageDTOUtil.fixPageDTO(request); 30 | return systemLogService.get(userInfo, request); 31 | } 32 | 33 | @GetMapping("role/filter") 34 | public ResultVO getFilterRole(UserInfo userInfo, FilterRoleRequest request) { 35 | return permissionService.getFilterRole(userInfo, request); 36 | } 37 | 38 | 39 | /** 40 | * 添加用户 41 | * 42 | * @param userInfo 43 | * @return 44 | */ 45 | @PostMapping("/user/item") 46 | public ResultVO addUser(UserInfo userInfo, @Valid @RequestBody UserAddRequest request) { 47 | return userService.addUser(userInfo, request); 48 | } 49 | 50 | @GetMapping("/user/tree") 51 | public ResultVO userTree(UserInfo userInfo) { 52 | return userService.userTree(userInfo); 53 | } 54 | 55 | 56 | @PutMapping("/user/item/{id}") 57 | public ResultVO updateUser(UserInfo userInfo, @PathVariable Long id, @RequestBody UserUpdateRequest request) { 58 | return userService.updateUser(userInfo, id, request); 59 | } 60 | 61 | @DeleteMapping("/user/item/{id}") 62 | public ResultVO deleteUser(UserInfo userInfo, @PathVariable Long id) { 63 | return userService.deleteUser(userInfo, id); 64 | } 65 | 66 | @GetMapping("/user/item") 67 | public ResultVO getUserList(UserInfo userInfo, UserInfoPageRequest request) { 68 | PageDTOUtil.fixPageDTO(request); 69 | return userService.getUserList(userInfo, request); 70 | } 71 | 72 | 73 | @PostMapping("role/item") 74 | public ResultVO addRole(UserInfo userInfo, @Valid @RequestBody RoleAddRequest request) { 75 | return permissionService.addRole(userInfo, request); 76 | } 77 | 78 | @GetMapping("role/item") 79 | public ResultVO getRoleList(UserInfo userInfo, RoleListRequest request) { 80 | PageDTOUtil.fixPageDTO(request); 81 | return permissionService.getRoleList(userInfo, request); 82 | } 83 | 84 | 85 | @PutMapping("role/item/{id}/limit") 86 | public ResultVO updateLimit(UserInfo userInfo, @PathVariable Long id, @Valid @RequestBody PermissionUpdateRequest request) { 87 | return permissionService.updateLimit(userInfo, id, request); 88 | } 89 | 90 | @GetMapping("role/item/{id}/limit") 91 | public ResultVO getLimitList(UserInfo userInfo, @PathVariable Long id, PermissionListRequest request) { 92 | PageDTOUtil.fixPageDTO(request); 93 | return permissionService.getLimitList(userInfo, id, request); 94 | } 95 | 96 | @DeleteMapping("role/item/{id}") 97 | public ResultVO deleteRole(UserInfo userInfo, @PathVariable Long id) { 98 | return permissionService.deleteRole(userInfo, id); 99 | } 100 | 101 | 102 | @PutMapping("role/item/{id}") 103 | public ResultVO updateRole(UserInfo userInfo, @PathVariable Long id, @Valid @RequestBody RoleUpdateRequest request) { 104 | return permissionService.updateRole(userInfo, id, request); 105 | } 106 | 107 | /** 108 | * 将多个用户修改为指定的角色 109 | * 110 | * @param userInfo 111 | * @param request 112 | * @return 113 | */ 114 | @PutMapping("role/member") 115 | public ResultVO updateRoleMember(UserInfo userInfo, @Valid @RequestBody RoleMemberUpdateRequest request) { 116 | return permissionService.updateRoleMember(userInfo, request); 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/Requires.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.igroupes.rtadmin.util; 18 | 19 | import org.apache.commons.lang3.StringUtils; 20 | 21 | /** 22 | * Simple static methods to be called at the start of your own methods to verify 23 | * correct arguments and state. 24 | * 25 | * @author jiachun.fjc 26 | */ 27 | public final class Requires { 28 | 29 | /** 30 | * Checks that the specified object reference is not {@code null}. 31 | * 32 | * @param obj the object reference to check for nullity 33 | * @param the type of the reference 34 | * @return {@code obj} if not {@code null} 35 | * @throws NullPointerException if {@code obj} is {@code null} 36 | */ 37 | public static T requireNonNull(T obj) { 38 | if (obj == null) { 39 | throw new NullPointerException(); 40 | } 41 | return obj; 42 | } 43 | 44 | /** 45 | * Checks that the specified object reference is not {@code null} and 46 | * throws a customized {@link NullPointerException} if it is. 47 | * 48 | * @param obj the object reference to check for nullity 49 | * @param message detail message to be used in the event that a {@code 50 | * NullPointerException} is thrown 51 | * @param the type of the reference 52 | * @return {@code obj} if not {@code null} 53 | * @throws NullPointerException if {@code obj} is {@code null} 54 | */ 55 | public static T requireNonNull(T obj, String message) { 56 | if (obj == null) { 57 | throw new NullPointerException(message); 58 | } 59 | return obj; 60 | } 61 | 62 | 63 | public static String requireNonBlank(String obj) { 64 | if (StringUtils.isBlank(obj)) { 65 | throw new IllegalArgumentException(); 66 | } 67 | return obj; 68 | } 69 | 70 | 71 | public static String requireNonBlank(String obj, String message) { 72 | if (StringUtils.isBlank(obj)) { 73 | throw new IllegalArgumentException(message); 74 | } 75 | return obj; 76 | } 77 | 78 | 79 | 80 | /** 81 | * Ensures the truth of an expression involving one or more parameters 82 | * to the calling method. 83 | * 84 | * @param expression a boolean expression 85 | * @throws IllegalArgumentException if {@code expression} is false 86 | */ 87 | public static void requireTrue(boolean expression) { 88 | if (!expression) { 89 | throw new IllegalArgumentException(); 90 | } 91 | } 92 | 93 | /** 94 | * Ensures the truth of an expression involving one or more parameters 95 | * to the calling method. 96 | * 97 | * @param expression a boolean expression 98 | * @param message the exception message to use if the check fails; 99 | * will be converted to a string using 100 | * {@link String#valueOf(Object)} 101 | * @throws IllegalArgumentException if {@code expression} is false 102 | */ 103 | public static void requireTrue(boolean expression, Object message) { 104 | if (!expression) { 105 | throw new IllegalArgumentException(String.valueOf(message)); 106 | } 107 | } 108 | 109 | /** 110 | * Ensures the truth of an expression involving one or more parameters 111 | * to the calling method. 112 | * 113 | * @param expression a boolean expression 114 | * @param fmt the exception message with format string 115 | * @param args arguments referenced by the format specifiers in the format 116 | * string 117 | * @throws IllegalArgumentException if {@code expression} is false 118 | */ 119 | public static void requireTrue(boolean expression, String fmt, Object... args) { 120 | if (!expression) { 121 | throw new IllegalArgumentException(String.format(fmt, args)); 122 | } 123 | } 124 | 125 | private Requires() { 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-service/src/main/java/com/igroupes/rtadmin/service/impl/DefaultVerifyCodeManager.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.service.impl; 2 | 3 | import com.igroupes.RtThread; 4 | import com.igroupes.rtadmin.ExpiryQueue; 5 | import com.igroupes.rtadmin.config.ExpiryQueueProperties; 6 | import com.igroupes.rtadmin.enums.ErrorCode; 7 | import com.igroupes.rtadmin.file.exception.RtAdminException; 8 | import com.igroupes.rtadmin.service.IVerifyCodeManager; 9 | import com.igroupes.rtadmin.util.UniqueKeyUtils; 10 | import com.igroupes.rtadmin.util.Requires; 11 | import com.igroupes.rtadmin.util.VerifyCodeUtil; 12 | import lombok.extern.slf4j.Slf4j; 13 | import org.apache.commons.lang3.StringUtils; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Service; 16 | 17 | import java.awt.image.BufferedImage; 18 | import java.util.concurrent.ConcurrentHashMap; 19 | 20 | @Service 21 | @Slf4j 22 | public class DefaultVerifyCodeManager extends RtThread implements IVerifyCodeManager { 23 | private static final ConcurrentHashMap CODE_MAP = new ConcurrentHashMap<>(); 24 | private volatile boolean running = true; 25 | private static final int DEFAULT_VERIFY_CODE_INTERVAL = 5 * 60 * 1000; 26 | private final ExpiryQueue expiryQueue; 27 | private final ExpiryQueueProperties expiryQueueProperties; 28 | 29 | @Autowired 30 | public DefaultVerifyCodeManager(ExpiryQueueProperties expiryQueueProperties) { 31 | super("verifyCodeManage"); 32 | this.expiryQueueProperties = expiryQueueProperties; 33 | Integer verifyCodeInterval = expiryQueueProperties.getVerifyCodeInterval(); 34 | if (verifyCodeInterval == null) { 35 | expiryQueue = new ExpiryQueue(DEFAULT_VERIFY_CODE_INTERVAL); 36 | } else { 37 | expiryQueue = new ExpiryQueue(verifyCodeInterval); 38 | } 39 | // 启动线程 40 | this.start(); 41 | } 42 | 43 | public VerifyCode genCode(CodeType codeType) { 44 | switch (codeType) { 45 | case SIMPLE_PICTURE: 46 | return genPictureCode(); 47 | default: 48 | throw new RtAdminException(ErrorCode.SYSTEM_ERROR); 49 | } 50 | } 51 | 52 | @Override 53 | public void run() { 54 | try { 55 | while (running) { 56 | // 等待下一个过期时间点 57 | long waitTime = expiryQueue.getWaitTime(); 58 | if (waitTime > 0) { 59 | Thread.sleep(waitTime); 60 | continue; 61 | } 62 | 63 | for (Long key : expiryQueue.poll()) { 64 | CODE_MAP.remove(key); 65 | } 66 | } 67 | } catch (InterruptedException e) { 68 | handleException(this.getName(), e); 69 | } 70 | } 71 | 72 | /** 73 | * 简单的图片 74 | * 75 | * @return 76 | */ 77 | private VerifyCode genPictureCode() { 78 | Object[] image = VerifyCodeUtil.createImage(); 79 | if (image.length != 2) { 80 | throw new RtAdminException(ErrorCode.SYSTEM_ERROR); 81 | } 82 | VerifyCode verifyCode = new VerifyCode<>(); 83 | String code = image[0].toString(); 84 | log.info("verify code : {} ", code); 85 | Requires.requireNonNull(code, "verify code"); 86 | verifyCode.setCode(code); 87 | verifyCode.setData((BufferedImage) image[1]); 88 | Long codeKey = null; 89 | while (true) { 90 | codeKey = UniqueKeyUtils.getKey(); 91 | if (CODE_MAP.putIfAbsent(codeKey, code.toUpperCase()) == null) { 92 | verifyCode.setCodeId(UniqueKeyUtils.getKey()); 93 | break; 94 | } 95 | } 96 | verifyCode.setCodeId(codeKey); 97 | expiryQueue.update(codeKey, expiryQueueProperties.getVerifyCodeTimeout()); 98 | return verifyCode; 99 | } 100 | 101 | /** 102 | * 判断是不是正确的验证码 103 | * 104 | * @param codeKey 105 | * @param code 106 | * @return 107 | */ 108 | public boolean isRightVerifyCode(Long codeKey, String code) { 109 | if (codeKey == null || StringUtils.isBlank(code)) { 110 | return false; 111 | } 112 | if (code.toUpperCase().equals(CODE_MAP.get(codeKey))) { 113 | return true; 114 | } 115 | return false; 116 | } 117 | 118 | public String getVerifyCode(Long codeKey) { 119 | if (codeKey == null) { 120 | return null; 121 | } 122 | return CODE_MAP.get(codeKey); 123 | } 124 | 125 | 126 | public void deleteVerifyCode(Long codeKey) { 127 | CODE_MAP.remove(codeKey); 128 | } 129 | 130 | /** 131 | * 终止线程 132 | */ 133 | public void close() { 134 | running = false; 135 | } 136 | 137 | 138 | } 139 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-file/src/main/java/com/igroupes/rtadmin/file/core/QiuNiuFileStore.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin.file.core; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.igroupes.rtadmin.constant.RtAdminConstant; 5 | import com.igroupes.rtadmin.file.exception.FileStoreException; 6 | import com.qiniu.common.Zone; 7 | import com.qiniu.http.Response; 8 | import com.qiniu.storage.BucketManager; 9 | import com.qiniu.storage.Configuration; 10 | import com.qiniu.storage.UploadManager; 11 | import com.qiniu.storage.model.DefaultPutRet; 12 | import com.qiniu.util.Auth; 13 | import com.qiniu.util.StringMap; 14 | import lombok.extern.slf4j.Slf4j; 15 | import org.apache.commons.lang3.StringUtils; 16 | 17 | import java.io.InputStream; 18 | import java.net.URLEncoder; 19 | import java.util.UUID; 20 | 21 | @Slf4j 22 | public class QiuNiuFileStore extends FileStoreAdapter { 23 | private QiniuFileStoreConfig config; 24 | private UploadManager uploadManager; 25 | private Auth auth; 26 | private StringMap putPolicy; 27 | private BucketManager bucketManager; 28 | private static final String DEFAULT_KEY_PREFIX = "file-"; 29 | private static final Integer DEFAULT_MAX_UPLOAD_COUNT = 3; 30 | private static final Integer DEFAULT_DOWNLOAD_EXPIRE_SECONDS = 24 * 60 * 60; 31 | private static final Integer DEFAULT_UPLOAD_EXPIRE_SECONDS = 24 * 60 * 60; 32 | 33 | 34 | public QiuNiuFileStore(FileStoreConfig config) { 35 | Configuration configuration = qiniuConfig(); 36 | this.config = checkConfig(config); 37 | this.auth = Auth.create(this.config.getAccessKey(), this.config.getSecretKey()); 38 | this.uploadManager = new UploadManager(configuration); 39 | putPolicy = new StringMap(); 40 | putPolicy.put("returnBody", "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"bucket\":\"$(bucket)\",\"width\":$(imageInfo.width), \"height\":${imageInfo.height}}"); 41 | bucketManager = new BucketManager(auth, qiniuConfig()); 42 | } 43 | 44 | private QiniuFileStoreConfig checkConfig(FileStoreConfig config) { 45 | QiniuFileStoreConfig storeConfig = (QiniuFileStoreConfig) config; 46 | if (StringUtils.isBlank(storeConfig.getAccessKey()) || 47 | StringUtils.isBlank(storeConfig.getSecretKey()) || 48 | StringUtils.isBlank(storeConfig.getBucket()) || 49 | StringUtils.isBlank(storeConfig.getBucketDomain())) { 50 | throw new FileStoreException.FileStoreConfigException("qiniu config: accessKey , secretKey , bucket, bucketDomain must provide"); 51 | } 52 | if (StringUtils.isBlank(storeConfig.getKeyPrefix())) { 53 | storeConfig.setKeyPrefix(DEFAULT_KEY_PREFIX); 54 | } 55 | if (storeConfig.getMaxUploadCount() == null) { 56 | storeConfig.setMaxUploadCount(DEFAULT_MAX_UPLOAD_COUNT); 57 | } 58 | if (storeConfig.getDownloadExpireSeconds() == null) { 59 | storeConfig.setDownloadExpireSeconds(DEFAULT_DOWNLOAD_EXPIRE_SECONDS); 60 | } 61 | if (storeConfig.getUploadExpireSeconds() == null) { 62 | storeConfig.setUploadExpireSeconds(DEFAULT_UPLOAD_EXPIRE_SECONDS); 63 | } 64 | return storeConfig; 65 | } 66 | 67 | @Override 68 | public boolean delete(String key) { 69 | try { 70 | Response response = bucketManager.delete(config.getBucket(), key); 71 | int retry = 0; 72 | while (response.needRetry() && retry++ < config.getMaxUploadCount()) { 73 | response = bucketManager.delete(config.getBucket(), key); 74 | } 75 | return true; 76 | } catch (Exception ex) { 77 | log.error("exception:", ex); 78 | return false; 79 | } 80 | } 81 | 82 | @Override 83 | public String downloadUrl(String key) { 84 | if (StringUtils.isBlank(key)) { 85 | return null; 86 | } 87 | String downloadUrl = null; 88 | try { 89 | String domainOfBucket = config.getBucketDomain(); 90 | String encodedFileName = URLEncoder.encode(key, RtAdminConstant.URL_DECODE_CHARSET); 91 | String publicUrl = String.format("%s/%s", domainOfBucket, encodedFileName); 92 | downloadUrl = auth.privateDownloadUrl(publicUrl, config.getDownloadExpireSeconds()); 93 | } catch (Exception ex) { 94 | throw new FileStoreException(ex); 95 | } 96 | return downloadUrl; 97 | } 98 | 99 | 100 | @Override 101 | public String uploadFile(InputStream is) { 102 | String key = getPrefixKey(); 103 | try { 104 | Response response = uploadManager.put(is, key, getUploadToken(), null, null); 105 | int retry = 0; 106 | while (response.needRetry() && retry++ < config.getMaxUploadCount()) { 107 | response = uploadManager.put(is, key, getUploadToken(), null, null); 108 | } 109 | if (response != null) { 110 | DefaultPutRet defaultPutRet = JSON.parseObject(response.bodyString(), DefaultPutRet.class); 111 | return defaultPutRet.key; 112 | } else { 113 | throw new FileStoreException("upload qiniu fail"); 114 | } 115 | } catch (Exception ex) { 116 | throw new FileStoreException("upload qiniu fail"); 117 | } 118 | } 119 | 120 | 121 | /** 122 | * 生成带有前缀的key 123 | */ 124 | private String getPrefixKey() { 125 | String uuid = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); 126 | long now = System.currentTimeMillis(); 127 | return config.getKeyPrefix() + "-" + uuid + "-" + now; 128 | } 129 | 130 | 131 | private com.qiniu.storage.Configuration qiniuConfig() { 132 | return new com.qiniu.storage.Configuration(Zone.zone0()); 133 | } 134 | 135 | /** 136 | * 获取上传凭证 137 | * 138 | * @return 139 | */ 140 | private String getUploadToken() { 141 | return auth.uploadToken(config.getBucket(), null, config.getUploadExpireSeconds(), putPolicy); 142 | } 143 | 144 | 145 | } 146 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/util/SystemPropertyUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.igroupes.rtadmin.util; 17 | 18 | import lombok.extern.slf4j.Slf4j; 19 | 20 | import java.security.AccessController; 21 | import java.security.PrivilegedAction; 22 | 23 | /** 24 | * A collection of utility methods to retrieve and parse the values of the Java system properties. 25 | */ 26 | @Slf4j 27 | public final class SystemPropertyUtils { 28 | 29 | 30 | /** 31 | * Returns {@code true} if and only if the system property with the specified {@code key} 32 | * exists. 33 | */ 34 | public static boolean contains(String key) { 35 | return get(key) != null; 36 | } 37 | 38 | /** 39 | * Returns the value of the Java system property with the specified 40 | * {@code key}, while falling back to {@code null} if the property access fails. 41 | * 42 | * @return the property value or {@code null} 43 | */ 44 | public static String get(String key) { 45 | return get(key, null); 46 | } 47 | 48 | /** 49 | * Returns the value of the Java system property with the specified 50 | * {@code key}, while falling back to the specified default value if 51 | * the property access fails. 52 | * 53 | * @return the property value. 54 | * {@code def} if there's no such property or if an access to the 55 | * specified property is not allowed. 56 | */ 57 | public static String get(final String key, String def) { 58 | Requires.requireNonNull(key, "key"); 59 | if (key.isEmpty()) { 60 | throw new IllegalArgumentException("key must not be empty."); 61 | } 62 | 63 | String value = null; 64 | try { 65 | if (System.getSecurityManager() == null) { 66 | value = System.getProperty(key); 67 | } else { 68 | value = AccessController.doPrivileged(new PrivilegedAction() { 69 | @Override 70 | public String run() { 71 | return System.getProperty(key); 72 | } 73 | }); 74 | } 75 | } catch (SecurityException e) { 76 | log.warn("Unable to retrieve a system property '{}'; default values will be used.", key, e); 77 | } 78 | 79 | if (value == null) { 80 | return def; 81 | } 82 | 83 | return value; 84 | } 85 | 86 | /** 87 | * Returns the value of the Java system property with the specified 88 | * {@code key}, while falling back to the specified default value if 89 | * the property access fails. 90 | * 91 | * @return the property value. 92 | * {@code def} if there's no such property or if an access to the 93 | * specified property is not allowed. 94 | */ 95 | public static boolean getBoolean(String key, boolean def) { 96 | String value = get(key); 97 | if (value == null) { 98 | return def; 99 | } 100 | 101 | value = value.trim().toLowerCase(); 102 | if (value.isEmpty()) { 103 | return def; 104 | } 105 | 106 | if ("true".equals(value) || "yes".equals(value) || "1".equals(value)) { 107 | return true; 108 | } 109 | 110 | if ("false".equals(value) || "no".equals(value) || "0".equals(value)) { 111 | return false; 112 | } 113 | 114 | log.warn( 115 | "Unable to parse the boolean system property '{}':{} - using the default value: {}", 116 | key, value, def 117 | ); 118 | 119 | return def; 120 | } 121 | 122 | /** 123 | * Returns the value of the Java system property with the specified 124 | * {@code key}, while falling back to the specified default value if 125 | * the property access fails. 126 | * 127 | * @return the property value. 128 | * {@code def} if there's no such property or if an access to the 129 | * specified property is not allowed. 130 | */ 131 | public static int getInt(String key, int def) { 132 | String value = get(key); 133 | if (value == null) { 134 | return def; 135 | } 136 | 137 | value = value.trim(); 138 | try { 139 | return Integer.parseInt(value); 140 | } catch (Exception e) { 141 | // Ignore 142 | } 143 | 144 | log.warn( 145 | "Unable to parse the integer system property '{}':{} - using the default value: {}", 146 | key, value, def 147 | ); 148 | 149 | return def; 150 | } 151 | 152 | /** 153 | * Returns the value of the Java system property with the specified 154 | * {@code key}, while falling back to the specified default value if 155 | * the property access fails. 156 | * 157 | * @return the property value. 158 | * {@code def} if there's no such property or if an access to the 159 | * specified property is not allowed. 160 | */ 161 | public static long getLong(String key, long def) { 162 | String value = get(key); 163 | if (value == null) { 164 | return def; 165 | } 166 | 167 | value = value.trim(); 168 | try { 169 | return Long.parseLong(value); 170 | } catch (Exception e) { 171 | // Ignore 172 | } 173 | 174 | log.warn( 175 | "Unable to parse the long integer system property '{}':{} - using the default value: {}", 176 | key, value, def 177 | ); 178 | 179 | return def; 180 | } 181 | 182 | private SystemPropertyUtils() { 183 | // Unused 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{10}) - 26 | %cyan(%msg%n) 27 | 28 | UTF-8 29 | 30 | 31 | 32 | DEBUG 33 | 34 | 35 | 36 | 37 | true 38 | false 39 | /disk1/log/rt-admin/logs/${FILE_NAME}-INFO.log 40 | 41 | /disk1/log/rt-admin/logs/${byDay}/${FILE_NAME}-INFO-${byDay}-%i.log.zip 42 | 43 | 1 44 | 10 45 | 46 | 47 | 48 | 50MB 49 | 50 | 51 | %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %class.%method:%line - %msg%n 52 | UTF-8 53 | 54 | 55 | 56 | INFO 57 | ACCEPT 58 | DENY 59 | 60 | 61 | 62 | 63 | true 64 | false 65 | /disk1/log/rt-admin/logs/${FILE_NAME}-DEBUG.log 66 | 67 | /disk1/log/rt-admin/logs/${byDay}/${FILE_NAME}-DEBUG-${byDay}-%i.log.zip 68 | 69 | 1 70 | 10 71 | 72 | 73 | 74 | 50MB 75 | 76 | 77 | %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %class.%method:%line - %msg%n 78 | UTF-8 79 | 80 | 81 | 82 | DEBUG 83 | ACCEPT 84 | DENY 85 | 86 | 87 | 88 | true 89 | false 90 | /disk1/log/rt-admin/logs/${FILE_NAME}-WARN.log 91 | 92 | /disk1/log/rt-admin/logs/${byDay}/${FILE_NAME}-WARN-${byDay}-%i.log.zip 93 | 94 | 1 95 | 10 96 | 97 | 98 | 99 | 50MB 100 | 101 | 102 | %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %class.%method:%line - %msg%n 103 | UTF-8 104 | 105 | 106 | 107 | WARN 108 | ACCEPT 109 | DENY 110 | 111 | 112 | 113 | 114 | true 115 | false 116 | /disk1/log/rt-admin/logs/${FILE_NAME}-ERROR.log 117 | 118 | /disk1/log/rt-admin/logs/${byDay}/${FILE_NAME}-ERROR-${byDay}-%i.log.zip 119 | 120 | 1 121 | 10 122 | 123 | 124 | 125 | 50MB 126 | 127 | 128 | %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %class.%method:%line - %msg%n 129 | UTF-8 130 | 131 | 132 | 133 | ERROR 134 | ACCEPT 135 | DENY 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /rt-admin-parent/rt-admin-common/src/main/java/com/igroupes/rtadmin/ExpiryQueue.java: -------------------------------------------------------------------------------- 1 | package com.igroupes.rtadmin; 2 | 3 | import com.igroupes.rtadmin.util.TimeUtils; 4 | 5 | import java.io.PrintWriter; 6 | import java.util.ArrayList; 7 | import java.util.Collections; 8 | import java.util.Map; 9 | import java.util.Set; 10 | import java.util.concurrent.ConcurrentHashMap; 11 | import java.util.concurrent.atomic.AtomicLong; 12 | 13 | public class ExpiryQueue { 14 | private final ConcurrentHashMap elemMap = 15 | new ConcurrentHashMap(); 16 | /** 17 | * The maximum number of buckets is equal to max timeout/expirationInterval, 18 | * so the expirationInterval should not be too small compared to the 19 | * max timeout that this expiry queue needs to maintain. 20 | * 21 | */ 22 | private final ConcurrentHashMap> expiryMap = 23 | new ConcurrentHashMap>(); 24 | 25 | private final AtomicLong nextExpirationTime = new AtomicLong(); // 最近的一个过期时间 26 | private final int expirationInterval; // 存放分桶策略中的两次超时时间的间隔(也即分组时间段长度) 27 | 28 | public ExpiryQueue(int expirationInterval) { 29 | this.expirationInterval = expirationInterval; 30 | nextExpirationTime.set(roundToNextInterval(TimeUtils.currentElapsedTime())); 31 | } 32 | 33 | /** 34 | * @param time 35 | * @return 36 | */ 37 | private long roundToNextInterval(long time) { 38 | return (time / expirationInterval + 1) * expirationInterval; 39 | } 40 | 41 | /** 42 | * Removes element from the queue. 43 | * @param elem element to remove 44 | * @return time at which the element was set to expire, or null if 45 | * it wasn't present 46 | */ 47 | public Long remove(E elem) { 48 | Long expiryTime = elemMap.remove(elem); 49 | if (expiryTime != null) { 50 | Set set = expiryMap.get(expiryTime); 51 | if (set != null) { 52 | set.remove(elem); 53 | // We don't need to worry about removing empty sets, 54 | // they'll eventually be removed when they expire. 55 | } 56 | } 57 | return expiryTime; 58 | } 59 | 60 | /** 61 | * Adds or updates expiration time for element in queue, rounding the 62 | * timeout to the expiry interval bucketed used by this queue. 63 | * @param elem element to add/update 64 | * @param timeout timout in milliseconds 65 | * @return time at which the element is now set to expire if 66 | * changed, or null if unchanged 67 | */ 68 | public Long update(E elem, int timeout) { 69 | // 前一个过期时间 70 | Long prevExpiryTime = elemMap.get(elem); 71 | long now = TimeUtils.currentElapsedTime(); 72 | // 重新计算新的过期时间 73 | Long newExpiryTime = roundToNextInterval(now + timeout); 74 | 75 | if (newExpiryTime.equals(prevExpiryTime)) { 76 | // No change, so nothing to update 77 | return null; 78 | } 79 | 80 | // First add the elem to the new expiry time bucket in expiryMap. 81 | // 新的过期时间桶中,添加一个新元素 82 | Set set = expiryMap.get(newExpiryTime); 83 | if (set == null) { 84 | // Construct a ConcurrentHashSet using a ConcurrentHashMap 85 | set = Collections.newSetFromMap( 86 | new ConcurrentHashMap()); 87 | // Put the new set in the map, but only if another thread 88 | // hasn't beaten us to it 89 | Set existingSet = expiryMap.putIfAbsent(newExpiryTime, set); 90 | if (existingSet != null) { 91 | set = existingSet; 92 | } 93 | } 94 | set.add(elem); 95 | 96 | // Map the elem to the new expiry time. If a different previous 97 | // mapping was present, clean up the previous expiry bucket. 98 | prevExpiryTime = elemMap.put(elem, newExpiryTime); 99 | if (prevExpiryTime != null && !newExpiryTime.equals(prevExpiryTime)) { 100 | Set prevSet = expiryMap.get(prevExpiryTime); 101 | if (prevSet != null) { 102 | prevSet.remove(elem); 103 | } 104 | } 105 | return newExpiryTime; 106 | } 107 | 108 | /** 109 | * 110 | * 111 | * @return milliseconds until next expiration time, or 0 if has already past 112 | */ 113 | public long getWaitTime() { 114 | long now = TimeUtils.currentElapsedTime(); 115 | long expirationTime = nextExpirationTime.get(); 116 | return now < expirationTime ? (expirationTime - now) : 0L; 117 | } 118 | 119 | /** 120 | * 121 | * 122 | * Remove the next expired set of elements from expireMap. This method needs 123 | * to be called frequently enough by checking getWaitTime(), otherwise there 124 | * will be a backlog of empty sets queued up in expiryMap. 125 | * 126 | * @return next set of expired elements, or an empty set if none are 127 | * ready 128 | */ 129 | public Set poll() { 130 | long now = TimeUtils.currentElapsedTime(); 131 | long expirationTime = nextExpirationTime.get(); 132 | if (now < expirationTime) { 133 | return Collections.emptySet(); 134 | } 135 | 136 | Set set = null; 137 | long newExpirationTime = expirationTime + expirationInterval; 138 | if (nextExpirationTime.compareAndSet( 139 | expirationTime, newExpirationTime)) { 140 | set = expiryMap.remove(expirationTime); 141 | } 142 | if (set == null) { 143 | return Collections.emptySet(); 144 | } 145 | return set; 146 | } 147 | 148 | /** 149 | * dump 150 | * @param pwriter 151 | */ 152 | public void dump(PrintWriter pwriter) { 153 | pwriter.print("Sets ("); 154 | pwriter.print(expiryMap.size()); 155 | pwriter.print(")/("); 156 | pwriter.print(elemMap.size()); 157 | pwriter.println("):"); 158 | ArrayList keys = new ArrayList(expiryMap.keySet()); 159 | Collections.sort(keys); 160 | for (long time : keys) { 161 | Set set = expiryMap.get(time); 162 | if (set != null) { 163 | pwriter.print(set.size()); 164 | pwriter.print(" expire at "); 165 | pwriter.print(TimeUtils.elapsedTimeToDate(time)); 166 | pwriter.println(":"); 167 | for (E elem : set) { 168 | pwriter.print("\t"); 169 | pwriter.println(elem.toString()); 170 | } 171 | } 172 | } 173 | } 174 | 175 | /** 176 | * Returns an unmodifiable view of the expiration time -> elements mapping. 177 | */ 178 | public Map> getExpiryMap() { 179 | return Collections.unmodifiableMap(expiryMap); 180 | } 181 | } 182 | 183 | -------------------------------------------------------------------------------- /rt-admin-parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.igroupes 8 | rt-admin-parent 9 | pom 10 | 0.0.1 11 | 12 | rt-admin 13 | rt-admin-common 14 | rt-admin-dao 15 | rt-admin-service 16 | rt-admin-file 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-parent 22 | 2.1.1.RELEASE 23 | 24 | 25 | 26 | 27 | 0.0.1 28 | 0.0.1 29 | 0.0.1 30 | 0.0.1 31 | 0.0.1 32 | 33 | 34 | UTF-8 35 | UTF-8 36 | 1.8 37 | 1.2.42 38 | 3.7 39 | 1.9.1 40 | 2.6 41 | 27.0.1-jre 42 | 1.16.20 43 | 2.5 44 | 3.2.0 45 | 1.1.10 46 | 4.5.6 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-autoconfigure 55 | 56 | 57 | 58 | org.projectlombok 59 | lombok 60 | ${lombok.version} 61 | 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-starter-logging 66 | 67 | 68 | 69 | com.google.guava 70 | guava 71 | ${guava.version} 72 | 73 | 74 | 75 | commons-io 76 | commons-io 77 | ${commons-io.version} 78 | 79 | 80 | 81 | commons-beanutils 82 | commons-beanutils 83 | ${commons-beanutils.version} 84 | 85 | 86 | 87 | org.springframework.boot 88 | spring-boot-configuration-processor 89 | true 90 | 91 | 92 | 93 | javax.servlet 94 | servlet-api 95 | ${servlet-api.version} 96 | provided 97 | 98 | 99 | 100 | org.apache.commons 101 | commons-lang3 102 | ${commons-lang3.version} 103 | 104 | 105 | 106 | com.alibaba 107 | fastjson 108 | ${fastjson.version} 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | com.igroupes 118 | rt-admin 119 | ${rt-admin.version} 120 | 121 | 122 | com.igroupes 123 | rt-admin-dao 124 | ${rt-admin-dao.version} 125 | 126 | 127 | com.igroupes 128 | rt-admin-service 129 | ${rt-admin-service.version} 130 | 131 | 132 | com.igroupes 133 | rt-admin-common 134 | ${rt-admin-common.version} 135 | 136 | 137 | com.igroupes 138 | rt-admin-file 139 | ${rt-admin-file.version} 140 | 141 | 142 | 143 | com.baomidou 144 | mybatis-plus-boot-starter 145 | ${mybatis-plus-boot-starter.version} 146 | 147 | 148 | 149 | com.alibaba 150 | druid 151 | ${druid.version} 152 | 153 | 154 | org.apache.httpcomponents 155 | httpclient 156 | ${httpclient.version} 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | org.apache.maven.plugins 166 | maven-compiler-plugin 167 | 3.1 168 | 169 | 1.8 170 | 1.8 171 | 172 | 173 | 174 | 175 | --------------------------------------------------------------------------------