|
|
|
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,BatchDataopLabelConfigModelVo
|
|
|
|
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:
|
|
|
|
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 get_dataop_vo_services(cls, db: AsyncSession, query_object, is_page: bool = False):
|
|
|
|
result = BatchDataopLabelConfigModelVo() # 自定义返回 VO 对象
|
|
|
|
resultList = await BatchLabelConfigDAO.get_dataop_list_all(db, query_object)
|
|
|
|
if resultList:
|
|
|
|
|
|
|
|
for item in resultList:
|
|
|
|
if item.optype == "唯一类型":
|
|
|
|
result.config1 = item.config1
|
|
|
|
result.config2 = item.config2
|
|
|
|
result.config3 = item.config3
|
|
|
|
result.config4 = item.config4
|
|
|
|
result.ssys_cd = item.ssys_cd
|
|
|
|
result.mdl_name = item.mdl_name
|
|
|
|
result.upd_by = item.upd_by
|
|
|
|
result.upd_time = item.upd_time
|
|
|
|
|
|
|
|
elif item.optype == "忽略类型":
|
|
|
|
result.config5 = item.config1 # 注意:忽略类型只有 config1, config2
|
|
|
|
result.config6 = item.config2
|
|
|
|
# 其他公共字段,如果你也想覆盖可再写一次:
|
|
|
|
result.ssys_cd = item.ssys_cd
|
|
|
|
result.mdl_name = item.mdl_name
|
|
|
|
result.upd_by = item.upd_by
|
|
|
|
result.upd_time = item.upd_time
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
async def add_dataop_services(cls, db: AsyncSession, page_object):
|
|
|
|
try:
|
|
|
|
|
|
|
|
resultList = await BatchLabelConfigDAO.get_dataop_list_all(db, page_object)
|
|
|
|
|
|
|
|
# 唯一类型对象
|
|
|
|
onopLabel = BatchDataopLabelConfigModel(
|
|
|
|
optype="唯一类型",
|
|
|
|
config1=page_object.config1,
|
|
|
|
config2=page_object.config2,
|
|
|
|
config3=page_object.config3,
|
|
|
|
config4=page_object.config4,
|
|
|
|
ssysCd=page_object.ssys_cd,
|
|
|
|
mdlName=page_object.mdl_name,
|
|
|
|
updBy=page_object.upd_by,
|
|
|
|
updTime=page_object.upd_time
|
|
|
|
)
|
|
|
|
|
|
|
|
# 忽略类型对象
|
|
|
|
inopLabel = BatchDataopLabelConfigModel(
|
|
|
|
optype="忽略类型",
|
|
|
|
config1=page_object.config5,
|
|
|
|
config2=page_object.config6,
|
|
|
|
ssysCd=page_object.ssys_cd,
|
|
|
|
mdlName=page_object.mdl_name,
|
|
|
|
updBy=page_object.upd_by,
|
|
|
|
updTime=page_object.upd_time
|
|
|
|
)
|
|
|
|
|
|
|
|
if resultList:
|
|
|
|
for item in resultList:
|
|
|
|
if item.optype == "唯一类型":
|
|
|
|
update_data = {
|
|
|
|
"config1": onopLabel.config1,
|
|
|
|
"config2": onopLabel.config2,
|
|
|
|
"config3": onopLabel.config3,
|
|
|
|
"config4": onopLabel.config4,
|
|
|
|
"ssys_cd": onopLabel.ssys_cd,
|
|
|
|
"mdl_name": onopLabel.mdl_name,
|
|
|
|
"upd_by": onopLabel.upd_by,
|
|
|
|
"upd_time": onopLabel.upd_time
|
|
|
|
}
|
|
|
|
elif item.optype == "忽略类型":
|
|
|
|
update_data = {
|
|
|
|
"config1": inopLabel.config1,
|
|
|
|
"config2": inopLabel.config2,
|
|
|
|
"ssys_cd": inopLabel.ssys_cd,
|
|
|
|
"mdl_name": inopLabel.mdl_name,
|
|
|
|
"upd_by": inopLabel.upd_by,
|
|
|
|
"upd_time": inopLabel.upd_time
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
continue # 忽略未知类型
|
|
|
|
await BatchLabelConfigDAO.edit_dataop(db, item.onum, update_data)
|
|
|
|
else:
|
|
|
|
await BatchLabelConfigDAO.add_dataop(db, onopLabel)
|
|
|
|
await BatchLabelConfigDAO.add_dataop(db, inopLabel)
|
|
|
|
|
|
|
|
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:
|
|
|
|
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
|