From 6bcea6484e9fdc4354238579fb19c9a8c5aaa156 Mon Sep 17 00:00:00 2001 From: 16358 <1635849544@qq.com> Date: Thu, 26 Jun 2025 17:18:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=9F=E7=A9=BA=E5=AF=B9=E6=8E=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=BC=80=E5=8F=91:=E4=BF=AE=E6=94=B9=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=E6=98=9F=E7=A9=BA=E6=8E=A5=E5=8F=A3=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E8=A1=A5=E5=85=85=E7=9B=B4=E6=8E=A5=E8=B0=83=E6=8B=A8?= =?UTF-8?q?=E5=8D=95json=E5=AE=9E=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/webApi/ApiPostBack.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/measurement/src/main/java/com/ruoyi/webApi/ApiPostBack.java b/measurement/src/main/java/com/ruoyi/webApi/ApiPostBack.java index 6efdd91..c2d17e8 100644 --- a/measurement/src/main/java/com/ruoyi/webApi/ApiPostBack.java +++ b/measurement/src/main/java/com/ruoyi/webApi/ApiPostBack.java @@ -1,5 +1,7 @@ package com.ruoyi.webApi; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.ruoyi.bill.domain.PoundBill; @@ -41,7 +43,7 @@ public class ApiPostBack { private static final ObjectMapper objectMapper = new ObjectMapper(); //单据保存(更新) - public String makePoundBillFormData(String id) throws IOException { + public void makePoundBillFormData(String id) throws IOException { PoundBill poundBill = poundBillService.selectPoundBillById(id); if (poundBill == null) throw new RuntimeException("磅单不存在!"); @@ -55,10 +57,34 @@ public class ApiPostBack { try { jsonInputString = objectMapper.writeValueAsString(request); } catch (JsonProcessingException e) { - return "JSON序列化失败:" + e.getMessage(); + throw new RuntimeException("JSON序列化失败:" + e.getMessage()); } - return sendPostRequest(url, jsonInputString); + String resultJSON = sendPostRequest(url, jsonInputString); + JSONObject jsonObject = JSONObject.parseObject(resultJSON); + // 获取 Result.NeedReturnData 数组,更新fid ,fentryid的值 + JSONArray needReturnDataArray = jsonObject.getJSONObject("Result").getJSONArray("NeedReturnData"); + String fid = "0"; + String fEntryID = "0"; + for (int i = 0; i < needReturnDataArray.size(); i++) { + JSONObject needReturnDataItem = needReturnDataArray.getJSONObject(i); + // 取得 FID + fid = needReturnDataItem.getString("FID"); + // 取得 FEntity 数组 + JSONArray fEntityArray = needReturnDataItem.getJSONArray("FEntity"); + if (fEntityArray != null && !fEntityArray.isEmpty()){ + fEntityArray = needReturnDataItem.getJSONArray("FBillEntry"); + } + for (int j = 0; j < fEntityArray.size(); j++) { + JSONObject fEntityItem = fEntityArray.getJSONObject(j); + // 取得 FEntryID + fEntryID = fEntityItem.getString("FEntryID"); + break; + } + } + poundBill.setFid(fid); + poundBill.setFentity_fentryid(fEntryID); + poundBillService.updatePoundBill(poundBill); } //单据下推