a1886074dd
后端: FastAPI + SQLAlchemy 2.0 (async) + Alembic + MinIO + Casdoor + 企微 前端: Vue 3 + Vite + TypeScript + Element Plus + Pinia 功能清单: - 8 张数据表自动建表 / Casdoor OIDC 登录 / 企微静默登录 - 双布局: 移动端(填报) + PC端(汇总管理) - 拜访记录 CRUD + MinIO 照片直传 + 缩略图预览 + 同访人草稿 - 今日纪要 (6 分类) / 工作计划 / 小微商机 / 要客拜访 CRUD - 客户档案: 备注/收支费用/联系人/归属分配/批量转移 - 客户导入导出 + 模板下载 + 搜索/分页/筛选 - 仪表盘: 四卡统计 + 填报进度 (拜访+纪要双维度) - 周报详情: 五 Tab + 按人/客户筛选 + 时间轴 - 用户管理 / 客户经理 PC 端工作台 - 企微: 催办/公告/定时提醒 / 时区修正 - Docker 部署配置 Co-Authored-By: Claude <noreply@anthropic.com>
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
import uuid
|
|
from fastapi import APIRouter, Depends, File, UploadFile, HTTPException
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from app.database import get_db
|
|
from app.middleware.auth import get_current_user, require_director
|
|
from app.services.excel_import import import_from_excel
|
|
|
|
router = APIRouter(prefix="/import", tags=["Import"])
|
|
|
|
|
|
@router.post("/weekly-report")
|
|
async def import_weekly_report(
|
|
file: UploadFile = File(...),
|
|
current_user: dict = Depends(require_director),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
"""Upload old weekly report Excel and import data. Only director can do this."""
|
|
if not file.filename or not file.filename.endswith(('.xlsx', '.xls')):
|
|
raise HTTPException(status_code=400, detail="Only .xlsx and .xls files are supported")
|
|
|
|
content = await file.read()
|
|
|
|
# Preview first: parse headers
|
|
try:
|
|
import openpyxl
|
|
wb = openpyxl.load_workbook(io.BytesIO(content), data_only=True)
|
|
preview = {}
|
|
for sheet_name in wb.sheetnames:
|
|
ws = wb[sheet_name]
|
|
headers = [str(cell.value) for cell in ws[1]]
|
|
row_count = ws.max_row - 1 # minus header
|
|
preview[sheet_name] = {"headers": headers, "row_count": row_count}
|
|
except Exception as e:
|
|
raise HTTPException(status_code=400, detail=f"Failed to parse Excel: {str(e)}")
|
|
|
|
# Import data
|
|
stats = await import_from_excel(db, content, uuid.UUID(current_user["user_id"]))
|
|
stats["preview"] = preview
|
|
|
|
return stats
|
|
|
|
|
|
import io
|