Compare commits

..

4 Commits

5 changed files with 24 additions and 23 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

BIN
src/main/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -85,9 +85,9 @@ public class ThemesController {
@GetMapping("/recommended")
@Operation(summary = "推荐主题列表", description = "按真实下载数量降序返回推荐主题")
public BaseResponse<List<KeyboardThemesRespVO>> getRecommendedThemes() {
public BaseResponse<List<KeyboardThemesRespVO>> getRecommendedThemes(@RequestParam(required = false) Long themeId) {
Long userId = StpUtil.getLoginIdAsLong();
List<KeyboardThemesRespVO> result = themesService.getRecommendedThemes(userId);
List<KeyboardThemesRespVO> result = themesService.getRecommendedThemes(userId, themeId);
return ResultUtils.success(result);
}

View File

@@ -34,7 +34,7 @@ public interface KeyboardThemesService extends IService<KeyboardThemes>{
* @param userId 用户ID
* @return 推荐主题列表
*/
List<KeyboardThemesRespVO> getRecommendedThemes(Long userId);
List<KeyboardThemesRespVO> getRecommendedThemes(Long userId,Long themeId);
/**
* 根据主题名称模糊搜索主题

View File

@@ -118,12 +118,27 @@ public class KeyboardThemesServiceImpl extends ServiceImpl<KeyboardThemesMapper,
@Override
/*
获取推荐主题列表
<p>推荐规则:根据真实下载量降序排序,排除用户已购买的主题最多返回8个主题</p>
<p>推荐规则:根据真实下载量降序排序,排除当前查看的主题最多返回8个主题</p>
@param userId 用户ID
* @return 推荐主题列表,包含主题详情和购买状态(推荐列表中的主题购买状态均为未购买)
@param themeId 当前主题ID需要从推荐列表中排除
* @return 推荐主题列表,包含主题详情和购买状态
*/
public List<KeyboardThemesRespVO> getRecommendedThemes(Long userId) {
public List<KeyboardThemesRespVO> getRecommendedThemes(Long userId, Long themeId) {
// 构建查询器
LambdaQueryChainWrapper<KeyboardThemes> queryWrapper = this.lambdaQuery()
.eq(KeyboardThemes::getDeleted, false)
.eq(KeyboardThemes::getThemeStatus, true)
.orderByDesc(KeyboardThemes::getRealDownloadCount);
// 排除传入的当前主题ID
if (themeId != null) {
queryWrapper.ne(KeyboardThemes::getId, themeId);
}
// 查询推荐主题列表限制8条
List<KeyboardThemes> themesList = queryWrapper.list();
// 查询用户已购买的主题ID集合
Set<Long> purchasedThemeIds = purchaseService.lambdaQuery()
.eq(KeyboardThemePurchase::getUserId, userId)
@@ -133,27 +148,13 @@ public class KeyboardThemesServiceImpl extends ServiceImpl<KeyboardThemesMapper,
.map(KeyboardThemePurchase::getThemeId)
.collect(Collectors.toSet());
// 构建查询器
LambdaQueryChainWrapper<KeyboardThemes> queryWrapper = this.lambdaQuery()
.eq(KeyboardThemes::getDeleted, false)
.eq(KeyboardThemes::getThemeStatus, true)
.orderByDesc(KeyboardThemes::getRealDownloadCount);
// 如果有已购买的主题,排除它们
if (!purchasedThemeIds.isEmpty()) {
queryWrapper.notIn(KeyboardThemes::getId, purchasedThemeIds);
}
// 查询推荐主题列表限制8条
List<KeyboardThemes> themesList = queryWrapper.list();
// 只取前8条数据
// 只取前8条数据并设置购买状态
return themesList.stream()
.limit(8)
.map(theme -> {
KeyboardThemesRespVO vo = BeanUtil.copyProperties(theme, KeyboardThemesRespVO.class);
// 推荐列表中的主题均为未购买状态
vo.setIsPurchased(false);
// 设置主题的实际购买状态
vo.setIsPurchased(purchasedThemeIds.contains(theme.getId()));
return vo;
}).collect(Collectors.toList());
}