master:返回给APP的数据增加collectProd字段;

pull/1121/head
liujiang 2025-10-08 20:44:54 +08:00
parent 39b818f698
commit da94145037
2 changed files with 14 additions and 0 deletions

View File

@ -43,6 +43,8 @@ public class APPSearchDTO {
private String prodTitle;
@ApiModelProperty(value = "是否有视频")
private Boolean hasVideo;
@ApiModelProperty(value = "是否已收藏商品")
private Boolean collectProd;
@ApiModelProperty(value = "标签")
private List<String> tags;

View File

@ -344,6 +344,18 @@ public class WebsiteAPPServiceImpl implements IWebsiteAPPService {
.filter(x -> CollectionUtils.isEmpty(advertProdIdList) || !advertProdIdList.contains(x.getStoreProdId()))
.collect(Collectors.toList());
}
// 增加用户是否已收藏商品
Long userId = SecurityUtils.getUserIdSafe();
if (ObjectUtils.isNotEmpty(userId)) {
List<String> storeProdIdList = realDataList.stream().map(APPSearchDTO::getStoreProdId).filter(StringUtils::isNotBlank).collect(Collectors.toList());
CollectionUtils.addAll(storeProdIdList, redisList.stream().map(APPSearchDTO::getStoreProdId).collect(Collectors.toList()));
List<UserFavorites> userFavList = this.userFavMapper.selectList(new LambdaQueryWrapper<UserFavorites>()
.eq(UserFavorites::getUserId, userId).in(UserFavorites::getStoreProdId, storeProdIdList));
Map<String, Long> userFavMap = CollectionUtils.isEmpty(userFavList) ? new HashMap<>()
: userFavList.stream().collect(Collectors.toMap(x -> x.getStoreProdId().toString(), UserFavorites::getId));
realDataList.forEach(x -> x.setCollectProd(userFavMap.containsKey(x.getStoreProdId())));
redisList.forEach(x -> x.setCollectProd(userFavMap.containsKey(x.getStoreProdId())));
}
// APP 只有第一页 有数据 其它页暂时没有广告
if (searchDTO.getPageNum() > 1) {
return new Page<>(page.getPageNum(), page.getPageSize(), page.getPages(), page.getTotal(), realDataList);