[feat] negodata: 회사 커스터마이징(설정·라벨·커스텀필드·엑셀·상품공급사#20·분류카테고리#17)·일괄삭제·로그export·구분·카드 전체선택·부가정보 표시
This commit is contained in:
1 parent
1e4726f4cc
commit
88edcfed63
75 files changed
+1802
-126
No files matched your search
@@ -5,7 +5,7 @@ from sqlalchemy import select, func, and_, or_, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.database.model.models import items, users
|
||||
from common.database.model.models import items, users, supplier_items, suppliers
|
||||
from common.enums import ErrorType
|
||||
from common.logger import LOG
|
||||
from common.utils.gtime import GTime
|
||||
@@ -49,6 +49,10 @@ class IItemCRUD(ABC):
|
||||
async def user_name_map(self, cdb: AsyncSession, user_ids) -> Tuple[ErrorType, dict]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def supplier_name_map(self, cdb: AsyncSession, item_ids) -> Tuple[ErrorType, dict]:
|
||||
pass
|
||||
|
||||
|
||||
class ItemCRUD(IItemCRUD):
|
||||
async def search(
|
||||
@@ -184,3 +188,29 @@ class ItemCRUD(IItemCRUD):
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, {}
|
||||
|
||||
async def supplier_name_map(self, cdb: AsyncSession, item_ids) -> Tuple[ErrorType, dict]:
|
||||
"""item_id 목록 → {item_id: [공급사명...]}. 상품 목록 '공급사' 컬럼용(supplier_items→suppliers 배치 조인)."""
|
||||
try:
|
||||
if not item_ids:
|
||||
return ErrorType.SUCCESS, {}
|
||||
query = (
|
||||
select(supplier_items.item_id, suppliers.name)
|
||||
.join(suppliers, suppliers.supplier_id == supplier_items.supplier_id)
|
||||
.where(
|
||||
supplier_items.item_id.in_(item_ids),
|
||||
supplier_items.deleted == False, # noqa: E712
|
||||
suppliers.deleted == False, # noqa: E712
|
||||
)
|
||||
.order_by(suppliers.name)
|
||||
)
|
||||
err_type, rows = await DB_SESSION_MNG.execute(cdb, query)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
return err_type, {}
|
||||
out: dict = {}
|
||||
for item_id, name in rows:
|
||||
out.setdefault(item_id, []).append(name)
|
||||
return ErrorType.SUCCESS, out
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, {}
|
||||
@@ -5,7 +5,7 @@ from sqlalchemy import select, func, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.database.model.models import supplier_items, items
|
||||
from common.database.model.models import supplier_items, items, suppliers
|
||||
from common.enums import ErrorType
|
||||
from common.logger import LOG
|
||||
from common.utils.gtime import GTime
|
||||
@@ -48,7 +48,8 @@ class ISupplierItemCRUD(ABC):
|
||||
|
||||
class SupplierItemCRUD(ISupplierItemCRUD):
|
||||
async def list_by_supplier(self, cdb: AsyncSession, supplier_id) -> Tuple[ErrorType, list]:
|
||||
# 협력사 상세용: 매핑 + 상품명/코드 조인. Row(supplier_item_id, item_id, name, code, supply_type)
|
||||
# 협력사 상세용: 매핑 + 상품명/코드/카테고리/제조사 조인.
|
||||
# Row(supplier_item_id, item_id, name, code, supply_type, category, manufacturer)
|
||||
try:
|
||||
query = (
|
||||
select(
|
||||
@@ -57,6 +58,8 @@ class SupplierItemCRUD(ISupplierItemCRUD):
|
||||
items.name,
|
||||
items.code,
|
||||
supplier_items.supply_type,
|
||||
items.category,
|
||||
items.manufacturer,
|
||||
)
|
||||
.join(items, items.item_id == supplier_items.item_id)
|
||||
.where(
|
||||
@@ -75,11 +78,22 @@ class SupplierItemCRUD(ISupplierItemCRUD):
|
||||
return ErrorType.DB_RUN_FAILED, []
|
||||
|
||||
async def list_by_item(self, cdb: AsyncSession, item_id) -> Tuple[ErrorType, list]:
|
||||
# 견적생성 모달용: 이 상품을 취급하는 협력사별 공급유형. Row(supplier_id, supply_type)
|
||||
# 견적생성 모달·상품 상세 공용: 이 상품을 취급하는 협력사별 공급유형.
|
||||
# Row(supplier_id, supply_type, name, supplier_item_id)
|
||||
try:
|
||||
query = select(supplier_items.supplier_id, supplier_items.supply_type).where(
|
||||
supplier_items.item_id == item_id,
|
||||
supplier_items.deleted == False, # noqa: E712
|
||||
query = (
|
||||
select(
|
||||
supplier_items.supplier_id,
|
||||
supplier_items.supply_type,
|
||||
suppliers.name,
|
||||
supplier_items.supplier_item_id,
|
||||
)
|
||||
.join(suppliers, suppliers.supplier_id == supplier_items.supplier_id)
|
||||
.where(
|
||||
supplier_items.item_id == item_id,
|
||||
supplier_items.deleted == False, # noqa: E712
|
||||
suppliers.deleted == False, # noqa: E712
|
||||
)
|
||||
)
|
||||
err_type, rows = await DB_SESSION_MNG.execute(cdb, query)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
|
||||
@@ -35,6 +35,10 @@ class IUserCRUD(ABC):
|
||||
async def get_company(self, cdb: AsyncSession, company_id) -> Tuple[ErrorType, companies]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def update_company_settings(self, cdb: AsyncSession, company_id, settings: dict) -> ErrorType:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def list_by_company(self, cdb: AsyncSession, company_id, search, skip, limit) -> Tuple[ErrorType, list, int]:
|
||||
pass
|
||||
@@ -103,6 +107,18 @@ class UserCRUD(IUserCRUD):
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, None
|
||||
|
||||
async def update_company_settings(self, cdb: AsyncSession, company_id, settings: dict) -> ErrorType:
|
||||
try:
|
||||
query = (
|
||||
update(companies)
|
||||
.where(companies.company_id == company_id, companies.deleted == False) # noqa: E712
|
||||
.values(settings=settings, updated_at=GTime.UTC())
|
||||
)
|
||||
return await DB_SESSION_MNG.add(cdb, query)
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED
|
||||
|
||||
async def list_by_company(
|
||||
self, cdb: AsyncSession, company_id, search: Optional[str], skip: int, limit: int
|
||||
) -> Tuple[ErrorType, list, int]:
|
||||
|
||||
@@ -12,6 +12,7 @@ from config.server_configs import web_server_config
|
||||
from scheduler import shutdown_scheduler, start_scheduler
|
||||
import router.v1.auth.account
|
||||
import router.v1.company.user
|
||||
import router.v1.company.settings
|
||||
import router.v1.item.item
|
||||
import router.v1.supplier.supplier
|
||||
import router.v1.supplier_item.supplier_item
|
||||
@@ -68,6 +69,7 @@ async def healthz():
|
||||
# 각 도메인 라우터를 등록한다. 새 기능 추가 시 router.v1.<domain>.<file> 를 import 후 include.
|
||||
app.include_router(router.v1.auth.account.router)
|
||||
app.include_router(router.v1.company.user.router)
|
||||
app.include_router(router.v1.company.settings.router)
|
||||
app.include_router(router.v1.item.item.router)
|
||||
app.include_router(router.v1.supplier.supplier.router)
|
||||
app.include_router(router.v1.supplier_item.supplier_item.router)
|
||||
|
||||
@@ -56,3 +56,16 @@ class Res_CompanyUserList(Res_PageProtocol):
|
||||
|
||||
class Res_DeleteCompanyUser(Res_WebPacketProtocol):
|
||||
pass
|
||||
|
||||
|
||||
class CompanySettingsProtocol(WebPacketProtocol):
|
||||
pass
|
||||
|
||||
|
||||
class Req_UpdateCompanySettings(CompanySettingsProtocol):
|
||||
# settings 전체 치환. 서브키: branding/labels/features/item_fields/supplier_fields/session_fields
|
||||
settings: dict = {}
|
||||
|
||||
|
||||
class Res_CompanySettings(Res_WebPacketProtocol):
|
||||
settings: Optional[dict] = None
|
||||
@@ -0,0 +1,21 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from common.models.gmodel import UserInfo
|
||||
from router.v1.validator.dependencies import IsValidAccessToken, RemoveNoneResponse, RequireOwner
|
||||
from services.company_settings_service import CompanySettingsService
|
||||
from .protocol import Req_UpdateCompanySettings, Res_CompanySettings
|
||||
|
||||
# 회사별 커스터마이징 설정. 조회=로그인 유저 전원(앱 부팅 시 브랜딩/라벨 로드), 수정=최고관리자(OWNER) 전용.
|
||||
router = APIRouter(prefix="/v1/company/settings", tags=["CompanySettings"], responses={404: {"description": "Not found"}})
|
||||
|
||||
|
||||
@router.get(path="", response_model=Res_CompanySettings, summary="회사 커스터마이징 설정 조회")
|
||||
async def get_settings(service: CompanySettingsService = Depends(), user: UserInfo = Depends(IsValidAccessToken)):
|
||||
return RemoveNoneResponse(await service.get_settings(user.company_id))
|
||||
|
||||
|
||||
@router.put(path="/update", response_model=Res_CompanySettings, summary="회사 커스터마이징 설정 수정(최고관리자)")
|
||||
async def update_settings(
|
||||
req: Req_UpdateCompanySettings, service: CompanySettingsService = Depends(), owner: UserInfo = Depends(RequireOwner)
|
||||
):
|
||||
return RemoveNoneResponse(await service.update_settings(owner.company_id, req))
|
||||
@@ -33,6 +33,7 @@ class Req_CreateItem(ItemProtocol):
|
||||
delivery_type: Optional[int] = None
|
||||
vat_yn: Optional[bool] = None
|
||||
delivery_fee_yn: Optional[bool] = None
|
||||
custom: Optional[dict] = None # 회사 커스텀필드 값 {key: value} (정의는 companies.settings.item_fields)
|
||||
|
||||
|
||||
class Req_UpdateItem(ItemProtocol):
|
||||
@@ -56,6 +57,7 @@ class Req_UpdateItem(ItemProtocol):
|
||||
delivery_type: Optional[int] = None
|
||||
vat_yn: Optional[bool] = None
|
||||
delivery_fee_yn: Optional[bool] = None
|
||||
custom: Optional[dict] = None # 회사 커스텀필드 값 {key: value}
|
||||
|
||||
|
||||
class ItemData(WebPacketProtocol):
|
||||
@@ -85,6 +87,8 @@ class ItemData(WebPacketProtocol):
|
||||
delivery_type: Optional[DeliveryType] = None
|
||||
vat_yn: Optional[bool] = None
|
||||
delivery_fee_yn: Optional[bool] = None
|
||||
custom: Optional[dict] = None # 회사 커스텀필드 값 {key: value}
|
||||
supplier_names: list[str] = [] # 이 상품을 취급(계약)하는 공급사명 목록(목록 컬럼용, 배치 조인)
|
||||
created_at: Optional[datetime] = None
|
||||
updated_at: Optional[datetime] = None
|
||||
|
||||
|
||||
@@ -111,6 +111,7 @@ class SessionData(WebPacketProtocol):
|
||||
reject_price: Optional[int] = None
|
||||
reject_delivery_type: Optional[DeliveryType] = None
|
||||
email_sent_at: Optional[datetime] = None # 협상 초청 메일 발송 시각(None=미발송). 프론트 발송배지/재발송 판단
|
||||
custom: Optional[dict] = None # 협상완료 부가정보 값 {key: value} (공급사가 타결 후 입력, 정의는 companies.settings.session_fields)
|
||||
url: str = "" # 세션 chat 실행 URL(공급사 협상 프론트). DB 미저장 — session_id 로 구성
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ class Req_CreateSupplier(SupplierProtocol):
|
||||
manager_email: Optional[str] = None
|
||||
manager_contact_number: Optional[str] = None
|
||||
total_revenue: Optional[int] = None # 총매출액(원)
|
||||
custom: Optional[dict] = None # 회사 커스텀필드 값 {key: value} (정의는 companies.settings.supplier_fields)
|
||||
|
||||
|
||||
class Req_UpdateSupplier(SupplierProtocol):
|
||||
@@ -27,6 +28,7 @@ class Req_UpdateSupplier(SupplierProtocol):
|
||||
manager_email: Optional[str] = None
|
||||
manager_contact_number: Optional[str] = None
|
||||
total_revenue: Optional[int] = None
|
||||
custom: Optional[dict] = None # 회사 커스텀필드 값 {key: value}
|
||||
|
||||
|
||||
class SupplierData(WebPacketProtocol):
|
||||
@@ -42,6 +44,7 @@ class SupplierData(WebPacketProtocol):
|
||||
manager_email: Optional[str] = None
|
||||
manager_contact_number: Optional[str] = None
|
||||
total_revenue: Optional[int] = None # 총매출액(원)
|
||||
custom: Optional[dict] = None # 회사 커스텀필드 값 {key: value}
|
||||
account_login_id: Optional[str] = None # 채팅(협상) 계정 로그인 ID. None=미발급
|
||||
account_status: Optional[int] = None # SupplierUserStatus. None=미발급
|
||||
created_at: Optional[datetime] = None
|
||||
|
||||
@@ -33,6 +33,8 @@ class SupplierItemData(WebPacketProtocol):
|
||||
item_name: str
|
||||
item_code: Optional[str] = None
|
||||
supply_type: int
|
||||
item_category: Optional[str] = None
|
||||
item_manufacturer: Optional[str] = None
|
||||
created_at: Optional[datetime] = None
|
||||
updated_at: Optional[datetime] = None
|
||||
|
||||
@@ -40,6 +42,8 @@ class SupplierItemData(WebPacketProtocol):
|
||||
class ItemSupplyType(WebPacketProtocol):
|
||||
supplier_id: uuid.UUID
|
||||
supply_type: int
|
||||
supplier_name: Optional[str] = None
|
||||
supplier_item_id: Optional[uuid.UUID] = None # 상품측 매핑 편집(수정/삭제)용
|
||||
|
||||
|
||||
class Res_SupplierItem(Res_WebPacketProtocol):
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import uuid
|
||||
|
||||
from fastapi import Depends
|
||||
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.database.model.models import companies
|
||||
from common.enums import DBWRType, ErrorType
|
||||
from crud.user_crud import IUserCRUD, UserCRUD
|
||||
from router.v1.company.protocol import Req_UpdateCompanySettings, Res_CompanySettings
|
||||
|
||||
|
||||
class CompanySettingsService:
|
||||
"""회사별 커스터마이징 설정(companies.settings JSONB) 조회/수정.
|
||||
|
||||
- 조회는 로그인 유저 전원(브랜딩/라벨을 앱 부팅 시 로드), 수정은 라우터에서 RequireOwner 로 게이트.
|
||||
- company_id 는 토큰값만 쓴다 → 남의 회사 설정 접근 불가.
|
||||
"""
|
||||
|
||||
def __init__(self, user_crud: IUserCRUD = Depends(UserCRUD)):
|
||||
self.user_crud = user_crud
|
||||
|
||||
async def get_settings(self, company_id: str) -> Res_CompanySettings:
|
||||
res = Res_CompanySettings()
|
||||
err_type, company = await DB_SESSION_MNG.execute_lambda(
|
||||
companies.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.user_crud.get_company(s, uuid.UUID(company_id)),
|
||||
)
|
||||
if err_type != ErrorType.SUCCESS or company is None:
|
||||
res.result.SetResult(err_type if err_type != ErrorType.SUCCESS else ErrorType.ACCOUNT_NOT_FOUND)
|
||||
return res
|
||||
res.settings = company.settings
|
||||
return res
|
||||
|
||||
async def update_settings(self, company_id: str, req: Req_UpdateCompanySettings) -> Res_CompanySettings:
|
||||
res = Res_CompanySettings()
|
||||
err_type = await DB_SESSION_MNG.execute_lambda_run(
|
||||
[companies.DBType()],
|
||||
[lambda s: self.user_crud.update_company_settings(s, uuid.UUID(company_id), req.settings)],
|
||||
)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
res.result.SetResult(err_type)
|
||||
return res
|
||||
res.settings = req.settings
|
||||
return res
|
||||
@@ -67,6 +67,16 @@ class ItemService:
|
||||
if nm_err == ErrorType.SUCCESS:
|
||||
for d in res.items:
|
||||
d.creator_name = name_map.get(d.user_id)
|
||||
# 공급사명 배치 조인 — 페이지 상품의 item_id를 모아 IN 쿼리 1회로 {item_id:[공급사명]} 맵을 만들어 매핑.
|
||||
item_ids = [r.item_id for r in rows]
|
||||
if item_ids:
|
||||
sn_err, supplier_map = await DB_SESSION_MNG.execute_lambda(
|
||||
items.DBType(), DBWRType.DB_READ.value,
|
||||
lambda s: self.item_crud.supplier_name_map(s, item_ids),
|
||||
)
|
||||
if sn_err == ErrorType.SUCCESS:
|
||||
for d in res.items:
|
||||
d.supplier_names = supplier_map.get(d.item_id, [])
|
||||
res.total = total
|
||||
return res
|
||||
|
||||
|
||||
@@ -877,6 +877,7 @@ class QuotationService:
|
||||
reject_price=r.reject_price,
|
||||
reject_delivery_type=r.reject_delivery_type,
|
||||
email_sent_at=r.email_sent_at,
|
||||
custom=r.custom,
|
||||
url=self._session_chat_url(r.session_id),
|
||||
)
|
||||
for r in rows
|
||||
|
||||
@@ -85,10 +85,11 @@ class SupplierItemService:
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
res.result.SetResult(err_type)
|
||||
return res
|
||||
# Row(supplier_item_id, item_id, name, code, supply_type)
|
||||
# Row(supplier_item_id, item_id, name, code, supply_type, category, manufacturer)
|
||||
res.supplier_items = [
|
||||
SupplierItemData(
|
||||
supplier_item_id=r[0], item_id=r[1], item_name=r[2], item_code=r[3], supply_type=r[4]
|
||||
supplier_item_id=r[0], item_id=r[1], item_name=r[2], item_code=r[3], supply_type=r[4],
|
||||
item_category=r[5], item_manufacturer=r[6],
|
||||
)
|
||||
for r in rows
|
||||
]
|
||||
@@ -109,8 +110,10 @@ class SupplierItemService:
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
res.result.SetResult(err_type)
|
||||
return res
|
||||
# Row(supplier_id, supply_type)
|
||||
res.suppliers = [ItemSupplyType(supplier_id=r[0], supply_type=r[1]) for r in rows]
|
||||
# Row(supplier_id, supply_type, name, supplier_item_id)
|
||||
res.suppliers = [
|
||||
ItemSupplyType(supplier_id=r[0], supply_type=r[1], supplier_name=r[2], supplier_item_id=r[3]) for r in rows
|
||||
]
|
||||
return res
|
||||
|
||||
async def create(self, company_id: str, req: Req_CreateSupplierItem) -> Res_SupplierItem:
|
||||
|
||||
@@ -170,6 +170,7 @@ class SupplierService:
|
||||
manager_email=req.manager_email,
|
||||
manager_contact_number=req.manager_contact_number,
|
||||
total_revenue=req.total_revenue,
|
||||
custom=req.custom,
|
||||
)
|
||||
err_type = await DB_SESSION_MNG.execute_lambda_run(
|
||||
[suppliers.DBType()],
|
||||
|
||||
Reference in new issue
Block a user