From e069dd259739922a654c346d16758bda8751a690 Mon Sep 17 00:00:00 2001 From: bangae1 Date: Fri, 30 May 2025 13:07:07 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B2=B0=EC=9E=AC=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B0=8F=20=EA=B0=80=EA=B2=A9=EC=A1=B0=EC=82=AC=20=EB=94=94?= =?UTF-8?q?=ED=85=8C=EC=9D=BC=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../svcm/controller/EstimateController.java | 35 ++++++++++++++++++ .../kospo/svcm/service/EstimateService.java | 4 +++ .../service/impl/EstimateServiceImpl.java | 36 ++++++++++++++++++- .../svcm/service/impl/PrcsServiceImpl.java | 14 ++++---- 4 files changed, 81 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/kospo/svcm/controller/EstimateController.java b/src/main/java/com/kospo/svcm/controller/EstimateController.java index dad32b0..b71c56e 100644 --- a/src/main/java/com/kospo/svcm/controller/EstimateController.java +++ b/src/main/java/com/kospo/svcm/controller/EstimateController.java @@ -18,6 +18,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.UrlResource; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -28,6 +29,7 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import org.yaml.snakeyaml.util.UriEncoder; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.MalformedURLException; import java.security.Principal; @@ -229,6 +231,39 @@ public class EstimateController { .body(resource); } + @Operation(summary = "견적서 ZIP 다운로드", description = "견적서(첨부파일) ZIP 다운로드") + @ApiResponses({ + @ApiResponse(description = "Success", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(oneOf = + {byte[].class}))), + @ApiResponse(description = "Not found", responseCode = "404", + content = @Content(mediaType = "text/plain", schema = @Schema(oneOf = + {String.class}))), + @ApiResponse(description = "Internal Error", responseCode = "500", + content = @Content(mediaType = "application/json", schema = @Schema(oneOf = + {CustomErrorResponse.class}))) + }) + @GetMapping("/pbAtt/{prcsNo}/{bizNo}") + public ResponseEntity downloadZip( + @Parameter(description = "가격조사번호") @PathVariable String prcsNo, + @Parameter(description = "견적관리번호") @PathVariable String bizNo, + Principal principal + ) { + ByteArrayInputStream bais = null; + HttpHeaders headers = new HttpHeaders(); + try { + bais = estimateService.getPbAttCompression(prcsNo, bizNo, principal.getName()); + headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + UriEncoder.encode("entry.zip")); + headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); +// headers.setContentLength(bais.readAllBytes().length); + } catch (IOException e) { + throw new RuntimeException(e); + } + return ResponseEntity.ok() + .headers(headers) + .body(new InputStreamResource(bais)); + } + // @Operation(summary = "견적서 삭제", description = "견적서(첨부파일) 삭제") // @ApiResponses({ // @ApiResponse(description = "Success", responseCode = "200", diff --git a/src/main/java/com/kospo/svcm/service/EstimateService.java b/src/main/java/com/kospo/svcm/service/EstimateService.java index cad4ce1..9b11cbc 100644 --- a/src/main/java/com/kospo/svcm/service/EstimateService.java +++ b/src/main/java/com/kospo/svcm/service/EstimateService.java @@ -7,6 +7,8 @@ import com.kospo.svcm.dto.res.EstimateResponse; import com.kospo.svcm.model.PbAtt; import jakarta.transaction.Transactional; +import java.io.ByteArrayInputStream; +import java.io.IOException; import java.util.List; public interface EstimateService { @@ -21,4 +23,6 @@ public interface EstimateService { void pbAttFileDelete(String prcsNo, String bizNo, Integer fileOrd); PbAtt getPbAtt(String prcsNo, String bizNo, Integer fileOrd, String id); + + ByteArrayInputStream getPbAttCompression(String prcsNo, String bizNo, String id) throws IOException; } diff --git a/src/main/java/com/kospo/svcm/service/impl/EstimateServiceImpl.java b/src/main/java/com/kospo/svcm/service/impl/EstimateServiceImpl.java index 5312e31..58164a5 100644 --- a/src/main/java/com/kospo/svcm/service/impl/EstimateServiceImpl.java +++ b/src/main/java/com/kospo/svcm/service/impl/EstimateServiceImpl.java @@ -21,7 +21,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; -import java.io.IOException; +import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -29,6 +29,8 @@ import java.util.Date; import java.util.List; import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; @Service @RequiredArgsConstructor @@ -260,6 +262,38 @@ public class EstimateServiceImpl implements EstimateService { return pbAtt; } + @Override + public ByteArrayInputStream getPbAttCompression(String prcsNo, String bizNo, String id) throws IOException { + ByteArrayOutputStream baos = null; + ZipOutputStream zos = null; + + + baos = new ByteArrayOutputStream(); + zos = new ZipOutputStream(baos); + List pbAttList = pbAttRepository.findByIdPrcsNoAndIdBizNo(prcsNo, bizNo); + ZipOutputStream finalZos = zos; + pbAttList.stream().forEach(attPb -> { + ZipEntry entry = new ZipEntry(attPb.getLogiFnm()); + try { + finalZos.putNextEntry(entry); + File inputFile = new File(attPb.getPath());; + + FileInputStream fis = new FileInputStream(inputFile); + byte[] buf = new byte[1024]; + int length; + while((length = fis.read(buf)) > 0) { + finalZos.write(buf, 0, length); + } + fis.close(); + finalZos.closeEntry(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + finalZos.close(); + return new ByteArrayInputStream(baos.toByteArray()); + } + // @Override // public void bidFileDelete(String estNo, Integer fileOrd) { // BidDoc bidDoc = bidDocRepository.findById(BidDocId.builder() diff --git a/src/main/java/com/kospo/svcm/service/impl/PrcsServiceImpl.java b/src/main/java/com/kospo/svcm/service/impl/PrcsServiceImpl.java index 7e1803f..6f3b090 100644 --- a/src/main/java/com/kospo/svcm/service/impl/PrcsServiceImpl.java +++ b/src/main/java/com/kospo/svcm/service/impl/PrcsServiceImpl.java @@ -332,7 +332,7 @@ public class PrcsServiceImpl implements PrcsService { .apprDt("") .apprStatCd(apprReq.getSabun().equals(user.getSabun()) ? "0200" : apprCodeCd) .apprStat(apprReq.getSabun().equals(user.getSabun()) ? CommonUtils.getCodeNm(apprCodes, "0200") : CommonUtils.getCodeNm(apprCodes, apprCodeCd)) - .gubunCd(apprReq.getGubunCd()) + .gubunCd(StringUtil.isBlank(apprReq.getGubunCd()) ? "0000" : apprReq.getGubunCd()) .gubunNm(StringUtil.isBlank(apprReq.getGubunCd()) ? "입안" : CommonUtils.getCodeNm(gubunCodes, apprReq.getGubunCd())) .attendCd(StringUtil.isBlank(apprReq.getAttendCd()) ? "" : apprReq.getAttendCd()) .attendNm(StringUtil.isBlank(apprReq.getAttendCd()) ? "재중" : CommonUtils.getCodeNm(attendCodes, apprReq.getAttendCd())) @@ -474,12 +474,12 @@ public class PrcsServiceImpl implements PrcsService { .sabun(apprReqRequest.getSabun()) .name(apprReqRequest.getName()) .apprDt("") - .apprStatCd(apprCodeCd) - .apprStat(CommonUtils.getCodeNm(apprCodes, apprCodeCd)) - .gubunCd(apprReqRequest.getGubunCd()) - .gubunNm(CommonUtils.getCodeNm(gubunCodes, apprReqRequest.getGubunCd())) - .attendCd(apprReqRequest.getAttendCd()) - .attendNm(CommonUtils.getCodeNm(attendCodes, apprReqRequest.getAttendCd())) + .apprStatCd(apprReqRequest.getSabun().equals(apprUser.getSabun()) ? "0200" : apprCodeCd) + .apprStat(apprReqRequest.getSabun().equals(apprUser.getSabun()) ? CommonUtils.getCodeNm(apprCodes, "0200") : CommonUtils.getCodeNm(apprCodes, apprCodeCd)) + .gubunCd(StringUtil.isBlank(apprReqRequest.getGubunCd()) ? "0000" : apprReqRequest.getGubunCd()) + .gubunNm(StringUtil.isBlank(apprReqRequest.getGubunCd()) ? "입안" : CommonUtils.getCodeNm(gubunCodes, apprReqRequest.getGubunCd())) + .attendCd(StringUtil.isBlank(apprReqRequest.getAttendCd()) ? "" : apprReqRequest.getAttendCd()) + .attendNm(StringUtil.isBlank(apprReqRequest.getAttendCd()) ? "재중" : CommonUtils.getCodeNm(attendCodes, apprReqRequest.getAttendCd())) .deptCd(apprUser.getDept().getDeptCd()) .deptNm(apprUser.getDept().getDeptNm()) .build());