|
@@ -1,7 +1,10 @@
|
|
|
package com.fjhx.uitl.kd100;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fjhx.config.KD100Config;
|
|
|
+import com.fjhx.constants.RedisConstant;
|
|
|
import com.fjhx.constants.logistics.LogisticsConstant;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.kuaidi100.sdk.api.QueryTrack;
|
|
@@ -14,15 +17,19 @@ import com.kuaidi100.sdk.utils.SignUtils;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.redis.cache.BladeRedis;
|
|
|
import org.springblade.core.tool.api.ResultCode;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
|
|
|
import java.net.URLDecoder;
|
|
|
+import java.util.Date;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
@Log4j2
|
|
|
public class KD100Util {
|
|
|
|
|
|
+ private final static BladeRedis bladeRedis = SpringUtil.getBean(BladeRedis.class);
|
|
|
+
|
|
|
/**
|
|
|
* 实时快递查询接口
|
|
|
*
|
|
@@ -59,8 +66,8 @@ public class KD100Util {
|
|
|
* @param num 快递单号
|
|
|
* @return
|
|
|
*/
|
|
|
- public static JSONObject subscribe(String com, String num) {
|
|
|
- HttpResult result = new HttpResult();
|
|
|
+ public static JSONObject subscribe(String com, String num, Date date) {
|
|
|
+ HttpResult result;
|
|
|
try {
|
|
|
SubscribeParameters subscribeParameters = new SubscribeParameters();
|
|
|
subscribeParameters.setCallbackurl(KD100Config.getCallbackurl());
|
|
@@ -81,7 +88,7 @@ public class KD100Util {
|
|
|
log.error(e.toString());
|
|
|
throw new ServiceException("请求第三方快递订阅功能异常,请联系管理员!");
|
|
|
}
|
|
|
- return parseSubscribeData(result);
|
|
|
+ return parseSubscribeData(result, com, num, date);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -109,13 +116,26 @@ public class KD100Util {
|
|
|
* @param result 数据结果
|
|
|
* @return
|
|
|
*/
|
|
|
- private static JSONObject parseSubscribeData(HttpResult result) {
|
|
|
+ private static JSONObject parseSubscribeData(HttpResult result, String com, String num, Date date) {
|
|
|
if (Func.isNotEmpty(result) && result.getStatus() == ResultCode.SUCCESS.getCode()) {
|
|
|
JSONObject body = JSONObject.parseObject(result.getBody());
|
|
|
if (Func.isNotEmpty(body) && body.getBoolean("result")) {
|
|
|
return body;
|
|
|
} else {
|
|
|
- throw new ServiceException("操作失败,原因:物流信息【" + body.getString("message") + "】,请稍后重试,或者联系管理员!");
|
|
|
+
|
|
|
+ if (DateUtil.betweenDay(new Date(), date, false) < 3) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("com", com);
|
|
|
+ jsonObject.put("num", num);
|
|
|
+ jsonObject.put("date", date);
|
|
|
+ bladeRedis.set(RedisConstant.KD_100_SEND_SUBSCRIBE + com + ":" + num, jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.error("监听物流消息失败: com:{}, num:{}, messageL{}", com, num, body.toString());
|
|
|
+
|
|
|
+ return body;
|
|
|
+
|
|
|
+ // throw new ServiceException("操作失败,原因:物流信息【" + body.getString("message") + "】,请稍后重试,或者联系管理员!");
|
|
|
}
|
|
|
} else {
|
|
|
throw new ServiceException("物流信息订阅失败,请稍后重试,或者联系管理员!");
|
|
@@ -160,7 +180,7 @@ public class KD100Util {
|
|
|
new Thread(() -> {
|
|
|
if (!Objects.equals(state, LogisticsConstant.KD100Status.STATUS_3)) {
|
|
|
//如果不是已签收状态,则开启订阅(物流状态跟踪并推送)
|
|
|
- KD100Util.subscribe(logisticsCompanyCode, code);
|
|
|
+ KD100Util.subscribe(logisticsCompanyCode, code, new Date());
|
|
|
}
|
|
|
}).start();
|
|
|
return state;
|