|
|
@@ -28,6 +28,8 @@ import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* 2026-05-26:班主任请假后的海康临时权限同步服务。
|
|
|
@@ -62,6 +64,7 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
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");
|
|
|
+ private static final Pattern MJD_CHANNEL_NAME_PATTERN = Pattern.compile("^(.*?)(?:_门_(\\d+))?$");
|
|
|
|
|
|
/**
|
|
|
* 2026-05-26:请假保存后执行入口,保持原来的挂点不变。
|
|
|
@@ -284,13 +287,25 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
probeLimit = 3;
|
|
|
|
|
|
List<Map<String, Object>> resourceSourceList = selAllActiveMjdList(gdba);
|
|
|
- List<Map<String, Object>> resourceInfoList = makeResourceInfoList(resourceSourceList);
|
|
|
+ LeaveAuthResourceBundle resourceBundle = buildLeaveAuthResourceBundle(hkConnParm, resourceSourceList);
|
|
|
+ List<Map<String, Object>> resourceInfoList = resourceBundle.resourceInfoList;
|
|
|
if (probeLimit > resourceInfoList.size())
|
|
|
probeLimit = resourceInfoList.size();
|
|
|
|
|
|
result.put("resourceCount", resourceInfoList.size());
|
|
|
result.put("probeLimit", probeLimit);
|
|
|
- result.put("resourceSourceList", makeMjdRespList(resourceSourceList));
|
|
|
+ result.put("resourceSourceCount", resourceBundle.resourceSourceList.size());
|
|
|
+ result.put("resourceMappedCount", resourceInfoList.size());
|
|
|
+ result.put("hkAcsDeviceCount", resourceBundle.hkAcsDeviceCount);
|
|
|
+ result.put("resourceSourceList", resourceBundle.resourceSourceList);
|
|
|
+ result.put("resourceUnmappedList", resourceBundle.unmappedSourceList);
|
|
|
+ result.put("resourceMapMode", "acsDeviceSearchByNameAndChannel");
|
|
|
+ if (!resourceBundle.unmappedSourceList.isEmpty()) {
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", makeResourceMapErrorMsg(resourceBundle.unmappedSourceList));
|
|
|
+ persistLeaveAuthSyncResult(gdba, ctx, result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
List<Map<String, Object>> probeList = new ArrayList<>();
|
|
|
LinkedHashSet<String> detectedTemplateIdSet = new LinkedHashSet<>();
|
|
|
@@ -555,10 +570,22 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> resourceSourceList = selAllActiveMjdList(gdba);
|
|
|
- List<Map<String, Object>> resourceInfoList = makeResourceInfoList(resourceSourceList);
|
|
|
- result.put("resourceSourceList", makeMjdRespList(resourceSourceList));
|
|
|
+ LeaveAuthResourceBundle resourceBundle = buildLeaveAuthResourceBundle(hkConnParm, resourceSourceList);
|
|
|
+ List<Map<String, Object>> resourceInfoList = resourceBundle.resourceInfoList;
|
|
|
+ result.put("resourceSourceList", resourceBundle.resourceSourceList);
|
|
|
+ result.put("resourceUnmappedList", resourceBundle.unmappedSourceList);
|
|
|
result.put("resourceInfos", resourceInfoList);
|
|
|
result.put("resourceCount", resourceInfoList.size());
|
|
|
+ result.put("resourceSourceCount", resourceBundle.resourceSourceList.size());
|
|
|
+ result.put("resourceMappedCount", resourceInfoList.size());
|
|
|
+ result.put("hkAcsDeviceCount", resourceBundle.hkAcsDeviceCount);
|
|
|
+ result.put("resourceMapMode", "acsDeviceSearchByNameAndChannel");
|
|
|
+ if (!resourceBundle.unmappedSourceList.isEmpty()) {
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", makeResourceMapErrorMsg(resourceBundle.unmappedSourceList));
|
|
|
+ persistLeaveAuthSyncResult(gdba, ctx, result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
if (resourceInfoList.isEmpty()) {
|
|
|
result.put("ok", false);
|
|
|
result.put("msg", "未找到可下发的有效门禁点。");
|
|
|
@@ -746,55 +773,175 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 2026-05-26:请假权限直接按当前所有有效门禁点下发,避免再做班级或住宿点的额外过滤。
|
|
|
+ * 2026-06-08:请假权限改为先查海康 acsDevice 设备列表,再把本地门禁点映射成“设备级 indexCode + 通道号”。
|
|
|
*/
|
|
|
- private static List<Map<String, Object>> makeResourceInfoList(List<Map<String, Object>> mjdList) {
|
|
|
+ private static LeaveAuthResourceBundle buildLeaveAuthResourceBundle(Map<String, Object> hkConnParm,
|
|
|
+ List<Map<String, Object>> mjdList) throws Exception {
|
|
|
if (mjdList == null || mjdList.isEmpty())
|
|
|
- return List.of();
|
|
|
+ return new LeaveAuthResourceBundle(List.of(), List.of(), List.of(), 0);
|
|
|
|
|
|
- LinkedHashSet<String> resourceIndexCodeSet = new LinkedHashSet<>();
|
|
|
+ List<Map<String, Object>> acsDeviceList = HK_API_CLIENT.loadAcsDeviceList(hkConnParm);
|
|
|
+ Map<String, List<Map<String, Object>>> acsDeviceMap = makeAcsDeviceNameMap(acsDeviceList);
|
|
|
+ LinkedHashSet<String> resourceKeySet = new LinkedHashSet<>();
|
|
|
List<Map<String, Object>> resourceInfoList = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> resourceSourceList = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> unmappedSourceList = new ArrayList<>();
|
|
|
+
|
|
|
for (Map<String, Object> mjd : mjdList) {
|
|
|
- String resourceIndexCode = rdStr(mjd.get("sbbs"));
|
|
|
- if (StringUtils.isBlank(resourceIndexCode))
|
|
|
+ Map<String, Object> row = makeMjdRespRow(mjd);
|
|
|
+ String mjdName = rdStr(mjd.get("mc"));
|
|
|
+ String acsDeviceMatchName = makeAcsDeviceMatchName(mjdName);
|
|
|
+ int channelNo = rdChannelNo(mjdName);
|
|
|
+ row.put("acsDeviceMatchName", acsDeviceMatchName);
|
|
|
+ row.put("channelNo", channelNo);
|
|
|
+
|
|
|
+ List<Map<String, Object>> matchedDeviceList = acsDeviceMap.get(makeNormKey(acsDeviceMatchName));
|
|
|
+ if (matchedDeviceList == null || matchedDeviceList.isEmpty()) {
|
|
|
+ row.put("mapped", false);
|
|
|
+ row.put("mapStatus", "acsDeviceMissing");
|
|
|
+ row.put("mapMsg", "未找到同名海康 acsDevice 设备");
|
|
|
+ resourceSourceList.add(row);
|
|
|
+ unmappedSourceList.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (matchedDeviceList.size() > 1) {
|
|
|
+ row.put("mapped", false);
|
|
|
+ row.put("mapStatus", "acsDeviceAmbiguous");
|
|
|
+ row.put("mapMsg", "匹配到多个同名海康 acsDevice 设备");
|
|
|
+ row.put("acsDeviceCandidateCount", matchedDeviceList.size());
|
|
|
+ resourceSourceList.add(row);
|
|
|
+ unmappedSourceList.add(row);
|
|
|
continue;
|
|
|
- if (!resourceIndexCodeSet.add(resourceIndexCode))
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> acsDevice = matchedDeviceList.get(0);
|
|
|
+ String resourceIndexCode = rdStr(acsDevice.get("indexCode"));
|
|
|
+ if (StringUtils.isBlank(resourceIndexCode)) {
|
|
|
+ row.put("mapped", false);
|
|
|
+ row.put("mapStatus", "acsDeviceIndexCodeMissing");
|
|
|
+ row.put("mapMsg", "海康 acsDevice 设备缺少 indexCode");
|
|
|
+ resourceSourceList.add(row);
|
|
|
+ unmappedSourceList.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ row.put("mapped", true);
|
|
|
+ row.put("mapStatus", "mapped");
|
|
|
+ row.put("mapMsg", "已映射到海康设备级 acsDevice 码");
|
|
|
+ row.put("resourceIndexCode", resourceIndexCode);
|
|
|
+ row.put("resourceType", "acsDevice");
|
|
|
+ row.put("acsDeviceName", rdStr(acsDevice.get("name")));
|
|
|
+ row.put("acsDeviceIndexCode", resourceIndexCode);
|
|
|
+ row.put("acsDeviceRegionName", rdStr(acsDevice.get("regionName")));
|
|
|
+ row.put("acsDeviceIp", rdStr(acsDevice.get("ip")));
|
|
|
+ row.put("acsDevicePort", rdStr(acsDevice.get("port")));
|
|
|
+ row.put("acsDeviceDoorCapacity", rdInt(acsDevice.get("doorCapacity")));
|
|
|
+
|
|
|
+ resourceSourceList.add(row);
|
|
|
+
|
|
|
+ String resourceKey = makeLeaveResourceKey(resourceIndexCode, channelNo);
|
|
|
+ if (!resourceKeySet.add(resourceKey)) {
|
|
|
+ row.put("duplicateResourceKey", true);
|
|
|
continue;
|
|
|
- resourceInfoList.add(makeResourceInfo(resourceIndexCode));
|
|
|
+ }
|
|
|
+ resourceInfoList.add(makeResourceInfo(resourceIndexCode, channelNo));
|
|
|
}
|
|
|
- return resourceInfoList;
|
|
|
+
|
|
|
+ return new LeaveAuthResourceBundle(resourceInfoList, resourceSourceList, unmappedSourceList, acsDeviceList.size());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 2026-05-26:把 MJD 记录回显成前端能直接看懂的资源来源列表。
|
|
|
+ * 2026-06-08:把海康设备列表按规范化名称建索引,便于本地门禁点按名称映射。
|
|
|
*/
|
|
|
- private static List<Map<String, Object>> makeMjdRespList(List<Map<String, Object>> mjdList) {
|
|
|
- if (mjdList == null || mjdList.isEmpty())
|
|
|
- return List.of();
|
|
|
+ private static Map<String, List<Map<String, Object>>> makeAcsDeviceNameMap(List<Map<String, Object>> acsDeviceList) {
|
|
|
+ Map<String, List<Map<String, Object>>> rowMap = new LinkedHashMap<>();
|
|
|
+ if (acsDeviceList == null || acsDeviceList.isEmpty())
|
|
|
+ return rowMap;
|
|
|
+ for (Map<String, Object> row : acsDeviceList) {
|
|
|
+ String name = rdStr(row == null ? null : row.get("name"));
|
|
|
+ if (StringUtils.isBlank(name))
|
|
|
+ continue;
|
|
|
+ rowMap.computeIfAbsent(makeNormKey(name), key -> new ArrayList<>()).add(row);
|
|
|
+ }
|
|
|
+ return rowMap;
|
|
|
+ }
|
|
|
|
|
|
- List<Map<String, Object>> respList = new ArrayList<>();
|
|
|
- for (Map<String, Object> mjd : mjdList) {
|
|
|
- Map<String, Object> row = new LinkedHashMap<>();
|
|
|
- row.put("mjdid", rdLong(mjd.get("mjdid")));
|
|
|
- row.put("mc", rdStr(mjd.get("mc")));
|
|
|
- row.put("sbbs", rdStr(mjd.get("sbbs")));
|
|
|
- row.put("cdid", rdLong(mjd.get("cdid")));
|
|
|
- row.put("mjdlbm", rdLong(mjd.get("mjdlbm")));
|
|
|
- row.put("jcfxm", rdStr(mjd.get("jcfxm")));
|
|
|
- row.put("jlztm", rdLong(mjd.get("jlztm")));
|
|
|
- respList.add(row);
|
|
|
+ /**
|
|
|
+ * 2026-06-08:本地门禁点名称像“新宿舍入口3_门_1”,映射海康设备时需要还原成“新宿舍入口3”。
|
|
|
+ */
|
|
|
+ private static String makeAcsDeviceMatchName(String mjdName) {
|
|
|
+ if (StringUtils.isBlank(mjdName))
|
|
|
+ return null;
|
|
|
+ Matcher matcher = MJD_CHANNEL_NAME_PATTERN.matcher(StringUtils.trim(mjdName));
|
|
|
+ if (!matcher.matches())
|
|
|
+ return StringUtils.trimToNull(mjdName);
|
|
|
+ return StringUtils.trimToNull(matcher.group(1));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2026-06-08:从本地门禁点名称提取门通道号;未显式带 `_门_n` 时默认按 1 号通道处理。
|
|
|
+ */
|
|
|
+ private static int rdChannelNo(String mjdName) {
|
|
|
+ if (StringUtils.isBlank(mjdName))
|
|
|
+ return 1;
|
|
|
+ Matcher matcher = MJD_CHANNEL_NAME_PATTERN.matcher(StringUtils.trim(mjdName));
|
|
|
+ if (!matcher.matches())
|
|
|
+ return 1;
|
|
|
+ int channelNo = rdInt(matcher.group(2));
|
|
|
+ return channelNo > 0 ? channelNo : 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2026-06-08:把 MJD 记录回显成前端能直接看懂的资源来源列表。
|
|
|
+ */
|
|
|
+ private static Map<String, Object> makeMjdRespRow(Map<String, Object> mjd) {
|
|
|
+ Map<String, Object> row = new LinkedHashMap<>();
|
|
|
+ row.put("mjdid", rdLong(mjd.get("mjdid")));
|
|
|
+ row.put("mc", rdStr(mjd.get("mc")));
|
|
|
+ row.put("sbbs", rdStr(mjd.get("sbbs")));
|
|
|
+ row.put("cdid", rdLong(mjd.get("cdid")));
|
|
|
+ row.put("mjdlbm", rdLong(mjd.get("mjdlbm")));
|
|
|
+ row.put("jcfxm", rdStr(mjd.get("jcfxm")));
|
|
|
+ row.put("jlztm", rdLong(mjd.get("jlztm")));
|
|
|
+ return row;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2026-06-08:生成请假资源映射失败提示,优先列出前几条未映射名称便于现场核对。
|
|
|
+ */
|
|
|
+ private static String makeResourceMapErrorMsg(List<Map<String, Object>> unmappedSourceList) {
|
|
|
+ if (unmappedSourceList == null || unmappedSourceList.isEmpty())
|
|
|
+ return "部分门禁点未能映射到海康 acsDevice 设备。";
|
|
|
+ List<String> nameList = new ArrayList<>();
|
|
|
+ for (Map<String, Object> row : unmappedSourceList) {
|
|
|
+ String name = rdStr(row == null ? null : row.get("mc"));
|
|
|
+ if (StringUtils.isBlank(name))
|
|
|
+ continue;
|
|
|
+ nameList.add(name);
|
|
|
+ if (nameList.size() >= 6)
|
|
|
+ break;
|
|
|
}
|
|
|
- return respList;
|
|
|
+ String suffix = unmappedSourceList.size() > nameList.size() ? " 等" : "";
|
|
|
+ return "以下门禁点未能映射到海康 acsDevice 设备编码:" + String.join("、", nameList) + suffix;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2026-06-08:生成资源唯一键,口径统一为“设备级 indexCode + 通道号”。
|
|
|
+ */
|
|
|
+ private static String makeLeaveResourceKey(String resourceIndexCode, int channelNo) {
|
|
|
+ if (StringUtils.isBlank(resourceIndexCode))
|
|
|
+ return null;
|
|
|
+ return resourceIndexCode + "#" + (channelNo > 0 ? channelNo : 1);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 2026-05-26:给海康 special/person/diy 拼单条门禁资源信息。
|
|
|
*/
|
|
|
- private static Map<String, Object> makeResourceInfo(String resourceIndexCode) {
|
|
|
+ private static Map<String, Object> makeResourceInfo(String resourceIndexCode, int channelNo) {
|
|
|
Map<String, Object> row = new LinkedHashMap<>();
|
|
|
row.put("resourceIndexCode", resourceIndexCode);
|
|
|
row.put("resourceType", "acsDevice");
|
|
|
- row.put("channelNos", List.of(1));
|
|
|
+ row.put("channelNos", List.of(channelNo > 0 ? channelNo : 1));
|
|
|
row.put("channelIndexCodes", List.of(resourceIndexCode));
|
|
|
return row;
|
|
|
}
|
|
|
@@ -1895,9 +2042,22 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- List<Map<String, Object>> resourceInfoList = makeResourceInfoList(selAllActiveMjdList(gdba));
|
|
|
+ List<Map<String, Object>> resourceSourceList = selAllActiveMjdList(gdba);
|
|
|
+ LeaveAuthResourceBundle resourceBundle = buildLeaveAuthResourceBundle(hkConnParm, resourceSourceList);
|
|
|
+ List<Map<String, Object>> resourceInfoList = resourceBundle.resourceInfoList;
|
|
|
+ result.put("resourceSourceList", resourceBundle.resourceSourceList);
|
|
|
+ result.put("resourceUnmappedList", resourceBundle.unmappedSourceList);
|
|
|
result.put("resourceInfos", resourceInfoList);
|
|
|
result.put("resourceCount", resourceInfoList.size());
|
|
|
+ result.put("resourceSourceCount", resourceBundle.resourceSourceList.size());
|
|
|
+ result.put("resourceMappedCount", resourceInfoList.size());
|
|
|
+ result.put("hkAcsDeviceCount", resourceBundle.hkAcsDeviceCount);
|
|
|
+ result.put("resourceMapMode", "acsDeviceSearchByNameAndChannel");
|
|
|
+ if (!resourceBundle.unmappedSourceList.isEmpty()) {
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", makeResourceMapErrorMsg(resourceBundle.unmappedSourceList));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
String configTaskId = rdLeaveAuthLogField(ctx, "configTaskId");
|
|
|
if (StringUtils.isNotBlank(configTaskId)) {
|
|
|
@@ -3343,6 +3503,26 @@ public class HkLeaveAuthServ extends Serv {
|
|
|
row.put(key, value);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 2026-06-08:封装一次请假资源映射结果,避免调用方分别维护“原始门禁点 / 已映射资源 / 未映射资源”三套列表。
|
|
|
+ */
|
|
|
+ private static final class LeaveAuthResourceBundle {
|
|
|
+ private final List<Map<String, Object>> resourceInfoList;
|
|
|
+ private final List<Map<String, Object>> resourceSourceList;
|
|
|
+ private final List<Map<String, Object>> unmappedSourceList;
|
|
|
+ private final int hkAcsDeviceCount;
|
|
|
+
|
|
|
+ private LeaveAuthResourceBundle(List<Map<String, Object>> resourceInfoList,
|
|
|
+ List<Map<String, Object>> resourceSourceList,
|
|
|
+ List<Map<String, Object>> unmappedSourceList,
|
|
|
+ int hkAcsDeviceCount) {
|
|
|
+ this.resourceInfoList = resourceInfoList == null ? List.of() : resourceInfoList;
|
|
|
+ this.resourceSourceList = resourceSourceList == null ? List.of() : resourceSourceList;
|
|
|
+ this.unmappedSourceList = unmappedSourceList == null ? List.of() : unmappedSourceList;
|
|
|
+ this.hkAcsDeviceCount = hkAcsDeviceCount;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 2026-05-26:请假上下文只保留同步临时权限所需字段。
|
|
|
*/
|