diff --git a/main/java/shjh/jhzj7/fi/fi/webapi/PayreceiptQueryControler.java b/main/java/shjh/jhzj7/fi/fi/webapi/PayreceiptQueryControler.java index d872fdf..199b359 100644 --- a/main/java/shjh/jhzj7/fi/fi/webapi/PayreceiptQueryControler.java +++ b/main/java/shjh/jhzj7/fi/fi/webapi/PayreceiptQueryControler.java @@ -1,6 +1,7 @@ package shjh.jhzj7.fi.fi.webapi; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONException; import com.alibaba.fastjson.JSONObject; import com.drew.lang.annotations.NotNull; @@ -46,44 +47,55 @@ public class PayreceiptQueryControler { //select * from T_CAS_PaymentBill where fbillno = 'FKZJ2025030006'; 2168985504052162560 //select * from t_org_org where fid = 2116753963226241024; JSONObject json_body; - String jsonBodyString; try { // 解析入参,如果格式不正确,日志记录,并反馈esb7.4.1 json_body = (JSONObject) JSON.toJSON(PayreceiptQuerybill); - jsonBodyString = JSON.toJSONString(json_body); } catch (JSONException e) { return handleErrorAndReturn("付款电子回单查询接口入参异常:" + e.getMessage(), Apimenthod, null,apiResultExt); } - List entryBeans = new ArrayList<>(); - List items = PayreceiptQuerybill.getItems(); - for (PayreceiptQueryModel.EntryBean item : items) { - String companyNum = item.getCompanyNum();//公司编号 - String kdPayBillID = item.getKdPayBillID();//金蝶付款单ID - String fkBillID = item.getFkBillID();//费控单据主表ID - String fkEntryID = item.getFkEntryID();//费控单据分录ID - String fkBillNumber = item.getFkBillNumber();//费控单据编号 - String voucherNum = item.getVoucherNum();//付款凭证号 - String voucherYear = item.getVoucherYear();//付款凭证会计年度 + List entryBeans = new ArrayList<>();//结果返回值 + JSONArray itemarray = json_body.getJSONArray("items"); + JSONObject json_item; + String companyNum; + String kdPayBillID; + String fkBillID; + String fkEntryID; + String fkBillNumber; + String voucherNum; + String voucherYear; + DynamicObject orginfo; + DynamicObject paybill; + ApiResultExt.EntryBean entryBean; + for (int i = 0; i < itemarray.size(); i++) { + json_item = itemarray.getJSONObject(i); + companyNum = json_item.getString("companyNum");//公司编号 + kdPayBillID = json_item.getString("kdPayBillID");//金蝶付款单ID + fkBillID = json_item.getString("fkBillID");//费控单据主表ID + fkEntryID = json_item.getString("fkEntryID");//费控单据分录ID + fkBillNumber = json_item.getString("fkBillNumber");//费控单据编号 + voucherNum = json_item.getString("voucherNum");//付款凭证号 + voucherYear = json_item.getString("voucherYear");//付款凭证会计年度 - DynamicObject org = loadOrgByCompanyNum(companyNum); - if (org == null) { - handleError("查询失败,费控单据编号:" + fkBillNumber + "的组织编码不存在", fkBillNumber, jsonBodyString); + orginfo = loadOrgByCompanyNum(companyNum); + if (orginfo == null) { + handleError("查询失败,费控单据编号:" + fkBillNumber + "的组织编码不存在", fkBillNumber, json_item.toJSONString()); + continue; } QFilter q1 = new QFilter("openorg.number", QCP.equals, companyNum);//公司编号 - if (kdPayBillID != null && !kdPayBillID.isEmpty()) { + if (!JhzjUtils.isEmpty(kdPayBillID)) { q1 = addFilterIfNotNull(q1, "id", Long.valueOf(kdPayBillID));//金蝶付款单ID } q1 = addFilterIfNotEmpty(q1, "shjh_fkbillid", fkBillID);//费控单据主表ID q1 = addFilterIfNotEmpty(q1, "shjh_fkentryid", fkEntryID);//费控单据分录ID q1 = addFilterIfNotEmpty(q1, "entry.shjh_fkdjbh", fkBillNumber);//费控单据编号-外部系统单号 - q1 = addFilterIfNotEmpty(q1, "shjh_credentialnum", voucherNum);//付款凭证号 - q1 = addFilterIfNotEmpty(q1, "shjh_sapfiscalyear", voucherYear);//付款凭证年份 - DynamicObject paybill = BusinessDataServiceHelper.loadSingle(paybillName, new QFilter[]{q1}); + q1 = addFilterIfNotEmpty(q1, "entry.shjh_vouchernums", voucherNum);//应付凭证号 + q1 = addFilterIfNotEmpty(q1, "entry.shjh_voucheryear", voucherYear);//应付凭证年份 + paybill = BusinessDataServiceHelper.loadSingle(paybillName, new QFilter[]{q1}); //申明此次查询的返回值 - ApiResultExt.EntryBean entryBean = new ApiResultExt.EntryBean(); + entryBean = new ApiResultExt.EntryBean(); entryBean.setCompanyNum(companyNum);//公司编号 entryBean.setKdPayBillID(kdPayBillID);//金蝶付款单ID entryBean.setFkBillID(fkBillID);//费控单据主表ID @@ -94,7 +106,11 @@ public class PayreceiptQueryControler { entryBean.setReceipturl("");//电子回单路径 entryBeans.add(entryBean); if (null == paybill) { - handleError("查询失败:付款单不存在", fkEntryID, jsonBodyString); + if(JhzjUtils.isEmpty(fkEntryID)){ + //说明本次是sap来查询的,不是费控来查询的 + fkEntryID = voucherNum; + } + handleError("查询失败:付款单不存在", fkEntryID, json_item.toJSONString()); continue; } //查询电子回单,返回pdf url @@ -141,23 +157,27 @@ public class PayreceiptQueryControler { // } } catch (Exception var11) { logger.error("电子回单获取文件路径异常: " + var11.getMessage()); - handleError("查询失败:电子回单获取文件路径异常", receiptNo, jsonBodyString); + handleError("查询失败:电子回单获取文件路径异常", receiptNo, json_item.toJSONString()); } } else { logger.warn(receiptNo + "回单为非文件类回单"); - handleError("查询失败:回单为非文件类回单", receiptNo, jsonBodyString); + handleError("查询失败:回单为非文件类回单", receiptNo, json_item.toJSONString()); } }else{ - handleError("查询失败:电子回单不存在", eReceiptid+"", jsonBodyString); + handleError("查询失败:电子回单不存在", eReceiptid+"", json_item.toJSONString()); } }else{ - handleError("查询失败:交易明细未关联电子回单", edetailbillno, jsonBodyString); + handleError("查询失败:交易明细未关联电子回单", edetailbillno, json_item.toJSONString()); } }else{ - handleError("查询失败:交易明细编号不存在", edetailbillno, jsonBodyString); + handleError("查询失败:交易明细编号不存在", edetailbillno, json_item.toJSONString()); } }else{ - handleError("查询失败:付款单未关联交易明细", fkEntryID, jsonBodyString); + if(JhzjUtils.isEmpty(fkEntryID)){ + //说明本次是sap来查询的,不是费控来查询的 + fkEntryID = voucherNum; + } + handleError("查询失败:付款单未关联交易明细", fkEntryID, json_item.toJSONString()); } } return handleSuccessAndReturn(apiResultExt, entryBeans);