From d1a245c340638a900742f583f0d3470305162249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B2=E8=BE=B0=E7=94=9F=E4=BA=A7?= Date: Fri, 24 Apr 2026 14:10:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20network=5Fmatched=5Fcount=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=9C=BA=E5=88=B6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 创建寻配号时初始化network_matched_count 2. 列表接口从数据库读取,如为0则计算一次 3. 点击查看网络匹配时更新数据库 News.jsx: 0.0.6 → 0.0.7 seek.py: 0.0.7 → 0.0.8 seek_info.py: 添加network_matched_count字段 --- backend/app/models/seek_info.py | 1 + backend/app/routers/seek.py | 40 ++++++++++++++++++++++++--------- frontend/src/pages/News.jsx | 4 ++-- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/backend/app/models/seek_info.py b/backend/app/models/seek_info.py index eb3fd6c..13b21b1 100644 --- a/backend/app/models/seek_info.py +++ b/backend/app/models/seek_info.py @@ -33,6 +33,7 @@ class SeekInfo(Base): # 统计 view_count = Column(Integer, default=0) contact_count = Column(Integer, default=0) + network_matched_count = Column(Integer, default=0) # 网络匹配数量(缓存) # 时间 created_at = Column(DateTime(timezone=True), server_default=func.now()) diff --git a/backend/app/routers/seek.py b/backend/app/routers/seek.py index 16130ff..3a277d5 100644 --- a/backend/app/routers/seek.py +++ b/backend/app/routers/seek.py @@ -1,6 +1,6 @@ # seek - 寻配号路由 -# Version: 0.0.7 (2026-04-24) -# 更新:添加network_matched_count计算 +# Version: 0.0.8 (2026-04-24) +# 更新:network_matched_count缓存到数据库,创建时初始化,点击时更新 from fastapi import APIRouter, Depends, Query, HTTPException from sqlalchemy.orm import Session @@ -104,14 +104,19 @@ def get_seek_list( user_name = user.f01_01_name if user else '匿名用户' # 构建响应(不实时计算网络匹配,网络匹配在点击时再查) - # 计算自有匹配数量和网络匹配数量 + # 计算自有匹配数量,网络匹配数量从数据库读取(如为0则计算一次) matched_count = 0 - network_matched_count = 0 + network_matched_count = getattr(item, 'network_matched_count', 0) or 0 + if network_matched_count == 0 and item.expect_number and len(item.expect_number) == 10: + # 如果数据库中没有值,计算一次并保存 + network_matched_count = match_collections_count_from_coolbot(item.expect_number) + # 更新数据库 + item.network_matched_count = network_matched_count + db.commit() + if item.expect_number and len(item.expect_number) == 10: if current_user and current_user.f99_90_id: matched_count = match_collections_count(db, current_user.f99_90_id, item.expect_number) - # 网络匹配数量(需要一定时间,可以返回0让用户点击时再计算) - network_matched_count = match_collections_count_from_coolbot(item.expect_number) result.append(SeekInfoResponse( id=item.id, @@ -164,6 +169,11 @@ def create_seek( if not current_user: raise HTTPException(status_code=401, detail="请先登录") + # 计算网络匹配数量(创建时初始化) + network_matched_count = 0 + if data.expect_number and len(data.expect_number) == 10: + network_matched_count = match_collections_count_from_coolbot(data.expect_number) + seek = SeekInfo( user_id=current_user.f99_90_id, title=data.title, @@ -174,7 +184,10 @@ def create_seek( expect_number=data.expect_number, expect_price_min=data.expect_price_min, expect_price_max=data.expect_price_max, - status="active" + status="active", + view_count=0, + contact_count=0, + network_matched_count=network_matched_count # 保存初始化值 ) db.add(seek) db.commit() @@ -232,10 +245,10 @@ def get_seek_match( @router.get("/network-match/{info_id}") def get_network_match( info_id: str, - limit: int = Query(20, ge=1, le=100), + limit: int = Query(100, ge=1, le=500), db: Session = Depends(get_db) ): - """获取一尘数据库中匹配的藏品列表""" + """获取一尘数据库中匹配的藏品列表,点击时更新network_matched_count""" info = db.query(SeekInfo).filter(SeekInfo.id == info_id).first() if not info: raise HTTPException(status_code=404, detail="寻配号信息不存在") @@ -243,8 +256,15 @@ def get_network_match( if not info.expect_number: return {"matched_count": 0, "collections": []} + # 获取匹配列表 matched = match_collections_list_from_coolbot(info.expect_number, limit=limit) - return {"matched_count": len(matched), "collections": matched} + actual_count = len(matched) + + # 点击查看时更新network_matched_count + info.network_matched_count = actual_count + db.commit() + + return {"matched_count": actual_count, "collections": matched} @router.post("/match-confirm") def match_seek_confirm( diff --git a/frontend/src/pages/News.jsx b/frontend/src/pages/News.jsx index d592716..b72d681 100644 --- a/frontend/src/pages/News.jsx +++ b/frontend/src/pages/News.jsx @@ -1,7 +1,7 @@ /** * News - 资讯列表页面 - * Version: 0.0.6 (2026-04-24) - * 更新:网络匹配数量正确显示 + * Version: 0.0.7 (2026-04-24) + * 更新:network_matched_count缓存机制 */ import React, { useState, useEffect } from 'react'