Merge commit 'dc8c288f' — lps-admin 신설·LPS 운영기능(ip_session/alerts/admin API)·최저가 출처링크 반영
This commit is contained in:
commit
b539e073cb
86 files changed
+7216
-968
No files matched your search
@@ -132,6 +132,8 @@ class item_internet_lowest_prices(MainTableMixin, MAIN_BASE):
|
||||
fail_reason = Column(String(100), nullable=True) # 실패 사유(예: not_found)
|
||||
ai_model = Column(SmallInteger, nullable=True) # (예약) AI 모델 코드 — LPS 계약엔 미포함
|
||||
crawl_duration_ms = Column(Integer, nullable=True) # (예약) 수집 소요 — LPS 계약엔 미포함
|
||||
lp_name = Column(String(300), nullable=True) # 찾은 상품명(판매 페이지 기준) — 근거 검증용
|
||||
lp_url = Column(String, nullable=True) # 찾은 판매 페이지 링크(TEXT) — 근거 검증용
|
||||
crawl_end_time = Column(DateTime(timezone=True), nullable=False) # 수집 완료 시각(=price_history.created_at, 워터마크 기준)
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ class WebServerConfig(ConfigModel):
|
||||
nego_chat_url: str = "http://localhost:3300"
|
||||
agent_base_url: str = "http://localhost:9500" # 협상 agent(9500). 공용 카탈로그 변경 알림용.
|
||||
lps_base_url: str = "http://localhost:9600" # 인터넷 최저가 검색 LPS(9600). 검색요청 enqueue 용.
|
||||
lps_api_key: str = "" # LPS API guard 키 — LPS 쪽 [WebServerConfig].api_keys 와 동일 값. 빈값=헤더 미첨부(개발)
|
||||
|
||||
|
||||
class LogConfig(ConfigModel):
|
||||
|
||||
@@ -63,3 +63,6 @@ _apply_lps_db_env_override(lps_db_config)
|
||||
# LPS API 주소 env override (도커: http://lps-api:9600 또는 host.docker.internal:9600)
|
||||
if os.environ.get("LPS_BASE_URL"):
|
||||
web_server_config.lps_base_url = os.environ["LPS_BASE_URL"]
|
||||
# LPS API guard 키 (LPS 는 toml 단일 관리로 전환 — negodata 쪽은 기존 관례대로 toml+env override 유지)
|
||||
if os.environ.get("LPS_API_KEY"):
|
||||
web_server_config.lps_api_key = os.environ["LPS_API_KEY"]
|
||||
@@ -25,6 +25,10 @@ _price_history = table(
|
||||
column("outcome"), # found | not_found
|
||||
column("final_lowest"), # 전체 최저가(원)
|
||||
column("final_source"), # naver | coupang | (폴백몰)
|
||||
column("naver_name"), # 네이버 최저가 상품명/링크 — final_source 에 맞는 출처를 실어온다
|
||||
column("naver_url"),
|
||||
column("coupang_name"), # 쿠팡 최저가 상품명/링크
|
||||
column("coupang_url"),
|
||||
column("created_at"),
|
||||
)
|
||||
|
||||
@@ -108,6 +112,10 @@ class LpsSyncCRUD(ILpsSyncCRUD):
|
||||
_price_history.c.outcome,
|
||||
_price_history.c.final_lowest,
|
||||
_price_history.c.final_source,
|
||||
_price_history.c.naver_name,
|
||||
_price_history.c.naver_url,
|
||||
_price_history.c.coupang_name,
|
||||
_price_history.c.coupang_url,
|
||||
_price_history.c.created_at,
|
||||
).order_by(_price_history.c.created_at.asc())
|
||||
if since is not None:
|
||||
|
||||
@@ -143,6 +143,8 @@ class LowestPriceEntry(WebPacketProtocol):
|
||||
website: int = 0 # LowestPriceWebsite 코드(1=naver 2=coupang …)
|
||||
success_yn: bool = False
|
||||
fail_reason: Optional[str] = None
|
||||
lp_name: Optional[str] = None # 찾은 상품명(판매 페이지 기준) — 근거 검증용
|
||||
lp_url: Optional[str] = None # 찾은 판매 페이지 링크
|
||||
crawl_end_time: Optional[datetime] = None
|
||||
|
||||
|
||||
|
||||
@@ -72,9 +72,11 @@ class LpsSyncService:
|
||||
"price": str(item.price) if item.price else "",
|
||||
}
|
||||
base = web_server_config.lps_base_url.rstrip("/")
|
||||
# LPS API guard: prod 는 lps_api_key 를 채워 X-API-Key 로 인증(개발은 빈값=개방 모드).
|
||||
headers = {"X-API-Key": web_server_config.lps_api_key} if web_server_config.lps_api_key else None
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10.0) as client:
|
||||
r = await client.post(f"{base}/v1/lps/search", json={"data": [payload]})
|
||||
r = await client.post(f"{base}/v1/lps/search", json={"data": [payload]}, headers=headers)
|
||||
r.raise_for_status()
|
||||
body = r.json()
|
||||
entry = (body.get("items") or [{}])[0]
|
||||
@@ -129,11 +131,18 @@ class LpsSyncService:
|
||||
|
||||
# product_code(uuid=item_id) 검증 — LPS 부하테스트 등 비상품 코드는 조용히 스킵
|
||||
parsed = []
|
||||
for code, outcome, final_lowest, final_source, created_at in rows:
|
||||
for code, outcome, final_lowest, final_source, nv_name, nv_url, cp_name, cp_url, created_at in rows:
|
||||
try:
|
||||
parsed.append((uuid.UUID(code), outcome, final_lowest, final_source, created_at))
|
||||
iid = uuid.UUID(code)
|
||||
except (ValueError, AttributeError, TypeError):
|
||||
results["skipped_not_uuid"] += 1
|
||||
continue
|
||||
# 출처(찾은 상품명·링크) — 최종 최저가를 낸 소스의 것을 싣는다(근거 검증용)
|
||||
src_name, src_url = {
|
||||
"naver": (nv_name, nv_url),
|
||||
"coupang": (cp_name, cp_url),
|
||||
}.get((final_source or "").lower(), (None, None))
|
||||
parsed.append((iid, outcome, final_lowest, final_source, src_name, src_url, created_at))
|
||||
|
||||
err, existing = await DB_SESSION_MNG.execute_lambda(
|
||||
DBType.MAIN.value, DBWRType.DB_READ.value,
|
||||
@@ -143,7 +152,7 @@ class LpsSyncService:
|
||||
return results
|
||||
|
||||
history_rows, latest_found = [], {} # latest_found: item_id → (created_at, price)
|
||||
for item_id, outcome, final_lowest, final_source, created_at in parsed:
|
||||
for item_id, outcome, final_lowest, final_source, src_name, src_url, created_at in parsed:
|
||||
if item_id not in existing:
|
||||
results["skipped_unknown_item"] += 1
|
||||
continue
|
||||
@@ -154,6 +163,8 @@ class LpsSyncService:
|
||||
website=LowestPriceWebsite.from_source(final_source).value,
|
||||
success_yn=found,
|
||||
fail_reason=None if found else (outcome or "unknown")[:100],
|
||||
lp_name=(src_name or None) and src_name[:300],
|
||||
lp_url=src_url or None,
|
||||
crawl_end_time=created_at, # 워터마크 기준값 — price_history.created_at 그대로 보존
|
||||
))
|
||||
results["found" if found else "not_found"] += 1
|
||||
|
||||
Reference in new issue
Block a user