Commit ed34b18d82ddba9cf25bb5f2e7ef0792ce3eab63

Authored by YunaiV
1 parent d58da7b2

✨ MALL:简化商品分类的 VO 转化

Showing 11 changed files with 50 additions and 121 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java
1 package cn.iocoder.yudao.module.product.controller.admin.category; 1 package cn.iocoder.yudao.module.product.controller.admin.category;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; 4 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; 5 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
6 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryRespVO; 6 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryRespVO;
7 -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO;  
8 -import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert; 7 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategorySaveReqVO;
9 import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; 8 import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
10 import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; 9 import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
11 import io.swagger.v3.oas.annotations.Operation; 10 import io.swagger.v3.oas.annotations.Operation;
12 import io.swagger.v3.oas.annotations.Parameter; 11 import io.swagger.v3.oas.annotations.Parameter;
13 import io.swagger.v3.oas.annotations.tags.Tag; 12 import io.swagger.v3.oas.annotations.tags.Tag;
  13 +import jakarta.annotation.Resource;
  14 +import jakarta.validation.Valid;
14 import org.springframework.security.access.prepost.PreAuthorize; 15 import org.springframework.security.access.prepost.PreAuthorize;
15 import org.springframework.validation.annotation.Validated; 16 import org.springframework.validation.annotation.Validated;
16 import org.springframework.web.bind.annotation.*; 17 import org.springframework.web.bind.annotation.*;
17 18
18 -import jakarta.annotation.Resource;  
19 -import jakarta.validation.Valid;  
20 import java.util.Comparator; 19 import java.util.Comparator;
21 import java.util.List; 20 import java.util.List;
22 21
@@ -34,14 +33,14 @@ public class ProductCategoryController { @@ -34,14 +33,14 @@ public class ProductCategoryController {
34 @PostMapping("/create") 33 @PostMapping("/create")
35 @Operation(summary = "创建商品分类") 34 @Operation(summary = "创建商品分类")
36 @PreAuthorize("@ss.hasPermission('product:category:create')") 35 @PreAuthorize("@ss.hasPermission('product:category:create')")
37 - public CommonResult<Long> createCategory(@Valid @RequestBody ProductCategoryCreateReqVO createReqVO) { 36 + public CommonResult<Long> createCategory(@Valid @RequestBody ProductCategorySaveReqVO createReqVO) {
38 return success(categoryService.createCategory(createReqVO)); 37 return success(categoryService.createCategory(createReqVO));
39 } 38 }
40 39
41 @PutMapping("/update") 40 @PutMapping("/update")
42 @Operation(summary = "更新商品分类") 41 @Operation(summary = "更新商品分类")
43 @PreAuthorize("@ss.hasPermission('product:category:update')") 42 @PreAuthorize("@ss.hasPermission('product:category:update')")
44 - public CommonResult<Boolean> updateCategory(@Valid @RequestBody ProductCategoryUpdateReqVO updateReqVO) { 43 + public CommonResult<Boolean> updateCategory(@Valid @RequestBody ProductCategorySaveReqVO updateReqVO) {
45 categoryService.updateCategory(updateReqVO); 44 categoryService.updateCategory(updateReqVO);
46 return success(true); 45 return success(true);
47 } 46 }
@@ -61,7 +60,7 @@ public class ProductCategoryController { @@ -61,7 +60,7 @@ public class ProductCategoryController {
61 @PreAuthorize("@ss.hasPermission('product:category:query')") 60 @PreAuthorize("@ss.hasPermission('product:category:query')")
62 public CommonResult<ProductCategoryRespVO> getCategory(@RequestParam("id") Long id) { 61 public CommonResult<ProductCategoryRespVO> getCategory(@RequestParam("id") Long id) {
63 ProductCategoryDO category = categoryService.getCategory(id); 62 ProductCategoryDO category = categoryService.getCategory(id);
64 - return success(ProductCategoryConvert.INSTANCE.convert(category)); 63 + return success(BeanUtils.toBean(category, ProductCategoryRespVO.class));
65 } 64 }
66 65
67 @GetMapping("/list") 66 @GetMapping("/list")
@@ -70,7 +69,7 @@ public class ProductCategoryController { @@ -70,7 +69,7 @@ public class ProductCategoryController {
70 public CommonResult<List<ProductCategoryRespVO>> getCategoryList(@Valid ProductCategoryListReqVO listReqVO) { 69 public CommonResult<List<ProductCategoryRespVO>> getCategoryList(@Valid ProductCategoryListReqVO listReqVO) {
71 List<ProductCategoryDO> list = categoryService.getCategoryList(listReqVO); 70 List<ProductCategoryDO> list = categoryService.getCategoryList(listReqVO);
72 list.sort(Comparator.comparing(ProductCategoryDO::getSort)); 71 list.sort(Comparator.comparing(ProductCategoryDO::getSort));
73 - return success(ProductCategoryConvert.INSTANCE.convertList(list)); 72 + return success(BeanUtils.toBean(list, ProductCategoryRespVO.class));
74 } 73 }
75 74
76 } 75 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryCreateReqVO.java deleted
1 -package cn.iocoder.yudao.module.product.controller.admin.category.vo;  
2 -  
3 -import io.swagger.v3.oas.annotations.media.Schema;  
4 -import lombok.Data;  
5 -import lombok.EqualsAndHashCode;  
6 -import lombok.ToString;  
7 -  
8 -import jakarta.validation.constraints.NotBlank;  
9 -  
10 -@Schema(description = "管理后台 - 商品分类创建 Request VO")  
11 -@Data  
12 -@EqualsAndHashCode(callSuper = true)  
13 -@ToString(callSuper = true)  
14 -public class ProductCategoryCreateReqVO extends ProductCategoryBaseVO {  
15 -  
16 - @Schema(description = "分类描述", example = "描述")  
17 - private String description;  
18 -  
19 -}  
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; @@ -2,20 +2,34 @@ package cn.iocoder.yudao.module.product.controller.admin.category.vo;
2 2
3 import io.swagger.v3.oas.annotations.media.Schema; 3 import io.swagger.v3.oas.annotations.media.Schema;
4 import lombok.Data; 4 import lombok.Data;
5 -import lombok.EqualsAndHashCode;  
6 -import lombok.ToString;  
7 5
8 import java.time.LocalDateTime; 6 import java.time.LocalDateTime;
9 7
10 @Schema(description = "管理后台 - 商品分类 Response VO") 8 @Schema(description = "管理后台 - 商品分类 Response VO")
11 @Data 9 @Data
12 -@EqualsAndHashCode(callSuper = true)  
13 -@ToString(callSuper = true)  
14 -public class ProductCategoryRespVO extends ProductCategoryBaseVO { 10 +public class ProductCategoryRespVO {
15 11
16 @Schema(description = "分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") 12 @Schema(description = "分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
17 private Long id; 13 private Long id;
18 14
  15 + @Schema(description = "父分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  16 + private Long parentId;
  17 +
  18 + @Schema(description = "分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "办公文具")
  19 + private String name;
  20 +
  21 + @Schema(description = "移动端分类图", requiredMode = Schema.RequiredMode.REQUIRED)
  22 + private String picUrl;
  23 +
  24 + @Schema(description = "分类排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  25 + private Integer sort;
  26 +
  27 + @Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
  28 + private Integer status;
  29 +
  30 + @Schema(description = "分类描述", example = "描述")
  31 + private String description;
  32 +
19 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) 33 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
20 private LocalDateTime createTime; 34 private LocalDateTime createTime;
21 35
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryBaseVO.java renamed to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategorySaveReqVO.java
1 package cn.iocoder.yudao.module.product.controller.admin.category.vo; 1 package cn.iocoder.yudao.module.product.controller.admin.category.vo;
2 2
3 import io.swagger.v3.oas.annotations.media.Schema; 3 import io.swagger.v3.oas.annotations.media.Schema;
4 -import lombok.Data;  
5 -  
6 import jakarta.validation.constraints.NotBlank; 4 import jakarta.validation.constraints.NotBlank;
7 import jakarta.validation.constraints.NotNull; 5 import jakarta.validation.constraints.NotNull;
  6 +import lombok.Data;
8 7
9 -/**  
10 -* 商品分类 Base VO,提供给添加、修改、详细的子 VO 使用  
11 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成  
12 -*/ 8 +@Schema(description = "管理后台 - 商品分类新增/更新 Request VO")
13 @Data 9 @Data
14 -public class ProductCategoryBaseVO { 10 +public class ProductCategorySaveReqVO {
  11 +
  12 + @Schema(description = "分类编号", example = "2")
  13 + private Long id;
15 14
16 @Schema(description = "父分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") 15 @Schema(description = "父分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
17 @NotNull(message = "父分类编号不能为空") 16 @NotNull(message = "父分类编号不能为空")
@@ -25,9 +24,6 @@ public class ProductCategoryBaseVO { @@ -25,9 +24,6 @@ public class ProductCategoryBaseVO {
25 @NotBlank(message = "移动端分类图不能为空") 24 @NotBlank(message = "移动端分类图不能为空")
26 private String picUrl; 25 private String picUrl;
27 26
28 - @Schema(description = "PC 端分类图")  
29 - private String bigPicUrl;  
30 -  
31 @Schema(description = "分类排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") 27 @Schema(description = "分类排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
32 private Integer sort; 28 private Integer sort;
33 29
@@ -35,4 +31,7 @@ public class ProductCategoryBaseVO { @@ -35,4 +31,7 @@ public class ProductCategoryBaseVO {
35 @NotNull(message = "开启状态不能为空") 31 @NotNull(message = "开启状态不能为空")
36 private Integer status; 32 private Integer status;
37 33
  34 + @Schema(description = "分类描述", example = "描述")
  35 + private String description;
  36 +
38 } 37 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryUpdateReqVO.java deleted
1 -package cn.iocoder.yudao.module.product.controller.admin.category.vo;  
2 -  
3 -import io.swagger.v3.oas.annotations.media.Schema;  
4 -import lombok.Data;  
5 -import lombok.EqualsAndHashCode;  
6 -import lombok.ToString;  
7 -  
8 -import jakarta.validation.constraints.NotBlank;  
9 -import jakarta.validation.constraints.NotNull;  
10 -  
11 -@Schema(description = "管理后台 - 商品分类更新 Request VO")  
12 -@Data  
13 -@EqualsAndHashCode(callSuper = true)  
14 -@ToString(callSuper = true)  
15 -public class ProductCategoryUpdateReqVO extends ProductCategoryBaseVO {  
16 -  
17 - @Schema(description = "分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")  
18 - @NotNull(message = "分类编号不能为空")  
19 - private Long id;  
20 -  
21 - @Schema(description = "分类描述", example = "描述")  
22 - private String description;  
23 -  
24 -}  
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; @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
4 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryRespVO; 6 import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryRespVO;
7 -import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert;  
8 import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; 7 import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
9 import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; 8 import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
10 import io.swagger.v3.oas.annotations.Operation; 9 import io.swagger.v3.oas.annotations.Operation;
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/category/ProductCategoryConvert.java deleted
1 -package cn.iocoder.yudao.module.product.convert.category;  
2 -  
3 -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO;  
4 -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryRespVO;  
5 -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO;  
6 -import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryRespVO;  
7 -import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;  
8 -import org.mapstruct.Mapper;  
9 -import org.mapstruct.factory.Mappers;  
10 -  
11 -import java.util.List;  
12 -  
13 -/**  
14 - * 商品分类 Convert  
15 - *  
16 - * @author 芋道源码  
17 - */  
18 -@Mapper  
19 -public interface ProductCategoryConvert {  
20 -  
21 - ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class);  
22 -  
23 - ProductCategoryDO convert(ProductCategoryCreateReqVO bean);  
24 -  
25 - ProductCategoryDO convert(ProductCategoryUpdateReqVO bean);  
26 -  
27 - ProductCategoryRespVO convert(ProductCategoryDO bean);  
28 -  
29 - List<ProductCategoryRespVO> convertList(List<ProductCategoryDO> list);  
30 -  
31 -}  
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/category/ProductCategoryDO.java
@@ -49,12 +49,6 @@ public class ProductCategoryDO extends BaseDO { @@ -49,12 +49,6 @@ public class ProductCategoryDO extends BaseDO {
49 */ 49 */
50 private String picUrl; 50 private String picUrl;
51 /** 51 /**
52 - * PC 端分类图  
53 - *  
54 - * 建议 468*340 分辨率  
55 - */  
56 - private String bigPicUrl;  
57 - /**  
58 * 分类排序 52 * 分类排序
59 */ 53 */
60 private Integer sort; 54 private Integer sort;
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryService.java
1 package cn.iocoder.yudao.module.product.service.category; 1 package cn.iocoder.yudao.module.product.service.category;
2 2
3 -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO;  
4 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; 3 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
5 -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; 4 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategorySaveReqVO;
6 import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; 5 import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
7 -  
8 import jakarta.validation.Valid; 6 import jakarta.validation.Valid;
  7 +
9 import java.util.Collection; 8 import java.util.Collection;
10 import java.util.List; 9 import java.util.List;
11 10
@@ -22,14 +21,14 @@ public interface ProductCategoryService { @@ -22,14 +21,14 @@ public interface ProductCategoryService {
22 * @param createReqVO 创建信息 21 * @param createReqVO 创建信息
23 * @return 编号 22 * @return 编号
24 */ 23 */
25 - Long createCategory(@Valid ProductCategoryCreateReqVO createReqVO); 24 + Long createCategory(@Valid ProductCategorySaveReqVO createReqVO);
26 25
27 /** 26 /**
28 * 更新商品分类 27 * 更新商品分类
29 * 28 *
30 * @param updateReqVO 更新信息 29 * @param updateReqVO 更新信息
31 */ 30 */
32 - void updateCategory(@Valid ProductCategoryUpdateReqVO updateReqVO); 31 + void updateCategory(@Valid ProductCategorySaveReqVO updateReqVO);
33 32
34 /** 33 /**
35 * 删除商品分类 34 * 删除商品分类
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; @@ -3,18 +3,17 @@ package cn.iocoder.yudao.module.product.service.category;
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
4 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; 4 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
5 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; 5 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
6 -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; 6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
7 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; 7 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
8 -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO;  
9 -import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert; 8 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategorySaveReqVO;
10 import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; 9 import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
11 import cn.iocoder.yudao.module.product.dal.mysql.category.ProductCategoryMapper; 10 import cn.iocoder.yudao.module.product.dal.mysql.category.ProductCategoryMapper;
12 import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; 11 import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
  12 +import jakarta.annotation.Resource;
13 import org.springframework.context.annotation.Lazy; 13 import org.springframework.context.annotation.Lazy;
14 import org.springframework.stereotype.Service; 14 import org.springframework.stereotype.Service;
15 import org.springframework.validation.annotation.Validated; 15 import org.springframework.validation.annotation.Validated;
16 16
17 -import jakarta.annotation.Resource;  
18 import java.util.Collection; 17 import java.util.Collection;
19 import java.util.List; 18 import java.util.List;
20 import java.util.Map; 19 import java.util.Map;
@@ -40,26 +39,26 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { @@ -40,26 +39,26 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
40 private ProductSpuService productSpuService; 39 private ProductSpuService productSpuService;
41 40
42 @Override 41 @Override
43 - public Long createCategory(ProductCategoryCreateReqVO createReqVO) { 42 + public Long createCategory(ProductCategorySaveReqVO createReqVO) {
44 // 校验父分类存在 43 // 校验父分类存在
45 validateParentProductCategory(createReqVO.getParentId()); 44 validateParentProductCategory(createReqVO.getParentId());
46 45
47 // 插入 46 // 插入
48 - ProductCategoryDO category = ProductCategoryConvert.INSTANCE.convert(createReqVO); 47 + ProductCategoryDO category = BeanUtils.toBean(createReqVO, ProductCategoryDO.class);
49 productCategoryMapper.insert(category); 48 productCategoryMapper.insert(category);
50 // 返回 49 // 返回
51 return category.getId(); 50 return category.getId();
52 } 51 }
53 52
54 @Override 53 @Override
55 - public void updateCategory(ProductCategoryUpdateReqVO updateReqVO) { 54 + public void updateCategory(ProductCategorySaveReqVO updateReqVO) {
56 // 校验分类是否存在 55 // 校验分类是否存在
57 validateProductCategoryExists(updateReqVO.getId()); 56 validateProductCategoryExists(updateReqVO.getId());
58 // 校验父分类存在 57 // 校验父分类存在
59 validateParentProductCategory(updateReqVO.getParentId()); 58 validateParentProductCategory(updateReqVO.getParentId());
60 59
61 // 更新 60 // 更新
62 - ProductCategoryDO updateObj = ProductCategoryConvert.INSTANCE.convert(updateReqVO); 61 + ProductCategoryDO updateObj = BeanUtils.toBean(updateReqVO, ProductCategoryDO.class);
63 productCategoryMapper.updateById(updateObj); 62 productCategoryMapper.updateById(updateObj);
64 } 63 }
65 64
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; @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; 4 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
5 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; 5 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO;
6 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; 6 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
7 -import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; 7 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategorySaveReqVO;
8 import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; 8 import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
9 import cn.iocoder.yudao.module.product.dal.mysql.category.ProductCategoryMapper; 9 import cn.iocoder.yudao.module.product.dal.mysql.category.ProductCategoryMapper;
10 import org.junit.jupiter.api.Disabled; 10 import org.junit.jupiter.api.Disabled;
@@ -65,7 +65,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { @@ -65,7 +65,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest {
65 ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class); 65 ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class);
66 productCategoryMapper.insert(dbCategory);// @Sql: 先插入出一条存在的数据 66 productCategoryMapper.insert(dbCategory);// @Sql: 先插入出一条存在的数据
67 // 准备参数 67 // 准备参数
68 - ProductCategoryUpdateReqVO reqVO = randomPojo(ProductCategoryUpdateReqVO.class, o -> { 68 + ProductCategorySaveReqVO reqVO = randomPojo(ProductCategorySaveReqVO.class, o -> {
69 o.setId(dbCategory.getId()); // 设置更新的 ID 69 o.setId(dbCategory.getId()); // 设置更新的 ID
70 }); 70 });
71 // mock 父类 71 // mock 父类
@@ -82,7 +82,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { @@ -82,7 +82,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest {
82 @Test 82 @Test
83 public void testUpdateCategory_notExists() { 83 public void testUpdateCategory_notExists() {
84 // 准备参数 84 // 准备参数
85 - ProductCategoryUpdateReqVO reqVO = randomPojo(ProductCategoryUpdateReqVO.class); 85 + ProductCategorySaveReqVO reqVO = randomPojo(ProductCategorySaveReqVO.class);
86 86
87 // 调用, 并断言异常 87 // 调用, 并断言异常
88 assertServiceException(() -> productCategoryService.updateCategory(reqVO), CATEGORY_NOT_EXISTS); 88 assertServiceException(() -> productCategoryService.updateCategory(reqVO), CATEGORY_NOT_EXISTS);