docs: write 开发文档.md
This commit is contained in:
@ -5,13 +5,116 @@
|
||||
**作者**:Zhuang Yumin
|
||||
|
||||
# 程序功能概述
|
||||
|
||||
此项目分为前端和后端。后端即本次大作业的主体部分,接受文本格式的命令,并以文本格式返回响应;前端则以WebUI的形式向用户提供操作界面。
|
||||
# 主体逻辑说明
|
||||
业务流程图:
|
||||
|
||||
数据流图:
|
||||
|
||||
系统结构图:
|
||||
|
||||
详见[开发文档](开发文档.md)和[总体设计文档](总体设计文档.md)
|
||||
# 代码文件结构
|
||||
- `backend/include`:后端头文件
|
||||
- `backend/src`:后端实现文件
|
||||
- `frontend/Web`:WebUI相关
|
||||
- `frontend/client`:客户端
|
||||
- `external/clipp`:第三方库,解析命令行参数
|
||||
- `external/json`:第三方库,为调试器提供json支持(虽然基本没啥用)
|
||||
|
||||
# 各个类的接口及成员说明
|
||||
## DriveArray
|
||||
提供文件存储支持,有缓存等元数据,在兼容MemoryRiver的基础上提供下列接口:
|
||||
- `bool IsOpen()`
|
||||
- `void OpenFile(const std::string &__file_name)`
|
||||
- `void CloseFile()`
|
||||
- `void LoadInfoTo(int *dest)`:批量读取info
|
||||
- `void WriteInfoFrom(int *src)`:批量写入info
|
||||
- `void FetchAll(std::vector<T> &vec)`:遍历并获取所有元素
|
||||
|
||||
## key2index
|
||||
提供从字符串映射到一个值的支持,有内存中的散列表等内部数据,相当于multimap,有如下接口:
|
||||
- `void OpenFile(const std::string __file_name)`
|
||||
- `void Insert(const std::string &str, int val)`
|
||||
- `void Delete(const std::string &str, int val)`
|
||||
- `std::vector<int> Find(const std::string &str)`
|
||||
|
||||
## 数据库
|
||||
三个数据库的声明如下,相关信息见注释:
|
||||
```cpp
|
||||
class UserDataBase {
|
||||
DriveArray<UserItemClass> full_user_data;
|
||||
String2Index user_name2index;
|
||||
|
||||
public:
|
||||
UserDataBase() = default;
|
||||
void Open(std::string file_name);
|
||||
bool PAM(const std::string &user_id, const std::string &password); // 登陆验证
|
||||
int GetPrevilege(const std::string &user_id); // 获取用户权限,用户不存在时返回-1
|
||||
void AddUser(const std::string &user_id, const std::string &password,
|
||||
const std::string &user_name, int privilege); // 新增用户
|
||||
void DeleteUser(const std::string &user_id); // 删除用户
|
||||
void ChangePassword(const std::string &user_id, const std::string &password); // 修改密码
|
||||
};
|
||||
class BookDataBase {
|
||||
DriveArray<BookItemClass> full_book_data;
|
||||
String2Index ISBN2index, name2index, author2index, keyword2index;
|
||||
|
||||
public:
|
||||
void Open(std::string file_name);
|
||||
bool HaveISBN(const std::string &ISBN); // 判断是否有
|
||||
bool HaveISBN(const std::string &ISBN, BookItemClass &ret); // 判断是否有并且获取内容
|
||||
void CreateEmptyBook(const std::string &ISBN); // 新建一个书
|
||||
void QueryBook(const std::string &ISBN, const std::string &name,
|
||||
const std::string &author, const std::string &keyword,
|
||||
std::vector<BookItemClass> &ret);
|
||||
// 查询书籍,没有的关键词直接置为空
|
||||
void ModifyInfo(const std::string &ISBN, const std::string &new_ISBN,
|
||||
const std::string &name, const std::string &author,
|
||||
const std::string &keyword, double price,
|
||||
int quantity_remain);
|
||||
// 修改信息,当一个字段无需修改时,字符串设为空,数值设为-1
|
||||
std::string GetISBN(int bid);
|
||||
// 获取某个bid(当ISBN变化后唯一确定一本书的方式)对应的图书的ISBN号
|
||||
};
|
||||
class LogDataBase {
|
||||
DriveArray<FinanceItemClass> finance_data;
|
||||
DriveArray<OperationLogItemClass> operation_log_data;
|
||||
int finance_operation_count;
|
||||
|
||||
public:
|
||||
~LogDataBase() { finance_data.write_info(finance_operation_count, 1); }
|
||||
void Open(std::string file_name);
|
||||
void AddSell(int book_id, int quantity, double total_price); // 添加一笔销售记录
|
||||
void AddImport(int book_id, int quantity, double total_price); // 添加一笔进货记录
|
||||
std::pair<double, double> QueryFinance(int count = -1); // 查询最近count次交易的资金流动概要
|
||||
void QueryFinance(int count, std::vector<FinanceItemClass> &ret);
|
||||
int TotalFinanceOperationCount() noexcept { return finance_operation_count; } // 查询总交易笔数
|
||||
};
|
||||
```
|
||||
|
||||
# 文件存储说明
|
||||
默认往当前目录下存放文件,但也可以指定。
|
||||
- `book.author`:书籍数据库的作者名索引
|
||||
- `book.isbn`:书籍数据库的ISBN索引
|
||||
- `book.keyword`:书籍数据库的关键词索引
|
||||
- `book.name`:书籍数据库的书名索引
|
||||
- `book.full`:书籍数据库的完整信息
|
||||
- `user.n2i`:用户数据库的索引
|
||||
- `user.full`:用户数据库的完整信息
|
||||
- `log.finance`:交易日志
|
||||
- `log.log`:完整操作日志
|
||||
|
||||
# 其他补充说明
|
||||
主程序命令行交互方式:
|
||||
```
|
||||
SYNOPSIS
|
||||
./code [-s] [-c <config directory>]
|
||||
|
||||
OPTIONS
|
||||
-s, --server
|
||||
run as server
|
||||
|
||||
-c, --config
|
||||
use config directory
|
||||
```
|
@ -11,8 +11,7 @@
|
||||
- 快照
|
||||
- 文件系统修复
|
||||
|
||||
系统结构图:
|
||||
|
||||
系统结构图:
|
||||
|
||||
# 功能设计(模块划分)、数据库设计
|
||||
整个程序分为后端和前端两部分,后端即主体部分
|
||||
|
@ -2,7 +2,7 @@
|
||||
一个中小规模的书店,后台运行一个服务端,使得用户、店员、店主可以方便地在电脑端或移动端上完成相关业务操作
|
||||
|
||||
业务流程图:
|
||||
数据流图:
|
||||
数据流图:
|
||||
|
||||
## 功能需求
|
||||
### 游客
|
||||
|
Reference in New Issue
Block a user