SpringBoot微信點餐系統 - 項目設計、數據庫設計

微信點餐系統 - 項目設計


記錄一下二月疫情學的 廖師兄的基於Spring Boot實現的企業微信點餐系統

微信點餐系統

包括需求分析,項目設計,項目架構,數據庫設計等等。

  • 項目設計
  • 架構和基礎框架
  • 數據庫設計

開發流程

  • 項目設計
  • 環境搭建
  • 功能開發
  • 項目優化
  • 部署上線 (應用部署Nginx、Tomcat、Redis、MySQL)
  • (一直單元測試)

1、項目設計

項目設計

  • 角色劃分

  • 功能模塊劃分

  • 部署架構

  • 數據庫設計

角色劃分

角色劃分

買家(手機端) 微信點餐

賣家(PC端)管理

微信點餐系統就買家和賣家

一個瀏覽定吃的(瀏覽、下單、取消、支付、查詢)、一個接單做吃的(商品上下架、接單、查詢、取消、類目刪除)

買家(手機端)

  • 下單
  • 查詢訂單
  • 取消訂單
  • 支付訂單

賣家(PC端)

  • 類目刪除
  • 商品上下架
  • 接單
  • 查詢訂單
  • 取消訂單

功能模塊劃分

在這裏插入圖片描述

功能模塊劃分 - 功能分析

商品的、訂單的、類目的。。。

商品

  • 商品列表

訂單

  • 訂單創建
  • 訂單查詢
  • 訂單取消

類目

  • 訂單管理
  • 商品管理
  • 類目管理

關係圖

在這裏插入圖片描述

微信點餐系統的關係圖

買家

  • 查詢 商品

  • 創建/查詢 訂單

消息

賣家

  • 查詢/接單 訂單

  • 管理商品

消息

消息互相聯繫哦

部署架構

部署架構

在這裏插入圖片描述

分佈式部署

Tomcat 多臺服務器 多個應用

多端 手機微信端 Web端

Nginx

Tomcat

Redist、MySQL

2、架構和基礎框架

微服務 -》Spring Cloud -》Spring Boot

在這裏插入圖片描述

微服務

在這裏插入圖片描述

單一 垂直 分佈式 流動式

在這裏插入圖片描述
架構的演進

微服務 實現

兩大“門派”

  • 阿里系

  • SpringCloud棧

Spring社區

阿里系

  • Dubbo

  • Zookeeper

  • Spring MVC or SpringBoot

Apache Dubbo 服務化治理?
Apache Dubbo™ 是一款高性能Java RPC框架。

Zookeeper https://zookeeper.apache.org/ 註冊中心?

在這裏插入圖片描述

Spring Cloud 棧

  • Spring Cloud
  • Netflix Eureka
  • SpringBoot

https://spring.io/projects/spring-cloud-netflix

微服務 面對 服務化的

演進過程

本身 不受技術框架的束縛 微服務

3、數據庫設計

數據庫設計

  • 表和表之間的關係

  • 建表SQL

  • 注意事項

在這裏插入圖片描述

數據庫 設計 五張

商品表 商品的屬性

類目表

訂單詳情表

賣家信息表

訂單主表

設計我們的數據庫

設計數據庫

自增有上限,設置下字符類型 。

微信點餐的數據庫設計 表設計

商品表

商品表

名稱 product_name 商品名稱

單價 product_price 商品單價

庫存 庫存 product_stock

描述 product_description 商品的描述

圖片 product_icon 商品小圖

類目編號 category_type

商品狀態,0正常1下架 product_status

創建時間 create_time

修改時間 update_time

-- 商品
create table `product_info` (
    `product_id` varchar(32) not null,
    `product_name` varchar(64) not null comment '商品名稱',
    `product_price` decimal(8,2) not null comment '單價',
    `product_stock` int not null comment '庫存',
    `product_description` varchar(64) comment '描述',
    `product_icon` varchar(512) comment '小圖',
    `product_status` tinyint(3) DEFAULT '0' COMMENT '商品狀態,0正常1下架',
    `category_type` int not null comment '類目編號',
    `create_time` timestamp not null default current_timestamp comment '創建時間',
    `update_time` timestamp not null default current_timestamp on update current_timestamp comment '修改時間',
    primary key (`product_id`)
);

簡單說明

主鍵product_id商品的id , primary key (product_id)

create_time timestamp not null default current_timestamp comment ‘創建時間’,
update_time timestamp not null default current_timestamp on update current_timestamp comment ‘修改時間’,

timestamp時間戳

decimal 8 2

這是上線的項目,自增上線是不行的,自增不夠用商品id有上限。

更新的時候自動寫進去

mysql5.7 可以這麼設置

價格8位 加二個小數點

類目表

類目表

名稱 category_name

編號 category

-- 類目
create table `product_category` (
    `category_id` int not null auto_increment,
    `category_name` varchar(64) not null comment '類目名字',
    `category_type` int not null comment '類目編號',
    `create_time` timestamp not null default current_timestamp comment '創建時間',
    `update_time` timestamp not null default current_timestamp on update current_timestamp comment '修改時間',
    primary key (`category_id`),
    UNIQUE KEY `uqe_category_type` (`category_type`)
);

類目沒那多麼多 int 類目名稱 類目編號少的

類目編號 自定義的

查詢性能的優化 約束索引 unique key `` 與商品也有關

訂單表

訂單表

買家名字 buyer_name

買家電話 buyer_phone

買家地址 buyer_address

買家微信id buyer_openid

總金額 order_amount

訂單狀態 order_status

支付狀態 pay_status

常見時間

修改時間

