diff --git a/measurement/src/main/java/com/ruoyi/webApi/ApiPostBack.java b/measurement/src/main/java/com/ruoyi/webApi/ApiPostBack.java index 5cd3995..b1e0843 100644 --- a/measurement/src/main/java/com/ruoyi/webApi/ApiPostBack.java +++ b/measurement/src/main/java/com/ruoyi/webApi/ApiPostBack.java @@ -161,10 +161,18 @@ public class ApiPostBack { demoPoundMst.setFid(fid); poundBillService.updateById(demoPoundMst); } - } } + } + /** + * 删除简单生产入库单 + * return: true 成功删除 + */ + public boolean deleteSPbill(String fid) throws IOException { + SPbillUnAudit(fid); + SPbillDelete(fid); + return true; } //单据下推 @@ -212,13 +220,37 @@ public class ApiPostBack { int responseCode = connection.getResponseCode(); 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()); + 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("接口返回错误,但未找到具体的错误信息。"); } - return response.toString(); + } + return response.toString(); } } else { throw new RuntimeException("请求失败,响应码:" + responseCode); @@ -289,4 +321,42 @@ public class ApiPostBack { return result; } + /** + * 简单生产入库单反审核接口 + */ + public void SPbillUnAudit(String fid) throws IOException { + //查询单据是否存在下游 + // 目标URL + String url = sysConfigService.selectConfigByKey("OA_Url")+"/k3cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.UnAudit.common.kdsvc"; + String jsonInputString = "{\n" + + " “Formid”:”SP_InStock”,\n" + + " “data”:\n" + + "{\n" + + " \"Numbers\": [],\n" + + " \"Ids\": "+fid+"\"\",\n" + + " \"NetworkCtrl\": \"false\",\n" + + " \"IsVerifyProcInst\": \"true\"\n" + + "}\n" + + "}"; + String oaData = sendPostRequest(url, jsonInputString); + } + + /** + * 简单生产入库删除接口 + */ + public void SPbillDelete(String fid) throws IOException { + //查询单据是否存在下游 + // 目标URL + String url = sysConfigService.selectConfigByKey("OA_Url")+"/k3cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Delete.common.kdsvc"; + String jsonInputString = "{\n" + + "\t\"Formid\": \"SP_InStock\",\n" + + "\t\"data\": {\n" + + "\t\t\"Numbers\": [],\n" + + "\t\t\"Ids\": \""+fid+"\",\n" + + "\t\t\"NetworkCtrl\": \"false\"\n" + + "\t}\n" + + "}"; + sendPostRequest(url, jsonInputString); + } + } \ No newline at end of file