瀏覽代碼

feat(recommend): 优化推荐算法过滤逻辑

- 移除用户在线状态显示功能
- 注释掉不感兴趣按钮及其相关处理逻辑
- 从用户数据中移除在线状态字段
- 在推荐服务中增加已喜欢用户过滤机制
- 避免已喜欢用户重复出现在推荐列表中
- 更新排除列表逻辑以包含不喜欢和已喜欢用户
李思佳 21 小時之前
父節點
當前提交
0c5aa04782

+ 33 - 38
LiangZhiYUMao/pages/today-recommend/index.vue

@@ -27,10 +27,6 @@
 								<text class="user-detail" v-if="user.location && user.location !== '未填写'">{{ user.location }}</text>
 							</view>
 						</view>
-						<view class="online-status" :class="{ online: user.isOnline }">
-							<text class="status-dot"></text>
-							<text class="status-text">{{ user.isOnline ? '在线' : '离线' }}</text>
-						</view>
 					</view>
 
 					<view class="card-content">
@@ -64,10 +60,10 @@
 					</view>
 
 					<view class="card-actions">
-						<view class="action-btn pass-btn" @click="handlePass(user, index)">
-							<text class="action-icon">👎</text>
-							<text class="action-text">不感兴趣</text>
-						</view>
+<!--						<view class="action-btn pass-btn" @click="handlePass(user, index)">-->
+<!--							<text class="action-icon">👎</text>-->
+<!--							<text class="action-text">不感兴趣</text>-->
+<!--						</view>-->
 						<view class="action-btn like-btn" @click="handleLike(user, index)">
 							<text class="action-icon">❤️</text>
 							<text class="action-text">喜欢</text>
@@ -200,8 +196,7 @@
 					hobbies: this.parseHobbies(u.hobby),
 					introduction: u.introduction || u.selfIntro || '',
 					isVip: u.isVip || false,
-					isOnline: u.isOnline || false,
-					compatibilityScore: u.compatibilityScore || 0
+          compatibilityScore: u.compatibilityScore || 0
 				}
 			},
 
@@ -272,34 +267,34 @@
 			},
 
 			// 处理不感兴趣
-			async handlePass(user, index) {
-				uni.showModal({
-					title: '确认操作',
-					content: `确定对${user.nickname}不感兴趣吗?`,
-					success: async (res) => {
-						if (res.confirm) {
-							try {
-								await api.recommend.feedback({
-									userId: this.currentUserId,
-									targetUserId: user.userId || user.id,
-									type: 'dislike'
-								})
-								uni.showToast({
-									title: '已记录您的偏好',
-									icon: 'success'
-								})
-								this.recommendUsers.splice(index, 1)
-							} catch (e) {
-								console.error('失败:', e)
-								uni.showToast({
-									title: '操作失败,请重试',
-									icon: 'none'
-								})
-							}
-						}
-					}
-				})
-			},
+			// async handlePass(user, index) {
+			// 	uni.showModal({
+			// 		title: '确认操作',
+			// 		content: `确定对${user.nickname}不感兴趣吗?`,
+			// 		success: async (res) => {
+			// 			if (res.confirm) {
+			// 				try {
+			// 					await api.recommend.feedback({
+			// 						userId: this.currentUserId,
+			// 						targetUserId: user.userId || user.id,
+			// 						type: 'dislike'
+			// 					})
+			// 					uni.showToast({
+			// 						title: '已记录您的偏好',
+			// 						icon: 'success'
+			// 					})
+			// 					this.recommendUsers.splice(index, 1)
+			// 				} catch (e) {
+			// 					console.error('失败:', e)
+			// 					uni.showToast({
+			// 						title: '操作失败,请重试',
+			// 						icon: 'none'
+			// 					})
+			// 				}
+			// 			}
+			// 		}
+			// 	})
+			// },
 
 			// 处理喜欢
 			async handleLike(user, index) {

+ 14 - 2
service/Recommend/src/main/java/com/zhentao/service/impl/RecommendServiceImpl.java

@@ -123,12 +123,18 @@ public class RecommendServiceImpl implements RecommendService {
             } catch (Exception ignore) {}
         }
 
-        // 过滤用户的"不喜欢"集合,避免再次出现
+        // 过滤用户的"不喜欢"集合和"已喜欢"集合,避免再次出现
         try {
+            // 过滤不喜欢的用户
             java.util.Set<String> disliked = stringRedisTemplate.opsForSet().members("rec:dislike:user:" + userId);
             if (disliked != null && !disliked.isEmpty()) {
                 pool.removeIf(u -> u.getUserId() != null && disliked.contains(String.valueOf(u.getUserId())));
             }
+            // 过滤已喜欢的用户
+            java.util.Set<String> liked = stringRedisTemplate.opsForSet().members("rec:like:user:" + userId);
+            if (liked != null && !liked.isEmpty()) {
+                pool.removeIf(u -> u.getUserId() != null && liked.contains(String.valueOf(u.getUserId())));
+            }
         } catch (Exception ignore) {}
         
         // 再次过滤:确保不包含当前用户本身和未完善性别信息的用户,以及同性用户
@@ -275,13 +281,19 @@ public class RecommendServiceImpl implements RecommendService {
             try { hobbyJson = objectMapper.writeValueAsString(q.getHobbyTags()); } catch (Exception ignore) {}
         }
 
-        // 读取不喜欢集合,作为排除列表
+        // 读取不喜欢集合和已喜欢集合,作为排除列表
         java.util.List<Integer> excludeIds = new java.util.ArrayList<>();
         try {
+            // 添加不喜欢的用户到排除列表
             java.util.Set<String> disliked = stringRedisTemplate.opsForSet().members("rec:dislike:user:" + q.getUserId());
             if (disliked != null) {
                 for (String s : disliked) { try { excludeIds.add(Integer.parseInt(s)); } catch (Exception ignore) {} }
             }
+            // 添加已喜欢的用户到排除列表
+            java.util.Set<String> liked = stringRedisTemplate.opsForSet().members("rec:like:user:" + q.getUserId());
+            if (liked != null) {
+                for (String s : liked) { try { excludeIds.add(Integer.parseInt(s)); } catch (Exception ignore) {} }
+            }
         } catch (Exception ignore) {}
 
         // 获取当前用户的性别信息