|
|
@@ -121,12 +121,14 @@ class AIReviewCoreFun:
|
|
|
Tuple[int, List[Dict]]: (处理的块数量, 更新后的issues列表)
|
|
|
"""
|
|
|
logger.info(f"📝 处理章节: {chapter_code}, 共 {len(chapter_content)} 个chunk")
|
|
|
- chapter_total_chunks = len(chapter_content)
|
|
|
+ # chapter_total_chunks = len(chapter_content)
|
|
|
|
|
|
# 按块串行遍历(所有章节统一流程)
|
|
|
for chunk_index, chunk in enumerate(chapter_content):
|
|
|
- chunk_label = chunk.get("section_label", f"chunk_{chunk_index}")
|
|
|
- logger.info(f" 📄 处理块 {chunk_index+1}/{chapter_total_chunks}: {chunk_label}")
|
|
|
+ # 计算全局块索引,避免不同章节间索引重复导致Redis计数错误
|
|
|
+ global_chunk_index = completed_chunks + chunk_index
|
|
|
+ chunk_label = chunk.get("section_label", f"chunk_{global_chunk_index}")
|
|
|
+ logger.info(f" 📄 处理块 {global_chunk_index+1}/{total_chunks}: {chunk_label}")
|
|
|
|
|
|
# 终止信号检查(块级别)
|
|
|
if await self.workflow_manager.check_terminate_signal(state["callback_task_id"]):
|
|
|
@@ -135,7 +137,7 @@ class AIReviewCoreFun:
|
|
|
|
|
|
# 并发执行当前块的所有审查方法
|
|
|
chunk_results = await self._execute_chunk_methods(
|
|
|
- chapter_code, chunk, chunk_index, func_names, state
|
|
|
+ chapter_code, chunk, global_chunk_index, func_names, state
|
|
|
)
|
|
|
|
|
|
# 格式化当前块的结果为issues
|
|
|
@@ -143,7 +145,7 @@ class AIReviewCoreFun:
|
|
|
review_location_label = f"第{chunk_page}页:{chunk_label}"
|
|
|
issues = self.inter_tool._format_review_results_to_issues(
|
|
|
callback_task_id=state["callback_task_id"],
|
|
|
- unit_index=chunk_index,
|
|
|
+ unit_index=global_chunk_index,
|
|
|
review_location_label=review_location_label,
|
|
|
chapter_code=chapter_code,
|
|
|
unit_content=chunk,
|
|
|
@@ -153,9 +155,9 @@ class AIReviewCoreFun:
|
|
|
)
|
|
|
|
|
|
# 推送当前块的进度
|
|
|
- current = int(((completed_chunks + chunk_index + 1) / total_chunks) * 100)
|
|
|
+ current = int(((global_chunk_index + 1) / total_chunks) * 100)
|
|
|
await self._send_unit_review_progress(
|
|
|
- state, chunk_index, chapter_total_chunks, chunk_label, issues, current
|
|
|
+ state, global_chunk_index, total_chunks, chunk_label, issues, current
|
|
|
)
|
|
|
|
|
|
# 累积issues
|
|
|
@@ -165,8 +167,8 @@ class AIReviewCoreFun:
|
|
|
else:
|
|
|
logger.warning(f"⚠️ 块{chunk_index}: issues为空,未添加到all_issues")
|
|
|
|
|
|
- logger.info(f"🔍 章节{chapter_code}完成: 总共处理{chapter_total_chunks}个块, all_issues最终数量={len(all_issues)}")
|
|
|
- return chapter_total_chunks, all_issues
|
|
|
+ logger.info(f"🔍 章节{chapter_code}完成: 总共处理{total_chunks}个块, all_issues最终数量={len(all_issues)}")
|
|
|
+ return total_chunks, all_issues
|
|
|
|
|
|
def _extract_issues_from_result(self, result: Any) -> List[Dict]:
|
|
|
"""
|
|
|
@@ -258,8 +260,8 @@ class AIReviewCoreFun:
|
|
|
chapter_map[chapter_code] = []
|
|
|
|
|
|
chapter_map[chapter_code].append(chunk)
|
|
|
-
|
|
|
- return chapter_map
|
|
|
+ chapter_names = list(chapter_map.keys())
|
|
|
+ return chapter_map, chapter_names
|
|
|
|
|
|
async def _execute_chunk_methods(self, chapter_code: str, chunk: Dict[str, Any], chunk_index: int, func_names: List[str], state: AIReviewState) -> Dict[str, Any]:
|
|
|
"""
|
|
|
@@ -951,7 +953,7 @@ class AIReviewCoreFun:
|
|
|
overall_risk="error"
|
|
|
)
|
|
|
|
|
|
- async def _send_start_review_progress(self, state: AIReviewState, total_units: int = None, review_type : str =None) -> None:
|
|
|
+ async def _send_start_review_progress(self, state: AIReviewState, total_units: int, chapter_names: list) -> None:
|
|
|
"""
|
|
|
发送开始审查的进度更新
|
|
|
|
|
|
@@ -959,45 +961,24 @@ class AIReviewCoreFun:
|
|
|
state: AI审查状态
|
|
|
total_units: 总审查单元数
|
|
|
"""
|
|
|
-
|
|
|
-
|
|
|
+ #logger.info(f"发送开始审查的进度更新 {chapter_names}")
|
|
|
+ chapter_count = len(chapter_names)
|
|
|
+ chapter_names_str = "、".join(chapter_names)
|
|
|
try:
|
|
|
-
|
|
|
-
|
|
|
if state["progress_manager"]:
|
|
|
- if review_type == "outline":
|
|
|
- await state["progress_manager"].update_stage_progress(
|
|
|
- callback_task_id=state["callback_task_id"],
|
|
|
- stage_name="AI审查",
|
|
|
- current=0,
|
|
|
- status="processing",
|
|
|
- message=f"开始大纲审查",
|
|
|
- event_type="processing"
|
|
|
- )
|
|
|
- # elif review_type is "prpe_basis":
|
|
|
- # await state["progress_manager"].update_stage_progress(
|
|
|
- # callback_task_id=state["callback_task_id"],
|
|
|
- # stage_name="AI审查",
|
|
|
- # current=0,
|
|
|
- # total=total_units,
|
|
|
- # status="processing",
|
|
|
- # message=f"开始编制依据审查",
|
|
|
- # event_type="processing"
|
|
|
- # )
|
|
|
- else:
|
|
|
- await state["progress_manager"].update_stage_progress(
|
|
|
- callback_task_id=state["callback_task_id"],
|
|
|
- stage_name="AI审查",
|
|
|
- current=0,
|
|
|
- status="processing",
|
|
|
- message=f"开始核心审查,共 {total_units} 个审查单元",
|
|
|
- event_type="processing"
|
|
|
- )
|
|
|
+ await state["progress_manager"].update_stage_progress(
|
|
|
+ callback_task_id=state["callback_task_id"],
|
|
|
+ stage_name="AI审查",
|
|
|
+ current=0,
|
|
|
+ status="processing",
|
|
|
+ message=f"开始核心审查,共计{chapter_count}章,{chapter_names_str}, {total_units} 个审查单元",
|
|
|
+ event_type="processing"
|
|
|
+ )
|
|
|
except Exception as e:
|
|
|
logger.warning(f"发送开始进度更新失败: {str(e)}")
|
|
|
|
|
|
async def _send_unit_review_progress(self, state: AIReviewState, unit_index: int,
|
|
|
- total_units: int, section_label: str,
|
|
|
+ total_chunks: int, section_label: str,
|
|
|
issues: List[Dict], current: int) -> None:
|
|
|
"""
|
|
|
发送单元审查详细信息 - 强制串行并统一进度值
|
|
|
@@ -1015,7 +996,7 @@ class AIReviewCoreFun:
|
|
|
)
|
|
|
|
|
|
real_current = await self._send_unit_overall_progress(
|
|
|
- state, unit_index, total_units, section_label, issues_count
|
|
|
+ state, unit_index, total_chunks, section_label, issues_count
|
|
|
)
|
|
|
|
|
|
|
|
|
@@ -1052,7 +1033,7 @@ class AIReviewCoreFun:
|
|
|
logger.error(f"发送单元审查详情失败: {str(e)}")
|
|
|
|
|
|
async def _send_unit_overall_progress(self, state: AIReviewState, unit_index: int,
|
|
|
- total_units: int, section_label: str,
|
|
|
+ total_chunks: int, section_label: str,
|
|
|
issues_count: int = None) -> Optional[int]:
|
|
|
"""
|
|
|
发送单元完成进度更新 - 返回计算出的实时进度
|
|
|
@@ -1078,17 +1059,16 @@ class AIReviewCoreFun:
|
|
|
completed_count = await redis_client.scard(completed_key)
|
|
|
|
|
|
# 计算进度
|
|
|
- current_percent = int((completed_count / total_units) * 100)
|
|
|
+ current_percent = int((completed_count / total_chunks) * 100)
|
|
|
else:
|
|
|
# 降级方案
|
|
|
completed_count = unit_index + 1
|
|
|
- current_percent = int((completed_count / total_units) * 100)
|
|
|
-
|
|
|
+ current_percent = int((completed_count / total_chunks) * 100)
|
|
|
# 构建消息
|
|
|
if issues_count is not None and issues_count > 0:
|
|
|
- message = f"已完成第 {completed_count}/{total_units} 个单元: {section_label}(已发现{issues_count}个问题)"
|
|
|
+ message = f"已完成第 {completed_count}/{total_chunks} 个单元: {section_label}(已发现{issues_count}个问题)"
|
|
|
else:
|
|
|
- message = f"已完成第 {completed_count}/{total_units} 个单元: {section_label}"
|
|
|
+ message = f"已完成第 {completed_count}/{total_chunks} 个单元: {section_label}"
|
|
|
|
|
|
logger.info(f"进度更新: {current_percent}% - {message}")
|
|
|
|
|
|
@@ -1167,4 +1147,27 @@ class AIReviewCoreFun:
|
|
|
for val in mapped_value:
|
|
|
result.append(f"{prefix}_{val}")
|
|
|
|
|
|
- return result
|
|
|
+ return result
|
|
|
+
|
|
|
+ def _check_item_mapping_order(self, review_item_config: List[str]) -> Dict[str, List[str]]:
|
|
|
+ """
|
|
|
+ 根据标准顺序对项目进行映射排序
|
|
|
+ """
|
|
|
+ review_item_dict = {}
|
|
|
+ for item in review_item_config:
|
|
|
+ key, value = item.split("_", 1)
|
|
|
+ review_item_dict.setdefault(key, []).append(value)
|
|
|
+
|
|
|
+ # 依据方案标准章节顺序进行排序
|
|
|
+ sgfa_chapter_index_order = ["catalogue", "basis", "overview", "plan","technology", "safety", "quality", "environment",
|
|
|
+"management", "acceptance", "other"]
|
|
|
+
|
|
|
+ all_keys = review_item_dict.keys()
|
|
|
+ sorted_keys = sorted(
|
|
|
+ all_keys,
|
|
|
+ key=lambda x :sgfa_chapter_index_order.index(x)
|
|
|
+ )
|
|
|
+ review_item_dict_sorted = {}
|
|
|
+ for key in sorted_keys:
|
|
|
+ review_item_dict_sorted[key] = review_item_dict[key]
|
|
|
+ return review_item_dict_sorted
|