From 6f8b4b419022f4df1c332d6d4c6e8ad119c75826 Mon Sep 17 00:00:00 2001 From: MTing Date: Wed, 17 Sep 2025 17:56:10 +0800 Subject: [PATCH] fix test 10 --- .../com/ouxuan/oxface/OXFaceOnlineActivity.java | 8 +---- .../com/ouxuan/oxface/device/GateABController.java | 35 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/ouxuan/oxface/OXFaceOnlineActivity.java b/app/src/main/java/com/ouxuan/oxface/OXFaceOnlineActivity.java index 1df32f8..20e575d 100644 --- a/app/src/main/java/com/ouxuan/oxface/OXFaceOnlineActivity.java +++ b/app/src/main/java/com/ouxuan/oxface/OXFaceOnlineActivity.java @@ -418,13 +418,7 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi @Override public void onVerificationSuccess(com.ouxuan.oxface.network.api.PadApiService.CheckOrderResult data, int verificationType) { - // 订单核销成功后开启B门 - if (gateABController != null) { - LogManager.logInfo(TAG, "订单核销成功,开启B门"); - gateABController.handleFaceRecognitionSuccess(true); // 参数保留兼容性,实际都开B门 - } - - // 然后处理原有的页面跳转逻辑 + // 直接处理页面跳转逻辑,不在这里开门 orderVerificationResultHandler.handleVerificationSuccess(data, verificationType); } diff --git a/app/src/main/java/com/ouxuan/oxface/device/GateABController.java b/app/src/main/java/com/ouxuan/oxface/device/GateABController.java index 1d40c90..503ae88 100644 --- a/app/src/main/java/com/ouxuan/oxface/device/GateABController.java +++ b/app/src/main/java/com/ouxuan/oxface/device/GateABController.java @@ -279,8 +279,9 @@ public class GateABController { // } // 实时查询1次AB门状态, 防止AB门用户作弊 + // 在开门场景中使用缓存状态以避免UDP查询延迟 if (getGateAbEnable()) { - String gateStatus = getGateABState(); // 获取AB门状态 + String gateStatus = getGateABState(true); // 获取AB门状态,使用缓存以避免延迟 LogManager.logInfo(TAG, "开门-门状态查询:" + gateStatus + " gpio:" + getGateAbGpio()); if (!"close".equals(gateStatus)) { @@ -384,13 +385,22 @@ public class GateABController { * @return "open"表示开启状态,"close"表示关闭状态 . 当a门 b门中有任一个开启状态,则返回"open", 两个门都关闭时返回"close" */ private String getGateABState() { - LogManager.logInfo(TAG, "查询AB门状态"); + return getGateABState(false); + } + + /** + * 获取AB门状态 + * @param useCacheOnly 是否仅使用缓存状态(用于开门场景避免延迟) + * @return "open"表示开启状态,"close"表示关闭状态 + */ + private String getGateABState(boolean useCacheOnly) { + LogManager.logInfo(TAG, "查询AB门状态, useCacheOnly: " + useCacheOnly); try { // 检查是否启用UDP门禁控制 if (getGateAbUdp() && udpController != null && udpController.isInitialized()) { LogManager.logInfo(TAG, "使用UDP查询AB门状态"); - return getGateStateFromUDP(); + return getGateStateFromUDP(useCacheOnly); } // 检查是否启用GPIO门禁控制 @@ -792,6 +802,25 @@ public class GateABController { * @return "open" 或 "close" */ private String getGateStateFromUDP() { + return getGateStateFromUDP(false); + } + + /** + * 从 UDP 获取门状态 + * @param useCacheOnly 是否仅使用缓存状态(用于开门场景避免延迟) + * @return "open" 或 "close" + */ + private String getGateStateFromUDP(boolean useCacheOnly) { + // 对于开门操作,我们使用缓存状态以避免UDP查询延迟 + if (useCacheOnly && currentGateState != null) { + // 按照业务逻辑:当A门或B门中有任一个开启时,返回"open" + // 两个门都关闭时返回"close" + String result = (currentGateState.gateAOpen || currentGateState.gateBOpen) ? "open" : "close"; + LogManager.logInfo(TAG, "使用缓存门状态(开门场景优化): " + result + " (A门: " + currentGateState.gateAOpen + + ", B门: " + currentGateState.gateBOpen + ")"); + return result; + } + try { LogManager.logInfo(TAG, "使用UDP查询门状态");