[feat] negosium/협상: 협상 종료폼 통일·의견 수취 — rejectRSP/CM를 단일 RejectForm(사유·희망가·의견)으로 통합해 액션바 렌더, 타결 부가정보에 의견 추가(custom.opinion), 결렬 제출값 파싱해 reject_reason/reject_price 컬럼 저장, 상품상세 필드 라벨 회사설정 연동·협상 단가 VAT별도 표기

This commit is contained in:
minaChoi committed 2026-07-29 09:51:21 +09:00
1 parent b33ae05cd6
commit a56589c6d9
14 files changed
+290 -317

No files matched your search

+1
View File
@@ -78,6 +78,7 @@ class Res_ChatInit(Res_WebPacketProtocol):
item_vat_yn: Optional[bool] = Field(None, description="VAT 포함 여부(미설정 시 null)")
item_delivery_fee_yn: Optional[bool] = Field(None, description="배송비 포함 여부(미설정 시 null)")
custom: dict = Field(default_factory=dict, description="협상완료 부가정보 기존 입력값(sessions.custom). 재진입 시 폼 프리필용")
labels: dict = Field(default_factory=dict, description="회사 커스텀 라벨(companies.settings.labels). 상품 상세 필드명(예: lead_time) 치환용. 없으면 프론트 기본값")
# 대화 히스토리(재진입 복원)
+37 -1
View File
@@ -24,6 +24,7 @@ from common.logger import LOG
from common.models.gmodel import UserInfo
from crud.chat_crud import ChatCRUD, IChatCRUD
from crud.session_crud import ISessionCRUD, SessionCRUD
from crud.user_crud import IUserCRUD, UserCRUD
from router.v1.chat.protocol import ChatMessage, ChatSummary, Res_ChatInit, Res_ChatMessages, Res_ChatSend
from services.agent_client import AgentChatContext, IAgentClient, get_agent_client
from services.auth_service import AuthService
@@ -44,11 +45,13 @@ class ChatService:
auth: AuthService = Depends(AuthService),
session_crud: ISessionCRUD = Depends(SessionCRUD),
chat_crud: IChatCRUD = Depends(ChatCRUD),
user_crud: IUserCRUD = Depends(UserCRUD),
agent: IAgentClient = Depends(get_agent_client),
):
self.auth = auth
self.session_crud = session_crud
self.chat_crud = chat_crud
self.user_crud = user_crud
self.agent = agent
# ---- 순수 헬퍼/매퍼 (self 불필요, 상단 집약) ----
@@ -59,6 +62,27 @@ class ChatService:
digits = "".join(ch for ch in text if ch.isdigit())
return int(digits) if digits else None
@staticmethod
def _parse_reject(text: Optional[str]) -> dict:
"""통일 결렬 폼 제출 문자열 파싱 → {offer_price, reason, opinion}.
형식: '공급희망가격-{원}, 합의불가사유-{사유}, 의견-{의견}' (사유는 '기타-{내용}' 가능).
의견은 자유서술이라 콤마 포함 가능 → 맨 뒤 '의견-' 기준으로 먼저 떼어낸다."""
s = text or ""
opinion = None
if ", 의견-" in s:
s, opinion = s.split(", 의견-", 1)
reason = None
if ", 합의불가사유-" in s:
price_part, reason = s.split(", 합의불가사유-", 1)
else:
price_part = s
price_digits = "".join(ch for ch in price_part.replace("공급희망가격-", "") if ch.isdigit())
return {
"offer_price": int(price_digits) if price_digits else None,
"reason": reason or None,
"opinion": (opinion.strip() or None) if opinion is not None else None,
}
@staticmethod
def _in_price_range(price: int, target_price: Optional[int]) -> bool:
if not target_price:
@@ -229,6 +253,13 @@ class ChatService:
res.item_vat_yn = item.vat_yn
res.item_delivery_fee_yn = item.delivery_fee_yn
res.custom = sess.custom or {}
# 회사 커스텀 라벨(companies.settings.labels) — 상품 상세 필드명 치환용(예: lead_time→표준납기). 실패해도 빈 dict 폴백.
_e, settings = await DB_SESSION_MNG.execute_lambda(
suppliers.DBType(), DBWRType.DB_READ.value,
lambda s: self.user_crud.get_company_settings(s, sess.supplier_id),
)
res.labels = (settings.get("labels") or {}) if _e == ErrorType.SUCCESS and settings else {}
return res
async def _ensure_in_progress(self, sess, quote) -> None:
@@ -455,10 +486,15 @@ class ChatService:
funcs.append(lambda s: self.chat_crud.finalize_session(s, sess.session_id, new_status, bid_price=bid))
else:
new_status = SessionStatus.REJECTED.value
parsed = self._parse_reject(user_input)
funcs.append(lambda s: self.chat_crud.finalize_session(
s, sess.session_id, new_status,
reject_reason=(user_input or None), reject_price=price,
reject_reason=parsed["reason"], reject_price=parsed["offer_price"],
))
if parsed["opinion"]:
funcs.append(lambda s, op=parsed["opinion"]: self.session_crud.merge_session_custom(
s, sess.session_id, sess.supplier_id, {"opinion": op},
))
err_type = await DB_SESSION_MNG.execute_lambda_run([chats.DBType()], funcs)
if err_type != ErrorType.SUCCESS: