From 14d02bdfb3931be8f98ebdcb4bfd6737e27d876b Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Sat, 6 May 2023 11:58:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E6=94=B6=E8=97=8F=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/enums/ErrorCodeConstants.java | 4 +- .../app/favorite/AppFavoriteController.java | 43 ++++++----- .../app/favorite/vo/AppFavoriteReqVO.java | 2 +- .../app/favorite/vo/AppFavoriteRespVO.java | 12 ++-- .../favorite/ProductFavoriteConvert.java | 6 ++ .../favorite/ProductFavoriteDO.java | 9 ++- .../mysql/favorite/ProductFavoriteMapper.java | 26 +++---- .../favorite/ProductFavoriteService.java | 19 +++-- .../favorite/ProductFavoriteServiceImpl.java | 72 ++++++++++++------- .../mapper/favorite/ProductFavoriteMapper.xml | 22 ------ 10 files changed, 117 insertions(+), 98 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/resources/mapper/favorite/ProductFavoriteMapper.xml diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java index 5c36a2328..0ae400999 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java @@ -49,7 +49,7 @@ public interface ErrorCodeConstants { ErrorCode COMMENT_ADDITIONAL_EXISTS = new ErrorCode(1008007003, "商品追加评价已存在"); // ========== 商品 收藏 1008008000 ========== - ErrorCode COLLECTION_EXISTS = new ErrorCode(1008008000, "该商品已经被收藏"); - ErrorCode COLLECTION_NOT_EXISTS = new ErrorCode(1008008001, "商品收藏不存在"); + ErrorCode PRODUCT_FAVORITE_EXISTS = new ErrorCode(1008008000, "该商品已经被收藏"); + ErrorCode PRODUCT_FAVORITE_NOT_EXISTS = new ErrorCode(1008008001, "商品收藏不存在"); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/AppFavoriteController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/AppFavoriteController.java index 9d1d53dd3..1b085e144 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/AppFavoriteController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/AppFavoriteController.java @@ -1,22 +1,20 @@ package cn.iocoder.yudao.module.product.controller.app.favorite; -import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; 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.service.favorite.ProductFavoriteService; import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO; +import cn.iocoder.yudao.module.product.service.favorite.ProductFavoriteService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.Objects; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.module.product.enums.favorite.ProductFavoriteTypeEnum.COLLECT; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Tag(name = "用户 APP - 商品收藏") @RestController @@ -26,30 +24,31 @@ public class AppFavoriteController { @Resource private ProductFavoriteService productFavoriteService; - // TODO @jason:创建;create - @PostMapping(value = "/collect") + @PostMapping(value = "/create") @Operation(summary = "商品收藏") - public CommonResult collect(@RequestBody @Valid AppFavoriteReqVO reqVO) { - Assert.isTrue(Objects.equals(COLLECT.getType(), reqVO.getType()), "参数type 不匹配"); - return success(productFavoriteService.collect(reqVO)); + public CommonResult create(@RequestBody @Valid AppFavoriteReqVO reqVO) { + Long loginUserId = getLoginUserId(); + return success(productFavoriteService.create(loginUserId, reqVO)); } - // TODO @jason:创建;delete;使用 @DeleteMapping - @PostMapping(value = "/cancelCollect") + @DeleteMapping(value = "/delete") @Operation(summary = "取消商品收藏(通过商品详情)") - public CommonResult cancelCollect(@RequestBody @Valid AppFavoriteReqVO reqVO) { - // TODO @jason:是不是不用校验呀? - Assert.isTrue(Objects.equals(COLLECT.getType(), reqVO.getType()), "参数type 不匹配"); - return success(productFavoriteService.cancelCollect(reqVO)); + public CommonResult delete(@RequestBody @Valid AppFavoriteReqVO reqVO) { + Long loginUserId = getLoginUserId(); + return success(productFavoriteService.delete(loginUserId,reqVO)); } - // TODO @jason:page;分页 - @GetMapping(value = "/collectList") - @Operation(summary = "商品收藏列表") - public CommonResult> pageCollectList(AppFavoritePageReqVO reqVO) { - return success(productFavoriteService.pageCollectList(reqVO)); + @GetMapping(value = "/page") + @Operation(summary = "分页获取商品收藏列表") + public CommonResult> page(AppFavoritePageReqVO reqVO) { + Long userId = getLoginUserId(); + return success(productFavoriteService.page(userId,reqVO)); } - // TODO @json:需要在给一个,用户查询某个商品是否收藏;详情页要用 - + @GetMapping(value = "/checkFavorite") + @Operation(summary = "检查是否收藏过商品") + public CommonResult checkFavorite(AppFavoriteReqVO reqVO) { + Long userId = getLoginUserId(); + return success(productFavoriteService.checkFavorite(userId,reqVO)); + } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteReqVO.java index d4f2ba760..292750a7b 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteReqVO.java @@ -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 { diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteRespVO.java index 686a24d6d..da6937c5b 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteRespVO.java @@ -3,24 +3,22 @@ package cn.iocoder.yudao.module.product.controller.app.favorite.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; + @Schema(description = "用户APP - 商品收藏 Response VO") @Data public class AppFavoriteRespVO { - // TODO @jason:required true 哈 - @Schema(description = "编号", example = "1") + @Schema(description = "编号", requiredMode = REQUIRED, example = "1") private Long id; - // TODO @jason:required true 哈 - @Schema(description = "商品 SPU 编号", example = "29502") + @Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502") private Long spuId; - // TODO @jason:required true 哈 - @Schema(description = "类型", example = "1") + @Schema(description = "类型", requiredMode = REQUIRED, example = "1") private Integer type; // ========== 商品相关字段 ========== - @Schema(description = "商品 SPU 名称", example = "赵六") private String spuName; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/favorite/ProductFavoriteConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/favorite/ProductFavoriteConvert.java index 03fb1caf9..0d9e5e809 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/favorite/ProductFavoriteConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/favorite/ProductFavoriteConvert.java @@ -1,8 +1,11 @@ package cn.iocoder.yudao.module.product.convert.favorite; 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; +import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; @Mapper @@ -11,4 +14,7 @@ public interface ProductFavoriteConvert { ProductFavoriteConvert INSTANCE = Mappers.getMapper(ProductFavoriteConvert.class); ProductFavoriteDO convert(Long userId, AppFavoriteReqVO reqVO); + @Mapping(target = "id", source = "favoriteDO.id") + @Mapping(target = "spuName", source = "spuDO.name") + AppFavoriteRespVO convert(ProductSpuDO spuDO, ProductFavoriteDO favoriteDO); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDO.java index 356bba065..177087646 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDO.java @@ -1,7 +1,8 @@ package cn.iocoder.yudao.module.product.dal.dataobject.favorite; -import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; +import cn.iocoder.yudao.module.product.enums.favorite.ProductFavoriteTypeEnum; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -20,7 +21,7 @@ import lombok.*; @Builder @NoArgsConstructor @AllArgsConstructor -public class ProductFavoriteDO extends TenantBaseDO { // TODO @jason:如无必要,使用 BaseDO 哈。例如说 tenant_id 在业务里,是否需要使用到 +public class ProductFavoriteDO extends BaseDO { /** * 编号,主键自增 @@ -40,7 +41,9 @@ public class ProductFavoriteDO extends TenantBaseDO { // TODO @jason:如无必 */ private Long spuId; /** - * 类型 1 收藏;2 点赞 // TODO @jason:不要注释 1 收藏 2 点赞;而是注释好,它对应的枚举类 + * 类型 + * + * 枚举 {@link ProductFavoriteTypeEnum} */ private Integer type; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/favorite/ProductFavoriteMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/favorite/ProductFavoriteMapper.java index 435152ea7..a9c19026a 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/favorite/ProductFavoriteMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/favorite/ProductFavoriteMapper.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO; import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -15,24 +16,23 @@ import org.apache.ibatis.annotations.Param; @Mapper public interface ProductFavoriteMapper extends BaseMapperX { - default ProductFavoriteDO selectByUserAndSpuAndType(Long userId, Long spuId, Integer type) { - Assert.notNull(userId, "the userId argument must not be null"); - Assert.notNull(spuId, "the spuId argument must not be null"); - Assert.notNull(type, "the type argument must not be null"); + 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() .eq(ProductFavoriteDO::getUserId, userId) .eq(ProductFavoriteDO::getSpuId, spuId) .eq(ProductFavoriteDO::getType, type)); } - default PageResult selectPageByUserAndType(Long userId, Integer type, PageParam pageParam){ - Page page = MyBatisUtils.buildPage(pageParam); - page = selectFavoriteProductList(page, userId, type); - return new PageResult<>(page.getRecords(), page.getTotal()); + default PageResult 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() + .eq(ProductFavoriteDO::getUserId, userId) + .eq(ProductFavoriteDO::getType, type) + .orderByDesc(ProductFavoriteDO::getId)); } - - // TODO @jason:内存中拼接哈。这样好兼容更多的 db 类型; - Page selectFavoriteProductList(Page page, - @Param("userId") Long userId, - @Param("type") Integer type); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteService.java index c1b85af17..d75cb4a2d 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteService.java @@ -15,20 +15,31 @@ import javax.validation.Valid; public interface ProductFavoriteService { /** - * 商品收藏 + * 创建商品收藏 + * @param userId 用户id * @param reqVO 请求vo */ - Boolean collect(@Valid AppFavoriteReqVO reqVO); + Boolean create(Long userId, @Valid AppFavoriteReqVO reqVO); /** * 取消商品收藏 (通过商品详情页面) + * @param userId 用户id * @param reqVO 请求vo */ - Boolean cancelCollect(@Valid AppFavoriteReqVO reqVO); + Boolean delete(Long userId, @Valid AppFavoriteReqVO reqVO); /** * 分页查询用户收藏列表 + * @param userId 用户id * @param reqVO 请求 vo */ - PageResult pageCollectList(@Valid AppFavoritePageReqVO reqVO); + PageResult page(Long userId, @Valid AppFavoritePageReqVO reqVO); + + /** + * 检查是否收藏过商品 + * @param userId 用户id + * @param reqVO 请求 vo + * @return true: 已收藏 false: 未收藏 + */ + Boolean checkFavorite(Long userId, @Valid AppFavoriteReqVO reqVO); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteServiceImpl.java index 8300cbc8c..d2c741045 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteServiceImpl.java @@ -1,23 +1,29 @@ 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; -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.COLLECTION_EXISTS; -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.COLLECTION_NOT_EXISTS; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_FAVORITE_EXISTS; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_FAVORITE_NOT_EXISTS; /** * 商品收藏 Service 实现类 @@ -27,43 +33,61 @@ import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.COLLECTIO @Service @Validated public class ProductFavoriteServiceImpl implements ProductFavoriteService { - + @Resource + private ProductSpuService productSpuService; @Resource private ProductFavoriteMapper mapper; @Override - public Boolean collect(@Valid AppFavoriteReqVO reqVO) { - // TODO @jason:userId 要从 Controller 传递过来,Service 不能有转台 - Long userId = getLoginUserId(); - // TODO @jason:代码缩进不对; + public Boolean create(Long userId, @Valid AppFavoriteReqVO reqVO) { + Assert.notNull(userId, "the userId must not be null"); ProductFavoriteDO favoriteDO = mapper.selectByUserAndSpuAndType(userId, reqVO.getSpuId(), reqVO.getType()); if (Objects.nonNull(favoriteDO)) { - throw exception(COLLECTION_EXISTS); + throw exception(PRODUCT_FAVORITE_EXISTS); } - - // TODO @jason:插入只有成功,不用判断 1 ProductFavoriteDO entity = ProductFavoriteConvert.INSTANCE.convert(userId, reqVO); - int count = mapper.insert(entity); - return count == 1; + mapper.insert(entity); + return Boolean.TRUE; } @Override - public Boolean cancelCollect(@Valid AppFavoriteReqVO reqVO) { - // TODO @jason:代码缩进不对; - Long loginUserId = getLoginUserId(); - ProductFavoriteDO favoriteDO = mapper.selectByUserAndSpuAndType(loginUserId, reqVO.getSpuId(), reqVO.getType()); + public Boolean delete(Long userId, @Valid AppFavoriteReqVO reqVO) { + Assert.notNull(userId, "the userId must not be null "); + ProductFavoriteDO favoriteDO = mapper.selectByUserAndSpuAndType(userId, reqVO.getSpuId(), reqVO.getType()); if (Objects.isNull(favoriteDO)) { - throw exception(COLLECTION_NOT_EXISTS); + throw exception(PRODUCT_FAVORITE_NOT_EXISTS); } - // TODO @jason:插入只有成功,不用判断 1 - int count = mapper.deleteById(favoriteDO.getId()); - return count == 1; + mapper.deleteById(favoriteDO.getId()); + return Boolean.TRUE; } @Override - public PageResult pageCollectList(@Valid AppFavoritePageReqVO reqVO) { - Long userId = getLoginUserId(); - return mapper.selectPageByUserAndType(userId, reqVO.getType(), reqVO); + public PageResult page(Long userId, @Valid AppFavoritePageReqVO reqVO) { + Assert.notNull(userId, "the userId must not be null "); + PageResult favorites = mapper.selectPageByUserAndType(userId, reqVO.getType(), reqVO); + if (favorites.getTotal() > 0) { + PageResult pageResult = new PageResult<>(favorites.getTotal()); + List list = favorites.getList(); + //得到商品spu 信息 + List spuIds = CollectionUtils.convertList(list, ProductFavoriteDO::getSpuId); + Map spuMap = CollectionUtils.convertMap(productSpuService.getSpuList(spuIds), ProductSpuDO::getId, val -> val); + List resultList = new ArrayList<>(list.size()); + for (ProductFavoriteDO item : list) { + ProductSpuDO spuDO = spuMap.get(item.getSpuId()); + resultList.add(ProductFavoriteConvert.INSTANCE.convert(spuDO, item)); + } + pageResult.setList(resultList); + return pageResult; + }else { + return PageResult.empty(); + } + } + + @Override + public Boolean checkFavorite(Long userId, @Valid AppFavoriteReqVO reqVO) { + Assert.notNull(userId, "the userId must not be null "); + ProductFavoriteDO favoriteDO = mapper.selectByUserAndSpuAndType(userId, reqVO.getSpuId(), reqVO.getType()); + return Objects.nonNull(favoriteDO); } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/resources/mapper/favorite/ProductFavoriteMapper.xml b/yudao-module-mall/yudao-module-product-biz/src/main/resources/mapper/favorite/ProductFavoriteMapper.xml deleted file mode 100644 index 8d2741e03..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/resources/mapper/favorite/ProductFavoriteMapper.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - \ No newline at end of file