|
|
@@ -5,6 +5,8 @@ import core.co.haikang.HkApiClient;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
+import ss.serv.Serv;
|
|
|
+import ss.serv.ServC;
|
|
|
import ss.db.Db;
|
|
|
import ss.db.SqlCmd;
|
|
|
|
|
|
@@ -26,7 +28,7 @@ import java.util.Map;
|
|
|
* 2. 即使开启,也默认只做 dry-run,先把“人、请假时段、权限条目”串起来供联调验证
|
|
|
* 3. 真正写海康权限时再打开 execute 开关,避免在接口字段尚未完全确认前误下发权限
|
|
|
*/
|
|
|
-final class HkLeaveAuthServ {
|
|
|
+public class HkLeaveAuthServ extends Serv {
|
|
|
|
|
|
private static final Logger log4j = LogManager.getLogger(HkLeaveAuthServ.class);
|
|
|
|
|
|
@@ -46,63 +48,127 @@ final class HkLeaveAuthServ {
|
|
|
private HkLeaveAuthServ() {
|
|
|
}
|
|
|
|
|
|
+ public String previewLeaveAuthSync() {
|
|
|
+ super.wrJsonByResp(previewLeaveAuthSyncResult());
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+
|
|
|
static void syncLeaveAuthAfterCommit(RcPo rcPo) {
|
|
|
if (rcPo == null || rcPo.getRcid() <= 0)
|
|
|
return;
|
|
|
if (!rdBoolCfg(CFG_ENABLED, "HK_LEAVE_AUTH_ENABLED", false))
|
|
|
return;
|
|
|
|
|
|
+ try {
|
|
|
+ Map<String, Object> result = buildLeaveAuthSyncResult(rcPo.getRcid(), true);
|
|
|
+ if (!Boolean.TRUE.equals(result.get("ok")))
|
|
|
+ logSkip(String.valueOf(result.get("msg")), rcPo.getRcid(), null, null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("HkLeaveAuthServ.syncLeaveAuthAfterCommit() 异常,rcid={}", rcPo.getRcid(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> previewLeaveAuthSyncResult() {
|
|
|
+ Map<String, Object> result = new LinkedHashMap<>();
|
|
|
+ long rcid = rdReqLongParm("rcid");
|
|
|
+ if (rcid <= 0) {
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "缺少有效的 rcid 参数。");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return buildLeaveAuthSyncResult(rcid, false);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("HkLeaveAuthServ.previewLeaveAuthSync() 异常,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);
|
|
|
+ result.put("autoTrigger", autoTrigger);
|
|
|
+ result.put("enabled", rdBoolCfg(CFG_ENABLED, "HK_LEAVE_AUTH_ENABLED", false));
|
|
|
+ result.put("execute", rdBoolCfg(CFG_EXECUTE, "HK_LEAVE_AUTH_EXECUTE", false));
|
|
|
+ result.put("rcid", rcid);
|
|
|
+
|
|
|
try (Db gdba = Db.makeConn()) {
|
|
|
+ RcPo rcPo = new RcPo();
|
|
|
+ rcPo.setRcid(rcid);
|
|
|
LeaveAuthSyncCtx ctx = selLeaveAuthSyncCtx(gdba, rcPo);
|
|
|
if (ctx == null) {
|
|
|
- logSkip("missingLeaveCtx", rcPo.getRcid(), null, null);
|
|
|
- return;
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "未找到对应请假记录。");
|
|
|
+ return result;
|
|
|
}
|
|
|
+ result.put("leaveCtx", makeLeaveCtxResp(ctx));
|
|
|
+
|
|
|
if (StringUtils.isBlank(ctx.jobNo)) {
|
|
|
- logSkip("missingJobNo", ctx.rcid, ctx.ryid, ctx.bjid);
|
|
|
- return;
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "学生缺少人员号(ryh/jobNo),无法匹配海康人员。");
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
Map<String, Object> hkConnParm = makeHkConnParm();
|
|
|
if (hkConnParm == null) {
|
|
|
- logSkip("missingHkConnCfg", ctx.rcid, ctx.ryid, ctx.bjid);
|
|
|
- return;
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "缺少海康连接配置,请补齐 hk.host / hk.appKey / hk.appSecret。");
|
|
|
+ return result;
|
|
|
}
|
|
|
+ result.put("hkConn", makeSafeHkConnResp(hkConnParm));
|
|
|
|
|
|
Map<String, Map<String, Object>> personInfoMap = HK_API_CLIENT.loadPersonInfoMapByJobNo(
|
|
|
hkConnParm, List.of(ctx.jobNo));
|
|
|
Map<String, Object> personInfo = personInfoMap.get(makeNormKey(ctx.jobNo));
|
|
|
+ result.put("personQueryJobNo", ctx.jobNo);
|
|
|
+ result.put("personInfoFound", personInfo != null);
|
|
|
if (personInfo == null) {
|
|
|
- logSkip("hkPersonNotFound", ctx.rcid, ctx.ryid, ctx.bjid);
|
|
|
- return;
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "海康侧未找到对应人员。");
|
|
|
+ return result;
|
|
|
}
|
|
|
+ result.put("personInfo", makePersonInfoResp(personInfo));
|
|
|
|
|
|
String personId = rdStr(personInfo.get("personId"));
|
|
|
if (StringUtils.isBlank(personId)) {
|
|
|
- logSkip("hkPersonIdMissing", ctx.rcid, ctx.ryid, ctx.bjid);
|
|
|
- return;
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "海康人员缺少 personId。");
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
List<String> authItemNoList = rdAuthItemNoList(ctx.bjid);
|
|
|
+ List<String> doorIndexCodeList = rdDoorIndexCodeList(ctx.bjid);
|
|
|
+ result.put("authItemNos", authItemNoList);
|
|
|
+ result.put("doorIndexCodes", doorIndexCodeList);
|
|
|
if (authItemNoList.isEmpty()) {
|
|
|
- logSkip("missingAuthItemNos", ctx.rcid, ctx.ryid, ctx.bjid);
|
|
|
- return;
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "未配置海康权限条目号。");
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
- List<String> doorIndexCodeList = rdDoorIndexCodeList(ctx.bjid);
|
|
|
Map<String, Object> payload = makeSpecialAuthPayload(ctx, personId, authItemNoList, doorIndexCodeList);
|
|
|
- boolean execute = rdBoolCfg(CFG_EXECUTE, "HK_LEAVE_AUTH_EXECUTE", false);
|
|
|
- if (!execute) {
|
|
|
- logDryRun(ctx, personInfo, payload);
|
|
|
- return;
|
|
|
- }
|
|
|
+ result.put("payload", payload);
|
|
|
|
|
|
Map<String, Object> authItemQuery = makeAuthItemQuery(authItemNoList);
|
|
|
+ result.put("authItemQuery", authItemQuery);
|
|
|
Map<String, Object> authItemResp = HK_API_CLIENT.searchSingleAuthItem(hkConnParm, authItemQuery);
|
|
|
+ result.put("authItemResp", authItemResp);
|
|
|
+
|
|
|
+ boolean execute = rdBoolCfg(CFG_EXECUTE, "HK_LEAVE_AUTH_EXECUTE", false);
|
|
|
+ if (!autoTrigger || !execute) {
|
|
|
+ result.put("mode", "dryRun");
|
|
|
+ if (autoTrigger)
|
|
|
+ logDryRun(ctx, personInfo, payload);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
Map<String, Object> authSyncResp = HK_API_CLIENT.downloadSpecialPersonAuth(hkConnParm, payload);
|
|
|
+ result.put("mode", "execute");
|
|
|
+ result.put("authSyncResp", authSyncResp);
|
|
|
logExecute(ctx, personInfo, authItemResp, authSyncResp);
|
|
|
- } catch (Exception e) {
|
|
|
- log4j.error("HkLeaveAuthServ.syncLeaveAuthAfterCommit() 异常,rcid={}", rcPo.getRcid(), e);
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -279,6 +345,38 @@ final class HkLeaveAuthServ {
|
|
|
return logRow;
|
|
|
}
|
|
|
|
|
|
+ private static Map<String, Object> makeLeaveCtxResp(LeaveAuthSyncCtx ctx) {
|
|
|
+ Map<String, Object> row = new LinkedHashMap<>();
|
|
|
+ row.put("rcid", ctx.rcid);
|
|
|
+ row.put("bjid", ctx.bjid);
|
|
|
+ row.put("ryid", ctx.ryid);
|
|
|
+ row.put("rclbm", ctx.rclbm);
|
|
|
+ row.put("xm", ctx.xm);
|
|
|
+ row.put("jobNo", ctx.jobNo);
|
|
|
+ row.put("leaveBeg", makeHkTime(ctx.kssj));
|
|
|
+ row.put("leaveEnd", makeHkTime(ctx.jssj));
|
|
|
+ return row;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String, Object> makeSafeHkConnResp(Map<String, Object> hkConnParm) {
|
|
|
+ Map<String, Object> row = new LinkedHashMap<>();
|
|
|
+ row.put("host", rdStr(hkConnParm.get("host")));
|
|
|
+ row.put("port", hkConnParm.get("port"));
|
|
|
+ row.put("appKeyMask", makeMaskStr(rdStr(hkConnParm.get("appKey"))));
|
|
|
+ return row;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String, Object> makePersonInfoResp(Map<String, Object> personInfo) {
|
|
|
+ Map<String, Object> row = new LinkedHashMap<>();
|
|
|
+ row.put("personId", rdStr(personInfo.get("personId")));
|
|
|
+ row.put("jobNo", rdStr(personInfo.get("jobNo")));
|
|
|
+ row.put("personName", rdStr(personInfo.get("personName")));
|
|
|
+ row.put("studentId", rdStr(personInfo.get("studentId")));
|
|
|
+ row.put("orgIndexCode", rdStr(personInfo.get("orgIndexCode")));
|
|
|
+ row.put("orgPathName", rdStr(personInfo.get("orgPathName")));
|
|
|
+ return row;
|
|
|
+ }
|
|
|
+
|
|
|
private static String rdStr(Object value) {
|
|
|
return value == null ? null : StringUtils.trimToNull(String.valueOf(value));
|
|
|
}
|
|
|
@@ -311,6 +409,30 @@ final class HkLeaveAuthServ {
|
|
|
return StringUtils.upperCase(StringUtils.trimToEmpty(value));
|
|
|
}
|
|
|
|
|
|
+ private static String makeMaskStr(String value) {
|
|
|
+ if (StringUtils.isBlank(value))
|
|
|
+ return "";
|
|
|
+ String trimVal = StringUtils.trim(value);
|
|
|
+ if (trimVal.length() <= 4)
|
|
|
+ return "****";
|
|
|
+ return trimVal.substring(0, 2) + "****" + trimVal.substring(trimVal.length() - 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ private long rdReqLongParm(String... fieldNameArr) {
|
|
|
+ if (super.req == null || fieldNameArr == null)
|
|
|
+ return 0L;
|
|
|
+ for (String fieldName : fieldNameArr) {
|
|
|
+ String value = super.req.getParameter(fieldName);
|
|
|
+ if (StringUtils.isBlank(value))
|
|
|
+ continue;
|
|
|
+ try {
|
|
|
+ return Long.parseLong(StringUtils.trim(value));
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+
|
|
|
private static final class LeaveAuthSyncCtx {
|
|
|
private final long rcid;
|
|
|
private final long bjid;
|