|
|
|
|
@ -15,9 +15,17 @@ import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@ -35,7 +43,6 @@ public class ListenerService {
|
|
|
|
|
ackDto = AckDto.builder().result(AckDto.ResultType.RECEIVE_FAIL).resultText("금일 전송한 메시지 중 중복된 UUID가 존재합니다.").build();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
//receiveMessageDto.setProcessStatus();
|
|
|
|
|
dropBoxService.add(receiveMessageDto);
|
|
|
|
|
ackDto = AckDto.builder().result(AckDto.ResultType.RECEIVE_SUCCESS).build();
|
|
|
|
|
}
|
|
|
|
|
@ -67,12 +74,32 @@ public class ListenerService {
|
|
|
|
|
firstPart = iterator.next();
|
|
|
|
|
String messageJsonString = new String(firstPart.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
|
|
|
|
ReceiveMessageDto receiveMessageDto = MessageUtils.toReceiveMessageDto(messageJsonString);
|
|
|
|
|
// DropBox(수신설정) 가져오기
|
|
|
|
|
AgentConfigDto.DropBox dropBox = agentConfigReader.getDropBox(receiveMessageDto.getRecipientDropBoxId());
|
|
|
|
|
// DropBox 의 경로에 따라서 파일 저장 위치 설정
|
|
|
|
|
String saveDirectoryRoot = dropBox.getSaveDirectoryRoot();
|
|
|
|
|
Date today = new Date(System.currentTimeMillis());
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd/hh/mm/ss");
|
|
|
|
|
String targetDirectoryString = saveDirectoryRoot + "/" + dateFormat.format(today);
|
|
|
|
|
File targetDirectory = new File(targetDirectoryString);
|
|
|
|
|
if(!targetDirectory.exists()) {
|
|
|
|
|
targetDirectory.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
byte[] buff = new byte[4096];
|
|
|
|
|
while(iterator.hasNext()) {
|
|
|
|
|
// 파일 수신 처리
|
|
|
|
|
Part part = iterator.next();
|
|
|
|
|
//TODO 파일 수신 처리
|
|
|
|
|
String fileName = part.getSubmittedFileName();
|
|
|
|
|
String targetFilePath = targetDirectoryString + "/" + fileName;
|
|
|
|
|
Path targetPath = Paths.get(targetDirectoryString, fileName);
|
|
|
|
|
try(InputStream inputStream = part.getInputStream()) {
|
|
|
|
|
Files.copy(inputStream, targetPath, StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
|
}
|
|
|
|
|
receiveMessageDto.getAttachFileList().add(targetFilePath);
|
|
|
|
|
}
|
|
|
|
|
// 수신 정보를 queue 에 저장하고 Ack 설정
|
|
|
|
|
dropBoxService.add(receiveMessageDto);
|
|
|
|
|
ackDto = AckDto.builder().result(AckDto.ResultType.RECEIVE_SUCCESS).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(IllegalMessageException | IOException | InCompleteMessageException | NullMessageException e) {
|
|
|
|
|
|