fix(service): 修正推荐主题查询逻辑避免重复数据
优化 getRecommendedThemes 方法,使用 limit(8) 替代 SQL 的 LIMIT 8,防止分页插件干扰,确保只返回 8 条未购买的热门主题。
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.yolo.keyborad.service.impl;
|
package com.yolo.keyborad.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||||
import com.yolo.keyborad.model.entity.KeyboardThemePurchase;
|
import com.yolo.keyborad.model.entity.KeyboardThemePurchase;
|
||||||
import com.yolo.keyborad.service.KeyboardThemePurchaseService;
|
import com.yolo.keyborad.service.KeyboardThemePurchaseService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
@@ -132,15 +133,23 @@ public class KeyboardThemesServiceImpl extends ServiceImpl<KeyboardThemesMapper,
|
|||||||
.map(KeyboardThemePurchase::getThemeId)
|
.map(KeyboardThemePurchase::getThemeId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
// 查询推荐主题列表:未删除、已启用、未购买、按真实下载量降序、限制8条
|
// 构建查询器
|
||||||
return this.lambdaQuery()
|
LambdaQueryChainWrapper<KeyboardThemes> queryWrapper = this.lambdaQuery()
|
||||||
.eq(KeyboardThemes::getDeleted, false)
|
.eq(KeyboardThemes::getDeleted, false)
|
||||||
.eq(KeyboardThemes::getThemeStatus, true)
|
.eq(KeyboardThemes::getThemeStatus, true)
|
||||||
.notIn(!purchasedThemeIds.isEmpty(), KeyboardThemes::getId, purchasedThemeIds)
|
.orderByDesc(KeyboardThemes::getRealDownloadCount);
|
||||||
.orderByDesc(KeyboardThemes::getRealDownloadCount)
|
|
||||||
.last("LIMIT 8")
|
// 如果有已购买的主题,排除它们
|
||||||
.list()
|
if (!purchasedThemeIds.isEmpty()) {
|
||||||
.stream()
|
queryWrapper.notIn(KeyboardThemes::getId, purchasedThemeIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询推荐主题列表,限制8条
|
||||||
|
List<KeyboardThemes> themesList = queryWrapper.list();
|
||||||
|
|
||||||
|
// 只取前8条数据
|
||||||
|
return themesList.stream()
|
||||||
|
.limit(8)
|
||||||
.map(theme -> {
|
.map(theme -> {
|
||||||
KeyboardThemesRespVO vo = BeanUtil.copyProperties(theme, KeyboardThemesRespVO.class);
|
KeyboardThemesRespVO vo = BeanUtil.copyProperties(theme, KeyboardThemesRespVO.class);
|
||||||
// 推荐列表中的主题均为未购买状态
|
// 推荐列表中的主题均为未购买状态
|
||||||
|
|||||||
Reference in New Issue
Block a user