Просмотр исходного кода

补充海康权限条目诊断入口

“gaohp” 6 месяцев назад
Родитель
Сommit
4f6b6c1f0e
2 измененных файлов с 103 добавлено и 4 удалено
  1. 102 4
      src/biz/kq/HkLeaveAuthServ.java
  2. 1 0
      web/cfg/biz/kq/hkkq.serv.xml

+ 102 - 4
src/biz/kq/HkLeaveAuthServ.java

@@ -46,7 +46,7 @@ public class HkLeaveAuthServ extends Serv {
     private static final int HK_DEF_PORT = 443;
     private static final DateTimeFormatter HK_AUTH_TIME_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
 
-    private HkLeaveAuthServ() {
+    public HkLeaveAuthServ() {
     }
 
     public String previewLeaveAuthSync() {
@@ -54,6 +54,11 @@ public class HkLeaveAuthServ extends Serv {
         return ServC.SERV_notByA;
     }
 
+    public String diagLeaveAuthItem() {
+        super.wrJsonByResp(diagLeaveAuthItemResult());
+        return ServC.SERV_notByA;
+    }
+
     static void syncLeaveAuthAfterCommit(RcPo rcPo) {
         if (rcPo == null || rcPo.getRcid() <= 0)
             return;
@@ -87,6 +92,47 @@ public class HkLeaveAuthServ extends Serv {
         }
     }
 
+    private Map<String, Object> diagLeaveAuthItemResult() {
+        Map<String, Object> result = new LinkedHashMap<>();
+        long rcid = rdReqLongParm("rcid");
+        if (rcid > 0)
+            result.put("rcid", rcid);
+
+        try (Db gdba = Db.makeConn()) {
+            Long bjid = null;
+            if (rcid > 0) {
+                RcPo rcPo = new RcPo();
+                rcPo.setRcid(rcid);
+                LeaveAuthSyncCtx ctx = selLeaveAuthSyncCtx(gdba, rcPo);
+                if (ctx != null) {
+                    bjid = ctx.bjid;
+                    result.put("leaveCtx", makeLeaveCtxResp(ctx));
+                }
+            }
+
+            Map<String, Object> hkConnParm = makeHkConnParm();
+            if (hkConnParm == null) {
+                result.put("ok", false);
+                result.put("msg", "缺少海康连接配置,请补齐 hk.host / hk.appKey / hk.appSecret。");
+                return result;
+            }
+
+            result.put("ok", true);
+            result.put("hkConn", makeSafeHkConnResp(hkConnParm));
+            List<String> authItemNoList = bjid == null ? rdAuthItemNoList(0L) : rdAuthItemNoList(bjid);
+            result.put("authItemNosCfg", authItemNoList);
+            result.put("probeRequests", makeAuthItemProbeReqList(authItemNoList));
+            result.put("probeResults", probeAuthItemSearch(hkConnParm, authItemNoList));
+            result.put("authItemNoMeaning", "authItemNo/authItemNos 是海康一卡通权限条目的编号;请假临时权限下发时,需要把人员关联到这些权限条目。");
+            return result;
+        } catch (Exception e) {
+            log4j.error("HkLeaveAuthServ.diagLeaveAuthItem() 异常,rcid={}", rcid, e);
+            result.put("ok", false);
+            result.put("msg", e.getMessage());
+            return result;
+        }
+    }
+
     private static Map<String, Object> buildLeaveAuthSyncResult(long rcid, boolean autoTrigger) throws Exception {
         Map<String, Object> result = new LinkedHashMap<>();
         result.put("ok", true);
@@ -237,9 +283,11 @@ public class HkLeaveAuthServ extends Serv {
     }
 
     private static List<String> rdAuthItemNoList(long bjid) {
-        List<String> authItemNoList = rdCsvCfg("hk.leaveAuth.bjid." + bjid + ".authItemNos", null);
-        if (!authItemNoList.isEmpty())
-            return authItemNoList;
+        if (bjid > 0) {
+            List<String> authItemNoList = rdCsvCfg("hk.leaveAuth.bjid." + bjid + ".authItemNos", null);
+            if (!authItemNoList.isEmpty())
+                return authItemNoList;
+        }
         return rdCsvCfg(CFG_AUTH_ITEM_NOS, "HK_LEAVE_AUTH_AUTH_ITEM_NOS");
     }
 
@@ -355,6 +403,56 @@ public class HkLeaveAuthServ extends Serv {
         log4j.info("HkLeaveAuthServ.syncLeaveAuthAfterCommit() 已执行:{}", logRow);
     }
 
+    private List<Map<String, Object>> probeAuthItemSearch(Map<String, Object> hkConnParm,
+                                                          List<String> authItemNoList) {
+        List<Map<String, Object>> resultList = new ArrayList<>();
+        for (Map<String, Object> probeReq : makeAuthItemProbeReqList(authItemNoList)) {
+            Map<String, Object> row = new LinkedHashMap<>();
+            row.put("request", probeReq);
+            try {
+                row.put("response", HK_API_CLIENT.searchSingleAuthItem(hkConnParm, probeReq));
+                row.put("ok", true);
+            } catch (Exception e) {
+                row.put("ok", false);
+                row.put("msg", e.getMessage());
+            }
+            resultList.add(row);
+        }
+        return resultList;
+    }
+
+    private List<Map<String, Object>> makeAuthItemProbeReqList(List<String> authItemNoList) {
+        List<Map<String, Object>> reqList = new ArrayList<>();
+
+        reqList.add(new LinkedHashMap<>());
+
+        Map<String, Object> pageReq = new LinkedHashMap<>();
+        pageReq.put("pageNo", 1);
+        pageReq.put("pageSize", 20);
+        reqList.add(pageReq);
+
+        Map<String, Object> emptyNosReq = new LinkedHashMap<>();
+        emptyNosReq.put("pageNo", 1);
+        emptyNosReq.put("pageSize", 20);
+        emptyNosReq.put("authItemNos", List.of());
+        reqList.add(emptyNosReq);
+
+        Map<String, Object> emptyNameReq = new LinkedHashMap<>();
+        emptyNameReq.put("pageNo", 1);
+        emptyNameReq.put("pageSize", 20);
+        emptyNameReq.put("authItemName", "");
+        reqList.add(emptyNameReq);
+
+        if (authItemNoList != null && !authItemNoList.isEmpty()) {
+            Map<String, Object> cfgNosReq = new LinkedHashMap<>();
+            cfgNosReq.put("pageNo", 1);
+            cfgNosReq.put("pageSize", Math.max(authItemNoList.size(), 1));
+            cfgNosReq.put("authItemNos", authItemNoList);
+            reqList.add(cfgNosReq);
+        }
+        return reqList;
+    }
+
     private static void logSkip(String reason, long rcid, Long ryid, Long bjid) {
         Map<String, Object> logRow = new LinkedHashMap<>();
         logRow.put("mode", "skip");

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

@@ -13,6 +13,7 @@
 	<serv name="hkkq_event_view" desc="海康事件订阅查看" clazz="biz.kq.HkKqServ" func="viewHkEventPush" auth="true"/>
 	<serv name="hkkq_event_unsubscribe" desc="海康事件取消订阅" clazz="biz.kq.HkKqServ" func="unsubscribeHkEventPush" auth="true"/>
 	<serv name="hkkq_leave_auth_preview" desc="海康请假权限预览" clazz="biz.kq.HkLeaveAuthServ" func="previewLeaveAuthSync" auth="true"/>
+	<serv name="hkkq_leave_auth_diag" desc="海康权限条目诊断" clazz="biz.kq.HkLeaveAuthServ" func="diagLeaveAuthItem" auth="true"/>
 	<serv name="hkkq_event_push" desc="海康事件订阅回调" clazz="biz.kq.HkKqServ" func="recvHkEventPush" pub="true"/>
 	<serv name="hkkq_timer_plan" desc="海康考勤定时计划" clazz="biz.kq.HkKqServ" func="runScheduledPlan" pub="true"/>
 </servs>