| | |
| | | |
| | | @Override |
| | | public R queryInventoryDetails(InventoryQueryCondition condition) { |
| | | log.error("调用WMS Server库存查询明细接口失败,触发降级处理"); |
| | | return R.error("服务调用失败,请稍后重试"); |
| | | return queryInventoryDetails(condition, null); |
| | | } |
| | | |
| | | /** |
| | | * 库存查询明细降级处理(带异常信息) |
| | | * @param condition 查询条件 |
| | | * @param throwable 异常信息(可选) |
| | | * @return 错误响应 |
| | | */ |
| | | public R queryInventoryDetails(InventoryQueryCondition condition, Throwable throwable) { |
| | | log.error("调用WMS Server库存查询明细接口失败,触发降级处理", throwable); |
| | | String errorMessage = filterErrorMessage(throwable); |
| | | return R.error(errorMessage); |
| | | } |
| | | |
| | | @Override |
| | | public R queryInventorySummary(InventoryQueryCondition condition) { |
| | | return queryInventorySummary(condition, null); |
| | | } |
| | | |
| | | /** |
| | | * 库存查询汇总降级处理(带异常信息) |
| | | * @param condition 查询条件 |
| | | * @param throwable 异常信息(可选) |
| | | * @return 错误响应 |
| | | */ |
| | | public R queryInventorySummary(InventoryQueryCondition condition, Throwable throwable) { |
| | | log.error("调用WMS Server库存查询汇总接口失败,触发降级处理", throwable); |
| | | String errorMessage = filterErrorMessage(throwable); |
| | | return R.error(errorMessage); |
| | | } |
| | | |
| | | /** |
| | | * 过滤错误消息中的URL,只保留错误类型 |
| | | * @param throwable 异常对象(可选) |
| | | * @return 过滤后的完整错误消息(包含"查询失败:"前缀) |
| | | */ |
| | | public static String filterErrorMessage(Throwable throwable) { |
| | | if (throwable == null) { |
| | | return "查询失败:服务调用失败,请稍后重试"; |
| | | } |
| | | return filterErrorMessage(throwable.getMessage()); |
| | | } |
| | | |
| | | /** |
| | | * 过滤错误消息中的URL,只保留错误类型 |
| | | * @param errorMessage 错误消息字符串(可选) |
| | | * @return 过滤后的完整错误消息(包含"查询失败:"前缀) |
| | | */ |
| | | public static String filterErrorMessage(String errorMessage) { |
| | | if (errorMessage == null || errorMessage.isEmpty()) { |
| | | return "查询失败:未知错误"; |
| | | } |
| | | |
| | | String filteredMessage = errorMessage; |
| | | |
| | | // 如果包含"executing",说明是HTTP请求错误,去掉URL部分 |
| | | if (filteredMessage.contains("executing")) { |
| | | int executingIndex = filteredMessage.indexOf("executing"); |
| | | if (executingIndex > 0) { |
| | | // 提取"executing"之前的部分(如"Read timed out") |
| | | filteredMessage = filteredMessage.substring(0, executingIndex).trim(); |
| | | } else { |
| | | // 如果"executing"在开头,使用默认错误消息 |
| | | filteredMessage = "请求超时"; |
| | | } |
| | | } |
| | | // 如果包含"http://"或"https://",也尝试去掉URL部分 |
| | | else if (filteredMessage.contains("http://") || filteredMessage.contains("https://")) { |
| | | // 使用正则表达式去掉URL |
| | | filteredMessage = filteredMessage.replaceAll("https?://[^\\s]+", "").trim(); |
| | | if (filteredMessage.isEmpty()) { |
| | | filteredMessage = "请求失败"; |
| | | } |
| | | } |
| | | |
| | | // 如果过滤后的消息为空,使用默认错误消息 |
| | | if (filteredMessage.isEmpty()) { |
| | | filteredMessage = "未知错误"; |
| | | } |
| | | |
| | | // 返回包含"查询失败:"前缀的完整错误消息 |
| | | return "查询失败:" + filteredMessage; |
| | | } |
| | | } |