去除旧的识别记录表,添加新的识别记录表
This commit is contained in:
parent
b79ef0504b
commit
2687b73dfe
@ -65,7 +65,6 @@ class CustomHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||
# else:
|
||||
# self._send_json_response(404, {'error': '接口未找到'})
|
||||
if self.path == "/api/resource/v2/door/search":
|
||||
|
||||
self._send_json_response(
|
||||
200,
|
||||
{
|
||||
|
||||
@ -0,0 +1,104 @@
|
||||
from datetime import datetime
|
||||
from fastapi import APIRouter, Depends, Form, Request
|
||||
from pydantic_validation_decorator import ValidateFields
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from config.enums import BusinessType
|
||||
from config.get_db import get_db
|
||||
from module_admin.annotation.log_annotation import Log
|
||||
from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
|
||||
from module_admin.entity.vo.user_vo import CurrentUserModel
|
||||
from module_admin.service.login_service import LoginService
|
||||
from module_admin.service.identification_record_service import Identification_recordService
|
||||
from module_admin.entity.vo.identification_record_vo import DeleteIdentification_recordModel, Identification_recordModel, Identification_recordPageQueryModel
|
||||
from utils.common_util import bytes2file_response
|
||||
from utils.log_util import logger
|
||||
from utils.page_util import PageResponseModel
|
||||
from utils.response_util import ResponseUtil
|
||||
|
||||
|
||||
identification_recordController = APIRouter(prefix='/system/identification_record', dependencies=[Depends(LoginService.get_current_user)])
|
||||
|
||||
|
||||
@identification_recordController.get(
|
||||
'/list', response_model=PageResponseModel
|
||||
# , dependencies=[Depends(CheckUserInterfaceAuth('system:identification_record:list'))]
|
||||
)
|
||||
async def get_system_identification_record_list(
|
||||
request: Request,
|
||||
identification_record_page_query: Identification_recordPageQueryModel = Depends(Identification_recordPageQueryModel.as_query),
|
||||
query_db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
# 获取分页数据
|
||||
identification_record_page_query_result = await Identification_recordService.get_identification_record_list_services(query_db, identification_record_page_query, is_page=True)
|
||||
logger.info('获取成功')
|
||||
|
||||
return ResponseUtil.success(model_content=identification_record_page_query_result)
|
||||
|
||||
|
||||
@identification_recordController.post('', dependencies=[Depends(CheckUserInterfaceAuth('system:identification_record:add'))])
|
||||
@ValidateFields(validate_model='add_identification_record')
|
||||
@Log(title='识别记录', business_type=BusinessType.INSERT)
|
||||
async def add_system_identification_record(
|
||||
request: Request,
|
||||
add_identification_record: Identification_recordModel,
|
||||
query_db: AsyncSession = Depends(get_db),
|
||||
current_user: CurrentUserModel = Depends(LoginService.get_current_user),
|
||||
):
|
||||
add_identification_record.create_time = datetime.now()
|
||||
add_identification_record.create_by = current_user.user.user_name
|
||||
add_identification_record_result = await Identification_recordService.add_identification_record_services(query_db, add_identification_record)
|
||||
logger.info(add_identification_record_result.message)
|
||||
|
||||
return ResponseUtil.success(msg=add_identification_record_result.message)
|
||||
|
||||
|
||||
@identification_recordController.put('', dependencies=[Depends(CheckUserInterfaceAuth('system:identification_record:edit'))])
|
||||
@ValidateFields(validate_model='edit_identification_record')
|
||||
@Log(title='识别记录', business_type=BusinessType.UPDATE)
|
||||
async def edit_system_identification_record(
|
||||
request: Request,
|
||||
edit_identification_record: Identification_recordModel,
|
||||
query_db: AsyncSession = Depends(get_db),
|
||||
current_user: CurrentUserModel = Depends(LoginService.get_current_user),
|
||||
):
|
||||
edit_identification_record.update_by = current_user.user.user_name
|
||||
edit_identification_record.update_time = datetime.now()
|
||||
edit_identification_record_result = await Identification_recordService.edit_identification_record_services(query_db, edit_identification_record)
|
||||
logger.info(edit_identification_record_result.message)
|
||||
|
||||
return ResponseUtil.success(msg=edit_identification_record_result.message)
|
||||
|
||||
|
||||
@identification_recordController.delete('/{ids}', dependencies=[Depends(CheckUserInterfaceAuth('system:identification_record:remove'))])
|
||||
@Log(title='识别记录', business_type=BusinessType.DELETE)
|
||||
async def delete_system_identification_record(request: Request, ids: str, query_db: AsyncSession = Depends(get_db)):
|
||||
delete_identification_record = DeleteIdentification_recordModel(ids=ids)
|
||||
delete_identification_record_result = await Identification_recordService.delete_identification_record_services(query_db, delete_identification_record)
|
||||
logger.info(delete_identification_record_result.message)
|
||||
|
||||
return ResponseUtil.success(msg=delete_identification_record_result.message)
|
||||
|
||||
|
||||
@identification_recordController.get(
|
||||
'/{id}', response_model=Identification_recordModel, dependencies=[Depends(CheckUserInterfaceAuth('system:identification_record:query'))]
|
||||
)
|
||||
async def query_detail_system_identification_record(request: Request, id: int, query_db: AsyncSession = Depends(get_db)):
|
||||
identification_record_detail_result = await Identification_recordService.identification_record_detail_services(query_db, id)
|
||||
logger.info(f'获取id为{id}的信息成功')
|
||||
|
||||
return ResponseUtil.success(data=identification_record_detail_result)
|
||||
|
||||
|
||||
@identification_recordController.post('/export', dependencies=[Depends(CheckUserInterfaceAuth('system:identification_record:export'))])
|
||||
@Log(title='识别记录', business_type=BusinessType.EXPORT)
|
||||
async def export_system_identification_record_list(
|
||||
request: Request,
|
||||
identification_record_page_query: Identification_recordPageQueryModel = Form(),
|
||||
query_db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
# 获取全量数据
|
||||
identification_record_query_result = await Identification_recordService.get_identification_record_list_services(query_db, identification_record_page_query, is_page=False)
|
||||
identification_record_export_result = await Identification_recordService.export_identification_record_list_services(identification_record_query_result)
|
||||
logger.info('导出成功')
|
||||
|
||||
return ResponseUtil.streaming(data=bytes2file_response(identification_record_export_result))
|
||||
@ -1,108 +1,112 @@
|
||||
from datetime import datetime
|
||||
from fastapi import APIRouter, Depends, Form, Request
|
||||
from pydantic_validation_decorator import ValidateFields
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from config.enums import BusinessType
|
||||
from config.get_db import get_db
|
||||
from module_admin.annotation.log_annotation import Log
|
||||
from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
|
||||
from module_admin.entity.vo.user_vo import CurrentUserModel
|
||||
from module_admin.service.login_service import LoginService
|
||||
from module_admin.service.identify_record_service import Identify_recordService
|
||||
from module_admin.entity.vo.identify_record_vo import DeleteIdentify_recordModel, Identify_recordModel, Identify_recordPageQueryModel
|
||||
from utils.common_util import bytes2file_response
|
||||
from utils.log_util import logger
|
||||
from utils.page_util import PageResponseModel
|
||||
from utils.response_util import ResponseUtil
|
||||
"""已启用
|
||||
"""
|
||||
|
||||
|
||||
identify_recordController = APIRouter(prefix='/system/identify_record', dependencies=[Depends(LoginService.get_current_user)])
|
||||
# from datetime import datetime
|
||||
# from fastapi import APIRouter, Depends, Form, Request
|
||||
# from pydantic_validation_decorator import ValidateFields
|
||||
# from sqlalchemy.ext.asyncio import AsyncSession
|
||||
# from config.enums import BusinessType
|
||||
# from config.get_db import get_db
|
||||
# from module_admin.annotation.log_annotation import Log
|
||||
# from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
|
||||
# from module_admin.entity.vo.user_vo import CurrentUserModel
|
||||
# from module_admin.service.login_service import LoginService
|
||||
# from module_admin.service.identify_record_service import Identify_recordService
|
||||
# from module_admin.entity.vo.identify_record_vo import DeleteIdentify_recordModel, Identify_recordModel, Identify_recordPageQueryModel
|
||||
# from utils.common_util import bytes2file_response
|
||||
# from utils.log_util import logger
|
||||
# from utils.page_util import PageResponseModel
|
||||
# from utils.response_util import ResponseUtil
|
||||
|
||||
|
||||
@identify_recordController.get(
|
||||
'/list', response_model=PageResponseModel
|
||||
# , dependencies=[Depends(CheckUserInterfaceAuth('system:identify_record:list'))]
|
||||
)
|
||||
async def get_system_identify_record_list(
|
||||
request: Request,
|
||||
identify_record_page_query: Identify_recordPageQueryModel = Depends(Identify_recordPageQueryModel.as_query) ,
|
||||
query_db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
# 获取分页数据
|
||||
identify_record_page_query_result = await Identify_recordService.get_identify_record_list_services(query_db, identify_record_page_query, is_page=True)
|
||||
logger.info('获取成功')
|
||||
|
||||
return ResponseUtil.success(model_content=identify_record_page_query_result)
|
||||
# identify_recordController = APIRouter(prefix='/system/identify_record', dependencies=[Depends(LoginService.get_current_user)])
|
||||
|
||||
|
||||
# @identify_recordController.post('', dependencies=[Depends(CheckUserInterfaceAuth('system:identify_record:add'))])
|
||||
# @ValidateFields(validate_model='add_identify_record')
|
||||
# @Log(title='识别记录', business_type=BusinessType.INSERT)
|
||||
# async def add_system_identify_record(
|
||||
# request: Request,
|
||||
# add_identify_record: Identify_recordModel,
|
||||
# query_db: AsyncSession = Depends(get_db),
|
||||
# current_user: CurrentUserModel = Depends(LoginService.get_current_user),
|
||||
# ):
|
||||
# add_identify_record.create_time = datetime.now()
|
||||
# add_identify_record_result = await Identify_recordService.add_identify_record_services(query_db, add_identify_record)
|
||||
# logger.info(add_identify_record_result.message)
|
||||
#
|
||||
# return ResponseUtil.success(msg=add_identify_record_result.message)
|
||||
|
||||
|
||||
# @identify_recordController.put('', dependencies=[Depends(CheckUserInterfaceAuth('system:identify_record:edit'))])
|
||||
# @ValidateFields(validate_model='edit_identify_record')
|
||||
# @Log(title='识别记录', business_type=BusinessType.UPDATE)
|
||||
# async def edit_system_identify_record(
|
||||
# request: Request,
|
||||
# edit_identify_record: Identify_recordModel,
|
||||
# query_db: AsyncSession = Depends(get_db),
|
||||
# current_user: CurrentUserModel = Depends(LoginService.get_current_user),
|
||||
# ):
|
||||
# edit_identify_record.update_by = current_user.user.user_name
|
||||
# edit_identify_record.update_time = datetime.now()
|
||||
# edit_identify_record_result = await Identify_recordService.edit_identify_record_services(query_db, edit_identify_record)
|
||||
# logger.info(edit_identify_record_result.message)
|
||||
#
|
||||
# return ResponseUtil.success(msg=edit_identify_record_result.message)
|
||||
|
||||
|
||||
# @identify_recordController.delete('/{record_ids}', dependencies=[Depends(CheckUserInterfaceAuth('system:identify_record:remove'))])
|
||||
# @Log(title='识别记录', business_type=BusinessType.DELETE)
|
||||
# async def delete_system_identify_record(request: Request, record_ids: str, query_db: AsyncSession = Depends(get_db)):
|
||||
# delete_identify_record = DeleteIdentify_recordModel(recordIds=record_ids)
|
||||
# delete_identify_record_result = await Identify_recordService.delete_identify_record_services(query_db, delete_identify_record)
|
||||
# logger.info(delete_identify_record_result.message)
|
||||
#
|
||||
# return ResponseUtil.success(msg=delete_identify_record_result.message)
|
||||
#
|
||||
#
|
||||
# @identify_recordController.get(
|
||||
# '/{record_id}', response_model=Identify_recordModel, dependencies=[Depends(CheckUserInterfaceAuth('system:identify_record:query'))]
|
||||
# '/list', response_model=PageResponseModel
|
||||
# # , dependencies=[Depends(CheckUserInterfaceAuth('system:identify_record:list'))]
|
||||
# )
|
||||
# async def query_detail_system_identify_record(request: Request, record_id: int, query_db: AsyncSession = Depends(get_db)):
|
||||
# identify_record_detail_result = await Identify_recordService.identify_record_detail_services(query_db, record_id)
|
||||
# logger.info(f'获取record_id为{record_id}的信息成功')
|
||||
#
|
||||
# return ResponseUtil.success(data=identify_record_detail_result)
|
||||
#
|
||||
#
|
||||
@identify_recordController.post('/export'
|
||||
# , dependencies=[Depends(CheckUserInterfaceAuth('system:identify_record:export'))]
|
||||
)
|
||||
@Log(title='识别记录', business_type=BusinessType.EXPORT)
|
||||
async def export_system_identify_record_list(
|
||||
request: Request,
|
||||
identify_record_page_query: Identify_recordPageQueryModel = Form(),
|
||||
query_db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
# 获取全量数据
|
||||
# identify_record_query_result = await Identify_recordService.get_identify_record_list_services(query_db, identify_record_page_query, is_page=False)
|
||||
# async def get_system_identify_record_list(
|
||||
# request: Request,
|
||||
# identify_record_page_query: Identify_recordPageQueryModel = Depends(Identify_recordPageQueryModel.as_query) ,
|
||||
# query_db: AsyncSession = Depends(get_db),
|
||||
# ):
|
||||
# # 获取分页数据
|
||||
# identify_record_page_query_result = await Identify_recordService.get_identify_record_list_services(query_db, identify_record_page_query, is_page=True)
|
||||
# logger.info('获取成功')
|
||||
|
||||
identify_record_query_result = await Identify_recordService.test_export_services(query_db)
|
||||
# return ResponseUtil.success(model_content=identify_record_page_query_result)
|
||||
|
||||
identify_record_export_result = await Identify_recordService.export_identify_record_list_services(identify_record_query_result)
|
||||
logger.info('导出成功')
|
||||
|
||||
return ResponseUtil.streaming(data=bytes2file_response(identify_record_export_result))
|
||||
# # @identify_recordController.post('', dependencies=[Depends(CheckUserInterfaceAuth('system:identify_record:add'))])
|
||||
# # @ValidateFields(validate_model='add_identify_record')
|
||||
# # @Log(title='识别记录', business_type=BusinessType.INSERT)
|
||||
# # async def add_system_identify_record(
|
||||
# # request: Request,
|
||||
# # add_identify_record: Identify_recordModel,
|
||||
# # query_db: AsyncSession = Depends(get_db),
|
||||
# # current_user: CurrentUserModel = Depends(LoginService.get_current_user),
|
||||
# # ):
|
||||
# # add_identify_record.create_time = datetime.now()
|
||||
# # add_identify_record_result = await Identify_recordService.add_identify_record_services(query_db, add_identify_record)
|
||||
# # logger.info(add_identify_record_result.message)
|
||||
# #
|
||||
# # return ResponseUtil.success(msg=add_identify_record_result.message)
|
||||
|
||||
|
||||
# # @identify_recordController.put('', dependencies=[Depends(CheckUserInterfaceAuth('system:identify_record:edit'))])
|
||||
# # @ValidateFields(validate_model='edit_identify_record')
|
||||
# # @Log(title='识别记录', business_type=BusinessType.UPDATE)
|
||||
# # async def edit_system_identify_record(
|
||||
# # request: Request,
|
||||
# # edit_identify_record: Identify_recordModel,
|
||||
# # query_db: AsyncSession = Depends(get_db),
|
||||
# # current_user: CurrentUserModel = Depends(LoginService.get_current_user),
|
||||
# # ):
|
||||
# # edit_identify_record.update_by = current_user.user.user_name
|
||||
# # edit_identify_record.update_time = datetime.now()
|
||||
# # edit_identify_record_result = await Identify_recordService.edit_identify_record_services(query_db, edit_identify_record)
|
||||
# # logger.info(edit_identify_record_result.message)
|
||||
# #
|
||||
# # return ResponseUtil.success(msg=edit_identify_record_result.message)
|
||||
|
||||
|
||||
# # @identify_recordController.delete('/{record_ids}', dependencies=[Depends(CheckUserInterfaceAuth('system:identify_record:remove'))])
|
||||
# # @Log(title='识别记录', business_type=BusinessType.DELETE)
|
||||
# # async def delete_system_identify_record(request: Request, record_ids: str, query_db: AsyncSession = Depends(get_db)):
|
||||
# # delete_identify_record = DeleteIdentify_recordModel(recordIds=record_ids)
|
||||
# # delete_identify_record_result = await Identify_recordService.delete_identify_record_services(query_db, delete_identify_record)
|
||||
# # logger.info(delete_identify_record_result.message)
|
||||
# #
|
||||
# # return ResponseUtil.success(msg=delete_identify_record_result.message)
|
||||
# #
|
||||
# #
|
||||
# # @identify_recordController.get(
|
||||
# # '/{record_id}', response_model=Identify_recordModel, dependencies=[Depends(CheckUserInterfaceAuth('system:identify_record:query'))]
|
||||
# # )
|
||||
# # async def query_detail_system_identify_record(request: Request, record_id: int, query_db: AsyncSession = Depends(get_db)):
|
||||
# # identify_record_detail_result = await Identify_recordService.identify_record_detail_services(query_db, record_id)
|
||||
# # logger.info(f'获取record_id为{record_id}的信息成功')
|
||||
# #
|
||||
# # return ResponseUtil.success(data=identify_record_detail_result)
|
||||
# #
|
||||
# #
|
||||
# @identify_recordController.post('/export'
|
||||
# # , dependencies=[Depends(CheckUserInterfaceAuth('system:identify_record:export'))]
|
||||
# )
|
||||
# @Log(title='识别记录', business_type=BusinessType.EXPORT)
|
||||
# async def export_system_identify_record_list(
|
||||
# request: Request,
|
||||
# identify_record_page_query: Identify_recordPageQueryModel = Form(),
|
||||
# query_db: AsyncSession = Depends(get_db),
|
||||
# ):
|
||||
# # 获取全量数据
|
||||
# # identify_record_query_result = await Identify_recordService.get_identify_record_list_services(query_db, identify_record_page_query, is_page=False)
|
||||
|
||||
# identify_record_query_result = await Identify_recordService.test_export_services(query_db)
|
||||
|
||||
# identify_record_export_result = await Identify_recordService.export_identify_record_list_services(identify_record_query_result)
|
||||
# logger.info('导出成功')
|
||||
|
||||
# return ResponseUtil.streaming(data=bytes2file_response(identify_record_export_result))
|
||||
|
||||
@ -0,0 +1,127 @@
|
||||
from datetime import datetime, time
|
||||
from sqlalchemy import delete, select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from module_admin.entity.do.identification_record_do import IdentificationRecord
|
||||
from module_admin.entity.vo.identification_record_vo import Identification_recordModel, Identification_recordPageQueryModel
|
||||
from utils.page_util import PageUtil
|
||||
|
||||
|
||||
class Identification_recordDao:
|
||||
"""
|
||||
识别记录模块数据库操作层
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
async def get_identification_record_detail_by_id(cls, db: AsyncSession, id: int):
|
||||
"""
|
||||
根据主键 自增获取识别记录详细信息
|
||||
|
||||
:param db: orm对象
|
||||
:param id: 主键 自增
|
||||
:return: 识别记录信息对象
|
||||
"""
|
||||
identification_record_info = (
|
||||
(
|
||||
await db.execute(
|
||||
select(IdentificationRecord)
|
||||
.where(
|
||||
IdentificationRecord.id == id
|
||||
)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.first()
|
||||
)
|
||||
|
||||
return identification_record_info
|
||||
|
||||
@classmethod
|
||||
async def get_identification_record_detail_by_info(cls, db: AsyncSession, identification_record: Identification_recordModel):
|
||||
"""
|
||||
根据识别记录参数获取识别记录信息
|
||||
|
||||
:param db: orm对象
|
||||
:param identification_record: 识别记录参数对象
|
||||
:return: 识别记录信息对象
|
||||
"""
|
||||
identification_record_info = (
|
||||
(
|
||||
await db.execute(
|
||||
select(IdentificationRecord).where(
|
||||
)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.first()
|
||||
)
|
||||
|
||||
return identification_record_info
|
||||
|
||||
@classmethod
|
||||
async def get_identification_record_list(cls, db: AsyncSession, query_object: Identification_recordPageQueryModel, is_page: bool = False):
|
||||
"""
|
||||
根据查询参数获取识别记录列表信息
|
||||
|
||||
:param db: orm对象
|
||||
:param query_object: 查询参数对象
|
||||
:param is_page: 是否开启分页
|
||||
:return: 识别记录列表信息对象
|
||||
"""
|
||||
query = (
|
||||
select(IdentificationRecord)
|
||||
.where(
|
||||
IdentificationRecord.person_name.like(f'%{query_object.person_name}%') if query_object.person_name else True,
|
||||
IdentificationRecord.door_name.like(f'%{query_object.door_name}%') if query_object.door_name else True,
|
||||
IdentificationRecord.status == query_object.status if query_object.status else True,
|
||||
IdentificationRecord.source == query_object.source if query_object.source else True,
|
||||
IdentificationRecord.create_time.between(
|
||||
datetime.combine(datetime.strptime(query_object.begin_create_time, '%Y-%m-%d'), time(00, 00, 00)),
|
||||
datetime.combine(datetime.strptime(query_object.end_create_time, '%Y-%m-%d'), time(23, 59, 59)),
|
||||
)
|
||||
if query_object.begin_create_time and query_object.end_create_time
|
||||
else True,
|
||||
)
|
||||
.order_by(IdentificationRecord.id)
|
||||
.distinct()
|
||||
)
|
||||
identification_record_list = await PageUtil.paginate(db, query, query_object.page_num, query_object.page_size, is_page)
|
||||
|
||||
return identification_record_list
|
||||
|
||||
@classmethod
|
||||
async def add_identification_record_dao(cls, db: AsyncSession, identification_record: Identification_recordModel):
|
||||
"""
|
||||
新增识别记录数据库操作
|
||||
|
||||
:param db: orm对象
|
||||
:param identification_record: 识别记录对象
|
||||
:return:
|
||||
"""
|
||||
db_identification_record = IdentificationRecord(**identification_record.model_dump(exclude={}))
|
||||
db.add(db_identification_record)
|
||||
await db.flush()
|
||||
|
||||
return db_identification_record
|
||||
|
||||
@classmethod
|
||||
async def edit_identification_record_dao(cls, db: AsyncSession, identification_record: dict):
|
||||
"""
|
||||
编辑识别记录数据库操作
|
||||
|
||||
:param db: orm对象
|
||||
:param identification_record: 需要更新的识别记录字典
|
||||
:return:
|
||||
"""
|
||||
await db.execute(update(IdentificationRecord), [identification_record])
|
||||
|
||||
@classmethod
|
||||
async def delete_identification_record_dao(cls, db: AsyncSession, identification_record: Identification_recordModel):
|
||||
"""
|
||||
删除识别记录数据库操作
|
||||
|
||||
:param db: orm对象
|
||||
:param identification_record: 识别记录对象
|
||||
:return:
|
||||
"""
|
||||
await db.execute(delete(IdentificationRecord).where(IdentificationRecord.id.in_([identification_record.id])))
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
from sqlalchemy import DateTime, String, BigInteger, Column
|
||||
from config.database import Base
|
||||
|
||||
|
||||
class IdentificationRecord(Base):
|
||||
"""
|
||||
识别记录表
|
||||
"""
|
||||
|
||||
__tablename__ = 'identification_record'
|
||||
|
||||
id = Column(BigInteger, primary_key=True, autoincrement=True, nullable=False, comment='主键 自增')
|
||||
person_name = Column(String(20), nullable=True, comment='识别人姓名')
|
||||
door_name = Column(String(20), nullable=True, comment='门禁点')
|
||||
status = Column(String(2), nullable=True, comment='识别结果, 0 拒绝, 1 通过')
|
||||
source = Column(String(20), nullable=True, comment='识别来源')
|
||||
pic_uri = Column(String(256), nullable=True, comment='图像url')
|
||||
create_time = Column(DateTime, nullable=True, comment='创建时间')
|
||||
create_by = Column(String(64), nullable=True, comment='创建者')
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
from pydantic.alias_generators import to_camel
|
||||
from typing import Optional
|
||||
from module_admin.annotation.pydantic_annotation import as_query
|
||||
|
||||
|
||||
|
||||
|
||||
class Identification_recordModel(BaseModel):
|
||||
"""
|
||||
识别记录表对应pydantic模型
|
||||
"""
|
||||
model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)
|
||||
|
||||
id: Optional[int] = Field(default=None, description='主键 自增')
|
||||
person_name: Optional[str] = Field(default=None, description='识别人姓名')
|
||||
door_name: Optional[str] = Field(default=None, description='门禁点')
|
||||
status: Optional[str] = Field(default=None, description='识别结果, 0 拒绝, 1 通过')
|
||||
source: Optional[str] = Field(default=None, description='识别来源')
|
||||
pic_uri: Optional[str] = Field(default=None, description='图像url')
|
||||
create_time: Optional[datetime] = Field(default=None, description='创建时间')
|
||||
create_by: Optional[str] = Field(default=None, description='创建者')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Identification_recordQueryModel(Identification_recordModel):
|
||||
"""
|
||||
识别记录不分页查询模型
|
||||
"""
|
||||
begin_create_time: Optional[str] = Field(default=None, description='开始创建时间')
|
||||
end_create_time: Optional[str] = Field(default=None, description='结束创建时间')
|
||||
|
||||
|
||||
@as_query
|
||||
class Identification_recordPageQueryModel(Identification_recordQueryModel):
|
||||
"""
|
||||
识别记录分页查询模型
|
||||
"""
|
||||
|
||||
page_num: int = Field(default=1, description='当前页码')
|
||||
page_size: int = Field(default=10, description='每页记录数')
|
||||
|
||||
|
||||
class DeleteIdentification_recordModel(BaseModel):
|
||||
"""
|
||||
删除识别记录模型
|
||||
"""
|
||||
|
||||
model_config = ConfigDict(alias_generator=to_camel)
|
||||
|
||||
ids: str = Field(description='需要删除的主键 自增')
|
||||
@ -0,0 +1,133 @@
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from typing import List
|
||||
from config.constant import CommonConstant
|
||||
from exceptions.exception import ServiceException
|
||||
from module_admin.entity.vo.common_vo import CrudResponseModel
|
||||
from module_admin.dao.identification_record_dao import Identification_recordDao
|
||||
from module_admin.entity.vo.identification_record_vo import DeleteIdentification_recordModel, Identification_recordModel, Identification_recordPageQueryModel
|
||||
from utils.common_util import CamelCaseUtil
|
||||
from utils.excel_util import ExcelUtil
|
||||
|
||||
|
||||
class Identification_recordService:
|
||||
"""
|
||||
识别记录模块服务层
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
async def get_identification_record_list_services(
|
||||
cls, query_db: AsyncSession, query_object: Identification_recordPageQueryModel, is_page: bool = False
|
||||
):
|
||||
"""
|
||||
获取识别记录列表信息service
|
||||
|
||||
:param query_db: orm对象
|
||||
:param query_object: 查询参数对象
|
||||
:param is_page: 是否开启分页
|
||||
:return: 识别记录列表信息对象
|
||||
"""
|
||||
identification_record_list_result = await Identification_recordDao.get_identification_record_list(query_db, query_object, is_page)
|
||||
|
||||
return identification_record_list_result
|
||||
|
||||
|
||||
@classmethod
|
||||
async def add_identification_record_services(cls, query_db: AsyncSession, page_object: Identification_recordModel):
|
||||
"""
|
||||
新增识别记录信息service
|
||||
|
||||
:param query_db: orm对象
|
||||
:param page_object: 新增识别记录对象
|
||||
:return: 新增识别记录校验结果
|
||||
"""
|
||||
try:
|
||||
await Identification_recordDao.add_identification_record_dao(query_db, page_object)
|
||||
await query_db.commit()
|
||||
return CrudResponseModel(is_success=True, message='新增成功')
|
||||
except Exception as e:
|
||||
await query_db.rollback()
|
||||
raise e
|
||||
|
||||
@classmethod
|
||||
async def edit_identification_record_services(cls, query_db: AsyncSession, page_object: Identification_recordModel):
|
||||
"""
|
||||
编辑识别记录信息service
|
||||
|
||||
:param query_db: orm对象
|
||||
:param page_object: 编辑识别记录对象
|
||||
:return: 编辑识别记录校验结果
|
||||
"""
|
||||
edit_identification_record = page_object.model_dump(exclude_unset=True, exclude={'create_time', 'create_by'})
|
||||
identification_record_info = await cls.identification_record_detail_services(query_db, page_object.id)
|
||||
if identification_record_info.id:
|
||||
try:
|
||||
await Identification_recordDao.edit_identification_record_dao(query_db, edit_identification_record)
|
||||
await query_db.commit()
|
||||
return CrudResponseModel(is_success=True, message='更新成功')
|
||||
except Exception as e:
|
||||
await query_db.rollback()
|
||||
raise e
|
||||
else:
|
||||
raise ServiceException(message='识别记录不存在')
|
||||
|
||||
@classmethod
|
||||
async def delete_identification_record_services(cls, query_db: AsyncSession, page_object: DeleteIdentification_recordModel):
|
||||
"""
|
||||
删除识别记录信息service
|
||||
|
||||
:param query_db: orm对象
|
||||
:param page_object: 删除识别记录对象
|
||||
:return: 删除识别记录校验结果
|
||||
"""
|
||||
if page_object.ids:
|
||||
id_list = page_object.ids.split(',')
|
||||
try:
|
||||
for id in id_list:
|
||||
await Identification_recordDao.delete_identification_record_dao(query_db, Identification_recordModel(id=id))
|
||||
await query_db.commit()
|
||||
return CrudResponseModel(is_success=True, message='删除成功')
|
||||
except Exception as e:
|
||||
await query_db.rollback()
|
||||
raise e
|
||||
else:
|
||||
raise ServiceException(message='传入主键 自增为空')
|
||||
|
||||
@classmethod
|
||||
async def identification_record_detail_services(cls, query_db: AsyncSession, id: int):
|
||||
"""
|
||||
获取识别记录详细信息service
|
||||
|
||||
:param query_db: orm对象
|
||||
:param id: 主键 自增
|
||||
:return: 主键 自增对应的信息
|
||||
"""
|
||||
identification_record = await Identification_recordDao.get_identification_record_detail_by_id(query_db, id=id)
|
||||
if identification_record:
|
||||
result = Identification_recordModel(**CamelCaseUtil.transform_result(identification_record))
|
||||
else:
|
||||
result = Identification_recordModel(**dict())
|
||||
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
async def export_identification_record_list_services(identification_record_list: List):
|
||||
"""
|
||||
导出识别记录信息service
|
||||
|
||||
:param identification_record_list: 识别记录信息列表
|
||||
:return: 识别记录信息对应excel的二进制数据
|
||||
"""
|
||||
# 创建一个映射字典,将英文键映射到中文键
|
||||
mapping_dict = {
|
||||
'id': '主键 自增',
|
||||
'personName': '识别人姓名',
|
||||
'doorName': '门禁点',
|
||||
'status': '识别结果, 0 拒绝, 1 通过',
|
||||
'source': '识别来源',
|
||||
'picUri': '图像url',
|
||||
'createTime': '创建时间',
|
||||
'createBy': '创建者',
|
||||
}
|
||||
binary_data = ExcelUtil.export_list2excel(identification_record_list, mapping_dict)
|
||||
|
||||
return binary_data
|
||||
Loading…
Reference in New Issue
Block a user