From ab05e6bae9d811a078d0f7886f714ed35d051e23 Mon Sep 17 00:00:00 2001 From: yuxueliang0813 <407010292@qq.com> Date: Sat, 15 Mar 2025 18:07:41 +0800 Subject: [PATCH] =?UTF-8?q?sap=E5=BA=94=E6=94=B6=E6=9C=AA=E6=B8=85?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fi/plugin/form/ASParbillFormPlugin.java | 273 ++++++++---------- .../fi/plugin/form/ClearBillFormPlugin.java | 9 +- .../fi/plugin/form/ClearBillListPlugin.java | 20 +- .../fi/plugin/form/ClearDetailFormPlugin.java | 15 +- .../fi/fi/plugin/form/SappzFormPlugin.java | 2 +- .../java/shjh/jhzj7/fi/fi/utils/SapUtils.java | 49 +++- 6 files changed, 198 insertions(+), 170 deletions(-) diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/form/ASParbillFormPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/form/ASParbillFormPlugin.java index 1f461ee..d516d93 100644 --- a/main/java/shjh/jhzj7/fi/fi/plugin/form/ASParbillFormPlugin.java +++ b/main/java/shjh/jhzj7/fi/fi/plugin/form/ASParbillFormPlugin.java @@ -15,12 +15,11 @@ import kd.bos.form.plugin.AbstractFormPlugin; import kd.bos.logging.Log; import kd.bos.logging.LogFactory; import kd.sdk.plugin.Plugin; -import shjh.jhzj7.fi.fi.utils.ApiUtils; -import shjh.jhzj7.fi.fi.utils.EsbUtils; +import shjh.jhzj7.fi.fi.utils.SapUtils; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.EventObject; -import java.util.HashMap; /** * 动态表单插件-【SAP应收未清】 shjh_sapyswq @@ -29,8 +28,7 @@ import java.util.HashMap; public class ASParbillFormPlugin extends AbstractFormPlugin implements Plugin { private final static Log logger = LogFactory.getLog(ASParbillFormPlugin.class); - private final static String entryID = "shjh_details";//分录标识 - private final static String apiurl = "shjh_details";//接口地址 + private final static String entryID = "shjh_entryentity";//分录标识 private static final String QUERY_BUTTON_KEY = "shjh_btnquery";//查询按钮 private static final String SELECTED_BUTTON_KEY = "shjh_btnok";//确认勾选按钮 private static final String RESET_BUTTON_KEY = "shjh_btnreset";//重置按钮 @@ -64,6 +62,8 @@ public class ASParbillFormPlugin extends AbstractFormPlugin implements Plugin { if("clearBillForm".equals(showParam.getCustomParam("Apikey"))){ this.getView().setVisible(false, SELECTED_BUTTON_KEY); } + this.getModel().setValue("shjh_org",((JSONObject)showParam.getCustomParam("billorg")).getLong("id"));//公司从父页面带过来 + this.getModel().setValue("shjh_customer",((JSONObject)showParam.getCustomParam("billcustomer")).getLong("id"));//客户从父页面带过来 } /** @@ -84,33 +84,31 @@ public class ASParbillFormPlugin extends AbstractFormPlugin implements Plugin { String key = source.getKey(); if (StringUtils.equals(QUERY_BUTTON_KEY, key)) { // 校验和获取过滤条件 - DynamicObject org = (DynamicObject) this.getModel().getValue("shjh_orgfield"); + DynamicObject customer = (DynamicObject) this.getModel().getValue("shjh_customer"); + if (customer == null) { + this.getView().showMessage("请选择一个客户!"); + return; + } + String customerCode = customer.getString("number"); + DynamicObject org = (DynamicObject) this.getModel().getValue("shjh_org"); if (org == null) { - this.getView().showMessage("请选择公司!"); + this.getView().showMessage("请选择一个公司!"); return; } - - Date startDate = (Date) this.getModel().getValue("shjh_startdate"); - if (startDate == null) { - this.getView().showMessage("请选择开始日期!"); - return; - } - - Date endDate = (Date) this.getModel().getValue("shjh_enddate"); - if (endDate == null) { - this.getView().showMessage("请选择结束日期!"); - return; - } - - String companyCode = org.getString("number"); + String orgrCode = org.getString("number"); // 点击查询按钮 - handleQueryButtonClick(companyCode, startDate, endDate); + handleQueryButtonClick(orgrCode,customerCode); } else if (StringUtils.equals(SELECTED_BUTTON_KEY, key)) { // 点击选择按钮 handleSelectedButton(); } else if (StringUtils.equals(RESET_BUTTON_KEY, key)) { // 点击重置按钮 - this.getModel().setValue("shjh_textfield",null); + this.getModel().setValue("shjh_pzh",null);//SAP应收凭证号 + this.getModel().setValue("shjh_kmbh",null);//总账科目编号 + this.getModel().setValue("shjh_fph",null);//发票号 + this.getModel().setValue("shjh_year",null);//会计年度 + this.getModel().setValue("shjh_gzrq_startdate",null);//SAP应收凭过账日期 + this.getModel().setValue("shjh_gzrq_enddate",null);//SAP应收凭过账日期 } } catch (Exception e) { logger.error("按钮处理异常:"+e.getMessage()); @@ -118,144 +116,124 @@ public class ASParbillFormPlugin extends AbstractFormPlugin implements Plugin { } } + // 添加过滤条件到IT_LIST的方法 + public 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); + } + /** * 点击查询按钮 * @param companyCode 公司编码 - * @param startDate 开始日期 - * @param endDate 结束日期 + * @param customerCode 客户编码 */ - private void handleQueryButtonClick(String companyCode, Date startDate, Date endDate) { + private void handleQueryButtonClick(String companyCode, String customerCode) { try { FormShowParameter showParameter = this.getView().getFormShowParameter(); - String apiKey = showParameter.getCustomParam("Apikey"); String billNumber = showParameter.getCustomParam("billNumber"); - //组装入参,调用SAP接口,处理返回值 - handleSAPApi(companyCode, startDate, endDate, billNumber); - this.getView().updateView(entryID); + //组装查询入参 日期格式 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String shjh_pzh = (String) this.getModel().getValue("shjh_pzh");//SAP应收凭证号 + String shjh_kmbh = (String) this.getModel().getValue("shjh_kmbh");//会计科目编号 + String shjh_year = (String) this.getModel().getValue("shjh_year");//会计年度 + Date postingdate_start = (Date) this.getModel().getValue("shjh_gzrq_startdate");//SAP应收凭过账日期(开始) + Date postingdate_endda = (Date) this.getModel().getValue("shjh_gzrq_enddate");//SAP应收凭过账日期(结束) + JSONArray IT_LIST = new JSONArray(); + // 添加公司过滤条件 + addFilterCondition(IT_LIST, "BUKRS", companyCode, companyCode); + // 添加客户过滤条件 + addFilterCondition(IT_LIST, "KUNNR", customerCode, customerCode); + // 添加SAP应收凭证号过滤条件 + if (StringUtils.isNotEmpty(shjh_pzh)) { + addFilterCondition(IT_LIST, "BELNR", shjh_pzh, shjh_pzh); + } + // 添加会计科目编号过滤条件 + if (StringUtils.isNotEmpty(shjh_kmbh)) { + addFilterCondition(IT_LIST, "HKONT", shjh_kmbh, shjh_kmbh); + } + // 会计年度 + if (StringUtils.isNotEmpty(shjh_year)) { + addFilterCondition(IT_LIST, "GJAHR", shjh_year, shjh_year); + } + // 添加SAP应收凭过账日期过滤条件 + if (postingdate_start != null || postingdate_endda != null) { + String postingdate_starts = postingdate_start == null ? "" : sdf.format(postingdate_start); + String postingdate_enddas = postingdate_endda == null ? "" : sdf.format(postingdate_endda); + addFilterCondition(IT_LIST, "BUDAT", postingdate_starts, postingdate_enddas); + } + JSONObject sapReturnData = SapUtils.sapArAPI(IT_LIST,billNumber); + //sap返回的结果不为空且正确,执行分录插入数据 + if(sapReturnData != null && parseResponse(sapReturnData)){ + JSONObject data = sapReturnData.getJSONObject("data"); + JSONArray rows = data.getJSONArray("IT_ITEMS"); + DynamicObjectCollection entry = this.getModel().getEntryEntity(entryID); + entry.clear(); + JSONObject detail; + for (int i = 0; i < rows.size(); i++) { + detail = (JSONObject) rows.get(i); + entry.addNew(); + setEntityRowValues(detail, i); + } + this.getView().updateView(entryID); + } + } catch (Exception e) { logger.error("查询操作失败: " + e.getMessage()); this.getView().showMessage("查询操作失败"+e.getMessage()); } } - /** - * 调用SAP接口 - * @param companyCode 公司编码 - * @param startDate 开始日期 - * @param endDate 结束日期 - * @param billNumber 本单单号:日志记录用 - */ - private void handleSAPApi(String companyCode, Date startDate, Date endDate, String billNumber) { - try { - DynamicObject supplier = (DynamicObject) this.getModel().getValue("shjh_supplier"); - if (supplier == null) { - this.getView().showMessage("请选择供应商!"); - return; - } - String supplierCode = supplier.getString("number"); - String interfaceID="FMGetJahYFKList"; - HashMap head = ApiUtils.buildHead(interfaceID); - HashMap body = ApiUtils.buildBody(companyCode, null, startDate, endDate); - HashMap data = (HashMap) body.get("data"); - - // 添加额外的参数 - data.put("SupplierCode", supplierCode); - data.put("IsWriteOffDetail", true); - - String response = ApiUtils.sendPost(head, body, apiurl); - if (response != null) { - Boolean result = parseResponse(response, billNumber, String.valueOf(body), "预付款单清单查询接口"); - if (result) { - handleAspApiResponse(response); - } - } - } catch (Exception e) { - logger.error("处理SAP应收未清接口时发生错误: "+e.getMessage()); - this.getView().showMessage("处理SAP应收未清接口时发生错误!"+e.getMessage()); - } - } - - /** - * 日志记录 - * @param response 响应参数 - * @param billNumber 本单单号 - * @param body 请求体 - * @param apiName 接口名 - */ - private Boolean parseResponse(String response, String billNumber, String body, String apiName) { - JSONObject result = JSONObject.parseObject(response); + private boolean parseResponse(JSONObject result) { boolean success = false; - if (null != result) { - String code = result.getString("code"); - switch (code) { - case "0": - success = true; - EsbUtils.saveLog(billNumber, apiName, body, response, true, "ESBQueryApi", "查询成功"); - break; - case "1": - this.getView().showMessage("服务异常"); - EsbUtils.saveLog(billNumber, apiName, body, response, false, "ESBQueryApi", "服务异常"); - break; - case "2": - this.getView().showMessage("三方服务异常"); - EsbUtils.saveLog(billNumber, apiName, body, response, false, "ESBQueryApi", "三方服务异常"); - break; - case "3": - this.getView().showMessage("业务异常"); - EsbUtils.saveLog(billNumber, apiName, body, response, false, "ESBQueryApi", "业务异常"); - break; - default: - this.getView().showMessage("未知异常"); - EsbUtils.saveLog(billNumber, apiName, body, response, false, "ESBQueryApi", "未知异常"); - break; - } + String code = result.getString("code"); + String msg = result.getString("msg"); + switch (code) { + case "0": + success = true; + break; + case "1": + this.getView().showMessage("服务异常:"+msg); + break; + case "2": + this.getView().showMessage("三方服务异常:"+msg); + break; + case "3": + this.getView().showMessage("业务异常:"+msg); + break; + default: + this.getView().showMessage("未知异常:"+msg); + break; } return success; } /** - * sap接口数据解析 - * @param response 响应参数 + * 应收未清分录赋值 + * @param detail sap接口返回json分录参数 + * @param i 分录行号 */ - private void handleAspApiResponse(String response) { + private void setEntityRowValues(JSONObject detail, int i) { + //TODO 与sap沟通确认字段对应 try { - JSONObject root = JSONObject.parseObject(response); - JSONObject data = root.getJSONObject("data"); - JSONArray rows = data.getJSONArray("rows"); - DynamicObjectCollection entry = this.getModel().getEntryEntity(entryID); - entry.clear(); - for (int i = 0; i < rows.size(); i++) { - JSONObject top = (JSONObject) rows.get(i); - JSONArray loanDetailInfo = top.getJSONArray("LoanDetailInfo"); - JSONObject detail = (JSONObject) loanDetailInfo.get(0); - entry.addNew(); - setPaymentApiValues(top, detail, i); - } - } catch (Exception e) { - logger.error("SAP应收未清数据解析异常: " + e.getMessage()); - this.getView().showMessage("SAP应收未清数据解析异常!"+e.getMessage()); - } - } - - /** - * 预付单赋值 - * - * @param top json头参数 - * @param detail json分录参数 - * @param i - */ - private void setPaymentApiValues(JSONObject top, JSONObject detail, int i) { - try { - this.getModel().setValue("shjh_billno", top.getString("CompanyCode"), i); - this.getModel().setValue("shjh_prepaymentnum", top.getString("RequestCode"), i); - this.getModel().setValue("shjh_purchasenum", detail.getString("PoOrderNo"), i); - this.getModel().setValue("shjh_purchaselinenum", detail.getString("PoOrderColNo"), i); - this.getModel().setValue("shjh_billsubject", detail.getString("RequestName"), i); - this.getModel().setValue("shjh_prepaymentdate", detail.getDate("CreatedDate"), i); - this.getModel().setValue("shjh_paymentamount", top.getBigDecimal("RequestAmt"), i); - this.getModel().setValue("shjh_documentamount", top.getBigDecimal("AvailableAmt"), i); - this.getModel().setValue("shjh_verificationnum", top.getString("StrColumn20"), i); - this.getModel().setValue("shjh_fiscalyear", top.getString("GLDate").substring(0, 4), i); + this.getModel().setValue("shjh_e_pzh",detail.getString("BELNR"), i);//凭证号 + this.getModel().setValue("shjh_e_pzlx",detail.getString("BLART"), i);//凭证类型 + this.getModel().setValue("shjh_e_pzhh",detail.getString("BUZEI"), i);//凭证行项目号 + this.getModel().setValue("shjh_e_fph",detail.getString("XREF1"), i);//发票号 +// this.getModel().setValue("shjh_e_fpdate",detail.getDate(""), i);//发票日期 + this.getModel().setValue("shjh_e_account",detail.getString("HKONT"), i);// 总账科目 +// this.getModel().setValue("shjh_e_fenpei",detail.getString(""), i);// 分配 + this.getModel().setValue("shjh_e_canzhao",detail.getString("AWKEY"), i);// 参照 + this.getModel().setValue("shjh_e_ckdm1",detail.getString("XREF2"), i);//参考代码1 + this.getModel().setValue("shjh_e_ckdm2",detail.getString("XREF3"), i);// 参考代码2 +// this.getModel().setValue("shjh_e_text",detail.getString(""), i);// 文本 + this.getModel().setValue("shjh_e_gzdate",detail.getDate("BUDAT"), i);// 过账日期 + this.getModel().setValue("shjh_e_unsettle",detail.getBigDecimal("DMBTR"), i);//未核销金额 + this.getModel().setValue("shjh_e_year",detail.getString("GJAHR"), i);//会计年度 } catch (Exception e) { logger.error("分录赋值异常: " + e.getMessage()); this.getView().showMessage("分录赋值异常!"+e.getMessage()); @@ -267,19 +245,20 @@ public class ASParbillFormPlugin extends AbstractFormPlugin implements Plugin { */ private void handleSelectedButton() { try { - //清空 - PARAM_LIST.clear(); - EntryGrid entryGrid = this.getControl(entryID); + EntryGrid entryGrid = this.getView().getControl(entryID);//获得分录的控件对象 int[] selectRows = entryGrid.getSelectRows(); - DynamicObjectCollection entity = this.getModel().getEntryEntity(entryID); if (selectRows != null && selectRows.length > 0) { + DynamicObjectCollection docolls = this.getModel().getEntryEntity(entryID); + //清空返回数据包 + PARAM_LIST.clear(); + DynamicObject doinfo; for (int selectRow : selectRows) { - DynamicObject dynamicObject = entity.get(selectRow); - PARAM_LIST.add(dynamicObject); + doinfo = docolls.get(selectRow); + PARAM_LIST.add(doinfo); } this.getView().close(); } else { - this.getView().showMessage("请选中一条数据!"); + this.getView().showMessage("请选择一条明细数据!"); } } catch (Exception e) { logger.error("传递参数异常: " + e.getMessage()); diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/form/ClearBillFormPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/form/ClearBillFormPlugin.java index 6f4601a..6f05579 100644 --- a/main/java/shjh/jhzj7/fi/fi/plugin/form/ClearBillFormPlugin.java +++ b/main/java/shjh/jhzj7/fi/fi/plugin/form/ClearBillFormPlugin.java @@ -71,11 +71,13 @@ public class ClearBillFormPlugin extends AbstractFormPlugin implements Plugin { * @param apiKey 按钮来源的区分标识 */ private FormShowParameter createASPParam(String apiKey) { - HashMap map = new HashMap<>(2); + HashMap map = new HashMap<>(4); //按钮区分标识 map.put("Apikey",apiKey); - //清账明细单单号 + //清账单单号 map.put("billNumber",this.getModel().getValue("billno")); + map.put("billorg",this.getModel().getValue("org"));//清账单公司 + map.put("billcustomer",this.getModel().getValue("shjh_customer"));//清账单客户 FormShowParameter showParameter = new FormShowParameter(); //需要打开单据的标识 showParameter.setFormId(SAPFormID); @@ -89,6 +91,7 @@ public class ClearBillFormPlugin extends AbstractFormPlugin implements Plugin { } private BillShowParameter createDetailBillParam(String detailBillid) { + //组装打开清账明细单的界面参数 // HashMap map = new HashMap<>(2); // //按钮区分标识 // map.put("Apikey",apiKey); @@ -106,7 +109,7 @@ public class ClearBillFormPlugin extends AbstractFormPlugin implements Plugin { //pageid // showParameter.setPageId(); //传到目标页面的自定义参数 - showParameter.setCustomParam("Apikey","viewDetailFromClear"); + showParameter.setCustomParam("parentFromCustomParam","viewDetailFromClear"); //回调方法 // showParameter.setCloseCallBack(); return showParameter; diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/form/ClearBillListPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/form/ClearBillListPlugin.java index adbcf80..01bb6ee 100644 --- a/main/java/shjh/jhzj7/fi/fi/plugin/form/ClearBillListPlugin.java +++ b/main/java/shjh/jhzj7/fi/fi/plugin/form/ClearBillListPlugin.java @@ -30,20 +30,20 @@ public class ClearBillListPlugin extends AbstractListPlugin implements Plugin { @Override public void itemClick(ItemClickEvent evt) { super.itemClick(evt); - try { - if ("shjh_unclearacctount".equals(evt.getItemKey())) { - //点击反清账按钮 +// try { +// if ("shjh_unclearacctount".equals(evt.getItemKey())) { +// //点击反清账按钮 // FormShowParameter showParameter = createParam(evt.getItemKey(),unClearFormID); // this.getView().showForm(showParameter); - }else if("shjh_changestatus".equals(evt.getItemKey())){ - //点击修改清账单状态按钮 +// }else if("shjh_changestatus".equals(evt.getItemKey())){ +// //点击修改清账单状态按钮 // FormShowParameter showParameter = createParam(evt.getItemKey(),updateStatusFormID); // this.getView().showForm(showParameter); - } - } catch (Exception e) { - logger.error("按钮处理异常:"+e.getMessage()); - this.getView().showMessage("按钮处理异常"+e.getMessage()); - } +// } +// } catch (Exception e) { +// logger.error("按钮处理异常:"+e.getMessage()); +// this.getView().showMessage("按钮处理异常"+e.getMessage()); +// } } @Override diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/form/ClearDetailFormPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/form/ClearDetailFormPlugin.java index d7307a0..cee28e8 100644 --- a/main/java/shjh/jhzj7/fi/fi/plugin/form/ClearDetailFormPlugin.java +++ b/main/java/shjh/jhzj7/fi/fi/plugin/form/ClearDetailFormPlugin.java @@ -53,18 +53,21 @@ public class ClearDetailFormPlugin extends AbstractFormPlugin implements Plugin * 构建表单之间的传参 弹框展示SAP应收未清列表 */ private FormShowParameter createFormParameter() { - HashMap map = new HashMap<>(2); +// HashMap map = new HashMap<>(2); //按钮区分标识 // map.put("Apikey",SAP_BUTTON_KEY); - //清账明细单单号 - map.put("billNumber",this.getModel().getValue("billno")); FormShowParameter showParameter = new FormShowParameter(); //需要打开单据的标识 showParameter.setFormId(destFormID); //打开方式 showParameter.getOpenStyle().setShowType(ShowType.Modal); //传到子页面参数 - showParameter.setCustomParams(map); +// showParameter.setCustomParams(map); + showParameter.setCustomParam("billNumber",this.getModel().getValue("billno"));//清账明细单单号 + showParameter.setCustomParam("billorg",this.getModel().getValue("org"));//清账明细单公司 + showParameter.setCustomParam("billcustomer",this.getModel().getValue("shjh_customer"));//清账明细单客户 +// map.put("billorg",(DynamicObject)this.getModel().getValue("org")); +// map.put("billcustomer",(DynamicObject)this.getModel().getValue("shjh_customer")); //回调方法 showParameter.setCloseCallBack(new CloseCallBack(this, SAP_BUTTON_KEY)); return showParameter; @@ -144,7 +147,7 @@ public class ClearDetailFormPlugin extends AbstractFormPlugin implements Plugin this.getModel().setValue("shjh_e_text",returnInfo.getString("shjh_e_text"), i);// 文本 this.getModel().setValue("shjh_e_gzdate",returnInfo.getDate("shjh_e_gzdate"), i);// 过账日期 this.getModel().setValue("shjh_e_unsettle",returnInfo.getBigDecimal("shjh_e_unsettle"), i);//未核销金额 - this.getModel().setValue("shjh_e_cursettle",returnInfo.getBigDecimal("shjh_e_cursettle"), i);//本次核销金额 +// this.getModel().setValue("shjh_e_cursettle",returnInfo.getBigDecimal("shjh_e_cursettle"), i);//本次核销金额 this.getModel().setValue("shjh_e_year",returnInfo.getString("shjh_e_year"), i);//会计年度 this.getModel().setValue("shjh_e_qzpztext",returnInfo.getString("shjh_e_qzpztext"), i);// 清账凭证文本 } @@ -157,7 +160,7 @@ public class ClearDetailFormPlugin extends AbstractFormPlugin implements Plugin super.afterBindData(e); FormShowParameter showParam = this.getView().getFormShowParameter(); //如果是清账单过来的,只能进行查看 - if("viewDetailFromClear".equals(showParam.getCustomParam("Apikey"))){ + if("viewDetailFromClear".equals(showParam.getCustomParam("parentFromCustomParam"))){ this.getView().setVisible(false, "tbmain"); } } diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/form/SappzFormPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/form/SappzFormPlugin.java index 5f77931..c46f252 100644 --- a/main/java/shjh/jhzj7/fi/fi/plugin/form/SappzFormPlugin.java +++ b/main/java/shjh/jhzj7/fi/fi/plugin/form/SappzFormPlugin.java @@ -63,7 +63,7 @@ public class SappzFormPlugin extends AbstractFormPlugin { Boolean isselfprocurement = (Boolean) this.getModel().getValue("shjh_isselfprocurement");//是否自行采购 // 日期格式 - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); JSONArray IT_LIST = new JSONArray(); // 添加公司过滤条件 if (shjhOrgfield != null) { diff --git a/main/java/shjh/jhzj7/fi/fi/utils/SapUtils.java b/main/java/shjh/jhzj7/fi/fi/utils/SapUtils.java index 9ff373c..e32107a 100644 --- a/main/java/shjh/jhzj7/fi/fi/utils/SapUtils.java +++ b/main/java/shjh/jhzj7/fi/fi/utils/SapUtils.java @@ -2,7 +2,6 @@ package shjh.jhzj7.fi.fi.utils; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import kd.bos.dataentity.entity.DynamicObject; import kd.bos.logging.Log; import kd.bos.logging.LogFactory; import org.apache.http.HttpEntity; @@ -17,7 +16,6 @@ import org.apache.http.util.EntityUtils; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; @@ -45,6 +43,11 @@ public class SapUtils { // public static final String withholdingUrl = "https://hipint.jahwa.com.cn:6443/gateway//HIP_ReceiveFromFM/1.0/fm/send";//正式环境 public static final String receiverID2 = "FeiKong";//定义的发送者 + private static final String interfaceID5 = "AccountsReceivableVoucherList";//识别被调接口并进行路由 + private static final String Apimenthod5 = "SAP应收凭证清单"; + public static final String sapArUrl = "https://hipint-stg.jahwa.com.cn:6443/gateway/HIP_ReceiveFromFM/1.0/fm/send";//测试环境(SAP应收凭证清单) + // public static final String sapArUrl = "https://hipint.jahwa.com.cn:6443/gateway/HIP_ReceiveFromFM/1.0/fm/send";//正式环境 + /** * SAP应付凭证锁定解锁状态回写 */ @@ -83,6 +86,46 @@ public class SapUtils { return pendingsBody; } + /** + * SAP应收凭证清单接口 + * @param IT_LIST 过滤条件入参 + * @param billno 单据编号 + * @author yuxueliang + */ + public static JSONObject sapArAPI(JSONArray IT_LIST,String billno){ + Map thirdPartyMap = new HashMap<>(); + thirdPartyMap.put("interfaceID",interfaceID5); + thirdPartyMap.put("receiverID",receiverID1); + thirdPartyMap.put("URL",sapArUrl); + thirdPartyMap.put("billno",billno); + // 组装请求体 + JSONObject arBody = sapArBody(IT_LIST); + // 发送请求并处理响应 + return processRequest(arBody, thirdPartyMap, Apimenthod5); + } + + /** + * SAP应收凭证清单接口组装请求体 + * @param IT_LIST 过滤条件入参 + * @author yuxueliang + */ + private static JSONObject sapArBody(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());//唯一事务ID,采用UUID或其他强唯一性ID + pendingsBody.put("requestTime",dates);//请求时间,格式为yyyy-MM-dd HH:mm:ss.SSS + + JSONObject data = new JSONObject(); + data.put("IT_INPUT",IT_LIST); + pendingsBody.put("data", data); + return pendingsBody; + } /** * SAP应付凭证清单接口 @@ -251,7 +294,7 @@ public class SapUtils { private static void handleResponse(JSONObject jsonObject, JSONObject pendingsBody, Map thirdPartyMap,String apiName) { String operResult = jsonObject.getString("code"); JSONObject jsonobject = jsonObject.getJSONObject("data"); - if (jsonobject == null&&!"0".equals(operResult)) { + if (jsonobject == null && !"0".equals(operResult)) { logger.info(apiName + "失败!"); saveLog((thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, false,apiName); return;