|
|
@ -698,6 +698,7 @@ public class ErpInterfaceServiceImpl implements ErpInterfaceService { |
|
|
* @return 调用结果 {success: true/false, message: "...", u8CCode: "..."} |
|
|
* @return 调用结果 {success: true/false, message: "...", u8CCode: "..."} |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public Map<String, Object> syncCallErpInterface(String site, String buNo, String transactionId) { |
|
|
public Map<String, Object> syncCallErpInterface(String site, String buNo, String transactionId) { |
|
|
logger.info("同步调用ERP接口 - site: {}, buNo: {}, transactionId: {}", site, buNo, transactionId); |
|
|
logger.info("同步调用ERP接口 - site: {}, buNo: {}, transactionId: {}", site, buNo, transactionId); |
|
|
|
|
|
|
|
|
@ -730,7 +731,8 @@ public class ErpInterfaceServiceImpl implements ErpInterfaceService { |
|
|
ApiInterfaceEntity apiInterface = apiInterfaceDao.getByInterfaceName(site, buNo, interfaceName); |
|
|
ApiInterfaceEntity apiInterface = apiInterfaceDao.getByInterfaceName(site, buNo, interfaceName); |
|
|
if (apiInterface == null) { |
|
|
if (apiInterface == null) { |
|
|
logger.error("未找到接口配置 - interfaceName: {}", interfaceName); |
|
|
logger.error("未找到接口配置 - interfaceName: {}", interfaceName); |
|
|
saveFailureLog(site, buNo, transactionId, interfaceName, transactionLogs, "未找到接口配置"); |
|
|
|
|
|
|
|
|
// 失败时更新或新增api_log |
|
|
|
|
|
updateOrInsertApiLog(site, buNo, transactionId, interfaceName, transactionLogs, "未找到接口配置", null); |
|
|
result.put("message", "未找到接口配置: " + interfaceName); |
|
|
result.put("message", "未找到接口配置: " + interfaceName); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
@ -764,28 +766,34 @@ public class ErpInterfaceServiceImpl implements ErpInterfaceService { |
|
|
String flag = jsonResponse.getString("Flag"); |
|
|
String flag = jsonResponse.getString("Flag"); |
|
|
|
|
|
|
|
|
if ("success".equalsIgnoreCase(flag)) { |
|
|
if ("success".equalsIgnoreCase(flag)) { |
|
|
// 成功:更新StockTransactionLog |
|
|
|
|
|
|
|
|
// 成功:更新StockTransactionLog和api_log |
|
|
String u8CCode = jsonResponse.getString("U8CCode"); |
|
|
String u8CCode = jsonResponse.getString("U8CCode"); |
|
|
logger.info("ERP接口调用成功 - U8单号: {}", u8CCode); |
|
|
logger.info("ERP接口调用成功 - U8单号: {}", u8CCode); |
|
|
|
|
|
|
|
|
|
|
|
// 更新StockTransactionLog为成功 |
|
|
stockTransactionLogDao.updateSyncedSuccess(site, buNo, transactionId); |
|
|
stockTransactionLogDao.updateSyncedSuccess(site, buNo, transactionId); |
|
|
|
|
|
|
|
|
|
|
|
// 更新api_log表(成功时设置need_retry_flag=0) |
|
|
|
|
|
updateApiLogOnSuccess(site, transactionId, responseBody); |
|
|
|
|
|
|
|
|
result.put("success", true); |
|
|
result.put("success", true); |
|
|
result.put("message", "接口调用成功"); |
|
|
result.put("message", "接口调用成功"); |
|
|
result.put("u8CCode", u8CCode != null ? u8CCode : ""); |
|
|
result.put("u8CCode", u8CCode != null ? u8CCode : ""); |
|
|
} else { |
|
|
} else { |
|
|
// 失败:记录到api_log |
|
|
|
|
|
|
|
|
// 失败:更新或新增api_log |
|
|
String errMsg = jsonResponse.getString("ErrMsg"); |
|
|
String errMsg = jsonResponse.getString("ErrMsg"); |
|
|
logger.error("ERP接口调用失败 - 错误: {}", errMsg); |
|
|
logger.error("ERP接口调用失败 - 错误: {}", errMsg); |
|
|
|
|
|
|
|
|
saveFailureLog(site, buNo, transactionId, interfaceName, transactionLogs, errMsg); |
|
|
|
|
|
|
|
|
// 失败时更新或新增api_log |
|
|
|
|
|
updateOrInsertApiLog(site, buNo, transactionId, interfaceName, transactionLogs, errMsg, responseBody); |
|
|
|
|
|
|
|
|
result.put("message", errMsg != null ? errMsg : "接口调用失败"); |
|
|
result.put("message", errMsg != null ? errMsg : "接口调用失败"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error("调用ERP接口异常 - transactionId: {}, error: {}", transactionId, e.getMessage(), e); |
|
|
logger.error("调用ERP接口异常 - transactionId: {}, error: {}", transactionId, e.getMessage(), e); |
|
|
saveFailureLog(site, buNo, transactionId, interfaceName, transactionLogs, "接口调用异常: " + e.getMessage()); |
|
|
|
|
|
|
|
|
// 异常时更新或新增api_log |
|
|
|
|
|
updateOrInsertApiLog(site, buNo, transactionId, interfaceName, transactionLogs, "接口调用异常: " + e.getMessage(), null); |
|
|
result.put("message", "接口调用异常: " + e.getMessage()); |
|
|
result.put("message", "接口调用异常: " + e.getMessage()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -797,6 +805,63 @@ public class ErpInterfaceServiceImpl implements ErpInterfaceService { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 更新api_log表(ERP接口调用成功时) |
|
|
|
|
|
*/ |
|
|
|
|
|
private void updateApiLogOnSuccess(String site, String transactionId, String responseData) { |
|
|
|
|
|
try { |
|
|
|
|
|
// 检查api_log中是否已存在该transactionId的记录 |
|
|
|
|
|
Map<String, Object> existingLog = interfaceLogDao.getApiLogByTransactionId(site, transactionId); |
|
|
|
|
|
|
|
|
|
|
|
if (existingLog != null) { |
|
|
|
|
|
// 如果存在,更新记录(成功时设置status_code=200, need_retry_flag=0) |
|
|
|
|
|
interfaceLogDao.updateApiLogByTransactionId( |
|
|
|
|
|
site, |
|
|
|
|
|
transactionId, |
|
|
|
|
|
"200", // statusCode |
|
|
|
|
|
"接口调用成功", // message |
|
|
|
|
|
0, // needRetryFlag(0表示不需要重试) |
|
|
|
|
|
responseData // lastResponseData |
|
|
|
|
|
); |
|
|
|
|
|
logger.info("成功更新api_log表 - transactionId: {}", transactionId); |
|
|
|
|
|
} else { |
|
|
|
|
|
logger.info("api_log表中不存在该记录,跳过更新 - transactionId: {}", transactionId); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("更新api_log表失败 - transactionId: {}, error: {}", transactionId, e.getMessage(), e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 更新或新增api_log表(ERP接口调用失败时) |
|
|
|
|
|
*/ |
|
|
|
|
|
private void updateOrInsertApiLog(String site, String buNo, String transactionId, String interfaceName, |
|
|
|
|
|
List<StockTransactionLogEntity> transactionLogs, String errorMsg, String responseData) { |
|
|
|
|
|
try { |
|
|
|
|
|
// 检查api_log中是否已存在该transactionId的记录 |
|
|
|
|
|
Map<String, Object> existingLog = interfaceLogDao.getApiLogByTransactionId(site, transactionId); |
|
|
|
|
|
|
|
|
|
|
|
if (existingLog != null) { |
|
|
|
|
|
// 如果存在,更新记录(失败时设置status_code=500, need_retry_flag=1) |
|
|
|
|
|
interfaceLogDao.updateApiLogByTransactionId( |
|
|
|
|
|
site, |
|
|
|
|
|
transactionId, |
|
|
|
|
|
"500", // statusCode |
|
|
|
|
|
errorMsg, // message |
|
|
|
|
|
1, // needRetryFlag(1表示需要重试) |
|
|
|
|
|
responseData // lastResponseData |
|
|
|
|
|
); |
|
|
|
|
|
logger.info("成功更新api_log表 - transactionId: {}", transactionId); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 如果不存在,新增记录 |
|
|
|
|
|
logger.info("api_log表中不存在该记录,开始新增 - transactionId: {}", transactionId); |
|
|
|
|
|
saveFailureLog(site, buNo, transactionId, interfaceName, transactionLogs, errorMsg); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("更新或新增api_log表失败 - transactionId: {}, error: {}", transactionId, e.getMessage(), e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 格式化日期 |
|
|
* 格式化日期 |
|
|
*/ |
|
|
*/ |
|
|
|