From c9e674b7de3c9c20343be7ff394e42d67aa0e871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Tue, 19 Nov 2024 13:46:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=96=E9=83=A8=E6=8E=A5=E5=8F=A3=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=EF=BC=8C=E5=AD=98=E5=82=A8=E7=BB=93=E6=9E=9C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../task/ExternalInterfaceMonitoringTask.java | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java b/zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java index 8da45c0f..f9de75d4 100644 --- a/zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java +++ b/zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java @@ -414,8 +414,13 @@ public class ExternalInterfaceMonitoringTask extends BaseController { if (response.code() == UniversalEnum.TWO_HUNDRED.getNumber()) { externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber()); if (response.body() != null) { - JSONArray array = DcNmcController.parseHtmlContent(response.body().string()); - externalInterfaceMonitoring.setOperationResult(JSON.toJSONString(array)); + ResponseBody body = response.body(); + // 存储 msg 和 code + JSONObject newJson = new JSONObject(); + newJson.put("msg", response.message()); + newJson.put("code", response.code()); + // JSONArray array = DcNmcController.parseHtmlContent(response.body().string()); + externalInterfaceMonitoring.setOperationResult(newJson.toJSONString()); } } else { externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); @@ -657,7 +662,7 @@ public class ExternalInterfaceMonitoringTask extends BaseController { Response response = getRequestByHeadersByParam(header, cameraInfo.getString("URL") + UniversalEnum.GET_CAMERA_INFORMATION_BY_ORGANIZATION.getValue(), requestParams); - //插入 + //插入 videoResultInsertInto(externalInterfaceMonitoring, response); } catch (Exception e) { externalInterfaceMonitoring.setOperationResult(e.getMessage()); @@ -744,7 +749,9 @@ public class ExternalInterfaceMonitoringTask extends BaseController { } else { externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); } - externalInterfaceMonitoring.setOperationResult(JSON.toJSONString(jsonResult)); + JSONObject newJson = new JSONObject(); + newJson.put("code", jsonResult.get("retCode")); + externalInterfaceMonitoring.setOperationResult(newJson.toJSONString()); } else { externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); externalInterfaceMonitoring.setOperationResult(response.toString()); @@ -766,11 +773,15 @@ public class ExternalInterfaceMonitoringTask extends BaseController { * 交通流结果处理 */ public void trafficFlowResultProcessing(ExternalInterfaceMonitoring externalInterfaceMonitoring, Response response) throws Exception { - ResponseBody body = response.body(); - if (response.code() == UniversalEnum.TWO_HUNDRED.getNumber()) { externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber()); + // 存储 msg 和 code + JSONObject newJson = new JSONObject(); + newJson.put("msg", response.message()); + newJson.put("code",response.code()); + externalInterfaceMonitoring.setOperationResult(newJson.toJSONString()); + } else { externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); } @@ -785,11 +796,11 @@ public class ExternalInterfaceMonitoringTask extends BaseController { if (jsonElement.isJsonObject()) { // 如果是对象,进行对象处理 jsonResult = jsonElement.getAsJsonObject(); + if (!jsonResult.get("code").toString().equals(UniversalEnum.TWO_HUNDRED.getValue())) { externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); } } - externalInterfaceMonitoring.setOperationResult(bodyString); } else { externalInterfaceMonitoring.setOperationResult(response.toString()); } @@ -805,7 +816,10 @@ public class ExternalInterfaceMonitoringTask extends BaseController { */ public void insertIntoExternalInterface(ExternalInterfaceMonitoring externalInterfaceMonitoring, Response response) throws Exception { ResponseBody body = response.body(); - + // 存储 msg 和 code + JSONObject newJson = new JSONObject(); + newJson.put("msg", response.message()); + newJson.put("code", response.code()); if (response.code() == UniversalEnum.TWO_HUNDRED.getNumber()) { externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber()); } else { @@ -813,9 +827,9 @@ public class ExternalInterfaceMonitoringTask extends BaseController { } if (body != null) { - externalInterfaceMonitoring.setOperationResult(body.string()); + externalInterfaceMonitoring.setOperationResult(newJson.toJSONString()); } else { - externalInterfaceMonitoring.setOperationResult(response.toString()); + externalInterfaceMonitoring.setOperationResult(newJson.toJSONString()); } externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); @@ -834,12 +848,19 @@ public class ExternalInterfaceMonitoringTask extends BaseController { public void videoResultInsertInto(ExternalInterfaceMonitoring externalInterfaceMonitoring, Response response) throws Exception { ResponseBody body = response.body(); externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + if (body != null) { JSONObject jsonResult = JSONObject.parseObject(body.string()); + Object msg = jsonResult.get("msg"); + Object code = jsonResult.get("code"); + // 存储 msg 和 code + JSONObject newJson = new JSONObject(); + newJson.put("msg", msg); + newJson.put("code", code); if (jsonResult.containsKey("code") && jsonResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber()); } - externalInterfaceMonitoring.setOperationResult(JSON.toJSONString(jsonResult)); + externalInterfaceMonitoring.setOperationResult(newJson.toJSONString()); } else { externalInterfaceMonitoring.setOperationResult(response.toString()); } @@ -888,7 +909,10 @@ public class ExternalInterfaceMonitoringTask extends BaseController { public void resultAnalysis(AjaxResult ajaxResult, ExternalInterfaceMonitoring externalInterfaceMonitoring) { if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber()); - externalInterfaceMonitoring.setOperationResult(JSON.toJSONString(ajaxResult.get("data"))); + JSONObject newJson = new JSONObject(); + newJson.put("msg", ajaxResult.get("msg")); + newJson.put("code", ajaxResult.get("code")); + externalInterfaceMonitoring.setOperationResult(JSON.toJSONString(newJson.toJSONString())); } else { externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); externalInterfaceMonitoring.setOperationResult(ajaxResult.get("msg").toString());