Compare commits
4 Commits
d07478eaea
...
e90078791c
| Author | SHA1 | Date | |
|---|---|---|---|
| e90078791c | |||
| 1b7374e959 | |||
| 2b0fa71c40 | |||
| 619c59d786 |
BIN
src/main/.DS_Store
vendored
Normal file
BIN
src/main/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -85,9 +85,9 @@ public class ThemesController {
|
|||||||
|
|
||||||
@GetMapping("/recommended")
|
@GetMapping("/recommended")
|
||||||
@Operation(summary = "推荐主题列表", description = "按真实下载数量降序返回推荐主题")
|
@Operation(summary = "推荐主题列表", description = "按真实下载数量降序返回推荐主题")
|
||||||
public BaseResponse<List<KeyboardThemesRespVO>> getRecommendedThemes() {
|
public BaseResponse<List<KeyboardThemesRespVO>> getRecommendedThemes(@RequestParam(required = false) Long themeId) {
|
||||||
Long userId = StpUtil.getLoginIdAsLong();
|
Long userId = StpUtil.getLoginIdAsLong();
|
||||||
List<KeyboardThemesRespVO> result = themesService.getRecommendedThemes(userId);
|
List<KeyboardThemesRespVO> result = themesService.getRecommendedThemes(userId, themeId);
|
||||||
return ResultUtils.success(result);
|
return ResultUtils.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public interface KeyboardThemesService extends IService<KeyboardThemes>{
|
|||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 推荐主题列表
|
* @return 推荐主题列表
|
||||||
*/
|
*/
|
||||||
List<KeyboardThemesRespVO> getRecommendedThemes(Long userId);
|
List<KeyboardThemesRespVO> getRecommendedThemes(Long userId,Long themeId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据主题名称模糊搜索主题
|
* 根据主题名称模糊搜索主题
|
||||||
|
|||||||
@@ -118,12 +118,27 @@ public class KeyboardThemesServiceImpl extends ServiceImpl<KeyboardThemesMapper,
|
|||||||
@Override
|
@Override
|
||||||
/*
|
/*
|
||||||
获取推荐主题列表
|
获取推荐主题列表
|
||||||
<p>推荐规则:根据真实下载量降序排序,排除用户已购买的主题,最多返回8个主题</p>
|
<p>推荐规则:根据真实下载量降序排序,排除当前查看的主题,最多返回8个主题</p>
|
||||||
|
|
||||||
@param userId 用户ID
|
@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集合
|
// 查询用户已购买的主题ID集合
|
||||||
Set<Long> purchasedThemeIds = purchaseService.lambdaQuery()
|
Set<Long> purchasedThemeIds = purchaseService.lambdaQuery()
|
||||||
.eq(KeyboardThemePurchase::getUserId, userId)
|
.eq(KeyboardThemePurchase::getUserId, userId)
|
||||||
@@ -133,27 +148,13 @@ public class KeyboardThemesServiceImpl extends ServiceImpl<KeyboardThemesMapper,
|
|||||||
.map(KeyboardThemePurchase::getThemeId)
|
.map(KeyboardThemePurchase::getThemeId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
// 构建查询器
|
// 只取前8条数据并设置购买状态
|
||||||
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条数据
|
|
||||||
return themesList.stream()
|
return themesList.stream()
|
||||||
.limit(8)
|
.limit(8)
|
||||||
.map(theme -> {
|
.map(theme -> {
|
||||||
KeyboardThemesRespVO vo = BeanUtil.copyProperties(theme, KeyboardThemesRespVO.class);
|
KeyboardThemesRespVO vo = BeanUtil.copyProperties(theme, KeyboardThemesRespVO.class);
|
||||||
// 推荐列表中的主题均为未购买状态
|
// 设置主题的实际购买状态
|
||||||
vo.setIsPurchased(false);
|
vo.setIsPurchased(purchasedThemeIds.contains(theme.getId()));
|
||||||
return vo;
|
return vo;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user