数据库设计
用户表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 用户ID,主键自增 |
username | varchar(30), not null unique | 用户名,不可为空且唯一 |
email | varchar(30), not null unique | 邮箱,不可为空且唯一 |
password | varchar(30), not null | 密码,不可为空 |
gender | tinyint, default 3 | 性别,1-男,2-女,3-保密 |
id_card | varchar(30), not null | 身份证号,不能为空 |
phone | varchar(30), not null | 手机号,不能为空 |
avatar_url | varchar(255) | 用户头像URL,使用默认头像 |
role_id | bigint, default 1 | 角色ID,默认为1,1-普通用户,0-管理员,与角色表关联 |
receipt_name | varchar(30), default null | 收货人名称 |
receipt_id | bigint, default null | 收货地址ID,与地址表关联 |
profile | varchar(255), default null | 个人简介,默认为空 |
status | tinyint, default 0 | 账号状态,0-正常使用/未销户,1-已销户 |
ban_flag | tinyint, default 0 | 禁言标记,0-未禁言,1-已禁言 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除,默认为0 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
地址表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 地址ID,主键自增 |
address_text | varchar(255), not null | 地址名称,不为空且唯一 |
latitude | varchar(255), not null | 纬度值,不为空。填写时先写入纬度 |
longitude | varchar(255), not null | 经度值,不为空。填写时后写入经度 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除,默认为0 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
商品总表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 商品ID,主键自增 |
identifier | varchar(255), unique not null | 商品编号,唯一 |
name | varchar(50), not null | 商品名称,不为空 |
description | varchar(2048), not null | 商品描述,不为空 |
type | bigint, not null | 商品类型,1-宠物,2-宠物用品 |
ship_id | bigint, not null | 发货地址ID,不可为空,与地址表关联 |
main_category_id | bigint, not null | 商品分类ID,不可为空,与商品一级分类表关联 |
sub_category_id | bigint, not null | 商品分类ID,不可为空,与商品二级分类表关联 |
price | decimal(10, 2), not null | 商品价格 |
stock | bigint, default 1 | 库存数量,默认为1 |
status | tinyint, default 1 | 商品状态,1-出售中,2-售罄,3-已下架 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除,默认为0 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
宠物子表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 宠物ID,主键自增 |
product_id | bigint, unique not null | 商品ID,不为空且唯一,与商品总表关联 |
variety | varchar(50), not null | 宠物品种 |
health_status | tinyint, default 1 | 宠物健康状态,1-健康,2-良好,3-治疗中 |
train_note | varchar(255) | 驯养须知 |
raise_note | varchar(255) | 领养须知 |
vaccine_flag | tinyint, default 1 | 是否接种疫苗,0-未接种,1-已接种 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
宠物用品子表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 宠物用品ID,主键自增 |
product_id | bigint, unique not null | 商品ID,不为空且唯一,与商品总表关联 |
brand | varchar(50) | 宠物用品品牌 |
fit_age | varchar(255) | 适用年龄段 |
fit_variety | varchar(255) | 适用品种 |
manufacture_date | datetime, not null | 生产日期 |
guarantee_date | datetime, not null | 保质期 |
company | varchar(255) | 生产公司 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
商品图片表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 图片ID,主键自增 |
product_id | bigint, not null | 商品ID,关联商品总表 |
image_url | varchar(1024), not null | 图片地址(先用本地的地址,再考虑转为阿里云OSS) |
main_flag | tinyint, default 0 | 是否为主图,0-否,1-是,默认为0 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除,默认为0 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
商品一级分类表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 图片ID,主键自增 |
name | varchar(50), not null | 分类名称,代码控制不重复 |
type | tinyint, not null | 商品分类类型,1-宠物分类,2-宠物用品分类 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
商品二级分类表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 图片ID,主键自增 |
main_category_id | bigint, not null | 商品一级分类ID,与一级分类表关联 |
name | varchar(50), not null | 分类名称,在代码中对这个字段进行同一一级分类下重复性校验 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
帖子表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 帖子ID,主键自增 |
user_id | bigint, not null | 发帖人ID,不为空 |
column_id | bigint, not null | 栏目ID,不为空 |
title | varchar(50), not null | 帖子标题(目前不做重复校验) |
content | varchar(2048) | 帖子内容(当是视频贴时可以为空) |
status | tinyint, default 1 | 帖子状态,1-草稿,2-审核中,3-审核成功,4-审核失败,默认为1 |
like_count | bigint, default 0 | 点赞数量,默认为0 |
reject_count | bigint, default 0 | 反对数量,默认为0 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
帖子媒体表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 媒体ID,主键自增 |
post_id | bigint, not null | 帖子ID,与帖子表关联 |
media_url | varchar(1024), not null | 媒体地址 |
media_type | tinyint, not null | 媒体类型,1-图片,2-视频 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
帖子点赞表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 收藏ID,主键自增 |
user_id | bigint, not null | 用户ID,不可为空,与用户表关联 |
post_id | bigint, not null | 帖子ID,不可为空,与帖子表关联 |
cancel_flag | tinyint, default 0 | 取消点赞标记,0-未取消,1-已取消 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
帖子点踩表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 收藏ID,主键自增 |
user_id | bigint, not null | 用户ID,不可为空,与用户表关联 |
post_id | bigint, not null | 帖子ID,不可为空,与帖子表关联 |
cancel_flag | tinyint, default 0 | 取消点踩标记,0-未取消,1-已取消 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
帖子收藏表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 收藏ID,主键自增 |
user_id | bigint, not null | 用户ID,不可为空,与用户表关联 |
post_id | bigint, not null | 帖子ID,不可为空,与帖子表关联 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
话题帖子关联表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 关联ID,主键自增 |
post_id | bigint, not null | 帖子ID,不为空 |
topic_id | bigint, not null | 话题ID,不为空 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
话题表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 话题ID,主键自增 |
name | varchar(25), not null | 话题名称,不为空 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
栏目表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 栏目ID,主键自增 |
name | varchar(25), not null | 栏目名称,不为空 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
订单表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 订单ID,主键自增 |
user_id | bigint, not null | 用户ID,不为空 |
product_id | bigint, not null | 商品ID,不为空 |
phone | varchar(30), not null | 额外存储用户手机号(默认从用户表拿到) |
receipt_id | bigint, not null | 收货地址ID,与地址表关联(默认从用户表拿到) |
total_count | bigint, not null | 商品数量 |
total_price | decimal(10, 2), not null | 商品总价 |
status | tinyint, default 1 | 订单状态,1-待支付,2-待发货,3-已发货,4-待签收,5-已收货,6-订单取消 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
退款信息表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 订单ID,主键自增 |
order_id | bigint, not null | 订单ID,不为空 |
user_id | bigint, not null | 用户ID,不为空 |
message | varchar(2048), not null | 退款原因 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
订单物流表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 订单ID,主键自增 |
order_id | bigint, not null | 订单ID,不为空 |
transport_type | tinyint, not null | 物流类型,1-空运,2-陆运。当为空运时,不显示当前路线途经点 |
origin_lat | varchar(255), not null | 起点纬度值,不为空。填写时先写入纬度 |
origin_lng | varchar(255), not null | 起点经度值,不为空。填写时后写入经度 |
dest_lat | varchar(255), not null | 终点纬度值,不为空。填写时先写入纬度 |
dest_lng | varchar(255), not null | 终点经度值,不为空。填写时后写入经度 |
curr_lat | varchar(255) | 当前位置纬度值,不为空。填写时先写入纬度 |
curr_lng | varchar(255) | 当前位置经度值,不为空。填写时后写入经度 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
购物车表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 购物车ID,主键自增 |
user_id | bigint, not null | 用户ID,不为空 |
product_id | bigint, not null | 商品ID,不为空 |
total_count | bigint, not null | 商品数量 |
total_price | decimal(10, 2), not null | 商品总价 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除,默认为0 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
消息表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 消息ID,主键自增 |
receive_user_id | bigint, not null | 接收消息的用户ID |
send_user_id | bigint, not null | 发送消息的用户ID |
message | varchar(2048), not null | 消息内容 |
type | tinyint, not null | 消息类型,1-系统消息,2-聊天消息,3-商品卡片消息,4-订单卡片消息,5-媒体消息 |
status | tinyint, default 0 | 是否已读标记,0-未读,1-已读,默认为0 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除,默认为0 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
消息媒体表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 媒体ID,主键自增 |
message_id | bigint, not null | 消息ID,与消息表关联 |
media_url | varchar(1024), not null | 媒体地址 |
media_type | tinyint, not null | 媒体类型,1-图片,2-视频 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
最近消息表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 最近消息ID,主键自增 |
user_id | bigint, not null | 用户ID,与用户表关联 |
message_id | bigint, not null | 消息ID,与消息表关联 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
通知表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 通知ID,主键自增 |
receive_user_id | bigint, not null | 接收消息的用户ID |
title | varchar(50), not null | 通知标题 |
content | varchar(2048), not null | 通知内容 |
status | tinyint, default 0 | 是否已读标记,0-未读,1-已读,默认为0 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除,默认为0 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
评论总表/帖子评论表
Note
当前系统中,帖子评论字段和评论总表字段一致,帖子评论暂时不单独创建表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 评论ID,主键自增 |
object_id | bigint, not null | 评论对象ID,不为空,与商品表或帖子表关联 |
user_id | bigint, not null | 评论人ID,不为空,与用户表关联 |
parent_id | bigint, default null | 父级评论ID,默认为顶级评论 |
type | tinyint, not null | 评论类型,不为空,1-商品评论,2-帖子评论 |
content | varchar(2048), not null | 评论内容,不为空 |
status | tinyint, default 0 | 隐藏状态,0-未隐藏,1-已隐藏 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除,默认为0 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
商品评论子表
| 字段名 | 类型与约束 | 备注 |
sub_id | bigint, primary key auto_increment | 商品评论ID,主键自增 |
comment_id | bigint, not null | 评论总表ID,与评论总表关联 |
stars | bigint, default 5 | 商品评价等级,默认为5颗星 |
sub_create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
sub_update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
评论媒体表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 媒体ID,主键自增 |
comment_id | bigint, not null | 评论ID,与评论总表关联 |
media_url | varchar(1024), not null | 媒体地址 |
media_type | tinyint, not null | 媒体类型,1-图片,2-视频 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
敏感词表
| 字段名 | 类型与约束 | 备注 |
id | bigint, unique not null | 敏感词ID,唯一且不为空 |
word | varchar(255), unique not null | 敏感词完整内容,不能为空 |
category_id | bigint, not null | 敏感词分类ID |
delete_flag | tinyint, not null | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
敏感词分类表
| 字段名 | 类型与约束 | 备注 |
id | bigint, primary key auto_increment | 图片ID,主键自增 |
name | varchar(50), not null | 分类名称,代码控制不重复 |
delete_flag | tinyint, default 0 | 删除标记,0-未删除,1-已删除 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
角色表
| 字段名 | 类型与约束 | 备注 |
id | bigint, unique not null | 角色ID,唯一且不为空 |
name | varchar(20), unique not null | 角色名称,不能为空 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |
AI对话记忆表
| 字段名 | 类型与约束 | 备注 |
id | bigint, unique not null | 角色ID,唯一且不为空 |
conversation_id | varchar(64), unique not null | 角色名称,不能为空 |
type | tinyint, not null | 对话类型,1-用户消息,2-系统消息,3-助手消息 |
content | text, not null | 对话内容,不能为空 |
timestamp | timestamp, default current_time_stamp | 创建时间,默认为插入时时间戳 |
AI对话元数据表
| 字段名 | 类型与约束 | 备注 |
id | bigint, unique not null | 角色ID,唯一且不为空 |
user_id | bigint, not null | 用户ID,不为空,与用户表关联 |
title | varchar(20), not null | 对话标题,不能为空 |
conversation_id | varchar(64), unique not null | 角色名称,不能为空 |
create_time | datetime, default current_time_stamp | 创建时间,默认为插入时时间戳 |
update_time | datetime, default current_time_stamp on update current_time_stamp | 更新时间,默认为插入时时间戳,插入时自动更新 |