From 671fa173de49663d2dfd7097a6753185e8231925 Mon Sep 17 00:00:00 2001 From: leeheejin Date: Tue, 16 Dec 2025 16:53:47 +0900 Subject: [PATCH] =?UTF-8?q?=EC=97=91=EC=85=80=EA=B9=8C=EC=A7=80=20?= =?UTF-8?q?=EC=9D=BC=EB=8B=A8=20=ED=95=B4=EB=86=93=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../classes/com/pms/mapper/quality.xml | 137 +++++++++------ .../view/quality/incomingInspectionList.jsp | 13 -- .../view/quality/processInspectionList.jsp | 13 -- .../quality/semiProductInspectionExcel.jsp | 96 +++++++++++ .../quality/semiProductInspectionList.jsp | 159 +++++++++++++++++- src/com/pms/controller/QualityController.java | 25 ++- src/com/pms/mapper/quality.xml | 137 +++++++++------ 7 files changed, 441 insertions(+), 139 deletions(-) create mode 100644 WebContent/WEB-INF/view/quality/semiProductInspectionExcel.jsp diff --git a/WebContent/WEB-INF/classes/com/pms/mapper/quality.xml b/WebContent/WEB-INF/classes/com/pms/mapper/quality.xml index c6eb1af..4d6357e 100644 --- a/WebContent/WEB-INF/classes/com/pms/mapper/quality.xml +++ b/WebContent/WEB-INF/classes/com/pms/mapper/quality.xml @@ -1340,61 +1340,96 @@ ORDER BY MIN(T.INSPECTION_DATE) DESC, T.INSPECTION_GROUP_ID - + diff --git a/WebContent/WEB-INF/view/quality/incomingInspectionList.jsp b/WebContent/WEB-INF/view/quality/incomingInspectionList.jsp index 3510ef4..a37be9b 100644 --- a/WebContent/WEB-INF/view/quality/incomingInspectionList.jsp +++ b/WebContent/WEB-INF/view/quality/incomingInspectionList.jsp @@ -76,11 +76,6 @@ $(document).ready(function(){ fn_registPopUp(); }); - // 엑셀 다운로드 - $("#btnExcel").click(function(){ - fn_excelDownload(); - }); - fn_search(); }); @@ -204,13 +199,6 @@ function fn_formPopUp(objId){ hiddenForm.submit(); } -// 엑셀 다운로드 -function fn_excelDownload(){ - var form = document.form1; - form.action = "/quality/incomingInspectionExcelDownload.do"; - form.submit(); - form.action = ""; -} @@ -231,7 +219,6 @@ function fn_excelDownload(){
-
diff --git a/WebContent/WEB-INF/view/quality/processInspectionList.jsp b/WebContent/WEB-INF/view/quality/processInspectionList.jsp index 4fc59a7..8f83344 100644 --- a/WebContent/WEB-INF/view/quality/processInspectionList.jsp +++ b/WebContent/WEB-INF/view/quality/processInspectionList.jsp @@ -79,11 +79,6 @@ $(document).ready(function(){ fn_registPopUp(); }); - // 엑셀 다운로드 - $("#btnExcel").click(function(){ - fn_excelDownload(); - }); - fn_search(); }); @@ -147,13 +142,6 @@ function fn_registPopUp(){ window.open(url, "processInspectionPopUp", "width=" + popup_width + ",height=" + popup_height + ",scrollbars=yes,resizable=yes"); } -// 엑셀 다운로드 -function fn_excelDownload(){ - var form = document.form1; - form.action = "/quality/processInspectionExcelDownload.do"; - form.submit(); - form.action = ""; -} @@ -172,7 +160,6 @@ function fn_excelDownload(){
-
diff --git a/WebContent/WEB-INF/view/quality/semiProductInspectionExcel.jsp b/WebContent/WEB-INF/view/quality/semiProductInspectionExcel.jsp new file mode 100644 index 0000000..3851585 --- /dev/null +++ b/WebContent/WEB-INF/view/quality/semiProductInspectionExcel.jsp @@ -0,0 +1,96 @@ +<%@ page isThreadSafe = "true" %> +<%@ page buffer="256kb" %> +<%@ page autoFlush = "true" %> +<%@ page contentType="application/vnd.ms-excel;charset=UTF-8" %> +<%@ page import="com.pms.common.utils.*"%> +<%@ page import="java.util.*" %> +<% +java.text.SimpleDateFormat frm= new java.text.SimpleDateFormat ("yyyy_MM_dd_HH_mm"); +Calendar cal = Calendar.getInstance(); +String todayKor = frm.format(cal.getTime()); + +String excelName = "품질관리_반제품검사관리"; +String encodeName = excelName + todayKor + ".xls"; +String fileName = java.net.URLEncoder.encode(encodeName,"UTF-8"); + +response.setHeader("Content-Disposition", "attachment;filename=" + fileName); +response.setHeader("Content-Description", "JSP Generated Data"); +List list = (List)request.getAttribute("LIST"); +%> + + + + + +<%=Constants.SYSTEM_NAME%> + + +
+ +
+ + + diff --git a/WebContent/WEB-INF/view/quality/semiProductInspectionList.jsp b/WebContent/WEB-INF/view/quality/semiProductInspectionList.jsp index 9f2d387..f51747a 100644 --- a/WebContent/WEB-INF/view/quality/semiProductInspectionList.jsp +++ b/WebContent/WEB-INF/view/quality/semiProductInspectionList.jsp @@ -76,7 +76,7 @@ $(document).ready(function(){ fn_registPopUp(); }); - // 엑셀 다운로드 + // 엑셀 다운로드 (원본 데이터) $("#btnExcel").click(function(){ fn_excelDownload(); }); @@ -84,6 +84,153 @@ $(document).ready(function(){ fn_search(); }); +// 엑셀 다운로드 (원본 데이터 - 외 N건 풀어서) +function fn_excelDownload(){ + // 서버에서 원본 데이터 가져오기 + var params = { + search_model_name: $("#search_model_name").val() || "", + search_work_order_no: $("#search_work_order_no").val() || "", + search_part_no: $("#search_part_no").val() || "", + search_part_name: $("#search_part_name").val() || "", + search_inspection_date: $("#search_inspection_date").val() || "", + search_writer: $("#search_writer").val() || "" + }; + + $.ajax({ + url: "/quality/getSemiProductInspectionListForExcel.do", + type: "POST", + data: params, + dataType: "json", + success: function(result){ + if(result && result.list && result.list.length > 0){ + createExcelFile(result.list); + } else { + Swal.fire("다운로드할 데이터가 없습니다."); + } + }, + error: function(xhr, status, error){ + console.error("엑셀 데이터 조회 실패:", error); + Swal.fire("엑셀 데이터 조회 중 오류가 발생했습니다."); + } + }); +} + +// ExcelJS로 원본 데이터 엑셀 파일 생성 (공통 스타일 적용) +async function createExcelFile(data){ + var pageTitle = "반제품검사관리"; + const workbook = new ExcelJS.Workbook(); + const worksheet = workbook.addWorksheet(pageTitle); + + // 헤더 설정 + var headers = ["No", "품명(모델명)", "제품구분", "작업지시번호", "부품품번", "부품명", + "입고수량 합계", "양품수량 합계", "불량수량 합계", "불량율(%)", "재생수량 합계", "최종양품수량 합계", + "검사일", "검사자", "불량유형", "불량원인", "귀책부서", "처리현황", "처리결과", "비고"]; + + // 열 너비 설정 + var colWidths = [6, 25, 12, 18, 20, 25, 15, 15, 15, 12, 15, 18, 12, 12, 15, 15, 12, 12, 12, 20]; + colWidths.forEach(function(width, idx){ + worksheet.getColumn(idx + 1).width = width; + }); + + // 제목 행 추가 + worksheet.mergeCells('A1:T1'); + var titleCell = worksheet.getCell('A1'); + titleCell.value = pageTitle; + titleCell.font = { size: 16, bold: true }; + titleCell.alignment = { vertical: 'middle', horizontal: 'center' }; + worksheet.getRow(1).height = 30; + + // 빈 행 추가 + worksheet.addRow([]); + + // 헤더 행 추가 (3행) + var headerRow = worksheet.addRow(headers); + + // 헤더 스타일 (공통 스타일: 파란색 배경, 흰색 글자) + headerRow.eachCell(function(cell){ + cell.fill = { + type: 'pattern', + pattern: 'solid', + fgColor: { argb: 'FF4472C4' } // 파란색 + }; + cell.font = { + color: { argb: 'FFFFFFFF' }, // 흰색 글자 + bold: true + }; + cell.alignment = { + vertical: 'middle', + horizontal: 'center', + wrapText: true + }; + cell.border = { + top: { style: 'thin' }, + left: { style: 'thin' }, + bottom: { style: 'thin' }, + right: { style: 'thin' } + }; + }); + headerRow.height = 25; + + // 데이터 추가 + data.forEach(function(item, index){ + var row = worksheet.addRow([ + index + 1, + item.model_name || item.MODEL_NAME || "", + item.product_type || item.PRODUCT_TYPE || "", + item.work_order_no || item.WORK_ORDER_NO || "", + item.part_no || item.PART_NO || "", + item.part_name || item.PART_NAME || "", + item.receipt_qty || item.RECEIPT_QTY || 0, + item.good_qty || item.GOOD_QTY || 0, + item.defect_qty || item.DEFECT_QTY || 0, + item.defect_rate || item.DEFECT_RATE || 0, + item.regeneration_qty || item.REGENERATION_QTY || 0, + item.final_good_qty || item.FINAL_GOOD_QTY || 0, + item.inspection_date || item.INSPECTION_DATE || "", + item.writer_name || item.WRITER_NAME || "", + item.defect_type || item.DEFECT_TYPE || "", + item.defect_cause || item.DEFECT_CAUSE || "", + item.responsible_dept || item.RESPONSIBLE_DEPT || "", + item.process_status || item.PROCESS_STATUS || "", + item.disposition_type || item.DISPOSITION_TYPE || "", + item.remark || item.REMARK || "" + ]); + + // 데이터 행 스타일 (테두리) + row.eachCell(function(cell, colNumber){ + cell.border = { + top: { style: 'thin' }, + left: { style: 'thin' }, + bottom: { style: 'thin' }, + right: { style: 'thin' } + }; + // 숫자 컬럼 오른쪽 정렬 (7~12번 컬럼: 수량, 불량율) + if(colNumber >= 7 && colNumber <= 12){ + cell.alignment = { horizontal: 'right' }; + // 숫자에 천단위 구분자 (불량율 제외) + if(colNumber !== 10 && typeof cell.value === 'number'){ + cell.numFmt = '#,##0'; + } + } else if(colNumber === 1){ + cell.alignment = { horizontal: 'center' }; + } + }); + }); + + // 파일명 생성 + var date = new Date(); + var currentDate = date.getFullYear() + + ("0" + (date.getMonth() + 1)).slice(-2) + + ("0" + date.getDate()).slice(-2) + "_" + + ("0" + date.getHours()).slice(-2) + + ("0" + date.getMinutes()).slice(-2); + var fileName = pageTitle + "_" + currentDate + ".xlsx"; + + // 다운로드 + const buffer = await workbook.xlsx.writeBuffer(); + saveAs(new Blob([buffer]), fileName); +} + // 컬럼: 품명(모델명), 작업지시번호, 부품품번, 부품명, 입고수량 합계, 양품수량 합계, 불량수량 합계, 불량율, 재생수량 합계, 최종 양품수량 합계, 검사일, 검사자 var columns = [ {headerHozAlign:'center', hozAlign:'left', minWidth:150, widthGrow:2, title:'품명(모델명)', field:'MODEL_NAME'}, @@ -171,13 +318,6 @@ function fn_registPopUp(){ hiddenForm.submit(); } -// 엑셀 다운로드 -function fn_excelDownload(){ - var form = document.form1; - form.action = "/quality/semiProductInspectionExcelDownload.do"; - form.submit(); - form.action = ""; -} @@ -193,6 +333,7 @@ function fn_excelDownload(){
+
@@ -202,7 +343,7 @@ function fn_excelDownload(){
- +
diff --git a/src/com/pms/controller/QualityController.java b/src/com/pms/controller/QualityController.java index c65ed81..a447ffd 100644 --- a/src/com/pms/controller/QualityController.java +++ b/src/com/pms/controller/QualityController.java @@ -469,7 +469,10 @@ public class QualityController { */ @RequestMapping("/quality/semiProductInspectionList.do") public String semiProductInspectionList(HttpServletRequest request, @RequestParam Map paramMap){ + String actionType = CommonUtils.checkNull(paramMap.get("actionType")); + System.out.println("[DEBUG] semiProductInspectionList actionType: " + actionType); Map code_map = new HashMap(); + List list = null; try { // 품명(모델명) 드롭박스 code_map.put("model_name", commonService.bizMakeOptionList("", (String)paramMap.get("search_model_name"), "quality.getSemiProductModelNameList")); @@ -482,10 +485,16 @@ public class QualityController { // 검사자 드롭박스 code_map.put("writer", commonService.bizMakeOptionList("", (String)paramMap.get("search_writer"), "quality.getSemiProductWriterList")); request.setAttribute("code_map", code_map); + + // 엑셀 다운로드 + if("excel".equals(actionType)){ + list = commonService.selectList("quality.getSemiProductInspectionListForExcel", request, paramMap); + request.setAttribute("LIST", list); + } } catch(Exception e) { e.printStackTrace(); } - return "/quality/semiProductInspectionList"; + return "/quality/semiProductInspectionList" + ("excel".equals(actionType) ? "Excel" : ""); } /** @@ -528,7 +537,7 @@ public class QualityController { } /** - * 반제품검사 엑셀 다운로드 + * 반제품검사 엑셀 다운로드 (JSP 방식) */ @RequestMapping("/quality/semiProductInspectionExcelDownload.do") public String semiProductInspectionExcelDownload(HttpServletRequest request, @RequestParam Map paramMap){ @@ -537,6 +546,18 @@ public class QualityController { return "/quality/semiProductInspectionExcel"; } + /** + * 반제품검사 엑셀 데이터 조회 (AJAX JSON) + */ + @ResponseBody + @RequestMapping("/quality/getSemiProductInspectionListForExcel.do") + public Map getSemiProductInspectionListForExcel(HttpServletRequest request, @RequestParam Map paramMap){ + Map result = new HashMap(); + List list = service.getSemiProductInspectionListForExcel(paramMap); + result.put("list", list); + return result; + } + // ===================================================== // 고객 CS 관리 // ===================================================== diff --git a/src/com/pms/mapper/quality.xml b/src/com/pms/mapper/quality.xml index c6eb1af..4d6357e 100644 --- a/src/com/pms/mapper/quality.xml +++ b/src/com/pms/mapper/quality.xml @@ -1340,61 +1340,96 @@ ORDER BY MIN(T.INSPECTION_DATE) DESC, T.INSPECTION_GROUP_ID - +