[refactor] 공급유형 기준을 상품-협력사 매핑으로 전환

This commit is contained in:
minaChoi committed 2026-07-07 17:05:07 +09:00
1 parent 9ac8fe6363
commit d21e7c10b0
35 files changed
+157 -333

No files matched your search

+10 -8
View File
@@ -25,21 +25,23 @@ _current_values = table(
)
async def fetch_current_values(db: AsyncSession, company_ids: list, supplier_type: int) -> dict:
"""칸별 현재 앵커링 값 일괄 조회. {(company_id, price_range_index): rate‰} 반환.
async def fetch_current_values(db: AsyncSession, company_ids: list, supplier_types: list[int]) -> dict:
"""칸별 현재 앵커링 값 일괄 조회. {(company_id, supplier_type, price_range_index): rate‰} 반환.
supplier_type 은 견적 단위로 하나뿐이라 키에 넣지 않는다.
supplier_type 은 세션의 (item_id, supplier_id) 매핑에서 온 supply_type 이다.
조정 이력이 없는 칸은 결과에 없다(호출측 정적 폴백). 조회 실패 시 빈 dict."""
if not company_ids or supplier_type not in SAMPLEABLE_SUPPLIER_TYPES:
valid_types = sorted({int(t) for t in supplier_types if t in SAMPLEABLE_SUPPLIER_TYPES})
if not company_ids or not valid_types:
return {}
try:
stmt = select(
_current_values.c.company_id,
_current_values.c.supplier_type,
_current_values.c.price_range_index,
_current_values.c.anchoring_value,
).where(
_current_values.c.company_id.in_(company_ids),
_current_values.c.supplier_type == supplier_type,
_current_values.c.supplier_type.in_(valid_types),
)
rows = (await db.execute(stmt)).all()
except Exception as ex:
@@ -47,9 +49,9 @@ async def fetch_current_values(db: AsyncSession, company_ids: list, supplier_typ
return {}
out = {}
for company_id, price_range_index, rate in rows:
for company_id, supplier_type, price_range_index, rate in rows:
if not ANCHORING_VALUE_MIN <= rate <= ANCHORING_VALUE_MAX: # 범위 밖 값은 오염 방어 — 버리고 정적 폴백
LOG.w(f"[앵커링] rate 범위 밖 — 무시(정적 폴백): company={company_id} bracket={price_range_index} rate={rate}")
LOG.w(f"[앵커링] rate 범위 밖 — 무시(정적 폴백): company={company_id} type={supplier_type} bracket={price_range_index} rate={rate}")
continue
out[(company_id, price_range_index)] = rate
out[(company_id, supplier_type, price_range_index)] = rate
return out