feat(반품관리): 약품 위치 컬럼 추가
- API: return-candidates에서 CD_item_position 조인하여 위치 정보 반환 - 테이블에 '위치' 컬럼 추가 (노란색 뱃지 스타일) - 위치 미지정 약품은 '-' 표시
This commit is contained in:
@@ -5360,8 +5360,9 @@ def api_return_candidates():
|
||||
# 약품코드 목록 추출
|
||||
drug_codes = [row['drug_code'] for row in rows]
|
||||
|
||||
# MSSQL에서 가격 정보 조회 (한 번에)
|
||||
# MSSQL에서 가격 + 위치 정보 조회 (한 번에)
|
||||
price_map = {}
|
||||
location_map = {}
|
||||
if drug_codes:
|
||||
try:
|
||||
mssql_conn_str = (
|
||||
@@ -5378,20 +5379,24 @@ def api_return_candidates():
|
||||
|
||||
# IN 절 생성 (SQL Injection 방지를 위해 파라미터화)
|
||||
# Price가 없으면 Saleprice, Topprice 순으로 fallback
|
||||
# CD_item_position JOIN으로 위치 정보도 함께 조회
|
||||
placeholders = ','.join(['?' for _ in drug_codes])
|
||||
mssql_cursor.execute(f"""
|
||||
SELECT DrugCode,
|
||||
COALESCE(NULLIF(Price, 0), NULLIF(Saleprice, 0), NULLIF(Topprice, 0), 0) as BestPrice
|
||||
FROM CD_GOODS
|
||||
WHERE DrugCode IN ({placeholders})
|
||||
SELECT G.DrugCode,
|
||||
COALESCE(NULLIF(G.Price, 0), NULLIF(G.Saleprice, 0), NULLIF(G.Topprice, 0), 0) as BestPrice,
|
||||
ISNULL(POS.CD_NM_sale, '') as Location
|
||||
FROM CD_GOODS G
|
||||
LEFT JOIN CD_item_position POS ON G.DrugCode = POS.DrugCode
|
||||
WHERE G.DrugCode IN ({placeholders})
|
||||
""", drug_codes)
|
||||
|
||||
for row in mssql_cursor.fetchall():
|
||||
price_map[row[0]] = float(row[1]) if row[1] else 0
|
||||
location_map[row[0]] = row[2] or ''
|
||||
|
||||
mssql_conn.close()
|
||||
except Exception as e:
|
||||
logging.warning(f"MSSQL 가격 조회 실패: {e}")
|
||||
logging.warning(f"MSSQL 가격/위치 조회 실패: {e}")
|
||||
|
||||
# 전체 데이터 조회 (통계용)
|
||||
cursor.execute("SELECT drug_code, current_stock, months_since_use, months_since_purchase FROM return_candidates")
|
||||
@@ -5432,6 +5437,7 @@ def api_return_candidates():
|
||||
'current_stock': stock,
|
||||
'unit_price': price,
|
||||
'recoverable_amount': recoverable,
|
||||
'location': location_map.get(code, ''),
|
||||
'last_prescription_date': row['last_prescription_date'],
|
||||
'months_since_use': row['months_since_use'],
|
||||
'last_purchase_date': row['last_purchase_date'],
|
||||
|
||||
Reference in New Issue
Block a user