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.
149 lines
5.6 KiB
149 lines
5.6 KiB
from module_admin.entity.vo.modmak_vo import *
|
|
from module_admin.dao.modmak_dao import *
|
|
from utils.common_util import export_list2excel
|
|
|
|
|
|
class ModmakService:
|
|
"""
|
|
测试管理模块服务层
|
|
"""
|
|
|
|
@classmethod
|
|
def get_modmak_select_option_services(cls, result_db: Session):
|
|
"""
|
|
获取测试列表不分页信息service
|
|
:param result_db: orm对象
|
|
:return: 测试列表不分页信息对象
|
|
"""
|
|
modmak_list_result = ModmakDao.get_modmak_select_option_dao(result_db)
|
|
|
|
return modmak_list_result
|
|
|
|
@classmethod
|
|
def get_modmak_list_services(cls, result_db: Session, query_object: ModmakModel):
|
|
"""
|
|
获取测试列表信息service
|
|
:param result_db: orm对象
|
|
:param query_object: 查询参数对象
|
|
:return: 测试列表信息对象
|
|
"""
|
|
modmak_list_result = ModmakDao.get_modmak_list(result_db, query_object)
|
|
|
|
return modmak_list_result
|
|
|
|
@classmethod
|
|
def add_modmak_services(cls, result_db: Session, page_object: ModmakModel):
|
|
"""
|
|
新增测试信息service
|
|
:param result_db: orm对象
|
|
:param page_object: 新增测试对象
|
|
:return: 新增测试校验结果
|
|
"""
|
|
modmak = ModmakDao.get_modmak_detail_by_info(result_db, ModmakModel(**dict(model_oneid=page_object.model_oneid)))
|
|
if modmak:
|
|
result = dict(is_success=False, message='测试编号已存在')
|
|
else:
|
|
try:
|
|
ModmakDao.add_modmak_dao(result_db, page_object)
|
|
result_db.commit()
|
|
result = dict(is_success=True, message='新增成功')
|
|
except Exception as e:
|
|
result_db.rollback()
|
|
result = dict(is_success=False, message=str(e))
|
|
|
|
return CrudModmakResponse(**result)
|
|
|
|
@classmethod
|
|
def edit_modmak_services(cls, result_db: Session, page_object: ModmakModel):
|
|
"""
|
|
编辑测试信息service
|
|
:param result_db: orm对象
|
|
:param page_object: 编辑测试对象
|
|
:return: 编辑测试校验结果
|
|
"""
|
|
edit_modmak = page_object.dict(exclude_unset=True)
|
|
modmak_info = cls.detail_modmak_services(result_db, edit_modmak.get('model_oneid'))
|
|
if modmak_info:
|
|
if modmak_info.model_oneid != page_object.model_oneid:
|
|
modmak = ModmakDao.get_modmak_detail_by_info(result_db, ModmakModel(**dict(model_oneid=page_object.model_oneid)))
|
|
if modmak:
|
|
result = dict(is_success=False, message='测试名称已存在')
|
|
return CrudModmakResponse(**result)
|
|
try:
|
|
ModmakDao.edit_modmak_dao(result_db, edit_modmak)
|
|
result_db.commit()
|
|
result = dict(is_success=True, message='更新成功')
|
|
except Exception as e:
|
|
result_db.rollback()
|
|
result = dict(is_success=False, message=str(e))
|
|
else:
|
|
result = dict(is_success=False, message='测试不存在')
|
|
|
|
return CrudModmakResponse(**result)
|
|
|
|
@classmethod
|
|
def delete_modmak_services(cls, result_db: Session, page_object: DeleteModmakModel):
|
|
"""
|
|
删除测试信息service
|
|
:param result_db: orm对象
|
|
:param page_object: 删除测试对象
|
|
:return: 删除测试校验结果
|
|
"""
|
|
if page_object.model_oneids.split(','):
|
|
model_oneid_list = page_object.model_oneids.split(',')
|
|
try:
|
|
for model_oneid in model_oneid_list:
|
|
model_oneid_dict = dict(model_oneid=model_oneid)
|
|
ModmakDao.delete_modmak_dao(result_db, ModmakModel(**model_oneid_dict))
|
|
result_db.commit()
|
|
result = dict(is_success=True, message='删除成功')
|
|
except Exception as e:
|
|
result_db.rollback()
|
|
result = dict(is_success=False, message=str(e))
|
|
else:
|
|
result = dict(is_success=False, message='传入测试id为空')
|
|
return CrudModmakResponse(**result)
|
|
|
|
@classmethod
|
|
def detail_modmak_services(cls, result_db: Session, model_oneid: str):
|
|
"""
|
|
获取测试详细信息service
|
|
:param result_db: orm对象
|
|
:param model_oneid: 测试id
|
|
:return: 测试id对应的信息
|
|
"""
|
|
modmak = ModmakDao.get_modmak_detail_by_id(result_db, model_oneid=model_oneid)
|
|
|
|
return modmak
|
|
|
|
@staticmethod
|
|
def export_modmak_list_services(modmak_list: List):
|
|
"""
|
|
导出测试信息service
|
|
:param modmak_list: 测试信息列表
|
|
:return: 测试信息对应excel的二进制数据
|
|
"""
|
|
# 创建一个映射字典,将英文键映射到中文键
|
|
mapping_dict = {
|
|
"model_oneid": "主键",
|
|
"model_name_cn": "模型中文名称",
|
|
"model_name_en": "模型英文名称",
|
|
"model_status": "状态",
|
|
"model_create_by": "创建者",
|
|
"model_create_date": "创建日期",
|
|
"model_update_by": "更新者",
|
|
"model_update_date": "更新日期",
|
|
"remark": "备注",
|
|
}
|
|
|
|
data = [ModmakModel(**vars(row)).dict() for row in modmak_list]
|
|
|
|
for item in data:
|
|
if item.get('model_status') == '0':
|
|
item['model_status'] = '正常'
|
|
else:
|
|
item['model_status'] = '停用'
|
|
new_data = [{mapping_dict.get(key): value for key, value in item.items() if mapping_dict.get(key)} for item in data]
|
|
binary_data = export_list2excel(new_data)
|
|
|
|
return binary_data
|
|
|