diff --git a/backend/app/routers/information.py b/backend/app/routers/information.py index f981a63..ae3648e 100644 --- a/backend/app/routers/information.py +++ b/backend/app/routers/information.py @@ -1078,26 +1078,41 @@ def get_seek_stats( db: Session = Depends(get_db) ): """获取寻配号统计数据""" - # 寻号需求数(seek类型总数) + from sqlalchemy import or_, and_ + + # 寻号需求数(seek类型且expect_number不为空的总数) seek_count = db.query(Information).filter( - Information.info_type == 'seek' + Information.info_type == 'seek', + Information.expect_number.isnot(None), + Information.expect_number != '' ).count() - # 我的藏品匹配成功数(is_matched = 'confirmed'且有matched_user_id) + # 我的匹配:自有藏品匹配成功的寻号帖子数量(is_matched为confirmed或pending_network) user_matched_count = 0 if current_user: user_matched_count = db.query(Information).filter( Information.info_type == 'seek', - Information.is_matched == 'confirmed', - Information.matched_user_id == current_user.f99_90_id + Information.expect_number.isnot(None), + Information.expect_number != '', + Information.matched_user_id == current_user.f99_90_id, + Information.is_matched != 'pending' ).count() - # 总共匹配成功数(包含我的藏品匹配+网络数据匹配成功的) - # 网络数据匹配成功的定义:is_matched = 'confirmed' - total_matched_count = db.query(Information).filter( + # 总共匹配 = 自有匹配成功数 + 网络数据匹配成功数 + # 自有匹配成功:is_matched = 'confirmed' + # 网络数据匹配成功:is_matched = 'pending_network'(表示网络数据已匹配) + from sqlalchemy import func + self_matched = db.query(func.count(Information.f99_90_id)).filter( Information.info_type == 'seek', 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 { "seekCount": seek_count,