2020
2121
2222@log_api .route ("" )
23- @log_api .route ("/search" )
2423@permission_meta (name = "查询日志" , module = "日志" )
25- # @group_required
24+ @group_required
2625@api .validate (
2726 headers = AuthorizationSchema ,
2827 query = LogQuerySearchSchema ,
@@ -34,6 +33,36 @@ def get_logs():
3433 """
3534 日志浏览查询(人员,时间, 关键字),分页展示
3635 """
36+ logs = Log .query .filter ()
37+ total = logs .count ()
38+ items = (
39+ logs .order_by (text ("create_time desc" )).offset (g .offset ).limit (g .count ).all ()
40+ )
41+ total_page = math .ceil (total / g .count )
42+
43+ return LogPageSchema (
44+ page = g .page ,
45+ count = g .count ,
46+ total = total ,
47+ items = get_items_with_time_field (items ),
48+ total_page = total_page ,
49+ )
50+
51+
52+ @log_api .route ("/search" )
53+ @permission_meta (name = "搜索日志" , module = "日志" )
54+ @group_required
55+ @api .validate (
56+ headers = AuthorizationSchema ,
57+ query = LogQuerySearchSchema ,
58+ resp = DocResponse (r = LogPageSchema ),
59+ before = LogQuerySearchSchema .offset_handler ,
60+ tags = ["日志" ],
61+ )
62+ def search_logs ():
63+ """
64+ 日志搜索(人员,时间, 关键字),分页展示
65+ """
3766 if g .keyword :
3867 logs = Log .query .filter (Log .message .like (f"%{ g .keyword } %" ))
3968 else :
@@ -50,7 +79,11 @@ def get_logs():
5079 total_page = math .ceil (total / g .count )
5180
5281 return LogPageSchema (
53- page = g .page , count = g .count , total = total , items = items , total_page = total_page
82+ page = g .page ,
83+ count = g .count ,
84+ total = total ,
85+ items = get_items_with_time_field (items ),
86+ total_page = total_page ,
5487 )
5588
5689
@@ -74,3 +107,13 @@ def get_users_for_log():
74107 .all ()
75108 )
76109 return UsernameListSchema (items = [u .username for u in usernames ])
110+
111+
112+ # TODO:临时time字段, 等待lin 核心库中调整后移除
113+ def get_items_with_time_field (items ):
114+ new_items = list ()
115+ for item in items :
116+ item = dict (item )
117+ item ["time" ] = item ["create_time" ]
118+ new_items .append (item )
119+ return new_items
0 commit comments