|
|
@@ -1,14 +1,14 @@
|
|
|
package com.usoftchina.smartschool.file.po;
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
|
-import com.github.tobato.fastdfs.domain.StorePath;
|
|
|
-import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
|
|
import com.usoftchina.smartschool.base.entity.CommonBaseEntity;
|
|
|
import com.usoftchina.smartschool.context.BaseContextHolder;
|
|
|
-import com.usoftchina.smartschool.file.constant.FileType;
|
|
|
-import com.usoftchina.smartschool.file.util.FileTypeUtils;
|
|
|
+import com.usoftchina.smartschool.file.storage.FileMetadata;
|
|
|
+import com.usoftchina.smartschool.file.storage.FileStorageClient;
|
|
|
+import com.usoftchina.smartschool.file.storage.util.FileType;
|
|
|
+import com.usoftchina.smartschool.file.storage.util.FileTypeUtils;
|
|
|
+import com.usoftchina.smartschool.file.storage.util.FilenameUtils;
|
|
|
import com.usoftchina.smartschool.utils.StringUtils;
|
|
|
-import org.apache.commons.io.FilenameUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
@@ -19,7 +19,7 @@ import java.util.Date;
|
|
|
* @author yingp
|
|
|
* @date 2018/9/29
|
|
|
*/
|
|
|
-public class FileInfo extends CommonBaseEntity implements Serializable{
|
|
|
+public class FileInfo extends CommonBaseEntity implements Serializable {
|
|
|
/**
|
|
|
* 文件夹id
|
|
|
*/
|
|
|
@@ -47,7 +47,8 @@ public class FileInfo extends CommonBaseEntity implements Serializable{
|
|
|
private long size;
|
|
|
/**
|
|
|
* 类型
|
|
|
- * @see com.usoftchina.smartschool.file.constant.FileType
|
|
|
+ *
|
|
|
+ * @see com.usoftchina.smartschool.file.storage.util.FileType
|
|
|
*/
|
|
|
private String type;
|
|
|
|
|
|
@@ -211,7 +212,7 @@ public class FileInfo extends CommonBaseEntity implements Serializable{
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
- public static Builder newFile(MultipartFile file){
|
|
|
+ public static Builder newFile(MultipartFile file) {
|
|
|
return new Builder(file);
|
|
|
}
|
|
|
|
|
|
@@ -227,7 +228,7 @@ public class FileInfo extends CommonBaseEntity implements Serializable{
|
|
|
private long size;
|
|
|
private String type;
|
|
|
private MultipartFile multipartFile;
|
|
|
- private FastFileStorageClient storageClient;
|
|
|
+ private FileStorageClient storageClient;
|
|
|
private String baseUrl;
|
|
|
|
|
|
public Builder(MultipartFile file) {
|
|
|
@@ -274,7 +275,7 @@ public class FileInfo extends CommonBaseEntity implements Serializable{
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public Builder storeBy(FastFileStorageClient storageClient){
|
|
|
+ public Builder storeBy(FileStorageClient storageClient) {
|
|
|
this.storageClient = storageClient;
|
|
|
return this;
|
|
|
}
|
|
|
@@ -284,26 +285,14 @@ public class FileInfo extends CommonBaseEntity implements Serializable{
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public FileInfo build() throws IOException{
|
|
|
+ public FileInfo build() throws IOException {
|
|
|
if (null != storageClient) {
|
|
|
- StorePath storePath;
|
|
|
- if (FileType.of(type) == FileType.IMAGE) {
|
|
|
- // 保存图片 + 生成缩略图
|
|
|
- try {
|
|
|
- storePath = storageClient.uploadImageAndCrtThumbImage(multipartFile.getInputStream(),
|
|
|
- size, ext, null);
|
|
|
- }catch (Exception e) {
|
|
|
- storePath = storageClient.uploadFile(multipartFile.getInputStream(),
|
|
|
- size, ext, null);
|
|
|
- }
|
|
|
- } else {
|
|
|
- storePath = storageClient.uploadFile(multipartFile.getInputStream(),
|
|
|
- size, ext, null);
|
|
|
- }
|
|
|
- this.fullPath = StringUtils.nullIf(baseUrl) + storePath.getFullPath();
|
|
|
+ this.fullPath = StringUtils.nullIf(baseUrl) +
|
|
|
+ storageClient.uploadFile(multipartFile.getInputStream(),
|
|
|
+ new FileMetadata(mime, ext, size));
|
|
|
}
|
|
|
|
|
|
return new FileInfo(folderId, name, fullPath, mime, ext, type, size);
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|