fix: 使用network_matched_count统计网络匹配数据
This commit is contained in:
parent
e17024128f
commit
b8961a32e0
|
|
@ -1078,8 +1078,6 @@ def get_seek_stats(
|
||||||
db: Session = Depends(get_db)
|
db: Session = Depends(get_db)
|
||||||
):
|
):
|
||||||
"""获取寻配号统计数据"""
|
"""获取寻配号统计数据"""
|
||||||
from sqlalchemy import or_, and_
|
|
||||||
|
|
||||||
# 寻号需求数(seek类型且expect_number不为空的总数)
|
# 寻号需求数(seek类型且expect_number不为空的总数)
|
||||||
seek_count = db.query(Information).filter(
|
seek_count = db.query(Information).filter(
|
||||||
Information.info_type == 'seek',
|
Information.info_type == 'seek',
|
||||||
|
|
@ -1087,7 +1085,8 @@ def get_seek_stats(
|
||||||
Information.expect_number != ''
|
Information.expect_number != ''
|
||||||
).count()
|
).count()
|
||||||
|
|
||||||
# 我的匹配:自有藏品匹配成功的寻号帖子数量(is_matched为confirmed或pending_network)
|
# 我的匹配:自有藏品匹配成功的寻号帖子数量
|
||||||
|
# 即 is_matched = 'confirmed' 的记录,用户ID等于当前用户
|
||||||
user_matched_count = 0
|
user_matched_count = 0
|
||||||
if current_user:
|
if current_user:
|
||||||
user_matched_count = db.query(Information).filter(
|
user_matched_count = db.query(Information).filter(
|
||||||
|
|
@ -1095,24 +1094,30 @@ def get_seek_stats(
|
||||||
Information.expect_number.isnot(None),
|
Information.expect_number.isnot(None),
|
||||||
Information.expect_number != '',
|
Information.expect_number != '',
|
||||||
Information.matched_user_id == current_user.f99_90_id,
|
Information.matched_user_id == current_user.f99_90_id,
|
||||||
Information.is_matched != 'pending'
|
Information.is_matched == 'confirmed'
|
||||||
).count()
|
).count()
|
||||||
|
|
||||||
# 总共匹配 = 自有匹配成功数 + 网络数据匹配成功数
|
# 总共匹配:自有匹配成功 + 网络数据匹配成功
|
||||||
# 自有匹配成功:is_matched = 'confirmed'
|
# 自有匹配成功:is_matched = 'confirmed'
|
||||||
# 网络数据匹配成功:is_matched = 'pending_network'(表示网络数据已匹配)
|
# 网络数据匹配成功:查询每个帖子的network_matched_count并求和
|
||||||
from sqlalchemy import func
|
seeks = db.query(Information).filter(
|
||||||
self_matched = db.query(func.count(Information.id)).filter(
|
|
||||||
Information.info_type == 'seek',
|
Information.info_type == 'seek',
|
||||||
Information.is_matched == 'confirmed'
|
Information.expect_number.isnot(None),
|
||||||
).scalar() or 0
|
Information.expect_number != ''
|
||||||
|
).all()
|
||||||
|
|
||||||
network_matched = db.query(func.count(Information.id)).filter(
|
total_self_matched = 0
|
||||||
Information.info_type == 'seek',
|
total_network_matched = 0
|
||||||
Information.is_matched == 'pending_network'
|
for seek in seeks:
|
||||||
).scalar() or 0
|
# 自身匹配成功
|
||||||
|
if seek.is_matched == 'confirmed':
|
||||||
|
total_self_matched += 1
|
||||||
|
# 网络数据匹配成功(通过coolbot数据库查询)
|
||||||
|
if seek.expect_number:
|
||||||
|
network_count = match_collections_count_from_coolbot(seek.expect_number)
|
||||||
|
total_network_matched += network_count
|
||||||
|
|
||||||
total_matched_count = self_matched + network_matched
|
total_matched_count = total_self_matched + total_network_matched
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"seekCount": seek_count,
|
"seekCount": seek_count,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue