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 7c4a9591
authored
May 10, 2026
by
林冲
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
_process_audit_finance修复多保存一条数据
1 parent
c2cff019
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
150 additions
and
0 deletions
scene_refactor_data/BUGFIX_STEP5.md
scene_refactor_data/scene_split_processor.py
scene_refactor_data/BUGFIX_STEP5.md
0 → 100644
View file @
7c4a959
# Step5 Bug 修复报告
## 问题描述
**错误信息:**
```
AttributeError: 'IDMappingManager' object has no attribute 'get_mappings'. Did you mean: 'add_mapping'?
```
**错误位置:**
-
文件:
[
scene_split_processor.py:648
](
scene_split_processor.py#L648
)
-
方法:
`_batch_update_settle_rule_goods_type_group_id`
**错误原因:**
在批量更新表2的代码中,错误地调用了
`self.id_mapper.get_mappings()`
方法,但
`IDMappingManager`
类中没有这个方法。
---
## 问题分析
### IDMappingManager 可用方法
查看
[
id_mapping_manager.py
](
id_mapping_manager.py
)
发现,该类提供的方法有:
1.
`add_mapping(table_name, old_id, new_id, base_scene_code)`
- 添加映射
2.
`get_new_ids(table_name, old_id)`
- 获取所有新ID列表
3.
`get_new_id_by_scene(table_name, old_id, base_scene_code)`
- 根据场景获取新ID
4.
`get_mapping_count(table_name)`
- 获取映射数量
### 错误代码
```
python
# 错误的调用方式
mappings
=
self
.
id_mapper
.
get_mappings
(
goods_type_group_table
,
old_id
,
base_scene_code
)
if
mappings
:
new_goods_type_group_id
=
mappings
[
0
][
'new_id'
]
```
### 正确代码
```
python
# 正确的调用方式
new_goods_type_group_id
=
self
.
id_mapper
.
get_new_id_by_scene
(
goods_type_group_table
,
old_id
,
base_scene_code
)
if
new_goods_type_group_id
:
# 使用 new_goods_type_group_id
```
---
## 修复方案
### 修改位置
**文件:**
[
scene_split_processor.py:632-655
](
scene_split_processor.py#L632-L655
)
**修改前:**
```
python
# 从映射表查询新ID
mappings
=
self
.
id_mapper
.
get_mappings
(
goods_type_group_table
,
old_id
,
base_scene_code
)
# ❌ 错误
if
mappings
:
new_goods_type_group_id
=
mappings
[
0
][
'new_id'
]
```
**修改后:**
```
python
# 从映射表查询新ID
new_goods_type_group_id
=
self
.
id_mapper
.
get_new_id_by_scene
(
goods_type_group_table
,
old_id
,
base_scene_code
)
# ✅ 正确
if
new_goods_type_group_id
:
```
---
## 验证结果
### 测试命令
```
bash
python main_scene_split.py --start-step
=
5 --end-step
=
5 --test-mode
```
### 测试结果
```
第5步:开始处理商品分组表
找到 0 条需要复制的表4记录
开始批量更新表2中的 goods_type_group_id...
开始批量更新表7中的 goods_type_group_id...
第5步完成,共复制 0 条记录
第 5 步执行成功
```
**结果:**
✅ 修复成功,程序正常运行,没有报错
---
## 影响范围
### 受影响的方法
-
`_batch_update_settle_rule_goods_type_group_id`
- 已修复 ✅
### 其他方法检查
检查了其他使用
`id_mapper`
的地方,确认都使用了正确的方法:
-
✅
`add_mapping()`
- 正确使用
-
✅
`get_new_id_by_scene()`
- 正确使用
-
✅
`get_new_ids()`
- 正确使用
-
✅
`get_mapping_count()`
- 正确使用
---
## 总结
### 问题根源
在实现批量优化时,错误地假设
`IDMappingManager`
有
`get_mappings()`
方法,实际上应该使用
`get_new_id_by_scene()`
方法。
### 修复内容
将
`get_mappings()`
调用改为
`get_new_id_by_scene()`
调用,并相应调整返回值的处理逻辑。
### 验证状态
-
✅ 代码修复完成
-
✅ 测试模式验证通过
-
✅ 无其他类似问题
### 建议
在生产环境部署前,建议:
1.
先在测试环境用真实数据验证 Step5 的完整流程
2.
确认批量插入和批量更新都能正常工作
3.
验证映射关系的正确性
---
**修复状态:**
✅ 已完成
**修复日期:**
2026-05-10
**影响版本:**
v1.0
**修复版本:**
v1.1
scene_refactor_data/scene_split_processor.py
View file @
7c4a959
...
@@ -1858,10 +1858,20 @@ class SceneSplitProcessor:
...
@@ -1858,10 +1858,20 @@ class SceneSplitProcessor:
continue
continue
# 按顺序组装新记录
# 按顺序组装新记录
# 注意:第一个场景(110101)是通过更新原记录实现的,所以只需要插入后面3个
first_scene_code
=
SCENE_TYPE_0_SPLIT
[
0
]
# 110101
for
i
in
range
(
len
(
settle_mappings
)):
for
i
in
range
(
len
(
settle_mappings
)):
new_settle_id
=
settle_mappings
[
i
][
0
]
new_settle_id
=
settle_mappings
[
i
][
0
]
base_scene_code
=
settle_mappings
[
i
][
1
]
base_scene_code
=
settle_mappings
[
i
][
1
]
# 跳过第一个场景(110101),因为它是通过更新原记录实现的
if
base_scene_code
==
first_scene_code
:
# 为原记录建立映射关系(old_id -> old_id)
self
.
id_mapper
.
add_mapping
(
table_name
,
old_id
,
old_id
,
base_scene_code
)
self
.
logger
.
debug
(
f
" 原记录映射: old_id={old_id} -> old_id={old_id}, base_scene_code={base_scene_code}"
)
continue
new_division_id
=
'NULL'
new_division_id
=
'NULL'
if
division_mappings
and
i
<
len
(
division_mappings
):
if
division_mappings
and
i
<
len
(
division_mappings
):
new_division_id
=
division_mappings
[
i
][
0
]
new_division_id
=
division_mappings
[
i
][
0
]
...
...
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