|
@@ -4,16 +4,15 @@ 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.security.core.annotations.PreAuthenticated;
|
|
|
-import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavoriteBatchReqVO;
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavoritePageReqVO;
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavoriteReqVO;
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavoriteRespVO;
|
|
|
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.favorite.ProductFavoriteDetailDO;
|
|
|
+import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
|
|
import cn.iocoder.yudao.module.product.service.favorite.ProductFavoriteService;
|
|
|
+import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
-import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -24,6 +23,7 @@ import javax.validation.Valid;
|
|
|
import java.util.List;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
|
|
|
|
@Tag(name = "管理后台 - 商品收藏")
|
|
|
@RestController
|
|
@@ -34,6 +34,9 @@ public class ProductFavoriteController {
|
|
|
@Resource
|
|
|
private ProductFavoriteService productFavoriteService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ProductSpuService productSpuService;
|
|
|
+
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "添加单个商品收藏")
|
|
|
@PreAuthorize("@ss.hasPermission('product:favorite:create')")
|
|
@@ -41,14 +44,6 @@ public class ProductFavoriteController {
|
|
|
return success(productFavoriteService.createFavorite(reqVO.getUserId(), reqVO.getSpuId()));
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/create-list")
|
|
|
- @Operation(summary = "添加多个商品收藏")
|
|
|
- @PreAuthorize("@ss.hasPermission('product:favorite:create')")
|
|
|
- public CommonResult<Boolean> createFavoriteList(@Valid @RequestBody ProductFavoriteBatchReqVO reqVO) {
|
|
|
- // todo @jason:待实现;如果有已经收藏的,不用报错,忽略即可;
|
|
|
- return success(Boolean.TRUE);
|
|
|
- }
|
|
|
-
|
|
|
@DeleteMapping("/delete")
|
|
|
@Operation(summary = "取消单个商品收藏")
|
|
|
@PreAuthorize("@ss.hasPermission('product:favorite:delete')")
|
|
@@ -57,26 +52,19 @@ public class ProductFavoriteController {
|
|
|
return success(Boolean.TRUE);
|
|
|
}
|
|
|
|
|
|
- @DeleteMapping("/delete-list")
|
|
|
- @Operation(summary = "取消单个商品收藏")
|
|
|
- @PreAuthorize("@ss.hasPermission('product:favorite:delete')")
|
|
|
- public CommonResult<Boolean> deleteFavoriteList(@Valid @RequestBody ProductFavoriteBatchReqVO reqVO) {
|
|
|
- // todo @jason:待实现
|
|
|
-// productFavoriteService.deleteFavorite(getLoginUserId(), reqVO.getSpuId());
|
|
|
- return success(Boolean.TRUE);
|
|
|
- }
|
|
|
-
|
|
|
@GetMapping("/page")
|
|
|
@Operation(summary = "获得商品收藏分页")
|
|
|
@PreAuthorize("@ss.hasPermission('product:favorite:query')")
|
|
|
public CommonResult<PageResult<ProductFavoriteRespVO>> getFavoritePage(@Valid ProductFavoritePageReqVO pageVO) {
|
|
|
- PageResult<ProductFavoriteDetailDO> favoritePage = productFavoriteService.getFavoritePageByFilter(pageVO);
|
|
|
+ PageResult<ProductFavoriteDO> favoritePage = productFavoriteService.getFavoritePage(pageVO);
|
|
|
if (CollUtil.isEmpty(favoritePage.getList())) {
|
|
|
return success(PageResult.empty());
|
|
|
}
|
|
|
|
|
|
+ List<ProductSpuDO> list = productSpuService.getSpuList(convertSet(favoritePage.getList(), ProductFavoriteDO::getSpuId));
|
|
|
+
|
|
|
// 得到商品 spu 信息
|
|
|
- List<ProductFavoriteRespVO> favorites = ProductFavoriteConvert.INSTANCE.convertList2admin(favoritePage.getList());
|
|
|
+ List<ProductFavoriteRespVO> favorites = ProductFavoriteConvert.INSTANCE.convertList2admin(favoritePage.getList(), list);
|
|
|
|
|
|
// 转换 VO 结果
|
|
|
PageResult<ProductFavoriteRespVO> pageResult = new PageResult<>(favoritePage.getTotal());
|
|
@@ -92,13 +80,4 @@ public class ProductFavoriteController {
|
|
|
ProductFavoriteDO favorite = productFavoriteService.getFavorite(reqVO.getUserId(), reqVO.getSpuId());
|
|
|
return success(favorite != null);
|
|
|
}
|
|
|
-
|
|
|
- @GetMapping(value = "/get-count")
|
|
|
- @Operation(summary = "获得商品收藏数量")
|
|
|
- @Parameter(name = "userId", description = "用户编号", required = true)
|
|
|
- @PreAuthenticated
|
|
|
- public CommonResult<Long> getFavoriteCount(@RequestParam("userId") Long userId) {
|
|
|
- return success(productFavoriteService.getFavoriteCount(userId));
|
|
|
- }
|
|
|
-
|
|
|
}
|