mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-31 17:40:05 +08:00
调整商品收藏的命名
This commit is contained in:
parent
4b643a7b34
commit
8ed52701fd
@ -1,8 +1,8 @@
|
||||
package cn.iocoder.yudao.module.product.controller.app.favorite;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO;
|
||||
@ -17,11 +17,11 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@Tag(name = "用户 APP - 商品收藏")
|
||||
@ -51,17 +51,19 @@ public class AppFavoriteController {
|
||||
@GetMapping(value = "/page")
|
||||
@Operation(summary = "分页获取商品收藏列表")
|
||||
public CommonResult<PageResult<AppFavoriteRespVO>> getFavoritePage(AppFavoritePageReqVO reqVO) {
|
||||
PageResult<ProductFavoriteDO> favorites = productFavoriteService.getFavoritePage(getLoginUserId(), reqVO);
|
||||
if (favorites.getTotal() <= 0) {
|
||||
PageResult<ProductFavoriteDO> favoritePage = productFavoriteService.getFavoritePage(getLoginUserId(), reqVO);
|
||||
if (CollUtil.isEmpty(favoritePage.getList())) {
|
||||
return success(PageResult.empty());
|
||||
}
|
||||
List<ProductFavoriteDO> productFavoriteList = favorites.getList();
|
||||
|
||||
// 得到商品 spu 信息
|
||||
List<Long> spuIds = CollectionUtils.convertList(productFavoriteList, ProductFavoriteDO::getSpuId);
|
||||
List<ProductSpuDO> spuList = productSpuService.getSpuList(spuIds);
|
||||
//转换 VO
|
||||
PageResult<AppFavoriteRespVO> pageResult = new PageResult<>(favorites.getTotal());
|
||||
pageResult.setList(ProductFavoriteConvert.INSTANCE.convertList(productFavoriteList, spuList));
|
||||
List<ProductFavoriteDO> favorites = favoritePage.getList();
|
||||
List<Long> spuIds = convertList(favorites, ProductFavoriteDO::getSpuId);
|
||||
List<ProductSpuDO> spus = productSpuService.getSpuList(spuIds);
|
||||
|
||||
// 转换 VO 结果
|
||||
PageResult<AppFavoriteRespVO> pageResult = new PageResult<>(favoritePage.getTotal());
|
||||
pageResult.setList(ProductFavoriteConvert.INSTANCE.convertList(favorites, spus));
|
||||
return success(pageResult);
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull;
|
||||
|
||||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
|
||||
|
||||
@Schema(description = "用户 APP - 商品收藏 Request VO") // 用于收藏、取消收藏, 获取收藏
|
||||
@Schema(description = "用户 APP - 商品收藏 Request VO") // 用于收藏、取消收藏、获取收藏
|
||||
@Data
|
||||
public class AppFavoriteReqVO {
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.product.convert.favorite;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO;
|
||||
@ -13,6 +12,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
|
||||
@Mapper
|
||||
public interface ProductFavoriteConvert {
|
||||
|
||||
@ -20,17 +21,18 @@ public interface ProductFavoriteConvert {
|
||||
|
||||
ProductFavoriteDO convert(Long userId, AppFavoriteReqVO reqVO);
|
||||
|
||||
@Mapping(target = "id", source = "favoriteDO.id")
|
||||
@Mapping(target = "spuName", source = "spuDO.name")
|
||||
AppFavoriteRespVO convert(ProductSpuDO spuDO, ProductFavoriteDO favoriteDO);
|
||||
@Mapping(target = "id", source = "favorite.id")
|
||||
@Mapping(target = "spuName", source = "spu.name")
|
||||
AppFavoriteRespVO convert(ProductSpuDO spu, ProductFavoriteDO favorite);
|
||||
|
||||
default List<AppFavoriteRespVO> convertList(List<ProductFavoriteDO> productFavoriteDOList, List<ProductSpuDO> productSpuDOList) {
|
||||
List<AppFavoriteRespVO> resultList = new ArrayList<>(productFavoriteDOList.size());
|
||||
Map<Long, ProductSpuDO> spuMap = CollectionUtils.convertMap(productSpuDOList, ProductSpuDO::getId);
|
||||
for (ProductFavoriteDO item : productFavoriteDOList) {
|
||||
ProductSpuDO spuDO = spuMap.get(item.getSpuId());
|
||||
resultList.add(convert(spuDO, item));
|
||||
default List<AppFavoriteRespVO> convertList(List<ProductFavoriteDO> favorites, List<ProductSpuDO> spus) {
|
||||
List<AppFavoriteRespVO> resultList = new ArrayList<>(favorites.size());
|
||||
Map<Long, ProductSpuDO> spuMap = convertMap(spus, ProductSpuDO::getId);
|
||||
for (ProductFavoriteDO favorite : favorites) {
|
||||
ProductSpuDO spuDO = spuMap.get(favorite.getSpuId());
|
||||
resultList.add(convert(spuDO, favorite));
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.product.dal.mysql.favorite;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
@ -13,9 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
public interface ProductFavoriteMapper extends BaseMapperX<ProductFavoriteDO> {
|
||||
|
||||
default ProductFavoriteDO selectByUserAndSpuAndType(Long userId, Long spuId, Integer type) {
|
||||
Assert.notNull(userId, "the userId must not be null");
|
||||
Assert.notNull(spuId, "the spuId must not be null");
|
||||
Assert.notNull(type, "the type must not be null");
|
||||
return selectOne(new LambdaQueryWrapperX<ProductFavoriteDO>()
|
||||
.eq(ProductFavoriteDO::getUserId, userId)
|
||||
.eq(ProductFavoriteDO::getSpuId, spuId)
|
||||
@ -23,9 +19,6 @@ public interface ProductFavoriteMapper extends BaseMapperX<ProductFavoriteDO> {
|
||||
}
|
||||
|
||||
default PageResult<ProductFavoriteDO> selectPageByUserAndType(Long userId, Integer type, PageParam pageParam) {
|
||||
Assert.notNull(userId, "the userId must not be null");
|
||||
Assert.notNull(type, "the type must not be null");
|
||||
Assert.notNull(pageParam, "the pageParam must not be null");
|
||||
return selectPage(pageParam, new LambdaQueryWrapper<ProductFavoriteDO>()
|
||||
.eq(ProductFavoriteDO::getUserId, userId)
|
||||
.eq(ProductFavoriteDO::getType, type)
|
||||
|
@ -1,24 +1,16 @@
|
||||
package cn.iocoder.yudao.module.product.service.favorite;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteReqVO;
|
||||
import cn.iocoder.yudao.module.product.convert.favorite.ProductFavoriteConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||
import cn.iocoder.yudao.module.product.dal.mysql.favorite.ProductFavoriteMapper;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO;
|
||||
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
@ -39,10 +31,12 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService {
|
||||
|
||||
@Override
|
||||
public Long createFavorite(Long userId, @Valid AppFavoriteReqVO reqVO) {
|
||||
ProductFavoriteDO favoriteDO = productFavoriteMapper.selectByUserAndSpuAndType(userId, reqVO.getSpuId(), reqVO.getType());
|
||||
if (Objects.nonNull(favoriteDO)) {
|
||||
ProductFavoriteDO favorite = productFavoriteMapper.selectByUserAndSpuAndType(
|
||||
userId, reqVO.getSpuId(), reqVO.getType());
|
||||
if (Objects.nonNull(favorite)) {
|
||||
throw exception(FAVORITE_EXISTS);
|
||||
}
|
||||
|
||||
ProductFavoriteDO entity = ProductFavoriteConvert.INSTANCE.convert(userId, reqVO);
|
||||
productFavoriteMapper.insert(entity);
|
||||
return entity.getId();
|
||||
@ -50,16 +44,18 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService {
|
||||
|
||||
@Override
|
||||
public void deleteFavorite(Long userId, @Valid AppFavoriteReqVO reqVO) {
|
||||
ProductFavoriteDO favoriteDO = productFavoriteMapper.selectByUserAndSpuAndType(userId, reqVO.getSpuId(), reqVO.getType());
|
||||
if (Objects.isNull(favoriteDO)) {
|
||||
ProductFavoriteDO favorite = productFavoriteMapper.selectByUserAndSpuAndType(
|
||||
userId, reqVO.getSpuId(), reqVO.getType());
|
||||
if (Objects.isNull(favorite)) {
|
||||
throw exception(FAVORITE_NOT_EXISTS);
|
||||
}
|
||||
productFavoriteMapper.deleteById(favoriteDO.getId());
|
||||
|
||||
productFavoriteMapper.deleteById(favorite.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ProductFavoriteDO> getFavoritePage(Long userId, @Valid AppFavoritePageReqVO reqVO) {
|
||||
return productFavoriteMapper.selectPageByUserAndType(userId, reqVO.getType(), reqVO);
|
||||
return productFavoriteMapper.selectPageByUserAndType(userId, reqVO.getType(), reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user