第一阶段数据库表结构设计
1. 管理员表:admin_users
用于后台管理员登录和账户管理。
| 字段 | 类型 | 用途 |
|---|---|---|
| id | BIGINT UNSIGNED | 主键 |
| username | VARCHAR(100) | 登录账号,唯一 |
| password_hash | VARCHAR(255) | 密码哈希 |
| status | TINYINT | 账户状态 |
| last_login_at | DATETIME | 最后登录时间 |
| created_at | DATETIME | 创建时间 |
| updated_at | DATETIME | 更新时间 |
首次安装时创建一个管理员账户,密码通过 password_hash() 加密。
2. 服务商表:providers
用于保存可供系统匹配和推荐的服务商资料。
| 字段 | 类型 | 用途 |
|---|---|---|
| id | BIGINT UNSIGNED | 主键 |
| name | VARCHAR(255) | 服务商名称 |
| introduction | TEXT | 服务商介绍 |
| business_description | TEXT | 业务描述 |
| business_keywords | TEXT | 业务关键词 |
| website | VARCHAR(500) | 官网地址 |
| information_source | TEXT | 信息来源 |
| recommendation_status | TINYINT | 推荐状态 |
| recommendation_priority | INT | 推荐优先级 |
| status | TINYINT | 资料状态 |
| created_at | DATETIME | 创建时间 |
| updated_at | DATETIME | 更新时间 |
不设置固定行业字段,保持服务商资料通用性。
3. 分类目录表:categories
用于管理多级分类。
| 字段 | 类型 | 用途 |
|---|---|---|
| id | BIGINT UNSIGNED | 主键 |
| parent_id | BIGINT UNSIGNED | 父级分类 ID,顶级为 0 |
| name | VARCHAR(255) | 分类名称 |
| description | TEXT | 分类描述 |
| sort_order | INT | 排序值 |
| status | TINYINT | 分类状态 |
| created_at | DATETIME | 创建时间 |
| updated_at | DATETIME | 更新时间 |
通过 parent_id 建立父子关系,不限制固定层级。
4. AI 服务表:ai_services
用于管理多个 AI 服务提供方。
| 字段 | 类型 | 用途 |
|---|---|---|
| id | BIGINT UNSIGNED | 主键 |
| service_name | VARCHAR(255) | 服务名称 |
| provider_name | VARCHAR(255) | 服务提供方 |
| service_type | VARCHAR(100) | 服务类型 |
| endpoint | VARCHAR(500) | 服务地址 |
| api_key | TEXT | 服务认证信息 |
| configuration | TEXT | 其他配置 |
| priority | INT | 调度优先级 |
| is_primary | TINYINT | 是否主用服务 |
| status | TINYINT | 启用状态 |
| created_at | DATETIME | 创建时间 |
| updated_at | DATETIME | 更新时间 |
API 密钥属于敏感配置,后续需要明确存储保护方式,不能在后台页面或日志中明文展示。
5. AI 服务用途表:ai_service_usages
用于配置 AI 服务承担的具体用途。
| 字段 | 类型 | 用途 |
|---|---|---|
| id | BIGINT UNSIGNED | 主键 |
| service_id | BIGINT UNSIGNED | 关联 AI 服务 |
| usage_code | VARCHAR(100) | 用途标识 |
| usage_name | VARCHAR(255) | 用途名称 |
| priority | INT | 用途优先级 |
| is_primary | TINYINT | 是否该用途的主用服务 |
| status | TINYINT | 启用状态 |
| created_at | DATETIME | 创建时间 |
| updated_at | DATETIME | 更新时间 |
初始用途包括:
-
需求语义理解
-
互联网信息搜索
-
推荐结果组织
同一个 AI 服务可以承担多个用途,不同 AI 服务也可以承担同一个用途。
6. 系统配置表:system_configs
用于保存系统级配置。
| 字段 | 类型 | 用途 |
|---|---|---|
| id | BIGINT UNSIGNED | 主键 |
| config_key | VARCHAR(150) | 配置键,唯一 |
| config_value | TEXT | 配置值 |
| config_description | VARCHAR(500) | 配置说明 |
| updated_at | DATETIME | 更新时间 |
二、表之间的关系
#chatgpt-mermaid-_r_14q_{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:16px;fill:rgb(13, 13, 13);}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#chatgpt-mermaid-_r_14q_ .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#chatgpt-mermaid-_r_14q_ .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#chatgpt-mermaid-_r_14q_ .error-icon{fill:rgb(243, 243, 243);}#chatgpt-mermaid-_r_14q_ .error-text{fill:rgb(13, 13, 13);stroke:rgb(13, 13, 13);}#chatgpt-mermaid-_r_14q_ .edge-thickness-normal{stroke-width:1px;}#chatgpt-mermaid-_r_14q_ .edge-thickness-thick{stroke-width:3.5px;}#chatgpt-mermaid-_r_14q_ .edge-pattern-solid{stroke-dasharray:0;}#chatgpt-mermaid-_r_14q_ .edge-thickness-invisible{stroke-width:0;fill:none;}#chatgpt-mermaid-_r_14q_ .edge-pattern-dashed{stroke-dasharray:3;}#chatgpt-mermaid-_r_14q_ .edge-pattern-dotted{stroke-dasharray:2;}#chatgpt-mermaid-_r_14q_ .marker{fill:rgb(143, 143, 143);stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_14q_ .marker.cross{stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_14q_ svg{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:16px;}#chatgpt-mermaid-_r_14q_ p{margin:0;}#chatgpt-mermaid-_r_14q_ .entityBox{fill:rgb(222, 234, 251);stroke:rgb(83, 154, 248);}#chatgpt-mermaid-_r_14q_ .relationshipLabelBox{fill:rgb(243, 243, 243);opacity:0.7;background-color:rgb(243, 243, 243);}#chatgpt-mermaid-_r_14q_ .relationshipLabelBox rect{opacity:0.5;}#chatgpt-mermaid-_r_14q_ .labelBkg{background-color:rgba(243, 243, 243, 0.5);}#chatgpt-mermaid-_r_14q_ .edgeLabel{background-color:rgb(252, 252, 252);}#chatgpt-mermaid-_r_14q_ .edgeLabel .label rect{fill:rgb(252, 252, 252);}#chatgpt-mermaid-_r_14q_ .edgeLabel .label text{fill:rgb(13, 13, 13);}#chatgpt-mermaid-_r_14q_ .edgeLabel .label{fill:rgb(83, 154, 248);font-size:14px;}#chatgpt-mermaid-_r_14q_ .label{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_14q_ .edge-pattern-dashed{stroke-dasharray:8,8;}#chatgpt-mermaid-_r_14q_ .node rect,#chatgpt-mermaid-_r_14q_ .node circle,#chatgpt-mermaid-_r_14q_ .node ellipse,#chatgpt-mermaid-_r_14q_ .node polygon{fill:rgb(222, 234, 251);stroke:rgb(83, 154, 248);stroke-width:1px;}#chatgpt-mermaid-_r_14q_ .relationshipLine{stroke:rgb(143, 143, 143);stroke-width:1px;fill:none;}#chatgpt-mermaid-_r_14q_ .marker{fill:none!important;stroke:rgb(143, 143, 143)!important;stroke-width:1;}#chatgpt-mermaid-_r_14q_ [data-look=neo].labelBkg{background-color:rgba(243, 243, 243, 0.5);}#chatgpt-mermaid-_r_14q_ .node .neo-node{stroke:rgb(83, 154, 248);}#chatgpt-mermaid-_r_14q_ [data-look=”neo”].node rect,#chatgpt-mermaid-_r_14q_ [data-look=”neo”].cluster rect,#chatgpt-mermaid-_r_14q_ [data-look=”neo”].node polygon{stroke:url(#chatgpt-mermaid-_r_14q_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_14q_ [data-look=”neo”].swimlane.cluster rect{filter:none;}#chatgpt-mermaid-_r_14q_ [data-look=”neo”].node path{stroke:url(#chatgpt-mermaid-_r_14q_-gradient);stroke-width:1px;}#chatgpt-mermaid-_r_14q_ [data-look=”neo”].node .outer-path{filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_14q_ [data-look=”neo”].node .neo-line path{stroke:rgb(83, 154, 248);filter:none;}#chatgpt-mermaid-_r_14q_ [data-look=”neo”].node circle{stroke:url(#chatgpt-mermaid-_r_14q_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_14q_ [data-look=”neo”].node circle .state-start{fill:#000000;}#chatgpt-mermaid-_r_14q_ [data-look=”neo”].icon-shape .icon{fill:url(#chatgpt-mermaid-_r_14q_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_14q_ [data-look=”neo”].icon-shape .icon-neo path{stroke:url(#chatgpt-mermaid-_r_14q_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_14q_ :root{–mermaid-font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;}ADMIN_USERSbigintidPKvarcharusernameUKvarcharpassword_hashPROVIDERSbigintidPKvarcharnametextbusiness_keywordsCATEGORIESbigintidPKbigintparent_idvarcharnameAI_SERVICESbigintidPKvarcharservice_namevarcharprovider_nameAI_SERVICE_USAGESbigintidPKbigintservice_idFKvarcharusage_codeSYSTEM_CONFIGSbigintidPKvarcharconfig_keyUKtextconfig_valueprovidesparent_child
三、需要特别明确的设计边界
-
服务商分类关联:当前规划没有明确服务商是否必须关联一个或多个分类,因此暂不擅自增加关联表。
-
AI 密钥保护:需要在实现时确定加密和读取方式。
-
AI 服务用途:需要支持同一用途配置多个服务,并明确主用服务与备用服务的调度规则。
-
系统日志:继续使用现有文件日志,不纳入本次数据库建表范围。