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 326f3e62
authored
Oct 20, 2026
by
chenxi
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
广爱报表提交
1 parent
84b3bdcc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
196 additions
and
30 deletions
data-process/app.py
data-process/guangai_processor.py
data-process/models.py
data-process/static/css/style.css
data-process/static/js/list.js
data-process/test_guangai_processor.py
data-process/app.py
View file @
326f3e6
...
@@ -486,7 +486,7 @@ def task_create():
...
@@ -486,7 +486,7 @@ def task_create():
@app.post
(
'/api/tasks/<int:task_id>/regenerate'
)
@app.post
(
'/api/tasks/<int:task_id>/regenerate'
)
@login_required
@login_required
def
task_regenerate
(
task_id
):
def
task_regenerate
(
task_id
):
"""重新生成:仅 COMPLETED / FAILED 可操作,类型
与月份
锁定,附件可替换。
"""重新生成:仅 COMPLETED / FAILED 可操作,类型
/ 月份 / 所属周期均
锁定,附件可替换。
附件已由前端直传 OSS,后端接收元信息(JSON);清洗中的附件不可覆盖;
附件已由前端直传 OSS,后端接收元信息(JSON);清洗中的附件不可覆盖;
覆盖采用软删除(is_deleted=1),旧附件数据保留。
覆盖采用软删除(is_deleted=1),旧附件数据保留。
"""
"""
...
@@ -505,11 +505,20 @@ def task_regenerate(task_id):
...
@@ -505,11 +505,20 @@ def task_regenerate(task_id):
if
not
data
.
get
(
'month'
):
if
not
data
.
get
(
'month'
):
data
[
'month'
]
=
t
.
month
data
[
'month'
]
=
t
.
month
# 所属周期 / 粒度:重新生成时可调整(包括 period_type 切换),类型与月份锁定
# 类型 / 月份 / 所属周期 全部锁定:重新生成只允许替换附件,不允许改周期。
try
:
# 前端弹窗已把周期控件置灰,后端同样忽略提交的周期字段(防止绕过前端直调 API
period_type
,
week_num
,
period_start
,
period_end
=
parse_period
(
data
,
tcfg
,
data_table_type
=
t
.
data_table_type
)
# 把单据改到别的周期上,也避免与已有同周期单据撞数据)。
except
ValueError
as
e
:
period_type
=
t
.
period_type
or
'month'
return
fail
(
str
(
e
))
week_num
=
t
.
week_num
period_start
=
t
.
period_start
period_end
=
t
.
period_end
# 历史单据可能没有周期(早期数据)→ 仅在缺值时回退到提交值解析
if
not
period_start
or
not
period_end
:
try
:
period_type
,
week_num
,
period_start
,
period_end
=
parse_period
(
data
,
tcfg
,
data_table_type
=
t
.
data_table_type
)
except
ValueError
as
e
:
return
fail
(
str
(
e
))
needs_period
=
tcfg
.
get
(
'need_period'
)
or
period_type
==
'week'
needs_period
=
tcfg
.
get
(
'need_period'
)
or
period_type
==
'week'
if
needs_period
and
(
not
period_start
or
not
period_end
):
if
needs_period
and
(
not
period_start
or
not
period_end
):
if
period_type
==
'week'
:
if
period_type
==
'week'
:
...
@@ -561,7 +570,7 @@ def task_regenerate(task_id):
...
@@ -561,7 +570,7 @@ def task_regenerate(task_id):
t
.
updater
=
updater
t
.
updater
=
updater
t
.
result_file_url
=
''
t
.
result_file_url
=
''
t
.
error_msg
=
''
t
.
error_msg
=
''
#
更新周期粒度字段(可在重新生成时切换按月/按周
)
#
周期字段回写(取原单据值,重新生成不改变周期;历史缺值单据此处为解析结果
)
t
.
period_type
=
period_type
t
.
period_type
=
period_type
t
.
week_num
=
week_num
t
.
week_num
=
week_num
t
.
period_start
=
period_start
t
.
period_start
=
period_start
...
...
data-process/guangai_processor.py
View file @
326f3e6
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
2. 填 7 个字段后上传 → 提交时同步解析校验(validate_attachment_file,失败直接返回错误文件、不建任务):
2. 填 7 个字段后上传 → 提交时同步解析校验(validate_attachment_file,失败直接返回错误文件、不建任务):
- 门店名称精确匹配系统门店清单;对不上的行追加"错误原因"列生成错误文件
- 门店名称精确匹配系统门店清单;对不上的行追加"错误原因"列生成错误文件
- 交车/触客 ≥0 整数;触客率留空=系统算(触客÷交车),有值按 4 位小数校验
- 交车/触客 ≥0 整数;触客率留空=系统算(触客÷交车),有值按 4 位小数校验
- 校验通过 → 新表 guangai_store_report_data(月+维度+商户 唯一,
重复上传软删
覆盖)
- 校验通过 → 新表 guangai_store_report_data(月+维度+商户 唯一,
同键原地更新
覆盖)
- 校验失败 → 任务置 FAILED(错误文件 URL 写入 error_msg),可重新生成
- 校验失败 → 任务置 FAILED(错误文件 URL 写入 error_msg),可重新生成
3. 调度器扫描 PROCESSING 任务 → 指标系统取数 → 渲染模板 → 上传 OSS → COMPLETED
3. 调度器扫描 PROCESSING 任务 → 指标系统取数 → 渲染模板 → 上传 OSS → COMPLETED
...
@@ -71,6 +71,17 @@ SEC_BASE_ROWS = {'title_cur': 39, 'note_cur': 43, 'title_prev': 45, 'note_prev':
...
@@ -71,6 +71,17 @@ SEC_BASE_ROWS = {'title_cur': 39, 'note_cur': 43, 'title_prev': 45, 'note_prev':
SAMPLE_STORE_ROWS
=
31
# 模板样例门店行数(行 7~37)
SAMPLE_STORE_ROWS
=
31
# 模板样例门店行数(行 7~37)
DATA_START_ROW
=
7
DATA_START_ROW
=
7
# 明细区「比率列」(1 起):值由 _pct() 已 ×100(如 0.7652 → 76.52),
# 单元格统一用 0.00"%" 只追加 % 号、不再缩放(与 processor.py 的 RATIO_COLS 口径一致)。
# L 触客率 / O 触客渗透率 / P 交付渗透率 / U 交付渗透率 / V 达成率(目标20%) /
# W~Z 周渗透率 / AH 权益交付渗透率 / AI 权益达成率 / AJ~AM 权益周渗透率 /
# AT 达成(产值) / AV 达成(件数)
RATE_COLS
=
{
12
,
15
,
16
,
21
,
22
,
23
,
24
,
25
,
26
,
34
,
35
,
36
,
37
,
38
,
39
,
46
,
48
}
# 品牌汇总区比率列:G 触客率 / L 触客渗透率 / N 交付渗透率 / O~R 环比
BRAND_SUMMARY_RATE_COLS
=
{
7
,
12
,
14
,
15
,
16
,
17
,
18
}
# 比率列显示格式:仅追加 % 号,不缩放数值
RATE_NUMBER_FORMAT
=
'0.00"
%
"'
def
compute_guangai_week_period
(
month
,
week_num
):
def
compute_guangai_week_period
(
month
,
week_num
):
"""广爱周区间(累计制,严格口径):WN = 当月 1 日 ~ 当月第 N 个周日。
"""广爱周区间(累计制,严格口径):WN = 当月 1 日 ~ 当月第 N 个周日。
...
@@ -420,29 +431,80 @@ class GuangaiProcessor:
...
@@ -420,29 +431,80 @@ class GuangaiProcessor:
wb
.
save
(
out_path
)
wb
.
save
(
out_path
)
return
out_path
return
out_path
# 原地更新时需同步的业务字段(不覆盖 id / created_at / creator)
UPSERT_FIELDS
=
(
'merchant_name'
,
'brand'
,
'after_sales_enabled'
,
'group_delivery_cnt'
,
'group_refer_cnt'
,
'refer_rate'
,
'output_target'
,
'unit_target'
,
'period_start'
,
'period_end'
)
def
store_validated_rows
(
self
,
rows
,
task_id
,
operator
):
def
store_validated_rows
(
self
,
rows
,
task_id
,
operator
):
"""校验通过的行入库:同 月+维度+商户 软删旧行再插新行。"""
"""校验通过的行入库:按 月+维度+商户 **原地更新**(不存在才新增)。
⚠ 不能"软删旧行再插新行":唯一键 uq_guangai_store_dim 为
(month, period_type, week_num, merchant_id),不含 is_deleted/task_id,
软删的行仍占键 → 同一周期重新生成(task_id 不变)或重复上传必然
撞 1062 Duplicate entry(2026-10-20 实测:2026-09-week-3 重新生成报错)。
month 维度因 week_num 为 NULL 不参与唯一性判定,才侥幸没暴露。
因此改为:命中已有行 → 原地覆盖业务字段并复活;文件里已不存在的门店
才软删(保留可追溯,后续重新出现会被复活)。
"""
if
not
rows
:
if
not
rows
:
return
0
return
0
from
datetime
import
datetime
as
_dt
from
datetime
import
datetime
as
_dt
now
=
_dt
.
now
()
first
=
rows
[
0
]
first
=
rows
[
0
]
old
=
GuangaiStoreReportData
.
query
.
filter_by
(
# 取该 月+维度 下的全部行(含已软删),按商户号分组:有效行优先
existing
=
GuangaiStoreReportData
.
query
.
filter_by
(
month
=
first
.
month
,
month
=
first
.
month
,
period_type
=
first
.
period_type
,
period_type
=
first
.
period_type
,
week_num
=
first
.
week_num
,
week_num
=
first
.
week_num
,
is_deleted
=
0
,
)
.
order_by
(
GuangaiStoreReportData
.
is_deleted
.
asc
(),
)
.
all
()
GuangaiStoreReportData
.
id
.
asc
())
.
all
()
for
o
in
old
:
by_mid
=
{}
o
.
is_deleted
=
1
for
e
in
existing
:
o
.
deleted_at
=
_dt
.
now
()
by_mid
.
setdefault
(
e
.
merchant_id
,
[])
.
append
(
e
)
keep_mids
=
set
()
inserted
=
updated
=
purged
=
0
for
row
in
rows
:
for
row
in
rows
:
row
.
task_id
=
task_id
keep_mids
.
add
(
row
.
merchant_id
)
row
.
creator
=
operator
hits
=
by_mid
.
get
(
row
.
merchant_id
)
or
[]
row
.
updater
=
operator
if
hits
:
db
.
session
.
add_all
(
rows
)
target
=
hits
[
0
]
for
f
in
self
.
UPSERT_FIELDS
:
setattr
(
target
,
f
,
getattr
(
row
,
f
))
target
.
task_id
=
task_id
target
.
updater
=
operator
target
.
is_deleted
=
0
target
.
deleted_at
=
None
updated
+=
1
# 历史重复行(同一商户多行)物理删除,避免继续占用唯一键
for
dup
in
hits
[
1
:]:
db
.
session
.
delete
(
dup
)
purged
+=
1
else
:
row
.
task_id
=
task_id
row
.
creator
=
operator
row
.
updater
=
operator
db
.
session
.
add
(
row
)
inserted
+=
1
# 本次附件中已不存在的门店 → 软删
removed
=
0
for
mid
,
ents
in
by_mid
.
items
():
if
mid
in
keep_mids
:
continue
for
e
in
ents
:
if
not
e
.
is_deleted
:
e
.
is_deleted
=
1
e
.
deleted_at
=
now
e
.
updater
=
operator
removed
+=
1
db
.
session
.
commit
()
db
.
session
.
commit
()
logger
.
info
(
f
"[广爱专项] 附件数据入库 {len(rows)} 行(覆盖旧记录 {len(old)} 行)"
)
logger
.
info
(
f
"[广爱专项] 附件数据入库:新增 {inserted} 行、更新 {updated} 行、"
return
len
(
rows
)
f
"软删 {removed} 行、清理重复 {purged} 行"
)
return
inserted
+
updated
@staticmethod
@staticmethod
def
_parse_nonneg_int
(
val
,
allow_empty
=
False
,
label
=
''
,
errors
=
None
):
def
_parse_nonneg_int
(
val
,
allow_empty
=
False
,
label
=
''
,
errors
=
None
):
...
@@ -925,6 +987,9 @@ class GuangaiProcessor:
...
@@ -925,6 +987,9 @@ class GuangaiProcessor:
cell
.
_style
=
copy
(
row_styles
.
get
(
col
))
cell
.
_style
=
copy
(
row_styles
.
get
(
col
))
val
=
values
.
get
(
col
)
val
=
values
.
get
(
col
)
cell
.
value
=
val
if
val
is
not
None
else
None
cell
.
value
=
val
if
val
is
not
None
else
None
# 比率列统一追加 % 号(值已是 ×100 的百分数,格式不再缩放)
if
col
in
RATE_COLS
:
cell
.
number_format
=
RATE_NUMBER_FORMAT
fill
=
RATE_FILL
.
get
(
val
)
if
isinstance
(
val
,
str
)
else
None
fill
=
RATE_FILL
.
get
(
val
)
if
isinstance
(
val
,
str
)
else
None
if
fill
:
if
fill
:
cell
.
fill
=
PatternFill
(
start_color
=
fill
,
end_color
=
fill
,
cell
.
fill
=
PatternFill
(
start_color
=
fill
,
end_color
=
fill
,
...
@@ -952,7 +1017,11 @@ class GuangaiProcessor:
...
@@ -952,7 +1017,11 @@ class GuangaiProcessor:
# 合计行(行 6)
# 合计行(行 6)
def
set6
(
col
,
val
):
def
set6
(
col
,
val
):
ws
.
cell
(
row
=
6
,
column
=
col
)
.
value
=
val
if
val
is
not
None
else
None
cell
=
ws
.
cell
(
row
=
6
,
column
=
col
)
cell
.
value
=
val
if
val
is
not
None
else
None
# 比率列统一追加 % 号(与明细行同口径)
if
col
in
RATE_COLS
:
cell
.
number_format
=
RATE_NUMBER_FORMAT
set6
(
1
,
'合计'
)
set6
(
1
,
'合计'
)
for
c
in
range
(
2
,
10
):
for
c
in
range
(
2
,
10
):
...
@@ -1093,7 +1162,11 @@ class GuangaiProcessor:
...
@@ -1093,7 +1162,11 @@ class GuangaiProcessor:
for
r
,
row
in
((
r_cur
,
row_cur
),
(
r_prev
,
row_prev
)):
for
r
,
row
in
((
r_cur
,
row_cur
),
(
r_prev
,
row_prev
)):
for
col
,
val
in
row
.
items
():
for
col
,
val
in
row
.
items
():
ws
.
cell
(
row
=
r
,
column
=
col
)
.
value
=
val
cell
=
ws
.
cell
(
row
=
r
,
column
=
col
)
cell
.
value
=
val
# 品牌汇总比率列一并追加 % 号
if
col
in
BRAND_SUMMARY_RATE_COLS
:
cell
.
number_format
=
RATE_NUMBER_FORMAT
# 上月行 O~R 留空(环比只在本月行)
# 上月行 O~R 留空(环比只在本月行)
for
col
in
range
(
15
,
19
):
for
col
in
range
(
15
,
19
):
ws
.
cell
(
row
=
r_prev
,
column
=
col
)
.
value
=
None
ws
.
cell
(
row
=
r_prev
,
column
=
col
)
.
value
=
None
...
...
data-process/models.py
View file @
326f3e6
...
@@ -1131,15 +1131,15 @@ class CommonEquityMonthSnapshot(db.Model):
...
@@ -1131,15 +1131,15 @@ class CommonEquityMonthSnapshot(db.Model):
class
GuangaiStoreReportData
(
db
.
Model
):
class
GuangaiStoreReportData
(
db
.
Model
):
"""广爱专项-门店维度上传数据(附件解析入库,按 月+维度+商户
+任务 唯一,重复上传
覆盖)"""
"""广爱专项-门店维度上传数据(附件解析入库,按 月+维度+商户
唯一,同键原地更新
覆盖)"""
__tablename__
=
'guangai_store_report_data'
__tablename__
=
'guangai_store_report_data'
__table_args__
=
(
__table_args__
=
(
# ⚠
唯一键必须含 task_id:周维度 week_num 非空,若仅 (month,period_type,week_num,merchant_id)
,
# ⚠
生产库实际索引就是这 4 列(不含 task_id);因为不含 is_deleted
,
# 软删的
旧行会永久占用键导致"重复上传=覆盖"必然冲突(2026-10-19 实测);
# 软删的
行仍会占用唯一键 → 入库必须走"原地 upsert"
#
month 维度因 week_num 为 NULL 侥幸不冲突。task_id 每次上传不同 → 不冲突
,
#
(GuangaiProcessor.store_validated_rows),严禁"软删旧行再插新行"
,
#
当前有效行由 is_deleted=0 过滤保证
。
#
否则同一周期重新生成必撞 1062(2026-10-20 实测)
。
db
.
UniqueConstraint
(
'month'
,
'period_type'
,
'week_num'
,
'merchant_id'
,
db
.
UniqueConstraint
(
'month'
,
'period_type'
,
'week_num'
,
'merchant_id'
,
'task_id'
,
name
=
'uq_guangai_store_dim'
),
name
=
'uq_guangai_store_dim'
),
{
'comment'
:
'广爱专项-门店维度上传数据'
},
{
'comment'
:
'广爱专项-门店维度上传数据'
},
)
)
...
...
data-process/static/css/style.css
View file @
326f3e6
...
@@ -483,3 +483,14 @@ tbody tr:hover { background: #f8fafd; }
...
@@ -483,3 +483,14 @@ tbody tr:hover { background: #f8fafd; }
background
:
#185fa5
;
background
:
#185fa5
;
color
:
#fff
;
color
:
#fff
;
}
}
/* 置灰(重新生成时周期锁定,不可切换) */
.seg-group
.seg-btn
:disabled
{
cursor
:
not-allowed
;
color
:
#a8abb2
;
background
:
#f5f7fa
;
}
.seg-group
.seg-btn
:disabled:hover
{
color
:
#a8abb2
;
}
.seg-group
.seg-btn.active
:disabled
{
background
:
#a8abb2
;
color
:
#fff
;
}
data-process/static/js/list.js
View file @
326f3e6
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
var
formFiles
=
{};
// form_type -> { file, fileName, size, oldUrl }
var
formFiles
=
{};
// form_type -> { file, fileName, size, oldUrl }
var
modalPeriodType
=
'month'
;
// 'month' | 'week'
var
modalPeriodType
=
'month'
;
// 'month' | 'week'
var
modalWeekNum
=
null
;
// 1~当月周数(4~6)
var
modalWeekNum
=
null
;
// 1~当月周数(4~6)
var
modalPeriodLocked
=
false
;
// true = 重新生成:周期沿用原单据,控件全部置灰
var
editingTaskPeriod
=
null
;
// 重新生成时原单据的周期(提交时原样回传)
// ---------- 通用 ----------
// ---------- 通用 ----------
function
api
(
url
,
opts
)
{
function
api
(
url
,
opts
)
{
...
@@ -379,12 +381,17 @@
...
@@ -379,12 +381,17 @@
if
(
isWeek
||
need
)
{
if
(
isWeek
||
need
)
{
// 按周:无论 need_period 是什么,都显示周期行且 disabled
// 按周:无论 need_period 是什么,都显示周期行且 disabled
// 按月 + need_period=True:显示,可编辑(现有行为)
// 按月 + need_period=True:显示,可编辑(现有行为)
// 重新生成(modalPeriodLocked):任何情况都 disabled,只能看不能改
mPeriodRow
.
style
.
display
=
''
;
mPeriodRow
.
style
.
display
=
''
;
if
(
isWeek
)
{
if
(
isWeek
)
{
mPeriodStart
.
disabled
=
true
;
mPeriodStart
.
disabled
=
true
;
mPeriodEnd
.
disabled
=
true
;
mPeriodEnd
.
disabled
=
true
;
// 按周时自动填入日期(如果已有 weekNum)
// 按周时自动填入日期(如果已有 weekNum)
if
(
modalWeekNum
)
applyWeekPeriod
(
modalWeekNum
);
if
(
modalWeekNum
)
applyWeekPeriod
(
modalWeekNum
);
}
else
if
(
modalPeriodLocked
)
{
mPeriodStart
.
disabled
=
true
;
mPeriodEnd
.
disabled
=
true
;
if
(
!
mPeriodStart
.
value
||
!
mPeriodEnd
.
value
)
setPeriodDefault
(
mMonth
.
value
);
}
else
{
}
else
{
mPeriodStart
.
disabled
=
false
;
mPeriodStart
.
disabled
=
false
;
mPeriodEnd
.
disabled
=
false
;
mPeriodEnd
.
disabled
=
false
;
...
@@ -491,6 +498,8 @@
...
@@ -491,6 +498,8 @@
sel
.
appendChild
(
opt
);
sel
.
appendChild
(
opt
);
});
});
sel
.
style
.
display
=
''
;
sel
.
style
.
display
=
''
;
// 重新生成:周下拉置灰(禁用后浏览器不再派发 click,用户无法改周)
sel
.
disabled
=
modalPeriodLocked
;
// 选中已有的 weekNum(重新生成回填时),否则默认 W1
// 选中已有的 weekNum(重新生成回填时),否则默认 W1
if
(
modalWeekNum
)
{
if
(
modalWeekNum
)
{
sel
.
value
=
String
(
modalWeekNum
);
sel
.
value
=
String
(
modalWeekNum
);
...
@@ -531,6 +540,13 @@
...
@@ -531,6 +540,13 @@
// 周期提示:结束日期 ≤ 月份最后一天;开始默认1号
// 周期提示:结束日期 ≤ 月份最后一天;开始默认1号
function
updatePeriodHint
()
{
function
updatePeriodHint
()
{
if
(
!
mPeriodRow
||
mPeriodRow
.
style
.
display
===
'none'
)
return
;
if
(
!
mPeriodRow
||
mPeriodRow
.
style
.
display
===
'none'
)
return
;
// 重新生成:周期锁定为原单据值,提示只读
if
(
modalPeriodLocked
)
{
mPeriodStart
.
disabled
=
true
;
mPeriodEnd
.
disabled
=
true
;
if
(
mPeriodHint
)
mPeriodHint
.
textContent
=
'重新生成沿用原单据周期,不可修改'
;
return
;
}
if
(
!
mMonth
.
value
)
{
if
(
mPeriodHint
)
mPeriodHint
.
textContent
=
''
;
return
;
}
if
(
!
mMonth
.
value
)
{
if
(
mPeriodHint
)
mPeriodHint
.
textContent
=
''
;
return
;
}
var
last
=
lastDayOfMonth
(
mMonth
.
value
);
var
last
=
lastDayOfMonth
(
mMonth
.
value
);
var
maxEnd
=
mMonth
.
value
+
'-'
+
String
(
last
).
padStart
(
2
,
'0'
);
var
maxEnd
=
mMonth
.
value
+
'-'
+
String
(
last
).
padStart
(
2
,
'0'
);
...
@@ -551,6 +567,14 @@
...
@@ -551,6 +567,14 @@
// 初始化周期粒度状态(regenerate 时从任务回填,否则默认 month)
// 初始化周期粒度状态(regenerate 时从任务回填,否则默认 month)
modalPeriodType
=
(
task
&&
task
.
period_type
)
?
task
.
period_type
:
'month'
;
modalPeriodType
=
(
task
&&
task
.
period_type
)
?
task
.
period_type
:
'month'
;
modalWeekNum
=
(
task
&&
task
.
week_num
)
?
task
.
week_num
:
null
;
modalWeekNum
=
(
task
&&
task
.
week_num
)
?
task
.
week_num
:
null
;
// 重新生成:类型 / 月份 / 周期全部锁定(沿用原单据周期,用户不可选择)
modalPeriodLocked
=
(
mode
===
'regenerate'
);
editingTaskPeriod
=
(
modalPeriodLocked
&&
task
)
?
{
period_type
:
task
.
period_type
||
'month'
,
week_num
:
task
.
week_num
||
null
,
period_start
:
task
.
period_start
||
''
,
period_end
:
task
.
period_end
||
''
}
:
null
;
document
.
getElementById
(
'modalTitle'
).
textContent
=
mode
===
'regenerate'
?
'重新生成'
:
'新增数据'
;
document
.
getElementById
(
'modalTitle'
).
textContent
=
mode
===
'regenerate'
?
'重新生成'
:
'新增数据'
;
fillModalTypes
();
fillModalTypes
();
mType
.
value
=
task
?
task
.
data_table_type
:
''
;
mType
.
value
=
task
?
task
.
data_table_type
:
''
;
...
@@ -590,6 +614,14 @@
...
@@ -590,6 +614,14 @@
}
else
{
}
else
{
document
.
getElementById
(
'mWeekSelect'
).
style
.
display
=
'none'
;
document
.
getElementById
(
'mWeekSelect'
).
style
.
display
=
'none'
;
}
}
// 重新生成:周期相关控件全部置灰(粒度按钮 / 周下拉 / 起止日期),只能看不能改
btns
.
forEach
(
function
(
b
)
{
b
.
disabled
=
modalPeriodLocked
;
});
document
.
getElementById
(
'mWeekSelect'
).
disabled
=
modalPeriodLocked
;
if
(
modalPeriodLocked
)
{
mPeriodStart
.
disabled
=
true
;
mPeriodEnd
.
disabled
=
true
;
}
updatePeriodHint
();
// 编辑态:用原文件回填文件名
// 编辑态:用原文件回填文件名
if
(
locked
&&
task
&&
task
.
files
)
{
if
(
locked
&&
task
&&
task
.
files
)
{
task
.
files
.
forEach
(
function
(
f
)
{
task
.
files
.
forEach
(
function
(
f
)
{
...
@@ -612,6 +644,14 @@
...
@@ -612,6 +644,14 @@
modal
.
style
.
display
=
'none'
;
modal
.
style
.
display
=
'none'
;
modalMode
=
''
;
editingTaskId
=
null
;
formFiles
=
{};
modalMode
=
''
;
editingTaskId
=
null
;
formFiles
=
{};
modalPeriodType
=
'month'
;
modalWeekNum
=
null
;
modalPeriodType
=
'month'
;
modalWeekNum
=
null
;
modalPeriodLocked
=
false
;
editingTaskPeriod
=
null
;
// 恢复周期控件可用态(否则下一次「新增」会沿用上一次的禁用态)
document
.
querySelectorAll
(
'#mPeriodTypeGroup .seg-btn'
).
forEach
(
function
(
b
)
{
b
.
disabled
=
false
;
});
document
.
getElementById
(
'mWeekSelect'
).
disabled
=
false
;
mPeriodStart
.
disabled
=
false
;
mPeriodEnd
.
disabled
=
false
;
// 防御性:清理可能残留的 loading 遮罩与「确定」按钮禁用态
// 防御性:清理可能残留的 loading 遮罩与「确定」按钮禁用态
var
lm
=
document
.
getElementById
(
'loadingMask'
);
var
lm
=
document
.
getElementById
(
'loadingMask'
);
if
(
lm
)
lm
.
style
.
display
=
'none'
;
if
(
lm
)
lm
.
style
.
display
=
'none'
;
...
@@ -719,6 +759,13 @@
...
@@ -719,6 +759,13 @@
payload
.
period_start
=
mPeriodStart
.
value
;
payload
.
period_start
=
mPeriodStart
.
value
;
payload
.
period_end
=
mPeriodEnd
.
value
;
payload
.
period_end
=
mPeriodEnd
.
value
;
}
}
// 重新生成:周期沿用原单据(后端同样以任务上的周期为准,这里双保险)
if
(
modalMode
===
'regenerate'
&&
editingTaskPeriod
)
{
payload
.
period_type
=
editingTaskPeriod
.
period_type
;
payload
.
week_num
=
editingTaskPeriod
.
week_num
;
if
(
editingTaskPeriod
.
period_start
)
payload
.
period_start
=
editingTaskPeriod
.
period_start
;
if
(
editingTaskPeriod
.
period_end
)
payload
.
period_end
=
editingTaskPeriod
.
period_end
;
}
var
url
=
modalMode
===
'regenerate'
var
url
=
modalMode
===
'regenerate'
?
'/api/tasks/'
+
editingTaskId
+
'/regenerate'
?
'/api/tasks/'
+
editingTaskId
+
'/regenerate'
:
'/api/tasks'
;
:
'/api/tasks'
;
...
@@ -793,6 +840,8 @@
...
@@ -793,6 +840,8 @@
mType
.
addEventListener
(
'change'
,
onTypeChange
);
mType
.
addEventListener
(
'change'
,
onTypeChange
);
mMonth
.
addEventListener
(
'change'
,
function
()
{
mMonth
.
addEventListener
(
'change'
,
function
()
{
// 重新生成:周期锁定,禁止月份事件把回填的原单据周期(周序号/起止日期)冲掉
if
(
modalPeriodLocked
)
return
;
var
cfg
=
typeConfigs
.
find
(
function
(
t
)
{
return
t
.
code
===
mType
.
value
;
});
var
cfg
=
typeConfigs
.
find
(
function
(
t
)
{
return
t
.
code
===
mType
.
value
;
});
if
(
modalPeriodType
===
'week'
)
{
if
(
modalPeriodType
===
'week'
)
{
// 按周:月份变了重新生成周选项
// 按周:月份变了重新生成周选项
...
@@ -826,6 +875,8 @@
...
@@ -826,6 +875,8 @@
// ---------- 弹窗:周期粒度切换 ----------
// ---------- 弹窗:周期粒度切换 ----------
document
.
querySelectorAll
(
'#mPeriodTypeGroup .seg-btn'
).
forEach
(
function
(
btn
)
{
document
.
querySelectorAll
(
'#mPeriodTypeGroup .seg-btn'
).
forEach
(
function
(
btn
)
{
btn
.
addEventListener
(
'click'
,
function
()
{
btn
.
addEventListener
(
'click'
,
function
()
{
// 重新生成:周期锁定,不允许切换粒度
if
(
modalPeriodLocked
)
return
;
var
cfg
=
typeConfigs
.
find
(
function
(
t
)
{
return
t
.
code
===
mType
.
value
;
});
var
cfg
=
typeConfigs
.
find
(
function
(
t
)
{
return
t
.
code
===
mType
.
value
;
});
// 防御:当前类型不支持按周时忽略点击(理论上行已隐藏,用户不可达)
// 防御:当前类型不支持按周时忽略点击(理论上行已隐藏,用户不可达)
if
(
!
cfg
||
!
cfg
.
support_week
)
return
;
if
(
!
cfg
||
!
cfg
.
support_week
)
return
;
...
@@ -840,7 +891,13 @@
...
@@ -840,7 +891,13 @@
if
(
modalPeriodType
===
'week'
)
{
if
(
modalPeriodType
===
'week'
)
{
// 按周:渲染周下拉 + 自动计算日期
// 按周:渲染周下拉 + 自动计算日期
document
.
getElementById
(
'mWeekSelect'
).
style
.
display
=
''
;
document
.
getElementById
(
'mWeekSelect'
).
style
.
display
=
''
;
if
(
mMonth
.
value
)
renderWeekSelect
(
mMonth
.
value
);
if
(
mMonth
.
value
)
{
renderWeekSelect
(
mMonth
.
value
);
}
else
{
// 月份未选时周区间算不出来,下拉会空着——明确提示,避免误以为"不可选"
// (选好月份后 mMonth 的 change 监听会自动补渲染)
toast
(
'请先选择所属月份,再选择按周'
,
true
);
}
}
else
{
}
else
{
// 按月:隐藏周下拉 + 恢复默认
// 按月:隐藏周下拉 + 恢复默认
document
.
getElementById
(
'mWeekSelect'
).
style
.
display
=
'none'
;
document
.
getElementById
(
'mWeekSelect'
).
style
.
display
=
'none'
;
...
...
data-process/test_guangai_processor.py
View file @
326f3e6
...
@@ -228,6 +228,22 @@ class TestBuildWorkbook(unittest.TestCase):
...
@@ -228,6 +228,22 @@ class TestBuildWorkbook(unittest.TestCase):
os
.
remove
(
os
.
path
.
join
(
cls
.
tmp
,
f
))
os
.
remove
(
os
.
path
.
join
(
cls
.
tmp
,
f
))
os
.
rmdir
(
cls
.
tmp
)
os
.
rmdir
(
cls
.
tmp
)
def
test_rate_cells_have_percent_format
(
self
):
"""比率列(含合计行)必须带 0.00"
%
" 格式,导出后在单元格里显示
%
号。
覆盖:L/O/P 上月、U 交付渗透率、V 达成率(目标20
%
)、W~Z 周渗透率、
AH 权益交付渗透率、AI 权益达成率、AJ~AM 权益周渗透率、AT 产值达成、AV 件数达成。
值本身已是 _pct() ×100 的百分数,格式只追加
%
号、不再缩放。
"""
from
guangai_processor
import
RATE_COLS
,
RATE_NUMBER_FORMAT
self
.
assertTrue
(
RATE_COLS
,
'RATE_COLS 不应为空'
)
for
col
in
sorted
(
RATE_COLS
):
for
row
in
(
6
,
7
,
8
):
# 6=合计行,7/8=明细行
cell
=
self
.
ws
.
cell
(
row
=
row
,
column
=
col
)
self
.
assertEqual
(
cell
.
number_format
,
RATE_NUMBER_FORMAT
,
f
'第 {row} 行第 {col} 列应为 {RATE_NUMBER_FORMAT},实际 {cell.number_format}'
)
def
test_title_replaced
(
self
):
def
test_title_replaced
(
self
):
"""行 1 标题:8月→9月、2026-08-16→2026-09-26、8.16→9.26"""
"""行 1 标题:8月→9月、2026-08-16→2026-09-26、8.16→9.26"""
t
=
str
(
self
.
ws
.
cell
(
row
=
1
,
column
=
1
)
.
value
)
t
=
str
(
self
.
ws
.
cell
(
row
=
1
,
column
=
1
)
.
value
)
...
...
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