[feat] negodata: 견적 목록 작성자 컬럼·내 견적 필터 + 검색바 클리어(X) 버튼

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
minaChoiandClaude Opus 4.8 committed 2026-06-30 10:07:46 +09:00
1 parent 33ce82997a
commit 7b7a37ee98
15 files changed
+104 -14

No files matched your search

+23 -2
View File
@@ -8,7 +8,7 @@ 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, items, suppliers, quotation_settings,
version_nego_cards, version_wild_cards,
version_nego_cards, version_wild_cards, users,
)
from common.enums import ErrorType, QuotationStatus, SessionStatus
from common.logger import LOG
@@ -19,7 +19,7 @@ from common.utils.gtime import GTime
class IQuotationCRUD(ABC):
@abstractmethod
async def search(
self, cdb: AsyncSession, search, status, type_, start_from, start_to, skip, limit
self, cdb: AsyncSession, owner, search, status, type_, start_from, start_to, skip, limit
) -> Tuple[ErrorType, list, int]:
pass
@@ -103,6 +103,10 @@ class IQuotationCRUD(ABC):
async def item_map(self, cdb: AsyncSession, qt_ids) -> Tuple[ErrorType, dict]:
pass
@abstractmethod
async def user_name_map(self, cdb: AsyncSession, user_ids) -> Tuple[ErrorType, dict]:
pass
# ----- 스케줄러(크론) 전용 -----
@abstractmethod
async def list_due_for_close(self, cdb: AsyncSession, now) -> Tuple[ErrorType, list]:
@@ -145,6 +149,7 @@ class QuotationCRUD(IQuotationCRUD):
async def search(
self,
cdb: AsyncSession,
owner,
search: Optional[str],
status: Optional[str],
type_: Optional[str],
@@ -155,6 +160,8 @@ class QuotationCRUD(IQuotationCRUD):
) -> Tuple[ErrorType, list, int]:
try:
conditions = [quotations.deleted == False] # noqa: E712
if owner:
conditions.append(quotations.user_id == owner) # '내 견적만' — 작성자(user_id)=로그인 유저
if search:
conditions.append(or_(quotations.name.ilike(f"%{search}%"), quotations.number.ilike(f"%{search}%")))
if status:
@@ -227,6 +234,20 @@ class QuotationCRUD(IQuotationCRUD):
LOG.e_no_callstack(ex)
return ErrorType.DB_RUN_FAILED, {}
async def user_name_map(self, cdb: AsyncSession, user_ids) -> Tuple[ErrorType, dict]:
"""user_id 목록 → {user_id: name}. 견적 목록 '작성자(등록자)' 표기용(company.users 조인)."""
try:
if not user_ids:
return ErrorType.SUCCESS, {}
query = select(users.user_id, users.name).where(users.user_id.in_(user_ids))
err_type, rows = await DB_SESSION_MNG.execute(cdb, query)
if err_type != ErrorType.SUCCESS:
return err_type, {}
return ErrorType.SUCCESS, {uid: name for uid, name in rows}
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
@@ -65,6 +65,7 @@ class QuotationData(WebPacketProtocol):
participation_count: int = 0 # 견적별 참여 협력사 수(세션 distinct supplier). 목록 집계로 채움.
item_id: Optional[uuid.UUID] = None # 대표 상품 id(세션의 첫 item). 목록 조인으로 채움.
item_name: Optional[str] = None # 대표 상품명. 목록 조인으로 채움.
creator_name: Optional[str] = None # 등록자(작성자) 이름. user_id→company.users.name 조인으로 채움.
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
@@ -40,9 +40,11 @@ async def list_quotations(
type: str | None = Query(None, description="유형 필터(정확히 일치)"),
start_from: datetime | None = Query(None, description="시작일시 이후(ISO)"),
start_to: datetime | None = Query(None, description="시작일시 이전(ISO)"),
mine: bool = Query(False, description="내 견적만 보기(작성자=로그인 유저)"),
pg: PageParams = Depends(),
):
return RemoveNoneResponse(await service.list_quotations(search, status, type, start_from, start_to, pg))
owner = user_info.user_id if mine else None
return RemoveNoneResponse(await service.list_quotations(owner, search, status, type, start_from, start_to, pg))
@router.post(path="/create", response_model=Res_CreateQuotation, summary="견적 생성")
+16 -4
View File
@@ -185,23 +185,26 @@ class QuotationService:
res.target_anchoring_price = sess.target_anchoring_price
return res
async def list_quotations(self, search, status, type_, start_from, start_to, pg: PageParams) -> Res_QuotationList:
async def list_quotations(self, owner, search, status, type_, start_from, start_to, pg: PageParams) -> Res_QuotationList:
"""견적 목록. owner(user_id) 가 주어지면 '내 견적만'(작성자=로그인 유저)으로 필터한다."""
res = Res_QuotationList(page=pg.page, size=pg.size)
owner_uuid = uuid.UUID(owner) if owner else None
err_type, rows, total = await DB_SESSION_MNG.execute_lambda(
quotations.DBType(),
DBWRType.DB_READ.value,
lambda s: self.quotation_crud.search(s, search, status, type_, start_from, start_to, pg.skip, pg.size),
lambda s: self.quotation_crud.search(s, owner_uuid, search, status, type_, start_from, start_to, pg.skip, pg.size),
)
if err_type != ErrorType.SUCCESS:
res.result.SetResult(err_type)
return res
# 참여 협력사 수(세션 distinct supplier)와 대표 상품(세션 item)을 이 페이지 견적들에 대해
# 각각 한 방으로 모아 합친다(메인 쿼리 비건드림).
# 참여 협력사 수(세션 distinct supplier)·대표 상품(세션 item)·작성자명(user→users.name)을
# 이 페이지 견적들에 대해 각각 한 방으로 모아 합친다(메인 쿼리 비건드림).
qt_ids = [r.qt_id for r in rows]
counts = {}
item_map = {}
name_map = {}
if qt_ids:
cnt_err, got = await DB_SESSION_MNG.execute_lambda(
quotations.DBType(),
@@ -217,11 +220,20 @@ class QuotationService:
)
if im_err == ErrorType.SUCCESS:
item_map = got_im
user_ids = list({r.user_id for r in rows})
nm_err, got_nm = await DB_SESSION_MNG.execute_lambda(
quotations.DBType(),
DBWRType.DB_READ.value,
lambda s: self.quotation_crud.user_name_map(s, user_ids),
)
if nm_err == ErrorType.SUCCESS:
name_map = got_nm
for r in rows:
r.participation_count = counts.get(r.qt_id, 0)
item = item_map.get(r.qt_id)
if item:
r.item_id, r.item_name = item
r.creator_name = name_map.get(r.user_id)
res.quotations = [QuotationData.model_validate(r) for r in rows]
res.total = total