fix: 제품구분별현황, 제품별폐기현황 엑셀다운로드 구현

dev
Jonguk. Lim 4 months ago
parent ca58dafde8
commit 3c991074da

@ -24,6 +24,7 @@ import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -988,17 +989,26 @@ public class AddsNimsController extends ApplicationController {
CellDef.setValues(cellDefs, valueMap); CellDef.setValues(cellDefs, valueMap);
Style headerStyle = new Style().foregroundColor(HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getIndex())
.configure(styl -> {
styl.alignment(HorizontalAlignment.CENTER);
styl.alignment(VerticalAlignment.CENTER);
});
Style headerStyle2 = new Style().foregroundColor(HSSFColor.HSSFColorPredefined.GREY_50_PERCENT.getIndex()) Style headerStyle2 = new Style().foregroundColor(HSSFColor.HSSFColorPredefined.GREY_50_PERCENT.getIndex())
.configure(styl -> { .configure(styl -> {
Font font = xlsx.workbook().createFont(); Font font = xlsx.workbook().createFont();
font.setColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex()); font.setColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
styl.alignment(HorizontalAlignment.CENTER); styl.alignment(HorizontalAlignment.CENTER);
styl.alignment(VerticalAlignment.CENTER);
}); });
xlsx.cell(0, 0).value("마약류 제품 구분별 현황").value(center).merge(0, cellDefs.size()-1); xlsx.cell(0, 1).value("마약류 제품 구분별 현황").value(center).merge(1, cellDefs.size()-1);
// 관할관청 - rowspan
xlsx.cell(2, 0).value("관할관청").value(headerStyle).merge(2, 3, 0, 0);
xlsx.cell(2, 1).value("마약/향정 구분(폐기건수 / 폐기수량)").value(headerStyle2).merge(1, 7); xlsx.cell(2, 1).value("마약/향정 구분(폐기건수 / 폐기수량)").value(headerStyle2).merge(1, 7);
xlsx.cell(2, 8).value("중점/일반 구분(폐기건수 / 폐기수량)").value(headerStyle2).merge(8, 11); xlsx.cell(2, 8).value("중점/일반 구분(폐기건수 / 폐기수량)").value(headerStyle2).merge(8, 11);
xlsx.cell(3, 0).rowValues(CellDef.header(cellDefs, () -> StyleMaker.headerStyle(xlsx))); List<CellDef> cellDefs2 = cellDefs.subList(1, cellDefs.size());
xlsx.cell(3, 1).rowValues(CellDef.header(cellDefs2, () -> 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.cell(4, 0).values(list, CellDef.values(cellDefs.stream().map(i -> {if(i.getValue() instanceof Format) {i.setField(null);}; return i;}).toList()));
ModelAndView mav = new ModelAndView("downloadView"); ModelAndView mav = new ModelAndView("downloadView");
@ -1020,7 +1030,7 @@ public class AddsNimsController extends ApplicationController {
List<DataObject> list = addsNimsService.getDsuseMgtDsuseQyByPrdStatistics(query); List<DataObject> list = addsNimsService.getDsuseMgtDsuseQyByPrdStatistics(query);
Map<String, Object> valueMap = new HashMap<String, Object>(); Map<String, Object> valueMap = new HashMap<String, Object>();
valueMap.put("No.", format.of("ROW_NUM").style(center)); valueMap.put("NO.", format.of("ROW_NUM").style(center));
valueMap.put("관할관청", format.of("dept_nm").style(center)); valueMap.put("관할관청", format.of("dept_nm").style(center));
valueMap.put("제품코드", format.of("prduct_cd").style(center)); valueMap.put("제품코드", format.of("prduct_cd").style(center));
valueMap.put("제품명", format.of("prduct_nm").style(left)); valueMap.put("제품명", format.of("prduct_nm").style(left));
@ -1033,17 +1043,31 @@ public class AddsNimsController extends ApplicationController {
CellDef.setValues(cellDefs, valueMap); CellDef.setValues(cellDefs, valueMap);
Style headerStyle = new Style().foregroundColor(HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getIndex())
.configure(styl -> {
styl.alignment(HorizontalAlignment.CENTER);
styl.alignment(VerticalAlignment.CENTER);
});
Style headerStyle2 = new Style().foregroundColor(HSSFColor.HSSFColorPredefined.GREY_50_PERCENT.getIndex()) Style headerStyle2 = new Style().foregroundColor(HSSFColor.HSSFColorPredefined.GREY_50_PERCENT.getIndex())
.configure(styl -> { .configure(styl -> {
Font font = xlsx.workbook().createFont(); Font font = xlsx.workbook().createFont();
font.setColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex()); font.setColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
styl.alignment(HorizontalAlignment.CENTER); styl.alignment(HorizontalAlignment.CENTER);
styl.alignment(VerticalAlignment.CENTER);
}); });
xlsx.cell(0, 0).value("마약류 제품별 폐기 현황").value(center).merge(0, cellDefs.size()-1); xlsx.cell(0, 0).value("마약류 제품별 폐기 현황").value(center).merge(0, cellDefs.size()-1);
xlsx.cell(2, 1).value("마약/향정 구분").value(headerStyle2).merge(1, 7); // rowspan
xlsx.cell(2, 8).value("중점/일반 구분").value(headerStyle2).merge(8, 11); xlsx.cell(2, 0).value("NO.").value(headerStyle).merge(2, 3, 0, 0);
xlsx.cell(3, 0).rowValues(CellDef.header(cellDefs, () -> StyleMaker.headerStyle(xlsx))); xlsx.cell(2, 1).value("관할관청").value(headerStyle).merge(2, 3, 1, 1);
xlsx.cell(2, 2).value("제품코드").value(headerStyle).merge(2, 3, 2, 2);
xlsx.cell(2, 3).value("제품명").value(headerStyle).merge(2, 3, 3, 3);
xlsx.cell(2, 4).value("처리상태 별 (폐기건수 / 폐기수량)").value(headerStyle2).merge(4, 7);
xlsx.cell(2, 8).value("폐기건수").value(headerStyle).merge(2, 3, 8, 8);
xlsx.cell(2, 9).value("폐기수량").value(headerStyle).merge(2, 3, 9, 9);
List<CellDef> cellDefs2 = cellDefs.subList(4, cellDefs.size()-2);
xlsx.cell(3, 4).rowValues(CellDef.header(cellDefs2, () -> 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.cell(4, 0).values(list, CellDef.values(cellDefs.stream().map(i -> {if(i.getValue() instanceof Format) {i.setField(null);}; return i;}).toList()));
ModelAndView mav = new ModelAndView("downloadView"); ModelAndView mav = new ModelAndView("downloadView");

@ -303,8 +303,8 @@
// 끝에서 2개의 th 요소 선택 // 끝에서 2개의 th 요소 선택
let lastColNames = $(`#theadTr0--${pageName} th`).not("[colspan]").slice(-2); let lastColNames = $(`#theadTr0--${pageName} th`).not("[colspan]").slice(-2);
$P.control.query.cellDefs = getCellDefs2( $P.control.query.cellDefs = getCellDefs(
[...firstColNames, ...middleColNames, ...lastColNames], $([...firstColNames, ...middleColNames, ...lastColNames]),
$($("#${infoPrefix}Row--${pageName}")[0].content).find("td") $($("#${infoPrefix}Row--${pageName}")[0].content).find("td")
.not(".dummy-td").not(":eq(0)").not("[colspan]") .not(".dummy-td").not(":eq(0)").not("[colspan]")
); );
@ -383,43 +383,35 @@
$P.fnReset(); $P.fnReset();
}); });
function getCellDefs2(ths, $tds, fieldGetterOption){ // function getCellDefs2(ths, $tds, fieldGetterOption){
let cellDefs = []; // let cellDefs = [];
//
for(let i=0; i < ths.length; i++){ // ths.forEach((th, idx) => {
// let label = $(ths).text();
let label = $(ths[i]).text(); // label = label.replace("\n", "");
label = label.replace("\n", ""); // label = label.replace("\t", "");
label = label.replace("\t", ""); // label = label.replace(" ", "");
label = label.replace(" ", ""); //
// if(label !== ""){
if(label !== ""){ // let field = "";
// if(fieldGetterOption != null){
let width = $(ths[i]).outerWidth(); // field = fieldGetterOption($tds.eq(idx));
width = Math.ceil(width/10) + 2; // } else {
// field = $tds.eq(idx).text();
let field = ""; // }
if(fieldGetterOption != null){ // field = field.replace("{", "");
field = fieldGetterOption($tds.eq(i)); // field = field.replace("}", "");
} else { // field = field.replace("\n", "");
field = $tds.eq(i).text(); // field = field.replace("\t", "");
} // field = field.replace(" ", "");
//
field = field.replace("{", ""); // cellDefs.push({
field = field.replace("}", ""); // label : label,
field = field.replace("\n", ""); // width : Math.ceil($(ths).outerWidth()/10) + 2,
field = field.replace("\t", ""); // field : field
field = field.replace(" ", ""); // });
// }
cellDefs.push({ // });
label : label, // return JSON.stringify(cellDefs);
width : width, // }
field : field
});
}
}
return JSON.stringify(cellDefs);
}
</script> </script>

Loading…
Cancel
Save