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({
|
||||
|
||||
@@ -987,11 +987,15 @@
|
||||
imgContainer.innerHTML = '<div style="width:40px;height:40px;background:#f1f5f9;border-radius:4px;display:flex;align-items:center;justify-content:center;font-size:20px;">💊</div>';
|
||||
}
|
||||
|
||||
// 텍스트
|
||||
// 텍스트 (약국/도매 재고)
|
||||
const textDiv = document.createElement('div');
|
||||
const stockColor = (p.stock > 0) ? '#10b981' : '#ef4444';
|
||||
const stockText = (p.stock > 0) ? `재고 ${p.stock}` : '품절';
|
||||
textDiv.innerHTML = `<div style="font-size:13px;font-weight:500;color:#334155;">${p.name}</div><div style="font-size:12px;"><span style="color:#10b981;">${formatPrice(p.price)}</span> <span style="color:${stockColor};margin-left:6px;">${stockText}</span></div>`;
|
||||
const pharmacyStock = p.stock || 0;
|
||||
const wholesalerStock = p.wholesaler_stock || 0;
|
||||
const stockColor = (pharmacyStock > 0) ? '#10b981' : '#ef4444';
|
||||
const pharmacyText = (pharmacyStock > 0) ? `약국 ${pharmacyStock}` : '품절';
|
||||
const wholesalerText = (wholesalerStock > 0) ? `도매 ${wholesalerStock}` : '';
|
||||
const stockDisplay = wholesalerText ? `${pharmacyText} / ${wholesalerText}` : pharmacyText;
|
||||
textDiv.innerHTML = `<div style="font-size:13px;font-weight:500;color:#334155;">${p.name}</div><div style="font-size:12px;"><span style="color:#10b981;">${formatPrice(p.price)}</span> <span style="color:${stockColor};margin-left:6px;">${stockDisplay}</span></div>`;
|
||||
|
||||
card.appendChild(imgContainer);
|
||||
card.appendChild(textDiv);
|
||||
|
||||
Reference in New Issue
Block a user