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.
 
 
 
 
 

196 lines
7.9 KiB

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, BatchDatatypeLabelConfigModel
from module_admin.entity.do.metadata_config_do import BatchDataopLabelConfig
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 get_col_optype_list_services(cls, db: AsyncSession, query_object, is_page: bool = False):
return await BatchLabelConfigDAO.get_col_optype_list(db, query_object, is_page)
@classmethod
async def add_busi_services(cls, db: AsyncSession, page_object):
try:
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 = [int(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:
if page_object.onum:
# edit
conf = BatchDataopLabelConfig()
conf.op_type = page_object.op_type
conf.col_type = page_object.col_type
conf.col_attr = page_object.col_attr
conf.ratio = page_object.ratio
conf.ssys_id = page_object.ssys_id
conf.mdl_name = page_object.mdl_name
conf.upd_by = page_object.upd_by
conf.upd_time = page_object.upd_time
dic = conf.model_dump(exclude_unset=True)
await BatchLabelConfigDAO.edit_dataop(db, page_object.onum, dic)
else:
# add
conf = BatchDataopLabelConfig()
conf.op_type = page_object.op_type
conf.col_type = page_object.col_type
conf.col_attr = page_object.col_attr
conf.ratio = page_object.ratio
conf.ssys_id = page_object.ssys_id
conf.mdl_name = page_object.mdl_name
conf.upd_by = page_object.upd_by
conf.upd_time = page_object.upd_time
await BatchLabelConfigDAO.add_dataop(db, conf)
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)
result = await BatchLabelConfigDAO.get_dataop_detail_by_id(db, page_object.onum)
if result.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 = [int(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
# 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:
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 = [int(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