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 1f7a724e
authored
May 16, 2026
by
林冲
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
去掉检查,因为商品和订单的商品放在一起了,无需二轮检查补充
1 parent
f2298857
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
30 deletions
scene_refactor_data/merchant_goods_code_processor.py
scene_refactor_data/merchant_goods_code_processor.py
View file @
1f7a724
...
@@ -136,7 +136,7 @@ class MerchantGoodsCodeProcessor:
...
@@ -136,7 +136,7 @@ class MerchantGoodsCodeProcessor:
## 这里的商品从上架商品+订单商品两个方面去取
## 这里的商品从上架商品+订单商品两个方面去取
query_sql
=
"""
query_sql
=
"""
select distinct merchant_id,
merchant_id,
base_scene_code,upgrade_goods_id,merchant_goods_code,id from
select distinct merchant_id,base_scene_code,upgrade_goods_id,merchant_goods_code,id from
(
(
(SELECT
(SELECT
mgr.merchant_id merchant_id,
mgr.merchant_id merchant_id,
...
@@ -302,8 +302,8 @@ class MerchantGoodsCodeProcessor:
...
@@ -302,8 +302,8 @@ class MerchantGoodsCodeProcessor:
self
.
db
.
execute_update
(
f
"TRUNCATE TABLE {self.context_table};"
)
self
.
db
.
execute_update
(
f
"TRUNCATE TABLE {self.context_table};"
)
# 1. 处理财务规则(rule_type=1)
# 1. 处理财务规则(rule_type=1)
self
.
logger
.
info
(
"处理财务规则上下文(rule_type=1)..."
)
#
self.logger.info("处理财务规则上下文(rule_type=1)...")
self
.
_build_finance_context
()
#
self._build_finance_context()
# 2. 处理对账规则(rule_type=3)
# 2. 处理对账规则(rule_type=3)
self
.
logger
.
info
(
"处理对账规则上下文(rule_type=3)..."
)
self
.
logger
.
info
(
"处理对账规则上下文(rule_type=3)..."
)
...
@@ -349,7 +349,7 @@ class MerchantGoodsCodeProcessor:
...
@@ -349,7 +349,7 @@ class MerchantGoodsCodeProcessor:
WHERE gtgr.rule_type = 1
WHERE gtgr.rule_type = 1
AND gtgr.category_type = 2 and sar.scene_type in (0,1,2,3,7)
AND gtgr.category_type = 2 and sar.scene_type in (0,1,2,3,7)
AND gtgr.upgrade_goods_id IS NOT NULL
AND gtgr.upgrade_goods_id IS NOT NULL
AND (gtgr.merchant_goods_code IS NULL OR gtgr.merchant_goods_code = '');
;
AND (gtgr.merchant_goods_code IS NULL OR gtgr.merchant_goods_code = '');
"""
"""
if
self
.
db
.
execute_update
(
insert_sql
):
if
self
.
db
.
execute_update
(
insert_sql
):
...
@@ -768,35 +768,37 @@ class MerchantGoodsCodeProcessor:
...
@@ -768,35 +768,37 @@ class MerchantGoodsCodeProcessor:
if
not
inserts
:
if
not
inserts
:
return
return
# 去掉检查,因为商品和订单的商品放在一起了,无需二轮检查补充
# 先批量检查已存在的记录(使用元组IN)
# 先批量检查已存在的记录(使用元组IN)
check_tuples
=
[
f
"({rule_type}, {goods_type_group_rule_id}, '{merchant_goods_code}')"
#
check_tuples = [f"({rule_type}, {goods_type_group_rule_id}, '{merchant_goods_code}')"
for
relation_id
,
rule_type
,
goods_type_group_rule_id
,
merchant_goods_code
in
inserts
]
#
for relation_id, rule_type, goods_type_group_rule_id, merchant_goods_code in inserts]
existing_set
=
set
()
#
existing_set = set()
batch_size
=
1000
#
batch_size = 1000
for
i
in
range
(
0
,
len
(
check_tuples
),
batch_size
):
#
for i in range(0, len(check_tuples), batch_size):
batch_tuples
=
check_tuples
[
i
:
i
+
batch_size
]
#
batch_tuples = check_tuples[i:i+batch_size]
in_clause
=
","
.
join
(
batch_tuples
)
#
in_clause = ",".join(batch_tuples)
#
check_sql
=
f
"""
#
check_sql = f"""
SELECT rule_type, goods_type_group_rule_id, merchant_goods_code
#
SELECT rule_type, goods_type_group_rule_id, merchant_goods_code
FROM dj_car_life_goods_type_group_relation
#
FROM dj_car_life_goods_type_group_relation
WHERE category_type = 2
#
WHERE category_type = 2
AND (rule_type, goods_type_group_rule_id, merchant_goods_code) IN ({in_clause});
#
AND (rule_type, goods_type_group_rule_id, merchant_goods_code) IN ({in_clause});
"""
#
"""
#
existing_results
=
self
.
db
.
execute_query
(
check_sql
)
#
existing_results = self.db.execute_query(check_sql)
for
row
in
existing_results
:
#
for row in existing_results:
existing_set
.
add
((
row
[
0
],
row
[
1
],
row
[
2
]))
#
existing_set.add((row[0], row[1], row[2]))
# 过滤掉已存在的记录
# 过滤掉已存在的记录
filtered_inserts
=
[]
# filtered_inserts = []
for
relation_id
,
rule_type
,
goods_type_group_rule_id
,
merchant_goods_code
in
inserts
:
# for relation_id, rule_type, goods_type_group_rule_id, merchant_goods_code in inserts:
if
(
rule_type
,
goods_type_group_rule_id
,
merchant_goods_code
)
not
in
existing_set
:
# if (rule_type, goods_type_group_rule_id, merchant_goods_code) not in existing_set:
filtered_inserts
.
append
((
relation_id
,
rule_type
,
goods_type_group_rule_id
,
merchant_goods_code
))
# filtered_inserts.append((relation_id, rule_type, goods_type_group_rule_id, merchant_goods_code))
#
if
not
filtered_inserts
:
# if not filtered_inserts:
return
# return
filtered_inserts
=
inserts
# 批量查询原记录数据(使用 id IN)
# 批量查询原记录数据(使用 id IN)
# 构建 relation_id 到 merchant_goods_code 列表的映射(一个 relation_id 可能对应多个 merchant_goods_code)
# 构建 relation_id 到 merchant_goods_code 列表的映射(一个 relation_id 可能对应多个 merchant_goods_code)
...
...
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