diff --git a/pom.xml b/pom.xml index 964a1093..ca194eac 100644 --- a/pom.xml +++ b/pom.xml @@ -70,13 +70,6 @@ runtime - - - cokr.xit.base - xit-docs - 23.04.01-SNAPSHOT - - cokr.xit.interfaces diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java index 6329915d..35a250aa 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java @@ -21,7 +21,6 @@ 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; @@ -36,8 +35,6 @@ import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.springframework.core.io.ClassPathResource; import cokr.xit.base.file.xls.XLSWriter; -import cokr.xit.base.file.xls.XLSWriter.CommentSupport; -import cokr.xit.fims.cmmn.xls.CellDecorator; import cokr.xit.fims.sndb.service.bean.SndngBean; import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.util.DateFormats; @@ -558,6 +555,14 @@ public class CmmnUtil { dataObject.put("BARCODE1", barcode); } + public static int[] intArray(int len) { + int[] arr = new int[len]; + for(int i=0; i < len; i++) { + arr[i] = i; + } + return arr; + } + /** 엑셀파일 공통 헤더 스타일 생성 * @param xlsx * @return XLSWriter.Styler @@ -573,63 +578,7 @@ public class CmmnUtil { }); } - /** 엑셀파일 결재용 사진 첨부 셀 처리 객체 생성 - * @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/cmmn/xls/CellDecorator.java b/src/main/java/cokr/xit/fims/cmmn/xls/CellDecorator.java deleted file mode 100644 index 83151bfb..00000000 --- a/src/main/java/cokr/xit/fims/cmmn/xls/CellDecorator.java +++ /dev/null @@ -1,23 +0,0 @@ -package cokr.xit.fims.cmmn.xls; - -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/xls/FormatMaker.java b/src/main/java/cokr/xit/fims/cmmn/xls/FormatMaker.java new file mode 100644 index 00000000..0d5d6b29 --- /dev/null +++ b/src/main/java/cokr/xit/fims/cmmn/xls/FormatMaker.java @@ -0,0 +1,76 @@ +package cokr.xit.fims.cmmn.xls; + +import java.io.File; +import java.util.Map; + +import org.apache.poi.hssf.util.HSSFColor; +import org.apache.poi.ss.usermodel.CellStyle; + +import cokr.xit.base.docs.xls.Comment; +import cokr.xit.base.docs.xls.Format; +import cokr.xit.base.docs.xls.Style; +import cokr.xit.foundation.data.DataFormat; + +public class FormatMaker { + + public static Format photoCellForApproval(Format format, Comment comment, String key) { + return format.of(key) + .value(obj -> { + if(((Map)obj).get(key) == null) { + return "없음"; + } + String value = (String)((Map)obj).get(key); + if(value.equals("")) { + return "없음"; + } + if(!(new File(value)).exists()) { + return "이미지 경로 존재하지 않음"; + } + if((new File(value)).length() == 0) { + return "이미지 크기 오류"; + } + if((new File(value)).length() > (1024 * 1024 * 3)){ + return "사진크기(3MB)초과"; + } + return " "; + }) + .onCell(obj -> { + if(((Map)obj).get(key) == null) { return; } + String value = (String)((Map)obj).get(key); + if(value.equals("")) { return; } + if(!(new File(value)).exists()) { return; } + if((new File(value)).length() == 0) { return; } + if((new File(value)).length() > (1024 * 1024 * 3)){ return; } + + comment.setImageComment((String)((Map)obj).get(key)); + }) + .style(new Style().foregroundColor(HSSFColor.HSSFColorPredefined.YELLOW.getIndex())); + } + + + public static Format yyyy_mm_dd_hh_mm_ss(Format format, CellStyle dateDT, String key) { + return format.of(key).value(o -> { + return DataFormat.yyyy_mm_dd_hh_mm_ss(((Map) o).get(key)); + }).style(dateDT); + } + + + public static Format yyyy_mm_dd(Format format, CellStyle dateYMD, String key) { + return format.of(key).value(o -> { + return DataFormat.yyyy_mm_dd_hh_mm_ss(((Map) o).get(key)); + }).style(dateYMD); + } + + public static Format key(Format format, CellStyle style, String key) { + return format.of(key).value(o -> { + return ((Map) o).get(key); + }).style(style); + } + + public static Format key(Format format, String key) { + return format.of(key).value(o -> { + return ((Map) o).get(key); + }); + } + +} diff --git a/src/main/java/cokr/xit/fims/cmmn/xls/StyleMaker.java b/src/main/java/cokr/xit/fims/cmmn/xls/StyleMaker.java new file mode 100644 index 00000000..ad7bd1d4 --- /dev/null +++ b/src/main/java/cokr/xit/fims/cmmn/xls/StyleMaker.java @@ -0,0 +1,24 @@ +package cokr.xit.fims.cmmn.xls; + +import org.apache.poi.hssf.util.HSSFColor; +import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.ss.usermodel.HorizontalAlignment; + +import cokr.xit.base.docs.xls.Style; +import cokr.xit.base.docs.xls.XLSWriter; + + +public class StyleMaker { + + public static Style headerStyle(XLSWriter xlsx) { + return new Style() + .foregroundColor(HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getIndex()) + .configure(styl -> { + Font font = xlsx.workbook().createFont(); + font.setColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex()); + styl.font(font); + styl.alignment(HorizontalAlignment.CENTER); + }); + } + +} 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 9fcacf15..c631f7c0 100644 --- a/src/main/java/cokr/xit/fims/crdn/web/Crdn06Controller.java +++ b/src/main/java/cokr/xit/fims/crdn/web/Crdn06Controller.java @@ -7,23 +7,26 @@ import java.util.Map; import javax.annotation.Resource; import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import cokr.xit.base.code.CommonCode; +import cokr.xit.base.docs.xls.CellDef; +import cokr.xit.base.docs.xls.Comment; +import cokr.xit.base.docs.xls.Format; +import cokr.xit.base.docs.xls.Style; +import cokr.xit.base.docs.xls.XLSWriter; 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.CmmnUtil; import cokr.xit.fims.cmmn.service.bean.StngBean; -import cokr.xit.fims.cmmn.xls.CellDecorator; +import cokr.xit.fims.cmmn.xls.FormatMaker; +import cokr.xit.fims.cmmn.xls.StyleMaker; import cokr.xit.fims.crdn.Crdn; import cokr.xit.fims.crdn.CrdnQuery; import cokr.xit.fims.crdn.dao.CrdnStngMapper; @@ -113,19 +116,37 @@ public class Crdn06Controller extends ApplicationController { if("xls".equals(query.getDownload())) { 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") - .worksheet(0); + XLSWriter xlsx = new XLSWriter().worksheet(0).trackWidth(CmmnUtil.intArray(cellDefs.size())); + Format format = new Format(xlsx); + Comment comment = new Comment(xlsx); + + CellStyle center = format.cellStyle(new Style().alignment(HorizontalAlignment.CENTER)); + CellStyle left = format.cellStyle(new Style().alignment(HorizontalAlignment.LEFT)); + CellStyle dateYMD = format.yyyy_mm_dd(); + CellStyle dateDT = format.yyyy_mm_dd_hh_mm_ss(); - CellStyle center = xlsx.cellStyle(Styler.CENTER); - CellStyle dateYMD = xlsx.yyyy_mm_dd(); - CellStyle dateDT = xlsx.yyyy_mm_dd_hh_mm_ss(); + Map valueMap = new HashMap(); + valueMap.put("자료출처", FormatMaker.key(format, center, "CRDN_INPT_SE_NM")); + valueMap.put("차량번호", left); + valueMap.put("위반일시", FormatMaker.yyyy_mm_dd_hh_mm_ss(format,dateDT,"CRDN_YMD_TM")); + valueMap.put("단속장소", left); + valueMap.put("사진건수", center); + valueMap.put("스티커번호", left); + valueMap.put("장애차량확인", FormatMaker.key(format, center, "PARKNG_PSBLTY_RSLT_NM")); + valueMap.put("처리상태", FormatMaker.key(format, center, "CRDN_STTS_NM")); + valueMap.put("제외사유", FormatMaker.key(format, center, "LEVY_EXCL_RSN_NM")); + valueMap.put("제외처리일자", FormatMaker.yyyy_mm_dd(format,dateYMD,"LEVY_EXCL_YMD")); + valueMap.put("제외내역", left); + if(ifEmpty(query.getIncludePhoto(), () -> "").equals("Y")) { + valueMap.put("사진1", FormatMaker.photoCellForApproval(format, comment, "CRDN_PHOTO_PATH1")); + valueMap.put("사진2", FormatMaker.photoCellForApproval(format, comment, "CRDN_PHOTO_PATH2")); + } + CellDef.setValues(cellDefs, valueMap); List list = crdnService.getCrackdownList(query.setFetchSize(0)); if(ifEmpty(query.getIncludePhoto(), () -> "").equals("Y")) { @@ -144,37 +165,15 @@ public class Crdn06Controller extends ApplicationController { } } - 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, valueMap); - - xlsx.cell(0, 0) - .value("단속자료 목록", center) - .merge(0, cellDefs.size()-1) - .cell(3, 0) - .rowValues(CellDef.header(cellDefs, () -> CmmnUtil.headerStyle(xlsx))) - .cell(4, 0) - .values(list, CellDef.values(cellDefs)); - - return new ModelAndView("xlsView").addObject("xls", xlsx) - .addObject("downloadData", list).addObject("dataNames", cellDefs.stream().map(CellDef::getLabel).toList()); + xlsx.cell(0, 0).value("단속자료 목록").value(center).merge(0, cellDefs.size()-1); + xlsx.cell(3, 0).rowValues(CellDef.header(cellDefs, () -> StyleMaker.headerStyle(xlsx))); + xlsx.cell(4, 0).values(list, CellDef.values(cellDefs.stream().map(i -> {if(i.getValue() instanceof Format) {i.setField(null);}; return i;}).toList())); + xlsx.autoWidth(); + ModelAndView mav = new ModelAndView("downloadView"); + mav.addObject("download", xlsx.getDownloadable().setFilename("단속자료 목록.xlsx")); + mav.addObject("downloadData", list); + mav.addObject("dataNames", cellDefs.stream().map(CellDef::getLabel).toList()); + return mav; } return setCollectionInfo(new ModelAndView("jsonView"), crdnService.getCrackdownList(query),"",""); diff --git a/src/main/java/cokr/xit/fims/cvlc/web/Cvlc02Controller.java b/src/main/java/cokr/xit/fims/cvlc/web/Cvlc02Controller.java index ecb658d4..c3807a14 100644 --- a/src/main/java/cokr/xit/fims/cvlc/web/Cvlc02Controller.java +++ b/src/main/java/cokr/xit/fims/cvlc/web/Cvlc02Controller.java @@ -8,23 +8,26 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import cokr.xit.base.code.CommonCode; +import cokr.xit.base.docs.xls.CellDef; +import cokr.xit.base.docs.xls.Comment; +import cokr.xit.base.docs.xls.Format; +import cokr.xit.base.docs.xls.Style; +import cokr.xit.base.docs.xls.XLSWriter; 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.CmmnUtil; import cokr.xit.fims.cmmn.service.bean.StngBean; -import cokr.xit.fims.cmmn.xls.CellDecorator; +import cokr.xit.fims.cmmn.xls.FormatMaker; +import cokr.xit.fims.cmmn.xls.StyleMaker; import cokr.xit.fims.crdn.Crdn; import cokr.xit.fims.crdn.CrdnQuery; import cokr.xit.fims.crdn.service.CrdnService; @@ -104,19 +107,38 @@ public class Cvlc02Controller extends ApplicationController { if("xls".equals(query.getDownload())) { 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") - .worksheet(0); + XLSWriter xlsx = new XLSWriter().worksheet(0).trackWidth(CmmnUtil.intArray(cellDefs.size())); + Format format = new Format(xlsx); + Comment comment = new Comment(xlsx); - CellStyle center = xlsx.cellStyle(Styler.CENTER); - CellStyle dateYMD = xlsx.yyyy_mm_dd(); - CellStyle dateDT = xlsx.yyyy_mm_dd_hh_mm_ss(); + CellStyle center = format.cellStyle(new Style().alignment(HorizontalAlignment.CENTER)); + CellStyle left = format.cellStyle(new Style().alignment(HorizontalAlignment.LEFT)); + CellStyle dateYMD = format.yyyy_mm_dd(); + CellStyle dateDT = format.yyyy_mm_dd_hh_mm_ss(); + + Map valueMap = new HashMap(); + valueMap.put("접수번호", center); + valueMap.put("목록번호", center); + valueMap.put("신고자", center); + valueMap.put("담당자", center); + valueMap.put("담당자전화번호", center); + valueMap.put("접수일자", FormatMaker.yyyy_mm_dd(format,dateYMD,"CVLCPT_RCPT_YMD")); + valueMap.put("처리기한", FormatMaker.yyyy_mm_dd_hh_mm_ss(format,dateDT,"CVLCPT_PRCS_PRNMNT_DT")); + valueMap.put("위반일시", FormatMaker.yyyy_mm_dd_hh_mm_ss(format,dateDT,"CRDN_YMD_TM")); + valueMap.put("위반내용", center); + valueMap.put("차량번호", left); + valueMap.put("서손/계고사유", center); + valueMap.put("특기사항", left); + if(ifEmpty(query.getIncludePhoto(), () -> "").equals("Y")) { + valueMap.put("사진1", FormatMaker.photoCellForApproval(format, comment, "CRDN_PHOTO_PATH1")); + valueMap.put("사진2", FormatMaker.photoCellForApproval(format, comment, "CRDN_PHOTO_PATH2")); + } + CellDef.setValues(cellDefs, valueMap); List list = crdnCvlcptService.getCivilComplaintList(query.setFetchSize(0)); if(ifEmpty(query.getIncludePhoto(), () -> "").equals("Y")) { @@ -135,48 +157,15 @@ public class Cvlc02Controller extends ApplicationController { } } - Map valueMap = new HashMap(); - valueMap.put("접수번호", xlsx.style("CVLCPT_RCPT_NO", center)); - valueMap.put("목록번호", xlsx.style("CVLCPT_LIST_NO", center)); - valueMap.put("신고자", xlsx.style("CVLCPT_APLCNT_NM", center)); - valueMap.put("담당자", xlsx.style("CVLCPT_PRCS_PIC_NM", center)); - valueMap.put("담당자전화번호", xlsx.style("CVLCPT_PRCS_PIC_TELNO", center)); - valueMap.put("접수일자", xlsx.format(o -> xlsx.str2date(o.get("CVLCPT_RCPT_YMD"))).style(dateYMD)); - valueMap.put("처리기한", xlsx.format(o -> { - if(o.get("CVLCPT_PRCS_PRNMNT_DT") != null && ((String)o.get("CVLCPT_PRCS_PRNMNT_DT")).length() > 8) { - return xlsx.str2datetime(o.get("CVLCPT_PRCS_PRNMNT_DT")); - } else { - return xlsx.str2date(o.get("CVLCPT_PRCS_PRNMNT_DT")); - } - }).style(dateDT)); - valueMap.put("위반일시", xlsx.format(o -> xlsx.str2datetime(o.get("CRDN_YMD_TM"))).style(dateDT)); - valueMap.put("위반내용", xlsx.style("VLTN_ARTCL", center)); - valueMap.put("차량번호", "VHRNO"); - valueMap.put("서손/계고사유", xlsx.style("LEVY_EXCL_RSN_NM", center)); - valueMap.put("특기사항", "ETC_CN"); - - 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, valueMap); - - xlsx.cell(0, 0) - .value("민원답변대상자료 목록", center) - .merge(0, cellDefs.size()-1) - .cell(3, 0) - .rowValues(CellDef.header(cellDefs, () -> CmmnUtil.headerStyle(xlsx))) - .cell(4, 0) - .values(list, CellDef.values(cellDefs)); - - return new ModelAndView("xlsView").addObject("xls", xlsx) - .addObject("downloadData", list).addObject("dataNames", cellDefs.stream().map(CellDef::getLabel).toList()); + xlsx.cell(0, 0).value("민원답변대상자료 목록").value(center).merge(0, cellDefs.size()-1); + xlsx.cell(3, 0).rowValues(CellDef.header(cellDefs, () -> StyleMaker.headerStyle(xlsx))); + xlsx.cell(4, 0).values(list, CellDef.values(cellDefs.stream().map(i -> {if(i.getValue() instanceof Format) {i.setField(null);}; return i;}).toList())); + xlsx.autoWidth(); + ModelAndView mav = new ModelAndView("downloadView"); + mav.addObject("download", xlsx.getDownloadable().setFilename("민원답변대상자료 목록.xlsx")); + mav.addObject("downloadData", list); + mav.addObject("dataNames", cellDefs.stream().map(CellDef::getLabel).toList()); + return mav; } return setCollectionInfo(new ModelAndView("jsonView"), crdnCvlcptService.getCivilComplaintList(query),"","");