업로드 관련 수정

This commit is contained in:
Moon
2026-01-08 18:43:40 +09:00
parent 0a311b09a8
commit ecf9b8a24f
15 changed files with 185 additions and 239 deletions

View File

@@ -490,7 +490,8 @@ public class FIleChecker {
return true; return true;
} }
public static boolean multipartChunkSaveTo(MultipartFile mfile, String targetPath, int chunkIndex) { public static boolean multipartChunkSaveTo(
MultipartFile mfile, String targetPath, int chunkIndex) {
File dest = new File(targetPath, String.valueOf(chunkIndex)); File dest = new File(targetPath, String.valueOf(chunkIndex));
boolean fileUpload = true; boolean fileUpload = true;

View File

@@ -44,7 +44,7 @@ public class SecurityConfig {
.authorizeHttpRequests( .authorizeHttpRequests(
auth -> auth ->
auth auth
// .requestMatchers("/chunk_upload_test.html").authenticated() // .requestMatchers("/chunk_upload_test.html").authenticated()
// 맵시트 영역 전체 허용 (우선순위 최상단) // 맵시트 영역 전체 허용 (우선순위 최상단)
.requestMatchers("/api/mapsheet/**") .requestMatchers("/api/mapsheet/**")

View File

@@ -13,7 +13,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import java.io.IOException;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.UUID; import java.util.UUID;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -106,33 +105,31 @@ public class ModelMngApiController {
return ApiResponseDto.okObject(modelMngService.removeModel(UUID.fromString(uuid))); return ApiResponseDto.okObject(modelMngService.removeModel(UUID.fromString(uuid)));
} }
@Operation(summary = "모델등록") @Operation(summary = "모델등록")
@PostMapping @PostMapping
public ApiResponseDto<ApiResponseDto.ResponseObj> ModelMgmt( public ApiResponseDto<ApiResponseDto.ResponseObj> ModelMgmt(
@RequestBody @Valid ModelMngDto.AddReq addReq) { @RequestBody @Valid ModelMngDto.AddReq addReq) {
return ApiResponseDto.ok(modelMngService.insertModel(addReq)); return ApiResponseDto.ok(modelMngService.insertModel(addReq));
} }
@Operation(summary = "데이터셋 대용량 파일 분할 전송", description = "데이터셋 파일 대용량 파일을 청크 단위로 전송합니다.") @Operation(summary = "데이터셋 대용량 파일 분할 전송", description = "데이터셋 파일 대용량 파일을 청크 단위로 전송합니다.")
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse(responseCode = "200", description = "청크 업로드 성공", content = @Content), @ApiResponse(responseCode = "200", description = "청크 업로드 성공", content = @Content),
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content), @ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
@ApiResponse(responseCode = "404", description = "업로드 세션을 찾을 수 없음", content = @Content), @ApiResponse(responseCode = "404", description = "업로드 세션을 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
}) })
@PostMapping(value = "/file-chunk-upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(value = "/file-chunk-upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ApiResponseDto<UploadDto.UploadRes> fileChunkUpload( public ApiResponseDto<UploadDto.UploadRes> fileChunkUpload(
@RequestParam("uuid") UUID uuid, @RequestParam("uuid") UUID uuid,
@RequestParam("fileName") String fileName, @RequestParam("fileName") String fileName,
@RequestParam("fileSize") long fileSize, @RequestParam("fileSize") long fileSize,
// @RequestParam("fileHash") String fileHash, // @RequestParam("fileHash") String fileHash,
@RequestParam("chunkIndex") Integer chunkIndex, @RequestParam("chunkIndex") Integer chunkIndex,
@RequestParam("chunkTotalIndex") Integer chunkTotalIndex, @RequestParam("chunkTotalIndex") Integer chunkTotalIndex,
@RequestPart("chunkFile") MultipartFile chunkFile) { @RequestPart("chunkFile") MultipartFile chunkFile) {
String uploadDivi = "model"; String uploadDivi = "model";
@@ -147,7 +144,7 @@ public class ModelMngApiController {
upAddReqDto.setFinalPath(modelDir); upAddReqDto.setFinalPath(modelDir);
upAddReqDto.setTempPath(modelTmpDir); upAddReqDto.setTempPath(modelTmpDir);
System.out.println("uuid === "+ uuid); System.out.println("uuid === " + uuid);
return ApiResponseDto.ok(modelMngService.uploadChunkModelFile(upAddReqDto, chunkFile)); return ApiResponseDto.ok(modelMngService.uploadChunkModelFile(upAddReqDto, chunkFile));
} }

View File

@@ -125,9 +125,7 @@ public class ModelMngDto {
private String fileName; private String fileName;
private String memo; private String memo;
@JsonIgnore @JsonIgnore private UUID uuid;
private UUID uuid;
} }
@Schema(name = "searchReq", description = "검색 요청") @Schema(name = "searchReq", description = "검색 요청")

View File

@@ -59,7 +59,6 @@ public class ModelMngService {
return new ApiResponseDto.ResponseObj(ApiResponseDto.ApiResponseCode.OK, "삭제되었습니다."); return new ApiResponseDto.ResponseObj(ApiResponseDto.ApiResponseCode.OK, "삭제되었습니다.");
} }
public ApiResponseDto.ResponseObj insertModel(ModelMngDto.AddReq addReq) { public ApiResponseDto.ResponseObj insertModel(ModelMngDto.AddReq addReq) {
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();
addReq.setUuid(uuid); addReq.setUuid(uuid);
@@ -67,12 +66,10 @@ public class ModelMngService {
return new ApiResponseDto.ResponseObj(ApiResponseDto.ApiResponseCode.OK, "등록되었습니다."); return new ApiResponseDto.ResponseObj(ApiResponseDto.ApiResponseCode.OK, "등록되었습니다.");
} }
public UploadDto.UploadRes uploadChunkModelFile(UploadDto.UploadAddReq upAddReqDto, MultipartFile chunkFile) public UploadDto.UploadRes uploadChunkModelFile(
{ UploadDto.UploadAddReq upAddReqDto, MultipartFile chunkFile) {
UploadDto.UploadRes upRes = uploadService.uploadChunk(upAddReqDto, chunkFile); UploadDto.UploadRes upRes = uploadService.uploadChunk(upAddReqDto, chunkFile);
return upRes; return upRes;
} }
} }

