mirror of
https://github.com/1024-lab/smart-admin.git
synced 2025-09-01 18:34:37 +00:00
v3.25.0【优化】密码加密随机盐;【优化】java依赖版本;【优化】后端依赖库;【优化】单号生成器;【优化】防重复提交;【优化】sa-base.yaml健康检查邮箱;【新增】前端夜间模式;【优化】标签页issue;【优化】字典int回显bug
This commit is contained in:
@@ -131,6 +131,17 @@
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-jsqlparser-4.9</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -179,8 +190,8 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-s3</artifactId>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>s3</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -250,17 +261,12 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>ooxml-schemas</artifactId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml-full</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@@ -52,8 +52,7 @@ public class SmartPageUtil {
|
||||
log.error("《存在SQL注入:》 : {}", sortItem.getColumn());
|
||||
throw new BusinessException("存在SQL注入风险,请联系技术工作人员!");
|
||||
}
|
||||
|
||||
orderItemList.add(new OrderItem(sortItem.getColumn(), sortItem.getIsAsc()));
|
||||
orderItemList.add(sortItem.getIsAsc() ? OrderItem.asc(sortItem.getColumn()) : OrderItem.desc(sortItem.getColumn()));
|
||||
}
|
||||
page.setOrders(orderItemList);
|
||||
return page;
|
||||
@@ -94,7 +93,7 @@ public class SmartPageUtil {
|
||||
return newPageResult;
|
||||
}
|
||||
|
||||
public static <T> PageResult subListPage(Integer pageNum, Integer pageSize, List<T> list) {
|
||||
public static <T> PageResult<T> subListPage(Integer pageNum, Integer pageSize, List<T> list) {
|
||||
PageResult<T> pageRet = new PageResult<T>();
|
||||
//总条数
|
||||
int count = list.size();
|
||||
|
@@ -18,6 +18,9 @@ public class SmartRequestUtil {
|
||||
private static final ThreadLocal<RequestUser> REQUEST_THREAD_LOCAL = new ThreadLocal<>();
|
||||
|
||||
public static void setRequestUser(RequestUser requestUser) {
|
||||
if(requestUser == null){
|
||||
return;
|
||||
}
|
||||
REQUEST_THREAD_LOCAL.set(requestUser);
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static cn.hutool.core.util.CharsetUtil.UTF_8;
|
||||
|
||||
@@ -55,9 +54,8 @@ public class SmartResponseUtil {
|
||||
if (SmartStringUtil.isNotEmpty(fileName)) {
|
||||
response.setHeader(HttpHeaders.CONTENT_TYPE, MediaTypeFactory.getMediaType(fileName).orElse(MediaType.APPLICATION_OCTET_STREAM) + ";charset=utf-8");
|
||||
try {
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode(fileName, UTF_8).replaceAll("\\+", "%20"));
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode(fileName, "utf-8").replaceAll("\\+", "%20"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
response.setHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION);
|
||||
|
@@ -1,12 +1,5 @@
|
||||
package net.lab1024.sa.base.config;
|
||||
|
||||
import com.amazonaws.ClientConfiguration;
|
||||
import com.amazonaws.Protocol;
|
||||
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.client.builder.AwsClientBuilder;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||
import lombok.Data;
|
||||
import net.lab1024.sa.base.module.support.file.service.FileStorageCloudServiceImpl;
|
||||
import net.lab1024.sa.base.module.support.file.service.FileStorageLocalServiceImpl;
|
||||
@@ -17,6 +10,13 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.s3.S3Client;
|
||||
import software.amazon.awssdk.services.s3.S3Configuration;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* 文件上传 配置
|
||||
@@ -31,6 +31,10 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@Configuration
|
||||
public class FileConfig implements WebMvcConfigurer {
|
||||
|
||||
private static final String HTTPS = "https://";
|
||||
|
||||
private static final String HTTP = "http://";
|
||||
|
||||
private static final String MODE_CLOUD = "cloud";
|
||||
|
||||
private static final String MODE_LOCAL = "local";
|
||||
@@ -69,15 +73,17 @@ public class FileConfig implements WebMvcConfigurer {
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "file.storage", name = {"mode"}, havingValue = MODE_CLOUD)
|
||||
public AmazonS3 initAmazonS3() {
|
||||
ClientConfiguration clientConfig = new ClientConfiguration();
|
||||
clientConfig.setProtocol(Protocol.HTTPS);
|
||||
return AmazonS3ClientBuilder.standard()
|
||||
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
|
||||
.withClientConfiguration(clientConfig)
|
||||
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region))
|
||||
.withPathStyleAccessEnabled(false)
|
||||
.withChunkedEncodingDisabled(true)
|
||||
public S3Client initAmazonS3() {
|
||||
return S3Client.builder()
|
||||
.region(Region.AWS_GLOBAL)
|
||||
.endpointOverride(URI.create((urlPrefix.startsWith(HTTPS) ? HTTPS : HTTP) + endpoint))
|
||||
.credentialsProvider(
|
||||
StaticCredentialsProvider.create(
|
||||
AwsBasicCredentials.create(accessKey, secretKey)))
|
||||
.serviceConfiguration(S3Configuration.builder()
|
||||
.pathStyleAccessEnabled(false)
|
||||
.chunkedEncodingEnabled(false)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@@ -3,13 +3,13 @@ package net.lab1024.sa.base.config;
|
||||
import net.lab1024.sa.base.common.constant.StringConst;
|
||||
import net.lab1024.sa.base.common.util.SmartRequestUtil;
|
||||
import net.lab1024.sa.base.module.support.repeatsubmit.RepeatSubmitAspect;
|
||||
import net.lab1024.sa.base.module.support.repeatsubmit.ticket.RepeatSubmitCaffeineTicket;
|
||||
import net.lab1024.sa.base.module.support.repeatsubmit.ticket.RepeatSubmitRedisTicket;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 重复提交配置
|
||||
@@ -24,22 +24,22 @@ import javax.annotation.Resource;
|
||||
public class RepeatSubmitConfig {
|
||||
|
||||
@Resource
|
||||
private ValueOperations<String, String> valueOperations;
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Bean
|
||||
public RepeatSubmitAspect repeatSubmitAspect() {
|
||||
RepeatSubmitRedisTicket caffeineTicket = new RepeatSubmitRedisTicket(valueOperations, this::ticket);
|
||||
return new RepeatSubmitAspect(caffeineTicket);
|
||||
RepeatSubmitRedisTicket ticket = new RepeatSubmitRedisTicket(redisTemplate, this::ticket);
|
||||
return new RepeatSubmitAspect(ticket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指明某个用户的凭证
|
||||
*/
|
||||
private String ticket(String servletPath) {
|
||||
private String ticket(HttpServletRequest request) {
|
||||
Long userId = SmartRequestUtil.getRequestUserId();
|
||||
if (null == userId) {
|
||||
return StringConst.EMPTY;
|
||||
}
|
||||
return servletPath + "_" + userId;
|
||||
return request.getServletPath() + "_" + userId;
|
||||
}
|
||||
}
|
||||
|
@@ -6,15 +6,10 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.base.common.code.ErrorCodeRegister;
|
||||
import net.lab1024.sa.base.common.enumeration.SystemEnvironmentEnum;
|
||||
import net.lab1024.sa.base.common.util.SmartEnumUtil;
|
||||
import net.lab1024.sa.base.module.support.reload.ReloadCommand;
|
||||
import net.lab1024.sa.base.module.support.reload.core.SmartReloadManager;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.boot.web.context.WebServerApplicationContext;
|
||||
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
||||
import org.springframework.boot.web.server.WebServer;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@@ -3,9 +3,9 @@ package net.lab1024.sa.base.module.support.captcha;
|
||||
import cn.hutool.captcha.CaptchaUtil;
|
||||
import cn.hutool.captcha.LineCaptcha;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.base.common.constant.StringConst;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
import net.lab1024.sa.base.common.domain.SystemEnvironment;
|
||||
import net.lab1024.sa.base.constant.RedisKeyConst;
|
||||
@@ -18,7 +18,6 @@ import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 图形验证码 服务
|
||||
@@ -70,7 +69,7 @@ public class CaptchaService {
|
||||
* 图片 base64格式
|
||||
*/
|
||||
// uuid 唯一标识
|
||||
String uuid = UUID.randomUUID().toString().replace("-", StringConst.EMPTY);
|
||||
String uuid = IdUtil.fastSimpleUUID();
|
||||
|
||||
CaptchaVO captchaVO = new CaptchaVO();
|
||||
captchaVO.setCaptchaUuid(uuid);
|
||||
|
@@ -40,7 +40,7 @@ import java.util.Optional;
|
||||
@Service
|
||||
public class CodeGeneratorService {
|
||||
|
||||
private static final String COLUMN_NULLABLE_IDENTIFY = "NO";
|
||||
private static final String COLUMN_NO_NULLABLE_IDENTIFY = "NO";
|
||||
|
||||
private static final String COLUMN_PRIMARY_KEY = "PRI";
|
||||
|
||||
@@ -65,7 +65,7 @@ public class CodeGeneratorService {
|
||||
public List<TableColumnVO> getTableColumns(String tableName) {
|
||||
List<TableColumnVO> tableColumns = codeGeneratorDao.selectTableColumn(tableName);
|
||||
for (TableColumnVO tableColumn : tableColumns) {
|
||||
tableColumn.setNullableFlag(!COLUMN_NULLABLE_IDENTIFY.equalsIgnoreCase(tableColumn.getIsNullable()));
|
||||
tableColumn.setNullableFlag(!COLUMN_NO_NULLABLE_IDENTIFY.equalsIgnoreCase(tableColumn.getIsNullable()));
|
||||
tableColumn.setPrimaryKeyFlag(COLUMN_PRIMARY_KEY.equalsIgnoreCase(tableColumn.getColumnKey()));
|
||||
tableColumn.setAutoIncreaseFlag(SmartStringUtil.isNotEmpty(tableColumn.getExtra()) && COLUMN_AUTO_INCREASE.equalsIgnoreCase(tableColumn.getExtra()));
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
@@ -82,7 +83,7 @@ public class CodeGeneratorTemplateService {
|
||||
}
|
||||
|
||||
public void zipGeneratedFiles(OutputStream outputStream, String tableName, CodeGeneratorConfigEntity codeGeneratorConfigEntity) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String uuid = IdUtil.fastSimpleUUID();
|
||||
File dir = new File(uuid);
|
||||
|
||||
// 1、生产文件
|
||||
|
@@ -8,7 +8,6 @@ import net.lab1024.sa.base.module.support.codegenerator.domain.form.CodeGenerato
|
||||
import net.lab1024.sa.base.module.support.codegenerator.domain.model.CodeField;
|
||||
import net.lab1024.sa.base.module.support.codegenerator.domain.model.CodeQueryField;
|
||||
import net.lab1024.sa.base.module.support.codegenerator.service.variable.CodeGenerateBaseVariableService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import java.util.*;
|
||||
|
@@ -18,7 +18,6 @@ import net.lab1024.sa.base.module.support.file.domain.form.FileQueryForm;
|
||||
import net.lab1024.sa.base.module.support.file.domain.vo.FileDownloadVO;
|
||||
import net.lab1024.sa.base.module.support.file.domain.vo.FileUploadVO;
|
||||
import net.lab1024.sa.base.module.support.file.domain.vo.FileVO;
|
||||
import net.lab1024.sa.base.module.support.redis.RedisService;
|
||||
import net.lab1024.sa.base.module.support.securityprotect.service.SecurityFileService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -55,9 +54,6 @@ public class FileService {
|
||||
@Resource
|
||||
private FileDao fileDao;
|
||||
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
@Resource
|
||||
private SecurityFileService securityFileService;
|
||||
|
||||
|
@@ -2,10 +2,7 @@ package net.lab1024.sa.base.module.support.file.service;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.model.CannedAccessControlList;
|
||||
import com.amazonaws.services.s3.model.ObjectMetadata;
|
||||
import com.amazonaws.services.s3.model.S3Object;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.base.common.code.SystemErrorCode;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
@@ -21,22 +18,29 @@ import net.lab1024.sa.base.module.support.file.domain.vo.FileVO;
|
||||
import net.lab1024.sa.base.module.support.redis.RedisService;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import software.amazon.awssdk.core.ResponseBytes;
|
||||
import software.amazon.awssdk.core.sync.RequestBody;
|
||||
import software.amazon.awssdk.core.sync.ResponseTransformer;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.s3.S3Client;
|
||||
import software.amazon.awssdk.services.s3.model.*;
|
||||
import software.amazon.awssdk.services.s3.presigner.S3Presigner;
|
||||
import software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest;
|
||||
import software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 云计算 实现
|
||||
@@ -45,7 +49,7 @@ import java.util.UUID;
|
||||
* @Date 2019年10月11日 15:34:47
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
@Slf4j
|
||||
public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
@@ -66,7 +70,7 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
private static final String USER_METADATA_FILE_SIZE = "file-size";
|
||||
|
||||
@Resource
|
||||
private AmazonS3 amazonS3;
|
||||
private S3Client s3Client;
|
||||
|
||||
@Resource
|
||||
private FileConfig cloudConfig;
|
||||
@@ -86,44 +90,44 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
}
|
||||
|
||||
String fileType = FilenameUtils.getExtension(originalFileName);
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
String uuid = IdUtil.fastSimpleUUID();
|
||||
String time = LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_FORMATTER);
|
||||
String fileKey = path + uuid + "_" + time+ "." + fileType;
|
||||
String fileKey = path + uuid + "_" + time + "." + fileType;
|
||||
|
||||
// 文件名称 URL 编码
|
||||
String urlEncoderFilename;
|
||||
try {
|
||||
urlEncoderFilename = URLEncoder.encode(originalFileName, StandardCharsets.UTF_8.name());
|
||||
urlEncoderFilename = URLEncoder.encode(originalFileName, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("文件上传服务URL ENCODE-发生异常:", e);
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, "上传失败");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
ObjectMetadata meta = new ObjectMetadata();
|
||||
meta.setContentEncoding(StandardCharsets.UTF_8.name());
|
||||
meta.setContentDisposition("attachment;filename=" + urlEncoderFilename);
|
||||
Map<String, String> userMetadata = new HashMap<>(10);
|
||||
userMetadata.put(USER_METADATA_FILE_NAME, urlEncoderFilename);
|
||||
userMetadata.put(USER_METADATA_FILE_FORMAT, fileType);
|
||||
userMetadata.put(USER_METADATA_FILE_SIZE, String.valueOf(file.getSize()));
|
||||
meta.setUserMetadata(userMetadata);
|
||||
meta.setContentLength(file.getSize());
|
||||
meta.setContentType(this.getContentType(fileType));
|
||||
|
||||
PutObjectRequest putObjectRequest = PutObjectRequest.builder().bucket(cloudConfig.getBucketName()).key(fileKey).metadata(userMetadata).contentLength(file.getSize()).contentType(this.getContentType(fileType)).contentEncoding(StandardCharsets.UTF_8.name()).contentDisposition("attachment;filename=" + urlEncoderFilename).build();
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
amazonS3.putObject(cloudConfig.getBucketName(), fileKey, file.getInputStream(), meta);
|
||||
inputStream = file.getInputStream();
|
||||
s3Client.putObject(putObjectRequest, RequestBody.fromInputStream(inputStream, file.getSize()));
|
||||
} catch (IOException e) {
|
||||
log.error("文件上传-发生异常:", e);
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, "上传失败");
|
||||
} finally {
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
}
|
||||
// 根据文件路径获取并设置访问权限
|
||||
CannedAccessControlList acl = this.getACL(path);
|
||||
amazonS3.setObjectAcl(cloudConfig.getBucketName(), fileKey, acl);
|
||||
ObjectCannedACL acl = this.getACL(path);
|
||||
PutObjectAclRequest aclRequest = PutObjectAclRequest.builder().bucket(cloudConfig.getBucketName()).key(fileKey).acl(this.getACL(path)).build();
|
||||
s3Client.putObjectAcl(aclRequest);
|
||||
// 返回上传结果
|
||||
FileUploadVO uploadVO = new FileUploadVO();
|
||||
uploadVO.setFileName(originalFileName);
|
||||
uploadVO.setFileType(fileType);
|
||||
// 根据 访问权限 返回不同的 URL
|
||||
String url = cloudConfig.getUrlPrefix() + fileKey;
|
||||
if (CannedAccessControlList.Private.equals(acl)) {
|
||||
if (ObjectCannedACL.PRIVATE.equals(acl)) {
|
||||
// 获取临时访问的URL
|
||||
url = this.getFileUrl(fileKey).getData();
|
||||
}
|
||||
@@ -136,8 +140,8 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
/**
|
||||
* 获取文件url
|
||||
*
|
||||
* @param fileKey
|
||||
* @return
|
||||
* @param fileKey 文件key
|
||||
* @return url
|
||||
*/
|
||||
@Override
|
||||
public ResponseDTO<String> getFileUrl(String fileKey) {
|
||||
@@ -159,10 +163,14 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
if (fileVO == null) {
|
||||
return ResponseDTO.userErrorParam("文件不存在");
|
||||
}
|
||||
GetObjectRequest getUrlRequest = GetObjectRequest.builder().bucket(cloudConfig.getBucketName()).key(fileKey).build();
|
||||
GetObjectPresignRequest getObjectPresignRequest = GetObjectPresignRequest.builder().signatureDuration(Duration.ofSeconds(cloudConfig.getPrivateUrlExpireSeconds())).getObjectRequest(getUrlRequest).build();
|
||||
|
||||
Date expiration = new Date(System.currentTimeMillis() + cloudConfig.getPrivateUrlExpireSeconds() * 1000L);
|
||||
URL url = amazonS3.generatePresignedUrl(cloudConfig.getBucketName(), fileKey, expiration);
|
||||
fileVO.setFileUrl(url.toString());
|
||||
S3Presigner presigner = S3Presigner.builder().region(Region.of(cloudConfig.getRegion())).build();
|
||||
|
||||
PresignedGetObjectRequest presignedGetObjectRequest = presigner.presignGetObject(getObjectPresignRequest);
|
||||
String url = presignedGetObjectRequest.url().toString();
|
||||
fileVO.setFileUrl(url);
|
||||
redisService.set(fileRedisKey, fileVO, cloudConfig.getPrivateUrlExpireSeconds() - 5);
|
||||
}
|
||||
|
||||
@@ -175,11 +183,11 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
*/
|
||||
@Override
|
||||
public ResponseDTO<FileDownloadVO> download(String key) {
|
||||
//获取oss对象
|
||||
S3Object s3Object = amazonS3.getObject(cloudConfig.getBucketName(), key);
|
||||
|
||||
// 获取文件 meta
|
||||
ObjectMetadata metadata = s3Object.getObjectMetadata();
|
||||
Map<String, String> userMetadata = metadata.getUserMetadata();
|
||||
HeadObjectRequest objectRequest = HeadObjectRequest.builder().bucket(this.cloudConfig.getBucketName()).key(key).build();
|
||||
HeadObjectResponse headObjectResponse = s3Client.headObject(objectRequest);
|
||||
Map<String, String> userMetadata = headObjectResponse.metadata();
|
||||
FileMetadataVO metadataDTO = null;
|
||||
if (MapUtils.isNotEmpty(userMetadata)) {
|
||||
metadataDTO = new FileMetadataVO();
|
||||
@@ -190,43 +198,31 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
metadataDTO.setFileSize(fileSize);
|
||||
}
|
||||
|
||||
// 获得输入流
|
||||
InputStream objectContent = s3Object.getObjectContent();
|
||||
try {
|
||||
// 输入流转换为字节流
|
||||
byte[] buffer = FileCopyUtils.copyToByteArray(objectContent);
|
||||
//获取oss对象
|
||||
GetObjectRequest getObjectRequest = GetObjectRequest.builder().bucket(cloudConfig.getBucketName()).key(key).build();
|
||||
ResponseBytes<GetObjectResponse> s3ClientObject = s3Client.getObject(getObjectRequest, ResponseTransformer.toBytes());
|
||||
|
||||
FileDownloadVO fileDownloadVO = new FileDownloadVO();
|
||||
fileDownloadVO.setData(buffer);
|
||||
fileDownloadVO.setMetadata(metadataDTO);
|
||||
return ResponseDTO.ok(fileDownloadVO);
|
||||
} catch (IOException e) {
|
||||
log.error("文件下载-发生异常:", e);
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, "下载失败");
|
||||
} finally {
|
||||
try {
|
||||
// 关闭输入流
|
||||
objectContent.close();
|
||||
s3Object.close();
|
||||
} catch (IOException e) {
|
||||
log.error("文件下载-发生异常:", e);
|
||||
}
|
||||
}
|
||||
// 输入流转换为字节流
|
||||
byte[] buffer = s3ClientObject.asByteArray();
|
||||
FileDownloadVO fileDownloadVO = new FileDownloadVO();
|
||||
fileDownloadVO.setData(buffer);
|
||||
fileDownloadVO.setMetadata(metadataDTO);
|
||||
return ResponseDTO.ok(fileDownloadVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件夹路径 返回对应的访问权限
|
||||
*
|
||||
* @param fileKey
|
||||
* @return
|
||||
* @param fileKey 文件key
|
||||
* @return 权限
|
||||
*/
|
||||
private CannedAccessControlList getACL(String fileKey) {
|
||||
private ObjectCannedACL getACL(String fileKey) {
|
||||
// 公用读
|
||||
if (fileKey.contains(FileFolderTypeEnum.FOLDER_PUBLIC)) {
|
||||
return CannedAccessControlList.PublicRead;
|
||||
return ObjectCannedACL.PUBLIC_READ;
|
||||
}
|
||||
// 其他默认私有读写
|
||||
return CannedAccessControlList.Private;
|
||||
return ObjectCannedACL.PRIVATE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,11 +231,11 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
* ps:不能删除fileKey不为空的文件夹
|
||||
*
|
||||
* @param fileKey 文件or文件夹
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ResponseDTO<String> delete(String fileKey) {
|
||||
amazonS3.deleteObject(cloudConfig.getBucketName(), fileKey);
|
||||
DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder().bucket(cloudConfig.getBucketName()).key(fileKey).build();
|
||||
s3Client.deleteObject(deleteObjectRequest);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,6 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
@@ -13,7 +13,6 @@ import net.lab1024.sa.base.module.support.helpdoc.domain.form.HelpDocUpdateForm;
|
||||
import net.lab1024.sa.base.module.support.helpdoc.domain.vo.HelpDocDetailVO;
|
||||
import net.lab1024.sa.base.module.support.helpdoc.domain.vo.HelpDocVO;
|
||||
import net.lab1024.sa.base.module.support.helpdoc.manager.HelpDocManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package net.lab1024.sa.base.module.support.mail;
|
||||
|
||||
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import freemarker.cache.StringTemplateLoader;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
@@ -16,7 +16,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.text.StringSubstitutor;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
@@ -163,7 +162,7 @@ public class MailService {
|
||||
private String freemarkerResolverContent(String htmlTemplate, Map<String, Object> templateParamsMap) {
|
||||
Configuration configuration = new Configuration(Configuration.VERSION_2_3_23);
|
||||
StringTemplateLoader stringLoader = new StringTemplateLoader();
|
||||
String templateName = UUID.fastUUID().toString(true);
|
||||
String templateName = IdUtil.fastSimpleUUID();
|
||||
stringLoader.putTemplate(templateName, htmlTemplate);
|
||||
configuration.setTemplateLoader(stringLoader);
|
||||
try {
|
||||
|
@@ -13,13 +13,23 @@ import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 重复提交 aop切口
|
||||
* 重复提交 aop切口 <br>
|
||||
* -------------------------<br>
|
||||
* 着重说明:<br>
|
||||
* 注解属性 intervalMilliSecond 是指 一段时间内只允许有一次请求;<br>
|
||||
* intervalMilliSecond = 0: 表示只有上个请求执行完以后才可以执行<br>
|
||||
* intervalMilliSecond > 0: 表示指定时间内只才能执行,特别提醒<br>
|
||||
* ------------------------<br>
|
||||
* 特殊说明 intervalMilliSecond > 0 <br>
|
||||
* 若假设 方法执行时间为 100ms,若 intervalMilliSecond = 50,则 同一时间内可能会有2个请求同时在执行!<br>
|
||||
* 若假设 方法执行时间为 100ms,若 intervalMilliSecond = 200,则 同一时间内只能有1请求执行,且执行完后100ms,才会执行下一次请求<br>
|
||||
*
|
||||
* @Author 1024创新实验室: 胡克
|
||||
* @Date 2020-11-25 20:56:58
|
||||
* @Author 1024创新实验室-主任: 卓大
|
||||
* @Date 2025-07-26 23:56:58
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
@@ -43,36 +53,46 @@ public class RepeatSubmitAspect {
|
||||
@Around("@annotation(net.lab1024.sa.base.module.support.repeatsubmit.annoation.RepeatSubmit)")
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||
|
||||
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
String ticketToken = attributes.getRequest().getServletPath();
|
||||
String ticket = this.repeatSubmitTicket.getTicket(ticketToken);
|
||||
if (attributes == null) {
|
||||
return point.proceed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 第一步:生成防重复提交的 ticket凭证
|
||||
* ticket 是根据 Request对象 自定义 生成的,可以加入请求user相关属性作为生成要素
|
||||
*/
|
||||
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
String ticket = this.repeatSubmitTicket.generateTicket(request);
|
||||
if (StringUtils.isEmpty(ticket)) {
|
||||
return point.proceed();
|
||||
}
|
||||
|
||||
Method method = ((MethodSignature) point.getSignature()).getMethod();
|
||||
RepeatSubmit annotation = method.getAnnotation(RepeatSubmit.class);
|
||||
int limit = annotation.value();
|
||||
Long intervalMilliSecond = (long) annotation.intervalMilliSecond();
|
||||
|
||||
// 获取上一次请求时间
|
||||
Long lastRequestTime = this.repeatSubmitTicket.getTicketTimestamp(ticket);
|
||||
// 校验是否限制时间内重复提交
|
||||
if (lastRequestTime != null && System.currentTimeMillis() < lastRequestTime + limit) {
|
||||
/**
|
||||
* 第二步:根据 ticket 凭证进行 加锁
|
||||
* 能加锁,则可以执行
|
||||
* 若不能加锁,则证明还是时间间隔interval中
|
||||
*/
|
||||
|
||||
boolean lockSuccessFlag = this.repeatSubmitTicket.tryLock(ticket, System.currentTimeMillis(), intervalMilliSecond);
|
||||
if (!lockSuccessFlag) {
|
||||
return ResponseDTO.error(UserErrorCode.REPEAT_SUBMIT);
|
||||
}
|
||||
|
||||
// 执行
|
||||
Object obj = null;
|
||||
try {
|
||||
// 给 ticket 设置在执行中
|
||||
this.repeatSubmitTicket.putTicket(ticket);
|
||||
// 执行
|
||||
obj = point.proceed();
|
||||
return point.proceed();
|
||||
} catch (Throwable throwable) {
|
||||
log.error("", throwable);
|
||||
log.error(throwable.getMessage(), throwable);
|
||||
throw throwable;
|
||||
} finally {
|
||||
this.repeatSubmitTicket.unLock(ticket, intervalMilliSecond);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,10 +7,19 @@ import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 标记 需要防止重复提交 的注解<br>
|
||||
* 单位:毫秒
|
||||
* 单位:毫秒<br>
|
||||
* -------------------------<br>
|
||||
* 着重说明:<br>
|
||||
* 注解属性 intervalMilliSecond 是指 一段时间内只允许有一次请求;<br>
|
||||
* intervalMilliSecond = 0: 表示只有上个请求执行完以后才可以执行<br>
|
||||
* intervalMilliSecond > 0: 表示指定时间内只才能执行,特别提醒<br>
|
||||
* ------------------------<br>
|
||||
* 特殊说明 intervalMilliSecond > 0 <br>
|
||||
* 若假设 方法执行时间为 100ms,若 intervalMilliSecond = 50,则 同一时间内可能会有2个请求同时在执行!<br>
|
||||
* 若假设 方法执行时间为 100ms,若 intervalMilliSecond = 200,则 同一时间内只能有1请求执行,且执行完后100ms,才会执行下一次请求<br>
|
||||
*
|
||||
* @Author 1024创新实验室: 胡克
|
||||
* @Date 2020-11-25 20:56:58
|
||||
* @Author 1024创新实验室-主任: 卓大
|
||||
* @Date 2025-07-26 20:56:58
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
@@ -20,8 +29,8 @@ import java.lang.annotation.Target;
|
||||
public @interface RepeatSubmit {
|
||||
|
||||
/**
|
||||
* 重复提交间隔时间/毫秒
|
||||
* 间隔时间/毫秒
|
||||
*/
|
||||
int value() default 300;
|
||||
int intervalMilliSecond() default 0;
|
||||
|
||||
}
|
||||
|
@@ -1,42 +1,42 @@
|
||||
package net.lab1024.sa.base.module.support.repeatsubmit.ticket;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 凭证(用于校验重复提交的东西)
|
||||
*
|
||||
* @Author 1024创新实验室: 罗伊
|
||||
* @Date 2020-11-25 20:56:58
|
||||
* @Author 1024创新实验室-主任: 卓大
|
||||
* @Date 2025-07-26 23:56:58
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
public abstract class AbstractRepeatSubmitTicket {
|
||||
|
||||
private final Function<String, String> ticketFunction;
|
||||
private final Function<HttpServletRequest, String> generateTicketFunction;
|
||||
|
||||
|
||||
public AbstractRepeatSubmitTicket(Function<String, String> ticketFunction) {
|
||||
this.ticketFunction = ticketFunction;
|
||||
public AbstractRepeatSubmitTicket(Function<HttpServletRequest, String> generateTicketFunction) {
|
||||
this.generateTicketFunction = generateTicketFunction;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取凭证
|
||||
* 生成 加锁的 凭证
|
||||
*/
|
||||
public String getTicket(String ticketToken) {
|
||||
return this.ticketFunction.apply(ticketToken);
|
||||
public String generateTicket(HttpServletRequest request) {
|
||||
return this.generateTicketFunction.apply(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取凭证 时间戳
|
||||
* 加锁
|
||||
*/
|
||||
public abstract Long getTicketTimestamp(String ticket);
|
||||
|
||||
public abstract boolean tryLock(String ticket, Long currentTimestamp, Long intervalMilliSecond);
|
||||
|
||||
/**
|
||||
* 设置本次请求时间
|
||||
* 移除锁
|
||||
*/
|
||||
public abstract void putTicket(String ticket);
|
||||
public abstract void unLock(String ticket, Long intervalMilliSecond);
|
||||
|
||||
}
|
||||
|
@@ -1,44 +0,0 @@
|
||||
package net.lab1024.sa.base.module.support.repeatsubmit.ticket;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 凭证(内存实现)
|
||||
*
|
||||
* @Author 1024创新实验室: 罗伊
|
||||
* @Date 2020-11-25 20:56:58
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
public class RepeatSubmitCaffeineTicket extends AbstractRepeatSubmitTicket {
|
||||
|
||||
/**
|
||||
* 限制缓存最大数量 超过后先放入的会自动移除
|
||||
* 默认缓存时间
|
||||
* 初始大小为:100万
|
||||
*/
|
||||
private static final Cache<String, Long> cache = Caffeine.newBuilder()
|
||||
.maximumSize(100 * 10000)
|
||||
.expireAfterWrite(300 * 1000L, TimeUnit.MILLISECONDS).build();
|
||||
|
||||
|
||||
public RepeatSubmitCaffeineTicket(Function<String, String> ticketFunction) {
|
||||
super(ticketFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getTicketTimestamp(String ticket) {
|
||||
return cache.getIfPresent(ticket);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void putTicket(String ticket) {
|
||||
cache.put(ticket, System.currentTimeMillis());
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
package net.lab1024.sa.base.module.support.repeatsubmit.ticket;
|
||||
|
||||
import com.google.common.collect.Interner;
|
||||
import com.google.common.collect.Interners;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 凭证(内存实现)
|
||||
*
|
||||
* @Author 1024创新实验室-主任: 卓大
|
||||
* @Date 2025-07-26 23:56:58
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
public class RepeatSubmitMemoryTicket extends AbstractRepeatSubmitTicket {
|
||||
|
||||
private Interner<String> pool = Interners.newStrongInterner();
|
||||
|
||||
private ConcurrentMap<String, Long> ticketMap = Maps.newConcurrentMap();
|
||||
|
||||
public RepeatSubmitMemoryTicket(Function<HttpServletRequest, String> ticketFunction) {
|
||||
super(ticketFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryLock(String ticket, Long currentTimestamp, Long intervalMilliSecond) {
|
||||
synchronized (pool.intern(ticket)) {
|
||||
Long lastTime = ticketMap.putIfAbsent(ticket, currentTimestamp);
|
||||
if (lastTime == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (intervalMilliSecond <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentTimestamp - lastTime < intervalMilliSecond) {
|
||||
return false;
|
||||
|
||||
}
|
||||
ticketMap.put(ticket, currentTimestamp);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unLock(String ticket, Long intervalMilliSecond) {
|
||||
if (intervalMilliSecond > 0) {
|
||||
return;
|
||||
}
|
||||
ticketMap.remove(ticket);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,38 +1,47 @@
|
||||
package net.lab1024.sa.base.module.support.repeatsubmit.ticket;
|
||||
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 凭证(redis实现)
|
||||
*
|
||||
* @Author 1024创新实验室: 罗伊
|
||||
* @Date 2020-11-25 20:56:58
|
||||
* @Author 1024创新实验室-主任: 卓大
|
||||
* @Date 2025-07-26 23:56:58
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
public class RepeatSubmitRedisTicket extends AbstractRepeatSubmitTicket {
|
||||
|
||||
private final ValueOperations<String, String> redisValueOperations;
|
||||
private final RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
public RepeatSubmitRedisTicket(ValueOperations<String, String> redisValueOperations,
|
||||
Function<String, String> ticketFunction) {
|
||||
public RepeatSubmitRedisTicket(RedisTemplate<String, Object> redisTemplate,
|
||||
Function<HttpServletRequest, String> ticketFunction) {
|
||||
super(ticketFunction);
|
||||
this.redisValueOperations = redisValueOperations;
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getTicketTimestamp(String ticket) {
|
||||
String ticketLastTime = redisValueOperations.get(ticket);
|
||||
return ticketLastTime == null ? null : Long.valueOf(ticketLastTime);
|
||||
public boolean tryLock(String ticket, Long currentTimestamp, Long intervalMilliSecond) {
|
||||
if (intervalMilliSecond > 0) {
|
||||
return Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(ticket, String.valueOf(currentTimestamp), intervalMilliSecond, TimeUnit.MILLISECONDS));
|
||||
} else {
|
||||
return Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(ticket, String.valueOf(currentTimestamp)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putTicket(String ticket) {
|
||||
redisValueOperations.getOperations().delete(ticket);
|
||||
this.getTicketTimestamp(ticket);
|
||||
public void unLock(String ticket, Long intervalMilliSecond) {
|
||||
if (intervalMilliSecond > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
redisTemplate.delete(ticket);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package net.lab1024.sa.base.module.support.securityprotect.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.tika.config.TikaConfig;
|
||||
import org.apache.tika.exception.TikaException;
|
||||
import org.apache.tika.io.TikaInputStream;
|
||||
@@ -14,6 +15,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -35,27 +37,9 @@ public class SecurityFileService {
|
||||
private Level3ProtectConfigService level3ProtectConfigService;
|
||||
|
||||
// 定义白名单MIME类型
|
||||
private static final List<String> ALLOWED_MIME_TYPES = Arrays.asList(
|
||||
"application/json",
|
||||
"application/zip",
|
||||
"application/x-7z-compressed",
|
||||
"application/pdf",
|
||||
"application/vnd.ms-excel",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"application/vnd.ms-powerpoint",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||
"application/msword",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"application/vnd.ms-works",
|
||||
"text/csv",
|
||||
"audio/*",
|
||||
"video/*",
|
||||
private static final List<String> ALLOWED_MIME_TYPES = Arrays.asList("application/json", "application/zip", "application/x-7z-compressed", "application/pdf", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-works", "text/csv", "audio/*", "video/*",
|
||||
// 图片类型 svg有安全隐患,所以不使用"image/*"
|
||||
"image/jpeg",
|
||||
"image/png",
|
||||
"image/gif",
|
||||
"image/bmp"
|
||||
);
|
||||
"image/jpeg", "image/png", "image/gif", "image/bmp");
|
||||
|
||||
/**
|
||||
* 检测文件安全类型
|
||||
@@ -73,8 +57,7 @@ public class SecurityFileService {
|
||||
// 文件类型安全检测
|
||||
if (level3ProtectConfigService.isFileDetectFlag()) {
|
||||
String fileType = getFileMimeType(file);
|
||||
if (ALLOWED_MIME_TYPES.stream()
|
||||
.noneMatch(allowedType -> matchesMimeType(fileType, allowedType))) {
|
||||
if (ALLOWED_MIME_TYPES.stream().noneMatch(allowedType -> matchesMimeType(fileType, allowedType))) {
|
||||
return ResponseDTO.userErrorParam("禁止上传此文件类型");
|
||||
}
|
||||
}
|
||||
@@ -89,16 +72,20 @@ public class SecurityFileService {
|
||||
* @return 文件的 MIME 类型
|
||||
*/
|
||||
public static String getFileMimeType(MultipartFile file) {
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = file.getInputStream();
|
||||
TikaConfig tika = new TikaConfig();
|
||||
Metadata metadata = new Metadata();
|
||||
metadata.set(TikaCoreProperties.RESOURCE_NAME_KEY, file.getOriginalFilename());
|
||||
TikaInputStream stream = TikaInputStream.get(file.getInputStream());
|
||||
TikaInputStream stream = TikaInputStream.get(inputStream);
|
||||
MediaType mimetype = tika.getDetector().detect(stream, metadata);
|
||||
return mimetype.toString();
|
||||
} catch (IOException | TikaException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return MimeTypes.OCTET_STREAM;
|
||||
} finally {
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* @Date 2022-03-25 21:46:07
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
public abstract class SerialNumberBaseService implements SerialNumberService {
|
||||
|
||||
@@ -37,7 +37,7 @@ public abstract class SerialNumberBaseService implements SerialNumberService {
|
||||
@Resource
|
||||
protected SerialNumberDao serialNumberDao;
|
||||
|
||||
private ConcurrentHashMap<Integer, SerialNumberInfoBO> serialNumberMap = new ConcurrentHashMap<>();
|
||||
protected ConcurrentHashMap<Integer, SerialNumberInfoBO> serialNumberMap = new ConcurrentHashMap<>();
|
||||
|
||||
public abstract List<String> generateSerialNumberList(SerialNumberInfoBO serialNumber, int count);
|
||||
|
||||
|
@@ -1,23 +1,34 @@
|
||||
package net.lab1024.sa.base.module.support.serialnumber.service.impl;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.base.common.exception.BusinessException;
|
||||
import net.lab1024.sa.base.common.util.SmartDateFormatterEnum;
|
||||
import net.lab1024.sa.base.common.util.SmartEnumUtil;
|
||||
import net.lab1024.sa.base.common.util.SmartLocalDateUtil;
|
||||
import net.lab1024.sa.base.common.util.SmartStringUtil;
|
||||
import net.lab1024.sa.base.constant.RedisKeyConst;
|
||||
import net.lab1024.sa.base.module.support.redis.RedisService;
|
||||
import net.lab1024.sa.base.module.support.serialnumber.constant.SerialNumberRuleTypeEnum;
|
||||
import net.lab1024.sa.base.module.support.serialnumber.domain.SerialNumberEntity;
|
||||
import net.lab1024.sa.base.module.support.serialnumber.domain.SerialNumberGenerateResultBO;
|
||||
import net.lab1024.sa.base.module.support.serialnumber.domain.SerialNumberInfoBO;
|
||||
import net.lab1024.sa.base.module.support.serialnumber.domain.SerialNumberLastGenerateBO;
|
||||
import net.lab1024.sa.base.module.support.serialnumber.service.SerialNumberBaseService;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 单据序列号 基于redis锁实现
|
||||
* 单据序列号 基于redis key-value increase 实现
|
||||
*
|
||||
* @Author 1024创新实验室-主任: 卓大
|
||||
* @Date 2022-03-25 21:46:07
|
||||
* @Date 2025-08-03 22:46:07
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
@@ -25,86 +36,125 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class SerialNumberRedisService extends SerialNumberBaseService {
|
||||
|
||||
private static final int MAX_GET_LOCK_COUNT = 5;
|
||||
|
||||
private static final long SLEEP_MILLISECONDS = 200L;
|
||||
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
@Override
|
||||
public void initLastGenerateData(List<SerialNumberEntity> serialNumberEntityList) {
|
||||
if (serialNumberEntityList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//删除之前的
|
||||
redisService.delete(RedisKeyConst.Support.SERIAL_NUMBER_LAST_INFO);
|
||||
|
||||
// 设置redis的上次值
|
||||
for (SerialNumberEntity serialNumberEntity : serialNumberEntityList) {
|
||||
SerialNumberLastGenerateBO lastGenerateBO = SerialNumberLastGenerateBO
|
||||
.builder()
|
||||
.serialNumberId(serialNumberEntity.getSerialNumberId())
|
||||
.lastNumber(serialNumberEntity.getLastNumber())
|
||||
.lastTime(serialNumberEntity.getLastTime())
|
||||
.build();
|
||||
if (serialNumberEntity.getLastTime() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
redisService.mset(RedisKeyConst.Support.SERIAL_NUMBER_LAST_INFO,
|
||||
String.valueOf(serialNumberEntity.getSerialNumberId()),
|
||||
lastGenerateBO
|
||||
);
|
||||
String redisKey = generateRedisKeyByDate(serialNumberEntity.getSerialNumberId(),
|
||||
SmartEnumUtil.getEnumByName(serialNumberEntity.getRuleType().toUpperCase(), SerialNumberRuleTypeEnum.class),
|
||||
serialNumberEntity.getLastTime().toLocalDate());
|
||||
|
||||
Object o = redisTemplate.opsForValue().get(redisKey);
|
||||
if (o == null) {
|
||||
redisTemplate.opsForValue().set(redisKey, serialNumberEntity.getLastNumber());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 每天凌晨一点进行检测;
|
||||
* 检测单位数量为3; 3天前、3月前、3年前
|
||||
*/
|
||||
@Scheduled(cron = "0 0 1 * * ?")
|
||||
public void tryDeleteUnusedRedisKey() {
|
||||
for (SerialNumberInfoBO serialNumberInfoBO : serialNumberMap.values()) {
|
||||
SerialNumberRuleTypeEnum typeEnum = serialNumberInfoBO.getSerialNumberRuleTypeEnum();
|
||||
String dateStr = "";
|
||||
switch (typeEnum) {
|
||||
case DAY:
|
||||
dateStr = SmartLocalDateUtil.format(LocalDate.now().minusDays(3), SmartDateFormatterEnum.YMD);
|
||||
case MONTH:
|
||||
dateStr = SmartLocalDateUtil.format(LocalDate.now().minusMonths(3), SmartDateFormatterEnum.YM);
|
||||
case YEAR:
|
||||
dateStr = String.valueOf(LocalDate.now().minusYears(3));
|
||||
}
|
||||
if (SmartStringUtil.isNotEmpty(dateStr)) {
|
||||
String redisKey = RedisKeyConst.Support.SERIAL_NUMBER + serialNumberInfoBO.getSerialNumberId() + ":" + dateStr;
|
||||
redisService.delete(redisKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> generateSerialNumberList(SerialNumberInfoBO serialNumberInfo, int count) {
|
||||
SerialNumberGenerateResultBO serialNumberGenerateResult = null;
|
||||
String lockKey = RedisKeyConst.Support.SERIAL_NUMBER + serialNumberInfo.getSerialNumberId();
|
||||
|
||||
boolean lock = false;
|
||||
for (int i = 0; i < MAX_GET_LOCK_COUNT; i++) {
|
||||
try {
|
||||
lock = redisService.getLock(lockKey, 60 * 1000L);
|
||||
if (lock) {
|
||||
break;
|
||||
}
|
||||
Thread.sleep(SLEEP_MILLISECONDS);
|
||||
} catch (Throwable e) {
|
||||
log.error(e.getMessage(), e);
|
||||
// 根据步长,计算 redis 增加值
|
||||
ArrayList<Integer> list = new ArrayList<>(count);
|
||||
int redisIncrease = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
int stepIncrease = 1;
|
||||
Integer stepRandomRange = serialNumberInfo.getStepRandomRange();
|
||||
if (stepRandomRange > 1) {
|
||||
stepIncrease = RandomUtil.getSecureRandom().nextInt(serialNumberInfo.getStepRandomRange()) + 1;
|
||||
}
|
||||
redisIncrease += stepIncrease;
|
||||
list.add(stepIncrease);
|
||||
}
|
||||
if (!lock) {
|
||||
throw new BusinessException("SerialNumber 尝试5次,未能生成单号");
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取上次的生成结果
|
||||
SerialNumberLastGenerateBO lastGenerateBO = (SerialNumberLastGenerateBO) redisService.mget(
|
||||
RedisKeyConst.Support.SERIAL_NUMBER_LAST_INFO,
|
||||
String.valueOf(serialNumberInfo.getSerialNumberId()));
|
||||
String redisKey = generateRedisKeyByDate(serialNumberInfo.getSerialNumberId(), serialNumberInfo.getSerialNumberRuleTypeEnum(), LocalDate.now());
|
||||
Long increaseResult = redisTemplate.opsForValue().increment(redisKey, redisIncrease);
|
||||
|
||||
ArrayList<Long> numberList = new ArrayList<>(count);
|
||||
Long number = increaseResult;
|
||||
for (Integer i : list) {
|
||||
number = number - i;
|
||||
numberList.add((number + 1));
|
||||
}
|
||||
|
||||
Collections.reverse(numberList);
|
||||
|
||||
SerialNumberGenerateResultBO serialNumberGenerateResult = SerialNumberGenerateResultBO
|
||||
.builder()
|
||||
.serialNumberId(serialNumberInfo.getSerialNumberId())
|
||||
.lastNumber(increaseResult)
|
||||
.lastTime(LocalDateTime.now())
|
||||
.numberList(numberList)
|
||||
.isReset(false)
|
||||
.build();
|
||||
|
||||
// 生成
|
||||
serialNumberGenerateResult = super.loopNumberList(lastGenerateBO, serialNumberInfo, count);
|
||||
|
||||
// 将生成信息保存的内存和数据库
|
||||
lastGenerateBO.setLastNumber(serialNumberGenerateResult.getLastNumber());
|
||||
lastGenerateBO.setLastTime(serialNumberGenerateResult.getLastTime());
|
||||
serialNumberDao.updateLastNumberAndTime(serialNumberInfo.getSerialNumberId(),
|
||||
serialNumberGenerateResult.getLastNumber(),
|
||||
serialNumberGenerateResult.getLastTime());
|
||||
|
||||
redisService.mset(RedisKeyConst.Support.SERIAL_NUMBER_LAST_INFO,
|
||||
String.valueOf(serialNumberInfo.getSerialNumberId()), lastGenerateBO);
|
||||
|
||||
// 把生成过程保存到数据库里
|
||||
super.saveRecord(serialNumberGenerateResult);
|
||||
return formatNumberList(serialNumberGenerateResult, serialNumberInfo);
|
||||
} catch (Throwable e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw e;
|
||||
} finally {
|
||||
redisService.unLock(lockKey);
|
||||
}
|
||||
}
|
||||
|
||||
return formatNumberList(serialNumberGenerateResult, serialNumberInfo);
|
||||
private String generateRedisKeyByDate(Integer serialNumberId, SerialNumberRuleTypeEnum serialNumberRuleTypeEnum, LocalDate localDate) {
|
||||
switch (serialNumberRuleTypeEnum) {
|
||||
case DAY:
|
||||
String dayStr = SmartLocalDateUtil.format(localDate, SmartDateFormatterEnum.YMD);
|
||||
return RedisKeyConst.Support.SERIAL_NUMBER + serialNumberId + ":" + dayStr;
|
||||
case MONTH:
|
||||
String monthStr = SmartLocalDateUtil.format(localDate, SmartDateFormatterEnum.YM);
|
||||
return RedisKeyConst.Support.SERIAL_NUMBER + serialNumberId + ":" + monthStr;
|
||||
case YEAR:
|
||||
String yearStr = String.valueOf(localDate.getYear());
|
||||
return RedisKeyConst.Support.SERIAL_NUMBER + serialNumberId + ":" + yearStr;
|
||||
case NONE:
|
||||
return RedisKeyConst.Support.SERIAL_NUMBER + serialNumberId;
|
||||
default:
|
||||
throw new BusinessException("serialNumberRuleTypeEnum not exist error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -64,10 +64,26 @@ spring:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
|
||||
# 上传文件和请求大小
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 20MB # 单个文件的最大大小
|
||||
max-request-size: 10MB # 整个请求的最大大小
|
||||
|
||||
# 缓存实现类型
|
||||
cache:
|
||||
type: redis
|
||||
|
||||
# 健康检查
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info
|
||||
health:
|
||||
mail:
|
||||
enabled: false
|
||||
|
||||
# tomcat 配置,主要用于 配置 访问日志(便于将来排查错误)
|
||||
server:
|
||||
tomcat:
|
||||
@@ -109,7 +125,7 @@ knife4j:
|
||||
username: api # Basic认证用户名
|
||||
password: 1024 # Basic认证密码
|
||||
|
||||
# RestTemplate 请求配置
|
||||
# RestTemplate 请求配置 毫秒
|
||||
http:
|
||||
pool:
|
||||
max-total: 20
|
||||
|
@@ -64,10 +64,26 @@ spring:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
|
||||
# 上传文件和请求大小
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 20MB # 单个文件的最大大小
|
||||
max-request-size: 10MB # 整个请求的最大大小
|
||||
|
||||
# 缓存实现类型
|
||||
cache:
|
||||
type: redis
|
||||
|
||||
# 健康检查
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info
|
||||
health:
|
||||
mail:
|
||||
enabled: false
|
||||
|
||||
# tomcat 配置,主要用于 配置 访问日志(便于将来排查错误)
|
||||
server:
|
||||
tomcat:
|
||||
@@ -109,7 +125,7 @@ knife4j:
|
||||
username: api # Basic认证用户名
|
||||
password: 1024 # Basic认证密码
|
||||
|
||||
# RestTemplate 请求配置
|
||||
# RestTemplate 请求配置 毫秒
|
||||
http:
|
||||
pool:
|
||||
max-total: 20
|
||||
@@ -133,7 +149,7 @@ reload:
|
||||
sa-token:
|
||||
# token 名称(同时也是 cookie 名称)
|
||||
token-name: Authorization
|
||||
# token 前缀 例如:Bear
|
||||
# token 前缀 例如:Bearer
|
||||
token-prefix: Bearer
|
||||
# token 有效期(单位:秒) 默认30天(2592000秒),-1 代表永久有效
|
||||
timeout: 2592000
|
||||
@@ -167,4 +183,4 @@ smart:
|
||||
# 数据库配置检测-开关 默认开启 可选(作用是固定间隔读取数据库配置更新任务,关闭后只能重启服务或通过接口修改定时任务,建议开启)
|
||||
db-refresh-enabled: true
|
||||
# 数据库配置检测-执行间隔 默认120秒 可选
|
||||
db-refresh-interval: 60
|
||||
db-refresh-interval: 60
|
||||
|
@@ -7,14 +7,14 @@ spring:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
initial-size: 10
|
||||
min-idle: 10
|
||||
max-active: 100
|
||||
max-active: 200
|
||||
max-wait: 60000
|
||||
time-between-eviction-runs-millis: 60000
|
||||
min-evictable-idle-time-millis: 300000
|
||||
filters: stat
|
||||
druid:
|
||||
username: druid
|
||||
password: 1024lab
|
||||
password: 1024
|
||||
login:
|
||||
enabled: false
|
||||
method:
|
||||
@@ -63,10 +63,26 @@ spring:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
|
||||
# 上传文件和请求大小
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 20MB # 单个文件的最大大小
|
||||
max-request-size: 10MB # 整个请求的最大大小
|
||||
|
||||
# 缓存实现类型
|
||||
cache:
|
||||
type: redis
|
||||
|
||||
# 健康检查
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info
|
||||
health:
|
||||
mail:
|
||||
enabled: false
|
||||
|
||||
# tomcat 配置,主要用于 配置 访问日志(便于将来排查错误)
|
||||
server:
|
||||
tomcat:
|
||||
@@ -93,14 +109,13 @@ file:
|
||||
url-prefix: https://${file.storage.cloud.bucket-name}.${file.storage.cloud.endpoint}/
|
||||
private-url-expire-seconds: 3600
|
||||
|
||||
|
||||
# open api配置
|
||||
springdoc:
|
||||
swagger-ui:
|
||||
enabled: true # 开关
|
||||
doc-expansion: none #关闭展开
|
||||
tags-sorter: alpha
|
||||
server-base-url: https://preview.smartadmin.vip/smart-admin-api
|
||||
server-base-url:
|
||||
api-docs:
|
||||
enabled: true # 开关
|
||||
knife4j:
|
||||
@@ -110,7 +125,7 @@ knife4j:
|
||||
username: api # Basic认证用户名
|
||||
password: 1024 # Basic认证密码
|
||||
|
||||
# RestTemplate 请求配置
|
||||
# RestTemplate 请求配置 毫秒
|
||||
http:
|
||||
pool:
|
||||
max-total: 100
|
||||
@@ -131,7 +146,7 @@ reload:
|
||||
sa-token:
|
||||
# token 名称(同时也是 cookie 名称)
|
||||
token-name: Authorization
|
||||
# token 前缀 例如:Bear
|
||||
# token 前缀 例如:Bearer
|
||||
token-prefix: Bearer
|
||||
# token 有效期(单位:秒) 默认30天(2592000秒),-1 代表永久有效
|
||||
timeout: 2592000
|
||||
|
@@ -64,10 +64,26 @@ spring:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
|
||||
# 上传文件和请求大小
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 20MB # 单个文件的最大大小
|
||||
max-request-size: 10MB # 整个请求的最大大小
|
||||
|
||||
# 缓存实现类型
|
||||
cache:
|
||||
type: redis
|
||||
|
||||
# 健康检查
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info
|
||||
health:
|
||||
mail:
|
||||
enabled: false
|
||||
|
||||
# tomcat 配置,主要用于 配置 访问日志(便于将来排查错误)
|
||||
server:
|
||||
tomcat:
|
||||
@@ -109,7 +125,7 @@ knife4j:
|
||||
username: api # Basic认证用户名
|
||||
password: 1024 # Basic认证密码
|
||||
|
||||
# RestTemplate 请求配置
|
||||
# RestTemplate 请求配置 毫秒
|
||||
http:
|
||||
pool:
|
||||
max-total: 20
|
||||
@@ -133,7 +149,7 @@ reload:
|
||||
sa-token:
|
||||
# token 名称(同时也是 cookie 名称)
|
||||
token-name: Authorization
|
||||
# token 前缀 例如:Bear
|
||||
# token 前缀 例如:Bearer
|
||||
token-prefix: Bearer
|
||||
# token 有效期(单位:秒) 默认30天(2592000秒),-1 代表永久有效
|
||||
timeout: 2592000
|
||||
@@ -167,4 +183,4 @@ smart:
|
||||
# 数据库配置检测-开关 默认开启 可选(作用是固定间隔读取数据库配置更新任务,关闭后只能重启服务或通过接口修改定时任务,建议开启)
|
||||
db-refresh-enabled: true
|
||||
# 数据库配置检测-执行间隔 默认120秒 可选
|
||||
db-refresh-interval: 60
|
||||
db-refresh-interval: 60
|
||||
|
Reference in New Issue
Block a user