From b4cfd0aaf6ea704e109c459c9427251e32a2006a Mon Sep 17 00:00:00 2001 From: zoujiangtao Date: Tue, 12 Nov 2024 17:36:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A=E9=82=B9?= =?UTF-8?q?=E6=B1=9F=E6=B6=9B=20=E4=BF=AE=E6=94=B9=E5=86=85=E5=AE=B9?= =?UTF-8?q?=EF=BC=9AAPI=E5=85=A5=E5=8F=82=E5=87=BA=E5=8F=82=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4=EF=BC=9A2024/1?= =?UTF-8?q?1/12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sys/plugin/api/PayBillApiSavePlugin.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java index db952ff..976e223 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java @@ -6,6 +6,8 @@ import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.logging.Log; +import kd.bos.logging.LogFactory; import kd.bos.openapi.api.plugin.ApiSavePlugin; import kd.bos.openapi.api.plugin.ApiSerializerPlugin; import kd.bos.openapi.api.plugin.SerializerResult; @@ -24,13 +26,14 @@ import java.util.Map; * @Date 2024/11/7 */ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin { + private static final Log logger = LogFactory.getLog(PayBillApiSavePlugin.class); private static final long serialVersionUID = 7055073356277386444L; private String shkd_businessid; private String shkd_businessnumber; @Override public List> preHandleRequestData(List> reqData) { - + logger.info("接口调用接口参数:{}", reqData); //付款处理 → 收款人ID payee → 付款银行.编码 payerbank_number payeetype 收款人类型 → payeenumber 收款人编码 //payeracctbank_number 付款银行账号.number @@ -51,6 +54,7 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin Object payeetype = map.get("payeetype");//如果是收款人类型 则为付款处理保存接口 Object payertype = map.get("payertype");//如果是付款人类型 则为收款处理保存接口 if (payeetype != null) { + logger.info("进入付款处理单API"); objectType = payeetype.toString(); objectNumber = map.get("payeenumber").toString(); fieldName1 = "payee"; @@ -58,12 +62,14 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin bankNumber = map.get("payeracctbank_number").toString(); fieldName2 = "payerbank_number"; DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray()); + logger.info("objectType:{},objectNumber:{}", objectType, objectNumber); DynamicObject amAccountbank = BusinessDataServiceHelper.loadSingle("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray()); + logger.info("amAccountbank:{}", amAccountbank); map.put(fieldName1, dynamicObject.getString("id")); map.put(fieldName2, amAccountbank.getDynamicObject("bank").getString("number")); } - if (payertype != null){ + if (payertype != null) { objectType = payertype.toString(); objectNumber = map.get("payernumber").toString(); fieldName1 = "payer"; @@ -71,7 +77,9 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin bankNumber = map.get("accountbank_number").toString(); fieldName2 = "payeebank_number"; DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray()); + logger.info("objectType:{},objectNumber:{}", objectType, objectNumber); DynamicObject amAccountbank = BusinessDataServiceHelper.loadSingle("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray()); + logger.info("amAccountbank:{}", amAccountbank); map.put(fieldName1, dynamicObject.getString("id")); map.put(fieldName2, amAccountbank.getDynamicObject("bank").getString("number")); } @@ -80,14 +88,17 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin // shkd_businessid // shkd_businessnumber // shkd_businessname + logger.info("最终处理 → 调用接口参数:{}", reqData); } return reqData; } @Override public SerializerResult serialize(Object response, String accept, String contentType) { + logger.info("进入serialize方法"); try { if (contentType.contains(MediaType.APPLICATION_JSON)) { + logger.info("进入if"); //返回text文本 String responseStr = new ObjectMapper().writeValueAsString(response); JSONObject jsonObject = JSON.parseObject(responseStr); @@ -100,13 +111,15 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin result.getJSONObject(0).put("shkd_businessnumber", shkd_businessnumber); return new SerializerResult(MediaType.TEXT_PLAIN, jsonObject.toJSONString()); } else { + logger.info("进入else"); //其他类型的出参序列化 return null; } } catch (JsonProcessingException e) { + logger.info("catch"); //处理异常时严禁抛出异常,可以定义自己的错误返回信息 - String result="..."; - return new SerializerResult(MediaType.TEXT_PLAIN,result); + String result = "..."; + return new SerializerResult(MediaType.TEXT_PLAIN, result); } } }