From 4cbca6fdf16767e5121f1ea79bf4af3897d49631 Mon Sep 17 00:00:00 2001 From: Kang Jung Kyo Date: Tue, 24 Sep 2024 16:33:56 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B3=B4=EC=A6=9D=EC=84=9C=20=EB=B0=9C?= =?UTF-8?q?=ED=96=89=20=EC=99=84=EB=A3=8C=20=EB=AC=BC=EA=B1=B4=20=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=8B=A4=EC=9A=B4=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/excelDown/ExcelDownController.java | 80 +++++++++++------- .../qcast/biz/excelDown/ExcelDownMapper.java | 25 ++++-- .../qcast/biz/excelDown/ExcelDownService.java | 82 +++++++++++++++---- .../dto/WrntIsncCmplFileResponse.java | 18 ++++ .../interplug/qcast/util/ZipFileManager.java | 31 ++++--- .../mappers/excelDown/excelDownMapper.xml | 20 +++++ 6 files changed, 194 insertions(+), 62 deletions(-) create mode 100644 src/main/java/com/interplug/qcast/biz/excelDown/dto/WrntIsncCmplFileResponse.java diff --git a/src/main/java/com/interplug/qcast/biz/excelDown/ExcelDownController.java b/src/main/java/com/interplug/qcast/biz/excelDown/ExcelDownController.java index 531a83fd..4b86b008 100644 --- a/src/main/java/com/interplug/qcast/biz/excelDown/ExcelDownController.java +++ b/src/main/java/com/interplug/qcast/biz/excelDown/ExcelDownController.java @@ -1,14 +1,25 @@ package com.interplug.qcast.biz.excelDown; -import com.interplug.qcast.biz.excelDown.dto.*; +import java.util.List; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; +import com.interplug.qcast.biz.excelDown.dto.NtrCtsCmpRequest; +import com.interplug.qcast.biz.excelDown.dto.NtrCtsCmpResponse; +import com.interplug.qcast.biz.excelDown.dto.QuotItemResponse; +import com.interplug.qcast.biz.excelDown.dto.QuotPlanResponse; +import com.interplug.qcast.biz.excelDown.dto.QuotRequest; +import com.interplug.qcast.biz.excelDown.dto.QuotResponse; +import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplRequest; +import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; - -import java.util.List; @Slf4j @RestController @@ -16,36 +27,47 @@ import java.util.List; @RequiredArgsConstructor @Tag(name = "ExcelDownController", description = "과거데이터 엑셀다운로드 API") public class ExcelDownController { - private final ExcelDownService excelDownService; + private final ExcelDownService excelDownService; - @Operation(description = "과거데이터_견적 엑셀다운로드 조회") - @PostMapping("/quot-excl-down-data") - @ResponseStatus(HttpStatus.OK) - public QuotResponse quotExclDownData(@RequestBody QuotRequest quotRequest) throws Exception { + @Operation(description = "과거데이터_견적 엑셀다운로드 조회") + @PostMapping("/quot-excl-down-data") + @ResponseStatus(HttpStatus.OK) + public QuotResponse quotExclDownData(@RequestBody QuotRequest quotRequest) throws Exception { - List quotPlanExclDownData = excelDownService.selectQuotPlanExclDownData(quotRequest); - List quotItemExclDownData = excelDownService.selectQuotItemExclDownData(quotRequest); + List quotPlanExclDownData = + excelDownService.selectQuotPlanExclDownData(quotRequest); + List quotItemExclDownData = + excelDownService.selectQuotItemExclDownData(quotRequest); - QuotResponse quotRes = new QuotResponse(); - quotRes.setQuotPlanList(quotPlanExclDownData); - quotRes.setQuotItemList(quotItemExclDownData); + QuotResponse quotRes = new QuotResponse(); + quotRes.setQuotPlanList(quotPlanExclDownData); + quotRes.setQuotItemList(quotItemExclDownData); - return quotRes; - } + return quotRes; + } - @Operation(description = "과거데이터_자연재해보상입력 엑셀다운로드 조회") - @PostMapping("/ntr-cts-cmp-excl-down-data") - @ResponseStatus(HttpStatus.OK) - public List ntrCtsCmpExclDownData(@RequestBody NtrCtsCmpRequest ntrCtsCmpRequest) throws Exception { - return excelDownService.selectNtrCtsCmpExclDownData(ntrCtsCmpRequest); - } + @Operation(description = "과거데이터_자연재해보상입력 엑셀다운로드 조회") + @PostMapping("/ntr-cts-cmp-excl-down-data") + @ResponseStatus(HttpStatus.OK) + public List ntrCtsCmpExclDownData( + @RequestBody NtrCtsCmpRequest ntrCtsCmpRequest) throws Exception { + return excelDownService.selectNtrCtsCmpExclDownData(ntrCtsCmpRequest); + } - @Operation(description = "과거데이터_보증서발행완료 물건 엑셀다운로드 조회") - @PostMapping("/wrnt-isnc-cmpl-excl-down-data") - @ResponseStatus(HttpStatus.OK) - public List warrantyIssuedCmpExclDownData(@RequestBody WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception { - return excelDownService.selectWarrantyIssuedCmpExclDownData(wrntIsncCmplRequest); - } + @Operation(description = "과거데이터_보증서발행완료 물건 엑셀다운로드 조회") + @PostMapping("/wrnt-isnc-cmpl-excl-down-data") + @ResponseStatus(HttpStatus.OK) + public List warrantyIssuedCmpExclDownData( + @RequestBody WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception { + return excelDownService.selectWarrantyIssuedCmpExclDownData(wrntIsncCmplRequest); + } + @Operation(description = "과거데이터_보증서발행완료 물건 파일 다운로드 조회") + @PostMapping("/wrnt-isnc-cmpl-file-down") + @ResponseStatus(HttpStatus.OK) + public void warrantyIssuedCmpFileDown(@RequestBody WrntIsncCmplRequest wrntIsncCmplRequest, + HttpServletResponse response) throws Exception { + excelDownService.selectWarrantyIssuedCmpFileData(wrntIsncCmplRequest, response); + } } diff --git a/src/main/java/com/interplug/qcast/biz/excelDown/ExcelDownMapper.java b/src/main/java/com/interplug/qcast/biz/excelDown/ExcelDownMapper.java index 094ac172..580272a4 100644 --- a/src/main/java/com/interplug/qcast/biz/excelDown/ExcelDownMapper.java +++ b/src/main/java/com/interplug/qcast/biz/excelDown/ExcelDownMapper.java @@ -1,17 +1,28 @@ package com.interplug.qcast.biz.excelDown; -import com.interplug.qcast.biz.excelDown.dto.*; -import org.apache.ibatis.annotations.Mapper; - import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import com.interplug.qcast.biz.excelDown.dto.NtrCtsCmpRequest; +import com.interplug.qcast.biz.excelDown.dto.NtrCtsCmpResponse; +import com.interplug.qcast.biz.excelDown.dto.QuotItemResponse; +import com.interplug.qcast.biz.excelDown.dto.QuotPlanResponse; +import com.interplug.qcast.biz.excelDown.dto.QuotRequest; +import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplFileResponse; +import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplRequest; +import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplResponse; @Mapper interface ExcelDownMapper { - List selectQuotPlanExclDownData(QuotRequest quotRequest) throws Exception; + List selectQuotPlanExclDownData(QuotRequest quotRequest) throws Exception; - List selectQuotItemExclDownData(QuotRequest quotRequest) throws Exception; + List selectQuotItemExclDownData(QuotRequest quotRequest) throws Exception; - List selectNtrCtsCmpExclDownData(NtrCtsCmpRequest ntrCtsCmpRequest) throws Exception; + List selectNtrCtsCmpExclDownData(NtrCtsCmpRequest ntrCtsCmpRequest) + throws Exception; - List selectWarrantyIssuedCmpExclDownData(WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception; + List selectWarrantyIssuedCmpExclDownData( + WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception; + + List selectWarrantyIssuedCmpFileData( + WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception; } diff --git a/src/main/java/com/interplug/qcast/biz/excelDown/ExcelDownService.java b/src/main/java/com/interplug/qcast/biz/excelDown/ExcelDownService.java index 939cd6b8..f2e2e7fc 100644 --- a/src/main/java/com/interplug/qcast/biz/excelDown/ExcelDownService.java +++ b/src/main/java/com/interplug/qcast/biz/excelDown/ExcelDownService.java @@ -1,31 +1,81 @@ package com.interplug.qcast.biz.excelDown; -import com.interplug.qcast.biz.excelDown.dto.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import com.interplug.qcast.biz.excelDown.dto.NtrCtsCmpRequest; +import com.interplug.qcast.biz.excelDown.dto.NtrCtsCmpResponse; +import com.interplug.qcast.biz.excelDown.dto.QuotItemResponse; +import com.interplug.qcast.biz.excelDown.dto.QuotPlanResponse; +import com.interplug.qcast.biz.excelDown.dto.QuotRequest; +import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplFileResponse; +import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplRequest; +import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplResponse; +import com.interplug.qcast.config.Exception.BaseException; +import com.interplug.qcast.config.message.Messages; +import com.interplug.qcast.util.ZipFileManager; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.List; @Slf4j @Service @RequiredArgsConstructor public class ExcelDownService { - private final ExcelDownMapper excelDownMapper; + private final ExcelDownMapper excelDownMapper; - public List selectQuotPlanExclDownData(QuotRequest quotRequest) throws Exception { - return excelDownMapper.selectQuotPlanExclDownData(quotRequest); - } + private final ZipFileManager zipFileManager; - public List selectQuotItemExclDownData(QuotRequest quotRequest) throws Exception { - return excelDownMapper.selectQuotItemExclDownData(quotRequest); - } + @Autowired + Messages message; - public List selectNtrCtsCmpExclDownData(NtrCtsCmpRequest ntrCtsCmpRequest) throws Exception { - return excelDownMapper.selectNtrCtsCmpExclDownData(ntrCtsCmpRequest); - } + @Value("${file.ini.root.path}") + private String baseDirPath; - public List selectWarrantyIssuedCmpExclDownData(WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception { - return excelDownMapper.selectWarrantyIssuedCmpExclDownData(wrntIsncCmplRequest); + public List selectQuotPlanExclDownData(QuotRequest quotRequest) + throws Exception { + return excelDownMapper.selectQuotPlanExclDownData(quotRequest); + } + + public List selectQuotItemExclDownData(QuotRequest quotRequest) + throws Exception { + return excelDownMapper.selectQuotItemExclDownData(quotRequest); + } + + public List selectNtrCtsCmpExclDownData(NtrCtsCmpRequest ntrCtsCmpRequest) + throws Exception { + return excelDownMapper.selectNtrCtsCmpExclDownData(ntrCtsCmpRequest); + } + + public List selectWarrantyIssuedCmpExclDownData( + WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception { + return excelDownMapper.selectWarrantyIssuedCmpExclDownData(wrntIsncCmplRequest); + } + + public void selectWarrantyIssuedCmpFileData(WrntIsncCmplRequest wrntIsncCmplRequest, + HttpServletResponse response) throws Exception { + List listData = + excelDownMapper.selectWarrantyIssuedCmpFileData(wrntIsncCmplRequest); + + if (listData != null && listData.size() > 0) { + // 파일 목록 설정 + List> listFile = new ArrayList>(); + Map mapFile = null; + + for (WrntIsncCmplFileResponse res : listData) { + mapFile = new HashMap(); + mapFile.put("directory", res.getObjectNo()); + mapFile.put("filename", baseDirPath + "\\" + res.getObjectNo() + "\\" + res.getFaileName()); + listFile.add(mapFile); + } + + zipFileManager.createZipFile(response, "Warranty-issued-completed-files", listFile); + } else { + throw new BaseException(message.getMessage("common.message.no.dataDown")); } + } } diff --git a/src/main/java/com/interplug/qcast/biz/excelDown/dto/WrntIsncCmplFileResponse.java b/src/main/java/com/interplug/qcast/biz/excelDown/dto/WrntIsncCmplFileResponse.java new file mode 100644 index 00000000..ef1f06bb --- /dev/null +++ b/src/main/java/com/interplug/qcast/biz/excelDown/dto/WrntIsncCmplFileResponse.java @@ -0,0 +1,18 @@ +package com.interplug.qcast.biz.excelDown.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class WrntIsncCmplFileResponse { + @Schema(description = "부동산 관리 번호") + private String objectNo; + @Schema(description = "계획") + private String planNo; + @Schema(description = "번호") + private String no; + @Schema(description = "파일명") + private String faileName; +} diff --git a/src/main/java/com/interplug/qcast/util/ZipFileManager.java b/src/main/java/com/interplug/qcast/util/ZipFileManager.java index 9cbce912..785b86c8 100644 --- a/src/main/java/com/interplug/qcast/util/ZipFileManager.java +++ b/src/main/java/com/interplug/qcast/util/ZipFileManager.java @@ -5,9 +5,12 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Path; import java.util.List; +import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import com.interplug.qcast.config.message.Messages; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -17,22 +20,26 @@ import lombok.extern.slf4j.Slf4j; @RequiredArgsConstructor public class ZipFileManager { + @Autowired + Messages message; + /** * zip file을 생성하여 ZipOutputStream를 반환하는 method * * @param response HttpServletResponse * @param strCreateFileName 생성할 file 이름 - * @param listFilePath 파일 경로 목록 + * @param listFilePath 파일 정보 목록 */ public void createZipFile(HttpServletResponse response, String strCreateFileName, - List listFilePath) throws Exception { + List> listFile) throws Exception { // 압축될 파일명이 존재하지 않을 경우 if (strCreateFileName == null || "".equals(strCreateFileName)) - throw new IllegalArgumentException("파일명이 존재하지 않습니다."); + throw new IllegalArgumentException( + message.getMessage("common.message.data.no.exists", "file name")); // 파일이 존재하지 않을 경우 - if (listFilePath == null || listFilePath.size() == 0) - throw new IllegalArgumentException("파일이 존재하지 않습니다."); + if (listFile == null || listFile.size() == 0) + throw new IllegalArgumentException(message.getMessage("common.message.no.dataDown")); // zip 파일명 String strZipName = strCreateFileName + ".zip"; @@ -43,12 +50,14 @@ public class ZipFileManager { response.setStatus(HttpServletResponse.SC_OK); try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) { - for (String strSourceFile : listFilePath) { + for (Map mapFile : listFile) { + String strDirectory = mapFile.get("directory"); + String strSourceFile = mapFile.get("filename"); Path path = Path.of(strSourceFile); try (FileInputStream fis = new FileInputStream(path.toFile())) { // 압축될 파일명을 ZipEntry에 담아준다 - ZipEntry zipEntry = new ZipEntry(path.getFileName().toString()); + ZipEntry zipEntry = new ZipEntry(strDirectory + "\\" + path.getFileName().toString()); // 압축될 파일명을 ZipOutputStream 에 담아준다 zos.putNextEntry(zipEntry); @@ -59,12 +68,14 @@ public class ZipFileManager { zos.write(buffer, 0, length); } } catch (FileNotFoundException e) { - response.setStatus(HttpServletResponse.SC_NOT_FOUND); - throw new IllegalArgumentException("파일 변환 작업중, [ " + strZipName + " ] 파일을 찾을 수 없습니다."); + // response.setStatus(HttpServletResponse.SC_NOT_FOUND); + // throw new IllegalArgumentException("파일 변환 작업중, [ " + strSourceFile + " ] 파일을 찾을 수 + // 없습니다."); + log.debug("파일 변환 작업중, [ " + strSourceFile + " ] 파일을 찾을 수 없습니다."); } catch (IOException e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); throw new IllegalArgumentException( - "파일 변환 작업중, [ " + strZipName + " ] 파일을 다운로드 할 수 없습니다."); + "파일 변환 작업중, [ " + strSourceFile + " ] 파일을 다운로드 할 수 없습니다."); } finally { // ZipOutputStream 에 담아둔 압축될 파일명을 flush 시켜준다 zos.flush(); diff --git a/src/main/resources/mappers/excelDown/excelDownMapper.xml b/src/main/resources/mappers/excelDown/excelDownMapper.xml index 811fcdb7..260f0fa0 100644 --- a/src/main/resources/mappers/excelDown/excelDownMapper.xml +++ b/src/main/resources/mappers/excelDown/excelDownMapper.xml @@ -472,5 +472,25 @@ + \ No newline at end of file