Browse Source

调整: 请假海康授权主链路切换为 auth_config add/search 口径

1. 在 HkLeaveAuthServ 中按 platform_config 模式统一预览、dryRun、执行与结果查看口径,主链路改为 auth_config/add + auth_config/search,并补充 auth_config/delete 接口路径信息。

2. 新增 auth_config/search 轮询确认与 platformConfigConfirmed/configSearchMatched 等持久化字段,去掉对 person/reset、shortcut、authItem、下载任务与回调的主成功依赖;taskId 改为可选诊断字段。

3. 验证:已使用显式 classpath 执行 javac 编译 HkProtocolC、HkApiClient、HkKqServ、HkLeaveAuthServ;未做生产环境联调,待重新部署后验证。
“gaohp” 6 months ago
parent
commit
42ac8a4de9
1 changed files with 161 additions and 373 deletions
  1. 161 373
      src/biz/kq/HkLeaveAuthServ.java

+ 161 - 373
src/biz/kq/HkLeaveAuthServ.java

@@ -31,7 +31,7 @@ import java.util.Set;
 
 /**
  * 2026-05-26:班主任请假后的海康临时权限同步服务。
- * 2026-06-04:当前默认走“平台权限配置 + authItem 下载状态确认”口径,主链路不再依赖 person/reset。
+ * 2026-06-04:当前默认走“auth_config/add + auth_config/search”口径,主链路不再依赖 person/reset、shortcut、authItem。
  */
 public class HkLeaveAuthServ extends Serv {
 
@@ -576,32 +576,59 @@ public class HkLeaveAuthServ extends Serv {
             if (StringUtils.isNotBlank(tagId))
                 hkConnParm.put("tagId", tagId);
 
-            // 2026-05-27:当前请假自动开门按“添加权限配置”口径执行,templateId 只在海康侧明确要求时才附带。
-            Map<String, Object> singleSearchReq = null;
-            Map<String, Object> singleSearchResp = null;
-            String probedTemplateId = null;
-            String templateIdSource = "missing";
-            if (StringUtils.isBlank(templateId)) {
-                singleSearchReq = makeSingleAuthItemSearchReq(personId, resourceInfoList.get(0));
-                result.put("singleSearchReq", singleSearchReq);
-                try {
-                    singleSearchResp = HK_API_CLIENT.searchSingleAuthItem(hkConnParm, singleSearchReq);
-                    result.put("singleSearchResp", singleSearchResp);
-                } catch (Exception e) {
-                    result.put("singleSearchError", e.getMessage());
-                    result.put("templateProbeStatus", "failed");
-                    result.put("templateProbeHint", "海康侧 single/search 当前不能稳定用于自动探测 templateId,请改为显式配置。");
+            boolean platformConfigMode = "platform_config".equalsIgnoreCase(mode);
+            boolean legacyMode = !platformConfigMode;
+            Map<String, Object> payload;
+            if (platformConfigMode) {
+                payload = makeAuthConfigAddReq(personId, resourceInfoList, ctx.kssj, ctx.jssj);
+                result.put("templateIdSource", "unused");
+                result.put("templateId", null);
+                result.put("templateDimension", templateDimension);
+                result.put("downloadMode", "authConfigAddSearchDelete");
+                result.put("executeApiPath", "/artemis/api/acps/v1/auth_config/add");
+                result.put("searchApiPath", "/artemis/api/acps/v1/auth_config/search");
+                result.put("deleteApiPath", "/artemis/api/acps/v1/auth_config/delete");
+                result.put("resultApiPath", "/artemis/api/acps/v1/auth_config/search");
+                result.put("rateApiPath", "/artemis/api/acps/v1/auth_config/rate/search");
+                result.put("platformConfigAddReq", payload);
+                result.put("authConfigSearchReq", makeAuthConfigSearchReq(personId, resourceInfoList));
+                result.put("payload", payload);
+                result.put("templateIdAdvice", "当前平台权限配置模式不依赖 templateId。");
+            } else {
+                // 2026-05-27:旧版 special-person 模式仍保留 templateId 探测逻辑,便于兼容历史联调。
+                Map<String, Object> singleSearchReq = null;
+                Map<String, Object> singleSearchResp = null;
+                String probedTemplateId = null;
+                String templateIdSource = "missing";
+                if (StringUtils.isBlank(templateId)) {
+                    singleSearchReq = makeSingleAuthItemSearchReq(personId, resourceInfoList.get(0));
+                    result.put("singleSearchReq", singleSearchReq);
+                    try {
+                        singleSearchResp = HK_API_CLIENT.searchSingleAuthItem(hkConnParm, singleSearchReq);
+                        result.put("singleSearchResp", singleSearchResp);
+                    } catch (Exception e) {
+                        result.put("singleSearchError", e.getMessage());
+                        result.put("templateProbeStatus", "failed");
+                        result.put("templateProbeHint", "海康侧 single/search 当前不能稳定用于自动探测 templateId,请改为显式配置。");
+                    }
+                    probedTemplateId = extTemplateId(singleSearchResp);
+                    templateIdSource = StringUtils.isNotBlank(probedTemplateId) ? "singleSearchResp" : "missing";
                 }
-                probedTemplateId = extTemplateId(singleSearchResp);
-                templateIdSource = StringUtils.isNotBlank(probedTemplateId) ? "singleSearchResp" : "missing";
+                if (StringUtils.isNotBlank(templateId))
+                    templateIdSource = "cfg";
+                String effectiveTemplateId = StringUtils.defaultIfBlank(templateId, probedTemplateId);
+                result.put("templateIdSource", templateIdSource);
+                result.put("templateId", effectiveTemplateId);
+                result.put("downloadMode", StringUtils.isBlank(effectiveTemplateId) ? "addPermissionConfig" : "addPermissionConfigWithTemplate");
+                result.put("executeApiPath", "/artemis/api/acps/v1/authDownload/special/person/diy");
+                result.put("resultApiPath", "/artemis/api/acps/v1/authDownload/special/person/diy/result");
+                // 2026-05-27:templateId 为空时,不再把 templateConfigInfos 强塞进请求体,避免把新增权限配置卡死。
+                payload = makeSpecialAuthPayload(
+                        ctx, personInfo, personId, resourceInfoList, tagId, callbackUrl, effectiveTemplateId, templateDimension);
+                result.put("payload", payload);
+                result.put("authDownloadResultQueryReq", makeAuthDownloadResultQueryReq(personId, resourceInfoList));
+                result.put("templateIdAdvice", "templateId 仅在海康侧明确要求模板时再补;当前请假自动开门默认可不传。");
             }
-            if (StringUtils.isNotBlank(templateId))
-                templateIdSource = "cfg";
-            String effectiveTemplateId = StringUtils.defaultIfBlank(templateId, probedTemplateId);
-            result.put("templateIdSource", templateIdSource);
-            result.put("templateId", effectiveTemplateId);
-            result.put("downloadMode", StringUtils.isBlank(effectiveTemplateId) ? "addPermissionConfig" : "addPermissionConfigWithTemplate");
-            result.put("templateDimension", templateDimension);
             result.put("mode", mode);
             result.put("tagId", tagId);
             result.put("tagIdSource", tagIdSource);
@@ -614,15 +641,6 @@ public class HkLeaveAuthServ extends Serv {
             result.put("missingConfig", missingCfgList);
             result.put("nextSteps", makeNextStepList(missingCfgList));
             result.put("tagIdAdvice", "当前项目只做接口下发时,tagId 只要海康侧提供可用值即可;若还要求平台门禁管理可见,再评估是否改成 acs。");
-            result.put("templateIdAdvice", "templateId 仅在海康侧明确要求模板时再补;当前请假自动开门默认可不传。");
-            result.put("executeApiPath", "/artemis/api/acps/v1/authDownload/special/person/diy");
-            result.put("resultApiPath", "/artemis/api/acps/v1/authDownload/special/person/diy/result");
-
-            // 2026-05-27:templateId 为空时,不再把 templateConfigInfos 强塞进请求体,避免把新增权限配置卡死。
-            Map<String, Object> payload = makeSpecialAuthPayload(
-                    ctx, personInfo, personId, resourceInfoList, tagId, callbackUrl, effectiveTemplateId, templateDimension);
-            result.put("payload", payload);
-            result.put("authDownloadResultQueryReq", makeAuthDownloadResultQueryReq(personId, resourceInfoList));
 
             if (StringUtils.isBlank(tagId)) {
                 result.put("skipReason", "缺少海康下发配置 tagId,暂不执行下发。");
@@ -632,8 +650,6 @@ public class HkLeaveAuthServ extends Serv {
             }
 
             boolean execute = rdBoolCfg(CFG_EXECUTE, "HK_LEAVE_AUTH_EXECUTE", false);
-            boolean platformConfigMode = "platform_config".equalsIgnoreCase(mode);
-            boolean legacyMode = !platformConfigMode;
             if (!autoTrigger || !execute) {
                 result.put("mode", "dryRun");
                 if (autoTrigger)
@@ -836,8 +852,8 @@ public class HkLeaveAuthServ extends Serv {
 
     /**
      * 2026-06-04:按平台权限配置模式执行。
-     * 流程:添加权限配置 -> 查询配置进度/配置结果 -> 以 authItem 为主确认设备下载状态。
-     * 如显式开启 shortcut 补下载,再补做一次 authItem 复核。
+     * 流程:添加权限配置 -> 轮询 auth_config/search 确认平台权限已落库。
+     * delete 由后续销假/结束回收场景复用,这里先把新增与查询口径收口。
      */
     private static Map<String, Object> runPlatformConfigMode(Db gdba,
                                                              LeaveAuthSyncCtx ctx,
@@ -860,17 +876,15 @@ public class HkLeaveAuthServ extends Serv {
         if (StringUtils.isNotBlank(tagId))
             hkConnParm.put("tagId", tagId);
 
-        Map<String, Object> configAddReq = makeAuthConfigAddReq(personId, resourceInfoList, ctx.kssj, ctx.jssj);
+        Map<String, Object> configAddReq = castMap(result.get("platformConfigAddReq"));
+        if (configAddReq == null)
+            configAddReq = makeAuthConfigAddReq(personId, resourceInfoList, ctx.kssj, ctx.jssj);
         result.put("platformConfigAddReq", configAddReq);
         result.put("executeApiPath", "/artemis/api/acps/v1/auth_config/add");
-        result.put("resultApiPath", "/artemis/api/acps/v1/auth_config/rate/search");
-        result.put("authItemTotalApiPath", "/artemis/api/acps/v1/auth_item/total/search");
-        result.put("authItemListApiPath", "/artemis/api/acps/v1/auth_item/list/search");
-        result.put("downloadApiPath", "/artemis/api/acps/v1/authDownload/configuration/shortcut");
-        result.put("downloadTaskProgressApiPath", "/artemis/api/acps/v1/authDownload/task/progress");
-        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");
+        result.put("searchApiPath", "/artemis/api/acps/v1/auth_config/search");
+        result.put("deleteApiPath", "/artemis/api/acps/v1/auth_config/delete");
+        result.put("resultApiPath", "/artemis/api/acps/v1/auth_config/search");
+        result.put("rateApiPath", "/artemis/api/acps/v1/auth_config/rate/search");
         boolean callbackConfigured = StringUtils.isNotBlank(callbackUrl);
         result.put("callbackConfigured", callbackConfigured);
         if (callbackConfigured)
@@ -878,138 +892,44 @@ public class HkLeaveAuthServ extends Serv {
         if (StringUtils.isNotBlank(templateId))
             result.put("platformTemplateId", templateId);
         result.put("platformTemplateDimension", templateDimension);
-        result.put("payload", legacyPayload);
+        result.put("payload", configAddReq);
 
         Map<String, Object> configAddResp = HK_API_CLIENT.addAuthConfig(hkConnParm, configAddReq);
         result.put("authSyncResp", configAddResp);
         result.put("mode", "execute_platform_config");
+        result.put("downloadMode", "authConfigAddSearchDelete");
 
-        String configTaskId = rdTaskId(configAddResp);
-        result.put("configTaskId", configTaskId);
-        if (StringUtils.isBlank(configTaskId)) {
+        if (!isHkRespAccepted(configAddResp)) {
             result.put("ok", false);
-            result.put("msg", "平台权限配置返回成功,但未拿到 taskId。");
+            result.put("msg", "海康平台未受理权限配置请求。");
             persistLeaveAuthSyncResult(gdba, ctx, result);
             return result;
         }
 
-        Map<String, Object> configRateReq = Map.of("taskId", configTaskId);
-        result.put("authConfigRateReq", configRateReq);
-        try {
-            result.put("authConfigRateResp", HK_API_CLIENT.searchAuthConfigRate(hkConnParm, configRateReq));
-        } catch (Exception e) {
-            result.put("authConfigRateError", e.getMessage());
+        String configTaskId = rdTaskId(configAddResp);
+        result.put("configTaskId", configTaskId);
+        if (StringUtils.isNotBlank(configTaskId)) {
+            Map<String, Object> configRateReq = Map.of("taskId", configTaskId);
+            result.put("authConfigRateReq", configRateReq);
+            try {
+                result.put("authConfigRateResp", HK_API_CLIENT.searchAuthConfigRate(hkConnParm, configRateReq));
+            } catch (Exception e) {
+                result.put("authConfigRateError", e.getMessage());
+            }
         }
 
-        Map<String, Object> configSearchReq = makeAuthConfigSearchReq(personId, resourceInfoList);
+        Map<String, Object> configSearchReq = castMap(result.get("authConfigSearchReq"));
+        if (configSearchReq == null)
+            configSearchReq = makeAuthConfigSearchReq(personId, resourceInfoList);
         result.put("authConfigSearchReq", configSearchReq);
         try {
-            result.put("authConfigSearchResp", HK_API_CLIENT.searchAuthConfig(hkConnParm, configSearchReq));
+            result.put("authConfigSearchResp",
+                    queryAuthConfigSearchWithRetry(hkConnParm, configSearchReq, ctx.kssj, ctx.jssj, resourceInfoList.size()));
         } catch (Exception e) {
             result.put("authConfigSearchError", e.getMessage());
         }
 
-        Map<String, Object> authItemTotalReq = makeAuthItemTotalReq(personId, resourceInfoList);
-        Map<String, Object> authItemListReq = makeAuthItemListReq(personId, resourceInfoList);
-        result.put("authItemTotalReq", authItemTotalReq);
-        result.put("authItemListReq", authItemListReq);
-        try {
-            result.put("authItemTotalResp",
-                    queryAuthItemTotalWithRetry(hkConnParm, authItemTotalReq, resourceInfoList.size()));
-        } catch (Exception e) {
-            result.put("authItemTotalError", e.getMessage());
-        }
-        try {
-            result.put("authItemListResp",
-                    queryAuthItemListWithRetry(hkConnParm, authItemListReq, ctx.kssj, ctx.jssj, resourceInfoList, false));
-        } catch (Exception e) {
-            result.put("authItemListError", e.getMessage());
-        }
-
-        boolean shortcutEnabled = rdBoolCfg("hk.leaveAuth.platform.shortcutEnabled",
-                "HK_LEAVE_AUTH_PLATFORM_SHORTCUT_ENABLED", false);
-        result.put("downloadMode", shortcutEnabled ? "platformConfigAndShortcutDownload" : "platformConfigAndAuthItemConfirm");
-        result.put("shortcutEnabled", shortcutEnabled);
-
-        List<Map<String, Object>> preAuthItemMatchedRowList = extAuthItemMatchedRowList(
-                result.get("authItemListResp"), ctx.kssj, ctx.jssj, resourceInfoList);
-        boolean shortcutNeeded = shortcutEnabled && hasPendingAuthItemDownload(preAuthItemMatchedRowList);
-        result.put("shortcutNeeded", shortcutNeeded);
-        if (shortcutNeeded) {
-            result.put("authItemBeforeShortcutResp", result.get("authItemListResp"));
-            List<Integer> shortcutTaskTypeList = rdShortcutTaskTypeList(preAuthItemMatchedRowList);
-            result.put("shortcutTaskTypeList", shortcutTaskTypeList);
-            result.put("authDownloadShortcutReqList", makeAuthConfigShortcutReqList(shortcutTaskTypeList, resourceInfoList));
-
-            List<Map<String, Object>> shortcutRespList = new ArrayList<>();
-            List<String> downloadTaskIdList = new ArrayList<>();
-            boolean shortcutAccepted = false;
-            for (Map<String, Object> shortcutReq : castMapList(result.get("authDownloadShortcutReqList"))) {
-                Map<String, Object> shortcutResp = HK_API_CLIENT.shortcutAuthDownload(hkConnParm, shortcutReq);
-                shortcutRespList.add(shortcutResp);
-                if (isHkRespAccepted(shortcutResp))
-                    shortcutAccepted = true;
-                String taskId = rdTaskId(shortcutResp);
-                if (StringUtils.isNotBlank(taskId))
-                    downloadTaskIdList.add(taskId);
-            }
-            result.put("authDownloadShortcutRespList", shortcutRespList);
-            result.put("authDownloadShortcutAccepted", shortcutAccepted);
-            result.put("downloadTaskAccepted", shortcutAccepted || !downloadTaskIdList.isEmpty());
-            result.put("downloadTaskSource", "configShortcut");
-            result.put("downloadTaskIdList", downloadTaskIdList);
-            if (downloadTaskIdList.size() == 1)
-                result.put("downloadTaskId", downloadTaskIdList.get(0));
-
-            if (StringUtils.isNotBlank(rdStr(result.get("downloadTaskId")))) {
-                String downloadTaskId = rdStr(result.get("downloadTaskId"));
-                Map<String, Object> taskSearchReq = makeAuthDownloadTaskSearchReq(downloadTaskId);
-                result.put("authDownloadTaskSearchReq", taskSearchReq);
-                try {
-                    result.put("authDownloadTaskSearchResp",
-                            queryAuthDownloadTaskSearchWithRetry(hkConnParm, taskSearchReq));
-                } catch (Exception e) {
-                    result.put("authDownloadTaskSearchError", e.getMessage());
-                }
-                Map<String, Object> progressReq = Map.of("taskId", downloadTaskId);
-                result.put("authDownloadTaskProgressReq", progressReq);
-                try {
-                    result.put("authDownloadTaskProgressResp",
-                            queryAuthDownloadTaskProgressWithRetry(hkConnParm, progressReq));
-                } catch (Exception e) {
-                    result.put("authDownloadTaskProgressError", e.getMessage());
-                }
-
-                Map<String, Object> channelRecordReq = makeDownloadRecordChannelListReq(downloadTaskId, resourceInfoList);
-                result.put("downloadRecordChannelReq", channelRecordReq);
-                try {
-                    Map<String, Object> channelRecordResp = queryDownloadRecordChannelListWithRetry(
-                            hkConnParm, channelRecordReq, resourceInfoList);
-                    result.put("downloadRecordChannelResp", channelRecordResp);
-                    result.put("downloadRecordPersonDetailReqList",
-                            makeDownloadRecordPersonDetailReqList(downloadTaskId, personId, channelRecordResp));
-                    result.put("downloadRecordPersonDetailRespList",
-                            queryDownloadRecordPersonDetailRespListWithRetry(hkConnParm, downloadTaskId, personId, channelRecordResp));
-                } catch (Exception e) {
-                    result.put("downloadRecordQueryError", e.getMessage());
-                }
-            }
-
-            try {
-                result.put("authItemTotalResp",
-                        queryAuthItemTotalWithRetry(hkConnParm, authItemTotalReq, resourceInfoList.size()));
-            } catch (Exception e) {
-                result.put("authItemTotalError", e.getMessage());
-            }
-            try {
-                result.put("authItemListResp",
-                        queryAuthItemListWithRetry(hkConnParm, authItemListReq, ctx.kssj, ctx.jssj, resourceInfoList, true));
-            } catch (Exception e) {
-                result.put("authItemListError", e.getMessage());
-            }
-        }
-
-        finalizePlatformConfigResult(result, ctx.kssj, ctx.jssj, resourceInfoList.size(), shortcutEnabled);
+        finalizePlatformConfigResult(result, ctx.kssj, ctx.jssj, resourceInfoList.size());
         logExecute(ctx, personInfo, configAddReq, configAddResp);
         persistLeaveAuthSyncResult(gdba, ctx, result);
         return result;
@@ -1133,6 +1053,37 @@ public class HkLeaveAuthServ extends Serv {
         return req;
     }
 
+    /**
+     * 2026-06-04:平台权限配置新增后,search 结果可能有短暂延迟,做短轮询避免刚受理就误判失败。
+     */
+    private static Map<String, Object> queryAuthConfigSearchWithRetry(Map<String, Object> hkConnParm,
+                                                                      Map<String, Object> searchReq,
+                                                                      Timestamp leaveBeg,
+                                                                      Timestamp leaveEnd,
+                                                                      int expectedResourceCount) throws Exception {
+        Map<String, Object> lastResp = null;
+        int pollCount = Math.max(1, rdIntCfg("hk.leaveAuth.platform.searchPollCount",
+                "HK_LEAVE_AUTH_PLATFORM_SEARCH_POLL_COUNT", HK_DEF_DOWNLOAD_POLL_COUNT));
+        int sleepMs = Math.max(0, rdIntCfg("hk.leaveAuth.platform.searchPollSleepMs",
+                "HK_LEAVE_AUTH_PLATFORM_SEARCH_POLL_SLEEP_MS", HK_DEF_DOWNLOAD_POLL_SLEEP_MS));
+        int expectedCount = Math.max(1, expectedResourceCount);
+
+        for (int i = 0; i < pollCount; i++) {
+            if (i > 0 && sleepMs > 0) {
+                try {
+                    Thread.sleep(sleepMs);
+                } catch (InterruptedException e) {
+                    Thread.currentThread().interrupt();
+                    break;
+                }
+            }
+            lastResp = HK_API_CLIENT.searchAuthConfig(hkConnParm, searchReq);
+            if (rdAuthConfigMatchedCount(lastResp, leaveBeg, leaveEnd) >= expectedCount)
+                break;
+        }
+        return lastResp;
+    }
+
     /**
      * 2026-05-28:平台权限配置和快捷下载复用同一批资源,但不强制带 channelIndexCodes。
      */
@@ -1427,6 +1378,11 @@ public class HkLeaveAuthServ extends Serv {
         putLeaveAuthPersistField(fieldMap, "mode", rdStr(result.get("mode")));
         putLeaveAuthPersistField(fieldMap, "ok", rdStr(result.get("ok")));
         putLeaveAuthPersistField(fieldMap, "msg", rdStr(result.get("msg")));
+        putLeaveAuthPersistField(fieldMap, "platformConfigConfirmed", rdStr(result.get("platformConfigConfirmed")));
+        putLeaveAuthPersistField(fieldMap, "platformConfirmSource", rdStr(result.get("platformConfirmSource")));
+        putLeaveAuthPersistField(fieldMap, "configSearchMatched", rdStr(result.get("configSearchMatched")));
+        putLeaveAuthPersistField(fieldMap, "expectedConfigCount", rdStr(result.get("expectedConfigCount")));
+        putLeaveAuthPersistField(fieldMap, "matchedConfigCount", rdStr(result.get("matchedConfigCount")));
         putLeaveAuthPersistField(fieldMap, "configTaskId", rdStr(result.get("configTaskId")));
         putLeaveAuthPersistField(fieldMap, "downloadTaskId", rdStr(result.get("downloadTaskId")));
         putLeaveAuthPersistField(fieldMap, "downloadTaskSource", rdStr(result.get("downloadTaskSource")));
@@ -1456,6 +1412,7 @@ public class HkLeaveAuthServ extends Serv {
         putLeaveAuthPersistField(fieldMap, "callbackPersonId", rdStr(result.get("callbackPersonId")));
         putLeaveAuthPersistField(fieldMap, "callbackPersonDownloadResult", rdStr(result.get("callbackPersonDownloadResult")));
         putLeaveAuthPersistField(fieldMap, "authSyncResp", makeRespBrief(result.get("authSyncResp")));
+        putLeaveAuthPersistField(fieldMap, "authConfigSearchResp", makeRespBrief(result.get("authConfigSearchResp")));
         putLeaveAuthPersistField(fieldMap, "authDownloadResultQueryResp", makeRespBrief(result.get("authDownloadResultQueryResp")));
         putLeaveAuthPersistField(fieldMap, "authDownloadResetResp", makeRespBrief(result.get("authDownloadResetResp")));
         putLeaveAuthPersistField(fieldMap, "downloadRecordChannelResp", makeRespBrief(result.get("downloadRecordChannelResp")));
@@ -1618,6 +1575,11 @@ public class HkLeaveAuthServ extends Serv {
     private static void applyPersistedLeaveAuthSnapshot(LeaveAuthSyncCtx ctx, Map<String, Object> result) {
         if (ctx == null || result == null)
             return;
+        putPersistedField(result, "platformConfigConfirmed", rdLeaveAuthLogField(ctx, "platformConfigConfirmed"));
+        putPersistedField(result, "platformConfirmSource", rdLeaveAuthLogField(ctx, "platformConfirmSource"));
+        putPersistedField(result, "configSearchMatched", rdLeaveAuthLogField(ctx, "configSearchMatched"));
+        putPersistedField(result, "expectedConfigCount", rdLeaveAuthLogField(ctx, "expectedConfigCount"));
+        putPersistedField(result, "matchedConfigCount", rdLeaveAuthLogField(ctx, "matchedConfigCount"));
         putPersistedField(result, "callbackConfigured", rdLeaveAuthLogField(ctx, "callbackConfigured"));
         putPersistedField(result, "downloadResetAccepted", rdLeaveAuthLogField(ctx, "downloadResetAccepted"));
         putPersistedField(result, "downloadTaskAccepted", rdLeaveAuthLogField(ctx, "downloadTaskAccepted"));
@@ -1953,85 +1915,23 @@ public class HkLeaveAuthServ extends Serv {
             Map<String, Object> configSearchReq = makeAuthConfigSearchReq(personId, resourceInfoList);
             result.put("authConfigSearchReq", configSearchReq);
             try {
-                result.put("authConfigSearchResp", HK_API_CLIENT.searchAuthConfig(hkConnParm, configSearchReq));
+                result.put("authConfigSearchResp",
+                        queryAuthConfigSearchWithRetry(hkConnParm, configSearchReq, ctx.kssj, ctx.jssj, resourceInfoList.size()));
             } catch (Exception e) {
                 result.put("authConfigSearchError", e.getMessage());
             }
-
-            Map<String, Object> authItemTotalReq = makeAuthItemTotalReq(personId, resourceInfoList);
-            Map<String, Object> authItemListReq = makeAuthItemListReq(personId, resourceInfoList);
-            result.put("authItemTotalReq", authItemTotalReq);
-            result.put("authItemListReq", authItemListReq);
-            try {
-                result.put("authItemTotalResp",
-                        queryAuthItemTotalWithRetry(hkConnParm, authItemTotalReq, resourceInfoList.size()));
-            } catch (Exception e) {
-                result.put("authItemTotalError", e.getMessage());
-            }
-            try {
-                result.put("authItemListResp",
-                        queryAuthItemListWithRetry(hkConnParm, authItemListReq, ctx.kssj, ctx.jssj, resourceInfoList, true));
-            } catch (Exception e) {
-                result.put("authItemListError", e.getMessage());
-            }
         } else {
             result.put("authConfigSearchError", "未能获取海康 personId,无法查询平台权限配置。");
-            result.put("authItemListError", "未能获取海康 personId,无法查询 authItem 下载状态。");
-        }
-
-        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);
-            try {
-                result.put("authDownloadTaskSearchResp",
-                        queryAuthDownloadTaskSearchWithRetry(hkConnParm, taskSearchReq));
-            } catch (Exception e) {
-                result.put("authDownloadTaskSearchError", e.getMessage());
-            }
-            try {
-                result.put("authDownloadTaskProgressResp",
-                        queryAuthDownloadTaskProgressWithRetry(hkConnParm, progressReq));
-            } catch (Exception e) {
-                result.put("authDownloadTaskProgressError", e.getMessage());
-            }
-            try {
-                Map<String, Object> channelRecordResp = queryDownloadRecordChannelListWithRetry(
-                        hkConnParm, channelRecordReq, resourceInfoList);
-                result.put("downloadRecordChannelResp", channelRecordResp);
-                result.put("downloadRecordPersonDetailReqList",
-                        makeDownloadRecordPersonDetailReqList(downloadTaskId, personId, channelRecordResp));
-                result.put("downloadRecordPersonDetailRespList",
-                        queryDownloadRecordPersonDetailRespListWithRetry(hkConnParm, downloadTaskId, personId, channelRecordResp));
-            } catch (Exception e) {
-                result.put("downloadRecordQueryError", e.getMessage());
-            }
         }
 
         result.put("mode", "viewPlatformConfigResult");
         result.put("executeApiPath", "/artemis/api/acps/v1/auth_config/add");
-        result.put("resultApiPath", "/artemis/api/acps/v1/auth_config/rate/search");
-        result.put("authItemTotalApiPath", "/artemis/api/acps/v1/auth_item/total/search");
-        result.put("authItemListApiPath", "/artemis/api/acps/v1/auth_item/list/search");
-        result.put("downloadApiPath", "/artemis/api/acps/v1/authDownload/configuration/shortcut");
-        result.put("downloadTaskProgressApiPath", "/artemis/api/acps/v1/authDownload/task/progress");
-        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");
-        boolean shortcutEnabled = rdBoolCfg("hk.leaveAuth.platform.shortcutEnabled",
-                "HK_LEAVE_AUTH_PLATFORM_SHORTCUT_ENABLED", false);
-        result.put("shortcutEnabled", shortcutEnabled);
-        result.put("downloadMode", shortcutEnabled ? "platformConfigAndShortcutDownload" : "platformConfigAndAuthItemConfirm");
-        finalizePlatformConfigResult(result, ctx.kssj, ctx.jssj, resourceInfoList.size(), shortcutEnabled);
+        result.put("searchApiPath", "/artemis/api/acps/v1/auth_config/search");
+        result.put("deleteApiPath", "/artemis/api/acps/v1/auth_config/delete");
+        result.put("resultApiPath", "/artemis/api/acps/v1/auth_config/search");
+        result.put("rateApiPath", "/artemis/api/acps/v1/auth_config/rate/search");
+        result.put("downloadMode", "authConfigAddSearchDelete");
+        finalizePlatformConfigResult(result, ctx.kssj, ctx.jssj, resourceInfoList.size());
         return result;
     }
 
@@ -2564,95 +2464,24 @@ public class HkLeaveAuthServ extends Serv {
     }
 
     /**
-     * 2026-06-04:平台配置模式必须同时确认“配置成功 + 平台可查 + authItem 已显示下载完成”后,才对外返回成功。
-     * task / download_record / callback 现在只作为辅助诊断,主判据改为 authItem。
+     * 2026-06-04:平台配置模式按海康技术支持建议,仅以 auth_config/search 查到完整权限配置作为主成功判据。
+     * callback/下载记录只保留为辅助诊断,不再作为请假自动开门主链路的阻断条件。
      */
     private static void finalizePlatformConfigResult(Map<String, Object> result,
                                                      Timestamp leaveBeg,
                                                      Timestamp leaveEnd,
-                                                     int expectedResourceCount,
-                                                     boolean shortcutEnabled) {
+                                                     int expectedResourceCount) {
         int configTotalCount = rdAuthConfigTotalCount(result.get("authConfigSearchResp"));
         int matchedConfigCount = rdAuthConfigMatchedCount(result.get("authConfigSearchResp"), leaveBeg, leaveEnd);
         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"));
-        List<Map<String, Object>> authItemMatchedRowList = extAuthItemMatchedRowList(
-                result.get("authItemListResp"), leaveBeg, leaveEnd, castMapList(result.get("resourceInfos")));
-        int authItemTotalCount = rdAuthItemTotalCount(result.get("authItemTotalResp"));
-        int authItemMatchedCount = authItemMatchedRowList.size();
-        int authItemDownloadedCount = rdAuthItemDownloadedCount(authItemMatchedRowList);
-        int authItemPendingCount = rdAuthItemPendingCount(authItemMatchedRowList);
-        int authItemCredentialMissingCount = rdAuthItemCredentialMissingCount(authItemMatchedRowList);
-        boolean authItemSearchMatched = expectedResourceCount > 0 && authItemMatchedCount >= expectedResourceCount;
-        boolean authItemDownloaded = expectedResourceCount > 0
-                && authItemMatchedCount >= expectedResourceCount
-                && authItemPendingCount == 0
-                && authItemDownloadedCount >= expectedResourceCount;
-        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 shortcutAccepted = rdBoolLike(result.get("authDownloadShortcutAccepted"));
-        boolean downloadTaskAccepted = rdBoolLike(result.get("downloadTaskAccepted"))
-                || shortcutAccepted
-                || downloadTaskIdPresent
-                || downloadTaskExists
-                || downloadCallbackReceived;
-        int downloadRecordChannelTotalCount = rdDownloadRecordChannelTotalCount(result.get("downloadRecordChannelResp"));
-        int downloadRecordChannelMatchedCount = rdDownloadRecordChannelMatchedCount(result.get("downloadRecordChannelResp"),
-                castMapList(result.get("resourceInfos")));
-        int downloadRecordChannelSuccessCount = rdDownloadRecordChannelSuccessCount(result.get("downloadRecordChannelResp"),
-                castMapList(result.get("resourceInfos")));
-        int downloadRecordChannelFailedCount = rdDownloadRecordChannelFailedCount(result.get("downloadRecordChannelResp"),
-                castMapList(result.get("resourceInfos")));
-        int downloadRecordPersonDetailMatchedCount = rdDownloadRecordPersonDetailMatchedCount(result.get("downloadRecordPersonDetailRespList"));
-        int downloadRecordPersonDetailSuccessCount = rdDownloadRecordPersonDetailSuccessCount(result.get("downloadRecordPersonDetailRespList"));
-        int downloadRecordPersonDetailFailedCount = rdDownloadRecordPersonDetailFailedCount(result.get("downloadRecordPersonDetailRespList"));
-        boolean downloadRecordConfirmed = expectedResourceCount > 0
-                && downloadRecordChannelMatchedCount >= expectedResourceCount
-                && downloadRecordChannelFailedCount == 0
-                && downloadRecordPersonDetailSuccessCount >= expectedResourceCount
-                && downloadRecordPersonDetailFailedCount == 0;
-        boolean downloadConfirmed = authItemDownloaded || downloadRecordConfirmed || downloadCallbackSuccess;
-        String downloadConfirmSource = null;
-        String downloadPendingReason;
-        if (authItemDownloaded) {
-            downloadConfirmSource = "authItem";
-            downloadPendingReason = "authItemDownloaded";
-        } else if (downloadRecordConfirmed) {
-            downloadConfirmSource = "taskRecord";
-            downloadPendingReason = "taskRecordConfirmed";
-        } else if (downloadCallbackSuccess) {
-            downloadConfirmSource = "callback";
-            downloadPendingReason = "callbackCompleted";
-        } else if (!authItemSearchMatched) {
-            downloadPendingReason = "authItemNotReady";
-        } else if (downloadCallbackReceived) {
-            downloadPendingReason = "callbackReturnedFailure";
-        } else if (shortcutEnabled && !downloadTaskAccepted) {
-            downloadPendingReason = "shortcutNotAccepted";
-        } else if (shortcutEnabled && downloadTaskAccepted && !downloadTaskExists && !downloadCallbackReceived && !downloadTaskIdPresent) {
-            downloadPendingReason = "shortcutAcceptedAwaitAuthItem";
-        } else if (shortcutEnabled && !downloadTaskFinished && !downloadProgressFinished && downloadTaskExists) {
-            downloadPendingReason = "taskRunning";
-        } else if (authItemPendingCount > 0) {
-            downloadPendingReason = "authItemNotDownloaded";
-        } 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";
-        }
+        boolean deviceEffectConfirmed = downloadCallbackSuccess;
+        String platformConfirmSource = configSearchMatched ? "authConfigSearch" : null;
+        String downloadPendingReason = configSearchMatched ? "authConfigSearchMatched" : "authConfigSearchNotMatched";
 
         result.put("expectedConfigCount", expectedResourceCount);
         result.put("configTotalCount", configTotalCount);
@@ -2660,84 +2489,43 @@ public class HkLeaveAuthServ extends Serv {
         result.put("configRateFinished", configRateFinished);
         result.put("configRateSuccess", configRateSuccess);
         result.put("configSearchMatched", configSearchMatched);
-        result.put("authItemTotalCount", authItemTotalCount);
-        result.put("authItemMatchedCount", authItemMatchedCount);
-        result.put("authItemDownloadedCount", authItemDownloadedCount);
-        result.put("authItemPendingCount", authItemPendingCount);
-        result.put("authItemCredentialMissingCount", authItemCredentialMissingCount);
-        result.put("authItemSearchMatched", authItemSearchMatched);
-        result.put("authItemDownloaded", authItemDownloaded);
-        result.put("authItemStatusSummary", makeAuthItemStatusSummary(authItemMatchedRowList));
-        result.put("authItemPendingSampleList", makeAuthItemPendingSampleList(authItemMatchedRowList, 12));
+        result.put("platformConfigConfirmed", configSearchMatched);
+        result.put("platformConfirmSource", platformConfirmSource);
+        result.put("downloadTaskSource", "authConfigSearchOnly");
         result.put("callbackConfigured", callbackConfigured);
         result.put("downloadResetAccepted", false);
-        result.put("authDownloadShortcutAccepted", shortcutAccepted);
-        result.put("downloadTaskAccepted", downloadTaskAccepted);
-        result.put("downloadTaskExists", downloadTaskExists);
-        result.put("downloadTaskFinished", downloadTaskFinished);
-        result.put("downloadProgressFinished", downloadProgressFinished);
+        result.put("authDownloadShortcutAccepted", false);
+        result.put("downloadTaskAccepted", false);
+        result.put("downloadTaskExists", false);
+        result.put("downloadTaskFinished", false);
+        result.put("downloadProgressFinished", false);
         result.put("downloadCallbackReceived", downloadCallbackReceived);
         result.put("downloadCallbackSuccess", downloadCallbackSuccess);
-        result.put("downloadRecordChannelTotalCount", downloadRecordChannelTotalCount);
-        result.put("downloadRecordChannelMatchedCount", downloadRecordChannelMatchedCount);
-        result.put("downloadRecordChannelSuccessCount", downloadRecordChannelSuccessCount);
-        result.put("downloadRecordChannelFailedCount", downloadRecordChannelFailedCount);
-        result.put("downloadRecordPersonDetailMatchedCount", downloadRecordPersonDetailMatchedCount);
-        result.put("downloadRecordPersonDetailSuccessCount", downloadRecordPersonDetailSuccessCount);
-        result.put("downloadRecordPersonDetailFailedCount", downloadRecordPersonDetailFailedCount);
-        result.put("downloadRecordConfirmed", downloadRecordConfirmed);
-        result.put("downloadConfirmSource", downloadConfirmSource);
+        result.put("downloadRecordChannelTotalCount", 0);
+        result.put("downloadRecordChannelMatchedCount", 0);
+        result.put("downloadRecordChannelSuccessCount", 0);
+        result.put("downloadRecordChannelFailedCount", 0);
+        result.put("downloadRecordPersonDetailMatchedCount", 0);
+        result.put("downloadRecordPersonDetailSuccessCount", 0);
+        result.put("downloadRecordPersonDetailFailedCount", 0);
+        result.put("downloadRecordConfirmed", false);
+        result.put("deviceEffectConfirmed", deviceEffectConfirmed);
+        result.put("downloadConfirmSource", platformConfirmSource);
         result.put("downloadPendingReason", downloadPendingReason);
-        result.put("downloadResultConfirmed", downloadConfirmed);
-        result.put("downloadConfirmed", downloadConfirmed);
+        result.put("downloadResultConfirmed", configSearchMatched);
+        result.put("downloadConfirmed", configSearchMatched);
 
-        if (!configRateSuccess) {
-            result.put("ok", false);
-            result.put("msg", "海康平台权限配置任务未确认全部成功。");
-            return;
-        }
         if (!configSearchMatched) {
             result.put("ok", false);
-            result.put("msg", "海康平台未查到覆盖当前请假时段的完整权限配置。");
-            return;
-        }
-        if (!downloadConfirmed) {
-            result.put("ok", false);
-            if (!authItemSearchMatched) {
-                result.put("msg", "海康平台配置已完成,但 authItem 暂未生成覆盖当前请假时段的完整权限条目。");
-            } else if (downloadCallbackReceived) {
-                result.put("msg", "已收到海康下载回调,但回调结果未显示全部成功。");
-            } else if (authItemPendingCount > 0 && !shortcutEnabled) {
-                result.put("msg", "海康平台已生成权限条目,但 authItem 显示仍有资源处于“已配置未下载/待下载”状态,请确认海康 ACPS 是否已开启权限自动下发。");
-            } else if (authItemPendingCount > 0 && !downloadTaskAccepted) {
-                result.put("msg", "海康平台已生成权限条目,但 shortcut 下载未确认受理,设备生效状态未确认。");
-            } else if (authItemPendingCount > 0 && !downloadTaskExists && !downloadTaskIdPresent && callbackConfigured) {
-                result.put("msg", "海康已受理 shortcut 下载,当前等待 authItem 或回调反映设备侧生效结果。");
-            } else if (authItemPendingCount > 0 && !downloadTaskExists && !downloadTaskIdPresent) {
-                result.put("msg", "海康平台已生成权限条目,但 authItem 仍显示未下载,且 shortcut 未返回可追踪任务号。");
-            } else if (authItemPendingCount > 0 && !downloadTaskFinished && !downloadProgressFinished && downloadTaskExists) {
-                result.put("msg", "海康 shortcut 下载任务仍未结束,authItem 尚未反映全部设备已下载。");
-            } else if (downloadRecordChannelMatchedCount <= 0) {
-                result.put("msg", "authItem 仍未显示全部下载完成,且当前未查询到可支撑确认的设备通道下载记录。");
-            } else if (downloadRecordPersonDetailMatchedCount <= 0) {
-                result.put("msg", "海康已生成设备通道下载记录,但当前仍缺少该学生的完整人员下载详情。");
-            } else if (downloadRecordChannelFailedCount > 0 || downloadRecordPersonDetailFailedCount > 0) {
-                result.put("msg", "海康下载记录显示存在失败或部分失败,authItem 也未显示全部下载完成。");
-            } else if (downloadTaskFinished) {
-                result.put("msg", "海康下载任务摘要显示已结束,但 authItem 仍未达到完整下载成功状态。");
-            } else {
-                result.put("msg", "海康 authItem 仍未达到完整下载成功状态,门禁设备生效结果未确认。");
-            }
+            result.put("msg", "海康已受理权限配置,但 auth_config/search 暂未查到覆盖当前请假时段的完整权限配置。");
             return;
         }
 
         result.put("ok", true);
-        if ("callback".equals(downloadConfirmSource)) {
-            result.put("msg", "海康平台权限配置已完成,设备生效已由回调确认。");
-        } else if ("authItem".equals(downloadConfirmSource)) {
-            result.put("msg", "海康平台权限配置已完成,authItem 已确认设备下载成功。");
+        if (deviceEffectConfirmed) {
+            result.put("msg", "海康平台权限配置已完成,且已收到下载成功回调。");
         } else {
-            result.put("msg", "海康平台权限配置与下载已确认完成。");
+            result.put("msg", "海康平台权限配置已完成,已通过 auth_config/search 确认。");
         }
     }