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 2654bec52..db054e972 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 @@ -133,9 +133,9 @@ public interface BaseMapperX extends MPJBaseMapper { Db.saveOrUpdateBatch(collection); } - default PageResult selectJoinPage(PageParam pageParam, @Param("resultTypeClass_Eg1sG") Class var2, @Param("ew") MPJBaseJoin queryWrapper) { + default PageResult selectJoinPage(PageParam pageParam, Class resultTypeClass, MPJBaseJoin joinQueryWrapper) { IPage mpPage = MyBatisUtils.buildPage(pageParam); - selectJoinPage(mpPage, var2, queryWrapper); + selectJoinPage(mpPage, resultTypeClass, joinQueryWrapper); // 转换返回 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 e59c10827..9157e8a05 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 @@ -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 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 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> getFavoritePage(@Valid ProductFavoritePageReqVO pageVO) { - PageResult favoritePage = productFavoriteService.getFavoritePageByFilter(pageVO); + PageResult favoritePage = productFavoriteService.getFavoritePage(pageVO); if (CollUtil.isEmpty(favoritePage.getList())) { return success(PageResult.empty()); } + List list = productSpuService.getSpuList(convertSet(favoritePage.getList(), ProductFavoriteDO::getSpuId)); + // 得到商品 spu 信息 - List favorites = ProductFavoriteConvert.INSTANCE.convertList2admin(favoritePage.getList()); + List favorites = ProductFavoriteConvert.INSTANCE.convertList2admin(favoritePage.getList(), list); // 转换 VO 结果 PageResult 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 getFavoriteCount(@RequestParam("userId") Long userId) { - return success(productFavoriteService.getFavoriteCount(userId)); - } - } 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 22ffb8577..9adac8c86 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 @@ -13,6 +13,7 @@ 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; @@ -41,13 +42,13 @@ public interface ProductFavoriteConvert { @Mapping(target = "userId", source = "favorite.userId") @Mapping(target = "spuId", source = "favorite.spuId") @Mapping(target = "createTime", source = "favorite.createTime") - @Mapping(target = "favoriteStatus", constant = "1") ProductFavoriteRespVO convert2admin(ProductSpuDO spu, ProductFavoriteDO favorite); - default List convertList2admin(List favorites) { - List resultList = new ArrayList<>(favorites.size()); - for (ProductFavoriteDetailDO favorite : favorites) { - resultList.add(convert2admin(favorite.getSpuDO(), 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; } 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 index ba4d5b557..60e401e11 100644 --- 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 @@ -12,5 +12,4 @@ import lombok.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 08a5c3063..e116a7c4a 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 @@ -5,12 +5,8 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 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 cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDetailDO; -import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper; -import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.annotations.Mapper; @Mapper @@ -27,34 +23,11 @@ public interface ProductFavoriteMapper extends BaseMapperX { .orderByDesc(ProductFavoriteDO::getId)); } - default PageResult selectPageByUserAndFields(ProductFavoritePageReqVO reqVO) { - MPJLambdaWrapper wrapper = new MPJLambdaWrapper() + default PageResult selectPageByUserId(ProductFavoritePageReqVO reqVO) { + return selectPage(reqVO, new MPJLambdaWrapper() .selectAll(ProductFavoriteDO.class) .eq(ProductFavoriteDO::getUserId, reqVO.getUserId()) - .selectAssociation(ProductSpuDO.class, ProductFavoriteDetailDO::getSpuDO); - if(StringUtils.isNotEmpty(reqVO.getName())){ - wrapper.likeRight(ProductSpuDO::getName, reqVO.getName()); - } - if(StringUtils.isNotEmpty(reqVO.getName()) && StringUtils.isNotEmpty(reqVO.getKeyword())){ - wrapper.or(); - } - if(StringUtils.isNotEmpty(reqVO.getKeyword())){ - wrapper.likeRight(ProductSpuDO::getKeyword, reqVO.getKeyword()); - } - - if(reqVO.getCreateTime() != null){ - if (reqVO.getCreateTime()[0] != null && reqVO.getCreateTime()[1] != null) { - wrapper.between(ProductFavoriteDO::getCreateTime, reqVO.getCreateTime()[0], reqVO.getCreateTime()[1]); - } - if (reqVO.getCreateTime()[0] != null) { - wrapper.ge(ProductFavoriteDO::getCreateTime, reqVO.getCreateTime()[0]); - } - if (reqVO.getCreateTime()[1] != null) { - wrapper.le(ProductFavoriteDO::getCreateTime, reqVO.getCreateTime()[1]); - } - } - - return selectJoinPage(reqVO, ProductFavoriteDetailDO.class, wrapper); + .orderByDesc(ProductFavoriteDO::getCreateTime)); } default Long selectCountByUserId(Long userId) { 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 87c9854a9..295af4c94 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 @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; 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 cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDetailDO; import javax.validation.Valid; @@ -44,7 +43,7 @@ public interface ProductFavoriteService { * * @param reqVO 请求 vo */ - PageResult getFavoritePageByFilter(@Valid ProductFavoritePageReqVO reqVO); + PageResult getFavoritePage(@Valid ProductFavoritePageReqVO 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 0f8d30ec0..945201286 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 @@ -5,7 +5,6 @@ import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavor import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO; 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.mysql.favorite.ProductFavoriteMapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -56,8 +55,8 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService { } @Override - public PageResult getFavoritePageByFilter(@Valid ProductFavoritePageReqVO reqVO) { - return productFavoriteMapper.selectPageByUserAndFields(reqVO); + public PageResult getFavoritePage(@Valid ProductFavoritePageReqVO reqVO) { + return productFavoriteMapper.selectPageByUserId(reqVO); } @Override