|
|
@@ -113,6 +113,73 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 2026-06-12:销假把结束时间改短后,需要按“旧时间窗”先回收海康临时权限,再按新时间窗决定 pending 或立即重下发。
|
|
|
+ */
|
|
|
+ static void syncLeaveAuthAfterEndTimeChange(long rcid, Timestamp oldJssj, Timestamp newJssj) {
|
|
|
+ if (rcid <= 0 || oldJssj == null || newJssj == null || !newJssj.before(oldJssj))
|
|
|
+ return;
|
|
|
+ if (!rdBoolCfg(CFG_ENABLED, "HK_LEAVE_AUTH_ENABLED", false))
|
|
|
+ return;
|
|
|
+
|
|
|
+ try {
|
|
|
+ Map<String, Object> deleteResult;
|
|
|
+ try (Db gdba = Db.makeConn()) {
|
|
|
+ LeaveAuthSyncCtx ctx = selLeaveAuthSyncCtx(gdba, rcid);
|
|
|
+ if (ctx == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ Map<String, Object> overrideParm = new LinkedHashMap<>();
|
|
|
+ overrideParm.put("matchBegTime", ctx.kssj);
|
|
|
+ overrideParm.put("matchEndTime", oldJssj);
|
|
|
+ overrideParm.put("deleteMode", "endTimeChange");
|
|
|
+ overrideParm.put("deleteTriggerReason", "leaveEndTimeChanged");
|
|
|
+ deleteResult = executePlatformConfigDeleteResult(gdba, ctx, overrideParm, true, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ log4j.info("HkLeaveAuthServ.syncLeaveAuthAfterEndTimeChange() 旧时间窗回收结果:rcid={}, oldJssj={}, newJssj={}, deleteConfirmed={}, ok={}, msg={}",
|
|
|
+ rcid, oldJssj, newJssj, deleteResult.get("deleteConfirmed"), deleteResult.get("ok"), deleteResult.get("msg"));
|
|
|
+ if (!rdBoolLike(deleteResult.get("deleteConfirmed"))) {
|
|
|
+ log4j.warn("HkLeaveAuthServ.syncLeaveAuthAfterEndTimeChange() 未能确认旧时间窗已回收,停止后续重同步,rcid={}", rcid);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Timestamp now = new Timestamp(System.currentTimeMillis());
|
|
|
+ LeaveAuthSyncCtx freshCtx;
|
|
|
+ try (Db gdba = Db.makeConn()) {
|
|
|
+ freshCtx = selLeaveAuthSyncCtx(gdba, rcid);
|
|
|
+ if (freshCtx == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (!ifLeaveEnded(freshCtx.jssj, now)) {
|
|
|
+ String resetMsg = ifLeaveStarted(freshCtx.kssj, now)
|
|
|
+ ? "销假已更新结束时间,准备按新时间窗重新同步海康临时权限。"
|
|
|
+ : "销假已更新结束时间,待临近开始时再同步海康临时权限。";
|
|
|
+ resetLeaveAuthPersistStateForResync(gdba, freshCtx, resetMsg);
|
|
|
+ gdba.commit();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (freshCtx == null || ifLeaveEnded(freshCtx.jssj, now))
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (ifLeaveStarted(freshCtx.kssj, now)) {
|
|
|
+ Map<String, Object> addResult = buildLeaveAuthSyncResult(rcid, true, Map.of());
|
|
|
+ log4j.info("HkLeaveAuthServ.syncLeaveAuthAfterEndTimeChange() 已按新时间窗立即重下发:rcid={}, ok={}, msg={}",
|
|
|
+ rcid, addResult.get("ok"), addResult.get("msg"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> pendingResult = registerPendingLeaveAuthAfterCommit(rcid);
|
|
|
+ log4j.info("HkLeaveAuthServ.syncLeaveAuthAfterEndTimeChange() 已重新登记 pending:rcid={}, ok={}, msg={}, syncStage={}",
|
|
|
+ rcid, pendingResult.get("ok"), pendingResult.get("msg"), pendingResult.get("syncStage"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("HkLeaveAuthServ.syncLeaveAuthAfterEndTimeChange() 异常,rcid={}, oldJssj={}, newJssj={}",
|
|
|
+ rcid, oldJssj, newJssj, e);
|
|
|
+ persistUnexpectedSyncError(rcid, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 2026-05-26:请假权限预览入口,只回显请求和海康组装结果,不影响现网写入。
|
|
|
*/
|
|
|
@@ -572,6 +639,77 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 2026-06-12:销假重同步前重置 pending/confirmed/delete 相关持久化状态,避免沿用旧时间窗的结果。
|
|
|
+ */
|
|
|
+ private static void resetLeaveAuthPersistStateForResync(Db gdba,
|
|
|
+ LeaveAuthSyncCtx ctx,
|
|
|
+ String msg) throws Exception {
|
|
|
+ if (gdba == null || ctx == null || ctx.rcid <= 0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ LinkedHashMap<String, String> fieldMap = loadLeaveAuthPersistFieldMap(ctx);
|
|
|
+ if (fieldMap.isEmpty())
|
|
|
+ return;
|
|
|
+
|
|
|
+ Timestamp now = new Timestamp(System.currentTimeMillis());
|
|
|
+ fieldMap.put("syncTime", makeHkTime(now));
|
|
|
+ fieldMap.put("mode", "pendingRegister");
|
|
|
+ fieldMap.put("ok", "true");
|
|
|
+ fieldMap.put("msg", StringUtils.defaultIfBlank(msg, "请假时间窗已更新,待重新同步海康临时权限。"));
|
|
|
+ fieldMap.put("platformConfigConfirmed", "false");
|
|
|
+ fieldMap.put("configSearchMatched", "false");
|
|
|
+ fieldMap.put("expectedConfigCount", "");
|
|
|
+ fieldMap.put("matchedConfigCount", "");
|
|
|
+ fieldMap.put("configTaskId", "");
|
|
|
+ fieldMap.put("platformConfirmSource", "");
|
|
|
+ fieldMap.put("deleteConfirmed", "false");
|
|
|
+ fieldMap.put("deleteTime", "");
|
|
|
+ fieldMap.put("deleteMode", "");
|
|
|
+ fieldMap.put("deleteConfirmSource", "");
|
|
|
+ fieldMap.put("deleteTaskAccepted", "");
|
|
|
+ fieldMap.put("deleteTaskId", "");
|
|
|
+ fieldMap.put("deleteSkipReason", "");
|
|
|
+ fieldMap.put("deleteSearchTotalBefore", "");
|
|
|
+ fieldMap.put("deleteSearchMatchedBefore", "");
|
|
|
+ fieldMap.put("deleteSearchForeignBefore", "");
|
|
|
+ fieldMap.put("deleteSearchTotalAfter", "");
|
|
|
+ fieldMap.put("deleteSearchMatchedAfter", "");
|
|
|
+ fieldMap.put("deleteSearchForeignAfter", "");
|
|
|
+ fieldMap.put("syncStage", "pending");
|
|
|
+ fieldMap.put("retryCount", "0");
|
|
|
+ fieldMap.put("nextRetryTime", "");
|
|
|
+ fieldMap.put("firstAcceptTime", "");
|
|
|
+ fieldMap.put("platformConfirmTime", "");
|
|
|
+ fieldMap.put("lastError", "");
|
|
|
+ fieldMap.put("totalCostMs", "");
|
|
|
+ fieldMap.put("downloadTaskId", "");
|
|
|
+ fieldMap.put("downloadTaskSource", "");
|
|
|
+ fieldMap.put("downloadResultConfirmed", "");
|
|
|
+ fieldMap.put("downloadCallbackReceived", "");
|
|
|
+ fieldMap.put("callbackTaskId", "");
|
|
|
+ fieldMap.put("callbackRecvTime", "");
|
|
|
+ fieldMap.put("authSyncResp", "");
|
|
|
+ fieldMap.put("authConfigSearchResp", "");
|
|
|
+ fieldMap.put("authConfigDeleteResp", "");
|
|
|
+ fieldMap.put("authConfigDeleteRateResp", "");
|
|
|
+ fieldMap.put("authConfigDeleteSearchBeforeResp", "");
|
|
|
+ fieldMap.put("authConfigDeleteSearchAfterResp", "");
|
|
|
+ fieldMap.put("authConfigRateResp", "");
|
|
|
+
|
|
|
+ normalizeLeaveAuthPersistFieldMap(fieldMap);
|
|
|
+ String rawPersistText = makeLeaveAuthPersistText(fieldMap);
|
|
|
+ String persistText = fitWcmswjText(rawPersistText);
|
|
|
+ if (StringUtils.isBlank(persistText))
|
|
|
+ return;
|
|
|
+
|
|
|
+ RcPo rcPo = new RcPo();
|
|
|
+ rcPo.setRcid(ctx.rcid);
|
|
|
+ rcPo.setWcmswj(persistText);
|
|
|
+ gdba.doUpdPo(rcPo, Set.of("wcmswj"));
|
|
|
+ syncLeaveAuthExtSnapshotQuietly(gdba, ctx, fieldMap, rawPersistText);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 2026-06-10:批量回收已结束请假的临时权限,给定时器复用。
|
|
|
*/
|
|
|
@@ -894,6 +1032,20 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
result.put("deleteApiPath", "/artemis/api/acps/v1/auth_config/delete");
|
|
|
result.put("rateApiPath", "/artemis/api/acps/v1/auth_config/rate/search");
|
|
|
applyPersistedLeaveAuthSnapshot(ctx, result);
|
|
|
+ Timestamp matchBegTime = rdOverrideTime(overrideParm, "matchBegTime");
|
|
|
+ Timestamp matchEndTime = rdOverrideTime(overrideParm, "matchEndTime");
|
|
|
+ if (matchBegTime == null)
|
|
|
+ matchBegTime = ctx == null ? null : ctx.kssj;
|
|
|
+ if (matchEndTime == null)
|
|
|
+ matchEndTime = ctx == null ? null : ctx.jssj;
|
|
|
+ result.put("deleteMatchBegTime", makeHkTime(matchBegTime));
|
|
|
+ result.put("deleteMatchEndTime", makeHkTime(matchEndTime));
|
|
|
+ String deleteMode = rdStr(overrideParm == null ? null : overrideParm.get("deleteMode"));
|
|
|
+ if (StringUtils.isNotBlank(deleteMode))
|
|
|
+ result.put("deleteMode", deleteMode);
|
|
|
+ String deleteTriggerReason = rdStr(overrideParm == null ? null : overrideParm.get("deleteTriggerReason"));
|
|
|
+ if (StringUtils.isNotBlank(deleteTriggerReason))
|
|
|
+ result.put("deleteTriggerReason", deleteTriggerReason);
|
|
|
|
|
|
if (gdba == null || ctx == null) {
|
|
|
result.put("ok", false);
|
|
|
@@ -902,7 +1054,7 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
}
|
|
|
|
|
|
Timestamp now = new Timestamp(System.currentTimeMillis());
|
|
|
- boolean leaveExpired = ifLeaveEnded(ctx.jssj, now);
|
|
|
+ boolean leaveExpired = ifLeaveEnded(matchEndTime, now);
|
|
|
result.put("leaveExpired", leaveExpired);
|
|
|
if (!forceDelete && !leaveExpired) {
|
|
|
result.put("ok", false);
|
|
|
@@ -991,9 +1143,9 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> matchedBeforeRowList = extAuthConfigMatchedRowList(
|
|
|
- deleteSearchBeforeResp, ctx.kssj, ctx.jssj, resourceInfoList, personId);
|
|
|
+ deleteSearchBeforeResp, matchBegTime, matchEndTime, resourceInfoList, personId);
|
|
|
List<Map<String, Object>> foreignBeforeRowList = extAuthConfigForeignRowList(
|
|
|
- deleteSearchBeforeResp, ctx.kssj, ctx.jssj, resourceInfoList, personId);
|
|
|
+ deleteSearchBeforeResp, matchBegTime, matchEndTime, resourceInfoList, personId);
|
|
|
result.put("deleteSearchTotalBefore", rdAuthConfigTotalCount(deleteSearchBeforeResp));
|
|
|
result.put("deleteSearchMatchedBefore", matchedBeforeRowList.size());
|
|
|
result.put("deleteSearchForeignBefore", foreignBeforeRowList.size());
|
|
|
@@ -1045,7 +1197,7 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
}
|
|
|
|
|
|
Map<String, Object> deleteSearchAfterResp = queryAuthConfigDeleteClearedWithRetry(
|
|
|
- hkConnParm, deleteSearchReq, ctx.kssj, ctx.jssj, resourceInfoList, personId);
|
|
|
+ hkConnParm, deleteSearchReq, matchBegTime, matchEndTime, resourceInfoList, personId);
|
|
|
result.put("authConfigDeleteSearchAfterResp", deleteSearchAfterResp);
|
|
|
if (!isHkRespAccepted(deleteSearchAfterResp)) {
|
|
|
result.put("ok", false);
|
|
|
@@ -1055,9 +1207,9 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> matchedAfterRowList = extAuthConfigMatchedRowList(
|
|
|
- deleteSearchAfterResp, ctx.kssj, ctx.jssj, resourceInfoList, personId);
|
|
|
+ deleteSearchAfterResp, matchBegTime, matchEndTime, resourceInfoList, personId);
|
|
|
List<Map<String, Object>> foreignAfterRowList = extAuthConfigForeignRowList(
|
|
|
- deleteSearchAfterResp, ctx.kssj, ctx.jssj, resourceInfoList, personId);
|
|
|
+ deleteSearchAfterResp, matchBegTime, matchEndTime, resourceInfoList, personId);
|
|
|
result.put("deleteSearchTotalAfter", rdAuthConfigTotalCount(deleteSearchAfterResp));
|
|
|
result.put("deleteSearchMatchedAfter", matchedAfterRowList.size());
|
|
|
result.put("deleteSearchForeignAfter", foreignAfterRowList.size());
|
|
|
@@ -2478,6 +2630,21 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
fieldMap.put(fieldName, value);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 2026-06-12:直接规范化字段集,空字符串统一移除,避免销假重同步时把无效空值继续写回摘要。
|
|
|
+ */
|
|
|
+ private static void normalizeLeaveAuthPersistFieldMap(Map<String, String> fieldMap) {
|
|
|
+ if (fieldMap == null || fieldMap.isEmpty())
|
|
|
+ return;
|
|
|
+ List<String> blankKeyList = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, String> entry : fieldMap.entrySet()) {
|
|
|
+ if (StringUtils.isBlank(entry.getValue()))
|
|
|
+ blankKeyList.add(entry.getKey());
|
|
|
+ }
|
|
|
+ for (String blankKey : blankKeyList)
|
|
|
+ fieldMap.remove(blankKey);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 2026-06-10:RC 摘要写完后顺手同步扩展表;若扩展表尚未建好,则只保留 RC 兼容摘要,不阻断主链路。
|
|
|
*/
|
|
|
@@ -2703,6 +2870,20 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 2026-06-12:删除链路允许调用方临时指定要匹配的海康时间窗,销假改结束时间场景复用。
|
|
|
+ */
|
|
|
+ private static Timestamp rdOverrideTime(Map<String, Object> overrideParm, String fieldName) {
|
|
|
+ if (overrideParm == null || StringUtils.isBlank(fieldName))
|
|
|
+ return null;
|
|
|
+ Object value = overrideParm.get(fieldName);
|
|
|
+ if (value instanceof Timestamp)
|
|
|
+ return (Timestamp) value;
|
|
|
+ if (value instanceof java.util.Date date)
|
|
|
+ return new Timestamp(date.getTime());
|
|
|
+ return rdLeaveAuthPersistTime(rdStr(value));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 2026-06-01:把异常压成一行,既能定位错误类型,也不会把 RC 字段撑得过长。
|
|
|
*/
|
|
|
@@ -2744,6 +2925,16 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
return !leaveEnd.after(baseTime);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 2026-06-12:请假开始后如果销假仍落在当前时间之后,需要立即按新时间窗重下发。
|
|
|
+ */
|
|
|
+ private static boolean ifLeaveStarted(Timestamp leaveBeg, Timestamp now) {
|
|
|
+ if (leaveBeg == null)
|
|
|
+ return false;
|
|
|
+ Timestamp baseTime = now == null ? new Timestamp(System.currentTimeMillis()) : now;
|
|
|
+ return !leaveBeg.after(baseTime);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 2026-05-28:从 RC 备注里提取上次执行时写回的字段值。
|
|
|
*/
|