View File

@@ -1,10 +1,7 @@
package com.kamco.cd.kamcoback.postgres.core; package com.kamco.cd.kamcoback.postgres.core;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import com.kamco.cd.kamcoback.model.dto.ModelMngDto; import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
import com.kamco.cd.kamcoback.postgres.entity.ModelMngEntity;
import com.kamco.cd.kamcoback.postgres.repository.model.ModelMngRepository; import com.kamco.cd.kamcoback.postgres.repository.model.ModelMngRepository;
import jakarta.persistence.EntityNotFoundException;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.UUID; import java.util.UUID;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -35,15 +32,15 @@ public class ModelMngCoreService {
.orElseThrow(() -> new EntityNotFoundException("model을 찾을 수 없습니다.")); .orElseThrow(() -> new EntityNotFoundException("model을 찾을 수 없습니다."));
*/ */
// id 코드 deleted = true 업데이트 // id 코드 deleted = true 업데이트
//entity.deleted(); // entity.deleted();
modelMngRepository.deleteByModelUuid(uuid); modelMngRepository.deleteByModelUuid(uuid);
} }
public void insertModel(ModelMngDto.AddReq addReq){ public void insertModel(ModelMngDto.AddReq addReq) {
//ModelMngEntity addEntity = new ModelMngEntity(); // ModelMngEntity addEntity = new ModelMngEntity();
//addEntity.setModelType(addReq.getModelType()); // addEntity.setModelType(addReq.getModelType());
modelMngRepository.insertModel(addReq); modelMngRepository.insertModel(addReq);
} }

View File

@@ -12,8 +12,7 @@ public class UploadSessionCoreService {
private final UploadSessionRepository uploadSessionRepository; private final UploadSessionRepository uploadSessionRepository;
public void createUploadSession(UploadDto.UploadAddReq addReq) public void createUploadSession(UploadDto.UploadAddReq addReq) {
{
/* /*
UUID newUuid = UUID.randomUUID(); UUID newUuid = UUID.randomUUID();
@@ -39,18 +38,17 @@ public class UploadSessionCoreService {
*/ */
uploadSessionRepository.insertUploadSession(addReq); uploadSessionRepository.insertUploadSession(addReq);
} }
public UploadDto.uploadDto findByDatasetUid(Long datasetId, String uploadDivi){ public UploadDto.uploadDto findByDatasetUid(Long datasetId, String uploadDivi) {
return uploadSessionRepository.findByDatasetUid(datasetId, uploadDivi); return uploadSessionRepository.findByDatasetUid(datasetId, uploadDivi);
} }
public UploadDto.uploadDto findByUuid(UUID uuid){ public UploadDto.uploadDto findByUuid(UUID uuid) {
return uploadSessionRepository.findByUuid(uuid); return uploadSessionRepository.findByUuid(uuid);
} }
public void updateUploadSessionStatus(UploadDto.UploadAddReq addReq){ public void updateUploadSessionStatus(UploadDto.UploadAddReq addReq) {
uploadSessionRepository.updateUploadSessionStatus(addReq); uploadSessionRepository.updateUploadSessionStatus(addReq);
} }
} }

