From ff307a4c864a6e0d0540066e13780f6920ef0b1c Mon Sep 17 00:00:00 2001 From: jeromesoar Date: Thu, 12 May 2022 16:57:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20TODO=20pid=20=E6=94=B9=E6=88=90=20parent?= =?UTF-8?q?Id=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mall.sql | 32 +++++++++---------- .../admin/category/vo/CategoryBaseVO.java | 2 +- .../admin/category/vo/CategoryExcelVO.java | 11 +++---- .../dal/dataobject/category/CategoryDO.java | 3 +- .../category/CategoryServiceImplTest.java | 8 ++--- .../src/test/resources/sql/create_tables.sql | 2 +- .../src/views/mall/product/category/index.vue | 13 ++++---- 7 files changed, 35 insertions(+), 36 deletions(-) diff --git a/sql/mall.sql b/sql/mall.sql index db60049ce..ad32c96d1 100644 --- a/sql/mall.sql +++ b/sql/mall.sql @@ -24,7 +24,7 @@ DROP TABLE IF EXISTS `product_category`; CREATE TABLE `product_category` ( `id` bigint NOT NULL AUTO_INCREMENT COMMENT '分类编号', - `pid` bigint NOT NULL COMMENT '父分类编号', + `parent_id` bigint NOT NULL COMMENT '父分类编号', `name` varchar(255) NOT NULL COMMENT '分类名称', `icon` varchar(100) NOT NULL DEFAULT '#' COMMENT '分类图标', `banner_url` varchar(255) NOT NULL COMMENT '分类图片', @@ -62,29 +62,29 @@ CREATE TABLE `product_brand` PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB COMMENT='品牌'; --- TODO 父级菜单的 id 处理 -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); -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); +-- TODO 父级菜单的 id 处理: 2000 、 2001 +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES (2000, '商城', '', 1, 1, 0, '/mall', 'merchant', NULL, 0); +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES (2001, '商品管理', '', 1, 1, 2000, 'product', 'dict', NULL, 0); -- 商品分类 菜单 SQL -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类管理', '', 2, 0, 2001, 'category', '', 'mall/product/category/index', 0); +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类管理', '', 2, 0, 2001, 'category', '', 'mall/product/category/index', 0); -- 按钮父菜单ID SELECT @parentId := LAST_INSERT_ID(); -- 按钮 SQL -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类查询', 'product:category:query', 3, 1, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类创建', 'product:category:create', 3, 2, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类更新', 'product:category:update', 3, 3, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类删除', 'product:category:delete', 3, 4, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类导出', 'product:category:export', 3, 5, @parentId, '', '', '', 0); +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类查询', 'product:category:query', 3, 1, @parentId, '', '', '', 0); +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类创建', 'product:category:create', 3, 2, @parentId, '', '', '', 0); +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类更新', 'product:category:update', 3, 3, @parentId, '', '', '', 0); +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类删除', 'product:category:delete', 3, 4, @parentId, '', '', '', 0); +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类导出', 'product:category:export', 3, 5, @parentId, '', '', '', 0); -- 品牌管理 菜单 SQL -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌管理', '', 2, 0, 2001, 'brand', '', 'mall/product/brand/index', 0); +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌管理', '', 2, 0, 2001, 'brand', '', 'mall/product/brand/index', 0); -- 按钮父菜单ID SELECT @parentId := LAST_INSERT_ID(); -- 按钮 SQL -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌查询', 'product:brand:query', 3, 1, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌创建', 'product:brand:create', 3, 2, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌更新', 'product:brand:update', 3, 3, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌删除', 'product:brand:delete', 3, 4, @parentId, '', '', '', 0); -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌导出', 'product:brand:export', 3, 5, @parentId, '', '', '', 0); +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌查询', 'product:brand:query', 3, 1, @parentId, '', '', '', 0); +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌创建', 'product:brand:create', 3, 2, @parentId, '', '', '', 0); +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌更新', 'product:brand:update', 3, 3, @parentId, '', '', '', 0); +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌删除', 'product:brand:delete', 3, 4, @parentId, '', '', '', 0); +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌导出', 'product:brand:export', 3, 5, @parentId, '', '', '', 0); -- ---------------------------- 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 d4c2ebb8b..598e093eb 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 @@ -15,7 +15,7 @@ public class CategoryBaseVO { @ApiModelProperty(value = "父分类编号", required = true, example = "1") @NotNull(message = "父分类编号不能为空") - private Long pid; + private Long parentId; @ApiModelProperty(value = "分类名称", required = true, example = "办公文具") @NotBlank(message = "分类名称不能为空") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryExcelVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryExcelVO.java index ae754e42d..f8e36ee8c 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryExcelVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryExcelVO.java @@ -1,12 +1,11 @@ package cn.iocoder.yudao.module.product.controller.admin.category.vo; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; - -import com.alibaba.excel.annotation.ExcelProperty; import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +import java.util.Date; /** @@ -21,7 +20,7 @@ public class CategoryExcelVO { private Long id; @ExcelProperty("父分类编号") - private Long pid; + private Long parentId; @ExcelProperty("分类名称") private String name; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/category/CategoryDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/category/CategoryDO.java index ce52ebf9c..09632b5e3 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/category/CategoryDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/category/CategoryDO.java @@ -28,8 +28,7 @@ public class CategoryDO extends BaseDO { /** * 父分类编号 */ - // TODO @JeromeSoar:改成 parentId 字段 - private Long pid; + private Long parentId; /** * 分类名称 */ diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImplTest.java index c0ef7e572..5749e65ee 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImplTest.java +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImplTest.java @@ -105,7 +105,7 @@ public class CategoryServiceImplTest extends BaseDbUnitTest { public void testGetCategoryPage() { // mock 数据 CategoryDO dbCategory = randomPojo(CategoryDO.class, o -> { // 等会查询到 - o.setPid(null); + o.setParentId(null); o.setName(null); o.setIcon(null); o.setBannerUrl(null); @@ -116,7 +116,7 @@ public class CategoryServiceImplTest extends BaseDbUnitTest { }); categoryMapper.insert(dbCategory); // 测试 pid 不匹配 - categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setPid(null))); + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setParentId(null))); // 测试 name 不匹配 categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setName(null))); // 测试 icon 不匹配 @@ -151,7 +151,7 @@ public class CategoryServiceImplTest extends BaseDbUnitTest { public void testGetCategoryList() { // mock 数据 CategoryDO dbCategory = randomPojo(CategoryDO.class, o -> { // 等会查询到 - o.setPid(null); + o.setParentId(null); o.setName(null); o.setIcon(null); o.setBannerUrl(null); @@ -162,7 +162,7 @@ public class CategoryServiceImplTest extends BaseDbUnitTest { }); categoryMapper.insert(dbCategory); // 测试 pid 不匹配 - categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setPid(null))); + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setParentId(null))); // 测试 name 不匹配 categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setName(null))); // 测试 icon 不匹配 diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql b/yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql index 165a7454e..94f0b7937 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS "product_category" ( "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "pid" bigint(20) NOT NULL, + "parent_id" bigint(20) NOT NULL, "name" varchar(255) NOT NULL, "icon" varchar(100), "banner_url" varchar(255) NOT NULL, 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 6fa403889..41ed4c020 100644 --- a/yudao-ui-admin/src/views/mall/product/category/index.vue +++ b/yudao-ui-admin/src/views/mall/product/category/index.vue @@ -77,8 +77,9 @@ - - + @@ -172,7 +173,7 @@ export default { form: {}, // 表单校验 rules: { - pid: [{required: true, message: "请选择上级分类", trigger: "blur"}], + parentId: [{required: true, message: "请选择上级分类", trigger: "blur"}], name: [{required: true, message: "分类名称不能为空", trigger: "blur"}], icon: [{required: true, message: "分类图标不能为空", trigger: "blur"}], bannerUrl: [{required: true, message: "分类图片不能为空", trigger: "blur"}], @@ -191,7 +192,7 @@ export default { let params = {...this.queryParams}; // 执行查询 listCategory(params).then(response => { - this.list = this.handleTree(response.data, "id", "pid"); + this.list = this.handleTree(response.data, "id", "parentId"); this.loading = false; }); }, @@ -215,7 +216,7 @@ export default { listCategory().then(response => { this.parentCategoryOptions = []; const menu = {id: 0, name: '主分类', children: []}; - menu.children = this.handleTree(response.data, "id", "pid"); + menu.children = this.handleTree(response.data, "id", "parentId"); this.parentCategoryOptions.push(menu); }); }, @@ -228,7 +229,7 @@ export default { reset() { this.form = { id: undefined, - pid: undefined, + parentId: undefined, name: undefined, icon: undefined, bannerUrl: undefined,