feat(themes): 为主题列表接口增加用户购买状态标记
在 KeyboardThemesRespVO 中新增 isPurchased 字段; selectThemesByStyle 方法增加 userId 参数并查询用户已购主题 ID, 返回结果标记当前用户是否已购买。
This commit is contained in:
@@ -42,8 +42,8 @@ public class ThemesController {
|
||||
@GetMapping("/listByStyle")
|
||||
@Operation(summary = "按风格查询主题", description = "按主题风格查询主题列表接口")
|
||||
public BaseResponse<List<KeyboardThemesRespVO>> listByStyle(@RequestParam("themeStyle") Long themeStyleId) {
|
||||
return ResultUtils.success(themesService.selectThemesByStyle(themeStyleId));
|
||||
}
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
return ResultUtils.success(themesService.selectThemesByStyle(themeStyleId,userId));}
|
||||
|
||||
@GetMapping("/listAllStyles")
|
||||
@Operation(summary = "查询所有主题风格", description = "查询所有主题风格列表接口")
|
||||
|
||||
@@ -67,4 +67,7 @@ public class KeyboardThemesRespVO {
|
||||
|
||||
@Schema(description = "是否免费")
|
||||
private Boolean isFree;
|
||||
|
||||
@Schema(description = "当前用户是否已购买")
|
||||
private Boolean isPurchased;
|
||||
}
|
||||
|
||||
@@ -12,11 +12,13 @@ import java.util.List;
|
||||
|
||||
public interface KeyboardThemesService extends IService<KeyboardThemes>{
|
||||
|
||||
|
||||
/**
|
||||
* 按主题风格查询主题列表(未删除且上架)
|
||||
* 按主题风格查询主题列表(未删除且上架),包含用户购买状态
|
||||
* @param themeStyle 主题风格
|
||||
* @param userId 用户ID
|
||||
* @return 主题列表
|
||||
*/
|
||||
List<KeyboardThemesRespVO> selectThemesByStyle(Long themeStyle);
|
||||
List<KeyboardThemesRespVO> selectThemesByStyle(Long themeStyle, Long userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package com.yolo.keyborad.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.yolo.keyborad.model.entity.KeyboardThemePurchase;
|
||||
import com.yolo.keyborad.service.KeyboardThemePurchaseService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yolo.keyborad.mapper.KeyboardThemesMapper;
|
||||
import com.yolo.keyborad.model.entity.KeyboardThemes;
|
||||
@@ -17,21 +23,39 @@ import com.yolo.keyborad.service.KeyboardThemesService;
|
||||
@Service
|
||||
public class KeyboardThemesServiceImpl extends ServiceImpl<KeyboardThemesMapper, KeyboardThemes> implements KeyboardThemesService {
|
||||
|
||||
@Resource
|
||||
@Lazy // 延迟加载,打破循环依赖
|
||||
private KeyboardThemePurchaseService purchaseService;
|
||||
|
||||
@Override
|
||||
public List<KeyboardThemesRespVO> selectThemesByStyle(Long themeStyle) {
|
||||
public List<KeyboardThemesRespVO> selectThemesByStyle(Long themeStyle, Long userId) {
|
||||
List<KeyboardThemes> themesList;
|
||||
if (themeStyle == 9999) {
|
||||
List<KeyboardThemes> themesList = this.lambdaQuery()
|
||||
themesList = this.lambdaQuery()
|
||||
.eq(KeyboardThemes::getDeleted, false)
|
||||
.eq(KeyboardThemes::getThemeStatus, true)
|
||||
.orderByAsc(KeyboardThemes::getSort)
|
||||
.list();
|
||||
} else {
|
||||
themesList = this.lambdaQuery()
|
||||
.eq(KeyboardThemes::getDeleted, false)
|
||||
.eq(KeyboardThemes::getThemeStatus, true)
|
||||
.eq(KeyboardThemes::getThemeStyle, themeStyle)
|
||||
.list();
|
||||
return BeanUtil.copyToList(themesList, KeyboardThemesRespVO.class);
|
||||
}
|
||||
List<KeyboardThemes> themesList = this.lambdaQuery()
|
||||
.eq(KeyboardThemes::getDeleted, false)
|
||||
.eq(KeyboardThemes::getThemeStatus, true)
|
||||
.eq(KeyboardThemes::getThemeStyle, themeStyle)
|
||||
.list();
|
||||
return BeanUtil.copyToList(themesList, KeyboardThemesRespVO.class);
|
||||
|
||||
Set<Long> purchasedThemeIds = purchaseService.lambdaQuery()
|
||||
.eq(KeyboardThemePurchase::getUserId, userId)
|
||||
.eq(KeyboardThemePurchase::getPayStatus, (short) 1)
|
||||
.list()
|
||||
.stream()
|
||||
.map(KeyboardThemePurchase::getThemeId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
return themesList.stream().map(theme -> {
|
||||
KeyboardThemesRespVO vo = BeanUtil.copyProperties(theme, KeyboardThemesRespVO.class);
|
||||
vo.setIsPurchased(purchasedThemeIds.contains(theme.getId()));
|
||||
return vo;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user