feat(category): 添加上级分类ID字段并更新数据库表结构

- 在 CmsProductCategory 实体中新增 parentId 字段,表示上级分类ID,默认为0表示顶级
- 在 CmsProductCategoryParam 参数类中新增 parentId 查询字段,支持查询上级分类
- 修改 cms_product_category 表,新增 parent_id 字段,默认为0并创建索引
- 添加兼容已有数据库的 parent_id 补齐注释和索引说明
This commit is contained in:
2026-07-22 19:18:30 +08:00
parent fe502fb030
commit fedaa4a3ef
3 changed files with 13 additions and 1 deletions

View File

@@ -31,6 +31,9 @@ public class CmsProductCategory implements Serializable {
@TableId(value = "category_id", type = IdType.AUTO)
private Integer categoryId;
@Schema(description = "上级分类ID, 0=顶级")
private Integer parentId;
@Schema(description = "分类名称")
private String categoryName;

View File

@@ -23,6 +23,10 @@ public class CmsProductCategoryParam extends BaseParam {
@QueryField(type = QueryType.EQ)
private Integer categoryId;
@Schema(description = "上级分类ID, 0=顶级")
@QueryField(type = QueryType.EQ)
private Integer parentId;
@Schema(description = "分类名称")
@QueryField(type = QueryType.LIKE)
private String categoryName;

View File

@@ -4,6 +4,7 @@
-- ----------------------------
CREATE TABLE IF NOT EXISTS `cms_product_category` (
`category_id` INT NOT NULL AUTO_INCREMENT COMMENT '分类ID',
`parent_id` INT NOT NULL DEFAULT 0 COMMENT '上级分类ID, 0=顶级',
`category_name` VARCHAR(100) NOT NULL COMMENT '分类名称',
`status` TINYINT NOT NULL DEFAULT 1 COMMENT '状态: 1启用 0禁用',
`sort_number` INT NOT NULL DEFAULT 0 COMMENT '排序(数字越小越靠前)',
@@ -12,9 +13,13 @@ CREATE TABLE IF NOT EXISTS `cms_product_category` (
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`category_id`),
KEY `idx_tenant_id` (`tenant_id`)
KEY `idx_tenant_id` (`tenant_id`),
KEY `idx_parent_id` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='产品分类';
-- 兼容已有库:补齐 parent_id 列(已存在则忽略)
-- ALTER TABLE `cms_product_category` ADD COLUMN `parent_id` INT NOT NULL DEFAULT 0 COMMENT '上级分类ID, 0=顶级' AFTER `category_id`, ADD KEY `idx_parent_id` (`parent_id`);
-- ----------------------------
-- 产品表
-- 官网展示的云产品