Commit 4e67b6bbcfb353ac8da1df71bb1342deeac337fb

Authored by JeromeSoar
1 parent 09722c0c

商品分类代码生成

Showing 26 changed files with 1319 additions and 4 deletions
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) DEFAULT '#' COMMENT '分类图标',
  30 + `banner_url` varchar(255) NOT NULL COMMENT '分类图片',
  31 + `sort` int NOT NULL DEFAULT '0' COMMENT '分类排序',
  32 + `description` varchar(1024) NOT 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-mall/pom.xml
@@ -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-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 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.category.vo.*;
  25 +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO;
  26 +import cn.iocoder.yudao.module.product.convert.category.CategoryConvert;
  27 +import cn.iocoder.yudao.module.product.service.category.CategoryService;
  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("/list")
  72 + @ApiOperation("获得商品分类列表")
  73 + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
  74 + @PreAuthorize("@ss.hasPermission('product:category:query')")
  75 + public CommonResult<List<CategoryRespVO>> getCategoryList(@RequestParam("ids") Collection<Long> ids) {
  76 + List<CategoryDO> list = categoryService.getCategoryList(ids);
  77 + return success(CategoryConvert.INSTANCE.convertList(list));
  78 + }
  79 +
  80 + @GetMapping("/page")
  81 + @ApiOperation("获得商品分类分页")
  82 + @PreAuthorize("@ss.hasPermission('product:category:query')")
  83 + public CommonResult<PageResult<CategoryRespVO>> getCategoryPage(@Valid CategoryPageReqVO pageVO) {
  84 + PageResult<CategoryDO> pageResult = categoryService.getCategoryPage(pageVO);
  85 + return success(CategoryConvert.INSTANCE.convertPage(pageResult));
  86 + }
  87 +
  88 + @GetMapping("/export-excel")
  89 + @ApiOperation("导出商品分类 Excel")
  90 + @PreAuthorize("@ss.hasPermission('product:category:export')")
  91 + @OperateLog(type = EXPORT)
  92 + public void exportCategoryExcel(@Valid CategoryExportReqVO exportReqVO,
  93 + HttpServletResponse response) throws IOException {
  94 + List<CategoryDO> list = categoryService.getCategoryList(exportReqVO);
  95 + // 导出 Excel
  96 + List<CategoryExcelVO> datas = CategoryConvert.INSTANCE.convertList02(list);
  97 + ExcelUtils.write(response, "商品分类.xls", "数据", CategoryExcelVO.class, datas);
  98 + }
  99 +
  100 +}
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 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 CategoryBaseVO {
  14 +
  15 + @ApiModelProperty(value = "父分类编号", required = true, example = "1")
  16 + @NotNull(message = "父分类编号不能为空")
  17 + private Long pid;
  18 +
  19 + @ApiModelProperty(value = "分类名称", required = true, example = "办公文具")
  20 + @NotNull(message = "分类名称不能为空")
  21 + private String name;
  22 +
  23 + @ApiModelProperty(value = "分类图标")
  24 + private String icon;
  25 +
  26 + @ApiModelProperty(value = "分类图片", required = true)
  27 + @NotNull(message = "分类图片不能为空")
  28 + private String bannerUrl;
  29 +
  30 + @ApiModelProperty(value = "分类排序", required = true, example = "1")
  31 + @NotNull(message = "分类排序不能为空")
  32 + private Integer sort;
  33 +
  34 + @ApiModelProperty(value = "分类描述", required = true, example = "描述")
  35 + @NotNull(message = "分类描述不能为空")
  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/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 java.util.*;
  4 +import javax.validation.*;
  5 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.*;
  6 +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO;
  7 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  8 +
  9 +/**
  10 + * 商品分类 Service 接口
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +public interface CategoryService {
  15 +
  16 + /**
  17 + * 创建商品分类
  18 + *
  19 + * @param createReqVO 创建信息
  20 + * @return 编号
  21 + */
  22 + Long createCategory(@Valid CategoryCreateReqVO createReqVO);
  23 +
  24 + /**
  25 + * 更新商品分类
  26 + *
  27 + * @param updateReqVO 更新信息
  28 + */
  29 + void updateCategory(@Valid CategoryUpdateReqVO updateReqVO);
  30 +
  31 + /**
  32 + * 删除商品分类
  33 + *
  34 + * @param id 编号
  35 + */
  36 + void deleteCategory(Long id);
  37 +
  38 + /**
  39 + * 获得商品分类
  40 + *
  41 + * @param id 编号
  42 + * @return 商品分类
  43 + */
  44 + CategoryDO getCategory(Long id);
  45 +
  46 + /**
  47 + * 获得商品分类列表
  48 + *
  49 + * @param ids 编号
  50 + * @return 商品分类列表
  51 + */
  52 + List<CategoryDO> getCategoryList(Collection<Long> ids);
  53 +
  54 + /**
  55 + * 获得商品分类分页
  56 + *
  57 + * @param pageReqVO 分页查询
  58 + * @return 商品分类分页
  59 + */
  60 + PageResult<CategoryDO> getCategoryPage(CategoryPageReqVO pageReqVO);
  61 +
  62 + /**
  63 + * 获得商品分类列表, 用于 Excel 导出
  64 + *
  65 + * @param exportReqVO 查询条件
  66 + * @return 商品分类列表
  67 + */
  68 + List<CategoryDO> getCategoryList(CategoryExportReqVO exportReqVO);
  69 +
  70 +}
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 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.category.vo.*;
  9 +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO;
  10 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  11 +
  12 +import cn.iocoder.yudao.module.product.convert.category.CategoryConvert;
  13 +import cn.iocoder.yudao.module.product.dal.mysql.category.CategoryMapper;
  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 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 +}
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 getCategoryPage(query) {
  39 + return request({
  40 + url: '/product/category/page',
  41 + method: 'get',
  42 + params: query
  43 + })
  44 +}
  45 +
  46 +// 导出商品分类 Excel
  47 +export function exportCategoryExcel(query) {
  48 + return request({
  49 + url: '/product/category/export-excel',
  50 + method: 'get',
  51 + params: query,
  52 + responseType: 'blob'
  53 + })
  54 +}
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 label="创建时间">
  16 + <el-date-picker v-model="dateRangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd"
  17 + type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
  18 + </el-form-item>
  19 + <el-form-item>
  20 + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  21 + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  22 + </el-form-item>
  23 + </el-form>
  24 +
  25 + <!-- 操作工具栏 -->
  26 + <el-row :gutter="10" class="mb8">
  27 + <el-col :span="1.5">
  28 + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  29 + v-hasPermi="['product:category:create']">新增
  30 + </el-button>
  31 + </el-col>
  32 + <el-col :span="1.5">
  33 + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
  34 + :loading="exportLoading"
  35 + v-hasPermi="['product:category:export']">导出
  36 + </el-button>
  37 + </el-col>
  38 + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  39 + </el-row>
  40 +
  41 + <!-- 列表 -->
  42 + <el-table v-loading="loading" :data="list">
  43 + <el-table-column label="分类编号" align="center" prop="id"/>
  44 + <el-table-column label="父分类编号" align="center" prop="pid"/>
  45 + <el-table-column label="分类名称" align="center" prop="name"/>
  46 + <el-table-column label="分类图标" align="center" prop="icon"/>
  47 + <el-table-column label="分类图片" align="center" prop="bannerUrl"/>
  48 + <el-table-column label="分类排序" align="center" prop="sort"/>
  49 + <el-table-column label="分类描述" align="center" prop="description"/>
  50 + <el-table-column label="开启状态" align="center" prop="status">
  51 + <template slot-scope="scope">
  52 + <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
  53 + </template>
  54 + </el-table-column>
  55 + <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  56 + <template slot-scope="scope">
  57 + <span>{{ parseTime(scope.row.createTime) }}</span>
  58 + </template>
  59 + </el-table-column>
  60 + <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  61 + <template slot-scope="scope">
  62 + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  63 + v-hasPermi="['product:category:update']">修改
  64 + </el-button>
  65 + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  66 + v-hasPermi="['product:category:delete']">删除
  67 + </el-button>
  68 + </template>
  69 + </el-table-column>
  70 + </el-table>
  71 + <!-- 分页组件 -->
  72 + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  73 + @pagination="getList"/>
  74 +
  75 + <!-- 对话框(添加 / 修改) -->
  76 + <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  77 + <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  78 + <el-form-item label="父分类编号" prop="pid">
  79 + <el-input v-model="form.pid" placeholder="请输入父分类编号"/>
  80 + </el-form-item>
  81 + <el-form-item label="分类名称" prop="name">
  82 + <el-input v-model="form.name" placeholder="请输入分类名称"/>
  83 + </el-form-item>
  84 + <el-form-item label="分类图标" prop="icon">
  85 + <el-input v-model="form.icon" placeholder="请输入分类图标"/>
  86 + </el-form-item>
  87 + <el-form-item label="分类图片" prop="bannerUrl">
  88 + <el-input v-model="form.bannerUrl" placeholder="请输入分类图片"/>
  89 + </el-form-item>
  90 + <el-form-item label="分类排序" prop="sort">
  91 + <el-input v-model="form.sort" placeholder="请输入分类排序"/>
  92 + </el-form-item>
  93 + <el-form-item label="分类描述">
  94 + <editor v-model="form.description" :min-height="192"/>
  95 + </el-form-item>
  96 + <el-form-item label="开启状态" prop="status">
  97 + <el-radio-group v-model="form.status">
  98 + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
  99 + :key="dict.value" :label="parseInt(dict.value)">{{ dict.label }}
  100 + </el-radio>
  101 + </el-radio-group>
  102 + </el-form-item>
  103 + </el-form>
  104 + <div slot="footer" class="dialog-footer">
  105 + <el-button type="primary" @click="submitForm">确 定</el-button>
  106 + <el-button @click="cancel">取 消</el-button>
  107 + </div>
  108 + </el-dialog>
  109 + </div>
  110 +</template>
  111 +
  112 +<script>
  113 +import {
  114 + createCategory,
  115 + deleteCategory,
  116 + exportCategoryExcel,
  117 + getCategory,
  118 + getCategoryPage,
  119 + updateCategory
  120 +} from "@/api/mall/product/category";
  121 +import Editor from '@/components/Editor';
  122 +
  123 +export default {
  124 + name: "Category",
  125 + components: {
  126 + Editor,
  127 + },
  128 + data() {
  129 + return {
  130 + // 遮罩层
  131 + loading: true,
  132 + // 导出遮罩层
  133 + exportLoading: false,
  134 + // 显示搜索条件
  135 + showSearch: true,
  136 + // 总条数
  137 + total: 0,
  138 + // 商品分类列表
  139 + list: [],
  140 + // 弹出层标题
  141 + title: "",
  142 + // 是否显示弹出层
  143 + open: false,
  144 + dateRangeCreateTime: [],
  145 + // 查询参数
  146 + queryParams: {
  147 + pageNo: 1,
  148 + pageSize: 10,
  149 + name: null,
  150 + status: null,
  151 + },
  152 + // 表单参数
  153 + form: {},
  154 + // 表单校验
  155 + rules: {
  156 + pid: [{required: true, message: "父分类编号不能为空", trigger: "blur"}],
  157 + name: [{required: true, message: "分类名称不能为空", trigger: "blur"}],
  158 + bannerUrl: [{required: true, message: "分类图片不能为空", trigger: "blur"}],
  159 + sort: [{required: true, message: "分类排序不能为空", trigger: "blur"}],
  160 + description: [{required: true, message: "分类描述不能为空", trigger: "blur"}],
  161 + status: [{required: true, message: "开启状态不能为空", trigger: "blur"}],
  162 + }
  163 + };
  164 + },
  165 + created() {
  166 + this.getList();
  167 + },
  168 + methods: {
  169 + /** 查询列表 */
  170 + getList() {
  171 + this.loading = true;
  172 + // 处理查询参数
  173 + let params = {...this.queryParams};
  174 + this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
  175 + // 执行查询
  176 + getCategoryPage(params).then(response => {
  177 + this.list = response.data.list;
  178 + this.total = response.data.total;
  179 + this.loading = false;
  180 + });
  181 + },
  182 + /** 取消按钮 */
  183 + cancel() {
  184 + this.open = false;
  185 + this.reset();
  186 + },
  187 + /** 表单重置 */
  188 + reset() {
  189 + this.form = {
  190 + id: undefined,
  191 + pid: undefined,
  192 + name: undefined,
  193 + icon: undefined,
  194 + bannerUrl: undefined,
  195 + sort: undefined,
  196 + description: undefined,
  197 + status: undefined,
  198 + };
  199 + this.resetForm("form");
  200 + },
  201 + /** 搜索按钮操作 */
  202 + handleQuery() {
  203 + this.queryParams.pageNo = 1;
  204 + this.getList();
  205 + },
  206 + /** 重置按钮操作 */
  207 + resetQuery() {
  208 + this.dateRangeCreateTime = [];
  209 + this.resetForm("queryForm");
  210 + this.handleQuery();
  211 + },
  212 + /** 新增按钮操作 */
  213 + handleAdd() {
  214 + this.reset();
  215 + this.open = true;
  216 + this.title = "添加商品分类";
  217 + },
  218 + /** 修改按钮操作 */
  219 + handleUpdate(row) {
  220 + this.reset();
  221 + const id = row.id;
  222 + getCategory(id).then(response => {
  223 + this.form = response.data;
  224 + this.open = true;
  225 + this.title = "修改商品分类";
  226 + });
  227 + },
  228 + /** 提交按钮 */
  229 + submitForm() {
  230 + this.$refs["form"].validate(valid => {
  231 + if (!valid) {
  232 + return;
  233 + }
  234 + // 修改的提交
  235 + if (this.form.id != null) {
  236 + updateCategory(this.form).then(response => {
  237 + this.$modal.msgSuccess("修改成功");
  238 + this.open = false;
  239 + this.getList();
  240 + });
  241 + return;
  242 + }
  243 + // 添加的提交
  244 + createCategory(this.form).then(response => {
  245 + this.$modal.msgSuccess("新增成功");
  246 + this.open = false;
  247 + this.getList();
  248 + });
  249 + });
  250 + },
  251 + /** 删除按钮操作 */
  252 + handleDelete(row) {
  253 + const id = row.id;
  254 + this.$modal.confirm('是否确认删除商品分类编号为"' + id + '"的数据项?').then(function () {
  255 + return deleteCategory(id);
  256 + }).then(() => {
  257 + this.getList();
  258 + this.$modal.msgSuccess("删除成功");
  259 + }).catch(() => {
  260 + });
  261 + },
  262 + /** 导出按钮操作 */
  263 + handleExport() {
  264 + // 处理查询参数
  265 + let params = {...this.queryParams};
  266 + params.pageNo = undefined;
  267 + params.pageSize = undefined;
  268 + this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
  269 + // 执行导出
  270 + this.$modal.confirm('是否确认导出所有商品分类数据项?').then(() => {
  271 + this.exportLoading = true;
  272 + return exportCategoryExcel(params);
  273 + }).then(response => {
  274 + this.$download.excel(response, '${table.classComment}.xls');
  275 + this.exportLoading = false;
  276 + }).catch(() => {
  277 + });
  278 + }
  279 + }
  280 +};
  281 +</script>