This commit is contained in:
fengchuanhn@gmail.com
2026-05-21 16:38:11 +08:00
parent 8d5f5f2608
commit 13c8493e4c
8 changed files with 116 additions and 14 deletions

View File

@@ -44,11 +44,21 @@ async def list_configs(
async def create_config(db: AsyncSession, body: DesktopConfigCreate) -> DesktopConfig:
existing = await db.scalar(select(DesktopConfig).where(DesktopConfig.name == body.name))
existing = await db.scalar(
select(DesktopConfig).where(
DesktopConfig.name == body.name,
DesktopConfig.oem_id == body.oem_id,
)
)
if existing is not None:
raise AdminDesktopConfigError("配置键名已存在")
raise AdminDesktopConfigError("该 OEM 下配置键名已存在")
row = DesktopConfig(name=body.name, value=body.value, mark=body.mark)
row = DesktopConfig(
name=body.name,
value=body.value,
mark=body.mark,
oem_id=body.oem_id,
)
db.add(row)
await db.flush()
await db.refresh(row)
@@ -65,9 +75,15 @@ async def update_config(
raise AdminDesktopConfigError("配置不存在")
if body.name is not None and body.name != row.name:
taken = await db.scalar(select(DesktopConfig).where(DesktopConfig.name == body.name))
taken = await db.scalar(
select(DesktopConfig).where(
DesktopConfig.name == body.name,
DesktopConfig.oem_id == row.oem_id,
DesktopConfig.id != config_id,
)
)
if taken is not None:
raise AdminDesktopConfigError("配置键名已存在")
raise AdminDesktopConfigError("该 OEM 下配置键名已存在")
row.name = body.name
if body.value is not None:

View File

@@ -6,7 +6,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.models.desktopConfig import DesktopConfig
async def list_all_as_map(db: AsyncSession) -> dict[str, str]:
result = await db.execute(select(DesktopConfig))
async def list_all_as_map(db: AsyncSession, oem_id: int = 1) -> dict[str, str]:
result = await db.execute(select(DesktopConfig).where(DesktopConfig.oem_id == oem_id))
rows = result.scalars().all()
return {row.name: row.value for row in rows}

View File

@@ -0,0 +1,12 @@
"""desktop_configs 表:键值配置。"""
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.desktopConfig import DesktopConfig
async def list_all_as_map(db: AsyncSession,oem_id: int) -> dict[str, str]:
result = await db.execute(select(DesktopConfig).where(DesktopConfig.oem_id == oem_id))
rows = result.scalars().all()
return {row.name: row.value for row in rows}