From b8961a32e0a73d8a795f4d141c1c56a7be20ca98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B2=E8=BE=B0=E7=94=9F=E4=BA=A7?= Date: Wed, 8 Apr 2026 13:22:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8network=5Fmatched=5Fco?= =?UTF-8?q?unt=E7=BB=9F=E8=AE=A1=E7=BD=91=E7=BB=9C=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/routers/information.py | 35 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/backend/app/routers/information.py b/backend/app/routers/information.py index 5080795..2c75c5e 100644 --- a/backend/app/routers/information.py +++ b/backend/app/routers/information.py @@ -1078,8 +1078,6 @@ def get_seek_stats( db: Session = Depends(get_db) ): """获取寻配号统计数据""" - from sqlalchemy import or_, and_ - # 寻号需求数(seek类型且expect_number不为空的总数) seek_count = db.query(Information).filter( Information.info_type == 'seek', @@ -1087,7 +1085,8 @@ def get_seek_stats( Information.expect_number != '' ).count() - # 我的匹配:自有藏品匹配成功的寻号帖子数量(is_matched为confirmed或pending_network) + # 我的匹配:自有藏品匹配成功的寻号帖子数量 + # 即 is_matched = 'confirmed' 的记录,用户ID等于当前用户 user_matched_count = 0 if current_user: user_matched_count = db.query(Information).filter( @@ -1095,24 +1094,30 @@ def get_seek_stats( Information.expect_number.isnot(None), Information.expect_number != '', Information.matched_user_id == current_user.f99_90_id, - Information.is_matched != 'pending' + Information.is_matched == 'confirmed' ).count() - # 总共匹配 = 自有匹配成功数 + 网络数据匹配成功数 + # 总共匹配:自有匹配成功 + 网络数据匹配成功 # 自有匹配成功:is_matched = 'confirmed' - # 网络数据匹配成功:is_matched = 'pending_network'(表示网络数据已匹配) - from sqlalchemy import func - self_matched = db.query(func.count(Information.id)).filter( + # 网络数据匹配成功:查询每个帖子的network_matched_count并求和 + seeks = db.query(Information).filter( Information.info_type == 'seek', - Information.is_matched == 'confirmed' - ).scalar() or 0 + Information.expect_number.isnot(None), + Information.expect_number != '' + ).all() - network_matched = db.query(func.count(Information.id)).filter( - Information.info_type == 'seek', - Information.is_matched == 'pending_network' - ).scalar() or 0 + total_self_matched = 0 + total_network_matched = 0 + for seek in seeks: + # 自身匹配成功 + 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 { "seekCount": seek_count,