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.
178 lines
6.9 KiB
178 lines
6.9 KiB
3 days ago
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||
|
from module_admin.dao.batch_label_config_dao import BatchLabelConfigDAO
|
||
|
from module_admin.entity.vo.common_vo import CrudResponseModel
|
||
|
from module_admin.entity.vo.metadata_config_vo import BatchBusiLabelConfigModel,BatchDataopLabelConfigModel,BatchDatatypeLabelConfigModel
|
||
|
from exceptions.exception import ServiceException
|
||
|
import uuid
|
||
|
from utils.common_util import CamelCaseUtil
|
||
|
from typing import List
|
||
|
from datetime import datetime
|
||
|
|
||
|
|
||
|
class BatchLabelConfigService:
|
||
|
|
||
|
# region === BatchBusiLabelConfig ===
|
||
|
|
||
|
@classmethod
|
||
|
async def get_busi_list_services(cls, db: AsyncSession, query_object, is_page: bool = False):
|
||
|
return await BatchLabelConfigDAO.get_busi_list(db, query_object, is_page)
|
||
|
|
||
|
@classmethod
|
||
|
async def add_busi_services(cls, db: AsyncSession, page_object):
|
||
|
try:
|
||
|
page_object.onum = str(uuid.uuid4())
|
||
|
await BatchLabelConfigDAO.add_busi(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_busi_services(cls, db: AsyncSession, page_object):
|
||
|
edit_data = page_object.model_dump(exclude_unset=True)
|
||
|
info = await cls.get_busi_detail_services(db, page_object.onum)
|
||
|
if info.onum:
|
||
|
try:
|
||
|
await BatchLabelConfigDAO.edit_busi(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_busi_services(cls, db: AsyncSession, onum_list: str):
|
||
|
id_list = [x.strip() for x in onum_list.split(",") if x.strip()]
|
||
|
if not id_list:
|
||
|
raise ServiceException(message="无效的编号列表")
|
||
|
|
||
|
try:
|
||
|
await BatchLabelConfigDAO.delete_busi(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_busi_detail_services(cls, db: AsyncSession, onum: str):
|
||
|
result = await BatchLabelConfigDAO.get_busi_detail_by_id(db, onum)
|
||
|
if result:
|
||
|
return BatchBusiLabelConfigModel(**CamelCaseUtil.transform_result(result))
|
||
|
return BatchBusiLabelConfigModel(**dict())
|
||
|
|
||
|
# endregion
|
||
|
|
||
|
# region === BatchDataopLabelConfig ===
|
||
|
|
||
|
@classmethod
|
||
|
async def get_dataop_list_services(cls, db: AsyncSession, query_object, is_page: bool = False):
|
||
|
return await BatchLabelConfigDAO.get_dataop_list(db, query_object, is_page)
|
||
|
|
||
|
@classmethod
|
||
|
async def add_dataop_services(cls, db: AsyncSession, page_object):
|
||
|
try:
|
||
|
page_object.onum = str(uuid.uuid4())
|
||
|
await BatchLabelConfigDAO.add_dataop(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_dataop_services(cls, db: AsyncSession, page_object):
|
||
|
edit_data = page_object.model_dump(exclude_unset=True)
|
||
|
info = await cls.get_dataop_detail_services(db, page_object.onum)
|
||
|
if info.onum:
|
||
|
try:
|
||
|
await BatchLabelConfigDAO.edit_dataop(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_dataop_services(cls, db: AsyncSession, onum_list: str):
|
||
|
id_list = [x.strip() for x in onum_list.split(",") if x.strip()]
|
||
|
if not id_list:
|
||
|
raise ServiceException(message="无效的编号列表")
|
||
|
|
||
|
try:
|
||
|
await BatchLabelConfigDAO.delete_dataop(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_dataop_detail_services(cls, db: AsyncSession, onum: str):
|
||
|
result = await BatchLabelConfigDAO.get_dataop_detail_by_id(db, onum)
|
||
|
if result:
|
||
|
return BatchDataopLabelConfigModel(**CamelCaseUtil.transform_result(result))
|
||
|
return BatchDataopLabelConfigModel(**dict())
|
||
|
|
||
|
# endregion
|
||
|
|
||
|
# region === BatchDatatypeLabelConfig ===
|
||
|
|
||
|
@classmethod
|
||
|
async def get_datatype_list_services(cls, db: AsyncSession, query_object, is_page: bool = False):
|
||
|
return await BatchLabelConfigDAO.get_datatype_list(db, query_object, is_page)
|
||
|
|
||
|
@classmethod
|
||
|
async def add_datatype_services(cls, db: AsyncSession, page_object):
|
||
|
try:
|
||
|
page_object.onum = str(uuid.uuid4())
|
||
|
await BatchLabelConfigDAO.add_datatype(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_datatype_services(cls, db: AsyncSession, page_object):
|
||
|
edit_data = page_object.model_dump(exclude_unset=True)
|
||
|
info = await cls.get_datatype_detail_services(db, page_object.onum)
|
||
|
if info.onum:
|
||
|
try:
|
||
|
await BatchLabelConfigDAO.edit_datatype(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_datatype_services(cls, db: AsyncSession, onum_list: str):
|
||
|
id_list = [x.strip() for x in onum_list.split(",") if x.strip()]
|
||
|
if not id_list:
|
||
|
raise ServiceException(message="无效的编号列表")
|
||
|
|
||
|
try:
|
||
|
await BatchLabelConfigDAO.delete_datatype(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_datatype_detail_services(cls, db: AsyncSession, onum: str):
|
||
|
result = await BatchLabelConfigDAO.get_datatype_detail_by_id(db, onum)
|
||
|
if result:
|
||
|
return BatchDatatypeLabelConfigModel(**CamelCaseUtil.transform_result(result))
|
||
|
return BatchDatatypeLabelConfigModel(**dict())
|
||
|
|
||
|
# endregion
|