spa/database/spa_system_config.sql

119 lines
4.4 KiB
SQL

-- ============================================
-- SPA管理系统 - 系统配置SQL
-- ============================================
-- 版本: v1.0
-- 创建时间: 2025-12-30
-- 数据库: MySQL 8.0+
-- 字符集: utf8mb4
-- ============================================
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ============================================
-- 系统配置相关表
-- ============================================
-- 1. 系统配置表
DROP TABLE IF EXISTS `spa_system_config`;
CREATE TABLE `spa_system_config` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime(3) DEFAULT NULL,
`updated_at` datetime(3) DEFAULT NULL,
`config_key` varchar(100) NOT NULL COMMENT '配置键',
`config_value` text COMMENT '配置值',
`config_type` varchar(50) DEFAULT 'string' COMMENT '配置类型 string/number/boolean/json',
`config_group` varchar(50) DEFAULT 'system' COMMENT '配置分组',
`name` varchar(100) NOT NULL COMMENT '配置名称',
`description` varchar(500) DEFAULT NULL COMMENT '配置说明',
`is_public` tinyint DEFAULT 0 COMMENT '是否公开 0否 1是',
`sort` int DEFAULT 0 COMMENT '排序',
PRIMARY KEY (`id`),
UNIQUE KEY `idx_config_key` (`config_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统配置表';
-- 2. 数据字典表
DROP TABLE IF EXISTS `spa_dictionary`;
CREATE TABLE `spa_dictionary` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime(3) DEFAULT NULL,
`updated_at` datetime(3) DEFAULT NULL,
`deleted_at` datetime(3) DEFAULT NULL,
`dict_type` varchar(50) NOT NULL COMMENT '字典类型',
`dict_label` varchar(100) NOT NULL COMMENT '字典标签',
`dict_value` varchar(100) NOT NULL COMMENT '字典值',
`parent_id` bigint unsigned DEFAULT 0 COMMENT '父级ID',
`sort` int DEFAULT 0 COMMENT '排序',
`status` tinyint DEFAULT 1 COMMENT '状态 1启用 2停用',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`id`),
KEY `idx_dict_type` (`dict_type`),
KEY `idx_deleted_at` (`deleted_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='数据字典表';
-- 3. 操作日志表
DROP TABLE IF EXISTS `spa_operation_log`;
CREATE TABLE `spa_operation_log` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime(3) DEFAULT NULL,
`user_id` bigint unsigned DEFAULT NULL COMMENT '操作用户ID',
`user_name` varchar(100) DEFAULT NULL COMMENT '操作用户名',
`user_type` tinyint DEFAULT NULL COMMENT '用户类型 1管理员 2技师 3客户',
`module` varchar(50) DEFAULT NULL COMMENT '操作模块',
`operation` varchar(100) DEFAULT NULL COMMENT '操作类型',
`method` varchar(200) DEFAULT NULL COMMENT '请求方法',
`request_url` varchar(500) DEFAULT NULL COMMENT '请求URL',
`request_params` text COMMENT '请求参数',
`response_data` text COMMENT '响应数据',
`ip` varchar(50) DEFAULT NULL COMMENT 'IP地址',
`location` varchar(200) DEFAULT NULL COMMENT 'IP归属地',
`user_agent` varchar(500) DEFAULT NULL COMMENT '用户代理',
`status` tinyint DEFAULT 1 COMMENT '状态 1成功 2失败',
`error_msg` text COMMENT '错误信息',
`cost_time` int DEFAULT NULL COMMENT '耗时(毫秒)',
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='操作日志表';
-- 4. 消息通知表
DROP TABLE IF EXISTS `spa_notification`;
CREATE TABLE `spa_notification` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime(3) DEFAULT NULL,
`updated_at` datetime(3) DEFAULT NULL,
`deleted_at` datetime(3) DEFAULT NULL,
`user_type` tinyint NOT NULL COMMENT '接收用户类型 1客户 2技师 3代理',
`user_id` bigint unsigned NOT NULL COMMENT '接收用户ID',
`title` varchar(200) NOT NULL COMMENT '通知标题',
`content` text COMMENT '通知内容',
`notification_type` tinyint NOT NULL COMMENT '通知类型 1系统 2订单 3分佣 4活动',
`related_id` bigint unsigned DEFAULT NULL COMMENT '关联业务ID',
`related_type` varchar(50) DEFAULT NULL COMMENT '关联业务类型',
`is_read` tinyint DEFAULT 0 COMMENT '是否已读 0否 1是',
`read_time` datetime DEFAULT NULL COMMENT '阅读时间',
PRIMARY KEY (`id`),
KEY `idx_user` (`user_type`, `user_id`),
KEY `idx_deleted_at` (`deleted_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='消息通知表';
SET FOREIGN_KEY_CHECKS = 1;