|
|
@@ -143,6 +143,12 @@ public class FaceCollectAuditServ extends Serv {
|
|
|
return ServC.SERV_notByA;
|
|
|
}
|
|
|
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ public String faceCollect_autoClosedLoopByA() {
|
|
|
+ super.wrJsonByResp(autoClosedLoopResult());
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+
|
|
|
private Map<String, Object> matchPendingResult() {
|
|
|
int limit = Math.min(200, Math.max(1, rdReqInt("limit", 50)));
|
|
|
try (Db fcDb = FaceCollectDb.makeConn(); Db pmsDb = Db.makeConn()) {
|
|
|
@@ -378,61 +384,141 @@ public class FaceCollectAuditServ extends Serv {
|
|
|
try (Db fcDb = FaceCollectDb.makeConn(); Db pmsDb = Db.makeConn()) {
|
|
|
if (fcDb == null)
|
|
|
return mkFail("FACE_COLLECT_DB_ERROR", "人脸采集数据源不可用。");
|
|
|
+ if (pmsDb == null)
|
|
|
+ return mkFail("PMS_DB_ERROR", "PMS 数据源不可用。");
|
|
|
|
|
|
- List<Map<String, Object>> steps = new ArrayList<>();
|
|
|
- Map<String, Object> collect = selCollectById(fcDb, faceCollectId, true);
|
|
|
- if (collect == null)
|
|
|
- return mkFail("FACE_COLLECT_NOT_FOUND", "未找到采集记录。");
|
|
|
-
|
|
|
- if (rdInt(collect, "match_status", MATCH_UNMATCHED) != MATCH_OK) {
|
|
|
- MatchResult matchResult = matchCollect(fcDb, pmsDb, collect, true);
|
|
|
- steps.add(step("match", matchResult.ok, matchResult.msg, matchResult.toMap()));
|
|
|
- collect = selCollectById(fcDb, faceCollectId, true);
|
|
|
- if (!matchResult.ok) {
|
|
|
- fcDb.commit();
|
|
|
- pmsDb.commit();
|
|
|
- return mkClosedLoopResult(false, "主数据未匹配成功,已停止推进。", steps);
|
|
|
- }
|
|
|
- }
|
|
|
+ Map<String, Object> result = runClosedLoopInternal(fcDb, pmsDb, faceCollectId, autoReview, confirmHk);
|
|
|
+ pmsDb.commit();
|
|
|
+ fcDb.commit();
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("FaceCollectAuditServ.runClosedLoopResult() 异常", e);
|
|
|
+ return mkFail("FACE_COLLECT_CLOSED_LOOP_FAIL", rdErrMsg(e, "闭环推进失败。"));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (autoReview && rdInt(collect, "review_status", REVIEW_PENDING) != REVIEW_PASS) {
|
|
|
- reviewPassInternal(fcDb, collect, "闭环推进自动审核通过。");
|
|
|
- steps.add(step("review", true, "审核通过。", null));
|
|
|
- collect = selCollectById(fcDb, faceCollectId, true);
|
|
|
- }
|
|
|
+ private Map<String, Object> autoClosedLoopResult() {
|
|
|
+ int limit = Math.min(100, Math.max(1, rdReqInt("limit", 20)));
|
|
|
+ boolean autoReview = rdReqBool("autoReview", true);
|
|
|
+ boolean confirmHk = rdReqBool("confirmHk", true);
|
|
|
+ boolean retryFailed = rdReqBool("retryFailed", true);
|
|
|
+ try (Db fcDb = FaceCollectDb.makeConn(); Db pmsDb = Db.makeConn()) {
|
|
|
+ if (fcDb == null)
|
|
|
+ return mkFail("FACE_COLLECT_DB_ERROR", "人脸采集数据源不可用。");
|
|
|
+ if (pmsDb == null)
|
|
|
+ return mkFail("PMS_DB_ERROR", "PMS 数据源不可用。");
|
|
|
|
|
|
- if (rdInt(collect, "review_status", REVIEW_PENDING) != REVIEW_PASS) {
|
|
|
- fcDb.commit();
|
|
|
- pmsDb.commit();
|
|
|
- return mkClosedLoopResult(false, "等待管理员审核通过。", steps);
|
|
|
- }
|
|
|
+ List<Map<String, Object>> collectList = selAutoClosedLoopList(fcDb, limit, retryFailed);
|
|
|
+ List<Map<String, Object>> items = new ArrayList<>();
|
|
|
+ int successCount = 0;
|
|
|
+ int blockedCount = 0;
|
|
|
+ int failCount = 0;
|
|
|
|
|
|
- if (rdInt(collect, "write_ry_status", WRITE_UNDONE) != WRITE_OK) {
|
|
|
- WriteBackResult writeBack = writeBackRy(fcDb, pmsDb, collect);
|
|
|
- steps.add(step("write_ry", writeBack.ok, writeBack.msg, writeBack.toMap()));
|
|
|
- collect = selCollectById(fcDb, faceCollectId, true);
|
|
|
- if (!writeBack.ok) {
|
|
|
- pmsDb.commit();
|
|
|
- fcDb.commit();
|
|
|
- return mkClosedLoopResult(false, "RY 回写失败,已停止推进。", steps);
|
|
|
+ for (Map<String, Object> collect : collectList) {
|
|
|
+ long faceCollectId = rdLongVal(collect, "face_collect_id");
|
|
|
+ Map<String, Object> itemResult;
|
|
|
+ try {
|
|
|
+ itemResult = runClosedLoopInternal(fcDb, pmsDb, faceCollectId, autoReview, confirmHk);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("FaceCollectAuditServ.autoClosedLoopResult() 处理 faceCollectId=" + faceCollectId + " 异常", e);
|
|
|
+ itemResult = mkFail("FACE_COLLECT_CLOSED_LOOP_FAIL", rdErrMsg(e, "自动闭环处理失败。"));
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ fcDb.commit();
|
|
|
+ } catch (Exception commitErr) {
|
|
|
+ log4j.warn("FaceCollectAuditServ.autoClosedLoopResult() 提交人脸采集库失败", commitErr);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ pmsDb.commit();
|
|
|
+ } catch (Exception commitErr) {
|
|
|
+ log4j.warn("FaceCollectAuditServ.autoClosedLoopResult() 提交 PMS 库失败", commitErr);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (!confirmHk) {
|
|
|
- pmsDb.commit();
|
|
|
- fcDb.commit();
|
|
|
- return mkClosedLoopResult(true, "已完成主数据匹配、审核和 RY 回写;如需正式同步海康,请传 confirmHk=true。", steps);
|
|
|
+ Map<String, Object> item = new LinkedHashMap<>();
|
|
|
+ item.put("faceCollectId", faceCollectId);
|
|
|
+ item.put("xm", rdStr(collect, "xm"));
|
|
|
+ item.put("sfzh", rdStr(collect, "sfzh"));
|
|
|
+ item.put("matchStatus", rdInt(collect, "match_status", MATCH_UNMATCHED));
|
|
|
+ item.put("reviewStatus", rdInt(collect, "review_status", REVIEW_PENDING));
|
|
|
+ item.put("writeRyStatus", rdInt(collect, "write_ry_status", WRITE_UNDONE));
|
|
|
+ item.put("syncHkStatus", rdInt(collect, "sync_hk_status", HK_UNSYNC));
|
|
|
+ item.put("ok", rdBool(itemResult.get("ok")));
|
|
|
+ item.put("code", rdStr(itemResult, "code"));
|
|
|
+ item.put("msg", rdStr(itemResult, "msg"));
|
|
|
+ item.put("data", itemResult.get("data"));
|
|
|
+ items.add(item);
|
|
|
+
|
|
|
+ if (rdBool(itemResult.get("ok"))) {
|
|
|
+ successCount++;
|
|
|
+ } else if ("FACE_COLLECT_CLOSED_LOOP_STOP".equals(rdStr(itemResult, "code"))) {
|
|
|
+ blockedCount++;
|
|
|
+ } else {
|
|
|
+ failCount++;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- HkSyncResult syncResult = syncHk(fcDb, pmsDb, collect);
|
|
|
- steps.add(step("sync_hk", syncResult.ok, syncResult.msg, syncResult.toMap()));
|
|
|
- pmsDb.commit();
|
|
|
- fcDb.commit();
|
|
|
- return mkClosedLoopResult(syncResult.ok, syncResult.msg, steps);
|
|
|
+ Map<String, Object> result = mkOk("自动闭环任务执行完成。");
|
|
|
+ Map<String, Object> data = castData(result);
|
|
|
+ data.put("limit", limit);
|
|
|
+ data.put("autoReview", autoReview);
|
|
|
+ data.put("confirmHk", confirmHk);
|
|
|
+ data.put("retryFailed", retryFailed);
|
|
|
+ data.put("count", collectList.size());
|
|
|
+ data.put("successCount", successCount);
|
|
|
+ data.put("blockedCount", blockedCount);
|
|
|
+ data.put("failCount", failCount);
|
|
|
+ data.put("items", items);
|
|
|
+ data.put("nextStep", failCount > 0
|
|
|
+ ? "先处理失败项的错误原因,再继续自动闭环或人工补跑。"
|
|
|
+ : blockedCount > 0
|
|
|
+ ? "先补齐主数据或人工确认被阻塞项,再继续重试。"
|
|
|
+ : "可继续观察下一轮定时任务执行结果。");
|
|
|
+ return result;
|
|
|
} catch (Exception e) {
|
|
|
- log4j.error("FaceCollectAuditServ.runClosedLoopResult() 异常", e);
|
|
|
- return mkFail("FACE_COLLECT_CLOSED_LOOP_FAIL", rdErrMsg(e, "闭环推进失败。"));
|
|
|
+ log4j.error("FaceCollectAuditServ.autoClosedLoopResult() 异常", e);
|
|
|
+ return mkFail("FACE_COLLECT_AUTO_CLOSED_LOOP_FAIL", rdErrMsg(e, "自动闭环任务执行失败。"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> runClosedLoopInternal(Db fcDb, Db pmsDb, long faceCollectId,
|
|
|
+ boolean autoReview, boolean confirmHk) throws Exception {
|
|
|
+ List<Map<String, Object>> steps = new ArrayList<>();
|
|
|
+ Map<String, Object> collect = selCollectById(fcDb, faceCollectId, true);
|
|
|
+ if (collect == null)
|
|
|
+ return mkFail("FACE_COLLECT_NOT_FOUND", "未找到采集记录。");
|
|
|
+
|
|
|
+ if (rdInt(collect, "match_status", MATCH_UNMATCHED) != MATCH_OK) {
|
|
|
+ MatchResult matchResult = matchCollect(fcDb, pmsDb, collect, true);
|
|
|
+ steps.add(step("match", matchResult.ok, matchResult.msg, matchResult.toMap()));
|
|
|
+ collect = selCollectById(fcDb, faceCollectId, true);
|
|
|
+ if (!matchResult.ok)
|
|
|
+ return mkClosedLoopResult(false, "主数据未匹配成功,已停止推进。", steps);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (autoReview && rdInt(collect, "review_status", REVIEW_PENDING) != REVIEW_PASS) {
|
|
|
+ reviewPassInternal(fcDb, collect, "闭环推进自动审核通过。");
|
|
|
+ steps.add(step("review", true, "审核通过。", null));
|
|
|
+ collect = selCollectById(fcDb, faceCollectId, true);
|
|
|
}
|
|
|
+
|
|
|
+ if (rdInt(collect, "review_status", REVIEW_PENDING) != REVIEW_PASS)
|
|
|
+ return mkClosedLoopResult(false, "等待管理员审核通过。", steps);
|
|
|
+
|
|
|
+ if (rdInt(collect, "write_ry_status", WRITE_UNDONE) != WRITE_OK) {
|
|
|
+ WriteBackResult writeBack = writeBackRy(fcDb, pmsDb, collect);
|
|
|
+ steps.add(step("write_ry", writeBack.ok, writeBack.msg, writeBack.toMap()));
|
|
|
+ collect = selCollectById(fcDb, faceCollectId, true);
|
|
|
+ if (!writeBack.ok)
|
|
|
+ return mkClosedLoopResult(false, "RY 回写失败,已停止推进。", steps);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!confirmHk)
|
|
|
+ return mkClosedLoopResult(true, "已完成主数据匹配、审核和 RY 回写;如需正式同步海康,请传 confirmHk=true。", steps);
|
|
|
+
|
|
|
+ HkSyncResult syncResult = syncHk(fcDb, pmsDb, collect);
|
|
|
+ steps.add(step("sync_hk", syncResult.ok, syncResult.msg, syncResult.toMap()));
|
|
|
+ return mkClosedLoopResult(syncResult.ok, syncResult.msg, steps);
|
|
|
}
|
|
|
|
|
|
private List<Map<String, Object>> selPendingCollectList(Db fcDb, int limit) throws Exception {
|
|
|
@@ -445,6 +531,24 @@ public class FaceCollectAuditServ extends Serv {
|
|
|
return fcDb.doSelMapListByC(sqlCmd);
|
|
|
}
|
|
|
|
|
|
+ private List<Map<String, Object>> selAutoClosedLoopList(Db fcDb, int limit, boolean retryFailed) throws Exception {
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
+ sql.append("select * from (");
|
|
|
+ sql.append(" select FACE_COLLECT_ID,XM,SFZH,MATCH_STATUS,REVIEW_STATUS,WRITE_RY_STATUS,SYNC_HK_STATUS,CJSJ");
|
|
|
+ sql.append(" from ").append(TAB_FACE_COLLECT);
|
|
|
+ sql.append(" where IS_CURRENT=1 and JLZTM=1");
|
|
|
+ sql.append(" and nvl(MATCH_STATUS,0) not in (2,4)");
|
|
|
+ sql.append(" and nvl(REVIEW_STATUS,0) not in (2,3)");
|
|
|
+ sql.append(" and nvl(SYNC_HK_STATUS,0) not in (2,4)");
|
|
|
+ if (!retryFailed)
|
|
|
+ sql.append(" and nvl(WRITE_RY_STATUS,0) <> 2 and nvl(SYNC_HK_STATUS,0) <> 3");
|
|
|
+ sql.append(" order by CJSJ asc, FACE_COLLECT_ID asc");
|
|
|
+ sql.append(" ) where rownum<=:limit");
|
|
|
+ SqlCmd sqlCmd = new SqlCmd(sql.toString());
|
|
|
+ sqlCmd.wrIntParm("limit", limit);
|
|
|
+ return fcDb.doSelMapListByC(sqlCmd);
|
|
|
+ }
|
|
|
+
|
|
|
private List<Map<String, Object>> selReviewList(Db fcDb, int pageNo, int pageSize) throws Exception {
|
|
|
int startNo = (pageNo - 1) * pageSize + 1;
|
|
|
int endNo = pageNo * pageSize;
|