task_count.py
1.3 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
# coding=utf-8
# author: 4N
# createtime: 2020/9/4
# email: nheweijun@sina.com
from ..models import db,Task
from sqlalchemy import func
from app.util.component.ApiTemplate import ApiTemplate
class Api(ApiTemplate):
api_name = "任务统计"
def process(self):
res= {}
try:
tasks = db.session.query(func.count(Task.state), Task.state)
creator = self.para.get("creator")
if creator:
tasks = tasks.filter_by(creator=creator)
tasks = tasks.group_by(Task.state).all()
res["data"] = {}
for task in tasks:
res["data"][task[1].__str__()] = task[0]
for status in ["-1", "0", "1", "2"]:
if not res["data"].get(status):
res["data"][status] = 0
res["result"] = True
except Exception as e:
raise e
return res
api_doc = {
"tags": ["任务接口"],
"parameters": [
{"name": "creator",
"in": "formData",
"type": "string"}
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}