Commit ff307a4c864a6e0d0540066e13780f6920ef0b1c

Authored by jeromesoar
1 parent 1fc5c3c7

fix: TODO pid 改成 parentId 字段

sql/mall.sql
@@ -24,7 +24,7 @@ DROP TABLE IF EXISTS `product_category`; @@ -24,7 +24,7 @@ DROP TABLE IF EXISTS `product_category`;
24 CREATE TABLE `product_category` 24 CREATE TABLE `product_category`
25 ( 25 (
26 `id` bigint NOT NULL AUTO_INCREMENT COMMENT '分类编号', 26 `id` bigint NOT NULL AUTO_INCREMENT COMMENT '分类编号',
27 - `pid` bigint NOT NULL COMMENT '父分类编号', 27 + `parent_id` bigint NOT NULL COMMENT '父分类编号',
28 `name` varchar(255) NOT NULL COMMENT '分类名称', 28 `name` varchar(255) NOT NULL COMMENT '分类名称',
29 `icon` varchar(100) NOT NULL DEFAULT '#' COMMENT '分类图标', 29 `icon` varchar(100) NOT NULL DEFAULT '#' COMMENT '分类图标',
30 `banner_url` varchar(255) NOT NULL COMMENT '分类图片', 30 `banner_url` varchar(255) NOT NULL COMMENT '分类图片',
@@ -62,29 +62,29 @@ CREATE TABLE `product_brand` @@ -62,29 +62,29 @@ CREATE TABLE `product_brand`
62 PRIMARY KEY (`id`) USING BTREE 62 PRIMARY KEY (`id`) USING BTREE
63 ) ENGINE=InnoDB COMMENT='品牌'; 63 ) ENGINE=InnoDB COMMENT='品牌';
64 64
65 --- TODO 父级菜单的 id 处理  
66 -INSERT INTO `system_menu` (`id`, `name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES (2000, '商城', '', 1, 1, 0, '/mall', 'merchant', NULL, 0);  
67 -INSERT INTO `system_menu` (`id`, `name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES (2001, '商品管理', '', 1, 1, 2000, 'product', 'dict', NULL, 0); 65 +-- TODO 父级菜单的 id 处理: 2000 、 2001
  66 +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES (2000, '商城', '', 1, 1, 0, '/mall', 'merchant', NULL, 0);
  67 +INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES (2001, '商品管理', '', 1, 1, 2000, 'product', 'dict', NULL, 0);
68 -- 商品分类 菜单 SQL 68 -- 商品分类 菜单 SQL
69 -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类管理', '', 2, 0, 2001, 'category', '', 'mall/product/category/index', 0); 69 +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类管理', '', 2, 0, 2001, 'category', '', 'mall/product/category/index', 0);
70 -- 按钮父菜单ID 70 -- 按钮父菜单ID
71 SELECT @parentId := LAST_INSERT_ID(); 71 SELECT @parentId := LAST_INSERT_ID();
72 -- 按钮 SQL 72 -- 按钮 SQL
73 -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类查询', 'product:category:query', 3, 1, @parentId, '', '', '', 0);  
74 -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类创建', 'product:category:create', 3, 2, @parentId, '', '', '', 0);  
75 -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类更新', 'product:category:update', 3, 3, @parentId, '', '', '', 0);  
76 -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类删除', 'product:category:delete', 3, 4, @parentId, '', '', '', 0);  
77 -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类导出', 'product:category:export', 3, 5, @parentId, '', '', '', 0); 73 +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类查询', 'product:category:query', 3, 1, @parentId, '', '', '', 0);
  74 +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类创建', 'product:category:create', 3, 2, @parentId, '', '', '', 0);
  75 +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类更新', 'product:category:update', 3, 3, @parentId, '', '', '', 0);
  76 +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类删除', 'product:category:delete', 3, 4, @parentId, '', '', '', 0);
  77 +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('商品分类导出', 'product:category:export', 3, 5, @parentId, '', '', '', 0);
78 -- 品牌管理 菜单 SQL 78 -- 品牌管理 菜单 SQL
79 -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌管理', '', 2, 0, 2001, 'brand', '', 'mall/product/brand/index', 0); 79 +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌管理', '', 2, 0, 2001, 'brand', '', 'mall/product/brand/index', 0);
80 -- 按钮父菜单ID 80 -- 按钮父菜单ID
81 SELECT @parentId := LAST_INSERT_ID(); 81 SELECT @parentId := LAST_INSERT_ID();
82 -- 按钮 SQL 82 -- 按钮 SQL
83 -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌查询', 'product:brand:query', 3, 1, @parentId, '', '', '', 0);  
84 -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌创建', 'product:brand:create', 3, 2, @parentId, '', '', '', 0);  
85 -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌更新', 'product:brand:update', 3, 3, @parentId, '', '', '', 0);  
86 -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌删除', 'product:brand:delete', 3, 4, @parentId, '', '', '', 0);  
87 -INSERT INTO `system_menu`(`name`, `permission`, `menu_type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌导出', 'product:brand:export', 3, 5, @parentId, '', '', '', 0); 83 +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌查询', 'product:brand:query', 3, 1, @parentId, '', '', '', 0);
  84 +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌创建', 'product:brand:create', 3, 2, @parentId, '', '', '', 0);
  85 +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌更新', 'product:brand:update', 3, 3, @parentId, '', '', '', 0);
  86 +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌删除', 'product:brand:delete', 3, 4, @parentId, '', '', '', 0);
  87 +INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`) VALUES ('品牌导出', 'product:brand:export', 3, 5, @parentId, '', '', '', 0);
