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 dcdd35d0
authored
Jul 14, 2026
by
江名洋
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat(analysis): 新增分析页面历史批次与预览功能
1 parent
910a19bf
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
798 additions
and
140 deletions
__pycache__/main.cpython-313.pyc
app/api/__pycache__/endpoints.cpython-313.pyc
app/api/endpoints.py
app/services/upload_service.py
app/templates/analysis.html
app/templates/data_import.html
sql/init_upload_tables.sql
temp_uploads/问界分析_生态(0626-0705)_自然(0701-0705)_1784017806.xlsx
__pycache__/main.cpython-313.pyc
View file @
dcdd35d
No preview for this file type
app/api/__pycache__/endpoints.cpython-313.pyc
View file @
dcdd35d
No preview for this file type
app/api/endpoints.py
View file @
dcdd35d
...
...
@@ -301,6 +301,58 @@ async def analysis_upload(
return
result
@router.post
(
"/analysis/save-batch"
)
async
def
analysis_save_batch
(
file_type
:
str
=
Form
(
...
),
# "store", "ecology", "nature"
file
:
UploadFile
=
File
(
...
),
period_start
:
str
=
Form
(
""
),
period_end
:
str
=
Form
(
""
),
period_type
:
str
=
Form
(
""
),
# ecology / nature,仅 oem 使用
):
"""将分析页面上传的文件保存为历史批次,便于下次复用"""
if
file_type
not
in
(
"store"
,
"ecology"
,
"nature"
):
raise
HTTPException
(
status_code
=
400
,
detail
=
"file_type 仅支持 store/ecology/nature"
)
if
not
file
.
filename
:
raise
HTTPException
(
status_code
=
400
,
detail
=
"请选择文件"
)
file_path
=
os
.
path
.
join
(
UPLOAD_DIR
,
f
"_save_batch_{file.filename}"
)
try
:
with
open
(
file_path
,
"wb"
)
as
f
:
shutil
.
copyfileobj
(
file
.
file
,
f
)
file_size
=
os
.
path
.
getsize
(
file_path
)
if
file_type
==
"store"
:
from
app.services.upload_service
import
import_store_guarantee
result
=
import_store_guarantee
(
file_path
=
file_path
,
original_filename
=
file
.
filename
,
brand
=
"问界"
,
file_size
=
file_size
,
)
else
:
from
app.services.upload_service
import
import_oem_delivery
pt
=
period_type
or
(
"ecology"
if
file_type
==
"ecology"
else
"nature"
)
result
=
import_oem_delivery
(
file_path
=
file_path
,
original_filename
=
file
.
filename
,
brand
=
"问界"
,
data_period_start
=
period_start
or
""
,
data_period_end
=
period_end
or
""
,
period_type
=
pt
,
file_size
=
file_size
,
)
return
{
"status"
:
"success"
,
"data"
:
result
}
except
ValueError
as
e
:
raise
HTTPException
(
status_code
=
400
,
detail
=
str
(
e
))
except
Exception
as
e
:
logger
.
error
(
f
"Save batch failed: {e}"
,
exc_info
=
True
)
raise
HTTPException
(
status_code
=
500
,
detail
=
f
"保存批次失败: {str(e)}"
)
finally
:
if
os
.
path
.
exists
(
file_path
):
os
.
remove
(
file_path
)
@router.post
(
"/analysis/generate"
)
async
def
analysis_generate
(
background_tasks
:
BackgroundTasks
,
...
...
@@ -393,6 +445,108 @@ async def analysis_download(file: str = Query(None)):
)
# ==================== 分析预览接口 ====================
@router.post
(
"/analysis/preview-file"
)
async
def
analysis_preview_file
(
file_type
:
str
=
Form
(
...
),
# "store" or "factory"
file
:
UploadFile
=
File
(
...
),
):
"""上传分析文件并返回解析后的预览数据"""
file_path
=
os
.
path
.
join
(
UPLOAD_DIR
,
f
"_preview_{file.filename}"
)
try
:
with
open
(
file_path
,
"wb"
)
as
f
:
shutil
.
copyfileobj
(
file
.
file
,
f
)
if
file_type
==
"store"
:
df
=
AnalysisService
.
read_store_list
(
file_path
)
else
:
data
=
AnalysisService
.
read_factory_data
(
file_path
)
sheet_names
=
list
(
data
.
keys
())
if
sheet_names
:
df
=
data
[
sheet_names
[
0
]]
else
:
df
=
pd
.
DataFrame
()
import
pandas
as
pd
rows
=
df
.
head
(
100
)
.
fillna
(
""
)
.
to_dict
(
orient
=
"records"
)
columns
=
list
(
df
.
columns
)
return
{
"status"
:
"success"
,
"data"
:
{
"columns"
:
columns
,
"rows"
:
rows
,
"total"
:
len
(
df
)}}
except
Exception
as
e
:
logger
.
error
(
f
"Analysis preview file failed: {e}"
,
exc_info
=
True
)
raise
HTTPException
(
status_code
=
500
,
detail
=
f
"文件解析失败: {str(e)}"
)
finally
:
if
os
.
path
.
exists
(
file_path
):
os
.
remove
(
file_path
)
@router.get
(
"/analysis/batch-data"
)
async
def
analysis_batch_data
(
batch_no
:
str
=
Query
(
...
)):
"""获取历史批次数据用于右侧预览"""
import
decimal
import
datetime
as
dt
from
app.services.upload_service
import
_get_conn
conn
=
_get_conn
()
try
:
with
conn
.
cursor
()
as
cur
:
cur
.
execute
(
"""SELECT id, batch_no, data_type FROM upload_batch
WHERE batch_no =
%
s AND status != 3"""
,
(
batch_no
,),
)
batch
=
cur
.
fetchone
()
if
not
batch
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"批次不存在"
)
batch_id
=
batch
[
"id"
]
data_type
=
batch
[
"data_type"
]
if
data_type
==
"store_guarantee"
:
cur
.
execute
(
"""SELECT store_name, brand, guarantee_target, province, city,
direct_sale, area_supervision, flight_supervision, online_supervision,
guarantee_type, special_case_1, special_case_2,
ew_conversion_rate, ax_conversion_rate, battery_conversion_rate,
ew_compensation, ax_compensation, battery_compensation,
guarantee_end_date
FROM store_guarantee_config WHERE batch_id =
%
s"""
,
(
batch_id
,),
)
else
:
cur
.
execute
(
"""SELECT store_code, store_name, brand, province, city,
delivery_count, ew_purchase_count, ax_purchase_count,
battery_purchase_count, tire_purchase_count
FROM oem_delivery_data WHERE batch_id =
%
s"""
,
(
batch_id
,),
)
rows
=
cur
.
fetchall
()
columns
=
list
(
rows
[
0
]
.
keys
())
if
rows
else
[]
clean_rows
=
[]
for
r
in
rows
:
clean
=
{}
for
k
,
v
in
r
.
items
():
if
isinstance
(
v
,
decimal
.
Decimal
):
clean
[
k
]
=
float
(
v
)
elif
isinstance
(
v
,
(
dt
.
date
,
dt
.
datetime
)):
clean
[
k
]
=
str
(
v
)
elif
v
is
None
:
clean
[
k
]
=
""
else
:
clean
[
k
]
=
v
clean_rows
.
append
(
clean
)
return
{
"status"
:
"success"
,
"data"
:
{
"columns"
:
columns
,
"rows"
:
clean_rows
,
"total"
:
len
(
rows
)},
}
finally
:
conn
.
close
()
# ==================== 鸿蒙生态分析接口 ====================
@router.get
(
"/harmony/template/{template_type}"
)
...
...
@@ -758,13 +912,16 @@ async def upload_oem_delivery(
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}"
)
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"
)
...
...
@@ -776,6 +933,7 @@ async def upload_oem_delivery(
brand
=
brand
,
data_period_start
=
period_start
,
data_period_end
=
period_end
,
period_type
=
period_type
,
file_size
=
file_size
,
)
return
{
"status"
:
"success"
,
"data"
:
result
}
...
...
@@ -790,10 +948,11 @@ async def upload_oem_delivery(
async
def
get_import_history
(
brand
:
Optional
[
str
]
=
Query
(
None
),
data_type
:
Optional
[
str
]
=
Query
(
None
),
period_type
:
Optional
[
str
]
=
Query
(
None
),
):
"""获取上传批次历史列表"""
try
:
rows
=
get_upload_history
(
brand
=
brand
,
data_type
=
data_type
)
rows
=
get_upload_history
(
brand
=
brand
,
data_type
=
data_type
,
period_type
=
period_type
)
return
{
"status"
:
"success"
,
"data"
:
rows
}
except
Exception
as
e
:
logger
.
error
(
f
"Get upload history failed: {e}"
,
exc_info
=
True
)
...
...
app/services/upload_service.py
View file @
dcdd35d
...
...
@@ -334,9 +334,12 @@ def parse_harmony_oem_delivery(file_path: str) -> List[Dict]:
rows
=
[]
for
_
,
r
in
df
.
iterrows
():
store_name
=
str
(
r
.
get
(
"门店名"
,
""
))
.
strip
()
if
pd
.
notna
(
r
.
get
(
"门店名"
))
else
""
if
not
store_name
:
store_name
=
str
(
r
.
get
(
"用户中心门店名"
,
""
))
.
strip
()
if
pd
.
notna
(
r
.
get
(
"用户中心门店名"
))
else
""
rows
.
append
({
"store_code"
:
str
(
r
.
get
(
"门店编号"
,
""
))
if
pd
.
notna
(
r
.
get
(
"门店编号"
))
else
""
,
"store_name"
:
st
r
(
r
.
get
(
"用户中心门店名"
,
r
.
get
(
"门店名"
,
""
)))
.
strip
()
if
pd
.
notna
(
r
.
get
(
"用户中心门店名"
,
r
.
get
(
"门店名"
)))
else
""
,
"store_name"
:
st
ore_name
,
"merchant_id"
:
None
,
# 后续通过 store_code/name 匹配
"province"
:
str
(
r
.
get
(
"省份"
,
""
))
if
pd
.
notna
(
r
.
get
(
"省份"
))
else
None
,
"city"
:
str
(
r
.
get
(
"城市"
,
""
))
if
pd
.
notna
(
r
.
get
(
"城市"
))
else
None
,
...
...
@@ -681,13 +684,14 @@ def import_oem_delivery(
brand
:
str
,
data_period_start
:
str
,
data_period_end
:
str
,
period_type
:
str
=
""
,
uploaded_by
:
Optional
[
str
]
=
None
,
file_size
:
int
=
0
,
original_filename
:
str
=
""
,
)
->
Dict
:
"""
导入主机厂交付数据到 oem_delivery_data 表。
同一 (brand, data_period_start, data_period_end) 覆盖更新。
同一 (brand, data_period_start, data_period_end
, period_type
) 覆盖更新。
"""
conn
=
_get_conn
()
try
:
...
...
@@ -709,13 +713,14 @@ def import_oem_delivery(
file_name
=
original_filename
or
os
.
path
.
basename
(
file_path
)
with
conn
.
cursor
()
as
cur
:
# 1. 按 (brand + 数据周期) 排重:查找同周期已有批次
# 1. 按 (brand + 数据周期
+ period_type
) 排重:查找同周期已有批次
cur
.
execute
(
"""SELECT id, batch_no FROM upload_batch
WHERE brand =
%
s AND data_type = 'oem_delivery'
AND data_period_start =
%
s AND data_period_end =
%
s
AND IFNULL(period_type,'') =
%
s
AND status != 3"""
,
(
brand
,
data_period_start
,
data_period_end
)
(
brand
,
data_period_start
,
data_period_end
,
period_type
)
)
old_batches
=
cur
.
fetchall
()
...
...
@@ -744,10 +749,10 @@ def import_oem_delivery(
batch_no
=
_generate_batch_no
()
cur
.
execute
(
"""INSERT INTO upload_batch
(batch_no, brand, data_type, data_period_start, data_period_end,
(batch_no, brand, data_type,
period_type,
data_period_start, data_period_end,
file_name, file_size, row_count, uploaded_by)
VALUES (
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s)"""
,
(
batch_no
,
brand
,
"oem_delivery"
,
VALUES (
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s
,
%
s
)"""
,
(
batch_no
,
brand
,
"oem_delivery"
,
period_type
or
None
,
data_period_start
,
data_period_end
,
file_name
,
file_size
,
len
(
rows
),
uploaded_by
)
)
...
...
@@ -755,15 +760,15 @@ def import_oem_delivery(
# 2. 写入新数据
insert_sql
=
"""INSERT INTO oem_delivery_data
(batch_id, batch_no, brand, data_period_start, data_period_end,
(batch_id, batch_no, brand,
period_type,
data_period_start, data_period_end,
store_code, store_name, merchant_id,
province, city, enabler, delivery_count, ew_purchase_count,
battery_purchase_count, ax_purchase_count, tire_purchase_count,
excel_row_no, excel_sheet_name)
VALUES (
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s)"""
VALUES (
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s
,
%
s
)"""
for
idx
,
r
in
enumerate
(
rows
):
cur
.
execute
(
insert_sql
,
(
batch_id
,
batch_no
,
brand
,
batch_id
,
batch_no
,
brand
,
period_type
or
None
,
data_period_start
,
data_period_end
,
r
.
get
(
"store_code"
),
r
.
get
(
"store_name"
),
...
...
@@ -793,6 +798,7 @@ def import_oem_delivery(
"overwritten"
:
overwritten_count
if
old_batches
else
0
,
"is_overwrite"
:
bool
(
old_batches
),
"period"
:
f
"{data_period_start} ~ {data_period_end}"
,
"period_type"
:
period_type
or
""
,
"merchant_matched"
:
merchant_matched
,
}
except
Exception
:
...
...
@@ -802,12 +808,13 @@ def import_oem_delivery(
conn
.
close
()
def
get_upload_history
(
brand
:
Optional
[
str
]
=
None
,
data_type
:
Optional
[
str
]
=
None
)
->
List
[
Dict
]:
"""获取上传历史(批次列表)"""
def
get_upload_history
(
brand
:
Optional
[
str
]
=
None
,
data_type
:
Optional
[
str
]
=
None
,
period_type
:
Optional
[
str
]
=
None
)
->
List
[
Dict
]:
"""获取上传历史(批次列表),只返回有实际数据的批次"""
conn
=
_get_conn
()
try
:
with
conn
.
cursor
()
as
cur
:
conditions
=
[
"status != 3"
]
conditions
=
[
"status != 3"
,
"row_count > 0"
]
params
=
[]
if
brand
:
conditions
.
append
(
"brand =
%
s"
)
...
...
@@ -815,9 +822,12 @@ def get_upload_history(brand: Optional[str] = None, data_type: Optional[str] = N
if
data_type
:
conditions
.
append
(
"data_type =
%
s"
)
params
.
append
(
data_type
)
if
period_type
:
conditions
.
append
(
"IFNULL(period_type,'') =
%
s"
)
params
.
append
(
period_type
)
where
=
" AND "
.
join
(
conditions
)
cur
.
execute
(
f
"""SELECT batch_no, brand, data_type,
f
"""SELECT batch_no, brand, data_type,
period_type,
data_period_start, data_period_end,
file_name, file_size, row_count, status,
uploaded_by, created_at
...
...
app/templates/analysis.html
View file @
dcdd35d
...
...
@@ -5,6 +5,241 @@
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
问界生态系数分析 - 问界门店运营数据分析平台
</title>
<link
rel=
"stylesheet"
href=
"./static/css/style.css"
>
<style>
.analysis-layout
{
display
:
flex
;
gap
:
16px
;
height
:
calc
(
100vh
-
160px
);
min-height
:
600px
;
align-items
:
flex-start
;
overflow
:
hidden
;
}
.left-panel
{
width
:
420px
;
min-width
:
380px
;
height
:
100%
;
overflow-y
:
auto
;
scrollbar-width
:
none
;
/* Firefox 隐藏滚动条 */
-ms-overflow-style
:
none
;
/* IE/Edge 隐藏滚动条 */
display
:
flex
;
flex-direction
:
column
;
gap
:
10px
;
}
.left-panel
::-webkit-scrollbar
{
display
:
none
;
/* Chrome/Safari 隐藏滚动条 */
}
.right-panel
{
flex
:
1
;
height
:
100%
;
overflow
:
hidden
;
border
:
1px
solid
#e8e8e8
;
border-radius
:
6px
;
background
:
#fff
;
display
:
flex
;
flex-direction
:
column
;
}
.right-panel-header
{
padding
:
10px
16px
;
border-bottom
:
1px
solid
#e8e8e8
;
background
:
#fafafa
;
font-size
:
13px
;
color
:
#666
;
display
:
flex
;
align-items
:
center
;
justify-content
:
space-between
;
}
.right-panel-body
{
flex
:
1
;
overflow
:
auto
;
padding
:
0
;
}
.right-panel-empty
{
display
:
flex
;
align-items
:
center
;
justify-content
:
center
;
height
:
100%
;
color
:
#bbb
;
font-size
:
14px
;
}
.step-card
{
background
:
#f8f9fa
;
padding
:
10px
14px
;
border-radius
:
6px
;
border
:
1px
solid
#e8e8e8
;
}
.step-card.active
{
border-color
:
#1890ff
;
background
:
#f0f5ff
;
}
.step-title
{
font-size
:
14px
;
font-weight
:
600
;
color
:
#333
;
margin-bottom
:
8px
;
display
:
flex
;
align-items
:
center
;
gap
:
6px
;
}
.step-row
{
display
:
flex
;
align-items
:
center
;
gap
:
8px
;
margin-bottom
:
6px
;
}
.step-row
:last-child
{
margin-bottom
:
0
;
}
.step-select
{
flex
:
1
;
padding
:
5px
8px
;
border
:
1px
solid
#d9d9d9
;
border-radius
:
4px
;
font-size
:
12px
;
background
:
#fff
;
color
:
#333
;
}
.btn-save-batch
{
margin-top
:
6px
;
padding
:
4px
12px
;
border
:
1px
solid
#1890ff
;
border-radius
:
4px
;
background
:
#e6f7ff
;
color
:
#1890ff
;
font-size
:
12px
;
cursor
:
pointer
;
width
:
100%
;
}
.btn-save-batch
:hover
{
background
:
#bae7ff
;
}
.btn-save-batch
:disabled
{
opacity
:
0.5
;
cursor
:
not-allowed
;
}
.step-or
{
font-size
:
11px
;
color
:
#999
;
white-space
:
nowrap
;
}
.step-upload-zone
{
flex
:
1
;
border
:
1px
dashed
#d9d9d9
;
padding
:
5px
10px
;
border-radius
:
4px
;
cursor
:
pointer
;
background
:
#fff
;
font-size
:
12px
;
color
:
#999
;
white-space
:
nowrap
;
overflow
:
hidden
;
text-overflow
:
ellipsis
;
display
:
flex
;
align-items
:
center
;
gap
:
4px
;
}
.step-upload-zone.has-file
{
color
:
#52c41a
;
border-color
:
#52c41a
;
background
:
#f6ffed
;
}
.step-date-row
{
display
:
flex
;
align-items
:
center
;
gap
:
6px
;
margin-top
:
6px
;
}
.step-date-row
input
[
type
=
"date"
]
{
width
:
130px
;
padding
:
4px
6px
;
border
:
1px
solid
#d9d9d9
;
border-radius
:
4px
;
font-size
:
12px
;
}
.btn-download-tpl
{
font-size
:
11px
;
color
:
#1890ff
;
text-decoration
:
none
;
white-space
:
nowrap
;
cursor
:
pointer
;
}
.btn-download-tpl
:hover
{
text-decoration
:
underline
;
}
.btn-generate
{
padding
:
12px
48px
;
background
:
#1890ff
;
color
:
white
;
border
:
none
;
border-radius
:
6px
;
font-size
:
16px
;
cursor
:
pointer
;
transition
:
all
0.3s
;
width
:
100%
;
}
.btn-generate
:hover
{
background
:
#40a9ff
;
}
.btn-generate
:disabled
{
background
:
#d9d9d9
;
cursor
:
not-allowed
;
}
/* Preview Table */
.preview-table
{
width
:
100%
;
border-collapse
:
collapse
;
font-size
:
12px
;
white-space
:
nowrap
;
}
.preview-table
thead
{
position
:
sticky
;
top
:
0
;
z-index
:
2
;
}
.preview-table
th
{
background
:
#fafafa
;
padding
:
6px
10px
;
border-bottom
:
2px
solid
#e8e8e8
;
text-align
:
left
;
font-weight
:
600
;
color
:
#333
;
position
:
sticky
;
top
:
0
;
}
.preview-table
td
{
padding
:
5px
10px
;
border-bottom
:
1px
solid
#f0f0f0
;
color
:
#555
;
max-width
:
200px
;
overflow
:
hidden
;
text-overflow
:
ellipsis
;
}
.preview-table
tr
:hover
td
{
background
:
#e6f7ff
;
}
/* Result */
.result-box
{
padding
:
16px
;
border-radius
:
8px
;
text-align
:
center
;
display
:
none
;
}
.result-box.success
{
display
:
block
;
background
:
#f6ffed
;
border
:
1px
solid
#b7eb8f
;
}
.result-box.error
{
display
:
block
;
background
:
#fff2f0
;
border
:
1px
solid
#ffccc7
;
}
.btn-download
{
display
:
inline-block
;
padding
:
10px
32px
;
background
:
#52c41a
;
color
:
white
;
border
:
none
;
border-radius
:
4px
;
font-size
:
14px
;
text-decoration
:
none
;
cursor
:
pointer
;
margin-top
:
10px
;
}
@media
(
max-width
:
900px
)
{
.analysis-layout
{
flex-direction
:
column
;
height
:
auto
;
}
.left-panel
{
width
:
100%
;
min-width
:
0
;
}
.right-panel
{
min-height
:
400px
;
}
}
</style>
</head>
<body>
<header>
...
...
@@ -26,73 +261,111 @@
<div
class=
"card"
>
<h2
id=
"content-title"
>
问界生态系数分析
</h2>
<div
id=
"content-body"
>
<div
class=
"analysis-layout"
>
<!-- 数据分析部分 -->
<div
id=
"data-analysis-section"
>
<div
style=
"display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px;"
>
<!-- 步骤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>
<!-- ============ 左侧表单 ============ -->
<div
class=
"left-panel"
>
<!-- 步骤1: 门店列表 -->
<div
class=
"step-card"
id=
"step1-card"
>
<div
class=
"step-title"
>
①
步骤1: 门店列表
</div>
<div
class=
"step-row"
>
<select
class=
"step-select"
id=
"store-batch-select"
onchange=
"onStoreBatchSelect()"
>
<option
value=
""
>
-- 选择历史批次 --
</option>
</select>
</div>
<div
class=
"step-row"
>
<span
class=
"step-or"
>
或
</span>
<div
class=
"step-upload-zone"
id=
"store-drop-zone"
onclick=
"document.getElementById('store-file-input').click()"
>
<input
type=
"file"
id=
"store-file-input"
style=
"display:none;"
accept=
".xlsx,.xls"
onchange=
"onStoreFileChange()"
>
📁
<span
id=
"store-file-name"
>
点击上传门店列表文件
</span>
</div>
<a
class=
"btn-download-tpl"
href=
"./api/analysis/template/store"
>
📥
模板
</a>
</div>
<
a
href=
"./api/analysis/template/store"
style=
"font-size:12px; color:#1890ff; text-decoration:none; white-space:nowrap;"
>
📥
下载模板
</a
>
<
button
class=
"btn-save-batch"
id=
"btn-save-store"
style=
"display:none;"
onclick=
"saveBatch('store')"
>
💾
保存为历史批次
</button
>
</div>
<!-- 步骤2: 生态主机厂数据 -->
<div
style=
"background: #f8f9fa; padding: 8px 16px; border-radius: 6px; border: 1px solid #e8e8e8; display: flex; align-items: center; gap: 12px;"
>
<span
style=
"font-size:14px; font-weight:600; color:#333; white-space:nowrap;"
>
步骤2: 生态(26日)
</span>
<div
id=
"ecology-drop-zone"
style=
"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=
"ecology-factory-input"
style=
"display:none;"
accept=
".xlsx,.xls"
>
<span
style=
"font-size:16px;"
>
🏭
</span>
<p
id=
"ecology-file-name"
style=
"margin:0; font-size:12px; color:#999;"
>
点击选择生态主机厂数据
</p>
<!-- 步骤2: 生态(26日) -->
<div
class=
"step-card"
id=
"step2-card"
>
<div
class=
"step-title"
>
②
步骤2: 生态(26日)
</div>
<div
class=
"step-row"
>
<select
class=
"step-select"
id=
"ecology-batch-select"
onchange=
"onFactoryBatchSelect('ecology')"
>
<option
value=
""
>
-- 选择历史批次 --
</option>
</select>
</div>
<div
class=
"step-row"
>
<span
class=
"step-or"
>
或
</span>
<div
class=
"step-upload-zone"
id=
"ecology-drop-zone"
onclick=
"document.getElementById('ecology-factory-input').click()"
>
<input
type=
"file"
id=
"ecology-factory-input"
style=
"display:none;"
accept=
".xlsx,.xls"
onchange=
"onFactoryFileChange('ecology')"
>
📁
<span
id=
"ecology-file-name"
>
点击上传生态主机厂数据
</span>
</div>
<a
class=
"btn-download-tpl"
href=
"./api/analysis/template/factory"
>
📥
模板
</a>
</div>
<input
type=
"date"
id=
"ecology-start-date"
style=
"width:130px; padding: 4px 6px; border: 1px solid #d9d9d9; border-radius: 4px; font-size:12px;"
placeholder=
"开始"
>
<span
style=
"color:#999; font-size:12px;"
>
~
</span>
<input
type=
"date"
id=
"ecology-end-date"
style=
"width:130px; padding: 4px 6px; border: 1px solid #d9d9d9; border-radius: 4px; font-size:12px;"
placeholder=
"结束"
>
<div
class=
"step-date-row"
>
<input
type=
"date"
id=
"ecology-start-date"
title=
"开始日期"
>
<span
style=
"font-size:12px;color:#999;"
>
~
</span>
<input
type=
"date"
id=
"ecology-end-date"
title=
"结束日期"
>
</div>
<button
class=
"btn-save-batch"
id=
"btn-save-ecology"
style=
"display:none;"
onclick=
"saveBatch('ecology')"
>
💾
保存为历史批次
</button>
</div>
<!-- 步骤3: 自然月主机厂数据 -->
<div
style=
"background: #f8f9fa; padding: 8px 16px; border-radius: 6px; border: 1px solid #e8e8e8; display: flex; align-items: center; gap: 12px;"
>
<span
style=
"font-size:14px; font-weight:600; color:#333; white-space:nowrap;"
>
步骤3: 自然月(1日)
</span>
<div
id=
"nature-drop-zone"
style=
"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=
"nature-factory-input"
style=
"display:none;"
accept=
".xlsx,.xls"
>
<span
style=
"font-size:16px;"
>
📅
</span>
<p
id=
"nature-file-name"
style=
"margin:0; font-size:12px; color:#999;"
>
点击选择自然月主机厂数据
</p>
<!-- 步骤3: 自然月(1日) -->
<div
class=
"step-card"
id=
"step3-card"
>
<div
class=
"step-title"
>
③
步骤3: 自然月(1日)
</div>
<div
class=
"step-row"
>
<select
class=
"step-select"
id=
"nature-batch-select"
onchange=
"onFactoryBatchSelect('nature')"
>
<option
value=
""
>
-- 选择历史批次 --
</option>
</select>
</div>
<div
class=
"step-row"
>
<span
class=
"step-or"
>
或
</span>
<div
class=
"step-upload-zone"
id=
"nature-drop-zone"
onclick=
"document.getElementById('nature-factory-input').click()"
>
<input
type=
"file"
id=
"nature-factory-input"
style=
"display:none;"
accept=
".xlsx,.xls"
onchange=
"onFactoryFileChange('nature')"
>
📁
<span
id=
"nature-file-name"
>
点击上传自然月主机厂数据
</span>
</div>
<a
class=
"btn-download-tpl"
href=
"./api/analysis/template/factory"
>
📥
模板
</a>
</div>
<div
class=
"step-date-row"
>
<input
type=
"date"
id=
"nature-start-date"
title=
"开始日期"
>
<span
style=
"font-size:12px;color:#999;"
>
~
</span>
<input
type=
"date"
id=
"nature-end-date"
title=
"结束日期"
>
</div>
<input
type=
"date"
id=
"nature-start-date"
style=
"width:130px; padding: 4px 6px; border: 1px solid #d9d9d9; border-radius: 4px; font-size:12px;"
placeholder=
"开始"
>
<span
style=
"color:#999; font-size:12px;"
>
~
</span>
<input
type=
"date"
id=
"nature-end-date"
style=
"width:130px; padding: 4px 6px; border: 1px solid #d9d9d9; border-radius: 4px; font-size:12px;"
placeholder=
"结束"
>
<button
class=
"btn-save-batch"
id=
"btn-save-nature"
style=
"display:none;"
onclick=
"saveBatch('nature')"
>
💾
保存为历史批次
</button>
</div>
</div>
<!-- 步骤4: 生成报表 -->
<div
style=
"text-align: center; margin: 20px 0;"
>
<button
id=
"btn-generate-report"
style=
"padding: 12px 48px; background: #1890ff; color: white; border: none; border-radius: 6px; font-size: 16px; cursor: pointer; transition: all 0.3s;"
>
🚀
开始生成分析报表
</button>
<p
style=
"font-size:12px; color:#999; margin-top:8px;"
>
门店按兜底截止日期分组:月底/25日→生态数据sheet,其余→自然月sheet
</p>
<p
style=
"font-size:11px; color:#faad14;"
>
📌
使用模板: 门店数据-问界-模板(最新序号)
</p>
</div>
<!-- 生成按钮 -->
<div
style=
"text-align:center; margin-top:4px;"
>
<button
class=
"btn-generate"
id=
"btn-generate-report"
>
🚀
开始生成分析报表
</button>
<p
style=
"font-size:11px;color:#999;margin-top:4px;"
>
门店按兜底截止日期分组:月底/25日→生态数据sheet,其余→自然月sheet
</p>
</div>
<!-- 生成结果提示 -->
<div
id=
"analysis-result"
style=
"display:none; background: #f6ffed; border: 1px solid #b7eb8f; padding: 20px; border-radius: 8px; text-align: center;"
>
<h3
style=
"color:#52c41a; margin:0 0 10px;"
>
✅
报表生成成功
</h3>
<div
id=
"analysis-result-info"
style=
"font-size:13px; color:#666; margin-bottom:15px;"
></div>
<a
id=
"btn-download-report"
href=
"./api/analysis/download"
style=
"display:inline-block; padding: 10px 32px; background: #52c41a; color: white; border: none; border-radius: 4px; font-size: 14px; text-decoration: none; cursor: pointer;"
>
📥
下载分析报表
</a>
<!-- 生成结果 -->
<div
class=
"result-box"
id=
"analysis-result"
>
<h3
style=
"color:#52c41a;margin:0 0 6px;"
>
✅
报表生成成功
</h3>
<div
style=
"font-size:12px;color:#666;margin-bottom:10px;"
id=
"analysis-result-info"
></div>
<a
class=
"btn-download"
id=
"btn-download-report"
href=
"#"
>
📥
下载分析报表
</a>
</div>
<div
class=
"result-box"
id=
"analysis-error"
>
<h3
style=
"color:#f5222d;margin:0 0 6px;"
>
❌
报表生成失败
</h3>
<p
style=
"margin:0;color:#666;font-size:12px;"
id=
"analysis-error-msg"
></p>
</div>
</div>
<div
id=
"analysis-error"
style=
"display:none; background: #fff2f0; border: 1px solid #ffccc7; padding: 20px; border-radius: 8px; text-align: center;"
>
<h3
style=
"color:#f5222d; margin:0 0 10px;"
>
❌
报表生成失败
</h3>
<p
id=
"analysis-error-msg"
style=
"margin:0; color:#666;"
></p>
<!-- ============ 右侧预览 ============ -->
<div
class=
"right-panel"
>
<div
class=
"right-panel-header"
>
<span
id=
"preview-title"
>
📊
数据预览
</span>
<span
id=
"preview-count"
style=
"font-size:11px;color:#999;"
></span>
</div>
<div
class=
"right-panel-body"
id=
"preview-body"
>
<div
class=
"right-panel-empty"
id=
"preview-empty"
>
请在左侧选择历史批次或上传文件,数据将在此处预览
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
...
...
@@ -100,6 +373,7 @@
<script>
(
function
(){
var
p
=
window
.
location
.
pathname
;
if
(
p
.
endsWith
(
'/'
))
p
=
p
.
slice
(
0
,
-
1
);
var
i
=
p
.
lastIndexOf
(
'/'
);
window
.
API_BASE
=
p
.
substring
(
0
,
i
)
+
'/api'
;})();
document
.
addEventListener
(
'DOMContentLoaded'
,
()
=>
{
const
fmt
=
d
=>
`
${
d
.
getFullYear
()}
-
${
String
(
d
.
getMonth
()
+
1
).
padStart
(
2
,
'0'
)}
-
${
String
(
d
.
getDate
()).
padStart
(
2
,
'0'
)}
`
;
const
now
=
new
Date
();
...
...
@@ -108,103 +382,127 @@
const
startStr
=
fmt
(
lastMonth26
);
const
firstOfMonth
=
fmt
(
new
Date
(
now
.
getFullYear
(),
now
.
getMonth
(),
1
));
// 默认日期
const
ecoStart
=
document
.
getElementById
(
'ecology-start-date'
);
const
ecoEnd
=
document
.
getElementById
(
'ecology-end-date'
);
if
(
ecoStart
&&
!
ecoStart
.
value
)
ecoStart
.
value
=
startStr
;
if
(
ecoEnd
&&
!
ecoEnd
.
value
)
ecoEnd
.
value
=
todayStr
;
const
natStart
=
document
.
getElementById
(
'nature-start-date'
);
const
natEnd
=
document
.
getElementById
(
'nature-end-date'
);
if
(
natStart
&&
!
natStart
.
value
)
natStart
.
value
=
firstOfMonth
;
if
(
natEnd
&&
!
natEnd
.
value
)
natEnd
.
value
=
todayStr
;
// 门店列表上传
const
storeDropZone
=
document
.
getElementById
(
'store-drop-zone'
);
const
storeFileInput
=
document
.
getElementById
(
'store-file-input'
);
if
(
storeDropZone
)
{
storeDropZone
.
addEventListener
(
'click'
,
()
=>
storeFileInput
.
click
());
storeFileInput
.
addEventListener
(
'change'
,
()
=>
{
if
(
storeFileInput
.
files
.
length
>
0
)
{
document
.
getElementById
(
'store-file-name'
).
textContent
=
'✅ 已选择: '
+
storeFileInput
.
files
[
0
].
name
;
document
.
getElementById
(
'store-file-name'
).
style
.
color
=
'#52c41a'
;
}
});
}
// 加载历史批次下拉
loadBatchOptions
();
// 生态主机厂数据上传
const
ecologyDropZone
=
document
.
getElementById
(
'ecology-drop-zone'
);
const
ecologyFactoryInput
=
document
.
getElementById
(
'ecology-factory-input'
);
if
(
ecologyDropZone
&&
ecologyFactoryInput
)
{
ecologyDropZone
.
addEventListener
(
'click'
,
()
=>
ecologyFactoryInput
.
click
());
ecologyFactoryInput
.
addEventListener
(
'change'
,
()
=>
{
if
(
ecologyFactoryInput
.
files
.
length
>
0
)
{
document
.
getElementById
(
'ecology-file-name'
).
textContent
=
'✅ 已选择: '
+
ecologyFactoryInput
.
files
[
0
].
name
;
document
.
getElementById
(
'ecology-file-name'
).
style
.
color
=
'#52c41a'
;
}
});
}
// ========== 步骤1: 门店列表 ==========
window
.
onStoreBatchSelect
=
async
function
()
{
const
sel
=
document
.
getElementById
(
'store-batch-select'
);
if
(
!
sel
.
value
)
return
;
highlightStep
(
'step1-card'
);
await
loadBatchPreview
(
sel
.
value
,
'门店列表 - 历史批次'
);
};
// 自然月主机厂数据上传
const
natureDropZone
=
document
.
getElementById
(
'nature-drop-zone'
);
const
natureFactoryInput
=
document
.
getElementById
(
'nature-factory-input'
);
if
(
natureDropZone
&&
natureFactoryInput
)
{
natureDropZone
.
addEventListener
(
'click'
,
()
=>
natureFactoryInput
.
click
());
natureFactoryInput
.
addEventListener
(
'change'
,
()
=>
{
if
(
natureFactoryInput
.
files
.
length
>
0
)
{
document
.
getElementById
(
'nature-file-name'
).
textContent
=
'✅ 已选择: '
+
natureFactoryInput
.
files
[
0
].
name
;
document
.
getElementById
(
'nature-file-name'
).
style
.
color
=
'#52c41a'
;
}
});
}
window
.
onStoreFileChange
=
async
function
()
{
const
input
=
document
.
getElementById
(
'store-file-input'
);
if
(
!
input
.
files
.
length
)
return
;
const
name
=
input
.
files
[
0
].
name
;
document
.
getElementById
(
'store-file-name'
).
textContent
=
'\u2705 '
+
name
;
document
.
getElementById
(
'store-drop-zone'
).
classList
.
add
(
'has-file'
);
document
.
getElementById
(
'store-batch-select'
).
value
=
''
;
highlightStep
(
'step1-card'
);
document
.
getElementById
(
'btn-save-store'
).
style
.
display
=
'block'
;
const
formData
=
new
FormData
();
formData
.
append
(
'file_type'
,
'store'
);
formData
.
append
(
'file'
,
input
.
files
[
0
]);
await
previewFile
(
formData
,
'门店列表 - '
+
name
);
};
// ========== 步骤2/3: 主机厂数据 ==========
window
.
onFactoryBatchSelect
=
async
function
(
type
)
{
const
selId
=
type
===
'ecology'
?
'ecology-batch-select'
:
'nature-batch-select'
;
const
sel
=
document
.
getElementById
(
selId
);
if
(
!
sel
.
value
)
return
;
const
cardId
=
type
===
'ecology'
?
'step2-card'
:
'step3-card'
;
highlightStep
(
cardId
);
const
label
=
type
===
'ecology'
?
'生态(26日)'
:
'自然月(1日)'
;
await
loadBatchPreview
(
sel
.
value
,
label
+
' - 历史批次'
);
};
window
.
onFactoryFileChange
=
async
function
(
type
)
{
const
inputId
=
type
===
'ecology'
?
'ecology-factory-input'
:
'nature-factory-input'
;
const
zoneId
=
type
===
'ecology'
?
'ecology-drop-zone'
:
'nature-drop-zone'
;
const
nameId
=
type
===
'ecology'
?
'ecology-file-name'
:
'nature-file-name'
;
const
selId
=
type
===
'ecology'
?
'ecology-batch-select'
:
'nature-batch-select'
;
const
cardId
=
type
===
'ecology'
?
'step2-card'
:
'step3-card'
;
const
btnId
=
type
===
'ecology'
?
'btn-save-ecology'
:
'btn-save-nature'
;
const
input
=
document
.
getElementById
(
inputId
);
if
(
!
input
.
files
.
length
)
return
;
const
name
=
input
.
files
[
0
].
name
;
document
.
getElementById
(
nameId
).
textContent
=
'\u2705 '
+
name
;
document
.
getElementById
(
zoneId
).
classList
.
add
(
'has-file'
);
document
.
getElementById
(
selId
).
value
=
''
;
highlightStep
(
cardId
);
document
.
getElementById
(
btnId
).
style
.
display
=
'block'
;
const
label
=
type
===
'ecology'
?
'生态(26日)'
:
'自然月(1日)'
;
const
formData
=
new
FormData
();
formData
.
append
(
'file_type'
,
'factory'
);
formData
.
append
(
'file'
,
input
.
files
[
0
]);
await
previewFile
(
formData
,
label
+
' - '
+
name
);
};
//
生成报表按钮
const
btnGenerate
Report
=
document
.
getElementById
(
'btn-generate-report'
);
if
(
btnGenerate
Report
)
{
btnGenerate
Report
.
addEventListener
(
'click'
,
async
()
=>
{
document
.
getElementById
(
'analysis-result'
).
style
.
display
=
'none
'
;
document
.
getElementById
(
'analysis-error'
).
style
.
display
=
'none
'
;
//
========== 生成报表 ==========
const
btnGenerate
=
document
.
getElementById
(
'btn-generate-report'
);
if
(
btnGenerate
)
{
btnGenerate
.
addEventListener
(
'click'
,
async
()
=>
{
document
.
getElementById
(
'analysis-result'
).
className
=
'result-box
'
;
document
.
getElementById
(
'analysis-error'
).
className
=
'result-box
'
;
const
hasStore
=
storeFileInput
&&
storeFileInput
.
files
.
length
>
0
;
const
hasEcology
=
ecologyFactoryInput
&&
ecologyFactoryInput
.
files
.
length
>
0
;
const
hasNature
=
natureFactoryInput
&&
natureFactoryInput
.
files
.
length
>
0
;
const
storeInput
=
document
.
getElementById
(
'store-file-input'
);
const
ecoInput
=
document
.
getElementById
(
'ecology-factory-input'
);
const
natInput
=
document
.
getElementById
(
'nature-factory-input'
);
const
hasStore
=
storeInput
&&
storeInput
.
files
.
length
>
0
;
const
hasEco
=
ecoInput
&&
ecoInput
.
files
.
length
>
0
;
const
hasNat
=
natInput
&&
natInput
.
files
.
length
>
0
;
if
(
!
hasEco
logy
&&
!
hasNature
)
{
if
(
!
hasEco
&&
!
hasNat
)
{
alert
(
'请至少上传一个主机厂数据文件(步骤2或步骤3)'
);
return
;
}
btnGenerate
Report
.
disabled
=
true
;
btnGenerate
Report
.
textContent
=
'⏳
正在生成报表...'
;
btnGenerate
.
disabled
=
true
;
btnGenerate
.
textContent
=
'\u23f3
正在生成报表...'
;
try
{
const
uploadForm
=
new
FormData
();
if
(
hasStore
)
uploadForm
.
append
(
'store_file'
,
store
File
Input
.
files
[
0
]);
if
(
hasEco
logy
)
uploadForm
.
append
(
'ecology_factory_file'
,
ecologyFactory
Input
.
files
[
0
]);
if
(
hasNat
ure
)
uploadForm
.
append
(
'nature_factory_file'
,
natureFactory
Input
.
files
[
0
]);
if
(
hasStore
)
uploadForm
.
append
(
'store_file'
,
storeInput
.
files
[
0
]);
if
(
hasEco
)
uploadForm
.
append
(
'ecology_factory_file'
,
eco
Input
.
files
[
0
]);
if
(
hasNat
)
uploadForm
.
append
(
'nature_factory_file'
,
nat
Input
.
files
[
0
]);
const
uploadRes
=
await
fetch
(
window
.
API_BASE
+
'/analysis/upload'
,
{
method
:
'POST'
,
body
:
uploadForm
});
const
uploadData
=
await
uploadRes
.
json
();
if
(
uploadData
.
status
!==
'success'
)
{
throw
new
Error
(
uploadData
.
detail
||
'文件上传失败'
);
}
if
(
uploadData
.
status
!==
'success'
)
throw
new
Error
(
uploadData
.
detail
||
'文件上传失败'
);
btnGenerate
Report
.
textContent
=
'⏳
正在分析计算...'
;
btnGenerate
.
textContent
=
'\u23f3
正在分析计算...'
;
const
genForm
=
new
FormData
();
const
e
coStart
=
document
.
getElementById
(
'ecology-start-date'
).
value
;
const
e
coEnd
=
document
.
getElementById
(
'ecology-end-date'
).
value
;
const
n
atStart
=
document
.
getElementById
(
'nature-start-date'
).
value
;
const
n
atEnd
=
document
.
getElementById
(
'nature-end-date'
).
value
;
if
(
e
coStart
)
genForm
.
append
(
'ecology_start_date'
,
ecoStart
);
if
(
e
coEnd
)
genForm
.
append
(
'ecology_end_date'
,
ecoEnd
);
if
(
n
atStart
)
genForm
.
append
(
'nature_start_date'
,
natStart
);
if
(
n
atEnd
)
genForm
.
append
(
'nature_end_date'
,
natEnd
);
const
e
S
=
document
.
getElementById
(
'ecology-start-date'
).
value
;
const
e
E
=
document
.
getElementById
(
'ecology-end-date'
).
value
;
const
n
S
=
document
.
getElementById
(
'nature-start-date'
).
value
;
const
n
E
=
document
.
getElementById
(
'nature-end-date'
).
value
;
if
(
e
S
)
genForm
.
append
(
'ecology_start_date'
,
eS
);
if
(
e
E
)
genForm
.
append
(
'ecology_end_date'
,
eE
);
if
(
n
S
)
genForm
.
append
(
'nature_start_date'
,
nS
);
if
(
n
E
)
genForm
.
append
(
'nature_end_date'
,
nE
);
const
genRes
=
await
fetch
(
window
.
API_BASE
+
'/analysis/generate'
,
{
method
:
'POST'
,
body
:
genForm
});
const
genData
=
await
genRes
.
json
();
if
(
genData
.
status
===
'success'
)
{
document
.
getElementById
(
'analysis-result'
).
style
.
display
=
'block
'
;
document
.
getElementById
(
'analysis-result'
).
className
=
'result-box success
'
;
document
.
getElementById
(
'analysis-result-info'
).
innerHTML
=
'生态数据门店: <strong>'
+
genData
.
ecology_store_count
+
'</strong> 家 | '
+
'自然月门店: <strong>'
+
genData
.
nature_store_count
+
'</strong> 家'
;
...
...
@@ -214,15 +512,190 @@
}
}
catch
(
err
)
{
console
.
error
(
'分析失败:'
,
err
);
document
.
getElementById
(
'analysis-error'
).
style
.
display
=
'block
'
;
document
.
getElementById
(
'analysis-error'
).
className
=
'result-box error
'
;
document
.
getElementById
(
'analysis-error-msg'
).
textContent
=
err
.
message
||
'未知错误'
;
}
finally
{
btnGenerate
Report
.
disabled
=
false
;
btnGenerate
Report
.
textContent
=
'🚀
开始生成分析报表'
;
btnGenerate
.
disabled
=
false
;
btnGenerate
.
textContent
=
'\u{1f680}
开始生成分析报表'
;
}
});
}
});
// ========== 辅助函数 ==========
function
highlightStep
(
cardId
)
{
document
.
querySelectorAll
(
'.step-card'
).
forEach
(
c
=>
c
.
classList
.
remove
(
'active'
));
const
card
=
document
.
getElementById
(
cardId
);
if
(
card
)
card
.
classList
.
add
(
'active'
);
}
async
function
loadBatchOptions
()
{
try
{
const
[
storeRes
,
ecoRes
,
natRes
]
=
await
Promise
.
all
([
fetch
(
window
.
API_BASE
+
'/data-import/history?brand=问界&data_type=store_guarantee'
),
fetch
(
window
.
API_BASE
+
'/data-import/history?brand=问界&data_type=oem_delivery&period_type=ecology'
),
fetch
(
window
.
API_BASE
+
'/data-import/history?brand=问界&data_type=oem_delivery&period_type=nature'
)
]);
const
storeData
=
await
storeRes
.
json
();
const
ecoData
=
await
ecoRes
.
json
();
const
natData
=
await
natRes
.
json
();
function
fillSelect
(
selId
,
rows
)
{
const
sel
=
document
.
getElementById
(
selId
);
if
(
!
sel
)
return
;
(
rows
||
[]).
forEach
(
r
=>
{
const
opt
=
document
.
createElement
(
'option'
);
opt
.
value
=
r
.
batch_no
;
const
dt
=
r
.
created_at
?
r
.
created_at
.
substring
(
0
,
10
)
:
''
;
opt
.
textContent
=
`
${
r
.
file_name
||
r
.
batch_no
}
[
${
r
.
data_period_start
}
~
${
r
.
data_period_end
}
]`
;
sel
.
appendChild
(
opt
);
});
}
if
(
storeData
.
status
===
'success'
)
{
fillSelect
(
'store-batch-select'
,
storeData
.
data
);
}
if
(
ecoData
.
status
===
'success'
)
{
fillSelect
(
'ecology-batch-select'
,
ecoData
.
data
);
}
if
(
natData
.
status
===
'success'
)
{
fillSelect
(
'nature-batch-select'
,
natData
.
data
);
}
}
catch
(
e
)
{
console
.
error
(
'加载历史批次失败:'
,
e
);
}
}
async
function
loadBatchPreview
(
batchNo
,
title
)
{
showPreviewLoading
(
title
);
try
{
const
res
=
await
fetch
(
window
.
API_BASE
+
'/analysis/batch-data?batch_no='
+
encodeURIComponent
(
batchNo
));
const
data
=
await
res
.
json
();
if
(
data
.
status
===
'success'
)
{
renderPreviewTable
(
data
.
data
,
title
);
}
else
{
showPreviewError
(
data
.
detail
||
'加载失败'
);
}
}
catch
(
e
)
{
console
.
error
(
'加载批次数据失败:'
,
e
);
showPreviewError
(
'加载失败: '
+
e
.
message
);
}
}
async
function
previewFile
(
formData
,
title
)
{
showPreviewLoading
(
title
);
try
{
const
res
=
await
fetch
(
window
.
API_BASE
+
'/analysis/preview-file'
,
{
method
:
'POST'
,
body
:
formData
});
const
data
=
await
res
.
json
();
if
(
data
.
status
===
'success'
)
{
renderPreviewTable
(
data
.
data
,
title
);
}
else
{
showPreviewError
(
data
.
detail
||
'解析失败'
);
}
}
catch
(
e
)
{
console
.
error
(
'预览文件失败:'
,
e
);
showPreviewError
(
'预览失败: '
+
e
.
message
);
}
}
function
showPreviewLoading
(
title
)
{
document
.
getElementById
(
'preview-title'
).
textContent
=
'\u23f3 '
+
title
;
document
.
getElementById
(
'preview-count'
).
textContent
=
'加载中...'
;
document
.
getElementById
(
'preview-body'
).
innerHTML
=
'<div class="right-panel-empty">正在解析数据...</div>'
;
}
function
showPreviewError
(
msg
)
{
document
.
getElementById
(
'preview-title'
).
textContent
=
'\u274c 加载失败'
;
document
.
getElementById
(
'preview-count'
).
textContent
=
''
;
document
.
getElementById
(
'preview-body'
).
innerHTML
=
'<div class="right-panel-empty" style="color:#f5222d;">'
+
msg
+
'</div>'
;
}
function
renderPreviewTable
(
data
,
title
)
{
document
.
getElementById
(
'preview-title'
).
textContent
=
'\u{1f4ca} '
+
title
;
document
.
getElementById
(
'preview-count'
).
textContent
=
'共 '
+
data
.
total
+
' 条'
;
const
{
columns
,
rows
}
=
data
;
if
(
!
columns
.
length
||
!
rows
.
length
)
{
document
.
getElementById
(
'preview-body'
).
innerHTML
=
'<div class="right-panel-empty">无数据</div>'
;
return
;
}
let
html
=
'<table class="preview-table"><thead><tr>'
;
html
+=
'<th style="width:40px;text-align:center;">#</th>'
;
columns
.
forEach
(
c
=>
{
html
+=
'<th>'
+
escapeHtml
(
String
(
c
))
+
'</th>'
;
});
html
+=
'</tr></thead><tbody>'
;
rows
.
forEach
((
row
,
i
)
=>
{
html
+=
'<tr>'
;
html
+=
'<td style="text-align:center;color:#999;">'
+
(
i
+
1
)
+
'</td>'
;
columns
.
forEach
(
c
=>
{
const
val
=
row
[
c
]
!==
undefined
&&
row
[
c
]
!==
null
?
String
(
row
[
c
])
:
''
;
html
+=
'<td>'
+
escapeHtml
(
val
)
+
'</td>'
;
});
html
+=
'</tr>'
;
});
html
+=
'</tbody></table>'
;
document
.
getElementById
(
'preview-body'
).
innerHTML
=
html
;
}
async
function
saveBatch
(
fileType
)
{
const
config
=
{
store
:
{
inputId
:
'store-file-input'
,
btnId
:
'btn-save-store'
},
ecology
:
{
inputId
:
'ecology-factory-input'
,
btnId
:
'btn-save-ecology'
,
startId
:
'ecology-start-date'
,
endId
:
'ecology-end-date'
,
periodType
:
'ecology'
},
nature
:
{
inputId
:
'nature-factory-input'
,
btnId
:
'btn-save-nature'
,
startId
:
'nature-start-date'
,
endId
:
'nature-end-date'
,
periodType
:
'nature'
},
};
const
cfg
=
config
[
fileType
];
const
input
=
document
.
getElementById
(
cfg
.
inputId
);
if
(
!
input
||
!
input
.
files
.
length
)
{
alert
(
'请先上传文件'
);
return
;
}
const
btn
=
document
.
getElementById
(
cfg
.
btnId
);
btn
.
disabled
=
true
;
btn
.
textContent
=
'\u23f3 保存中...'
;
const
formData
=
new
FormData
();
formData
.
append
(
'file_type'
,
fileType
);
formData
.
append
(
'file'
,
input
.
files
[
0
]);
if
(
cfg
.
periodType
)
{
formData
.
append
(
'period_type'
,
cfg
.
periodType
);
formData
.
append
(
'period_start'
,
document
.
getElementById
(
cfg
.
startId
).
value
||
''
);
formData
.
append
(
'period_end'
,
document
.
getElementById
(
cfg
.
endId
).
value
||
''
);
}
try
{
const
res
=
await
fetch
(
window
.
API_BASE
+
'/analysis/save-batch'
,
{
method
:
'POST'
,
body
:
formData
});
const
data
=
await
res
.
json
();
if
(
data
.
status
===
'success'
)
{
btn
.
textContent
=
'\u2705 已保存 ('
+
(
data
.
data
.
batch_no
||
''
)
+
')'
;
btn
.
style
.
background
=
'#f6ffed'
;
btn
.
style
.
borderColor
=
'#b7eb8f'
;
btn
.
style
.
color
=
'#52c41a'
;
// 刷新下拉列表
loadBatchOptions
();
}
else
{
throw
new
Error
(
data
.
detail
||
'保存失败'
);
}
}
catch
(
e
)
{
console
.
error
(
'保存批次失败:'
,
e
);
btn
.
textContent
=
'\u274c 保存失败'
;
btn
.
style
.
background
=
'#fff2f0'
;
btn
.
style
.
borderColor
=
'#ffccc7'
;
btn
.
style
.
color
=
'#f5222d'
;
btn
.
disabled
=
false
;
}
}
function
escapeHtml
(
str
)
{
const
div
=
document
.
createElement
(
'div'
);
div
.
textContent
=
str
;
return
div
.
innerHTML
;
}
</script>
<script
src=
"./static/js/auth.js"
></script>
</body>
...
...
app/templates/data_import.html
View file @
dcdd35d
...
...
@@ -103,6 +103,14 @@
</select>
</div>
<div
class=
"form-group"
>
<label>
周期类型
</label>
<select
id=
"oem-period-type"
>
<option
value=
""
>
-- 请选择 --
</option>
<option
value=
"ecology"
>
生态月(26日)
</option>
<option
value=
"nature"
>
自然月(1日)
</option>
</select>
</div>
<div
class=
"form-group"
>
<label>
数据周期开始
</label>
<input
type=
"date"
id=
"oem-period-start"
/>
</div>
...
...
@@ -148,6 +156,7 @@
<th>
批次号
</th>
<th>
品牌
</th>
<th>
数据类型
</th>
<th>
周期类型
</th>
<th>
数据周期
</th>
<th>
文件名
</th>
<th>
行数
</th>
...
...
@@ -156,7 +165,7 @@
</tr>
</thead>
<tbody
id=
"history-tbody"
>
<tr><td
colspan=
"
8
"
style=
"text-align:center;color:#999;padding:30px"
>
加载中...
</td></tr>
<tr><td
colspan=
"
9
"
style=
"text-align:center;color:#999;padding:30px"
>
加载中...
</td></tr>
</tbody>
</table>
</div>
...
...
@@ -249,6 +258,7 @@
window
.
uploadOem
=
async
function
()
{
if
(
!
oemFile
)
{
alert
(
'请选择文件'
);
return
;
}
var
brand
=
document
.
getElementById
(
'oem-brand'
).
value
;
var
pt
=
document
.
getElementById
(
'oem-period-type'
).
value
;
var
ps
=
document
.
getElementById
(
'oem-period-start'
).
value
;
var
pe
=
document
.
getElementById
(
'oem-period-end'
).
value
;
if
(
!
ps
||
!
pe
)
{
alert
(
'请选择数据周期'
);
return
;
}
...
...
@@ -263,6 +273,7 @@
formData
.
append
(
'brand'
,
brand
);
formData
.
append
(
'period_start'
,
ps
);
formData
.
append
(
'period_end'
,
pe
);
if
(
pt
)
formData
.
append
(
'period_type'
,
pt
);
try
{
var
res
=
await
fetch
(
window
.
API_BASE
+
'/data-import/upload-oem'
,
{
method
:
'POST'
,
body
:
formData
});
...
...
@@ -293,7 +304,7 @@
// 加载历史
window
.
loadHistory
=
async
function
()
{
var
tbody
=
document
.
getElementById
(
'history-tbody'
);
tbody
.
innerHTML
=
'<tr><td colspan="
8
" style="text-align:center;color:#999;padding:30px">加载中...</td></tr>'
;
tbody
.
innerHTML
=
'<tr><td colspan="
9
" style="text-align:center;color:#999;padding:30px">加载中...</td></tr>'
;
var
brand
=
document
.
getElementById
(
'history-brand'
).
value
;
var
dtype
=
document
.
getElementById
(
'history-type'
).
value
;
var
params
=
new
URLSearchParams
();
...
...
@@ -305,10 +316,11 @@
var
json
=
await
res
.
json
();
var
rows
=
json
.
data
||
[];
if
(
rows
.
length
===
0
)
{
tbody
.
innerHTML
=
'<tr><td colspan="
8
" style="text-align:center;color:#999;padding:30px">暂无导入记录</td></tr>'
;
tbody
.
innerHTML
=
'<tr><td colspan="
9
" style="text-align:center;color:#999;padding:30px">暂无导入记录</td></tr>'
;
return
;
}
var
typeLabel
=
{
store_guarantee
:
'门店兜底配置'
,
oem_delivery
:
'主机厂交付数据'
};
var
periodTypeLabel
=
{
ecology
:
'生态月(26日)'
,
nature
:
'自然月(1日)'
};
var
statusLabel
=
{
1
:
'<span class="tag tag-imported">已导入</span>'
,
2
:
'<span class="tag tag-overwritten">已覆盖</span>'
,
3
:
'<span class="tag" style="background:#fff1f0;color:#f5222d">已删除</span>'
};
var
html
=
''
;
rows
.
forEach
(
function
(
r
)
{
...
...
@@ -316,6 +328,7 @@
'<td><code>'
+
escapeHtml
(
r
.
batch_no
)
+
'</code></td>'
+
'<td>'
+
escapeHtml
(
r
.
brand
)
+
'</td>'
+
'<td>'
+
(
typeLabel
[
r
.
data_type
]
||
r
.
data_type
)
+
'</td>'
+
'<td>'
+
(
periodTypeLabel
[
r
.
period_type
]
||
'-'
)
+
'</td>'
+
'<td>'
+
escapeHtml
(
r
.
data_period_start
)
+
' ~ '
+
escapeHtml
(
r
.
data_period_end
)
+
'</td>'
+
'<td style="max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="'
+
escapeHtml
(
r
.
file_name
||
''
)
+
'">'
+
escapeHtml
(
r
.
file_name
||
'-'
)
+
'</td>'
+
'<td>'
+
(
r
.
row_count
||
0
)
+
'</td>'
+
...
...
@@ -325,7 +338,7 @@
});
tbody
.
innerHTML
=
html
;
}
catch
(
err
)
{
tbody
.
innerHTML
=
'<tr><td colspan="
8
" style="text-align:center;color:#f5222d;padding:30px">加载失败: '
+
escapeHtml
(
err
.
message
)
+
'</td></tr>'
;
tbody
.
innerHTML
=
'<tr><td colspan="
9
" style="text-align:center;color:#f5222d;padding:30px">加载失败: '
+
escapeHtml
(
err
.
message
)
+
'</td></tr>'
;
}
};
...
...
sql/init_upload_tables.sql
View file @
dcdd35d
...
...
@@ -11,6 +11,7 @@ CREATE TABLE upload_batch (
batch_no
VARCHAR
(
32
)
NOT
NULL
COMMENT
'批次号 (唯一标识, 如 UB20260713001)'
,
brand
VARCHAR
(
32
)
NOT
NULL
COMMENT
'品牌: 问界 / 鸿蒙'
,
data_type
VARCHAR
(
32
)
NOT
NULL
COMMENT
'数据类型: store_guarantee(门店兜底配置) / oem_delivery(主机厂交付)'
,
period_type
VARCHAR
(
16
)
DEFAULT
NULL
COMMENT
'周期类型: ecology(生态26日) / nature(自然月1日),仅 oem_delivery 使用'
,
data_period_start
VARCHAR
(
10
)
NOT
NULL
COMMENT
'数据周期开始 yyyy-MM-dd'
,
data_period_end
VARCHAR
(
10
)
NOT
NULL
COMMENT
'数据周期结束 yyyy-MM-dd'
,
file_name
VARCHAR
(
255
)
DEFAULT
NULL
COMMENT
'上传文件名'
,
...
...
@@ -101,6 +102,7 @@ CREATE TABLE oem_delivery_data (
batch_id
BIGINT
NOT
NULL
COMMENT
'批次ID (关联 upload_batch.id)'
,
batch_no
VARCHAR
(
32
)
NOT
NULL
COMMENT
'批次号 (冗余, 便于查询)'
,
brand
VARCHAR
(
32
)
NOT
NULL
COMMENT
'品牌: 问界 / 鸿蒙'
,
period_type
VARCHAR
(
16
)
DEFAULT
NULL
COMMENT
'周期类型: ecology(生态26日) / nature(自然月1日)'
,
data_period_start
VARCHAR
(
10
)
DEFAULT
NULL
COMMENT
'数据周期开始 (YYYY-MM-DD)'
,
data_period_end
VARCHAR
(
10
)
DEFAULT
NULL
COMMENT
'数据周期结束 (YYYY-MM-DD)'
,
...
...
@@ -135,5 +137,6 @@ CREATE TABLE oem_delivery_data (
INDEX
idx_store_code
(
store_code
),
INDEX
idx_store_name
(
store_name
),
INDEX
idx_province
(
province
),
INDEX
idx_period_type
(
period_type
),
INDEX
idx_period
(
batch_no
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COMMENT
=
'主机厂交付数据表 (上传导入)'
;
temp_uploads/问界分析_生态(0626-0705)_自然(0701-0705)_1784017806.xlsx
0 → 100644
View file @
dcdd35d
No preview for this file type
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