|
|
@ -684,15 +684,34 @@ public class ErpInterfaceServiceImpl implements ErpInterfaceService { |
|
|
* 这个方法不使用@Async注解,确保在调用线程中同步执行 |
|
|
* 这个方法不使用@Async注解,确保在调用线程中同步执行 |
|
|
*/ |
|
|
*/ |
|
|
private void callErpInterfaceSync(String site, String buNo, String transactionId) { |
|
|
private void callErpInterfaceSync(String site, String buNo, String transactionId) { |
|
|
|
|
|
// 直接调用公开的同步方法 |
|
|
|
|
|
syncCallErpInterface(site, buNo, transactionId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 同步调用ERP接口(用于手动重试等需要同步返回结果的场景) |
|
|
|
|
|
* @param site 工厂 |
|
|
|
|
|
* @param buNo BU编号 |
|
|
|
|
|
* @param transactionId 事务ID |
|
|
|
|
|
* @return 调用结果 {success: true/false, message: "...", u8CCode: "..."} |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
result.put("success", false); |
|
|
|
|
|
result.put("message", ""); |
|
|
|
|
|
result.put("u8CCode", ""); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
// 1. 查询StockTransactionLog数据 |
|
|
// 1. 查询StockTransactionLog数据 |
|
|
List<StockTransactionLogEntity> transactionLogs = stockTransactionLogDao.queryByTransactionId(site, buNo, transactionId); |
|
|
List<StockTransactionLogEntity> transactionLogs = stockTransactionLogDao.queryByTransactionId(site, buNo, transactionId); |
|
|
|
|
|
|
|
|
if (transactionLogs == null || transactionLogs.isEmpty()) { |
|
|
if (transactionLogs == null || transactionLogs.isEmpty()) { |
|
|
logger.warn("未找到事务记录 - transactionId: {}", transactionId); |
|
|
logger.warn("未找到事务记录 - transactionId: {}", transactionId); |
|
|
return; |
|
|
|
|
|
|
|
|
result.put("message", "未找到事务记录"); |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 取第一条记录作为主表数据 |
|
|
// 取第一条记录作为主表数据 |
|
|
@ -701,7 +720,8 @@ public class ErpInterfaceServiceImpl implements ErpInterfaceService { |
|
|
|
|
|
|
|
|
if (interfaceName == null || interfaceName.trim().isEmpty()) { |
|
|
if (interfaceName == null || interfaceName.trim().isEmpty()) { |
|
|
logger.warn("接口名称为空 - transactionId: {}", transactionId); |
|
|
logger.warn("接口名称为空 - transactionId: {}", transactionId); |
|
|
return; |
|
|
|
|
|
|
|
|
result.put("message", "接口名称为空"); |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 2. 获取接口地址 |
|
|
// 2. 获取接口地址 |
|
|
@ -709,7 +729,8 @@ public class ErpInterfaceServiceImpl implements ErpInterfaceService { |
|
|
if (apiInterface == null) { |
|
|
if (apiInterface == null) { |
|
|
logger.error("未找到接口配置 - interfaceName: {}", interfaceName); |
|
|
logger.error("未找到接口配置 - interfaceName: {}", interfaceName); |
|
|
saveFailureLog(site, buNo, transactionId, interfaceName, transactionLogs, "未找到接口配置"); |
|
|
saveFailureLog(site, buNo, transactionId, interfaceName, transactionLogs, "未找到接口配置"); |
|
|
return; |
|
|
|
|
|
|
|
|
result.put("message", "未找到接口配置: " + interfaceName); |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
String interfaceUrl = "http://" + apiInterface.getInterfaceIp() + apiInterface.getInterfaceValue(); |
|
|
String interfaceUrl = "http://" + apiInterface.getInterfaceIp() + apiInterface.getInterfaceValue(); |
|
|
@ -746,22 +767,32 @@ public class ErpInterfaceServiceImpl implements ErpInterfaceService { |
|
|
logger.info("ERP接口调用成功 - U8单号: {}", u8CCode); |
|
|
logger.info("ERP接口调用成功 - U8单号: {}", u8CCode); |
|
|
|
|
|
|
|
|
stockTransactionLogDao.updateSyncedSuccess(site, buNo, transactionId); |
|
|
stockTransactionLogDao.updateSyncedSuccess(site, buNo, transactionId); |
|
|
|
|
|
|
|
|
|
|
|
result.put("success", true); |
|
|
|
|
|
result.put("message", "接口调用成功"); |
|
|
|
|
|
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); |
|
|
saveFailureLog(site, buNo, transactionId, interfaceName, transactionLogs, 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()); |
|
|
saveFailureLog(site, buNo, transactionId, interfaceName, transactionLogs, "接口调用异常: " + e.getMessage()); |
|
|
|
|
|
result.put("message", "接口调用异常: " + e.getMessage()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error("同步调用ERP接口失败 - transactionId: {}, error: {}", transactionId, e.getMessage(), e); |
|
|
logger.error("同步调用ERP接口失败 - transactionId: {}, error: {}", transactionId, e.getMessage(), e); |
|
|
|
|
|
result.put("message", "同步调用失败: " + e.getMessage()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|