View File

@@ -86,5 +86,4 @@ public class UploadSessionEntity {
@ColumnDefault("uuid_generate_v4()") @ColumnDefault("uuid_generate_v4()")
@Column(name = "uuid", nullable = false) @Column(name = "uuid", nullable = false)
private UUID uuid; private UUID uuid;
} }

View File

@@ -20,7 +20,6 @@ public interface ModelMngRepositoryCustom {
Optional<ModelMngEntity> findByModelUuid(UUID uuid); Optional<ModelMngEntity> findByModelUuid(UUID uuid);
void insertModel(ModelMngDto.AddReq addReq); void insertModel(ModelMngDto.AddReq addReq);
void deleteByModelUuid(UUID uuid); void deleteByModelUuid(UUID uuid);

View File

@@ -123,10 +123,7 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
System.out.println("uuid == " + uuid); System.out.println("uuid == " + uuid);
return Optional.ofNullable( return Optional.ofNullable(
queryFactory queryFactory.selectFrom(modelMngEntity).where(modelMngEntity.uuid.eq(uuid)).fetchOne());
.selectFrom(modelMngEntity)
.where(modelMngEntity.uuid.eq(uuid))
.fetchOne());
} }
private BooleanExpression eventEndedAtBetween( private BooleanExpression eventEndedAtBetween(
@@ -172,33 +169,32 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
@Override @Override
public void insertModel(@Valid ModelMngDto.AddReq addReq) { public void insertModel(@Valid ModelMngDto.AddReq addReq) {
long execCount = long execCount =
queryFactory queryFactory
.insert(modelMngEntity) .insert(modelMngEntity)
.columns( .columns(
modelMngEntity.modelVer, modelMngEntity.modelVer,
modelMngEntity.modelType, modelMngEntity.modelType,
modelMngEntity.filePath, modelMngEntity.filePath,
modelMngEntity.fileName, modelMngEntity.fileName,
modelMngEntity.memo, modelMngEntity.memo,
modelMngEntity.uuid) modelMngEntity.uuid)
.values( .values(
addReq.getModelVer(), addReq.getModelVer(),
addReq.getModelType(), addReq.getModelType(),
addReq.getFilePath(), addReq.getFilePath(),
addReq.getFileName(), addReq.getFileName(),
addReq.getMemo(), addReq.getMemo(),
addReq.getUuid()) addReq.getUuid())
.execute(); .execute();
} }
@Override @Override
public void deleteByModelUuid(UUID uuid){ public void deleteByModelUuid(UUID uuid) {
long execCount = long execCount =
queryFactory queryFactory
.update(modelMngEntity) .update(modelMngEntity)
.set(modelMngEntity.deleted, true) .set(modelMngEntity.deleted, true)
.where(modelMngEntity.uuid.eq(uuid)) .where(modelMngEntity.uuid.eq(uuid))
.execute(); .execute();
} }
} }

View File

@@ -1,19 +1,15 @@
package com.kamco.cd.kamcoback.postgres.repository.upload; package com.kamco.cd.kamcoback.postgres.repository.upload;
import com.kamco.cd.kamcoback.upload.dto.UploadDto; import com.kamco.cd.kamcoback.upload.dto.UploadDto;
import java.util.UUID; import java.util.UUID;
public interface UploadSessionRepositoryCustom { public interface UploadSessionRepositoryCustom {
void insertUploadSession(UploadDto.UploadAddReq addReq); void insertUploadSession(UploadDto.UploadAddReq addReq);
UploadDto.uploadDto findByDatasetUid(Long datasetId, String uploadDivi); UploadDto.uploadDto findByDatasetUid(Long datasetId, String uploadDivi);
UploadDto.uploadDto findByUuid(UUID uuid); UploadDto.uploadDto findByUuid(UUID uuid);
void updateUploadSessionStatus(UploadDto.UploadAddReq addReq); void updateUploadSessionStatus(UploadDto.UploadAddReq addReq);
} }

