발전시뮬레이션 엑셀/pdf 다운로드 분리(가로 처리)

This commit is contained in:
DESKTOP-6ARNG1Q\dlsgk 2025-03-11 17:33:44 +09:00
parent ca8c239e8b
commit 115b0253c2
5 changed files with 646 additions and 10 deletions

View File

@ -1,17 +1,17 @@
package com.interplug.qcast.biz.pwrGnrSimulation;
import com.interplug.qcast.biz.estimate.dto.EstimateRequest;
import com.interplug.qcast.biz.pwrGnrSimulation.dto.PwrGnrSimGuideResponse;
import com.interplug.qcast.biz.pwrGnrSimulation.dto.PwrGnrSimRequest;
import com.interplug.qcast.biz.pwrGnrSimulation.dto.PwrGnrSimResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@ -36,4 +36,15 @@ public class PwrGnrSimController {
public PwrGnrSimGuideResponse selectPwrGnrSimulationGuideInfo() throws Exception {
return pwrGnrSimService.selectPwrGnrSimulationGuideInfo();
}
@Operation(description = "견적서를 엑셀로 다운로드한다.")
@PostMapping("/excel-download")
@ResponseStatus(HttpStatus.OK)
public void excelDownload(
HttpServletRequest request,
HttpServletResponse response,
@RequestBody EstimateRequest estimateRequest)
throws Exception {
pwrGnrSimService.excelDownload(request, response, estimateRequest);
}
}

View File

