feat(main): implement FastAPI application entry point
This commit is contained in:
16
lsfx-mock-server/.env.example
Normal file
16
lsfx-mock-server/.env.example
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# 应用配置
|
||||||
|
APP_NAME=流水分析Mock服务
|
||||||
|
APP_VERSION=1.0.0
|
||||||
|
DEBUG=true
|
||||||
|
|
||||||
|
# 服务器配置
|
||||||
|
HOST=0.0.0.0
|
||||||
|
PORT=8000
|
||||||
|
|
||||||
|
# 模拟配置
|
||||||
|
PARSE_DELAY_SECONDS=4
|
||||||
|
MAX_FILE_SIZE=10485760
|
||||||
|
|
||||||
|
# 初始ID配置
|
||||||
|
INITIAL_PROJECT_ID=1000
|
||||||
|
INITIAL_LOG_ID=10000
|
||||||
80
lsfx-mock-server/main.py
Normal file
80
lsfx-mock-server/main.py
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
"""
|
||||||
|
流水分析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",
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user