[feat] negodata: 견적목록 상품조인 + 견적/카드 페이지네이션 + 견적중단 서버연동 + 발의→등록
- 견적 목록에 대표 상품(세션 item) 조인 노출 → '대상 상품 확인 불가' 해소 (backend protocol/crud/service + orval 재생성 + front mapQuotation 매핑) - 견적·협상카드 목록 클라이언트 페이지네이션 추가 (useClientPagination) - 견적중단을 서버 stop_quotation 호출로 영속 처리(상태=견적마감) - 신규 협상견적 라벨 발의→등록 통일 - 발의 위저드 카드선택에 협상/와일드 구분 뱃지 추가 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
53b8a78de7
commit
4f0e4c29ce
25 files changed
+668
-165
No files matched your search
@@ -6,7 +6,10 @@ from sqlalchemy import select, func, and_, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.database.model.models import quotations, sessions, chats, nego_cards, wild_cards
|
||||
from common.database.model.models import (
|
||||
quotations, sessions, chats, nego_cards, wild_cards, items, quotation_settings,
|
||||
version_nego_cards, version_wild_cards,
|
||||
)
|
||||
from common.enums import ErrorType
|
||||
from common.logger import LOG
|
||||
from common.utils.gtime import GTime
|
||||
@@ -28,6 +31,30 @@ class IQuotationCRUD(ABC):
|
||||
async def add_quotation(self, cdb: AsyncSession, quotation: quotations) -> ErrorType:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def add_sessions(self, cdb: AsyncSession, session_list: list) -> ErrorType:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def get_item_prices(self, cdb: AsyncSession, item_ids) -> Tuple[ErrorType, dict]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def get_target_margin(self, cdb: AsyncSession, qt_setting_id) -> Tuple[ErrorType, Optional[float]]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def add_rows(self, cdb: AsyncSession, obj_list: list) -> ErrorType:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def classify_card_ids(self, cdb: AsyncSession, card_ids) -> Tuple[ErrorType, dict]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def get_version_cards(self, cdb: AsyncSession, version_id) -> Tuple[ErrorType, list]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def update_quotation(self, cdb: AsyncSession, qt_id, data: dict) -> ErrorType:
|
||||
pass
|
||||
@@ -52,6 +79,10 @@ class IQuotationCRUD(ABC):
|
||||
async def session_counts(self, cdb: AsyncSession, qt_ids) -> Tuple[ErrorType, dict]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def item_map(self, cdb: AsyncSession, qt_ids) -> Tuple[ErrorType, dict]:
|
||||
pass
|
||||
|
||||
|
||||
class QuotationCRUD(IQuotationCRUD):
|
||||
async def search(
|
||||
@@ -110,6 +141,32 @@ class QuotationCRUD(IQuotationCRUD):
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, {}
|
||||
|
||||
async def item_map(self, cdb: AsyncSession, qt_ids) -> Tuple[ErrorType, dict]:
|
||||
"""견적 id 목록에 대해 대표 상품(세션의 첫 item) {qt_id: (item_id, item_name)} 을 한 번에 가져온다."""
|
||||
try:
|
||||
if not qt_ids:
|
||||
return ErrorType.SUCCESS, {}
|
||||
query = (
|
||||
select(sessions.quotation_id, sessions.item_id, items.name)
|
||||
.join(items, items.item_id == sessions.item_id)
|
||||
.where(
|
||||
sessions.quotation_id.in_(qt_ids),
|
||||
sessions.deleted == False, # noqa: E712
|
||||
items.deleted == False, # noqa: E712
|
||||
)
|
||||
)
|
||||
err_type, rows = await DB_SESSION_MNG.execute(cdb, query)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
return err_type, {}
|
||||
result = {}
|
||||
for qid, iid, iname in rows:
|
||||
if qid not in result: # 견적당 대표 1개(첫 세션 상품)
|
||||
result[qid] = (iid, iname)
|
||||
return ErrorType.SUCCESS, result
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, {}
|
||||
|
||||
async def get_by_id(self, cdb: AsyncSession, qt_id) -> Tuple[ErrorType, quotations]:
|
||||
try:
|
||||
query = select(quotations).where(quotations.qt_id == qt_id, quotations.deleted == False).limit(1) # noqa: E712
|
||||
@@ -130,6 +187,117 @@ class QuotationCRUD(IQuotationCRUD):
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED
|
||||
|
||||
async def add_sessions(self, cdb: AsyncSession, session_list: list) -> ErrorType:
|
||||
"""견적 생성 시 만들어진 협상 세션들을 한 번에 insert. 빈 목록이면 그냥 통과."""
|
||||
try:
|
||||
if not session_list:
|
||||
return ErrorType.SUCCESS
|
||||
return await DB_SESSION_MNG.insert(cdb, session_list)
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED
|
||||
|
||||
async def add_rows(self, cdb: AsyncSession, obj_list: list) -> ErrorType:
|
||||
"""임의 ORM 행 묶음 insert(버전/버전-카드 매핑 등). 빈 목록이면 통과."""
|
||||
try:
|
||||
if not obj_list:
|
||||
return ErrorType.SUCCESS
|
||||
return await DB_SESSION_MNG.insert(cdb, obj_list)
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED
|
||||
|
||||
async def classify_card_ids(self, cdb: AsyncSession, card_ids) -> Tuple[ErrorType, dict]:
|
||||
"""선택 카드 id 를 협상(1)/와일드(2)로 분류. {card_id: card_type}."""
|
||||
try:
|
||||
if not card_ids:
|
||||
return ErrorType.SUCCESS, {}
|
||||
out = {}
|
||||
n_err, n_rows = await DB_SESSION_MNG.execute(
|
||||
cdb, select(nego_cards.nego_card_id).where(nego_cards.nego_card_id.in_(card_ids), nego_cards.deleted == False) # noqa: E712
|
||||
)
|
||||
if n_err != ErrorType.SUCCESS:
|
||||
return n_err, {}
|
||||
for r in n_rows:
|
||||
out[r] = 1
|
||||
w_err, w_rows = await DB_SESSION_MNG.execute(
|
||||
cdb, select(wild_cards.wild_card_id).where(wild_cards.wild_card_id.in_(card_ids), wild_cards.deleted == False) # noqa: E712
|
||||
)
|
||||
if w_err != ErrorType.SUCCESS:
|
||||
return w_err, {}
|
||||
for r in w_rows:
|
||||
out[r] = 2
|
||||
return ErrorType.SUCCESS, out
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, {}
|
||||
|
||||
async def get_version_cards(self, cdb: AsyncSession, version_id) -> Tuple[ErrorType, list]:
|
||||
"""견적 버전에 묶인 카드. version_nego_cards/version_wild_cards 조인.
|
||||
반환: [(card_type, card_pk, number, name, script, edit_script, condition, memo), ...]."""
|
||||
try:
|
||||
out = []
|
||||
n_q = (
|
||||
select(
|
||||
nego_cards.nego_card_id, nego_cards.number, nego_cards.name,
|
||||
nego_cards.script, nego_cards.edit_script,
|
||||
)
|
||||
.join(version_nego_cards, version_nego_cards.nego_card_id == nego_cards.nego_card_id)
|
||||
.where(version_nego_cards.version_id == version_id, version_nego_cards.deleted == False, nego_cards.deleted == False) # noqa: E712
|
||||
)
|
||||
n_err, n_rows = await DB_SESSION_MNG.execute(cdb, n_q)
|
||||
if n_err != ErrorType.SUCCESS:
|
||||
return n_err, []
|
||||
for pk, number, name, script, edit in n_rows:
|
||||
out.append((1, pk, number, name, script, edit, None, None))
|
||||
w_q = (
|
||||
select(
|
||||
wild_cards.wild_card_id, wild_cards.number, wild_cards.name,
|
||||
wild_cards.script, wild_cards.edit_script, wild_cards.condition, wild_cards.memo,
|
||||
)
|
||||
.join(version_wild_cards, version_wild_cards.wild_card_id == wild_cards.wild_card_id)
|
||||
.where(version_wild_cards.version_id == version_id, version_wild_cards.deleted == False, wild_cards.deleted == False) # noqa: E712
|
||||
)
|
||||
w_err, w_rows = await DB_SESSION_MNG.execute(cdb, w_q)
|
||||
if w_err != ErrorType.SUCCESS:
|
||||
return w_err, []
|
||||
for pk, number, name, script, edit, condition, memo in w_rows:
|
||||
out.append((2, pk, number, name, script, edit, condition, memo))
|
||||
return ErrorType.SUCCESS, out
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, []
|
||||
|
||||
async def get_item_prices(self, cdb: AsyncSession, item_ids) -> Tuple[ErrorType, dict]:
|
||||
"""item_id -> price(원, NULL 가능) 매핑. 세션 목표가 계산 입력."""
|
||||
try:
|
||||
if not item_ids:
|
||||
return ErrorType.SUCCESS, {}
|
||||
query = select(items.item_id, items.price).where(
|
||||
items.item_id.in_(item_ids), items.deleted == False # noqa: E712
|
||||
)
|
||||
err_type, rows = await DB_SESSION_MNG.execute(cdb, query)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
return err_type, {}
|
||||
return ErrorType.SUCCESS, {r[0]: r[1] for r in rows}
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, {}
|
||||
|
||||
async def get_target_margin(self, cdb: AsyncSession, qt_setting_id) -> Tuple[ErrorType, Optional[float]]:
|
||||
"""견적 세팅의 목표 마진율. 세션 목표가 = price / (1 + margin)."""
|
||||
try:
|
||||
query = select(quotation_settings.target_margin_rate).where(
|
||||
quotation_settings.qt_setting_id == qt_setting_id
|
||||
).limit(1)
|
||||
err_type, rows = await DB_SESSION_MNG.execute(cdb, query)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
return err_type, None
|
||||
return ErrorType.SUCCESS, (float(rows[0]) if rows and rows[0] is not None else None)
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, None
|
||||
|
||||
async def update_quotation(self, cdb: AsyncSession, qt_id, data: dict) -> ErrorType:
|
||||
try:
|
||||
if not data:
|
||||
|
||||
Reference in new issue
Block a user