浏览代码

修复: 调整请假自动开门 Step3/Step4 状态判定

1. 具体改动:将平台配置模式下的 Step3 下载链路统一为 person/reset,不再在 reset 未返回 taskId 时自动回退 shortcut;新增 callbackConfigured、downloadResetAccepted、downloadTaskAccepted、downloadPendingReason、downloadConfirmSource 等状态字段,并将其写入 RC.wcmswj 快照;回查链路补充从 callbackTaskId 反查下载任务,并新增基于回调摘要的成功判定。

2. 影响范围或行为变化:请假自动开门在 person/reset 返回 code=0 但暂未返回 taskId 时,不再误判为下载任务创建失败,而是区分为等待回调、未配置回调、taskId 已返回但任务摘要未落库等状态;最终结果收敛支持以海康回调作为设备生效确认来源,提示文案更贴近现场实际链路。

3. 验证情况:已执行 git diff --cached --stat、git diff --cached、git diff --check;已尝试执行 javac --% @tmp_hk_leave_auth_compile.args,但当前本地编译环境缺少 Gson/OkHttp/commons-lang/log4j 等依赖 classpath,无法完成有效编译验证。
“gaohp” 5 月之前
父节点
当前提交
e8232dd43c
共有 1 个文件被更改,包括 133 次插入 和 34 次删除
  1. 133 34
      src/biz/kq/HkLeaveAuthServ.java

+ 133 - 34
src/biz/kq/HkLeaveAuthServ.java

