-- ./product_category.json -- 建库时请用以下语句,支持emoji字符 -- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; drop table if exists product_category; CREATE TABLE product_category ( `id` VARCHAR(32) NOT NULL comment '主键ID', `parent_id` VARCHAR(32) DEFAULT '0' comment '父类别ID', `name` VARCHAR(255) NOT NULL comment '类别名称', `description` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '类别描述', `has_product` CHAR(1) DEFAULT '0' comment '是否可挂产品', `product_type` VARCHAR(64) comment '产品类型标识', `product_type_title` VARCHAR(255) comment '产品类型显示名', `sort_order` int DEFAULT '0' comment '排序序号', `icon` VARCHAR(255) comment '图标', `status` CHAR(1) DEFAULT '1' comment '状态', `org_id` VARCHAR(32) DEFAULT '0' comment '所属机构ID', `created_by` VARCHAR(32) comment '创建人', `created_at` datetime NOT NULL comment '创建时间', `updated_at` datetime NOT NULL comment '更新时间' ,primary key(id) ) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci engine=innodb comment '产品类别树' ; CREATE INDEX product_category_idx_pc_org_parent ON product_category(org_id,parent_id); CREATE INDEX product_category_idx_pc_org_status ON product_category(org_id,status); CREATE INDEX product_category_idx_pc_org_type ON product_category(org_id,product_type); -- ./product.json -- 建库时请用以下语句,支持emoji字符 -- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; drop table if exists product; CREATE TABLE product ( `id` VARCHAR(32) NOT NULL comment '主键ID', `category_id` VARCHAR(32) NOT NULL comment '类别ID', `product_code` VARCHAR(64) NOT NULL comment '产品编码', `product_name` VARCHAR(255) NOT NULL comment '产品名称', `product_type` VARCHAR(64) NOT NULL comment '产品类型标识', `brief_intro` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '产品简介', `detail_intro` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '产品详情', `extra_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '扩展属性', `enabled_date` date comment '启用日期', `expired_date` date comment '失效日期', `status` CHAR(1) DEFAULT '1' comment '状态', `price_type` CHAR(1) DEFAULT '1' comment '价格类型', `price` double(15,2) DEFAULT '0.00' comment '价格', `currency` CHAR(8) DEFAULT 'CNY' comment '货币', `sort_order` int DEFAULT '0' comment '排序序号', `org_id` VARCHAR(32) DEFAULT '0' comment '所属机构ID', `created_by` VARCHAR(32) comment '创建人', `created_at` datetime NOT NULL comment '创建时间', `updated_at` datetime NOT NULL comment '更新时间' ,primary key(id) ) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci engine=innodb comment '产品注册表' ; CREATE INDEX product_idx_product_org_category ON product(org_id,category_id); CREATE UNIQUE INDEX product_idx_product_org_code ON product(org_id,product_code); CREATE INDEX product_idx_product_org_type ON product(org_id,product_type); CREATE INDEX product_idx_product_status ON product(status); CREATE INDEX product_idx_product_enabled_expired ON product(enabled_date,expired_date); -- ./product_type_config.json -- 建库时请用以下语句,支持emoji字符 -- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; drop table if exists product_type_config; CREATE TABLE product_type_config ( `id` VARCHAR(32) NOT NULL comment '主键ID', `operator_id` VARCHAR(32) NOT NULL comment '运营商用户ID', `org_id` VARCHAR(32) NOT NULL comment '所属机构ID', `category_id` VARCHAR(32) NOT NULL comment '产品类别ID', `config_name` VARCHAR(255) NOT NULL comment '配置名称', `config_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '配置内容', `enabled_flg` CHAR(1) DEFAULT '1' comment '是否启用', `created_by` VARCHAR(32) comment '创建人', `created_at` datetime NOT NULL comment '创建时间', `updated_at` datetime NOT NULL comment '更新时间' ,primary key(id) ) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci engine=innodb comment '运营商产品类型配置' ; CREATE INDEX product_type_config_idx_ptc_org_opr ON product_type_config(org_id,operator_id); CREATE UNIQUE INDEX product_type_config_idx_ptc_org_cat ON product_type_config(org_id,operator_id,category_id,config_name); CREATE INDEX product_type_config_idx_ptc_enabled ON product_type_config(enabled_flg); -- ./product_resource.json drop table if exists product_resource; CREATE TABLE product_resource ( `id` VARCHAR(32) NOT NULL comment '主键ID', `product_id` VARCHAR(32) NOT NULL comment '产品ID', `resource_type` VARCHAR(32) NOT NULL comment '资源类型', `resource_ref_id` VARCHAR(32) NOT NULL comment '资源引用ID', `resource_ref_name` VARCHAR(255) comment '资源显示名', `quota` double(15,4) DEFAULT '0' comment '配额量', `quota_unit` VARCHAR(32) comment '配额单位', `priority` int DEFAULT '1' comment '优先级', `overflow_product_id` VARCHAR(32) comment '超额后转用产品ID', `status` CHAR(1) DEFAULT '1' comment '状态', `created_at` datetime NOT NULL comment '创建时间', `updated_at` datetime comment '更新时间' ,primary key(id) ) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci engine=innodb comment '产品资源绑定表' ; CREATE INDEX product_resource_idx_pr_product ON product_resource(product_id); CREATE INDEX product_resource_idx_pr_resource ON product_resource(resource_type,resource_ref_id); CREATE INDEX product_resource_idx_pr_status ON product_resource(status); -- ./product_resource_supplier.json drop table if exists product_resource_supplier; CREATE TABLE product_resource_supplier ( `id` VARCHAR(32) NOT NULL comment '主键ID', `product_resource_id` VARCHAR(32) NOT NULL comment '产品资源绑定ID', `supplier_org_id` VARCHAR(32) NOT NULL comment '供应商机构ID', `priority` int DEFAULT '1' comment '优先级', `weight` int DEFAULT '100' comment '权重', `status` CHAR(1) DEFAULT '1' comment '状态', `created_at` datetime NOT NULL comment '创建时间' ,primary key(id) ) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci engine=innodb comment '产品资源供应商关联表' ; CREATE INDEX product_resource_supplier_idx_prs_resource ON product_resource_supplier(product_resource_id); CREATE INDEX product_resource_supplier_idx_prs_supplier ON product_resource_supplier(supplier_org_id); CREATE UNIQUE INDEX product_resource_supplier_idx_prs_unique ON product_resource_supplier(product_resource_id,supplier_org_id); -- ./product_subscription.json drop table if exists product_subscription; CREATE TABLE product_subscription ( `id` VARCHAR(32) NOT NULL comment '主键ID', `product_id` VARCHAR(32) NOT NULL comment '产品ID', `user_id` VARCHAR(32) NOT NULL comment '客户用户ID', `user_org_id` VARCHAR(32) NOT NULL comment '客户机构ID', `subscription_type` CHAR(1) NOT NULL comment '订购类型', `status` CHAR(1) NOT NULL DEFAULT '1' comment '状态', `start_date` date NOT NULL comment '生效日期', `end_date` date NOT NULL comment '到期日期', `quota_total` double(15,4) DEFAULT '0' comment '总配额', `quota_used` double(15,4) DEFAULT '0' comment '已使用量', `quota_unit` VARCHAR(32) comment '配额单位', `overflow_mode` CHAR(1) DEFAULT '1' comment '超额模式', `overflow_rate` double(15,6) DEFAULT '0' comment '超额单价', `purchase_price` double(15,2) DEFAULT '0' comment '购买价格', `purchase_currency` CHAR(8) DEFAULT 'CNY' comment '货币', `created_at` datetime NOT NULL comment '创建时间', `updated_at` datetime comment '更新时间' ,primary key(id) ) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci engine=innodb comment '客户订购表' ; CREATE INDEX product_subscription_idx_ps_product ON product_subscription(product_id); CREATE INDEX product_subscription_idx_ps_user ON product_subscription(user_id,user_org_id); CREATE INDEX product_subscription_idx_ps_status ON product_subscription(status); CREATE INDEX product_subscription_idx_ps_dates ON product_subscription(start_date,end_date); -- ./product_usage_log.json drop table if exists product_usage_log; CREATE TABLE product_usage_log ( `id` VARCHAR(32) NOT NULL comment '主键ID', `product_id` VARCHAR(32) NOT NULL comment '产品ID', `subscription_id` VARCHAR(32) comment '订购ID', `user_id` VARCHAR(32) NOT NULL comment '消费者用户ID', `user_org_id` VARCHAR(32) NOT NULL comment '消费者机构ID', `product_resource_id` VARCHAR(32) comment '产品资源绑定ID', `supplier_org_id` VARCHAR(32) comment '供应商机构ID', `resource_type` VARCHAR(32) comment '资源类型', `resource_ref_id` VARCHAR(32) comment '资源引用ID', `used_amount` double(15,4) NOT NULL comment '消耗量', `used_unit` VARCHAR(32) comment '消耗单位', `unit_cost` double(15,8) DEFAULT '0' comment '单位成本', `total_cost` double(15,6) DEFAULT '0' comment '总成本', `sell_price` double(15,6) DEFAULT '0' comment '客户售价', `billing_mode` CHAR(1) NOT NULL comment '计费模式', `source_ref_table` VARCHAR(64) comment '来源表', `source_ref_id` VARCHAR(32) comment '来源记录ID', `use_time` datetime NOT NULL comment '消费时间', `created_at` datetime NOT NULL comment '创建时间' ,primary key(id) ) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci engine=innodb comment '产品消费记录表' ; CREATE INDEX product_usage_log_idx_pul_product ON product_usage_log(product_id); CREATE INDEX product_usage_log_idx_pul_subscription ON product_usage_log(subscription_id); CREATE INDEX product_usage_log_idx_pul_user ON product_usage_log(user_id,user_org_id); CREATE INDEX product_usage_log_idx_pul_supplier ON product_usage_log(supplier_org_id); CREATE INDEX product_usage_log_idx_pul_time ON product_usage_log(use_time); CREATE INDEX product_usage_log_idx_pul_source ON product_usage_log(source_ref_table,source_ref_id);