refactor: 优化部分代码格式

This commit is contained in:
2025-06-01 11:10:53 +08:00
parent 6b95083c63
commit eda35e59bc
6 changed files with 15 additions and 54 deletions

View File

@@ -66,6 +66,7 @@ import java.util.concurrent.TimeUnit;
@EnableConfigurationProperties(SpringDocExtensionProperties.class) @EnableConfigurationProperties(SpringDocExtensionProperties.class)
@PropertySource(value = "classpath:default-api-doc.yml", factory = GeneralPropertySourceFactory.class) @PropertySource(value = "classpath:default-api-doc.yml", factory = GeneralPropertySourceFactory.class)
public class SpringDocAutoConfiguration implements WebMvcConfigurer { public class SpringDocAutoConfiguration implements WebMvcConfigurer {
private static final Logger log = LoggerFactory.getLogger(SpringDocAutoConfiguration.class); private static final Logger log = LoggerFactory.getLogger(SpringDocAutoConfiguration.class);
@Override @Override

View File

@@ -40,6 +40,8 @@ import top.continew.starter.extension.tenant.handler.datasource.TenantDataSource
import top.continew.starter.extension.tenant.handler.datasource.TenantDataSourceInterceptor; import top.continew.starter.extension.tenant.handler.datasource.TenantDataSourceInterceptor;
import top.continew.starter.extension.tenant.handler.line.DefaultTenantLineHandler; import top.continew.starter.extension.tenant.handler.line.DefaultTenantLineHandler;
import javax.sql.DataSource;
/** /**
* 租户自动配置 * 租户自动配置
* *
@@ -72,8 +74,8 @@ public class TenantAutoConfiguration {
*/ */
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public TenantLineHandler tenantLineHandler(TenantProperties properties) { public TenantLineHandler tenantLineHandler() {
return new DefaultTenantLineHandler(properties); return new DefaultTenantLineHandler(tenantProperties);
} }
/** /**
@@ -99,7 +101,7 @@ public class TenantAutoConfiguration {
*/ */
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public TenantDataSourceHandler tenantDataSourceHandler(javax.sql.DataSource dataSource, public TenantDataSourceHandler tenantDataSourceHandler(DataSource dataSource,
DefaultDataSourceCreator dataSourceCreator) { DefaultDataSourceCreator dataSourceCreator) {
return new DefaultTenantDataSourceHandler((DynamicRoutingDataSource)dataSource, dataSourceCreator); return new DefaultTenantDataSourceHandler((DynamicRoutingDataSource)dataSource, dataSourceCreator);
} }

View File

@@ -24,7 +24,6 @@ import java.lang.reflect.Method;
* @author Charles7c * @author Charles7c
* @since 2.2.0 * @since 2.2.0
*/ */
@FunctionalInterface
public interface RateLimiterNameGenerator { public interface RateLimiterNameGenerator {
/** /**

View File

@@ -23,5 +23,11 @@
<groupId>net.coobird</groupId> <groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId> <artifactId>thumbnailator</artifactId>
</dependency> </dependency>
<!-- Hutool 加密解密模块(封装 JDK 中加密解密算法) -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-crypto</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -21,6 +21,7 @@ import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.file.FileNameUtil; import cn.hutool.core.io.file.FileNameUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.DigestUtil;
import top.continew.starter.core.constant.StringConstants; import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.exception.BusinessException; import top.continew.starter.core.exception.BusinessException;
import top.continew.starter.core.validation.CheckUtils; import top.continew.starter.core.validation.CheckUtils;
@@ -33,14 +34,12 @@ import top.continew.starter.storage.model.req.StorageProperties;
import top.continew.starter.storage.model.resp.ThumbnailResp; import top.continew.starter.storage.model.resp.ThumbnailResp;
import top.continew.starter.storage.model.resp.UploadResp; import top.continew.starter.storage.model.resp.UploadResp;
import top.continew.starter.storage.util.ImageThumbnailUtils; import top.continew.starter.storage.util.ImageThumbnailUtils;
import top.continew.starter.storage.util.LocalUtils;
import top.continew.starter.storage.util.StorageUtils; import top.continew.starter.storage.util.StorageUtils;
import java.io.*; import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Base64; import java.util.Base64;
@@ -147,12 +146,12 @@ public class LocalStorageStrategy implements StorageStrategy<LocalClient> {
} }
// 构建文件 md5 // 构建文件 md5
String eTag = LocalUtils.calculateMD5(inputStream); String eTag = DigestUtil.md5Hex(IoUtil.readBytes(inputStream));
// 构建 上传后的文件路径地址 格式 xxx/xxx/xxx.jpg // 构建 上传后的文件路径地址 格式 xxx/xxx/xxx.jpg
String filePath = Paths.get(path, formatFileName).toString(); String filePath = Paths.get(path, formatFileName).toString();
// 构建 文件上传记录 并返回 // 构建 文件上传记录 并返回
return buildStorageRecord(bucketName, fileName, filePath, eTag, originalBytes.length, thumbnailResp); return buildStorageRecord(bucketName, fileName, filePath, eTag, originalBytes.length, thumbnailResp);
} catch (NoSuchAlgorithmException | IOException e) { } catch (IOException e) {
throw new BusinessException("文件上传异常", e); throw new BusinessException("文件上传异常", e);
} }

View File

@@ -1,46 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 top.continew.starter.storage.util;
import cn.hutool.core.io.IoUtil;
import net.dreamlu.mica.core.utils.DigestUtil;
import java.io.InputStream;
import java.security.NoSuchAlgorithmException;
/**
* 本地存储工具
*
* @author echo
* @since 2.9.0
*/
public class LocalUtils {
public LocalUtils() {
}
/**
* 计算MD5
*
* @param inputStream 输入流
* @return {@link String }
* @throws NoSuchAlgorithmException 没有这样算法例外
*/
public static String calculateMD5(InputStream inputStream) throws NoSuchAlgorithmException {
byte[] fileBytes = IoUtil.readBytes(inputStream);
return DigestUtil.md5Hex(fileBytes);
}
}