@@ -868,7 +868,9 @@ public class HkLeaveAuthServ extends Serv {
         result.put("downloadTaskSearchApiPath", "/artemis/api/acps/v1/authDownload/task/search");
         result.put("downloadRecordChannelApiPath", "/artemis/api/acps/v1/download_record/channel/list/search");
         result.put("downloadRecordPersonDetailApiPath", "/artemis/api/acps/v2/download_record/person/detail/search");
-        if (StringUtils.isNotBlank(callbackUrl))
+        boolean callbackConfigured = StringUtils.isNotBlank(callbackUrl);
+        result.put("callbackConfigured", callbackConfigured);
+        if (callbackConfigured)
             result.put("platformCallbackUrl", callbackUrl);
         if (StringUtils.isNotBlank(templateId))
             result.put("platformTemplateId", templateId);
@@ -912,26 +914,20 @@ public class HkLeaveAuthServ extends Serv {
             result.put("authDownloadResetReq", resetReq);
             Map<String, Object> resetResp = HK_API_CLIENT.resetAuthDownloadByPerson(hkConnParm, resetReq);
             result.put("authDownloadResetResp", resetResp);
+            boolean downloadResetAccepted = isHkRespAccepted(resetResp);
+            result.put("downloadResetAccepted", downloadResetAccepted);
 
             String downloadTaskId = rdTaskId(resetResp);
-            String downloadTaskSource = StringUtils.isNotBlank(downloadTaskId) ? "personReset" : null;
-            if (StringUtils.isBlank(downloadTaskId)) {
-                Map<String, Object> shortcutReq = makeAuthConfigShortcutReq(resourceInfoList);
-                result.put("authDownloadShortcutReq", shortcutReq);
-                try {
-                    Map<String, Object> shortcutResp = HK_API_CLIENT.shortcutAuthDownload(hkConnParm, shortcutReq);
-                    result.put("authDownloadShortcutResp", shortcutResp);
-                    String shortcutTaskId = rdTaskId(shortcutResp);
-                    if (StringUtils.isNotBlank(shortcutTaskId)) {
-                        downloadTaskId = shortcutTaskId;
-                        downloadTaskSource = "configShortcut";
-                    }
-                } catch (Exception e) {
-                    result.put("authDownloadShortcutError", e.getMessage());
-                }
-            }
+            String downloadTaskSource = downloadResetAccepted || StringUtils.isNotBlank(downloadTaskId) ? "personReset" : null;
+            result.put("downloadTaskAccepted", downloadResetAccepted || StringUtils.isNotBlank(downloadTaskId));
             result.put("downloadTaskId", downloadTaskId);
             result.put("downloadTaskSource", downloadTaskSource);
+            if (downloadResetAccepted && StringUtils.isBlank(downloadTaskId)) {
+                result.put("downloadPendingReason",
+                        callbackConfigured ? "resetAcceptedAwaitCallback" : "resetAcceptedWithoutTaskIdOrCallback");
+            } else if (!downloadResetAccepted) {
+                result.put("downloadPendingReason", "resetNotAccepted");
+            }
             if (StringUtils.isNotBlank(downloadTaskId)) {
                 Map<String, Object> taskSearchReq = makeAuthDownloadTaskSearchReq(downloadTaskId);
                 result.put("authDownloadTaskSearchReq", taskSearchReq);
@@ -990,16 +986,6 @@ public class HkLeaveAuthServ extends Serv {
         return req;
     }
 
-    /**
-     * 2026-05-28:平台配置快捷下载仅需资源信息和任务类型。
-     */
-    private static Map<String, Object> makeAuthConfigShortcutReq(List<Map<String, Object>> resourceInfoList) {
-        Map<String, Object> req = new LinkedHashMap<>();
-        req.put("taskType", 4);
-        req.put("resourceInfos", makeAuthConfigResourceInfoList(resourceInfoList));
-        return req;
-    }
-
     /**
      * 2026-06-02:平台配置完成后,按人员和设备通道做一次定向重下发,更贴近“请假单即时生效”场景。
      */
@@ -1353,6 +1339,11 @@ public class HkLeaveAuthServ extends Serv {
         putLeaveAuthPersistField(fieldMap, "configTaskId", rdStr(result.get("configTaskId")));
         putLeaveAuthPersistField(fieldMap, "downloadTaskId", rdStr(result.get("downloadTaskId")));
         putLeaveAuthPersistField(fieldMap, "downloadTaskSource", rdStr(result.get("downloadTaskSource")));
+        putLeaveAuthPersistField(fieldMap, "callbackConfigured", rdStr(result.get("callbackConfigured")));
+        putLeaveAuthPersistField(fieldMap, "downloadResetAccepted", rdStr(result.get("downloadResetAccepted")));
+        putLeaveAuthPersistField(fieldMap, "downloadTaskAccepted", rdStr(result.get("downloadTaskAccepted")));
+        putLeaveAuthPersistField(fieldMap, "downloadPendingReason", rdStr(result.get("downloadPendingReason")));
+        putLeaveAuthPersistField(fieldMap, "downloadConfirmSource", rdStr(result.get("downloadConfirmSource")));
         putLeaveAuthPersistField(fieldMap, "downloadResultConfirmed", rdStr(result.get("downloadResultConfirmed")));
         putLeaveAuthPersistField(fieldMap, "downloadTaskFinished", rdStr(result.get("downloadTaskFinished")));
         putLeaveAuthPersistField(fieldMap, "downloadProgressFinished", rdStr(result.get("downloadProgressFinished")));
@@ -1378,7 +1369,6 @@ public class HkLeaveAuthServ extends Serv {
         putLeaveAuthPersistField(fieldMap, "authDownloadResetResp", makeRespBrief(result.get("authDownloadResetResp")));
         putLeaveAuthPersistField(fieldMap, "downloadRecordChannelResp", makeRespBrief(result.get("downloadRecordChannelResp")));
         putLeaveAuthPersistField(fieldMap, "authConfigRateResp", makeRespBrief(result.get("authConfigRateResp")));
-        putLeaveAuthPersistField(fieldMap, "authDownloadShortcutResp", makeRespBrief(result.get("authDownloadShortcutResp")));
         putLeaveAuthPersistField(fieldMap, "authDownloadTaskSearchResp", makeRespBrief(result.get("authDownloadTaskSearchResp")));
         putLeaveAuthPersistField(fieldMap, "authDownloadTaskProgressResp", makeRespBrief(result.get("authDownloadTaskProgressResp")));
 
@@ -1537,8 +1527,14 @@ public class HkLeaveAuthServ extends Serv {
     private static void applyPersistedLeaveAuthSnapshot(LeaveAuthSyncCtx ctx, Map<String, Object> result) {
         if (ctx == null || result == null)
             return;
+        putPersistedField(result, "callbackConfigured", rdLeaveAuthLogField(ctx, "callbackConfigured"));
+        putPersistedField(result, "downloadResetAccepted", rdLeaveAuthLogField(ctx, "downloadResetAccepted"));
+        putPersistedField(result, "downloadTaskAccepted", rdLeaveAuthLogField(ctx, "downloadTaskAccepted"));
         putPersistedField(result, "downloadTaskId", rdLeaveAuthLogField(ctx, "downloadTaskId"));
         putPersistedField(result, "downloadTaskSource", rdLeaveAuthLogField(ctx, "downloadTaskSource"));
+        putPersistedField(result, "downloadPendingReason", rdLeaveAuthLogField(ctx, "downloadPendingReason"));
+        putPersistedField(result, "downloadConfirmSource", rdLeaveAuthLogField(ctx, "downloadConfirmSource"));
+        putPersistedField(result, "downloadResultConfirmed", rdLeaveAuthLogField(ctx, "downloadResultConfirmed"));
         putPersistedField(result, "downloadCallbackReceived", rdLeaveAuthLogField(ctx, "downloadCallbackReceived"));
         putPersistedField(result, "callbackTaskId", rdLeaveAuthLogField(ctx, "callbackTaskId"));
         putPersistedField(result, "callbackRecvTime", rdLeaveAuthLogField(ctx, "callbackRecvTime"));
@@ -1601,6 +1597,8 @@ public class HkLeaveAuthServ extends Serv {
             persistResult.put("callbackRecvTime", makeHkTime(new Timestamp(System.currentTimeMillis())));
             persistResult.put("callbackBodySize", pushBodyStr == null ? 0 : pushBodyStr.length());
             persistResult.put("callbackMatchedRcid", ctx.rcid);
+            persistResult.put("downloadResetAccepted", true);
+            persistResult.put("downloadTaskAccepted", true);
 
             Map<String, Object> resourceInfo = resourceResult == null ? null : castMap(resourceResult.get("resourceInfo"));
             String resourceKey = makeResourceKey(resourceInfo);
@@ -1612,6 +1610,9 @@ public class HkLeaveAuthServ extends Serv {
             persistResult.put("callbackPersonDownloadResult", rdStr(resourceDetail == null ? null : resourceDetail.get("persondownloadResult")));
 
             boolean callbackSuccess = isLeaveAuthCallbackSuccess(resourceResult, resourceDetail);
+            persistResult.put("downloadConfirmSource", callbackSuccess ? "callback" : null);
+            persistResult.put("downloadResultConfirmed", callbackSuccess);
+            persistResult.put("downloadPendingReason", callbackSuccess ? "callbackCompleted" : "callbackReturnedFailure");
             persistResult.put("ok", callbackSuccess);
             persistResult.put("msg", callbackSuccess ? "已收到海康下载成功回调。" : "已收到海康下载回调,但当前资源结果未全部成功。");
             persistLeaveAuthSyncResult(gdba, ctx, persistResult);
@@ -1667,6 +1668,25 @@ public class HkLeaveAuthServ extends Serv {
         return resourceOk && personOk;
     }
 
+    /**
+     * 2026-06-04:结果回查直接读取 RC 快照里的回调摘要,判断这次回调本身是否成功。
+     */
+    private static boolean isPersistedLeaveAuthCallbackSuccess(Map<String, Object> result) {
+        if (!rdBoolLike(result == null ? null : result.get("downloadCallbackReceived")))
+            return false;
+        String resourceDownloadResult = rdStr(result == null ? null : result.get("callbackResourceDownloadResult"));
+        String personDownloadResult = rdStr(result == null ? null : result.get("callbackPersonDownloadResult"));
+        if (StringUtils.isAllBlank(resourceDownloadResult, personDownloadResult))
+            return false;
+        boolean resourceOk = "0".equals(resourceDownloadResult)
+                || "success".equalsIgnoreCase(resourceDownloadResult)
+                || StringUtils.isBlank(resourceDownloadResult);
+        boolean personOk = "0".equals(personDownloadResult)
+                || "success".equalsIgnoreCase(personDownloadResult)
+                || StringUtils.isBlank(personDownloadResult);
+        return resourceOk && personOk;
+    }
+
     /**
      * 2026-06-02:按下载任务号回查对应请假记录,供回调补写使用。
      */
@@ -1786,6 +1806,11 @@ public class HkLeaveAuthServ extends Serv {
         result.put("tagId", tagId);
         result.put("tagIdSource", rdCfgSource(overrideParm, "tagId", CFG_TAG_ID, "HK_LEAVE_AUTH_TAG_ID", HK_DEF_TAG_ID));
         applyPersistedLeaveAuthSnapshot(ctx, result);
+        String callbackUrl = rdCfgOrOverride(overrideParm, "callbackUrl", CFG_CALLBACK_URL, "HK_LEAVE_AUTH_CALLBACK_URL");
+        if (StringUtils.isNotBlank(callbackUrl))
+            result.put("platformCallbackUrl", callbackUrl);
+        if (!result.containsKey("callbackConfigured"))
+            result.put("callbackConfigured", StringUtils.isNotBlank(callbackUrl));
 
         Map<String, Object> personInfo = null;
         String personId = null;
@@ -1826,12 +1851,16 @@ public class HkLeaveAuthServ extends Serv {
             result.put("authConfigSearchError", "未能获取海康 personId,无法查询平台权限配置。");
         }
 
-        String downloadTaskId = rdLeaveAuthLogField(ctx, "downloadTaskId");
+        String downloadTaskId = StringUtils.defaultIfBlank(
+                rdLeaveAuthLogField(ctx, "downloadTaskId"),
+                rdLeaveAuthLogField(ctx, "callbackTaskId"));
         if (StringUtils.isNotBlank(downloadTaskId)) {
             Map<String, Object> taskSearchReq = makeAuthDownloadTaskSearchReq(downloadTaskId);
             Map<String, Object> progressReq = Map.of("taskId", downloadTaskId);
             Map<String, Object> channelRecordReq = makeDownloadRecordChannelListReq(downloadTaskId, resourceInfoList);
             result.put("downloadTaskId", downloadTaskId);
+            if (StringUtils.isBlank(rdStr(result.get("downloadTaskSource"))))
+                result.put("downloadTaskSource", "personReset");
             result.put("authDownloadTaskSearchReq", taskSearchReq);
             result.put("authDownloadTaskProgressReq", progressReq);
             result.put("downloadRecordChannelReq", channelRecordReq);
@@ -2351,10 +2380,21 @@ public class HkLeaveAuthServ extends Serv {
         boolean configRateFinished = isAuthConfigFinished(result.get("authConfigRateResp"));
         boolean configRateSuccess = isAuthConfigSuccess(result.get("authConfigRateResp"), expectedResourceCount);
         boolean configSearchMatched = expectedResourceCount > 0 && matchedConfigCount >= expectedResourceCount;
+        boolean callbackConfigured = rdBoolLike(result.get("callbackConfigured"));
+        boolean downloadResetAccepted = rdBoolLike(result.get("downloadResetAccepted"))
+                || isHkRespAccepted(result.get("authDownloadResetResp"));
+        String downloadTaskId = rdStr(result.get("downloadTaskId"));
+        boolean downloadTaskIdPresent = StringUtils.isNotBlank(downloadTaskId);
         boolean downloadTaskExists = hasAuthDownloadTask(result.get("authDownloadTaskSearchResp"));
         boolean downloadTaskFinished = isAuthDownloadTaskFinished(result.get("authDownloadTaskSearchResp"));
         boolean downloadProgressFinished = isAuthDownloadFinished(castMap(result.get("authDownloadTaskProgressResp")));
         boolean downloadCallbackReceived = rdBoolLike(result.get("downloadCallbackReceived"));
+        boolean downloadCallbackSuccess = isPersistedLeaveAuthCallbackSuccess(result);
+        boolean downloadTaskAccepted = rdBoolLike(result.get("downloadTaskAccepted"))
+                || downloadResetAccepted
+                || downloadTaskIdPresent
+                || downloadTaskExists
+                || downloadCallbackReceived;
         int downloadRecordChannelTotalCount = rdDownloadRecordChannelTotalCount(result.get("downloadRecordChannelResp"));
         int downloadRecordChannelMatchedCount = rdDownloadRecordChannelMatchedCount(result.get("downloadRecordChannelResp"),
                 castMapList(result.get("resourceInfos")));
@@ -2370,7 +2410,41 @@ public class HkLeaveAuthServ extends Serv {
                 && downloadRecordChannelFailedCount == 0
                 && downloadRecordPersonDetailSuccessCount >= expectedResourceCount
                 && downloadRecordPersonDetailFailedCount == 0;
-        boolean downloadConfirmed = !autoDownload || downloadRecordConfirmed;
+        boolean downloadConfirmed = !autoDownload || downloadRecordConfirmed || downloadCallbackSuccess;
+        String downloadConfirmSource = null;
+        String downloadPendingReason;
+        if (!autoDownload) {
+            downloadConfirmSource = "notRequired";
+            downloadPendingReason = "downloadNotRequired";
+        } else if (downloadRecordConfirmed) {
+            downloadConfirmSource = "taskRecord";
+            downloadPendingReason = "taskRecordConfirmed";
+        } else if (downloadCallbackSuccess) {
+            downloadConfirmSource = "callback";
+            downloadPendingReason = "callbackCompleted";
+        } else if (!downloadTaskAccepted) {
+            downloadPendingReason = "resetNotAccepted";
+        } else if (!downloadTaskExists && !downloadCallbackReceived && !downloadTaskIdPresent && callbackConfigured) {
+            downloadPendingReason = "resetAcceptedAwaitCallback";
+        } else if (!downloadTaskExists && !downloadCallbackReceived && !downloadTaskIdPresent) {
+            downloadPendingReason = "resetAcceptedWithoutTaskIdOrCallback";
+        } else if (!downloadTaskExists && !downloadCallbackReceived) {
+            downloadPendingReason = "taskIdReturnedAwaitTaskSearch";
+        } else if (downloadCallbackReceived) {
+            downloadPendingReason = "callbackReturnedFailure";
+        } else if (!downloadTaskFinished && !downloadProgressFinished) {
+            downloadPendingReason = "taskRunning";
+        } else if (downloadRecordChannelMatchedCount <= 0) {
+            downloadPendingReason = "noChannelRecord";
+        } else if (downloadRecordPersonDetailMatchedCount <= 0) {
+            downloadPendingReason = "noPersonDetail";
+        } else if (downloadRecordChannelFailedCount > 0 || downloadRecordPersonDetailFailedCount > 0) {
+            downloadPendingReason = "recordContainsFailure";
+        } else if (downloadTaskFinished) {
+            downloadPendingReason = "taskFinishedButRecordIncomplete";
+        } else {
+            downloadPendingReason = "recordIncomplete";
+        }
 
         result.put("expectedConfigCount", expectedResourceCount);
         result.put("configTotalCount", configTotalCount);
@@ -2378,10 +2452,14 @@ public class HkLeaveAuthServ extends Serv {
         result.put("configRateFinished", configRateFinished);
         result.put("configRateSuccess", configRateSuccess);
         result.put("configSearchMatched", configSearchMatched);
+        result.put("callbackConfigured", callbackConfigured);
+        result.put("downloadResetAccepted", downloadResetAccepted);
+        result.put("downloadTaskAccepted", downloadTaskAccepted);
         result.put("downloadTaskExists", downloadTaskExists);
         result.put("downloadTaskFinished", downloadTaskFinished);
         result.put("downloadProgressFinished", downloadProgressFinished);
         result.put("downloadCallbackReceived", downloadCallbackReceived);
+        result.put("downloadCallbackSuccess", downloadCallbackSuccess);
         result.put("downloadRecordChannelTotalCount", downloadRecordChannelTotalCount);
         result.put("downloadRecordChannelMatchedCount", downloadRecordChannelMatchedCount);
         result.put("downloadRecordChannelSuccessCount", downloadRecordChannelSuccessCount);
@@ -2390,6 +2468,9 @@ public class HkLeaveAuthServ extends Serv {
         result.put("downloadRecordPersonDetailSuccessCount", downloadRecordPersonDetailSuccessCount);
         result.put("downloadRecordPersonDetailFailedCount", downloadRecordPersonDetailFailedCount);
         result.put("downloadRecordConfirmed", downloadRecordConfirmed);
+        result.put("downloadConfirmSource", downloadConfirmSource);
+        result.put("downloadPendingReason", downloadPendingReason);
+        result.put("downloadResultConfirmed", downloadConfirmed);
         result.put("downloadConfirmed", downloadConfirmed);
 
         if (!configRateSuccess) {
@@ -2404,12 +2485,18 @@ public class HkLeaveAuthServ extends Serv {
         }
         if (!downloadConfirmed) {
             result.put("ok", false);
-            if (!downloadTaskExists) {
-                result.put("msg", "海康下载任务未创建成功,设备生效状态未确认。");
+            if (!downloadTaskAccepted) {
+                result.put("msg", "海康人员权限重下发未确认受理,设备生效状态未确认。");
+            } else if (!downloadTaskExists && !downloadCallbackReceived && !downloadTaskIdPresent && callbackConfigured) {
+                result.put("msg", "海康已受理人员权限重下发,当前等待回调确认设备生效。");
+            } else if (!downloadTaskExists && !downloadCallbackReceived && !downloadTaskIdPresent) {
+                result.put("msg", "海康已受理人员权限重下发,但未返回 taskId,且当前未配置回调地址,无法继续确认设备生效状态。");
+            } else if (!downloadTaskExists && !downloadCallbackReceived) {
+                result.put("msg", "海康已返回 downloadTaskId,但暂未查到任务摘要或完整设备记录。");
             } else if (!downloadTaskFinished && !downloadProgressFinished) {
                 result.put("msg", "海康下载任务仍未结束,设备生效状态未确认。");
             } else if (downloadCallbackReceived) {
-                result.put("msg", "已收到海康下载回调,但平台轮询结果仍未达到完整成功状态。");
+                result.put("msg", "已收到海康下载回调,但回调结果未显示全部成功。");
             } else if (downloadRecordChannelMatchedCount <= 0) {
                 result.put("msg", "海康下载任务已结束,但未查询到设备通道下载记录。");
             } else if (downloadRecordPersonDetailMatchedCount <= 0) {
@@ -2427,7 +2514,11 @@ public class HkLeaveAuthServ extends Serv {
         }
 
         result.put("ok", true);
-        result.put("msg", autoDownload ? "海康平台权限配置与下载已确认完成。" : "海康平台权限配置已确认完成。");
+        if (autoDownload && "callback".equals(downloadConfirmSource)) {
+            result.put("msg", "海康平台权限配置已完成,设备生效已由回调确认。");
+        } else {
+            result.put("msg", autoDownload ? "海康平台权限配置与下载已确认完成。" : "海康平台权限配置已确认完成。");
+        }
     }
 
     /**
@@ -2529,6 +2620,14 @@ public class HkLeaveAuthServ extends Serv {
         return (Map<String, Object>) dataObj;
     }
 
+    /**
+     * 2026-06-04:海康标准响应 code=0 视为接口已受理,taskId 是否即时返回不再作为唯一判据。
+     */
+    private static boolean isHkRespAccepted(Object respObj) {
+        Map<String, Object> resp = castMap(respObj);
+        return "0".equals(rdStr(resp == null ? null : resp.get("code")));
+    }
+
     /**
      * 2026-06-02:把弱类型响应对象安全转成 Map,避免到处重复 `instanceof`。
      */