Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
dj
/
dealaccountdata
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 0587f16f
authored
May 10, 2026
by
林冲
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
_process_audit_finance性能优化
1 parent
5f342069
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
56 deletions
scene_refactor_data/scene_split_processor.py
scene_refactor_data/scene_split_processor.py
View file @
0587f16
...
...
@@ -1352,66 +1352,86 @@ class SceneSplitProcessor:
settle_table
=
'dj_car_life_merchant_settle_account_rule'
division_table
=
'dj_car_life_merchant_division_rule'
# 查询表1和表6的映射关系
query_mapping_sql
=
f
"""
SELECT DISTINCT
m1.old_id as old_settle_id,
m1.new_id as new_settle_id,
m6.old_id as old_division_id,
m6.new_id as new_division_id,
m1.base_scene_code
FROM tmp_rule_id_mapping m1
JOIN tmp_rule_id_mapping m6
ON m6.table_name = '{division_table}'
AND m6.base_scene_code = m1.base_scene_code
WHERE m1.table_name = '{settle_table}'
AND m1.old_id != m1.new_id
AND m6.old_id != m6.new_id
ORDER BY m1.old_id, m1.base_scene_code;
# 从dj_car_life_rule_audit出发,查询需要拆分的旧数据
query_old_audit_sql
=
f
"""
SELECT id, merchant_id, merchant_name, scene_type, rule_type,
rule_id, division_rule_id, effect_date_type, effect_start_date,
audit_status, audit_by, auditor_name, audit_date,
creator_name, enabled_flag, created_by, created_date, updated_by, updated_date
FROM {table_name}
WHERE scene_type = 0
AND rule_type = 1
AND deleted_flag = 'N'
ORDER BY id;
"""
mappings
=
self
.
db
.
execute_query
(
query_mapping
_sql
)
self
.
logger
.
info
(
f
" 找到 {len(
mappings)} 条财务规则映射关系需要处理
"
)
old_audit_records
=
self
.
db
.
execute_query
(
query_old_audit
_sql
)
self
.
logger
.
info
(
f
" 找到 {len(
old_audit_records)} 条需要拆分的财务审核记录
"
)
copy_count
=
0
for
mapping
in
mappings
:
old_settle_id
=
mapping
[
0
]
new_settle_id
=
mapping
[
1
]
old_division_id
=
mapping
[
2
]
new_division_id
=
mapping
[
3
]
base_scene_code
=
mapping
[
4
]
skip_count
=
0
# 查询原审核记录
query_sql
=
f
"""
SELECT id, merchant_id, merchant_name, scene_type, rule_type,
rule_id, division_rule_id, effect_date_type, effect_start_date,
audit_status, audit_by, auditor_name, audit_date,
creator_name, enabled_flag, created_by, created_date, updated_by, updated_date
FROM {table_name}
WHERE rule_type = 1
AND rule_id = {old_settle_id}
AND division_rule_id = {old_division_id}
AND deleted_flag = 'N';
for
old_record
in
old_audit_records
:
old_id
=
old_record
[
0
]
merchant_id
=
old_record
[
1
]
merchant_name
=
old_record
[
2
]
scene_type
=
old_record
[
3
]
rule_type
=
old_record
[
4
]
old_rule_id
=
old_record
[
5
]
old_division_rule_id
=
old_record
[
6
]
effect_date_type
=
old_record
[
7
]
effect_start_date
=
f
"'{old_record[8]}'"
if
old_record
[
8
]
is
not
None
else
'NULL'
audit_status
=
old_record
[
9
]
audit_by
=
f
"'{old_record[10]}'"
if
old_record
[
10
]
is
not
None
else
'NULL'
auditor_name
=
f
"'{old_record[11]}'"
if
old_record
[
11
]
is
not
None
else
'NULL'
audit_date
=
f
"'{old_record[12]}'"
if
old_record
[
12
]
is
not
None
else
'NULL'
creator_name
=
old_record
[
13
]
enabled_flag
=
old_record
[
14
]
created_by
=
old_record
[
15
]
created_date
=
old_record
[
16
]
updated_by
=
old_record
[
17
]
updated_date
=
old_record
[
18
]
# 查询rule_id对应的拆分后的数据
query_settle_mapping_sql
=
f
"""
SELECT new_id, base_scene_code
FROM tmp_rule_id_mapping
WHERE table_name = '{settle_table}'
AND old_id = {old_rule_id}
ORDER BY old_id, base_scene_code;
"""
records
=
self
.
db
.
execute_query
(
query
_sql
)
settle_mappings
=
self
.
db
.
execute_query
(
query_settle_mapping
_sql
)
for
record
in
records
:
old_id
=
record
[
0
]
merchant_id
=
record
[
1
]
merchant_name
=
record
[
2
]
scene_type
=
record
[
3
]
rule_type
=
record
[
4
]
effect_date_type
=
record
[
7
]
effect_start_date
=
f
"'{record[8]}'"
if
record
[
8
]
is
not
None
else
'NULL'
audit_status
=
record
[
9
]
audit_by
=
f
"'{record[10]}'"
if
record
[
10
]
is
not
None
else
'NULL'
auditor_name
=
f
"'{record[11]}'"
if
record
[
11
]
is
not
None
else
'NULL'
audit_date
=
f
"'{record[12]}'"
if
record
[
12
]
is
not
None
else
'NULL'
creator_name
=
record
[
13
]
enabled_flag
=
record
[
14
]
created_by
=
record
[
15
]
created_date
=
record
[
16
]
updated_by
=
record
[
17
]
updated_date
=
record
[
18
]
# 查询division_rule_id对应的拆分后的数据
division_mappings
=
[]
if
old_division_rule_id
is
not
None
:
query_division_mapping_sql
=
f
"""
SELECT new_id, base_scene_code
FROM tmp_rule_id_mapping
WHERE table_name = '{division_table}'
AND old_id = {old_division_rule_id}
ORDER BY old_id, base_scene_code;
"""
division_mappings
=
self
.
db
.
execute_query
(
query_division_mapping_sql
)
# 检查两个映射列表的长度是否一致
if
len
(
settle_mappings
)
==
0
:
self
.
logger
.
warning
(
f
" 审核记录 id={old_id} 的 rule_id={old_rule_id} 没有找到映射关系,跳过"
)
skip_count
+=
1
continue
if
old_division_rule_id
is
not
None
and
len
(
division_mappings
)
!=
len
(
settle_mappings
):
self
.
logger
.
warning
(
f
" 审核记录 id={old_id} 的 settle 和 division 映射数量不一致,跳过"
)
skip_count
+=
1
continue
# 按顺序组装新记录
for
i
in
range
(
len
(
settle_mappings
)):
new_settle_id
=
settle_mappings
[
i
][
0
]
base_scene_code
=
settle_mappings
[
i
][
1
]
new_division_id
=
'NULL'
if
division_mappings
and
i
<
len
(
division_mappings
):
new_division_id
=
division_mappings
[
i
][
0
]
insert_sql
=
f
"""
INSERT INTO {table_name}
...
...
@@ -1434,9 +1454,9 @@ class SceneSplitProcessor:
new_id
=
result
[
0
]
self
.
id_mapper
.
add_mapping
(
table_name
,
old_id
,
new_id
,
base_scene_code
)
copy_count
+=
1
self
.
logger
.
debug
(
f
" 复制财务审核: old_id={old_id} -> new_id={new_id}"
)
self
.
logger
.
debug
(
f
" 复制财务审核: old_id={old_id} -> new_id={new_id}
, base_scene_code={base_scene_code}
"
)
self
.
logger
.
info
(
f
" 财务审核记录复制完成,共 {copy_count} 条"
)
self
.
logger
.
info
(
f
" 财务审核记录复制完成,共 {copy_count} 条
,跳过 {skip_count} 条
"
)
def
_process_audit_reconciliation
(
self
):
"""处理对账审核记录(rule_type=3)"""
...
...
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