View File

@@ -1,6 +1,5 @@
package com.kamco.cd.kamcoback.postgres.repository.upload; package com.kamco.cd.kamcoback.postgres.repository.upload;
import static com.kamco.cd.kamcoback.postgres.entity.QUploadSessionEntity.uploadSessionEntity; import static com.kamco.cd.kamcoback.postgres.entity.QUploadSessionEntity.uploadSessionEntity;
import com.kamco.cd.kamcoback.postgres.entity.UploadSessionEntity; import com.kamco.cd.kamcoback.postgres.entity.UploadSessionEntity;
@@ -30,113 +29,104 @@ public class UploadSessionRepositoryImpl extends QuerydslRepositorySupport
@Override @Override
public void insertUploadSession(UploadDto.UploadAddReq addReq) { public void insertUploadSession(UploadDto.UploadAddReq addReq) {
long execCnt = long execCnt =
queryFactory queryFactory
.insert(uploadSessionEntity) .insert(uploadSessionEntity)
.columns( .columns(
uploadSessionEntity.uploadId, uploadSessionEntity.uploadId,
uploadSessionEntity.datasetId, uploadSessionEntity.datasetId,
uploadSessionEntity.fileName, uploadSessionEntity.fileName,
uploadSessionEntity.fileSize, uploadSessionEntity.fileSize,
uploadSessionEntity.finalPath, uploadSessionEntity.finalPath,
uploadSessionEntity.status, uploadSessionEntity.status,
uploadSessionEntity.tempPath, uploadSessionEntity.tempPath,
uploadSessionEntity.chunkIndex, uploadSessionEntity.chunkIndex,
uploadSessionEntity.chunkTotalIndex, uploadSessionEntity.chunkTotalIndex,
uploadSessionEntity.uploadDivi, uploadSessionEntity.uploadDivi,
uploadSessionEntity.fileHash, uploadSessionEntity.fileHash,
uploadSessionEntity.uuid uploadSessionEntity.uuid)
) .values(
.values( addReq.getUploadId(),
addReq.getUploadId(), addReq.getDatasetId(),
addReq.getDatasetId(), addReq.getFileName(),
addReq.getFileName(), addReq.getFileSize(),
addReq.getFileSize(), addReq.getFinalPath(),
addReq.getFinalPath(), addReq.getStatus(),
addReq.getStatus(), addReq.getTempPath(),
addReq.getTempPath(), addReq.getChunkIndex(),
addReq.getChunkIndex(), addReq.getChunkTotalIndex(),
addReq.getChunkTotalIndex(), addReq.getUploadDivi(),
addReq.getUploadDivi(), addReq.getFileHash(),
addReq.getFileHash(), addReq.getUuid())
addReq.getUuid() .execute();
)
.execute();
} }
@Override @Override
public UploadDto.uploadDto findByDatasetUid(Long datasetId, String uploadDivi) { public UploadDto.uploadDto findByDatasetUid(Long datasetId, String uploadDivi) {
UploadDto.uploadDto foundContent = UploadDto.uploadDto foundContent =
queryFactory queryFactory
.select( .select(
Projections.constructor( Projections.constructor(
UploadDto.uploadDto.class, UploadDto.uploadDto.class,
uploadSessionEntity.uploadId, uploadSessionEntity.uploadId,
uploadSessionEntity.datasetId, uploadSessionEntity.datasetId,
uploadSessionEntity.fileName, uploadSessionEntity.fileName,
uploadSessionEntity.fileSize, uploadSessionEntity.fileSize,
uploadSessionEntity.finalPath, uploadSessionEntity.finalPath,
uploadSessionEntity.uploadDivi, uploadSessionEntity.uploadDivi,
uploadSessionEntity.status, uploadSessionEntity.status,
uploadSessionEntity.tempPath, uploadSessionEntity.tempPath,
uploadSessionEntity.chunkIndex, uploadSessionEntity.chunkIndex,
uploadSessionEntity.chunkTotalIndex, uploadSessionEntity.chunkTotalIndex,
uploadSessionEntity.fileHash, uploadSessionEntity.fileHash,
uploadSessionEntity.uuid uploadSessionEntity.uuid))
)) .from(uploadSessionEntity)
.from(uploadSessionEntity) .where(
.where(uploadSessionEntity.datasetId.eq(datasetId) uploadSessionEntity
.and(uploadSessionEntity.uploadDivi.eq(uploadDivi))) .datasetId
.limit(1) .eq(datasetId)
.fetchOne(); .and(uploadSessionEntity.uploadDivi.eq(uploadDivi)))
.limit(1)
.fetchOne();
return foundContent; return foundContent;
} }
@Override @Override
public UploadDto.uploadDto findByUuid(UUID uuid) { public UploadDto.uploadDto findByUuid(UUID uuid) {
UploadDto.uploadDto foundContent = UploadDto.uploadDto foundContent =
queryFactory queryFactory
.select( .select(
Projections.constructor( Projections.constructor(
UploadDto.uploadDto.class, UploadDto.uploadDto.class,
uploadSessionEntity.uploadId, uploadSessionEntity.uploadId,
uploadSessionEntity.datasetId, uploadSessionEntity.datasetId,
uploadSessionEntity.fileName, uploadSessionEntity.fileName,
uploadSessionEntity.fileSize, uploadSessionEntity.fileSize,
uploadSessionEntity.finalPath, uploadSessionEntity.finalPath,
uploadSessionEntity.uploadDivi, uploadSessionEntity.uploadDivi,
uploadSessionEntity.status, uploadSessionEntity.status,
uploadSessionEntity.tempPath, uploadSessionEntity.tempPath,
uploadSessionEntity.chunkIndex, uploadSessionEntity.chunkIndex,
uploadSessionEntity.chunkTotalIndex, uploadSessionEntity.chunkTotalIndex,
uploadSessionEntity.fileHash, uploadSessionEntity.fileHash,
uploadSessionEntity.uuid uploadSessionEntity.uuid))
)) .from(uploadSessionEntity)
.from(uploadSessionEntity) .where(uploadSessionEntity.uuid.eq(uuid))
.where(uploadSessionEntity.uuid.eq(uuid)) .limit(1)
.limit(1) .fetchOne();
.fetchOne();
return foundContent; return foundContent;
} }
public void updateUploadSessionStatus(UploadDto.UploadAddReq addReq) {
public void updateUploadSessionStatus(UploadDto.UploadAddReq addReq){
long fileCount = long fileCount =
queryFactory queryFactory
.update(uploadSessionEntity) .update(uploadSessionEntity)
.set(uploadSessionEntity.chunkIndex, addReq.getChunkIndex()) .set(uploadSessionEntity.chunkIndex, addReq.getChunkIndex())
.set(uploadSessionEntity.status, addReq.getStatus()) .set(uploadSessionEntity.status, addReq.getStatus())
.where(uploadSessionEntity.uploadId.eq(addReq.getUploadId())) .where(uploadSessionEntity.uploadId.eq(addReq.getUploadId()))
.execute(); .execute();
} }
} }

