1.SAP凭证查询,返回动态表单页面

--s
This commit is contained in:
weiyunlong 2025-03-06 17:41:07 +08:00
parent 193ac58f71
commit 0b172097a1
2 changed files with 234 additions and 83 deletions

View File

@ -1,9 +1,12 @@
package shjh.jhzj7.fi.fi.plugin.form;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kd.bos.context.RequestContext;
import kd.bos.dataentity.OperateOption;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.operate.OperateOptionConst;
import kd.bos.entity.operate.result.OperateErrorInfo;
import kd.bos.entity.operate.result.OperationResult;
@ -22,8 +25,10 @@ import shjh.jhzj7.fi.fi.utils.JhzjUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import static shjh.jhzj7.fi.fi.utils.SapUtils.vouchers_payable;
import static shjh.jhzj7.fi.fi.webapi.ApplyBillControler.*;
/**
@ -57,43 +62,107 @@ public class SappzFormPlugin extends AbstractFormPlugin {
String procurementteam = (String) this.getModel().getValue("shjh_procurementteam");//采购组
Boolean isselfprocurement = (Boolean) this.getModel().getValue("shjh_isselfprocurement");//是否自行采购
// 日期格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
JSONArray IT_LIST = new JSONArray();
// 添加公司过滤条件
if (shjhOrgfield != null) {
addFilterCondition(IT_LIST, "BUKRS", shjhOrgfield.getString("number"), shjhOrgfield.getString("number"));
}
// 添加SAP应付凭证号过滤条件
if (StringUtils.isNotEmpty(payablevouchernumber)) {
addFilterCondition(IT_LIST, "BELNR", payablevouchernumber, payablevouchernumber);
}
// 添加会计科目编号过滤条件
if (StringUtils.isNotEmpty(accountingsubjects)) {
addFilterCondition(IT_LIST, "HKONT", accountingsubjects, accountingsubjects);
}
// 添加SAP应付凭过账日期过滤条件
if (postingdate_start != null || postingdate_endda != null) {
String postingdate_starts = formatDate(sdf, postingdate_start);
String postingdate_enddas = formatDate(sdf, postingdate_endda);
addFilterCondition(IT_LIST, "BUDAT", postingdate_starts, postingdate_enddas);
}
// 添加SAP应付凭到期日过滤条件
if (duedate_start != null || duedate_end != null) {
String duedate_starts = formatDate(sdf, duedate_start);
String duedate_ends = formatDate(sdf, duedate_end);
addFilterCondition(IT_LIST, "FAEDT", duedate_starts, duedate_ends);
}
// 添加SAP应付凭证制单日期过滤条件
if (dateofpreparat_start != null && dateofpreparat_end != null) {
String dateofpreparat_starts = formatDate(sdf, dateofpreparat_start);
String dateofpreparat_ends = formatDate(sdf, dateofpreparat_end);
addFilterCondition(IT_LIST, "BLDAT", dateofpreparat_starts, dateofpreparat_ends);
}
DynamicObjectCollection shjhEntryentity = this.getModel().getEntryEntity("shjh_entryentity");
shjhEntryentity.clear();
//todo:根据查询条件,调用SAP查询凭证接口,生成分录行
//模拟查询到两个数据
for (int i = 0; i < 3; i++) {
DynamicObject add = shjhEntryentity.addNew();
if (null != shjhOrgfield) {
this.getModel().setValue("shjh_orgnumber", shjhOrgfield.getString("number"), i);//公司编号
JSONObject result = vouchers_payable(IT_LIST, payablevouchernumber);
if (null != result && result.containsKey("data")) {
// 处理查询结果
JSONObject data = (JSONObject) result.get("data");
if (null != data && data.containsKey("IT_ITEM")) {
JSONArray IT_ITEMs = (JSONArray) data.get("IT_ITEM");
if (!IT_ITEMs.isEmpty()) {
// for (int i = 0; i <5000; i++) {
for (int i = 0; i < IT_ITEMs.size(); i++) {
JSONObject it_list = (JSONObject)IT_ITEMs.get(i);
DynamicObject add = shjhEntryentity.addNew();
this.getModel().setValue("shjh_orgnumber", it_list.getString("BUKRS"), i);//公司编号,"公司代码
this.getModel().setValue("shjh_vouchernumber", it_list.getString("BELNR"), i);//凭证号,会计凭证编号
this.getModel().setValue("shjh_accountingyear", it_list.getString("GJAHR"), i);//会计年度,会计年度
this.getModel().setValue("shjh_accountingsubject", it_list.getString("SAKNR"), i);//todo:会计科目:1001,总帐科目编号
this.getModel().setValue("shjh_accountingsubjecline", it_list.getString("EBELP"), i);//会计科目行项目号,采购凭证的项目编号
this.getModel().setValue("shjh_outstandingamount", new BigDecimal(it_list.getString("WRBTR")), i);//未清金额,凭证货币金额
BigDecimal KURSF = new BigDecimal(it_list.getString("KURSF"));
if (KURSF.compareTo(BigDecimal.ZERO) == 0) {
KURSF = BigDecimal.ONE;
}
this.getModel().setValue("shjh_exchangerate",KURSF, i);//汇率
this.getModel().setValue("shjh_applyforconversionof",new BigDecimal(it_list.getString("DMBTR")), i);//申请金额折结算币别,按本位币计的金额
String FAEDT = it_list.getString("FAEDT");
if (StringUtils.isNotEmpty(FAEDT)) {
Date date = StrToDate(FAEDT);
this.getModel().setValue("shjh_duedat", date, i);//到期日,净价到期日
}
String BUDAT = it_list.getString("BUDAT");
if (StringUtils.isNotEmpty(BUDAT)) {
Date date = StrToDate(BUDAT);
this.getModel().setValue("shjh_bookkeepingdate", date, i);//记账日期,凭证中的过帐日期
}
String BLDAT = it_list.getString("BLDAT");
if (StringUtils.isNotEmpty(BLDAT)) {
Date date = StrToDate(BLDAT);
this.getModel().setValue("shjh_documentdate", date, i);//凭证日期,凭证中的凭证日期
}
String ZFBDT = it_list.getString("ZFBDT");
if (StringUtils.isNotEmpty(ZFBDT)) {
Date date = StrToDate(ZFBDT);
this.getModel().setValue("shjh_basedate", date, i);//基准日期,用于到期日计算的基准日期
}
// this.getModel().setValue("shjh_payee", "供应商", i);//todo:往来类型
// this.getModel().setValue("shjh_payeebanknum", it_list.getString("ZWLZH"), i);//todo:往来户名称
this.getModel().setValue("shjh_payee", "供应商", i);//往来类型
this.getModel().setValue("shjh_payeebanknum", "上海家化销售有限公司", i);//往来户名称
this.getModel().setValue("shjh_description",it_list.getString("BVTYP") , i);//合作银行类型.合作银行类型
this.getModel().setValue("shjh_reasoncode", "014", i);//todo:原因码
this.getModel().setValue("shjh_classificationoffund", payablevouchernumber, i);//todo:资金计划分类
this.getModel().setValue("shjh_secondarydept", it_list.getString("ZREQ_DEPT"), i);//二级部门,需求部门
this.getModel().setValue("shjh_procurementeam", it_list.getString("EKGRP"), i);//采购组
this.getModel().setValue("shjh_isselfprocurment", it_list.getString("ZZXCG_FLAG"), i);//todo:是否自行采购
this.getModel().setValue("shjh_paymentcurrency", it_list.getString("WAERS"), i);//付款币别编号CNY,货币码
this.getModel().setValue("shjh_settlementcurrency", it_list.getString("WAERS"), i);//结算币别编号,货币码
}
this.getView().updateView("shjh_entryentity");
}
}
this.getModel().setValue("shjh_vouchernumber", payablevouchernumber, i);//凭证号
this.getModel().setValue("shjh_accountingyear", payablevouchernumber, i);//会计年度
// this.getModel().setValue("shjh_accountingsubject", accountingsubjects, i);//会计科目:1001
this.getModel().setValue("shjh_accountingsubject", "1001", i);//会计科目:1001
this.getModel().setValue("shjh_accountingsubjecline", payablevouchernumber, i);//会计科目行项目号
this.getModel().setValue("shjh_outstandingamount", BigDecimal.ONE, i);//未清金额
this.getModel().setValue("shjh_exchangerate", BigDecimal.ONE, i);//汇率
this.getModel().setValue("shjh_applyforconversionof", BigDecimal.ONE, i);//申请金额折结算币别
this.getModel().setValue("shjh_duedat", new Date(), i);//到期日
this.getModel().setValue("shjh_bookkeepingdate", new Date(), i);//记账日期
this.getModel().setValue("shjh_documentdate", new Date(), i);//凭证日期
this.getModel().setValue("shjh_basedate", new Date(), i);//基准日期
this.getModel().setValue("shjh_payee", "供应商", i);//往来类型
this.getModel().setValue("shjh_payeebanknum", "上海家化销售有限公司", i);//往来户名称
this.getModel().setValue("shjh_description", payablevouchernumber, i);//合作银行类型
this.getModel().setValue("shjh_reasoncode", "014", i);//原因码
this.getModel().setValue("shjh_classificationoffund", payablevouchernumber, i);//资金计划分类
this.getModel().setValue("shjh_secondarydept", payablevouchernumber, i);//二级部门
this.getModel().setValue("shjh_procurementeam", procurementteam, i);//采购组
this.getModel().setValue("shjh_isselfprocurment", isselfprocurement, i);//是否自行采购
this.getModel().setValue("shjh_paymentcurrency", "CNY", i);//付款币别编号
this.getModel().setValue("shjh_settlementcurrency", "CNY", i);//结算币别编号
}
this.getView().updateView("shjh_entryentity");
break;
//todo:(字段待确认)遍历选中的分录行,生成付款申请单 7.1.3
// 日志中入参根据分录中存入的存储
case "confirm":
//todo:(字段待确认)遍历选中的分录行,生成付款申请单 7.1.3
// 日志中入参根据分录中存入的存储
EntryGrid entryentitys = (EntryGrid) this.getView().getControl("shjh_entryentity");
int[] selectRows = entryentitys.getSelectRows();
if (selectRows.length == 0) {
@ -188,7 +257,7 @@ public class SappzFormPlugin extends AbstractFormPlugin {
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的费控单据已锁定");
return;
} else {
//存在且单据中SAP锁定状态为未锁定,更新数据
//todo:存在且单据中SAP锁定状态为未锁定,更新数据
ap_payapply = ap_payapplys;
}
}
@ -242,6 +311,9 @@ public class SappzFormPlugin extends AbstractFormPlugin {
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "" + currencyTypeName + "为空");
return;
}
if ("RMB".equals(currencyNumber)) {
currencyNumber = "CNY";
}
QFilter filter = new QFilter("number", QCP.equals, currencyNumber);
DynamicObject currency = BusinessDataServiceHelper.loadSingle(BD_CURRENCY, new QFilter[]{filter});
// 检查 currency 是否为空
@ -455,14 +527,14 @@ public class SappzFormPlugin extends AbstractFormPlugin {
}
//若多条数据相同,则合并为一条数据处理
for (DynamicObject ap_payapply : bills.values()){
for (DynamicObject ap_payapply : bills.values()) {
String fkBillNum = ap_payapply.getString("shjh_vouchernum");
OperateOption option= OperateOption.create();
OperateOption option = OperateOption.create();
option.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(false)); // 不执行警告级别校验器
// 新增数据
OperationResult saveResult = OperationServiceHelper.executeOperate("save", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
if (!saveResult.isSuccess()) {
handleAndLogError(saveResult, "保存失败",apimenthod, fkBillNum, null);
handleAndLogError(saveResult, "保存失败", apimenthod, fkBillNum, null);
String errorMessage = getFirstErrorMessage(saveResult);
this.getView().showErrorNotification(errorMessage);
return;
@ -470,12 +542,18 @@ public class SappzFormPlugin extends AbstractFormPlugin {
//todo:SAP是否锁定
OperationResult submitResult = OperationServiceHelper.executeOperate("submit", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
if (!submitResult.isSuccess()) {
handleAndLogError(submitResult, "提交失败",apimenthod, fkBillNum, null);
// 提交失败将保存的数据删除,记录日志
OperationServiceHelper.executeOperate("delete", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
handleAndLogError(submitResult, "提交失败", apimenthod, fkBillNum, null);
String errorMessage = getFirstErrorMessage(submitResult);
this.getView().showErrorNotification(errorMessage);
return;
}
OperationResult auditResult = OperationServiceHelper.executeOperate("audit", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
if (!auditResult.isSuccess()) {
handleAndLogError(auditResult, "审核失败",apimenthod, fkBillNum, null);
handleAndLogError(auditResult, "审核失败", apimenthod, fkBillNum, null);
String errorMessage = getFirstErrorMessage(auditResult);
this.getView().showErrorNotification(errorMessage);
return;
}
log.error("审核成功,凭证号:" + fkBillNum);
@ -491,8 +569,19 @@ public class SappzFormPlugin extends AbstractFormPlugin {
}
private Date StrToDate(String strDate){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
return sdf.parse(strDate);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 获取第一个错误信息
*
* @param result 操作返回结果
*/
private String getFirstErrorMessage(OperationResult result) {
@ -512,7 +601,7 @@ public class SappzFormPlugin extends AbstractFormPlugin {
*/
private void handleAndLogError(OperationResult result, String operationType, String fkBillNum, String apimenthod, String jsonBodyString) {
String errorMessage = getFirstErrorMessage(result);
handleError(operationType +",原因:" + errorMessage, apimenthod, fkBillNum, jsonBodyString);
handleError(operationType + ",原因:" + errorMessage, apimenthod, fkBillNum, jsonBodyString);
}
/**
@ -527,4 +616,29 @@ public class SappzFormPlugin extends AbstractFormPlugin {
log.error(errorMessage);
JhzjUtils.saveLog(apimenthod, moduleName, inputParam, errorMessage, false, "API");
}
// 添加过滤条件到IT_LIST的方法
private void addFilterCondition(JSONArray IT_LIST, String field, String low, String high) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("FIELD", field); // 字段
jsonObject.put("SIGN", "I"); // I:包含 E排除
jsonObject.put("LOW", low); // LOW 枚举字段所代表值的区间开始值
jsonObject.put("HIGH", high); // HIGH枚举字段所代表值的区间结束值
jsonObject.put("OPTION", "BT"); // 默认BT
IT_LIST.add(jsonObject);
}
// 日期格式化方法添加异常处理
private String formatDate(SimpleDateFormat sdf, Date date) {
if (date == null) {
return null;
}
try {
return sdf.format(date);
} catch (Exception e) {
// 处理日期格式化异常
e.printStackTrace();
return null;
}
}
}

View File

@ -5,9 +5,18 @@ import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.util.HttpClientUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.sql.Date;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -26,7 +35,7 @@ public class SapUtils {
public static final String unlockedUrl = "https://hipint-stg.jahwa.com.cn:6443/gateway/HIP_ReceiveFromFM/1.0/fm/send";//测试环境(SAP应付凭证锁定解锁状态回写)
// public static final String unlockedUrl = "https://hipint.jahwa.com.cn:6443/gateway/HIP_ReceiveFromFM/1.0/fm/send";//正式环境
private static final String Apimenthod2 = "SAP应付凭证清单接口";
private static final String interfaceID2 = "ZFS_GET_AP_OPENITEMS";//识别被调接口并进行路由
private static final String interfaceID2 = "PayableVoucherList";//识别被调接口并进行路由
public static final String vouchersUrl = "https://hipint-stg.jahwa.com.cn:6443/gateway/HIP_ReceiveFromFM/1.0/fm/send";//测试环境(SAP应付凭证清单)
// public static final String vouchersUrl = "https://hipint.jahwa.com.cn:6443/gateway/HIP_ReceiveFromFM/1.0/fm/send";//正式环境
@ -44,8 +53,6 @@ public class SapUtils {
*/
private static Map<String, String> buildCustomerHeader(Map<String, Object> thirdPartyMap) {
Map<String, String> customerHeader = new HashMap<>();
customerHeader.put("Content-Type", "application/json;charset=UTF-8");//请求报文类型
customerHeader.put("x-Gateway-APIKey",APIKey);//apiKey,由ESB提供
customerHeader.put("interfaceID", ""+thirdPartyMap.get("interfaceID"));//识别被调接口并进行路由
customerHeader.put("receiverID", ""+thirdPartyMap.get("receiverID"));
return customerHeader;
@ -55,7 +62,7 @@ public class SapUtils {
/**
* SAP应付凭证锁定解锁状态回写
*/
public static void unlocked_status(Map<String, Object> thirdPartyMap) {
public static void unlocked_status(Map<String, Object> thirdPartyMap){
thirdPartyMap.put("interfaceID",interfaceID1);
thirdPartyMap.put("receiverID",receiverID1);
thirdPartyMap.put("URL",unlockedUrl);
@ -64,7 +71,7 @@ public class SapUtils {
// 组装请求体
JSONObject pendingsBody = unlockedBody(thirdPartyMap);
// 发送请求并处理响应
processRequest(customerHeader, pendingsBody, thirdPartyMap,Apimenthod1);
// processRequest(customerHeader, pendingsBody, thirdPartyMap,Apimenthod1);
}
/**
@ -102,43 +109,36 @@ public class SapUtils {
/**
* SAP应付凭证清单接口
*/
public static void vouchers_payable(Map<String, Object> thirdPartyMap) {
public static JSONObject vouchers_payable(JSONArray IT_LIST,String billno){
Map<String, Object> thirdPartyMap = new HashMap<>();
thirdPartyMap.put("interfaceID",interfaceID2);
thirdPartyMap.put("senderID",receiverID1);
thirdPartyMap.put("receiverID",receiverID1);
thirdPartyMap.put("URL",vouchersUrl);
// 构建请求头
Map<String, String> customerHeader = buildCustomerHeader(thirdPartyMap);
thirdPartyMap.put("billno",billno);
// 组装请求体
JSONObject payableBody = payableBody(thirdPartyMap);
JSONObject payableBody = payableBody(IT_LIST);
// 发送请求并处理响应
processRequest(customerHeader, payableBody, thirdPartyMap,Apimenthod2);
return processRequest(payableBody, thirdPartyMap, Apimenthod2);
}
/**
* SAP应付凭证清单接口组装请求体:
* @param thirdPartyMap 第三方数据映射
* @return 请求体的 JSON 对象
*/
private static JSONObject payableBody(Map<String, Object> thirdPartyMap) {
private static JSONObject payableBody(JSONArray IT_LIST) {
// 获取当前日期和时间
LocalDateTime date = LocalDateTime.now();
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
// 格式化当前日期和时间
String dates = date.format(formatter);
//组装请求体
JSONObject pendingsBody = new JSONObject();
pendingsBody.put("rootContextID",""+System.currentTimeMillis());//todo:唯一事务ID采用UUID或其他强唯一性ID
pendingsBody.put("requestTime", ""+(thirdPartyMap.get("createdatetime")));//请求时间,格式为yyyy-MM-dd HH:mm:ss.SSS
pendingsBody.put("rootContextID",""+System.currentTimeMillis());//唯一事务ID采用UUID或其他强唯一性ID
pendingsBody.put("requestTime",dates);//请求时间,格式为yyyy-MM-dd HH:mm:ss.SSS
JSONObject data = new JSONObject();
JSONArray IT_LIST = new JSONArray();
//todo:
List<DynamicObject> Lists = (List<DynamicObject>) thirdPartyMap.get("Lists");
for (DynamicObject obj : Lists) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("FIELD", ""+(thirdPartyMap.get("FIELD")));//字段
jsonObject.put("SIGN", ""+(thirdPartyMap.get("SIGN")));//I:包含 E排除
jsonObject.put("LOW", ""+(thirdPartyMap.get("LOW")));//LOW 枚举字段所代表值的区间开始值
jsonObject.put("HIGH", ""+(thirdPartyMap.get("HIGH")));//HIGH枚举字段所代表值的区间结束值
jsonObject.put("OPTION", "BT");//默认BT
IT_LIST.add(jsonObject);
}
data.put("IT_LIST",IT_LIST);
data.put("IT_INPUT",IT_LIST);
pendingsBody.put("data", data);
return pendingsBody;
}
@ -146,16 +146,24 @@ public class SapUtils {
/**
* 生成代扣款记账单接口
*/
public static void withholding_billing(Map<String, Object> thirdPartyMap) {
public static void withholding_billing(){
Map<String, Object> thirdPartyMap = new HashMap<>();
thirdPartyMap.put("interfaceID",interfaceID3);
thirdPartyMap.put("senderID",receiverID2);
thirdPartyMap.put("receiverID",receiverID2);
thirdPartyMap.put("URL",withholdingUrl);
// 获取当前日期和时间
LocalDateTime date = LocalDateTime.now();
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
// 格式化当前日期和时间
String dates = date.format(formatter);
thirdPartyMap.put("createdatetime",dates);
// 构建请求头
Map<String, String> customerHeader = buildCustomerHeader(thirdPartyMap);
// 组装请求体
JSONObject withholdingBody = withholdingBody(thirdPartyMap);
// 发送请求并处理响应
processRequest(customerHeader, withholdingBody, thirdPartyMap, Apimenthod3);
// processRequest(customerHeader, withholdingBody, thirdPartyMap, Apimenthod3);
}
/**
@ -213,29 +221,58 @@ public class SapUtils {
/**
* 发送请求并处理响应
*
* @param customerHeader 请求头
* @param pendingsBody 请求体
* @param thirdPartyMap 第三方数据映射
* @param apiName 接口名称
*/
private static void processRequest(Map<String, String> customerHeader, JSONObject pendingsBody, Map<String, Object> thirdPartyMap,String apiName) {
String pendingPostjson = null;
private static JSONObject processRequest(JSONObject pendingsBody, Map<String, Object> thirdPartyMap, String apiName){
// 配置超时时间
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(10000) // 连接超时时间单位毫秒
.setConnectionRequestTimeout(10000) // 请求获取连接的超时时间单位毫秒
.setSocketTimeout(30000) // 读取超时时间单位毫秒
.build();
// 创建 HttpClient 实例并应用配置
HttpClient httpClient = HttpClients.custom()
.setDefaultRequestConfig(requestConfig)
.build();
// 创建 HttpPost 请求
HttpPost httpPost = new HttpPost(thirdPartyMap.get("URL").toString());
// 设置请求头
httpPost.setHeader("Content-Type", "application/json");
httpPost.setHeader("x-Gateway-APIKey", APIKey);
httpPost.setHeader("interfaceID", "" + thirdPartyMap.get("interfaceID"));
httpPost.setHeader("receiverID", "" + thirdPartyMap.get("receiverID"));
JSONObject jsonObject = null;
try {
// 发送POST请求并获取响应
pendingPostjson = HttpClientUtils.postjson(thirdPartyMap.get("URL").toString(), customerHeader, pendingsBody.toJSONString());
jsonObject = parseResponse(pendingPostjson,apiName);
// 检查JSON对象是否为空
if (jsonObject != null && !jsonObject.isEmpty()) {
// 设置请求体
StringEntity entity = new StringEntity(pendingsBody.toJSONString(), "UTF-8");
httpPost.setEntity(entity);
// 执行请求
HttpResponse response = httpClient.execute(httpPost);
// 获取响应实体
HttpEntity responseEntity = response.getEntity();
if (responseEntity != null) {
String responseString = EntityUtils.toString(responseEntity, "UTF-8");
jsonObject = JSONObject.parseObject(responseString);
handleResponse(jsonObject, pendingsBody, thirdPartyMap,apiName);
return com.alibaba.fastjson.JSONObject.parseObject(responseString);
}else {
logger.info(apiName +"失败!");
saveLog(apiName +(thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, false,apiName);
saveLog(apiName +(thirdPartyMap.get("billno").toString()), pendingsBody, null, false,apiName);
}
} catch (Exception e) {
handleException(e, pendingsBody, thirdPartyMap, jsonObject,apiName);
}
return jsonObject;
}
/**
@ -261,15 +298,15 @@ public class SapUtils {
* @param apiName 接口名称
*/
private static void handleResponse(JSONObject jsonObject, JSONObject pendingsBody, Map<String, Object> thirdPartyMap,String apiName) {
JSONArray data1 = jsonObject.getJSONArray("data");
if (data1 == null || data1.isEmpty()) {
String operResult = jsonObject.getString("code");
JSONObject jsonobject = jsonObject.getJSONObject("data");
if (jsonobject == null || jsonobject.isEmpty()) {
logger.info(apiName + "失败!");
saveLog(apiName + (thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, false,apiName);
return;
}
JSONObject jsonobject = data1.getJSONObject(0);
String operResult = jsonobject.getString("operResult");
String logMessage = Objects.equals(operResult, "1") ? apiName +"成功!" : apiName +"失败!";
String logMessage = Objects.equals(operResult, "0") ? apiName +"成功!" : apiName +"失败!";
// 记录日志
logger.info(logMessage);