Explorar o código

新增: 海康请假扩展表并接入结构化回填链路

1. 新增 docs/sql/2026-06-10_rchkla.sql,创建 RCHKLA 扩展表与 taskId/回收相关索引,独立承载海康请假同步、删除、回调状态,不改 RC 主表结构。

2. 调整 HkLeaveAuthServ:在写 RC.WCMSWJ 时同步 upsert RCHKLA,新增 hkkq_leave_auth_backfill_ext 手工回填入口,并把 taskId 回查、最近执行记录、到期回收筛选改为优先走扩展表;扩展表未建时自动回退旧的 WCMSWJ like 逻辑。

3. 更新 web/cfg/biz/kq/hkkq.serv.xml 暴露扩展表回填服务。

4. 验证:已执行 javac --% -sourcepath tmp_empty_src -cp out/artifacts/PMS_war_exploded/WEB-INF/classes;out/artifacts/PMS_war_exploded/WEB-INF/lib/* -d tmp_hk_leave_auth_compile src/core/co/haikang/HkProtocolC.java src/core/co/haikang/HkApiClient.java src/biz/kq/HkKqServ.java src/biz/kq/HkLeaveAuthServ.java 编译通过;未执行数据库 DDL 与线上回填联调。
“gaohp” hai 5 meses
pai
achega
574c8d2509
Modificáronse 3 ficheiros con 468 adicións e 48 borrados
  1. 48 0
      docs/sql/2026-06-10_rchkla.sql
  2. 419 48
      src/biz/kq/HkLeaveAuthServ.java
  3. 1 0
      web/cfg/biz/kq/hkkq.serv.xml

+ 48 - 0
docs/sql/2026-06-10_rchkla.sql

@@ -0,0 +1,48 @@
+create table RCHKLA (
+    RCID number(20) not null,
+    SYNC_MODE varchar2(120),
+    SYNC_TIME timestamp,
+    SYNC_OK number(1),
+    SYNC_MSG varchar2(1000),
+    PERSON_ID varchar2(128),
+    RESOURCE_KEYS varchar2(2000),
+    RESOURCE_COUNT number(10),
+    PLATFORM_CONFIG_CONFIRMED number(1),
+    PLATFORM_CONFIRM_SOURCE varchar2(120),
+    CONFIG_SEARCH_MATCHED number(1),
+    EXPECTED_CONFIG_COUNT number(10),
+    MATCHED_CONFIG_COUNT number(10),
+    CONFIG_TASK_ID varchar2(128),
+    DELETE_TIME timestamp,
+    DELETE_MODE varchar2(120),
+    DELETE_CONFIRMED number(1),
+    DELETE_CONFIRM_SOURCE varchar2(120),
+    DELETE_TASK_ACCEPTED number(1),
+    DELETE_TASK_ID varchar2(128),
+    DELETE_SKIP_REASON varchar2(500),
+    DOWNLOAD_TASK_ID varchar2(128),
+    DOWNLOAD_TASK_SOURCE varchar2(120),
+    DOWNLOAD_RESULT_CONFIRMED number(1),
+    DOWNLOAD_CALLBACK_RECEIVED number(1),
+    CALLBACK_TASK_ID varchar2(128),
+    CALLBACK_RECV_TIME timestamp,
+    WCMSWJ_SNAPSHOT clob,
+    UPDATED_AT timestamp default systimestamp not null,
+    constraint PK_RCHKLA primary key (RCID)
+);
+
+comment on table RCHKLA is '海康请假临时权限扩展状态表';
+comment on column RCHKLA.RCID is '对应 RC.RCID';
+comment on column RCHKLA.SYNC_MODE is '最近一次海康请假链路模式';
+comment on column RCHKLA.SYNC_TIME is '最近一次海康同步时间';
+comment on column RCHKLA.CONFIG_TASK_ID is 'auth_config/add 链路任务号';
+comment on column RCHKLA.DELETE_TASK_ID is 'auth_config/delete 链路任务号';
+comment on column RCHKLA.DOWNLOAD_TASK_ID is '海康下载任务号';
+comment on column RCHKLA.CALLBACK_TASK_ID is '海康下载回调任务号';
+comment on column RCHKLA.WCMSWJ_SNAPSHOT is 'RC.WCMSWJ 结构化摘要快照';
+
+create index IDX_RCHKLA_CFG_TASK on RCHKLA (CONFIG_TASK_ID);
+create index IDX_RCHKLA_DEL_TASK on RCHKLA (DELETE_TASK_ID);
+create index IDX_RCHKLA_DW_TASK on RCHKLA (DOWNLOAD_TASK_ID);
+create index IDX_RCHKLA_CB_TASK on RCHKLA (CALLBACK_TASK_ID);
+create index IDX_RCHKLA_RECYCLE on RCHKLA (PLATFORM_CONFIG_CONFIRMED, DELETE_CONFIRMED, UPDATED_AT);

+ 419 - 48
src/biz/kq/HkLeaveAuthServ.java

@@ -62,6 +62,8 @@ public class HkLeaveAuthServ extends Serv {
     private static final int HK_DEF_DOWNLOAD_POLL_COUNT = 4;
     private static final int HK_DEF_DOWNLOAD_POLL_SLEEP_MS = 1200;
     private static final int HK_DEF_RECYCLE_LIMIT = 20;
+    private static final int HK_DEF_BACKFILL_LIMIT = 200;
+    private static final String HK_LEAVE_AUTH_EXT_TAB = "RCHKLA";
     private static final int RC_WCMSWJ_MAX_BYTES = 4000;
     private static final String RC_WCMSWJ_TRUNCATE_SUFFIX = "...";
     private static final DateTimeFormatter HK_AUTH_TIME_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
@@ -152,6 +154,14 @@ public class HkLeaveAuthServ extends Serv {
         return ServC.SERV_notByA;
     }
 
+    /**
+     * 2026-06-10:手工把现有 RC 里的海康请假摘要回填到独立扩展表,便于后续按 rcid/taskId 结构化追踪。
+     */
+    public String backfillLeaveAuthExt() {
+        super.wrJsonByResp(backfillLeaveAuthExtResult());
+        return ServC.SERV_notByA;
+    }
+
     /**
      * 2026-06-02:海康下载结果回调入口,优先把任务号与下载摘要回写到请假记录,便于现场后补确认。
      */
