단속관리 사진포함 엑셀다운 추가

main
이범준 9 months ago
parent c5fedc2193
commit 513c73ecee

@ -0,0 +1,23 @@
package cokr.xit.fims.cmmn;
import java.util.Map;
import java.util.function.Function;
public class CellDecorator {
private Function<Map<?, ?>, Object> cellValue;
private Function<Map<?, ?>, Runnable> cellMemo;
public Function<Map<?, ?>, Object> value(){
return this.cellValue;
}
public Function<Map<?, ?>, Runnable> memo(){
return this.cellMemo;
}
public CellDecorator(Function<Map<?, ?>, Object> valueDeco, Function<Map<?, ?>, Runnable> memoDeco) {
this.cellValue = valueDeco;
this.cellMemo = memoDeco;
}
}

@ -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 extends CmmnQuery> T setIncludePhoto(String includePhoto) {
this.includePhoto = includePhoto;
return self();
}
public String getThisDay() {
return ifEmpty(thisDay, () -> null);
}

@ -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<Map<?, ?>, Object> valueDeco = new Function<Map<?,?>, 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<Map<?, ?>, Runnable> memoDeco = new Function<Map<?,?>, 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;
}
}

@ -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<CellDef> cellDefs = fromJson(query.getCellDefs(), new TypeReference<ArrayList<CellDef>>() {});
List<CellDef> 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<DataObject> 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<DataObject> 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<String,Object> valueMap = new HashMap<String,Object>();
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)

@ -16,6 +16,9 @@
<button type="button" id="btnExcel--${pageName}" class="btn btn-excel w-px-120" title="엑셀 저장">
엑셀
</button>
<button type="button" id="btnExcelForApproval--${pageName}" class="btn btn-excel w-px-120" title="엑셀 저장">
엑셀(사진 포함)
</button>
</span>
</div>
@ -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);

Loading…
Cancel
Save