From 84b365a70718f42f36fb405233fe8a8f3fbe4082 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 9 Jun 2023 20:44:00 +0800 Subject: [PATCH] =?UTF-8?q?mall=20+=20product=EF=BC=9A=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E6=94=B6=E8=97=8F=E9=80=BB=E8=BE=91=EF=BC=8C=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=20type=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../favorite/ProductFavoriteTypeEnum.java | 36 ------------------- .../app/favorite/AppFavoriteController.java | 15 ++++---- .../app/favorite/vo/AppFavoritePageReqVO.java | 12 ------- .../app/favorite/vo/AppFavoriteReqVO.java | 7 ---- .../app/favorite/vo/AppFavoriteRespVO.java | 3 -- .../favorite/ProductFavoriteConvert.java | 3 +- .../favorite/ProductFavoriteDO.java | 7 ---- .../mysql/favorite/ProductFavoriteMapper.java | 16 ++++----- .../favorite/ProductFavoriteService.java | 14 ++++---- .../favorite/ProductFavoriteServiceImpl.java | 19 +++++----- 10 files changed, 30 insertions(+), 102 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/favorite/ProductFavoriteTypeEnum.java diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/favorite/ProductFavoriteTypeEnum.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/favorite/ProductFavoriteTypeEnum.java deleted file mode 100644 index 4d28ae8ae..000000000 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/favorite/ProductFavoriteTypeEnum.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.iocoder.yudao.module.product.enums.favorite; - -import cn.iocoder.yudao.framework.common.core.IntArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * 商品收藏的类型枚举 - * - * @author jason - */ -@Getter -@AllArgsConstructor -public enum ProductFavoriteTypeEnum implements IntArrayValuable { - - COLLECT(1,"收藏"), - THUMBS_UP(2, "点赞"); - - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ProductFavoriteTypeEnum::getType).toArray(); - - /** - * 类型 - */ - private final Integer type; - /** - * 描述 - */ - private final String desc; - - @Override - public int[] array() { - return ARRAYS; - } -} 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 f2a41ac5a..68f6e8010 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 @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.product.controller.app.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.app.favorite.vo.AppFavoritePageReqVO; import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteReqVO; import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO; @@ -35,21 +36,23 @@ public class AppFavoriteController { private ProductSpuService productSpuService; @PostMapping(value = "/create") - @Operation(summary = "商品收藏") - //@PreAuthenticated TODO 暂时注释 + @Operation(summary = "添加商品收藏") + @PreAuthenticated public CommonResult createFavorite(@RequestBody @Valid AppFavoriteReqVO reqVO) { - return success(productFavoriteService.createFavorite(getLoginUserId(), reqVO)); + return success(productFavoriteService.createFavorite(getLoginUserId(), reqVO.getSpuId())); } @DeleteMapping(value = "/delete") @Operation(summary = "取消商品收藏") + @PreAuthenticated public CommonResult deleteFavorite(@RequestBody @Valid AppFavoriteReqVO reqVO) { - productFavoriteService.deleteFavorite(getLoginUserId(), reqVO); + productFavoriteService.deleteFavorite(getLoginUserId(), reqVO.getSpuId()); return success(Boolean.TRUE); } @GetMapping(value = "/page") @Operation(summary = "分页获取商品收藏列表") + @PreAuthenticated public CommonResult> getFavoritePage(AppFavoritePageReqVO reqVO) { PageResult favoritePage = productFavoriteService.getFavoritePage(getLoginUserId(), reqVO); if (CollUtil.isEmpty(favoritePage.getList())) { @@ -67,11 +70,11 @@ public class AppFavoriteController { return success(pageResult); } - @GetMapping(value = "/exits") @Operation(summary = "检查是否收藏过商品") + @PreAuthenticated public CommonResult isFavoriteExists(AppFavoriteReqVO reqVO) { - ProductFavoriteDO favoriteDO = productFavoriteService.getFavorite(getLoginUserId(), reqVO); + ProductFavoriteDO favoriteDO = productFavoriteService.getFavorite(getLoginUserId(), reqVO.getSpuId()); return success(Objects.nonNull(favoriteDO)); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoritePageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoritePageReqVO.java index 3ca8b6da6..cdf8257c3 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoritePageReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoritePageReqVO.java @@ -1,22 +1,10 @@ package cn.iocoder.yudao.module.product.controller.app.favorite.vo; import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.product.enums.favorite.ProductFavoriteTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import javax.validation.constraints.NotNull; - -import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; - @Schema(description = "用户APP - 商品收藏分页查询 Request VO") @Data public class AppFavoritePageReqVO extends PageParam { - - @Schema(description = "类型", requiredMode = REQUIRED, example = "1") - @NotNull(message = "类型不能为空") - @InEnum(ProductFavoriteTypeEnum.class) - private Integer type; - } 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 63da3340b..639de011e 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 @@ -1,7 +1,5 @@ package cn.iocoder.yudao.module.product.controller.app.favorite.vo; -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.product.enums.favorite.ProductFavoriteTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -17,9 +15,4 @@ public class AppFavoriteReqVO { @NotNull(message = "商品 SPU 编号不能为空") private Long spuId; - @Schema(description = "类型", requiredMode = REQUIRED, example = "1") - @NotNull(message = "类型不能为空") - @InEnum(ProductFavoriteTypeEnum.class) - private Integer type; - } 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 a0f81a909..399e1fb0a 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 @@ -14,9 +14,6 @@ public class AppFavoriteRespVO { @Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502") private Long spuId; - @Schema(description = "类型", requiredMode = REQUIRED, example = "1") - private Integer type; - // ========== 商品相关字段 ========== @Schema(description = "商品 SPU 名称", example = "赵六") 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 d19f67c49..b15afacb2 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,6 +1,5 @@ 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; @@ -19,7 +18,7 @@ public interface ProductFavoriteConvert { ProductFavoriteConvert INSTANCE = Mappers.getMapper(ProductFavoriteConvert.class); - ProductFavoriteDO convert(Long userId, AppFavoriteReqVO reqVO); + ProductFavoriteDO convert(Long userId, Long spuId); @Mapping(target = "id", source = "favorite.id") @Mapping(target = "spuName", source = "spu.name") 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 d99ae0fe6..6e00eaa6c 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 @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.product.dal.dataobject.favorite; 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; @@ -40,11 +39,5 @@ public class ProductFavoriteDO extends BaseDO { * 关联 {@link ProductSpuDO#getId()} */ private Long spuId; - /** - * 类型 - * - * 枚举 {@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 0246e0fee..68f7db319 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 @@ -1,9 +1,8 @@ package cn.iocoder.yudao.module.product.dal.mysql.favorite; -import cn.iocoder.yudao.framework.common.pojo.PageParam; 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.app.favorite.vo.AppFavoritePageReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; @@ -11,17 +10,14 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface ProductFavoriteMapper extends BaseMapperX { - default ProductFavoriteDO selectByUserAndSpuAndType(Long userId, Long spuId, Integer type) { - return selectOne(new LambdaQueryWrapperX() - .eq(ProductFavoriteDO::getUserId, userId) - .eq(ProductFavoriteDO::getSpuId, spuId) - .eq(ProductFavoriteDO::getType, type)); + default ProductFavoriteDO selectByUserIdAndSpuId(Long userId, Long spuId) { + return selectOne(ProductFavoriteDO::getUserId, userId, + ProductFavoriteDO::getSpuId, spuId); } - default PageResult selectPageByUserAndType(Long userId, Integer type, PageParam pageParam) { - return selectPage(pageParam, new LambdaQueryWrapper() + default PageResult selectPageByUserAndType(Long userId, AppFavoritePageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapper() .eq(ProductFavoriteDO::getUserId, userId) - .eq(ProductFavoriteDO::getType, type) .orderByDesc(ProductFavoriteDO::getId)); } 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 2c6076969..7ea7489a4 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 @@ -2,8 +2,6 @@ package cn.iocoder.yudao.module.product.service.favorite; 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.controller.app.favorite.vo.AppFavoriteRespVO; import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO; import javax.validation.Valid; @@ -19,17 +17,17 @@ public interface ProductFavoriteService { * 创建商品收藏 * * @param userId 用户 id - * @param reqVO 请求 vo + * @param spuId SPU 编号 */ - Long createFavorite(Long userId, @Valid AppFavoriteReqVO reqVO); + Long createFavorite(Long userId, Long spuId); /** * 取消商品收藏 * * @param userId 用户 id - * @param reqVO 请求 vo + * @param spuId SPU 编号 */ - void deleteFavorite(Long userId, @Valid AppFavoriteReqVO reqVO); + void deleteFavorite(Long userId, Long spuId); /** * 分页查询用户收藏列表 @@ -43,8 +41,8 @@ public interface ProductFavoriteService { * 获取收藏过商品 * * @param userId 用户id - * @param reqVO 请求 vo + * @param spuId SPU 编号 */ - ProductFavoriteDO getFavorite(Long userId, @Valid AppFavoriteReqVO reqVO); + ProductFavoriteDO getFavorite(Long userId, Long spuId); } 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 b1dd84fa5..775aa0e69 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 @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.product.service.favorite; 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.convert.favorite.ProductFavoriteConvert; import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO; import cn.iocoder.yudao.module.product.dal.mysql.favorite.ProductFavoriteMapper; @@ -30,22 +29,20 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService { private ProductFavoriteMapper productFavoriteMapper; @Override - public Long createFavorite(Long userId, @Valid AppFavoriteReqVO reqVO) { - ProductFavoriteDO favorite = productFavoriteMapper.selectByUserAndSpuAndType( - userId, reqVO.getSpuId(), reqVO.getType()); + public Long createFavorite(Long userId, Long spuId) { + ProductFavoriteDO favorite = productFavoriteMapper.selectByUserIdAndSpuId(userId, spuId); if (Objects.nonNull(favorite)) { throw exception(FAVORITE_EXISTS); } - ProductFavoriteDO entity = ProductFavoriteConvert.INSTANCE.convert(userId, reqVO); + ProductFavoriteDO entity = ProductFavoriteConvert.INSTANCE.convert(userId, spuId); productFavoriteMapper.insert(entity); return entity.getId(); } @Override - public void deleteFavorite(Long userId, @Valid AppFavoriteReqVO reqVO) { - ProductFavoriteDO favorite = productFavoriteMapper.selectByUserAndSpuAndType( - userId, reqVO.getSpuId(), reqVO.getType()); + public void deleteFavorite(Long userId, Long spuId) { + ProductFavoriteDO favorite = productFavoriteMapper.selectByUserIdAndSpuId(userId, spuId); if (Objects.isNull(favorite)) { throw exception(FAVORITE_NOT_EXISTS); } @@ -55,12 +52,12 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService { @Override public PageResult getFavoritePage(Long userId, @Valid AppFavoritePageReqVO reqVO) { - return productFavoriteMapper.selectPageByUserAndType(userId, reqVO.getType(), reqVO); + return productFavoriteMapper.selectPageByUserAndType(userId, reqVO); } @Override - public ProductFavoriteDO getFavorite(Long userId, @Valid AppFavoriteReqVO reqVO) { - return productFavoriteMapper.selectByUserAndSpuAndType(userId, reqVO.getSpuId(), reqVO.getType()); + public ProductFavoriteDO getFavorite(Long userId, Long spuId) { + return productFavoriteMapper.selectByUserIdAndSpuId(userId, spuId); } }