@@ -545,6 +555,69 @@ public class HkLeaveAuthServ extends Serv {
         }
     }
 
+    /**
+     * 2026-06-10:把历史 RC.wcmswj/mswj/ms 里的海康同步摘要回填到扩展表,避免后续仍靠 like 文本检索。
+     */
+    private Map<String, Object> backfillLeaveAuthExtResult() {
+        Map<String, Object> result = new LinkedHashMap<>();
+        long rcid = rdReqLongParm("rcid");
+        int limit = rdReqIntParm("limit", "batchSize");
+        if (limit <= 0)
+            limit = HK_DEF_BACKFILL_LIMIT;
+
+        result.put("ok", true);
+        result.put("rcid", rcid > 0 ? rcid : null);
+        result.put("limit", limit);
+
+        try (Db gdba = Db.makeConn()) {
+            if (!ifLeaveAuthExtTableReady(gdba)) {
+                result.put("ok", false);
+                result.put("msg", "扩展表 RCHKLA 不存在,请先执行 docs/sql/2026-06-10_rchkla.sql。");
+                return result;
+            }
+
+            List<LeaveAuthSyncCtx> ctxList = selLeaveAuthSyncCtxListForBackfill(gdba, rcid, limit);
+            int importedCount = 0;
+            int skippedCount = 0;
+            List<Map<String, Object>> detailList = new ArrayList<>();
+            for (LeaveAuthSyncCtx ctx : ctxList) {
+                LinkedHashMap<String, String> fieldMap = loadLeaveAuthPersistFieldMap(ctx);
+                if (fieldMap.isEmpty()) {
+                    skippedCount++;
+                    continue;
+                }
+
+                String snapshotText = makeLeaveAuthPersistText(fieldMap);
+                upsertLeaveAuthExtRow(gdba, ctx, fieldMap, snapshotText);
+                importedCount++;
+
+                if (detailList.size() < 20) {
+                    Map<String, Object> item = new LinkedHashMap<>();
+                    item.put("rcid", ctx.rcid);
+                    item.put("xm", ctx.xm);
+                    item.put("mode", fieldMap.get("mode"));
+                    item.put("configTaskId", fieldMap.get("configTaskId"));
+                    item.put("downloadTaskId", fieldMap.get("downloadTaskId"));
+                    item.put("deleteTaskId", fieldMap.get("deleteTaskId"));
+                    detailList.add(item);
+                }
+            }
+            gdba.commit();
+
+            result.put("candidateCount", ctxList.size());
+            result.put("importedCount", importedCount);
+            result.put("skippedCount", skippedCount);
+            result.put("detailList", detailList);
+            result.put("msg", "海康请假扩展表回填完成。");
+            return result;
+        } catch (Exception e) {
+            log4j.error("HkLeaveAuthServ.backfillLeaveAuthExtResult() 异常,rcid={}, limit={}", rcid, limit, e);
+            result.put("ok", false);
+            result.put("msg", e.getMessage());
+            return result;
+        }
+    }
+
     /**
      * 2026-06-10:平台权限配置模式的删除链路。
      * 先查当前请假时段是否仍存在,再按同一批资源做定向 delete,最后用 search 反查确认已清空。
@@ -1050,7 +1123,15 @@ public class HkLeaveAuthServ extends Serv {
         if (rowList == null || rowList.isEmpty())
             return null;
 
-        Map<String, Object> row = rowList.get(0);
+        return buildLeaveAuthSyncCtx(rowList.get(0));
+    }
+
+    /**
+     * 2026-06-10:统一从查询结果行构造请假同步上下文,避免扩展表查询与 RC 原始查询各写一套映射。
+     */
+    private static LeaveAuthSyncCtx buildLeaveAuthSyncCtx(Map<String, Object> row) {
+        if (row == null || row.isEmpty())
+            return null;
         return new LeaveAuthSyncCtx(
                 rdLong(row.get("rcid")),
                 rdLong(row.get("bjid")),
@@ -1836,7 +1917,9 @@ public class HkLeaveAuthServ extends Serv {
         if (!shouldPersist)
             return;
 
-        String persistText = fitWcmswjText(makeLeaveAuthPersistText(ctx, result));
+        LinkedHashMap<String, String> fieldMap = makeLeaveAuthPersistFieldMap(ctx, result);
+        String rawPersistText = makeLeaveAuthPersistText(fieldMap);
+        String persistText = fitWcmswjText(rawPersistText);
         if (StringUtils.isBlank(persistText)) {
             log4j.warn("HkLeaveAuthServ.persistLeaveAuthSyncResult() skip empty rc.wcmswj, rcid={}, mode={}, ok={}, msg={}",
                     ctx.rcid, rdStr(result.get("mode")), rdStr(result.get("ok")), rdStr(result.get("msg")));
@@ -1846,6 +1929,7 @@ public class HkLeaveAuthServ extends Serv {
         rcPo.setRcid(ctx.rcid);
         rcPo.setWcmswj(persistText);
         gdba.doUpdPo(rcPo, Set.of("wcmswj"));
+        syncLeaveAuthExtSnapshotQuietly(gdba, ctx, fieldMap, rawPersistText);
         gdba.commit();
         log4j.info("HkLeaveAuthServ.persistLeaveAuthSyncResult() saved rc.wcmswj, rcid={}, mode={}, ok={}, msg={}",
                 ctx.rcid, rdStr(result.get("mode")), rdStr(result.get("ok")), rdStr(result.get("msg")));
@@ -1878,13 +1962,17 @@ public class HkLeaveAuthServ extends Serv {
      * 2026-05-29:把关键任务号和执行摘要压缩到 RC.wcmswj,供后续结果回查复用。
      */
     private static String makeLeaveAuthPersistText(LeaveAuthSyncCtx ctx, Map<String, Object> result) {
-        if (result == null)
-            return null;
+        return makeLeaveAuthPersistText(makeLeaveAuthPersistFieldMap(ctx, result));
+    }
 
-        LinkedHashMap<String, String> fieldMap = new LinkedHashMap<>();
-        mergeLeaveAuthPersistFieldMap(fieldMap, ctx == null ? null : ctx.ms);
-        mergeLeaveAuthPersistFieldMap(fieldMap, ctx == null ? null : ctx.mswj);
-        mergeLeaveAuthPersistFieldMap(fieldMap, ctx == null ? null : ctx.wcmswj);
+    /**
+     * 2026-06-10:统一生成海康请假持久化字段集,RC.wcmswj 与独立扩展表共用同一份结构来源。
+     */
+    private static LinkedHashMap<String, String> makeLeaveAuthPersistFieldMap(LeaveAuthSyncCtx ctx,
+                                                                              Map<String, Object> result) {
+        LinkedHashMap<String, String> fieldMap = loadLeaveAuthPersistFieldMap(ctx);
+        if (result == null)
+            return fieldMap;
 
         putLeaveAuthPersistField(fieldMap, "syncTime", makeHkTime(new Timestamp(System.currentTimeMillis())));
         putLeaveAuthPersistField(fieldMap, "mode", rdStr(result.get("mode")));
@@ -1951,7 +2039,26 @@ public class HkLeaveAuthServ extends Serv {
         putLeaveAuthPersistField(fieldMap, "authConfigRateResp", makeRespBrief(result.get("authConfigRateResp")));
         putLeaveAuthPersistField(fieldMap, "authDownloadTaskSearchResp", makeRespBrief(result.get("authDownloadTaskSearchResp")));
         putLeaveAuthPersistField(fieldMap, "authDownloadTaskProgressResp", makeRespBrief(result.get("authDownloadTaskProgressResp")));
+        return fieldMap;
+    }
+
+    /**
+     * 2026-06-10:从 RC.ms / RC.mswj / RC.wcmswj 里提取已落库的海康请假字段,供回填和后续增量覆盖复用。
+     */
+    private static LinkedHashMap<String, String> loadLeaveAuthPersistFieldMap(LeaveAuthSyncCtx ctx) {
+        LinkedHashMap<String, String> fieldMap = new LinkedHashMap<>();
+        mergeLeaveAuthPersistFieldMap(fieldMap, ctx == null ? null : ctx.ms);
+        mergeLeaveAuthPersistFieldMap(fieldMap, ctx == null ? null : ctx.mswj);
+        mergeLeaveAuthPersistFieldMap(fieldMap, ctx == null ? null : ctx.wcmswj);
+        return fieldMap;
+    }
 
+    /**
+     * 2026-06-10:把持久化字段集合重新组装为 RC.wcmswj 文本,保证 RC 与扩展表的来源完全一致。
+     */
+    private static String makeLeaveAuthPersistText(Map<String, String> fieldMap) {
+        if (fieldMap == null || fieldMap.isEmpty())
+            return null;
         List<String> partList = new ArrayList<>();
         for (Map.Entry<String, String> entry : fieldMap.entrySet())
             appendLeaveAuthPersistField(partList, entry.getKey(), entry.getValue());
@@ -2026,6 +2133,166 @@ public class HkLeaveAuthServ extends Serv {
         fieldMap.put(fieldName, value);
     }
 
+    /**
+     * 2026-06-10:RC 摘要写完后顺手同步扩展表;若扩展表尚未建好,则只保留 RC 兼容摘要,不阻断主链路。
+     */
+    private static void syncLeaveAuthExtSnapshotQuietly(Db gdba,
+                                                        LeaveAuthSyncCtx ctx,
+                                                        Map<String, String> fieldMap,
+                                                        String snapshotText) {
+        if (gdba == null || ctx == null || fieldMap == null || fieldMap.isEmpty())
+            return;
+        try {
+            if (!ifLeaveAuthExtTableReady(gdba))
+                return;
+            upsertLeaveAuthExtRow(gdba, ctx, fieldMap, snapshotText);
+        } catch (Exception e) {
+            log4j.warn("HkLeaveAuthServ.syncLeaveAuthExtSnapshotQuietly() 扩展表同步失败,rcid={}", ctx.rcid, e);
+        }
+    }
+
+    /**
+     * 2026-06-10:探测海康请假扩展表是否已建,支持代码先部署、DDL 后执行的灰度顺序。
+     */
+    private static boolean ifLeaveAuthExtTableReady(Db gdba) {
+        if (gdba == null)
+            return false;
+        try {
+            SqlCmd sqlCmd = new SqlCmd("select count(*) rowcnt from user_tables where table_name=:tableName");
+            sqlCmd.wrStrParm("tableName", HK_LEAVE_AUTH_EXT_TAB);
+            gdba.doSelByC(sqlCmd);
+            return gdba.rowNum > 0 && gdba.rdIntCol("rowcnt") > 0;
+        } catch (Exception e) {
+            log4j.warn("HkLeaveAuthServ.ifLeaveAuthExtTableReady() 检测扩展表异常", e);
+            return false;
+        }
+    }
+
+    /**
+     * 2026-06-10:把海康请假关键状态结构化 upsert 到 RCHKLA,后续查询优先走这张表而不是全文 like。
+     */
+    private static void upsertLeaveAuthExtRow(Db gdba,
+                                              LeaveAuthSyncCtx ctx,
+                                              Map<String, String> fieldMap,
+                                              String snapshotText) throws Exception {
+        if (gdba == null || ctx == null || ctx.rcid <= 0 || fieldMap == null || fieldMap.isEmpty())
+            return;
+
+        String sql = "merge into RCHKLA t using (select"
+                + " :rcid rcid,:syncMode sync_mode,:syncTime sync_time,:syncOk sync_ok,:syncMsg sync_msg,"
+                + " :personId person_id,:resourceKeys resource_keys,:resourceCount resource_count,"
+                + " :platformConfigConfirmed platform_config_confirmed,:platformConfirmSource platform_confirm_source,"
+                + " :configSearchMatched config_search_matched,:expectedConfigCount expected_config_count,"
+                + " :matchedConfigCount matched_config_count,:configTaskId config_task_id,"
+                + " :deleteTime delete_time,:deleteMode delete_mode,:deleteConfirmed delete_confirmed,"
+                + " :deleteConfirmSource delete_confirm_source,:deleteTaskAccepted delete_task_accepted,"
+                + " :deleteTaskId delete_task_id,:deleteSkipReason delete_skip_reason,"
+                + " :downloadTaskId download_task_id,:downloadTaskSource download_task_source,"
+                + " :downloadResultConfirmed download_result_confirmed,"
+                + " :downloadCallbackReceived download_callback_received,:callbackTaskId callback_task_id,"
+                + " :callbackRecvTime callback_recv_time,:wcmswjSnapshot wcmswj_snapshot,:updatedAt updated_at"
+                + " from dual) s on (t.RCID=s.RCID)"
+                + " when matched then update set"
+                + " t.SYNC_MODE=s.sync_mode,t.SYNC_TIME=s.sync_time,t.SYNC_OK=s.sync_ok,t.SYNC_MSG=s.sync_msg,"
+                + " t.PERSON_ID=s.person_id,t.RESOURCE_KEYS=s.resource_keys,t.RESOURCE_COUNT=s.resource_count,"
+                + " t.PLATFORM_CONFIG_CONFIRMED=s.platform_config_confirmed,"
+                + " t.PLATFORM_CONFIRM_SOURCE=s.platform_confirm_source,"
+                + " t.CONFIG_SEARCH_MATCHED=s.config_search_matched,"
+                + " t.EXPECTED_CONFIG_COUNT=s.expected_config_count,"
+                + " t.MATCHED_CONFIG_COUNT=s.matched_config_count,t.CONFIG_TASK_ID=s.config_task_id,"
+                + " t.DELETE_TIME=s.delete_time,t.DELETE_MODE=s.delete_mode,t.DELETE_CONFIRMED=s.delete_confirmed,"
+                + " t.DELETE_CONFIRM_SOURCE=s.delete_confirm_source,t.DELETE_TASK_ACCEPTED=s.delete_task_accepted,"
+                + " t.DELETE_TASK_ID=s.delete_task_id,t.DELETE_SKIP_REASON=s.delete_skip_reason,"
+                + " t.DOWNLOAD_TASK_ID=s.download_task_id,t.DOWNLOAD_TASK_SOURCE=s.download_task_source,"
+                + " t.DOWNLOAD_RESULT_CONFIRMED=s.download_result_confirmed,"
+                + " t.DOWNLOAD_CALLBACK_RECEIVED=s.download_callback_received,"
+                + " t.CALLBACK_TASK_ID=s.callback_task_id,t.CALLBACK_RECV_TIME=s.callback_recv_time,"
+                + " t.WCMSWJ_SNAPSHOT=s.wcmswj_snapshot,t.UPDATED_AT=s.updated_at"
+                + " when not matched then insert"
+                + " (RCID,SYNC_MODE,SYNC_TIME,SYNC_OK,SYNC_MSG,PERSON_ID,RESOURCE_KEYS,RESOURCE_COUNT,"
+                + " PLATFORM_CONFIG_CONFIRMED,PLATFORM_CONFIRM_SOURCE,CONFIG_SEARCH_MATCHED,"
+                + " EXPECTED_CONFIG_COUNT,MATCHED_CONFIG_COUNT,CONFIG_TASK_ID,DELETE_TIME,DELETE_MODE,"
+                + " DELETE_CONFIRMED,DELETE_CONFIRM_SOURCE,DELETE_TASK_ACCEPTED,DELETE_TASK_ID,DELETE_SKIP_REASON,"
+                + " DOWNLOAD_TASK_ID,DOWNLOAD_TASK_SOURCE,DOWNLOAD_RESULT_CONFIRMED,DOWNLOAD_CALLBACK_RECEIVED,"
+                + " CALLBACK_TASK_ID,CALLBACK_RECV_TIME,WCMSWJ_SNAPSHOT,UPDATED_AT)"
+                + " values"
+                + " (s.rcid,s.sync_mode,s.sync_time,s.sync_ok,s.sync_msg,s.person_id,s.resource_keys,s.resource_count,"
+                + " s.platform_config_confirmed,s.platform_confirm_source,s.config_search_matched,"
+                + " s.expected_config_count,s.matched_config_count,s.config_task_id,s.delete_time,s.delete_mode,"
+                + " s.delete_confirmed,s.delete_confirm_source,s.delete_task_accepted,s.delete_task_id,s.delete_skip_reason,"
+                + " s.download_task_id,s.download_task_source,s.download_result_confirmed,s.download_callback_received,"
+                + " s.callback_task_id,s.callback_recv_time,s.wcmswj_snapshot,s.updated_at)";
+        SqlCmd sqlCmd = new SqlCmd(sql);
+        sqlCmd.wrLongParm("rcid", ctx.rcid);
+        sqlCmd.wrStrParm("syncMode", fieldMap.get("mode"));
+        sqlCmd.wrTimeParm("syncTime", rdLeaveAuthPersistTime(fieldMap.get("syncTime")));
+        sqlCmd.wrIntParm("syncOk", rdLeaveAuthPersistBool(fieldMap.get("ok")));
+        sqlCmd.wrStrParm("syncMsg", fieldMap.get("msg"));
+        sqlCmd.wrStrParm("personId", fieldMap.get("personId"));
+        sqlCmd.wrStrParm("resourceKeys", fieldMap.get("resourceKeys"));
+        sqlCmd.wrIntParm("resourceCount", rdLeaveAuthPersistInt(fieldMap.get("resourceCount")));
+        sqlCmd.wrIntParm("platformConfigConfirmed", rdLeaveAuthPersistBool(fieldMap.get("platformConfigConfirmed")));
+        sqlCmd.wrStrParm("platformConfirmSource", fieldMap.get("platformConfirmSource"));
+        sqlCmd.wrIntParm("configSearchMatched", rdLeaveAuthPersistBool(fieldMap.get("configSearchMatched")));
+        sqlCmd.wrIntParm("expectedConfigCount", rdLeaveAuthPersistInt(fieldMap.get("expectedConfigCount")));
+        sqlCmd.wrIntParm("matchedConfigCount", rdLeaveAuthPersistInt(fieldMap.get("matchedConfigCount")));
+        sqlCmd.wrStrParm("configTaskId", fieldMap.get("configTaskId"));
+        sqlCmd.wrTimeParm("deleteTime", rdLeaveAuthPersistTime(fieldMap.get("deleteTime")));
+        sqlCmd.wrStrParm("deleteMode", fieldMap.get("deleteMode"));
+        sqlCmd.wrIntParm("deleteConfirmed", rdLeaveAuthPersistBool(fieldMap.get("deleteConfirmed")));
+        sqlCmd.wrStrParm("deleteConfirmSource", fieldMap.get("deleteConfirmSource"));
+        sqlCmd.wrIntParm("deleteTaskAccepted", rdLeaveAuthPersistBool(fieldMap.get("deleteTaskAccepted")));
+        sqlCmd.wrStrParm("deleteTaskId", fieldMap.get("deleteTaskId"));
+        sqlCmd.wrStrParm("deleteSkipReason", fieldMap.get("deleteSkipReason"));
+        sqlCmd.wrStrParm("downloadTaskId", fieldMap.get("downloadTaskId"));
+        sqlCmd.wrStrParm("downloadTaskSource", fieldMap.get("downloadTaskSource"));
+        sqlCmd.wrIntParm("downloadResultConfirmed", rdLeaveAuthPersistBool(fieldMap.get("downloadResultConfirmed")));
+        sqlCmd.wrIntParm("downloadCallbackReceived", rdLeaveAuthPersistBool(fieldMap.get("downloadCallbackReceived")));
+        sqlCmd.wrStrParm("callbackTaskId", fieldMap.get("callbackTaskId"));
+        sqlCmd.wrTimeParm("callbackRecvTime", rdLeaveAuthPersistTime(fieldMap.get("callbackRecvTime")));
+        sqlCmd.wrStrParm("wcmswjSnapshot", StringUtils.defaultIfBlank(snapshotText, ctx.wcmswj));
+        sqlCmd.wrTimeParm("updatedAt", new Timestamp(System.currentTimeMillis()));
+        gdba.doModByC(sqlCmd);
+    }
+
+    /**
+     * 2026-06-10:解析 RC 摘要里保存的海康时间文本,统一转为数据库时间字段。
+     */
+    private static Timestamp rdLeaveAuthPersistTime(String text) {
+        String value = rdStr(text);
+        if (StringUtils.isBlank(value))
+            return null;
+        try {
+            return Timestamp.from(OffsetDateTime.parse(value).toInstant());
+        } catch (Exception ignored) {
+            return null;
+        }
+    }
+
+    /**
+     * 2026-06-10:解析 RC 摘要里的布尔标记,扩展表统一按 1/0 落库。
+     */
+    private static Integer rdLeaveAuthPersistBool(String text) {
+        String value = rdStr(text);
+        if (StringUtils.isBlank(value))
+            return null;
+        return rdBoolLike(value) ? 1 : 0;
+    }
+
+    /**
+     * 2026-06-10:解析 RC 摘要里的整数字段,非法值回退为 null,避免把脏文本写成 0。
+     */
+    private static Integer rdLeaveAuthPersistInt(String text) {
+        String value = rdStr(text);
+        if (StringUtils.isBlank(value))
+            return null;
+        try {
+            return Integer.valueOf(value);
+        } catch (Exception ignored) {
+            return null;
+        }
+    }
+
     /**
      * 2026-06-01:把异常压成一行,既能定位错误类型,也不会把 RC 字段撑得过长。
      */
@@ -2415,6 +2682,9 @@ public class HkLeaveAuthServ extends Serv {
     private static LeaveAuthSyncCtx selLeaveAuthSyncCtxByTaskId(Db gdba, String taskId) throws Exception {
         if (gdba == null || StringUtils.isBlank(taskId))
             return null;
+        LeaveAuthSyncCtx ctx = selLeaveAuthSyncCtxByTaskIdFromExt(gdba, taskId);
+        if (ctx != null)
+            return ctx;
         String sql = "select rc.RCID rcid,rc.BJID bjid,rc.FZRYID ryid,rc.RCLBM rclbm,rc.KSSJ kssj,rc.JSSJ jssj,"
                 + " rc.MS ms,rc.MSWJ mswj,rc.WCMSWJ wcmswj,ry.XM xm,ry.RYH ryh"
                 + " from RC rc"
@@ -2426,19 +2696,34 @@ public class HkLeaveAuthServ extends Serv {
         List<Map<String, Object>> rowList = gdba.doSelMapListByC(sqlCmd);
         if (rowList == null || rowList.isEmpty())
             return null;
-        Map<String, Object> row = rowList.get(0);
-        return new LeaveAuthSyncCtx(
-                rdLong(row.get("rcid")),
-                rdLong(row.get("bjid")),
-                rdLong(row.get("ryid")),
-                rdInt(row.get("rclbm")),
-                (Timestamp) row.get("kssj"),
-                (Timestamp) row.get("jssj"),
-                rdStr(row.get("xm")),
-                rdStr(row.get("ryh")),
-                rdStr(row.get("ms")),
-                rdStr(row.get("mswj")),
-                rdStr(row.get("wcmswj")));
+        return buildLeaveAuthSyncCtx(rowList.get(0));
+    }
+
+    /**
+     * 2026-06-10:优先按扩展表里的结构化 taskId 精确回查,避免全表 like。
+     */
+    private static LeaveAuthSyncCtx selLeaveAuthSyncCtxByTaskIdFromExt(Db gdba, String taskId) throws Exception {
+        if (gdba == null || StringUtils.isBlank(taskId) || !ifLeaveAuthExtTableReady(gdba))
+            return null;
+        String sql = "select rc.RCID rcid,rc.BJID bjid,rc.FZRYID ryid,rc.RCLBM rclbm,rc.KSSJ kssj,rc.JSSJ jssj,"
+                + " rc.MS ms,rc.MSWJ mswj,rc.WCMSWJ wcmswj,ry.XM xm,ry.RYH ryh"
+                + " from RCHKLA ext"
+                + " join RC rc on rc.RCID=ext.RCID"
+                + " left join RY ry on ry.RYID=rc.FZRYID"
+                + " where ext.CONFIG_TASK_ID=:configTaskId"
+                + " or ext.DELETE_TASK_ID=:deleteTaskId"
+                + " or ext.DOWNLOAD_TASK_ID=:downloadTaskId"
+                + " or ext.CALLBACK_TASK_ID=:callbackTaskId"
+                + " order by nvl(ext.UPDATED_AT,ext.SYNC_TIME) desc nulls last,rc.RCID desc";
+        SqlCmd sqlCmd = new SqlCmd(sql);
+        sqlCmd.wrStrParm("configTaskId", taskId);
+        sqlCmd.wrStrParm("deleteTaskId", taskId);
+        sqlCmd.wrStrParm("downloadTaskId", taskId);
+        sqlCmd.wrStrParm("callbackTaskId", taskId);
+        List<Map<String, Object>> rowList = gdba.doSelMapListByC(sqlCmd);
+        if (rowList == null || rowList.isEmpty())
+            return null;
+        return buildLeaveAuthSyncCtx(rowList.get(0));
     }
 
     /**
@@ -2476,6 +2761,9 @@ public class HkLeaveAuthServ extends Serv {
     private static List<LeaveAuthSyncCtx> selRecentLeaveAuthSyncCtxList(Db gdba, int limit) throws Exception {
         if (gdba == null)
             return List.of();
+        List<LeaveAuthSyncCtx> extCtxList = selRecentLeaveAuthSyncCtxListFromExt(gdba, limit);
+        if (!extCtxList.isEmpty())
+            return extCtxList;
         String sql = "select * from ("
                 + " select rc.RCID rcid,rc.BJID bjid,rc.FZRYID ryid,rc.RCLBM rclbm,rc.KSSJ kssj,rc.JSSJ jssj,"
                 + " rc.MS ms,rc.MSWJ mswj,rc.WCMSWJ wcmswj,ry.XM xm,ry.RYH ryh"
@@ -2491,20 +2779,8 @@ public class HkLeaveAuthServ extends Serv {
             return List.of();
 
         List<LeaveAuthSyncCtx> ctxList = new ArrayList<>();
-        for (Map<String, Object> row : rowList) {
-            ctxList.add(new LeaveAuthSyncCtx(
-                    rdLong(row.get("rcid")),
-                    rdLong(row.get("bjid")),
-                    rdLong(row.get("ryid")),
-                    rdInt(row.get("rclbm")),
-                    (Timestamp) row.get("kssj"),
-                    (Timestamp) row.get("jssj"),
-                    rdStr(row.get("xm")),
-                    rdStr(row.get("ryh")),
-                    rdStr(row.get("ms")),
-                    rdStr(row.get("mswj")),
-                    rdStr(row.get("wcmswj"))));
-        }
+        for (Map<String, Object> row : rowList)
+            ctxList.add(buildLeaveAuthSyncCtx(row));
         return ctxList;
     }
 
@@ -2514,6 +2790,9 @@ public class HkLeaveAuthServ extends Serv {
     private static List<LeaveAuthSyncCtx> selExpiredPlatformConfigDeleteCtxList(Db gdba, int limit) throws Exception {
         if (gdba == null)
             return List.of();
+        List<LeaveAuthSyncCtx> extCtxList = selExpiredPlatformConfigDeleteCtxListFromExt(gdba, limit);
+        if (!extCtxList.isEmpty())
+            return extCtxList;
         String sql = "select * from ("
                 + " select rc.RCID rcid,rc.BJID bjid,rc.FZRYID ryid,rc.RCLBM rclbm,rc.KSSJ kssj,rc.JSSJ jssj,"
                 + " rc.MS ms,rc.MSWJ mswj,rc.WCMSWJ wcmswj,ry.XM xm,ry.RYH ryh"
@@ -2532,20 +2811,112 @@ public class HkLeaveAuthServ extends Serv {
             return List.of();
 
         List<LeaveAuthSyncCtx> ctxList = new ArrayList<>();
-        for (Map<String, Object> row : rowList) {
-            ctxList.add(new LeaveAuthSyncCtx(
-                    rdLong(row.get("rcid")),
-                    rdLong(row.get("bjid")),
-                    rdLong(row.get("ryid")),
-                    rdInt(row.get("rclbm")),
-                    (Timestamp) row.get("kssj"),
-                    (Timestamp) row.get("jssj"),
-                    rdStr(row.get("xm")),
-                    rdStr(row.get("ryh")),
-                    rdStr(row.get("ms")),
-                    rdStr(row.get("mswj")),
-                    rdStr(row.get("wcmswj"))));
+        for (Map<String, Object> row : rowList)
+            ctxList.add(buildLeaveAuthSyncCtx(row));
+        return ctxList;
+    }
+
+    /**
+     * 2026-06-10:最近执行记录优先读扩展表,兼容 delete/recycle 后 mode 被覆盖的场景。
+     */
+    private static List<LeaveAuthSyncCtx> selRecentLeaveAuthSyncCtxListFromExt(Db gdba, int limit) throws Exception {
+        if (gdba == null || !ifLeaveAuthExtTableReady(gdba))
+            return List.of();
+        String sql = "select * from ("
+                + " select rc.RCID rcid,rc.BJID bjid,rc.FZRYID ryid,rc.RCLBM rclbm,rc.KSSJ kssj,rc.JSSJ jssj,"
+                + " rc.MS ms,rc.MSWJ mswj,rc.WCMSWJ wcmswj,ry.XM xm,ry.RYH ryh"
+                + " from RCHKLA ext"
+                + " join RC rc on rc.RCID=ext.RCID"
+                + " left join RY ry on ry.RYID=rc.FZRYID"
+                + " where nvl(ext.PLATFORM_CONFIG_CONFIRMED,0)=1"
+                + " or nvl(ext.CONFIG_SEARCH_MATCHED,0)=1"
+                + " or ext.CONFIG_TASK_ID is not null"
+                + " or ext.DOWNLOAD_TASK_ID is not null"
+                + " order by nvl(ext.SYNC_TIME,rc.RJSJ) desc nulls last,rc.RCID desc"
+                + " ) where rownum<=:limit";
+        SqlCmd sqlCmd = new SqlCmd(sql);
+        sqlCmd.wrIntParm("limit", Math.max(1, limit));
+        List<Map<String, Object>> rowList = gdba.doSelMapListByC(sqlCmd);
+        if (rowList == null || rowList.isEmpty())
+            return List.of();
+        List<LeaveAuthSyncCtx> ctxList = new ArrayList<>();
+        for (Map<String, Object> row : rowList)
+            ctxList.add(buildLeaveAuthSyncCtx(row));
+        return ctxList;
+    }
+
+    /**
+     * 2026-06-10:到期回收候选优先读扩展表,明确按“已确认下发、未确认删除”筛选。
+     */
+    private static List<LeaveAuthSyncCtx> selExpiredPlatformConfigDeleteCtxListFromExt(Db gdba, int limit) throws Exception {
+        if (gdba == null || !ifLeaveAuthExtTableReady(gdba))
+            return List.of();
+        String sql = "select * from ("
+                + " select rc.RCID rcid,rc.BJID bjid,rc.FZRYID ryid,rc.RCLBM rclbm,rc.KSSJ kssj,rc.JSSJ jssj,"
+                + " rc.MS ms,rc.MSWJ mswj,rc.WCMSWJ wcmswj,ry.XM xm,ry.RYH ryh"
+                + " from RCHKLA ext"
+                + " join RC rc on rc.RCID=ext.RCID"
+                + " left join RY ry on ry.RYID=rc.FZRYID"
+                + " where rc.JSSJ is not null"
+                + " and rc.JSSJ<=sysdate"
+                + " and (nvl(ext.PLATFORM_CONFIG_CONFIRMED,0)=1"
+                + " or nvl(ext.CONFIG_SEARCH_MATCHED,0)=1"
+                + " or ext.CONFIG_TASK_ID is not null)"
+                + " and nvl(ext.DELETE_CONFIRMED,0)=0"
+                + " order by rc.JSSJ asc,rc.RCID asc"
+                + " ) where rownum<=:limit";
+        SqlCmd sqlCmd = new SqlCmd(sql);
+        sqlCmd.wrIntParm("limit", Math.max(1, limit));
+        List<Map<String, Object>> rowList = gdba.doSelMapListByC(sqlCmd);
+        if (rowList == null || rowList.isEmpty())
+            return List.of();
+        List<LeaveAuthSyncCtx> ctxList = new ArrayList<>();
+        for (Map<String, Object> row : rowList)
+            ctxList.add(buildLeaveAuthSyncCtx(row));
+        return ctxList;
+    }
+
+    /**
+     * 2026-06-10:为扩展表回填挑出历史海康摘要记录;指定 rcid 时只处理单条,未指定时按最近记录批量处理。
+     */
+    private static List<LeaveAuthSyncCtx> selLeaveAuthSyncCtxListForBackfill(Db gdba, long rcid, int limit) throws Exception {
+        if (gdba == null)
+            return List.of();
+        String baseSql = " select rc.RCID rcid,rc.BJID bjid,rc.FZRYID ryid,rc.RCLBM rclbm,rc.KSSJ kssj,rc.JSSJ jssj,"
+                + " rc.MS ms,rc.MSWJ mswj,rc.WCMSWJ wcmswj,ry.XM xm,ry.RYH ryh"
+                + " from RC rc"
+                + " left join RY ry on ry.RYID=rc.FZRYID";
+        SqlCmd sqlCmd;
+        if (rcid > 0) {
+            sqlCmd = new SqlCmd(baseSql + " where rc.RCID=:rcid");
+            sqlCmd.wrLongParm("rcid", rcid);
+        } else {
+            String sql = "select * from (" + baseSql
+                    + " where nvl(rc.WCMSWJ,' ') like '%configTaskId=%'"
+                    + " or nvl(rc.WCMSWJ,' ') like '%downloadTaskId=%'"
+                    + " or nvl(rc.WCMSWJ,' ') like '%deleteTaskId=%'"
+                    + " or nvl(rc.WCMSWJ,' ') like '%personId=%'"
+                    + " or nvl(rc.WCMSWJ,' ') like '%platformConfigConfirmed=%'"
+                    + " or nvl(rc.MSWJ,' ') like '%configTaskId=%'"
+                    + " or nvl(rc.MSWJ,' ') like '%downloadTaskId=%'"
+                    + " or nvl(rc.MSWJ,' ') like '%deleteTaskId=%'"
+                    + " or nvl(rc.MSWJ,' ') like '%personId=%'"
+                    + " or nvl(rc.MS,' ') like '%configTaskId=%'"
+                    + " or nvl(rc.MS,' ') like '%downloadTaskId=%'"
+                    + " or nvl(rc.MS,' ') like '%deleteTaskId=%'"
+                    + " or nvl(rc.MS,' ') like '%personId=%'"
+                    + " order by rc.RCID desc"
+                    + " ) where rownum<=:limit";
+            sqlCmd = new SqlCmd(sql);
+            sqlCmd.wrIntParm("limit", Math.max(1, limit));
         }
+
+        List<Map<String, Object>> rowList = gdba.doSelMapListByC(sqlCmd);
+        if (rowList == null || rowList.isEmpty())
+            return List.of();
+        List<LeaveAuthSyncCtx> ctxList = new ArrayList<>();
+        for (Map<String, Object> row : rowList)
+            ctxList.add(buildLeaveAuthSyncCtx(row));
         return ctxList;
     }
 

+ 1 - 0
web/cfg/biz/kq/hkkq.serv.xml

@@ -19,6 +19,7 @@
 	<serv name="hkkq_leave_auth_execute" desc="海康请假权限真实下发" clazz="biz.kq.HkLeaveAuthServ" func="executeLeaveAuthSync" auth="true"/>
 	<serv name="hkkq_leave_auth_delete" desc="海康请假权限删除" clazz="biz.kq.HkLeaveAuthServ" func="executeLeaveAuthDelete" auth="true"/>
 	<serv name="hkkq_leave_auth_result" desc="海康请假权限下发结果查询" clazz="biz.kq.HkLeaveAuthServ" func="viewLeaveAuthSyncResult" auth="true"/>
+	<serv name="hkkq_leave_auth_backfill_ext" desc="海康请假权限扩展表回填" clazz="biz.kq.HkLeaveAuthServ" func="backfillLeaveAuthExt" auth="true"/>
 	<serv name="hkkq_leave_auth_recycle" desc="海康请假权限到期回收" clazz="biz.kq.HkLeaveAuthServ" func="recycleExpiredLeaveAuth" pub="true"/>
 	<serv name="hkkq_leave_auth_download_push" desc="海康请假权限下载回调" clazz="biz.kq.HkLeaveAuthServ" func="recvLeaveAuthDownloadPush" pub="true"/>
 	<serv name="hkkq_event_push" desc="海康事件订阅回调" clazz="biz.kq.HkKqServ" func="recvHkEventPush" pub="true"/>