1010from backend .plugin .config .schema .config import (
1111 CreateConfigParam ,
1212 UpdateConfigParam ,
13+ UpdateConfigsParam ,
1314)
1415
1516
@@ -30,6 +31,17 @@ async def get(*, pk: int) -> Config:
3031 raise errors .NotFoundError (msg = '参数配置不存在' )
3132 return config
3233
34+ @staticmethod
35+ async def get_all (* , type : str | None ):
36+ """
37+ 获取所有参数配置
38+
39+ :param type: 参数配置类型
40+ :return:
41+ """
42+ async with async_db_session () as db :
43+ return await config_dao .get_all (db , type )
44+
3345 @staticmethod
3446 async def get_select (* , name : str | None , type : str | None ) -> Select :
3547 """
@@ -75,6 +87,27 @@ async def update(*, pk: int, obj: UpdateConfigParam) -> int:
7587 count = await config_dao .update (db , pk , obj )
7688 return count
7789
90+ @staticmethod
91+ async def bulk_update (* , objs : list [UpdateConfigsParam ]) -> int :
92+ """
93+ 批量更新参数配置
94+
95+ :param objs: 参数配置批量更新参数
96+ :return:
97+ """
98+ async with async_db_session .begin () as db :
99+ for batch in range (0 , len (objs ), 1000 ):
100+ for obj in objs :
101+ config = await config_dao .get (db , obj .id )
102+ if not config :
103+ raise errors .NotFoundError (msg = '参数配置不存在' )
104+ if config .key != obj .key :
105+ config = await config_dao .get_by_key (db , obj .key )
106+ if config :
107+ raise errors .ConflictError (msg = f'参数配置 { obj .key } 已存在' )
108+ count = await config_dao .bulk_update (db , objs )
109+ return count
110+
78111 @staticmethod
79112 async def delete (* , pks : list [int ]) -> int :
80113 """
0 commit comments