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

133 lines
3.4 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-25 17:08:30 +08:00
def get_monitor_data_impl():
2022-03-29 16:01:29 +08:00
"""
监测数据
"""
2022-03-25 17:08:30 +08:00
db = MongoHelper("tfse_v0.21")
monitor_data = dict()
2022-02-17 16:58:39 +08:00
2022-03-25 17:08:30 +08:00
def log_data_impl():
monitor_data['异常日志'] = 0
2022-02-17 16:58:39 +08:00
2022-03-25 17:08:30 +08:00
def feedback_data_impl():
monitor_data['留言反馈'] = 0
2022-02-18 14:23:50 +08:00
2022-03-25 17:08:30 +08:00
def services_data_impl():
monitor_data['服务次数'] = db.find_all_data_with_count(
"企业数据",
"评价记录",
{"进行状态": "完成"}
)
2022-02-18 14:23:50 +08:00
2022-03-25 17:08:30 +08:00
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
def get_rating_static_impl():
2022-03-29 16:01:29 +08:00
"""
评价统计查询
"""
2022-03-25 17:08:30 +08:00
db = MongoHelper("tfse_v0.21")
2022-03-28 15:00:12 +08:00
# 日期正则表达式 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天以前
start = time.strftime("%Y-%m-%d", time.localtime(time.time() - 60*60*24*30))
2022-03-25 17:08:30 +08:00
records = db.find_data_with_aggregate(
"企业数据",
"评价记录",
[
2022-03-28 15:00:12 +08:00
{"$match": {"进行状态": "完成", "评价完成日期": {"$gte": start}}},
2022-03-25 17:08:30 +08:00
{"$group": {"_id": "$评价完成日期", "count": {"$sum": 1}}},
{"$sort": {"_id": 1}}
]
)
2022-03-28 15:00:12 +08:00
# 聚类统计用的_id字段更名为date
2022-03-28 15:59:49 +08:00
result = dict()
result['日期'] = list()
result['次数'] = list()
for data in records:
result['日期'].append(data['_id'])
result['次数'].append(data['count'])
return result
def get_industry_distribute_impl():
2022-03-29 16:01:29 +08:00
"""
行业分布数据查询
"""
2022-03-28 15:59:49 +08:00
db = MongoHelper("tfse_v0.21")
records = db.find_data_with_aggregate(
"应用端",
"企业用户",
[
{"$match": {"已认证": ""}},
{"$group": {"_id": "$一级行业", "count": {"$sum": 1}}},
{"$sort": {"_id": 1}}
]
)
result = list()
2022-03-25 17:08:30 +08:00
for data in records:
2022-03-28 15:59:49 +08:00
values = list(data.values())
result.append({values[0]: values[1]})
return result
2022-03-28 16:27:37 +08:00
def get_new_companies_impl(page_size, page_no):
2022-03-29 16:01:29 +08:00
"""
按照注册时间倒序返回新增企业信息
page_size: 每页数据条数
page_no: 当前页码
return: 查询结果
"""
2022-03-28 16:27:37 +08:00
db = MongoHelper("tfse_v0.21")
records = db.find_data_by_page_with_sort(
"应用端",
"企业用户",
{"已认证": ""},
["企业ID", "企业名称", "邮箱", "注册时间"],
{"注册时间": -1},
page_size,
page_no
)
2022-03-30 13:56:05 +08:00
total = db.find_all_data_with_count(
"应用端",
"企业用户",
{"已认证": ""}
)
result = {
"records": records,
"total": total
}
return result