Jelajahi Sumber

全部查询增加total
log增加时间区间查询
token过期时间增加至24小时

zhangnaiwen 2 tahun lalu
induk
melakukan
9ae0bcb894

+ 5 - 2
src/app/api/data.py

@@ -3,7 +3,7 @@ import os
 
 from flask import request, jsonify, g, current_app
 from flask_restx import Resource, Namespace, reqparse
-from sqlalchemy import select, insert, update, delete
+from sqlalchemy import select, insert, update, delete, func
 from sqlalchemy.orm import Session
 from werkzeug.datastructures import FileStorage
 
@@ -46,6 +46,9 @@ class TemplateConfigListApi(Resource):
         with Session(current_app.engine) as session:
             stmt = select(Template).where(Template.template_type == template_type)
 
+            count = select(func.count(Template.id)).where(Template.template_type == template_type)
+            count_results = session.execute(count).scalars().first()
+
             if template_name:
                 stmt = stmt.where(Template.name == template_name)
 
@@ -61,7 +64,7 @@ class TemplateConfigListApi(Resource):
 
         save_log(request, Module.DATA, 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))
 
 
 template = reqparse.RequestParser(bundle_errors=True)

+ 15 - 6
src/app/api/log.py

@@ -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')

+ 5 - 2
src/app/api/organization.py

@@ -3,7 +3,7 @@ import os
 
 from flask import request, jsonify, current_app
 from flask_restx import Resource, Namespace, reqparse
-from sqlalchemy import select, insert, delete, update
+from sqlalchemy import select, insert, delete, update, func
 from sqlalchemy.orm import Session
 from werkzeug.datastructures import FileStorage
 
@@ -36,12 +36,15 @@ class CompanyListApi(Resource):
         page = int(request.args.get('page', 1))
 
         with Session(current_app.engine) as session:
+            count = select(func.count(Company.id))
+            count_results = session.execute(count).scalars().first()
+
             stmt = select(Company).offset(page_size * (page - 1)).limit(page_size)
             results = session.execute(stmt).scalars().all()
 
         save_log(request, Module.ORGANIZATION, 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))
 
 
 company_details = reqparse.RequestParser(bundle_errors=True)

+ 0 - 1
src/app/api/permission.py

@@ -54,7 +54,6 @@ class AuthPermissionApi(Resource):
         path = request.args.get('path')
 
         with Session(current_app.engine) as session:
-            # todo role_id 写入token?
             # 根据用户id获取角色id
             stmt = select(User.role).where(User.id == g.user_id)
             role_id = session.execute(stmt).scalars().first()

+ 5 - 1
src/app/api/role.py

@@ -32,12 +32,16 @@ class GetUserListApi(Resource):
         page = int(request.args.get('page', 1))
 
         with Session(current_app.engine) as session:
+
+            count = select(func.count(Role.id))
+            count_results = session.execute(count).scalars().first()
+
             stmt = select(Role).offset(page_size * (page - 1)).limit(page_size)
             results = session.execute(stmt).scalars().all()
 
         save_log(request, Module.ROLE, 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))
 
 
 role = reqparse.RequestParser(bundle_errors=True)

+ 5 - 2
src/app/api/users.py

@@ -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 insert, select, update, delete
+from sqlalchemy import insert, select, update, delete, func
 from sqlalchemy.orm import Session
 
 from app.defines import StatesCode, Module, OperationType
@@ -36,12 +36,15 @@ class GetUserListApi(Resource):
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='用户状态不能为空')
 
         with Session(current_app.engine) as session:
+            count = select(func.count(User.id)).where(User.account_status == status)
+            count_results = session.execute(count).scalars().first()
+
             stmt = select(User).where(User.account_status == status).offset(page_size * (page - 1)).limit(page_size)
             results = session.execute(stmt).scalars().all()
 
         save_log(request, Module.USER, 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))
 
 
 add_user = reqparse.RequestParser(bundle_errors=True)