View File

@@ -81,13 +81,13 @@ public class UploadApiController {
}) })
@PostMapping(value = "/file-chunk-upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(value = "/file-chunk-upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ApiResponseDto<UploadDto.UploadRes> fileChunkUpload( public ApiResponseDto<UploadDto.UploadRes> fileChunkUpload(
@RequestParam("uuid") UUID uuid, @RequestParam("uuid") UUID uuid,
@RequestParam("fileName") String fileName, @RequestParam("fileName") String fileName,
@RequestParam("fileSize") long fileSize, @RequestParam("fileSize") long fileSize,
// @RequestParam("fileHash") String fileHash, // @RequestParam("fileHash") String fileHash,
@RequestParam("chunkIndex") Integer chunkIndex, @RequestParam("chunkIndex") Integer chunkIndex,
@RequestParam("chunkTotalIndex") Integer chunkTotalIndex, @RequestParam("chunkTotalIndex") Integer chunkTotalIndex,
@RequestPart("chunkFile") MultipartFile chunkFile) { @RequestPart("chunkFile") MultipartFile chunkFile) {
String uploadDivi = "dataset"; String uploadDivi = "dataset";
@@ -102,7 +102,7 @@ public class UploadApiController {
upAddReqDto.setFinalPath(datasetDir); upAddReqDto.setFinalPath(datasetDir);
upAddReqDto.setTempPath(datasetTmpDir); upAddReqDto.setTempPath(datasetTmpDir);
System.out.println("uuid === "+ uuid); System.out.println("uuid === " + uuid);
return ApiResponseDto.ok(uploadService.uploadChunk(upAddReqDto, chunkFile)); return ApiResponseDto.ok(uploadService.uploadChunk(upAddReqDto, chunkFile));
} }
@@ -116,8 +116,7 @@ public class UploadApiController {
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
}) })
@PutMapping("/chunk-upload-complete/{uuid}") @PutMapping("/chunk-upload-complete/{uuid}")
public ApiResponseDto<UploadDto.UploadRes> completeUpload( public ApiResponseDto<UploadDto.UploadRes> completeUpload(@PathVariable UUID uuid) {
@PathVariable UUID uuid) {
return ApiResponseDto.ok(uploadService.completeUpload(uuid)); return ApiResponseDto.ok(uploadService.completeUpload(uuid));
} }

