diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index db054e972..57e7133fb 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -139,4 +139,5 @@ public interface BaseMapperX extends MPJBaseMapper { // 转换返回 return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); } + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/ProductFavoriteController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/ProductFavoriteController.java index 6f66c2062..721cf19c0 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/ProductFavoriteController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/ProductFavoriteController.java @@ -41,20 +41,13 @@ public class ProductFavoriteController { @Operation(summary = "获得商品收藏分页") @PreAuthorize("@ss.hasPermission('product:favorite:query')") public CommonResult> getFavoritePage(@Valid ProductFavoritePageReqVO pageVO) { - PageResult favoritePage = productFavoriteService.getFavoritePage(pageVO); - if (CollUtil.isEmpty(favoritePage.getList())) { + PageResult pageResult = productFavoriteService.getFavoritePage(pageVO); + if (CollUtil.isEmpty(pageResult.getList())) { return success(PageResult.empty()); } - - List list = productSpuService.getSpuList(convertSet(favoritePage.getList(), ProductFavoriteDO::getSpuId)); - - // 得到商品 spu 信息 - List favorites = ProductFavoriteConvert.INSTANCE.convertList2admin(favoritePage.getList(), list); - - // 转换 VO 结果 - PageResult pageResult = new PageResult<>(favoritePage.getTotal()); - pageResult.setList(favorites); - - return success(pageResult); + // 拼接数据 + List spuList = productSpuService.getSpuList(convertSet(pageResult.getList(), ProductFavoriteDO::getSpuId)); + return success(ProductFavoriteConvert.INSTANCE.convertPage(pageResult, spuList)); } + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoritePageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoritePageReqVO.java index 9c0b33035..3d78883ec 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoritePageReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoritePageReqVO.java @@ -14,4 +14,5 @@ public class ProductFavoritePageReqVO extends PageParam { @Schema(description = "用户编号", example = "5036") private Long userId; + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteRespVO.java index bbf972181..3c09aa8fc 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteRespVO.java @@ -15,4 +15,5 @@ public class ProductFavoriteRespVO extends ProductSpuRespVO { @Schema(description = "spuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "111") private Long spuId; + } 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 9adac8c86..7b419b6a8 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,10 +1,10 @@ package cn.iocoder.yudao.module.product.convert.favorite; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavoriteRespVO; 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.favorite.ProductFavoriteDetailDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -13,7 +13,6 @@ import org.mapstruct.factory.Mappers; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Optional; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; @@ -38,20 +37,18 @@ public interface ProductFavoriteConvert { return resultList; } + default PageResult convertPage(PageResult pageResult, List spuList) { + Map spuMap = convertMap(spuList, ProductSpuDO::getId); + List voList = CollectionUtils.convertList(pageResult.getList(), favorite -> { + ProductSpuDO spu = spuMap.get(favorite.getSpuId()); + return convert02(spu, favorite); + }); + return new PageResult<>(voList, pageResult.getTotal()); + } @Mapping(target = "id", source = "favorite.id") @Mapping(target = "userId", source = "favorite.userId") @Mapping(target = "spuId", source = "favorite.spuId") @Mapping(target = "createTime", source = "favorite.createTime") - ProductFavoriteRespVO convert2admin(ProductSpuDO spu, ProductFavoriteDO favorite); + ProductFavoriteRespVO convert02(ProductSpuDO spu, ProductFavoriteDO favorite); - default List convertList2admin(List favorites, List spus) { - List resultList = new ArrayList<>(spus.size()); - for (ProductFavoriteDO favorite : favorites) { - Optional spu = spus.stream().filter(e -> e.getId().equals(favorite.getSpuId())).findFirst(); - resultList.add(convert2admin(spu.get(), favorite)); - } - return resultList; - } - - PageResult convertPage(PageResult page); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDetailDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDetailDO.java deleted file mode 100644 index 60e401e11..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDetailDO.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.yudao.module.product.dal.dataobject.favorite; - -import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; -import lombok.Data; - -/** - * 商品收藏 DO - * - * @author 芋道源码 - */ -@Data -public class ProductFavoriteDetailDO extends ProductFavoriteDO { - - ProductSpuDO spuDO; -} 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 e116a7c4a..a681d42a7 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 @@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.product.dal.mysql.favorite; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavoritePageReqVO; import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.github.yulichang.wrapper.MPJLambdaWrapper; import org.apache.ibatis.annotations.Mapper; @Mapper @@ -24,10 +24,9 @@ public interface ProductFavoriteMapper extends BaseMapperX { } default PageResult selectPageByUserId(ProductFavoritePageReqVO reqVO) { - return selectPage(reqVO, new MPJLambdaWrapper() - .selectAll(ProductFavoriteDO.class) - .eq(ProductFavoriteDO::getUserId, reqVO.getUserId()) - .orderByDesc(ProductFavoriteDO::getCreateTime)); + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(ProductFavoriteDO::getUserId, reqVO.getUserId()) + .orderByDesc(ProductFavoriteDO::getId)); } default Long selectCountByUserId(Long userId) {