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 3fcdf2e8
authored
May 12, 2026
by
林冲
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
step11_2_1_fix_expense_category_rule_parent_id 修复parent_id
1 parent
cabf413d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
0 deletions
scene_refactor_data/scene_split_processor.py
scene_refactor_data/scene_split_processor.py
View file @
3fcdf2e
...
@@ -1652,6 +1652,9 @@ class SceneSplitProcessor:
...
@@ -1652,6 +1652,9 @@ class SceneSplitProcessor:
# 子步骤2:处理表3(费用类目规则表,rule_type=3)
# 子步骤2:处理表3(费用类目规则表,rule_type=3)
self
.
step11_2_process_expense_category_rule_reconciliation
()
self
.
step11_2_process_expense_category_rule_reconciliation
()
# 子步骤2-1:修补费用类目规则表的parent_id
self
.
step11_2_1_fix_expense_category_rule_parent_id
()
# 子步骤3:处理表5(商品分组关系表,rule_type=3)
# 子步骤3:处理表5(商品分组关系表,rule_type=3)
self
.
step11_3_process_goods_type_group_relation_reconciliation
()
self
.
step11_3_process_goods_type_group_relation_reconciliation
()
...
@@ -1887,6 +1890,68 @@ class SceneSplitProcessor:
...
@@ -1887,6 +1890,68 @@ class SceneSplitProcessor:
self
.
logger
.
info
(
f
"第11步-2完成,共复制 {copy_count} 条记录"
)
self
.
logger
.
info
(
f
"第11步-2完成,共复制 {copy_count} 条记录"
)
def
step11_2_1_fix_expense_category_rule_parent_id
(
self
):
"""
第11步-2-1:修补费用类目规则表的parent_id
将parent_id指向新复制的记录ID
"""
table_name
=
'dj_car_life_merchant_expense_category_rule'
self
.
logger
.
info
(
f
"第11步-2-1:开始修补费用类目规则表的parent_id"
)
# 执行修补SQL
fix_sql
=
"""
UPDATE dj_car_life_merchant_expense_category_rule cr
INNER JOIN
(SELECT goods_type_group_rule_id, parent_id, MIN(id) min_id
FROM (SELECT id, parent_id, goods_type_group_rule_id
FROM dj_car_life_merchant_expense_category_rule
WHERE created_by = 'DATA_MIGRATION'
AND deleted_flag = 'N'
AND parent_id IS NOT NULL
ORDER BY id ASC) tmp
GROUP BY goods_type_group_rule_id, parent_id)
t ON t.parent_id = cr.parent_id AND t.goods_type_group_rule_id = cr.goods_type_group_rule_id
SET cr.parent_id = min_id - 1
WHERE
cr.created_by = 'DATA_MIGRATION' AND cr.deleted_flag = 'N';
"""
try
:
# 先查询需要修补的记录数
count_sql
=
"""
SELECT COUNT(*)
FROM dj_car_life_merchant_expense_category_rule cr
INNER JOIN
(SELECT goods_type_group_rule_id, parent_id, MIN(id) min_id
FROM (SELECT id, parent_id, goods_type_group_rule_id
FROM dj_car_life_merchant_expense_category_rule
WHERE created_by = 'DATA_MIGRATION'
AND deleted_flag = 'N'
AND parent_id IS NOT NULL
ORDER BY id ASC) tmp
GROUP BY goods_type_group_rule_id, parent_id)
t ON t.parent_id = cr.parent_id AND t.goods_type_group_rule_id = cr.goods_type_group_rule_id
WHERE
cr.created_by = 'DATA_MIGRATION' AND cr.deleted_flag = 'N';
"""
count_result
=
self
.
db
.
execute_query_one
(
count_sql
)
affected_count
=
count_result
[
0
]
if
count_result
else
0
self
.
logger
.
info
(
f
" 需要修补的记录数:{affected_count}"
)
if
affected_count
==
0
:
self
.
logger
.
info
(
f
"第11步-2-1完成,没有需要修补的记录"
)
return
# 执行修补
if
self
.
db
.
execute_update
(
fix_sql
):
self
.
logger
.
info
(
f
"第11步-2-1完成,成功修补 {affected_count} 条记录的parent_id"
)
else
:
self
.
logger
.
error
(
f
"第11步-2-1失败,修补parent_id时发生错误"
)
except
Exception
as
e
:
self
.
logger
.
error
(
f
"第11步-2-1执行失败:{str(e)}"
)
raise
def
step11_3_process_goods_type_group_relation_reconciliation
(
self
):
def
step11_3_process_goods_type_group_relation_reconciliation
(
self
):
"""
"""
第11步-3:处理商品分组关系表(对账侧,rule_type=3)
第11步-3:处理商品分组关系表(对账侧,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