From 98aae5ed1a176283f937834b9074eb1f755a5b0f Mon Sep 17 00:00:00 2001 From: dongshanshan Date: Tue, 31 Oct 2023 16:51:56 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=E4=BC=9A=E5=91=98=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/core/mapper/BaseMapperX.java | 7 ++ .../favorite/ProductFavoriteController.java | 104 ++++++++++++++++++ .../favorite/vo/ProductFavoriteBaseVO.java | 21 ++++ .../vo/ProductFavoriteBatchReqVO.java | 21 ++++ .../favorite/vo/ProductFavoritePageReqVO.java | 35 ++++++ .../favorite/vo/ProductFavoriteReqVO.java | 17 +++ .../favorite/vo/ProductFavoriteRespVO.java | 22 ++++ .../favorite/ProductFavoriteConvert.java | 19 ++++ .../favorite/ProductFavoriteDetailDO.java | 16 +++ .../mysql/favorite/ProductFavoriteMapper.java | 36 ++++++ .../favorite/ProductFavoriteService.java | 10 +- .../favorite/ProductFavoriteServiceImpl.java | 8 +- 12 files changed, 314 insertions(+), 2 deletions(-) create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/ProductFavoriteController.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteBaseVO.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteBatchReqVO.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoritePageReqVO.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteReqVO.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteRespVO.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDetailDO.java 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 d70c21626..2654bec52 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 @@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.extension.toolkit.Db; import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.interfaces.MPJBaseJoin; import org.apache.ibatis.annotations.Param; import java.util.Collection; @@ -132,4 +133,10 @@ public interface BaseMapperX extends MPJBaseMapper { Db.saveOrUpdateBatch(collection); } + default PageResult selectJoinPage(PageParam pageParam, @Param("resultTypeClass_Eg1sG") Class var2, @Param("ew") MPJBaseJoin queryWrapper) { + IPage mpPage = MyBatisUtils.buildPage(pageParam); + selectJoinPage(mpPage, var2, queryWrapper); + // 转换返回 + 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 new file mode 100644 index 000000000..e59c10827 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/ProductFavoriteController.java @@ -0,0 +1,104 @@ +package cn.iocoder.yudao.module.product.controller.admin.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.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.service.favorite.ProductFavoriteService; +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; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "管理后台 - 商品收藏") +@RestController +@RequestMapping("/product/favorite") +@Validated +public class ProductFavoriteController { + + @Resource + private ProductFavoriteService productFavoriteService; + + @PostMapping("/create") + @Operation(summary = "添加单个商品收藏") + @PreAuthorize("@ss.hasPermission('product:favorite:create')") + public CommonResult createFavorite(@Valid @RequestBody ProductFavoriteReqVO reqVO) { + 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')") + public CommonResult deleteFavorite(@Valid @RequestBody ProductFavoriteReqVO reqVO) { + productFavoriteService.deleteFavorite(reqVO.getUserId(), reqVO.getSpuId()); + 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); + if (CollUtil.isEmpty(favoritePage.getList())) { + return success(PageResult.empty()); + } + + // 得到商品 spu 信息 + List favorites = ProductFavoriteConvert.INSTANCE.convertList2admin(favoritePage.getList()); + + // 转换 VO 结果 + PageResult pageResult = new PageResult<>(favoritePage.getTotal()); + pageResult.setList(favorites); + + return success(pageResult); + } + + @PostMapping(value = "/exits") + @Operation(summary = "检查是否收藏过商品") + @PreAuthenticated + public CommonResult isFavoriteExists(@Valid @RequestBody ProductFavoriteReqVO reqVO) { + 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/controller/admin/favorite/vo/ProductFavoriteBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteBaseVO.java new file mode 100644 index 000000000..72b2613d5 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteBaseVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.product.controller.admin.favorite.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 商品收藏 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class ProductFavoriteBaseVO { + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "5036") + @NotNull(message = "用户编号不能为空") + 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/ProductFavoriteBatchReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteBatchReqVO.java new file mode 100644 index 000000000..d779ff3a8 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteBatchReqVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.product.controller.admin.favorite.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.ToString; + +import javax.validation.constraints.NotNull; +import java.util.List; + +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; + +@Schema(description = "管理后台 - 商品收藏的批量 Request VO") +@Data +@ToString(callSuper = true) +public class ProductFavoriteBatchReqVO extends ProductFavoriteBaseVO{ + + @Schema(description = "商品 SPU 编号数组", requiredMode = REQUIRED, example = "29502") + @NotNull(message = "商品 SPU 编号数组不能为空") + private List spuIds; + +} 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 new file mode 100644 index 000000000..37f8cecc3 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoritePageReqVO.java @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.module.product.controller.admin.favorite.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 商品收藏分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class ProductFavoritePageReqVO extends PageParam { + + @Schema(description = "用户编号", example = "5036") + private Long userId; + + @Schema(description = "商品 SPU 编号", example = "32734") + private Long spuId; + + @Schema(description = "收藏时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + + @Schema(description = "商品名称", example = "5036") + private String name; + + @Schema(description = "关键字", example = "5036") + private String keyword; +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteReqVO.java new file mode 100644 index 000000000..3c2222643 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteReqVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.product.controller.admin.favorite.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.ToString; + +import javax.validation.constraints.NotNull; + +@Schema(description = "管理后台 - 商品收藏的单个 Response VO") +@Data +@ToString(callSuper = true) +public class ProductFavoriteReqVO extends ProductFavoriteBaseVO { + + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "32734") + @NotNull(message = "商品 SPU 编号不能为空") + private Long spuId; +} 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 new file mode 100644 index 000000000..255fc631b --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteRespVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.product.controller.admin.favorite.vo; + +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuRespVO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.ToString; + +@Schema(description = "管理后台 - 商品收藏 Response VO") +@Data +@ToString(callSuper = true) +public class ProductFavoriteRespVO extends ProductSpuRespVO { + + @Schema(description = "userId", requiredMode = Schema.RequiredMode.REQUIRED, example = "111") + private Long userId; + + @Schema(description = "spuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "111") + private Long spuId; + + @Schema(description = "收藏状态", example = "1") + private Integer favoriteStatus; + +} 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 b15afacb2..22ffb8577 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,7 +1,10 @@ package cn.iocoder.yudao.module.product.convert.favorite; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +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; @@ -34,4 +37,20 @@ public interface ProductFavoriteConvert { return resultList; } + @Mapping(target = "id", source = "favorite.id") + @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)); + } + 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 new file mode 100644 index 000000000..ba4d5b557 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDetailDO.java @@ -0,0 +1,16 @@ +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 54d9d2dd6..08a5c3063 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,9 +2,15 @@ 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.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 @@ -21,6 +27,36 @@ public interface ProductFavoriteMapper extends BaseMapperX { .orderByDesc(ProductFavoriteDO::getId)); } + default PageResult selectPageByUserAndFields(ProductFavoritePageReqVO reqVO) { + MPJLambdaWrapper wrapper = 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); + } + default Long selectCountByUserId(Long userId) { return selectCount(ProductFavoriteDO::getUserId, 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 00aeddb8a..87c9854a9 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 @@ -1,8 +1,10 @@ package cn.iocoder.yudao.module.product.service.favorite; 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; @@ -37,6 +39,13 @@ public interface ProductFavoriteService { */ PageResult getFavoritePage(Long userId, @Valid AppFavoritePageReqVO reqVO); + /** + * 分页查询用户收藏列表 + * + * @param reqVO 请求 vo + */ + PageResult getFavoritePageByFilter(@Valid ProductFavoritePageReqVO reqVO); + /** * 获取收藏过商品 * @@ -52,5 +61,4 @@ public interface ProductFavoriteService { * @return 数量 */ Long getFavoriteCount(Long userId); - } 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 983cbf83c..0f8d30ec0 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,9 +1,11 @@ package cn.iocoder.yudao.module.product.service.favorite; 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.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; @@ -33,7 +35,6 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService { if (favorite != null) { throw exception(FAVORITE_EXISTS); } - ProductFavoriteDO entity = ProductFavoriteConvert.INSTANCE.convert(userId, spuId); productFavoriteMapper.insert(entity); return entity.getId(); @@ -54,6 +55,11 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService { return productFavoriteMapper.selectPageByUserAndType(userId, reqVO); } + @Override + public PageResult getFavoritePageByFilter(@Valid ProductFavoritePageReqVO reqVO) { + return productFavoriteMapper.selectPageByUserAndFields(reqVO); + } + @Override public ProductFavoriteDO getFavorite(Long userId, Long spuId) { return productFavoriteMapper.selectByUserIdAndSpuId(userId, spuId); From daa7d14b092342b1bd7062873c9c9b7ec79cc2bc Mon Sep 17 00:00:00 2001 From: niou233 <2922564446@qq.com> Date: Wed, 8 Nov 2023 14:36:44 +0800 Subject: [PATCH 2/6] =?UTF-8?q?reafactor:=20=E4=BC=9A=E5=91=98=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/core/mapper/BaseMapperX.java | 4 +- .../favorite/ProductFavoriteController.java | 41 +++++-------------- .../favorite/ProductFavoriteConvert.java | 11 ++--- .../favorite/ProductFavoriteDetailDO.java | 1 - .../mysql/favorite/ProductFavoriteMapper.java | 33 ++------------- .../favorite/ProductFavoriteService.java | 3 +- .../favorite/ProductFavoriteServiceImpl.java | 5 +-- 7 files changed, 24 insertions(+), 74 deletions(-) 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 From 5facac733039e924c293ae892d289bd154187e9d Mon Sep 17 00:00:00 2001 From: niou233 <2922564446@qq.com> Date: Wed, 8 Nov 2023 14:37:18 +0800 Subject: [PATCH 3/6] =?UTF-8?q?refactor:=20=E4=BC=9A=E5=91=98=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../favorite/vo/ProductFavoriteBaseVO.java | 2 -- .../vo/ProductFavoriteBatchReqVO.java | 21 ------------------- .../favorite/vo/ProductFavoritePageReqVO.java | 18 ---------------- .../favorite/vo/ProductFavoriteRespVO.java | 4 ---- 4 files changed, 45 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteBatchReqVO.java diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteBaseVO.java index 72b2613d5..68b0a0a16 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteBaseVO.java @@ -16,6 +16,4 @@ public class ProductFavoriteBaseVO { @NotNull(message = "用户编号不能为空") 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/ProductFavoriteBatchReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteBatchReqVO.java deleted file mode 100644 index d779ff3a8..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/favorite/vo/ProductFavoriteBatchReqVO.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.favorite.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.ToString; - -import javax.validation.constraints.NotNull; -import java.util.List; - -import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; - -@Schema(description = "管理后台 - 商品收藏的批量 Request VO") -@Data -@ToString(callSuper = true) -public class ProductFavoriteBatchReqVO extends ProductFavoriteBaseVO{ - - @Schema(description = "商品 SPU 编号数组", requiredMode = REQUIRED, example = "29502") - @NotNull(message = "商品 SPU 编号数组不能为空") - private List spuIds; - -} 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 37f8cecc3..9c0b33035 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 @@ -5,11 +5,6 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @Schema(description = "管理后台 - 商品收藏分页 Request VO") @Data @@ -19,17 +14,4 @@ public class ProductFavoritePageReqVO extends PageParam { @Schema(description = "用户编号", example = "5036") private Long userId; - - @Schema(description = "商品 SPU 编号", example = "32734") - private Long spuId; - - @Schema(description = "收藏时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - - @Schema(description = "商品名称", example = "5036") - private String name; - - @Schema(description = "关键字", example = "5036") - private String keyword; } 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 255fc631b..bbf972181 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,8 +15,4 @@ public class ProductFavoriteRespVO extends ProductSpuRespVO { @Schema(description = "spuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "111") private Long spuId; - - @Schema(description = "收藏状态", example = "1") - private Integer favoriteStatus; - } From 670c0962a76fbf8e393d347c78ae66b2c4af1ee0 Mon Sep 17 00:00:00 2001 From: niou233 <2922564446@qq.com> Date: Wed, 8 Nov 2023 17:03:37 +0800 Subject: [PATCH 4/6] =?UTF-8?q?refactor:=20=E4=BC=9A=E5=91=98=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../favorite/ProductFavoriteController.java | 29 ++----------------- 1 file changed, 3 insertions(+), 26 deletions(-) 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 9157e8a05..6f66c2062 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 @@ -3,9 +3,7 @@ package cn.iocoder.yudao.module.product.controller.admin.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.security.core.annotations.PreAuthenticated; 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; @@ -16,7 +14,9 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.validation.Valid; @@ -37,21 +37,6 @@ public class ProductFavoriteController { @Resource private ProductSpuService productSpuService; - @PostMapping("/create") - @Operation(summary = "添加单个商品收藏") - @PreAuthorize("@ss.hasPermission('product:favorite:create')") - public CommonResult createFavorite(@Valid @RequestBody ProductFavoriteReqVO reqVO) { - return success(productFavoriteService.createFavorite(reqVO.getUserId(), reqVO.getSpuId())); - } - - @DeleteMapping("/delete") - @Operation(summary = "取消单个商品收藏") - @PreAuthorize("@ss.hasPermission('product:favorite:delete')") - public CommonResult deleteFavorite(@Valid @RequestBody ProductFavoriteReqVO reqVO) { - productFavoriteService.deleteFavorite(reqVO.getUserId(), reqVO.getSpuId()); - return success(Boolean.TRUE); - } - @GetMapping("/page") @Operation(summary = "获得商品收藏分页") @PreAuthorize("@ss.hasPermission('product:favorite:query')") @@ -72,12 +57,4 @@ public class ProductFavoriteController { return success(pageResult); } - - @PostMapping(value = "/exits") - @Operation(summary = "检查是否收藏过商品") - @PreAuthenticated - public CommonResult isFavoriteExists(@Valid @RequestBody ProductFavoriteReqVO reqVO) { - ProductFavoriteDO favorite = productFavoriteService.getFavorite(reqVO.getUserId(), reqVO.getSpuId()); - return success(favorite != null); - } } From 92be763c6f35a1735d45e8fae8cce870c8808c10 Mon Sep 17 00:00:00 2001 From: niou233 <2922564446@qq.com> Date: Wed, 8 Nov 2023 17:18:28 +0800 Subject: [PATCH 5/6] =?UTF-8?q?refactor:=20=E4=BC=9A=E5=91=98=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/product/service/favorite/ProductFavoriteService.java | 1 + 1 file changed, 1 insertion(+) 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 295af4c94..3dd3bd59e 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 @@ -60,4 +60,5 @@ public interface ProductFavoriteService { * @return 数量 */ Long getFavoriteCount(Long userId); + } From 5a5a42463bbfad1f95a32a6c8ee1c13094f633c3 Mon Sep 17 00:00:00 2001 From: niou233 <2922564446@qq.com> Date: Wed, 8 Nov 2023 17:22:00 +0800 Subject: [PATCH 6/6] =?UTF-8?q?refactor:=20=E4=BC=9A=E5=91=98=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/service/favorite/ProductFavoriteServiceImpl.java | 1 + 1 file changed, 1 insertion(+) 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 945201286..927d030d5 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 @@ -34,6 +34,7 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService { if (favorite != null) { throw exception(FAVORITE_EXISTS); } + ProductFavoriteDO entity = ProductFavoriteConvert.INSTANCE.convert(userId, spuId); productFavoriteMapper.insert(entity); return entity.getId();