|
|
@@ -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
|
|
|
*/
|
|
|
@@ -33,6 +33,10 @@ public class FileInfo extends CommonBaseEntity implements Serializable{
|
|
|
* 存储路径
|
|
|
*/
|
|
|
private String fullPath;
|
|
|
+ /**
|
|
|
+ * 访问路径
|
|
|
+ */
|
|
|
+ private String accessPath;
|
|
|
/**
|
|
|
* Content-Type
|
|
|
*/
|
|
|
@@ -47,7 +51,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;
|
|
|
|
|
|
@@ -76,10 +81,11 @@ public class FileInfo extends CommonBaseEntity implements Serializable{
|
|
|
this.name = name;
|
|
|
}
|
|
|
|
|
|
- public FileInfo(Long folderId, String name, String fullPath, String mime, String ext, String type, long size) {
|
|
|
+ public FileInfo(Long folderId, String name, String fullPath, String accessPath, String mime, String ext, String type, long size) {
|
|
|
this.folderId = folderId;
|
|
|
this.name = name;
|
|
|
this.fullPath = fullPath;
|
|
|
+ this.accessPath = accessPath;
|
|
|
this.mime = mime;
|
|
|
this.ext = ext;
|
|
|
this.type = type;
|
|
|
@@ -142,6 +148,14 @@ public class FileInfo extends CommonBaseEntity implements Serializable{
|
|
|
this.type = type;
|
|
|
}
|
|
|
|
|
|
+ public String getAccessPath() {
|
|
|
+ return accessPath;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setAccessPath(String accessPath) {
|
|
|
+ this.accessPath = accessPath;
|
|
|
+ }
|
|
|
+
|
|
|
public boolean isDeleted() {
|
|
|
return deleted;
|
|
|
}
|
|
|
@@ -211,7 +225,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 +241,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 +288,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 +298,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 = storageClient.uploadFile(multipartFile.getInputStream(),
|
|
|
+ new FileMetadata(mime, ext, size));
|
|
|
}
|
|
|
|
|
|
- return new FileInfo(folderId, name, fullPath, mime, ext, type, size);
|
|
|
+ String accessPath = StringUtils.nullIf(baseUrl) + fullPath;
|
|
|
+ return new FileInfo(folderId, name, fullPath, accessPath, mime, ext, type, size);
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|