功能:新增托盘二维码与用户分配

This commit is contained in:
焦龙言
2026-07-26 11:48:22 +08:00
parent f3eda856b0
commit 6851499be2
7 changed files with 1635 additions and 2 deletions
@@ -1,3 +1,4 @@
from datetime import datetime
from typing import Any, Literal
from pydantic import BaseModel
@@ -6,9 +7,11 @@ from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm.attributes import InstrumentedAttribute
from common.vo import PageModel
from module_admin.entity.do.user_do import SysUser
from module_business.entity.do.master_do import (
BizCustomer,
BizCustomerSite,
BizPallet,
BizProductionLine,
BizStrain,
BizUserSite,
@@ -29,6 +32,8 @@ from module_business.entity.vo.master_vo import (
CustomerPageQueryModel,
LineModel,
LinePageQueryModel,
PalletEditModel,
PalletPageQueryModel,
SiteModel,
SitePageQueryModel,
StrainModel,
@@ -357,6 +362,128 @@ class MasterDao:
async def delete_warehouse(cls, db: AsyncSession, warehouse_id: int) -> None:
await cls._delete(db, BizWarehouse, BizWarehouse.warehouse_id, warehouse_id)
@classmethod
async def list_pallet(
cls,
db: AsyncSession,
query_object: PalletPageQueryModel,
is_page: bool = True,
) -> PageModel | list[dict[str, Any]]:
conditions = []
if query_object.pallet_code:
conditions.append(BizPallet.pallet_code.like(f'%{query_object.pallet_code}%'))
if query_object.asset_status:
conditions.append(BizPallet.asset_status == query_object.asset_status)
statement = select(BizPallet).where(*conditions).order_by(BizPallet.pallet_id)
return await cls._paginate(db, statement, query_object, is_page)
@classmethod
async def get_pallet(
cls,
db: AsyncSession,
pallet_id: int,
*,
for_update: bool = False,
) -> BizPallet | None:
statement = select(BizPallet).where(BizPallet.pallet_id == pallet_id)
if for_update:
statement = statement.with_for_update()
result = await db.execute(statement)
return result.scalar_one_or_none()
@classmethod
async def find_pallet_by_code(cls, db: AsyncSession, pallet_code: str) -> BizPallet | None:
return await cls._find(db, BizPallet, BizPallet.pallet_code, pallet_code)
@classmethod
async def add_pallet(cls, db: AsyncSession, pallet: BizPallet) -> BizPallet:
db.add(pallet)
await db.flush()
return pallet
@classmethod
async def update_pallet(
cls,
db: AsyncSession,
pallet: PalletEditModel,
update_by: str,
update_time: datetime,
) -> None:
await db.execute(
update(BizPallet)
.where(BizPallet.pallet_id == pallet.pallet_id)
.values(
capacity_packages=pallet.capacity_packages,
asset_status=pallet.asset_status,
remark=pallet.remark,
update_by=update_by,
update_time=update_time,
)
)
@classmethod
async def delete_pallet(cls, db: AsyncSession, pallet_id: int) -> None:
await cls._delete(db, BizPallet, BizPallet.pallet_id, pallet_id)
@classmethod
async def get_pallet_inventory(
cls,
db: AsyncSession,
pallet_id: int,
*,
for_update: bool = False,
) -> BizPalletInventory | None:
statement = select(BizPalletInventory).where(BizPalletInventory.pallet_id == pallet_id)
if for_update:
statement = statement.with_for_update()
result = await db.execute(statement)
return result.scalar_one_or_none()
@classmethod
async def add_pallet_inventory(
cls,
db: AsyncSession,
inventory: BizPalletInventory,
) -> BizPalletInventory:
db.add(inventory)
await db.flush()
return inventory
@classmethod
async def delete_pallet_inventory(cls, db: AsyncSession, pallet_id: int) -> None:
await cls._delete(db, BizPalletInventory, BizPalletInventory.pallet_id, pallet_id)
@classmethod
async def count_pallet_events(cls, db: AsyncSession, pallet_id: int) -> int:
result = await db.execute(
select(func.count('*')).select_from(BizPalletEvent).where(BizPalletEvent.pallet_id == pallet_id)
)
return result.scalar() or 0
@classmethod
async def list_assignable_users(cls, db: AsyncSession) -> list[Any]:
result = await db.execute(
select(SysUser.user_id, SysUser.user_name, SysUser.nick_name)
.where(SysUser.status == '0', SysUser.del_flag == '0')
.order_by(SysUser.user_id)
)
return list(result.all())
@classmethod
async def list_assignable_users_by_ids(cls, db: AsyncSession, user_ids: list[int]) -> list[Any]:
if not user_ids:
return []
result = await db.execute(
select(SysUser.user_id, SysUser.user_name, SysUser.nick_name)
.where(
SysUser.user_id.in_(user_ids),
SysUser.status == '0',
SysUser.del_flag == '0',
)
.order_by(SysUser.user_id)
)
return list(result.all())
@classmethod
async def count_references(
cls,