mirror of
https://github.com/PlayEdu/PlayEdu
synced 2026-01-04 18:19:28 +08:00
!12 使用内存缓存
* 后台管理员登录失败次数设置为10次 * 优化代码 * 后台缓存接口新增权限控制 * 移除redis关键字 * Merge branch 'dev' into dev-cache * 优化静态资源访问不存在抛出异常 * 删除redis相关内容 * 移除compose.yml中redis和minio的配置 * changelog * 后台 s3配置 * 后台 s3配置 * 云存储:移除minio;新增阿里云oss,腾讯云cos * 内存缓存替换redis缓存
This commit is contained in:
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package xyz.playedu.common.annotation;
|
||||
|
||||
import xyz.playedu.common.constant.BusinessTypeConstant;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import xyz.playedu.common.constant.BusinessTypeConstant;
|
||||
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package xyz.playedu.common.bus;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import xyz.playedu.common.constant.BackendConstant;
|
||||
import xyz.playedu.common.context.BCtx;
|
||||
import xyz.playedu.common.domain.AdminRole;
|
||||
@@ -26,9 +27,6 @@ import xyz.playedu.common.service.AdminRoleService;
|
||||
import xyz.playedu.common.service.AdminUserService;
|
||||
import xyz.playedu.common.util.PrivacyUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class BackendBus {
|
||||
|
||||
|
||||
@@ -15,11 +15,15 @@
|
||||
*/
|
||||
package xyz.playedu.common.bus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.naming.NamingException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import xyz.playedu.common.domain.Department;
|
||||
import xyz.playedu.common.domain.LdapDepartment;
|
||||
import xyz.playedu.common.domain.LdapUser;
|
||||
@@ -32,14 +36,6 @@ import xyz.playedu.common.util.ldap.LdapTransformDepartment;
|
||||
import xyz.playedu.common.util.ldap.LdapTransformUser;
|
||||
import xyz.playedu.common.util.ldap.LdapUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class LDAPBus {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package xyz.playedu.common.config;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package xyz.playedu.common.config;
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package xyz.playedu.common.config;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 杭州白书科技有限公司
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.playedu.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
||||
import org.springframework.data.redis.core.script.RedisScript;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.scripting.support.ResourceScriptSource;
|
||||
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
@Bean(name = "redisTemplate")
|
||||
public RedisTemplate<String, Object> redisTemplate(
|
||||
RedisConnectionFactory redisConnectionFactory) {
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
|
||||
// key值采用StringRedisSerializer序列化
|
||||
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
||||
redisTemplate.setKeySerializer(stringRedisSerializer);
|
||||
redisTemplate.setHashKeySerializer(stringRedisSerializer);
|
||||
|
||||
GenericJackson2JsonRedisSerializer jsonRedisSerializer =
|
||||
new GenericJackson2JsonRedisSerializer();
|
||||
redisTemplate.setValueSerializer(jsonRedisSerializer);
|
||||
redisTemplate.setHashValueSerializer(jsonRedisSerializer);
|
||||
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
@Bean(name = "rateLimiterScript")
|
||||
public RedisScript<Long> rateLimiterScript() {
|
||||
DefaultRedisScript<Long> script = new DefaultRedisScript<>();
|
||||
script.setScriptSource(
|
||||
new ResourceScriptSource(new ClassPathResource("lua/RateLimiterScript.lua")));
|
||||
script.setResultType(Long.class);
|
||||
return script;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ package xyz.playedu.common.config;
|
||||
|
||||
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
|
||||
import cn.dev33.satoken.stp.StpLogic;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
@@ -21,36 +21,28 @@ public class BPermissionConstant {
|
||||
public static final String TYPE_DATA = "data";
|
||||
|
||||
public static final String PASSWORD_CHANGE = "password-change";
|
||||
|
||||
public static final String ADMIN_USER_INDEX = "admin-user-index";
|
||||
public static final String ADMIN_USER_CUD = "admin-user-cud";
|
||||
|
||||
public static final String ADMIN_ROLE = "admin-role";
|
||||
|
||||
public static final String ADMIN_LOG = "admin-log";
|
||||
|
||||
public static final String DEPARTMENT_CUD = "department-cud";
|
||||
public static final String DEPARTMENT_USER_LEARN = "department-user-learn";
|
||||
|
||||
public static final String USER_INDEX = "user-index";
|
||||
public static final String USER_STORE = "user-store";
|
||||
public static final String USER_UPDATE = "user-update";
|
||||
public static final String USER_DESTROY = "user-destroy";
|
||||
public static final String USER_LEARN = "user-learn";
|
||||
public static final String USER_LEARN_DESTROY = "user-learn-destroy";
|
||||
|
||||
public static final String COURSE = "course";
|
||||
public static final String COURSE_CUD = "course-cud";
|
||||
public static final String COURSE_USER = "course-user";
|
||||
public static final String COURSE_USER_DESTROY = "course-user-destroy";
|
||||
|
||||
public static final String RESOURCE_CATEGORY = "resource-category";
|
||||
public static final String RESOURCE_CATEGORY_MENU = "resource-category-menu";
|
||||
public static final String RESOURCE_MENU = "resource-menu";
|
||||
|
||||
public static final String SYSTEM_CONFIG = "system-config";
|
||||
|
||||
public static final String UPLOAD = "upload";
|
||||
public static final String CACHE_MANAGE = "cache-manage";
|
||||
|
||||
// ##### 友情分割线 ##################################################
|
||||
|
||||
|
||||
@@ -30,11 +30,13 @@ public class ConfigConstant {
|
||||
|
||||
public static final String MEMBER_DEFAULT_AVATAR = "member.default_avatar";
|
||||
|
||||
public static final String MINIO_ACCESS_KEY = "minio.access_key";
|
||||
public static final String MINIO_SECRET_KEY = "minio.secret_key";
|
||||
public static final String MINIO_BUCKET = "minio.bucket";
|
||||
public static final String MINIO_ENDPOINT = "minio.endpoint";
|
||||
public static final String MINIO_DOMAIN = "minio.domain";
|
||||
public static final String S3_SERVICE = "s3.service";
|
||||
public static final String S3_ACCESS_KEY = "s3.access_key";
|
||||
public static final String S3_SECRET_KEY = "s3.secret_key";
|
||||
public static final String S3_BUCKET = "s3.bucket";
|
||||
public static final String S3_REGION = "s3.region";
|
||||
public static final String S3_ENDPOINT = "s3.endpoint";
|
||||
public static final String S3_DOMAIN = "s3.domain";
|
||||
|
||||
public static final String LDAP_ENABLED = "ldap.enabled";
|
||||
public static final String LDAP_URL = "ldap.url";
|
||||
|
||||
@@ -21,7 +21,7 @@ public class SystemConstant {
|
||||
|
||||
public static final String ENV_PROD = "prod";
|
||||
|
||||
public static final String REDIS_PREFIX = "playedu:";
|
||||
public static final String CACHE_NAME_PREFIX = "playedu:";
|
||||
|
||||
public static final String JWT_PRV_ADMIN_USER =
|
||||
"dc14511e97e7eb725fb2976bc939b375"; // AdminUser的md5加密
|
||||
|
||||
@@ -15,11 +15,10 @@
|
||||
*/
|
||||
package xyz.playedu.common.context;
|
||||
|
||||
import xyz.playedu.common.domain.AdminUser;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import xyz.playedu.common.domain.AdminUser;
|
||||
|
||||
public class BCtx {
|
||||
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package xyz.playedu.common.context;
|
||||
|
||||
import xyz.playedu.common.domain.User;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import xyz.playedu.common.domain.User;
|
||||
|
||||
public class FCtx {
|
||||
private static final ThreadLocal<LinkedHashMap<String, Object>> THREAD_LOCAL =
|
||||
|
||||
@@ -20,11 +20,9 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @TableName admin_logs
|
||||
|
||||
@@ -20,11 +20,9 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @TableName admin_permissions
|
||||
|
||||
@@ -20,11 +20,9 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @TableName admin_roles
|
||||
|
||||
@@ -20,10 +20,8 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @TableName admin_role_permission
|
||||
|
||||
@@ -22,17 +22,14 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import xyz.playedu.common.bus.BackendBus;
|
||||
import xyz.playedu.common.constant.BPermissionConstant;
|
||||
import xyz.playedu.common.constant.BackendConstant;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @TableName admin_users
|
||||
*/
|
||||
|
||||
@@ -20,10 +20,8 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @TableName admin_user_role
|
||||
|
||||
@@ -22,11 +22,9 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @TableName app_config
|
||||
|
||||
@@ -21,11 +21,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @TableName resource_categories
|
||||
|
||||
@@ -20,11 +20,9 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @TableName departments
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@@ -22,16 +22,13 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
import xyz.playedu.common.bus.BackendBus;
|
||||
import xyz.playedu.common.constant.BPermissionConstant;
|
||||
import xyz.playedu.common.constant.BackendConstant;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @TableName users
|
||||
*/
|
||||
|
||||
@@ -20,10 +20,8 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @TableName user_department
|
||||
|
||||
@@ -19,11 +19,9 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @TableName user_login_records
|
||||
|
||||
@@ -20,11 +20,9 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @TableName user_upload_image_logs
|
||||
|
||||
@@ -16,14 +16,11 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.common.domain.AdminLog;
|
||||
import xyz.playedu.common.types.paginate.AdminLogPaginateFiler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【admin_logs】的数据库操作Mapper
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.common.domain.AdminPermission;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.common.domain.AdminRole;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.common.domain.AdminRolePermission;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.common.domain.AdminUser;
|
||||
|
||||
@Mapper
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.common.domain.AdminUserRole;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.common.domain.AppConfig;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.common.domain.Category;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,14 +16,11 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.common.domain.Department;
|
||||
import xyz.playedu.common.types.mapper.DepartmentsUserCountMapRes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【departments】的数据库操作Mapper
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import xyz.playedu.common.domain.LdapDepartment;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import xyz.playedu.common.domain.LdapUser;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.common.domain.UserDepartment;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.common.domain.UserLoginRecord;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,14 +16,11 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.common.domain.User;
|
||||
import xyz.playedu.common.types.paginate.UserPaginateFilter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【users】的数据库操作Mapper
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.common.domain.UserUploadImageLog;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import xyz.playedu.common.domain.AdminLog;
|
||||
import xyz.playedu.common.types.paginate.AdminLogPaginateFiler;
|
||||
import xyz.playedu.common.types.paginate.PaginationResult;
|
||||
|
||||
@@ -16,11 +16,9 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import xyz.playedu.common.domain.AdminPermission;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import xyz.playedu.common.domain.AdminPermission;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import xyz.playedu.common.domain.AdminRolePermission;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import xyz.playedu.common.domain.AdminRole;
|
||||
import xyz.playedu.common.exception.NotFoundException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【admin_roles】的数据库操作Service
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import xyz.playedu.common.domain.AdminUserRole;
|
||||
|
||||
import java.util.List;
|
||||
import xyz.playedu.common.domain.AdminUserRole;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
|
||||
@@ -16,16 +16,14 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import xyz.playedu.common.domain.AdminUser;
|
||||
import xyz.playedu.common.exception.NotFoundException;
|
||||
import xyz.playedu.common.exception.ServiceException;
|
||||
import xyz.playedu.common.types.paginate.AdminUserPaginateFilter;
|
||||
import xyz.playedu.common.types.paginate.PaginationResult;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【admin_users】的数据库操作Service
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import xyz.playedu.common.domain.AppConfig;
|
||||
import xyz.playedu.common.types.LdapConfig;
|
||||
import xyz.playedu.common.types.config.S3Config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import xyz.playedu.common.domain.AppConfig;
|
||||
import xyz.playedu.common.types.LdapConfig;
|
||||
import xyz.playedu.common.types.config.S3Config;
|
||||
|
||||
public interface AppConfigService extends IService<AppConfig> {
|
||||
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import xyz.playedu.common.domain.Category;
|
||||
import xyz.playedu.common.exception.NotFoundException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import xyz.playedu.common.domain.Category;
|
||||
import xyz.playedu.common.exception.NotFoundException;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import xyz.playedu.common.domain.Department;
|
||||
import xyz.playedu.common.exception.NotFoundException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import xyz.playedu.common.domain.Department;
|
||||
import xyz.playedu.common.exception.NotFoundException;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import xyz.playedu.common.domain.LdapDepartment;
|
||||
|
||||
import java.util.List;
|
||||
import xyz.playedu.common.domain.LdapDepartment;
|
||||
|
||||
public interface LdapDepartmentService extends IService<LdapDepartment> {
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import xyz.playedu.common.domain.LdapUser;
|
||||
import xyz.playedu.common.util.ldap.LdapTransformUser;
|
||||
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import xyz.playedu.common.domain.UserDepartment;
|
||||
|
||||
import java.util.List;
|
||||
import xyz.playedu.common.domain.UserDepartment;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import xyz.playedu.common.domain.UserLoginRecord;
|
||||
|
||||
public interface UserLoginRecordService extends IService<UserLoginRecord> {
|
||||
|
||||
@@ -16,16 +16,14 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import xyz.playedu.common.domain.User;
|
||||
import xyz.playedu.common.exception.NotFoundException;
|
||||
import xyz.playedu.common.exception.ServiceException;
|
||||
import xyz.playedu.common.types.paginate.PaginationResult;
|
||||
import xyz.playedu.common.types.paginate.UserPaginateFilter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【users】的数据库操作Service
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package xyz.playedu.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import xyz.playedu.common.domain.UserUploadImageLog;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.common.domain.AdminLog;
|
||||
import xyz.playedu.common.mapper.AdminLogMapper;
|
||||
import xyz.playedu.common.service.AdminLogService;
|
||||
|
||||
@@ -16,16 +16,13 @@
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.common.domain.AdminPermission;
|
||||
import xyz.playedu.common.mapper.AdminPermissionMapper;
|
||||
import xyz.playedu.common.service.AdminPermissionService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
import xyz.playedu.common.domain.AdminPermission;
|
||||
import xyz.playedu.common.mapper.AdminPermissionMapper;
|
||||
import xyz.playedu.common.service.AdminPermissionService;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.common.domain.AdminRolePermission;
|
||||
import xyz.playedu.common.mapper.AdminRolePermissionMapper;
|
||||
import xyz.playedu.common.service.AdminRolePermissionService;
|
||||
|
||||
@@ -17,11 +17,12 @@ package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import xyz.playedu.common.constant.BackendConstant;
|
||||
import xyz.playedu.common.domain.AdminRole;
|
||||
import xyz.playedu.common.domain.AdminRolePermission;
|
||||
@@ -32,10 +33,6 @@ import xyz.playedu.common.service.AdminRoleService;
|
||||
import xyz.playedu.common.service.AdminUserRoleService;
|
||||
import xyz.playedu.common.util.HelperUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【admin_roles】的数据库操作Service实现
|
||||
|
||||
@@ -16,15 +16,12 @@
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.common.domain.AdminUserRole;
|
||||
import xyz.playedu.common.mapper.AdminUserRoleMapper;
|
||||
import xyz.playedu.common.service.AdminUserRoleService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【admin_user_role】的数据库操作Service实现
|
||||
|
||||
@@ -19,11 +19,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import xyz.playedu.common.domain.AdminUser;
|
||||
import xyz.playedu.common.domain.AdminUserRole;
|
||||
import xyz.playedu.common.exception.NotFoundException;
|
||||
@@ -35,9 +35,6 @@ import xyz.playedu.common.types.paginate.AdminUserPaginateFilter;
|
||||
import xyz.playedu.common.types.paginate.PaginationResult;
|
||||
import xyz.playedu.common.util.HelperUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser>
|
||||
implements AdminUserService {
|
||||
|
||||
@@ -16,12 +16,14 @@
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.common.constant.ConfigConstant;
|
||||
import xyz.playedu.common.domain.AppConfig;
|
||||
import xyz.playedu.common.exception.ServiceException;
|
||||
@@ -31,12 +33,6 @@ import xyz.playedu.common.types.LdapConfig;
|
||||
import xyz.playedu.common.types.config.S3Config;
|
||||
import xyz.playedu.common.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Log4j2
|
||||
public class AppConfigServiceImpl extends ServiceImpl<AppConfigMapper, AppConfig>
|
||||
@@ -102,40 +98,32 @@ public class AppConfigServiceImpl extends ServiceImpl<AppConfigMapper, AppConfig
|
||||
Map<String, String> config = keyValues();
|
||||
|
||||
S3Config s3Config = new S3Config();
|
||||
s3Config.setAccessKey(config.get(ConfigConstant.MINIO_ACCESS_KEY));
|
||||
s3Config.setSecretKey(config.get(ConfigConstant.MINIO_SECRET_KEY));
|
||||
s3Config.setBucket(config.get(ConfigConstant.MINIO_BUCKET));
|
||||
s3Config.setEndpoint(config.get(ConfigConstant.MINIO_ENDPOINT));
|
||||
s3Config.setDomain(config.get(ConfigConstant.MINIO_DOMAIN));
|
||||
s3Config.setRegion(null);
|
||||
s3Config.setService("minio");
|
||||
s3Config.setAccessKey(config.get(ConfigConstant.S3_ACCESS_KEY));
|
||||
s3Config.setSecretKey(config.get(ConfigConstant.S3_SECRET_KEY));
|
||||
s3Config.setBucket(config.get(ConfigConstant.S3_BUCKET));
|
||||
s3Config.setEndpoint(config.get(ConfigConstant.S3_ENDPOINT));
|
||||
s3Config.setDomain(config.get(ConfigConstant.S3_DOMAIN));
|
||||
s3Config.setService(ConfigConstant.S3_SERVICE);
|
||||
|
||||
if (StringUtil.isEmpty(s3Config.getAccessKey())) {
|
||||
s3Config.setAccessKey(environment.getProperty("MINIO_USERNAME"));
|
||||
}
|
||||
if (StringUtil.isEmpty(s3Config.getSecretKey())) {
|
||||
s3Config.setSecretKey(environment.getProperty("MINIO_PASSWORD"));
|
||||
}
|
||||
if (StringUtil.isEmpty(s3Config.getBucket())) {
|
||||
s3Config.setBucket(environment.getProperty("MINIO_BUCKET"));
|
||||
}
|
||||
if (StringUtil.isEmpty(s3Config.getEndpoint())) {
|
||||
s3Config.setEndpoint(environment.getProperty("MINIO_ENDPOINT"));
|
||||
}
|
||||
if (StringUtil.isEmpty(s3Config.getDomain())) {
|
||||
s3Config.setDomain(environment.getProperty("MINIO_DOMAIN"));
|
||||
}
|
||||
// region解析
|
||||
String region = config.get(ConfigConstant.S3_REGION);
|
||||
s3Config.setRegion(StringUtil.isEmpty(region) ? null : region);
|
||||
|
||||
if (s3Config.getService().equals("minio") && StringUtil.isNotEmpty(s3Config.getDomain())) {
|
||||
if (StringUtil.isNotEmpty(s3Config.getService())
|
||||
&& StringUtil.isNotEmpty(s3Config.getDomain())) {
|
||||
String _domain = s3Config.getDomain();
|
||||
// 拼接https://前缀
|
||||
if (_domain.length() < 7
|
||||
|| (!"http://".equalsIgnoreCase(_domain.substring(0, 7))
|
||||
&& !"https://".equalsIgnoreCase(_domain.substring(0, 8)))) {
|
||||
_domain = "https://" + _domain;
|
||||
}
|
||||
|
||||
// 移除 / 后缀
|
||||
if (StringUtil.endsWith(_domain, "/")) {
|
||||
_domain = _domain.substring(0, _domain.length() - 1);
|
||||
}
|
||||
// 判断是否携带了bucket
|
||||
if (!StringUtil.endsWith(_domain, s3Config.getBucket())) {
|
||||
_domain += "/" + s3Config.getBucket();
|
||||
}
|
||||
|
||||
s3Config.setDomain(_domain);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,17 +17,13 @@ package xyz.playedu.common.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.SaLoginConfig;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.common.config.AuthConfig;
|
||||
import xyz.playedu.common.service.AuthService;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AuthServiceImpl implements AuthService {
|
||||
|
||||
@@ -15,15 +15,13 @@
|
||||
*/
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.common.constant.SystemConstant;
|
||||
import xyz.playedu.common.service.AuthService;
|
||||
import xyz.playedu.common.service.BackendAuthService;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Service
|
||||
public class BackendAuthServiceImpl implements BackendAuthService {
|
||||
@Autowired private AuthService authService;
|
||||
|
||||
@@ -16,20 +16,17 @@
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import xyz.playedu.common.domain.Category;
|
||||
import xyz.playedu.common.exception.NotFoundException;
|
||||
import xyz.playedu.common.mapper.CategoryMapper;
|
||||
import xyz.playedu.common.service.CategoryService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import xyz.playedu.common.domain.Category;
|
||||
import xyz.playedu.common.exception.NotFoundException;
|
||||
import xyz.playedu.common.mapper.CategoryMapper;
|
||||
import xyz.playedu.common.service.CategoryService;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
|
||||
@@ -17,14 +17,13 @@ package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import xyz.playedu.common.domain.Department;
|
||||
import xyz.playedu.common.domain.UserDepartment;
|
||||
import xyz.playedu.common.exception.NotFoundException;
|
||||
@@ -34,9 +33,6 @@ import xyz.playedu.common.service.UserDepartmentService;
|
||||
import xyz.playedu.common.types.mapper.DepartmentsUserCountMapRes;
|
||||
import xyz.playedu.common.util.StringUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【departments】的数据库操作Service实现
|
||||
|
||||
@@ -15,15 +15,13 @@
|
||||
*/
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.common.constant.SystemConstant;
|
||||
import xyz.playedu.common.service.AuthService;
|
||||
import xyz.playedu.common.service.FrontendAuthService;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Service
|
||||
public class FrontendAuthServiceImpl implements FrontendAuthService {
|
||||
|
||||
|
||||
@@ -16,16 +16,13 @@
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.common.domain.LdapDepartment;
|
||||
import xyz.playedu.common.mapper.LdapDepartmentMapper;
|
||||
import xyz.playedu.common.service.LdapDepartmentService;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class LdapDepartmentServiceImpl extends ServiceImpl<LdapDepartmentMapper, LdapDepartment>
|
||||
implements LdapDepartmentService {
|
||||
|
||||
@@ -16,17 +16,14 @@
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.util.Date;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.common.domain.LdapUser;
|
||||
import xyz.playedu.common.mapper.LdapUserMapper;
|
||||
import xyz.playedu.common.service.LdapUserService;
|
||||
import xyz.playedu.common.util.StringUtil;
|
||||
import xyz.playedu.common.util.ldap.LdapTransformUser;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author tengyongzhi
|
||||
* @description 针对表【ldap_user】的数据库操作Service实现
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2023 杭州白书科技有限公司
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.springframework.stereotype.Service;
|
||||
import xyz.playedu.common.service.RateLimiterService;
|
||||
import xyz.playedu.common.util.MemoryCacheUtil;
|
||||
|
||||
@Service
|
||||
public class MemoryRateLimiterServiceImpl implements RateLimiterService {
|
||||
private static final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
@Override
|
||||
public Long current(String key, Long duration) {
|
||||
lock.lock();
|
||||
try {
|
||||
Long count = (Long) MemoryCacheUtil.get(key);
|
||||
if (count == null) {
|
||||
// 第一次访问,设置初始值和过期时间
|
||||
MemoryCacheUtil.set(key, 1L, duration);
|
||||
return 1L;
|
||||
}
|
||||
// 已存在计数器,直接自增
|
||||
return MemoryCacheUtil.increment(key, 1L);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 杭州白书科技有限公司
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.redis.core.script.RedisScript;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import xyz.playedu.common.service.RateLimiterService;
|
||||
import xyz.playedu.common.util.RedisUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RateLimiterServiceImpl implements RateLimiterService {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("rateLimiterScript")
|
||||
private RedisScript<Long> redisScript;
|
||||
|
||||
@Override
|
||||
public Long current(String key, Long seconds) {
|
||||
return RedisUtil.handler().execute(redisScript, Arrays.asList(key, seconds + ""));
|
||||
}
|
||||
}
|
||||
@@ -16,16 +16,13 @@
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.common.domain.UserDepartment;
|
||||
import xyz.playedu.common.mapper.UserDepartmentMapper;
|
||||
import xyz.playedu.common.service.UserDepartmentService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【user_department】的数据库操作Service实现
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.common.domain.UserLoginRecord;
|
||||
import xyz.playedu.common.mapper.UserLoginRecordMapper;
|
||||
import xyz.playedu.common.service.UserLoginRecordService;
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import xyz.playedu.common.constant.SystemConstant;
|
||||
import xyz.playedu.common.domain.User;
|
||||
import xyz.playedu.common.domain.UserDepartment;
|
||||
@@ -35,10 +35,6 @@ import xyz.playedu.common.types.paginate.PaginationResult;
|
||||
import xyz.playedu.common.types.paginate.UserPaginateFilter;
|
||||
import xyz.playedu.common.util.HelperUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【users】的数据库操作Service实现
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package xyz.playedu.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.common.domain.UserUploadImageLog;
|
||||
import xyz.playedu.common.mapper.UserUploadImageLogMapper;
|
||||
import xyz.playedu.common.service.UserUploadImageLogService;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package xyz.playedu.common.types.mapper;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package xyz.playedu.common.types.mapper;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
package xyz.playedu.common.types.mapper;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package xyz.playedu.common.types.paginate;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package xyz.playedu.common.types.paginate;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package xyz.playedu.common.types.paginate;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
|
||||
@@ -17,14 +17,12 @@ package xyz.playedu.common.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
public class HelperUtil {
|
||||
|
||||
|
||||
@@ -18,14 +18,11 @@ package xyz.playedu.common.util;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class IpUtil {
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (C) 2023 杭州白书科技有限公司
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.playedu.common.util;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import org.springframework.stereotype.Component;
|
||||
import xyz.playedu.common.constant.SystemConstant;
|
||||
|
||||
@Component
|
||||
public class MemoryCacheUtil {
|
||||
private static final Map<String, CacheObject> cache = new ConcurrentHashMap<>();
|
||||
private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private static final String cacheNamePrefix = SystemConstant.CACHE_NAME_PREFIX;
|
||||
|
||||
static {
|
||||
// 启动定时清理过期缓存的线程
|
||||
scheduler.scheduleAtFixedRate(
|
||||
() -> {
|
||||
cache.entrySet().removeIf(entry -> entry.getValue().isExpired());
|
||||
},
|
||||
1,
|
||||
1,
|
||||
TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
// 基本操作
|
||||
public static void set(String key, Object value) {
|
||||
key = cacheNamePrefix + key;
|
||||
cache.put(key, new CacheObject(value, Long.MAX_VALUE));
|
||||
}
|
||||
|
||||
public static void set(String key, Object value, long expireSeconds) {
|
||||
key = cacheNamePrefix + key;
|
||||
cache.put(key, new CacheObject(value, System.currentTimeMillis() + expireSeconds * 1000));
|
||||
}
|
||||
|
||||
public static void set(String key, Object value, long expire, TimeUnit timeUnit) {
|
||||
key = cacheNamePrefix + key;
|
||||
cache.put(
|
||||
key,
|
||||
new CacheObject(value, System.currentTimeMillis() + timeUnit.toMillis(expire)));
|
||||
}
|
||||
|
||||
public static Object get(String key) {
|
||||
key = cacheNamePrefix + key;
|
||||
CacheObject cacheObject = cache.get(key);
|
||||
if (cacheObject != null && !cacheObject.isExpired()) {
|
||||
return cacheObject.getValue();
|
||||
}
|
||||
cache.remove(key);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Long ttlWithoutPrefix(String key) {
|
||||
return getExpire(cacheNamePrefix + key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有缓存键值对
|
||||
*
|
||||
* @return 所有缓存键值对的Map,包含值和失效时间
|
||||
*/
|
||||
public Map<String, Map<String, Object>> getAllCache() {
|
||||
Map<String, Map<String, Object>> result = new HashMap<>();
|
||||
for (Map.Entry<String, CacheObject> entry : cache.entrySet()) {
|
||||
Map<String, Object> cacheInfo = new HashMap<>();
|
||||
cacheInfo.put("value", entry.getValue().getValue());
|
||||
cacheInfo.put("expireTime", entry.getValue().getExpireTime());
|
||||
cacheInfo.put("ttl", getExpire(entry.getKey()));
|
||||
result.put(entry.getKey(), cacheInfo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有缓存键
|
||||
*
|
||||
* @return 所有缓存键的列表
|
||||
*/
|
||||
public List<String> getAllKeys() {
|
||||
return new ArrayList<>(cache.keySet());
|
||||
}
|
||||
|
||||
// 键操作
|
||||
public static Boolean exists(String key) {
|
||||
key = cacheNamePrefix + key;
|
||||
CacheObject cacheObject = cache.get(key);
|
||||
return cacheObject != null && !cacheObject.isExpired();
|
||||
}
|
||||
|
||||
public static void del(String... key) {
|
||||
if (key == null || key.length == 0) {
|
||||
return;
|
||||
}
|
||||
if (key.length == 1) {
|
||||
key[0] = cacheNamePrefix + key[0];
|
||||
cache.remove(key[0]);
|
||||
} else {
|
||||
for (String k : key) {
|
||||
cache.remove(cacheNamePrefix + k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hash操作
|
||||
public static Object hGet(String key, String field) {
|
||||
key = cacheNamePrefix + key;
|
||||
CacheObject cacheObject = cache.get(key);
|
||||
if (cacheObject != null && !cacheObject.isExpired()) {
|
||||
Map<String, Object> map = (Map<String, Object>) cacheObject.getValue();
|
||||
return map.get(field);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void hSet(String key, String item, Object value) {
|
||||
key = cacheNamePrefix + key;
|
||||
CacheObject cacheObject = cache.get(key);
|
||||
if (cacheObject != null && !cacheObject.isExpired()) {
|
||||
Map<String, Object> map = (Map<String, Object>) cacheObject.getValue();
|
||||
map.put(item, value);
|
||||
} else {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put(item, value);
|
||||
cache.put(key, new CacheObject(map, Long.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
|
||||
// 内部方法
|
||||
public static Long increment(String key, long delta) {
|
||||
CacheObject cacheObject = cache.get(key);
|
||||
if (cacheObject == null || cacheObject.isExpired()) {
|
||||
cache.put(key, new CacheObject(new AtomicLong(delta), Long.MAX_VALUE));
|
||||
return delta;
|
||||
}
|
||||
AtomicLong counter = (AtomicLong) cacheObject.getValue();
|
||||
return counter.addAndGet(delta);
|
||||
}
|
||||
|
||||
private static Long getExpire(String key) {
|
||||
CacheObject cacheObject = cache.get(key);
|
||||
if (cacheObject == null) {
|
||||
return -2L;
|
||||
}
|
||||
if (cacheObject.getExpireTime() == Long.MAX_VALUE) {
|
||||
return -1L;
|
||||
}
|
||||
return (cacheObject.getExpireTime() - System.currentTimeMillis()) / 1000;
|
||||
}
|
||||
|
||||
private static class CacheObject {
|
||||
private Object value;
|
||||
private long expireTime;
|
||||
|
||||
public CacheObject(Object value, long expireTime) {
|
||||
this.value = value;
|
||||
this.expireTime = expireTime;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public long getExpireTime() {
|
||||
return expireTime;
|
||||
}
|
||||
|
||||
public void setExpireTime(long expireTime) {
|
||||
this.expireTime = expireTime;
|
||||
}
|
||||
|
||||
public boolean isExpired() {
|
||||
return System.currentTimeMillis() > expireTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2023 杭州白书科技有限公司
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.playedu.common.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MemoryDistributedLock {
|
||||
private static final Map<String, LockInfo> locks = new ConcurrentHashMap<>();
|
||||
|
||||
public boolean tryLock(String key, long expire, TimeUnit timeUnit) {
|
||||
LockInfo lockInfo = locks.get(key);
|
||||
if (lockInfo == null || lockInfo.isExpired()) {
|
||||
locks.put(
|
||||
key,
|
||||
new LockInfo(
|
||||
Thread.currentThread().getId(),
|
||||
System.currentTimeMillis() + timeUnit.toMillis(expire)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void releaseLock(String key) {
|
||||
LockInfo lockInfo = locks.get(key);
|
||||
if (lockInfo != null && lockInfo.getThreadId() == Thread.currentThread().getId()) {
|
||||
locks.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
private static class LockInfo {
|
||||
private final long threadId;
|
||||
private final long expireTime;
|
||||
|
||||
public LockInfo(long threadId, long expireTime) {
|
||||
this.threadId = threadId;
|
||||
this.expireTime = expireTime;
|
||||
}
|
||||
|
||||
public long getThreadId() {
|
||||
return threadId;
|
||||
}
|
||||
|
||||
public boolean isExpired() {
|
||||
return System.currentTimeMillis() > expireTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 杭州白书科技有限公司
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.playedu.common.util;
|
||||
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/3/12 10:43
|
||||
*/
|
||||
@Component
|
||||
public class RedisDistributedLock {
|
||||
|
||||
private final StringRedisTemplate redisTemplate;
|
||||
private final ThreadLocal<String> lockValue = new ThreadLocal<>();
|
||||
|
||||
public RedisDistributedLock(StringRedisTemplate redisTemplate) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
public boolean tryLock(String key, long expire, TimeUnit timeUnit) {
|
||||
String value = UUID.randomUUID().toString();
|
||||
Boolean success = redisTemplate.opsForValue().setIfAbsent(key, value, expire, timeUnit);
|
||||
if (Boolean.TRUE.equals(success)) {
|
||||
lockValue.set(value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean releaseLock(String key) {
|
||||
String value = lockValue.get();
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
DefaultRedisScript<Boolean> script =
|
||||
new DefaultRedisScript<>(
|
||||
"if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del',"
|
||||
+ " KEYS[1]) else return 0 end",
|
||||
Boolean.class);
|
||||
Boolean success = redisTemplate.execute(script, Collections.singletonList(key), value);
|
||||
if (Boolean.TRUE.equals(success)) {
|
||||
lockValue.remove();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,683 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 杭州白书科技有限公司
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.playedu.common.util;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import xyz.playedu.common.constant.SystemConstant;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class RedisUtil {
|
||||
|
||||
private static RedisTemplate<String, Object> redisTemplate;
|
||||
private static final String redisPrefix = SystemConstant.REDIS_PREFIX;
|
||||
|
||||
/**
|
||||
* 注入Redis
|
||||
*
|
||||
* @param redisTemplate Redis对象
|
||||
* @author fzr
|
||||
*/
|
||||
@Resource
|
||||
public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) {
|
||||
RedisUtil.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象句柄
|
||||
*
|
||||
* @return RedisTemplate
|
||||
* @author fzr
|
||||
*/
|
||||
public static RedisTemplate<String, Object> handler() {
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定缓存失效时间
|
||||
*
|
||||
* @param key 键
|
||||
* @param second 时间(秒)
|
||||
* @author fzr
|
||||
*/
|
||||
public static void expire(String key, Long second) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.expire(key, second, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定缓存失效时间
|
||||
*
|
||||
* @param key 键
|
||||
* @param millisecond 时间(毫秒)
|
||||
* @author fzr
|
||||
*/
|
||||
public static void pExpire(String key, Long millisecond) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.expire(key, millisecond, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定缓存永久有效
|
||||
*
|
||||
* @param key 键
|
||||
* @author fzr
|
||||
*/
|
||||
public static void persist(String key) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.persist(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据key获取过期时间
|
||||
*
|
||||
* @param key 键不能为null
|
||||
* @return 返回0代表为永久有效(秒)
|
||||
* @author fzr
|
||||
*/
|
||||
public static Long ttl(String key) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.getExpire(key, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public static Long ttlWithoutPrefix(String key) {
|
||||
return redisTemplate.getExpire(key, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据key获取过期时间
|
||||
*
|
||||
* @param key 键不能为null
|
||||
* @return 返回0代表为永久有效(毫秒)
|
||||
* @author fzr
|
||||
*/
|
||||
public static Long pTtl(String key) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断key是否存在
|
||||
*
|
||||
* @param key 键
|
||||
* @return true=存在,false=不存在
|
||||
* @author fzr
|
||||
*/
|
||||
public static Boolean exists(String key) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.hasKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除1个或多个键
|
||||
*
|
||||
* @param key 键(一个或多个)
|
||||
* @author fzr
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void del(String... key) {
|
||||
if (key.length == 1) {
|
||||
key[0] = redisPrefix + key[0];
|
||||
redisTemplate.delete(key[0]);
|
||||
} else {
|
||||
for (int i = 0; key.length > i; i++) {
|
||||
key[i] = redisPrefix + key[i];
|
||||
}
|
||||
redisTemplate.delete((Collection<String>) CollectionUtils.arrayToList(key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给key赋值一个新的key名
|
||||
*
|
||||
* @param oldKey 旧的key
|
||||
* @param newKey 新的key
|
||||
* @author fzr
|
||||
*/
|
||||
public static void rename(String oldKey, String newKey) {
|
||||
oldKey = redisPrefix + oldKey;
|
||||
newKey = redisPrefix + newKey;
|
||||
redisTemplate.rename(oldKey, newKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将当前数据库的key移动到给定的数据库db当中
|
||||
*
|
||||
* @param key 键
|
||||
* @param db 库
|
||||
* @return Boolean
|
||||
* @author fzr
|
||||
*/
|
||||
public static Boolean move(String key, int db) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.move(key, db);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取匹配的key值
|
||||
*
|
||||
* @param pattern 通配符(*, ?, [])
|
||||
* @return Set
|
||||
* @author fzr
|
||||
* @author fzr
|
||||
*/
|
||||
public static Set<String> keys(String pattern) {
|
||||
return redisTemplate.keys(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机返回一个key
|
||||
*
|
||||
* @return String
|
||||
* @author fzr
|
||||
* @author fzr
|
||||
*/
|
||||
public static String randomKey() {
|
||||
return redisTemplate.randomKey();
|
||||
}
|
||||
|
||||
/* ***************** common end *************** */
|
||||
|
||||
/**
|
||||
* 按匹配获取或有KEY
|
||||
*
|
||||
* @param pattern 规则
|
||||
* @return Set<String>
|
||||
* @author fzr
|
||||
*/
|
||||
public static Set<String> matchSet(String pattern) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
RedisUtil.handler()
|
||||
.execute(
|
||||
(RedisConnection connection) -> {
|
||||
try (Cursor<byte[]> cursor =
|
||||
connection.scan(
|
||||
ScanOptions.scanOptions()
|
||||
.count(Long.MAX_VALUE)
|
||||
.match(pattern)
|
||||
.build())) {
|
||||
cursor.forEachRemaining(
|
||||
item -> {
|
||||
keys.add(RedisSerializer.string().deserialize(item));
|
||||
});
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取key的值
|
||||
*
|
||||
* @param key 键
|
||||
* @return Object
|
||||
* @author fzr
|
||||
*/
|
||||
public static Object get(String key) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForValue().get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取旧值并设置新值
|
||||
*
|
||||
* @param key 键
|
||||
* @param newVal 新值
|
||||
* @return Object
|
||||
* @author fzr
|
||||
*/
|
||||
public static Object getSet(String key, Object newVal) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForValue().getAndSet(key, newVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置键值对
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @author fzr
|
||||
*/
|
||||
public static void set(String key, Object value) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置键值对并设置时间
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @param time time要大于0 如果time小于等于0 将设置无限期
|
||||
* @author fzr
|
||||
*/
|
||||
public static void set(String key, Object value, long time) {
|
||||
key = redisPrefix + key;
|
||||
if (time > 0) {
|
||||
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
|
||||
} else {
|
||||
set(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递增
|
||||
*
|
||||
* @param key 键
|
||||
* @param delta 要增加几(大于0)
|
||||
* @return Long
|
||||
* @author fzr
|
||||
*/
|
||||
public static Long incr(String key, long delta) {
|
||||
if (delta < 0) {
|
||||
throw new RuntimeException("递增因子必须大于0");
|
||||
}
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForValue().increment(key, delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递减
|
||||
*
|
||||
* @param key 键
|
||||
* @param delta 要减少几(小于0)
|
||||
* @return Long
|
||||
* @author fzr
|
||||
*/
|
||||
public static Long decr(String key, long delta) {
|
||||
if (delta < 0) {
|
||||
throw new RuntimeException("递减因子必须大于0");
|
||||
}
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForValue().increment(key, -delta);
|
||||
}
|
||||
|
||||
/* ***************** String end *************** */
|
||||
|
||||
/**
|
||||
* 获取key中field域的值
|
||||
*
|
||||
* @param key 键 不能为null
|
||||
* @param field 项 不能为null
|
||||
* @return 值
|
||||
* @author fzr
|
||||
*/
|
||||
public static Object hGet(String key, String field) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForHash().get(key, field);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断key中有没有field域名
|
||||
*
|
||||
* @param key 键
|
||||
* @param field 字段
|
||||
* @return Boolean
|
||||
* @author fzr
|
||||
*/
|
||||
public static Boolean hExists(String key, Object field) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForHash().hasKey(key, field);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取hashKey对应的所有键值
|
||||
*
|
||||
* @param key 键
|
||||
* @return 对应的多个键值
|
||||
* @author fzr
|
||||
*/
|
||||
public Map<Object, Object> hmGet(String key) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForHash().entries(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置field1->N个域,对应的值是value1->N
|
||||
*
|
||||
* @param key 键
|
||||
* @param map 对应多个键值
|
||||
* @author fzr
|
||||
*/
|
||||
public static void hmSet(String key, Map<String, Object> map) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.opsForHash().putAll(key, map);
|
||||
}
|
||||
|
||||
/**
|
||||
* HashSet 并设置时间
|
||||
*
|
||||
* @param key 键
|
||||
* @param map 对应多个键值
|
||||
* @param time 时间(秒)
|
||||
* @author fzr
|
||||
*/
|
||||
public static void hmSet(String key, Map<String, Object> map, long time) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.opsForHash().putAll(key, map);
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 向一张hash表中放入数据,如果不存在将创建
|
||||
*
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param value 值
|
||||
* @author fzr
|
||||
*/
|
||||
public static void hSet(String key, String item, Object value) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.opsForHash().put(key, item, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向一张hash表中放入数据,如果不存在将创建
|
||||
*
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param value 值
|
||||
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
|
||||
* @return true 成功 false失败
|
||||
* @author fzr
|
||||
*/
|
||||
public static boolean hSet(String key, String item, Object value, long time) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.opsForHash().put(key, item, value);
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除hash表中的值
|
||||
*
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 可以使多个 不能为null
|
||||
* @author fzr
|
||||
*/
|
||||
public static void hDel(String key, Object... item) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.opsForHash().delete(key, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断hash表中是否有该项的值
|
||||
*
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 不能为null
|
||||
* @return true 存在 false不存在
|
||||
* @author fzr
|
||||
*/
|
||||
public static boolean hHasKey(String key, String item) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForHash().hasKey(key, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash递增 如果不存在,就会创建一个并把新增后的值返回
|
||||
*
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param by 要增加几(大于0)
|
||||
* @return double
|
||||
* @author fzr
|
||||
*/
|
||||
public static double hIncr(String key, String item, long by) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForHash().increment(key, item, by);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash递减
|
||||
*
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param by 要减少记(小于0)
|
||||
* @return double
|
||||
* @author fzr
|
||||
*/
|
||||
public static double hDecr(String key, String item, long by) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForHash().increment(key, item, -by);
|
||||
}
|
||||
|
||||
/* ***************** Map end *************** */
|
||||
|
||||
/**
|
||||
* 根据key获取Set中的所有值
|
||||
*
|
||||
* @param key 键
|
||||
* @return Set
|
||||
* @author fzr
|
||||
*/
|
||||
public static Set<Object> sGet(String key) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForSet().members(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据value从一个set中查询,是否存在
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return true 存在 false不存在
|
||||
* @author fzr
|
||||
*/
|
||||
public Boolean sHasKey(String key, Object value) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForSet().isMember(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数据放入set缓存
|
||||
*
|
||||
* @param key 键
|
||||
* @param values 值 可以是多个
|
||||
* @return 成功个数
|
||||
* @author fzr
|
||||
*/
|
||||
public static Long sSet(String key, Object... values) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForSet().add(key, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将set数据放入缓存
|
||||
*
|
||||
* @param key 键
|
||||
* @param time 时间(秒)
|
||||
* @param values 值 可以是多个
|
||||
* @return 成功个数
|
||||
* @author fzr
|
||||
*/
|
||||
public Long sSetAndTime(String key, long time, Object... values) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForSet().add(key, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取set缓存的长度
|
||||
*
|
||||
* @param key 键
|
||||
* @return Long
|
||||
* @author fzr
|
||||
*/
|
||||
public Long sGetSetSize(String key) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForSet().size(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除值为value的
|
||||
*
|
||||
* @param key 键
|
||||
* @param values 值 可以是多个
|
||||
* @return 移除的个数
|
||||
* @author fzr
|
||||
*/
|
||||
public Long setRemove(String key, Object... values) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForSet().remove(key, values);
|
||||
}
|
||||
|
||||
/* ***************** Set end *************** */
|
||||
|
||||
/**
|
||||
* 获取list缓存的内容
|
||||
*
|
||||
* @param key 键
|
||||
* @param start 开始
|
||||
* @param end 结束 0 到 -1代表所有值
|
||||
* @return List
|
||||
* @author fzr
|
||||
*/
|
||||
public List<Object> lGet(String key, long start, long end) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForList().range(key, start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取list缓存的长度
|
||||
*
|
||||
* @param key 键
|
||||
* @return Long
|
||||
* @author fzr
|
||||
*/
|
||||
public Long lGetListSize(String key) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForList().size(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过索引获取list中的值
|
||||
*
|
||||
* @param key 键
|
||||
* @param index 索引 index>=0时,0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
|
||||
* @return Object
|
||||
* @author fzr
|
||||
*/
|
||||
public Object lGetIndex(String key, long index) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForList().index(key, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将list放入缓存
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return boolean
|
||||
* @author fzr
|
||||
*/
|
||||
public boolean lSet(String key, Object value) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.opsForList().rightPush(key, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将list放入缓存
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @param second 时间(秒)
|
||||
* @return boolean
|
||||
* @author fzr
|
||||
*/
|
||||
public boolean lSet(String key, Object value, long second) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.opsForList().rightPush(key, value);
|
||||
if (second > 0) expire(key, second);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将list放入缓存
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return boolean
|
||||
* @author fzr
|
||||
*/
|
||||
public boolean lSet(String key, List<Object> value) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.opsForList().rightPushAll(key, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将list放入缓存
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @param time 时间(秒)
|
||||
* @return boolean
|
||||
* @author fzr
|
||||
*/
|
||||
public boolean lSet(String key, List<Object> value, Long time) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.opsForList().rightPushAll(key, value);
|
||||
if (time > 0) expire(key, time);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据索引修改list中的某条数据
|
||||
*
|
||||
* @param key 键
|
||||
* @param index 索引
|
||||
* @param value 值
|
||||
* @return boolean
|
||||
* @author fzr
|
||||
*/
|
||||
public boolean lUpdateIndex(String key, Long index, Object value) {
|
||||
key = redisPrefix + key;
|
||||
redisTemplate.opsForList().set(key, index, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除N个值为value
|
||||
*
|
||||
* @param key 键
|
||||
* @param count 移除多少个
|
||||
* @param value 值
|
||||
* @return 移除的个数
|
||||
* @author fzr
|
||||
*/
|
||||
public Long lRemove(String key, Long count, Object value) {
|
||||
key = redisPrefix + key;
|
||||
return redisTemplate.opsForList().remove(key, count, value);
|
||||
}
|
||||
}
|
||||
@@ -17,14 +17,11 @@ package xyz.playedu.common.util;
|
||||
|
||||
import cn.hutool.http.useragent.UserAgent;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
public class RequestUtil {
|
||||
|
||||
|
||||
@@ -23,21 +23,17 @@ import com.amazonaws.client.builder.AwsClientBuilder;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||
import com.amazonaws.services.s3.model.*;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import xyz.playedu.common.exception.ServiceException;
|
||||
import xyz.playedu.common.types.config.S3Config;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import xyz.playedu.common.exception.ServiceException;
|
||||
import xyz.playedu.common.types.config.S3Config;
|
||||
|
||||
@Slf4j
|
||||
public class S3Util {
|
||||
@@ -57,14 +53,6 @@ public class S3Util {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean configIsEmpty() {
|
||||
return defaultConfig == null
|
||||
|| StringUtil.isEmpty(defaultConfig.getDomain())
|
||||
|| StringUtil.isEmpty(defaultConfig.getEndpoint())
|
||||
|| StringUtil.isEmpty(defaultConfig.getAccessKey())
|
||||
|| StringUtil.isEmpty(defaultConfig.getSecretKey());
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private AmazonS3 getClient() {
|
||||
if (defaultConfig == null) {
|
||||
@@ -78,8 +66,6 @@ public class S3Util {
|
||||
defaultConfig.getEndpoint(), defaultConfig.getRegion());
|
||||
|
||||
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
|
||||
// 开启路径访问
|
||||
builder.setPathStyleAccessEnabled(true);
|
||||
|
||||
return builder.withCredentials(new AWSStaticCredentialsProvider(credentials))
|
||||
.withEndpointConfiguration(endpointConfiguration)
|
||||
@@ -170,9 +156,6 @@ public class S3Util {
|
||||
}
|
||||
|
||||
public String generateEndpointPreSignUrl(String path) {
|
||||
if (defaultConfig.getService().equals("minio")) {
|
||||
return defaultConfig.getDomain() + "/" + path;
|
||||
}
|
||||
return "";
|
||||
return defaultConfig.getDomain() + "/" + path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
package xyz.playedu.common.util;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import java.util.*;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
/** 字符串工具类 */
|
||||
public class StringUtil extends org.apache.commons.lang3.StringUtils {
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package xyz.playedu.common.util.ldap;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LdapTransformUser {
|
||||
|
||||
@@ -15,15 +15,8 @@
|
||||
*/
|
||||
package xyz.playedu.common.util.ldap;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import xyz.playedu.common.exception.ServiceException;
|
||||
import xyz.playedu.common.types.LdapConfig;
|
||||
import xyz.playedu.common.util.StringUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
@@ -32,6 +25,10 @@ import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
import javax.naming.ldap.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import xyz.playedu.common.exception.ServiceException;
|
||||
import xyz.playedu.common.types.LdapConfig;
|
||||
import xyz.playedu.common.util.StringUtil;
|
||||
|
||||
@Slf4j
|
||||
public class LdapUtil {
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
local current
|
||||
current = redis.call("incr", KEYS[1])
|
||||
if tonumber(current) == 1 then
|
||||
redis.call("expire", KEYS[1], KEYS[2])
|
||||
end
|
||||
return current
|
||||
Reference in New Issue
Block a user