You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.7 KiB
77 lines
2.7 KiB
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from module_admin.dao.datasec_config_dao import DatasecConfigDao
|
|
from module_admin.entity.vo.metadata_config_vo import DatasecConfigModel
|
|
from module_admin.entity.vo.common_vo import CrudResponseModel
|
|
from exceptions.exception import ServiceException
|
|
from utils.common_util import CamelCaseUtil
|
|
|
|
|
|
class DatasecConfigService:
|
|
"""
|
|
数据安全参数配置表 Service 层
|
|
"""
|
|
|
|
@classmethod
|
|
async def get_datasec_list_services(cls, db: AsyncSession, query_object, is_page: bool = False):
|
|
"""
|
|
获取配置列表(支持分页)
|
|
"""
|
|
return await DatasecConfigDao.get_list(db, query_object, is_page)
|
|
|
|
@classmethod
|
|
async def add_datasec_services(cls, db: AsyncSession, page_object: DatasecConfigModel):
|
|
"""
|
|
新增配置
|
|
"""
|
|
try:
|
|
await DatasecConfigDao.add(db, page_object)
|
|
await db.commit()
|
|
return CrudResponseModel(is_success=True, message="新增成功")
|
|
except Exception as e:
|
|
await db.rollback()
|
|
raise e
|
|
|
|
@classmethod
|
|
async def edit_datasec_services(cls, db: AsyncSession, page_object: DatasecConfigModel):
|
|
"""
|
|
编辑配置
|
|
"""
|
|
edit_data = page_object.model_dump(exclude_unset=True)
|
|
info = await cls.get_datasec_detail_services(db, page_object.onum)
|
|
if info and info.onum:
|
|
try:
|
|
await DatasecConfigDao.edit(db, page_object.onum, edit_data)
|
|
await db.commit()
|
|
return CrudResponseModel(is_success=True, message="更新成功")
|
|
except Exception as e:
|
|
await db.rollback()
|
|
raise e
|
|
else:
|
|
raise ServiceException(message="配置数据不存在")
|
|
|
|
@classmethod
|
|
async def delete_datasec_services(cls, db: AsyncSession, onum_list: str):
|
|
"""
|
|
批量删除配置
|
|
"""
|
|
id_list = [int(x.strip()) for x in onum_list.split(",") if x.strip().isdigit()]
|
|
if not id_list:
|
|
raise ServiceException(message="无效的编号列表")
|
|
|
|
try:
|
|
await DatasecConfigDao.delete(db, id_list)
|
|
await db.commit()
|
|
return CrudResponseModel(is_success=True, message="删除成功")
|
|
except Exception as e:
|
|
await db.rollback()
|
|
raise e
|
|
|
|
@classmethod
|
|
async def get_datasec_detail_services(cls, db: AsyncSession, onum: int):
|
|
"""
|
|
获取配置详情
|
|
"""
|
|
result = await DatasecConfigDao.get_detail_by_id(db, onum)
|
|
if result:
|
|
return DatasecConfigModel(**CamelCaseUtil.transform_result(result))
|
|
return DatasecConfigModel(**dict())
|
|
|