星空对接接口开发:修改对接星空接口逻辑,补充直接调拨单json实体

This commit is contained in:
16358 2025-06-26 17:18:51 +08:00
parent 7996f41b74
commit 6bcea6484e
1 changed files with 29 additions and 3 deletions

View File

@ -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);
}
//单据下推