feat: 챗봇 관련 제품에 분류 뱃지 추가 (내부구충제, 심장사상충약 등)
This commit is contained in:
@@ -2797,6 +2797,7 @@ def _get_animal_drugs():
|
||||
'apc': apc,
|
||||
'stock': int(r.Stock) if r.Stock else 0,
|
||||
'wholesaler_stock': 0, # PostgreSQL에서 가져옴
|
||||
'category': None, # PostgreSQL에서 가져옴
|
||||
'image_url': None # PostgreSQL에서 가져옴
|
||||
})
|
||||
|
||||
@@ -2807,11 +2808,12 @@ def _get_animal_drugs():
|
||||
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])
|
||||
# 이미지 URL 조회
|
||||
img_result = conn.execute(text(f"""
|
||||
SELECT apc, image_url1 FROM apc WHERE apc IN ({placeholders})
|
||||
# 이미지 URL + 분류 조회
|
||||
info_result = conn.execute(text(f"""
|
||||
SELECT apc, image_url1, llm_pharm->>'분류' as category
|
||||
FROM apc WHERE apc IN ({placeholders})
|
||||
"""))
|
||||
img_map = {row.apc: row.image_url1 for row in img_result}
|
||||
info_map = {row.apc: {'image_url': row.image_url1, 'category': row.category} for row in info_result}
|
||||
|
||||
# 도매상 재고 조회 (SUM)
|
||||
stock_result = conn.execute(text(f"""
|
||||
@@ -2825,8 +2827,9 @@ def _get_animal_drugs():
|
||||
|
||||
for item in result:
|
||||
if item['apc']:
|
||||
if item['apc'] in img_map:
|
||||
item['image_url'] = img_map[item['apc']]
|
||||
if item['apc'] in info_map:
|
||||
item['image_url'] = info_map[item['apc']]['image_url']
|
||||
item['category'] = info_map[item['apc']]['category']
|
||||
if item['apc'] in stock_map:
|
||||
item['wholesaler_stock'] = stock_map[item['apc']]
|
||||
else:
|
||||
@@ -2991,7 +2994,8 @@ def api_animal_chat():
|
||||
'code': drug['code'],
|
||||
'image_url': drug.get('image_url'), # APC 이미지 URL
|
||||
'stock': drug.get('stock', 0), # 약국 재고
|
||||
'wholesaler_stock': drug.get('wholesaler_stock', 0) # 도매상 재고
|
||||
'wholesaler_stock': drug.get('wholesaler_stock', 0), # 도매상 재고
|
||||
'category': drug.get('category') # 분류 (내부구충제, 심장사상충약 등)
|
||||
})
|
||||
|
||||
return jsonify({
|
||||
|
||||
Reference in New Issue
Block a user