Commit cc6c3d2759a8a659ae4c4f92959ad7d03d840bd5
1 parent
6102c1ce
品牌代码生成
Showing
21 changed files
with
1147 additions
and
8 deletions
sql/mall.sql
| @@ -40,10 +40,32 @@ CREATE TABLE `product_category` | @@ -40,10 +40,32 @@ CREATE TABLE `product_category` | ||
| 40 | PRIMARY KEY (`id`) USING BTREE | 40 | PRIMARY KEY (`id`) USING BTREE |
| 41 | ) ENGINE=InnoDB COMMENT='商品分类'; | 41 | ) ENGINE=InnoDB COMMENT='商品分类'; |
| 42 | 42 | ||
| 43 | +-- ---------------------------- | ||
| 44 | +-- Table structure for product_brand | ||
| 45 | +-- ---------------------------- | ||
| 46 | +DROP TABLE IF EXISTS `product_brand`; | ||
| 47 | +CREATE TABLE `product_brand` | ||
| 48 | +( | ||
| 49 | + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '品牌编号', | ||
| 50 | + `category_id` bigint NOT NULL COMMENT '分类编号', | ||
| 51 | + `name` varchar(255) NOT NULL COMMENT '品牌名称', | ||
| 52 | + `banner_url` varchar(255) NOT NULL COMMENT '品牌图片', | ||
| 53 | + `sort` int DEFAULT '0' COMMENT '品牌排序', | ||
| 54 | + `description` varchar(1024) DEFAULT NULL COMMENT '品牌描述', | ||
| 55 | + `status` tinyint NOT NULL COMMENT '状态', | ||
| 56 | + `creator` varchar(64) DEFAULT '' COMMENT '创建者', | ||
| 57 | + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||
| 58 | + `updater` varchar(64) DEFAULT '' COMMENT '更新者', | ||
| 59 | + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', | ||
| 60 | + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', | ||
| 61 | + `tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号', | ||
| 62 | + PRIMARY KEY (`id`) USING BTREE | ||
| 63 | +) ENGINE=InnoDB COMMENT='品牌'; | ||
| 64 | + | ||
| 43 | -- TODO 父级菜单的 id 处理 | 65 | -- TODO 父级菜单的 id 处理 |
| 44 | INSERT INTO `system_menu` (`id`, `name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES (2000, '商城', '', 1, 1, 0, '/mall', 'merchant', NULL, 0); | 66 | INSERT INTO `system_menu` (`id`, `name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES (2000, '商城', '', 1, 1, 0, '/mall', 'merchant', NULL, 0); |
| 45 | INSERT INTO `system_menu` (`id`, `name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES (2001, '商品管理', '', 1, 1, 2000, 'product', 'dict', NULL, 0); | 67 | INSERT INTO `system_menu` (`id`, `name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES (2001, '商品管理', '', 1, 1, 2000, 'product', 'dict', NULL, 0); |
| 46 | --- 菜单 SQL | 68 | +-- 商品分类 菜单 SQL |
| 47 | INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类管理', '', 2, 0, 2001, 'category', '', 'mall/product/category/index', 0); | 69 | INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类管理', '', 2, 0, 2001, 'category', '', 'mall/product/category/index', 0); |
| 48 | -- 按钮父菜单ID | 70 | -- 按钮父菜单ID |
| 49 | SELECT @parentId := LAST_INSERT_ID(); | 71 | SELECT @parentId := LAST_INSERT_ID(); |
| @@ -53,3 +75,13 @@ INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id` | @@ -53,3 +75,13 @@ INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id` | ||
| 53 | INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类更新', 'product:category:update', 3, 3, @parentId, '', '', '', 0); | 75 | INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类更新', 'product:category:update', 3, 3, @parentId, '', '', '', 0); |
| 54 | INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类删除', 'product:category:delete', 3, 4, @parentId, '', '', '', 0); | 76 | INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类删除', 'product:category:delete', 3, 4, @parentId, '', '', '', 0); |
| 55 | INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类导出', 'product:category:export', 3, 5, @parentId, '', '', '', 0); | 77 | INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类导出', 'product:category:export', 3, 5, @parentId, '', '', '', 0); |
| 78 | +-- 品牌管理 菜单 SQL | ||
| 79 | +INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌管理', '', 2, 0, 2001, 'brand', '', 'mall/product/brand/index', 0); | ||
| 80 | +-- 按钮父菜单ID | ||
| 81 | +SELECT @parentId := LAST_INSERT_ID(); | ||
| 82 | +-- 按钮 SQL | ||
| 83 | +INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌查询', 'product:brand:query', 3, 1, @parentId, '', '', '', 0); | ||
| 84 | +INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌创建', 'product:brand:create', 3, 2, @parentId, '', '', '', 0); | ||
| 85 | +INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌更新', 'product:brand:update', 3, 3, @parentId, '', '', '', 0); | ||
| 86 | +INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌删除', 'product:brand:delete', 3, 4, @parentId, '', '', '', 0); | ||
| 87 | +INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌导出', 'product:brand:export', 3, 5, @parentId, '', '', '', 0); |
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java
| @@ -11,4 +11,7 @@ public interface ErrorCodeConstants { | @@ -11,4 +11,7 @@ public interface ErrorCodeConstants { | ||
| 11 | 11 | ||
| 12 | // ========== 商品分类相关 1008001000============ | 12 | // ========== 商品分类相关 1008001000============ |
| 13 | ErrorCode CATEGORY_NOT_EXISTS = new ErrorCode(1008001000, "商品分类不存在"); | 13 | ErrorCode CATEGORY_NOT_EXISTS = new ErrorCode(1008001000, "商品分类不存在"); |
| 14 | + | ||
| 15 | + // ========== 品牌相关编号 1008002000 ========== | ||
| 16 | + ErrorCode BRAND_NOT_EXISTS = new ErrorCode(1008002000, "品牌不存在"); | ||
| 14 | } | 17 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/BrandController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.product.controller.admin.brand; | ||
| 2 | + | ||
| 3 | +import org.springframework.web.bind.annotation.*; | ||
| 4 | +import javax.annotation.Resource; | ||
| 5 | +import org.springframework.validation.annotation.Validated; | ||
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 7 | +import io.swagger.annotations.*; | ||
| 8 | + | ||
| 9 | +import javax.validation.constraints.*; | ||
| 10 | +import javax.validation.*; | ||
| 11 | +import javax.servlet.http.*; | ||
| 12 | +import java.util.*; | ||
| 13 | +import java.io.IOException; | ||
| 14 | + | ||
| 15 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 16 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 17 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 18 | + | ||
| 19 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 20 | + | ||
| 21 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||
| 22 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | ||
| 23 | + | ||
| 24 | +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; | ||
| 25 | +import cn.iocoder.yudao.module.product.dal.dataobject.brand.BrandDO; | ||
| 26 | +import cn.iocoder.yudao.module.product.convert.brand.BrandConvert; | ||
| 27 | +import cn.iocoder.yudao.module.product.service.brand.BrandService; | ||
| 28 | + | ||
| 29 | +@Api(tags = "管理后台 - 品牌") | ||
| 30 | +@RestController | ||
| 31 | +@RequestMapping("/product/brand") | ||
| 32 | +@Validated | ||
| 33 | +public class BrandController { | ||
| 34 | + | ||
| 35 | + @Resource | ||
| 36 | + private BrandService brandService; | ||
| 37 | + | ||
| 38 | + @PostMapping("/create") | ||
| 39 | + @ApiOperation("创建品牌") | ||
| 40 | + @PreAuthorize("@ss.hasPermission('product:brand:create')") | ||
| 41 | + public CommonResult<Long> createBrand(@Valid @RequestBody BrandCreateReqVO createReqVO) { | ||
| 42 | + return success(brandService.createBrand(createReqVO)); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + @PutMapping("/update") | ||
| 46 | + @ApiOperation("更新品牌") | ||
| 47 | + @PreAuthorize("@ss.hasPermission('product:brand:update')") | ||
| 48 | + public CommonResult<Boolean> updateBrand(@Valid @RequestBody BrandUpdateReqVO updateReqVO) { | ||
| 49 | + brandService.updateBrand(updateReqVO); | ||
| 50 | + return success(true); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @DeleteMapping("/delete") | ||
| 54 | + @ApiOperation("删除品牌") | ||
| 55 | + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) | ||
| 56 | + @PreAuthorize("@ss.hasPermission('product:brand:delete')") | ||
| 57 | + public CommonResult<Boolean> deleteBrand(@RequestParam("id") Long id) { | ||
| 58 | + brandService.deleteBrand(id); | ||
| 59 | + return success(true); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @GetMapping("/get") | ||
| 63 | + @ApiOperation("获得品牌") | ||
| 64 | + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) | ||
| 65 | + @PreAuthorize("@ss.hasPermission('product:brand:query')") | ||
| 66 | + public CommonResult<BrandRespVO> getBrand(@RequestParam("id") Long id) { | ||
| 67 | + BrandDO brand = brandService.getBrand(id); | ||
| 68 | + return success(BrandConvert.INSTANCE.convert(brand)); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @GetMapping("/list") | ||
| 72 | + @ApiOperation("获得品牌列表") | ||
| 73 | + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) | ||
| 74 | + @PreAuthorize("@ss.hasPermission('product:brand:query')") | ||
| 75 | + public CommonResult<List<BrandRespVO>> getBrandList(@RequestParam("ids") Collection<Long> ids) { | ||
| 76 | + List<BrandDO> list = brandService.getBrandList(ids); | ||
| 77 | + return success(BrandConvert.INSTANCE.convertList(list)); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + @GetMapping("/page") | ||
| 81 | + @ApiOperation("获得品牌分页") | ||
| 82 | + @PreAuthorize("@ss.hasPermission('product:brand:query')") | ||
| 83 | + public CommonResult<PageResult<BrandRespVO>> getBrandPage(@Valid BrandPageReqVO pageVO) { | ||
| 84 | + PageResult<BrandDO> pageResult = brandService.getBrandPage(pageVO); | ||
| 85 | + return success(BrandConvert.INSTANCE.convertPage(pageResult)); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + @GetMapping("/export-excel") | ||
| 89 | + @ApiOperation("导出品牌 Excel") | ||
| 90 | + @PreAuthorize("@ss.hasPermission('product:brand:export')") | ||
| 91 | + @OperateLog(type = EXPORT) | ||
| 92 | + public void exportBrandExcel(@Valid BrandExportReqVO exportReqVO, | ||
| 93 | + HttpServletResponse response) throws IOException { | ||
| 94 | + List<BrandDO> list = brandService.getBrandList(exportReqVO); | ||
| 95 | + // 导出 Excel | ||
| 96 | + List<BrandExcelVO> datas = BrandConvert.INSTANCE.convertList02(list); | ||
| 97 | + ExcelUtils.write(response, "品牌.xls", "数据", BrandExcelVO.class, datas); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | +} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandBaseVO.java
0 → 100644
| 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 javax.validation.constraints.*; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | +* 品牌 Base VO,提供给添加、修改、详细的子 VO 使用 | ||
| 10 | +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | ||
| 11 | +*/ | ||
| 12 | +@Data | ||
| 13 | +public class BrandBaseVO { | ||
| 14 | + | ||
| 15 | + @ApiModelProperty(value = "分类编号", required = true, example = "1") | ||
| 16 | + @NotNull(message = "分类编号不能为空") | ||
| 17 | + private Long categoryId; | ||
| 18 | + | ||
| 19 | + @ApiModelProperty(value = "品牌名称", required = true, example = "芋道") | ||
| 20 | + @NotNull(message = "品牌名称不能为空") | ||
| 21 | + private String name; | ||
| 22 | + | ||
| 23 | + @ApiModelProperty(value = "品牌图片", required = true) | ||
| 24 | + @NotNull(message = "品牌图片不能为空") | ||
| 25 | + private String bannerUrl; | ||
| 26 | + | ||
| 27 | + @ApiModelProperty(value = "品牌排序", example = "1") | ||
| 28 | + private Integer sort; | ||
| 29 | + | ||
| 30 | + @ApiModelProperty(value = "品牌描述", example = "描述") | ||
| 31 | + private String description; | ||
| 32 | + | ||
| 33 | + @ApiModelProperty(value = "状态", required = true, example = "0") | ||
| 34 | + @NotNull(message = "状态不能为空") | ||
| 35 | + private Integer status; | ||
| 36 | + | ||
| 37 | +} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandCreateReqVO.java
0 → 100644
| 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 javax.validation.constraints.*; | ||
| 7 | + | ||
| 8 | +@ApiModel("管理后台 - 品牌创建 Request VO") | ||
| 9 | +@Data | ||
| 10 | +@EqualsAndHashCode(callSuper = true) | ||
| 11 | +@ToString(callSuper = true) | ||
| 12 | +public class BrandCreateReqVO extends BrandBaseVO { | ||
| 13 | + | ||
| 14 | +} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandExcelVO.java
0 → 100644
| 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
0 → 100644
| 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 beginCreateTime; | ||
| 27 | + | ||
| 28 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 29 | + @ApiModelProperty(value = "结束创建时间") | ||
| 30 | + private Date endCreateTime; | ||
| 31 | + | ||
| 32 | +} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandPageReqVO.java
0 → 100644
| 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("管理后台 - 品牌分页 Request VO") | ||
| 12 | +@Data | ||
| 13 | +@EqualsAndHashCode(callSuper = true) | ||
| 14 | +@ToString(callSuper = true) | ||
| 15 | +public class BrandPageReqVO extends PageParam { | ||
| 16 | + | ||
| 17 | + @ApiModelProperty(value = "分类编号", example = "1") | ||
| 18 | + private Long categoryId; | ||
| 19 | + | ||
| 20 | + @ApiModelProperty(value = "品牌名称", example = "芋道") | ||
| 21 | + private String name; | ||
| 22 | + | ||
| 23 | + @ApiModelProperty(value = "状态", example = "0") | ||
| 24 | + private Integer status; | ||
| 25 | + | ||
| 26 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 27 | + @ApiModelProperty(value = "开始创建时间") | ||
| 28 | + private Date beginCreateTime; | ||
| 29 | + | ||
| 30 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 31 | + @ApiModelProperty(value = "结束创建时间") | ||
| 32 | + private Date endCreateTime; | ||
| 33 | + | ||
| 34 | +} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandRespVO.java
0 → 100644
| 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 | +@ApiModel("管理后台 - 品牌 Response VO") | ||
| 8 | +@Data | ||
| 9 | +@EqualsAndHashCode(callSuper = true) | ||
| 10 | +@ToString(callSuper = true) | ||
| 11 | +public class BrandRespVO extends BrandBaseVO { | ||
| 12 | + | ||
| 13 | + @ApiModelProperty(value = "品牌编号", required = true, example = "1") | ||
| 14 | + private Long id; | ||
| 15 | + | ||
| 16 | + @ApiModelProperty(value = "创建时间", required = true) | ||
| 17 | + private Date createTime; | ||
| 18 | + | ||
| 19 | +} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/BrandUpdateReqVO.java
0 → 100644
| 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 javax.validation.constraints.*; | ||
| 7 | + | ||
| 8 | +@ApiModel("管理后台 - 品牌更新 Request VO") | ||
| 9 | +@Data | ||
| 10 | +@EqualsAndHashCode(callSuper = true) | ||
| 11 | +@ToString(callSuper = true) | ||
| 12 | +public class BrandUpdateReqVO extends BrandBaseVO { | ||
| 13 | + | ||
| 14 | + @ApiModelProperty(value = "品牌编号", required = true, example = "1") | ||
| 15 | + @NotNull(message = "品牌编号不能为空") | ||
| 16 | + private Long id; | ||
| 17 | + | ||
| 18 | +} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/brand/BrandConvert.java
0 → 100644
| 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/dal/dataobject/brand/BrandDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.product.dal.dataobject.brand; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 7 | +import lombok.*; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 品牌 DO | ||
| 11 | + * | ||
| 12 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +@TableName("product_brand") | ||
| 15 | +@Data | ||
| 16 | +@EqualsAndHashCode(callSuper = true) | ||
| 17 | +@ToString(callSuper = true) | ||
| 18 | +@Builder | ||
| 19 | +@NoArgsConstructor | ||
| 20 | +@AllArgsConstructor | ||
| 21 | +public class BrandDO extends BaseDO { | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 品牌编号 | ||
| 25 | + */ | ||
| 26 | + @TableId | ||
| 27 | + private Long id; | ||
| 28 | + /** | ||
| 29 | + * 分类编号 | ||
| 30 | + */ | ||
| 31 | + private Long categoryId; | ||
| 32 | + /** | ||
| 33 | + * 品牌名称 | ||
| 34 | + */ | ||
| 35 | + private String name; | ||
| 36 | + /** | ||
| 37 | + * 品牌图片 | ||
| 38 | + */ | ||
| 39 | + private String bannerUrl; | ||
| 40 | + /** | ||
| 41 | + * 品牌排序 | ||
| 42 | + */ | ||
| 43 | + private Integer sort; | ||
| 44 | + /** | ||
| 45 | + * 品牌描述 | ||
| 46 | + */ | ||
| 47 | + private String description; | ||
| 48 | + /** | ||
| 49 | + * 状态 | ||
| 50 | + * <p> | ||
| 51 | + * 枚举 {@link CommonStatusEnum} | ||
| 52 | + */ | ||
| 53 | + private Integer status; | ||
| 54 | + | ||
| 55 | +} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/category/CategoryDO.java
| 1 | package cn.iocoder.yudao.module.product.dal.dataobject.category; | 1 | package cn.iocoder.yudao.module.product.dal.dataobject.category; |
| 2 | 2 | ||
| 3 | -import lombok.*; | ||
| 4 | -import java.util.*; | ||
| 5 | -import com.baomidou.mybatisplus.annotation.*; | 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 6 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 7 | +import lombok.*; | ||
| 7 | 8 | ||
| 8 | /** | 9 | /** |
| 9 | * 商品分类 DO | 10 | * 商品分类 DO |
| @@ -50,8 +51,8 @@ public class CategoryDO extends BaseDO { | @@ -50,8 +51,8 @@ public class CategoryDO extends BaseDO { | ||
| 50 | private String description; | 51 | private String description; |
| 51 | /** | 52 | /** |
| 52 | * 开启状态 | 53 | * 开启状态 |
| 53 | - * | ||
| 54 | - * 枚举 {@link TODO common_status 对应的类} | 54 | + * <p> |
| 55 | + * 枚举 {@link CommonStatusEnum} | ||
| 55 | */ | 56 | */ |
| 56 | private Integer status; | 57 | private Integer status; |
| 57 | 58 |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/BrandMapper.java
0 → 100644
| 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.getBeginCreateTime(), reqVO.getEndCreateTime()) | ||
| 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.getBeginCreateTime(), reqVO.getEndCreateTime()) | ||
| 35 | + .orderByDesc(BrandDO::getId)); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | +} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.product.service.brand; | ||
| 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; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 品牌 Service 接口 | ||
| 11 | + * | ||
| 12 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +public interface BrandService { | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 创建品牌 | ||
| 18 | + * | ||
| 19 | + * @param createReqVO 创建信息 | ||
| 20 | + * @return 编号 | ||
| 21 | + */ | ||
| 22 | + Long createBrand(@Valid BrandCreateReqVO createReqVO); | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 更新品牌 | ||
| 26 | + * | ||
| 27 | + * @param updateReqVO 更新信息 | ||
| 28 | + */ | ||
| 29 | + void updateBrand(@Valid BrandUpdateReqVO updateReqVO); | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 删除品牌 | ||
| 33 | + * | ||
| 34 | + * @param id 编号 | ||
| 35 | + */ | ||
| 36 | + void deleteBrand(Long id); | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 获得品牌 | ||
| 40 | + * | ||
| 41 | + * @param id 编号 | ||
| 42 | + * @return 品牌 | ||
| 43 | + */ | ||
| 44 | + BrandDO getBrand(Long id); | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 获得品牌列表 | ||
| 48 | + * | ||
| 49 | + * @param ids 编号 | ||
| 50 | + * @return 品牌列表 | ||
| 51 | + */ | ||
| 52 | + List<BrandDO> getBrandList(Collection<Long> ids); | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 获得品牌分页 | ||
| 56 | + * | ||
| 57 | + * @param pageReqVO 分页查询 | ||
| 58 | + * @return 品牌分页 | ||
| 59 | + */ | ||
| 60 | + PageResult<BrandDO> getBrandPage(BrandPageReqVO pageReqVO); | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 获得品牌列表, 用于 Excel 导出 | ||
| 64 | + * | ||
| 65 | + * @param exportReqVO 查询条件 | ||
| 66 | + * @return 品牌列表 | ||
| 67 | + */ | ||
| 68 | + List<BrandDO> getBrandList(BrandExportReqVO exportReqVO); | ||
| 69 | + | ||
| 70 | +} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.product.service.brand; | ||
| 2 | + | ||
| 3 | +import org.springframework.stereotype.Service; | ||
| 4 | +import javax.annotation.Resource; | ||
| 5 | +import org.springframework.validation.annotation.Validated; | ||
| 6 | + | ||
| 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; | ||
| 14 | + | ||
| 15 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 16 | +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * 品牌 Service 实现类 | ||
| 20 | + * | ||
| 21 | + * @author 芋道源码 | ||
| 22 | + */ | ||
| 23 | +@Service | ||
| 24 | +@Validated | ||
| 25 | +public class BrandServiceImpl implements BrandService { | ||
| 26 | + | ||
| 27 | + @Resource | ||
| 28 | + private BrandMapper brandMapper; | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public Long createBrand(BrandCreateReqVO createReqVO) { | ||
| 32 | + // 插入 | ||
| 33 | + BrandDO brand = BrandConvert.INSTANCE.convert(createReqVO); | ||
| 34 | + brandMapper.insert(brand); | ||
| 35 | + // 返回 | ||
| 36 | + return brand.getId(); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + @Override | ||
| 40 | + public void updateBrand(BrandUpdateReqVO updateReqVO) { | ||
| 41 | + // 校验存在 | ||
| 42 | + this.validateBrandExists(updateReqVO.getId()); | ||
| 43 | + // 更新 | ||
| 44 | + BrandDO updateObj = BrandConvert.INSTANCE.convert(updateReqVO); | ||
| 45 | + brandMapper.updateById(updateObj); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + @Override | ||
| 49 | + public void deleteBrand(Long id) { | ||
| 50 | + // 校验存在 | ||
| 51 | + this.validateBrandExists(id); | ||
| 52 | + // 删除 | ||
| 53 | + brandMapper.deleteById(id); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + private void validateBrandExists(Long id) { | ||
| 57 | + if (brandMapper.selectById(id) == null) { | ||
| 58 | + throw exception(BRAND_NOT_EXISTS); | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public BrandDO getBrand(Long id) { | ||
| 64 | + return brandMapper.selectById(id); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + @Override | ||
| 68 | + public List<BrandDO> getBrandList(Collection<Long> ids) { | ||
| 69 | + return brandMapper.selectBatchIds(ids); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @Override | ||
| 73 | + public PageResult<BrandDO> getBrandPage(BrandPageReqVO pageReqVO) { | ||
| 74 | + return brandMapper.selectPage(pageReqVO); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @Override | ||
| 78 | + public List<BrandDO> getBrandList(BrandExportReqVO exportReqVO) { | ||
| 79 | + return brandMapper.selectList(exportReqVO); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | +} |
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/BrandServiceImplTest.java
0 → 100644
| 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.setBeginCreateTime(null); | ||
| 131 | + reqVO.setEndCreateTime(null); | ||
| 132 | + | ||
| 133 | + // 调用 | ||
| 134 | + PageResult<BrandDO> pageResult = brandService.getBrandPage(reqVO); | ||
| 135 | + // 断言 | ||
| 136 | + assertEquals(1, pageResult.getTotal()); | ||
| 137 | + assertEquals(1, pageResult.getList().size()); | ||
| 138 | + assertPojoEquals(dbBrand, pageResult.getList().get(0)); | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + @Test | ||
| 142 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | ||
| 143 | + public void testGetBrandList() { | ||
| 144 | + // mock 数据 | ||
| 145 | + BrandDO dbBrand = randomPojo(BrandDO.class, o -> { // 等会查询到 | ||
| 146 | + o.setCategoryId(null); | ||
| 147 | + o.setName(null); | ||
| 148 | + o.setStatus(null); | ||
| 149 | + o.setCreateTime(null); | ||
| 150 | + }); | ||
| 151 | + brandMapper.insert(dbBrand); | ||
| 152 | + // 测试 categoryId 不匹配 | ||
| 153 | + brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setCategoryId(null))); | ||
| 154 | + // 测试 name 不匹配 | ||
| 155 | + brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setName(null))); | ||
| 156 | + // 测试 status 不匹配 | ||
| 157 | + brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setStatus(null))); | ||
| 158 | + // 测试 createTime 不匹配 | ||
| 159 | + brandMapper.insert(cloneIgnoreId(dbBrand, o -> o.setCreateTime(null))); | ||
| 160 | + // 准备参数 | ||
| 161 | + BrandExportReqVO reqVO = new BrandExportReqVO(); | ||
| 162 | + reqVO.setCategoryId(null); | ||
| 163 | + reqVO.setName(null); | ||
| 164 | + reqVO.setStatus(null); | ||
| 165 | + reqVO.setBeginCreateTime(null); | ||
| 166 | + reqVO.setEndCreateTime(null); | ||
| 167 | + | ||
| 168 | + // 调用 | ||
| 169 | + List<BrandDO> list = brandService.getBrandList(reqVO); | ||
| 170 | + // 断言 | ||
| 171 | + assertEquals(1, list.size()); | ||
| 172 | + assertPojoEquals(dbBrand, list.get(0)); | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | +} |
yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/clean.sql
yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql
| @@ -14,4 +14,21 @@ CREATE TABLE IF NOT EXISTS "product_category" ( | @@ -14,4 +14,21 @@ CREATE TABLE IF NOT EXISTS "product_category" ( | ||
| 14 | "deleted" bit NOT NULL DEFAULT FALSE, | 14 | "deleted" bit NOT NULL DEFAULT FALSE, |
| 15 | "tenant_id" bigint(20) NOT NULL, | 15 | "tenant_id" bigint(20) NOT NULL, |
| 16 | PRIMARY KEY ("id") | 16 | PRIMARY KEY ("id") |
| 17 | -) COMMENT '商品分类'; | ||
| 18 | \ No newline at end of file | 17 | \ No newline at end of file |
| 18 | +) COMMENT '商品分类'; | ||
| 19 | + | ||
| 20 | +CREATE TABLE IF NOT EXISTS "product_brand" ( | ||
| 21 | + "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, | ||
| 22 | + "category_id" bigint(20) NOT NULL, | ||
| 23 | + "name" varchar(255) NOT NULL, | ||
| 24 | + "banner_url" varchar(255) NOT NULL, | ||
| 25 | + "sort" int(11), | ||
| 26 | + "description" varchar(1024), | ||
| 27 | + "status" tinyint(4) NOT NULL, | ||
| 28 | + "creator" varchar(64) DEFAULT '', | ||
| 29 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| 30 | + "updater" varchar(64) DEFAULT '', | ||
| 31 | + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
| 32 | + "deleted" bit NOT NULL DEFAULT FALSE, | ||
| 33 | + "tenant_id" bigint(20) NOT NULL, | ||
| 34 | + PRIMARY KEY ("id") | ||
| 35 | +) COMMENT '品牌'; |
yudao-ui-admin/src/api/mall/product/brand.js
0 → 100644
| 1 | +import request from '@/utils/request' | ||
| 2 | + | ||
| 3 | +// 创建品牌 | ||
| 4 | +export function createBrand(data) { | ||
| 5 | + return request({ | ||
| 6 | + url: '/product/brand/create', | ||
| 7 | + method: 'post', | ||
| 8 | + data: data | ||
| 9 | + }) | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +// 更新品牌 | ||
| 13 | +export function updateBrand(data) { | ||
| 14 | + return request({ | ||
| 15 | + url: '/product/brand/update', | ||
| 16 | + method: 'put', | ||
| 17 | + data: data | ||
| 18 | + }) | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +// 删除品牌 | ||
| 22 | +export function deleteBrand(id) { | ||
| 23 | + return request({ | ||
| 24 | + url: '/product/brand/delete?id=' + id, | ||
| 25 | + method: 'delete' | ||
| 26 | + }) | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +// 获得品牌 | ||
| 30 | +export function getBrand(id) { | ||
| 31 | + return request({ | ||
| 32 | + url: '/product/brand/get?id=' + id, | ||
| 33 | + method: 'get' | ||
| 34 | + }) | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +// 获得品牌分页 | ||
| 38 | +export function getBrandPage(query) { | ||
| 39 | + return request({ | ||
| 40 | + url: '/product/brand/page', | ||
| 41 | + method: 'get', | ||
| 42 | + params: query | ||
| 43 | + }) | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +// 导出品牌 Excel | ||
| 47 | +export function exportBrandExcel(query) { | ||
| 48 | + return request({ | ||
| 49 | + url: '/product/brand/export-excel', | ||
| 50 | + method: 'get', | ||
| 51 | + params: query, | ||
| 52 | + responseType: 'blob' | ||
| 53 | + }) | ||
| 54 | +} |
yudao-ui-admin/src/views/mall/product/brand/index.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div class="app-container"> | ||
| 3 | + | ||
| 4 | + <!-- 搜索工作栏 --> | ||
| 5 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> | ||
| 6 | + <el-form-item label="分类编号" prop="categoryId"> | ||
| 7 | + <el-input v-model="queryParams.categoryId" placeholder="请输入分类编号" clearable @keyup.enter.native="handleQuery"/> | ||
| 8 | + </el-form-item> | ||
| 9 | + <el-form-item label="品牌名称" prop="name"> | ||
| 10 | + <el-input v-model="queryParams.name" placeholder="请输入品牌名称" clearable @keyup.enter.native="handleQuery"/> | ||
| 11 | + </el-form-item> | ||
| 12 | + <el-form-item label="状态" prop="status"> | ||
| 13 | + <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small"> | ||
| 14 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)" | ||
| 15 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | ||
| 16 | + </el-select> | ||
| 17 | + </el-form-item> | ||
| 18 | + <el-form-item label="创建时间"> | ||
| 19 | + <el-date-picker v-model="dateRangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd" | ||
| 20 | + type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/> | ||
| 21 | + </el-form-item> | ||
| 22 | + <el-form-item> | ||
| 23 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | ||
| 24 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | ||
| 25 | + </el-form-item> | ||
| 26 | + </el-form> | ||
| 27 | + | ||
| 28 | + <!-- 操作工具栏 --> | ||
| 29 | + <el-row :gutter="10" class="mb8"> | ||
| 30 | + <el-col :span="1.5"> | ||
| 31 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" | ||
| 32 | + v-hasPermi="['product:brand:create']">新增 | ||
| 33 | + </el-button> | ||
| 34 | + </el-col> | ||
| 35 | + <el-col :span="1.5"> | ||
| 36 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" | ||
| 37 | + :loading="exportLoading" | ||
| 38 | + v-hasPermi="['product:brand:export']">导出 | ||
| 39 | + </el-button> | ||
| 40 | + </el-col> | ||
| 41 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | ||
| 42 | + </el-row> | ||
| 43 | + | ||
| 44 | + <!-- 列表 --> | ||
| 45 | + <el-table v-loading="loading" :data="list"> | ||
| 46 | + <el-table-column label="品牌编号" align="center" prop="id"/> | ||
| 47 | + <el-table-column label="分类编号" align="center" prop="categoryId"/> | ||
| 48 | + <el-table-column label="品牌名称" align="center" prop="name"/> | ||
| 49 | + <el-table-column label="品牌图片" align="center" prop="bannerUrl"/> | ||
| 50 | + <el-table-column label="品牌排序" align="center" prop="sort"/> | ||
| 51 | + <el-table-column label="品牌描述" align="center" prop="description"/> | ||
| 52 | + <el-table-column label="状态" align="center" prop="status"> | ||
| 53 | + <template slot-scope="scope"> | ||
| 54 | + <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/> | ||
| 55 | + </template> | ||
| 56 | + </el-table-column> | ||
| 57 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | ||
| 58 | + <template slot-scope="scope"> | ||
| 59 | + <span>{{ parseTime(scope.row.createTime) }}</span> | ||
| 60 | + </template> | ||
| 61 | + </el-table-column> | ||
| 62 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ||
| 63 | + <template slot-scope="scope"> | ||
| 64 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" | ||
| 65 | + v-hasPermi="['product:brand:update']">修改 | ||
| 66 | + </el-button> | ||
| 67 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | ||
| 68 | + v-hasPermi="['product:brand:delete']">删除 | ||
| 69 | + </el-button> | ||
| 70 | + </template> | ||
| 71 | + </el-table-column> | ||
| 72 | + </el-table> | ||
| 73 | + <!-- 分页组件 --> | ||
| 74 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | ||
| 75 | + @pagination="getList"/> | ||
| 76 | + | ||
| 77 | + <!-- 对话框(添加 / 修改) --> | ||
| 78 | + <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> | ||
| 79 | + <el-form ref="form" :model="form" :rules="rules" label-width="80px"> | ||
| 80 | + <el-form-item label="分类编号" prop="categoryId"> | ||
| 81 | + <el-input v-model="form.categoryId" placeholder="请输入分类编号"/> | ||
| 82 | + </el-form-item> | ||
| 83 | + <el-form-item label="品牌名称" prop="name"> | ||
| 84 | + <el-input v-model="form.name" placeholder="请输入品牌名称"/> | ||
| 85 | + </el-form-item> | ||
| 86 | + <el-form-item label="品牌图片"> | ||
| 87 | + <imageUpload v-model="form.bannerUrl" :limit="1"/> | ||
| 88 | + </el-form-item> | ||
| 89 | + <el-form-item label="品牌排序" prop="sort"> | ||
| 90 | + <el-input v-model="form.sort" placeholder="请输入品牌排序"/> | ||
| 91 | + </el-form-item> | ||
| 92 | + <el-form-item label="品牌描述" prop="description"> | ||
| 93 | + <el-input v-model="form.description" type="textarea" placeholder="请输入内容"/> | ||
| 94 | + </el-form-item> | ||
| 95 | + <el-form-item label="状态" prop="status"> | ||
| 96 | + <el-select v-model="form.status" placeholder="请选择状态"> | ||
| 97 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)" | ||
| 98 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"/> | ||
| 99 | + </el-select> | ||
| 100 | + </el-form-item> | ||
| 101 | + </el-form> | ||
| 102 | + <div slot="footer" class="dialog-footer"> | ||
| 103 | + <el-button type="primary" @click="submitForm">确 定</el-button> | ||
| 104 | + <el-button @click="cancel">取 消</el-button> | ||
| 105 | + </div> | ||
| 106 | + </el-dialog> | ||
| 107 | + </div> | ||
| 108 | +</template> | ||
| 109 | + | ||
| 110 | +<script> | ||
| 111 | +import { | ||
| 112 | + createBrand, | ||
| 113 | + deleteBrand, | ||
| 114 | + exportBrandExcel, | ||
| 115 | + getBrand, | ||
| 116 | + getBrandPage, | ||
| 117 | + updateBrand | ||
| 118 | +} from "@/api/mall/product/brand"; | ||
| 119 | +import ImageUpload from '@/components/ImageUpload'; | ||
| 120 | + | ||
| 121 | +export default { | ||
| 122 | + name: "Brand", | ||
| 123 | + components: { | ||
| 124 | + ImageUpload, | ||
| 125 | + }, | ||
| 126 | + data() { | ||
| 127 | + return { | ||
| 128 | + // 遮罩层 | ||
| 129 | + loading: true, | ||
| 130 | + // 导出遮罩层 | ||
| 131 | + exportLoading: false, | ||
| 132 | + // 显示搜索条件 | ||
| 133 | + showSearch: true, | ||
| 134 | + // 总条数 | ||
| 135 | + total: 0, | ||
| 136 | + // 品牌列表 | ||
| 137 | + list: [], | ||
| 138 | + // 弹出层标题 | ||
| 139 | + title: "", | ||
| 140 | + // 是否显示弹出层 | ||
| 141 | + open: false, | ||
| 142 | + dateRangeCreateTime: [], | ||
| 143 | + // 查询参数 | ||
| 144 | + queryParams: { | ||
| 145 | + pageNo: 1, | ||
| 146 | + pageSize: 10, | ||
| 147 | + categoryId: null, | ||
| 148 | + name: null, | ||
| 149 | + status: null, | ||
| 150 | + }, | ||
| 151 | + // 表单参数 | ||
| 152 | + form: {}, | ||
| 153 | + // 表单校验 | ||
| 154 | + rules: { | ||
| 155 | + categoryId: [{required: true, message: "分类编号不能为空", trigger: "blur"}], | ||
| 156 | + name: [{required: true, message: "品牌名称不能为空", trigger: "blur"}], | ||
| 157 | + bannerUrl: [{required: true, message: "品牌图片不能为空", trigger: "blur"}], | ||
| 158 | + status: [{required: true, message: "状态不能为空", trigger: "change"}], | ||
| 159 | + } | ||
| 160 | + }; | ||
| 161 | + }, | ||
| 162 | + created() { | ||
| 163 | + this.getList(); | ||
| 164 | + }, | ||
| 165 | + methods: { | ||
| 166 | + /** 查询列表 */ | ||
| 167 | + getList() { | ||
| 168 | + this.loading = true; | ||
| 169 | + // 处理查询参数 | ||
| 170 | + let params = {...this.queryParams}; | ||
| 171 | + this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime'); | ||
| 172 | + // 执行查询 | ||
| 173 | + getBrandPage(params).then(response => { | ||
| 174 | + this.list = response.data.list; | ||
| 175 | + this.total = response.data.total; | ||
| 176 | + this.loading = false; | ||
| 177 | + }); | ||
| 178 | + }, | ||
| 179 | + /** 取消按钮 */ | ||
| 180 | + cancel() { | ||
| 181 | + this.open = false; | ||
| 182 | + this.reset(); | ||
| 183 | + }, | ||
| 184 | + /** 表单重置 */ | ||
| 185 | + reset() { | ||
| 186 | + this.form = { | ||
| 187 | + id: undefined, | ||
| 188 | + categoryId: undefined, | ||
| 189 | + name: undefined, | ||
| 190 | + bannerUrl: undefined, | ||
| 191 | + sort: undefined, | ||
| 192 | + description: undefined, | ||
| 193 | + status: undefined, | ||
| 194 | + }; | ||
| 195 | + this.resetForm("form"); | ||
| 196 | + }, | ||
| 197 | + /** 搜索按钮操作 */ | ||
| 198 | + handleQuery() { | ||
| 199 | + this.queryParams.pageNo = 1; | ||
| 200 | + this.getList(); | ||
| 201 | + }, | ||
| 202 | + /** 重置按钮操作 */ | ||
| 203 | + resetQuery() { | ||
| 204 | + this.dateRangeCreateTime = []; | ||
| 205 | + this.resetForm("queryForm"); | ||
| 206 | + this.handleQuery(); | ||
| 207 | + }, | ||
| 208 | + /** 新增按钮操作 */ | ||
| 209 | + handleAdd() { | ||
| 210 | + this.reset(); | ||
| 211 | + this.open = true; | ||
| 212 | + this.title = "添加品牌"; | ||
| 213 | + }, | ||
| 214 | + /** 修改按钮操作 */ | ||
| 215 | + handleUpdate(row) { | ||
| 216 | + this.reset(); | ||
| 217 | + const id = row.id; | ||
| 218 | + getBrand(id).then(response => { | ||
| 219 | + this.form = response.data; | ||
| 220 | + this.open = true; | ||
| 221 | + this.title = "修改品牌"; | ||
| 222 | + }); | ||
| 223 | + }, | ||
| 224 | + /** 提交按钮 */ | ||
| 225 | + submitForm() { | ||
| 226 | + this.$refs["form"].validate(valid => { | ||
| 227 | + if (!valid) { | ||
| 228 | + return; | ||
| 229 | + } | ||
| 230 | + // 修改的提交 | ||
| 231 | + if (this.form.id != null) { | ||
| 232 | + updateBrand(this.form).then(response => { | ||
| 233 | + this.$modal.msgSuccess("修改成功"); | ||
| 234 | + this.open = false; | ||
| 235 | + this.getList(); | ||
| 236 | + }); | ||
| 237 | + return; | ||
| 238 | + } | ||
| 239 | + // 添加的提交 | ||
| 240 | + createBrand(this.form).then(response => { | ||
| 241 | + this.$modal.msgSuccess("新增成功"); | ||
| 242 | + this.open = false; | ||
| 243 | + this.getList(); | ||
| 244 | + }); | ||
| 245 | + }); | ||
| 246 | + }, | ||
| 247 | + /** 删除按钮操作 */ | ||
| 248 | + handleDelete(row) { | ||
| 249 | + const id = row.id; | ||
| 250 | + this.$modal.confirm('是否确认删除品牌编号为"' + id + '"的数据项?').then(function () { | ||
| 251 | + return deleteBrand(id); | ||
| 252 | + }).then(() => { | ||
| 253 | + this.getList(); | ||
| 254 | + this.$modal.msgSuccess("删除成功"); | ||
| 255 | + }).catch(() => { | ||
| 256 | + }); | ||
| 257 | + }, | ||
| 258 | + /** 导出按钮操作 */ | ||
| 259 | + handleExport() { | ||
| 260 | + // 处理查询参数 | ||
| 261 | + let params = {...this.queryParams}; | ||
| 262 | + params.pageNo = undefined; | ||
| 263 | + params.pageSize = undefined; | ||
| 264 | + this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime'); | ||
| 265 | + // 执行导出 | ||
| 266 | + this.$modal.confirm('是否确认导出所有品牌数据项?').then(() => { | ||
| 267 | + this.exportLoading = true; | ||
| 268 | + return exportBrandExcel(params); | ||
| 269 | + }).then(response => { | ||
| 270 | + this.$download.excel(response, "品牌.xls"); | ||
| 271 | + this.exportLoading = false; | ||
| 272 | + }).catch(() => { | ||
| 273 | + }); | ||
| 274 | + } | ||
| 275 | + } | ||
| 276 | +}; | ||
| 277 | +</script> |