81 lines
2.1 KiB
Python
81 lines
2.1 KiB
Python
"""
|
||
流水分析Mock服务器 - 主应用入口
|
||
|
||
基于 FastAPI 实现的 Mock 服务器,用于模拟流水分析平台的 7 个核心接口
|
||
"""
|
||
from fastapi import FastAPI
|
||
from routers import api
|
||
from config.settings import settings
|
||
|
||
# 创建 FastAPI 应用实例
|
||
app = FastAPI(
|
||
title=settings.APP_NAME,
|
||
description="""
|
||
## 流水分析 Mock 服务器
|
||
|
||
模拟流水分析平台的 7 个核心接口,用于开发和测试。
|
||
|
||
### 主要功能
|
||
|
||
- **Token管理** - 创建项目并获取访问Token
|
||
- **文件上传** - 上传流水文件,支持异步解析(4秒延迟)
|
||
- **行内流水** - 拉取行内流水数据
|
||
- **解析状态** - 轮询检查文件解析状态
|
||
- **文件删除** - 批量删除上传的文件
|
||
- **流水查询** - 分页获取银行流水数据
|
||
|
||
### 错误模拟
|
||
|
||
在请求参数中包含 `error_XXXX` 标记可触发对应的错误响应。
|
||
|
||
例如:`projectNo: "test_error_40101"` 将返回 40101 错误。
|
||
|
||
### 使用方式
|
||
|
||
1. 获取Token: POST /account/common/getToken
|
||
2. 上传文件: POST /watson/api/project/remoteUploadSplitFile
|
||
3. 轮询解析状态: POST /watson/api/project/upload/getpendings
|
||
4. 获取流水: POST /watson/api/project/getBSByLogId
|
||
""",
|
||
version=settings.APP_VERSION,
|
||
docs_url="/docs",
|
||
redoc_url="/redoc",
|
||
)
|
||
|
||
# 包含 API 路由
|
||
app.include_router(api.router, tags=["流水分析接口"])
|
||
|
||
|
||
@app.get("/", summary="服务根路径")
|
||
async def root():
|
||
"""服务根路径,返回基本信息"""
|
||
return {
|
||
"service": settings.APP_NAME,
|
||
"version": settings.APP_VERSION,
|
||
"swagger_docs": "/docs",
|
||
"redoc": "/redoc",
|
||
"status": "running",
|
||
}
|
||
|
||
|
||
@app.get("/health", summary="健康检查")
|
||
async def health_check():
|
||
"""健康检查端点"""
|
||
return {
|
||
"status": "healthy",
|
||
"service": settings.APP_NAME,
|
||
"version": settings.APP_VERSION,
|
||
}
|
||
|
||
|
||
if __name__ == "__main__":
|
||
import uvicorn
|
||
|
||
# 启动服务器
|
||
uvicorn.run(
|
||
app,
|
||
host=settings.HOST,
|
||
port=settings.PORT,
|
||
log_level="debug" if settings.DEBUG else "info",
|
||
)
|