feat(themes): 新增主题模糊搜索接口及鉴权放行

支持按名称模糊搜索主题,并标记用户已购状态;同步放开 /themes/search 无需登录访问
This commit is contained in:
2025-12-17 16:57:39 +08:00
parent 4666180b73
commit 198650556f
4 changed files with 43 additions and 0 deletions

View File

@@ -92,6 +92,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
"/themes/purchase/list",
"/themes/detail",
"/themes/recommended",
"/themes/search",
"/user-themes/batch-delete",
"/products/listByType",
"/products/detail",

View File

@@ -91,4 +91,12 @@ public class ThemesController {
return ResultUtils.success(result);
}
@GetMapping("/search")
@Operation(summary = "搜索主题", description = "根据主题名称模糊搜索主题")
public BaseResponse<List<KeyboardThemesRespVO>> searchThemes(@RequestParam String themeName) {
Long userId = StpUtil.getLoginIdAsLong();
List<KeyboardThemesRespVO> result = themesService.searchThemesByName(themeName, userId);
return ResultUtils.success(result);
}
}

View File

@@ -36,4 +36,12 @@ public interface KeyboardThemesService extends IService<KeyboardThemes>{
*/
List<KeyboardThemesRespVO> getRecommendedThemes(Long userId);
/**
* 根据主题名称模糊搜索主题
* @param themeName 主题名称关键字
* @param userId 用户ID
* @return 主题列表
*/
List<KeyboardThemesRespVO> searchThemesByName(String themeName, Long userId);
}

View File

@@ -157,4 +157,30 @@ public class KeyboardThemesServiceImpl extends ServiceImpl<KeyboardThemesMapper,
return vo;
}).collect(Collectors.toList());
}
@Override
public List<KeyboardThemesRespVO> searchThemesByName(String themeName, Long userId) {
// 根据主题名称模糊搜索
List<KeyboardThemes> themesList = this.lambdaQuery()
.eq(KeyboardThemes::getDeleted, false)
.eq(KeyboardThemes::getThemeStatus, true)
.like(KeyboardThemes::getThemeName, themeName)
.list();
// 查询用户已购买的主题ID集合
Set<Long> purchasedThemeIds = purchaseService.lambdaQuery()
.eq(KeyboardThemePurchase::getUserId, userId)
.eq(KeyboardThemePurchase::getPayStatus, (short) 1)
.list()
.stream()
.map(KeyboardThemePurchase::getThemeId)
.collect(Collectors.toSet());
// 转换为VO并设置购买状态
return themesList.stream().map(theme -> {
KeyboardThemesRespVO vo = BeanUtil.copyProperties(theme, KeyboardThemesRespVO.class);
vo.setIsPurchased(purchasedThemeIds.contains(theme.getId()));
return vo;
}).collect(Collectors.toList());
}
}