-- 訂單
create table `order_master` (
    `order_id` varchar(32) not null,
    `buyer_name` varchar(32) not null comment '買家名字',
    `buyer_phone` varchar(32) not null comment '買家電話',
    `buyer_address` varchar(128) not null comment '買家地址',
    `buyer_openid` varchar(64) not null comment '買家微信openid',
    `order_amount` decimal(8,2) not null comment '訂單總金額',
    `order_status` tinyint(3) not null default '0' comment '訂單狀態, 默認爲新下單',
    `pay_status` tinyint(3) not null default '0' comment '支付狀態, 默認未支付',
    `create_time` timestamp not null default current_timestamp comment '創建時間',
    `update_time` timestamp not null default current_timestamp on update current_timestamp comment '修改時間',
    primary key (`order_id`),
    key `idx_buyer_openid` (`buyer_openid`)
);

加一個索引

keyidx_buyer_openid(buyer_openid)

訂單詳情表

訂單詳情表

訂單id order_id

商品id product_id

商品名字 product_name

商品價格 product_price

商品數量 product_quantity

商品圖片 product_icon

-- 訂單商品
create table `order_detail` (
    `detail_id` varchar(32) not null,
    `order_id` varchar(32) not null,
    `product_id` varchar(32) not null,
    `product_name` varchar(64) not null comment '商品名稱',
    `product_price` decimal(8,2) not null comment '當前價格,單位分',
    `product_quantity` int not null comment '數量',
    `product_icon` varchar(512) comment '小圖',
    `create_time` timestamp not null default current_timestamp comment '創建時間',
    `update_time` timestamp not null default current_timestamp on update current_timestamp comment '修改時間',
    primary key (`detail_id`),
    key `idx_order_id` (`order_id`)
);

查詢的時候用到訂單id 來查

order_id varchar(32) not null,

加個索引

key idx_order_id (order_id)

總的 創建個sell數據庫再執行sell.sql吧

sell.sql

-- 類目
create table `product_category` (
    `category_id` int not null auto_increment,
    `category_name` varchar(64) not null comment '類目名字',
    `category_type` int not null comment '類目編號',
    `create_time` timestamp not null default current_timestamp comment '創建時間',
    `update_time` timestamp not null default current_timestamp on update current_timestamp comment '修改時間',
    primary key (`category_id`),
    UNIQUE KEY `uqe_category_type` (`category_type`)
);

-- 商品
create table `product_info` (
    `product_id` varchar(32) not null,
    `product_name` varchar(64) not null comment '商品名稱',
    `product_price` decimal(8,2) not null comment '單價',
    `product_stock` int not null comment '庫存',
    `product_description` varchar(64) comment '描述',
    `product_icon` varchar(512) comment '小圖',
    `product_status` tinyint(3) DEFAULT '0' COMMENT '商品狀態,0正常1下架',
    `category_type` int not null comment '類目編號',
    `create_time` timestamp not null default current_timestamp comment '創建時間',
    `update_time` timestamp not null default current_timestamp on update current_timestamp comment '修改時間',
    primary key (`product_id`)
);

-- 訂單
create table `order_master` (
    `order_id` varchar(32) not null,
    `buyer_name` varchar(32) not null comment '買家名字',
    `buyer_phone` varchar(32) not null comment '買家電話',
    `buyer_address` varchar(128) not null comment '買家地址',
    `buyer_openid` varchar(64) not null comment '買家微信openid',
    `order_amount` decimal(8,2) not null comment '訂單總金額',
    `order_status` tinyint(3) not null default '0' comment '訂單狀態, 默認爲新下單',
    `pay_status` tinyint(3) not null default '0' comment '支付狀態, 默認未支付',
    `create_time` timestamp not null default current_timestamp comment '創建時間',
    `update_time` timestamp not null default current_timestamp on update current_timestamp comment '修改時間',
    primary key (`order_id`),
    key `idx_buyer_openid` (`buyer_openid`)
);

-- 訂單商品
create table `order_detail` (
    `detail_id` varchar(32) not null,
    `order_id` varchar(32) not null,
    `product_id` varchar(32) not null,
    `product_name` varchar(64) not null comment '商品名稱',
    `product_price` decimal(8,2) not null comment '當前價格,單位分',
    `product_quantity` int not null comment '數量',
    `product_icon` varchar(512) comment '小圖',
    `create_time` timestamp not null default current_timestamp comment '創建時間',
    `update_time` timestamp not null default current_timestamp on update current_timestamp comment '修改時間',
    primary key (`detail_id`),
    key `idx_order_id` (`order_id`)
);

-- 賣家(登錄後臺使用, 賣家登錄之後可能直接採用微信掃碼登錄,不使用賬號密碼)
create table `seller_info` (
    `seller_id` varchar(32) not null,
    `username` varchar(32) not null,
    `password` varchar(32) not null,
    `openid` varchar(64) not null comment '微信openid',
    `create_time` timestamp not null default current_timestamp comment '創建時間',
    `update_time` timestamp not null default current_timestamp on update current_timestamp comment '修改時間',
    primary key (`seller_id`)
) comment '賣家信息表';

在這裏插入圖片描述

執行成功 數據庫搞定

樣例圖片鏈接

阿里雲OSS 存儲圖片

烤肉

https://sell-liuawen.oss-cn-beijing.aliyuncs.com/kaorou.jpg

皮蛋粥

https://sell-liuawen.oss-cn-beijing.aliyuncs.com/pidanzhou.jpg

白米飯

https://sell-liuawen.oss-cn-beijing.aliyuncs.com/baimifan.jpg

4、參考資料

1、Spring Boot 打造企業級微信點餐系統

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章