Compare commits

..

No commits in common. "main" and "feature/landing" have entirely different histories.

2 changed files with 5 additions and 14 deletions

View File

@ -5,7 +5,7 @@ from sqlalchemy import select, func, and_, or_, update, case
from sqlalchemy.ext.asyncio import AsyncSession
from common.database.db_session_manager import DB_SESSION_MNG
from common.database.model.models import users, chats, sessions, quotations
from common.database.model.models import users, chats, sessions
from common.enums import ErrorType, SessionStatus
from common.logger import LOG
from common.utils.gtime import GTime
@ -38,7 +38,7 @@ class ICardCRUD(ABC):
pass
@abstractmethod
async def card_success_map(self, cdb: AsyncSession, company_id) -> Tuple[ErrorType, dict]:
async def card_success_map(self, cdb: AsyncSession) -> Tuple[ErrorType, dict]:
pass
@abstractmethod
@ -83,10 +83,9 @@ class CardCRUD(ICardCRUD):
LOG.e_no_callstack(ex)
return ErrorType.DB_RUN_FAILED, [], 0
async def card_success_map(self, cdb: AsyncSession, company_id) -> Tuple[ErrorType, dict]:
async def card_success_map(self, cdb: AsyncSession) -> Tuple[ErrorType, dict]:
# 카드별 성공률: 카드 사용(card_used_yn) 채팅이 속한 세션의 타결(DONE) 비율.
# {card_id(UUID): (used_sessions, won_sessions)}. 성공=세션 DONE(협상완료).
# 집계 범위는 내 회사 견적에서 쓰인 이력만 — quotations 까지 조인해 작성자 회사로 좁힌다.
try:
stmt = (
select(
@ -95,15 +94,7 @@ class CardCRUD(ICardCRUD):
func.count(func.distinct(case((sessions.status == SessionStatus.DONE.value, chats.session_id)))).label("won"),
)
.join(sessions, sessions.session_id == chats.session_id)
.join(quotations, quotations.qt_id == sessions.quotation_id)
.where(
chats.card_used_yn == True, # noqa: E712
chats.card_id.isnot(None),
chats.deleted == False, # noqa: E712
sessions.deleted == False, # noqa: E712
quotations.deleted == False, # noqa: E712
quotations.user_id.in_(select(users.user_id).where(users.company_id == company_id)),
)
.where(chats.card_used_yn == True, chats.card_id.isnot(None), chats.deleted == False) # noqa: E712
.group_by(chats.card_id)
)
err, rows = await DB_SESSION_MNG.execute(cdb, stmt)

View File

@ -142,7 +142,7 @@ class CardService:
# 카드 성공률(#12) — 카드 사용→타결 집계를 page 카드에 매핑.
_e, success_map = await DB_SESSION_MNG.execute_lambda(
nego_cards.DBType(), DBWRType.DB_READ.value,
lambda s: self.card_crud.card_success_map(s, company_uuid),
lambda s: self.card_crud.card_success_map(s),
)
success_map = success_map or {}
for c in page: