Ver Fonte

feat: 优化体位自动选择逻辑

- exam 模式下自动选择第一个未曝光体位
- process 模式下自动选择第一个已曝光体位
- 增强边界条件处理和日志记录

close #71

修改文件: src/domain/exam/bodyPositionSelection.ts
sw há 1 semana atrás
pai
commit
8401763d20
1 ficheiros alterados com 41 adições e 3 exclusões
  1. 41 3
      src/domain/exam/bodyPositionSelection.ts

+ 41 - 3
src/domain/exam/bodyPositionSelection.ts

@@ -74,20 +74,58 @@ export const selectBodyPositionWithFullLogic = async (
 
 /**
  * 自动选中第一个体位(通常在进入exam时调用)
+ * - exam 模式:自动选择第一个未曝光的体位
+ * - process 模式:自动选择第一个已曝光的体位
+ * - 其他模式:选择第一个体位
  */
 export const autoSelectFirstBodyPosition = async (
   bodyPositions: ExtendedBodyPosition[],
   dispatch: AppDispatch,
   currentKey: string
 ): Promise<void> => {
-  if (bodyPositions.length > 0) {
-    console.log('[bodyPositionSelection] Auto-selecting first body position');
+  if (bodyPositions.length === 0) {
+    console.log('[bodyPositionSelection] No body positions available');
+    return;
+  }
+
+  // 根据当前业务流程选择合适的体位
+  let targetBodyPosition: ExtendedBodyPosition | undefined;
+
+  if (currentKey === 'exam') {
+    // exam 模式:选择第一个未曝光的体位
+    targetBodyPosition = bodyPositions.find(
+      (bp) => bp.dview.expose_status === 'Unexposed'
+    );
+    console.log(
+      '[bodyPositionSelection] Auto-selecting first unexposed body position in exam mode'
+    );
+  } else if (currentKey === 'process') {
+    // process 模式:选择第一个已曝光的体位
+    targetBodyPosition = bodyPositions.find(
+      (bp) => bp.dview.expose_status === 'Exposed'
+    );
+    console.log(
+      '[bodyPositionSelection] Auto-selecting first exposed body position in process mode'
+    );
+  } else {
+    // 其他模式:默认选择第一个
+    targetBodyPosition = bodyPositions[0];
+    console.log(
+      `[bodyPositionSelection] Auto-selecting first body position in ${currentKey} mode`
+    );
+  }
+
+  if (targetBodyPosition) {
     await selectBodyPositionWithFullLogic(
-      bodyPositions[0],
+      targetBodyPosition,
       dispatch,
       currentKey,
       false // 自动选中时不显示用户消息
     );
+  } else {
+    console.warn(
+      `[bodyPositionSelection] No suitable body position found for ${currentKey} mode`
+    );
   }
 };