!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:
白书科技
2025-05-10 02:13:24 +00:00
parent 05bad03d69
commit b9f600d3bc
281 changed files with 886 additions and 3397 deletions

View File

@@ -17,11 +17,11 @@ package xyz.playedu.system.aspectj;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import jakarta.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
@@ -30,7 +30,6 @@ import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xyz.playedu.common.annotation.Log;
import xyz.playedu.common.constant.SystemConstant;
import xyz.playedu.common.domain.AdminLog;
@@ -42,10 +41,6 @@ import xyz.playedu.common.util.IpUtil;
import xyz.playedu.common.util.RequestUtil;
import xyz.playedu.common.util.StringUtil;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.Map;
@Aspect
@Component
@Slf4j

View File

@@ -15,8 +15,8 @@
*/
package xyz.playedu.system.aspectj;
import java.util.HashMap;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@@ -24,14 +24,11 @@ import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xyz.playedu.common.annotation.BackendPermission;
import xyz.playedu.common.bus.BackendBus;
import xyz.playedu.common.context.BCtx;
import xyz.playedu.common.types.JsonResponse;
import java.util.HashMap;
@Aspect
@Component
@Slf4j

View File

@@ -15,44 +15,43 @@
*/
package xyz.playedu.system.aspectj;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xyz.playedu.common.annotation.Lock;
import xyz.playedu.common.exception.LimitException;
import xyz.playedu.common.util.RedisDistributedLock;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import xyz.playedu.common.util.MemoryDistributedLock;
@Aspect
@Component
public class LockAspect {
private final RedisDistributedLock redisDistributedLock;
@Autowired private MemoryDistributedLock distributedLock;
public LockAspect(RedisDistributedLock redisDistributedLock) {
this.redisDistributedLock = redisDistributedLock;
public LockAspect(MemoryDistributedLock distributedLock) {
this.distributedLock = distributedLock;
}
@Around("@annotation(xyz.playedu.common.annotation.Lock)")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
Lock distributedLock = method.getAnnotation(Lock.class);
String key = distributedLock.key();
long expire = distributedLock.expire();
TimeUnit timeUnit = distributedLock.timeUnit();
boolean success = redisDistributedLock.tryLock(key, expire, timeUnit);
Lock lock = method.getAnnotation(Lock.class);
String key = lock.key();
long expire = lock.expire();
TimeUnit timeUnit = lock.timeUnit();
boolean success = distributedLock.tryLock(key, expire, timeUnit);
if (!success) {
throw new LimitException("请稍后再试");
}
try {
return joinPoint.proceed();
} finally {
redisDistributedLock.releaseLock(key);
distributedLock.releaseLock(key);
}
}
}

View File

@@ -15,17 +15,15 @@
*/
package xyz.playedu.system.checks;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import xyz.playedu.common.constant.BPermissionConstant;
import xyz.playedu.common.domain.AdminPermission;
import xyz.playedu.common.service.AdminPermissionService;
import java.util.*;
@Order(1020)
@Component
public class AdminPermissionCheck implements CommandLineRunner {

View File

@@ -15,18 +15,16 @@
*/
package xyz.playedu.system.checks;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import xyz.playedu.common.constant.BackendConstant;
import xyz.playedu.common.constant.ConfigConstant;
import xyz.playedu.common.domain.AppConfig;
import xyz.playedu.common.service.AppConfigService;
import java.util.*;
@Component
@Order(100)
public class AppConfigCheck implements CommandLineRunner {
@@ -174,14 +172,25 @@ public class AppConfigCheck implements CommandLineRunner {
},
});
put(
"MinIO",
"S3存储",
new AppConfig[] {
new AppConfig() {
{
setName("服务商");
setSort(1);
setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_SELECT);
setKeyName(ConfigConstant.S3_SERVICE);
setKeyValue("");
setOptionValue(
"[{\"name\":\"阿里云OSS\",\"value\":\"oss\"},{\"name\":\"腾讯云COS\",\"value\":\"cos\"}]");
}
},
new AppConfig() {
{
setName("AccessKey");
setSort(10);
setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_TEXT);
setKeyName(ConfigConstant.MINIO_ACCESS_KEY);
setKeyName(ConfigConstant.S3_ACCESS_KEY);
setKeyValue("");
}
},
@@ -190,7 +199,7 @@ public class AppConfigCheck implements CommandLineRunner {
setName("SecretKey");
setSort(20);
setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_TEXT);
setKeyName(ConfigConstant.MINIO_SECRET_KEY);
setKeyName(ConfigConstant.S3_SECRET_KEY);
setKeyValue("");
setIsPrivate(1);
}
@@ -200,7 +209,16 @@ public class AppConfigCheck implements CommandLineRunner {
setName("Bucket");
setSort(30);
setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_TEXT);
setKeyName(ConfigConstant.MINIO_BUCKET);
setKeyName(ConfigConstant.S3_BUCKET);
setKeyValue("");
}
},
new AppConfig() {
{
setName("Region");
setSort(35);
setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_TEXT);
setKeyName(ConfigConstant.S3_REGION);
setKeyValue("");
}
},
@@ -209,7 +227,7 @@ public class AppConfigCheck implements CommandLineRunner {
setName("Endpoint");
setSort(40);
setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_TEXT);
setKeyName(ConfigConstant.MINIO_ENDPOINT);
setKeyName(ConfigConstant.S3_ENDPOINT);
setKeyValue("");
}
},
@@ -218,7 +236,7 @@ public class AppConfigCheck implements CommandLineRunner {
setName("Domain");
setSort(50);
setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_TEXT);
setKeyName(ConfigConstant.MINIO_DOMAIN);
setKeyName(ConfigConstant.S3_DOMAIN);
setKeyValue("");
}
},

View File

@@ -15,21 +15,18 @@
*/
package xyz.playedu.system.checks;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import xyz.playedu.system.service.MigrationService;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Order(10)
@Component
@Slf4j

View File

@@ -16,12 +16,10 @@
package xyz.playedu.system.checks;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import xyz.playedu.common.constant.BackendConstant;
import xyz.playedu.common.domain.AdminRole;
import xyz.playedu.common.service.AdminRoleService;

View File

@@ -15,17 +15,15 @@
*/
package xyz.playedu.system.checks;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import xyz.playedu.common.domain.AppConfig;
import xyz.playedu.common.service.AdminPermissionService;
import xyz.playedu.common.service.AppConfigService;
import java.util.ArrayList;
@Order(10000)
@Component
public class UpgradeCheck implements CommandLineRunner {

View File

@@ -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;
/**

View File

@@ -16,7 +16,6 @@
package xyz.playedu.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import xyz.playedu.system.domain.Migration;
/**

View File

@@ -16,10 +16,8 @@
package xyz.playedu.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import xyz.playedu.system.domain.Migration;
import java.util.List;
import xyz.playedu.system.domain.Migration;
/**
* @author tengyongzhi

View File

@@ -16,15 +16,12 @@
package xyz.playedu.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import org.springframework.stereotype.Service;
import xyz.playedu.system.domain.Migration;
import xyz.playedu.system.mapper.MigrationMapper;
import xyz.playedu.system.service.MigrationService;
import java.util.List;
/**
* @author tengyongzhi
* @description 针对表【migrations】的数据库操作Service实现