- 添加骆驼加油API端点设计及系统架构文档 - 新增定时任务模块详细说明及任务流程图 - 完成订单管理服务功能及架构介绍 - 增加账号管理模块设计与状态机说明 - 集成Pig接码平台文档,介绍验证码检测流程 - 详细列出各组件的依赖关系及性能优化措施 - 提供故障排除指南及系统扩展性总结
7.5 KiB
骆驼加油账号管理
**本文档引用的文件** - [camel_oil.go](file://api/camel_oil/camel_oil.go) - [account.go](file://api/camel_oil/v1/account.go) - [order.go](file://api/camel_oil/v1/order.go) - [camel_oil_new.go](file://internal/controller/camel_oil/camel_oil_new.go) - [camel_oil_v1_list_account.go](file://internal/controller/camel_oil/camel_oil_v1_list_account.go) - [camel_oil_v1_submit_order.go](file://internal/controller/camel_oil/camel_oil_v1_submit_order.go) - [camel_oil_v1_list_order.go](file://internal/controller/camel_oil/camel_oil_v1_list_order.go) - [camel_oil_v1_order_detail.go](file://internal/controller/camel_oil/camel_oil_v1_order_detail.go) - [camel_oil.go](file://internal/service/camel_oil.go) - [camel_oil.go](file://internal/consts/camel_oil.go) - [camel_oil_tables.sql](file://sql/camel_oil_tables.sql)目录
简介
本系统为骆驼加油平台的账号与订单管理模块,提供完整的账号生命周期管理、订单处理及状态追踪功能。系统通过API接口实现账号查询、状态检测、订单提交与查询等核心业务功能,支持高并发下的稳定运行。
项目结构
骆驼加油模块采用分层架构设计,包含API定义、控制器、服务层和数据访问层。主要目录结构如下:
api/camel_oil/:API接口定义internal/controller/camel_oil/:控制器层internal/service/camel_oil.go:服务层主入口internal/consts/camel_oil.go:常量定义sql/camel_oil_tables.sql:数据库表结构
graph TD
A[API接口] --> B[Controller]
B --> C[Service]
C --> D[DAO]
D --> E[(数据库)]
图示来源
本节来源
核心组件
系统核心功能包括账号管理、订单处理两大模块。账号管理支持状态查询、历史记录查看;订单处理支持提交、查询、回调等功能。所有接口均通过统一的服务入口进行调度。
本节来源
架构概述
系统采用GoFrame框架构建,遵循MVC设计模式。前端请求通过API路由进入Controller层,由Controller调用Service层处理业务逻辑,最终通过DAO层操作数据库。Redis用于分布式锁控制并发访问。
graph LR
Client[客户端] --> API[API接口]
API --> Controller[控制器]
Controller --> Service[服务层]
Service --> DAO[数据访问层]
DAO --> DB[(MySQL)]
Service --> Cache[(Redis)]
图示来源
详细组件分析
账号管理分析
账号管理模块提供账号列表查询、状态检测、历史记录等功能。系统通过状态机管理账号生命周期,支持待登录、在线、暂停、失效等多种状态。
classDiagram
class AccountListItem {
+int64 AccountId
+string AccountName
+string Phone
+int Status
+string StatusText
+int DailyOrderCount
+string DailyOrderDate
+int TotalOrderCount
+*gtime.Time LastUsedAt
+*gtime.Time LastLoginAt
+*gtime.Time TokenExpireAt
+int RemainingOrders
+string FailureReason
+string Remark
+*gtime.Time CreatedAt
+*gtime.Time UpdatedAt
}
class ListAccountReq {
+CommonPageReq Meta
+int Page
+int Limit
+int Status
+string Keyword
}
class CheckAccountReq {
+CommonMeta Meta
+int64 AccountId
}
ListAccountReq --> AccountListItem : "返回列表"
CheckAccountReq --> AccountListItem : "返回详情"
图示来源
本节来源
订单处理分析
订单处理模块负责订单的创建、查询、状态更新和回调通知。系统通过分布式锁保证订单处理的原子性,防止重复提交。
sequenceDiagram
participant Client
participant Controller
participant Service
participant DB
Client->>Controller : SubmitOrder(金额, 商户订单号)
Controller->>Service : 调用SubmitOrder
Service->>DB : 检查可用账号
DB-->>Service : 返回账号信息
Service->>Service : 分配账号并创建订单
Service-->>Controller : 返回订单号和支付链接
Controller-->>Client : 返回响应
Note over Client,DB : 订单提交流程
图示来源
本节来源
状态管理分析
系统定义了完整的状态转换机制,涵盖账号状态、订单状态、支付状态等多个维度。状态变更均记录到历史表中,便于追踪和审计。
stateDiagram-v2
[*] --> 待登录
待登录 --> 登录中 : 开始登录
登录中 --> 在线 : 登录成功
登录中 --> 已失效 : 登录失败
在线 --> 已暂停 : 达到每日上限
已暂停 --> 在线 : 每日重置
在线 --> 已失效 : 长时间未使用
已失效 --> [*]
图示来源
本节来源
依赖分析
系统依赖于多个外部组件和内部模块。主要依赖关系如下:
graph TD
A[骆驼加油API] --> B[用户中心]
A --> C[支付系统]
A --> D[通知服务]
A --> E[Redis缓存]
A --> F[MySQL数据库]
B --> G[认证服务]
C --> H[支付宝网关]
style A fill:#f9f,stroke:#333
style F fill:#bbf,stroke:#333
图示来源
本节来源
性能考虑
系统在设计时充分考虑了性能因素。通过Redis分布式锁控制并发,避免热点账号的竞争;使用数据库索引优化查询性能;设置合理的超时机制防止资源占用。
本节来源
故障排除指南
常见问题包括账号无法登录、订单提交失败等。排查时应首先检查日志中的错误码,根据错误码定位问题根源。对于分布式锁相关问题,需检查Redis连接状态。
本节来源
结论
骆驼加油账号管理系统实现了完整的账号与订单管理功能,具备良好的扩展性和稳定性。通过合理的设计和优化,能够满足高并发场景下的业务需求。