Commit fa9823161e785c38bcf7d4edc910921d41a21699

Authored by YunaiV
1 parent efd49421

mall:完善商品品牌的前后端实现

Showing 22 changed files with 287 additions and 566 deletions
sql/optional/mall/mall.sql
@@ -24,64 +24,6 @@ SET NAMES utf8mb4; @@ -24,64 +24,6 @@ SET NAMES utf8mb4;
24 -- ---------------------------- 24 -- ----------------------------
25 -- Table structure for product_brand 25 -- Table structure for product_brand
26 -- ---------------------------- 26 -- ----------------------------
27 -DROP TABLE IF EXISTS `product_brand`;  
28 -CREATE TABLE `product_brand`  
29 -(  
30 - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '品牌编号',  
31 - `category_id` bigint NOT NULL COMMENT '分类编号',  
32 - `name` varchar(255) NOT NULL COMMENT '品牌名称',  
33 - `banner_url` varchar(255) NOT NULL COMMENT '品牌图片',  
34 - `sort` int DEFAULT '0' COMMENT '品牌排序',  
35 - `description` varchar(1024) DEFAULT NULL COMMENT '品牌描述',  
36 - `status` tinyint NOT NULL COMMENT '状态',  
37 - `creator` varchar(64) DEFAULT '' COMMENT '创建者',  
38 - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',  
39 - `updater` varchar(64) DEFAULT '' COMMENT '更新者',  
40 - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',  
41 - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',  
42 - `tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号',  
43 - PRIMARY KEY (`id`) USING BTREE  
44 -) ENGINE=InnoDB COMMENT='品牌';  
45 -  
46 --- TODO 父级菜单的 id 处理: 2000 、 2001  
47 -INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
48 -VALUES (2000, '商城', '', 1, 1, 0, '/mall', 'merchant', NULL, 0);  
49 -INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
50 -VALUES (2001, '商品', '', 1, 1, 2000, 'product', 'dict', NULL, 0);  
51 --- 商品分类 菜单 SQL  
52 -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
53 -VALUES ('分类管理', '', 2, 0, 2001, 'category', '', 'mall/product/category/index', 0);  
54 --- 按钮父菜单ID  
55 -SELECT @parentId := LAST_INSERT_ID();  
56 --- 按钮 SQL  
57 -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
58 -VALUES ('分类查询', 'product:category:query', 3, 1, @parentId, '', '', '', 0);  
59 -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
60 -VALUES ('分类创建', 'product:category:create', 3, 2, @parentId, '', '', '', 0);  
61 -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
62 -VALUES ('分类更新', 'product:category:update', 3, 3, @parentId, '', '', '', 0);  
63 -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
64 -VALUES ('分类删除', 'product:category:delete', 3, 4, @parentId, '', '', '', 0);  
65 -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
66 -VALUES ('分类导出', 'product:category:export', 3, 5, @parentId, '', '', '', 0);  
67 -  
68 --- 品牌管理 菜单 SQL  
69 -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
70 -VALUES ('品牌管理', '', 2, 1, 2001, 'brand', '', 'mall/product/brand/index', 0);  
71 --- 按钮父菜单ID  
72 -SELECT @parentId := LAST_INSERT_ID();  
73 --- 按钮 SQL  
74 -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
75 -VALUES ('品牌查询', 'product:brand:query', 3, 1, @parentId, '', '', '', 0);  
76 -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
77 -VALUES ('品牌创建', 'product:brand:create', 3, 2, @parentId, '', '', '', 0);  
78 -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
79 -VALUES ('品牌更新', 'product:brand:update', 3, 3, @parentId, '', '', '', 0);  
80 -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
81 -VALUES ('品牌删除', 'product:brand:delete', 3, 4, @parentId, '', '', '', 0);  
82 -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)  
83 -VALUES ('品牌导出', 'product:brand:export', 3, 5, @parentId, '', '', '', 0);  
84 -  
85 27
86 -- ---------------------------- 28 -- ----------------------------
87 -- Table structure for market_activity 29 -- Table structure for market_activity
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java
@@ -17,7 +17,7 @@ public interface ErrorCodeConstants { @@ -17,7 +17,7 @@ public interface ErrorCodeConstants {
17 ErrorCode PRODUCT_CATEGORY_DISABLED = new ErrorCode(1008001004, "商品分类({})已禁用,无法使用"); 17 ErrorCode PRODUCT_CATEGORY_DISABLED = new ErrorCode(1008001004, "商品分类({})已禁用,无法使用");
18 18
19 // ========== 品牌相关编号 1008002000 ========== 19 // ========== 品牌相关编号 1008002000 ==========
20 - ErrorCode BRAND_NOT_EXISTS = new ErrorCode(1008002000, "品牌不存在"); 20 + ErrorCode PRODUCT_BRAND_NOT_EXISTS = new ErrorCode(1008002000, "品牌不存在");
21 21
22 // ========== 规格名称 1008003000 ========== 22 // ========== 规格名称 1008003000 ==========
23 ErrorCode PROPERTY_NOT_EXISTS = new ErrorCode(1008003000, "规格名称不存在"); 23 ErrorCode PROPERTY_NOT_EXISTS = new ErrorCode(1008003000, "规格名称不存在");
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/BrandController.java renamed to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java
@@ -5,9 +5,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -5,9 +5,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; 5 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
6 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; 6 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
7 import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; 7 import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;
8 -import cn.iocoder.yudao.module.product.convert.brand.BrandConvert;  
9 -import cn.iocoder.yudao.module.product.dal.dataobject.brand.BrandDO;  
10 -import cn.iocoder.yudao.module.product.service.brand.BrandService; 8 +import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert;
  9 +import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
  10 +import cn.iocoder.yudao.module.product.service.brand.ProductBrandService;
11 import io.swagger.annotations.Api; 11 import io.swagger.annotations.Api;
12 import io.swagger.annotations.ApiImplicitParam; 12 import io.swagger.annotations.ApiImplicitParam;
13 import io.swagger.annotations.ApiOperation; 13 import io.swagger.annotations.ApiOperation;
@@ -24,26 +24,26 @@ import java.util.List; @@ -24,26 +24,26 @@ import java.util.List;
24 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 24 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
25 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; 25 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
26 26
27 -@Api(tags = "管理后台 - 品牌") 27 +@Api(tags = "管理后台 - 商品品牌")
28 @RestController 28 @RestController
29 @RequestMapping("/product/brand") 29 @RequestMapping("/product/brand")
30 @Validated 30 @Validated
31 -public class BrandController { 31 +public class ProductBrandController {
32 32
33 @Resource 33 @Resource
34 - private BrandService brandService; 34 + private ProductBrandService brandService;
35 35
36 @PostMapping("/create") 36 @PostMapping("/create")
37 @ApiOperation("创建品牌") 37 @ApiOperation("创建品牌")
38 @PreAuthorize("@ss.hasPermission('product:brand:create')") 38 @PreAuthorize("@ss.hasPermission('product:brand:create')")
39 - public CommonResult<Long> createBrand(@Valid @RequestBody BrandCreateReqVO createReqVO) {  
40 - return success(brandService.createBrand(createReqVO)); 39 + public CommonResult<Long> createBrand(@Valid @RequestBody ProductBrandCreateReqVO createReqVO) {
  40 + return success(brandService.createProductBrand(createReqVO));
41 } 41 }
42 42
43 @PutMapping("/update") 43 @PutMapping("/update")
44 @ApiOperation("更新品牌") 44 @ApiOperation("更新品牌")
45 @PreAuthorize("@ss.hasPermission('product:brand:update')") 45 @PreAuthorize("@ss.hasPermission('product:brand:update')")
46 - public CommonResult<Boolean> updateBrand(@Valid @RequestBody BrandUpdateReqVO updateReqVO) { 46 + public CommonResult<Boolean> updateBrand(@Valid @RequestBody ProductBrandUpdateReqVO updateReqVO) {
47 brandService.updateBrand(updateReqVO); 47 brandService.updateBrand(updateReqVO);
48 return success(true); 48 return success(true);
49 } 49 }
@@ -61,29 +61,17 @@ public class BrandController { @@ -61,29 +61,17 @@ public class BrandController {
61 @ApiOperation("获得品牌") 61 @ApiOperation("获得品牌")
62 @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) 62 @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
63 @PreAuthorize("@ss.hasPermission('product:brand:query')") 63 @PreAuthorize("@ss.hasPermission('product:brand:query')")
64 - public CommonResult<BrandRespVO> getBrand(@RequestParam("id") Long id) {  
65 - BrandDO brand = brandService.getBrand(id);  
66 - return success(BrandConvert.INSTANCE.convert(brand)); 64 + public CommonResult<ProductBrandRespVO> getBrand(@RequestParam("id") Long id) {
  65 + ProductBrandDO brand = brandService.getBrand(id);
  66 + return success(ProductBrandConvert.INSTANCE.convert(brand));
67 } 67 }
68 68
69 @GetMapping("/page") 69 @GetMapping("/page")
70 @ApiOperation("获得品牌分页") 70 @ApiOperation("获得品牌分页")
71 @PreAuthorize("@ss.hasPermission('product:brand:query')") 71 @PreAuthorize("@ss.hasPermission('product:brand:query')")
72 - public CommonResult<PageResult<BrandRespVO>> getBrandPage(@Valid BrandPageReqVO pageVO) {  
73 - PageResult<BrandDO> pageResult = brandService.getBrandPage(pageVO);  
74 - return success(BrandConvert.INSTANCE.convertPage(pageResult));  
75 - }  
76 -  
77 - @GetMapping("/export-excel")  
78 - @ApiOperation("导出品牌 Excel")  
79 - @PreAuthorize("@ss.hasPermission('product:brand:export')")  
80 - @OperateLog(type = EXPORT)  
81 - public void exportBrandExcel(@Valid BrandExportReqVO exportReqVO,  
82 - HttpServletResponse response) throws IOException {  
83 - List<BrandDO> list = brandService.getBrandList(exportReqVO);  
84 - // 导出 Excel  
85 - List<BrandExcelVO> datas = BrandConvert.INSTANCE.convertList02(list);  
86 - ExcelUtils.write(response, "品牌.xls", "数据", BrandExcelVO.class, datas); 72 + public CommonResult<PageResult<ProductBrandRespVO>> getBrandPage(@Valid ProductBrandPageReqVO pageVO) {
  73 + PageResult<ProductBrandDO> pageResult = brandService.getBrandPage(pageVO);
  74 + return success(ProductBrandConvert.INSTANCE.convertPage(pageResult));
87 } 75 }
88 76
89 } 77 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandExcelVO.java deleted
1 -package cn.iocoder.yudao.module.product.controller.admin.brand.vo;  
2 -  
3 -import lombok.*;  
4 -import java.util.*;  
5 -import io.swagger.annotations.*;  
6 -  
7 -import com.alibaba.excel.annotation.ExcelProperty;  
8 -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;  
9 -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;  
10 -  
11 -  
12 -/**  
13 - * 品牌 Excel VO  
14 - *  
15 - * @author 芋道源码  
16 - */  
17 -@Data  
18 -public class BrandExcelVO {  
19 -  
20 - @ExcelProperty("品牌编号")  
21 - private Long id;  
22 -  
23 - @ExcelProperty("分类编号")  
24 - private Long categoryId;  
25 -  
26 - @ExcelProperty("品牌名称")  
27 - private String name;  
28 -  
29 - @ExcelProperty("品牌图片")  
30 - private String bannerUrl;  
31 -  
32 - @ExcelProperty("品牌排序")  
33 - private Integer sort;  
34 -  
35 - @ExcelProperty("品牌描述")  
36 - private String description;  
37 -  
38 - @ExcelProperty(value = "状态", converter = DictConvert.class)  
39 - @DictFormat("common_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中  
40 - private Integer status;  
41 -  
42 - @ExcelProperty("创建时间")  
43 - private Date createTime;  
44 -  
45 -}  
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandExportReqVO.java deleted
1 -package cn.iocoder.yudao.module.product.controller.admin.brand.vo;  
2 -  
3 -import lombok.*;  
4 -import java.util.*;  
5 -import io.swagger.annotations.*;  
6 -import cn.iocoder.yudao.framework.common.pojo.PageParam;  
7 -import org.springframework.format.annotation.DateTimeFormat;  
8 -  
9 -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;  
10 -  
11 -@ApiModel(value = "管理后台 - 品牌 Excel 导出 Request VO", description = "参数和 BrandPageReqVO 是一致的")  
12 -@Data  
13 -public class BrandExportReqVO {  
14 -  
15 - @ApiModelProperty(value = "分类编号", example = "1")  
16 - private Long categoryId;  
17 -  
18 - @ApiModelProperty(value = "品牌名称", example = "芋道")  
19 - private String name;  
20 -  
21 - @ApiModelProperty(value = "状态", example = "0")  
22 - private Integer status;  
23 -  
24 - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)  
25 - @ApiModelProperty(value = "创建时间")  
26 - private Date[] createTime;  
27 -  
28 -}  
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandBaseVO.java renamed to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandBaseVO.java
1 package cn.iocoder.yudao.module.product.controller.admin.brand.vo; 1 package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
2 2
3 -import lombok.*;  
4 -import java.util.*;  
5 -import io.swagger.annotations.*;  
6 -import javax.validation.constraints.*; 3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.constraints.NotNull;
7 7
8 /** 8 /**
9 -* 品牌 Base VO,提供给添加、修改、详细的子 VO 使用 9 +* 商品品牌 Base VO,提供给添加、修改、详细的子 VO 使用
10 * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 10 * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
11 */ 11 */
12 @Data 12 @Data
13 -public class BrandBaseVO {  
14 -  
15 - @ApiModelProperty(value = "分类编号", required = true, example = "1")  
16 - @NotNull(message = "分类编号不能为空")  
17 - private Long categoryId; 13 +public class ProductBrandBaseVO {
18 14
19 @ApiModelProperty(value = "品牌名称", required = true, example = "芋道") 15 @ApiModelProperty(value = "品牌名称", required = true, example = "芋道")
20 @NotNull(message = "品牌名称不能为空") 16 @NotNull(message = "品牌名称不能为空")
@@ -22,7 +18,7 @@ public class BrandBaseVO { @@ -22,7 +18,7 @@ public class BrandBaseVO {
22 18
23 @ApiModelProperty(value = "品牌图片", required = true) 19 @ApiModelProperty(value = "品牌图片", required = true)
24 @NotNull(message = "品牌图片不能为空") 20 @NotNull(message = "品牌图片不能为空")
25 - private String bannerUrl; 21 + private String picUrl;
26 22
27 @ApiModelProperty(value = "品牌排序", example = "1") 23 @ApiModelProperty(value = "品牌排序", example = "1")
28 private Integer sort; 24 private Integer sort;
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandCreateReqVO.java renamed to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandCreateReqVO.java
1 package cn.iocoder.yudao.module.product.controller.admin.brand.vo; 1 package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
2 2
3 import lombok.*; 3 import lombok.*;
4 -import java.util.*;  
5 import io.swagger.annotations.*; 4 import io.swagger.annotations.*;
6 -import javax.validation.constraints.*;  
7 5
8 -@ApiModel("管理后台 - 品牌创建 Request VO") 6 +@ApiModel("管理后台 - 商品品牌创建 Request VO")
9 @Data 7 @Data
10 @EqualsAndHashCode(callSuper = true) 8 @EqualsAndHashCode(callSuper = true)
11 @ToString(callSuper = true) 9 @ToString(callSuper = true)
12 -public class BrandCreateReqVO extends BrandBaseVO { 10 +public class ProductBrandCreateReqVO extends ProductBrandBaseVO {
13 11
14 } 12 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandPageReqVO.java renamed to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandPageReqVO.java
1 package cn.iocoder.yudao.module.product.controller.admin.brand.vo; 1 package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
2 2
3 -import lombok.*;  
4 -import java.util.*;  
5 -import io.swagger.annotations.*;  
6 import cn.iocoder.yudao.framework.common.pojo.PageParam; 3 import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.annotations.ApiModel;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import lombok.Data;
  7 +import lombok.EqualsAndHashCode;
  8 +import lombok.ToString;
7 import org.springframework.format.annotation.DateTimeFormat; 9 import org.springframework.format.annotation.DateTimeFormat;
8 10
  11 +import java.util.Date;
  12 +
9 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; 13 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
10 14
11 -@ApiModel("管理后台 - 品牌分页 Request VO") 15 +@ApiModel("管理后台 - 商品品牌分页 Request VO")
12 @Data 16 @Data
13 @EqualsAndHashCode(callSuper = true) 17 @EqualsAndHashCode(callSuper = true)
14 @ToString(callSuper = true) 18 @ToString(callSuper = true)
15 -public class BrandPageReqVO extends PageParam {  
16 -  
17 - @ApiModelProperty(value = "分类编号", example = "1")  
18 - private Long categoryId; 19 +public class ProductBrandPageReqVO extends PageParam {
19 20
20 @ApiModelProperty(value = "品牌名称", example = "芋道") 21 @ApiModelProperty(value = "品牌名称", example = "芋道")
21 private String name; 22 private String name;
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandRespVO.java renamed to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandRespVO.java
1 package cn.iocoder.yudao.module.product.controller.admin.brand.vo; 1 package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
2 2
3 -import lombok.*;  
4 -import java.util.*;  
5 -import io.swagger.annotations.*; 3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import lombok.ToString;
  8 +
  9 +import java.util.Date;
6 10
7 @ApiModel("管理后台 - 品牌 Response VO") 11 @ApiModel("管理后台 - 品牌 Response VO")
8 @Data 12 @Data
9 @EqualsAndHashCode(callSuper = true) 13 @EqualsAndHashCode(callSuper = true)
10 @ToString(callSuper = true) 14 @ToString(callSuper = true)
11 -public class BrandRespVO extends BrandBaseVO { 15 +public class ProductBrandRespVO extends ProductBrandBaseVO {
12 16
13 @ApiModelProperty(value = "品牌编号", required = true, example = "1") 17 @ApiModelProperty(value = "品牌编号", required = true, example = "1")
14 private Long id; 18 private Long id;
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandUpdateReqVO.java renamed to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandUpdateReqVO.java
1 package cn.iocoder.yudao.module.product.controller.admin.brand.vo; 1 package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
2 2
3 import lombok.*; 3 import lombok.*;
4 -import java.util.*;  
5 import io.swagger.annotations.*; 4 import io.swagger.annotations.*;
6 import javax.validation.constraints.*; 5 import javax.validation.constraints.*;
7 6
8 -@ApiModel("管理后台 - 品牌更新 Request VO") 7 +@ApiModel("管理后台 - 商品品牌更新 Request VO")
9 @Data 8 @Data
10 @EqualsAndHashCode(callSuper = true) 9 @EqualsAndHashCode(callSuper = true)
11 @ToString(callSuper = true) 10 @ToString(callSuper = true)
12 -public class BrandUpdateReqVO extends BrandBaseVO { 11 +public class ProductBrandUpdateReqVO extends ProductBrandBaseVO {
13 12
14 @ApiModelProperty(value = "品牌编号", required = true, example = "1") 13 @ApiModelProperty(value = "品牌编号", required = true, example = "1")
15 @NotNull(message = "品牌编号不能为空") 14 @NotNull(message = "品牌编号不能为空")
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/brand/BrandConvert.java deleted
1 -package cn.iocoder.yudao.module.product.convert.brand;  
2 -  
3 -import java.util.*;  
4 -  
5 -import cn.iocoder.yudao.framework.common.pojo.PageResult;  
6 -  
7 -import org.mapstruct.Mapper;  
8 -import org.mapstruct.factory.Mappers;  
9 -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;  
10 -import cn.iocoder.yudao.module.product.dal.dataobject.brand.BrandDO;  
11 -  
12 -/**  
13 - * 品牌 Convert  
14 - *  
15 - * @author 芋道源码  
16 - */  
17 -@Mapper  
18 -public interface BrandConvert {  
19 -  
20 - BrandConvert INSTANCE = Mappers.getMapper(BrandConvert.class);  
21 -  
22 - BrandDO convert(BrandCreateReqVO bean);  
23 -  
24 - BrandDO convert(BrandUpdateReqVO bean);  
25 -  
26 - BrandRespVO convert(BrandDO bean);  
27 -  
28 - List<BrandRespVO> convertList(List<BrandDO> list);  
29 -  
30 - PageResult<BrandRespVO> convertPage(PageResult<BrandDO> page);  
31 -  
32 - List<BrandExcelVO> convertList02(List<BrandDO> list);  
33 -  
34 -}  
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/brand/ProductBrandConvert.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.convert.brand;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO;
  5 +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandRespVO;
  6 +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO;
  7 +import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
  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 ProductBrandConvert {
  20 +
  21 + ProductBrandConvert INSTANCE = Mappers.getMapper(ProductBrandConvert.class);
  22 +
  23 + ProductBrandDO convert(ProductBrandCreateReqVO bean);
  24 +
  25 + ProductBrandDO convert(ProductBrandUpdateReqVO bean);
  26 +
  27 + ProductBrandRespVO convert(ProductBrandDO bean);
  28 +
  29 + List<ProductBrandRespVO> convertList(List<ProductBrandDO> list);
  30 +
  31 + PageResult<ProductBrandRespVO> convertPage(PageResult<ProductBrandDO> page);
  32 +
  33 +}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/brand/BrandDO.java renamed to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/brand/ProductBrandDO.java
@@ -6,9 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableId; @@ -6,9 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
6 import com.baomidou.mybatisplus.annotation.TableName; 6 import com.baomidou.mybatisplus.annotation.TableName;
7 import lombok.*; 7 import lombok.*;
8 8
9 -// TODO @JeromeSoar:Product 前缀  
10 /** 9 /**
11 - * 品牌 DO 10 + * 商品品牌 DO
12 * 11 *
13 * @author 芋道源码 12 * @author 芋道源码
14 */ 13 */
@@ -19,7 +18,7 @@ import lombok.*; @@ -19,7 +18,7 @@ import lombok.*;
19 @Builder 18 @Builder
20 @NoArgsConstructor 19 @NoArgsConstructor
21 @AllArgsConstructor 20 @AllArgsConstructor
22 -public class BrandDO extends BaseDO { 21 +public class ProductBrandDO extends BaseDO {
23 22
24 /** 23 /**
25 * 品牌编号 24 * 品牌编号
@@ -27,17 +26,13 @@ public class BrandDO extends BaseDO { @@ -27,17 +26,13 @@ public class BrandDO extends BaseDO {
27 @TableId 26 @TableId
28 private Long id; 27 private Long id;
29 /** 28 /**
30 - * 分类编号  
31 - */  
32 - private Long categoryId;  
33 - /**  
34 * 品牌名称 29 * 品牌名称
35 */ 30 */
36 private String name; 31 private String name;
37 /** 32 /**
38 * 品牌图片 33 * 品牌图片
39 */ 34 */
40 - private String bannerUrl; 35 + private String picUrl;
41 /** 36 /**
42 * 品牌排序 37 * 品牌排序
43 */ 38 */
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/BrandMapper.java deleted
1 -package cn.iocoder.yudao.module.product.dal.mysql.brand;  
2 -  
3 -import java.util.*;  
4 -  
5 -import cn.iocoder.yudao.framework.common.pojo.PageResult;  
6 -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;  
7 -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;  
8 -import cn.iocoder.yudao.module.product.dal.dataobject.brand.BrandDO;  
9 -import org.apache.ibatis.annotations.Mapper;  
10 -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;  
11 -  
12 -/**  
13 - * 品牌 Mapper  
14 - *  
15 - * @author 芋道源码  
16 - */  
17 -@Mapper  
18 -public interface BrandMapper extends BaseMapperX<BrandDO> {  
19 -  
20 - default PageResult<BrandDO> selectPage(BrandPageReqVO reqVO) {  
21 - return selectPage(reqVO, new LambdaQueryWrapperX<BrandDO>()  
22 - .eqIfPresent(BrandDO::getCategoryId, reqVO.getCategoryId())  
23 - .likeIfPresent(BrandDO::getName, reqVO.getName())  
24 - .eqIfPresent(BrandDO::getStatus, reqVO.getStatus())  
25 - .betweenIfPresent(BrandDO::getCreateTime, reqVO.getCreateTime())  
26 - .orderByDesc(BrandDO::getId));  
27 - }  
28 -  
29 - default List<BrandDO> selectList(BrandExportReqVO reqVO) {  
30 - return selectList(new LambdaQueryWrapperX<BrandDO>()  
31 - .eqIfPresent(BrandDO::getCategoryId, reqVO.getCategoryId())  
32 - .likeIfPresent(BrandDO::getName, reqVO.getName())  
33 - .eqIfPresent(BrandDO::getStatus, reqVO.getStatus())  
34 - .betweenIfPresent(BrandDO::getCreateTime, reqVO.getCreateTime())  
35 - .orderByDesc(BrandDO::getId));  
36 - }  
37 -  
38 -}  
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.dal.mysql.brand;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO;
  7 +import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +@Mapper
  11 +public interface ProductBrandMapper extends BaseMapperX<ProductBrandDO> {
  12 +
  13 + default PageResult<ProductBrandDO> selectPage(ProductBrandPageReqVO reqVO) {
  14 + return selectPage(reqVO, new LambdaQueryWrapperX<ProductBrandDO>()
  15 + .likeIfPresent(ProductBrandDO::getName, reqVO.getName())
  16 + .eqIfPresent(ProductBrandDO::getStatus, reqVO.getStatus())
  17 + .betweenIfPresent(ProductBrandDO::getCreateTime, reqVO.getCreateTime())
  18 + .orderByDesc(ProductBrandDO::getId));
  19 + }
  20 +
  21 +}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandService.java renamed to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java
1 package cn.iocoder.yudao.module.product.service.brand; 1 package cn.iocoder.yudao.module.product.service.brand;
2 2
3 -import java.util.*;  
4 -import javax.validation.*;  
5 -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;  
6 -import cn.iocoder.yudao.module.product.dal.dataobject.brand.BrandDO;  
7 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO;
  5 +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO;
  6 +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO;
  7 +import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
  8 +
  9 +import javax.validation.Valid;
  10 +import java.util.Collection;
  11 +import java.util.List;
8 12
9 /** 13 /**
10 - * 品牌 Service 接口 14 + * 商品品牌 Service 接口
11 * 15 *
12 * @author 芋道源码 16 * @author 芋道源码
13 */ 17 */
14 -public interface BrandService { 18 +public interface ProductBrandService {
15 19
16 /** 20 /**
17 * 创建品牌 21 * 创建品牌
@@ -19,14 +23,14 @@ public interface BrandService { @@ -19,14 +23,14 @@ public interface BrandService {
19 * @param createReqVO 创建信息 23 * @param createReqVO 创建信息
20 * @return 编号 24 * @return 编号
21 */ 25 */
22 - Long createBrand(@Valid BrandCreateReqVO createReqVO); 26 + Long createProductBrand(@Valid ProductBrandCreateReqVO createReqVO);
23 27
24 /** 28 /**
25 * 更新品牌 29 * 更新品牌
26 * 30 *
27 * @param updateReqVO 更新信息 31 * @param updateReqVO 更新信息
28 */ 32 */
29 - void updateBrand(@Valid BrandUpdateReqVO updateReqVO); 33 + void updateBrand(@Valid ProductBrandUpdateReqVO updateReqVO);
30 34
31 /** 35 /**
32 * 删除品牌 36 * 删除品牌
@@ -41,7 +45,7 @@ public interface BrandService { @@ -41,7 +45,7 @@ public interface BrandService {
41 * @param id 编号 45 * @param id 编号
42 * @return 品牌 46 * @return 品牌
43 */ 47 */
44 - BrandDO getBrand(Long id); 48 + ProductBrandDO getBrand(Long id);
45 49
46 /** 50 /**
47 * 获得品牌列表 51 * 获得品牌列表
@@ -49,7 +53,7 @@ public interface BrandService { @@ -49,7 +53,7 @@ public interface BrandService {
49 * @param ids 编号 53 * @param ids 编号
50 * @return 品牌列表 54 * @return 品牌列表
51 */ 55 */
52 - List<BrandDO> getBrandList(Collection<Long> ids); 56 + List<ProductBrandDO> getBrandList(Collection<Long> ids);
53 57
54 /** 58 /**
55 * 获得品牌分页 59 * 获得品牌分页
@@ -57,14 +61,6 @@ public interface BrandService { @@ -57,14 +61,6 @@ public interface BrandService {
57 * @param pageReqVO 分页查询 61 * @param pageReqVO 分页查询
58 * @return 品牌分页 62 * @return 品牌分页
59 */ 63 */
60 - PageResult<BrandDO> getBrandPage(BrandPageReqVO pageReqVO);  
61 -  
62 - /**  
63 - * 获得品牌列表, 用于 Excel 导出  
64 - *  
65 - * @param exportReqVO 查询条件  
66 - * @return 品牌列表  
67 - */  
68 - List<BrandDO> getBrandList(BrandExportReqVO exportReqVO); 64 + PageResult<ProductBrandDO> getBrandPage(ProductBrandPageReqVO pageReqVO);
69 65
70 } 66 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImpl.java renamed to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java
1 package cn.iocoder.yudao.module.product.service.brand; 1 package cn.iocoder.yudao.module.product.service.brand;
2 2
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO;
  5 +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO;
  6 +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO;
  7 +import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert;
  8 +import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
  9 +import cn.iocoder.yudao.module.product.dal.mysql.brand.ProductBrandMapper;
3 import org.springframework.stereotype.Service; 10 import org.springframework.stereotype.Service;
4 -import javax.annotation.Resource;  
5 import org.springframework.validation.annotation.Validated; 11 import org.springframework.validation.annotation.Validated;
6 12
7 -import java.util.*;  
8 -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;  
9 -import cn.iocoder.yudao.module.product.dal.dataobject.brand.BrandDO;  
10 -import cn.iocoder.yudao.framework.common.pojo.PageResult;  
11 -  
12 -import cn.iocoder.yudao.module.product.convert.brand.BrandConvert;  
13 -import cn.iocoder.yudao.module.product.dal.mysql.brand.BrandMapper; 13 +import javax.annotation.Resource;
  14 +import java.util.Collection;
  15 +import java.util.List;
14 16
15 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 17 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
16 -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; 18 +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_BRAND_NOT_EXISTS;
17 19
18 /** 20 /**
19 * 品牌 Service 实现类 21 * 品牌 Service 实现类
@@ -22,26 +24,26 @@ import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; @@ -22,26 +24,26 @@ import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
22 */ 24 */
23 @Service 25 @Service
24 @Validated 26 @Validated
25 -public class BrandServiceImpl implements BrandService { 27 +public class ProductBrandServiceImpl implements ProductBrandService {
26 28
27 @Resource 29 @Resource
28 - private BrandMapper brandMapper; 30 + private ProductBrandMapper brandMapper;
29 31
30 @Override 32 @Override
31 - public Long createBrand(BrandCreateReqVO createReqVO) { 33 + public Long createProductBrand(ProductBrandCreateReqVO createReqVO) {
32 // 插入 34 // 插入
33 - BrandDO brand = BrandConvert.INSTANCE.convert(createReqVO); 35 + ProductBrandDO brand = ProductBrandConvert.INSTANCE.convert(createReqVO);
34 brandMapper.insert(brand); 36 brandMapper.insert(brand);
35 // 返回 37 // 返回
36 return brand.getId(); 38 return brand.getId();
37 } 39 }
38 40
39 @Override 41 @Override
40 - public void updateBrand(BrandUpdateReqVO updateReqVO) { 42 + public void updateBrand(ProductBrandUpdateReqVO updateReqVO) {
41 // 校验存在 43 // 校验存在
42 - this.validateBrandExists(updateReqVO.getId()); 44 + validateBrandExists(updateReqVO.getId());
43 // 更新 45 // 更新
44 - BrandDO updateObj = BrandConvert.INSTANCE.convert(updateReqVO); 46 + ProductBrandDO updateObj = ProductBrandConvert.INSTANCE.convert(updateReqVO);
45 brandMapper.updateById(updateObj); 47 brandMapper.updateById(updateObj);
46 } 48 }
47 49
@@ -55,28 +57,23 @@ public class BrandServiceImpl implements BrandService { @@ -55,28 +57,23 @@ public class BrandServiceImpl implements BrandService {
55 57
56 private void validateBrandExists(Long id) { 58 private void validateBrandExists(Long id) {
57 if (brandMapper.selectById(id) == null) { 59 if (brandMapper.selectById(id) == null) {
58 - throw exception(BRAND_NOT_EXISTS); 60 + throw exception(PRODUCT_BRAND_NOT_EXISTS);
59 } 61 }
60 } 62 }
61 63
62 @Override 64 @Override
63 - public BrandDO getBrand(Long id) { 65 + public ProductBrandDO getBrand(Long id) {
64 return brandMapper.selectById(id); 66 return brandMapper.selectById(id);
65 } 67 }
66 68
67 @Override 69 @Override
68 - public List<BrandDO> getBrandList(Collection<Long> ids) { 70 + public List<ProductBrandDO> getBrandList(Collection<Long> ids) {
69 return brandMapper.selectBatchIds(ids); 71 return brandMapper.selectBatchIds(ids);
70 } 72 }
71 73
72 @Override 74 @Override
73 - public PageResult<BrandDO> getBrandPage(BrandPageReqVO pageReqVO) { 75 + public PageResult<ProductBrandDO> getBrandPage(ProductBrandPageReqVO pageReqVO) {
74 return brandMapper.selectPage(pageReqVO); 76 return brandMapper.selectPage(pageReqVO);
75 } 77 }
76 78
77 - @Override  
78 - public List<BrandDO> getBrandList(BrandExportReqVO exportReqVO) {  
79 - return brandMapper.selectList(exportReqVO);  
80 - }  
81 -  
82 } 79 }
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImplTest.java deleted
1 -package cn.iocoder.yudao.module.product.service.brand;  
2 -  
3 -import org.junit.jupiter.api.Disabled;  
4 -import org.junit.jupiter.api.Test;  
5 -import org.springframework.boot.test.mock.mockito.MockBean;  
6 -  
7 -import javax.annotation.Resource;  
8 -  
9 -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;  
10 -  
11 -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;  
12 -import cn.iocoder.yudao.module.product.dal.dataobject.brand.BrandDO;  
13 -import cn.iocoder.yudao.module.product.dal.mysql.brand.BrandMapper;  
14 -import cn.iocoder.yudao.framework.common.pojo.PageResult;  
15 -  
16 -import javax.annotation.Resource;  
17 -import org.springframework.context.annotation.Import;  
18 -import java.util.*;  
19 -  
20 -import static cn.hutool.core.util.RandomUtil.*;  
21 -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;  
22 -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;  
23 -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;  
24 -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;  
25 -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;  
26 -import static org.junit.jupiter.api.Assertions.*;  
27 -import static org.mockito.Mockito.*;  
28 -  
29 -/**  
30 -* {@link BrandServiceImpl} 的单元测试类  
31 -*  
32 -* @author 芋道源码  
33 -*/  
34 -@Import(BrandServiceImpl.class)  
35 -public class BrandServiceImplTest extends BaseDbUnitTest {  
36 -  
37 - @Resource  
38 - private BrandServiceImpl brandService;  
39 -  
40 - @Resource  
41 - private BrandMapper brandMapper;  
42 -  
43 - @Test  
44 - public void testCreateBrand_success() {  
45 - // 准备参数  
46 - BrandCreateReqVO reqVO = randomPojo(BrandCreateReqVO.class);  
47 -  
48 - // 调用  
49 - Long brandId = brandService.createBrand(reqVO);  
50 - // 断言  
51 - assertNotNull(brandId);  
52 - // 校验记录的属性是否正确  
53 - BrandDO brand = brandMapper.selectById(brandId);  
54 - assertPojoEquals(reqVO, brand);  
55 - }  
56 -  
57 - @Test  
58 - public void testUpdateBrand_success() {  
59 - // mock 数据  
60 - BrandDO dbBrand = randomPojo(BrandDO.class);  
61 - brandMapper.insert(dbBrand);// @Sql: 先插入出一条存在的数据  
62 - // 准备参数  
63 - BrandUpdateReqVO reqVO = randomPojo(BrandUpdateReqVO.class, o -> {  
64 - o.setId(dbBrand.getId()); // 设置更新的 ID  
65 - });  
66 -  
67 - // 调用  
68 - brandService.updateBrand(reqVO);  
69 - // 校验是否更新正确  
70 - BrandDO brand = brandMapper.selectById(reqVO.getId()); // 获取最新的  
71 - assertPojoEquals(reqVO, brand);  
72 - }  
73 -  
74 - @Test  
75 - public void testUpdateBrand_notExists() {  
76 - // 准备参数  
77 - BrandUpdateReqVO reqVO = randomPojo(BrandUpdateReqVO.class);  
78 -  
79 - // 调用, 并断言异常  
80 - assertServiceException(() -> brandService.updateBrand(reqVO), BRAND_NOT_EXISTS);  
81 - }  
82 -  
83 - @Test  
84 - public void testDeleteBrand_success() {  
85 - // mock 数据  
86 - BrandDO dbBrand = randomPojo(BrandDO.class);  
87 - brandMapper.insert(dbBrand);// @Sql: 先插入出一条存在的数据  
88 - // 准备参数  
89 - Long id = dbBrand.getId();  
90 -  
91 - // 调用  
92 - brandService.deleteBrand(id);  
93 - // 校验数据不存在了  
94 - assertNull(brandMapper.selectById(id));  
95 - }  
96 -  
97 - @Test  
98 - public void testDeleteBrand_notExists() {  
99 - // 准备参数  
100 - Long id = randomLongId();  
101 -  
102 - // 调用, 并断言异常  
103 - assertServiceException(() -> brandService.deleteBrand(id), BRAND_NOT_EXISTS);  
104 - }  
105 -  
106 - @Test  
107 - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解  
108 - public void testGetBrandPage() {  
109 - // mock 数据  
110 - BrandDO dbBrand = randomPojo(BrandDO.class, o -> { // 等会查询到  
111 - o.setCategoryId(null);  
112 - o.setName(null);  
113 - o.setStatus(null);  
114 - o.setCreateTime(null);  
115 - });  
116 - brandMapper.insert(dbBrand);  
117 - // 测试 categoryId 不匹配  
118 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setCategoryId(null)));  
119 - // 测试 name 不匹配  
120 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setName(null)));  
121 - // 测试 status 不匹配  
122 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setStatus(null)));  
123 - // 测试 createTime 不匹配  
124 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setCreateTime(null)));  
125 - // 准备参数  
126 - BrandPageReqVO reqVO = new BrandPageReqVO();  
127 - reqVO.setCategoryId(null);  
128 - reqVO.setName(null);  
129 - reqVO.setStatus(null);  
130 - reqVO.setCreateTime((new Date[]{}));  
131 -  
132 - // 调用  
133 - PageResult<BrandDO> pageResult = brandService.getBrandPage(reqVO);  
134 - // 断言  
135 - assertEquals(1, pageResult.getTotal());  
136 - assertEquals(1, pageResult.getList().size());  
137 - assertPojoEquals(dbBrand, pageResult.getList().get(0));  
138 - }  
139 -  
140 - @Test  
141 - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解  
142 - public void testGetBrandList() {  
143 - // mock 数据  
144 - BrandDO dbBrand = randomPojo(BrandDO.class, o -> { // 等会查询到  
145 - o.setCategoryId(null);  
146 - o.setName(null);  
147 - o.setStatus(null);  
148 - o.setCreateTime(null);  
149 - });  
150 - brandMapper.insert(dbBrand);  
151 - // 测试 categoryId 不匹配  
152 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setCategoryId(null)));  
153 - // 测试 name 不匹配  
154 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setName(null)));  
155 - // 测试 status 不匹配  
156 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setStatus(null)));  
157 - // 测试 createTime 不匹配  
158 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setCreateTime(null)));  
159 - // 准备参数  
160 - BrandExportReqVO reqVO = new BrandExportReqVO();  
161 - reqVO.setCategoryId(null);  
162 - reqVO.setName(null);  
163 - reqVO.setStatus(null);  
164 - reqVO.setCreateTime((new Date[]{}));  
165 -  
166 - // 调用  
167 - List<BrandDO> list = brandService.getBrandList(reqVO);  
168 - // 断言  
169 - assertEquals(1, list.size());  
170 - assertPojoEquals(dbBrand, list.get(0));  
171 - }  
172 -  
173 -}  
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImplTest.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.service.brand;
  2 +
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  5 +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
  6 +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO;
  7 +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO;
  8 +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO;
  9 +import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
  10 +import cn.iocoder.yudao.module.product.dal.mysql.brand.ProductBrandMapper;
  11 +import org.junit.jupiter.api.Test;
  12 +import org.springframework.context.annotation.Import;
  13 +
  14 +import javax.annotation.Resource;
  15 +import java.util.Date;
  16 +
  17 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime;
  18 +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
  19 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
  20 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
  21 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
  22 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
  23 +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_BRAND_NOT_EXISTS;
  24 +import static org.junit.jupiter.api.Assertions.*;
  25 +
  26 +/**
  27 +* {@link ProductBrandServiceImpl} 的单元测试类
  28 +*
  29 +* @author 芋道源码
  30 +*/
  31 +@Import(ProductBrandServiceImpl.class)
  32 +public class ProductBrandServiceImplTest extends BaseDbUnitTest {
  33 +
  34 + @Resource
  35 + private ProductBrandServiceImpl brandService;
  36 +
  37 + @Resource
  38 + private ProductBrandMapper brandMapper;
  39 +
  40 + @Test
  41 + public void testCreateBrand_success() {
  42 + // 准备参数
  43 + ProductBrandCreateReqVO reqVO = randomPojo(ProductBrandCreateReqVO.class);
  44 +
  45 + // 调用
  46 + Long brandId = brandService.createProductBrand(reqVO);
  47 + // 断言
  48 + assertNotNull(brandId);
  49 + // 校验记录的属性是否正确
  50 + ProductBrandDO brand = brandMapper.selectById(brandId);
  51 + assertPojoEquals(reqVO, brand);
  52 + }
  53 +
  54 + @Test
  55 + public void testUpdateBrand_success() {
  56 + // mock 数据
  57 + ProductBrandDO dbBrand = randomPojo(ProductBrandDO.class);
  58 + brandMapper.insert(dbBrand);// @Sql: 先插入出一条存在的数据
  59 + // 准备参数
  60 + ProductBrandUpdateReqVO reqVO = randomPojo(ProductBrandUpdateReqVO.class, o -> {
  61 + o.setId(dbBrand.getId()); // 设置更新的 ID
  62 + });
  63 +
  64 + // 调用
  65 + brandService.updateBrand(reqVO);
  66 + // 校验是否更新正确
  67 + ProductBrandDO brand = brandMapper.selectById(reqVO.getId()); // 获取最新的
  68 + assertPojoEquals(reqVO, brand);
  69 + }
  70 +
  71 + @Test
  72 + public void testUpdateBrand_notExists() {
  73 + // 准备参数
  74 + ProductBrandUpdateReqVO reqVO = randomPojo(ProductBrandUpdateReqVO.class);
  75 +
  76 + // 调用, 并断言异常
  77 + assertServiceException(() -> brandService.updateBrand(reqVO), PRODUCT_BRAND_NOT_EXISTS);
  78 + }
  79 +
  80 + @Test
  81 + public void testDeleteBrand_success() {
  82 + // mock 数据
  83 + ProductBrandDO dbBrand = randomPojo(ProductBrandDO.class);
  84 + brandMapper.insert(dbBrand);// @Sql: 先插入出一条存在的数据
  85 + // 准备参数
  86 + Long id = dbBrand.getId();
  87 +
  88 + // 调用
  89 + brandService.deleteBrand(id);
  90 + // 校验数据不存在了
  91 + assertNull(brandMapper.selectById(id));
  92 + }
  93 +
  94 + @Test
  95 + public void testDeleteBrand_notExists() {
  96 + // 准备参数
  97 + Long id = randomLongId();
  98 +
  99 + // 调用, 并断言异常
  100 + assertServiceException(() -> brandService.deleteBrand(id), PRODUCT_BRAND_NOT_EXISTS);
  101 + }
  102 +
  103 + @Test
  104 + public void testGetBrandPage() {
  105 + // mock 数据
  106 + ProductBrandDO dbBrand = randomPojo(ProductBrandDO.class, o -> { // 等会查询到
  107 + o.setName("芋道源码");
  108 + o.setStatus(CommonStatusEnum.ENABLE.getStatus());
  109 + o.setCreateTime(buildTime(2022, 2, 1));
  110 + });
  111 + brandMapper.insert(dbBrand);
  112 + // 测试 name 不匹配
  113 + brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setName("源码")));
  114 + // 测试 status 不匹配
  115 + brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
  116 + // 测试 createTime 不匹配
  117 + brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setCreateTime(buildTime(2022, 3, 1))));
  118 + // 准备参数
  119 + ProductBrandPageReqVO reqVO = new ProductBrandPageReqVO();
  120 + reqVO.setName("芋道");
  121 + reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
  122 + reqVO.setCreateTime((new Date[]{buildTime(2022, 1, 1), buildTime(2022, 2, 25)}));
  123 +
  124 + // 调用
  125 + PageResult<ProductBrandDO> pageResult = brandService.getBrandPage(reqVO);
  126 + // 断言
  127 + assertEquals(1, pageResult.getTotal());
  128 + assertEquals(1, pageResult.getList().size());
  129 + assertPojoEquals(dbBrand, pageResult.getList().get(0));
  130 + }
  131 +
  132 +}
yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql
@@ -16,9 +16,8 @@ CREATE TABLE IF NOT EXISTS &quot;product_category&quot; ( @@ -16,9 +16,8 @@ CREATE TABLE IF NOT EXISTS &quot;product_category&quot; (
16 16
17 CREATE TABLE IF NOT EXISTS "product_brand" ( 17 CREATE TABLE IF NOT EXISTS "product_brand" (
18 "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, 18 "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY,
19 - "category_id" bigint(20) NOT NULL,  
20 "name" varchar(255) NOT NULL, 19 "name" varchar(255) NOT NULL,
21 - "banner_url" varchar(255) NOT NULL, 20 + "pic_url" varchar(255) NOT NULL,
22 "sort" int(11), 21 "sort" int(11),
23 "description" varchar(1024), 22 "description" varchar(1024),
24 "status" tinyint(4) NOT NULL, 23 "status" tinyint(4) NOT NULL,
@@ -28,4 +27,4 @@ CREATE TABLE IF NOT EXISTS &quot;product_brand&quot; ( @@ -28,4 +27,4 @@ CREATE TABLE IF NOT EXISTS &quot;product_brand&quot; (
28 "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 27 "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
29 "deleted" bit NOT NULL DEFAULT FALSE, 28 "deleted" bit NOT NULL DEFAULT FALSE,
30 PRIMARY KEY ("id") 29 PRIMARY KEY ("id")
31 -) COMMENT '品牌'; 30 +) COMMENT '商品品牌';
yudao-ui-admin/src/views/mall/product/brand/index.vue
@@ -26,25 +26,18 @@ @@ -26,25 +26,18 @@
26 <el-row :gutter="10" class="mb8"> 26 <el-row :gutter="10" class="mb8">
27 <el-col :span="1.5"> 27 <el-col :span="1.5">
28 <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" 28 <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
29 - v-hasPermi="['product:brand:create']">新增  
30 - </el-button>  
31 - </el-col>  
32 - <el-col :span="1.5">  
33 - <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"  
34 - :loading="exportLoading"  
35 - v-hasPermi="['product:brand:export']">导出  
36 - </el-button> 29 + v-hasPermi="['product:brand:create']">新增</el-button>
37 </el-col> 30 </el-col>
38 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> 31 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
39 </el-row> 32 </el-row>
40 33
41 <!-- 列表 --> 34 <!-- 列表 -->
42 <el-table v-loading="loading" :data="list"> 35 <el-table v-loading="loading" :data="list">
43 - <el-table-column label="商品分类" align="center" prop="categoryId"/> 36 + <el-table-column label="品牌编号" align="center" prop="id"/>
44 <el-table-column label="品牌名称" align="center" prop="name"/> 37 <el-table-column label="品牌名称" align="center" prop="name"/>
45 - <el-table-column label="品牌图片" align="center" prop="bannerUrl"> 38 + <el-table-column label="品牌图片" align="center" prop="picUrl">
46 <template slot-scope="scope"> 39 <template slot-scope="scope">
47 - <img v-if="scope.row.bannerUrl" :src="scope.row.bannerUrl" alt="分类图片" class="img-height"/> 40 + <img v-if="scope.row.picUrl" :src="scope.row.picUrl" alt="分类图片" style="height: 100px;" />
48 </template> 41 </template>
49 </el-table-column> 42 </el-table-column>
50 <el-table-column label="品牌排序" align="center" prop="sort"/> 43 <el-table-column label="品牌排序" align="center" prop="sort"/>
@@ -77,15 +70,11 @@ @@ -77,15 +70,11 @@
77 <!-- 对话框(添加 / 修改) --> 70 <!-- 对话框(添加 / 修改) -->
78 <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> 71 <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
79 <el-form ref="form" :model="form" :rules="rules" label-width="80px"> 72 <el-form ref="form" :model="form" :rules="rules" label-width="80px">
80 - <el-form-item label="商品分类" prop="categoryId">  
81 - <Treeselect v-model="form.categoryId" :options="categoryOptions" :normalizer="normalizer" :show-count="true"  
82 - placeholder="请选择商品分类"/>  
83 - </el-form-item>  
84 <el-form-item label="品牌名称" prop="name"> 73 <el-form-item label="品牌名称" prop="name">
85 <el-input v-model="form.name" placeholder="请输入品牌名称"/> 74 <el-input v-model="form.name" placeholder="请输入品牌名称"/>
86 </el-form-item> 75 </el-form-item>
87 - <el-form-item label="品牌图片" prop="bannerUrl">  
88 - <imageUpload v-model="form.bannerUrl" :limit="1"/> 76 + <el-form-item label="品牌图片" prop="picUrl">
  77 + <imageUpload v-model="form.picUrl" :limit="1"/>
89 </el-form-item> 78 </el-form-item>
90 <el-form-item label="品牌排序" prop="sort"> 79 <el-form-item label="品牌排序" prop="sort">
91 <el-input v-model="form.sort" placeholder="请输入品牌排序"/> 80 <el-input v-model="form.sort" placeholder="请输入品牌排序"/>
@@ -113,20 +102,18 @@ @@ -113,20 +102,18 @@
113 import { 102 import {
114 createBrand, 103 createBrand,
115 deleteBrand, 104 deleteBrand,
116 - exportBrandExcel,  
117 getBrand, 105 getBrand,
118 getBrandPage, 106 getBrandPage,
119 updateBrand 107 updateBrand
120 } from "@/api/mall/product/brand"; 108 } from "@/api/mall/product/brand";
121 -import {getProductCategoryList} from "@/api/mall/product/category";  
122 import ImageUpload from '@/components/ImageUpload'; 109 import ImageUpload from '@/components/ImageUpload';
123 -import Treeselect from "@riophae/vue-treeselect";  
124 import "@riophae/vue-treeselect/dist/vue-treeselect.css"; 110 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  111 +import {CommonStatusEnum} from "@/utils/constants";
125 112
126 export default { 113 export default {
127 - name: "Brand", 114 + name: "ProductBrand",
128 components: { 115 components: {
129 - ImageUpload, Treeselect, 116 + ImageUpload
130 }, 117 },
131 data() { 118 data() {
132 return { 119 return {
@@ -153,21 +140,18 @@ export default { @@ -153,21 +140,18 @@ export default {
153 status: null, 140 status: null,
154 createTime: [] 141 createTime: []
155 }, 142 },
156 - // 商品分类树选项  
157 - categoryOptions: [],  
158 // 表单参数 143 // 表单参数
159 form: {}, 144 form: {},
160 // 表单校验 145 // 表单校验
161 rules: { 146 rules: {
162 - categoryId: [{required: true, message: "分类编号不能为空", trigger: "blur"}],  
163 name: [{required: true, message: "品牌名称不能为空", trigger: "blur"}], 147 name: [{required: true, message: "品牌名称不能为空", trigger: "blur"}],
164 - bannerUrl: [{required: true, message: "品牌图片不能为空", trigger: "blur"}], 148 + picUrl: [{required: true, message: "品牌图片不能为空", trigger: "blur"}],
  149 + sort: [{required: true, message: "品牌排序不能为空", trigger: "blur"}],
165 status: [{required: true, message: "状态不能为空", trigger: "change"}], 150 status: [{required: true, message: "状态不能为空", trigger: "change"}],
166 } 151 }
167 }; 152 };
168 }, 153 },
169 created() { 154 created() {
170 - this.getTreeselect();  
171 this.getList(); 155 this.getList();
172 }, 156 },
173 methods: { 157 methods: {
@@ -181,26 +165,6 @@ export default { @@ -181,26 +165,6 @@ export default {
181 this.loading = false; 165 this.loading = false;
182 }); 166 });
183 }, 167 },
184 - /** 转换菜单数据结构 */  
185 - normalizer(node) {  
186 - if (node.children && !node.children.length) {  
187 - delete node.children;  
188 - }  
189 - return {  
190 - id: node.id,  
191 - label: node.name,  
192 - children: node.children  
193 - };  
194 - },  
195 - /** 查询分类下拉树结构 */  
196 - getTreeselect() {  
197 - getProductCategoryList().then(response => {  
198 - this.categoryOptions = [];  
199 - const menu = {id: 0, name: '商品分类', children: []};  
200 - menu.children = this.handleTree(response.data, "id", "pid");  
201 - this.categoryOptions.push(menu);  
202 - });  
203 - },  
204 /** 取消按钮 */ 168 /** 取消按钮 */
205 cancel() { 169 cancel() {
206 this.open = false; 170 this.open = false;
@@ -210,12 +174,11 @@ export default { @@ -210,12 +174,11 @@ export default {
210 reset() { 174 reset() {
211 this.form = { 175 this.form = {
212 id: undefined, 176 id: undefined,
213 - categoryId: undefined,  
214 name: undefined, 177 name: undefined,
215 - bannerUrl: undefined,  
216 - sort: undefined, 178 + picUrl: undefined,
  179 + sort: 0,
217 description: undefined, 180 description: undefined,
218 - status: undefined, 181 + status: CommonStatusEnum.ENABLE,
219 }; 182 };
220 this.resetForm("form"); 183 this.resetForm("form");
221 }, 184 },
@@ -232,14 +195,12 @@ export default { @@ -232,14 +195,12 @@ export default {
232 /** 新增按钮操作 */ 195 /** 新增按钮操作 */
233 handleAdd() { 196 handleAdd() {
234 this.reset(); 197 this.reset();
235 - this.getTreeselect();  
236 this.open = true; 198 this.open = true;
237 this.title = "添加品牌"; 199 this.title = "添加品牌";
238 }, 200 },
239 /** 修改按钮操作 */ 201 /** 修改按钮操作 */
240 handleUpdate(row) { 202 handleUpdate(row) {
241 this.reset(); 203 this.reset();
242 - this.getTreeselect();  
243 const id = row.id; 204 const id = row.id;
244 getBrand(id).then(response => { 205 getBrand(id).then(response => {
245 this.form = response.data; 206 this.form = response.data;
@@ -280,30 +241,7 @@ export default { @@ -280,30 +241,7 @@ export default {
280 this.$modal.msgSuccess("删除成功"); 241 this.$modal.msgSuccess("删除成功");
281 }).catch(() => { 242 }).catch(() => {
282 }); 243 });
283 - },  
284 - /** 导出按钮操作 */  
285 - handleExport() {  
286 - // 处理查询参数  
287 - let params = {...this.queryParams};  
288 - params.pageNo = undefined;  
289 - params.pageSize = undefined;  
290 - // 执行导出  
291 - this.$modal.confirm('是否确认导出所有品牌数据项?').then(() => {  
292 - this.exportLoading = true;  
293 - return exportBrandExcel(params);  
294 - }).then(response => {  
295 - this.$download.excel(response, "品牌.xls");  
296 - this.exportLoading = false;  
297 - }).catch(() => {  
298 - });  
299 } 244 }
300 } 245 }
301 }; 246 };
302 </script> 247 </script>
303 -  
304 -<style scoped lang="scss">  
305 -//  
306 -.img-height {  
307 - height: 150px;  
308 -}  
309 -</style>  
yudao-ui-admin/src/views/mall/product/category/index.vue
@@ -113,7 +113,7 @@ import ImageUpload from &#39;@/components/ImageUpload&#39;; @@ -113,7 +113,7 @@ import ImageUpload from &#39;@/components/ImageUpload&#39;;
113 import {CommonStatusEnum} from "@/utils/constants"; 113 import {CommonStatusEnum} from "@/utils/constants";
114 114
115 export default { 115 export default {
116 - name: "Category", 116 + name: "ProductCategory",
117 components: { 117 components: {
118 Editor, Treeselect, ImageUpload 118 Editor, Treeselect, ImageUpload
119 }, 119 },