Commit 1f7a724e by 林冲

去掉检查,因为商品和订单的商品放在一起了,无需二轮检查补充

1 parent f2298857
......@@ -136,7 +136,7 @@ class MerchantGoodsCodeProcessor:
## 这里的商品从上架商品+订单商品两个方面去取
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
mgr.merchant_id merchant_id,
......@@ -302,8 +302,8 @@ class MerchantGoodsCodeProcessor:
self.db.execute_update(f"TRUNCATE TABLE {self.context_table};")
# 1. 处理财务规则(rule_type=1)
self.logger.info("处理财务规则上下文(rule_type=1)...")
self._build_finance_context()
# self.logger.info("处理财务规则上下文(rule_type=1)...")
# self._build_finance_context()
# 2. 处理对账规则(rule_type=3)
self.logger.info("处理对账规则上下文(rule_type=3)...")
......@@ -349,7 +349,7 @@ class MerchantGoodsCodeProcessor:
WHERE gtgr.rule_type = 1
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.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):
......@@ -768,35 +768,37 @@ class MerchantGoodsCodeProcessor:
if not inserts:
return
# 去掉检查,因为商品和订单的商品放在一起了,无需二轮检查补充
# 先批量检查已存在的记录(使用元组IN)
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]
existing_set = set()
batch_size = 1000
for i in range(0, len(check_tuples), batch_size):
batch_tuples = check_tuples[i:i+batch_size]
in_clause = ",".join(batch_tuples)
check_sql = f"""
SELECT rule_type, goods_type_group_rule_id, merchant_goods_code
FROM dj_car_life_goods_type_group_relation
WHERE category_type = 2
AND (rule_type, goods_type_group_rule_id, merchant_goods_code) IN ({in_clause});
"""
existing_results = self.db.execute_query(check_sql)
for row in existing_results:
existing_set.add((row[0], row[1], row[2]))
# 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]
# existing_set = set()
# batch_size = 1000
# for i in range(0, len(check_tuples), batch_size):
# batch_tuples = check_tuples[i:i+batch_size]
# in_clause = ",".join(batch_tuples)
#
# check_sql = f"""
# SELECT rule_type, goods_type_group_rule_id, merchant_goods_code
# FROM dj_car_life_goods_type_group_relation
# WHERE category_type = 2
# AND (rule_type, goods_type_group_rule_id, merchant_goods_code) IN ({in_clause});
# """
#
# existing_results = self.db.execute_query(check_sql)
# for row in existing_results:
# existing_set.add((row[0], row[1], row[2]))
# 过滤掉已存在的记录
filtered_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:
filtered_inserts.append((relation_id, rule_type, goods_type_group_rule_id, merchant_goods_code))
if not filtered_inserts:
return
# filtered_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:
# filtered_inserts.append((relation_id, rule_type, goods_type_group_rule_id, merchant_goods_code))
#
# if not filtered_inserts:
# return
filtered_inserts = inserts
# 批量查询原记录数据(使用 id IN)
# 构建 relation_id 到 merchant_goods_code 列表的映射(一个 relation_id 可能对应多个 merchant_goods_code)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!