View File

@@ -74,8 +74,8 @@ public class UploadDto {
private Integer chunkTotalIndex; private Integer chunkTotalIndex;
@Schema( @Schema(
description = "파일해쉬", description = "파일해쉬",
example = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") example = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
private String fileHash; private String fileHash;
@Schema(description = "uuid", example = "303d4e24-1726-4272-bbc7-01ab85692b80") @Schema(description = "uuid", example = "303d4e24-1726-4272-bbc7-01ab85692b80")
@@ -153,7 +153,6 @@ public class UploadDto {
@Schema(description = "파일명", example = "data.zip") @Schema(description = "파일명", example = "data.zip")
private String fileName; private String fileName;
@Schema(description = "파일 크기 (bytes)", example = "10737418240") @Schema(description = "파일 크기 (bytes)", example = "10737418240")
private Long fileSize; private Long fileSize;
@@ -175,15 +174,13 @@ public class UploadDto {
@Schema(description = "총 청크 Index", example = "100") @Schema(description = "총 청크 Index", example = "100")
private Integer chunkTotalIndex; private Integer chunkTotalIndex;
@Schema( @Schema(
description = "파일해쉬", description = "파일해쉬",
example = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") example = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
private String fileHash; private String fileHash;
@Schema(description = "uuid") @Schema(description = "uuid")
private UUID uuid; private UUID uuid;
} }
@Schema(name = "UploadRes", description = "업로드 수행 후 리턴") @Schema(name = "UploadRes", description = "업로드 수행 후 리턴")
@@ -204,13 +201,10 @@ public class UploadDto {
if (this.chunkTotalIndex == 0) { if (this.chunkTotalIndex == 0) {
return 0.0; return 0.0;
} }
return (double) (this.chunkIndex+1) / (this.chunkTotalIndex+1) * 100.0; return (double) (this.chunkIndex + 1) / (this.chunkTotalIndex + 1) * 100.0;
} }
} }
@Schema(name = "DmlReturn", description = "수행 후 리턴") @Schema(name = "DmlReturn", description = "수행 후 리턴")
@Getter @Getter
@Setter @Setter

View File

@@ -59,17 +59,17 @@ public class UploadService {
UploadDto.UploadRes upRes = new UploadDto.UploadRes(); UploadDto.UploadRes upRes = new UploadDto.UploadRes();
long datasetId = 0; long datasetId = 0;
if( upAddReqDto.getDatasetId() != null )datasetId = upAddReqDto.getDatasetId(); if (upAddReqDto.getDatasetId() != null) datasetId = upAddReqDto.getDatasetId();
String uploadId = System.currentTimeMillis()+""; String uploadId = System.currentTimeMillis() + "";
//UUID uuid = UUID.randomUUID(); // UUID uuid = UUID.randomUUID();
UUID uuid = upAddReqDto.getUuid(); UUID uuid = upAddReqDto.getUuid();
String tmpDataSetDir = upAddReqDto.getTempPath()+uuid; String tmpDataSetDir = upAddReqDto.getTempPath() + uuid;
String fianlDir = upAddReqDto.getFinalPath()+uuid; String fianlDir = upAddReqDto.getFinalPath() + uuid;
String uploadDivi = upAddReqDto.getUploadDivi(); String uploadDivi = upAddReqDto.getUploadDivi();
//String fileName = file.getOriginalFilename(); // String fileName = file.getOriginalFilename();
String fileName = upAddReqDto.getFileName(); String fileName = upAddReqDto.getFileName();
Integer chunkIndex = upAddReqDto.getChunkIndex(); Integer chunkIndex = upAddReqDto.getChunkIndex();
Integer chunkTotalIndex = upAddReqDto.getChunkTotalIndex(); Integer chunkTotalIndex = upAddReqDto.getChunkTotalIndex();
String status = FileUploadStatus.INIT.name(); String status = FileUploadStatus.INIT.name();
upRes.setUuid(uuid); upRes.setUuid(uuid);
@@ -83,37 +83,33 @@ public class UploadService {
upAddReqDto.setTempPath(tmpDataSetDir); upAddReqDto.setTempPath(tmpDataSetDir);
upAddReqDto.setFinalPath(fianlDir); upAddReqDto.setFinalPath(fianlDir);
//세션 신규,중복체크(초기화 포함) // 세션 신규,중복체크(초기화 포함)
UploadDto.uploadDto dto = this.checkUploadSession(upAddReqDto, upRes); UploadDto.uploadDto dto = this.checkUploadSession(upAddReqDto, upRes);
if( !upRes.getRes().equals("success") )return upRes; if (!upRes.getRes().equals("success")) return upRes;
status = FileUploadStatus.UPLOADING.name(); status = FileUploadStatus.UPLOADING.name();
upAddReqDto.setStatus(status); upAddReqDto.setStatus(status);
if( dto != null ) if (dto != null) {
{ tmpDataSetDir = dto.getTempPath();
tmpDataSetDir = dto.getTempPath();
fianlDir = dto.getFinalPath(); fianlDir = dto.getFinalPath();
} }
//폴더 생성 및 체크 // 폴더 생성 및 체크
if( ! checkChunkFoler(upRes, tmpDataSetDir, fianlDir) )return upRes; if (!checkChunkFoler(upRes, tmpDataSetDir, fianlDir)) return upRes;
//chunk저장하기 // chunk저장하기
if( ! FIleChecker.multipartChunkSaveTo(file, tmpDataSetDir, chunkIndex ) ) if (!FIleChecker.multipartChunkSaveTo(file, tmpDataSetDir, chunkIndex)) {
{
upRes.setRes("fail"); upRes.setRes("fail");
upRes.setResMsg("chunkIndex:"+chunkIndex+" 업로드 애러"); upRes.setResMsg("chunkIndex:" + chunkIndex + " 업로드 애러");
} }
if( chunkIndex == chunkTotalIndex ) { if (chunkIndex == chunkTotalIndex) {
upAddReqDto.setUploadId(dto.getUploadId()); upAddReqDto.setUploadId(dto.getUploadId());
upAddReqDto.setStatus(FileUploadStatus.DONE.name()); upAddReqDto.setStatus(FileUploadStatus.DONE.name());
uploadSessionCoreService.updateUploadSessionStatus(upAddReqDto); uploadSessionCoreService.updateUploadSessionStatus(upAddReqDto);
try { try {
this.mergeChunks(tmpDataSetDir, fianlDir, fileName, chunkTotalIndex); this.mergeChunks(tmpDataSetDir, fianlDir, fileName, chunkTotalIndex);
@@ -122,14 +118,11 @@ public class UploadService {
uploadSessionCoreService.updateUploadSessionStatus(upAddReqDto); uploadSessionCoreService.updateUploadSessionStatus(upAddReqDto);
} catch (IOException e) { } catch (IOException e) {
//throw new RuntimeException(e); // throw new RuntimeException(e);
upRes.setRes("fail"); upRes.setRes("fail");
upRes.setResMsg("파일Chunk 병합(merge) 애러"); upRes.setResMsg("파일Chunk 병합(merge) 애러");
return upRes; return upRes;
} }
} }
return upRes; return upRes;
@@ -149,7 +142,8 @@ public class UploadService {
upRes.setChunkTotalIndex(dto.getChunkTotalIndex()); upRes.setChunkTotalIndex(dto.getChunkTotalIndex());
try { try {
this.mergeChunks(dto.getTempPath(), dto.getFinalPath(), dto.getFileName(), dto.getChunkTotalIndex()); this.mergeChunks(
dto.getTempPath(), dto.getFinalPath(), dto.getFileName(), dto.getChunkTotalIndex());
} catch (IOException e) { } catch (IOException e) {
upRes.setRes("fail"); upRes.setRes("fail");
@@ -159,21 +153,17 @@ public class UploadService {
} }
return upRes; return upRes;
} }
public boolean checkChunkFoler(UploadDto.UploadRes upRes, String tmpDataSetDir, String fianlDir) public boolean checkChunkFoler(UploadDto.UploadRes upRes, String tmpDataSetDir, String fianlDir) {
{
if( ! FIleChecker.mkDir(tmpDataSetDir) ) if (!FIleChecker.mkDir(tmpDataSetDir)) {
{
upRes.setRes("fail"); upRes.setRes("fail");
upRes.setRes("CHUNK 폴더 생성 ERROR"); upRes.setRes("CHUNK 폴더 생성 ERROR");
return false; return false;
} }
if( ! FIleChecker.mkDir(fianlDir) ) if (!FIleChecker.mkDir(fianlDir)) {
{
upRes.setRes("fail"); upRes.setRes("fail");
upRes.setRes("업로드 완료 폴더 생성 ERROR"); upRes.setRes("업로드 완료 폴더 생성 ERROR");
return false; return false;
@@ -182,28 +172,26 @@ public class UploadService {
return true; return true;
} }
public UploadDto.uploadDto checkUploadSession(
public UploadDto.uploadDto checkUploadSession(UploadDto.UploadAddReq upAddReqDto, UploadDto.UploadRes upRes) { UploadDto.UploadAddReq upAddReqDto, UploadDto.UploadRes upRes) {
upRes.setRes("success"); upRes.setRes("success");
upRes.setResMsg("정상처리되었습니다."); upRes.setResMsg("정상처리되었습니다.");
UploadDto.uploadDto dto = uploadSessionCoreService.findByUuid(upAddReqDto.getUuid()); UploadDto.uploadDto dto = uploadSessionCoreService.findByUuid(upAddReqDto.getUuid());
if( upAddReqDto.getChunkIndex() == 0 ) { if (upAddReqDto.getChunkIndex() == 0) {
if( dto != null ) if (dto != null) {
{
upRes.setRes("duplicate"); upRes.setRes("duplicate");
upRes.setResMsg("이미 진행중인 업로드세션입니다."); upRes.setResMsg("이미 진행중인 업로드세션입니다.");
return dto; return dto;
} }
upAddReqDto.setStatus("UPLOADING"); upAddReqDto.setStatus("UPLOADING");
upRes.setUuid( upAddReqDto.getUuid() ); upRes.setUuid(upAddReqDto.getUuid());
uploadSessionCoreService.createUploadSession(upAddReqDto); uploadSessionCoreService.createUploadSession(upAddReqDto);
} } else {
else { if (dto == null) {
if( dto == null ){
upRes.setRes("nosession"); upRes.setRes("nosession");
upRes.setResMsg("업로드 세션이 존재하지 않습니다."); upRes.setResMsg("업로드 세션이 존재하지 않습니다.");
return dto; return dto;
@@ -214,22 +202,22 @@ public class UploadService {
uploadSessionCoreService.updateUploadSessionStatus(upAddReqDto); uploadSessionCoreService.updateUploadSessionStatus(upAddReqDto);
} }
if( dto != null )upRes.setUuid( dto.getUuid() ); if (dto != null) upRes.setUuid(dto.getUuid());
upRes.setChunkIndex(upAddReqDto.getChunkIndex()); upRes.setChunkIndex(upAddReqDto.getChunkIndex());
upRes.setChunkTotalIndex(upAddReqDto.getChunkTotalIndex()); upRes.setChunkTotalIndex(upAddReqDto.getChunkTotalIndex());
return dto; return dto;
} }
public void mergeChunks(String tmpDir, String fianlDir, String fileName, int chunkTotalIndex) throws IOException { public void mergeChunks(String tmpDir, String fianlDir, String fileName, int chunkTotalIndex)
throws IOException {
Path outputPath = Paths.get(fianlDir, fileName); Path outputPath = Paths.get(fianlDir, fileName);
try (FileChannel outChannel = FileChannel.open(outputPath, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) { try (FileChannel outChannel =
FileChannel.open(outputPath, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
for (int i = 0; i <= chunkTotalIndex; i++) { for (int i = 0; i <= chunkTotalIndex; i++) {
Path chunkPath = Paths.get(tmpDir, i+""); Path chunkPath = Paths.get(tmpDir, i + "");
try (FileChannel inChannel = FileChannel.open(chunkPath, StandardOpenOption.READ)) { try (FileChannel inChannel = FileChannel.open(chunkPath, StandardOpenOption.READ)) {
long transferred = 0; long transferred = 0;
@@ -243,10 +231,7 @@ public class UploadService {
} }
} }
//병합후 임시 폴더 삭제 // 병합후 임시 폴더 삭제
FIleChecker.deleteFolder(tmpDir); FIleChecker.deleteFolder(tmpDir);
} }
} }