feat: 도매상 재고 표시 추가 (약국 N / 도매 M) + 문서화
This commit is contained in:
@@ -2796,26 +2796,43 @@ def _get_animal_drugs():
|
||||
'barcode': barcode,
|
||||
'apc': apc,
|
||||
'stock': int(r.Stock) if r.Stock else 0,
|
||||
'wholesaler_stock': 0, # PostgreSQL에서 가져옴
|
||||
'image_url': None # PostgreSQL에서 가져옴
|
||||
})
|
||||
|
||||
# PostgreSQL에서 이미지 URL 가져오기
|
||||
# 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])
|
||||
# 이미지 URL 조회
|
||||
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}
|
||||
|
||||
# 도매상 재고 조회 (SUM)
|
||||
stock_result = conn.execute(text(f"""
|
||||
SELECT A.apc, COALESCE(SUM(I.quantity), 0) as wholesaler_stock
|
||||
FROM apc A
|
||||
LEFT JOIN inventory I ON I.apdb_id = A.idx
|
||||
WHERE A.apc IN ({placeholders})
|
||||
GROUP BY A.apc
|
||||
"""))
|
||||
stock_map = {row.apc: int(row.wholesaler_stock) for row in stock_result}
|
||||
|
||||
for item in result:
|
||||
if item['apc'] and item['apc'] in img_map:
|
||||
item['image_url'] = img_map[item['apc']]
|
||||
if item['apc']:
|
||||
if item['apc'] in img_map:
|
||||
item['image_url'] = img_map[item['apc']]
|
||||
if item['apc'] in stock_map:
|
||||
item['wholesaler_stock'] = stock_map[item['apc']]
|
||||
else:
|
||||
item['wholesaler_stock'] = 0
|
||||
except Exception as e:
|
||||
logging.warning(f"PostgreSQL 이미지 URL 조회 실패: {e}")
|
||||
logging.warning(f"PostgreSQL 이미지/재고 조회 실패: {e}")
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
@@ -2973,7 +2990,8 @@ def api_animal_chat():
|
||||
'price': drug['price'],
|
||||
'code': drug['code'],
|
||||
'image_url': drug.get('image_url'), # APC 이미지 URL
|
||||
'stock': drug.get('stock', 0) # 재고
|
||||
'stock': drug.get('stock', 0), # 약국 재고
|
||||
'wholesaler_stock': drug.get('wholesaler_stock', 0) # 도매상 재고
|
||||
})
|
||||
|
||||
return jsonify({
|
||||
|
||||
Reference in New Issue
Block a user