Commit 924a23003ffce4163e3dfa1bb5a528fb364bc931

Authored by 芋道源码
Committed by Gitee
2 parents c4f9f489 145238ea

!136 商品模块

Merge pull request !136 from Jerome/feature/1.8.0-uniapp
Showing 32 changed files with 1447 additions and 10 deletions
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 <module>yudao-module-system</module> 18 <module>yudao-module-system</module>
19 <module>yudao-module-infra</module> 19 <module>yudao-module-infra</module>
20 <module>yudao-module-pay</module> 20 <module>yudao-module-pay</module>
21 - <module>yudao-module-market</module> 21 + <module>yudao-module-mall</module>
22 </modules> 22 </modules>
23 23
24 <name>${project.artifactId}</name> 24 <name>${project.artifactId}</name>
sql/mall.sql 0 → 100644
  1 +/*
  2 + Navicat Premium Data Transfer
  3 +
  4 + Source Server : 127.0.0.1
  5 + Source Server Type : MySQL
  6 + Source Server Version : 80026
  7 + Source Host : localhost:3306
  8 + Source Schema : ruoyi-vue-pro
  9 +
  10 + Target Server Type : MySQL
  11 + Target Server Version : 80026
  12 + File Encoding : 65001
  13 +
  14 + Date: 05/02/2022 00:50:30
  15 +*/
  16 +SET
  17 +FOREIGN_KEY_CHECKS = 0;
  18 +SET NAMES utf8mb4;
  19 +
  20 +-- ----------------------------
  21 +-- Table structure for product_category
  22 +-- ----------------------------
  23 +DROP TABLE IF EXISTS `product_category`;
  24 +CREATE TABLE `product_category`
  25 +(
  26 + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '分类编号',
  27 + `pid` bigint NOT NULL COMMENT '父分类编号',
  28 + `name` varchar(255) NOT NULL COMMENT '分类名称',
  29 + `icon` varchar(100) NOT NULL DEFAULT '#' COMMENT '分类图标',
  30 + `banner_url` varchar(255) NOT NULL COMMENT '分类图片',
  31 + `sort` int DEFAULT '0' COMMENT '分类排序',
  32 + `description` varchar(1024) DEFAULT NULL COMMENT '分类描述',
  33 + `status` tinyint NOT NULL COMMENT '开启状态',
  34 + `creator` varchar(64) DEFAULT '' COMMENT '创建者',
  35 + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  36 + `updater` varchar(64) DEFAULT '' COMMENT '更新者',
  37 + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  38 + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  39 + `tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
  40 + PRIMARY KEY (`id`) USING BTREE
  41 +) ENGINE=InnoDB COMMENT='商品分类';
  42 +
  43 +-- 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);
  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);
  46 +-- 菜单 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);
  48 +-- 按钮父菜单ID
  49 +SELECT @parentId := LAST_INSERT_ID();
  50 +-- 按钮 SQL
  51 +INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类查询', 'product:category:query', 3, 1, @parentId, '', '', '', 0);
  52 +INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类创建', 'product:category:create', 3, 2, @parentId, '', '', '', 0);
  53 +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);
  55 +INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类导出', 'product:category:export', 3, 5, @parentId, '', '', '', 0);
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java
1 package cn.iocoder.yudao.module.infra.controller.admin.file; 1 package cn.iocoder.yudao.module.infra.controller.admin.file;
2 2
  3 +import cn.hutool.core.date.DateUtil;
3 import cn.hutool.core.io.IoUtil; 4 import cn.hutool.core.io.IoUtil;
4 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
@@ -23,6 +24,7 @@ import org.springframework.web.multipart.MultipartFile; @@ -23,6 +24,7 @@ import org.springframework.web.multipart.MultipartFile;
23 import javax.annotation.Resource; 24 import javax.annotation.Resource;
24 import javax.servlet.http.HttpServletResponse; 25 import javax.servlet.http.HttpServletResponse;
25 import javax.validation.Valid; 26 import javax.validation.Valid;
  27 +import java.util.Date;
26 28
27 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 29 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
28 30
@@ -47,6 +49,17 @@ public class FileController { @@ -47,6 +49,17 @@ public class FileController {
47 return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream()))); 49 return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream())));
48 } 50 }
49 51
  52 + @PostMapping("/simple-upload")
  53 + @ApiOperation("简单上传文件")
  54 + @ApiImplicitParams({
  55 + @ApiImplicitParam(name = "file", value = "文件附件", required = true, dataTypeClass = MultipartFile.class),
  56 + })
  57 + public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file) throws Exception {
  58 + String path = DateUtil.format(new Date(), "yyyy/MM/dd/") + file.getOriginalFilename();
  59 + String file1 = fileService.createFile(path, IoUtil.readBytes(file.getInputStream()));
  60 + return success(file1);
  61 + }
  62 +
50 @DeleteMapping("/delete") 63 @DeleteMapping("/delete")
51 @ApiOperation("删除文件") 64 @ApiOperation("删除文件")
52 @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) 65 @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
yudao-module-mall/pom.xml
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 </parent> 9 </parent>
10 <modelVersion>4.0.0</modelVersion> 10 <modelVersion>4.0.0</modelVersion>
11 11
12 - <artifactId>yudao-module-market</artifactId> 12 + <artifactId>yudao-module-mall</artifactId>
13 <packaging>pom</packaging> 13 <packaging>pom</packaging>
14 14
15 <name>${project.artifactId}</name> 15 <name>${project.artifactId}</name>
@@ -21,6 +21,8 @@ @@ -21,6 +21,8 @@
21 <modules> 21 <modules>
22 <module>yudao-module-market-api</module> 22 <module>yudao-module-market-api</module>
23 <module>yudao-module-market-biz</module> 23 <module>yudao-module-market-biz</module>
  24 + <module>yudao-module-product-api</module>
  25 + <module>yudao-module-product-biz</module>
24 </modules> 26 </modules>
25 27
26 </project> 28 </project>
yudao-module-mall/yudao-module-market-api/pom.xml
@@ -3,8 +3,8 @@ @@ -3,8 +3,8 @@
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5 <parent> 5 <parent>
6 - <artifactId>yudao-module-market</artifactId>  
7 <groupId>cn.iocoder.boot</groupId> 6 <groupId>cn.iocoder.boot</groupId>
  7 + <artifactId>yudao-module-mall</artifactId>
8 <version>${revision}</version> 8 <version>${revision}</version>
9 </parent> 9 </parent>
10 <modelVersion>4.0.0</modelVersion> 10 <modelVersion>4.0.0</modelVersion>
yudao-module-mall/yudao-module-market-biz/pom.xml
@@ -3,8 +3,8 @@ @@ -3,8 +3,8 @@
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5 <parent> 5 <parent>
6 - <artifactId>yudao-module-market</artifactId>  
7 <groupId>cn.iocoder.boot</groupId> 6 <groupId>cn.iocoder.boot</groupId>
  7 + <artifactId>yudao-module-mall</artifactId>
8 <version>${revision}</version> 8 <version>${revision}</version>
9 </parent> 9 </parent>
10 <modelVersion>4.0.0</modelVersion> 10 <modelVersion>4.0.0</modelVersion>
yudao-module-mall/yudao-module-product-api/pom.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5 + <modelVersion>4.0.0</modelVersion>
  6 + <parent>
  7 + <groupId>cn.iocoder.boot</groupId>
  8 + <artifactId>yudao-module-mall</artifactId>
  9 + <version>${revision}</version>
  10 + </parent>
  11 +
  12 + <artifactId>yudao-module-product-api</artifactId>
  13 + <packaging>jar</packaging>
  14 +
  15 + <name>${project.artifactId}</name>
  16 + <description>
  17 + product 模块 API,暴露给其它模块调用
  18 + </description>
  19 +
  20 + <dependencies>
  21 + <dependency>
  22 + <groupId>cn.iocoder.boot</groupId>
  23 + <artifactId>yudao-common</artifactId>
  24 + </dependency>
  25 + </dependencies>
  26 +
  27 +</project>
0 \ No newline at end of file 28 \ No newline at end of file
yudao-module-mall/yudao-module-product-api/src/main/cn/iocoder/yudao/module/product/api/package-info.java 0 → 100644
  1 +/**
  2 + * 占位
  3 + */
  4 +package cn.iocoder.yudao.module.product.api;
0 \ No newline at end of file 5 \ No newline at end of file
yudao-module-mall/yudao-module-product-api/src/main/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.enums;
  2 +
  3 +import cn.iocoder.yudao.framework.common.exception.ErrorCode;
  4 +
  5 +/**
  6 + * product 错误码枚举类
  7 + * <p>
  8 + * product 系统,使用 1-008-000-000 段
  9 + */
  10 +public interface ErrorCodeConstants {
  11 +
  12 + // ========== 商品分类相关 1008001000============
  13 + ErrorCode CATEGORY_NOT_EXISTS = new ErrorCode(1008001000, "商品分类不存在");
  14 +}
yudao-module-mall/yudao-module-product-biz/pom.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5 + <modelVersion>4.0.0</modelVersion>
  6 + <parent>
  7 + <groupId>cn.iocoder.boot</groupId>
  8 + <artifactId>yudao-module-mall</artifactId>
  9 + <version>${revision}</version>
  10 + </parent>
  11 +
  12 + <artifactId>yudao-module-product-biz</artifactId>
  13 + <packaging>jar</packaging>
  14 +
  15 + <name>${project.artifactId}</name>
  16 + <description>
  17 + product 模块,主要实现商品相关功能
  18 + 例如:品牌、商品分类、spu、sku等功能。
  19 + </description>
  20 +
  21 +
  22 + <dependencies>
  23 + <dependency>
  24 + <groupId>cn.iocoder.boot</groupId>
  25 + <artifactId>yudao-module-product-api</artifactId>
  26 + <version>${revision}</version>
  27 + </dependency>
  28 +
  29 + <!-- 业务组件 -->
  30 + <dependency>
  31 + <groupId>cn.iocoder.boot</groupId>
  32 + <artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId>
  33 + </dependency>
  34 + <dependency>
  35 + <groupId>cn.iocoder.boot</groupId>
  36 + <artifactId>yudao-spring-boot-starter-biz-weixin</artifactId>
  37 + </dependency>
  38 + <dependency>
  39 + <groupId>cn.iocoder.boot</groupId>
  40 + <artifactId>yudao-spring-boot-starter-biz-tenant</artifactId>
  41 + </dependency>
  42 +
  43 + <!-- Web 相关 -->
  44 + <dependency>
  45 + <groupId>cn.iocoder.boot</groupId>
  46 + <artifactId>yudao-spring-boot-starter-web</artifactId>
  47 + </dependency>
  48 + <dependency>
  49 + <groupId>cn.iocoder.boot</groupId>
  50 + <artifactId>yudao-spring-boot-starter-excel</artifactId>
  51 + </dependency>
  52 +
  53 + <!-- DB 相关 -->
  54 + <dependency>
  55 + <groupId>cn.iocoder.boot</groupId>
  56 + <artifactId>yudao-spring-boot-starter-mybatis</artifactId>
  57 + </dependency>
  58 +
  59 + <!-- Test 测试相关 -->
  60 + <dependency>
  61 + <groupId>cn.iocoder.boot</groupId>
  62 + <artifactId>yudao-spring-boot-starter-test</artifactId>
  63 + </dependency>
  64 +
  65 + </dependencies>
  66 +
  67 +</project>
0 \ No newline at end of file 68 \ No newline at end of file
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/CategoryController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.controller.admin.category;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  5 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  6 +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  7 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.*;
  8 +import cn.iocoder.yudao.module.product.convert.category.CategoryConvert;
  9 +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO;
  10 +import cn.iocoder.yudao.module.product.service.category.CategoryService;
  11 +import io.swagger.annotations.Api;
  12 +import io.swagger.annotations.ApiImplicitParam;
  13 +import io.swagger.annotations.ApiOperation;
  14 +import org.springframework.security.access.prepost.PreAuthorize;
  15 +import org.springframework.validation.annotation.Validated;
  16 +import org.springframework.web.bind.annotation.*;
  17 +
  18 +import javax.annotation.Resource;
  19 +import javax.servlet.http.HttpServletResponse;
  20 +import javax.validation.Valid;
  21 +import java.io.IOException;
  22 +import java.util.Collection;
  23 +import java.util.Comparator;
  24 +import java.util.List;
  25 +
  26 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  27 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
  28 +
  29 +@Api(tags = "管理后台 - 商品分类")
  30 +@RestController
  31 +@RequestMapping("/product/category")
  32 +@Validated
  33 +public class CategoryController {
  34 +
  35 + @Resource
  36 + private CategoryService categoryService;
  37 +
  38 + @PostMapping("/create")
  39 + @ApiOperation("创建商品分类")
  40 + @PreAuthorize("@ss.hasPermission('product:category:create')")
  41 + public CommonResult<Long> createCategory(@Valid @RequestBody CategoryCreateReqVO createReqVO) {
  42 + return success(categoryService.createCategory(createReqVO));
  43 + }
  44 +
  45 + @PutMapping("/update")
  46 + @ApiOperation("更新商品分类")
  47 + @PreAuthorize("@ss.hasPermission('product:category:update')")
  48 + public CommonResult<Boolean> updateCategory(@Valid @RequestBody CategoryUpdateReqVO updateReqVO) {
  49 + categoryService.updateCategory(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:category:delete')")
  57 + public CommonResult<Boolean> deleteCategory(@RequestParam("id") Long id) {
  58 + categoryService.deleteCategory(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:category:query')")
  66 + public CommonResult<CategoryRespVO> getCategory(@RequestParam("id") Long id) {
  67 + CategoryDO category = categoryService.getCategory(id);
  68 + return success(CategoryConvert.INSTANCE.convert(category));
  69 + }
  70 +
  71 + @GetMapping("/listByIds")
  72 + @ApiOperation("获得商品分类列表")
  73 + @PreAuthorize("@ss.hasPermission('product:category:query')")
  74 + public CommonResult<List<CategoryRespVO>> getCategoryList(@RequestParam("ids") Collection<Long> ids) {
  75 + List<CategoryDO> list = categoryService.getCategoryList(ids);
  76 + return success(CategoryConvert.INSTANCE.convertList(list));
  77 + }
  78 +
  79 + @GetMapping("/listByQuery")
  80 + @ApiOperation("获得商品分类列表")
  81 + @PreAuthorize("@ss.hasPermission('product:category:query')")
  82 + public CommonResult<List<CategoryRespVO>> listByQuery(@Valid CategoryTreeListReqVO treeListReqVO) {
  83 + List<CategoryDO> list = categoryService.getCategoryTreeList(treeListReqVO);
  84 + list.sort(Comparator.comparing(CategoryDO::getSort));
  85 + return success(CategoryConvert.INSTANCE.convertList(list));
  86 + }
  87 +
  88 + @GetMapping("/page")
  89 + @ApiOperation("获得商品分类分页")
  90 + @PreAuthorize("@ss.hasPermission('product:category:query')")
  91 + public CommonResult<PageResult<CategoryRespVO>> getCategoryPage(@Valid CategoryPageReqVO pageVO) {
  92 + PageResult<CategoryDO> pageResult = categoryService.getCategoryPage(pageVO);
  93 + return success(CategoryConvert.INSTANCE.convertPage(pageResult));
  94 + }
  95 +
  96 + @GetMapping("/export-excel")
  97 + @ApiOperation("导出商品分类 Excel")
  98 + @PreAuthorize("@ss.hasPermission('product:category:export')")
  99 + @OperateLog(type = EXPORT)
  100 + public void exportCategoryExcel(@Valid CategoryExportReqVO exportReqVO,
  101 + HttpServletResponse response) throws IOException {
  102 + List<CategoryDO> list = categoryService.getCategoryList(exportReqVO);
  103 + // 导出 Excel
  104 + List<CategoryExcelVO> datas = CategoryConvert.INSTANCE.convertList02(list);
  105 + ExcelUtils.write(response, "商品分类.xls", "数据", CategoryExcelVO.class, datas);
  106 + }
  107 +
  108 +}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryBaseVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.controller.admin.category.vo;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.constraints.NotBlank;
  7 +import javax.validation.constraints.NotNull;
  8 +
  9 +/**
  10 +* 商品分类 Base VO,提供给添加、修改、详细的子 VO 使用
  11 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
  12 +*/
  13 +@Data
  14 +public class CategoryBaseVO {
  15 +
  16 + @ApiModelProperty(value = "父分类编号", required = true, example = "1")
  17 + @NotNull(message = "父分类编号不能为空")
  18 + private Long pid;
  19 +
  20 + @ApiModelProperty(value = "分类名称", required = true, example = "办公文具")
  21 + @NotBlank(message = "分类名称不能为空")
  22 + private String name;
  23 +
  24 + @ApiModelProperty(value = "分类图标")
  25 + @NotBlank(message = "分类图标不能为空")
  26 + private String icon;
  27 +
  28 + @ApiModelProperty(value = "分类图片", required = true)
  29 + @NotBlank(message = "分类图片不能为空")
  30 + private String bannerUrl;
  31 +
  32 + @ApiModelProperty(value = "分类排序", required = true, example = "1")
  33 + private Integer sort;
  34 +
  35 + @ApiModelProperty(value = "分类描述", required = true, example = "描述")
  36 + private String description;
  37 +
  38 + @ApiModelProperty(value = "开启状态", required = true, example = "0")
  39 + @NotNull(message = "开启状态不能为空")
  40 + private Integer status;
  41 +
  42 +}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryCreateReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.controller.admin.category.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 CategoryCreateReqVO extends CategoryBaseVO {
  13 +
  14 +}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryExcelVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.controller.admin.category.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 CategoryExcelVO {
  19 +
  20 + @ExcelProperty("分类编号")
  21 + private Long id;
  22 +
  23 + @ExcelProperty("父分类编号")
  24 + private Long pid;
  25 +
  26 + @ExcelProperty("分类名称")
  27 + private String name;
  28 +
  29 + @ExcelProperty("分类图标")
  30 + private String icon;
  31 +
  32 + @ExcelProperty("分类图片")
  33 + private String bannerUrl;
  34 +
  35 + @ExcelProperty("分类排序")
  36 + private Integer sort;
  37 +
  38 + @ExcelProperty("分类描述")
  39 + private String description;
  40 +
  41 + @ExcelProperty(value = "开启状态", converter = DictConvert.class)
  42 + @DictFormat("common_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
  43 + private Integer status;
  44 +
  45 + @ExcelProperty("创建时间")
  46 + private Date createTime;
  47 +
  48 +}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryExportReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.controller.admin.category.vo;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +import org.springframework.format.annotation.DateTimeFormat;
  7 +
  8 +import java.util.Date;
  9 +
  10 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  11 +
  12 +@ApiModel(value = "管理后台 - 商品分类 Excel 导出 Request VO", description = "参数和 CategoryPageReqVO 是一致的")
  13 +@Data
  14 +public class CategoryExportReqVO {
  15 +
  16 + @ApiModelProperty(value = "分类名称", example = "办公文具")
  17 + private String name;
  18 +
  19 + @ApiModelProperty(value = "开启状态", example = "0")
  20 + private Integer status;
  21 +
  22 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  23 + @ApiModelProperty(value = "开始创建时间")
  24 + private Date beginCreateTime;
  25 +
  26 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  27 + @ApiModelProperty(value = "结束创建时间")
  28 + private Date endCreateTime;
  29 +
  30 +}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.controller.admin.category.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.annotations.ApiModel;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import lombok.Data;
  7 +import lombok.EqualsAndHashCode;
  8 +import lombok.ToString;
  9 +import org.springframework.format.annotation.DateTimeFormat;
  10 +
  11 +import java.util.Date;
  12 +
  13 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  14 +
  15 +@ApiModel("管理后台 - 商品分类分页 Request VO")
  16 +@Data
  17 +@EqualsAndHashCode(callSuper = true)
  18 +@ToString(callSuper = true)
  19 +public class CategoryPageReqVO extends PageParam {
  20 +
  21 + @ApiModelProperty(value = "分类名称", example = "办公文具")
  22 + private String name;
  23 +
  24 + @ApiModelProperty(value = "开启状态", example = "0")
  25 + private Integer status;
  26 +
  27 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  28 + @ApiModelProperty(value = "开始创建时间")
  29 + private Date beginCreateTime;
  30 +
  31 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  32 + @ApiModelProperty(value = "结束创建时间")
  33 + private Date endCreateTime;
  34 +
  35 +}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.controller.admin.category.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 CategoryRespVO extends CategoryBaseVO {
  12 +
  13 + @ApiModelProperty(value = "分类编号", required = true, example = "2")
  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/category/vo/CategoryTreeListReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.controller.admin.category.vo;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +import org.springframework.format.annotation.DateTimeFormat;
  7 +
  8 +import java.util.Date;
  9 +
  10 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  11 +
  12 +@Data
  13 +@ApiModel(value = "管理后台 - 商品分类列表查询 Request VO", description = "参数和 CategoryPageReqVO 是一致的")
  14 +public class CategoryTreeListReqVO extends CategoryExportReqVO {
  15 +
  16 + @ApiModelProperty(value = "分类名称", example = "办公文具")
  17 + private String name;
  18 +
  19 + @ApiModelProperty(value = "开启状态", example = "0")
  20 + private Integer status;
  21 +
  22 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  23 + @ApiModelProperty(value = "开始创建时间")
  24 + private Date beginCreateTime;
  25 +
  26 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  27 + @ApiModelProperty(value = "结束创建时间")
  28 + private Date endCreateTime;
  29 +}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryUpdateReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.controller.admin.category.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 CategoryUpdateReqVO extends CategoryBaseVO {
  13 +
  14 + @ApiModelProperty(value = "分类编号", required = true, example = "2")
  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/category/CategoryConvert.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.convert.category;
  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.category.vo.*;
  10 +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO;
  11 +
  12 +/**
  13 + * 商品分类 Convert
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Mapper
  18 +public interface CategoryConvert {
  19 +
  20 + CategoryConvert INSTANCE = Mappers.getMapper(CategoryConvert.class);
  21 +
  22 + CategoryDO convert(CategoryCreateReqVO bean);
  23 +
  24 + CategoryDO convert(CategoryUpdateReqVO bean);
  25 +
  26 + CategoryRespVO convert(CategoryDO bean);
  27 +
  28 + List<CategoryRespVO> convertList(List<CategoryDO> list);
  29 +
  30 + PageResult<CategoryRespVO> convertPage(PageResult<CategoryDO> page);
  31 +
  32 + List<CategoryExcelVO> convertList02(List<CategoryDO> list);
  33 +
  34 +}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/category/CategoryDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.dal.dataobject.category;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import com.baomidou.mybatisplus.annotation.*;
  6 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  7 +
  8 +/**
  9 + * 商品分类 DO
  10 + *
  11 + * @author 芋道源码
  12 + */
  13 +@TableName("product_category")
  14 +@Data
  15 +@EqualsAndHashCode(callSuper = true)
  16 +@ToString(callSuper = true)
  17 +@Builder
  18 +@NoArgsConstructor
  19 +@AllArgsConstructor
  20 +public class CategoryDO extends BaseDO {
  21 +
  22 + /**
  23 + * 分类编号
  24 + */
  25 + @TableId
  26 + private Long id;
  27 + /**
  28 + * 父分类编号
  29 + */
  30 + private Long pid;
  31 + /**
  32 + * 分类名称
  33 + */
  34 + private String name;
  35 + /**
  36 + * 分类图标
  37 + */
  38 + private String icon;
  39 + /**
  40 + * 分类图片
  41 + */
  42 + private String bannerUrl;
  43 + /**
  44 + * 分类排序
  45 + */
  46 + private Integer sort;
  47 + /**
  48 + * 分类描述
  49 + */
  50 + private String description;
  51 + /**
  52 + * 开启状态
  53 + *
  54 + * 枚举 {@link TODO common_status 对应的类}
  55 + */
  56 + private Integer status;
  57 +
  58 +}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/category/CategoryMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.dal.mysql.category;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryExportReqVO;
  7 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryPageReqVO;
  8 +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO;
  9 +import org.apache.ibatis.annotations.Mapper;
  10 +
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * 商品分类 Mapper
  15 + *
  16 + * @author 芋道源码
  17 + */
  18 +@Mapper
  19 +public interface CategoryMapper extends BaseMapperX<CategoryDO> {
  20 +
  21 + default PageResult<CategoryDO> selectPage(CategoryPageReqVO reqVO) {
  22 + return selectPage(reqVO, new LambdaQueryWrapperX<CategoryDO>()
  23 + .likeIfPresent(CategoryDO::getName, reqVO.getName())
  24 + .eqIfPresent(CategoryDO::getStatus, reqVO.getStatus())
  25 + .betweenIfPresent(CategoryDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
  26 + .orderByDesc(CategoryDO::getId));
  27 + }
  28 +
  29 + default List<CategoryDO> selectList(CategoryExportReqVO reqVO) {
  30 + return selectList(new LambdaQueryWrapperX<CategoryDO>()
  31 + .likeIfPresent(CategoryDO::getName, reqVO.getName())
  32 + .eqIfPresent(CategoryDO::getStatus, reqVO.getStatus())
  33 + .betweenIfPresent(CategoryDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
  34 + .orderByDesc(CategoryDO::getId));
  35 + }
  36 +
  37 +}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/package-info.java 0 → 100644
  1 +/**
  2 + * TODO
  3 + *
  4 + * @author JeromeSoar
  5 + * @since 2022-04-24
  6 + */
  7 +package cn.iocoder.yudao.module.product;
0 \ No newline at end of file 8 \ No newline at end of file
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.service.category;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.*;
  5 +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO;
  6 +
  7 +import javax.validation.Valid;
  8 +import java.util.Collection;
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * 商品分类 Service 接口
  13 + *
  14 + * @author 芋道源码
  15 + */
  16 +public interface CategoryService {
  17 +
  18 + /**
  19 + * 创建商品分类
  20 + *
  21 + * @param createReqVO 创建信息
  22 + * @return 编号
  23 + */
  24 + Long createCategory(@Valid CategoryCreateReqVO createReqVO);
  25 +
  26 + /**
  27 + * 更新商品分类
  28 + *
  29 + * @param updateReqVO 更新信息
  30 + */
  31 + void updateCategory(@Valid CategoryUpdateReqVO updateReqVO);
  32 +
  33 + /**
  34 + * 删除商品分类
  35 + *
  36 + * @param id 编号
  37 + */
  38 + void deleteCategory(Long id);
  39 +
  40 + /**
  41 + * 获得商品分类
  42 + *
  43 + * @param id 编号
  44 + * @return 商品分类
  45 + */
  46 + CategoryDO getCategory(Long id);
  47 +
  48 + /**
  49 + * 获得商品分类列表
  50 + *
  51 + * @param ids 编号
  52 + * @return 商品分类列表
  53 + */
  54 + List<CategoryDO> getCategoryList(Collection<Long> ids);
  55 +
  56 + /**
  57 + * 获得商品分类分页
  58 + *
  59 + * @param pageReqVO 分页查询
  60 + * @return 商品分类分页
  61 + */
  62 + PageResult<CategoryDO> getCategoryPage(CategoryPageReqVO pageReqVO);
  63 +
  64 + /**
  65 + * 获得商品分类列表, 用于 Excel 导出
  66 + *
  67 + * @param exportReqVO 查询条件
  68 + * @return 商品分类列表
  69 + */
  70 + List<CategoryDO> getCategoryList(CategoryExportReqVO exportReqVO);
  71 +
  72 + /**
  73 + * 获得商品分类列表
  74 + *
  75 + * @param treeListReqVO 查询条件
  76 + * @return 商品分类列表
  77 + */
  78 + List<CategoryDO> getCategoryTreeList(CategoryTreeListReqVO treeListReqVO);
  79 +}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.service.category;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.*;
  5 +import cn.iocoder.yudao.module.product.convert.category.CategoryConvert;
  6 +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO;
  7 +import cn.iocoder.yudao.module.product.dal.mysql.category.CategoryMapper;
  8 +import org.springframework.stereotype.Service;
  9 +import org.springframework.validation.annotation.Validated;
  10 +
  11 +import javax.annotation.Resource;
  12 +import java.util.Collection;
  13 +import java.util.List;
  14 +
  15 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  16 +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.CATEGORY_NOT_EXISTS;
  17 +
  18 +/**
  19 + * 商品分类 Service 实现类
  20 + *
  21 + * @author 芋道源码
  22 + */
  23 +@Service
  24 +@Validated
  25 +public class CategoryServiceImpl implements CategoryService {
  26 +
  27 + @Resource
  28 + private CategoryMapper categoryMapper;
  29 +
  30 + @Override
  31 + public Long createCategory(CategoryCreateReqVO createReqVO) {
  32 + // 插入
  33 + CategoryDO category = CategoryConvert.INSTANCE.convert(createReqVO);
  34 + categoryMapper.insert(category);
  35 + // 返回
  36 + return category.getId();
  37 + }
  38 +
  39 + @Override
  40 + public void updateCategory(CategoryUpdateReqVO updateReqVO) {
  41 + // 校验存在
  42 + this.validateCategoryExists(updateReqVO.getId());
  43 + // 更新
  44 + CategoryDO updateObj = CategoryConvert.INSTANCE.convert(updateReqVO);
  45 + categoryMapper.updateById(updateObj);
  46 + }
  47 +
  48 + @Override
  49 + public void deleteCategory(Long id) {
  50 + // 校验存在
  51 + this.validateCategoryExists(id);
  52 + // 删除
  53 + categoryMapper.deleteById(id);
  54 + }
  55 +
  56 + private void validateCategoryExists(Long id) {
  57 + if (categoryMapper.selectById(id) == null) {
  58 + throw exception(CATEGORY_NOT_EXISTS);
  59 + }
  60 + }
  61 +
  62 + @Override
  63 + public CategoryDO getCategory(Long id) {
  64 + return categoryMapper.selectById(id);
  65 + }
  66 +
  67 + @Override
  68 + public List<CategoryDO> getCategoryList(Collection<Long> ids) {
  69 + return categoryMapper.selectBatchIds(ids);
  70 + }
  71 +
  72 + @Override
  73 + public PageResult<CategoryDO> getCategoryPage(CategoryPageReqVO pageReqVO) {
  74 + return categoryMapper.selectPage(pageReqVO);
  75 + }
  76 +
  77 + @Override
  78 + public List<CategoryDO> getCategoryList(CategoryExportReqVO exportReqVO) {
  79 + return categoryMapper.selectList(exportReqVO);
  80 + }
  81 +
  82 + @Override
  83 + public List<CategoryDO> getCategoryTreeList(CategoryTreeListReqVO treeListReqVO) {
  84 + return categoryMapper.selectList(treeListReqVO);
  85 + }
  86 +
  87 +}
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImplTest.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.service.category;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
  5 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryCreateReqVO;
  6 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryExportReqVO;
  7 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryPageReqVO;
  8 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryUpdateReqVO;
  9 +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO;
  10 +import cn.iocoder.yudao.module.product.dal.mysql.category.CategoryMapper;
  11 +import org.junit.jupiter.api.Disabled;
  12 +import org.junit.jupiter.api.Test;
  13 +import org.springframework.context.annotation.Import;
  14 +
  15 +import javax.annotation.Resource;
  16 +import java.util.List;
  17 +
  18 +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
  19 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
  20 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
  21 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
  22 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
  23 +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.CATEGORY_NOT_EXISTS;
  24 +import static org.junit.jupiter.api.Assertions.*;
  25 +
  26 +/**
  27 + * {@link CategoryServiceImpl} 的单元测试类
  28 + *
  29 + * @author 芋道源码
  30 + */
  31 +@Import(CategoryServiceImpl.class)
  32 +public class CategoryServiceImplTest extends BaseDbUnitTest {
  33 +
  34 + @Resource
  35 + private CategoryServiceImpl categoryService;
  36 +
  37 + @Resource
  38 + private CategoryMapper categoryMapper;
  39 +
  40 + @Test
  41 + public void testCreateCategory_success() {
  42 + // 准备参数
  43 + CategoryCreateReqVO reqVO = randomPojo(CategoryCreateReqVO.class);
  44 +
  45 + // 调用
  46 + Long categoryId = categoryService.createCategory(reqVO);
  47 + // 断言
  48 + assertNotNull(categoryId);
  49 + // 校验记录的属性是否正确
  50 + CategoryDO category = categoryMapper.selectById(categoryId);
  51 + assertPojoEquals(reqVO, category);
  52 + }
  53 +
  54 + @Test
  55 + public void testUpdateCategory_success() {
  56 + // mock 数据
  57 + CategoryDO dbCategory = randomPojo(CategoryDO.class);
  58 + categoryMapper.insert(dbCategory);// @Sql: 先插入出一条存在的数据
  59 + // 准备参数
  60 + CategoryUpdateReqVO reqVO = randomPojo(CategoryUpdateReqVO.class, o -> {
  61 + o.setId(dbCategory.getId()); // 设置更新的 ID
  62 + });
  63 +
  64 + // 调用
  65 + categoryService.updateCategory(reqVO);
  66 + // 校验是否更新正确
  67 + CategoryDO category = categoryMapper.selectById(reqVO.getId()); // 获取最新的
  68 + assertPojoEquals(reqVO, category);
  69 + }
  70 +
  71 + @Test
  72 + public void testUpdateCategory_notExists() {
  73 + // 准备参数
  74 + CategoryUpdateReqVO reqVO = randomPojo(CategoryUpdateReqVO.class);
  75 +
  76 + // 调用, 并断言异常
  77 + assertServiceException(() -> categoryService.updateCategory(reqVO), CATEGORY_NOT_EXISTS);
  78 + }
  79 +
  80 + @Test
  81 + public void testDeleteCategory_success() {
  82 + // mock 数据
  83 + CategoryDO dbCategory = randomPojo(CategoryDO.class);
  84 + categoryMapper.insert(dbCategory);// @Sql: 先插入出一条存在的数据
  85 + // 准备参数
  86 + Long id = dbCategory.getId();
  87 +
  88 + // 调用
  89 + categoryService.deleteCategory(id);
  90 + // 校验数据不存在了
  91 + assertNull(categoryMapper.selectById(id));
  92 + }
  93 +
  94 + @Test
  95 + public void testDeleteCategory_notExists() {
  96 + // 准备参数
  97 + Long id = randomLongId();
  98 +
  99 + // 调用, 并断言异常
  100 + assertServiceException(() -> categoryService.deleteCategory(id), CATEGORY_NOT_EXISTS);
  101 + }
  102 +
  103 + @Test
  104 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  105 + public void testGetCategoryPage() {
  106 + // mock 数据
  107 + CategoryDO dbCategory = randomPojo(CategoryDO.class, o -> { // 等会查询到
  108 + o.setPid(null);
  109 + o.setName(null);
  110 + o.setIcon(null);
  111 + o.setBannerUrl(null);
  112 + o.setSort(null);
  113 + o.setDescription(null);
  114 + o.setStatus(null);
  115 + o.setCreateTime(null);
  116 + });
  117 + categoryMapper.insert(dbCategory);
  118 + // 测试 pid 不匹配
  119 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setPid(null)));
  120 + // 测试 name 不匹配
  121 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setName(null)));
  122 + // 测试 icon 不匹配
  123 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setIcon(null)));
  124 + // 测试 bannerUrl 不匹配
  125 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setBannerUrl(null)));
  126 + // 测试 sort 不匹配
  127 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setSort(null)));
  128 + // 测试 description 不匹配
  129 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setDescription(null)));
  130 + // 测试 status 不匹配
  131 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setStatus(null)));
  132 + // 测试 createTime 不匹配
  133 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setCreateTime(null)));
  134 + // 准备参数
  135 + CategoryPageReqVO reqVO = new CategoryPageReqVO();
  136 + reqVO.setName(null);
  137 + reqVO.setStatus(null);
  138 + reqVO.setBeginCreateTime(null);
  139 + reqVO.setEndCreateTime(null);
  140 +
  141 + // 调用
  142 + PageResult<CategoryDO> pageResult = categoryService.getCategoryPage(reqVO);
  143 + // 断言
  144 + assertEquals(1, pageResult.getTotal());
  145 + assertEquals(1, pageResult.getList().size());
  146 + assertPojoEquals(dbCategory, pageResult.getList().get(0));
  147 + }
  148 +
  149 + @Test
  150 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  151 + public void testGetCategoryList() {
  152 + // mock 数据
  153 + CategoryDO dbCategory = randomPojo(CategoryDO.class, o -> { // 等会查询到
  154 + o.setPid(null);
  155 + o.setName(null);
  156 + o.setIcon(null);
  157 + o.setBannerUrl(null);
  158 + o.setSort(null);
  159 + o.setDescription(null);
  160 + o.setStatus(null);
  161 + o.setCreateTime(null);
  162 + });
  163 + categoryMapper.insert(dbCategory);
  164 + // 测试 pid 不匹配
  165 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setPid(null)));
  166 + // 测试 name 不匹配
  167 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setName(null)));
  168 + // 测试 icon 不匹配
  169 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setIcon(null)));
  170 + // 测试 bannerUrl 不匹配
  171 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setBannerUrl(null)));
  172 + // 测试 sort 不匹配
  173 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setSort(null)));
  174 + // 测试 description 不匹配
  175 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setDescription(null)));
  176 + // 测试 status 不匹配
  177 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setStatus(null)));
  178 + // 测试 createTime 不匹配
  179 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setCreateTime(null)));
  180 + // 准备参数
  181 + CategoryExportReqVO reqVO = new CategoryExportReqVO();
  182 + reqVO.setName(null);
  183 + reqVO.setStatus(null);
  184 + reqVO.setBeginCreateTime(null);
  185 + reqVO.setEndCreateTime(null);
  186 +
  187 + // 调用
  188 + List<CategoryDO> list = categoryService.getCategoryList(reqVO);
  189 + // 断言
  190 + assertEquals(1, list.size());
  191 + assertPojoEquals(dbCategory, list.get(0));
  192 + }
  193 +
  194 +}
yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/clean.sql 0 → 100644
  1 +DELETE FROM "product_category";
0 \ No newline at end of file 2 \ No newline at end of file
yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql 0 → 100644
  1 +CREATE TABLE IF NOT EXISTS "product_category" (
  2 + "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY,
  3 + "pid" bigint(20) NOT NULL,
  4 + "name" varchar(255) NOT NULL,
  5 + "icon" varchar(100),
  6 + "banner_url" varchar(255) NOT NULL,
  7 + "sort" int(11) NOT NULL,
  8 + "description" varchar(1024) NOT NULL,
  9 + "status" tinyint(4) NOT NULL,
  10 + "creator" varchar(64) DEFAULT '',
  11 + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  12 + "updater" varchar(64) DEFAULT '',
  13 + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  14 + "deleted" bit NOT NULL DEFAULT FALSE,
  15 + "tenant_id" bigint(20) NOT NULL,
  16 + PRIMARY KEY ("id")
  17 +) COMMENT '商品分类';
0 \ No newline at end of file 18 \ No newline at end of file
yudao-server/pom.xml
@@ -47,16 +47,21 @@ @@ -47,16 +47,21 @@
47 <artifactId>yudao-module-market-biz</artifactId> 47 <artifactId>yudao-module-market-biz</artifactId>
48 <version>${revision}</version> 48 <version>${revision}</version>
49 </dependency> 49 </dependency>
  50 + <dependency>
  51 + <groupId>cn.iocoder.boot</groupId>
  52 + <artifactId>yudao-module-product-biz</artifactId>
  53 + <version>${revision}</version>
  54 + </dependency>
50 <!-- 默认引入 yudao-module-bpm-biz-flowable 实现,可以替换为 yudao-module-bpm-biz-activiti 实现--> 55 <!-- 默认引入 yudao-module-bpm-biz-flowable 实现,可以替换为 yudao-module-bpm-biz-activiti 实现-->
51 <dependency> 56 <dependency>
52 <groupId>cn.iocoder.boot</groupId> 57 <groupId>cn.iocoder.boot</groupId>
53 <artifactId>yudao-module-bpm-biz-flowable</artifactId> 58 <artifactId>yudao-module-bpm-biz-flowable</artifactId>
54 <version>${revision}</version> 59 <version>${revision}</version>
55 </dependency> 60 </dependency>
56 -<!-- <dependency>-->  
57 -<!-- <groupId>cn.iocoder.boot</groupId>-->  
58 -<!-- <artifactId>yudao-module-bpm-biz-activiti</artifactId>-->  
59 -<!-- <version>${revision}</version>--> 61 + <!-- <dependency>-->
  62 + <!-- <groupId>cn.iocoder.boot</groupId>-->
  63 + <!-- <artifactId>yudao-module-bpm-biz-activiti</artifactId>-->
  64 + <!-- <version>${revision}</version>-->
60 <!-- </dependency>--> 65 <!-- </dependency>-->
61 66
62 <!-- spring boot 配置所需依赖 --> 67 <!-- spring boot 配置所需依赖 -->
yudao-ui-admin/src/api/mall/product/category.js 0 → 100644
  1 +import request from '@/utils/request'
  2 +
  3 +// 创建商品分类
  4 +export function createCategory(data) {
  5 + return request({
  6 + url: '/product/category/create',
  7 + method: 'post',
  8 + data: data
  9 + })
  10 +}
  11 +
  12 +// 更新商品分类
  13 +export function updateCategory(data) {
  14 + return request({
  15 + url: '/product/category/update',
  16 + method: 'put',
  17 + data: data
  18 + })
  19 +}
  20 +
  21 +// 删除商品分类
  22 +export function deleteCategory(id) {
  23 + return request({
  24 + url: '/product/category/delete?id=' + id,
  25 + method: 'delete'
  26 + })
  27 +}
  28 +
  29 +// 获得商品分类
  30 +export function getCategory(id) {
  31 + return request({
  32 + url: '/product/category/get?id=' + id,
  33 + method: 'get'
  34 + })
  35 +}
  36 +
  37 +// 获得商品分类
  38 +export function listCategory(query) {
  39 + return request({
  40 + url: '/product/category/listByQuery',
  41 + method: 'get',
  42 + params: query
  43 + })
  44 +}
  45 +
  46 +// 获得商品分类分页
  47 +export function getCategoryPage(query) {
  48 + return request({
  49 + url: '/product/category/page',
  50 + method: 'get',
  51 + params: query
  52 + })
  53 +}
  54 +
  55 +// 导出商品分类 Excel
  56 +export function exportCategoryExcel(query) {
  57 + return request({
  58 + url: '/product/category/export-excel',
  59 + method: 'get',
  60 + params: query,
  61 + responseType: 'blob'
  62 + })
  63 +}
yudao-ui-admin/src/components/ImageUpload/index.vue
@@ -77,7 +77,7 @@ export default { @@ -77,7 +77,7 @@ export default {
77 dialogVisible: false, 77 dialogVisible: false,
78 hideUpload: false, 78 hideUpload: false,
79 baseUrl: process.env.VUE_APP_BASE_API, 79 baseUrl: process.env.VUE_APP_BASE_API,
80 - uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址 80 + uploadImgUrl: process.env.VUE_APP_BASE_API + "/admin-api/infra/file/simple-upload", // 上传的图片服务器地址
81 headers: { 81 headers: {
82 Authorization: "Bearer " + getToken(), 82 Authorization: "Bearer " + getToken(),
83 }, 83 },
@@ -127,7 +127,7 @@ export default { @@ -127,7 +127,7 @@ export default {
127 }, 127 },
128 // 上传成功回调 128 // 上传成功回调
129 handleUploadSuccess(res) { 129 handleUploadSuccess(res) {
130 - this.uploadList.push({ name: res.fileName, url: res.fileName }); 130 + this.uploadList.push({ name: res.data, url: res.data });
131 if (this.uploadList.length === this.number) { 131 if (this.uploadList.length === this.number) {
132 this.fileList = this.fileList.concat(this.uploadList); 132 this.fileList = this.fileList.concat(this.uploadList);
133 this.uploadList = []; 133 this.uploadList = [];
yudao-ui-admin/src/views/mall/product/category/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="name">
  7 + <el-input v-model="queryParams.name" placeholder="请输入分类名称" clearable @keyup.enter.native="handleQuery"/>
  8 + </el-form-item>
  9 + <el-form-item label="开启状态" prop="status">
  10 + <el-select v-model="queryParams.status" placeholder="请选择开启状态" clearable size="small">
  11 + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
  12 + :key="dict.value" :label="dict.label" :value="dict.value"/>
  13 + </el-select>
  14 + </el-form-item>
  15 + <el-form-item>
  16 + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  17 + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  18 + </el-form-item>
  19 + </el-form>
  20 +
  21 + <!-- 操作工具栏 -->
  22 + <el-row :gutter="10" class="mb8">
  23 + <el-col :span="1.5">
  24 + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  25 + v-hasPermi="['product:category:create']">新增
  26 + </el-button>
  27 + </el-col>
  28 + <el-col :span="1.5">
  29 + <el-button type="info" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">展开/折叠</el-button>
  30 + </el-col>
  31 + <el-col :span="1.5">
  32 + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
  33 + :loading="exportLoading"
  34 + v-hasPermi="['product:category:export']">导出
  35 + </el-button>
  36 + </el-col>
  37 + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  38 + </el-row>
  39 +
  40 + <!-- 列表 -->
  41 + <el-table v-if="refreshTable" v-loading="loading" :data="list" row-key="id" :default-expand-all="isExpandAll"
  42 + :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
  43 + <el-table-column label="分类名称" align="center" prop="name"/>
  44 + <el-table-column label="分类图标" align="center" prop="icon">
  45 + <template slot-scope="scope">
  46 + <svg-icon :icon-class="scope.row.icon" />
  47 + </template>
  48 + </el-table-column>
  49 + <el-table-column label="分类图片" align="center" prop="bannerUrl">
  50 + <template slot-scope="scope">
  51 + <img v-if="scope.row.bannerUrl" :src="scope.row.bannerUrl" alt="分类图片"/>
  52 + </template>
  53 + </el-table-column>
  54 + <el-table-column label="分类排序" align="center" prop="sort"/>
  55 + <el-table-column label="开启状态" align="center" prop="status">
  56 + <template slot-scope="scope">
  57 + <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
  58 + </template>
  59 + </el-table-column>
  60 + <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  61 + <template slot-scope="scope">
  62 + <span>{{ parseTime(scope.row.createTime) }}</span>
  63 + </template>
  64 + </el-table-column>
  65 + <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  66 + <template slot-scope="scope">
  67 + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  68 + v-hasPermi="['product:category:update']">修改
  69 + </el-button>
  70 + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  71 + v-hasPermi="['product:category:delete']">删除
  72 + </el-button>
  73 + </template>
  74 + </el-table-column>
  75 + </el-table>
  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="pid">
  81 + <Treeselect v-model="form.pid" :options="parentCategoryOptions" :normalizer="normalizer" :show-count="true"
  82 + placeholder="上级分类"/>
  83 + </el-form-item>
  84 + <el-form-item label="分类名称" prop="name">
  85 + <el-input v-model="form.name" placeholder="请输入分类名称"/>
  86 + </el-form-item>
  87 + <el-form-item label="分类图标" prop="icon">
  88 + <el-popover placement="bottom-start" width="460" trigger="click" @show="$refs['iconSelect'].reset()">
  89 + <IconSelect ref="iconSelect" @selected="iconSelected"/>
  90 + <el-input slot="reference" v-model="form.icon" placeholder="点击选择分类图标" readonly>
  91 + <svg-icon v-if="form.icon" slot="prefix" :icon-class="form.icon" class="el-input__icon"
  92 + style="height: 32px;width: 16px;"/>
  93 + <i v-else slot="prefix" class="el-icon-search el-input__icon"/>
  94 + </el-input>
  95 + </el-popover>
  96 + </el-form-item>
  97 + <el-form-item label="分类图片" prop="bannerUrl">
  98 + <ImageUpload v-model="form.bannerUrl" />
  99 + </el-form-item>
  100 + <el-form-item label="分类排序" prop="sort">
  101 + <el-input-number v-model="form.sort" controls-position="right" :min="0" />
  102 + </el-form-item>
  103 + <el-form-item label="分类描述">
  104 + <editor v-model="form.description" :min-height="192"/>
  105 + </el-form-item>
  106 + <el-form-item label="开启状态" prop="status">
  107 + <el-radio-group v-model="form.status">
  108 + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
  109 + :key="dict.value" :label="parseInt(dict.value)">{{ dict.label }}
  110 + </el-radio>
  111 + </el-radio-group>
  112 + </el-form-item>
  113 + </el-form>
  114 + <div slot="footer" class="dialog-footer">
  115 + <el-button type="primary" @click="submitForm">确 定</el-button>
  116 + <el-button @click="cancel">取 消</el-button>
  117 + </div>
  118 + </el-dialog>
  119 + </div>
  120 +</template>
  121 +
  122 +<script>
  123 +import {
  124 + createCategory,
  125 + deleteCategory,
  126 + exportCategoryExcel,
  127 + getCategory,
  128 + getCategoryPage,
  129 + listCategory,
  130 + updateCategory
  131 +} from "@/api/mall/product/category";
  132 +import Editor from '@/components/Editor';
  133 +import Treeselect from "@riophae/vue-treeselect";
  134 +import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  135 +import IconSelect from "@/components/IconSelect";
  136 +import ImageUpload from '@/components/ImageUpload';
  137 +
  138 +export default {
  139 + name: "Category",
  140 + components: {
  141 + Editor, Treeselect, IconSelect, ImageUpload
  142 + },
  143 + data() {
  144 + return {
  145 + // 遮罩层
  146 + loading: true,
  147 + // 导出遮罩层
  148 + exportLoading: false,
  149 + // 显示搜索条件
  150 + showSearch: true,
  151 + // 总条数
  152 + total: 0,
  153 + // 商品分类列表
  154 + list: [],
  155 + // 商品分类树选项
  156 + parentCategoryOptions: [],
  157 + // 弹出层标题
  158 + title: "",
  159 + // 是否显示弹出层
  160 + open: false,
  161 + // 是否展开,默认全部折叠
  162 + isExpandAll: false,
  163 + // 重新渲染表格状态
  164 + refreshTable: true,
  165 + // 查询参数
  166 + queryParams: {
  167 + pageNo: 1,
  168 + pageSize: 10,
  169 + name: null,
  170 + status: null,
  171 + },
  172 + // 表单参数
  173 + form: {},
  174 + // 表单校验
  175 + rules: {
  176 + pid: [{required: true, message: "请选择上级分类", trigger: "blur"}],
  177 + name: [{required: true, message: "分类名称不能为空", trigger: "blur"}],
  178 + icon: [{required: true, message: "分类图标不能为空", trigger: "blur"}],
  179 + bannerUrl: [{required: true, message: "分类图片不能为空", trigger: "blur"}],
  180 + status: [{required: true, message: "开启状态不能为空", trigger: "blur"}],
  181 + }
  182 + };
  183 + },
  184 + created() {
  185 + this.getList();
  186 + },
  187 + methods: {
  188 + /** 查询列表 */
  189 + getList() {
  190 + this.loading = true;
  191 + // 处理查询参数
  192 + let params = {...this.queryParams};
  193 + // 执行查询
  194 + listCategory(params).then(response => {
  195 + this.list = this.handleTree(response.data, "id", "pid");
  196 + this.loading = false;
  197 + });
  198 + },
  199 + // 选择图标
  200 + iconSelected(name) {
  201 + this.form.icon = name;
  202 + },
  203 + /** 转换菜单数据结构 */
  204 + normalizer(node) {
  205 + if (node.children && !node.children.length) {
  206 + delete node.children;
  207 + }
  208 + return {
  209 + id: node.id,
  210 + label: node.name,
  211 + children: node.children
  212 + };
  213 + },
  214 + /** 查询分类下拉树结构 */
  215 + getTreeselect() {
  216 + listCategory().then(response => {
  217 + this.parentCategoryOptions = [];
  218 + const menu = {id: 0, name: '主分类', children: []};
  219 + menu.children = this.handleTree(response.data, "id", "pid");
  220 + this.parentCategoryOptions.push(menu);
  221 + });
  222 + },
  223 + /** 取消按钮 */
  224 + cancel() {
  225 + this.open = false;
  226 + this.reset();
  227 + },
  228 + /** 表单重置 */
  229 + reset() {
  230 + this.form = {
  231 + id: undefined,
  232 + pid: undefined,
  233 + name: undefined,
  234 + icon: undefined,
  235 + bannerUrl: undefined,
  236 + sort: undefined,
  237 + description: undefined,
  238 + status: undefined,
  239 + };
  240 + this.resetForm("form");
  241 + },
  242 + /** 搜索按钮操作 */
  243 + handleQuery() {
  244 + this.queryParams.pageNo = 1;
  245 + this.getList();
  246 + },
  247 + /** 重置按钮操作 */
  248 + resetQuery() {
  249 + this.resetForm("queryForm");
  250 + this.handleQuery();
  251 + },
  252 + /** 展开/折叠操作 */
  253 + toggleExpandAll() {
  254 + this.refreshTable = false;
  255 + this.isExpandAll = !this.isExpandAll;
  256 + this.$nextTick(() => {
  257 + this.refreshTable = true;
  258 + });
  259 + },
  260 + /** 新增按钮操作 */
  261 + handleAdd() {
  262 + this.reset();
  263 + this.getTreeselect();
  264 + this.open = true;
  265 + this.title = "添加商品分类";
  266 + },
  267 + /** 修改按钮操作 */
  268 + handleUpdate(row) {
  269 + this.reset();
  270 + this.getTreeselect();
  271 + const id = row.id;
  272 + getCategory(id).then(response => {
  273 + this.form = response.data;
  274 + this.open = true;
  275 + this.title = "修改商品分类";
  276 + });
  277 + },
  278 + /** 提交按钮 */
  279 + submitForm() {
  280 + this.$refs["form"].validate(valid => {
  281 + if (!valid) {
  282 + return;
  283 + }
  284 + // 修改的提交
  285 + if (this.form.id != null) {
  286 + updateCategory(this.form).then(response => {
  287 + this.$modal.msgSuccess("修改成功");
  288 + this.open = false;
  289 + this.getList();
  290 + });
  291 + return;
  292 + }
  293 + // 添加的提交
  294 + createCategory(this.form).then(response => {
  295 + this.$modal.msgSuccess("新增成功");
  296 + this.open = false;
  297 + this.getList();
  298 + });
  299 + });
  300 + },
  301 + /** 删除按钮操作 */
  302 + handleDelete(row) {
  303 + const id = row.id;
  304 + this.$modal.confirm('是否确认删除商品分类编号为"' + id + '"的数据项?').then(function () {
  305 + return deleteCategory(id);
  306 + }).then(() => {
  307 + this.getList();
  308 + this.$modal.msgSuccess("删除成功");
  309 + }).catch(() => {
  310 + });
  311 + },
  312 + /** 导出按钮操作 */
  313 + handleExport() {
  314 + // 处理查询参数
  315 + let params = {...this.queryParams};
  316 + params.pageNo = undefined;
  317 + params.pageSize = undefined;
  318 + // 执行导出
  319 + this.$modal.confirm('是否确认导出所有商品分类数据项?').then(() => {
  320 + this.exportLoading = true;
  321 + return exportCategoryExcel(params);
  322 + }).then(response => {
  323 + this.$download.excel(response, '${table.classComment}.xls');
  324 + this.exportLoading = false;
  325 + }).catch(() => {
  326 + });
  327 + }
  328 + }
  329 +};
  330 +</script>