From 513c73ecee2d311f6f5925acd4fe6e118ba7ae93 Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Mon, 5 Feb 2024 17:01:22 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8B=A8=EC=86=8D=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=EC=82=AC=EC=A7=84=ED=8F=AC=ED=95=A8=20=EC=97=91=EC=85=80?= =?UTF-8?q?=EB=8B=A4=EC=9A=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokr/xit/fims/cmmn/CellDecorator.java | 23 +++++++ .../java/cokr/xit/fims/cmmn/CmmnQuery.java | 10 +++ .../java/cokr/xit/fims/cmmn/CmmnUtil.java | 64 ++++++++++++++++++ .../xit/fims/crdn/web/Crdn06Controller.java | 65 ++++++++++++++----- .../WEB-INF/jsp/fims/crdn/crdn06010-main.jsp | 32 ++++++--- 5 files changed, 168 insertions(+), 26 deletions(-) create mode 100644 src/main/java/cokr/xit/fims/cmmn/CellDecorator.java diff --git a/src/main/java/cokr/xit/fims/cmmn/CellDecorator.java b/src/main/java/cokr/xit/fims/cmmn/CellDecorator.java new file mode 100644 index 00000000..614a9c5c --- /dev/null +++ b/src/main/java/cokr/xit/fims/cmmn/CellDecorator.java @@ -0,0 +1,23 @@ +package cokr.xit.fims.cmmn; + +import java.util.Map; +import java.util.function.Function; + +public class CellDecorator { + + private Function, Object> cellValue; + private Function, Runnable> cellMemo; + + public Function, Object> value(){ + return this.cellValue; + } + public Function, Runnable> memo(){ + return this.cellMemo; + } + + public CellDecorator(Function, Object> valueDeco, Function, Runnable> memoDeco) { + this.cellValue = valueDeco; + this.cellMemo = memoDeco; + } + +} diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnQuery.java b/src/main/java/cokr/xit/fims/cmmn/CmmnQuery.java index 71a97836..e9ab5c18 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnQuery.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnQuery.java @@ -10,6 +10,7 @@ public class CmmnQuery extends QueryRequest { private String subOption; private String cellDefs; + private String includePhoto; private String thisDay; @@ -57,6 +58,15 @@ public class CmmnQuery extends QueryRequest { return self(); } + public String getIncludePhoto() { + return ifEmpty(includePhoto, () -> null); + } + + public T setIncludePhoto(String includePhoto) { + this.includePhoto = includePhoto; + 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 601d9c58..c5ad4144 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java @@ -20,6 +20,7 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -32,6 +33,7 @@ import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.HorizontalAlignment; import cokr.xit.base.file.xls.XLSWriter; +import cokr.xit.base.file.xls.XLSWriter.CommentSupport; import cokr.xit.fims.sndb.service.bean.SndngBean; import cokr.xit.foundation.data.DataObject; @@ -445,6 +447,10 @@ public class CmmnUtil { return band6; } + /** 엑셀파일 공통 헤더 스타일 생성 + * @param xlsx + * @return XLSWriter.Styler + */ public static XLSWriter.Styler headerStyle(XLSWriter xlsx) { return new XLSWriter.Styler() .foregroundColor(HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getIndex()) @@ -455,4 +461,62 @@ public class CmmnUtil { styler.alignment(HorizontalAlignment.CENTER); }); } + + /** 엑셀파일 결재용 사진 첨부 셀 처리 객체 생성 + * @param commentSupport 엑셀파일 메모 지원 클래스, pathCol 사진 파일 경로 컬럼명 + * @return CellDecorator + */ + public static CellDecorator photoCellForApproval(CommentSupport commentSupport, String pathCol) { + + Function, Object> valueDeco = new Function, Object>() { + @Override + public Object apply(Map row) { + if(row.get(pathCol) == null) { + return "없음"; + } + if(row.get(pathCol).equals("")) { + return "없음"; + } + if(!(new File((String)row.get(pathCol))).exists()) { + return "이미지 오류"; + } + if((new File((String)row.get(pathCol))).length() == 0) { + return "이미지 오류"; + } + if((new File((String)row.get(pathCol))).length() > (1024 * 1024 * 3)){ + return "사진크기(3MB)초과"; + } + + return ""; + + } + }; + + Function, Runnable> memoDeco = new Function, Runnable>() { + @Override + public Runnable apply(Map row) { + if(row.get(pathCol) == null) { + return () -> {}; + } + if(row.get(pathCol).equals("")) { + return () -> {}; + } + if(!(new File((String)row.get(pathCol))).exists()) { + return () -> {}; + } + if((new File((String)row.get(pathCol))).length() == 0) { + return () -> {}; + } + if((new File((String)row.get(pathCol))).length() > (1024 * 1024 * 3)){ + return () -> {}; + } + + return commentSupport.getImageCommenter((String)row.get(pathCol)); + + } + }; + + CellDecorator decorator = new CellDecorator(valueDeco, memoDeco); + return decorator; + } } \ No newline at end of file diff --git a/src/main/java/cokr/xit/fims/crdn/web/Crdn06Controller.java b/src/main/java/cokr/xit/fims/crdn/web/Crdn06Controller.java index a9b31a28..006b7d2f 100644 --- a/src/main/java/cokr/xit/fims/crdn/web/Crdn06Controller.java +++ b/src/main/java/cokr/xit/fims/crdn/web/Crdn06Controller.java @@ -1,6 +1,6 @@ package cokr.xit.fims.crdn.web; -import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -9,15 +9,17 @@ import javax.annotation.Resource; import org.apache.poi.ss.usermodel.CellStyle; import org.springframework.web.servlet.ModelAndView; -import com.fasterxml.jackson.core.type.TypeReference; - import cokr.xit.base.code.CommonCode; +import cokr.xit.base.file.service.FileQuery; +import cokr.xit.base.file.service.bean.FileBean; import cokr.xit.base.file.xls.XLSWriter; import cokr.xit.base.file.xls.XLSWriter.CellDef; +import cokr.xit.base.file.xls.XLSWriter.CommentSupport; import cokr.xit.base.file.xls.XLSWriter.Styler; import cokr.xit.base.user.ManagedUser; import cokr.xit.base.user.dao.UserMapper; import cokr.xit.base.web.ApplicationController; +import cokr.xit.fims.cmmn.CellDecorator; import cokr.xit.fims.cmmn.CmmnUtil; import cokr.xit.fims.cmmn.service.bean.StngBean; import cokr.xit.fims.crdn.Crdn; @@ -62,6 +64,9 @@ public class Crdn06Controller extends ApplicationController { @Resource(name="globalStngMapper") protected GlobalStngMapper globalStngMapper; + @Resource(name = "fileBean") + private FileBean fileBean; + @Resource(name = "stngBean") private StngBean stngBean; @@ -100,7 +105,12 @@ public class Crdn06Controller extends ApplicationController { query.setSggCd(sggCd); if("xls".equals(query.getDownload())) { - ArrayList cellDefs = fromJson(query.getCellDefs(), new TypeReference>() {}); + List cellDefs = fromJson(query.getCellDefs(), CellDef.listType()); + + if(ifEmpty(query.getIncludePhoto(), () -> "").equals("Y")) { + cellDefs.add((new CellDef()).setLabel("사진1").setWidth(18).setField("CRDN_PHOTO_PATH1")); + cellDefs.add((new CellDef()).setLabel("사진2").setWidth(18).setField("CRDN_PHOTO_PATH2")); + } XLSWriter xlsx = new XLSWriter() .setFilename("단속자료 목록.xlsx") @@ -111,19 +121,42 @@ public class Crdn06Controller extends ApplicationController { CellStyle dateDT = xlsx.yyyy_mm_dd_hh_mm_ss(); List list = crdnService.getCrackdownList(query.setFetchSize(0)); + if(ifEmpty(query.getIncludePhoto(), () -> "").equals("Y")) { + for(DataObject crdn : list) { + String crdnId = crdn.string("CRDN_ID"); + FileQuery fileQuery = new FileQuery(); + fileQuery.setInfoType(Crdn.INF_TYPE); + fileQuery.setInfoKeys(crdnId); + List fileInfoList = fileBean.getFileList(fileQuery); + + if(fileInfoList != null && fileInfoList.size() > 0) { + for(int j=0; (j < fileInfoList.size()) && (j < 2); j++) { + crdn.set("CRDN_PHOTO_PATH"+(j+1), fileInfoList.get(j).string("FILE_PATH")); + } + } + } + } + + Map valueMap = new HashMap(); + valueMap.put("자료출처", xlsx.style("CRDN_INPT_SE_NM", center)); + valueMap.put("위반일시", xlsx.format(o -> xlsx.str2datetime(o.get("CRDN_YMD_TM"))).style(dateDT)); + valueMap.put("사진건수", xlsx.style("ATCH_FILE_CNT", center)); + valueMap.put("장애차량확인", xlsx.style("PARKNG_PSBLTY_RSLT_NM", center)); + valueMap.put("처리상태", xlsx.style("CRDN_STTS_NM", center)); + valueMap.put("제외사유", xlsx.style("LEVY_EXCL_RSN_NM", center)); + valueMap.put("제외처리일자", xlsx.format(o -> xlsx.str2date(o.get("LEVY_EXCL_YMD"))).style(dateYMD)); + + if(ifEmpty(query.getIncludePhoto(), () -> "").equals("Y")) { + CommentSupport commentSupport = new CommentSupport(xlsx); + + CellDecorator col1 = CmmnUtil.photoCellForApproval(commentSupport, "CRDN_PHOTO_PATH1"); + CellDecorator col2 = CmmnUtil.photoCellForApproval(commentSupport, "CRDN_PHOTO_PATH2"); + + valueMap.put("사진1", xlsx.format(col1.value()).onCell(col1.memo())); + valueMap.put("사진2", xlsx.format(col2.value()).onCell(col2.memo())); + } - CellDef.setValues( - cellDefs, - Map.of( - "자료출처", xlsx.style("CRDN_INPT_SE_NM", center), - "위반일시", xlsx.format(o -> xlsx.str2datetime(o.get("CRDN_YMD_TM"))).style(dateDT), - "사진건수", xlsx.style("ATCH_FILE_CNT", center), - "장애차량확인", xlsx.style("PARKNG_PSBLTY_RSLT_NM", center), - "처리상태", xlsx.style("CRDN_STTS_NM", center), - "제외사유", xlsx.style("LEVY_EXCL_RSN_NM", center), - "제외처리일자", xlsx.format(o -> xlsx.str2date(o.get("LEVY_EXCL_YMD"))).style(dateYMD) - ) - ); + CellDef.setValues(cellDefs, valueMap); xlsx.cell(0, 0) .value("단속자료 목록", center) 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 ea91d21c..b519d335 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 @@ -16,6 +16,9 @@ + @@ -529,15 +532,8 @@ $(document).ready(function(){ } }); } - - /************************************************************************** - * element.on - **************************************************************************/ - $('#btnReset--${pageName}').on('click', () => $P.fnReset()); - $('#btnSearch--${pageName}').on('click', () => $P.searchCrdnList()); - $('#btnExcel--${pageName}').on('click', function(){ - - if($P.crdnControl.dataset.empty){ + $P.fnExcelDown = (forApproval) => { + if($P.crdnControl.dataset.empty){ alert("조회된 자료가 없습니다."); return; } @@ -546,8 +542,24 @@ $(document).ready(function(){ $($("#crdnRow--${pageName}")[0].content).find("td").not(".dummy-td").not(":eq(0)").not(":eq(0)")); $P.crdnControl.query.cellDefs = cellDefs; + if(forApproval){ + $P.crdnControl.query.includePhoto = "Y"; + } else { + $P.crdnControl.query.includePhoto = "N"; + } + $P.crdnControl.download(); - }); + + $P.crdnControl.query.includePhoto = null; + }; + + /************************************************************************** + * element.on + **************************************************************************/ + $('#btnReset--${pageName}').on('click', () => $P.fnReset()); + $('#btnSearch--${pageName}').on('click', () => $P.searchCrdnList()); + $('#btnExcel--${pageName}').on('click', () => $P.fnExcelDown(false)); + $('#btnExcelForApproval--${pageName}').on('click', () => $P.fnExcelDown(true)); fnMakeScrollableTable($("#table-responsive--${pageName}")[0], $P.scrollCrdnList);