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 4ea17f0a
authored
Apr 25, 2026
by
林冲
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
测试模式
1 parent
35ad8161
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
3 deletions
common/dbase/MysqlHelper.py
scene_refactor_data/README.md
scene_refactor_data/db_config.yaml
scene_refactor_data/main_scene_split.py
scene_refactor_data/scene_split_processor.py
common/dbase/MysqlHelper.py
View file @
4ea17f0
...
...
@@ -95,7 +95,9 @@ class MysqlHelper:
执行查询语句
"""
try
:
logging
.
info
(
sql
)
# 只在非 LAST_INSERT_ID 查询时输出日志
if
"LAST_INSERT_ID"
not
in
sql
.
upper
():
logging
.
info
(
sql
)
self
.
cursor
.
execute
(
sql
)
res
=
self
.
cursor
.
fetchone
()
return
res
...
...
scene_refactor_data/README.md
View file @
4ea17f0
...
...
@@ -64,8 +64,48 @@ python main_scene_split.py --env test --config /path/to/config.yaml
# 设置日志级别
python main_scene_split.py --env
test
--log-level DEBUG
# 测试模式(每个scene_type只处理一条数据,用于验证脚本逻辑)
python main_scene_split.py --env
test
--test-mode
```
### 测试模式说明
测试模式用于快速验证脚本处理逻辑是否正确,避免全量数据处理耗时过长。
**测试模式特点:**
-
对于有
`scene_type`
字段的主表(表1、表6、表9),每个
`scene_type`
值只处理一条数据
-
选择规则:按
`id`
排序取最新的一条(
`id`
最大且
`deleted_flag='N'`
)
-
关联表会自动受限于主表的处理范围,无需额外配置
-
`scene_type=0`
复制插入的新记录会保持原记录的
`created_date`
,便于数据回溯
**使用场景:**
1.
首次执行前验证脚本逻辑
2.
调试和排查问题
3.
快速预览处理结果
**示例:**
```
bash
# 测试模式执行所有步骤
python main_scene_split.py --env
test
--test-mode
# 测试模式执行指定步骤
python main_scene_split.py --env
test
--test-mode --start-step 1 --end-step 5
# 测试模式 + DEBUG日志
python main_scene_split.py --env
test
--test-mode --log-level DEBUG
```
**注意事项:**
-
测试模式仅用于验证,不适用于生产环境的全量数据处理
-
建议先在测试环境使用测试模式验证,确认无误后再执行正式模式
-
测试模式下,每个
`scene_type`
只处理1条,例如:
-
`scene_type=0`
处理1条(拆分为4条)
-
`scene_type=1`
处理1条
-
`scene_type=2`
处理1条
-
`scene_type=3`
处理1条
-
`scene_type=7`
处理1条
## 处理步骤说明
### 阶段一:财务分账规则链路(第1-9步)
...
...
@@ -96,3 +136,21 @@ python main_scene_split.py --env test --log-level DEBUG
2.
**环境确认**
: 确认
`--env`
参数选择正确的环境
3.
**权限检查**
: 确保数据库用户有足够的权限
4.
**执行顺序**
: 步骤之间有依赖关系,建议按顺序执行
5.
**测试模式**
: 首次执行建议先使用
`--test-mode`
验证脚本逻辑
6.
**日志输出**
: 脚本会自动生成日志文件
`scene_split_YYYYMMDD_HHMMSS.log`
7.
**created_date 保持**
:
`scene_type=0`
复制插入的记录会保持原记录的
`created_date`
,便于数据回溯
## 执行流程建议
```
bash
# 步骤1: 在测试环境使用测试模式验证
python main_scene_split.py --env
test
--test-mode --log-level DEBUG
# 步骤2: 检查日志和数据库结果,确认逻辑正确
# 步骤3: 在测试环境执行正式模式(全量数据)
python main_scene_split.py --env
test
# 步骤4: 验证测试环境数据无误后,在生产环境执行
python main_scene_split.py --env prod
```
scene_refactor_data/db_config.yaml
View file @
4ea17f0
...
...
@@ -6,7 +6,7 @@ test_smartcarlife_db:
port
:
3306
user
:
"
dev_admin"
password
:
"
1f7e1ed2"
db
:
"
dj_smartcarlife_scene"
db
:
"
dj_smartcarlife_scene
2
"
charset
:
"
utf8mb4"
#prod_smartcarlife_db:
...
...
scene_refactor_data/main_scene_split.py
View file @
4ea17f0
...
...
@@ -80,6 +80,11 @@ def parse_args():
action
=
'store_true'
,
help
=
'试运行模式,只打印SQL不执行'
)
parser
.
add_argument
(
'--test-mode'
,
action
=
'store_true'
,
help
=
'测试模式,每个scene_type只处理一条数据(按ID排序最新的未删除记录)'
)
return
parser
.
parse_args
()
...
...
@@ -98,6 +103,7 @@ def main():
logger
.
info
(
f
"环境: {args.env}"
)
logger
.
info
(
f
"执行步骤: {args.start_step} - {args.end_step}"
)
logger
.
info
(
f
"试运行模式: {args.dry_run}"
)
logger
.
info
(
f
"测试模式: {args.test_mode}"
)
logger
.
info
(
"="
*
100
)
# 获取数据库连接
...
...
@@ -121,7 +127,7 @@ def main():
return
1
# 创建场景拆分处理器
processor
=
SceneSplitProcessor
(
db_helper
,
id_mapper
)
processor
=
SceneSplitProcessor
(
db_helper
,
id_mapper
,
test_mode
=
args
.
test_mode
)
# 定义步骤映射
steps
=
{
...
...
scene_refactor_data/scene_split_processor.py
View file @
4ea17f0
This diff is collapsed.
Click to expand it.
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