diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java index 631f48915..f3f598065 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java @@ -1,22 +1,21 @@ package cn.iocoder.yudao.module.product.controller.admin.category; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryRespVO; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; -import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategorySaveReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.validation.Valid; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import jakarta.annotation.Resource; -import jakarta.validation.Valid; import java.util.Comparator; import java.util.List; @@ -34,14 +33,14 @@ public class ProductCategoryController { @PostMapping("/create") @Operation(summary = "创建商品分类") @PreAuthorize("@ss.hasPermission('product:category:create')") - public CommonResult createCategory(@Valid @RequestBody ProductCategoryCreateReqVO createReqVO) { + public CommonResult createCategory(@Valid @RequestBody ProductCategorySaveReqVO createReqVO) { return success(categoryService.createCategory(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新商品分类") @PreAuthorize("@ss.hasPermission('product:category:update')") - public CommonResult updateCategory(@Valid @RequestBody ProductCategoryUpdateReqVO updateReqVO) { + public CommonResult updateCategory(@Valid @RequestBody ProductCategorySaveReqVO updateReqVO) { categoryService.updateCategory(updateReqVO); return success(true); } @@ -61,7 +60,7 @@ public class ProductCategoryController { @PreAuthorize("@ss.hasPermission('product:category:query')") public CommonResult getCategory(@RequestParam("id") Long id) { ProductCategoryDO category = categoryService.getCategory(id); - return success(ProductCategoryConvert.INSTANCE.convert(category)); + return success(BeanUtils.toBean(category, ProductCategoryRespVO.class)); } @GetMapping("/list") @@ -70,7 +69,7 @@ public class ProductCategoryController { public CommonResult> getCategoryList(@Valid ProductCategoryListReqVO listReqVO) { List list = categoryService.getCategoryList(listReqVO); list.sort(Comparator.comparing(ProductCategoryDO::getSort)); - return success(ProductCategoryConvert.INSTANCE.convertList(list)); + return success(BeanUtils.toBean(list, ProductCategoryRespVO.class)); } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryCreateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryCreateReqVO.java deleted file mode 100644 index 5451d2e82..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryCreateReqVO.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.category.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import jakarta.validation.constraints.NotBlank; - -@Schema(description = "管理后台 - 商品分类创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ProductCategoryCreateReqVO extends ProductCategoryBaseVO { - - @Schema(description = "分类描述", example = "描述") - private String description; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryRespVO.java index 8f46ff60f..c8ef92e17 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryRespVO.java @@ -2,20 +2,34 @@ package cn.iocoder.yudao.module.product.controller.admin.category.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import java.time.LocalDateTime; @Schema(description = "管理后台 - 商品分类 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ProductCategoryRespVO extends ProductCategoryBaseVO { +public class ProductCategoryRespVO { @Schema(description = "分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") private Long id; + @Schema(description = "父分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Long parentId; + + @Schema(description = "分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "办公文具") + private String name; + + @Schema(description = "移动端分类图", requiredMode = Schema.RequiredMode.REQUIRED) + private String picUrl; + + @Schema(description = "分类排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer sort; + + @Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") + private Integer status; + + @Schema(description = "分类描述", example = "描述") + private String description; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategorySaveReqVO.java similarity index 79% rename from yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryBaseVO.java rename to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategorySaveReqVO.java index 4174f3c98..5f03df1fa 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategorySaveReqVO.java @@ -1,17 +1,16 @@ package cn.iocoder.yudao.module.product.controller.admin.category.vo; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import lombok.Data; -/** -* 商品分类 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ +@Schema(description = "管理后台 - 商品分类新增/更新 Request VO") @Data -public class ProductCategoryBaseVO { +public class ProductCategorySaveReqVO { + + @Schema(description = "分类编号", example = "2") + private Long id; @Schema(description = "父分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "父分类编号不能为空") @@ -25,9 +24,6 @@ public class ProductCategoryBaseVO { @NotBlank(message = "移动端分类图不能为空") private String picUrl; - @Schema(description = "PC 端分类图") - private String bigPicUrl; - @Schema(description = "分类排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Integer sort; @@ -35,4 +31,7 @@ public class ProductCategoryBaseVO { @NotNull(message = "开启状态不能为空") private Integer status; + @Schema(description = "分类描述", example = "描述") + private String description; + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryUpdateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryUpdateReqVO.java deleted file mode 100644 index 73909b756..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryUpdateReqVO.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.category.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 商品分类更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ProductCategoryUpdateReqVO extends ProductCategoryBaseVO { - - @Schema(description = "分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") - @NotNull(message = "分类编号不能为空") - private Long id; - - @Schema(description = "分类描述", example = "描述") - private String description; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/category/AppCategoryController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/category/AppCategoryController.java index c4999a867..7bf6529c0 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/category/AppCategoryController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/category/AppCategoryController.java @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryRespVO; -import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert; import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; import io.swagger.v3.oas.annotations.Operation; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/category/ProductCategoryConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/category/ProductCategoryConvert.java deleted file mode 100644 index 4c4ff3fb3..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/category/ProductCategoryConvert.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.product.convert.category; - -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryRespVO; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; -import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryRespVO; -import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * 商品分类 Convert - * - * @author 芋道源码 - */ -@Mapper -public interface ProductCategoryConvert { - - ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class); - - ProductCategoryDO convert(ProductCategoryCreateReqVO bean); - - ProductCategoryDO convert(ProductCategoryUpdateReqVO bean); - - ProductCategoryRespVO convert(ProductCategoryDO bean); - - List convertList(List list); - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/category/ProductCategoryDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/category/ProductCategoryDO.java index bf69e0028..78e35d6f5 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/category/ProductCategoryDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/category/ProductCategoryDO.java @@ -48,12 +48,6 @@ public class ProductCategoryDO extends BaseDO { * 建议 180*180 分辨率 */ private String picUrl; - /** - * PC 端分类图 - * - * 建议 468*340 分辨率 - */ - private String bigPicUrl; /** * 分类排序 */ diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryService.java index 08138b53a..5cacccdb5 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryService.java @@ -1,11 +1,10 @@ package cn.iocoder.yudao.module.product.service.category; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategorySaveReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; - import jakarta.validation.Valid; + import java.util.Collection; import java.util.List; @@ -22,14 +21,14 @@ public interface ProductCategoryService { * @param createReqVO 创建信息 * @return 编号 */ - Long createCategory(@Valid ProductCategoryCreateReqVO createReqVO); + Long createCategory(@Valid ProductCategorySaveReqVO createReqVO); /** * 更新商品分类 * * @param updateReqVO 更新信息 */ - void updateCategory(@Valid ProductCategoryUpdateReqVO updateReqVO); + void updateCategory(@Valid ProductCategorySaveReqVO updateReqVO); /** * 删除商品分类 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java index bfcebf696..64b8a6127 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java @@ -3,18 +3,17 @@ package cn.iocoder.yudao.module.product.service.category; import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; -import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategorySaveReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; import cn.iocoder.yudao.module.product.dal.mysql.category.ProductCategoryMapper; import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; +import jakarta.annotation.Resource; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import jakarta.annotation.Resource; import java.util.Collection; import java.util.List; import java.util.Map; @@ -40,26 +39,26 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { private ProductSpuService productSpuService; @Override - public Long createCategory(ProductCategoryCreateReqVO createReqVO) { + public Long createCategory(ProductCategorySaveReqVO createReqVO) { // 校验父分类存在 validateParentProductCategory(createReqVO.getParentId()); // 插入 - ProductCategoryDO category = ProductCategoryConvert.INSTANCE.convert(createReqVO); + ProductCategoryDO category = BeanUtils.toBean(createReqVO, ProductCategoryDO.class); productCategoryMapper.insert(category); // 返回 return category.getId(); } @Override - public void updateCategory(ProductCategoryUpdateReqVO updateReqVO) { + public void updateCategory(ProductCategorySaveReqVO updateReqVO) { // 校验分类是否存在 validateProductCategoryExists(updateReqVO.getId()); // 校验父分类存在 validateParentProductCategory(updateReqVO.getParentId()); // 更新 - ProductCategoryDO updateObj = ProductCategoryConvert.INSTANCE.convert(updateReqVO); + ProductCategoryDO updateObj = BeanUtils.toBean(updateReqVO, ProductCategoryDO.class); productCategoryMapper.updateById(updateObj); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImplTest.java index e919a4668..7c674e7d3 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImplTest.java +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImplTest.java @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategorySaveReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; import cn.iocoder.yudao.module.product.dal.mysql.category.ProductCategoryMapper; import org.junit.jupiter.api.Disabled; @@ -65,7 +65,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class); productCategoryMapper.insert(dbCategory);// @Sql: 先插入出一条存在的数据 // 准备参数 - ProductCategoryUpdateReqVO reqVO = randomPojo(ProductCategoryUpdateReqVO.class, o -> { + ProductCategorySaveReqVO reqVO = randomPojo(ProductCategorySaveReqVO.class, o -> { o.setId(dbCategory.getId()); // 设置更新的 ID }); // mock 父类 @@ -82,7 +82,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateCategory_notExists() { // 准备参数 - ProductCategoryUpdateReqVO reqVO = randomPojo(ProductCategoryUpdateReqVO.class); + ProductCategorySaveReqVO reqVO = randomPojo(ProductCategorySaveReqVO.class); // 调用, 并断言异常 assertServiceException(() -> productCategoryService.updateCategory(reqVO), CATEGORY_NOT_EXISTS);