user_query.py
3.0 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
# coding=utf-8
#author: qianyingz
#createtime: 2021/8/14
#email: qianyingz@chinadci.com
from authlib.oidc.core.claims import UserInfo
from .models import *
from app.util.component.ApiTemplate import ApiTemplate
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")
id = self.para.get('guid')
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.displayname,
"status": tmp_user.status, "displayname": tmp_user.displayname}
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.displayname,
"status": t.status, "displayname": t.displayname},
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": "name",
"in": "query",
"type": "string",
"description": "名称关键字"},
{"name": "guid",
"in": "query",
"type": "string",
"description": "用户id,用于获取用户信息"}
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}