견적서 엑셀다운로드 시트 삭제 기능 추가

This commit is contained in:
LAPTOP-L3VE7KK2\USER 2024-11-22 10:45:53 +09:00
parent bee5c7059f
commit b7d4729342
3 changed files with 81 additions and 35 deletions

View File

@ -34,7 +34,10 @@ import com.interplug.qcast.util.InterfaceQsp;
import com.interplug.qcast.util.PdfUtil; import com.interplug.qcast.util.PdfUtil;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -44,6 +47,8 @@ import java.util.Map;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -977,6 +982,7 @@ public class EstimateService {
// SchDrawingFlg (1 : 견적서,2 : 발전시뮬레이션, 3 : 도면, 4 : 가대) // SchDrawingFlg (1 : 견적서,2 : 발전시뮬레이션, 3 : 도면, 4 : 가대)
// ex) 1|2|3|4 // ex) 1|2|3|4
if (!StringUtils.isEmpty(estimateRequest.getSchDrawingFlg())) {
if (estimateRequest.getSchDrawingFlg().indexOf("1") > -1) { if (estimateRequest.getSchDrawingFlg().indexOf("1") > -1) {
arrSection[iSection] = "div.section1"; arrSection[iSection] = "div.section1";
iSection++; iSection++;
@ -1000,22 +1006,59 @@ public class EstimateService {
arrSection[iSection] = "div.section6"; arrSection[iSection] = "div.section6";
iSection++; iSection++;
} }
}
// pdf 다운로드 // pdf 다운로드
PdfUtil.pdfDownload(request, response, doc, estimateRequest.getFileName(), arrSection); PdfUtil.pdfDownload(request, response, doc, estimateRequest.getFileName(), arrSection);
} else { } else {
Workbook workbook = null;
String excelTemplateNam = "excel_download_quotation_detail_template.xlsx"; String excelTemplateNam = "excel_download_quotation_detail_template.xlsx";
ExcelUtil excelUtil = new ExcelUtil(); ExcelUtil excelUtil = new ExcelUtil();
byte[] excelBytes =
excelUtil.download( excelUtil.download(
request, request,
response, response,
excelUtil.convertVoToMap(estimateResponse), excelUtil.convertVoToMap(estimateResponse),
excelUtil.convertListToMap(estimateItemList), excelUtil.convertListToMap(estimateItemList),
estimateRequest.getFileName(),
excelTemplateNam); excelTemplateNam);
InputStream in = new ByteArrayInputStream(excelBytes);
workbook = WorkbookFactory.create(in); // JXLS POI 엑셀로 재변환
// SchDrawingFlg (1 : 견적서,2 : 발전시뮬레이션, 3 : 도면, 4 : 가대)
// ex) 1|2|3|4
if (!StringUtils.isEmpty(estimateRequest.getSchDrawingFlg())) {
if (estimateRequest.getSchDrawingFlg().indexOf("1") < 0) {
workbook.removeSheetAt(workbook.getSheetIndex("見積書"));
workbook.removeSheetAt(workbook.getSheetIndex("特異事項"));
}
if (estimateRequest.getSchDrawingFlg().indexOf("2") < 0) {
workbook.removeSheetAt(workbook.getSheetIndex("発電シミュレーション"));
}
if (estimateRequest.getSchDrawingFlg().indexOf("3") < 0) {
workbook.removeSheetAt(workbook.getSheetIndex("割付図・系統図"));
workbook.removeSheetAt(workbook.getSheetIndex("架台図"));
}
}
// 추후 개발 (가대중량표)
if (estimateRequest.getSchDrawingFlg().indexOf("4") < 0) {}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
workbook.write(byteArrayOutputStream);
excelBytes = byteArrayOutputStream.toByteArray();
response.setHeader(
"Content-Disposition",
"attachment; filename=\"" + estimateRequest.getFileName() + ".xlsx\"");
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.getOutputStream().write(excelBytes);
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -29,40 +29,43 @@ public class ExcelUtil {
* @param response HttpServletResponse * @param response HttpServletResponse
* @param map 엑셀 출력데이터 * @param map 엑셀 출력데이터
* @param list 엑셀 출력 목록 데이터 * @param list 엑셀 출력 목록 데이터
* @param fileName 다운로드 파일명
* @param templateFileName * @param templateFileName
* @throws ParsePropertyException * @throws ParsePropertyException
* @throws InvalidFormatException * @throws InvalidFormatException
*/ */
public void download( public byte[] download(
HttpServletRequest request, HttpServletRequest request,
HttpServletResponse response, HttpServletResponse response,
Map<String, Object> map, Map<String, Object> map,
List<Map<String, Object>> list, List<Map<String, Object>> list,
String fileName,
String templateFileName) String templateFileName)
throws ParsePropertyException, InvalidFormatException { throws ParsePropertyException, InvalidFormatException {
byte[] excelBytes = null;
try { try {
String templateFilePath = "template/excel/" + templateFileName; String templateFilePath = "template/excel/" + templateFileName;
InputStream templateStream = InputStream templateStream =
PdfUtil.class.getClassLoader().getResourceAsStream(templateFilePath); PdfUtil.class.getClassLoader().getResourceAsStream(templateFilePath);
InputStream is = new BufferedInputStream(templateStream); // InputStream is = new BufferedInputStream(templateStream);
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".xlsx\""); try (InputStream is = new BufferedInputStream(templateStream)) {
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
try (OutputStream os = response.getOutputStream()) {
Context context = new Context(); Context context = new Context();
context.putVar("data", map); context.putVar("data", map);
context.putVar("list", list); context.putVar("list", list);
JxlsHelper.getInstance().processTemplate(is, os, context); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
JxlsHelper.getInstance().processTemplate(is, byteArrayOutputStream, context);
excelBytes = byteArrayOutputStream.toByteArray();
} }
} catch (Exception e) { } catch (Exception e) {
log.debug(e.getMessage()); log.debug(e.getMessage());
} }
return excelBytes;
} }
/** /**