Files
jiu/docs/context/project.md
T
wangjia 76ab19ea47 feat(client): 初版 Flutter UI 框架,仿照参考截图实现
- 蓝色顶栏(#1565C0)+ 深蓝侧边栏(#0D47A1),含折叠/展开
- 底部状态栏:门店编号、登录用户、登录时间、实时时钟、版本号
- 登录页:居中卡片,支持密码显示/隐藏
- 入库单列表:筛选/搜索/日期选择/分页,三个 Tab(入库单/查询/审核)
- 新建入库单:基本信息 + 商品明细动态增删,实时计算合计金额
- 出库单列表:同入库单风格
- 库存查询:4 张统计卡片 + 颜色高亮缺货/预警行,库存预警 Tab
- 往来单位、财务、商品、系统设置(用户/仓库/编号规则/系统参数)
- 使用 Riverpod 状态管理 + go_router 路由 + Dio HTTP

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-04 12:51:41 +08:00

199 lines
7.2 KiB
Markdown
Raw 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.
# 酒店仓库管理系统 — 项目上下文
> 所有 Agent 在开始工作前必须读取此文件,了解项目全貌。
## 项目简介
面向酒店的酒水仓库管理系统。核心特点:
- **多租户**:一个账号对应一个酒店,数据完全隔离(通过 `hotel_id` 字段)
- **付费授权**:许可证绑定设备 ID,支持试用/年付/买断
- **跨端客户端**:Flutter 单一代码库,支持 Windows / Web / macOS / iOS / Android
## 技术栈
```yaml
后端:
语言: Go 1.26
框架: GinHTTP+ GORMORM
数据库: MySQL 8.0
认证: JWTHS256),Access Token 60分钟,Refresh Token 7天
模块路径: github.com/wangjia/jiu/backend
前端:
框架: Flutter 3.x
状态管理: Riverpod
HTTP客户端: Dio
路由: go_router
目录: client/
数据库迁移:
工具: golang-migrate
迁移文件: backend/migrations/
完整schema: backend/schema/schema.sql
```
## 项目目录结构
```
jiu/
├── backend/
│ ├── main.go # 入口
│ ├── config/config.yaml # 配置(本地开发)
│ ├── internal/
│ │ ├── handler/ # HTTP 处理器(每模块一文件)
│ │ ├── service/ # 业务逻辑层
│ │ ├── model/ # GORM 数据模型
│ │ ├── middleware/auth.go # JWT 验证 + 租户注入
│ │ └── router/router.go # 路由注册
│ ├── migrations/ # 版本迁移 SQL
│ └── schema/schema.sql # 完整建表 SQL
├── client/ # Flutter 跨端客户端
├── deploy/
│ └── docker-compose.yml # 本地开发:MySQL + Adminer
└── docs/
├── context/project.md # 本文件
├── requirements/ # 需求文档
├── architecture/ # 架构设计
├── api/ # API 接口规范
├── review/ # 代码审查报告 + bug 报告
├── security/ # 安全审计报告
└── runbooks/ # 运维操作手册
```
## 核心数据模型
```yaml
主要表:
hotels: # 酒店(租户)
users: # 用户(含 hotel_id
licenses: # 许可证(含 device_id 绑定)
products: # 商品(含 custom_fields JSON 动态扩展)
warehouses: # 仓库
partners: # 往来单位(supplier/customer
stock_in_orders: # 入库单(draft→pending→approved/rejected
stock_in_items: # 入库单明细
stock_out_orders: # 出库单
stock_out_items: # 出库单明细
inventory: # 实时库存(唯一键:hotel_id+warehouse_id+product_id
inventory_logs: # 库存流水(每次变动记录)
inventory_checks: # 盘点单
finance_records: # 财务流水
number_rules: # 单号生成规则
```
## 关键业务规则
1. **多租户**:所有查询必须带 `hotel_id` 条件,`hotel_id` 只从 JWT 获取,不信任请求参数
2. **库存变更**:入库/出库审核通过时,在同一事务中更新 `inventory` + 写 `inventory_logs`
3. **出库前检查**:出库审核时必须校验库存充足,不足时返回错误并回滚事务
4. **单号生成**:通过 `number_rules` 表事务安全生成,格式 `{前缀}{日期}{6位序号}`
5. **扩展字段**:所有业务主表含 `custom_fields JSON`,用于存储动态业务字段
## 已实现的 API 接口
```yaml
认证:
- POST /api/v1/auth/login
- POST /api/v1/auth/refresh
许可证:
- POST /api/v1/license/activate
- GET /api/v1/license/verify
- POST /api/v1/license/deactivate
商品:
- GET/POST /api/v1/products
- PUT/DELETE /api/v1/products/:id
仓库:
- GET/POST /api/v1/warehouses
- PUT/DELETE /api/v1/warehouses/:id
往来单位:
- GET/POST /api/v1/partners
- PUT/DELETE /api/v1/partners/:id
入库:
- GET/POST /api/v1/stock-in/orders
- GET /api/v1/stock-in/orders/:id
- PUT /api/v1/stock-in/orders/:id/submit
- PUT /api/v1/stock-in/orders/:id/approve
- PUT /api/v1/stock-in/orders/:id/reject
出库:
- GET/POST /api/v1/stock-out/orders
- GET /api/v1/stock-out/orders/:id
- PUT /api/v1/stock-out/orders/:id/submit
- PUT /api/v1/stock-out/orders/:id/approve
- PUT /api/v1/stock-out/orders/:id/reject
库存:
- GET /api/v1/inventory
- GET /api/v1/inventory/logs
- POST/GET /api/v1/inventory/checks
数据导入:
- POST /api/v1/import/products (Excel/CSV)
- POST /api/v1/import/partners (Excel/CSV)
```
## Flutter 客户端结构
```
client/
├── pubspec.yaml # 依赖:riverpod, go_router, dio, intl
├── lib/
│ ├── main.dart # 入口,ProviderScope + MaterialApp.router
│ ├── core/
│ │ ├── theme/app_theme.dart # 颜色常量 + ThemeData
│ │ ├── auth/auth_state.dart # AuthUser, AuthState, AuthNotifier
│ │ ├── api/api_client.dart # Dio 封装
│ │ └── router/app_router.dart # go_router 路由定义(含登录重定向)
│ ├── screens/
│ │ ├── auth/login_screen.dart # 登录页(蓝色背景 + 居中卡片)
│ │ ├── shell/app_shell.dart # 主框架(顶栏 + 侧边栏 + 状态栏)
│ │ ├── stock_in/ # 入库单列表 + 新建表单
│ │ ├── stock_out/ # 出库单列表
│ │ ├── inventory/ # 库存查询 + 盘点
│ │ ├── partners/ # 往来单位
│ │ ├── finance/ # 财务管理
│ │ ├── products/ # 商品管理
│ │ └── settings/ # 系统设置(用户/仓库/编号规则)
│ └── widgets/
│ ├── page_scaffold.dart # Tab 页面封装
│ ├── data_table_card.dart # 含工具栏+分页的数据表格
│ ├── status_badge.dart # 状态标签(草稿/待审/已审/拒绝)
│ └── form_dialog.dart # 弹窗表单封装
```
**启动 Flutter 客户端**(需先安装 Flutter):
```bash
cd client
flutter pub get
flutter run -d macos # macOS 桌面
flutter run -d chrome # Web
```
## 本地开发启动
```bash
# 1. 启动数据库
cd deploy && docker compose up -d
# 2. 启动后端(会自动 AutoMigrate
cd backend && export PATH="/opt/homebrew/bin:$PATH" && go run main.go
# 3. 运行测试
cd backend && go test ./... -cover
# 4. 数据库管理界面
# 打开 http://localhost:8888,服务器:mysql, 用户:root, 密码:password, 数据库:jiu_db
```
## 文档索引
| 文档 | 路径 | 说明 |
|------|------|------|
| 本文件 | docs/context/project.md | 项目全貌,所有 Agent 必读 |
| Schema | backend/schema/schema.sql | 完整数据库建表 SQL |