|
@@ -13,6 +13,7 @@ import com.persagy.dmp.common.utils.ResourceUtil;
|
|
|
import com.persagy.dmp.file.constant.FileCommonConst;
|
|
|
import com.persagy.dmp.file.context.OldFileAppContext;
|
|
|
import com.persagy.dmp.file.model.FileInfo;
|
|
|
+import com.persagy.dmp.file.model.FileInfoCreator;
|
|
|
import com.persagy.dmp.file.model.FileMd5;
|
|
|
import com.persagy.dmp.file.model.FileMd5Creator;
|
|
|
import com.persagy.dmp.file.service.*;
|
|
@@ -29,10 +30,8 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.charset.Charset;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
* Description: 兼容旧的文件服务接口
|
|
@@ -258,6 +257,7 @@ public class CompatibleOldFileController {
|
|
|
*/
|
|
|
@PostMapping(value = "/common/register_multipart_upload")
|
|
|
@ResponseBody
|
|
|
+ @CrossOrigin(origins = "*",allowedHeaders = "*",allowCredentials = "true",methods = {RequestMethod.POST,RequestMethod.GET})
|
|
|
public String registerMultipartUpload() {
|
|
|
if (StrUtil.isBlank(OldFileAppContext.getContext().getSystemId())
|
|
|
|| StrUtil.isBlank(OldFileAppContext.getContext().getKey())){
|
|
@@ -288,6 +288,7 @@ public class CompatibleOldFileController {
|
|
|
@SneakyThrows
|
|
|
@RequestMapping(value = "/common/multipart_upload",consumes = {MediaType.MULTIPART_FORM_DATA})
|
|
|
@ResponseBody
|
|
|
+ @CrossOrigin(value = "*", origins = "*",allowedHeaders = "*",allowCredentials = "true",methods = {RequestMethod.POST,RequestMethod.GET})
|
|
|
public String multipartUpload(@RequestParam(value = "file",required = false) MultipartFile file,
|
|
|
@RequestParam(value = "uploadId",required = false) String uploadId,
|
|
|
@RequestParam(value = "chunkNumber",required = false) Integer chunkNumber,
|
|
@@ -336,7 +337,7 @@ public class CompatibleOldFileController {
|
|
|
if (ObjectUtil.isEmpty(fileMd5)){
|
|
|
FileMd5 fileMd5Create = FileMd5Creator.of(fileInfo.getCreator(), md5, FileCommonConst.UPLOAD_PART);
|
|
|
fileMd5Create.setFileSize(totalSize);
|
|
|
- fileMd5Create.setCreator(fileInfo.getCreator());
|
|
|
+ fileMd5Create.setCreator(FileInfoCreator.formatBucket(fileInfo.getCreator()));
|
|
|
fileMd5Service.save(fileMd5Create);
|
|
|
}
|
|
|
Map<Integer,String> okChunkMap = service.mapChunkObjectNames(service.getChuckBucketName(null), md5);
|
|
@@ -351,6 +352,7 @@ public class CompatibleOldFileController {
|
|
|
@SneakyThrows
|
|
|
@RequestMapping(value = "/common/merge_multipart")
|
|
|
@ResponseBody
|
|
|
+ @CrossOrigin(origins = "*",allowedHeaders = "*",allowCredentials = "true",methods = {RequestMethod.POST,RequestMethod.GET})
|
|
|
public String mergeMultipart() {
|
|
|
if (StrUtil.isBlank(OldFileAppContext.getContext().getUploadId())){
|
|
|
return INCORRECT_PARAMETERS;
|
|
@@ -366,11 +368,23 @@ public class CompatibleOldFileController {
|
|
|
return INCORRECT_PARAMETERS;
|
|
|
}
|
|
|
IFileStorageService service = FileStorageFactory.getService();
|
|
|
+ if (FileCommonConst.UPLOAD_SUCCESS.equals(fileMd5.getUploadStatus())
|
|
|
+ && StrUtil.isNotBlank(fileMd5.getFileBucket())
|
|
|
+ && StrUtil.isNotBlank(fileMd5.getFilePath())
|
|
|
+ && service.exists(fileMd5.getFileBucket(),fileMd5.getFilePath())){
|
|
|
+ JSONObject jsonObj = new JSONObject();
|
|
|
+ jsonObj.put("Result", "success");
|
|
|
+ jsonObj.put("ResultMsg", "");
|
|
|
+ return jsonObj.toJSONString();
|
|
|
+ }
|
|
|
List<String> chunks = service
|
|
|
.listObjectNames(service.getChuckBucketName(null),fileInfo.getFileMd5());
|
|
|
if (CollUtil.isEmpty(chunks)){
|
|
|
return INCORRECT_PARAMETERS;
|
|
|
}
|
|
|
+ chunks = chunks.stream()
|
|
|
+ .sorted(Comparator.comparingInt(n -> Integer.parseInt(StrUtil.subBetween(n, StrUtil.SLASH, StrUtil.DOT))))
|
|
|
+ .collect(Collectors.toList());
|
|
|
fileMd5Service.ensureFilePath(fileMd5,fileInfo.getFileName());
|
|
|
boolean composeObject = service.composeObject(fileInfo.getCreator(), chunks, fileMd5.getFilePath());
|
|
|
JSONObject jsonObj = new JSONObject();
|