From f2b3762f8c30825be8cd8c9cbe42e44f6c40e661 Mon Sep 17 00:00:00 2001 From: kmh Date: Thu, 30 Apr 2026 12:31:19 +0900 Subject: [PATCH] =?UTF-8?q?Filter=20POP=20defect-types=20to=20=EA=B3=B5?= =?UTF-8?q?=EC=A0=95=EA=B2=80=EC=82=AC=20master=20only?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Drop item_inspection_info branch in getDefectTypes - Always source from defect_standard_mng with inspection_type containing 공정검사 (CAT_MMEBA4LJ_UFJ9) - Fix is_active filter to category code CAT_DA_01 ('사용') — old 'Y' literal returned zero rows Co-Authored-By: Claude Opus 4.7 (1M context) --- .../controllers/popProductionController.ts | 65 ++++--------------- 1 file changed, 14 insertions(+), 51 deletions(-) diff --git a/backend-node/src/controllers/popProductionController.ts b/backend-node/src/controllers/popProductionController.ts index b65bba64..13b0c722 100644 --- a/backend-node/src/controllers/popProductionController.ts +++ b/backend-node/src/controllers/popProductionController.ts @@ -1186,9 +1186,13 @@ export const controlGroupTimer = async ( /** * 불량 유형 목록 조회 - * - item_code 쿼리 파라미터가 있으면: item_inspection_info 의 공정검사 항목을 반환 (품목별 검사항목) - * - 없으면: defect_standard_mng 마스터 반환 (기존 호환) + * - defect_standard_mng 중 inspection_type 에 공정검사(CAT_MMEBA4LJ_UFJ9) 가 포함된 활성 행 반환 + * - inspection_type 은 콤마 구분 다중값으로 저장됨 + * - is_active 는 카테고리 코드(CAT_DA_01='사용')로 저장됨 */ +const PROCESS_INSPECTION_CODE = "CAT_MMEBA4LJ_UFJ9"; +const ACTIVE_CODE = "CAT_DA_01"; + export const getDefectTypes = async ( req: AuthenticatedRequest, res: Response, @@ -1197,68 +1201,27 @@ export const getDefectTypes = async ( try { const companyCode = req.user!.companyCode; - const itemCode = - typeof req.query.item_code === "string" && req.query.item_code.trim() - ? req.query.item_code.trim() - : null; - const applyProcess = - typeof req.query.apply_process === "string" && - req.query.apply_process.trim() - ? req.query.apply_process.trim() - : null; let query: string; let params: unknown[]; - if (itemCode) { - if (companyCode === "*") { - const processFilter = applyProcess ? ` AND apply_process = $2` : ""; - query = ` - SELECT id, - inspection_standard_id AS defect_code, - inspection_item_name AS defect_name, - inspection_type AS defect_type, - '' AS severity, - company_code - FROM item_inspection_info - WHERE item_code = $1 - AND inspection_type = '공정검사' - AND is_active IN ('사용', 'Y')${processFilter} - ORDER BY sort_order, inspection_item_name`; - params = applyProcess ? [itemCode, applyProcess] : [itemCode]; - } else { - const processFilter = applyProcess ? ` AND apply_process = $3` : ""; - query = ` - SELECT id, - inspection_standard_id AS defect_code, - inspection_item_name AS defect_name, - inspection_type AS defect_type, - '' AS severity, - company_code - FROM item_inspection_info - WHERE company_code = $1 - AND item_code = $2 - AND inspection_type = '공정검사' - AND is_active IN ('사용', 'Y')${processFilter} - ORDER BY sort_order, inspection_item_name`; - params = applyProcess - ? [companyCode, itemCode, applyProcess] - : [companyCode, itemCode]; - } - } else if (companyCode === "*") { + if (companyCode === "*") { query = ` SELECT id, defect_code, defect_name, defect_type, severity, company_code FROM defect_standard_mng - WHERE is_active = 'Y' + WHERE is_active = $1 + AND (',' || COALESCE(inspection_type, '') || ',') LIKE '%,' || $2 || ',%' ORDER BY defect_code`; - params = []; + params = [ACTIVE_CODE, PROCESS_INSPECTION_CODE]; } else { query = ` SELECT id, defect_code, defect_name, defect_type, severity, company_code FROM defect_standard_mng - WHERE is_active = 'Y' AND company_code = $1 + WHERE is_active = $1 + AND company_code = $2 + AND (',' || COALESCE(inspection_type, '') || ',') LIKE '%,' || $3 || ',%' ORDER BY defect_code`; - params = [companyCode]; + params = [ACTIVE_CODE, companyCode, PROCESS_INSPECTION_CODE]; } const result = await pool.query(query, params);