From e95c08ef59514eb992f4847e0bbf029d35a75f79 Mon Sep 17 00:00:00 2001 From: thug0bin Date: Wed, 4 Mar 2026 15:27:50 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=EC=95=BD=ED=92=88?= =?UTF-8?q?=EB=A7=8C=20=EC=BF=BC=EB=A6=AC=EC=97=90=EC=84=9C=20=EB=8B=A8?= =?UTF-8?q?=EC=9C=84=EB=B0=94=EC=BD=94=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=88=84=EB=9D=BD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: 대표바코드(CD_GOODS.BARCODE)가 비어있으면 '없음'으로 표시 원인: in_stock_only 쿼리에 CD_ITEM_UNIT_MEMBER OUTER APPLY 누락 수정: - in_stock_only 쿼리에 단위바코드 조회 추가 - animal_only 쿼리에도 동일하게 추가 - COALESCE(대표바코드, 단위바코드, '') 순서로 조회 --- backend/app.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/app.py b/backend/app.py index d9f1479..c87bbe3 100644 --- a/backend/app.py +++ b/backend/app.py @@ -3335,11 +3335,12 @@ def api_products(): # 제품 검색 쿼리 - 사용약품만 옵션에 따라 JOIN 방식 변경 if in_stock_only: # 최적화된 쿼리: 재고 있는 제품만 (IM_total INNER JOIN) + # 대표바코드(G.BARCODE) 없으면 단위바코드(CD_ITEM_UNIT_MEMBER) 사용 products_query = text(f""" SELECT TOP {limit} G.DrugCode as drug_code, G.GoodsName as product_name, - COALESCE(NULLIF(G.BARCODE, ''), '') as barcode, + COALESCE(NULLIF(G.BARCODE, ''), U.CD_CD_BARCODE, '') as barcode, G.Saleprice as sale_price, G.Price as cost_price, ISNULL(G.SplName, '') as supplier, @@ -3350,6 +3351,11 @@ def api_products(): FROM CD_GOODS G INNER JOIN IM_total IT ON G.DrugCode = IT.DrugCode AND IT.IM_QT_sale_debit > 0 LEFT JOIN CD_item_position POS ON G.DrugCode = POS.DrugCode + OUTER APPLY ( + SELECT TOP 1 CD_CD_BARCODE + FROM CD_ITEM_UNIT_MEMBER + WHERE DRUGCODE = G.DrugCode AND CD_CD_BARCODE IS NOT NULL AND CD_CD_BARCODE != '' + ) U WHERE 1=1 {animal_condition} {search_condition} @@ -3363,7 +3369,7 @@ def api_products(): SELECT TOP {limit} G.DrugCode as drug_code, G.GoodsName as product_name, - COALESCE(NULLIF(G.BARCODE, ''), '') as barcode, + COALESCE(NULLIF(G.BARCODE, ''), U.CD_CD_BARCODE, '') as barcode, G.Saleprice as sale_price, G.Price as cost_price, ISNULL(G.SplName, '') as supplier, @@ -3374,6 +3380,11 @@ def api_products(): FROM CD_GOODS G LEFT JOIN IM_total IT ON G.DrugCode = IT.DrugCode LEFT JOIN CD_item_position POS ON G.DrugCode = POS.DrugCode + OUTER APPLY ( + SELECT TOP 1 CD_CD_BARCODE + FROM CD_ITEM_UNIT_MEMBER + WHERE DRUGCODE = G.DrugCode AND CD_CD_BARCODE IS NOT NULL AND CD_CD_BARCODE != '' + ) U WHERE G.POS_BOON = '010103' {search_condition} ORDER BY G.GoodsName