Commit 4cfaee4a by 江名洋

refactor: 移除数据导入接口并更新项目文档

- 移除门店与主机厂数据导入相关的 API 端点及前端导航入口
- 更新 `docs/project.md`,补充系统架构、业务模块及部署指南等详细说明
1 parent adf2d146
...@@ -15,9 +15,7 @@ from app.services.excel_service import ExcelService ...@@ -15,9 +15,7 @@ from app.services.excel_service import ExcelService
from app.services.analysis_service import AnalysisService from app.services.analysis_service import AnalysisService
from app.services.harmony_analysis_service import HarmonyAnalysisService, _find_latest_template from app.services.harmony_analysis_service import HarmonyAnalysisService, _find_latest_template
from app.services.strategy_service import StrategyService, get_task_state from app.services.strategy_service import StrategyService, get_task_state
from app.services.upload_service import ( from app.services.upload_service import get_upload_history
import_store_guarantee, import_oem_delivery, get_upload_history,
)
from app.services.file_naming import ( from app.services.file_naming import (
build_filename, build_filename,
build_store_filename, build_store_filename,
...@@ -1617,117 +1615,6 @@ async def strategy_stale_list(stale_hours: int = Query(4, ge=1, le=48)): ...@@ -1617,117 +1615,6 @@ async def strategy_stale_list(stale_hours: int = Query(4, ge=1, le=48)):
raise HTTPException(status_code=500, detail=f"查询超时策略失败: {str(e)}") raise HTTPException(status_code=500, detail=f"查询超时策略失败: {str(e)}")
# ==================== 门店数据 & 主机厂数据 上传接口 ====================
# 数据导入临时上传(使用 _date_path + data 类别实现日期分级)
DATA_UPLOAD_CATEGORY = "data"
def _save_upload(file: UploadFile, brand: str, data_type: str, start_date: str = None, end_date: str = None, period_type: str = "") -> tuple:
"""保存上传文件。
- 如果提供日期范围,则按正式命名规范整理并存入 data 目录
- 否则存入 drafts 目录
"""
if start_date and end_date:
if data_type == "store":
formal_name = build_store_filename(brand, start_date, end_date)
else:
formal_name = build_factory_filename(brand, period_type, start_date, end_date)
cat = DATA_UPLOAD_CATEGORY
file_name = formal_name
else:
ts = datetime.now().strftime("%H%M%S")
base, ext = os.path.splitext(file.filename)
file_name = f"{data_type}_{brand}_{ts}{ext}"
cat = "drafts"
file_path = _date_path(file_name, category=cat)
# 确保文件名唯一
file_path = ensure_unique_filename(os.path.dirname(file_path), os.path.basename(file_path))
file_path = os.path.join(os.path.dirname(file_path), os.path.basename(file_path))
with open(file_path, "wb") as f:
shutil.copyfileobj(file.file, f)
return file_path, file.filename
@router.post("/data-import/upload-store")
async def upload_store_guarantee(
background_tasks: BackgroundTasks,
file: UploadFile = File(...),
brand: str = Form(...),
period_start: str = Form(...),
period_end: str = Form(...),
):
"""上传门店兜底配置 Excel,导入 store_guarantee_config 表"""
logger.info(f"upload-store: filename={file.filename}, brand={brand}, period={period_start}~{period_end}")
if not file.filename:
raise HTTPException(status_code=400, detail="请选择文件")
if brand not in ("问界", "鸿蒙"):
raise HTTPException(status_code=400, detail="品牌仅支持 问界 或 鸿蒙")
file_path, original_name = _save_upload(file, brand, "store", start_date=period_start, end_date=period_end)
try:
file_size = os.path.getsize(file_path)
result = import_store_guarantee(
file_path=file_path,
original_filename=os.path.basename(file_path),
brand=brand,
data_period_start=period_start,
data_period_end=period_end,
file_size=file_size,
remark=file_path
)
return {"status": "success", "data": result}
except ValueError as e:
logger.warning(f"Store guarantee upload validation: {e}")
raise HTTPException(status_code=400, detail=str(e))
except Exception as e:
logger.error(f"Store guarantee upload failed: {e}", exc_info=True)
raise HTTPException(status_code=500, detail=f"导入失败: {str(e)}")
@router.post("/data-import/upload-oem")
async def upload_oem_delivery(
background_tasks: BackgroundTasks,
file: UploadFile = File(...),
brand: str = Form(...),
period_start: str = Form(...),
period_end: str = Form(...),
period_type: str = Form(""),
):
"""上传主机厂交付数据 Excel,导入 oem_delivery_data 表"""
logger.info(f"upload-oem: filename={file.filename}, brand={brand}, period={period_start}~{period_end}, period_type={period_type}")
if not file.filename:
raise HTTPException(status_code=400, detail="请选择文件")
if brand not in ("问界", "鸿蒙"):
raise HTTPException(status_code=400, detail="品牌仅支持 问界 或 鸿蒙")
if period_type not in ("", "ecology", "nature"):
raise HTTPException(status_code=400, detail="周期类型仅支持 ecology 或 nature")
file_path, original_name = _save_upload(file, brand, "oem", start_date=period_start, end_date=period_end, period_type=period_type)
try:
file_size = os.path.getsize(file_path)
result = import_oem_delivery(
file_path=file_path,
original_filename=os.path.basename(file_path),
brand=brand,
data_period_start=period_start,
data_period_end=period_end,
period_type=period_type,
file_size=file_size,
remark=file_path
)
return {"status": "success", "data": result}
except ValueError as e:
raise HTTPException(status_code=400, detail=str(e))
except Exception as e:
logger.error(f"OEM delivery upload failed: {e}", exc_info=True)
raise HTTPException(status_code=500, detail=f"导入失败: {str(e)}")
@router.get("/data-import/history") @router.get("/data-import/history")
async def get_import_history( async def get_import_history(
brand: Optional[str] = Query(None), brand: Optional[str] = Query(None),
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
'/harmony', '/harmony',
'/analysis', '/analysis',
'/strategy', '/strategy',
'/data-import',
'/ods', '/ods',
'/dw', '/dw',
'/login', '/login',
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
(function() { (function() {
var PAGE_SUFFIXES = [ var PAGE_SUFFIXES = [
'/harmony/sub-brand', '/strategy/detail', '/strategy/info', '/harmony/sub-brand', '/strategy/detail', '/strategy/info',
'/harmony', '/analysis', '/strategy', '/data-import', '/ods', '/dw', '/login', '/harmony', '/analysis', '/strategy', '/ods', '/dw', '/login',
]; ];
var p = window.location.pathname.replace(/\/$/, ''); var p = window.location.pathname.replace(/\/$/, '');
var root = (!p || p === '/') ? '' : p; var root = (!p || p === '/') ? '' : p;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
(function() { (function() {
var PAGE_SUFFIXES = [ var PAGE_SUFFIXES = [
'/harmony/sub-brand', '/strategy/detail', '/strategy/info', '/harmony/sub-brand', '/strategy/detail', '/strategy/info',
'/harmony', '/analysis', '/strategy', '/data-import', '/ods', '/dw', '/login', '/harmony', '/analysis', '/strategy', '/ods', '/dw', '/login',
]; ];
var p = window.location.pathname.replace(/\/$/, ''); var p = window.location.pathname.replace(/\/$/, '');
var root = (!p || p === '/') ? '' : p; var root = (!p || p === '/') ? '' : p;
......
...@@ -297,7 +297,6 @@ ...@@ -297,7 +297,6 @@
<a class="nav-item" href="./harmony">鸿蒙生态分析</a> <a class="nav-item" href="./harmony">鸿蒙生态分析</a>
<a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a> <a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a>
<a class="nav-item" href="./strategy">策略效果盯防(开发中)</a> <a class="nav-item" href="./strategy">策略效果盯防(开发中)</a>
<a class="nav-item" href="./import">数据导入</a>
</nav> </nav>
<div class="user-info" id="user-info">管理员</div> <div class="user-info" id="user-info">管理员</div>
</header> </header>
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
<a class="nav-item" href="./harmony">鸿蒙生态分析</a> <a class="nav-item" href="./harmony">鸿蒙生态分析</a>
<a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a> <a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a>
<a class="nav-item" href="./strategy">策略效果盯防(开发中)</a> <a class="nav-item" href="./strategy">策略效果盯防(开发中)</a>
<a class="nav-item" href="./import">数据导入</a>
</nav> </nav>
<div class="user-info" id="user-info">管理员</div> <div class="user-info" id="user-info">管理员</div>
</header> </header>
......
...@@ -137,7 +137,6 @@ ...@@ -137,7 +137,6 @@
<a class="nav-item active" href="./harmony">鸿蒙生态分析</a> <a class="nav-item active" href="./harmony">鸿蒙生态分析</a>
<a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a> <a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a>
<a class="nav-item" href="./strategy">策略效果盯防(开发中)</a> <a class="nav-item" href="./strategy">策略效果盯防(开发中)</a>
<a class="nav-item" href="./import">数据导入</a>
</nav> </nav>
<div class="user-info" id="user-info">管理员</div> <div class="user-info" id="user-info">管理员</div>
</header> </header>
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
<a class="nav-item" href="./harmony">鸿蒙生态分析</a> <a class="nav-item" href="./harmony">鸿蒙生态分析</a>
<a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a> <a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a>
<a class="nav-item" href="./strategy">策略效果盯防(开发中)</a> <a class="nav-item" href="./strategy">策略效果盯防(开发中)</a>
<a class="nav-item" href="./import">数据导入</a>
</nav> </nav>
<div class="user-info" id="user-info">管理员</div> <div class="user-info" id="user-info">管理员</div>
</header> </header>
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
<a class="nav-item" href="./harmony">鸿蒙生态分析</a> <a class="nav-item" href="./harmony">鸿蒙生态分析</a>
<a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a> <a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a>
<a class="nav-item" href="./strategy">策略效果盯防(开发中)</a> <a class="nav-item" href="./strategy">策略效果盯防(开发中)</a>
<a class="nav-item" href="./import">数据导入</a>
</nav> </nav>
<div class="user-info" id="user-info">管理员</div> <div class="user-info" id="user-info">管理员</div>
</header> </header>
......
...@@ -192,7 +192,6 @@ ...@@ -192,7 +192,6 @@
<a class="nav-item" href="./harmony">鸿蒙生态分析</a> <a class="nav-item" href="./harmony">鸿蒙生态分析</a>
<a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a> <a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a>
<a class="nav-item active" href="./strategy">策略效果盯防(开发中)</a> <a class="nav-item active" href="./strategy">策略效果盯防(开发中)</a>
<a class="nav-item" href="./import">数据导入</a>
</nav> </nav>
<div class="user-info" id="user-info">管理员</div> <div class="user-info" id="user-info">管理员</div>
</header> </header>
......
...@@ -200,7 +200,6 @@ ...@@ -200,7 +200,6 @@
<a class="nav-item" href="./harmony">鸿蒙生态分析</a> <a class="nav-item" href="./harmony">鸿蒙生态分析</a>
<a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a> <a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a>
<a class="nav-item active" href="./strategy">策略效果盯防(开发中)</a> <a class="nav-item active" href="./strategy">策略效果盯防(开发中)</a>
<a class="nav-item" href="./import">数据导入</a>
</nav> </nav>
<div class="user-info" id="user-info">管理员</div> <div class="user-info" id="user-info">管理员</div>
</header> </header>
......
...@@ -200,7 +200,6 @@ ...@@ -200,7 +200,6 @@
<a class="nav-item" href="./harmony">鸿蒙生态分析</a> <a class="nav-item" href="./harmony">鸿蒙生态分析</a>
<a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a> <a class="nav-item" href="./harmony/sub-brand">鸿蒙子品牌分析</a>
<a class="nav-item active" href="./strategy">策略效果盯防</a> <a class="nav-item active" href="./strategy">策略效果盯防</a>
<a class="nav-item" href="./import">数据导入</a>
</nav> </nav>
<div class="user-info" id="user-info">管理员</div> <div class="user-info" id="user-info">管理员</div>
</header> </header>
......
...@@ -153,7 +153,6 @@ PAGE_ROUTES = { ...@@ -153,7 +153,6 @@ PAGE_ROUTES = {
"/strategy": "strategy.html", "/strategy": "strategy.html",
"/strategy/detail": "strategy_detail.html", "/strategy/detail": "strategy_detail.html",
"/strategy/info": "strategy_info.html", "/strategy/info": "strategy_info.html",
"/import": "data_import.html",
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!