From 912679b1377a8acfd1f3f8d7a45ab045e1c8de33 Mon Sep 17 00:00:00 2001 From: thug0bin Date: Sat, 28 Feb 2026 11:45:27 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20PostgreSQL=EC=97=90=EC=84=9C=20image=5F?= =?UTF-8?q?url=20=EC=A7=81=EC=A0=91=20=EC=A1=B0=ED=9A=8C=20(=EB=B0=94?= =?UTF-8?q?=EC=BD=94=EB=93=9C=3DAPC=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=EC=A7=80=EC=9B=90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/backend/app.py b/backend/app.py index ed955dd..d1587a7 100644 --- a/backend/app.py +++ b/backend/app.py @@ -2704,6 +2704,7 @@ def _get_animal_drug_rag(apc_codes): result = conn.execute(text(f""" SELECT apc, product_name, main_ingredient, component_name_ko, + image_url1, llm_pharm->>'사용가능 동물' as target_animals, llm_pharm->>'분류' as category, llm_pharm->>'체중/부위' as dosage_weight, @@ -2728,7 +2729,8 @@ def _get_animal_drug_rag(apc_codes): 'owner_caution': row.owner_caution or '', 'main_ingredient': row.component_name_ko or row.main_ingredient_detail or row.main_ingredient or '', 'description': row.description or '', - 'usage_for': row.usage_for or '' + 'usage_for': row.usage_for or '', + 'image_url': row.image_url1 or '' } return rag_data except Exception as e: @@ -2767,18 +2769,17 @@ def _get_animal_drugs(): rows = drug_session.execute(query).fetchall() result = [] + apc_list = [] for r in rows: apc = r.APC_CODE if hasattr(r, 'APC_CODE') else None barcode = r.BARCODE or '' - image_url = None # APC가 없으면 바코드를 APC로 사용 (PostgreSQL에서 바코드=APC인 경우) if not apc and barcode: apc = barcode - if apc and apc.startswith('023'): - # 023으로 시작하는 APC만 이미지 URL 생성 - image_url = f"https://ani.0bin.in/img/{apc}_F.jpg" + if apc: + apc_list.append(apc) result.append({ 'code': r.DrugCode, @@ -2786,9 +2787,27 @@ def _get_animal_drugs(): 'price': float(r.Saleprice) if r.Saleprice else 0, 'barcode': barcode, 'apc': apc, - 'image_url': image_url + 'image_url': None # PostgreSQL에서 가져옴 }) + # PostgreSQL에서 이미지 URL 가져오기 + if apc_list: + try: + from sqlalchemy import create_engine + pg_engine = create_engine('postgresql://admin:trajet6640@192.168.0.87:5432/apdb_master') + with pg_engine.connect() as conn: + placeholders = ','.join([f"'{a}'" for a in apc_list]) + img_result = conn.execute(text(f""" + SELECT apc, image_url1 FROM apc WHERE apc IN ({placeholders}) + """)) + img_map = {row.apc: row.image_url1 for row in img_result} + + for item in result: + if item['apc'] and item['apc'] in img_map: + item['image_url'] = img_map[item['apc']] + except Exception as e: + logging.warning(f"PostgreSQL 이미지 URL 조회 실패: {e}") + return result except Exception as e: logging.warning(f"동물약 목록 조회 실패: {e}")