Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
data_report
/
daw
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 5b71ebc5
authored
Jun 26, 2026
by
江名洋
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat(analysis): 门店数据改为可选并支持指定文件下载
1 parent
009ed313
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
13 deletions
app/api/endpoints.py
app/services/analysis_service.py
app/static/js/app.js
app/templates/index.html
app/api/endpoints.py
View file @
5b71ebc
...
...
@@ -282,7 +282,12 @@ async def analysis_generate(
global
_analysis_store_file
,
_analysis_ecology_factory_file
,
_analysis_nature_factory_file
if
not
_analysis_store_file
or
not
os
.
path
.
exists
(
_analysis_store_file
):
raise
HTTPException
(
status_code
=
400
,
detail
=
"请先上传门店列表文件"
)
# 未上传时使用模板库中的默认门店数据
default_store
=
os
.
path
.
join
(
"app"
,
"templates"
,
"门店数据-模板.xlsx"
)
if
os
.
path
.
exists
(
default_store
):
_analysis_store_file
=
default_store
else
:
raise
HTTPException
(
status_code
=
400
,
detail
=
"请先上传门店列表文件"
)
ecology_factory
=
None
nature_factory
=
None
...
...
@@ -316,7 +321,7 @@ async def analysis_generate(
"status"
:
"success"
,
"message"
:
"分析报表已生成"
,
"file_path"
:
output_path
,
"download_url"
:
"api/analysis/download
"
,
"download_url"
:
f
"api/analysis/download?file={os.path.basename(output_path)}
"
,
"ecology_store_count"
:
len
(
ecology_stores
),
"nature_store_count"
:
len
(
nature_stores
),
"ecology_factory_sheets"
:
list
(
ecology_factory
.
keys
())
if
ecology_factory
else
[],
...
...
@@ -328,9 +333,19 @@ async def analysis_generate(
@router.get
(
"/analysis/download"
)
async
def
analysis_download
():
"""下载生成的分析报表"""
async
def
analysis_download
(
file
:
str
=
Query
(
None
)
):
"""下载生成的分析报表
,支持指定文件名
"""
output_dir
=
"temp_uploads"
if
file
:
file_path
=
os
.
path
.
join
(
output_dir
,
file
)
if
not
os
.
path
.
exists
(
file_path
):
raise
HTTPException
(
status_code
=
404
,
detail
=
"指定的报表文件不存在"
)
return
FileResponse
(
file_path
,
filename
=
file
,
media_type
=
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)
# 无指定时返回最新文件
output_files
=
sorted
(
[
f
for
f
in
os
.
listdir
(
output_dir
)
if
f
.
startswith
(
"问界生态系数分析"
)
and
f
.
endswith
(
".xlsx"
)],
key
=
lambda
f
:
os
.
path
.
getmtime
(
os
.
path
.
join
(
output_dir
,
f
)),
...
...
app/services/analysis_service.py
View file @
5b71ebc
...
...
@@ -626,10 +626,12 @@ class AnalysisService:
output_dir
=
"temp_uploads"
os
.
makedirs
(
output_dir
,
exist_ok
=
True
)
from
datetime
import
datetime
ts
=
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d_
%
H
%
M
%
S_
%
f"
)[:
18
]
eco_label
=
ecology_start
.
replace
(
"-"
,
""
)
if
ecology_start
else
""
nat_label
=
nature_start
.
replace
(
"-"
,
""
)
if
nature_start
else
""
safe_label
=
f
"生态{eco_label}_自然{nat_label}"
[:
7
0
]
output_path
=
os
.
path
.
join
(
output_dir
,
f
"问界生态系数分析_{safe_label}.xlsx"
)
safe_label
=
f
"生态{eco_label}_自然{nat_label}"
[:
5
0
]
output_path
=
os
.
path
.
join
(
output_dir
,
f
"问界生态系数分析_{safe_label}
_{ts}
.xlsx"
)
shutil
.
copy2
(
TEMPLATE_FILE
,
output_path
)
wb
=
load_workbook
(
output_path
)
...
...
app/static/js/app.js
View file @
5b71ebc
...
...
@@ -354,10 +354,6 @@ document.addEventListener('DOMContentLoaded', () => {
const hasEcology = ecologyFactoryInput && ecologyFactoryInput.files.length > 0;
const hasNature = natureFactoryInput && natureFactoryInput.files.length > 0;
if (!hasStore) {
alert('请先上传门店列表文件(步骤1)');
return;
}
if (!hasEcology && !hasNature) {
alert('请至少上传一个主机厂数据文件(步骤2或步骤3)');
return;
...
...
@@ -368,7 +364,7 @@ document.addEventListener('DOMContentLoaded', () => {
try {
const uploadForm = new FormData();
uploadForm.append('store_file', storeFileInput.files[0]);
if (hasStore)
uploadForm.append('store_file', storeFileInput.files[0]);
if (hasEcology) uploadForm.append('ecology_factory_file', ecologyFactoryInput.files[0]);
if (hasNature) uploadForm.append('nature_factory_file', natureFactoryInput.files[0]);
...
...
app/templates/index.html
View file @
5b71ebc
...
...
@@ -96,13 +96,13 @@
<!-- 数据分析部分 -->
<div
id=
"data-analysis-section"
style=
"display:none;"
>
<div
style=
"display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px;"
>
<!-- 步骤1: 上传门店列表 -->
<!-- 步骤1: 上传门店列表
(可选,未上传时使用默认模板)
-->
<div
style=
"background: #f8f9fa; padding: 8px 16px; border-radius: 6px; border: 1px solid #e8e8e8; display: flex; align-items: center; gap: 16px;"
>
<span
style=
"font-size:14px; font-weight:600; color:#333; white-space:nowrap;"
>
步骤1: 门店列表
</span>
<div
id=
"store-drop-zone"
style=
"flex:1; border: 1px dashed #d9d9d9; padding: 6px 12px; border-radius: 4px; cursor: pointer; background: #fff; display: flex; align-items: center; gap: 8px;"
>
<input
type=
"file"
id=
"store-file-input"
style=
"display:none;"
accept=
".xlsx,.xls"
>
<span
style=
"font-size:16px;"
>
🏪
</span>
<p
id=
"store-file-name"
style=
"margin:0; font-size:13px; color:#999;"
>
点击选择门店列表文件
</p>
<p
id=
"store-file-name"
style=
"margin:0; font-size:13px; color:#999;"
>
可选:点击选择门店列表文件(不选则使用系统默认模板)
</p>
</div>
<a
href=
"api/analysis/template/store"
style=
"font-size:12px; color:#1890ff; text-decoration:none; white-space:nowrap;"
>
📥 下载模板
</a>
</div>
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment