|
@@ -3,7 +3,7 @@ from io import StringIO
|
|
|
|
|
|
from flask import request, jsonify, Response, current_app
|
|
|
from flask_restx import Resource, Namespace, reqparse
|
|
|
-from sqlalchemy import select
|
|
|
+from sqlalchemy import select, func
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
|
from app.defines import StatesCode, Module, OperationType
|
|
@@ -17,10 +17,12 @@ ns = Namespace('log', description='日志管理接口')
|
|
|
log_list = reqparse.RequestParser(bundle_errors=True)
|
|
|
log_list.add_argument(name='page_size', type=int, location='args', required=False, help='每页记录数量,默认:20')
|
|
|
log_list.add_argument(name='page', type=int, location='args', required=False, help='第几页')
|
|
|
-log_list.add_argument(name='module', type=int, location='args', required=False, help='系统模块')
|
|
|
-log_list.add_argument(name='name', type=int, location='args', required=False, help='操作人员')
|
|
|
-log_list.add_argument(name='operation_type', type=int, location='args', required=False, help='操作类型')
|
|
|
-log_list.add_argument(name='operation_status', type=int, location='args', required=False, help='操作状态')
|
|
|
+log_list.add_argument(name='module', type=str, location='args', required=False, help='系统模块')
|
|
|
+log_list.add_argument(name='name', type=str, location='args', required=False, help='操作人员')
|
|
|
+log_list.add_argument(name='operation_type', type=str, location='args', required=False, help='操作类型')
|
|
|
+log_list.add_argument(name='operation_status', type=str, location='args', required=False, help='操作状态')
|
|
|
+log_list.add_argument(name='start_time', type=str, location='args', required=False, help='开始时间')
|
|
|
+log_list.add_argument(name='end_time', type=str, location='args', required=False, help='结束时间')
|
|
|
|
|
|
|
|
|
@ns.route('/log_list')
|
|
@@ -38,10 +40,15 @@ class LogList(Resource):
|
|
|
name = request.args.get('name')
|
|
|
operation_type = request.args.get('operation_type')
|
|
|
operation_status = request.args.get('operation_status')
|
|
|
+ start_time = request.args.get('start_time')
|
|
|
+ end_time = request.args.get('end_time')
|
|
|
|
|
|
with Session(current_app.engine) as session:
|
|
|
stmt = select(Log)
|
|
|
|
|
|
+ count = select(func.count(Log.id))
|
|
|
+ count_results = session.execute(count).scalars().first()
|
|
|
+
|
|
|
if module:
|
|
|
stmt = stmt.where(Log.module == module)
|
|
|
if name:
|
|
@@ -50,13 +57,15 @@ class LogList(Resource):
|
|
|
stmt = stmt.where(Log.operation_type == operation_type)
|
|
|
if operation_status:
|
|
|
stmt = stmt.where(Log.operation_status == operation_status)
|
|
|
+ if start_time and end_time:
|
|
|
+ stmt = stmt.where(Log.operation_time.between(start_time, end_time))
|
|
|
|
|
|
stmt = stmt.offset(page_size * (page - 1)).limit(page_size)
|
|
|
results = session.execute(stmt).scalars().all()
|
|
|
|
|
|
save_log(request, Module.LOG, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='成功', data=to_dict(results))
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功', total=count_results, data=to_dict(results))
|
|
|
|
|
|
|
|
|
@ns.route('/log_export')
|