Jelajahi Sumber

feat: 添加模板评分字段,移除mock数据

1. 数据库迁移:添加 rating 字段 (DECIMAL 2,1)
2. Template 实体:添加 rating 属性
3. TemplateListResponse DTO:添加 rating 字段并映射
4. 前端 Home.vue:
   - useCount 和 rating 使用后端真实数据
   - 热门标签:使用次数>=100 才显示
   - 推荐模板按使用次数排序
何文松 4 minggu lalu
induk
melakukan
e42229d993

+ 4 - 0
backend/extract-service/src/main/java/com/lingyue/extract/dto/response/TemplateListResponse.java

@@ -34,6 +34,9 @@ public class TemplateListResponse {
     @Schema(description = "使用次数")
     private Integer useCount;
     
+    @Schema(description = "模板评分 (0.0-5.0)")
+    private Double rating;
+    
     @Schema(description = "来源文件数量")
     private Integer sourceFileCount;
     
@@ -57,6 +60,7 @@ public class TemplateListResponse {
         response.setStatus(template.getStatus());
         response.setIsPublic(template.getIsPublic());
         response.setUseCount(template.getUseCount());
+        response.setRating(template.getRating());
         response.setCreateTime(template.getCreateTime());
         response.setUpdateTime(template.getUpdateTime());
         return response;

+ 4 - 0
backend/extract-service/src/main/java/com/lingyue/extract/entity/Template.java

@@ -57,6 +57,10 @@ public class Template extends SimpleModel {
     @TableField("use_count")
     private Integer useCount;
     
+    @Schema(description = "模板评分 (0.0-5.0)")
+    @TableField("rating")
+    private Double rating;
+    
     // ==================== 状态常量 ====================
     
     public static final String STATUS_DRAFT = "draft";

+ 7 - 0
database/migrations/V2026_01_29_01__add_template_rating.sql

@@ -0,0 +1,7 @@
+-- 添加模板评分字段
+ALTER TABLE templates ADD COLUMN IF NOT EXISTS rating DECIMAL(2,1) DEFAULT 0.0;
+
+COMMENT ON COLUMN templates.rating IS '模板评分 (0.0-5.0)';
+
+-- 为现有模板设置默认评分
+UPDATE templates SET rating = 4.5 WHERE rating IS NULL OR rating = 0;

+ 6 - 5
frontend/vue-demo/src/views/Home.vue

@@ -275,14 +275,15 @@ onMounted(async () => {
     
     // 获取模板列表
     await templateStore.fetchTemplates()
-    // 取前3个模板作为推荐
-    recommendTemplates.value = templateStore.templates.slice(0, 3).map((t, i) => ({
+    // 取前3个模板作为推荐(按使用次数排序)
+    const sortedTemplates = [...templateStore.templates].sort((a, b) => (b.useCount || 0) - (a.useCount || 0))
+    recommendTemplates.value = sortedTemplates.slice(0, 3).map((t, i) => ({
       ...t,
       icon: templateIcons[i % templateIcons.length],
-      useCount: t.useCount || Math.floor(Math.random() * 200),
-      rating: 4.5 + Math.random() * 0.5,
+      useCount: t.useCount || 0,
+      rating: t.rating || 0,
       isOfficial: t.isPublic,
-      isHot: i < 2
+      isHot: (t.useCount || 0) >= 100 // 使用次数>=100标记为热门
     }))
   } catch (error) {
     console.error('获取数据失败:', error)