feat: 챗봇 관련 제품에 분류 뱃지 추가 (내부구충제, 심장사상충약 등)
This commit is contained in:
parent
a42af23038
commit
4c93ee038a
@ -2797,6 +2797,7 @@ def _get_animal_drugs():
|
|||||||
'apc': apc,
|
'apc': apc,
|
||||||
'stock': int(r.Stock) if r.Stock else 0,
|
'stock': int(r.Stock) if r.Stock else 0,
|
||||||
'wholesaler_stock': 0, # PostgreSQL에서 가져옴
|
'wholesaler_stock': 0, # PostgreSQL에서 가져옴
|
||||||
|
'category': None, # PostgreSQL에서 가져옴
|
||||||
'image_url': 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')
|
pg_engine = create_engine('postgresql://admin:trajet6640@192.168.0.87:5432/apdb_master')
|
||||||
with pg_engine.connect() as conn:
|
with pg_engine.connect() as conn:
|
||||||
placeholders = ','.join([f"'{a}'" for a in apc_list])
|
placeholders = ','.join([f"'{a}'" for a in apc_list])
|
||||||
# 이미지 URL 조회
|
# 이미지 URL + 분류 조회
|
||||||
img_result = conn.execute(text(f"""
|
info_result = conn.execute(text(f"""
|
||||||
SELECT apc, image_url1 FROM apc WHERE apc IN ({placeholders})
|
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)
|
# 도매상 재고 조회 (SUM)
|
||||||
stock_result = conn.execute(text(f"""
|
stock_result = conn.execute(text(f"""
|
||||||
@ -2825,8 +2827,9 @@ def _get_animal_drugs():
|
|||||||
|
|
||||||
for item in result:
|
for item in result:
|
||||||
if item['apc']:
|
if item['apc']:
|
||||||
if item['apc'] in img_map:
|
if item['apc'] in info_map:
|
||||||
item['image_url'] = img_map[item['apc']]
|
item['image_url'] = info_map[item['apc']]['image_url']
|
||||||
|
item['category'] = info_map[item['apc']]['category']
|
||||||
if item['apc'] in stock_map:
|
if item['apc'] in stock_map:
|
||||||
item['wholesaler_stock'] = stock_map[item['apc']]
|
item['wholesaler_stock'] = stock_map[item['apc']]
|
||||||
else:
|
else:
|
||||||
@ -2991,7 +2994,8 @@ def api_animal_chat():
|
|||||||
'code': drug['code'],
|
'code': drug['code'],
|
||||||
'image_url': drug.get('image_url'), # APC 이미지 URL
|
'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) # 도매상 재고
|
'wholesaler_stock': drug.get('wholesaler_stock', 0), # 도매상 재고
|
||||||
|
'category': drug.get('category') # 분류 (내부구충제, 심장사상충약 등)
|
||||||
})
|
})
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
|
|||||||
@ -987,7 +987,7 @@
|
|||||||
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>';
|
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 textDiv = document.createElement('div');
|
||||||
const pharmacyStock = p.stock || 0;
|
const pharmacyStock = p.stock || 0;
|
||||||
const wholesalerStock = p.wholesaler_stock || 0;
|
const wholesalerStock = p.wholesaler_stock || 0;
|
||||||
@ -995,7 +995,13 @@
|
|||||||
const pharmacyText = (pharmacyStock > 0) ? `약국 ${pharmacyStock}` : '품절';
|
const pharmacyText = (pharmacyStock > 0) ? `약국 ${pharmacyStock}` : '품절';
|
||||||
const wholesalerText = (wholesalerStock > 0) ? `도매 ${wholesalerStock}` : '';
|
const wholesalerText = (wholesalerStock > 0) ? `도매 ${wholesalerStock}` : '';
|
||||||
const stockDisplay = wholesalerText ? `${pharmacyText} / ${wholesalerText}` : pharmacyText;
|
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>`;
|
|
||||||
|
// 카테고리 뱃지
|
||||||
|
const categoryBadge = p.category
|
||||||
|
? `<span style="display:inline-block;background:#8b5cf6;color:#fff;font-size:10px;padding:2px 5px;border-radius:3px;margin-left:4px;">${p.category}</span>`
|
||||||
|
: '';
|
||||||
|
|
||||||
|
textDiv.innerHTML = `<div style="font-size:13px;font-weight:500;color:#334155;">${p.name}${categoryBadge}</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(imgContainer);
|
||||||
card.appendChild(textDiv);
|
card.appendChild(textDiv);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user