为基础资料维护页面增加导入导出
This commit is contained in:
@@ -568,6 +568,70 @@ class MasterDao:
|
||||
await db.flush()
|
||||
return inventory
|
||||
|
||||
@classmethod
|
||||
async def list_sites_by_code(
|
||||
cls,
|
||||
db: AsyncSession,
|
||||
site_code: str,
|
||||
scope: TestBatchScope,
|
||||
) -> list[BizCustomerSite]:
|
||||
"""按现场编码列出当前数据范围内的现场,用于导入时消除重名。"""
|
||||
return await cls._list_by_code(db, BizCustomerSite, BizCustomerSite.site_code, site_code, scope)
|
||||
|
||||
@classmethod
|
||||
async def list_lines_by_code(
|
||||
cls,
|
||||
db: AsyncSession,
|
||||
line_code: str,
|
||||
scope: TestBatchScope,
|
||||
) -> list[BizProductionLine]:
|
||||
"""按产线编码列出当前数据范围内的产线,用于判断能否变更所属现场。"""
|
||||
return await cls._list_by_code(db, BizProductionLine, BizProductionLine.line_code, line_code, scope)
|
||||
|
||||
@classmethod
|
||||
async def list_tunnels_by_code(
|
||||
cls,
|
||||
db: AsyncSession,
|
||||
tunnel_code: str,
|
||||
scope: TestBatchScope,
|
||||
) -> list[BizTunnel]:
|
||||
"""按隧道编号列出当前数据范围内的隧道,用于判断能否变更所属现场。"""
|
||||
return await cls._list_by_code(db, BizTunnel, BizTunnel.tunnel_code, tunnel_code, scope)
|
||||
|
||||
@classmethod
|
||||
async def map_customer_codes(cls, db: AsyncSession, customer_ids: set[int]) -> dict[int, str]:
|
||||
"""批量把客户 ID 转成客户编码,供导出模板列使用。"""
|
||||
if not customer_ids:
|
||||
return {}
|
||||
result = await db.execute(
|
||||
select(BizCustomer.customer_id, BizCustomer.customer_code).where(BizCustomer.customer_id.in_(customer_ids))
|
||||
)
|
||||
return {int(customer_id): customer_code for customer_id, customer_code in result.all()}
|
||||
|
||||
@classmethod
|
||||
async def map_site_codes(cls, db: AsyncSession, site_ids: set[int]) -> dict[int, str]:
|
||||
"""批量把现场 ID 转成现场编码,供产线和隧道导出使用。"""
|
||||
if not site_ids:
|
||||
return {}
|
||||
result = await db.execute(
|
||||
select(BizCustomerSite.site_id, BizCustomerSite.site_code).where(BizCustomerSite.site_id.in_(site_ids))
|
||||
)
|
||||
return {int(site_id): site_code for site_id, site_code in result.all()}
|
||||
|
||||
@classmethod
|
||||
async def _list_by_code(
|
||||
cls,
|
||||
db: AsyncSession,
|
||||
model: type[Any],
|
||||
code_column: InstrumentedAttribute,
|
||||
code: str,
|
||||
scope: TestBatchScope,
|
||||
) -> list[Any]:
|
||||
result = await db.execute(
|
||||
select(model).where(code_column == code, batch_scope_condition(model.test_batch_id, scope))
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
|
||||
@classmethod
|
||||
async def list_assignable_users(cls, db: AsyncSession) -> list[Any]:
|
||||
result = await db.execute(
|
||||
|
||||
Reference in New Issue
Block a user