增加帖子详情api与前端页面,需完善按钮与显示

Change-Id: I84d3aace81055b8dc372f91942523d163b1ec463
diff --git a/JWLLL/main_online.py b/JWLLL/main_online.py
index f8fdc07..d479afa 100644
--- a/JWLLL/main_online.py
+++ b/JWLLL/main_online.py
@@ -339,19 +339,10 @@
     # 添加语义关联匹配得分
     # 扩展关键词进行匹配
     expanded_keywords = expand_search_keywords(keyword)
-    
     # 检测标题是否包含语义相关词
     for exp_keyword in expanded_keywords:
         if exp_keyword != keyword and exp_keyword in title:  # 避免重复计算原关键词
-            # 根据关联词的匹配类型给予不同分数
-            if exp_keyword in ["国宝", "熊猫"] and "功夫熊猫" in title:
-                score += 3.0  # 高度相关的语义映射
-            elif exp_keyword in title:
-                score += 1.5  # 一般语义关联
-    
-    # 对于特殊组合查询,额外加分
-    if ("国宝" in keyword or "熊猫" in keyword) and "电影" in keyword and "功夫熊猫" in title:
-        score += 4.0  # 对"国宝电影"、"熊猫电影"搜"功夫熊猫"特别加分
+            score += 1.5  # 一般语义关联
     
     return score
 
@@ -389,6 +380,66 @@
 # 在启动应用之前调用初始化函数
 initialize_app()
 
+# 测试路由
+@app.route('/test', methods=['GET'])
+def test():
+    import datetime
+    return jsonify({"message": "服务器正常运行", "timestamp": str(datetime.datetime.now())})
+
+# 获取单个帖子详情的API
+@app.route('/post/<int:post_id>', methods=['GET'])
+def get_post_detail(post_id):
+    """
+    获取单个帖子详情
+    """
+    logger.info(f"接收到获取帖子详情请求,post_id: {post_id}")
+    conn = get_db_conn()
+    try:
+        with conn.cursor(pymysql.cursors.DictCursor) as cursor:
+            # 查询帖子详情,先用简单查询调试
+            query = """
+            SELECT 
+                p.id,
+                p.title,
+                p.content,
+                p.heat,
+                p.created_at as create_time,
+                p.updated_at as last_active,
+                p.status
+            FROM posts p 
+            WHERE p.id = %s
+            """
+            logger.info(f"执行查询: {query} with post_id: {post_id}")
+            cursor.execute(query, (post_id,))
+            post = cursor.fetchone()
+            
+            logger.info(f"查询结果: {post}")
+            
+            if not post:
+                logger.warning(f"帖子不存在,post_id: {post_id}")
+                return jsonify({"error": "帖子不存在"}), 404
+            
+            # 设置默认值
+            post['tags'] = []
+            post['category'] = '未分类'
+            post['author'] = '匿名用户'
+            
+            # 格式化时间
+            if post['create_time']:
+                post['create_time'] = post['create_time'].strftime('%Y-%m-%d %H:%M:%S')
+            if post['last_active']:
+                post['last_active'] = post['last_active'].strftime('%Y-%m-%d %H:%M:%S')
+            
+            logger.info(f"返回帖子详情: {post}")
+            return Response(json.dumps(post, ensure_ascii=False), mimetype='application/json; charset=utf-8')
+    except Exception as e:
+        logger.error(f"获取帖子详情失败: {e}")
+        import traceback
+        traceback.print_exc()
+        return jsonify({"error": "服务器内部错误"}), 500
+    finally:
+        conn.close()
+
 # 搜索功能的API
 @app.route('/search', methods=['POST'])
 def search():