From fa9823161e785c38bcf7d4edc910921d41a21699 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 30 Jul 2022 22:15:03 +0800 Subject: [PATCH] mall:完善商品品牌的前后端实现 --- sql/optional/mall/mall.sql | 58 ---------------------------------------------------------- yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java | 2 +- yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/BrandController.java | 89 ----------------------------------------------------------------------------------------- yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandBaseVO.java | 37 ------------------------------------- yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandCreateReqVO.java | 14 -------------- yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandExcelVO.java | 45 --------------------------------------------- yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandExportReqVO.java | 28 ---------------------------- yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandPageReqVO.java | 30 ------------------------------ yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandRespVO.java | 19 ------------------- yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandUpdateReqVO.java | 18 ------------------ yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandBaseVO.java | 33 +++++++++++++++++++++++++++++++++ yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandCreateReqVO.java | 12 ++++++++++++ yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandPageReqVO.java | 31 +++++++++++++++++++++++++++++++ yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandRespVO.java | 23 +++++++++++++++++++++++ yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandUpdateReqVO.java | 17 +++++++++++++++++ yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/brand/BrandConvert.java | 34 ---------------------------------- yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/brand/ProductBrandConvert.java | 33 +++++++++++++++++++++++++++++++++ yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/brand/BrandDO.java | 56 -------------------------------------------------------- yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/brand/ProductBrandDO.java | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/BrandMapper.java | 38 -------------------------------------- yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java | 21 +++++++++++++++++++++ yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandService.java | 70 ---------------------------------------------------------------------- yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImpl.java | 82 ---------------------------------------------------------------------------------- yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImplTest.java | 173 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImplTest.java | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql | 5 ++--- yudao-ui-admin/src/views/mall/product/brand/index.vue | 90 ++++++++++++++---------------------------------------------------------------------------- yudao-ui-admin/src/views/mall/product/category/index.vue | 2 +- 31 files changed, 593 insertions(+), 872 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/BrandController.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandBaseVO.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandCreateReqVO.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandExcelVO.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandExportReqVO.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandPageReqVO.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandRespVO.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandUpdateReqVO.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandBaseVO.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandCreateReqVO.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandPageReqVO.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandRespVO.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandUpdateReqVO.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/brand/BrandConvert.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/brand/ProductBrandConvert.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/brand/BrandDO.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/brand/ProductBrandDO.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/BrandMapper.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandService.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImpl.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImplTest.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImplTest.java diff --git a/sql/optional/mall/mall.sql b/sql/optional/mall/mall.sql index e8a29fb..5dc5723 100644 --- a/sql/optional/mall/mall.sql +++ b/sql/optional/mall/mall.sql @@ -24,64 +24,6 @@ SET NAMES utf8mb4; -- ---------------------------- -- Table structure for product_brand -- ---------------------------- -DROP TABLE IF EXISTS `product_brand`; -CREATE TABLE `product_brand` -( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '品牌编号', - `category_id` bigint NOT NULL COMMENT '分类编号', - `name` varchar(255) NOT NULL COMMENT '品牌名称', - `banner_url` varchar(255) NOT NULL COMMENT '品牌图片', - `sort` int DEFAULT '0' COMMENT '品牌排序', - `description` varchar(1024) DEFAULT NULL COMMENT '品牌描述', - `status` tinyint NOT NULL COMMENT '状态', - `creator` varchar(64) DEFAULT '' COMMENT '创建者', - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `updater` varchar(64) DEFAULT '' COMMENT '更新者', - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', - `tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号', - PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB COMMENT='品牌'; - --- TODO 父级菜单的 id 处理: 2000 、 2001 -INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES (2000, '商城', '', 1, 1, 0, '/mall', 'merchant', NULL, 0); -INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES (2001, '商品', '', 1, 1, 2000, 'product', 'dict', NULL, 0); --- 商品分类 菜单 SQL -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES ('分类管理', '', 2, 0, 2001, 'category', '', 'mall/product/category/index', 0); --- 按钮父菜单ID -SELECT @parentId := LAST_INSERT_ID(); --- 按钮 SQL -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES ('分类查询', 'product:category:query', 3, 1, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES ('分类创建', 'product:category:create', 3, 2, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES ('分类更新', 'product:category:update', 3, 3, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES ('分类删除', 'product:category:delete', 3, 4, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES ('分类导出', 'product:category:export', 3, 5, @parentId, '', '', '', 0); - --- 品牌管理 菜单 SQL -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES ('品牌管理', '', 2, 1, 2001, 'brand', '', 'mall/product/brand/index', 0); --- 按钮父菜单ID -SELECT @parentId := LAST_INSERT_ID(); --- 按钮 SQL -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES ('品牌查询', 'product:brand:query', 3, 1, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES ('品牌创建', 'product:brand:create', 3, 2, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES ('品牌更新', 'product:brand:update', 3, 3, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES ('品牌删除', 'product:brand:delete', 3, 4, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) -VALUES ('品牌导出', 'product:brand:export', 3, 5, @parentId, '', '', '', 0); - -- ---------------------------- -- Table structure for market_activity diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java index d47bb75..0c47d94 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java +++ b/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 { ErrorCode PRODUCT_CATEGORY_DISABLED = new ErrorCode(1008001004, "商品分类({})已禁用,无法使用"); // ========== 品牌相关编号 1008002000 ========== - ErrorCode BRAND_NOT_EXISTS = new ErrorCode(1008002000, "品牌不存在"); + ErrorCode PRODUCT_BRAND_NOT_EXISTS = new ErrorCode(1008002000, "品牌不存在"); // ========== 规格名称 1008003000 ========== ErrorCode PROPERTY_NOT_EXISTS = new ErrorCode(1008003000, "规格名称不存在"); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/BrandController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/BrandController.java deleted file mode 100644 index 0702d20..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/BrandController.java +++ /dev/null @@ -1,89 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.brand; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; -import cn.iocoder.yudao.module.product.convert.brand.BrandConvert; -import cn.iocoder.yudao.module.product.dal.dataobject.brand.BrandDO; -import cn.iocoder.yudao.module.product.service.brand.BrandService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiOperation; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; -import javax.validation.Valid; -import java.io.IOException; -import java.util.List; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; - -@Api(tags = "管理后台 - 品牌") -@RestController -@RequestMapping("/product/brand") -@Validated -public class BrandController { - - @Resource - private BrandService brandService; - - @PostMapping("/create") - @ApiOperation("创建品牌") - @PreAuthorize("@ss.hasPermission('product:brand:create')") - public CommonResult createBrand(@Valid @RequestBody BrandCreateReqVO createReqVO) { - return success(brandService.createBrand(createReqVO)); - } - - @PutMapping("/update") - @ApiOperation("更新品牌") - @PreAuthorize("@ss.hasPermission('product:brand:update')") - public CommonResult updateBrand(@Valid @RequestBody BrandUpdateReqVO updateReqVO) { - brandService.updateBrand(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @ApiOperation("删除品牌") - @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) - @PreAuthorize("@ss.hasPermission('product:brand:delete')") - public CommonResult deleteBrand(@RequestParam("id") Long id) { - brandService.deleteBrand(id); - return success(true); - } - - @GetMapping("/get") - @ApiOperation("获得品牌") - @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) - @PreAuthorize("@ss.hasPermission('product:brand:query')") - public CommonResult getBrand(@RequestParam("id") Long id) { - BrandDO brand = brandService.getBrand(id); - return success(BrandConvert.INSTANCE.convert(brand)); - } - - @GetMapping("/page") - @ApiOperation("获得品牌分页") - @PreAuthorize("@ss.hasPermission('product:brand:query')") - public CommonResult> getBrandPage(@Valid BrandPageReqVO pageVO) { - PageResult pageResult = brandService.getBrandPage(pageVO); - return success(BrandConvert.INSTANCE.convertPage(pageResult)); - } - - @GetMapping("/export-excel") - @ApiOperation("导出品牌 Excel") - @PreAuthorize("@ss.hasPermission('product:brand:export')") - @OperateLog(type = EXPORT) - public void exportBrandExcel(@Valid BrandExportReqVO exportReqVO, - HttpServletResponse response) throws IOException { - List list = brandService.getBrandList(exportReqVO); - // 导出 Excel - List datas = BrandConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "品牌.xls", "数据", BrandExcelVO.class, datas); - } - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java new file mode 100644 index 0000000..14ffef8 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java @@ -0,0 +1,77 @@ +package cn.iocoder.yudao.module.product.controller.admin.brand; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; +import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert; +import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; +import cn.iocoder.yudao.module.product.service.brand.ProductBrandService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; + +@Api(tags = "管理后台 - 商品品牌") +@RestController +@RequestMapping("/product/brand") +@Validated +public class ProductBrandController { + + @Resource + private ProductBrandService brandService; + + @PostMapping("/create") + @ApiOperation("创建品牌") + @PreAuthorize("@ss.hasPermission('product:brand:create')") + public CommonResult createBrand(@Valid @RequestBody ProductBrandCreateReqVO createReqVO) { + return success(brandService.createProductBrand(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("更新品牌") + @PreAuthorize("@ss.hasPermission('product:brand:update')") + public CommonResult updateBrand(@Valid @RequestBody ProductBrandUpdateReqVO updateReqVO) { + brandService.updateBrand(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @ApiOperation("删除品牌") + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('product:brand:delete')") + public CommonResult deleteBrand(@RequestParam("id") Long id) { + brandService.deleteBrand(id); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得品牌") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('product:brand:query')") + public CommonResult getBrand(@RequestParam("id") Long id) { + ProductBrandDO brand = brandService.getBrand(id); + return success(ProductBrandConvert.INSTANCE.convert(brand)); + } + + @GetMapping("/page") + @ApiOperation("获得品牌分页") + @PreAuthorize("@ss.hasPermission('product:brand:query')") + public CommonResult> getBrandPage(@Valid ProductBrandPageReqVO pageVO) { + PageResult pageResult = brandService.getBrandPage(pageVO); + return success(ProductBrandConvert.INSTANCE.convertPage(pageResult)); + } + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandBaseVO.java deleted file mode 100644 index 57c5a39..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandBaseVO.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.brand.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import javax.validation.constraints.*; - -/** -* 品牌 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ -@Data -public class BrandBaseVO { - - @ApiModelProperty(value = "分类编号", required = true, example = "1") - @NotNull(message = "分类编号不能为空") - private Long categoryId; - - @ApiModelProperty(value = "品牌名称", required = true, example = "芋道") - @NotNull(message = "品牌名称不能为空") - private String name; - - @ApiModelProperty(value = "品牌图片", required = true) - @NotNull(message = "品牌图片不能为空") - private String bannerUrl; - - @ApiModelProperty(value = "品牌排序", example = "1") - private Integer sort; - - @ApiModelProperty(value = "品牌描述", example = "描述") - private String description; - - @ApiModelProperty(value = "状态", required = true, example = "0") - @NotNull(message = "状态不能为空") - private Integer status; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandCreateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandCreateReqVO.java deleted file mode 100644 index 3a6f844..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandCreateReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.brand.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import javax.validation.constraints.*; - -@ApiModel("管理后台 - 品牌创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class BrandCreateReqVO extends BrandBaseVO { - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandExcelVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandExcelVO.java deleted file mode 100644 index 261b69e..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandExcelVO.java +++ /dev/null @@ -1,45 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.brand.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; - -import com.alibaba.excel.annotation.ExcelProperty; -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; - - -/** - * 品牌 Excel VO - * - * @author 芋道源码 - */ -@Data -public class BrandExcelVO { - - @ExcelProperty("品牌编号") - private Long id; - - @ExcelProperty("分类编号") - private Long categoryId; - - @ExcelProperty("品牌名称") - private String name; - - @ExcelProperty("品牌图片") - private String bannerUrl; - - @ExcelProperty("品牌排序") - private Integer sort; - - @ExcelProperty("品牌描述") - private String description; - - @ExcelProperty(value = "状态", converter = DictConvert.class) - @DictFormat("common_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 - private Integer status; - - @ExcelProperty("创建时间") - private Date createTime; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandExportReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandExportReqVO.java deleted file mode 100644 index 1385613..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandExportReqVO.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.brand.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import org.springframework.format.annotation.DateTimeFormat; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@ApiModel(value = "管理后台 - 品牌 Excel 导出 Request VO", description = "参数和 BrandPageReqVO 是一致的") -@Data -public class BrandExportReqVO { - - @ApiModelProperty(value = "分类编号", example = "1") - private Long categoryId; - - @ApiModelProperty(value = "品牌名称", example = "芋道") - private String name; - - @ApiModelProperty(value = "状态", example = "0") - private Integer status; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @ApiModelProperty(value = "创建时间") - private Date[] createTime; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandPageReqVO.java deleted file mode 100644 index c706e51..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandPageReqVO.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.brand.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import org.springframework.format.annotation.DateTimeFormat; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@ApiModel("管理后台 - 品牌分页 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class BrandPageReqVO extends PageParam { - - @ApiModelProperty(value = "分类编号", example = "1") - private Long categoryId; - - @ApiModelProperty(value = "品牌名称", example = "芋道") - private String name; - - @ApiModelProperty(value = "状态", example = "0") - private Integer status; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @ApiModelProperty(value = "创建时间") - private Date[] createTime; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandRespVO.java deleted file mode 100644 index 5e010b4..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandRespVO.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.brand.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; - -@ApiModel("管理后台 - 品牌 Response VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class BrandRespVO extends BrandBaseVO { - - @ApiModelProperty(value = "品牌编号", required = true, example = "1") - private Long id; - - @ApiModelProperty(value = "创建时间", required = true) - private Date createTime; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandUpdateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandUpdateReqVO.java deleted file mode 100644 index 287157f..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandUpdateReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.brand.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import javax.validation.constraints.*; - -@ApiModel("管理后台 - 品牌更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class BrandUpdateReqVO extends BrandBaseVO { - - @ApiModelProperty(value = "品牌编号", required = true, example = "1") - @NotNull(message = "品牌编号不能为空") - private Long id; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandBaseVO.java new file mode 100644 index 0000000..3ad5d45 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandBaseVO.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.product.controller.admin.brand.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** +* 商品品牌 Base VO,提供给添加、修改、详细的子 VO 使用 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 +*/ +@Data +public class ProductBrandBaseVO { + + @ApiModelProperty(value = "品牌名称", required = true, example = "芋道") + @NotNull(message = "品牌名称不能为空") + private String name; + + @ApiModelProperty(value = "品牌图片", required = true) + @NotNull(message = "品牌图片不能为空") + private String picUrl; + + @ApiModelProperty(value = "品牌排序", example = "1") + private Integer sort; + + @ApiModelProperty(value = "品牌描述", example = "描述") + private String description; + + @ApiModelProperty(value = "状态", required = true, example = "0") + @NotNull(message = "状态不能为空") + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandCreateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandCreateReqVO.java new file mode 100644 index 0000000..7402492 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandCreateReqVO.java @@ -0,0 +1,12 @@ +package cn.iocoder.yudao.module.product.controller.admin.brand.vo; + +import lombok.*; +import io.swagger.annotations.*; + +@ApiModel("管理后台 - 商品品牌创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class ProductBrandCreateReqVO extends ProductBrandBaseVO { + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandPageReqVO.java new file mode 100644 index 0000000..8dae402 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandPageReqVO.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.product.controller.admin.brand.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("管理后台 - 商品品牌分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class ProductBrandPageReqVO extends PageParam { + + @ApiModelProperty(value = "品牌名称", example = "芋道") + private String name; + + @ApiModelProperty(value = "状态", example = "0") + private Integer status; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "创建时间") + private Date[] createTime; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandRespVO.java new file mode 100644 index 0000000..f577a6c --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandRespVO.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.product.controller.admin.brand.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.util.Date; + +@ApiModel("管理后台 - 品牌 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class ProductBrandRespVO extends ProductBrandBaseVO { + + @ApiModelProperty(value = "品牌编号", required = true, example = "1") + private Long id; + + @ApiModelProperty(value = "创建时间", required = true) + private Date createTime; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandUpdateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandUpdateReqVO.java new file mode 100644 index 0000000..54d6102 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandUpdateReqVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.product.controller.admin.brand.vo; + +import lombok.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 商品品牌更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class ProductBrandUpdateReqVO extends ProductBrandBaseVO { + + @ApiModelProperty(value = "品牌编号", required = true, example = "1") + @NotNull(message = "品牌编号不能为空") + private Long id; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/brand/BrandConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/brand/BrandConvert.java deleted file mode 100644 index 3165156..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/brand/BrandConvert.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.module.product.convert.brand; - -import java.util.*; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; -import cn.iocoder.yudao.module.product.dal.dataobject.brand.BrandDO; - -/** - * 品牌 Convert - * - * @author 芋道源码 - */ -@Mapper -public interface BrandConvert { - - BrandConvert INSTANCE = Mappers.getMapper(BrandConvert.class); - - BrandDO convert(BrandCreateReqVO bean); - - BrandDO convert(BrandUpdateReqVO bean); - - BrandRespVO convert(BrandDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/brand/ProductBrandConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/brand/ProductBrandConvert.java new file mode 100644 index 0000000..a318e91 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/brand/ProductBrandConvert.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.product.convert.brand; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandRespVO; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO; +import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 品牌 Convert + * + * @author 芋道源码 + */ +@Mapper +public interface ProductBrandConvert { + + ProductBrandConvert INSTANCE = Mappers.getMapper(ProductBrandConvert.class); + + ProductBrandDO convert(ProductBrandCreateReqVO bean); + + ProductBrandDO convert(ProductBrandUpdateReqVO bean); + + ProductBrandRespVO convert(ProductBrandDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/brand/BrandDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/brand/BrandDO.java deleted file mode 100644 index 2cbcee8..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/brand/BrandDO.java +++ /dev/null @@ -1,56 +0,0 @@ -package cn.iocoder.yudao.module.product.dal.dataobject.brand; - -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -// TODO @JeromeSoar:Product 前缀 -/** - * 品牌 DO - * - * @author 芋道源码 - */ -@TableName("product_brand") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class BrandDO extends BaseDO { - - /** - * 品牌编号 - */ - @TableId - private Long id; - /** - * 分类编号 - */ - private Long categoryId; - /** - * 品牌名称 - */ - private String name; - /** - * 品牌图片 - */ - private String bannerUrl; - /** - * 品牌排序 - */ - private Integer sort; - /** - * 品牌描述 - */ - private String description; - /** - * 状态 - * - * 枚举 {@link CommonStatusEnum} - */ - private Integer status; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/brand/ProductBrandDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/brand/ProductBrandDO.java new file mode 100644 index 0000000..e2178d5 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/brand/ProductBrandDO.java @@ -0,0 +1,51 @@ +package cn.iocoder.yudao.module.product.dal.dataobject.brand; + +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; + +/** + * 商品品牌 DO + * + * @author 芋道源码 + */ +@TableName("product_brand") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ProductBrandDO extends BaseDO { + + /** + * 品牌编号 + */ + @TableId + private Long id; + /** + * 品牌名称 + */ + private String name; + /** + * 品牌图片 + */ + private String picUrl; + /** + * 品牌排序 + */ + private Integer sort; + /** + * 品牌描述 + */ + private String description; + /** + * 状态 + * + * 枚举 {@link CommonStatusEnum} + */ + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/BrandMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/BrandMapper.java deleted file mode 100644 index cf7c5f6..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/BrandMapper.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.yudao.module.product.dal.mysql.brand; - -import java.util.*; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.module.product.dal.dataobject.brand.BrandDO; -import org.apache.ibatis.annotations.Mapper; -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; - -/** - * 品牌 Mapper - * - * @author 芋道源码 - */ -@Mapper -public interface BrandMapper extends BaseMapperX { - - default PageResult selectPage(BrandPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(BrandDO::getCategoryId, reqVO.getCategoryId()) - .likeIfPresent(BrandDO::getName, reqVO.getName()) - .eqIfPresent(BrandDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(BrandDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(BrandDO::getId)); - } - - default List selectList(BrandExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(BrandDO::getCategoryId, reqVO.getCategoryId()) - .likeIfPresent(BrandDO::getName, reqVO.getName()) - .eqIfPresent(BrandDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(BrandDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(BrandDO::getId)); - } - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java new file mode 100644 index 0000000..e33884d --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.product.dal.mysql.brand; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO; +import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ProductBrandMapper extends BaseMapperX { + + default PageResult selectPage(ProductBrandPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(ProductBrandDO::getName, reqVO.getName()) + .eqIfPresent(ProductBrandDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(ProductBrandDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(ProductBrandDO::getId)); + } + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandService.java deleted file mode 100644 index 2cb356f..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandService.java +++ /dev/null @@ -1,70 +0,0 @@ -package cn.iocoder.yudao.module.product.service.brand; - -import java.util.*; -import javax.validation.*; -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; -import cn.iocoder.yudao.module.product.dal.dataobject.brand.BrandDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -/** - * 品牌 Service 接口 - * - * @author 芋道源码 - */ -public interface BrandService { - - /** - * 创建品牌 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createBrand(@Valid BrandCreateReqVO createReqVO); - - /** - * 更新品牌 - * - * @param updateReqVO 更新信息 - */ - void updateBrand(@Valid BrandUpdateReqVO updateReqVO); - - /** - * 删除品牌 - * - * @param id 编号 - */ - void deleteBrand(Long id); - - /** - * 获得品牌 - * - * @param id 编号 - * @return 品牌 - */ - BrandDO getBrand(Long id); - - /** - * 获得品牌列表 - * - * @param ids 编号 - * @return 品牌列表 - */ - List getBrandList(Collection ids); - - /** - * 获得品牌分页 - * - * @param pageReqVO 分页查询 - * @return 品牌分页 - */ - PageResult getBrandPage(BrandPageReqVO pageReqVO); - - /** - * 获得品牌列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 品牌列表 - */ - List getBrandList(BrandExportReqVO exportReqVO); - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImpl.java deleted file mode 100644 index dedda3a..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -package cn.iocoder.yudao.module.product.service.brand; - -import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; - -import java.util.*; -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; -import cn.iocoder.yudao.module.product.dal.dataobject.brand.BrandDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import cn.iocoder.yudao.module.product.convert.brand.BrandConvert; -import cn.iocoder.yudao.module.product.dal.mysql.brand.BrandMapper; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; - -/** - * 品牌 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Validated -public class BrandServiceImpl implements BrandService { - - @Resource - private BrandMapper brandMapper; - - @Override - public Long createBrand(BrandCreateReqVO createReqVO) { - // 插入 - BrandDO brand = BrandConvert.INSTANCE.convert(createReqVO); - brandMapper.insert(brand); - // 返回 - return brand.getId(); - } - - @Override - public void updateBrand(BrandUpdateReqVO updateReqVO) { - // 校验存在 - this.validateBrandExists(updateReqVO.getId()); - // 更新 - BrandDO updateObj = BrandConvert.INSTANCE.convert(updateReqVO); - brandMapper.updateById(updateObj); - } - - @Override - public void deleteBrand(Long id) { - // 校验存在 - this.validateBrandExists(id); - // 删除 - brandMapper.deleteById(id); - } - - private void validateBrandExists(Long id) { - if (brandMapper.selectById(id) == null) { - throw exception(BRAND_NOT_EXISTS); - } - } - - @Override - public BrandDO getBrand(Long id) { - return brandMapper.selectById(id); - } - - @Override - public List getBrandList(Collection ids) { - return brandMapper.selectBatchIds(ids); - } - - @Override - public PageResult getBrandPage(BrandPageReqVO pageReqVO) { - return brandMapper.selectPage(pageReqVO); - } - - @Override - public List getBrandList(BrandExportReqVO exportReqVO) { - return brandMapper.selectList(exportReqVO); - } - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java new file mode 100644 index 0000000..6d54cd2 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java @@ -0,0 +1,66 @@ +package cn.iocoder.yudao.module.product.service.brand; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO; +import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; + +import javax.validation.Valid; +import java.util.Collection; +import java.util.List; + +/** + * 商品品牌 Service 接口 + * + * @author 芋道源码 + */ +public interface ProductBrandService { + + /** + * 创建品牌 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createProductBrand(@Valid ProductBrandCreateReqVO createReqVO); + + /** + * 更新品牌 + * + * @param updateReqVO 更新信息 + */ + void updateBrand(@Valid ProductBrandUpdateReqVO updateReqVO); + + /** + * 删除品牌 + * + * @param id 编号 + */ + void deleteBrand(Long id); + + /** + * 获得品牌 + * + * @param id 编号 + * @return 品牌 + */ + ProductBrandDO getBrand(Long id); + + /** + * 获得品牌列表 + * + * @param ids 编号 + * @return 品牌列表 + */ + List getBrandList(Collection ids); + + /** + * 获得品牌分页 + * + * @param pageReqVO 分页查询 + * @return 品牌分页 + */ + PageResult getBrandPage(ProductBrandPageReqVO pageReqVO); + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java new file mode 100644 index 0000000..8adfa71 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java @@ -0,0 +1,79 @@ +package cn.iocoder.yudao.module.product.service.brand; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO; +import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert; +import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; +import cn.iocoder.yudao.module.product.dal.mysql.brand.ProductBrandMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.util.Collection; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_BRAND_NOT_EXISTS; + +/** + * 品牌 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class ProductBrandServiceImpl implements ProductBrandService { + + @Resource + private ProductBrandMapper brandMapper; + + @Override + public Long createProductBrand(ProductBrandCreateReqVO createReqVO) { + // 插入 + ProductBrandDO brand = ProductBrandConvert.INSTANCE.convert(createReqVO); + brandMapper.insert(brand); + // 返回 + return brand.getId(); + } + + @Override + public void updateBrand(ProductBrandUpdateReqVO updateReqVO) { + // 校验存在 + validateBrandExists(updateReqVO.getId()); + // 更新 + ProductBrandDO updateObj = ProductBrandConvert.INSTANCE.convert(updateReqVO); + brandMapper.updateById(updateObj); + } + + @Override + public void deleteBrand(Long id) { + // 校验存在 + this.validateBrandExists(id); + // 删除 + brandMapper.deleteById(id); + } + + private void validateBrandExists(Long id) { + if (brandMapper.selectById(id) == null) { + throw exception(PRODUCT_BRAND_NOT_EXISTS); + } + } + + @Override + public ProductBrandDO getBrand(Long id) { + return brandMapper.selectById(id); + } + + @Override + public List getBrandList(Collection ids) { + return brandMapper.selectBatchIds(ids); + } + + @Override + public PageResult getBrandPage(ProductBrandPageReqVO pageReqVO) { + return brandMapper.selectPage(pageReqVO); + } + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImplTest.java deleted file mode 100644 index fc819e6..0000000 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImplTest.java +++ /dev/null @@ -1,173 +0,0 @@ -package cn.iocoder.yudao.module.product.service.brand; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.mock.mockito.MockBean; - -import javax.annotation.Resource; - -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; - -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; -import cn.iocoder.yudao.module.product.dal.dataobject.brand.BrandDO; -import cn.iocoder.yudao.module.product.dal.mysql.brand.BrandMapper; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import javax.annotation.Resource; -import org.springframework.context.annotation.Import; -import java.util.*; - -import static cn.hutool.core.util.RandomUtil.*; -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - -/** -* {@link BrandServiceImpl} 的单元测试类 -* -* @author 芋道源码 -*/ -@Import(BrandServiceImpl.class) -public class BrandServiceImplTest extends BaseDbUnitTest { - - @Resource - private BrandServiceImpl brandService; - - @Resource - private BrandMapper brandMapper; - - @Test - public void testCreateBrand_success() { - // 准备参数 - BrandCreateReqVO reqVO = randomPojo(BrandCreateReqVO.class); - - // 调用 - Long brandId = brandService.createBrand(reqVO); - // 断言 - assertNotNull(brandId); - // 校验记录的属性是否正确 - BrandDO brand = brandMapper.selectById(brandId); - assertPojoEquals(reqVO, brand); - } - - @Test - public void testUpdateBrand_success() { - // mock 数据 - BrandDO dbBrand = randomPojo(BrandDO.class); - brandMapper.insert(dbBrand);// @Sql: 先插入出一条存在的数据 - // 准备参数 - BrandUpdateReqVO reqVO = randomPojo(BrandUpdateReqVO.class, o -> { - o.setId(dbBrand.getId()); // 设置更新的 ID - }); - - // 调用 - brandService.updateBrand(reqVO); - // 校验是否更新正确 - BrandDO brand = brandMapper.selectById(reqVO.getId()); // 获取最新的 - assertPojoEquals(reqVO, brand); - } - - @Test - public void testUpdateBrand_notExists() { - // 准备参数 - BrandUpdateReqVO reqVO = randomPojo(BrandUpdateReqVO.class); - - // 调用, 并断言异常 - assertServiceException(() -> brandService.updateBrand(reqVO), BRAND_NOT_EXISTS); - } - - @Test - public void testDeleteBrand_success() { - // mock 数据 - BrandDO dbBrand = randomPojo(BrandDO.class); - brandMapper.insert(dbBrand);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbBrand.getId(); - - // 调用 - brandService.deleteBrand(id); - // 校验数据不存在了 - assertNull(brandMapper.selectById(id)); - } - - @Test - public void testDeleteBrand_notExists() { - // 准备参数 - Long id = randomLongId(); - - // 调用, 并断言异常 - assertServiceException(() -> brandService.deleteBrand(id), BRAND_NOT_EXISTS); - } - - @Test - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetBrandPage() { - // mock 数据 - BrandDO dbBrand = randomPojo(BrandDO.class, o -> { // 等会查询到 - o.setCategoryId(null); - o.setName(null); - o.setStatus(null); - o.setCreateTime(null); - }); - brandMapper.insert(dbBrand); - // 测试 categoryId 不匹配 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setCategoryId(null))); - // 测试 name 不匹配 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setName(null))); - // 测试 status 不匹配 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setStatus(null))); - // 测试 createTime 不匹配 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setCreateTime(null))); - // 准备参数 - BrandPageReqVO reqVO = new BrandPageReqVO(); - reqVO.setCategoryId(null); - reqVO.setName(null); - reqVO.setStatus(null); - reqVO.setCreateTime((new Date[]{})); - - // 调用 - PageResult pageResult = brandService.getBrandPage(reqVO); - // 断言 - assertEquals(1, pageResult.getTotal()); - assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbBrand, pageResult.getList().get(0)); - } - - @Test - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetBrandList() { - // mock 数据 - BrandDO dbBrand = randomPojo(BrandDO.class, o -> { // 等会查询到 - o.setCategoryId(null); - o.setName(null); - o.setStatus(null); - o.setCreateTime(null); - }); - brandMapper.insert(dbBrand); - // 测试 categoryId 不匹配 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setCategoryId(null))); - // 测试 name 不匹配 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setName(null))); - // 测试 status 不匹配 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setStatus(null))); - // 测试 createTime 不匹配 - brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setCreateTime(null))); - // 准备参数 - BrandExportReqVO reqVO = new BrandExportReqVO(); - reqVO.setCategoryId(null); - reqVO.setName(null); - reqVO.setStatus(null); - reqVO.setCreateTime((new Date[]{})); - - // 调用 - List list = brandService.getBrandList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbBrand, list.get(0)); - } - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImplTest.java new file mode 100644 index 0000000..68ca669 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImplTest.java @@ -0,0 +1,132 @@ +package cn.iocoder.yudao.module.product.service.brand; + +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO; +import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; +import cn.iocoder.yudao.module.product.dal.mysql.brand.ProductBrandMapper; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.util.Date; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_BRAND_NOT_EXISTS; +import static org.junit.jupiter.api.Assertions.*; + +/** +* {@link ProductBrandServiceImpl} 的单元测试类 +* +* @author 芋道源码 +*/ +@Import(ProductBrandServiceImpl.class) +public class ProductBrandServiceImplTest extends BaseDbUnitTest { + + @Resource + private ProductBrandServiceImpl brandService; + + @Resource + private ProductBrandMapper brandMapper; + + @Test + public void testCreateBrand_success() { + // 准备参数 + ProductBrandCreateReqVO reqVO = randomPojo(ProductBrandCreateReqVO.class); + + // 调用 + Long brandId = brandService.createProductBrand(reqVO); + // 断言 + assertNotNull(brandId); + // 校验记录的属性是否正确 + ProductBrandDO brand = brandMapper.selectById(brandId); + assertPojoEquals(reqVO, brand); + } + + @Test + public void testUpdateBrand_success() { + // mock 数据 + ProductBrandDO dbBrand = randomPojo(ProductBrandDO.class); + brandMapper.insert(dbBrand);// @Sql: 先插入出一条存在的数据 + // 准备参数 + ProductBrandUpdateReqVO reqVO = randomPojo(ProductBrandUpdateReqVO.class, o -> { + o.setId(dbBrand.getId()); // 设置更新的 ID + }); + + // 调用 + brandService.updateBrand(reqVO); + // 校验是否更新正确 + ProductBrandDO brand = brandMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, brand); + } + + @Test + public void testUpdateBrand_notExists() { + // 准备参数 + ProductBrandUpdateReqVO reqVO = randomPojo(ProductBrandUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> brandService.updateBrand(reqVO), PRODUCT_BRAND_NOT_EXISTS); + } + + @Test + public void testDeleteBrand_success() { + // mock 数据 + ProductBrandDO dbBrand = randomPojo(ProductBrandDO.class); + brandMapper.insert(dbBrand);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbBrand.getId(); + + // 调用 + brandService.deleteBrand(id); + // 校验数据不存在了 + assertNull(brandMapper.selectById(id)); + } + + @Test + public void testDeleteBrand_notExists() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> brandService.deleteBrand(id), PRODUCT_BRAND_NOT_EXISTS); + } + + @Test + public void testGetBrandPage() { + // mock 数据 + ProductBrandDO dbBrand = randomPojo(ProductBrandDO.class, o -> { // 等会查询到 + o.setName("芋道源码"); + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); + o.setCreateTime(buildTime(2022, 2, 1)); + }); + brandMapper.insert(dbBrand); + // 测试 name 不匹配 + brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setName("源码"))); + // 测试 status 不匹配 + brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); + // 测试 createTime 不匹配 + brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setCreateTime(buildTime(2022, 3, 1)))); + // 准备参数 + ProductBrandPageReqVO reqVO = new ProductBrandPageReqVO(); + reqVO.setName("芋道"); + reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); + reqVO.setCreateTime((new Date[]{buildTime(2022, 1, 1), buildTime(2022, 2, 25)})); + + // 调用 + PageResult pageResult = brandService.getBrandPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbBrand, pageResult.getList().get(0)); + } + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql b/yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql index 7b0e3e4..37fc0ff 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql @@ -16,9 +16,8 @@ CREATE TABLE IF NOT EXISTS "product_category" ( CREATE TABLE IF NOT EXISTS "product_brand" ( "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "category_id" bigint(20) NOT NULL, "name" varchar(255) NOT NULL, - "banner_url" varchar(255) NOT NULL, + "pic_url" varchar(255) NOT NULL, "sort" int(11), "description" varchar(1024), "status" tinyint(4) NOT NULL, @@ -28,4 +27,4 @@ CREATE TABLE IF NOT EXISTS "product_brand" ( "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "deleted" bit NOT NULL DEFAULT FALSE, PRIMARY KEY ("id") -) COMMENT '品牌'; +) COMMENT '商品品牌'; diff --git a/yudao-ui-admin/src/views/mall/product/brand/index.vue b/yudao-ui-admin/src/views/mall/product/brand/index.vue index 0dd2495..1060804 100644 --- a/yudao-ui-admin/src/views/mall/product/brand/index.vue +++ b/yudao-ui-admin/src/views/mall/product/brand/index.vue @@ -26,25 +26,18 @@ 新增 - - - - 导出 - + v-hasPermi="['product:brand:create']">新增 - + - + @@ -77,15 +70,11 @@ - - - - - + + @@ -113,20 +102,18 @@ import { createBrand, deleteBrand, - exportBrandExcel, getBrand, getBrandPage, updateBrand } from "@/api/mall/product/brand"; -import {getProductCategoryList} from "@/api/mall/product/category"; import ImageUpload from '@/components/ImageUpload'; -import Treeselect from "@riophae/vue-treeselect"; import "@riophae/vue-treeselect/dist/vue-treeselect.css"; +import {CommonStatusEnum} from "@/utils/constants"; export default { - name: "Brand", + name: "ProductBrand", components: { - ImageUpload, Treeselect, + ImageUpload }, data() { return { @@ -153,21 +140,18 @@ export default { status: null, createTime: [] }, - // 商品分类树选项 - categoryOptions: [], // 表单参数 form: {}, // 表单校验 rules: { - categoryId: [{required: true, message: "分类编号不能为空", trigger: "blur"}], name: [{required: true, message: "品牌名称不能为空", trigger: "blur"}], - bannerUrl: [{required: true, message: "品牌图片不能为空", trigger: "blur"}], + picUrl: [{required: true, message: "品牌图片不能为空", trigger: "blur"}], + sort: [{required: true, message: "品牌排序不能为空", trigger: "blur"}], status: [{required: true, message: "状态不能为空", trigger: "change"}], } }; }, created() { - this.getTreeselect(); this.getList(); }, methods: { @@ -181,26 +165,6 @@ export default { this.loading = false; }); }, - /** 转换菜单数据结构 */ - normalizer(node) { - if (node.children && !node.children.length) { - delete node.children; - } - return { - id: node.id, - label: node.name, - children: node.children - }; - }, - /** 查询分类下拉树结构 */ - getTreeselect() { - getProductCategoryList().then(response => { - this.categoryOptions = []; - const menu = {id: 0, name: '商品分类', children: []}; - menu.children = this.handleTree(response.data, "id", "pid"); - this.categoryOptions.push(menu); - }); - }, /** 取消按钮 */ cancel() { this.open = false; @@ -210,12 +174,11 @@ export default { reset() { this.form = { id: undefined, - categoryId: undefined, name: undefined, - bannerUrl: undefined, - sort: undefined, + picUrl: undefined, + sort: 0, description: undefined, - status: undefined, + status: CommonStatusEnum.ENABLE, }; this.resetForm("form"); }, @@ -232,14 +195,12 @@ export default { /** 新增按钮操作 */ handleAdd() { this.reset(); - this.getTreeselect(); this.open = true; this.title = "添加品牌"; }, /** 修改按钮操作 */ handleUpdate(row) { this.reset(); - this.getTreeselect(); const id = row.id; getBrand(id).then(response => { this.form = response.data; @@ -280,30 +241,7 @@ export default { this.$modal.msgSuccess("删除成功"); }).catch(() => { }); - }, - /** 导出按钮操作 */ - handleExport() { - // 处理查询参数 - let params = {...this.queryParams}; - params.pageNo = undefined; - params.pageSize = undefined; - // 执行导出 - this.$modal.confirm('是否确认导出所有品牌数据项?').then(() => { - this.exportLoading = true; - return exportBrandExcel(params); - }).then(response => { - this.$download.excel(response, "品牌.xls"); - this.exportLoading = false; - }).catch(() => { - }); } } }; - - diff --git a/yudao-ui-admin/src/views/mall/product/category/index.vue b/yudao-ui-admin/src/views/mall/product/category/index.vue index da600c5..fccadb8 100644 --- a/yudao-ui-admin/src/views/mall/product/category/index.vue +++ b/yudao-ui-admin/src/views/mall/product/category/index.vue @@ -113,7 +113,7 @@ import ImageUpload from '@/components/ImageUpload'; import {CommonStatusEnum} from "@/utils/constants"; export default { - name: "Category", + name: "ProductCategory", components: { Editor, Treeselect, ImageUpload }, -- libgit2 0.21.4