Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
data_report
/
data-report
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 f16ebf0f
authored
Aug 11, 2026
by
周立明
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
装修摊销字段解析及入库
1 parent
6cde69cd
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
1 deletions
data-process/clean_budget_achievement.py
data-process/parsers/__init__.py
data-process/parsers/renovation_parser.py
data-process/clean_budget_achievement.py
View file @
f16ebf0
This diff is collapsed.
Click to expand it.
data-process/parsers/__init__.py
View file @
f16ebf0
...
@@ -5,5 +5,6 @@
...
@@ -5,5 +5,6 @@
解析器只负责「读 Excel → 结构化数据」,不关心数据库读写。
解析器只负责「读 Excel → 结构化数据」,不关心数据库读写。
"""
"""
from
.settlement_parser
import
SettlementSummaryParser
,
normalize_brand
from
.settlement_parser
import
SettlementSummaryParser
,
normalize_brand
from
.renovation_parser
import
RenovationDetailParser
__all__
=
[
'SettlementSummaryParser'
,
'normalize_brand'
]
__all__
=
[
'SettlementSummaryParser'
,
'normalize_brand'
,
'RenovationDetailParser'
]
data-process/parsers/renovation_parser.py
0 → 100644
View file @
f16ebf0
# -*- coding: utf-8 -*-
"""门店装修费用明细表(装修费用表)解析器。
职责:解析「门店装修费用明细汇总.xlsx」第一个 sheet,提取计算装修摊销所需的字段:
- 门店名称(F 列,对应结果表 traffic_name 的匹配键)
- 系统园区店名称(G 列,对应结果表 park_store 的兜底匹配键)
- 合同金额(L 列,摊销基数)
- 实际验收日期(T 列,决定计提窗口)
表头位置:第 1 行为标题(合并 A1:Y1),第 2 行为表头,第 3 行起为数据。
解析器只负责「读 Excel → 结构化数据」,不关心数据库读写。
"""
import
os
import
re
import
openpyxl
# ---------- 列号(1 基,对应 Excel A、B、C ... 列) ----------
COL_STORE_NAME
=
6
# F 门店名称
COL_PARK_STORE
=
7
# G 系统园区店名称
COL_CONTRACT
=
12
# L 合同金额
COL_ACCEPT_DATE
=
20
# T 实际验收日期
MAX_COL
=
COL_ACCEPT_DATE
# 数据起始行:第 1 行标题、第 2 行表头,第 3 行起为数据
DATA_ROW_START
=
3
def
_s
(
value
):
"""单元格取值转字符串并去空白,None → ''。"""
if
value
is
None
:
return
''
if
isinstance
(
value
,
str
):
return
value
.
strip
()
return
str
(
value
)
.
strip
()
def
_to_num
(
value
):
"""单元格数值归一:None/空/布尔 → 0.0;数字原样;字符串去千分位与货币符号后转 float。"""
if
value
is
None
or
isinstance
(
value
,
bool
):
return
0.0
if
isinstance
(
value
,
(
int
,
float
)):
return
float
(
value
)
s
=
str
(
value
)
.
strip
()
.
replace
(
','
,
''
)
if
not
s
:
return
0.0
s
=
re
.
sub
(
r'[^\d.\-]'
,
''
,
s
)
# 去掉 ¥、空格等非数字字符
if
s
in
(
''
,
'.'
,
'-'
):
return
0.0
try
:
return
float
(
s
)
except
ValueError
:
return
0.0
def
strip_dplus
(
name
):
"""去掉名称前缀 'D+'(匹配时归一化用)。"""
if
name
and
name
.
startswith
(
'D+'
):
return
name
[
2
:]
return
name
class
RenovationDetailParser
:
"""门店装修费用明细表解析器。"""
def
__init__
(
self
,
file_path
):
if
not
os
.
path
.
exists
(
file_path
):
raise
FileNotFoundError
(
f
'装修费用明细表不存在:{file_path}'
)
self
.
file_path
=
file_path
self
.
details
=
[]
def
parse
(
self
):
"""解析第一个 sheet,返回明细列表。
每行返回 dict:
store_name 门店名称(F 列)
park_store_name 系统园区店名称(G 列)
contract_amount 合同金额(L 列,float)
accept_date 实际验收日期(T 列,datetime 或 None)
Returns:
list[dict]
"""
wb
=
openpyxl
.
load_workbook
(
self
.
file_path
,
data_only
=
True
,
read_only
=
True
)
try
:
ws
=
wb
[
wb
.
sheetnames
[
0
]]
details
=
[]
for
row
in
ws
.
iter_rows
(
min_row
=
DATA_ROW_START
,
max_col
=
MAX_COL
,
values_only
=
True
):
def
cell
(
col
):
idx
=
col
-
1
return
row
[
idx
]
if
idx
<
len
(
row
)
else
None
store_name
=
_s
(
cell
(
COL_STORE_NAME
))
park_store
=
_s
(
cell
(
COL_PARK_STORE
))
# 门店名称与系统园区店名称均为空的行视为空行/合计行,跳过
if
not
store_name
and
not
park_store
:
continue
details
.
append
({
'store_name'
:
store_name
,
'park_store_name'
:
park_store
,
'contract_amount'
:
_to_num
(
cell
(
COL_CONTRACT
)),
'accept_date'
:
cell
(
COL_ACCEPT_DATE
),
})
finally
:
wb
.
close
()
self
.
details
=
details
return
details
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