From d3edaec2b1d7c54bc5e03450431fb68983ec6368 Mon Sep 17 00:00:00 2001 From: JeromeSoar Date: Sun, 24 Apr 2022 17:01:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB=E7=BB=B4?= =?UTF-8?q?=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mall.sql | 6 +- .../admin/category/CategoryController.java | 48 +++++++------ .../admin/category/vo/CategoryBaseVO.java | 16 ++--- .../service/category/CategoryService.java | 19 +++-- .../service/category/CategoryServiceImpl.java | 26 ++++--- .../src/api/mall/product/category.js | 9 +++ .../src/views/mall/product/category/index.vue | 71 +++++++++++++++---- 7 files changed, 137 insertions(+), 58 deletions(-) diff --git a/sql/mall.sql b/sql/mall.sql index 390044e06..825d43e36 100644 --- a/sql/mall.sql +++ b/sql/mall.sql @@ -26,10 +26,10 @@ CREATE TABLE `product_category` `id` bigint NOT NULL AUTO_INCREMENT COMMENT '分类编号', `pid` bigint NOT NULL COMMENT '父分类编号', `name` varchar(255) NOT NULL COMMENT '分类名称', - `icon` varchar(100) DEFAULT '#' COMMENT '分类图标', + `icon` varchar(100) NOT NULL DEFAULT '#' COMMENT '分类图标', `banner_url` varchar(255) NOT NULL COMMENT '分类图片', - `sort` int NOT NULL DEFAULT '0' COMMENT '分类排序', - `description` varchar(1024) NOT NULL COMMENT '分类描述', + `sort` int DEFAULT '0' COMMENT '分类排序', + `description` varchar(1024) DEFAULT NULL COMMENT '分类描述', `status` tinyint NOT NULL COMMENT '开启状态', `creator` varchar(64) DEFAULT '' COMMENT '创建者', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/CategoryController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/CategoryController.java index 346b3177a..ed22def1d 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/CategoryController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/CategoryController.java @@ -1,30 +1,29 @@ package cn.iocoder.yudao.module.product.controller.admin.category; -import org.springframework.web.bind.annotation.*; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.security.access.prepost.PreAuthorize; -import io.swagger.annotations.*; - -import javax.validation.constraints.*; -import javax.validation.*; -import javax.servlet.http.*; -import java.util.*; -import java.io.IOException; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; - import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; - import cn.iocoder.yudao.module.product.controller.admin.category.vo.*; -import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO; import cn.iocoder.yudao.module.product.convert.category.CategoryConvert; +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO; import cn.iocoder.yudao.module.product.service.category.CategoryService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.util.Collection; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; @Api(tags = "管理后台 - 商品分类") @RestController @@ -68,15 +67,22 @@ public class CategoryController { return success(CategoryConvert.INSTANCE.convert(category)); } - @GetMapping("/list") + @GetMapping("/listByIds") @ApiOperation("获得商品分类列表") - @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) @PreAuthorize("@ss.hasPermission('product:category:query')") public CommonResult> getCategoryList(@RequestParam("ids") Collection ids) { List list = categoryService.getCategoryList(ids); return success(CategoryConvert.INSTANCE.convertList(list)); } + @GetMapping("/listByQuery") + @ApiOperation("获得商品分类列表") + @PreAuthorize("@ss.hasPermission('product:category:query')") + public CommonResult> listByQuery() { + List list = categoryService.listByQuery(); + return success(CategoryConvert.INSTANCE.convertList(list)); + } + @GetMapping("/page") @ApiOperation("获得商品分类分页") @PreAuthorize("@ss.hasPermission('product:category:query')") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryBaseVO.java index 82f2ba09d..d4c2ebb8b 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryBaseVO.java @@ -1,9 +1,10 @@ package cn.iocoder.yudao.module.product.controller.admin.category.vo; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import javax.validation.constraints.*; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; /** * 商品分类 Base VO,提供给添加、修改、详细的子 VO 使用 @@ -17,22 +18,21 @@ public class CategoryBaseVO { private Long pid; @ApiModelProperty(value = "分类名称", required = true, example = "办公文具") - @NotNull(message = "分类名称不能为空") + @NotBlank(message = "分类名称不能为空") private String name; @ApiModelProperty(value = "分类图标") + @NotBlank(message = "分类图标不能为空") private String icon; @ApiModelProperty(value = "分类图片", required = true) - @NotNull(message = "分类图片不能为空") + @NotBlank(message = "分类图片不能为空") private String bannerUrl; @ApiModelProperty(value = "分类排序", required = true, example = "1") - @NotNull(message = "分类排序不能为空") private Integer sort; @ApiModelProperty(value = "分类描述", required = true, example = "描述") - @NotNull(message = "分类描述不能为空") private String description; @ApiModelProperty(value = "开启状态", required = true, example = "0") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java index ff5f520fa..89ac934fb 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java @@ -1,10 +1,15 @@ package cn.iocoder.yudao.module.product.service.category; -import java.util.*; -import javax.validation.*; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.*; -import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryExportReqVO; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryPageReqVO; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryUpdateReqVO; +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO; + +import javax.validation.Valid; +import java.util.Collection; +import java.util.List; /** * 商品分类 Service 接口 @@ -67,4 +72,10 @@ public interface CategoryService { */ List getCategoryList(CategoryExportReqVO exportReqVO); + /** + * 获得商品分类列表 + * + * @return 商品分类列表 + */ + List listByQuery(); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java index 873bad297..1465892f6 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java @@ -1,19 +1,22 @@ package cn.iocoder.yudao.module.product.service.category; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryExportReqVO; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryPageReqVO; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryUpdateReqVO; +import cn.iocoder.yudao.module.product.convert.category.CategoryConvert; +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO; +import cn.iocoder.yudao.module.product.dal.mysql.category.CategoryMapper; import org.springframework.stereotype.Service; -import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; -import java.util.*; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.*; -import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import cn.iocoder.yudao.module.product.convert.category.CategoryConvert; -import cn.iocoder.yudao.module.product.dal.mysql.category.CategoryMapper; +import javax.annotation.Resource; +import java.util.Collection; +import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.CATEGORY_NOT_EXISTS; /** * 商品分类 Service 实现类 @@ -79,4 +82,9 @@ public class CategoryServiceImpl implements CategoryService { return categoryMapper.selectList(exportReqVO); } + @Override + public List listByQuery() { + return categoryMapper.selectList(); + } + } diff --git a/yudao-ui-admin/src/api/mall/product/category.js b/yudao-ui-admin/src/api/mall/product/category.js index 33fde73cd..bd825034d 100644 --- a/yudao-ui-admin/src/api/mall/product/category.js +++ b/yudao-ui-admin/src/api/mall/product/category.js @@ -34,6 +34,15 @@ export function getCategory(id) { }) } +// 获得商品分类 +export function listCategory(query) { + return request({ + url: '/product/category/listByQuery', + method: 'get', + params: query + }) +} + // 获得商品分类分页 export function getCategoryPage(query) { return request({ diff --git a/yudao-ui-admin/src/views/mall/product/category/index.vue b/yudao-ui-admin/src/views/mall/product/category/index.vue index 57273c146..26cfcdf94 100644 --- a/yudao-ui-admin/src/views/mall/product/category/index.vue +++ b/yudao-ui-admin/src/views/mall/product/category/index.vue @@ -40,13 +40,18 @@ - - - - + + + + + + -