1
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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}
|
||||
|
||||
12
app/services/oem_desktop_config.py
Normal file
12
app/services/oem_desktop_config.py
Normal 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}
|
||||
Reference in New Issue
Block a user