fix: 修正寻配号统计数据逻辑
This commit is contained in:
parent
81ac7fd826
commit
92bc6ab8d6
|
|
@ -1078,26 +1078,41 @@ def get_seek_stats(
|
||||||
db: Session = Depends(get_db)
|
db: Session = Depends(get_db)
|
||||||
):
|
):
|
||||||
"""获取寻配号统计数据"""
|
"""获取寻配号统计数据"""
|
||||||
# 寻号需求数(seek类型总数)
|
from sqlalchemy import or_, and_
|
||||||
|
|
||||||
|
# 寻号需求数(seek类型且expect_number不为空的总数)
|
||||||
seek_count = db.query(Information).filter(
|
seek_count = db.query(Information).filter(
|
||||||
Information.info_type == 'seek'
|
Information.info_type == 'seek',
|
||||||
|
Information.expect_number.isnot(None),
|
||||||
|
Information.expect_number != ''
|
||||||
).count()
|
).count()
|
||||||
|
|
||||||
# 我的藏品匹配成功数(is_matched = 'confirmed'且有matched_user_id)
|
# 我的匹配:自有藏品匹配成功的寻号帖子数量(is_matched为confirmed或pending_network)
|
||||||
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(
|
||||||
Information.info_type == 'seek',
|
Information.info_type == 'seek',
|
||||||
Information.is_matched == 'confirmed',
|
Information.expect_number.isnot(None),
|
||||||
Information.matched_user_id == current_user.f99_90_id
|
Information.expect_number != '',
|
||||||
|
Information.matched_user_id == current_user.f99_90_id,
|
||||||
|
Information.is_matched != 'pending'
|
||||||
).count()
|
).count()
|
||||||
|
|
||||||
# 总共匹配成功数(包含我的藏品匹配+网络数据匹配成功的)
|
# 总共匹配 = 自有匹配成功数 + 网络数据匹配成功数
|
||||||
# 网络数据匹配成功的定义:is_matched = 'confirmed'
|
# 自有匹配成功:is_matched = 'confirmed'
|
||||||
total_matched_count = db.query(Information).filter(
|
# 网络数据匹配成功:is_matched = 'pending_network'(表示网络数据已匹配)
|
||||||
|
from sqlalchemy import func
|
||||||
|
self_matched = db.query(func.count(Information.f99_90_id)).filter(
|
||||||
Information.info_type == 'seek',
|
Information.info_type == 'seek',
|
||||||
Information.is_matched == 'confirmed'
|
Information.is_matched == 'confirmed'
|
||||||
).count()
|
).scalar() or 0
|
||||||
|
|
||||||
|
network_matched = db.query(func.count(Information.f99_90_id)).filter(
|
||||||
|
Information.info_type == 'seek',
|
||||||
|
Information.is_matched == 'pending_network'
|
||||||
|
).scalar() or 0
|
||||||
|
|
||||||
|
total_matched_count = self_matched + network_matched
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"seekCount": seek_count,
|
"seekCount": seek_count,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue