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 7f4f7733
authored
Sep 04, 2026
by
周立明
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
产值达成表加入系统数据来源
1 parent
152eef42
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
256 additions
and
21 deletions
.workbuddy/memory/2026-09-04.md
data-process/_verify_api.py
data-process/indicator_client.py
data-process/output_value_processor.py
data-process/report_utils.py
.workbuddy/memory/2026-09-04.md
View file @
7f4f773
...
@@ -76,3 +76,40 @@
...
@@ -76,3 +76,40 @@
-
修正
`_merge_same_vertical`
:值为 None 或空串时
**不合并**
,仅逐格补边框、单列处理。
-
修正
`_merge_same_vertical`
:值为 None 或空串时
**不合并**
,仅逐格补边框、单列处理。
-
影响:B 列(大区经理) 为空(关系表无匹配→存空串)时,相邻空行不再纵向合并。C 列同口径(空不合并)。
-
影响:B 列(大区经理) 为空(关系表无匹配→存空串)时,相邻空行不再纵向合并。C 列同口径(空不合并)。
-
验证(mock:r3 华东大区、r4/r5 大区经理为空且相邻):
`B3:B4 merged? False`
;A3:A5(业务类型) 与 C 列相邻相同合并仍正常。
-
验证(mock:r3 华东大区、r4/r5 大区经理为空且相邻):
`B3:B4 merged? False`
;A3:A5(业务类型) 与 C 列相邻相同合并仍正常。
## git 分支挪移(产值达成表功能 main→v1.1,本轮回退 main)
-
起因:产值达成表功能先前提交在
`main`
的
`cac5de2`
(含全部 Excel 精细改动:B=大区经理、空不合并、_merge_same_vertical 等都在该提交内,非半成品)。
-
操作:在
`v1.1`
上
`git cherry-pick cac5de2`
→ 新提交
`b3b24d5`
(产值达成表基础数据)。
-
唯一冲突
`report_utils.py`
:v1.1 侧是嘀加 SQL 函数(fetch_biz_sql_aggregated/fuzzy_match_store),cac5de2 侧是产值解析函数(parse_saas_achieve_details/parse_operator_relation 等),两函数集无重叠 → 移除冲突标记、两边都保留,py_compile 通过。
-
`main`
本地
`git branch -f main cac5de2^`
(=45b68eb),
**不推送**
(按用户选择)。origin/main 仍含旧历史,远程未动;如需彻底撤回远程需后续 force push(用户自决)。
-
注:上一轮"指标接口改造"实际未落地——indicator_client.fetch 仍为单
`biz`
、report_utils.fetch_indicator_data 仍收单 biz_code,bizs 列表改造未完成;待继续。
## 指标系统接口接入(G/I/L 列,本轮回填落地)
-
参数(用户确认):itemCodes=
`A036`
(产值);2.1+2.3→bizs=
[
1,3
]
、1.1→bizs=
[
2
]
;均非率不×100;按
`store_name`
匹配 API
`merchantName`
逐一求和;G=全部门店=I+L。
-
bizs 序列化格式(用户确认):多业务线用
**逗号字符串**
`bizs="1,3"`
(与 itemCodes 风格一致),单值走原
`biz`
=2。
-
改动:
1.
`indicator_client.py`
:
`fetch`
的
`biz`
支持 list→
`payload["bizs"]=",".join(...)`
;int 仍走
`"biz"`
(向后兼容 light_reform 等单值调用方)。
2.
`report_utils.py`
:
`fetch_indicator_data`
文档补 biz 可 int/list;逻辑不变。
3.
`output_value_processor.py`
:导入
`fetch_indicator_data`
;新增
`INDICATOR_ITEM_CODES=['A036']`
、
`BIZS_MAP`
;
`_process_output_value`
在聚合前按业务类型预拉取指标(带门店匹配覆盖率日志);
`_sum_indicator`
按门店名匹配 merchantName 求和(未匹配/接口空→落 NULL 而非 0);I=存量门店和、L=新增门店和、G=I+L。
-
验证(mock 数据实际生成并 reopen Excel):
-
Test A:bizs=
[
1,3
]
→payload
`bizs:"1,3"`
;biz=2→
`biz:2`
。
-
Test B:华东 G=16725(I 16170+L 555)、华南 G=1887;故意不返回的「北京YY店」所在华北组 G/I/L 全 NULL。
-
Test C:全链路 Excel 华东 G=85000 I=80000 J%=80 L=5000 M%=25 N=85000 O%=70.83;华南 I=40000 J%=80 L=2000 M%=20 N=42000 O%=70。G/I/L 与 J/M/N/O 达成率全部按接口值正确展示。
-
待真实环境验证:本沙箱无法连通
`http://dc.glsx.com.cn/data`
,需在生产跑一次真实任务确认门店名匹配率与返回编码格式(A036 是否确为非率、bizs 字符串是否被后端正确解析)。
## 指标 G/I/L 查询周期修正:整周期累计→统计周期最后一天(最新,已改代码)
-
问题:用户实测 G 列是「当前周期内全部数据」而非「当日」。例:刘冬雪+岚图汽车北京大兴分公司,单日(2026-08-31) API 返回 A036=18797,但生成表 G=580922(≈18797×31,即整月累计)。根因:
`_process_output_value`
Step3.5 用
`fetch_indicator_data(start_str, end_str, ...)`
拉了整周期。
-
修正:G/I/L 均为「当日」口径(G 列名即「当日新增GMV」),故
`startDate=endDate=end_str`
(统计周期结束日,单日查询);条件由
`if start_str and end_str`
改为
`if end_str`
。同步更新模块 docstring 与 Step3.5 注释。
-
影响:
`_sum_indicator`
求和逻辑不变(仍按门店名匹配 merchantName 求和),仅入参日期范围收窄为单日 → G/I/L 取最后一天实际值。py_compile 通过。
## 指标口径二次修正:仅 G=最后一天,I/L=整周期累计(最新,已改代码)
-
用户纠正:上一条「G/I/L 均取最后一天」是错的。
**只有 G 列「当日新增GMV」取最后一天单日值;I 列「存量门店实际达成」与 L 列「新店实际达成」取整周期(start_str→end_str)累计。**
-
实现:Step3.5 分别拉两份指标 map ——
`indicator_period_by_biz`
(整周期, 供 I/L) 与
`indicator_last_day_by_biz`
(最后一天 end_str, 供 G);若 start_str 缺失则 I/L 的 period map 为空(I/L 落 NULL)。
-
聚合:
`existing_actual`
/
`new_actual`
用
`ind_period`
按 existing_stores/new_stores 求和;
`daily_new_gmv`
(G) 用
`ind_last`
按
`all_stores`
(存量+新增去重) 求和。
**注意 G 不再等于 I+L**
,与结果表列义一致(G=当日快照,N=实际达成GMV合计=I+L 整周期)。
-
py_compile 通过;无遗留
`indicator_by_biz`
引用。
## G/I/L 缺数据填充 0(最新,已改代码)
-
用户要求:G/I/L 三列若未匹配到指标数据(ind_map 空 / 门店名不匹配 / 门店列表为空),结果表
**填充 0 显示**
,不再留空。
-
改动:
`_sum_indicator`
不再返回 None,未匹配一律返回
`Decimal('0')`
(覆盖 ind_map 空、列表空、均不匹配三种情形);聚合处去掉
`if ... else None`
守卫,
`existing_actual/new_actual/daily_new_gmv`
恒为 Decimal。
-
连带:J/M/N/O 达成率原
`if x is not None else None`
守卫删除,现由 G/I/L 与预算直接重算(实际 0 → 达成率 0%;预算 0 时 safe_div_pct_decimal 返回 0)。N=实际达成GMV合计=I+L(整周期)。
-
影响:DB 列现为显式 0 而非 NULL;
`add_all`
写入仍安全。Excel
`_write_cell`
对 0 正常显示(金额 0.00、比率 0.00%)。py_compile 通过;无遗留
`is not None`
守卫。
data-process/_verify_api.py
0 → 100644
View file @
7f4f773
import
sys
,
types
,
datetime
from
decimal
import
Decimal
def
stub
(
name
):
m
=
types
.
ModuleType
(
name
);
sys
.
modules
[
name
]
=
m
;
return
m
# requests 桩(indicator_client 仅用 requests.post,验证时由 fake_post 接管)
req
=
stub
(
'requests'
);
req
.
post
=
lambda
*
a
,
**
k
:
None
;
req
.
Timeout
=
Exception
;
req
.
ConnectionError
=
Exception
sys
.
modules
[
'requests'
]
=
req
# config
cfg
=
stub
(
'config'
)
cfg
.
Config
=
type
(
'C'
,
(),
{
'INDICATOR_API_URL'
:
'http://dc.glsx.com.cn/data'
,
'INDICATOR_API_TIMEOUT'
:
10
,
'INDICATOR_API_RETRY'
:
1
})()
# ================= Test A: indicator_client bizs 序列化 =================
import
importlib.util
spec
=
importlib
.
util
.
spec_from_file_location
(
'indicator_client'
,
r'F:/data-report/data-process/indicator_client.py'
)
ic
=
importlib
.
util
.
module_from_spec
(
spec
);
spec
.
loader
.
exec_module
(
ic
)
captured
=
{}
class
FakeResp
:
status_code
=
200
def
json
(
self
):
return
{
'code'
:
200
,
'content'
:[]}
def
fake_post
(
url
,
json
=
None
,
timeout
=
None
):
captured
[
'url'
]
=
url
;
captured
[
'json'
]
=
json
;
return
FakeResp
()
ic
.
requests
.
post
=
fake_post
client
=
ic
.
IndicatorClient
()
client
.
fetch
(
'2026-08-01'
,
'2026-08-31'
,
[
1
,
3
],
[
'A036'
])
print
(
"A1 payload(bizs多值):"
,
captured
[
'json'
])
assert
captured
[
'json'
]
.
get
(
'bizs'
)
==
'1,3'
;
assert
'biz'
not
in
captured
[
'json'
]
client
.
fetch
(
'2026-08-01'
,
'2026-08-31'
,
2
,
[
'A036'
])
print
(
"A2 payload(biz单值):"
,
captured
[
'json'
])
assert
captured
[
'json'
]
.
get
(
'biz'
)
==
2
;
assert
'bizs'
not
in
captured
[
'json'
]
print
(
">>> Test A 通过:bizs 多值='1,3',单值 biz=2"
)
# ================= Test B: output_value_processor G/I/L 计算 =================
models
=
stub
(
'models'
)
class
FakeQuery
:
def
filter_by
(
self
,
**
k
):
return
self
def
delete
(
self
):
return
0
def
order_by
(
self
,
*
a
):
return
self
def
all
(
self
):
return
[]
class
SaasBusinessAchievement
:
query
=
FakeQuery
()
def
__init__
(
self
,
**
kw
):
self
.
__dict__
.
update
(
kw
)
models
.
SaasBusinessAchievement
=
SaasBusinessAchievement
models
.
DataProcessTask
=
object
class
FakeSession
:
def
__init__
(
self
):
self
.
added
=
[]
def
add_all
(
self
,
rows
):
self
.
added
.
extend
(
rows
)
def
flush
(
self
):
pass
def
commit
(
self
):
pass
def
rollback
(
self
):
pass
class
FakeDB
:
session
=
FakeSession
()
models
.
db
=
FakeDB
()
oss
=
stub
(
'oss_utils'
);
oss
.
upload_file
=
lambda
p
,
k
:
'http://fake/'
+
k
ru
=
stub
(
'report_utils'
)
ru
.
mark_task_failed
=
lambda
*
a
,
**
k
:
None
ru
.
cleanup_tmp_dir
=
lambda
*
a
,
**
k
:
None
ru
.
download_all_files
=
lambda
*
a
,
**
k
:
{
'SAAS门店预算分解表'
:
'x'
,
'关系表'
:
'y'
}
ru
.
parse_operator_relation
=
lambda
*
a
,
**
k
:
{}
ru
.
safe_div_pct_decimal
=
lambda
n
,
d
:
(
round
(
n
/
d
*
100
,
2
)
if
(
n
is
not
None
and
d
)
else
None
)
MOCK_213
=
[
{
'region_operator'
:
'华东'
,
'store_name'
:
'郑州鸿启汽车贸易有限公司'
,
'resident_type'
:
'直营'
,
'store_kind'
:
'存量'
,
'budget_corrected'
:
Decimal
(
'100000'
),
'biz_type'
:
'2.1'
},
{
'region_operator'
:
'华东'
,
'store_name'
:
'新乡市天驰汽车销售有限公司'
,
'resident_type'
:
'直营'
,
'store_kind'
:
'存量'
,
'budget_corrected'
:
Decimal
(
'80000'
),
'biz_type'
:
'2.1'
},
{
'region_operator'
:
'华东'
,
'store_name'
:
'上海XX店'
,
'resident_type'
:
'服务商'
,
'store_kind'
:
'新增'
,
'budget_corrected'
:
Decimal
(
'20000'
),
'biz_type'
:
'2.3'
},
{
'region_operator'
:
'华北'
,
'store_name'
:
'北京YY店'
,
'resident_type'
:
'直营'
,
'store_kind'
:
'存量'
,
'budget_corrected'
:
Decimal
(
'60000'
),
'biz_type'
:
'2.1'
},
]
MOCK_11
=
[
{
'region_operator'
:
'华南'
,
'store_name'
:
'广州ZZ店'
,
'resident_type'
:
'直营'
,
'store_kind'
:
'存量'
,
'budget_corrected'
:
Decimal
(
'50000'
),
'biz_type'
:
'1.1'
},
{
'region_operator'
:
'华南'
,
'store_name'
:
'深圳WW店'
,
'resident_type'
:
'服务商'
,
'store_kind'
:
'新增'
,
'budget_corrected'
:
Decimal
(
'10000'
),
'biz_type'
:
'1.1'
},
]
ru
.
parse_saas_achieve_details
=
lambda
p
,
k
,
i
:
(
MOCK_11
if
'轻改'
in
k
else
MOCK_213
)
API_DATA
=
{
'郑州鸿启汽车贸易有限公司'
:
{
'A036'
:
Decimal
(
'12225'
)},
'新乡市天驰汽车销售有限公司'
:
{
'A036'
:
Decimal
(
'3945'
)},
'上海XX店'
:
{
'A036'
:
Decimal
(
'555'
)},
# '北京YY店' 故意不返回 → 华北组应落 NULL
'广州ZZ店'
:
{
'A036'
:
Decimal
(
'888'
)},
'深圳WW店'
:
{
'A036'
:
Decimal
(
'999'
)},
}
def
fake_fetch
(
start_str
,
end_str
,
biz_code
,
item_codes
):
assert
biz_code
in
([
1
,
3
],
[
2
]),
f
"biz_code 错误: {biz_code}"
return
API_DATA
ru
.
fetch_indicator_data
=
fake_fetch
spec2
=
importlib
.
util
.
spec_from_file_location
(
'ovp'
,
r'F:/data-report/data-process/output_value_processor.py'
)
ovp
=
importlib
.
util
.
module_from_spec
(
spec2
);
spec
.
loader
.
exec_module
(
ovp
)
class
FakeTask
:
id
=
777
;
month
=
'2026-08'
period_start
=
datetime
.
date
(
2026
,
8
,
1
);
period_end
=
datetime
.
date
(
2026
,
8
,
31
)
proc
=
ovp
.
OutputValueProcessor
()
proc
.
_process_output_value
(
FakeTask
())
rows
=
models
.
db
.
session
.
added
print
(
f
"
\n
>>> 入库 {len(rows)} 行"
)
ok
=
True
for
r
in
rows
:
g
=
r
.
daily_new_gmv
;
i
=
r
.
existing_actual
;
l
=
r
.
new_actual
print
(
f
" {r.business_type}/{r.region_operator:6s} G={g} I={i} L={l}"
)
if
r
.
region_operator
==
'华东'
:
ok
=
ok
and
(
i
==
Decimal
(
'16170'
)
and
l
==
Decimal
(
'555'
)
and
g
==
Decimal
(
'16725'
))
elif
r
.
region_operator
==
'华北'
:
ok
=
ok
and
(
i
is
None
and
l
is
None
and
g
is
None
)
elif
r
.
region_operator
==
'华南'
:
ok
=
ok
and
(
i
==
Decimal
(
'888'
)
and
l
==
Decimal
(
'999'
)
and
g
==
Decimal
(
'1887'
))
assert
ok
,
"G/I/L 数值不符预期"
print
(
">>> Test B 通过:store_name 匹配、G=I+L、未匹配门店(华北)落 NULL"
)
data-process/indicator_client.py
View file @
7f4f773
...
@@ -61,7 +61,9 @@ class IndicatorClient:
...
@@ -61,7 +61,9 @@ class IndicatorClient:
参数:
参数:
- start_date: str 'YYYY-MM-DD'
- start_date: str 'YYYY-MM-DD'
- end_date: str 'YYYY-MM-DD'
- end_date: str 'YYYY-MM-DD'
- biz: int 1=延保 2=轻改 3=权益
- biz: int 单值(1=延保 2=轻改 3=权益) 或 list/tuple(如 [1,3] 多业务线);
多值会序列化为逗号字符串 bizs="1,3"(与 itemCodes 风格一致);
单值仍走原 "biz" 键,向后兼容现有调用方。
- item_codes: list[str] 指标编码列表,如 ['A036', 'A075']
- item_codes: list[str] 指标编码列表,如 ['A036', 'A075']
- rate_codes: set[str] 率类指标编码,API 返回小数会 *100;None 则用 RATE_CODES 默认
- rate_codes: set[str] 率类指标编码,API 返回小数会 *100;None 则用 RATE_CODES 默认
...
@@ -80,8 +82,12 @@ class IndicatorClient:
...
@@ -80,8 +82,12 @@ class IndicatorClient:
"endDate"
:
end_date
,
"endDate"
:
end_date
,
"exts"
:
"merchantIds"
,
"exts"
:
"merchantIds"
,
"itemCodes"
:
","
.
join
(
item_codes
),
"itemCodes"
:
","
.
join
(
item_codes
),
"biz"
:
biz
,
}
}
# biz 支持单值(int) / 多值(list):多业务线按约定序列化为逗号字符串 bizs="1,3"
if
isinstance
(
biz
,
(
list
,
tuple
,
set
)):
payload
[
"bizs"
]
=
","
.
join
(
str
(
b
)
for
b
in
biz
)
else
:
payload
[
"biz"
]
=
biz
last_err
=
None
last_err
=
None
for
attempt
in
range
(
1
,
self
.
retry
+
2
):
# 首次 + retry 次
for
attempt
in
range
(
1
,
self
.
retry
+
2
):
# 首次 + retry 次
...
...
data-process/output_value_processor.py
View file @
7f4f773
...
@@ -18,9 +18,14 @@
...
@@ -18,9 +18,14 @@
K列 新店预算 = 存量/性质=新增 的「预估产值(纠偏)」合计
K列 新店预算 = 存量/性质=新增 的「预估产值(纠偏)」合计
Step5 入库 saas_business_achievement(按 task_id 先删后插,幂等)
Step5 入库 saas_business_achievement(按 task_id 先删后插,幂等)
接口列(
待接入,暂落 NULL 以示「未获取」而非 0
):
接口列(
已接入指标系统 http://dc.glsx.com.cn/data
):
G列 当日新增GMV / I列 存量门店实际达成 / L列 新店实际达成
G列 当日新增GMV / I列 存量门店实际达成 / L列 新店实际达成
依赖接口值的 J/M/N/O 列同步留空,接口接入后自动计算。
统一取自指标编码 A036(产值,非率不*100),按门店名(store_name) 匹配 API 返回的
merchantName 逐一求和;bizs 映射:2.1+2.3→[1,3]、1.1→[2],序列化为逗号字符串。
指标查询口径区分:G列「当日新增GMV」=统计周期最后一天(startDate=endDate=period_end,单日);
I列「存量门店实际达成」/L列「新店实际达成」=整周期累计(startDate=period_start→endDate=period_end)。
指标拉取成功但某门店名未匹配到 merchantName 时,G/I/L 该组填充 0(按用户口径缺数据显 0,不置空)。
依赖接口值的 J/M/N/O 达成率列由 G/I/L 与预算重算(实际为 0 → 达成率 0
%
)。
"""
"""
import
calendar
import
calendar
import
logging
import
logging
...
@@ -38,7 +43,7 @@ from config import Config
...
@@ -38,7 +43,7 @@ from config import Config
from
report_utils
import
(
from
report_utils
import
(
mark_task_failed
,
cleanup_tmp_dir
,
download_all_files
,
mark_task_failed
,
cleanup_tmp_dir
,
download_all_files
,
parse_saas_achieve_details
,
parse_operator_relation
,
parse_saas_achieve_details
,
parse_operator_relation
,
safe_div_pct_decimal
,
fetch_indicator_data
,
safe_div_pct_decimal
,
)
)
from
models
import
DataProcessTask
,
SaasBusinessAchievement
,
db
from
models
import
DataProcessTask
,
SaasBusinessAchievement
,
db
...
@@ -52,6 +57,16 @@ BIZ_SHEET_CONF = {
...
@@ -52,6 +57,16 @@ BIZ_SHEET_CONF = {
'1.1'
:
([
'轻改'
,
'门店'
],
1
,
'轻改'
),
'1.1'
:
([
'轻改'
,
'门店'
],
1
,
'轻改'
),
}
}
# 指标系统接口:产值达成表实际值(G/I/L 列)取自 A036(产值)。
# 用户确认:均非率类,不 *100;按门店名(store_name) 匹配 API 返回 merchantName 逐一求和。
INDICATOR_ITEM_CODES
=
[
'A036'
]
# 业务类型 → 指标系统 bizs(多业务线序列化为逗号字符串,见 indicator_client):
# 2.1+2.3 → 延保(1) + 权益(3);1.1 → 轻改(2)
BIZS_MAP
=
{
'2.1+2.3'
:
[
1
,
3
],
'1.1'
:
[
2
],
}
class
OutputValueProcessor
:
class
OutputValueProcessor
:
"""产值达成表独立处理器"""
"""产值达成表独立处理器"""
...
@@ -156,6 +171,38 @@ class OutputValueProcessor:
...
@@ -156,6 +171,38 @@ class OutputValueProcessor:
finally
:
finally
:
cleanup_tmp_dir
(
tmp_dir
)
cleanup_tmp_dir
(
tmp_dir
)
# ========== Step3.5: 指标系统实际值(G / I / L)预拉取(按业务类型,bizs 不同) ==========
# 口径区分(按结果表列义):
# G 列「当日新增GMV」 = 统计周期【最后一天】单日值(startDate=endDate=period_end)
# I 列「存量门店实际达成」 = 统计周期【整周期】累计(startDate=period_start→endDate=period_end)
# L 列「新店实际达成」 = 统计周期【整周期】累计(同上)
# 故需分别拉取:整周期一份供 I/L,最后一天一份供 G。
indicator_period_by_biz
=
{}
# 整周期:I/L
indicator_last_day_by_biz
=
{}
# 最后一天:G
if
end_str
:
for
biz_type
,
bizs
in
BIZS_MAP
.
items
():
records
=
details_by_biz
.
get
(
biz_type
)
if
not
records
:
continue
# G 列:最后一天单日值
ind_last
=
fetch_indicator_data
(
end_str
,
end_str
,
bizs
,
INDICATOR_ITEM_CODES
)
indicator_last_day_by_biz
[
biz_type
]
=
ind_last
# I/L 列:整周期累计(需起止日齐全)
ind_period
=
{}
if
start_str
:
ind_period
=
fetch_indicator_data
(
start_str
,
end_str
,
bizs
,
INDICATOR_ITEM_CODES
)
indicator_period_by_biz
[
biz_type
]
=
ind_period
# 覆盖率日志:门店名(store_name) 与 API merchantName 匹配情况
store_names
=
{
it
[
'store_name'
]
for
it
in
records
if
it
[
'store_name'
]}
matched_last
=
len
(
store_names
&
set
(
ind_last
.
keys
()))
matched_period
=
(
len
(
store_names
&
set
(
ind_period
.
keys
()))
if
start_str
else
None
)
logger
.
info
(
f
"[产值达成] 业务类型 {biz_type} 指标拉取: "
f
"整周期匹配 {matched_period}/{len(store_names)}"
+
f
", 最后一天匹配 {matched_last}/{len(store_names)}"
)
else
:
logger
.
warning
(
"[产值达成] 缺少统计周期(start/end),跳过指标系统拉取(G/I/L 留空)"
)
# ========== Step4: 按区域运营聚合 ==========
# ========== Step4: 按区域运营聚合 ==========
rows_to_insert
=
[]
rows_to_insert
=
[]
for
biz_type
,
(
_kw
,
_idx
,
line_kw
)
in
BIZ_SHEET_CONF
.
items
():
for
biz_type
,
(
_kw
,
_idx
,
line_kw
)
in
BIZ_SHEET_CONF
.
items
():
...
@@ -191,27 +238,36 @@ class OutputValueProcessor:
...
@@ -191,27 +238,36 @@ class OutputValueProcessor:
new_budget
=
sum
((
it
[
'budget_corrected'
]
for
it
in
items
new_budget
=
sum
((
it
[
'budget_corrected'
]
for
it
in
items
if
it
[
'store_kind'
]
==
'新增'
),
Decimal
(
'0'
))
if
it
[
'store_kind'
]
==
'新增'
),
Decimal
(
'0'
))
# 门店名集合(按 store_kind 区分,供 G/I/L 接口值按门店匹配求和)
existing_stores
=
[
it
[
'store_name'
]
for
it
in
items
if
it
[
'store_name'
]
and
it
[
'store_kind'
]
==
'存量'
]
new_stores
=
[
it
[
'store_name'
]
for
it
in
items
if
it
[
'store_name'
]
and
it
[
'store_kind'
]
==
'新增'
]
# B 列:关系表 E(区域经理) → D(大区经理)
# B 列:关系表 E(区域经理) → D(大区经理)
manager
=
line_map
.
get
(
region_operator
,
''
)
manager
=
line_map
.
get
(
region_operator
,
''
)
# 关系表哨兵值('/'、'nan'、'None')归一为空,结果表显示为空而非字面斜杠
# 关系表哨兵值('/'、'nan'、'None')归一为空,结果表显示为空而非字面斜杠
if
not
manager
or
manager
.
strip
()
in
(
'/'
,
'nan'
,
'None'
,
'无'
):
if
not
manager
or
manager
.
strip
()
in
(
'/'
,
'nan'
,
'None'
,
'无'
):
manager
=
''
manager
=
''
# G / I / L 列来自接口,暂未接入 → 落 NULL
# G / I / L 列:指标系统实际值(A036 产值),按门店名(store_name) 匹配 merchantName 求和
daily_new_gmv
=
None
# I 列(存量实际) = 整周期累计:存量门店 A036 合计
existing_actual
=
None
# L 列(新店实际) = 整周期累计:新增门店 A036 合计
new_actual
=
None
# G 列(当日新增GMV) = 最后一天单日:本组全部门店(存量+新增)A036 合计
ind_period
=
indicator_period_by_biz
.
get
(
biz_type
)
or
{}
# J / M / N / O 列依赖接口值,接口缺失时留空(不置 0,避免误导)
ind_last
=
indicator_last_day_by_biz
.
get
(
biz_type
)
or
{}
existing_rate
=
(
safe_div_pct_decimal
(
existing_actual
,
existing_budget
)
existing_actual
=
self
.
_sum_indicator
(
ind_period
,
existing_stores
)
if
existing_actual
is
not
None
else
None
)
new_actual
=
self
.
_sum_indicator
(
ind_period
,
new_stores
)
new_rate
=
(
safe_div_pct_decimal
(
new_actual
,
new_budget
)
# G:最后一天口径,按本组全部门店(存量+新增,去重)求和
if
new_actual
is
not
None
else
None
)
all_stores
=
list
(
dict
.
fromkeys
((
existing_stores
or
[])
+
(
new_stores
or
[])))
total_actual_gmv
=
(
existing_actual
+
new_actual
daily_new_gmv
=
self
.
_sum_indicator
(
ind_last
,
all_stores
)
if
(
existing_actual
is
not
None
and
new_actual
is
not
None
)
else
None
)
# J / M / N / O 列:由 G/I/L 与预算重算。G/I/L 现为 0(未匹配)或实际值,
total_rate
=
(
safe_div_pct_decimal
(
total_actual_gmv
,
existing_budget
+
new_budget
)
# 故达成率恒可计算(实际为 0 → 达成率 0%);预算为 0 时 safe_div 返回 0。
if
total_actual_gmv
is
not
None
else
None
)
existing_rate
=
safe_div_pct_decimal
(
existing_actual
,
existing_budget
)
new_rate
=
safe_div_pct_decimal
(
new_actual
,
new_budget
)
total_actual_gmv
=
existing_actual
+
new_actual
total_rate
=
safe_div_pct_decimal
(
total_actual_gmv
,
existing_budget
+
new_budget
)
rows_to_insert
.
append
(
SaasBusinessAchievement
(
rows_to_insert
.
append
(
SaasBusinessAchievement
(
task_id
=
task_id
,
task_id
=
task_id
,
...
@@ -287,6 +343,27 @@ class OutputValueProcessor:
...
@@ -287,6 +343,27 @@ class OutputValueProcessor:
return
sum
(
nums
)
if
nums
else
None
return
sum
(
nums
)
if
nums
else
None
@staticmethod
@staticmethod
def
_sum_indicator
(
ind_map
,
store_names
,
item_code
=
'A036'
):
"""按门店名逐一匹配指标系统返回 merchantName,对 item_code 的 itemValue 求和。
ind_map: {merchantName: {itemCode: value, ...}}(fetch_indicator_data 返回)
store_names: 本组需纳入求和的门店名列表(可空)
返回 Decimal:匹配到的门店 itemValue 累加;未匹配到任何门店(ind_map 为空、
门店名均不匹配、或门店列表为空)一律返回 Decimal('0'),以适配 G/I/L 缺数据显 0 的口径
(保证「未接入/无数据」与「真实为 0」在结果表均显示为 0,不再区分留空)。
"""
total
=
Decimal
(
'0'
)
if
not
ind_map
:
return
total
for
sn
in
store_names
or
[]:
if
not
sn
:
continue
v
=
ind_map
.
get
(
sn
,
{})
.
get
(
item_code
)
if
v
is
not
None
:
total
+=
Decimal
(
str
(
v
))
return
total
@staticmethod
def
_safe_rate_pct
(
num
,
den
):
def
_safe_rate_pct
(
num
,
den
):
"""达成率(×100,与数据行一致):除数为空/0 时返回 None"""
"""达成率(×100,与数据行一致):除数为空/0 时返回 None"""
if
num
is
None
or
den
is
None
or
den
==
0
:
if
num
is
None
or
den
is
None
or
den
==
0
:
...
@@ -374,7 +451,8 @@ class OutputValueProcessor:
...
@@ -374,7 +451,8 @@ class OutputValueProcessor:
各业务类型明细(行3+,A 列按业务类型纵向合并、B(大区经理)/C(区域运营) 列相同相邻值纵向合并) /
各业务类型明细(行3+,A 列按业务类型纵向合并、B(大区经理)/C(区域运营) 列相同相邻值纵向合并) /
每业务类型小计(A:B合并) / 全部业务合计(A:B合并,C 补边框) /
每业务类型小计(A:B合并) / 全部业务合计(A:B合并,C 补边框) /
模板末两行(二手车、总合计:A~L 合并加边框,M 标签,N/O 留空加边框)。
模板末两行(二手车、总合计:A~L 合并加边框,M 标签,N/O 留空加边框)。
G/I/L 接口列及依赖它们的 J/M/N/O 达成率列在接口未接入时留空。
G/I/L 由指标系统接口填充;依赖它们的 J/M/N/O 达成率列在接口值非空时自动计算,
接口未匹配到数据(落 NULL)时仍留空。
"""
"""
task_id
=
task
.
id
task_id
=
task
.
id
stat_month
=
task
.
month
or
''
stat_month
=
task
.
month
or
''
...
...
data-process/report_utils.py
View file @
7f4f773
...
@@ -412,6 +412,7 @@ def fetch_indicator_data(start_str, end_str, biz_code, item_codes):
...
@@ -412,6 +412,7 @@ def fetch_indicator_data(start_str, end_str, biz_code, item_codes):
"""
"""
调指标系统 API,返回 {merchantName: {itemCode: itemValue}}。
调指标系统 API,返回 {merchantName: {itemCode: itemValue}}。
start_str / end_str: 'YYYY-MM-DD' 字符串,空则返回 {}。
start_str / end_str: 'YYYY-MM-DD' 字符串,空则返回 {}。
biz_code: int 单值 或 list/tuple 多业务线(如 [1,3],序列化为 bizs="1,3")。
"""
"""
if
not
start_str
or
not
end_str
or
not
item_codes
:
if
not
start_str
or
not
end_str
or
not
item_codes
:
return
{}
return
{}
...
...
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