Merge remote-tracking branch 'origin/main'

This commit is contained in:
yuxueliang0813 2025-03-03 18:28:56 +08:00
commit 4351f3bc65
3 changed files with 224 additions and 81 deletions

View File

@ -128,11 +128,11 @@ public class todoZyTaskServiceHandler extends AbstractMessageServiceHandler {
Map<String, Object> thirdPartyMap = new HashMap<>(); Map<String, Object> thirdPartyMap = new HashMap<>();
thirdPartyMap.put("syscode", "jindie");// 异构系统标识 // thirdPartyMap.put("syscode", "jindie");// 异构系统标识
thirdPartyMap.put("flowid", taskId);// 流程任务ID流程数据的标识可自定义 thirdPartyMap.put("flowid", taskId);// 流程任务ID流程数据的标识可自定义
thirdPartyMap.put("requestname", title);// 标题 thirdPartyMap.put("requestname", title);// 标题
thirdPartyMap.put("approversLists", approversLists);// 审批人集合 thirdPartyMap.put("approversLists", approversLists);// 审批人集合
thirdPartyMap.put("workflowname", "流程类型名称");// todo:流程类型名称 // thirdPartyMap.put("workflowname", "流程类型名称");// todo:流程类型名称
thirdPartyMap.put("nodename", executionName);// 步骤名称节点名称 thirdPartyMap.put("nodename", executionName);// 步骤名称节点名称
thirdPartyMap.put("pcurl", url);// PC地址第三方系统中流程处理界面的PC端地址 thirdPartyMap.put("pcurl", url);// PC地址第三方系统中流程处理界面的PC端地址
thirdPartyMap.put("appurl", appurl);// APP地址第三方系统中流程处理界面的移动端地址 thirdPartyMap.put("appurl", appurl);// APP地址第三方系统中流程处理界面的移动端地址

View File

@ -50,8 +50,8 @@ public class OAUtils {
Map<String, String> customerHeader = new HashMap<>(); Map<String, String> customerHeader = new HashMap<>();
customerHeader.put("Content-Type", "application/json;charset=UTF-8");//请求报文类型 customerHeader.put("Content-Type", "application/json;charset=UTF-8");//请求报文类型
customerHeader.put("x-Gateway-APIKey",oaAPIKey);//apiKey,由ESB提供 customerHeader.put("x-Gateway-APIKey",oaAPIKey);//apiKey,由ESB提供
customerHeader.put("interfaceID", "TodoFlow");//todo:识别被调接口并进行路由 customerHeader.put("interfaceID", "TodoFlow");//识别被调接口并进行路由
customerHeader.put("senderID", "FM");//定义的发送者.暂定工号 customerHeader.put("senderID", "FM");//定义的发送者
return customerHeader; return customerHeader;
} }
@ -64,24 +64,24 @@ public class OAUtils {
//组装请求体 //组装请求体
JSONObject pendingsBody = new JSONObject(); JSONObject pendingsBody = new JSONObject();
pendingsBody.put("rootContextID", ""+System.currentTimeMillis());//todo:唯一事务ID采用UUID或其他强唯一性ID pendingsBody.put("rootContextID", ""+System.currentTimeMillis());//todo:唯一事务ID采用UUID或其他强唯一性ID
pendingsBody.put("requestTime", String.valueOf(thirdPartyMap.get("createDateStr1")));//请求时间,格式为yyyy-MM-dd HH:mm:ss.SSS pendingsBody.put("requestTime", ""+(thirdPartyMap.get("createDateStr1")));//请求时间,格式为yyyy-MM-dd HH:mm:ss.SSS
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("syscode", String.valueOf(thirdPartyMap.get("syscode")));//异构系统标识 jsonObject.put("syscode", "jindie");//异构系统标识
jsonObject.put("flowid", String.valueOf(thirdPartyMap.get("flowid")));//流程任务ID流程数据的标识可自定义 jsonObject.put("flowid", ""+(thirdPartyMap.get("flowid")));//流程任务ID流程数据的标识可自定义
jsonObject.put("requestname", String.valueOf(thirdPartyMap.get("requestname")));//标题 jsonObject.put("requestname", ""+(thirdPartyMap.get("requestname")));//标题
jsonObject.put("workflowname", "流程类型测试用");//todo:流程类型名称 jsonObject.put("workflowname", "流程类型测试用");
jsonObject.put("nodename", String.valueOf(thirdPartyMap.get("nodename")));//步骤名称节点名称 jsonObject.put("nodename", ""+(thirdPartyMap.get("nodename")));//步骤名称节点名称
jsonObject.put("pcurl", String.valueOf(thirdPartyMap.get("pcurl")));//PC地址第三方系统中流程处理界面的PC端地址 jsonObject.put("pcurl", ""+(thirdPartyMap.get("pcurl")));//PC地址第三方系统中流程处理界面的PC端地址
jsonObject.put("appurl", String.valueOf(thirdPartyMap.get("appurl")));//APP地址第三方系统中流程处理界面的移动端地址 jsonObject.put("appurl", ""+(thirdPartyMap.get("appurl")));//APP地址第三方系统中流程处理界面的移动端地址
jsonObject.put("isremark", String.valueOf(thirdPartyMap.get("isremark")));//流程处理状态0待办 2已办 4办结 jsonObject.put("isremark", ""+(thirdPartyMap.get("isremark")));//流程处理状态0待办 2已办 4办结
jsonObject.put("viewtype", String.valueOf(thirdPartyMap.get("viewtype")));//流程查看状态0未读1已读 jsonObject.put("viewtype", ""+(thirdPartyMap.get("viewtype")));//流程查看状态0未读1已读
// jsonObject.put("creator", String.valueOf(thirdPartyMap.get("creator")));//创建人工号 jsonObject.put("creator", ""+(thirdPartyMap.get("creator")));//创建人工号
jsonObject.put("creator", "GH001657");//创建人工号 // jsonObject.put("creator", "GH001657");//创建人工号
jsonObject.put("createdatetime", String.valueOf(thirdPartyMap.get("createDateStr")));//创建日期时间格式yyyy-MM-dd HH:mm:ss jsonObject.put("createdatetime", ""+(thirdPartyMap.get("createDateStr")));//创建日期时间格式yyyy-MM-dd HH:mm:ss
// jsonObject.put("receiver", String.valueOf(thirdPartyMap.get("receiver")));//接收人工号 可以传多个以英文逗号分隔 jsonObject.put("receiver", ""+(thirdPartyMap.get("receiver")));//接收人工号 可以传多个以英文逗号分隔
jsonObject.put("receiver", "GH001657");//接收人工号 可以传多个以英文逗号分隔 // jsonObject.put("receiver", "GH001657");//接收人工号 可以传多个以英文逗号分隔
jsonObject.put("receivedatetime", String.valueOf(thirdPartyMap.get("receivedatetime")));//接收日期时间格式yyyy-MM-dd HH:mm:ss jsonObject.put("receivedatetime", ""+(thirdPartyMap.get("receivedatetime")));//接收日期时间格式yyyy-MM-dd HH:mm:ss
pendingsBody.put("data", jsonObject); pendingsBody.put("data", jsonObject);
return pendingsBody; return pendingsBody;
} }
@ -98,7 +98,7 @@ public class OAUtils {
JSONObject jsonObject = null; JSONObject jsonObject = null;
try { try {
// 发送POST请求并获取响应 // 发送POST请求并获取响应
pendingPostjson = HttpClientUtils.postjson(OAUtils.oaUrl, customerHeader, pendingsBody.toJSONString()); pendingPostjson = HttpClientUtils.postjson(oaUrl, customerHeader, pendingsBody.toJSONString());
jsonObject = parseResponse(pendingPostjson); jsonObject = parseResponse(pendingPostjson);
// 检查JSON对象是否为空 // 检查JSON对象是否为空
@ -106,7 +106,7 @@ public class OAUtils {
handleResponse(jsonObject, pendingsBody, thirdPartyMap); handleResponse(jsonObject, pendingsBody, thirdPartyMap);
}else { }else {
logger.info("推送OA消息失败"); logger.info("推送OA消息失败");
saveLog("待办:" + String.valueOf(thirdPartyMap.get("billno")), pendingsBody, jsonObject, false); saveLog("待办:" +(thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, false);
} }
} catch (Exception e) { } catch (Exception e) {
handleException(e, pendingsBody, thirdPartyMap, jsonObject); handleException(e, pendingsBody, thirdPartyMap, jsonObject);
@ -137,7 +137,7 @@ public class OAUtils {
JSONObject data = jsonObject.getJSONObject("data"); JSONObject data = jsonObject.getJSONObject("data");
if (data == null || data.isEmpty()) { if (data == null || data.isEmpty()) {
logger.info("推送OA消息失败"); logger.info("推送OA消息失败");
saveLog("待办:" + String.valueOf(thirdPartyMap.get("billno")), pendingsBody, jsonObject, false); saveLog("待办:" + (thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, false);
return; return;
} }
String operResult = data.getString("operResult"); String operResult = data.getString("operResult");
@ -145,7 +145,7 @@ public class OAUtils {
// 记录日志 // 记录日志
logger.info(logMessage); logger.info(logMessage);
saveLog("待办:" + String.valueOf(thirdPartyMap.get("billno")), pendingsBody, jsonObject, true); saveLog("待办:" + (thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, true);
} }
/** /**
@ -159,14 +159,14 @@ public class OAUtils {
// 记录异常信息 // 记录异常信息
String errorMessage = String.format("待办接口异常:%s", e.getMessage()); String errorMessage = String.format("待办接口异常:%s", e.getMessage());
logger.error(errorMessage); logger.error(errorMessage);
saveLog("待办:" + String.valueOf(thirdPartyMap.get("billno")), pendingsBody, jsonObject, false); saveLog("待办:" + (thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, false);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
/** /**
* 保存日志 * 保存日志
* *
* @param billNo 单号 * @param billNo 单号
* @param pendingsBody 请求体 * @param pendingsBody 请求体
* @param jsonObject 响应的 JSON 对象 * @param jsonObject 响应的 JSON 对象
* @param isSuccess 是否成功 * @param isSuccess 是否成功

View File

@ -7,6 +7,7 @@ import kd.bos.logging.Log;
import kd.bos.logging.LogFactory; import kd.bos.logging.LogFactory;
import kd.bos.util.HttpClientUtils; import kd.bos.util.HttpClientUtils;
import java.sql.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -14,23 +15,27 @@ import java.util.Objects;
/** /**
* SAP集成工具类 * SAP集成工具类
* SAP应付凭证锁定解锁状态回写
*/ */
public class SapUtils { public class SapUtils {
public static final String oaUrl = "https://hipint-stg.jahwa.com.cn:6443/gateway/HIP_ReceiveFromFM/1.0/fm/send";//测试环境
public static final String oaAPIKey = "207b5296-9866-4b4b-8146-1fea58b3c8c9";//测试环境APIKey
private static final Log logger = LogFactory.getLog(SapUtils.class); private static final Log logger = LogFactory.getLog(SapUtils.class);
private static final String Apimenthod = " SAP应付凭证锁定解锁状态回写接口"; public static final String APIKey = "207b5296-9866-4b4b-8146-1fea58b3c8c9";//测试环境APIKey
// public static final String APIKey = "8281da80-b39b-48c4-83bd-f8e480740c6a";//测试环境APIKey
private static final String Apimenthod1 = "SAP应付凭证锁定解锁状态回写接口";
private static final String interfaceID1 = "PayableVoucherStatus";//识别被调接口并进行路由
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";//识别被调接口并进行路由
public static void thirdParty(Map<String, Object> thirdPartyMap) { 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";//正式环境
Map<String, String> customerHeader = buildCustomerHeader(thirdPartyMap); public static final String receiverID1 = "SAP";//定义的发送者
// 组装请求体 private static final String Apimenthod3 = "生成代扣款记账单接口";
JSONObject pendingsBody = buildPendingsBody(thirdPartyMap); private static final String interfaceID3 = "FMCreateDKKRecord";//识别被调接口并进行路由
// 发送请求并处理响应 public static final String withholdingUrl = "https://hipint-stg.jahwa.com.cn:6443/gateway//HIP_ReceiveFromFM/1.0/fm/send";//测试环境(生成代扣款记账单)
processRequest(customerHeader, pendingsBody, thirdPartyMap); // public static final String withholdingUrl = "https://hipint.jahwa.com.cn:6443/gateway//HIP_ReceiveFromFM/1.0/fm/send";//正式环境
} public static final String receiverID2 = "FeiKong";//定义的发送者
/** /**
* 构建请求头 * 构建请求头
@ -40,37 +45,167 @@ public class SapUtils {
private static Map<String, String> buildCustomerHeader(Map<String, Object> thirdPartyMap) { private static Map<String, String> buildCustomerHeader(Map<String, Object> thirdPartyMap) {
Map<String, String> customerHeader = new HashMap<>(); Map<String, String> customerHeader = new HashMap<>();
customerHeader.put("Content-Type", "application/json;charset=UTF-8");//请求报文类型 customerHeader.put("Content-Type", "application/json;charset=UTF-8");//请求报文类型
customerHeader.put("x-Gateway-APIKey",oaAPIKey);//apiKey,由ESB提供 customerHeader.put("x-Gateway-APIKey",APIKey);//apiKey,由ESB提供
customerHeader.put("interfaceID", "TodoFlow");//todo:识别被调接口并进行路由 customerHeader.put("interfaceID", ""+thirdPartyMap.get("interfaceID"));//识别被调接口并进行路由
customerHeader.put("senderID", String.valueOf(thirdPartyMap.get("cname")));//TODO:定义的发送者.暂定工号 customerHeader.put("receiverID", ""+thirdPartyMap.get("receiverID"));
return customerHeader; return customerHeader;
} }
/** /**
* 组装请求体 * SAP应付凭证锁定解锁状态回写
*/
public static void unlocked_status(Map<String, Object> thirdPartyMap) {
thirdPartyMap.put("interfaceID",interfaceID1);
thirdPartyMap.put("receiverID",receiverID1);
thirdPartyMap.put("URL",unlockedUrl);
// 构建请求头
Map<String, String> customerHeader = buildCustomerHeader(thirdPartyMap);
// 组装请求体
JSONObject pendingsBody = unlockedBody(thirdPartyMap);
// 发送请求并处理响应
processRequest(customerHeader, pendingsBody, thirdPartyMap,Apimenthod1);
}
/**
* SAP应付凭证锁定解锁状态回写组装请求体:
* @param thirdPartyMap 第三方数据映射 * @param thirdPartyMap 第三方数据映射
* @return 请求体的 JSON 对象 * @return 请求体的 JSON 对象
*/ */
private static JSONObject buildPendingsBody(Map<String, Object> thirdPartyMap) { private static JSONObject unlockedBody(Map<String, Object> thirdPartyMap) {
//组装请求体 //组装请求体
JSONObject pendingsBody = new JSONObject(); JSONObject pendingsBody = new JSONObject();
pendingsBody.put("rootContextID",System.currentTimeMillis());//todo:唯一事务ID采用UUID或其他强唯一性ID pendingsBody.put("rootContextID",""+System.currentTimeMillis());//todo:唯一事务ID采用UUID或其他强唯一性ID
pendingsBody.put("requestTime", String.valueOf(thirdPartyMap.get("createdatetime")));//请求时间,格式为yyyy-MM-dd HH:mm:ss.SSS pendingsBody.put("requestTime", ""+(thirdPartyMap.get("createdatetime")));//请求时间,格式为yyyy-MM-dd HH:mm:ss.SSS
JSONArray data = new JSONArray(); JSONObject data = new JSONObject();
//todo:多凭证 JSONArray IT_INPUT = new JSONArray();
List<DynamicObject> approversLists = (List<DynamicObject>) thirdPartyMap.get("approversLists"); //todo:
for (DynamicObject approver : approversLists) { List<DynamicObject> Lists = (List<DynamicObject>) thirdPartyMap.get("Lists");
for (DynamicObject obj : Lists) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("bukrs", String.valueOf(thirdPartyMap.get("bukrs")));//公司代码 jsonObject.put("bukrs", ""+(thirdPartyMap.get("bukrs")));//公司代码
jsonObject.put("belnr", String.valueOf(thirdPartyMap.get("belnr")));//会计凭证编号 jsonObject.put("belnr", ""+(thirdPartyMap.get("belnr")));//会计凭证编号
jsonObject.put("gjahr", String.valueOf(thirdPartyMap.get("gjahr")));//会计年度 jsonObject.put("gjahr", ""+(thirdPartyMap.get("gjahr")));//会计年度
jsonObject.put("stasus", String.valueOf(thirdPartyMap.get("stasus")));//状态 01锁定02解锁03关闭04退单05作废 jsonObject.put("stasus", ""+(thirdPartyMap.get("stasus")));//状态 01锁定02解锁03关闭04退单05作废
jsonObject.put("cname", String.valueOf(thirdPartyMap.get("cname")));//创建人工号 jsonObject.put("cname", ""+(thirdPartyMap.get("cname")));//创建人工号
jsonObject.put("zjddjid", String.valueOf(thirdPartyMap.get("zjddjid")));//金蝶单据ID jsonObject.put("zjddjid", ""+(thirdPartyMap.get("zjddjid")));//金蝶单据ID
jsonObject.put("zjddjbh", String.valueOf(thirdPartyMap.get("zjddjbh")));//金蝶单据编号 jsonObject.put("zjddjbh", ""+(thirdPartyMap.get("zjddjbh")));//金蝶单据编号
data.add(jsonObject); IT_INPUT.add(jsonObject);
} }
data.put("IT_INPUT",IT_INPUT);
pendingsBody.put("data", data);
return pendingsBody;
}
/**
* SAP应付凭证清单接口
*/
public static void vouchers_payable(Map<String, Object> thirdPartyMap) {
thirdPartyMap.put("interfaceID",interfaceID2);
thirdPartyMap.put("senderID",receiverID1);
thirdPartyMap.put("URL",vouchersUrl);
// 构建请求头
Map<String, String> customerHeader = buildCustomerHeader(thirdPartyMap);
// 组装请求体
JSONObject payableBody = payableBody(thirdPartyMap);
// 发送请求并处理响应
processRequest(customerHeader, payableBody, thirdPartyMap,Apimenthod2);
}
/**
* SAP应付凭证清单接口组装请求体:
* @param thirdPartyMap 第三方数据映射
* @return 请求体的 JSON 对象
*/
private static JSONObject payableBody(Map<String, Object> thirdPartyMap) {
//组装请求体
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
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);
pendingsBody.put("data", data);
return pendingsBody;
}
/**
* 生成代扣款记账单接口
*/
public static void withholding_billing(Map<String, Object> thirdPartyMap) {
thirdPartyMap.put("interfaceID",interfaceID3);
thirdPartyMap.put("senderID",receiverID2);
thirdPartyMap.put("URL",withholdingUrl);
// 构建请求头
Map<String, String> customerHeader = buildCustomerHeader(thirdPartyMap);
// 组装请求体
JSONObject withholdingBody = withholdingBody(thirdPartyMap);
// 发送请求并处理响应
processRequest(customerHeader, withholdingBody, thirdPartyMap, Apimenthod3);
}
/**
* SAP应付凭证清单接口组装请求体:
* @param thirdPartyMap 第三方数据映射
* @return 请求体的 JSON 对象
*/
private static JSONObject withholdingBody(Map<String, Object> thirdPartyMap) {
//组装请求体
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
JSONObject data = new JSONObject();
JSONObject header = new JSONObject();
header.put("FM_RequestBillCode", "DKK");//单据类型编码固定值DKK
header.put("FM_RequestCode", ""+(thirdPartyMap.get("FM_RequestCode")));//资金系统的申请单号
header.put("FM_CompanyCode", ""+(thirdPartyMap.get("FM_CompanyCode")));//公司编码
header.put("FM_DeptCode", ""+(thirdPartyMap.get("FM_DeptCode")));//部门编码
header.put("FM_UserCode", ""+(thirdPartyMap.get("FM_UserCode")));//员工工号
header.put("FM_CreateUserCode", ""+(thirdPartyMap.get("FM_CreateUserCode")));//创建人工号
header.put("FM_ExpenseTypeCode", ""+(thirdPartyMap.get("FM_ExpenseTypeCode")));//业务大类编码(EQ49,EQ44,EQ1101)
header.put("FM_CurrencyCode", ""+(thirdPartyMap.get("FM_CurrencyCode")));//币种编码默认:RMB
header.put("FM_RequestName", ""+(thirdPartyMap.get("FM_RequestName")));//单据主题
header.put("FM_AttachUrl", JSONArray.parse(""+(thirdPartyMap.get("FM_AttachUrl"))));//todo:附件URL地址:array
header.put("FM_BudType", Integer.valueOf(""+thirdPartyMap.get("FM_AttachUr")));//预算类别0-组织预算,1-全年预算,当前只处理0 int
header.put("Remark", ""+(thirdPartyMap.get("Remark")));//事项描述
JSONArray body = new JSONArray();
//todo:
List<DynamicObject> Lists = (List<DynamicObject>) thirdPartyMap.get("Lists");
for (DynamicObject obj : Lists) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("FM_ClaimAmt", Double.valueOf(""+(thirdPartyMap.get("FM_ClaimAmt"))));//含税金额
jsonObject.put("FM_ExcluAmt", Double.valueOf(""+(thirdPartyMap.get("FM_ExcluAmt"))));//未税金额
jsonObject.put("FM_VatAmt", Double.valueOf(""+(thirdPartyMap.get("FM_VatAmt"))));//税额
jsonObject.put("FM_FiscalYear", Integer.valueOf(""+(thirdPartyMap.get("FM_FiscalYear"))));//费用年度
jsonObject.put("FM_FiscalMoth", Integer.valueOf(""+(thirdPartyMap.get("FM_FiscalMoth"))));//费用月度
jsonObject.put("FM_ExItemDate1", Date.valueOf(""+thirdPartyMap.get("FM_ExItemDate1")));//业务日期
jsonObject.put("FM_SupplierCode", ""+(thirdPartyMap.get("FM_SupplierCode")));//供应商编码业务大类=EQ49时必填
jsonObject.put("FM_CostCenterCode", ""+(thirdPartyMap.get("FM_CostCenterCode")));//成本中心编码业务大类=EQ49时必填
jsonObject.put("FM_ProfitCenterCode", ""+(thirdPartyMap.get("FM_ProfitCenterCode")));//利润中心编码业务大类=EQ49时必填
jsonObject.put("FM_ExpenseItemCode", ""+(thirdPartyMap.get("FM_ExpenseItemCode")));//业务小类编码业务大类=EQ49时必填
jsonObject.put("FM_InvoiceTypeCode", ""+(thirdPartyMap.get("FM_InvoiceTypeCode")));//发票类型编码(普票:INVOICE001,专票:INVOICE002其它票据:INVOICE003)
jsonObject.put("FM_TaxRateCode", ""+(thirdPartyMap.get("FM_TaxRateCode")));//税率编码(传J0时发票类型选INVOICE003)参考附表
jsonObject.put("FM_DetailAttachUrl", JSONArray.parse(""+(thirdPartyMap.get("FM_DetailAttachUrl"))));//todo:附件URL地址:array
jsonObject.put("Remark", ""+(thirdPartyMap.get("Remark")));//备注
body.add(jsonObject);
}
data.put("header",header);
data.put("body",body);
pendingsBody.put("data", data); pendingsBody.put("data", data);
return pendingsBody; return pendingsBody;
} }
@ -81,34 +216,39 @@ public class SapUtils {
* @param customerHeader 请求头 * @param customerHeader 请求头
* @param pendingsBody 请求体 * @param pendingsBody 请求体
* @param thirdPartyMap 第三方数据映射 * @param thirdPartyMap 第三方数据映射
* @param apiName 接口名称
*/ */
private static void processRequest(Map<String, String> customerHeader, JSONObject pendingsBody, Map<String, Object> thirdPartyMap) { private static void processRequest(Map<String, String> customerHeader, JSONObject pendingsBody, Map<String, Object> thirdPartyMap,String apiName) {
String pendingPostjson = null; String pendingPostjson = null;
JSONObject jsonObject = null; JSONObject jsonObject = null;
try { try {
// 发送POST请求并获取响应 // 发送POST请求并获取响应
pendingPostjson = HttpClientUtils.postjson(OAUtils.oaUrl, customerHeader, pendingsBody.toJSONString()); pendingPostjson = HttpClientUtils.postjson(thirdPartyMap.get("URL").toString(), customerHeader, pendingsBody.toJSONString());
jsonObject = parseResponse(pendingPostjson); jsonObject = parseResponse(pendingPostjson,apiName);
// 检查JSON对象是否为空 // 检查JSON对象是否为空
if (jsonObject != null && !jsonObject.isEmpty()) { if (jsonObject != null && !jsonObject.isEmpty()) {
handleResponse(jsonObject, pendingsBody, thirdPartyMap); handleResponse(jsonObject, pendingsBody, thirdPartyMap,apiName);
}else {
logger.info(apiName +"失败!");
saveLog(apiName +(thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, false,apiName);
} }
} catch (Exception e) { } catch (Exception e) {
handleException(e, pendingsBody, thirdPartyMap, jsonObject); handleException(e, pendingsBody, thirdPartyMap, jsonObject,apiName);
} }
} }
/** /**
* 解析响应 JSON 字符串 * 解析响应 JSON 字符串
* @param response 响应的 JSON 字符串 * @param response 响应的 JSON 字符串
* @param apiName 接口名称
* @return 解析后的 JSON 对象 * @return 解析后的 JSON 对象
*/ */
private static JSONObject parseResponse(String response) { private static JSONObject parseResponse(String response,String apiName) {
try { try {
return JSONObject.parseObject(response); return JSONObject.parseObject(response);
} catch (Exception e) { } catch (Exception e) {
logger.error("解析响应 JSON 时出错: {}", e.getMessage()); logger.error(apiName + "解析响应 JSON 时出错: {}", e.getMessage());
return null; return null;
} }
} }
@ -118,21 +258,22 @@ public class SapUtils {
* @param jsonObject 响应的 JSON 对象 * @param jsonObject 响应的 JSON 对象
* @param pendingsBody 请求体 * @param pendingsBody 请求体
* @param thirdPartyMap 第三方数据映射 * @param thirdPartyMap 第三方数据映射
* @param apiName 接口名称
*/ */
private static void handleResponse(JSONObject jsonObject, JSONObject pendingsBody, Map<String, Object> thirdPartyMap) { private static void handleResponse(JSONObject jsonObject, JSONObject pendingsBody, Map<String, Object> thirdPartyMap,String apiName) {
JSONArray data1 = jsonObject.getJSONArray("data"); JSONArray data1 = jsonObject.getJSONArray("data");
if (data1 == null || data1.isEmpty()) { if (data1 == null || data1.isEmpty()) {
logger.info("SAP应付凭证锁定解锁状态回写失败!"); logger.info(apiName + "失败!");
saveLog("状态回写:" + String.valueOf(thirdPartyMap.get("billno")), pendingsBody, jsonObject, false); saveLog(apiName + (thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, false,apiName);
return; return;
} }
JSONObject jsonobject = data1.getJSONObject(0); JSONObject jsonobject = data1.getJSONObject(0);
String operResult = jsonobject.getString("operResult"); String operResult = jsonobject.getString("operResult");
String logMessage = Objects.equals(operResult, "1") ? "SAP应付凭证锁定解锁状态回写成功!" : "SAP应付凭证锁定解锁状态回写失败!"; String logMessage = Objects.equals(operResult, "1") ? apiName +"成功!" : apiName +"失败!";
// 记录日志 // 记录日志
logger.info(logMessage); logger.info(logMessage);
saveLog("状态回写:" + String.valueOf(thirdPartyMap.get("billno")), pendingsBody, jsonObject, true); saveLog(apiName + (thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, true,apiName);
} }
/** /**
@ -141,25 +282,27 @@ public class SapUtils {
* @param pendingsBody 请求体 * @param pendingsBody 请求体
* @param thirdPartyMap 第三方数据映射 * @param thirdPartyMap 第三方数据映射
* @param jsonObject 响应的 JSON 对象 * @param jsonObject 响应的 JSON 对象
* @param apiName 接口名称
*/ */
private static void handleException(Exception e, JSONObject pendingsBody, Map<String, Object> thirdPartyMap, JSONObject jsonObject) { private static void handleException(Exception e, JSONObject pendingsBody, Map<String, Object> thirdPartyMap, JSONObject jsonObject,String apiName) {
// 记录异常信息 // 记录异常信息
String errorMessage = String.format("待办接口异常:%s", e.getMessage()); String errorMessage = String.format(apiName +"状态回写接口异常:%s", e.getMessage());
logger.error(errorMessage); logger.error(errorMessage);
saveLog("状态回写:" + String.valueOf(thirdPartyMap.get("billno")), pendingsBody, jsonObject, false); saveLog(apiName + thirdPartyMap.get("billno").toString(), pendingsBody, jsonObject, false,apiName);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
/** /**
* 保存日志 * 保存日志
* *
* @param billNo 单号 * @param billNo 单号
* @param pendingsBody 请求体 * @param pendingsBody 请求体
* @param jsonObject 响应的 JSON 对象 * @param jsonObject 响应的 JSON 对象
* @param isSuccess 是否成功 * @param isSuccess 是否成功
* @param apiName 接口名称
*/ */
private static void saveLog(String billNo, JSONObject pendingsBody, JSONObject jsonObject, boolean isSuccess) { private static void saveLog(String billNo, JSONObject pendingsBody, JSONObject jsonObject, boolean isSuccess,String apiName) {
JhzjUtils.saveLog(billNo, Apimenthod, pendingsBody.toJSONString(), JhzjUtils.saveLog(billNo, apiName, pendingsBody.toJSONString(),
jsonObject != null ? jsonObject.toJSONString() : "{}", isSuccess, "API"); jsonObject != null ? jsonObject.toJSONString() : "{}", isSuccess, "API");
} }
} }