diff --git a/README.md b/README.md index 55925b7..5bdf809 100644 --- a/README.md +++ b/README.md @@ -8,29 +8,6 @@    依赖[rice-toolkit](https://github.com/NicheToolkit/rice-toolkit/rice-toolkit-starter)组件下的基于[postgresql](https://www.postgresql.org/)数据库环境下的简单业务通用服务开发组件. -## Release介绍 - -- [File-Toolkit@1.0.3](https://github.com/NicheToolkit/file-toolkit/tree/master/release/1.0.3.md) - -### v1.0.3 Release - -1、修复`minio`依赖`okhttp3`版本为`4.8.1`。 - -2、升级`spring boot`版本至`2.6.6`版本。 - -3、优化文件上传异步处理,加快文件上传接口响应。 - -4、拆分`MinioUtils`工具至单独模块`file-toolkit-minio-utils`。 - -5、拆分文件模型定义相关`FileChunk`、`FileIndex`至单独模块`file-toolkit-common-starter`。 - -# [file-toolkit-test-web](https://github.com/NicheToolkit/file-toolkit/tree/master/file-toolkit-test-web) - -[logback-spring.xml](https://github.com/NicheToolkit/file-toolkit/blob/master/file-toolkit-test-web/src/main/resources/logback-spring.xml) -默认日志配置文件调整,新增`LOGS_FILE`所有日志的到`./logs.log`文件的输出,方便同一个`Tomcat`服务器下部署多个`War`包时,查看单个服务的日志混乱的问题。 - -**Full Changelog**: https://github.com/NicheToolkit/file-toolkit/compare/v1.0.2...v1.0.3 - ## Maven Central - [Maven Central Repository](https://search.maven.org/search?q=io.github.nichetoolkit) @@ -38,7 +15,7 @@ - [Sonatype Central Repository](https://central.sonatype.dev/search?q=io.github.nichetoolkit) ## 依赖环境 - > [Spring Boot](https://spring.io/projects/spring-boot) 2.6.6.RELEASE\ + > [Spring Boot](https://spring.io/projects/spring-boot) 2.7.7.RELEASE\ > [Maven](https://maven.apache.org/) 3.6.0+\ > [JDK](https://www.oracle.com/java/technologies/downloads/#java8) 1.8\ > [PostgreSQL](https://www.postgresql.org/) 10.0+ @@ -49,7 +26,7 @@ io.github.nichetoolkit file-toolkit-common-starter - 1.0.3 + 1.0.4 ``` @@ -59,7 +36,7 @@ io.github.nichetoolkit file-toolkit-service-starter - 1.0.3 + 1.0.4 ``` @@ -69,7 +46,7 @@ io.github.nichetoolkit file-toolkit-minio-starter - 1.0.3 + 1.0.4 ``` @@ -79,7 +56,7 @@ io.github.nichetoolkit file-toolkit-minio-utils - 1.0.3 + 1.0.4 ``` diff --git a/SECURITY.md b/SECURITY.md index e678037..207fb6e 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -7,13 +7,13 @@ currently being supported with security updates. | Version | Supported | | ------- | ------------------ | -| Spring boot 2.6.6+ | :white_check_mark: | -| < 2.6.6 | :x: | +| Spring boot 2.7.7+ | :white_check_mark: | +| < 2.7.7 | :x: | | Maven 3.6.0+ | :white_check_mark: | | < 3.6.0 | :x: | | JDK 1.8 | :white_check_mark: | | -| Rice-Toolkit 1.0.4+ | :white_check_mark: | -| < 1.0.4 | :x: +| Rice-Toolkit 1.0.5+ | :white_check_mark: | +| < 1.0.5 | :x: ## Reporting a Vulnerability Use this section to tell people how to report a vulnerability. diff --git a/file-toolkit-common-starter/pom.xml b/file-toolkit-common-starter/pom.xml index 66c9b73..b5779ff 100644 --- a/file-toolkit-common-starter/pom.xml +++ b/file-toolkit-common-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4 file-toolkit-common-starter - 1.0.3 + 1.0.4 file-toolkit-common-starter File toolkit common starter project for Spring Boot diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/AsyncFileService.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/handle/FileStoreService.java similarity index 88% rename from file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/AsyncFileService.java rename to file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/handle/FileStoreService.java index 0ffc7b6..f2fec9a 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/AsyncFileService.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/handle/FileStoreService.java @@ -1,4 +1,4 @@ -package io.github.nichetoolkit.file.service; +package io.github.nichetoolkit.file.handle; import io.github.nichetoolkit.rest.RestException; import org.springframework.scheduling.annotation.Async; @@ -8,11 +8,11 @@ import java.util.List; /** - *

AsyncFileService

+ *

FileStoreService

* @author Cyan (snow22314@outlook.com) * @version v1.0.0 */ -public abstract class AsyncFileService { +public abstract class FileStoreService { @Async abstract public void removeAll(List fileIdList) throws RestException; diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/ImageHelper.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/ImageHandleHelper.java similarity index 99% rename from file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/ImageHelper.java rename to file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/ImageHandleHelper.java index fb81785..058bff0 100644 --- a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/ImageHelper.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/ImageHandleHelper.java @@ -14,7 +14,7 @@ * @author Cyan (snow22314@outlook.com) * @version v1.0.0 */ -public class ImageHelper { +public class ImageHandleHelper { public static void write(BufferedImage bufferedImage, OutputStream outputStream) throws ImageWriteException { try { diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java index 75a3434..aaba571 100644 --- a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java @@ -17,11 +17,8 @@ import lombok.EqualsAndHashCode; import okhttp3.Headers; import org.springframework.lang.NonNull; -import org.springframework.web.multipart.MultipartFile; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -111,7 +108,7 @@ public class FileIndex extends RiceInfoModel { protected byte[] bytes; @JsonIgnore - protected MultipartFile file; + protected File file; public FileIndex() { } @@ -126,7 +123,7 @@ public InputStream inputStream() { return new ByteArrayInputStream(this.bytes); } else if (GeneralUtils.isNotEmpty(this.file)) { try { - return this.file.getInputStream(); + return new FileInputStream(this.file); } catch (IOException ignored) { } } diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/util/ImageUtils.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/util/ImageUtils.java index 52ebf0e..f804eff 100644 --- a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/util/ImageUtils.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/util/ImageUtils.java @@ -4,13 +4,12 @@ import io.github.nichetoolkit.file.error.ImageReadException; import io.github.nichetoolkit.file.error.ImageTransferException; import io.github.nichetoolkit.file.error.ImageWriteException; -import io.github.nichetoolkit.file.helper.ImageHelper; +import io.github.nichetoolkit.file.helper.ImageHandleHelper; import io.github.nichetoolkit.rest.util.GeneralUtils; import io.github.nichetoolkit.rest.util.StreamUtils; import lombok.extern.slf4j.Slf4j; import net.coobird.thumbnailator.Thumbnails; -import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; @@ -31,7 +30,7 @@ public class ImageUtils { public static void write(BufferedImage bufferedImage, OutputStream outputStream) { try { - ImageHelper.write(bufferedImage, outputStream); + ImageHandleHelper.write(bufferedImage, outputStream); } catch (ImageWriteException exception) { log.error("An error occurred during bufferedImage to write as outputStream!", exception); exception.printStackTrace(); @@ -40,7 +39,7 @@ public static void write(BufferedImage bufferedImage, OutputStream outputStream) public static void write(BufferedImage bufferedImage, String imagePath) { try { - ImageHelper.write(bufferedImage, imagePath); + ImageHandleHelper.write(bufferedImage, imagePath); } catch (ImageWriteException exception) { log.error("An error occurred during bufferedImage to write as file!", exception); exception.printStackTrace(); @@ -49,7 +48,7 @@ public static void write(BufferedImage bufferedImage, String imagePath) { public static void write(BufferedImage bufferedImage, File file) { try { - ImageHelper.write(bufferedImage, "png", file); + ImageHandleHelper.write(bufferedImage, "png", file); } catch (ImageWriteException exception) { log.error("An error occurred during bufferedImage to write as file!", exception); exception.printStackTrace(); @@ -59,7 +58,7 @@ public static void write(BufferedImage bufferedImage, File file) { public static void write(BufferedImage bufferedImage, String formatName, OutputStream outputStream) { try { - ImageHelper.write(bufferedImage, formatName, outputStream); + ImageHandleHelper.write(bufferedImage, formatName, outputStream); } catch (ImageWriteException exception) { log.error("An error occurred during bufferedImage to write as outputStream!", exception); exception.printStackTrace(); @@ -68,7 +67,7 @@ public static void write(BufferedImage bufferedImage, String formatName, OutputS public static void write(BufferedImage bufferedImage, String formatName, String imagePath) { try { - ImageHelper.write(bufferedImage, formatName, new File(imagePath)); + ImageHandleHelper.write(bufferedImage, formatName, new File(imagePath)); } catch (ImageWriteException exception) { log.error("An error occurred during bufferedImage to write as file!", exception); exception.printStackTrace(); @@ -77,7 +76,7 @@ public static void write(BufferedImage bufferedImage, String formatName, String public static void write(BufferedImage bufferedImage, String formatName, File file) { try { - ImageHelper.write(bufferedImage, formatName, file); + ImageHandleHelper.write(bufferedImage, formatName, file); } catch (ImageWriteException exception) { log.error("An error occurred during bufferedImage to read as file!", exception); exception.printStackTrace(); @@ -86,7 +85,7 @@ public static void write(BufferedImage bufferedImage, String formatName, File fi public static BufferedImage read(InputStream inputStream) { try { - return ImageHelper.read(inputStream); + return ImageHandleHelper.read(inputStream); } catch (ImageReadException exception) { log.error("An error occurred during inputStream to read as BufferedImage!", exception); exception.printStackTrace(); @@ -96,7 +95,7 @@ public static BufferedImage read(InputStream inputStream) { public static BufferedImage read(String imagePath) { try { - return ImageHelper.read(imagePath); + return ImageHandleHelper.read(imagePath); } catch (ImageReadException exception) { log.error("An error occurred during file to read as BufferedImage!", exception); exception.printStackTrace(); @@ -107,7 +106,7 @@ public static BufferedImage read(String imagePath) { public static BufferedImage read(File file) { try { - return ImageHelper.read(file); + return ImageHandleHelper.read(file); } catch (ImageReadException exception) { log.error("An error occurred during file to write as BufferedImage!", exception); exception.printStackTrace(); @@ -117,7 +116,7 @@ public static BufferedImage read(File file) { public static InputStream inputStream(BufferedImage bufferedImage) { try { - return ImageHelper.inputStream(bufferedImage); + return ImageHandleHelper.inputStream(bufferedImage); } catch (ImageTransferException exception) { log.error("An error occurred during bufferedImage to transfer as inputStream!", exception); exception.printStackTrace(); @@ -127,7 +126,7 @@ public static InputStream inputStream(BufferedImage bufferedImage) { public static byte[] bytes(BufferedImage bufferedImage) { try { - return ImageHelper.bytes(bufferedImage); + return ImageHandleHelper.bytes(bufferedImage); } catch (ImageTransferException exception) { log.error("An error occurred during bufferedImage to transfer as inputStream!", exception); exception.printStackTrace(); diff --git a/file-toolkit-gauss-starter/pom.xml b/file-toolkit-gauss-starter/pom.xml new file mode 100644 index 0000000..c9652d0 --- /dev/null +++ b/file-toolkit-gauss-starter/pom.xml @@ -0,0 +1,224 @@ + + + 4.0.0 + + io.github.nichetoolkit + file-toolkit-parent + 1.0.4 + + + file-toolkit-gauss-starter + 1.0.4 + file-toolkit-gauss-starter + jar + File toolkit service project for Spring Boot + https://github.com/NicheToolkit/file-toolkit/tree/master/file-toolkit-gauss-starter + + + 1.8 + UTF-8 + UTF-8 + + + + + The Apache License (Apache-2.0) + https://github.com/NicheToolkit/file-toolkit/blob/master/LICENSE + + + + + + Cyan + snow22314@outlook.com + + + + + scm:git:git@github.com:NicheToolkit/file-toolkit.git + scm:git:git@github.com:NicheToolkit/file-toolkit.git + git@github.com:NicheToolkit/file-toolkit.git + + + + + sonatype-nexus-snapshot + https://s01.oss.sonatype.org/content/repositories/snapshots + + + sonatype-nexus-deploy + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + + io.github.nichetoolkit + file-toolkit-service-starter + ${file-toolkit.version} + + + + tk.mybatis + mapper + ${tk-mybatis-mapper.version} + + + + tk.mybatis + mapper-spring-boot-starter + ${tk-mybatis-starter.version} + + + + + + + + sonatype-nexus-central + sonatype maven centrals + https://oss.sonatype.org/content/repositories/releases/ + + true + always + + + false + daily + + + + + sonatype-nexus-release + sonatype maven releases + https://s01.oss.sonatype.org/content/repositories/releases/ + + true + always + + + false + daily + + + + + sonatype-nexus-snapshot + sonatype maven snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + false + daily + + + true + always + + + + + + + ${project.artifactId} + + + false + src/main/resources + + + src/main/java + + **/*.xml + + false + + + + + org.apache.maven.plugins + maven-source-plugin + ${source-plugin.version} + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${javadoc-plugin.version} + + true + UTF-8 + UTF-8 + UTF-8 + + + + attach-javadocs + + jar + + package + + -Xdoclint:none + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-plugin.version} + true + + sonatype-nexus-central + https://s01.oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-release-plugin + ${release-plugin.version} + + v@{project.version} + true + true + sonatype-nexus-release + deploy + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + utf-8 + + + + + + diff --git a/file-toolkit-service-starter/sql/file-toolkit-postgres@1.0.2.sql b/file-toolkit-gauss-starter/sql/file-toolkit-gauss@1.0.2.sql similarity index 100% rename from file-toolkit-service-starter/sql/file-toolkit-postgres@1.0.2.sql rename to file-toolkit-gauss-starter/sql/file-toolkit-gauss@1.0.2.sql diff --git a/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/configure/FileGaussAutoConfigure.java b/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/configure/FileGaussAutoConfigure.java new file mode 100644 index 0000000..10c19ca --- /dev/null +++ b/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/configure/FileGaussAutoConfigure.java @@ -0,0 +1,22 @@ +package io.github.nichetoolkit.file.configure; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import tk.mybatis.spring.annotation.MapperScan; + +/** + *

FileServiceAutoConfigure

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +@Slf4j +@Configuration +@ComponentScan(basePackages = {"io.github.nichetoolkit.file"}) +@MapperScan(basePackages = {"io.github.nichetoolkit.file.mapper"}) +public class FileGaussAutoConfigure { + + public FileGaussAutoConfigure() { + log.debug("================= file-gauss-auto-config initiated ! ==================="); + } +} diff --git a/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml b/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml new file mode 100644 index 0000000..4973bbc --- /dev/null +++ b/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml @@ -0,0 +1,238 @@ + + + + + + + + + + + + + + + + + + + + id, file_index_id, chunk_index, chunk_size, chunk_start, chunk_end, chunk_md5, is_last_chunk, chunk_time, + start_time, end_time, operate + + + + c.id, c.file_index_id, c.chunk_index, c.chunk_size, c.chunk_start, c.chunk_end, c.chunk_md5, c.is_last_chunk, + c.chunk_time, c.start_time, c.end_time, c.operate + + + + INSERT INTO file_chunk ( + + ) + VALUES ( + #{entity.id}, + #{entity.fileId}, + #{entity.chunkIndex}, + #{entity.chunkSize}, + #{entity.chunkStart}, + #{entity.chunkEnd}, + #{entity.chunkMd5}, + #{entity.isLastChunk}, + now(), + #{entity.startTime}, + #{entity.endTime}, + CASE WHEN #{entity.operate}::INT4 IS NULL THEN 1 ELSE #{entity.operate} END + ) ON DUPLICATE KEY UPDATE + file_index_id = CASE WHEN EXCLUDED.file_index_id IS NOT NULL THEN EXCLUDED.file_index_id ELSE + file_chunk.file_index_id END, + chunk_index = CASE WHEN EXCLUDED.chunk_index IS NOT NULL THEN EXCLUDED.chunk_index ELSE + file_chunk.chunk_index END, + chunk_size = CASE WHEN EXCLUDED.chunk_size IS NOT NULL THEN EXCLUDED.chunk_size ELSE file_chunk.chunk_size + END, + chunk_start = CASE WHEN EXCLUDED.chunk_start IS NOT NULL THEN EXCLUDED.chunk_start ELSE + file_chunk.chunk_start END, + chunk_end = CASE WHEN EXCLUDED.chunk_end IS NOT NULL THEN EXCLUDED.chunk_end ELSE file_chunk.chunk_end END, + chunk_md5 = CASE WHEN EXCLUDED.chunk_md5 IS NOT NULL THEN EXCLUDED.chunk_md5 ELSE file_chunk.chunk_md5 END, + is_last_chunk = CASE WHEN EXCLUDED.is_last_chunk IS NOT NULL THEN EXCLUDED.is_last_chunk ELSE + file_chunk.is_last_chunk END, + chunk_time = now(), + start_time = CASE WHEN EXCLUDED.start_time IS NOT NULL THEN EXCLUDED.start_time ELSE file_chunk.start_time + END, + end_time = CASE WHEN EXCLUDED.end_time IS NOT NULL THEN EXCLUDED.end_time ELSE file_chunk.end_time END + + + + INSERT INTO file_chunk ( + + ) + VALUES + + ( + #{entity.id}, + #{entity.fileId}, + #{entity.chunkIndex}, + #{entity.chunkSize}, + #{entity.chunkStart}, + #{entity.chunkEnd}, + #{entity.chunkMd5}, + #{entity.isLastChunk}, + now(), + #{entity.startTime}, + #{entity.endTime}, + CASE WHEN #{entity.operate}::INT4 IS NULL THEN 1 ELSE #{entity.operate} END + ) + + ON DUPLICATE KEY UPDATE + file_index_id = CASE WHEN EXCLUDED.file_index_id IS NOT NULL THEN EXCLUDED.file_index_id ELSE + file_chunk.file_index_id END, + chunk_index = CASE WHEN EXCLUDED.chunk_index IS NOT NULL THEN EXCLUDED.chunk_index ELSE + file_chunk.chunk_index END, + chunk_size = CASE WHEN EXCLUDED.chunk_size IS NOT NULL THEN EXCLUDED.chunk_size ELSE file_chunk.chunk_size + END, + chunk_start = CASE WHEN EXCLUDED.chunk_start IS NOT NULL THEN EXCLUDED.chunk_start ELSE + file_chunk.chunk_start END, + chunk_end = CASE WHEN EXCLUDED.chunk_end IS NOT NULL THEN EXCLUDED.chunk_end ELSE file_chunk.chunk_end END, + chunk_md5 = CASE WHEN EXCLUDED.chunk_md5 IS NOT NULL THEN EXCLUDED.chunk_md5 ELSE file_chunk.chunk_md5 END, + is_last_chunk = CASE WHEN EXCLUDED.is_last_chunk IS NOT NULL THEN EXCLUDED.is_last_chunk ELSE + file_chunk.is_last_chunk END, + chunk_time = now(), + start_time = CASE WHEN EXCLUDED.start_time IS NOT NULL THEN EXCLUDED.start_time ELSE file_chunk.start_time + END, + end_time = CASE WHEN EXCLUDED.end_time IS NOT NULL THEN EXCLUDED.end_time ELSE file_chunk.end_time END + + + + UPDATE file_chunk + SET operate = ${operate} + WHERE id IN + + #{id} + + + + + UPDATE file_chunk + SET operate = ${operate} + WHERE id = #{id} + + + + UPDATE file_chunk + SET operate = 32 + WHERE id IN + + #{id} + + + + + UPDATE file_chunk + SET operate = 32 + WHERE id = #{id} + + + + DELETE FROM file_chunk + WHERE id IN + + #{id} + + + + + DELETE FROM file_chunk + WHERE id = #{id} + + + + + + + + + + DELETE FROM file_chunk + WHERE 1=1 + + ${whereSql} + + + + + + + + + + + + + diff --git a/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml b/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml new file mode 100644 index 0000000..d495ff2 --- /dev/null +++ b/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml @@ -0,0 +1,242 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id, user_id, original_filename, filename, alias, suffix, file_md5, + file_size, file_type, is_finish, is_condense, is_slice, slice_size, is_merge, etag, version_id, headers, + properties, create_time, update_time, operate + + + + INSERT INTO file_index ( + + ) + VALUES ( + #{entity.id}, + #{entity.userId}, + #{entity.originalFilename}, + #{entity.filename}, + #{entity.alias}, + #{entity.suffix}, + #{entity.fileMd5}, + #{entity.fileSize}, + #{entity.fileType}, + #{entity.isFinish}, + #{entity.isCondense}, + #{entity.isSlice}, + #{entity.sliceSize}, + #{entity.isMerge}, + #{entity.etag}, + #{entity.versionId}, + #{entity.headers}, + #{entity.properties}, + now(), + now(), + CASE WHEN #{entity.operate}::INT4 IS NULL THEN 1 ELSE #{entity.operate} END + ) ON DUPLICATE KEY UPDATE + user_id = CASE WHEN EXCLUDED.user_id IS NOT NULL THEN EXCLUDED.user_id ELSE file_index.user_id END, + original_filename = CASE WHEN EXCLUDED.original_filename IS NOT NULL THEN EXCLUDED.original_filename ELSE + file_index.original_filename END, + filename = CASE WHEN EXCLUDED.filename IS NOT NULL THEN EXCLUDED.filename ELSE file_index.filename END, + alias = CASE WHEN EXCLUDED.alias IS NOT NULL THEN EXCLUDED.alias ELSE file_index.alias END, + suffix = CASE WHEN EXCLUDED.suffix IS NOT NULL THEN EXCLUDED.suffix ELSE file_index.suffix END, + file_md5 = CASE WHEN EXCLUDED.file_md5 IS NOT NULL THEN EXCLUDED.file_md5 ELSE file_index.file_md5 END, + file_size = CASE WHEN EXCLUDED.file_size IS NOT NULL THEN EXCLUDED.file_size ELSE file_index.file_size END, + file_type = CASE WHEN EXCLUDED.file_type IS NOT NULL THEN EXCLUDED.file_type ELSE file_index.file_type END, + is_finish = CASE WHEN EXCLUDED.is_finish IS NOT NULL THEN EXCLUDED.is_finish ELSE file_index.is_finish END, + is_condense = CASE WHEN EXCLUDED.is_condense IS NOT NULL THEN EXCLUDED.is_condense ELSE + file_index.is_condense END, + is_slice = CASE WHEN EXCLUDED.is_slice IS NOT NULL THEN EXCLUDED.is_slice ELSE file_index.is_slice END, + slice_size = CASE WHEN EXCLUDED.slice_size IS NOT NULL THEN EXCLUDED.slice_size ELSE file_index.slice_size + END, + is_merge = CASE WHEN EXCLUDED.is_merge IS NOT NULL THEN EXCLUDED.is_merge ELSE file_index.is_merge END, + etag = CASE WHEN EXCLUDED.etag IS NOT NULL THEN EXCLUDED.etag ELSE file_index.etag END, + version_id = CASE WHEN EXCLUDED.version_id IS NOT NULL THEN EXCLUDED.version_id ELSE file_index.version_id + END, + headers = CASE WHEN EXCLUDED.headers IS NOT NULL THEN EXCLUDED.headers ELSE file_index.headers END, + properties = CASE WHEN EXCLUDED.properties IS NOT NULL THEN EXCLUDED.properties ELSE file_index.properties + END, + update_time = now() + + + + INSERT INTO file_index ( + + ) + VALUES + + ( + #{entity.id}, + #{entity.userId}, + #{entity.originalFilename}, + #{entity.filename}, + #{entity.alias}, + #{entity.suffix}, + #{entity.fileMd5}, + #{entity.fileSize}, + #{entity.fileType}, + #{entity.isFinish}, + #{entity.isCondense}, + #{entity.isSlice}, + #{entity.sliceSize}, + #{entity.isMerge}, + #{entity.etag}, + #{entity.versionId}, + #{entity.headers}, + #{entity.properties}, + now(), + now(), + CASE WHEN #{entity.operate}::INT4 IS NULL THEN 1 ELSE #{entity.operate} END + ) + + ON DUPLICATE KEY UPDATE + user_id = CASE WHEN EXCLUDED.user_id IS NOT NULL THEN EXCLUDED.user_id ELSE file_index.user_id END, + original_filename = CASE WHEN EXCLUDED.original_filename IS NOT NULL THEN EXCLUDED.original_filename ELSE + file_index.original_filename END, + filename = CASE WHEN EXCLUDED.filename IS NOT NULL THEN EXCLUDED.filename ELSE file_index.filename END, + alias = CASE WHEN EXCLUDED.alias IS NOT NULL THEN EXCLUDED.alias ELSE file_index.alias END, + suffix = CASE WHEN EXCLUDED.suffix IS NOT NULL THEN EXCLUDED.suffix ELSE file_index.suffix END, + file_md5 = CASE WHEN EXCLUDED.file_md5 IS NOT NULL THEN EXCLUDED.file_md5 ELSE file_index.file_md5 END, + file_size = CASE WHEN EXCLUDED.file_size IS NOT NULL THEN EXCLUDED.file_size ELSE file_index.file_size END, + file_type = CASE WHEN EXCLUDED.file_type IS NOT NULL THEN EXCLUDED.file_type ELSE file_index.file_type END, + is_finish = CASE WHEN EXCLUDED.is_finish IS NOT NULL THEN EXCLUDED.is_finish ELSE file_index.is_finish END, + is_condense = CASE WHEN EXCLUDED.is_condense IS NOT NULL THEN EXCLUDED.is_condense ELSE + file_index.is_condense END, + is_slice = CASE WHEN EXCLUDED.is_slice IS NOT NULL THEN EXCLUDED.is_slice ELSE file_index.is_slice END, + slice_size = CASE WHEN EXCLUDED.slice_size IS NOT NULL THEN EXCLUDED.slice_size ELSE file_index.slice_size + END, + is_merge = CASE WHEN EXCLUDED.is_merge IS NOT NULL THEN EXCLUDED.is_merge ELSE file_index.is_merge END, + etag = CASE WHEN EXCLUDED.etag IS NOT NULL THEN EXCLUDED.etag ELSE file_index.etag END, + version_id = CASE WHEN EXCLUDED.version_id IS NOT NULL THEN EXCLUDED.version_id ELSE file_index.version_id + END, + headers = CASE WHEN EXCLUDED.headers IS NOT NULL THEN EXCLUDED.headers ELSE file_index.headers END, + properties = CASE WHEN EXCLUDED.properties IS NOT NULL THEN EXCLUDED.properties ELSE file_index.properties + END, + update_time = now() + + + + UPDATE file_index + SET operate = ${operate} + WHERE id IN + + #{id} + + + + + UPDATE file_index + SET operate = ${operate} + WHERE id = #{id} + + + + UPDATE file_index + SET operate = 32 + WHERE id IN + + #{id} + + + + + UPDATE file_index + SET operate = 32 + WHERE id = #{id} + + + + DELETE FROM file_index + WHERE id IN + + #{id} + + + + + DELETE + FROM file_index + WHERE id = #{id} + + + + + + + + + + DELETE FROM file_index + WHERE 1=1 + + ${whereSql} + + + + + + + UPDATE file_index + SET is_finish = true, + slice_size = ${sliceSize} + WHERE id = ${id} + AND operate NOT IN (16,32) + AND is_slice = true + + + diff --git a/file-toolkit-gauss-starter/src/main/resources/META-INF/spring.factories b/file-toolkit-gauss-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..e0a2f16 --- /dev/null +++ b/file-toolkit-gauss-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=io.github.nichetoolkit.file.configure.FileGaussAutoConfigure \ No newline at end of file diff --git a/file-toolkit-hdfs-starter/pom.xml b/file-toolkit-hdfs-starter/pom.xml index 29eacb6..d0b8208 100644 --- a/file-toolkit-hdfs-starter/pom.xml +++ b/file-toolkit-hdfs-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4 file-toolkit-hdfs-starter - 1.0.3 + 1.0.4 file-toolkit-hdfs-starter jar File toolkit hdfs project for Spring Boot @@ -56,7 +56,7 @@ io.github.nichetoolkit - file-toolkit-service-starter + file-toolkit-postgres-starter ${file-toolkit.version} diff --git a/file-toolkit-minio-starter/pom.xml b/file-toolkit-minio-starter/pom.xml index ce6cf52..6e8e682 100644 --- a/file-toolkit-minio-starter/pom.xml +++ b/file-toolkit-minio-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4 file-toolkit-minio-starter - 1.0.3 + 1.0.4 file-toolkit-minio-starter jar File toolkit minio project for Spring Boot @@ -62,7 +62,7 @@ io.github.nichetoolkit - file-toolkit-service-starter + file-toolkit-common-starter ${file-toolkit.version} diff --git a/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/configure/FileMinioStarterAutoConfigure.java b/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/configure/FileMinioStarterAutoConfigure.java index 6dd848b..37f0a17 100644 --- a/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/configure/FileMinioStarterAutoConfigure.java +++ b/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/configure/FileMinioStarterAutoConfigure.java @@ -7,7 +7,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import tk.mybatis.spring.annotation.MapperScan; /** *

FileMinioStarterAutoConfigure

@@ -16,8 +15,6 @@ */ @Slf4j @Configuration -@org.mybatis.spring.annotation.MapperScan("io.github.nichetoolkit.file.mapper") -@MapperScan("io.github.nichetoolkit.file.mapper") @ComponentScan(basePackages = {"io.github.nichetoolkit.file"}) public class FileMinioStarterAutoConfigure { public FileMinioStarterAutoConfigure() { diff --git a/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/impl/MinioFileService.java b/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/MinioFileService.java similarity index 88% rename from file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/impl/MinioFileService.java rename to file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/MinioFileService.java index ed31971..6aec1a0 100644 --- a/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/impl/MinioFileService.java +++ b/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/MinioFileService.java @@ -1,7 +1,7 @@ -package io.github.nichetoolkit.file.service.impl; +package io.github.nichetoolkit.file.service; +import io.github.nichetoolkit.file.handle.FileStoreService; import io.github.nichetoolkit.file.minio.MinioUtils; -import io.github.nichetoolkit.file.service.AsyncFileService; import io.github.nichetoolkit.rest.RestException; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -16,7 +16,7 @@ * @version v1.0.0 */ @Service -public class MinioFileService extends AsyncFileService { +public class MinioFileService extends FileStoreService { @Override @Async public void removeAll(List fileIdList) throws RestException { diff --git a/file-toolkit-minio-utils/pom.xml b/file-toolkit-minio-utils/pom.xml index 087a148..57a016a 100644 --- a/file-toolkit-minio-utils/pom.xml +++ b/file-toolkit-minio-utils/pom.xml @@ -5,10 +5,10 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4 file-toolkit-minio-utils - 1.0.3 + 1.0.4 file-toolkit-minio-utils jar File toolkit minio utils project for Spring Boot @@ -77,12 +77,6 @@ ${minio.version} - - com.squareup.okhttp3 - okhttp - ${minio-okhttp3.version} - - diff --git a/file-toolkit-postgres-starter/pom.xml b/file-toolkit-postgres-starter/pom.xml new file mode 100644 index 0000000..a35e628 --- /dev/null +++ b/file-toolkit-postgres-starter/pom.xml @@ -0,0 +1,224 @@ + + + 4.0.0 + + io.github.nichetoolkit + file-toolkit-parent + 1.0.4 + + + file-toolkit-postgres-starter + 1.0.4 + file-toolkit-postgres-starter + jar + File toolkit postgres project for Spring Boot + https://github.com/NicheToolkit/file-toolkit/tree/master/file-toolkit-postgres-starter + + + 1.8 + UTF-8 + UTF-8 + + + + + The Apache License (Apache-2.0) + https://github.com/NicheToolkit/file-toolkit/blob/master/LICENSE + + + + + + Cyan + snow22314@outlook.com + + + + + scm:git:git@github.com:NicheToolkit/file-toolkit.git + scm:git:git@github.com:NicheToolkit/file-toolkit.git + git@github.com:NicheToolkit/file-toolkit.git + + + + + sonatype-nexus-snapshot + https://s01.oss.sonatype.org/content/repositories/snapshots + + + sonatype-nexus-deploy + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + + io.github.nichetoolkit + file-toolkit-service-starter + ${file-toolkit.version} + + + + tk.mybatis + mapper + ${tk-mybatis-mapper.version} + + + + tk.mybatis + mapper-spring-boot-starter + ${tk-mybatis-starter.version} + + + + + + + + sonatype-nexus-central + sonatype maven centrals + https://oss.sonatype.org/content/repositories/releases/ + + true + always + + + false + daily + + + + + sonatype-nexus-release + sonatype maven releases + https://s01.oss.sonatype.org/content/repositories/releases/ + + true + always + + + false + daily + + + + + sonatype-nexus-snapshot + sonatype maven snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + false + daily + + + true + always + + + + + + + ${project.artifactId} + + + false + src/main/resources + + + src/main/java + + **/*.xml + + false + + + + + org.apache.maven.plugins + maven-source-plugin + ${source-plugin.version} + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${javadoc-plugin.version} + + true + UTF-8 + UTF-8 + UTF-8 + + + + attach-javadocs + + jar + + package + + -Xdoclint:none + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-plugin.version} + true + + sonatype-nexus-central + https://s01.oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-release-plugin + ${release-plugin.version} + + v@{project.version} + true + true + sonatype-nexus-release + deploy + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + utf-8 + + + + + + diff --git a/file-toolkit-postgres-starter/sql/file-toolkit-postgres@1.0.2.sql b/file-toolkit-postgres-starter/sql/file-toolkit-postgres@1.0.2.sql new file mode 100644 index 0000000..6f03a56 --- /dev/null +++ b/file-toolkit-postgres-starter/sql/file-toolkit-postgres@1.0.2.sql @@ -0,0 +1,135 @@ +-- ---------------------------- +-- Table structure for file +-- ---------------------------- +DROP TABLE IF EXISTS "public"."file_index"; +CREATE TABLE "public"."file_index" +( + "id" VARCHAR(64) COLLATE "pg_catalog"."default" NOT NULL, + "user_id" VARCHAR(64) COLLATE "pg_catalog"."default", + "original_filename" VARCHAR(512) COLLATE "pg_catalog"."default", + "filename" VARCHAR(256) COLLATE "pg_catalog"."default", + "alias" VARCHAR(256) COLLATE "pg_catalog"."default", + "suffix" VARCHAR(32) COLLATE "pg_catalog"."default", + "file_md5" VARCHAR(2048) COLLATE "pg_catalog"."default", + "file_size" INT8, + "file_type" INT2, + "is_finish" BOOLEAN DEFAULT TRUE, + "is_condense" BOOLEAN DEFAULT FALSE, + "is_slice" BOOLEAN DEFAULT FALSE, + "slice_size" INT4, + "is_merge" BOOLEAN DEFAULT TRUE, + "etag" VARCHAR(512) COLLATE "pg_catalog"."default", + "version_id" VARCHAR(512) COLLATE "pg_catalog"."default", + "headers" jsonb, + "properties" jsonb, + "update_time" TIMESTAMPTZ, + "create_time" TIMESTAMPTZ, + "operate" INT4 +); +COMMENT ON COLUMN "public"."file_index"."id" IS '文件id'; +COMMENT ON COLUMN "public"."file_index"."user_id" IS '文件存储用户id'; +COMMENT ON COLUMN "public"."file_index"."original_filename" IS '文件源名称'; +COMMENT ON COLUMN "public"."file_index"."filename" IS '文件名称'; +COMMENT ON COLUMN "public"."file_index"."alias" IS '文件别名'; +COMMENT ON COLUMN "public"."file_index"."suffix" IS '文件扩展名'; +COMMENT ON COLUMN "public"."file_index"."file_md5" IS '文件md5校验'; +COMMENT ON COLUMN "public"."file_index"."file_size" IS '文件大小'; +COMMENT ON COLUMN "public"."file_index"."file_type" IS '文件类型'; +COMMENT ON COLUMN "public"."file_index"."is_finish" IS '文件分片上传完成状态'; +COMMENT ON COLUMN "public"."file_index"."is_condense" IS '文件压缩状态,暂时只对图片生效'; +COMMENT ON COLUMN "public"."file_index"."is_slice" IS '文件分片状态'; +COMMENT ON COLUMN "public"."file_index"."slice_size" IS '文件分片总数'; +COMMENT ON COLUMN "public"."file_index"."is_merge" IS '文件分片是否合并'; +COMMENT ON COLUMN "public"."file_index"."etag" IS '文件minio存储hash校验'; +COMMENT ON COLUMN "public"."file_index"."version_id" IS '文件minio存储版本'; +COMMENT ON COLUMN "public"."file_index"."headers" IS '文件minio存储请求头'; +COMMENT ON COLUMN "public"."file_index"."properties" IS '文件附属属性'; +COMMENT ON COLUMN "public"."file_index"."update_time" IS '文件更新时间'; +COMMENT ON COLUMN "public"."file_index"."create_time" IS '文件创建时间'; +COMMENT ON COLUMN "public"."file_index"."operate" IS '文件操作'; + +-- ---------------------------- +-- Primary Key structure for table file +-- ---------------------------- +ALTER TABLE "public"."file_index" + ADD CONSTRAINT "PK_FILE_INDEX_ID" PRIMARY KEY ("id"); + +CREATE INDEX "IDX_FILE_INDEX_USER_ID" ON "public"."file_index" USING btree ( + "user_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_FILENAME" ON "public"."file_index" USING btree ( + "filename" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_FILE_TYPE" ON "public"."file_index" USING btree ( + "file_type" "pg_catalog"."int2_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_FINISH" ON "public"."file_index" USING btree ( + "is_finish" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_CONDENSE" ON "public"."file_index" USING btree ( + "is_condense" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_SLICE" ON "public"."file_index" USING btree ( + "is_slice" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_MERGE" ON "public"."file_index" USING btree ( + "is_merge" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_OPERATE" ON "public"."file_index" USING btree ( + "operate" "pg_catalog"."int4_ops" ASC NULLS LAST +); + +DROP TABLE IF EXISTS "public"."file_chunk"; +CREATE TABLE "public"."file_chunk" +( + "id" VARCHAR(64) COLLATE "pg_catalog"."default" NOT NULL, + "file_index_id" VARCHAR(64) COLLATE "pg_catalog"."default" NOT NULL, + "chunk_index" INT4 NOT NULL, + "chunk_size" INT8, + "chunk_start" INT8, + "chunk_end" INT8, + "chunk_md5" VARCHAR(1024) COLLATE "pg_catalog"."default", + "is_last_chunk" BOOLEAN DEFAULT FALSE, + "chunk_time" TIMESTAMPTZ, + "start_time" TIMESTAMPTZ, + "end_time" TIMESTAMPTZ, + "operate" INT4 +); + +COMMENT ON COLUMN "public"."file_chunk"."id" IS '文件分片id'; +COMMENT ON COLUMN "public"."file_chunk"."file_index_id" IS '文件id'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_index" IS '分片编号'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_size" IS '分片长度'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_start" IS '分片起始位置'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_end" IS '分片结束位置'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_md5" IS '分片md5校验'; +COMMENT ON COLUMN "public"."file_chunk"."is_last_chunk" IS '是否最后一片数据 1:否,2:是'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_time" IS '分片上传时间'; +COMMENT ON COLUMN "public"."file_chunk"."start_time" IS '第一片上传时间'; +COMMENT ON COLUMN "public"."file_chunk"."end_time" IS '最后一片上传时间'; +COMMENT ON COLUMN "public"."file_chunk"."operate" IS '文件操作'; + +ALTER TABLE "public"."file_chunk" + ADD CONSTRAINT "PK_FILE_CHUNK_ID" PRIMARY KEY ("id"); + +ALTER TABLE "public"."file_chunk" + ADD CONSTRAINT "UK_FILE_CHUNK_FILE_INDEX_ID_CHUNK_INDEX" UNIQUE ("file_index_id", "chunk_index"); + +CREATE INDEX "IDX_FILE_CHUNK_FILE_INDEX_ID" ON "public"."file_chunk" USING btree ( + "file_index_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_CHUNK_CHUNK_INDEX" ON "public"."file_chunk" USING btree ( + "chunk_index" "pg_catalog"."int4_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_CHUNK_OPERATE" ON "public"."file_chunk" USING btree ( + "operate" "pg_catalog"."int4_ops" ASC NULLS LAST +); \ No newline at end of file diff --git a/file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/configure/FilePostgresAutoConfigure.java b/file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/configure/FilePostgresAutoConfigure.java new file mode 100644 index 0000000..c37e0b1 --- /dev/null +++ b/file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/configure/FilePostgresAutoConfigure.java @@ -0,0 +1,22 @@ +package io.github.nichetoolkit.file.configure; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import tk.mybatis.spring.annotation.MapperScan; + +/** + *

FilePostgresAutoConfigure

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +@Slf4j +@Configuration +@ComponentScan(basePackages = {"io.github.nichetoolkit.file"}) +@MapperScan(basePackages = {"io.github.nichetoolkit.file.mapper"}) +public class FilePostgresAutoConfigure { + + public FilePostgresAutoConfigure() { + log.debug("================= file-postgres-auto-config initiated ! ==================="); + } +} diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml b/file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml similarity index 100% rename from file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml rename to file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml b/file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml similarity index 100% rename from file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml rename to file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml diff --git a/file-toolkit-postgres-starter/src/main/resources/META-INF/spring.factories b/file-toolkit-postgres-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..88fc3b0 --- /dev/null +++ b/file-toolkit-postgres-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=io.github.nichetoolkit.file.configure.FilePostgresAutoConfigure \ No newline at end of file diff --git a/file-toolkit-service-starter/pom.xml b/file-toolkit-service-starter/pom.xml index d18bb5d..3777a34 100644 --- a/file-toolkit-service-starter/pom.xml +++ b/file-toolkit-service-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4 file-toolkit-service-starter - 1.0.3 + 1.0.4 file-toolkit-service-starter jar File toolkit service project for Spring Boot @@ -84,12 +84,6 @@ ${tk-mybatis-mapper.version} - - tk.mybatis - mapper-spring-boot-starter - ${tk-mybatis-starter.version} - - diff --git a/file-toolkit-service-starter/sql/file-toolkit@1.0.2.sql b/file-toolkit-service-starter/sql/file-toolkit@1.0.2.sql new file mode 100644 index 0000000..6f03a56 --- /dev/null +++ b/file-toolkit-service-starter/sql/file-toolkit@1.0.2.sql @@ -0,0 +1,135 @@ +-- ---------------------------- +-- Table structure for file +-- ---------------------------- +DROP TABLE IF EXISTS "public"."file_index"; +CREATE TABLE "public"."file_index" +( + "id" VARCHAR(64) COLLATE "pg_catalog"."default" NOT NULL, + "user_id" VARCHAR(64) COLLATE "pg_catalog"."default", + "original_filename" VARCHAR(512) COLLATE "pg_catalog"."default", + "filename" VARCHAR(256) COLLATE "pg_catalog"."default", + "alias" VARCHAR(256) COLLATE "pg_catalog"."default", + "suffix" VARCHAR(32) COLLATE "pg_catalog"."default", + "file_md5" VARCHAR(2048) COLLATE "pg_catalog"."default", + "file_size" INT8, + "file_type" INT2, + "is_finish" BOOLEAN DEFAULT TRUE, + "is_condense" BOOLEAN DEFAULT FALSE, + "is_slice" BOOLEAN DEFAULT FALSE, + "slice_size" INT4, + "is_merge" BOOLEAN DEFAULT TRUE, + "etag" VARCHAR(512) COLLATE "pg_catalog"."default", + "version_id" VARCHAR(512) COLLATE "pg_catalog"."default", + "headers" jsonb, + "properties" jsonb, + "update_time" TIMESTAMPTZ, + "create_time" TIMESTAMPTZ, + "operate" INT4 +); +COMMENT ON COLUMN "public"."file_index"."id" IS '文件id'; +COMMENT ON COLUMN "public"."file_index"."user_id" IS '文件存储用户id'; +COMMENT ON COLUMN "public"."file_index"."original_filename" IS '文件源名称'; +COMMENT ON COLUMN "public"."file_index"."filename" IS '文件名称'; +COMMENT ON COLUMN "public"."file_index"."alias" IS '文件别名'; +COMMENT ON COLUMN "public"."file_index"."suffix" IS '文件扩展名'; +COMMENT ON COLUMN "public"."file_index"."file_md5" IS '文件md5校验'; +COMMENT ON COLUMN "public"."file_index"."file_size" IS '文件大小'; +COMMENT ON COLUMN "public"."file_index"."file_type" IS '文件类型'; +COMMENT ON COLUMN "public"."file_index"."is_finish" IS '文件分片上传完成状态'; +COMMENT ON COLUMN "public"."file_index"."is_condense" IS '文件压缩状态,暂时只对图片生效'; +COMMENT ON COLUMN "public"."file_index"."is_slice" IS '文件分片状态'; +COMMENT ON COLUMN "public"."file_index"."slice_size" IS '文件分片总数'; +COMMENT ON COLUMN "public"."file_index"."is_merge" IS '文件分片是否合并'; +COMMENT ON COLUMN "public"."file_index"."etag" IS '文件minio存储hash校验'; +COMMENT ON COLUMN "public"."file_index"."version_id" IS '文件minio存储版本'; +COMMENT ON COLUMN "public"."file_index"."headers" IS '文件minio存储请求头'; +COMMENT ON COLUMN "public"."file_index"."properties" IS '文件附属属性'; +COMMENT ON COLUMN "public"."file_index"."update_time" IS '文件更新时间'; +COMMENT ON COLUMN "public"."file_index"."create_time" IS '文件创建时间'; +COMMENT ON COLUMN "public"."file_index"."operate" IS '文件操作'; + +-- ---------------------------- +-- Primary Key structure for table file +-- ---------------------------- +ALTER TABLE "public"."file_index" + ADD CONSTRAINT "PK_FILE_INDEX_ID" PRIMARY KEY ("id"); + +CREATE INDEX "IDX_FILE_INDEX_USER_ID" ON "public"."file_index" USING btree ( + "user_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_FILENAME" ON "public"."file_index" USING btree ( + "filename" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_FILE_TYPE" ON "public"."file_index" USING btree ( + "file_type" "pg_catalog"."int2_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_FINISH" ON "public"."file_index" USING btree ( + "is_finish" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_CONDENSE" ON "public"."file_index" USING btree ( + "is_condense" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_SLICE" ON "public"."file_index" USING btree ( + "is_slice" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_MERGE" ON "public"."file_index" USING btree ( + "is_merge" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_OPERATE" ON "public"."file_index" USING btree ( + "operate" "pg_catalog"."int4_ops" ASC NULLS LAST +); + +DROP TABLE IF EXISTS "public"."file_chunk"; +CREATE TABLE "public"."file_chunk" +( + "id" VARCHAR(64) COLLATE "pg_catalog"."default" NOT NULL, + "file_index_id" VARCHAR(64) COLLATE "pg_catalog"."default" NOT NULL, + "chunk_index" INT4 NOT NULL, + "chunk_size" INT8, + "chunk_start" INT8, + "chunk_end" INT8, + "chunk_md5" VARCHAR(1024) COLLATE "pg_catalog"."default", + "is_last_chunk" BOOLEAN DEFAULT FALSE, + "chunk_time" TIMESTAMPTZ, + "start_time" TIMESTAMPTZ, + "end_time" TIMESTAMPTZ, + "operate" INT4 +); + +COMMENT ON COLUMN "public"."file_chunk"."id" IS '文件分片id'; +COMMENT ON COLUMN "public"."file_chunk"."file_index_id" IS '文件id'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_index" IS '分片编号'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_size" IS '分片长度'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_start" IS '分片起始位置'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_end" IS '分片结束位置'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_md5" IS '分片md5校验'; +COMMENT ON COLUMN "public"."file_chunk"."is_last_chunk" IS '是否最后一片数据 1:否,2:是'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_time" IS '分片上传时间'; +COMMENT ON COLUMN "public"."file_chunk"."start_time" IS '第一片上传时间'; +COMMENT ON COLUMN "public"."file_chunk"."end_time" IS '最后一片上传时间'; +COMMENT ON COLUMN "public"."file_chunk"."operate" IS '文件操作'; + +ALTER TABLE "public"."file_chunk" + ADD CONSTRAINT "PK_FILE_CHUNK_ID" PRIMARY KEY ("id"); + +ALTER TABLE "public"."file_chunk" + ADD CONSTRAINT "UK_FILE_CHUNK_FILE_INDEX_ID_CHUNK_INDEX" UNIQUE ("file_index_id", "chunk_index"); + +CREATE INDEX "IDX_FILE_CHUNK_FILE_INDEX_ID" ON "public"."file_chunk" USING btree ( + "file_index_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_CHUNK_CHUNK_INDEX" ON "public"."file_chunk" USING btree ( + "chunk_index" "pg_catalog"."int4_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_CHUNK_OPERATE" ON "public"."file_chunk" USING btree ( + "operate" "pg_catalog"."int4_ops" ASC NULLS LAST +); \ No newline at end of file diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/configure/FileServiceAsyncConfigure.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/configure/FileServiceAsyncConfigure.java index 0af1cde..c091d52 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/configure/FileServiceAsyncConfigure.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/configure/FileServiceAsyncConfigure.java @@ -1,5 +1,6 @@ package io.github.nichetoolkit.file.configure; +import io.github.nichetoolkit.rest.logback.RestThreadPoolTaskExecutor; import lombok.extern.slf4j.Slf4j; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.scheduling.annotation.AsyncConfigurer; @@ -29,7 +30,7 @@ public class FileServiceAsyncConfigure implements AsyncConfigurer { */ @Override public Executor getAsyncExecutor() { - ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + RestThreadPoolTaskExecutor executor = new RestThreadPoolTaskExecutor(); executor.setDaemon(true); executor.setCorePoolSize(10); executor.setMaxPoolSize(100); diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileHandleHelper.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileHandleHelper.java new file mode 100644 index 0000000..22df1f5 --- /dev/null +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileHandleHelper.java @@ -0,0 +1,51 @@ +package io.github.nichetoolkit.file.helper; + +import io.github.nichetoolkit.file.error.FileErrorStatus; +import io.github.nichetoolkit.file.handle.FileStoreService; +import io.github.nichetoolkit.rest.RestException; +import io.github.nichetoolkit.rest.error.natives.FileErrorException; +import io.github.nichetoolkit.rest.util.StreamUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.io.IOException; +import java.io.InputStream; + +/** + *

FileHandleHelper

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +@Slf4j +@Component +public class FileHandleHelper implements InitializingBean { + + @Resource(type = FileStoreService.class) + private FileStoreService fileStoreService; + + private static FileHandleHelper INSTANCE = null; + + public static FileHandleHelper getInstance() { + return INSTANCE; + } + + @Override + public void afterPropertiesSet() throws Exception { + INSTANCE = this; + } + + public static FileStoreService fileStoreService() { + return INSTANCE.fileStoreService; + } + + public static void writeFile(String objectName, String itemFilePath) throws RestException { + try (InputStream inputStream = INSTANCE.fileStoreService.getById(objectName)) { + StreamUtils.write(itemFilePath, inputStream); + } catch (IOException exception) { + log.error("the file service download has error: {}", exception.getMessage()); + throw new FileErrorException(FileErrorStatus.SERVICE_DOWNLOAD_ERROR); + } + } +} diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java index 00fa310..b34209f 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java @@ -5,23 +5,20 @@ import io.github.nichetoolkit.file.entity.FileIndexEntity; import io.github.nichetoolkit.file.enums.FileType; import io.github.nichetoolkit.file.error.FileErrorStatus; -import io.github.nichetoolkit.file.error.ImageTransferException; import io.github.nichetoolkit.file.filter.FileFilter; import io.github.nichetoolkit.file.model.FileChunk; import io.github.nichetoolkit.file.model.FileIndex; import io.github.nichetoolkit.file.model.FileRequest; -import io.github.nichetoolkit.file.service.AsyncFileService; import io.github.nichetoolkit.file.service.FileChunkService; import io.github.nichetoolkit.file.service.FileIndexService; -import io.github.nichetoolkit.file.util.ImageUtils; import io.github.nichetoolkit.file.util.Md5Utils; import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.error.natives.FileErrorException; +import io.github.nichetoolkit.rest.identity.IdentityUtils; import io.github.nichetoolkit.rest.util.*; import io.github.nichetoolkit.rice.RestPage; import io.github.nichetoolkit.rice.helper.PropertyHelper; import lombok.extern.slf4j.Slf4j; -import net.coobird.thumbnailator.Thumbnails; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -29,10 +26,6 @@ import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; -import javax.annotation.PostConstruct; -import javax.naming.NamingEnumeration; -import javax.swing.*; -import java.awt.image.BufferedImage; import java.io.*; import java.util.*; import java.util.stream.Collectors; @@ -47,7 +40,7 @@ public class FileServiceHelper implements InitializingBean { @Autowired - private FileCommonProperties serviceProperties; + private FileCommonProperties commonProperties; @Autowired private FileIndexService fileIndexService; @@ -55,8 +48,6 @@ public class FileServiceHelper implements InitializingBean { @Autowired private FileChunkService fileChunkService; - private AsyncFileService asyncFileService; - private static FileServiceHelper INSTANCE = null; public static FileServiceHelper getInstance() { @@ -68,11 +59,6 @@ public void afterPropertiesSet() throws Exception { INSTANCE = this; } - @PostConstruct - public void InitFileSupperService() { - asyncFileService = ContextUtils.getBean(AsyncFileService.class); - } - public static void checkRestPage(RestPage restPage) throws RestException { if (GeneralUtils.isEmpty(restPage) || GeneralUtils.isEmpty(restPage.getItems())) { log.warn("the file service query result is empty!"); @@ -80,93 +66,6 @@ public static void checkRestPage(RestPage restPage) throws RestException { } } - public static void condenseFile(String randomPath, FileIndex fileIndex) throws RestException { - String filename = fileIndex.getName(); - String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); - String filePath = randomPath.concat(File.separator).concat(filename); - File file = FileUtils.createFile(filePath); - StreamUtils.write(file, fileIndex.inputStream()); - File zipFile = ZipUtils.zipFile(randomPath, zipFilename, file); - buildProperties(zipFilename, zipFile.length(), FileConstants.FILE_ZIP_SUFFIX, fileIndex); - if (fileIndex.getIsMd5()) { - buildMd5(zipFile, fileIndex); - } - } - - public static void autographImage(String randomPath, FileIndex fileIndex) throws RestException { - InputStream inputStream = fileIndex.inputStream(); - BufferedImage bufferedImage = ImageUtils.read(inputStream); - BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); - BufferedImage autographImage = ImageUtils.autograph(binaryImage); - String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); - String filePath = randomPath.concat(File.separator).concat(filename); - File file = new File(filePath); - if (file.exists()) { - FileUtils.delete(filePath); - } - ImageUtils.write(autographImage, file); - byte[] bytes = ImageUtils.bytes(file); - fileIndex.setBytes(bytes); - FileUtils.delete(filePath); - } - - public static void condenseImage(String randomPath, FileIndex fileIndex) throws RestException { - Long imageFileSize; - Double imageFileQuality = 1.0d; - Double imageFileScale = 1.0d; - String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); - String filePath; - File file; - Integer width = fileIndex.getWidth(); - Integer height = fileIndex.getHeight(); - filePath = randomPath.concat(File.separator).concat(filename); - file = new File(filePath); - do { - if (file.exists()) { - FileUtils.delete(filePath); - } - try { - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - BufferedImage bufferedImage = ImageHelper.read(file); - int imageWidth = bufferedImage.getWidth(); - int imageHeight = bufferedImage.getHeight(); - if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { - Thumbnails.of(fileIndex.inputStream()).size(width, height).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - } else if (GeneralUtils.isNotEmpty(width) || GeneralUtils.isNotEmpty(height)) { - if (GeneralUtils.isNotEmpty(width)) { - imageFileScale = ((double) width / (double) imageWidth >= 1.0D) ? imageFileScale : ((double) width / (double) imageWidth); - } else { - imageFileScale = ((double) height / (double) imageHeight >= 1.0D) ? imageFileScale : ((double) height / (double) imageHeight); - } - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - } else { - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - } - } catch (IOException exception) { - log.error("the image file has error during condensing: {}", exception.getMessage()); - throw new FileErrorException(FileErrorStatus.FILE_IMAGE_CONDENSE_ERROR); - } - imageFileSize = file.length(); - if (imageFileQuality.equals(INSTANCE.serviceProperties.getMinImageQuality())) { - imageFileScale += -0.1d; - } else { - imageFileQuality += -0.1d; - } - } while (imageFileSize > INSTANCE.serviceProperties.getMaxImageSize() - && imageFileQuality > INSTANCE.serviceProperties.getMinImageQuality() - && imageFileScale > INSTANCE.serviceProperties.getMinImageScale()); - if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_WIDTH_PROPERTY, width); - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_HEIGHT_PROPERTY, height); - } else { - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_SCALE_PROPERTY, imageFileScale); - } - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_QUALITY_PROPERTY, imageFileQuality); - buildProperties(filename, file.length(), FileConstants.IMAGE_PNG_SUFFIX, fileIndex); - buildMd5(file, fileIndex); - FileUtils.clearFile(randomPath); - } - public static void buildProperties(String filename, long size, String suffix, FileIndex fileIndex) { fileIndex.addProperty(FileConstants.ORIGINAL_SUFFIX_PROPERTY, fileIndex.getSuffix()); fileIndex.setSuffix(suffix); @@ -187,7 +86,7 @@ public static void buildChunkFiles(List fileIndices, FileFilter fileF itemFilename = fileIndex.getFilename().concat("_").concat(String.valueOf(fileChunk.getChunkIndex())).concat(FileConstants.SUFFIX_REGEX).concat(fileIndex.getSuffix()); } String itemFilePath = randomPath.concat(File.separator).concat(itemFilename); - writeFile(fileChunk.getId(), itemFilePath); + FileHandleHelper.writeFile(fileChunk.getId(), itemFilePath); fileList.add(new File(itemFilePath)); } } @@ -196,7 +95,7 @@ public static void buildChunkFiles(List fileIndices, FileFilter fileF public static void buildIndexFiles(List fileIndices, FileFilter fileFilter, String randomPath, List fileList) throws RestException { for (FileIndex fileIndex : fileIndices) { - if (fileIndex.getFileSize() > INSTANCE.serviceProperties.getMaxFileSize()) { + if (fileIndex.getFileSize() > INSTANCE.commonProperties.getMaxFileSize()) { log.warn("the file size is too large, id: {}, size: {}", fileIndex.getId(), fileIndex.getFileSize()); throw new FileErrorException(FileErrorStatus.FILE_TOO_LARGE_ERROR); } @@ -205,21 +104,11 @@ public static void buildIndexFiles(List fileIndices, FileFilter fileF itemFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(fileIndex.getSuffix()); } String itemFilePath = randomPath.concat(File.separator).concat(itemFilename); - writeFile(fileIndex.getId(), itemFilePath); + FileHandleHelper.writeFile(fileIndex.getId(), itemFilePath); fileList.add(new File(itemFilePath)); } } - public static void writeFile(String objectName, String itemFilePath) throws RestException { - try (InputStream getObjectResponse = INSTANCE.asyncFileService.getById(objectName)) { - StreamUtils.write(itemFilePath, getObjectResponse); - } catch (IOException exception) { - log.error("the file service download has error: {}", exception.getMessage()); - throw new FileErrorException(FileErrorStatus.SERVICE_DOWNLOAD_ERROR); - } - } - - public static FileIndex createFileIndex(FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { log.warn("the file index is null!"); @@ -271,8 +160,8 @@ public static void buildMd5(MultipartFile file, FileIndex fileIndex) throws Rest } public static void buildMd5(File file, FileIndex fileIndex) throws RestException { - try { - buildMd5(new FileInputStream(file), fileIndex); + try(FileInputStream fileInputStream = new FileInputStream(file)) { + buildMd5(fileInputStream, fileIndex); } catch (IOException exception) { log.error("the file read with bytes has error, filename: {}, error: {}", fileIndex.getName(), exception.getMessage()); throw new FileErrorException(FileErrorStatus.FILE_READ_BYTE_ERROR); @@ -327,7 +216,7 @@ public static void buildMd5(byte[] bytes, FileChunk fileChunk) throws RestExcept fileChunk.setChunkMd5(md5); } - public static FileIndex createFileChunk(MultipartFile file, FileIndex fileIndex) throws RestException { + public static FileIndex createFileChunk(MultipartFile multipartFile, FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { log.warn("the file index is null!"); throw new FileErrorException(FileErrorStatus.FILE_INDEX_IS_NULL); @@ -359,8 +248,8 @@ public static FileIndex createFileChunk(MultipartFile file, FileIndex fileIndex) } Long chunkSize = fileChunk.getChunkSize(); if (GeneralUtils.isEmpty(chunkSize)) { - chunkSize = file.getSize(); - fileChunk.setChunkSize(file.getSize()); + chunkSize = multipartFile.getSize(); + fileChunk.setChunkSize(multipartFile.getSize()); } Long chunkStart = fileChunk.getChunkStart(); if (chunkStart == null) { @@ -376,7 +265,7 @@ public static FileIndex createFileChunk(MultipartFile file, FileIndex fileIndex) log.error("the param of 'chunkEnd' or 'chunkStart' or 'chunkSize' for file chunk is invalid! "); throw new FileErrorException(FileErrorStatus.FILE_CHUNK_PARAM_INVALID); } - buildMd5(file, fileChunk); + buildMd5(multipartFile, fileChunk); fileChunk.setChunkTime(new Date()); if (fileChunk.getChunkIndex() == 1) { @@ -437,12 +326,22 @@ public static FileIndex createFileChunk(FileRequest fileRequest, String contentR return fileIndex; } - public static FileIndex createFileIndex(MultipartFile file, FileIndex fileIndex) throws RestException { + public static FileIndex createFileIndex(MultipartFile multipartFile, FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { fileIndex = new FileIndex(); } - String originalFilename = file.getOriginalFilename(); + if (GeneralUtils.isEmpty(fileIndex.getId())) { + String fileId = IdentityUtils.generateString(); + fileIndex.setId(fileId); + } + String originalFilename = multipartFile.getOriginalFilename(); + if (GeneralUtils.isNotEmpty(originalFilename)) { + originalFilename=originalFilename.trim().toLowerCase(); + } fileIndex.setName(originalFilename); + String tempPath = FileUtils.createPath(INSTANCE.commonProperties.getTempPath()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + File file = FileUtils.cacheFile(cachePath, multipartFile); fileIndex.setFile(file); String filename = FileUtils.filename(originalFilename); if (GeneralUtils.isEmpty(fileIndex.getFilename())) { @@ -455,7 +354,7 @@ public static FileIndex createFileIndex(MultipartFile file, FileIndex fileIndex) if (GeneralUtils.isEmpty(fileIndex.getSuffix())) { fileIndex.setSuffix(suffix); } - fileIndex.setFileSize(file.getSize()); + fileIndex.setFileSize(multipartFile.getSize()); FileType fileType = parseType(suffix); if (GeneralUtils.isEmpty(fileIndex.getIsSlice())) { fileIndex.setIsSlice(false); diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileChunkService.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileChunkService.java index a922d46..b6b5ad1 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileChunkService.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileChunkService.java @@ -17,7 +17,7 @@ * @author Cyan (snow22314@outlook.com) * @version v1.0.0 */ -public interface FileChunkService extends FilterService, RemoveService { +public interface FileChunkService extends FilterService, RemoveService { /** * 通过id查询实体 diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileHandleService.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileHandleService.java new file mode 100644 index 0000000..d619792 --- /dev/null +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileHandleService.java @@ -0,0 +1,18 @@ +package io.github.nichetoolkit.file.service; + +import io.github.nichetoolkit.file.model.FileIndex; +import io.github.nichetoolkit.rest.RestException; + +/** + *

FileHandleService

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +public interface FileHandleService { + + void autographImage(FileIndex fileIndex) throws RestException; + + void condenseImage(FileIndex fileIndex) throws RestException; + + void condenseFile(FileIndex fileIndex) throws RestException; +} diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileIndexService.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileIndexService.java index 3fe0c02..b31c2a8 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileIndexService.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileIndexService.java @@ -12,7 +12,7 @@ * @author Cyan (snow22314@outlook.com) * @version v1.0.0 */ -public interface FileIndexService extends FilterService, RemoveService { +public interface FileIndexService extends FilterService, RemoveService { /** * 通过id集合查询单个 diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java index e2c11f3..f3d1c70 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java @@ -127,6 +127,6 @@ public interface FileService { * @return FileIndex * @throws RestException 服务异常 */ - Future chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException; + FileIndex chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException; } diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileChunkServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileChunkServiceImpl.java index e4e9da8..991de72 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileChunkServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileChunkServiceImpl.java @@ -1,4 +1,4 @@ -package io.github.nichetoolkit.file.service.impl; +package io.github.nichetoolkit.file.service; import io.github.nichetoolkit.file.entity.FileChunkEntity; import io.github.nichetoolkit.file.filter.FileFilter; diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java new file mode 100644 index 0000000..c4c99aa --- /dev/null +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -0,0 +1,150 @@ +package io.github.nichetoolkit.file.service; + +import io.github.nichetoolkit.file.configure.FileCommonProperties; +import io.github.nichetoolkit.file.constant.FileConstants; +import io.github.nichetoolkit.file.error.FileErrorStatus; +import io.github.nichetoolkit.file.helper.FileServiceHelper; +import io.github.nichetoolkit.file.helper.ImageHandleHelper; +import io.github.nichetoolkit.file.model.FileIndex; +import io.github.nichetoolkit.file.service.FileHandleService; +import io.github.nichetoolkit.file.util.ImageUtils; +import io.github.nichetoolkit.rest.RestException; +import io.github.nichetoolkit.rest.error.natives.FileErrorException; +import io.github.nichetoolkit.rest.util.FileUtils; +import io.github.nichetoolkit.rest.util.GeneralUtils; +import io.github.nichetoolkit.rest.util.StreamUtils; +import io.github.nichetoolkit.rest.util.ZipUtils; +import lombok.extern.slf4j.Slf4j; +import net.coobird.thumbnailator.Thumbnails; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +/** + *

FileHandleServiceImpl

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +@Slf4j +@Service +public class FileHandleServiceImpl implements FileHandleService { + + @Autowired + protected FileCommonProperties commonProperties; + @Autowired + private FileCommonProperties serviceProperties; + + @Async + @Override + public void autographImage(FileIndex fileIndex) throws RestException { + String tempPath = FileUtils.createPath(commonProperties.getTempPath()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); + InputStream inputStream = fileIndex.inputStream(); + BufferedImage bufferedImage = ImageUtils.read(inputStream); + BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); + BufferedImage autographImage = ImageUtils.autograph(binaryImage); + String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); + String filePath = randomPath.concat(File.separator).concat(filename); + File file = new File(filePath); + if (file.exists()) { + FileUtils.delete(filePath); + } + ImageUtils.write(autographImage, file); + byte[] bytes = ImageUtils.bytes(file); + fileIndex.setBytes(bytes); + FileUtils.delete(filePath); + FileUtils.clear(randomPath); + FileUtils.clear(cachePath); + } + + @Async + @Override + public void condenseImage(FileIndex fileIndex) throws RestException { + String tempPath = FileUtils.createPath(commonProperties.getTempPath()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); + Long imageFileSize; + Double imageFileQuality = 1.0d; + Double imageFileScale = 1.0d; + String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); + String filePath; + File file; + Integer width = fileIndex.getWidth(); + Integer height = fileIndex.getHeight(); + filePath = randomPath.concat(File.separator).concat(filename); + file = new File(filePath); + do { + if (file.exists()) { + FileUtils.delete(filePath); + } + try { + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + BufferedImage bufferedImage = ImageHandleHelper.read(file); + int imageWidth = bufferedImage.getWidth(); + int imageHeight = bufferedImage.getHeight(); + if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { + Thumbnails.of(fileIndex.inputStream()).size(width, height).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + } else if (GeneralUtils.isNotEmpty(width) || GeneralUtils.isNotEmpty(height)) { + if (GeneralUtils.isNotEmpty(width)) { + imageFileScale = ((double) width / (double) imageWidth >= 1.0D) ? imageFileScale : ((double) width / (double) imageWidth); + } else { + imageFileScale = ((double) height / (double) imageHeight >= 1.0D) ? imageFileScale : ((double) height / (double) imageHeight); + } + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + } else { + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + } + } catch (IOException exception) { + log.error("the image file has error during condensing: {}", exception.getMessage()); + throw new FileErrorException(FileErrorStatus.FILE_IMAGE_CONDENSE_ERROR); + } + imageFileSize = file.length(); + if (imageFileQuality.equals(serviceProperties.getMinImageQuality())) { + imageFileScale += -0.1d; + } else { + imageFileQuality += -0.1d; + } + } while (imageFileSize > serviceProperties.getMaxImageSize() + && imageFileQuality > serviceProperties.getMinImageQuality() + && imageFileScale > serviceProperties.getMinImageScale()); + if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_WIDTH_PROPERTY, width); + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_HEIGHT_PROPERTY, height); + } else { + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_SCALE_PROPERTY, imageFileScale); + } + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_QUALITY_PROPERTY, imageFileQuality); + FileServiceHelper.buildProperties(filename, file.length(), FileConstants.IMAGE_PNG_SUFFIX, fileIndex); + FileServiceHelper.buildMd5(file, fileIndex); + FileUtils.delete(filePath); + FileUtils.clear(randomPath); + FileUtils.clear(cachePath); + } + + @Async + @Override + public void condenseFile(FileIndex fileIndex) throws RestException { + String tempPath = FileUtils.createPath(commonProperties.getTempPath()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); + String filename = fileIndex.getName(); + String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); + String filePath = randomPath.concat(File.separator).concat(filename); + File file = FileUtils.createFile(filePath); + StreamUtils.write(file, fileIndex.inputStream()); + File zipFile = ZipUtils.zipFile(randomPath, zipFilename, file); + FileServiceHelper.buildProperties(zipFilename, zipFile.length(), FileConstants.FILE_ZIP_SUFFIX, fileIndex); + if (fileIndex.getIsMd5()) { + FileServiceHelper.buildMd5(zipFile, fileIndex); + } + FileUtils.delete(filePath); + FileUtils.clear(randomPath); + FileUtils.clear(cachePath); + } +} diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java index a597a6e..6be4054 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java @@ -1,4 +1,4 @@ -package io.github.nichetoolkit.file.service.impl; +package io.github.nichetoolkit.file.service; import io.github.nichetoolkit.file.entity.FileIndexEntity; import io.github.nichetoolkit.file.filter.FileFilter; @@ -8,6 +8,7 @@ import io.github.nichetoolkit.file.service.FileChunkService; import io.github.nichetoolkit.file.service.FileIndexService; import io.github.nichetoolkit.rest.RestException; +import io.github.nichetoolkit.rest.actuator.BiConsumerActuator; import io.github.nichetoolkit.rest.actuator.ConsumerActuator; import io.github.nichetoolkit.rest.util.GeneralUtils; import io.github.nichetoolkit.rice.RiceInfoService; @@ -35,6 +36,16 @@ public class FileIndexServiceImpl extends RiceInfoService updateActuator() { - return this::optional; + protected BiConsumerActuator updateActuator() { + return (tableKey,fileIndex) -> this.optional(fileIndex); } @Override diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java index bdfa508..a765b91 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java @@ -5,29 +5,28 @@ import io.github.nichetoolkit.file.enums.FileType; import io.github.nichetoolkit.file.error.FileErrorStatus; import io.github.nichetoolkit.file.filter.FileFilter; +import io.github.nichetoolkit.file.handle.FileStoreService; import io.github.nichetoolkit.file.helper.FileServiceHelper; import io.github.nichetoolkit.file.model.FileChunk; import io.github.nichetoolkit.file.model.FileIndex; import io.github.nichetoolkit.file.model.FileRequest; -import io.github.nichetoolkit.file.service.AsyncFileService; import io.github.nichetoolkit.file.service.FileChunkService; +import io.github.nichetoolkit.file.service.FileHandleService; import io.github.nichetoolkit.file.service.FileIndexService; import io.github.nichetoolkit.file.service.FileService; import io.github.nichetoolkit.file.video.VideoHttpRequestHandler; import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.error.natives.FileErrorException; -import io.github.nichetoolkit.rest.identity.IdentityUtils; import io.github.nichetoolkit.rest.util.*; import io.github.nichetoolkit.rice.RestId; import io.github.nichetoolkit.rice.RestPage; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.AsyncResult; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; +import javax.annotation.Resource; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; @@ -41,7 +40,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.Future; import java.util.stream.Collectors; /** @@ -63,9 +61,12 @@ public class FileServiceImpl implements FileService { protected FileChunkService fileChunkService; @Autowired - protected AsyncFileService asyncFileService; + protected FileHandleService fileHandleService; - @Autowired + @Resource + protected FileStoreService fileStoreService; + + @Resource protected VideoHttpRequestHandler videoHttpRequestHandler; @Override @@ -81,7 +82,7 @@ public void remove(FileFilter fileFilter) throws RestException { } List fileIdList = restPage.getItems().stream().map(RestId::getId).distinct().collect(Collectors.toList()); if (GeneralUtils.isNotEmpty(fileIdList)) { - asyncFileService.removeAll(fileIdList); + fileStoreService.removeAll(fileIdList); if (fileFilter.isChunk()) { if (fileFilter.isDelete()) { fileChunkService.deleteAll(fileIdList); @@ -125,9 +126,9 @@ public void remove(String fileId, Boolean chunk, Boolean delete, Boolean rename) } if (isExist) { if (rename) { - asyncFileService.renameById(fileId, fileId.concat("_del")); + fileStoreService.renameById(fileId, fileId.concat("_del")); } - asyncFileService.removeById(fileId); + fileStoreService.removeById(fileId); } } @@ -160,7 +161,7 @@ public void download(FileIndex fileIndex, String filename, String contentType, B throw new FileErrorException(FileErrorStatus.SERVICE_DOWNLOAD_ERROR); } } else { - try (InputStream inputStream = asyncFileService.getById(fileIndex.getId()); + try (InputStream inputStream = fileStoreService.getById(fileIndex.getId()); ServletOutputStream outputStream = response.getOutputStream()) { response.addHeader(FileConstants.CONTENT_DISPOSITION_HEADER, FileConstants.ATTACHMENT_FILENAME_VALUE + URLEncoder.encode(filename, StandardCharsets.UTF_8.name())); StreamUtils.write(outputStream, inputStream); @@ -304,28 +305,21 @@ public FileIndex upload(FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { throw new RestException(FileErrorStatus.FILE_INDEX_IS_NULL); } - String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); - if (fileIndex.getIsAutograph() != null && fileIndex.getIsAutograph() && fileIndex.getFileType() == FileType.IMAGE) { - FileServiceHelper.autographImage(randomPath, fileIndex); + fileHandleService.autographImage(fileIndex); } if (fileIndex.getIsCondense()) { if (fileIndex.getFileType() == FileType.IMAGE) { - FileServiceHelper.condenseImage(randomPath, fileIndex); + fileHandleService.condenseImage(fileIndex); } else { - FileServiceHelper.condenseFile(randomPath, fileIndex); + fileHandleService.condenseFile(fileIndex); } } String fileId = fileIndex.getId(); - if (GeneralUtils.isEmpty(fileIndex.getId())) { - fileId = IdentityUtils.generateString(); - fileIndex.setId(fileId); - } - asyncFileService.putById(fileId, fileIndex.inputStream()); - FileUtils.clear(randomPath); + fileStoreService.putById(fileId, fileIndex.inputStream()); checkFileIndex(fileIndex); - return fileIndexService.save(fileIndex); + fileIndexService.save(fileIndex); + return fileIndex; } @Override @@ -341,12 +335,12 @@ public FileIndex indexUpload(FileIndex fileIndex) throws RestException { } @Override - @Async - public Future chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException { + public FileIndex chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException { FileIndex fileChunkIndex = FileServiceHelper.createFileChunk(fileRequest, contentRange); FileIndex fileIndex = FileServiceHelper.createFileChunk(file, fileChunkIndex); + checkFileIndex(fileIndex); FileChunk uploadChunk = fileChunkService.save(fileIndex.getFileChunk()); - asyncFileService.putById(uploadChunk.getId(), uploadChunk.inputStream()); + fileStoreService.putById(uploadChunk.getId(), uploadChunk.inputStream()); fileIndex.setFileChunk(uploadChunk); if (GeneralUtils.isEmpty(fileIndex.getFileChunks())) { fileIndex.setFileChunks(new ArrayList<>()); @@ -355,13 +349,13 @@ public Future chunkUpload(MultipartFile file, String contentRange, Fi fileChunks.add(uploadChunk); fileIndex.setCurrentIndex(uploadChunk.getChunkIndex()); if ((uploadChunk.getIsLastChunk() || uploadChunk.getChunkIndex().equals(fileIndex.getSliceSize())) && fileIndex.getIsMerge()) { - List sources = fileChunks.stream().map(RestId::getId).collect(Collectors.toList()); fileIndex.setIsFinish(true); - asyncFileService.margeById(fileIndex.getId(), sources); + List sources = fileIndex.getFileChunks().stream().map(RestId::getId).collect(Collectors.toList()); + fileStoreService.margeById(fileIndex.getId(), sources); checkFileIndex(fileIndex); fileIndexService.save(fileIndex); } - return AsyncResult.forValue(fileIndex); + return fileIndex; } private void checkFileIndex(FileIndex fileIndex) { diff --git a/file-toolkit-test-web/pom.xml b/file-toolkit-test-web/pom.xml index ecc3a6b..819d87f 100644 --- a/file-toolkit-test-web/pom.xml +++ b/file-toolkit-test-web/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4 file-toolkit-test-web - 1.0.3 + 1.0.4 file-toolkit-test-web jar file toolkit test web project for Spring Boot @@ -27,18 +27,18 @@ io.github.nichetoolkit file-toolkit-minio-starter ${file-toolkit.version} - - - com.squareup.okhttp3 - okhttp - - - com.squareup.okhttp3 - okhttp - ${minio-okhttp3.version} + io.github.nichetoolkit + file-toolkit-service-starter + ${file-toolkit.version} + + + + io.github.nichetoolkit + file-toolkit-postgres-starter + ${file-toolkit.version} diff --git a/file-toolkit-test-web/src/main/java/io/github/nichetoolkit/file/controller/FileController.java b/file-toolkit-test-web/src/main/java/io/github/nichetoolkit/file/controller/FileController.java index 47ac4c4..8b24282 100644 --- a/file-toolkit-test-web/src/main/java/io/github/nichetoolkit/file/controller/FileController.java +++ b/file-toolkit-test-web/src/main/java/io/github/nichetoolkit/file/controller/FileController.java @@ -12,8 +12,10 @@ import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.RestResult; import io.github.nichetoolkit.rest.error.natives.ServiceErrorException; +import io.github.nichetoolkit.rest.userlog.stereotype.RestNotelog; import io.github.nichetoolkit.rest.util.FileUtils; import io.github.nichetoolkit.rest.util.JsonUtils; +import io.github.nichetoolkit.rice.stereotype.RestSkip; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; @@ -31,6 +33,8 @@ import java.util.concurrent.Future; @Slf4j +@RestSkip +@RestNotelog @RestController @RequestMapping("/file") public class FileController { @@ -41,6 +45,12 @@ public class FileController { @Autowired private FileService fileService; + @GetMapping("/error") + public ResponseEntity error() throws RestException { + Object test = null; + test.toString(); + return RestResult.ok(); + } @GetMapping("/img/download") public void imgDownload(@RequestParam(value = "fileId") String fileId, @@ -118,12 +128,8 @@ public ResponseEntity chunkUpload(@NonNull @RequestPart("file") MultipartFile fi FileRequest fileRequest) throws RestException { String originalFilename = file.getOriginalFilename(); log.info("the chunk file will be started uploading at 'chunkUpload', filename: {}", originalFilename); - Future indexFuture = fileService.chunkUpload(file, contentRange, fileRequest); - try { - return RestResult.ok(indexFuture.get()); - } catch (InterruptedException | ExecutionException exception) { - throw new ServiceErrorException(FileErrorStatus.SERVICE_DOWNLOAD_ERROR, exception.getMessage()); - } + FileIndex fileIndex = fileService.chunkUpload(file, contentRange, fileRequest); + return ResponseEntity.ok(fileIndex); } @Deprecated diff --git a/file-toolkit-test-web/src/main/resources/application-dev.properties b/file-toolkit-test-web/src/main/resources/application-dev.properties index af4caad..33ceb8a 100644 --- a/file-toolkit-test-web/src/main/resources/application-dev.properties +++ b/file-toolkit-test-web/src/main/resources/application-dev.properties @@ -1,16 +1,20 @@ server.port=8081 nichetoolkit.rest.intercept.enabled=true nichetoolkit.rest.intercept.log-enabled=true -nichetoolkit.rest.intercept.bean-enabled=true -nichetoolkit.rest.error.console-log.rest-exception-enabled=true +nichetoolkit.rest.intercept.userlog-enabled=true + +nichetoolkit.rest.error.console-log.rest-exception-enabled=false nichetoolkit.rest.error.console-log.common-exception-enabled=true + nichetoolkit.rest.http.enabled=true nichetoolkit.rest.http.http-type=ok_http_client + spring.datasource.hikari.driver-class-name=org.postgresql.Driver spring.datasource.hikari.jdbc-url=jdbc:postgresql://localhost:5432/resource?stringtype=unspecified spring.datasource.hikari.username=postgres spring.datasource.hikari.password=2314 -nichetoolkit.file.service.temp-path=G:\\data\\server\\file\\temp + +nichetoolkit.file.common.temp-path=E:\\data\\server\\file\\temp nichetoolkit.file.minio.endpoint=http://172.16.107.144:9000 nichetoolkit.file.minio.bucket-name=local nichetoolkit.file.minio.access-key=admin diff --git a/file-toolkit-test-web/src/main/resources/application-pro.properties b/file-toolkit-test-web/src/main/resources/application-pro.properties index eb76985..270f62a 100644 --- a/file-toolkit-test-web/src/main/resources/application-pro.properties +++ b/file-toolkit-test-web/src/main/resources/application-pro.properties @@ -1,16 +1,21 @@ server.port=8081 nichetoolkit.rest.intercept.enabled=false nichetoolkit.rest.intercept.log-enabled=false -nichetoolkit.rest.intercept.bean-enabled=false +nichetoolkit.rest.intercept.userlog-enabled=true + nichetoolkit.rest.error.console-log.rest-exception-enabled=false nichetoolkit.rest.error.console-log.common-exception-enabled=true + nichetoolkit.rest.http.enabled=true nichetoolkit.rest.http.http-type=ok_http_client + spring.datasource.hikari.driver-class-name=org.postgresql.Driver spring.datasource.hikari.jdbc-url=jdbc:postgresql://172.16.107.144:5432/fileserver@1.0.0?stringtype=unspecified spring.datasource.hikari.username=postgres spring.datasource.hikari.password=xinfeng@postgres -nichetoolkit.file.service.temp-path=G:\\data\\server\\file\\temp + +nichetoolkit.file.common.temp-path=G:\\data\\server\\file\\temp + nichetoolkit.file.minio.endpoint=http://172.16.107.144:9000 nichetoolkit.file.minio.bucket-name=local nichetoolkit.file.minio.access-key=admin diff --git a/file-toolkit-test-web/src/main/resources/application.properties b/file-toolkit-test-web/src/main/resources/application.properties index b254387..3dc0956 100644 --- a/file-toolkit-test-web/src/main/resources/application.properties +++ b/file-toolkit-test-web/src/main/resources/application.properties @@ -2,28 +2,59 @@ spring.jmx.enabled=false spring.application.name=file-server spring.jmx.default-domain=file-server server.tomcat.connection-timeout=600s + spring.servlet.multipart.enabled=true spring.servlet.multipart.max-file-size=64000MB spring.servlet.multipart.max-request-size=6400MB -nichetoolkit.rice.bean.name.unique-enabled=true -nichetoolkit.rice.bean.name.nonnull-enabled=false + +nichetoolkit.rice.bean.name.unique-enabled = true +nichetoolkit.rice.bean.name.nonnull-enabled = true +nichetoolkit.rice.bean.key.invade-enabled = false + +nichetoolkit.rice.bean.model.dynamic-table-enabled= false + +nichetoolkit.rest.error.console-log.rest-exception-enabled=false +nichetoolkit.rest.error.console-log.common-exception-enabled=true + spring.jackson.default-property-inclusion=non_null spring.jackson.parser.allow-unquoted-control-chars=true spring.jackson.parser.allow-comments=true spring.jackson.parser.allow-single-quotes=true spring.jackson.deserialization.fail-on-unknown-properties=false spring.jackson.time-zone=GMT+8 + spring.main.allow-circular-references=true + +spring.main.allow-bean-definition-overriding=true + nichetoolkit.rest.identity.enabled=true nichetoolkit.rest.identity.type=config nichetoolkit.rest.identity.config.worker-id=1 nichetoolkit.rest.identity.config.center-id=2 -nichetoolkit.rest.md5.enabled=false -nichetoolkit.rest.md5.cipher=4AFa1sTe45FAst2^aPHV7sVG + +nichetoolkit.rest.http.enabled=true +nichetoolkit.rest.http.http-type=ok_http_client + +nichetoolkit.rest.intercept.enabled=true +nichetoolkit.rest.intercept.log-enabled=true +nichetoolkit.rest.intercept.userlog-enabled=true + +nichetoolkit.rice.login.enabled=true +nichetoolkit.rice.login.token-prefixes=Bearer +nichetoolkit.rice.login.header-tokens=Authorization + +nichetoolkit.rest.logback.enabled=true +nichetoolkit.rest.logback.attributes=t + +nichetoolkit.rest.sha.enabled=false +nichetoolkit.rest.sha.secret=4AFa1sTe45FAst2^aPHV7sVG + nichetoolkit.rest.jwt.enabled=false -nichetoolkit.rest.jwt.secret-key=4AFa1sTe45FAst2^aPHV7sVG +nichetoolkit.rest.jwt.secret=4AFa1sTe45FAst2^aPHV7sVG nichetoolkit.rest.jwt.issuer=io.github.nichetoolkit + nichetoolkit.rest.radix.enabled=false + spring.datasource.type=com.zaxxer.hikari.HikariDataSource spring.datasource.hikari.minimum-idle=5 spring.datasource.hikari.maximum-pool-size=15 @@ -33,5 +64,7 @@ spring.datasource.hikari.pool-name=DatebookHikariCP spring.datasource.hikari.max-lifetime=1800000 spring.datasource.hikari.connection-timeout=30000 spring.datasource.hikari.connection-test-query=SELECT 1 + logging.config=classpath:logback-spring.xml + spring.profiles.active=pro \ No newline at end of file diff --git a/file-toolkit-test-web/src/main/resources/logback-spring.xml b/file-toolkit-test-web/src/main/resources/logback-spring.xml index f24cd50..f4aafe5 100644 --- a/file-toolkit-test-web/src/main/resources/logback-spring.xml +++ b/file-toolkit-test-web/src/main/resources/logback-spring.xml @@ -3,31 +3,50 @@ - + logback - - + + + + - - - + + + - + value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%X{logKey}){magenta} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %rmx%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> - + ${CONSOLE_LOG_PATTERN} @@ -36,7 +55,6 @@ - @@ -45,7 +63,7 @@ ${log.path}/logs.log - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + %d{yyyy-MM-dd HH:mm:ss.SSS} %X{logKey} %X{requestKey} [%thread] %-5level %logger{50} - %rmx%n UTF-8 @@ -71,7 +89,7 @@ ${log.path}/log_debug.log - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + %d{yyyy-MM-dd HH:mm:ss.SSS} %X{logKey} %X{requestKey} [%thread] %-5level %logger{50} - %rmx%n UTF-8 @@ -98,7 +116,7 @@ ${log.path}/log_info.log - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + %d{yyyy-MM-dd HH:mm:ss.SSS} %X{logKey} %X{requestKey} [%thread] %-5level %logger{50} - %rmx%n UTF-8 @@ -125,7 +143,7 @@ ${log.path}/log_warn.log - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + %d{yyyy-MM-dd HH:mm:ss.SSS} %X{logKey} %X{requestKey} [%thread] %-5level %logger{50} - %rmx%n UTF-8 @@ -152,7 +170,7 @@ ${log.path}/log_error.log - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + %d{yyyy-MM-dd HH:mm:ss.SSS} %X{logKey} %X{requestKey} [%thread] %-5level %logger{50} - %rmx%n UTF-8 @@ -200,26 +218,26 @@ - - - - - - - + + + + + + + - - - - - - - + + + + + + + @@ -227,13 +245,13 @@ - - - - - - + + + + + + - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index dcfeac7..4693b7c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,11 +5,13 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4 file-toolkit-common-starter file-toolkit-service-starter + file-toolkit-postgres-starter + file-toolkit-gauss-starter file-toolkit-hdfs-starter file-toolkit-minio-utils file-toolkit-minio-starter @@ -44,7 +46,7 @@ org.springframework.boot spring-boot-starter-parent - 2.6.6 + 2.7.7 @@ -113,9 +115,9 @@ UTF-8 1.8 1.8 - 2.6.6 - 1.0.5 - 1.0.4 + 2.7.7 + 1.0.6 + 1.0.5 2.2.1 2.9.1 @@ -124,15 +126,14 @@ 3.3 2.5.3 - 1.0.3 + 1.0.4 2.8.5 0.4.16 4.1.5 2.1.5 - 8.3.7 - 4.8.1 + 8.4.6