|
|
@@ -1,6 +1,10 @@
|
|
|
package biz.kq;
|
|
|
|
|
|
import base.po.RcPo;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.JsonElement;
|
|
|
+import com.google.gson.JsonObject;
|
|
|
+import com.google.gson.JsonParser;
|
|
|
import core.co.haikang.HkApiClient;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
@@ -28,6 +32,7 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
|
|
|
private static final Logger log4j = LogManager.getLogger(HkLeaveAuthServ.class);
|
|
|
private static final HkApiClient HK_API_CLIENT = new HkApiClient();
|
|
|
+ private static final Gson GSON = new Gson();
|
|
|
|
|
|
private static final String CFG_ENABLED = "hk.leaveAuth.enabled";
|
|
|
private static final String CFG_EXECUTE = "hk.leaveAuth.execute";
|
|
|
@@ -89,6 +94,14 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
return ServC.SERV_notByA;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 2026-05-27:通用海康原始接口探测入口,便于逐个试海康文档候选接口并回收原始响应分析 templateId。
|
|
|
+ */
|
|
|
+ public String probeHkTemplateApi() {
|
|
|
+ super.wrJsonByResp(probeHkTemplateApiResult());
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 2026-05-26:手工真实下发入口,只在明确传参时执行海康写操作。
|
|
|
*/
|
|
|
@@ -262,6 +275,71 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 2026-05-27:透传海康接口路径和请求体,返回原始请求与响应,作为 templateId 联调诊断口。
|
|
|
+ */
|
|
|
+ private Map<String, Object> probeHkTemplateApiResult() {
|
|
|
+ Map<String, Object> result = new LinkedHashMap<>();
|
|
|
+ String apiPath = rdReqStrParm("apiPath", "path");
|
|
|
+ String reqBodyStr = rdReqStrParm("reqBody", "body", "json");
|
|
|
+ long rcid = rdReqLongParm("rcid");
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("apiPath", apiPath);
|
|
|
+ result.put("rcid", rcid);
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(apiPath)) {
|
|
|
+ result.put("msg", "缺少 apiPath 参数。");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ if (!StringUtils.startsWith(apiPath, "/artemis/api/")) {
|
|
|
+ result.put("msg", "apiPath 必须以 /artemis/api/ 开头。");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> reqBodyMap;
|
|
|
+ try {
|
|
|
+ reqBodyMap = rdReqBodyMap(reqBodyStr);
|
|
|
+ } catch (Exception e) {
|
|
|
+ result.put("msg", "reqBody 不是有效 JSON Object:" + e.getMessage());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ result.put("requestBody", reqBodyMap);
|
|
|
+
|
|
|
+ try {
|
|
|
+ Map<String, Object> hkConnParm = makeHkConnParm();
|
|
|
+ if (hkConnParm == null) {
|
|
|
+ result.put("msg", "缺少海康连接配置,请补齐 hk.host / hk.appKey / hk.appSecret。");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ result.put("hkConn", makeSafeHkConnResp(hkConnParm));
|
|
|
+
|
|
|
+ String tagId = rdCfgOrOverride(makeReqOverrideParm(), "tagId", CFG_TAG_ID, "HK_LEAVE_AUTH_TAG_ID", HK_DEF_TAG_ID);
|
|
|
+ if (StringUtils.isNotBlank(tagId))
|
|
|
+ hkConnParm.put("tagId", tagId);
|
|
|
+ result.put("tagId", tagId);
|
|
|
+ result.put("tagIdSource", rdCfgSource(makeReqOverrideParm(), "tagId", CFG_TAG_ID, "HK_LEAVE_AUTH_TAG_ID", HK_DEF_TAG_ID));
|
|
|
+
|
|
|
+ if (rcid > 0) {
|
|
|
+ try (Db gdba = Db.makeConn()) {
|
|
|
+ LeaveAuthSyncCtx ctx = selLeaveAuthSyncCtx(gdba, rcid);
|
|
|
+ if (ctx != null)
|
|
|
+ result.put("leaveCtx", makeLeaveCtxResp(ctx));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> responseMap = HK_API_CLIENT.postProbeApi(hkConnParm, apiPath, reqBodyMap);
|
|
|
+ result.put("ok", true);
|
|
|
+ result.put("response", responseMap);
|
|
|
+ result.put("templateIdCandidates", extTemplateIdList(responseMap));
|
|
|
+ result.put("msg", "海康接口探测已返回,请把 response 和 templateIdCandidates 一并发我分析。");
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("HkLeaveAuthServ.probeHkTemplateApi() 异常,apiPath={}", apiPath, e);
|
|
|
+ result.put("msg", e.getMessage());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 2026-05-26:手工触发真实下发,便于先做一次人工联调确认海康侧能成功接收。
|
|
|
*/
|
|
|
@@ -435,7 +513,7 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
if (StringUtils.isNotBlank(tagId))
|
|
|
hkConnParm.put("tagId", tagId);
|
|
|
|
|
|
- // 2026-05-26:真实下发优先使用显式配置的 templateId,避免把诊断探测结果当成业务前置条件。
|
|
|
+ // 2026-05-27:当前请假自动开门按“添加权限配置”口径执行,templateId 只在海康侧明确要求时才附带。
|
|
|
Map<String, Object> singleSearchReq = null;
|
|
|
Map<String, Object> singleSearchResp = null;
|
|
|
String probedTemplateId = null;
|
|
|
@@ -459,31 +537,31 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
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("tagId", tagId);
|
|
|
result.put("tagIdSource", tagIdSource);
|
|
|
result.put("callbackUrl", callbackUrl);
|
|
|
- result.put("configReady", StringUtils.isNotBlank(tagId) && StringUtils.isNotBlank(effectiveTemplateId));
|
|
|
+ result.put("configReady", StringUtils.isNotBlank(tagId));
|
|
|
|
|
|
List<String> missingCfgList = new ArrayList<>();
|
|
|
if (StringUtils.isBlank(tagId))
|
|
|
missingCfgList.add("tagId");
|
|
|
- if (StringUtils.isBlank(effectiveTemplateId))
|
|
|
- missingCfgList.add("templateId");
|
|
|
result.put("missingConfig", missingCfgList);
|
|
|
result.put("nextSteps", makeNextStepList(missingCfgList));
|
|
|
result.put("tagIdAdvice", "当前项目只做接口下发时,tagId 只要海康侧提供可用值即可;若还要求平台门禁管理可见,再评估是否改成 acs。");
|
|
|
- result.put("templateIdAdvice", "templateId 需要海康侧在门禁权限模板中提供,当前 single/search 不能稳定自动探测。");
|
|
|
+ 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) || StringUtils.isBlank(effectiveTemplateId)) {
|
|
|
- result.put("skipReason", "缺少海康下发配置,暂不执行 special/person/diy。");
|
|
|
+ if (StringUtils.isBlank(tagId)) {
|
|
|
+ result.put("skipReason", "缺少海康下发配置 tagId,暂不执行添加权限配置。");
|
|
|
result.put("mode", "preview");
|
|
|
return result;
|
|
|
}
|
|
|
@@ -637,7 +715,8 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
payload.put("callbackUrl", callbackUrl);
|
|
|
payload.put("resourceInfos", resourceInfoList);
|
|
|
payload.put("personInfos", List.of(makePersonInfoPayload(ctx, personInfo, personId)));
|
|
|
- payload.put("templateConfigInfos", makeTemplateConfigInfos(templateId, templateDimension));
|
|
|
+ if (StringUtils.isNotBlank(templateId))
|
|
|
+ payload.put("templateConfigInfos", makeTemplateConfigInfos(templateId, templateDimension));
|
|
|
return payload;
|
|
|
}
|
|
|
|
|
|
@@ -695,8 +774,6 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
}
|
|
|
if (missingCfgList.contains("tagId"))
|
|
|
nextStepList.add("联系海康侧提供当前合作方账号可用的 tagId。");
|
|
|
- if (missingCfgList.contains("templateId"))
|
|
|
- nextStepList.add("联系海康侧提供门禁权限模板 templateId,或在平台门禁权限模板中确认后填写。");
|
|
|
nextStepList.add("配置补齐前可继续使用 hkkq_leave_auth_preview / hkkq_leave_auth_diag 做联调。");
|
|
|
nextStepList.add("配置补齐后先调用 hkkq_leave_auth_execute,再调用 hkkq_leave_auth_result 回查。");
|
|
|
return nextStepList;
|
|
|
@@ -1061,6 +1138,23 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
return row;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 2026-05-27:把请求里的 JSON 字符串解析成 Map,供海康原始探测接口透传。
|
|
|
+ */
|
|
|
+ private static Map<String, Object> rdReqBodyMap(String reqBodyStr) {
|
|
|
+ if (StringUtils.isBlank(reqBodyStr))
|
|
|
+ return new LinkedHashMap<>();
|
|
|
+
|
|
|
+ JsonElement jsonElement = JsonParser.parseString(reqBodyStr);
|
|
|
+ if (!jsonElement.isJsonObject())
|
|
|
+ throw new IllegalArgumentException("仅支持 JSON Object。");
|
|
|
+
|
|
|
+ JsonObject jsonObject = jsonElement.getAsJsonObject();
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ Map<String, Object> row = GSON.fromJson(jsonObject, Map.class);
|
|
|
+ return row == null ? new LinkedHashMap<>() : row;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 2026-05-26:把列表字段转成长度统计,日志只看数量不看全文。
|
|
|
*/
|