From b00df327229529dfdaa2843bf7030091d805d39b Mon Sep 17 00:00:00 2001 From: "LAPTOP-L3VE7KK2\\USER" Date: Fri, 6 Dec 2024 15:52:54 +0900 Subject: [PATCH] =?UTF-8?q?=EB=AC=BC=EA=B1=B4=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20API=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interplug/qcast/biz/file/FileService.java | 68 ++++++++++--------- .../qcast/biz/file/dto/FileRequest.java | 4 +- .../resources/mappers/object/objectMapper.xml | 2 +- 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/interplug/qcast/biz/file/FileService.java b/src/main/java/com/interplug/qcast/biz/file/FileService.java index 33e0cae2..804ac5a6 100644 --- a/src/main/java/com/interplug/qcast/biz/file/FileService.java +++ b/src/main/java/com/interplug/qcast/biz/file/FileService.java @@ -219,6 +219,8 @@ public class FileService { HttpServletRequest request, HttpServletResponse response, FileRequest fileRequest) throws Exception { + System.out.println("fileRequest>>>" + fileRequest.toString()); + // 필수값 체크 if (fileRequest.getObjectNo() == null || fileRequest.getObjectNo().isEmpty()) { throw new QcastException( @@ -236,42 +238,46 @@ public class FileService { ErrorCode.NOT_FOUND, message.getMessage(" common.message.file.download.exists")); } - // 첨부파일 물리적 경로 - String strSeparator = File.separator; - String filePath = baseDirPath + strSeparator + fileResponse.getObjectNo(); - if (fileResponse.getPlanNo() != null && !fileResponse.getPlanNo().isEmpty()) { - filePath += strSeparator + fileResponse.getPlanNo(); - } - filePath += strSeparator + fileResponse.getFaileName(); + try { + // 첨부파일 물리적 경로 + String strSeparator = File.separator; + String filePath = baseDirPath + strSeparator + fileResponse.getObjectNo(); + if (fileResponse.getPlanNo() != null && !fileResponse.getPlanNo().isEmpty()) { + filePath += strSeparator + fileResponse.getPlanNo(); + } + filePath += strSeparator + fileResponse.getFaileName(); - File file = new File(filePath); - if (!file.exists()) { - log.error("### File not found: {}", filePath); - throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR); - } + File file = new File(filePath); + if (!file.exists()) { + log.error("### File not found: {}", filePath); + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR); + } - String mimeType = URLConnection.guessContentTypeFromName(file.getName()); - if (mimeType == null) { - mimeType = "application/octet-stream"; - } + String mimeType = URLConnection.guessContentTypeFromName(file.getName()); + if (mimeType == null) { + mimeType = "application/octet-stream"; + } - String originalFileName = fileResponse.getFaileName(); - String encodedFileName = - URLEncoder.encode(originalFileName, StandardCharsets.UTF_8).replaceAll("\\+", "%20"); + String originalFileName = fileResponse.getFaileName(); + String encodedFileName = + URLEncoder.encode(originalFileName, StandardCharsets.UTF_8).replaceAll("\\+", "%20"); - response.setHeader("Content-Transfer-Encoding", "binary;"); - response.setHeader("Pragma", "no-cache;"); - response.setHeader("Expires", "-1;"); - response.setHeader("Content-Disposition", "attachment; filename=\"" + encodedFileName + "\""); - response.setContentType(mimeType); - response.setContentLength((int) file.length()); + response.setHeader("Content-Transfer-Encoding", "binary;"); + response.setHeader("Pragma", "no-cache;"); + response.setHeader("Expires", "-1;"); + response.setHeader("Content-Disposition", "attachment; filename=\"" + encodedFileName + "\""); + response.setContentType(mimeType); + response.setContentLength((int) file.length()); - try (InputStream inputStream = new BufferedInputStream(new FileInputStream(file))) { - FileCopyUtils.copy(inputStream, response.getOutputStream()); - } catch (IOException e) { - throw new QcastException( - ErrorCode.INTERNAL_SERVER_ERROR, - message.getMessage("common.message.file.download.error")); + try (InputStream inputStream = new BufferedInputStream(new FileInputStream(file))) { + FileCopyUtils.copy(inputStream, response.getOutputStream()); + } catch (IOException e) { + throw new QcastException( + ErrorCode.INTERNAL_SERVER_ERROR, + message.getMessage("common.message.file.download.error")); + } + } catch (Exception e) { + e.printStackTrace(); } } diff --git a/src/main/java/com/interplug/qcast/biz/file/dto/FileRequest.java b/src/main/java/com/interplug/qcast/biz/file/dto/FileRequest.java index 52f125b8..713cf497 100644 --- a/src/main/java/com/interplug/qcast/biz/file/dto/FileRequest.java +++ b/src/main/java/com/interplug/qcast/biz/file/dto/FileRequest.java @@ -30,6 +30,6 @@ public class FileRequest { @Schema(description = "zip 파일 이름") private String zipFileName; - @Schema(description = "planNo null 체크 Flag (NULL=1, NOT NULL=0)", defaultValue = "1") - private String planNoNullChkFlg = "1"; + @Schema(description = "planNo null 체크 Flag (NULL=1, NOT NULL=0)") + private String planNoNullChkFlg; } diff --git a/src/main/resources/mappers/object/objectMapper.xml b/src/main/resources/mappers/object/objectMapper.xml index f6b9840b..da0e2abf 100644 --- a/src/main/resources/mappers/object/objectMapper.xml +++ b/src/main/resources/mappers/object/objectMapper.xml @@ -644,7 +644,7 @@ /* sqlid : com.interplug.qcast.biz.object.deleteObject */ UPDATE T_OBJECT SET - DEL_FLG = '1' + ORG_DEL_FLG = '1' , TEMP_DEL_FLG = '1' , LAST_EDIT_DATETIME = GETDATE() , LAST_EDIT_USER = #{userId}