feat(themes): 新增查询用户已购主题接口

在 KeyboardThemePurchaseService 及其实现中增加 getUserPurchasedThemes 方法,
通过用户ID获取已支付主题列表;同步新增 /themes/purchased 接口并放行鉴权。
补充 KeyboardThemesRespVO 缺失的 themePreviewImageUrl 字段。
This commit is contained in:
2025-12-10 20:19:47 +08:00
parent 1a6fb944b2
commit 03dc005b38
5 changed files with 66 additions and 0 deletions

View File

@@ -89,6 +89,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
"/themes/listByStyle",
"/wallet/balance",
"/themes/purchase",
"/themes/purchased",
"/themes/purchase/list"
};
}

View File

@@ -67,4 +67,12 @@ public class ThemesController {
return ResultUtils.success(result);
}
@GetMapping("/purchased")
@Operation(summary = "查询已购买的主题", description = "查询当前用户已购买的主题列表")
public BaseResponse<List<KeyboardThemesRespVO>> getPurchasedThemes() {
Long userId = StpUtil.getLoginIdAsLong();
List<KeyboardThemesRespVO> result = themePurchaseService.getUserPurchasedThemes(userId);
return ResultUtils.success(result);
}
}

View File

@@ -48,6 +48,8 @@ public class KeyboardThemesRespVO {
@Schema(description = "主题风格")
private Long themeStyle;
@Schema(description = "预览图")
private String themePreviewImageUrl;
/**
* 主题状态
*/

View File

@@ -4,6 +4,7 @@ import com.yolo.keyborad.model.entity.KeyboardThemePurchase;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yolo.keyborad.model.vo.purchase.ThemePurchaseListRespVO;
import com.yolo.keyborad.model.vo.purchase.ThemePurchaseRespVO;
import com.yolo.keyborad.model.vo.themes.KeyboardThemesRespVO;
import java.util.List;
@@ -23,4 +24,9 @@ public interface KeyboardThemePurchaseService extends IService<KeyboardThemePurc
* 查询用户购买记录
*/
List<ThemePurchaseListRespVO> getUserPurchaseList(Long userId);
/**
* 查询用户已购买的主题列表
*/
List<KeyboardThemesRespVO> getUserPurchasedThemes(Long userId);
}

View File

@@ -7,6 +7,7 @@ import com.yolo.keyborad.model.entity.KeyboardUserWallet;
import com.yolo.keyborad.model.entity.KeyboardWalletTransaction;
import com.yolo.keyborad.model.vo.purchase.ThemePurchaseListRespVO;
import com.yolo.keyborad.model.vo.purchase.ThemePurchaseRespVO;
import com.yolo.keyborad.model.vo.themes.KeyboardThemesRespVO;
import com.yolo.keyborad.service.KeyboardThemesService;
import com.yolo.keyborad.service.KeyboardUserWalletService;
import com.yolo.keyborad.service.KeyboardWalletTransactionService;
@@ -181,4 +182,52 @@ public class KeyboardThemePurchaseServiceImpl extends ServiceImpl<KeyboardThemeP
return vo;
}).collect(java.util.stream.Collectors.toList());
}
@Override
/**
* 获取用户已购买的主题列表
*
* @param userId 用户ID
* @return 用户已购买的主题详情列表
*/
public List<KeyboardThemesRespVO> getUserPurchasedThemes(Long userId) {
// 1. 查询用户所有已支付的主题ID列表
List<Long> themeIds = this.lambdaQuery()
.eq(KeyboardThemePurchase::getUserId, userId) // 根据用户ID筛选
.eq(KeyboardThemePurchase::getPayStatus, (short) 1) // 支付状态为1已支付
.list()
.stream()
.map(KeyboardThemePurchase::getThemeId) // 提取主题ID
.distinct() // 去重
.collect(java.util.stream.Collectors.toList());
// 2. 如果没有购买记录,返回空列表
if (themeIds.isEmpty()) {
return java.util.Collections.emptyList();
}
// 3. 根据主题ID列表查询主题详情并转换为响应VO对象
return themesService.lambdaQuery()
.in(KeyboardThemes::getId, themeIds) // 根据主题ID列表查询
.eq(KeyboardThemes::getDeleted, false) // 排除已删除的主题
.list()
.stream()
.map(theme -> {
// 创建响应VO对象并填充主题信息
KeyboardThemesRespVO vo = new KeyboardThemesRespVO();
vo.setId(theme.getId()); // 主题ID
vo.setThemePreviewImageUrl(theme.getThemePreviewImageUrl()); // 主题预览图片
vo.setThemeName(theme.getThemeName()); // 主题名称
vo.setThemePrice(theme.getThemePrice()); // 主题价格
vo.setThemeTag(theme.getThemeTag()); // 主题标签
vo.setThemeDownload(theme.getThemeDownload()); // 下载地址
vo.setThemeStyle(theme.getThemeStyle()); // 主题风格
vo.setThemeStatus(theme.getThemeStatus()); // 主题状态
vo.setThemePurchasesNumber(theme.getThemePurchasesNumber()); // 购买次数
vo.setSort(theme.getSort()); // 排序值
vo.setIsFree(theme.getIsFree()); // 是否免费
return vo;
}).collect(java.util.stream.Collectors.toList());
}
}