LuTong 2 сар өмнө
commit
5b50068a0a

+ 45 - 0
README.md

@@ -0,0 +1,45 @@
+# Alien Cloud Python (alien_py_cloud)
+
+U宝后端 V3.0
+
+## 技术栈
+- **语言**: Python 3.12+
+- **框架**: [FastAPI](https://fastapi.tiangolo.com/)
+- **异步**: 基于 Python `asyncio`
+- **依赖管理**: Poetry
+- **数据库 ORM**: SQLAlchemy 2.0
+- **数据校验**: Pydantic v2
+- **认证**: JWT (python-jose)
+
+## 项目结构 (扁平化模块设计)
+为了保持原 Java 项目的业务逻辑,我们采用了扁平化的模块化布局:
+
+- `alien_store/`: 核心业务 - 门店管理 (原 alien-store)
+- `alien_store_platform/`: 核心业务 - 商户平台 (原 alien-store-platform)
+- `alien_second/`: 核心业务 - 二手交易模块 (原 alien-second)
+- `alien_lawyer/`: 核心业务 - 律师服务模块 (原 alien-lawyer)
+- `alien_entity/`: 业务实体定义 (原 alien-entity),使用 Pydantic 模型
+- `alien_gateway/`: 网关功能 (原 alien-gateway),包含全局配置、鉴权、中间件
+- `alien_util/`: 通用工具类 (原 alien-util)
+- `common/`: 跨模块共享的内部组件(如数据库连接池、基类等)
+- `main.py`: FastAPI 应用入口
+
+## 快速开始
+
+### 1. 安装依赖
+```bash
+poetry install
+```
+
+### 2. 运行项目
+```bash
+uvicorn main:app --reload
+```
+
+### 3. 查看文档
+启动后访问:[http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) (Swagger UI) 或 [/redoc](/redoc)。
+
+## 重构原则
+1. **Snake Case**: 所有命名从 Java 的 Kebab-case (alien-store) 转换为 Python 的 Snake Case (alien_store)。
+2. **异步优先**: 充分利用 FastAPI 的 `async def` 处理 I/O 密集型任务。
+3. **职责单一**: 每个模块保持高内聚,低耦合。

+ 0 - 0
alien_entity/__init__.py


+ 12 - 0
alien_entity/base.py

@@ -0,0 +1,12 @@
+from pydantic import BaseModel, ConfigDict
+from datetime import datetime
+from typing import Optional
+
+class BaseSchema(BaseModel):
+    """基础数据模型,对应原 alien-entity 的公共基类"""
+    model_config = ConfigDict(from_attributes=True)
+    
+    id: Optional[int] = None
+    created_time: Optional[datetime] = None
+    updated_time: Optional[datetime] = None
+    delete_flag: int = 0

+ 0 - 0
alien_gateway/__init__.py


+ 29 - 0
alien_gateway/config.py

@@ -0,0 +1,29 @@
+from pydantic_settings import BaseSettings
+from typing import List
+
+class Settings(BaseSettings):
+    # 基础配置
+    PROJECT_NAME: str = "Alien Cloud Python"
+    API_V1_STR: str = "/api/v1"
+    
+    # 鉴权配置 (原 alien-gateway 职责)
+    SECRET_KEY: str = "your-super-secret-key-change-me"
+    ALGORITHM: str = "HS256"
+    ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7  # 7天
+    
+    # 数据库配置
+    DB_USER: str = "root"
+    DB_PASSWORD: str = "password"
+    DB_HOST: str = "localhost"
+    DB_PORT: int = 3306
+    DB_NAME: str = "alien_cloud"
+
+    @property
+    def SQLALCHEMY_DATABASE_URI(self) -> str:
+        return f"mysql+pymysql://{self.DB_USER}:{self.DB_PASSWORD}@{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}"
+
+    class Config:
+        case_sensitive = True
+        env_file = ".env"
+
+settings = Settings()

+ 0 - 0
alien_lawyer/__init__.py


+ 7 - 0
alien_lawyer/router.py

@@ -0,0 +1,7 @@
+from fastapi import APIRouter
+
+router = APIRouter()
+
+@router.get("/")
+async def index():
+    return {"module": "alien_lawyer", "status": "initialized"}

+ 0 - 0
alien_second/__init__.py


+ 7 - 0
alien_second/router.py

@@ -0,0 +1,7 @@
+from fastapi import APIRouter
+
+router = APIRouter()
+
+@router.get("/")
+async def index():
+    return {"module": "alien_second", "status": "initialized"}

+ 0 - 0
alien_store/__init__.py


+ 7 - 0
alien_store/router.py

@@ -0,0 +1,7 @@
+from fastapi import APIRouter
+
+router = APIRouter()
+
+@router.get("/")
+async def index():
+    return {"module": "alien_store", "status": "initialized"}

+ 0 - 0
alien_store_platform/__init__.py


+ 7 - 0
alien_store_platform/router.py

@@ -0,0 +1,7 @@
+from fastapi import APIRouter
+
+router = APIRouter()
+
+@router.get("/")
+async def index():
+    return {"module": "alien_store_platform", "status": "initialized"}

+ 0 - 0
alien_util/__init__.py


+ 0 - 0
common/__init__.py


+ 20 - 0
common/database.py

@@ -0,0 +1,20 @@
+from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
+from alien_gateway.config import settings
+
+# 异步数据库引擎
+engine = create_async_engine(
+    settings.SQLALCHEMY_DATABASE_URI.replace("mysql+pymysql", "mysql+aiomysql"),
+    echo=True,
+    pool_pre_ping=True,
+)
+
+AsyncSessionLocal = async_sessionmaker(
+    bind=engine,
+    class_=AsyncSession,
+    expire_on_commit=False,
+)
+
+async def get_db():
+    """获取数据库 Session 的依赖项"""
+    async with AsyncSessionLocal() as session:
+        yield session

+ 27 - 0
main.py

@@ -0,0 +1,27 @@
+from fastapi import FastAPI
+from alien_store.router import router as store_router
+from alien_store_platform.router import router as platform_router
+from alien_second.router import router as second_router
+from alien_lawyer.router import router as lawyer_router
+from alien_gateway.config import settings
+
+app = FastAPI(
+    title=settings.PROJECT_NAME,
+    description="Python 3.12 重构版本 - 异星云 (Alien Cloud)",
+    version="1.0.0",
+)
+
+# 注册各核心业务模块路由
+app.include_router(store_router, prefix="/api/store", tags=["Store"])
+app.include_router(platform_router, prefix="/api/platform", tags=["Platform"])
+app.include_router(second_router, prefix="/api/second", tags=["Second"])
+app.include_router(lawyer_router, prefix="/api/lawyer", tags=["Lawyer"])
+
+@app.get("/", tags=["Health Check"])
+async def root():
+    return {
+        "status": "online",
+        "project": "alien_py_cloud",
+        "version": "3.12",
+        "documentation": "/docs"
+    }

+ 25 - 0
pyproject.toml

@@ -0,0 +1,25 @@
+[tool.poetry]
+name = "alien-py-cloud"
+version = "0.1.0"
+description = "Alien Cloud Python 重构版本 - 基于 FastAPI 的扁平化模块架构"
+authors = ["Alien Team"]
+readme = "README.md"
+
+[tool.poetry.dependencies]
+python = "^3.12"
+fastapi = "^0.109.0"
+uvicorn = {extras = ["standard"], version = "^0.27.0"}
+pydantic = {extras = ["email"], version = "^2.6.0"}
+pydantic-settings = "^2.1.0"
+sqlalchemy = "^2.0.25"
+alembic = "^1.13.1"
+python-jose = {extras = ["cryptography"], version = "^3.3.0"}
+passlib = {extras = ["bcrypt"], version = "^1.7.4"}
+python-multipart = "^0.0.6"
+httpx = "^0.26.0"
+pymysql = "^1.1.0"
+redis = "^5.0.1"
+
+[build-system]
+requires = ["poetry-core>=1.0.0"]
+build-backend = "poetry.core.masonry.api"