auth_log_query.py
3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# coding=utf-8
#author: qianyingz
# createtime: 2022/03/09
#email: qianyingz@chinadci.com
from datetime import datetime
from .models import *
from app.util.component.ApiTemplate import ApiTemplate
import time
class Api(ApiTemplate):
api_name = "登录日志"
def para_check(self):
pass
def process(self):
# 返回结果
res = {}
res["result"] = False
try:
# 业务逻辑
page_index = int(self.para.get("page_index", "0"))
page_size = int(self.para.get("page_size", "1000"))
#name = self.para.get("name")
sort_key = self.para.get("sort_key")
log_query = OAuthLog.query
log_query = log_query.order_by(OAuthLog.create_time.desc())
count = log_query.count()
logs = log_query.limit(page_size).offset(
page_index*page_size).all()
res["data"] = {"count": count,
"list": list(map(lambda t:
{"id": t.id, "username": t.username, "ip": t.ip,
"message": t.message, "create_time": t.create_time.strftime("%Y-%m-%d %H:%M:%S"),
"operate_type": t.operate_type,
"auth_type": t.auth_type,
"displayname": t.displayname}, logs))}
# if id:
# tmp_user = User.query.filter_by(id=id).first()
# res["data"] = {"guid": tmp_user.id, "username": tmp_user.username,
# "role": tmp_user.role, "company": tmp_user.company,
# "position": tmp_user.position, "email": tmp_user.email,
# "phone": tmp_user.phone, "display_name": tmp_user.display_name,
# "status": tmp_user.status}
# else:
# # 获取集合
# userLinq = User.query.order_by(User.id.desc())
# if name:
# userLinq = userLinq.filter(
# User.username.like("%" + name + "%"))
# tmp_count = userLinq.count()
# tmp_list = userLinq.limit(page_size).offset(
# page_index * page_size).all()
# res["data"] = {
# "count": tmp_count,
# "list": list(map(lambda t:
# {"guid": t.id, "username": t.username,
# "role": t.role, "display_name": t.display_name,
# "status": t.status},
# tmp_list))}
res["result"] = True
except Exception as e:
raise e
return res
api_doc = {
"tags": ["登录日志"],
"parameters": [
{"name": "page_index",
"in": "query",
"type": "int",
"description": "当前页",
"default": 0},
{"name": "page_size",
"in": "query",
"type": "int",
"description": "条数",
"default": 1000},
{"name": "sort_key",
"in": "query",
"type": "string",
"description": "排序"}
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}