소스 검색

1:优化CIP存储重复判断逻辑

wmy 2 달 전
부모
커밋
d4cb2617e2
1개의 변경된 파일18개의 추가작업 그리고 5개의 파일을 삭제
  1. 18 5
      main_simple.py

+ 18 - 5
main_simple.py

@@ -737,7 +737,7 @@ def main(strategy=3, start_date=None, unit_filter=None, separate_stages=True, se
 
     return result_df
 
-def check_decision_exists(project_id, action_type, ctime):
+def check_decision_exists(project_id, action_type, ctime, stage_num=None):
     """
     检查指定决策数据是否已存在
     
@@ -747,6 +747,7 @@ def check_decision_exists(project_id, action_type, ctime):
         project_id: int,项目ID
         action_type: str,动作类型,如'RO1'
         ctime: str,CIP时间,格式'YYYY-MM-DD HH:MM:SS'
+        stage_num: int,段号(1=一段,2=二段),如果提供则同时匹配段号
     
     Returns:
         bool: 如果数据已存在返回True,不存在返回False
@@ -779,9 +780,21 @@ def check_decision_exists(project_id, action_type, ctime):
                     # 比较日期部分(忽略时分秒的差异)
                     existing_date = existing_ctime.split(" ")[0]
                     target_date = ctime.split(" ")[0]
+                    
+                    # 同时检查日期和段号(如果提供了段号)
                     if existing_date == target_date:
-                        print(f"  [去重] {action_type} 在 {target_date} 已存在记录(id={record.get('id')}), 跳过存储")
-                        return True
+                        existing_stage = record.get("ceb_backwash_frequency")
+                        
+                        # 如果提供了段号,需要同时匹配日期和段号
+                        if stage_num is not None:
+                            if existing_stage == stage_num:
+                                print(f"  [去重] {action_type} 段{stage_num} 在 {target_date} 已存在记录(id={record.get('id')}), 跳过存储")
+                                return True
+                            # 日期相同但段号不同,不算重复,继续检查下一条
+                        else:
+                            # 不区分段号,只要日期相同就算重复
+                            print(f"  [去重] {action_type} 在 {target_date} 已存在记录(id={record.get('id')}), 跳过存储")
+                            return True
         
         return False
         
@@ -834,8 +847,8 @@ def send_decision_to_callback(decision_data):
                     unit_name = unit_type.split('-')[0] if '-' in unit_type else unit_type
                     ctime_str = row["CIP时机"].strftime("%Y-%m-%d %H:%M:%S")
                     
-                    # ===== 去重检查:查询是否已存在该记录 =====
-                    if check_decision_exists(project_id, unit_name, ctime_str):
+                    # ===== 去重检查:查询是否已存在该记录(同时匹配日期和段号)=====
+                    if check_decision_exists(project_id, unit_name, ctime_str, stage_num):
                         continue  # 跳过已存在的记录
                     
                     callback_list.append({