瀏覽代碼

♻️ refactor(home): simplify hot knowledge and talent recommendation logic

- 📝 修改getHotKnowledge方法:移除用户兴趣推荐逻辑,统一返回最新发布的3条银龄库数据
- 🔧 调整getHotKnowledge默认limit参数从4改为3
- 📝 修改getSilverTalents方法:移除用户画像匹配逻辑,仅返回最新3条已认证的人才数据
- 🔧 统一数据源筛选条件,确保数据一致性和查询效率
yourname 7 月之前
父節點
當前提交
a1b44704b3
共有 1 個文件被更改,包括 14 次插入87 次删除
  1. 14 87
      src/server/modules/home/home.service.ts

+ 14 - 87
src/server/modules/home/home.service.ts

@@ -172,59 +172,17 @@ export class HomeService {
   }
 
   /**
-   * 获取热门知识(基于用户兴趣和互动
+   * 获取热门知识(3条最新银龄库数据
    */
-  async getHotKnowledge(userId?: number, limit: number = 4): Promise<SilverKnowledge[]> {
-    if (!userId) {
-      // 未登录用户:返回浏览量最高的知识
-      return await this.knowledgeRepo
-        .createQueryBuilder('knowledge')
-        .leftJoinAndSelect('knowledge.category', 'category')
-        .where('knowledge.status = :status', { status: 1 })
-        .orderBy('knowledge.viewCount', 'DESC')
-        .limit(limit)
-        .getMany();
-    }
-
-    // 登录用户:基于用户兴趣推荐
-    const userInteractions = await this.knowledgeInteractionRepo.find({ 
-      where: { userId }, 
-      select: ['knowledgeId'] 
-    });
-    const viewedKnowledgeIds = userInteractions.map(i => i.knowledgeId);
-
-    // 获取用户浏览过的知识分类
-    const userCategories = await this.knowledgeRepo
+  async getHotKnowledge(userId?: number, limit: number = 3): Promise<SilverKnowledge[]> {
+    // 获取最新发布的银龄库数据,不筛选关键字
+    return await this.knowledgeRepo
       .createQueryBuilder('knowledge')
-      .select('knowledge.categoryId')
-      .distinct(true)
-      .where({ id: In(viewedKnowledgeIds) })
-      .getRawMany();
-    
-    const preferredCategories = userCategories.map((c: any) => c.categoryId);
-
-    // 构建查询条件
-    const whereConditions: any = {
-      status: 1
-    };
-
-    if (viewedKnowledgeIds.length > 0) {
-      whereConditions.id = Not(In(viewedKnowledgeIds));
-    }
-
-    if (preferredCategories.length > 0) {
-      whereConditions.categoryId = In(preferredCategories);
-    }
-
-    return await this.knowledgeRepo.find({
-      where: whereConditions,
-      relations: ['category'],
-      order: {
-        viewCount: 'DESC',
-        createdAt: 'DESC'
-      },
-      take: limit
-    });
+      .leftJoinAndSelect('knowledge.category', 'category')
+      .where('knowledge.status = :status', { status: 1 })
+      .orderBy('knowledge.createdAt', 'DESC')
+      .limit(limit)
+      .getMany();
   }
 
   /**
@@ -276,47 +234,16 @@ export class HomeService {
   }
 
   /**
-   * 获取银龄人才(基于用户画像推荐
+   * 获取银龄人才(显示最新3条已认证的人才
    */
   async getSilverTalents(userId?: number, limit: number = 3): Promise<SilverUserProfile[]> {
-    if (!userId) {
-      // 未登录用户:返回最新注册的人才
-      return await this.userProfileRepo
-        .createQueryBuilder('profile')
-        .leftJoinAndSelect('profile.user', 'user')
-        .where('profile.personalSkills IS NOT NULL')
-        .andWhere('profile.personalSkills != :empty', { empty: '' })
-        .orderBy('profile.createdAt', 'DESC')
-        .limit(limit)
-        .getMany();
-    }
-
-    // 登录用户:基于技能匹配推荐
-    const userProfile = await this.userProfileRepo.findOne({ where: { userId } });
-    const userSkills = userProfile?.personalSkills?.split(',').map(s => s.trim()).filter(s => s) || [];
-
-    const queryBuilder = this.userProfileRepo
+    // 统一数据源:只显示已认证的人才,按创建时间倒序
+    return await this.userProfileRepo
       .createQueryBuilder('profile')
       .leftJoinAndSelect('profile.user', 'user')
-      .where('profile.userId != :userId', { userId })
+      .where('profile.certificationStatus = :certificationStatus', { certificationStatus: 2 })
       .andWhere('profile.personalSkills IS NOT NULL')
-      .andWhere('profile.personalSkills != :empty', { empty: '' });
-
-    if (userSkills.length > 0) {
-      queryBuilder.andWhere(
-        new Brackets(qb => {
-          userSkills.forEach((skill, index) => {
-            if (index === 0) {
-              qb.where('profile.personalSkills LIKE :skill', { skill: `%${skill}%` });
-            } else {
-              qb.orWhere('profile.personalSkills LIKE :skill', { skill: `%${skill}%` });
-            }
-          });
-        })
-      );
-    }
-
-    return await queryBuilder
+      .andWhere('profile.personalSkills != :empty', { empty: '' })
       .orderBy('profile.createdAt', 'DESC')
       .limit(limit)
       .getMany();