diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/form/FeeControlApiPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/form/FeeControlApiPlugin.java index ea3ace5..c2a2331 100644 --- a/main/java/shjh/jhzj7/fi/fi/plugin/form/FeeControlApiPlugin.java +++ b/main/java/shjh/jhzj7/fi/fi/plugin/form/FeeControlApiPlugin.java @@ -129,16 +129,20 @@ public class FeeControlApiPlugin extends AbstractFormPlugin implements Plugin { String supplierCode = supplier.getString("number"); HashMap head = ApiUtils.buildHead(); - HashMap body = ApiUtils.buildBody(companyCode, this.getUserCode(), startDate.toString(), endDate.toString()); + HashMap body = ApiUtils.buildBody(companyCode, this.getUserCode(), startDate, endDate); HashMap data = (HashMap) body.get("data"); // 添加额外的参数 data.put("SupplierCode", supplierCode); data.put("IsWriteOffDetail", true); - //String response = ApiUtils.sendPost(head, body, "预付款清单接口地址", billNumber, "预付款清单接口", "Query"); - //handlePaymentApiResponse(response); - handlePaymentApiResponse(); + String response = ApiUtils.sendPost(head, body, "https://hipint-stg.jahwa.com.cn:6443/gateway/HIP_ReceiveFromFM/1.0/fm/send"); + if (response!=null){ + Boolean result = parseResponse(response, billNumber, String.valueOf(body), "预付款单清单查询接口"); + if (result){ + handlePaymentApiResponse(response); + } + } } catch (Exception e) { logger.error("Error in handlePaymentApi: " + e.getMessage(), e); this.getView().showMessage("处理预付款清单接口时发生错误!"); @@ -148,21 +152,24 @@ public class FeeControlApiPlugin extends AbstractFormPlugin implements Plugin { private void handleLoanApi(String companyCode, Date startDate, Date endDate, String billNumber) { try { HashMap head = ApiUtils.buildHead(); - HashMap body = ApiUtils.buildBody(companyCode, this.getUserCode(), startDate.toString(), endDate.toString()); - //String response = ApiUtils.sendPost(head, body, "借款单清单接口地址", billNumber, "借款单清单接口", "Query"); - //handleLoanApiResponse(response); - handleLoanApiResponse(); + HashMap body = ApiUtils.buildBody(companyCode, this.getUserCode(), startDate, endDate); + String response = ApiUtils.sendPost(head, body, "https://hipint-stg.jahwa.com.cn:6443/gateway/HIP_ReceiveFromFM/1.0/fm/send"); + if (response!=null){ + Boolean result = parseResponse(response, billNumber, String.valueOf(body), "借款单清单查询接口"); + if (result){ + handleLoanApiResponse(response); + } + } } catch (Exception e) { logger.error("Error in handleLoanApi: " + e.getMessage(), e); this.getView().showMessage("处理借款单清单接口时发生错误!"); } } - private void handlePaymentApiResponse() { + private void handlePaymentApiResponse(String response) { try { hideLoanFields(); //获取测试数据 - String response = getPaymentApiResponse(); JSONObject root = JSONObject.parseObject(response); JSONObject data = root.getJSONObject("data"); JSONArray rows = data.getJSONArray("rows"); @@ -180,105 +187,26 @@ public class FeeControlApiPlugin extends AbstractFormPlugin implements Plugin { } } - private String getPaymentApiResponse() { - return "{\n" + - " \"rootContextID\": \"8as6dfasd6f98as7d6f9a98sd76f\",\n" + - " \"code\": \"0\",\n" + - " \"msg\": \"成功\",\n" + - " \"data\": {\n" + - " \"total\": 2,\n" + - " \"rows\": [\n" + - " {\n" + - " \"ID\": \"fc7443ac-9f85-4d17-a7ee-5620330f28a6\",\n" + - " \"RequestCode\": \"YFK2025010900001\",\n" + - " \"RequestAmt\": 111,\n" + - " \"RequestDate\": \"2025-01-09 11:29:22\",\n" + - " \"GLDate\": \"2025-01-14 00:00:00\",\n" + - " \"RequestUserName\": \"余超\",\n" + - " \"AvailableAmt\": 111,\n" + - " \"SupplierId\": 89948,\n" + - " \"SupplierId_Name\": \"品销宝\",\n" + - " \"CompanyCode\": \"C021\",\n" + - " \"CompanyName\": \"上海家化电子商务有限公司\",\n" + - " \"RequestRemark\": \"测试\",\n" + - " \"LoanDetailInfo\": [\n" + - " {\n" + - " \"BillHeaderID\": \"fc7443ac-9f85-4d17-a7ee-5620330f28a6\",\n" + - " \"PoOrderNo\": null,\n" + - " \"PoOrderColNo\": null,\n" + - " \"DetailID\": \"d7bc66bf-11e7-4ef5-9d98-80881c1caff7\",\n" + - " \"ApplyAmt\": 111,\n" + - " \"ThisAmt\": null,\n" + - " \"AvailableAmt\": 111,\n" + - " \"RequestCode\": \"YFK2025010900001\",\n" + - " \"RequestName\": \"2025-01-09对公预付款单\",\n" + - " \"RequestAmt\": 111,\n" + - " \"InitialAmount\": 111,\n" + - " \"Remark\": \"测试\",\n" + - " \"CreatedDate\": \"2025-01-09 11:29:11\",\n" + - " \"ExpenseItemName\": \"会务费\",\n" + - " \"CurrencyId\": 10510,\n" + - " \"BillAvailableAmt\": 111\n" + - " }\n" + - " ]\n" + - " },\n" + - " {\n" + - " \"ID\": \"fc7443ac-9f65-4d17-a7ee-5620330f28a6\",\n" + - " \"RequestCode\": \"YFK2025010900002\",\n" + - " \"RequestAmt\": 100,\n" + - " \"RequestDate\": \"2025-02-18 11:29:22\",\n" + - " \"GLDate\": \"2025-01-14 00:00:00\",\n" + - " \"RequestUserName\": \"余超\",\n" + - " \"AvailableAmt\": 100,\n" + - " \"SupplierId\": 89949,\n" + - " \"SupplierId_Name\": \"雀氏\",\n" + - " \"CompanyCode\": \"C021\",\n" + - " \"CompanyName\": \"上海家化电子商务有限公司\",\n" + - " \"RequestRemark\": \"测试\",\n" + - " \"LoanDetailInfo\": [\n" + - " {\n" + - " \"BillHeaderID\": \"fc7443ac-9f65-4d17-a7ee-5620330f28a6\",\n" + - " \"PoOrderNo\": null,\n" + - " \"PoOrderColNo\": null,\n" + - " \"DetailID\": \"d7bc66bf-11e7-4ef5-9d98-80881c1caff3\",\n" + - " \"ApplyAmt\": 100,\n" + - " \"ThisAmt\": null,\n" + - " \"AvailableAmt\": 100,\n" + - " \"RequestCode\": \"YFK2025010900002\",\n" + - " \"RequestName\": \"2025-02-18对公预付款单\",\n" + - " \"RequestAmt\": 100,\n" + - " \"InitialAmount\": 100,\n" + - " \"Remark\": \"测试\",\n" + - " \"CreatedDate\": \"2025-02-18 11:29:11\",\n" + - " \"ExpenseItemName\": \"会务费\",\n" + - " \"CurrencyId\": 10511,\n" + - " \"BillAvailableAmt\": 100\n" + - " }\n" + - " ]\n" + - " }\n" + - " ]\n" + - " }\n" + - "}\n"; - } - 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); } catch (Exception e) { logger.error("预付单赋值异常: " + e.getMessage(), e); } } - private void handleLoanApiResponse() { + private void handleLoanApiResponse(String response) { try { hidePaymentFields(); - String response = getLoanApiResponse(); JSONObject root = JSONObject.parseObject(response); JSONObject data = root.getJSONObject("data"); JSONArray rows = data.getJSONArray("rows"); @@ -294,38 +222,6 @@ public class FeeControlApiPlugin extends AbstractFormPlugin implements Plugin { } } - private String getLoanApiResponse() { - - return "{\n" + - " \"rootContextID\": \"8as6dfasd6f98as7d6f9a98sd76f\",\n" + - " \"code\": \"0\",\n" + - " \"msg\": \"成功\",\n" + - " \"data\": {\n" + - " \"total\": 1,\n" + - " \"rows\": [\n" + - " {\n" + - " \"ID\": \"a50547a4-d661-486b-a5c0-adecdbe958b9\",\n" + - " \"RequestCode\": \"JKY2025011400001\",\n" + - " \"RequestName\": \"财务及分销系统余超2025-01-14员工借款单员工借款员工借款\",\n" + - " \"RequestAmt\": 111,\n" + - " \"RequestDate\": \"2025-01-14 14:57:13\",\n" + - " \"GLDate\": \"2025-01-14 00:00:00\",\n" + - " \"RequestUserName\": \"余超\",\n" + - " \"AvailableAmt\": 111,\n" + - " \"CurrencyName\": \"人民币\",\n" + - " \"StrColumn6\": \"6217001180014130648\",\n" + - " \"StrColumn7\": \"建设银行\",\n" + - " \"CompanyCode\": \"C001\",\n" + - " \"CompanyName\": \"上海家化联合股份有限公司\",\n" + - " \"RequestRemark\": \"上传\",\n" + - " \"StrColumn20\": \"1600000001\",\n" + - " \"LoanDetailInfo\": null\n" + - " }\n" + - " ]\n" + - " }\n" + - "}\n"; - } - private void setLoanApiValues(JSONObject top, int i) { try { this.getModel().setValue("shjh_billno", top.getString("CompanyCode"), i); @@ -410,4 +306,35 @@ public class FeeControlApiPlugin extends AbstractFormPlugin implements Plugin { return number; } - } \ No newline at end of file + + private Boolean parseResponse(String response,String billNumber,String body,String apiName){ + JSONObject result = JSONObject.parseObject(response); + 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; + } + } + return success; + } +} \ No newline at end of file diff --git a/main/java/shjh/jhzj7/fi/fi/utils/ApiUtils.java b/main/java/shjh/jhzj7/fi/fi/utils/ApiUtils.java index 0a61ac8..d208918 100644 --- a/main/java/shjh/jhzj7/fi/fi/utils/ApiUtils.java +++ b/main/java/shjh/jhzj7/fi/fi/utils/ApiUtils.java @@ -32,7 +32,7 @@ public class ApiUtils { return header; } - public static HashMap buildBody(String companyCode,String userCode,String queryBeginDate,String queryEndDate){ + public static HashMap buildBody(String companyCode,String userCode,Date queryBeginDate,Date queryEndDate){ // 生成唯一事务ID String rootContextId = UUID.randomUUID().toString(); // 获取当前请求时间,格式为 yyyy-MM-dd HH:mm:ss.SSS @@ -43,8 +43,8 @@ public class ApiUtils { body.put("requestTime",requestTime); HashMap data = new HashMap<>(10); data.put("UserCode",userCode); - data.put("QueryBeginDate",queryBeginDate); - data.put("QueryEndDate",queryEndDate); + data.put("QueryBeginDate",sdf.format(queryBeginDate)); + data.put("QueryEndDate",sdf.format(queryEndDate)); data.put("page","1"); data.put("rows","10"); data.put("CompanyCode",companyCode); @@ -60,7 +60,7 @@ public class ApiUtils { * @return * @throws IOException */ - public static String sendPost(HashMap header, HashMap body, String url ,String billNumber,String api,String processName) throws IOException { + public static String sendPost(HashMap header, HashMap body, String url) throws IOException { String responseData = ""; // 准备要发送的 JSON 数据 // 使用 FastJSON 将 Map 转换为 JSON 字符串 @@ -82,10 +82,8 @@ public class ApiUtils { // 获取响应数据 responseData = EntityUtils.toString(response.getEntity()); log.info("SendPost,Response: " + responseData); - EsbUtils.saveLog(billNumber,api,httpPost.toString(),response.toString(),true,processName); } else { log.info("SendPost,Error: " + response.getStatusLine().getStatusCode()); - EsbUtils.saveLog(billNumber,api,httpPost.toString(),response.toString(),false,processName); } return responseData; } diff --git a/main/java/shjh/jhzj7/fi/fi/utils/EsbUtils.java b/main/java/shjh/jhzj7/fi/fi/utils/EsbUtils.java index 211489d..fc5ea8e 100644 --- a/main/java/shjh/jhzj7/fi/fi/utils/EsbUtils.java +++ b/main/java/shjh/jhzj7/fi/fi/utils/EsbUtils.java @@ -184,4 +184,21 @@ public class EsbUtils { billinfo.set("creator",currUserId); SaveServiceHelper.save(new DynamicObject[]{billinfo}); } + + public static void saveLog(String billno,String jkname,String inputs,String outputs,boolean isSuccess,String operation,String responseCode){ + //保存星瀚与第三方接口调用之间的日志记录 + //参数说明:单据编号、接口名称、接口入参、接口返回值、接口执行结果是否成功、操作名称(audit、unaudit等)、响应码 + DynamicObject billinfo = BusinessDataServiceHelper.newDynamicObject(jklogEntityName); + billinfo.set("number",billno); + billinfo.set("name",jkname); + billinfo.set("shjh_inputs_tag",inputs); + billinfo.set("shjh_outputs_tag",outputs); + billinfo.set("shjh_issuccess",isSuccess); + billinfo.set("shjh_operation",operation); + billinfo.set("shjh_responsecode",responseCode); + billinfo.set("status","A"); + long currUserId = RequestContext.get().getCurrUserId(); + billinfo.set("creator",currUserId); + SaveServiceHelper.save(new DynamicObject[]{billinfo}); + } }