1
This commit is contained in:
@@ -97,13 +97,17 @@ public class LogisticsServiceImpl implements ILogisticsService {
|
||||
|
||||
logger.info("检测到waybill_no: {} - 订单ID: {}", waybillNo, order.getId());
|
||||
|
||||
// 调用企业应用推送,只有推送成功才记录状态
|
||||
boolean pushSuccess = sendEnterprisePushNotification(order, waybillNo);
|
||||
if (!pushSuccess) {
|
||||
logger.warn("企业微信推送未确认成功,稍后将重试 - 订单ID: {}, waybill_no: {}", order.getId(), waybillNo);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 保存运单号到Redis(避免重复处理)
|
||||
String redisKey = REDIS_WAYBILL_KEY_PREFIX + order.getId();
|
||||
stringRedisTemplate.opsForValue().set(redisKey, waybillNo, 30, TimeUnit.DAYS);
|
||||
|
||||
// 调用企业应用推送
|
||||
sendEnterprisePushNotification(order, waybillNo);
|
||||
|
||||
logger.info("物流信息获取并推送成功 - 订单ID: {}, waybill_no: {}", order.getId(), waybillNo);
|
||||
return true;
|
||||
|
||||
@@ -118,7 +122,7 @@ public class LogisticsServiceImpl implements ILogisticsService {
|
||||
* @param order 订单信息
|
||||
* @param waybillNo 运单号
|
||||
*/
|
||||
private void sendEnterprisePushNotification(JDOrder order, String waybillNo) {
|
||||
private boolean sendEnterprisePushNotification(JDOrder order, String waybillNo) {
|
||||
try {
|
||||
// 构建推送消息内容
|
||||
StringBuilder pushContent = new StringBuilder();
|
||||
@@ -149,13 +153,61 @@ public class LogisticsServiceImpl implements ILogisticsService {
|
||||
|
||||
// 使用支持自定义header的HTTP请求
|
||||
String pushResult = sendPostWithHeaders(PUSH_URL, pushParam.toJSONString(), PUSH_TOKEN);
|
||||
logger.info("企业应用推送调用结果 - 订单ID: {}, waybill_no: {}, 推送结果: {}",
|
||||
order.getId(), waybillNo, pushResult);
|
||||
if (pushResult == null || pushResult.trim().isEmpty()) {
|
||||
logger.warn("企业应用推送响应为空 - 订单ID: {}, waybill_no: {}", order.getId(), waybillNo);
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean success = isPushResponseSuccess(pushResult);
|
||||
if (success) {
|
||||
logger.info("企业应用推送成功 - 订单ID: {}, waybill_no: {}, 推送结果: {}",
|
||||
order.getId(), waybillNo, pushResult);
|
||||
} else {
|
||||
logger.warn("企业应用推送响应未确认成功 - 订单ID: {}, waybill_no: {}, 响应: {}",
|
||||
order.getId(), waybillNo, pushResult);
|
||||
}
|
||||
return success;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("调用企业应用推送失败 - 订单ID: {}, waybill_no: {}, 错误: {}",
|
||||
order.getId(), waybillNo, e.getMessage(), e);
|
||||
// 不抛出异常,避免影响主流程
|
||||
// 不抛出异常,主流程根据返回值决定是否重试
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断推送返回值是否为成功状态
|
||||
* @param pushResult 推送接口返回结果
|
||||
* @return 是否成功
|
||||
*/
|
||||
private boolean isPushResponseSuccess(String pushResult) {
|
||||
try {
|
||||
JSONObject response = JSON.parseObject(pushResult);
|
||||
if (response == null) {
|
||||
return false;
|
||||
}
|
||||
Integer code = response.getInteger("code");
|
||||
Boolean successFlag = response.getBoolean("success");
|
||||
String status = response.getString("status");
|
||||
String message = response.getString("msg");
|
||||
|
||||
if (code != null && (code == 0 || code == 200)) {
|
||||
return true;
|
||||
}
|
||||
if (Boolean.TRUE.equals(successFlag)) {
|
||||
return true;
|
||||
}
|
||||
if (status != null && ("success".equalsIgnoreCase(status) || "ok".equalsIgnoreCase(status))) {
|
||||
return true;
|
||||
}
|
||||
if (message != null && ("success".equalsIgnoreCase(message) || "ok".equalsIgnoreCase(message))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
logger.warn("解析企业应用推送响应失败,将视为未成功: {}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user