1.接收流程数据:可接收待办、已办、归档的流程数据

2.SAP应付凭证清单
3..SAP应付凭证锁定解锁状态回写

--s
This commit is contained in:
weiyunlong 2025-03-03 10:54:01 +08:00
parent 8d55cf498b
commit c422c87b0f
2 changed files with 104 additions and 38 deletions

View File

@ -50,7 +50,7 @@ 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;
} }

View File

@ -14,23 +14,21 @@ 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应付凭证锁定解锁状态回写接口"; private static final String Apimenthod1 = "SAP应付凭证锁定解锁状态回写接口";
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应付凭证清单接口";
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";//正式环境
public static final String oaAPIKey = "207b5296-9866-4b4b-8146-1fea58b3c8c9";//测试环境APIKey
// public static final String oaAPIKey = "8281da80-b39b-48c4-83bd-f8e480740c6a";//测试环境APIKey
public static void thirdParty(Map<String, Object> thirdPartyMap) {
// 构建请求头
Map<String, String> customerHeader = buildCustomerHeader(thirdPartyMap);
// 组装请求体
JSONObject pendingsBody = buildPendingsBody(thirdPartyMap);
// 发送请求并处理响应
processRequest(customerHeader, pendingsBody, thirdPartyMap);
}
/** /**
* 构建请求头 * 构建请求头
@ -41,23 +39,41 @@ public class SapUtils {
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", ""+thirdPartyMap.get("interfaceID"));//识别被调接口并进行路由
customerHeader.put("senderID", String.valueOf(thirdPartyMap.get("cname")));//TODO:定义的发送者.暂定工号 customerHeader.put("senderID", ""+thirdPartyMap.get("senderID"));
return customerHeader; return customerHeader;
} }
/** /**
* 组装请求体 * SAP应付凭证锁定解锁状态回写
* @param thirdPartyMap
*/
public static void unlocked_status(Map<String, Object> thirdPartyMap) {
thirdPartyMap.put("interfaceID","PayableVoucherStatus");
thirdPartyMap.put("senderID","SAP");
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", String.valueOf(thirdPartyMap.get("createdatetime")));//请求时间,格式为yyyy-MM-dd HH:mm:ss.SSS
JSONArray data = new JSONArray(); JSONObject data = new JSONObject();
JSONArray IT_INPUT = new JSONArray();
//todo:多凭证 //todo:多凭证
List<DynamicObject> approversLists = (List<DynamicObject>) thirdPartyMap.get("approversLists"); List<DynamicObject> approversLists = (List<DynamicObject>) thirdPartyMap.get("approversLists");
for (DynamicObject approver : approversLists) { for (DynamicObject approver : approversLists) {
@ -69,8 +85,55 @@ public class SapUtils {
jsonObject.put("cname", String.valueOf(thirdPartyMap.get("cname")));//创建人工号 jsonObject.put("cname", String.valueOf(thirdPartyMap.get("cname")));//创建人工号
jsonObject.put("zjddjid", String.valueOf(thirdPartyMap.get("zjddjid")));//金蝶单据ID jsonObject.put("zjddjid", String.valueOf(thirdPartyMap.get("zjddjid")));//金蝶单据ID
jsonObject.put("zjddjbh", String.valueOf(thirdPartyMap.get("zjddjbh")));//金蝶单据编号 jsonObject.put("zjddjbh", String.valueOf(thirdPartyMap.get("zjddjbh")));//金蝶单据编号
data.add(jsonObject); IT_INPUT.add(jsonObject);
} }
data.put("IT_INPUT",IT_INPUT);
pendingsBody.put("data", data);
return pendingsBody;
}
/**
* SAP应付凭证清单接口
* @param thirdPartyMap
*/
public static void vouchers_payable(Map<String, Object> thirdPartyMap) {
thirdPartyMap.put("interfaceID","ZFS_GET_AP_OPENITEMS");
thirdPartyMap.put("senderID","SAP");
thirdPartyMap.put("URL",vouchersUrl);
// 构建请求头
Map<String, String> customerHeader = buildCustomerHeader(thirdPartyMap);
// 组装请求体
JSONObject pendingsBody = payableBody(thirdPartyMap);
// 发送请求并处理响应
processRequest(customerHeader, pendingsBody, 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", String.valueOf(thirdPartyMap.get("createdatetime")));//请求时间,格式为yyyy-MM-dd HH:mm:ss.SSS
JSONObject data = new JSONObject();
JSONArray IT_LIST = new JSONArray();
//todo:多凭证
List<DynamicObject> approversLists = (List<DynamicObject>) thirdPartyMap.get("approversLists");
for (DynamicObject approver : approversLists) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("FIELD", String.valueOf(thirdPartyMap.get("FIELD")));//字段
jsonObject.put("SIGN", String.valueOf(thirdPartyMap.get("SIGN")));//I:包含 E排除
jsonObject.put("LOW", String.valueOf(thirdPartyMap.get("LOW")));//LOW 枚举字段所代表值的区间开始值
jsonObject.put("HIGH", String.valueOf(thirdPartyMap.get("HIGH")));//HIGH枚举字段所代表值的区间结束值
jsonObject.put("OPTION", "BT");//默认BT
IT_LIST.add(jsonObject);
}
data.put("IT_LIST",IT_LIST);
pendingsBody.put("data", data); pendingsBody.put("data", data);
return pendingsBody; return pendingsBody;
} }
@ -82,20 +145,23 @@ public class SapUtils {
* @param pendingsBody 请求体 * @param pendingsBody 请求体
* @param thirdPartyMap 第三方数据映射 * @param thirdPartyMap 第三方数据映射
*/ */
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 + String.valueOf(thirdPartyMap.get("billno")), pendingsBody, jsonObject, false,apiName);
} }
} catch (Exception e) { } catch (Exception e) {
handleException(e, pendingsBody, thirdPartyMap, jsonObject); handleException(e, pendingsBody, thirdPartyMap, jsonObject,apiName);
} }
} }
@ -104,11 +170,11 @@ public class SapUtils {
* @param response 响应的 JSON 字符串 * @param response 响应的 JSON 字符串
* @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;
} }
} }
@ -119,20 +185,20 @@ public class SapUtils {
* @param pendingsBody 请求体 * @param pendingsBody 请求体
* @param thirdPartyMap 第三方数据映射 * @param thirdPartyMap 第三方数据映射
*/ */
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 + String.valueOf(thirdPartyMap.get("billno")), 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 + String.valueOf(thirdPartyMap.get("billno")), pendingsBody, jsonObject, true,apiName);
} }
/** /**
@ -142,24 +208,24 @@ public class SapUtils {
* @param thirdPartyMap 第三方数据映射 * @param thirdPartyMap 第三方数据映射
* @param jsonObject 响应的 JSON 对象 * @param jsonObject 响应的 JSON 对象
*/ */
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"), 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 是否成功
*/ */
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");
} }
} }