@ -2,23 +2,28 @@ package com.interplug.qcast.biz.pwrGnrSimulation;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.interplug.qcast.biz.estimate.dto.*;
import com.interplug.qcast.biz.pwrGnrSimulation.dto.*;
import com.interplug.qcast.config.Exception.ErrorCode;
import com.interplug.qcast.config.Exception.QcastException;
import com.interplug.qcast.config.message.Messages;
import com.interplug.qcast.util.ExcelUtil;
import com.interplug.qcast.util.InterfaceQsp;
import com.interplug.qcast.util.PdfUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
@ -29,6 +34,8 @@ import org.springframework.stereotype.Service;
public class PwrGnrSimService {
private final InterfaceQsp interfaceQsp;
@Autowired Messages message;
@Value("${qsp.url}")
private String qspUrl;
@ -1484,4 +1491,105 @@ public class PwrGnrSimService {
return (int) Math.ceil(value / place) * place;
}
public void excelDownload(
HttpServletRequest request, HttpServletResponse response, EstimateRequest estimateRequest)
throws Exception {
// Validation
if (StringUtils.isEmpty(estimateRequest.getObjectNo())) {
throw new QcastException(
ErrorCode.INVALID_INPUT_VALUE,
message.getMessage("common.message.required.data", "Object No"));
}
if (StringUtils.isEmpty(estimateRequest.getPlanNo())) {
throw new QcastException(
ErrorCode.INVALID_INPUT_VALUE,
message.getMessage("common.message.required.data", "Plan No"));
}
try {
EstimateResponse estimateResponse = new EstimateResponse();
estimateResponse.setObjectNo(estimateRequest.getObjectNo());
estimateResponse.setPlanNo(estimateRequest.getPlanNo());
// file Name 명이 없는경우
if (estimateRequest.getFileName() == null || "".equals(estimateRequest.getFileName())) {
estimateRequest.setFileName(
estimateResponse.getObjectNo()
+ "_"
+ new SimpleDateFormat("yyyyMMdd").format(new Date()));
}
// 발전시뮬레이션 계산
PwrGnrSimRequest pwrGnrSimRequest = new PwrGnrSimRequest();
pwrGnrSimRequest.setObjectNo(estimateResponse.getObjectNo());
pwrGnrSimRequest.setPlanNo(estimateResponse.getPlanNo());
PwrGnrSimResponse pwrGnrSimResponse = this.selectPwrGnrSimulation(pwrGnrSimRequest);
pwrGnrSimResponse.setPwrGnrSimType(estimateRequest.getPwrGnrSimType());
// 발전시뮬레이션 타입에 따른 list 셋팅
if ("A".equals(estimateRequest.getPwrGnrSimType())) {
pwrGnrSimResponse.setFrcPwrGnrList(pwrGnrSimResponse.getHatsudenryouAll());
} else if ("B".equals(estimateRequest.getPwrGnrSimType())) {
pwrGnrSimResponse.setFrcPwrGnrList(pwrGnrSimResponse.getHatsudenryouAllSnow());
} else if ("C".equals(estimateRequest.getPwrGnrSimType())) {
pwrGnrSimResponse.setFrcPwrGnrList(pwrGnrSimResponse.getHatsudenryouPeakcutAll());
} else if ("D".equals(estimateRequest.getPwrGnrSimType())) {
pwrGnrSimResponse.setFrcPwrGnrList(pwrGnrSimResponse.getHatsudenryouPeakcutAllSnow());
}
pwrGnrSimResponse.setIntFrcPwrGnrList(
Arrays.stream(pwrGnrSimResponse.getFrcPwrGnrList())
.map(s -> s.replace(",", "")) // , 제거
.mapToInt(Integer::parseInt) // 문자열을 int로 변환
.toArray());
if (pwrGnrSimResponse != null) {
try {
// 발전시뮬레이션 안내사항 조회
PwrGnrSimGuideResponse pwrGnrSimGuideInfo = this.selectPwrGnrSimulationGuideInfo();
if (pwrGnrSimGuideInfo != null) {
pwrGnrSimResponse.setGuideInfo(pwrGnrSimGuideInfo.getData());
}
} catch (Exception e) {
}
}
estimateResponse.setPwrGnrSim(pwrGnrSimResponse);
if ("PDF".equals(estimateRequest.getSchDownload())) { // PDF 다운로드
String[] arrSection = {"div.section3"};
String templateFilePath = "pdf_download_simulation_detail_template.html";
// 템플릿 html 조회
Document doc = PdfUtil.getPdfDoc(request, templateFilePath);
// 발전시뮬레이션 pdf Html 생성
doc = this.pwrGnrSimPdfHtml(doc, pwrGnrSimResponse);
// pdf 다운로드
PdfUtil.pdfDownload(request, response, doc, estimateRequest.getFileName(), null, true);
} else {
String excelTemplateName = "excel_download_simulation_detail_template.xlsx";
ExcelUtil excelUtil = new ExcelUtil();
excelUtil.download(
request,
response,
excelUtil.convertVoToMap(estimateResponse),
null,
estimateRequest.getFileName(),
excelTemplateName);
}
} catch (Exception e) {
e.printStackTrace();
throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -3,6 +3,7 @@ package com.interplug.qcast.util;
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
@ -60,6 +61,7 @@ public class PdfUtil {
* @param doc
* @param pdfFileName 파일명
* @param arrSection 노출 Section
* @param isLandscape 가로/세로 설정
* @throws IOException
*/
public static void pdfDownload(
@ -67,9 +69,13 @@ public class PdfUtil {
HttpServletResponse response,
Document doc,
String pdfFileName,
String[] arrSection)
String[] arrSection,
boolean isLandscape)
throws IOException {
// 가로 세로 설정
PageSize pageSize = isLandscape ? PageSize.A4.rotate() : PageSize.A4;
// 응답에 PDF 설정
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment; filename=\"" + pdfFileName + "\".pdf");
@ -79,6 +85,8 @@ public class PdfUtil {
PdfWriter writer = new PdfWriter(os);
PdfDocument pdfDoc = new PdfDocument(writer)) {
pdfDoc.setDefaultPageSize(pageSize);
// 폰트 설정
ConverterProperties properties = new ConverterProperties();
String fontPath = "template/pdf/BIZUDPGothic-Regular.ttf";
@ -88,7 +96,9 @@ public class PdfUtil {
if (arrSection == null || arrSection.length == 0) {
// HTML 전체를 pdfDoc에 직접 변환
HtmlConverter.convertToPdf(
new ByteArrayInputStream(doc.html().getBytes(StandardCharsets.UTF_8)), os, properties);
new ByteArrayInputStream(doc.html().getBytes(StandardCharsets.UTF_8)),
pdfDoc,
properties);
os.flush();
} else {
// arrSection이 있는 경우 섹션을 개별적으로 변환 병합
@ -108,6 +118,8 @@ public class PdfUtil {
PdfWriter tempWriter = new PdfWriter(tempOutputStream);
PdfDocument tempPdfDoc = new PdfDocument(tempWriter)) {
tempPdfDoc.setDefaultPageSize(pageSize);
HtmlConverter.convertToPdf(
new ByteArrayInputStream(sectionHtml.getBytes(StandardCharsets.UTF_8)),
tempPdfDoc,
@ -161,4 +173,15 @@ public class PdfUtil {
}
return fontProvider;
}
public static void pdfDownload(
HttpServletRequest request,
HttpServletResponse response,
Document doc,
String pdfFileName,
String[] arrSection)
throws IOException {
pdfDownload(request, response, doc, pdfFileName, arrSection, false); // 기본값은 세로
}
}

View File

@ -0,0 +1,494 @@
<!doctype html>
<html lang="ja">
<head>
<style>
@media print {
body {
print-color-adjust: exact;
-webkit-print-color-adjust: exact;
}
}
table {
width: 100%;
table-layout: fixed;
font-family: M-Gothic;
font-size: 11px;
border-collapse: collapse;
margin: 0 auto;
line-height: 150%;
color: #333
}
.month-table td {
word-break: break-all;
}
th, td {
padding: 5px 5px 3px;
text-align: center;
font-size: 10px;
border: 1px solid #000
}
th {
background-color: #eee;
font-weight: bold
}
td {
background-color: white
}
.col-20 {
width: 20%
}
.col-15 {
width: 15%
}
.col-10 {
width: 10%
}
body {
max-width: 1040px;
margin: 0 auto
}
.mb20 {
margin-bottom: 20px
}
.al-l {
text-align: left !important
}
.al-r {
text-align: right !important
}
/* 가이드박스 */
.guide-box {
border: 1px solid #000;
padding: 15px;
}
.guide-content {
white-space: pre-line;
line-height: 1.4;
font-size: 12px;
margin: 0;
}
/* 차트퍼블 */
.chart-wrapper {
width: 100%;
table-layout: fixed;
margin: 20px 0;
height: 324.3px;
}
.chart-wrapper td {
padding: 0;
border: none
}
.chart-wrapper td.y-axis-wrap {
vertical-align: bottom
}
.y-axis {
margin-top: -5px
}
.y-axis td {
font-size: 12px;
line-height: 1;
vertical-align: bottom;
padding: 12.3px 0
}
.y-axis td.zero {
padding-bottom: 0
}
.y-axis td.top {
padding-top: 0
}
.chart-wrapper td.bar-cell {
position: relative;
vertical-align: bottom;
border-bottom: 1px solid #ddd;
background-color: transparent
}
.chart-wrapper td.bar-cell .bar {
position: absolute;
bottom: 0;
left: 13.4px;
width: 18px;
margin: 0 auto
}
.chart-wrapper td.month-cell {
font-size: 11px;
padding-top: 7px
}
.chart-line td {
background-color: transparent;
padding: 18.2px 0;
border-bottom: 1px solid #ddd !important
}
.chart-line td.top {
padding: 1px
}
/* 타이틀 */
.title {
text-align: center;
font-size: 40px;
letter-spacing: 10px;
font-weight: bold;
margin: 10px 0 30px;
border-top: 1px solid #000;
border-bottom: 1px solid #000;
}
/* 비고퍼블 */
.note th, .note td {
padding: 10px
}
/* 총액퍼블 */
.all-price-wrap {
text-align: center;
margin-bottom: 50px;
}
.all-price {
display: inline-block;
text-align: center;
border-bottom: 1px solid #000;
}
.all-price span {
display: inline-block;
font-size: 18px;
font-weight: bold;
}
.all-price-value {
width: 300px;
display: inline-block;
text-align: right;
}
/* 태양전지 */
.sun-volt {
display: inline-block;
margin-bottom: 30px;
border-bottom: 1px solid #000;
}
.sun-volt span {
display: inline-block;
font-size: 15px;
font-weight: bold;
}
.sun-volt-value {
width: 130px;
display: inline-block;
text-align: right;
font-size: 15px;
}
.price-table td.end {
background-color: #eee;
font-weight: bold;
}
.product-info-wrap {
table-layout: fixed;
margin-bottom: 25px;
}
.product-info-wrap td {
border: none;
padding: 0;
text-align: left;
vertical-align: top;
}
/* 견적서 정의 */
.estimate-wrap {
display: inline-block;
vertical-align: top;
}
.estimate-info {
display: inline-block;
margin-bottom: 40px;
border-bottom: 1px solid #000;
}
.estimate-info span {
font-size: 13px;
font-weight: bold;
}
.estimate-info-name {
padding-right: 20px;
}
/* tit-form */
.estimate-tit-form {
display: block;
margin-bottom: 30px;
}
.estimate-tit-form span {
font-size: 13px;
border-bottom: 1px solid #000;
}
.estimate-tit-form .estimate-tit {
display: inline-block;
width: 82px;
font-size: 12px;
font-weight: bold;
border: none;
text-align: right;
}
/* 물품 */
.product-wrap > div {
margin-bottom: 10px;
}
.product-num {
display: inline-block;
margin-right: 20px;
}
.product-count {
display: inline-block;;
}
.product-count .tit, .product-num .tit {
display: inline-block;
font-size: 12px;
font-weight: bold;
}
.product-count span, .product-num span {
display: inline-block;
font-size: 13px;
}
.product-form {
display: block;
}
.product-form .tit {
display: inline-block;
width: 62px;
font-size: 12px;
font-weight: bold;
border: none;
text-align: right;
}
.product-form span {
display: inline-block;
font-size: 13px;
}
.store-info-tit {
font-size: 13px;
font-weight: bold;
display: block;
margin-bottom: 10px;
}
.product-info-wrap .store-info {
display: block;
margin-bottom: 25px;
}
.store-info span {
display: block;
font-size: 12px;
margin-bottom: 0px;
}
.store-info .number {
display: block;
font-size: 13px;
}
.store-info .number span {
display: inline-block;
}
.approval-table {
width: 200px;
margin: 0 0 0 auto;
}
.approval-table th {
background-color: transparent;
}
.approval-table td {
padding: 30px 0;
border: 1px solid #000;
}
.chart-wrap {
overflow: hidden;
}
.left-side {
margin-right: 20px;
width: 550px;
float: left;
}
.right-side {
width: 450px;
float: right;
}
.tit {
font-size: 14px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="section3">
<table class="mb20">
<tbody>
<tr>
<th class="col-10">物件番号</th>
<td id="objectNo"></td>
<th class="col-10">作成日</th>
<td id="drawingEstimateCreateDate"></td>
<th class="col-10">都道府県</th>
<td id="prefName"></td>
<th class="col-10">日射量観測地点</th>
<td id="areaName"></td>
</tr>
<tr>
<th class="col-10">システム容量</th>
<td id="capacity"></td>
<th class="col-10">年間予測発電量</th>
<td id="anlFrcsGnrt"></td>
<th class="col-10">積雪条件</th>
<td id="snowfall"></td>
<th class="col-10">風速条件</th>
<td id="standardWindSpeedId"></td>
</tr>
</tbody>
</table>
<div class="chart-wrap">
<div class="left-side">
<div id="pwrGnrChartImg">
<table class="chart-wrapper">
<tbody>
<tr id="htmlX">
<td class="y-axis-wrap">
<table class="y-axis">
<tbody id="htmlY">
</tbody>
</table>
</td>
</tr>
<tr>
<td class="month-cell"></td>
<td class="month-cell">1月</td>
<td class="month-cell">2月</td>
<td class="month-cell">3月</td>
<td class="month-cell">4月</td>
<td class="month-cell">5月</td>
<td class="month-cell">6月</td>
<td class="month-cell">7月</td>
<td class="month-cell">8月</td>
<td class="month-cell">9月</td>
<td class="month-cell">10月</td>
<td class="month-cell">11月</td>
<td class="month-cell">12月</td>
</tr>
</tbody>
</table>
</div>
<div class="tit">
● 予測発電量kWh
</div>
<table class="mb20 month-table">
<thead>
<tr>
<th>1月</th>
<th>2月</th>
<th>3月</th>
<th>4月</th>
<th>5月</th>
<th>6月</th>
<th>7月</th>
<th>8月</th>
<th>9月</th>
<th>10月</th>
<th>11月</th>
<th>12月</th>
<th>合計</th>
</tr>
</thead>
<tbody>
<tr id="frcPwrGnrList_detail">
</tr>
</tbody>
</table>
</div>
<div class="right-side">
<table class="mb20">
<thead>
<tr>
<th class="col-15">屋根面</th>
<th class="col-15">傾斜角度</th>
<th class="col-15">方位角(度)</th>
<th>太陽電池モジュール</th>
<th class="col-15">枚数(枚)</th>
</tr>
</thead>
<tbody id="roofModuleList_detail">
</tbody>
</table>
<table class="mb20">
<thead>
<tr>
<th>パワーコンディショナー</th>
<th class="col-20"></th>
</tr>
</thead>
<tbody id="pcsList_detail">
</tbody>
</table>
</div>
</div>
<div class="tit">
● Hanwha Japan 年間発電量シミュレーション案内事項
</div>
<div class="guide-box">
<pre class="guide-content" id="guideInfo"></pre>
</div>
</div>
</body>
</html>