diff --git a/measurement/src/main/java/com/ruoyi/webApi/ApiPostBack.java b/measurement/src/main/java/com/ruoyi/webApi/ApiPostBack.java index ed26001..8695d12 100644 --- a/measurement/src/main/java/com/ruoyi/webApi/ApiPostBack.java +++ b/measurement/src/main/java/com/ruoyi/webApi/ApiPostBack.java @@ -78,7 +78,7 @@ public class ApiPostBack { throw new RuntimeException("JSON序列化失败:" + e.getMessage()); } - String resultJSON = sendPostRequest(url, jsonInputString); + String resultJSON = sendPostRequest(url, jsonInputString,"save"); JSONObject jsonObject = JSONObject.parseObject(resultJSON); // 获取 Result.NeedReturnData 数组,更新fid ,fentryid的值 JSONArray needReturnDataArray = jsonObject.getJSONObject("Result").getJSONArray("NeedReturnData"); @@ -131,7 +131,7 @@ public class ApiPostBack { throw new RuntimeException("JSON序列化失败:" + e.getMessage()); } - String resultJSON = sendPostRequest(url, jsonInputString); + String resultJSON = sendPostRequest(url, jsonInputString,"save"); JSONObject jsonObject = JSONObject.parseObject(resultJSON); // 获取 Result.NeedReturnData 数组,更新fid ,fentryid的值 JSONArray needReturnDataArray = jsonObject.getJSONObject("Result").getJSONArray("NeedReturnData"); @@ -193,10 +193,10 @@ public class ApiPostBack { throw new RuntimeException("JSON序列化失败:" + e.getMessage()); } - sendPostRequest(url, jsonInputString); + sendPostRequest(url, jsonInputString,"save"); } - private String sendPostRequest(String url, String jsonBody) throws IOException { + private String sendPostRequest(String url, String jsonBody,String sendType) throws IOException { StringBuilder errorLog = new StringBuilder(); try { URL apiUrl = new URL(url); @@ -221,36 +221,38 @@ public class ApiPostBack { if (responseCode == HttpURLConnection.HTTP_OK) { try (BufferedReader br = new BufferedReader( new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) { - StringBuilder response = new StringBuilder(); - String responseLine; - while ((responseLine = br.readLine()) != null) { - response.append(responseLine.trim()); - } - // 解析响应 JSON - JSONObject jsonResponse = JSONObject.parseObject(response.toString()); - // 获取 Result 节点 - JSONObject resultObj = jsonResponse.getJSONObject("Result"); - if (resultObj == null) { - throw new RuntimeException("响应中未找到 'Result' 字段,请检查接口返回格式!"); - } - // 获取 ResponseStatus 节点 - JSONObject responseStatus = resultObj.getJSONObject("ResponseStatus"); - if (responseStatus == null) { - throw new RuntimeException("响应中未找到 'ResponseStatus' 字段,请检查接口返回格式!"); - } - // 判断 IsSuccess - Boolean isSuccess = responseStatus.getBoolean("IsSuccess"); - if (isSuccess != null && !isSuccess) { - // 提取错误信息并抛出异常 - JSONArray errors = responseStatus.getJSONArray("Errors"); - if (errors != null && !errors.isEmpty()) { - String errorMessage = errors.getJSONObject(0).getString("Message"); - throw new RuntimeException("接口返回错误: " + errorMessage); - } else { - throw new RuntimeException("接口返回错误,但未找到具体的错误信息。"); + StringBuilder response = new StringBuilder(); + String responseLine; + while ((responseLine = br.readLine()) != null) { + response.append(responseLine.trim()); } - } - return response.toString(); + if (sendType.equals("save")) { + // 解析响应 JSON + JSONObject jsonResponse = JSONObject.parseObject(response.toString()); + // 获取 Result 节点 + JSONObject resultObj = jsonResponse.getJSONObject("Result"); + if (resultObj == null) { + throw new RuntimeException("响应中未找到 'Result' 字段,请检查接口返回格式!"); + } + // 获取 ResponseStatus 节点 + JSONObject responseStatus = resultObj.getJSONObject("ResponseStatus"); + if (responseStatus == null) { + throw new RuntimeException("响应中未找到 'ResponseStatus' 字段,请检查接口返回格式!"); + } + // 判断 IsSuccess + Boolean isSuccess = responseStatus.getBoolean("IsSuccess"); + if (isSuccess != null && !isSuccess) { + // 提取错误信息并抛出异常 + JSONArray errors = responseStatus.getJSONArray("Errors"); + if (errors != null && !errors.isEmpty()) { + String errorMessage = errors.getJSONObject(0).getString("Message"); + throw new RuntimeException("接口返回错误: " + errorMessage); + } else { + throw new RuntimeException("接口返回错误,但未找到具体的错误信息。"); + } + } + } + return response.toString(); } } else { throw new RuntimeException("请求失败,响应码:" + responseCode); @@ -304,7 +306,7 @@ public class ApiPostBack { if (jsonInputString.isEmpty()) return result; - String oaData = sendPostRequest(url, jsonInputString); + String oaData = sendPostRequest(url, jsonInputString,"ExecuteBillQuery"); //查询的参数为FJoinOutQty/FInStockJoinQty,这两者如果有存在大于0的情况或者存在什么也没查到的情况就返回true JSONArray dataList = JSONArray.parseArray(oaData); @@ -338,7 +340,7 @@ public class ApiPostBack { " \"IsVerifyProcInst\": \"true\"\n" + "}\n" + "}"; - String oaData = sendPostRequest(url, jsonInputString); + String oaData = sendPostRequest(url, jsonInputString,"save"); } /** @@ -356,7 +358,7 @@ public class ApiPostBack { "\t\t\"NetworkCtrl\": \"false\"\n" + "\t}\n" + "}"; - sendPostRequest(url, jsonInputString); + sendPostRequest(url, jsonInputString,"save"); } } \ No newline at end of file