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 8f0f620a
authored
May 08, 2026
by
林冲
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
effect表通过多个维度补充数据
1 parent
11f16199
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
228 additions
and
0 deletions
.gitignore
scene_refactor_data/scene_split_processor.py
scene_refactor_data/step13_modification_summary.md
.gitignore
0 → 100644
View file @
8f0f620
# IntelliJ / IDEA
*.iml
.idea/
out/
scene_refactor_data/*.xml
scene_refactor_data/*.log
\ No newline at end of file
\ No newline at end of file
scene_refactor_data/scene_split_processor.py
View file @
8f0f620
This diff is collapsed.
Click to expand it.
scene_refactor_data/step13_modification_summary.md
0 → 100644
View file @
8f0f620
# Step13 修改总结
## 修改时间
2026-05-08
## 修改目标
将
`step13_process_effect_record`
方法重构为三个子步骤,以补全
`dj_car_life_division_rule_effect_record`
表的历史数据。
---
## 修改内容
### 1. 主方法重构
**原方法:**
`step13_process_effect_record()`
-
只处理从审核表 (
`dj_car_life_rule_audit`
) 补全生效记录
**新方法:**
`step13_process_effect_record()`
-
重构为三个子步骤的调用:
1.
`step13_1_update_existing_base_scene_code()`
- 更新已存在记录的 base_scene_code
2.
`step13_2_sync_from_audit()`
- 从审核表补全(现有逻辑)
3.
`step13_3_sync_from_rule_tables()`
- 从规则表补全未经审核的记录
---
## 子步骤详细说明
### 子步骤 13.1:更新已存在记录的 base_scene_code
**方法名:**
`step13_1_update_existing_base_scene_code()`
**处理对象:**
-
已存在于
`dj_car_life_division_rule_effect_record`
的记录
-
`base_scene_code`
为空或 NULL
-
`scene_type`
有值(0, 1, 2, 3, 7)
**处理逻辑:**
```
python
scene_type
→
base_scene_code
映射:
0
→
110101
(会员权益)
1
→
100101
(精品升级)
2
→
100102
(次新车转化)
3
→
100103
(售后众筹)
7
→
120101
(二手车)
```
**日志输出:**
-
每个 scene_type 更新的记录数
-
总更新记录数
---
### 子步骤 13.2:从审核表补全生效记录
**方法名:**
`step13_2_sync_from_audit()`
**处理对象:**
-
从
`dj_car_life_rule_audit`
审核表补全生效记录
-
保持原有逻辑不变
**调用方法:**
-
`_process_effect_finance()`
- 处理财务生效记录(rule_type=1)
-
`_process_effect_reconciliation()`
- 处理对账生效记录(rule_type=3)
---
### 子步骤 13.3:从规则表补全未经审核的记录
**方法名:**
`step13_3_sync_from_rule_tables()`
**处理对象:**
-
`rule_audit_id`
为 NULL 的生效记录
-
业务上允许不经过审核直接生效的规则
**调用方法:**
-
`_sync_settle_and_division_rules()`
- 补全财务分账规则
-
`_sync_reconciliation_rules()`
- 补全对账规则
---
## 新增方法详细说明
### 方法 1:`_sync_settle_and_division_rules()`
**功能:**
补全财务分账规则的生效记录
**数据源:**
-
财务规则表:
`dj_car_life_merchant_settle_account_rule`
(rule_type=1)
-
分账规则表:
`dj_car_life_merchant_division_rule`
(rule_type=1)
**处理流程:**
1.
获取所有旧财务规则ID
2.
查询最新生效记录(去重,按 updated_date DESC, created_date DESC)
3.
查询财务规则拆分后的新ID列表
4.
查询分账规则拆分后的新ID列表
5.
按顺序一一对应组装新记录
6.
幂等性检查
7.
插入新记录
**关键点:**
-
财务规则和分账规则的拆分记录数量必须相等
-
按顺序配对:(new_settle_id
[
0
]
, new_division_id
[
0
]
), (new_settle_id
[
1
]
, new_division_id
[
1
]
), ...
-
None 转 NULL 处理
-
rule_audit_id 设为 NULL
---
### 方法 2:`_sync_reconciliation_rules()`
**功能:**
补全对账规则的生效记录
**数据源:**
-
对账规则表:
`dj_car_life_merchant_goods_type_group_reconciliation_rule`
(rule_type=3)
**处理流程:**
1.
获取所有旧对账规则ID
2.
查询最新生效记录(去重,按 updated_date DESC, created_date DESC)
3.
查询对账规则拆分后的新ID列表
4.
为每个新ID生成一条记录
5.
幂等性检查
6.
插入新记录
**关键点:**
-
division_rule_id 设为 NULL(对账规则没有关联分账规则)
-
None 转 NULL 处理
-
rule_audit_id 设为 NULL
---
## 关键技术点
### 1. 脏数据去重
**问题:**
线上可能存在同一个
`rule_id + rule_type`
组合有多条记录的情况
**解决方案:**
-
先获取所有需要处理的旧规则ID(DISTINCT)
-
对每个旧规则ID,查询生效表中最新的一条记录
-
使用
`ORDER BY updated_date DESC, created_date DESC LIMIT 1`
### 2. 幂等性保证
**检查条件:**
-
财务分账:
`rule_id + rule_type + merchant_id + division_rule_id + deleted_flag='N'`
-
对账:
`rule_id + rule_type + merchant_id + deleted_flag='N'`
### 3. None 转 NULL
**解决方案:**
```
python
field_str
=
f
"'{field_value}'"
if
field_value
is
not
None
else
'NULL'
```
### 4. 财务规则和分账规则的配对
**要求:**
拆分记录数量必须相等,按顺序一一对应
---
## 日志输出示例
```
================================================================================
第13步:开始处理生效记录表
--------------------------------------------------------------------------------
子步骤 13.1:更新已存在记录的 base_scene_code
scene_type=0 更新为 base_scene_code=110101,更新 15 条
scene_type=1 更新为 base_scene_code=100101,更新 23 条
子步骤 13.1 完成,共更新 63 条记录
--------------------------------------------------------------------------------
子步骤 13.2:从审核表补全生效记录
处理财务生效记录(rule_type=1)...
财务生效记录处理完成: 新增 115 条, 跳过 5 条, 错误 0 条
处理对账生效记录(rule_type=3)...
对账生效记录处理完成: 新增 78 条, 跳过 2 条, 错误 0 条
子步骤 13.2 完成
--------------------------------------------------------------------------------
子步骤 13.3:从规则表补全未经审核的记录
处理财务分账规则...
查询到旧财务规则ID数量:45 个
财务分账规则处理完成,共插入:180 条新记录,跳过:0 条,错误:0 条
处理对账规则...
查询到旧对账规则ID数量:30 个
对账规则处理完成,共插入:120 条新记录,跳过:0 条,错误:0 条
子步骤 13.3 完成
================================================================================
第13步完成
```
---
## 修改文件
-
`scene_split_processor.py`
-
修改方法:
`step13_process_effect_record()`
-
新增方法:
`step13_1_update_existing_base_scene_code()`
-
新增方法:
`step13_2_sync_from_audit()`
-
新增方法:
`step13_3_sync_from_rule_tables()`
-
新增方法:
`_sync_settle_and_division_rules()`
-
新增方法:
`_sync_reconciliation_rules()`
---
## 总结
本次修改成功将
`step13_process_effect_record`
重构为三个子步骤,完整覆盖了以下场景:
1.
✅ 更新已存在记录的 base_scene_code(缺口1)
2.
✅ 从审核表补全生效记录(现有逻辑)
3.
✅ 从规则表补全未经审核的记录(缺口2)
-
✅ 财务分账规则(财务规则 + 分账规则配对)
-
✅ 对账规则(独立,division_rule_id 为 NULL)
所有逻辑都包含:
-
✅ 脏数据去重(取最新记录)
-
✅ 幂等性检查(避免重复插入)
-
✅ None 转 NULL 处理
-
✅ 详细的日志统计
代码已通过语法验证,可以进行测试和部署。
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