Commit 26cb4e3d by 江名洋

refactor: 将xlsx模板目录迁移至templates/xlsx

1 parent 6333c156
Showing 24 changed files with 40 additions and 34 deletions
...@@ -183,18 +183,19 @@ async def run_dw_sync_get( ...@@ -183,18 +183,19 @@ async def run_dw_sync_get(
# ==================== 数据分析接口 ==================== # ==================== 数据分析接口 ====================
XLSX_DIR = os.path.join("app", "templates", "xlsx")
def _find_latest_wenjie_template(): def _find_latest_wenjie_template():
"""返回最新的问界门店数据模板(最大序号),无带序号文件时回退到旧版""" """返回最新的问界门店数据模板(最大序号),无带序号文件时回退到旧版"""
tmpl_dir = os.path.join("app", "templates")
max_no = 0 max_no = 0
for f in glob.glob(os.path.join(tmpl_dir, "问界门店数据模板[0-9][0-9][0-9].xlsx")): for f in glob.glob(os.path.join(XLSX_DIR, "问界门店数据模板[0-9][0-9][0-9].xlsx")):
m = re.search(r"问界门店数据模板(\d{3})\.xlsx", os.path.basename(f)) m = re.search(r"问界门店数据模板(\d{3})\.xlsx", os.path.basename(f))
if m: if m:
max_no = max(max_no, int(m.group(1))) max_no = max(max_no, int(m.group(1)))
if max_no > 0: if max_no > 0:
return os.path.join(tmpl_dir, f"问界门店数据模板{max_no:03d}.xlsx") return os.path.join(XLSX_DIR, f"问界门店数据模板{max_no:03d}.xlsx")
# 回退到旧版模板 # 回退到旧版模板
fallback = os.path.join(tmpl_dir, "门店数据-模板0625.xlsx") fallback = os.path.join(XLSX_DIR, "门店数据-模板0625.xlsx")
if os.path.exists(fallback): if os.path.exists(fallback):
return fallback return fallback
return None return None
...@@ -219,7 +220,7 @@ async def download_analysis_template(template_type: str): ...@@ -219,7 +220,7 @@ async def download_analysis_template(template_type: str):
raise HTTPException(status_code=400, detail="无效的模板类型,支持: store, factory, output") raise HTTPException(status_code=400, detail="无效的模板类型,支持: store, factory, output")
# 查找模板文件 # 查找模板文件
search_paths = [ search_paths = [
os.path.join("app", "templates", filename), os.path.join(XLSX_DIR, filename),
os.path.join("docs", "test-demos", filename), os.path.join("docs", "test-demos", filename),
] ]
file_path = None file_path = None
...@@ -399,7 +400,7 @@ async def download_harmony_template(template_type: str): ...@@ -399,7 +400,7 @@ async def download_harmony_template(template_type: str):
if not filename: if not filename:
raise HTTPException(status_code=400, detail="无效的模板类型,支持: store, factory, output") raise HTTPException(status_code=400, detail="无效的模板类型,支持: store, factory, output")
file_path = os.path.join("app", "templates", filename) file_path = os.path.join(XLSX_DIR, filename)
if not os.path.exists(file_path): if not os.path.exists(file_path):
raise HTTPException(status_code=404, detail=f"模板文件不存在: {filename}") raise HTTPException(status_code=404, detail=f"模板文件不存在: {filename}")
...@@ -459,7 +460,7 @@ async def harmony_generate( ...@@ -459,7 +460,7 @@ async def harmony_generate(
# 门店兜底配置:未上传时使用默认模板 # 门店兜底配置:未上传时使用默认模板
if not _harmony_store_file or not os.path.exists(_harmony_store_file): if not _harmony_store_file or not os.path.exists(_harmony_store_file):
default_store = os.path.join("app", "templates", "鸿蒙门店数据-模板.xlsx") default_store = os.path.join(XLSX_DIR, "鸿蒙门店数据-模板.xlsx")
if os.path.exists(default_store): if os.path.exists(default_store):
_harmony_store_file = default_store _harmony_store_file = default_store
else: else:
......
...@@ -694,7 +694,7 @@ class AnalysisService: ...@@ -694,7 +694,7 @@ class AnalysisService:
""" """
import shutil import shutil
TEMPLATE_FILE = os.path.join("app", "templates", "输出-问界生态系数-模板0625.xlsx") TEMPLATE_FILE = os.path.join("app", "templates", "xlsx", "输出-问界生态系数-模板0625.xlsx")
TEMPLATE_SHEET = "模板" TEMPLATE_SHEET = "模板"
if not os.path.exists(TEMPLATE_FILE): if not os.path.exists(TEMPLATE_FILE):
......
...@@ -326,7 +326,7 @@ class HarmonyAnalysisService: ...@@ -326,7 +326,7 @@ class HarmonyAnalysisService:
import shutil import shutil
import time import time
TEMPLATE_FILE = os.path.join("app", "templates", "输出-鸿蒙生态系数-模板.xlsx") TEMPLATE_FILE = os.path.join("app", "templates", "xlsx", "输出-鸿蒙生态系数-模板.xlsx")
TEMPLATE_SHEET = "模板" TEMPLATE_SHEET = "模板"
if not os.path.exists(TEMPLATE_FILE): if not os.path.exists(TEMPLATE_FILE):
......
...@@ -22,7 +22,7 @@ let historyCache = {}; ...@@ -22,7 +22,7 @@ let historyCache = {};
// ========== 历史记录渲染 ========== // ========== 历史记录渲染 ==========
async function fetchHistory(filterFn) { async function fetchHistory(filterFn) {
try { try {
const res = await fetch('/api/etl/history?limit=15'); const res = await fetch('api/etl/history?limit=15');
const history = await res.json(); const history = await res.json();
const tbody = document.getElementById('history-tbody'); const tbody = document.getElementById('history-tbody');
if (!tbody) return false; if (!tbody) return false;
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>问界生态系数分析 - 问界门店运营数据分析平台</title> <title>问界生态系数分析 - 问界门店运营数据分析平台</title>
<link rel="stylesheet" href="/static/css/style.css"> <base href="/daw/">
<link rel="stylesheet" href="static/css/style.css">
</head> </head>
<body> <body>
<header> <header>
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DWS/DWM/DWA 任务 - 问界门店运营数据分析平台</title> <title>DWS/DWM/DWA 任务 - 问界门店运营数据分析平台</title>
<link rel="stylesheet" href="/static/css/style.css"> <base href="/daw/">
<link rel="stylesheet" href="static/css/style.css">
</head> </head>
<body> <body>
<header> <header>
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>鸿蒙生态分析 - 问界门店运营数据分析平台</title> <title>鸿蒙生态分析 - 问界门店运营数据分析平台</title>
<link rel="stylesheet" href="/static/css/style.css"> <base href="/daw/">
<link rel="stylesheet" href="static/css/style.css">
</head> </head>
<body> <body>
<header> <header>
......
...@@ -9,17 +9,17 @@ ...@@ -9,17 +9,17 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>问界门店运营数据分析平台</title> <title>问界门店运营数据分析平台</title>
<link rel="stylesheet" href="/static/css/style.css"> <link rel="stylesheet" href="./static/css/style.css">
</head> </head>
<body> <body>
<header> <header>
<div class="logo">问界运营分析平台</div> <div class="logo">问界运营分析平台</div>
<nav class="nav-links"> <nav class="nav-links">
<a class="nav-item active" href="/">首页</a> <a class="nav-item active" href="/">首页</a>
<a class="nav-item" href="/ods">ODS 同步任务</a> <a class="nav-item" href="./ods">ODS 同步任务</a>
<a class="nav-item" href="/dw">DWS/DWM/DWA 任务</a> <a class="nav-item" href="./dw">DWS/DWM/DWA 任务</a>
<a class="nav-item" href="/analysis">问界生态系数分析</a> <a class="nav-item" href="./analysis">问界生态系数分析</a>
<a class="nav-item" href="/harmony">鸿蒙生态分析</a> <a class="nav-item" href="./harmony">鸿蒙生态分析</a>
</nav> </nav>
<div class="user-info">管理员</div> <div class="user-info">管理员</div>
</header> </header>
...@@ -30,22 +30,22 @@ ...@@ -30,22 +30,22 @@
<p class="page-subtitle">欢迎使用问界门店运营数据分析平台,请选择功能模块</p> <p class="page-subtitle">欢迎使用问界门店运营数据分析平台,请选择功能模块</p>
<div class="nav-cards"> <div class="nav-cards">
<a class="nav-card" href="/ods"> <a class="nav-card" href="./ods">
<div class="nav-card-icon">&#128259;</div> <div class="nav-card-icon">&#128259;</div>
<h3>ODS 同步任务</h3> <h3>ODS 同步任务</h3>
<p>管理 ODS 层数据同步定时任务,查看执行历史与详情</p> <p>管理 ODS 层数据同步定时任务,查看执行历史与详情</p>
</a> </a>
<a class="nav-card" href="/dw"> <a class="nav-card" href="./dw">
<div class="nav-card-icon">&#9881;</div> <div class="nav-card-icon">&#9881;</div>
<h3>DWS/DWM/DWA 任务</h3> <h3>DWS/DWM/DWA 任务</h3>
<p>触发 DWS/DWM/DWA 各层数据加工,支持增量/全量/日期范围</p> <p>触发 DWS/DWM/DWA 各层数据加工,支持增量/全量/日期范围</p>
</a> </a>
<a class="nav-card" href="/analysis"> <a class="nav-card" href="./analysis">
<div class="nav-card-icon">&#128202;</div> <div class="nav-card-icon">&#128202;</div>
<h3>问界生态系数分析</h3> <h3>问界生态系数分析</h3>
<p>上传门店列表与主机厂数据,自动查询产值并计算生态系数</p> <p>上传门店列表与主机厂数据,自动查询产值并计算生态系数</p>
</a> </a>
<a class="nav-card" href="/harmony"> <a class="nav-card" href="./harmony">
<div class="nav-card-icon">&#127758;</div> <div class="nav-card-icon">&#127758;</div>
<h3>鸿蒙生态分析</h3> <h3>鸿蒙生态分析</h3>
<p>上传鸿蒙门店配置与产值表,计算渗透率达标系数与赔付金额</p> <p>上传鸿蒙门店配置与产值表,计算渗透率达标系数与赔付金额</p>
......
...@@ -4,17 +4,18 @@ ...@@ -4,17 +4,18 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ODS 同步任务 - 问界门店运营数据分析平台</title> <title>ODS 同步任务 - 问界门店运营数据分析平台</title>
<link rel="stylesheet" href="/static/css/style.css"> <base href="/daw/">
<link rel="stylesheet" href="static/css/style.css">
</head> </head>
<body> <body>
<header> <header>
<div class="logo">问界运营分析平台</div> <div class="logo">问界运营分析平台</div>
<nav class="nav-links"> <nav class="nav-links">
<a class="nav-item" href="/">首页</a> <a class="nav-item" href=".">首页</a>
<a class="nav-item active" href="/ods">ODS 同步任务</a> <a class="nav-item active" href="ods">ODS 同步任务</a>
<a class="nav-item" href="/dw">DWS/DWM/DWA 任务</a> <a class="nav-item" href="dw">DWS/DWM/DWA 任务</a>
<a class="nav-item" href="/analysis">问界生态系数分析</a> <a class="nav-item" href="analysis">问界生态系数分析</a>
<a class="nav-item" href="/harmony">鸿蒙生态分析</a> <a class="nav-item" href="harmony">鸿蒙生态分析</a>
</nav> </nav>
<div class="user-info">管理员</div> <div class="user-info">管理员</div>
</header> </header>
...@@ -77,13 +78,13 @@ ...@@ -77,13 +78,13 @@
</div> </div>
</div> </div>
<script src="/static/js/common.js"></script> <script src="static/js/common.js"></script>
<script> <script>
const ODS_FILTER = item => item.task_id.includes('ods'); const ODS_FILTER = item => item.task_id.includes('ods');
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
try { try {
const res = await fetch('/api/etl/scheduler-config?task_id=sync_ods_data'); const res = await fetch('api/etl/scheduler-config?task_id=sync_ods_data');
const config = await res.json(); const config = await res.json();
document.getElementById('conf-task-id').textContent = config.task_id || '-'; document.getElementById('conf-task-id').textContent = config.task_id || '-';
document.getElementById('conf-status').textContent = config.status || '-'; document.getElementById('conf-status').textContent = config.status || '-';
...@@ -100,7 +101,7 @@ ...@@ -100,7 +101,7 @@
btn.disabled = true; btn.disabled = true;
btn.textContent = '任务已启动...'; btn.textContent = '任务已启动...';
try { try {
const res = await fetch('/api/etl/run-ods', { method: 'POST' }); const res = await fetch('api/etl/run-ods', { method: 'POST' });
const data = await res.json(); const data = await res.json();
if (data.status === 'success') { if (data.status === 'success') {
setTimeout(() => { btn.disabled = false; btn.textContent = '立即同步 ODS'; }, 2000); setTimeout(() => { btn.disabled = false; btn.textContent = '立即同步 ODS'; }, 2000);
......
...@@ -44,7 +44,8 @@ app = FastAPI( ...@@ -44,7 +44,8 @@ app = FastAPI(
title="问界门店运营数据分析平台", title="问界门店运营数据分析平台",
description="支持 ODS/DWS/DWM/DWA 各层数据同步任务及分析模版展示", description="支持 ODS/DWS/DWM/DWA 各层数据同步任务及分析模版展示",
version="1.0.0", version="1.0.0",
lifespan=lifespan lifespan=lifespan,
root_path="/daw",
) )
# 挂载静态文件 # 挂载静态文件
......
...@@ -21,13 +21,13 @@ SRC = r'C:\Users\jiata\Desktop\问界生态系数生态(生态6.26-7.6&7.1-7.6 ...@@ -21,13 +21,13 @@ SRC = r'C:\Users\jiata\Desktop\问界生态系数生态(生态6.26-7.6&7.1-7.6
# 自动递增三位序号: 问界门店数据模板001.xlsx, 002.xlsx, ... # 自动递增三位序号: 问界门店数据模板001.xlsx, 002.xlsx, ...
import os, glob import os, glob
max_no = 0 max_no = 0
for f in glob.glob('app/templates/问界门店数据模板[0-9][0-9][0-9].xlsx'): for f in glob.glob('app/templates/xlsx/问界门店数据模板[0-9][0-9][0-9].xlsx'):
try: try:
no = int(os.path.splitext(os.path.basename(f))[0][-3:]) no = int(os.path.splitext(os.path.basename(f))[0][-3:])
max_no = max(max_no, no) max_no = max(max_no, no)
except ValueError: except ValueError:
pass pass
OUT = f'app/templates/问界门店数据模板{max_no + 1:03d}.xlsx' OUT = f'app/templates/xlsx/问界门店数据模板{max_no + 1:03d}.xlsx'
# ── 1. 读取主表门店信息 ── # ── 1. 读取主表门店信息 ──
wb = load_workbook(SRC, data_only=True) wb = load_workbook(SRC, data_only=True)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!