88 88
89 89
90 -- ---------------------------- 90 -- ----------------------------
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 { @@ -15,7 +15,7 @@ public class CategoryBaseVO {
15 15
16 @ApiModelProperty(value = "父分类编号", required = true, example = "1") 16 @ApiModelProperty(value = "父分类编号", required = true, example = "1")
17 @NotNull(message = "父分类编号不能为空") 17 @NotNull(message = "父分类编号不能为空")
18 - private Long pid; 18 + private Long parentId;
19 19
20 @ApiModelProperty(value = "分类名称", required = true, example = "办公文具") 20 @ApiModelProperty(value = "分类名称", required = true, example = "办公文具")
21 @NotBlank(message = "分类名称不能为空") 21 @NotBlank(message = "分类名称不能为空")
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryExcelVO.java
1 package cn.iocoder.yudao.module.product.controller.admin.category.vo; 1 package cn.iocoder.yudao.module.product.controller.admin.category.vo;
2 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; 3 import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
9 import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; 4 import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
  5 +import com.alibaba.excel.annotation.ExcelProperty;
  6 +import lombok.Data;
  7 +
  8 +import java.util.Date;
10 9
11 10
12 /** 11 /**
@@ -21,7 +20,7 @@ public class CategoryExcelVO { @@ -21,7 +20,7 @@ public class CategoryExcelVO {
21 private Long id; 20 private Long id;
22 21
23 @ExcelProperty("父分类编号") 22 @ExcelProperty("父分类编号")
24 - private Long pid; 23 + private Long parentId;
25 24
26 @ExcelProperty("分类名称") 25 @ExcelProperty("分类名称")
27 private String name; 26 private String name;
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 { @@ -28,8 +28,7 @@ public class CategoryDO extends BaseDO {
28 /** 28 /**
29 * 父分类编号 29 * 父分类编号
30 */ 30 */
31 - // TODO @JeromeSoar:改成 parentId 字段  
32 - private Long pid; 31 + private Long parentId;
33 /** 32 /**
34 * 分类名称 33 * 分类名称
35 */ 34 */
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 { @@ -105,7 +105,7 @@ public class CategoryServiceImplTest extends BaseDbUnitTest {
105 public void testGetCategoryPage() { 105 public void testGetCategoryPage() {
106 // mock 数据 106 // mock 数据
107 CategoryDO dbCategory = randomPojo(CategoryDO.class, o -> { // 等会查询到 107 CategoryDO dbCategory = randomPojo(CategoryDO.class, o -> { // 等会查询到
108 - o.setPid(null); 108 + o.setParentId(null);
109 o.setName(null); 109 o.setName(null);
110 o.setIcon(null); 110 o.setIcon(null);
111 o.setBannerUrl(null); 111 o.setBannerUrl(null);
@@ -116,7 +116,7 @@ public class CategoryServiceImplTest extends BaseDbUnitTest { @@ -116,7 +116,7 @@ public class CategoryServiceImplTest extends BaseDbUnitTest {
116 }); 116 });
117 categoryMapper.insert(dbCategory); 117 categoryMapper.insert(dbCategory);
118 // 测试 pid 不匹配 118 // 测试 pid 不匹配
119 - categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setPid(null))); 119 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setParentId(null)));
120 // 测试 name 不匹配 120 // 测试 name 不匹配
121 categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setName(null))); 121 categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setName(null)));
122 // 测试 icon 不匹配 122 // 测试 icon 不匹配
@@ -151,7 +151,7 @@ public class CategoryServiceImplTest extends BaseDbUnitTest { @@ -151,7 +151,7 @@ public class CategoryServiceImplTest extends BaseDbUnitTest {
151 public void testGetCategoryList() { 151 public void testGetCategoryList() {
152 // mock 数据 152 // mock 数据
153 CategoryDO dbCategory = randomPojo(CategoryDO.class, o -> { // 等会查询到 153 CategoryDO dbCategory = randomPojo(CategoryDO.class, o -> { // 等会查询到
154 - o.setPid(null); 154 + o.setParentId(null);
155 o.setName(null); 155 o.setName(null);
156 o.setIcon(null); 156 o.setIcon(null);
157 o.setBannerUrl(null); 157 o.setBannerUrl(null);
@@ -162,7 +162,7 @@ public class CategoryServiceImplTest extends BaseDbUnitTest { @@ -162,7 +162,7 @@ public class CategoryServiceImplTest extends BaseDbUnitTest {
162 }); 162 });
163 categoryMapper.insert(dbCategory); 163 categoryMapper.insert(dbCategory);
164 // 测试 pid 不匹配 164 // 测试 pid 不匹配
165 - categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setPid(null))); 165 + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setParentId(null)));
166 // 测试 name 不匹配 166 // 测试 name 不匹配
167 categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setName(null))); 167 categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setName(null)));
168 // 测试 icon 不匹配 168 // 测试 icon 不匹配
yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql
1 CREATE TABLE IF NOT EXISTS "product_category" ( 1 CREATE TABLE IF NOT EXISTS "product_category" (
2 "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, 2 "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY,
3 - "pid" bigint(20) NOT NULL, 3 + "parent_id" bigint(20) NOT NULL,
4 "name" varchar(255) NOT NULL, 4 "name" varchar(255) NOT NULL,
5 "icon" varchar(100), 5 "icon" varchar(100),
6 "banner_url" varchar(255) NOT NULL, 6 "banner_url" varchar(255) NOT NULL,
yudao-ui-admin/src/views/mall/product/category/index.vue
@@ -77,8 +77,9 @@ @@ -77,8 +77,9 @@
77 <!-- 对话框(添加 / 修改) --> 77 <!-- 对话框(添加 / 修改) -->
78 <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> 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"> 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" 80 + <el-form-item label="上级分类" prop="parentId">
  81 + <Treeselect v-model="form.parentId" :options="parentCategoryOptions" :normalizer="normalizer"
  82 + :show-count="true"
82 placeholder="上级分类"/> 83 placeholder="上级分类"/>
83 </el-form-item> 84 </el-form-item>
84 <el-form-item label="分类名称" prop="name"> 85 <el-form-item label="分类名称" prop="name">
@@ -172,7 +173,7 @@ export default { @@ -172,7 +173,7 @@ export default {
172 form: {}, 173 form: {},
173 // 表单校验 174 // 表单校验
174 rules: { 175 rules: {
175 - pid: [{required: true, message: "请选择上级分类", trigger: "blur"}], 176 + parentId: [{required: true, message: "请选择上级分类", trigger: "blur"}],
176 name: [{required: true, message: "分类名称不能为空", trigger: "blur"}], 177 name: [{required: true, message: "分类名称不能为空", trigger: "blur"}],
177 icon: [{required: true, message: "分类图标不能为空", trigger: "blur"}], 178 icon: [{required: true, message: "分类图标不能为空", trigger: "blur"}],
178 bannerUrl: [{required: true, message: "分类图片不能为空", trigger: "blur"}], 179 bannerUrl: [{required: true, message: "分类图片不能为空", trigger: "blur"}],
@@ -191,7 +192,7 @@ export default { @@ -191,7 +192,7 @@ export default {
191 let params = {...this.queryParams}; 192 let params = {...this.queryParams};
192 // 执行查询 193 // 执行查询
193 listCategory(params).then(response => { 194 listCategory(params).then(response => {
194 - this.list = this.handleTree(response.data, "id", "pid"); 195 + this.list = this.handleTree(response.data, "id", "parentId");
195 this.loading = false; 196 this.loading = false;
196 }); 197 });
197 }, 198 },
@@ -215,7 +216,7 @@ export default { @@ -215,7 +216,7 @@ export default {
215 listCategory().then(response => { 216 listCategory().then(response => {
216 this.parentCategoryOptions = []; 217 this.parentCategoryOptions = [];
217 const menu = {id: 0, name: '主分类', children: []}; 218 const menu = {id: 0, name: '主分类', children: []};
218 - menu.children = this.handleTree(response.data, "id", "pid"); 219 + menu.children = this.handleTree(response.data, "id", "parentId");
219 this.parentCategoryOptions.push(menu); 220 this.parentCategoryOptions.push(menu);
220 }); 221 });
221 }, 222 },
@@ -228,7 +229,7 @@ export default { @@ -228,7 +229,7 @@ export default {
228 reset() { 229 reset() {
229 this.form = { 230 this.form = {
230 id: undefined, 231 id: undefined,
231 - pid: undefined, 232 + parentId: undefined,
232 name: undefined, 233 name: undefined,
233 icon: undefined, 234 icon: undefined,
234 bannerUrl: undefined, 235 bannerUrl: undefined,