Files
TaoTaoWang_backend/doc/数据库关系图.md
qingfeng1121 5aa2017eef feat: 初始化后端项目基础架构
添加项目基础配置文件和目录结构
实现用户、角色、权限等核心模块的实体类、Mapper接口和服务层
配置数据库连接和MyBatis-Plus支持
添加统一响应格式和异常处理机制
2025-11-24 15:02:19 +08:00

268 lines
6.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 数据库关系图
下面使用Mermaid语法生成的数据库实体关系图ER图展示了系统中各个表之间的关联关系
```mermaid
erDiagram
%% 用户相关表
users ||--o{ user_details : has
users ||--o{ shops : owns
users ||--o{ orders : places
users ||--o{ payments : makes
users ||--o{ refunds : requests
users ||--o{ shop_ratings : writes
users ||--o{ user_roles : assigned_to
%% 权限相关表
roles ||--o{ user_roles : has
roles ||--o{ role_permissions : contains
permissions ||--o{ role_permissions : included_in
%% 店铺相关表
shops ||--o{ products : sells
shops ||--o{ orders : receives
shops ||--o{ refunds : processes
shops ||--o{ shop_ratings : receives
shop_categories ||--o{ shops : categorizes
shop_categories }o--|| shop_categories : parent
%% 商品相关表
products ||--o{ product_images : has
products ||--o{ product_skus : contains
products ||--o{ product_attribute_values : has
products ||--o{ order_items : included_in
product_categories ||--o{ products : categorizes
product_categories }o--|| product_categories : parent
product_categories ||--o{ product_attributes : defines
product_attributes ||--o{ product_attribute_values : has
product_skus ||--o{ product_inventories : manages
product_skus ||--o{ order_items : selected_in
%% 订单相关表
orders ||--o{ order_items : contains
orders ||--o{ order_status_history : tracks
orders ||--o{ payments : related_to
orders ||--o{ refunds : triggers
orders ||--o{ shop_ratings : based_on
%% 支付与退款相关表
payments ||--o{ refunds : reversed_by
order_items ||--o{ refunds : includes
%% 表定义
users {
BIGINT id PK
VARCHAR username
VARCHAR password
VARCHAR email
VARCHAR phone
INTEGER status
}
user_details {
BIGINT id PK
BIGINT userId FK
VARCHAR realName
VARCHAR idCard
INTEGER gender
}
roles {
BIGINT id PK
VARCHAR roleName
INTEGER roleType
INTEGER status
}
permissions {
BIGINT id PK
VARCHAR permissionName
VARCHAR permissionCode
INTEGER status
}
user_roles {
BIGINT id PK
BIGINT userId FK
BIGINT roleId FK
}
role_permissions {
BIGINT id PK
BIGINT roleId FK
BIGINT permissionId FK
}
shops {
BIGINT id PK
VARCHAR shopName
BIGINT userId FK
BIGINT categoryId FK
INTEGER status
}
shop_categories {
BIGINT id PK
VARCHAR categoryName
BIGINT parentId FK
INTEGER level
INTEGER status
}
products {
BIGINT id PK
VARCHAR productName
BIGINT shopId FK
BIGINT categoryId FK
DECIMAL price
INTEGER stock
INTEGER status
}
product_categories {
BIGINT id PK
VARCHAR categoryName
BIGINT parentId FK
INTEGER level
INTEGER status
}
product_attributes {
BIGINT id PK
VARCHAR attributeName
BIGINT categoryId FK
INTEGER attributeType
INTEGER status
}
product_attribute_values {
BIGINT id PK
BIGINT productId FK
BIGINT attributeId FK
VARCHAR attributeValue
}
product_images {
BIGINT id PK
BIGINT productId FK
VARCHAR imageUrl
INTEGER isMain
}
product_skus {
BIGINT id PK
BIGINT productId FK
VARCHAR skuCode
DECIMAL price
INTEGER stock
INTEGER status
}
product_inventories {
BIGINT id PK
BIGINT skuId FK
INTEGER currentStock
INTEGER safetyStock
INTEGER lockStock
}
orders {
BIGINT id PK
VARCHAR orderNo
BIGINT userId FK
BIGINT shopId FK
DECIMAL totalAmount
INTEGER orderStatus
}
order_items {
BIGINT id PK
BIGINT orderId FK
BIGINT productId FK
BIGINT skuId FK
DECIMAL price
INTEGER quantity
INTEGER itemStatus
}
order_status_history {
BIGINT id PK
BIGINT orderId FK
INTEGER previousStatus
INTEGER currentStatus
}
payments {
BIGINT id PK
VARCHAR paymentNo
BIGINT orderId FK
BIGINT userId FK
DECIMAL amount
INTEGER paymentStatus
}
refunds {
BIGINT id PK
VARCHAR refundNo
BIGINT orderId FK
BIGINT orderItemId FK
BIGINT userId FK
BIGINT shopId FK
DECIMAL refundAmount
INTEGER refundStatus
}
shop_ratings {
BIGINT id PK
BIGINT shopId FK
BIGINT userId FK
BIGINT orderId FK
INTEGER rating
INTEGER status
}
```
## 关系说明
### 一对一关系
- **users 和 user_details**:每个用户只有一个详细信息记录
### 一对多关系
- **users 和 shops**:一个用户可以创建多个店铺
- **shops 和 products**:一个店铺可以有多个商品
- **users 和 orders**:一个用户可以有多个订单
- **shops 和 orders**:一个店铺可以有多个订单
- **orders 和 order_items**:一个订单可以包含多个商品项
- **products 和 product_images**:一个商品可以有多个图片
- **products 和 product_skus**一个商品可以有多个SKU
- **product_skus 和 product_inventories**一个SKU对应一个库存记录
- **orders 和 order_status_history**:一个订单可以有多个状态历史记录
- **orders 和 payments**:一个订单可以有多个支付记录
- **orders 和 refunds**:一个订单可以有多个退款记录
- **order_items 和 refunds**:一个订单项可以有多个退款记录
- **shops 和 shop_ratings**:一个店铺可以有多个评价
- **users 和 shop_ratings**:一个用户可以对多个店铺进行评价
- **orders 和 shop_ratings**:一个订单对应一个店铺评价
### 多对多关系
- **users 和 roles**通过user_roles表关联
- **roles 和 permissions**通过role_permissions表关联
### 自关联关系
- **shop_categories 和 shop_categories**:店铺分类的父子关系
- **product_categories 和 product_categories**:商品分类的父子关系
## 查看方法
要查看此关系图可以使用支持Mermaid语法的工具或编辑器例如
1. **在线工具**
- [Mermaid Live Editor](https://mermaid.live/)
- [Markdown Preview Enhanced](https://shd101wyy.github.io/markdown-preview-enhanced/#/)
2. **IDE插件**
- VS Code的Markdown Preview Enhanced插件
- IntelliJ IDEA的Mermaid插件
3. **版本控制系统**
- GitHub、GitLab等平台已支持Mermaid语法渲染