From fedaa4a3efcf2d9356d477900cef992ef49c35c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Wed, 22 Jul 2026 19:18:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(category):=20=E6=B7=BB=E5=8A=A0=E4=B8=8A?= =?UTF-8?q?=E7=BA=A7=E5=88=86=E7=B1=BBID=E5=AD=97=E6=AE=B5=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE=E5=BA=93=E8=A1=A8=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 CmsProductCategory 实体中新增 parentId 字段,表示上级分类ID,默认为0表示顶级 - 在 CmsProductCategoryParam 参数类中新增 parentId 查询字段,支持查询上级分类 - 修改 cms_product_category 表,新增 parent_id 字段,默认为0并创建索引 - 添加兼容已有数据库的 parent_id 补齐注释和索引说明 --- .../java/com/gxwebsoft/cms/entity/CmsProductCategory.java | 3 +++ .../com/gxwebsoft/cms/param/CmsProductCategoryParam.java | 4 ++++ src/main/java/com/gxwebsoft/cms/sql/cms_new_modules.sql | 7 ++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gxwebsoft/cms/entity/CmsProductCategory.java b/src/main/java/com/gxwebsoft/cms/entity/CmsProductCategory.java index 5006a96..9d7b494 100644 --- a/src/main/java/com/gxwebsoft/cms/entity/CmsProductCategory.java +++ b/src/main/java/com/gxwebsoft/cms/entity/CmsProductCategory.java @@ -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; diff --git a/src/main/java/com/gxwebsoft/cms/param/CmsProductCategoryParam.java b/src/main/java/com/gxwebsoft/cms/param/CmsProductCategoryParam.java index 5130866..e379bec 100644 --- a/src/main/java/com/gxwebsoft/cms/param/CmsProductCategoryParam.java +++ b/src/main/java/com/gxwebsoft/cms/param/CmsProductCategoryParam.java @@ -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; diff --git a/src/main/java/com/gxwebsoft/cms/sql/cms_new_modules.sql b/src/main/java/com/gxwebsoft/cms/sql/cms_new_modules.sql index 1d2f254..0f0e2cd 100644 --- a/src/main/java/com/gxwebsoft/cms/sql/cms_new_modules.sql +++ b/src/main/java/com/gxwebsoft/cms/sql/cms_new_modules.sql @@ -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`); + -- ---------------------------- -- 产品表 -- 官网展示的云产品