tfse-admin-api-v0.2/Board/board_impl.py

139 lines
4.0 KiB
Python
Raw Normal View History

2022-02-17 16:58:39 +08:00
import time
2022-03-25 17:08:30 +08:00
from DBHelper.MongoHelper import MongoHelper
2022-02-17 16:58:39 +08:00
2022-02-16 17:03:12 +08:00
2022-03-31 04:00:44 +08:00
class DashBoardImpl:
@staticmethod
def get_monitor_data_impl():
"""
监测数据
"""
db = MongoHelper("tfse_v0.21")
monitor_data = dict()
def log_data_impl():
monitor_data['异常日志'] = db.find_all_data_with_count(
"日志",
"异常日志",
{"is_solved": "no"}
)
def feedback_data_impl():
monitor_data['留言反馈'] = 0
def services_data_impl():
monitor_data['服务次数'] = db.find_all_data_with_count(
"企业数据",
"评价记录",
{"进行状态": "完成"}
)
def verified_company_impl():
monitor_data['认证企业'] = db.find_all_data_with_count(
"应用端",
"企业用户",
{"已认证": ""}
)
log_data_impl()
feedback_data_impl()
services_data_impl()
verified_company_impl()
return monitor_data
@staticmethod
def get_rating_static_impl():
"""
评价统计查询
"""
db = MongoHelper("tfse_v0.21")
# 日期正则表达式 20xx-xx-xx格式
# data_regex = "((((19|20)\d{2})-(0?(1|[3-9])|1[012])-(0?[1-9]|[12]\d|30))|(((19|20)\d{2})-(0?[13578]|1[02])-31)|(((19|20)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))-0?2-29))$"
# 日期匹配结果
# match_result = re.match(data_regex, start)
# 若没有匹配到需求格式日期则默认查询起始日期是30天以前
# if not match_result:
# start = time.strftime("%Y-%m-%d", time.localtime(time.time() - 60*60*24*30))
# 默认查询起始日期是30天以前
2022-04-14 03:19:14 +08:00
start = time.strftime("%Y-%m-%d", time.localtime(time.time() - 60*60*24*365))
2022-03-31 04:00:44 +08:00
records = db.find_data_with_aggregate(
"企业数据",
"评价记录",
[
{"$match": {"进行状态": "完成", "评价完成日期": {"$gte": start}}},
{"$group": {"_id": "$评价完成日期", "count": {"$sum": 1}}},
{"$sort": {"_id": 1}}
]
)
2022-02-17 16:58:39 +08:00
2022-03-31 04:00:44 +08:00
# 聚类统计用的_id字段更名为date
result = dict()
result['日期'] = list()
result['次数'] = list()
for data in records:
result['日期'].append(data['_id'])
result['次数'].append(data['count'])
2022-02-17 16:58:39 +08:00
2022-03-31 04:00:44 +08:00
return result
2022-02-18 14:23:50 +08:00
2022-03-31 04:00:44 +08:00
@staticmethod
def get_industry_distribute_impl():
"""
行业分布数据查询
"""
db = MongoHelper("tfse_v0.21")
records = db.find_data_with_aggregate(
2022-04-14 03:24:58 +08:00
"企业数据",
"企业数据_更新汇总",
2022-03-31 04:00:44 +08:00
[
{"$group": {"_id": "$一级行业", "count": {"$sum": 1}}},
{"$sort": {"_id": 1}}
]
)
result = list()
for data in records:
values = list(data.values())
result.append({values[0]: values[1]})
return result
@staticmethod
def get_new_companies_impl(page_size, page_no):
"""
按照注册时间倒序返回新增企业信息
page_size: 每页数据条数
page_no: 当前页码
return: 查询结果
"""
db = MongoHelper("tfse_v0.21")
records = db.find_data_by_page_with_sort(
"应用端",
"企业用户",
{"已认证": ""},
["企业ID", "企业名称", "邮箱", "注册时间"],
{"注册时间": -1},
page_size,
page_no
2022-03-25 17:08:30 +08:00
)
2022-02-18 14:23:50 +08:00
2022-03-31 04:00:44 +08:00
total = db.find_all_data_with_count(
2022-03-25 17:08:30 +08:00
"应用端",
"企业用户",
{"已认证": ""}
)
2022-03-31 04:00:44 +08:00
result = {
"records": records,
"total": total
}
return result