From 82f4f58b6dcfebc3b0f6a0a852f9b3b72bbb4a59 Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Fri, 15 Dec 2023 10:28:48 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8B=A8=EC=86=8D=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=EC=97=91=EC=85=80=EC=A0=80=EC=9E=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cokr/xit/fims/cmmn/CmmnQuery.java | 21 ++++++++ .../java/cokr/xit/fims/cmmn/CmmnUtil.java | 51 +++++++++++++++++++ .../WEB-INF/jsp/fims/crdn/crdn06010-main.jsp | 21 ++++++-- 3 files changed, 90 insertions(+), 3 deletions(-) diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnQuery.java b/src/main/java/cokr/xit/fims/cmmn/CmmnQuery.java index a62e0cb2..668ceea1 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnQuery.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnQuery.java @@ -9,6 +9,9 @@ public class CmmnQuery extends QueryRequest { private String mainOption; private String subOption; + private String[] excelTitle; + private int[] excelTitleWidth; + private String thisDay; private String sggCd; // 시군구 코드 @@ -46,6 +49,24 @@ public class CmmnQuery extends QueryRequest { return self(); } + public String[] getExcelTitle() { + return ifEmpty(excelTitle, () -> null); + } + + public T setExcelTitle(String[] excelTitle) { + this.excelTitle = excelTitle; + return self(); + } + + public int[] getExcelTitleWidth() { + return ifEmpty(excelTitleWidth, () -> null); + } + + public T setExcelTitleWidth(int[] excelTitleWidth) { + this.excelTitleWidth = excelTitleWidth; + return self(); + } + public String getThisDay() { return ifEmpty(thisDay, () -> null); } diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java index eb5f2c86..d2829692 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java @@ -12,9 +12,11 @@ import java.text.SimpleDateFormat; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.format.TextStyle; +import java.util.ArrayList; import java.util.Calendar; import java.util.Comparator; import java.util.Date; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -26,7 +28,11 @@ import java.util.stream.Collectors; import javax.imageio.ImageIO; import org.apache.commons.io.FilenameUtils; +import org.apache.poi.hssf.util.HSSFColor; +import org.apache.poi.ss.usermodel.Font; +import cokr.xit.base.file.xls.XLSWriter; +import cokr.xit.base.file.xls.XLSWriter.Styler; import cokr.xit.fims.sndb.service.bean.SndngBean; import cokr.xit.foundation.data.DataObject; @@ -422,5 +428,50 @@ public class CmmnUtil { return band6; } + /** 요소의 갯수가 같은 리스트 2개를 병합한 새 리스트를 반환한다.
+ * 새 리스트의 정렬순서는 1차적으로 기존 요소의 인덱스번호, 2차적으로 해당 요소가 기존에 첫번째 리스트의 요소인지 여부로 정렬한다. + * @param list1, list2 + * @return list3 + */ + public static List mergeListByIndex(List list1, List list2) { + + List list3 = new ArrayList<>(); + for(int i=0; i < list1.size(); i++) { + list3.add(list1.get(i)); + list3.add(list2.get(i)); + } + return list3; + + } + + /** 엑셀의 열 제목 길이 목록을 입력받아서 길이를 제외한 스타일이 동일한 스타일 목록 반환한다.
+ * @param widths 열 제목 길이, xlsxWriter + * @return + */ + public static List makeHeadersByDiffrentWidths(List widths, XLSWriter xlsxWriter){ + + List result = new ArrayList(); + + Map headerWidthMap = new HashMap<>(); + + for(int i=0; i < widths.size(); i++) { + if(headerWidthMap.get(widths.get(i)) == null) { + headerWidthMap.put( + widths.get(i), + new XLSWriter.Styler() + .width(widths.get(i)) + .foregroundColor(HSSFColor.HSSFColorPredefined.LIGHT_BLUE.getIndex()) + .configure(styler -> { + Font font = xlsxWriter.workbook().createFont(); + font.setColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex()); + styler.font(font); + }) + ); + } + result.add(headerWidthMap.get(widths.get(i))); + } + + return result; + } } diff --git a/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn06010-main.jsp b/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn06010-main.jsp index b74883c8..ef9ad6e7 100644 --- a/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn06010-main.jsp +++ b/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn06010-main.jsp @@ -470,11 +470,26 @@ $(document).ready(function(){ $('#btnReset--${pageName}').on('click', () => $P.fnReset()); $('#btnSearch--${pageName}').on('click', () => $P.searchCrdnList()); $('#btnExcel--${pageName}').on('click', function(){ - if(!$P.crdnControl.dataset.empty){ - $P.crdnControl.download(); - } else { + + if($P.crdnControl.dataset.empty){ alert("조회된 자료가 없습니다."); + return; } + + var excelTitle = []; + var excelTitleWidth = []; + $("#crdnThead--${pageName} th").not(".dummy-th").not(":eq(0)").each(function(){ + var title = $(this).text(); + excelTitle.push(title); + var titleWidth = $(this).outerWidth(); + titleWidth = Math.ceil(titleWidth/10); + excelTitleWidth.push(titleWidth); + }); + + $P.crdnControl.query.excelTitle = excelTitle.join(","); + $P.crdnControl.query.excelTitleWidth = excelTitleWidth.join(","); + //return; + $P.crdnControl.download(); }); fnMakeScrollableTable($("#table-responsive--${pageName}")[0], $P.scrollCrdnList);