记得上下班打卡 | git大法好,push需谨慎

Commit b74ea203 authored by 姜秀龙's avatar 姜秀龙

补充主动查询逻辑

parent 44065b25
......@@ -118,6 +118,8 @@ public class GoblinMailTrackServiceImpl implements IGoblinMailTrackService {
return;
}
doSubscribe(orderId, mailId, mailNo, com, cache);
// 订阅成功也立刻主动查一次,避免等推送才有 track
queryAndOverwriteTrack(orderId, mailId, com, mailNo, "query");
}
@Override
......@@ -129,54 +131,58 @@ public class GoblinMailTrackServiceImpl implements IGoblinMailTrackService {
// 统一用包裹真实 mailId(兼容误传 mailNo)
mailId = mailVo.getMailId();
GoblinMailTrackCache cache = redisUtils.getMailTrackCache(mailId);
boolean emptyOrUnsubscribed = cache == null
|| cache.getSubscribe() == null
|| !Boolean.TRUE.equals(cache.getSubscribe().getSubscribed());
if (emptyOrUnsubscribed) {
String com = resolveAndPersistCom(orderId, mailVo);
if (cache == null) {
if (cache == null || cache.getSubscribe() == null) {
cache = newEmptyCache(orderId, mailId);
}
GoblinMailTrackSubscribeVo sub = cache.getSubscribe();
ensureMonthCounter(sub);
boolean finished = "shutdown".equals(sub.getSubscribeStatus())
|| (cache.getTrack() != null && "1".equals(cache.getTrack().getIscheck()));
// 已结束且已有轨迹:只读
if (finished && hasTrackData(cache)) {
return cache;
}
String com = resolveAndPersistCom(orderId, mailVo);
if (StringUtils.isBlank(com)) {
updateSubscribeFail(cache, "无法识别快递公司编码");
redisUtils.setMailTrackCache(mailId, cache);
return cache;
}
// 未订阅成功时可尝试首次订阅(未超限)
ensureMonthCounter(cache.getSubscribe());
if (!Boolean.TRUE.equals(cache.getSubscribe().getQuotaExceeded())
&& (cache.getSubscribe().getSubscribeCount() == null || cache.getSubscribe().getSubscribeCount() < MAX_SUBSCRIBE_PER_MONTH)
&& !Boolean.TRUE.equals(cache.getSubscribe().getSubscribed())) {
boolean overQuota = Boolean.TRUE.equals(sub.getQuotaExceeded())
|| (sub.getSubscribeCount() != null && sub.getSubscribeCount() >= MAX_SUBSCRIBE_PER_MONTH);
if (overQuota) {
sub.setQuotaExceeded(true);
}
// 订阅与查轨迹分开:已订阅则不再订;未订阅/需重订且未超限才订
boolean needSubscribe = !finished && !overQuota
&& (!Boolean.TRUE.equals(sub.getSubscribed()) || Boolean.TRUE.equals(sub.getNeedResubscribe()));
if (needSubscribe) {
doSubscribe(orderId, mailId, mailVo.getMailNo(), com, cache);
cache = redisUtils.getMailTrackCache(mailId);
if (cache == null) {
cache = newEmptyCache(orderId, mailId);
}
sub = cache.getSubscribe();
}
// 无轨迹(或超限只能靠主动查)则 QueryTrackMap
if (!hasTrackData(cache) || overQuota) {
queryAndOverwriteTrack(orderId, mailId, com, mailVo.getMailNo(), "query");
GoblinMailTrackCache latest = redisUtils.getMailTrackCache(mailId);
return latest != null ? latest : cache;
}
GoblinMailTrackSubscribeVo sub = cache.getSubscribe();
if ("shutdown".equals(sub.getSubscribeStatus()) || "1".equals(cache.getTrack() != null ? cache.getTrack().getIscheck() : null)) {
return cache;
}
if (Boolean.TRUE.equals(sub.getQuotaExceeded())
|| (sub.getSubscribeCount() != null && sub.getSubscribeCount() >= MAX_SUBSCRIBE_PER_MONTH)) {
sub.setQuotaExceeded(true);
String com = resolveAndPersistCom(orderId, mailVo);
queryAndOverwriteTrack(orderId, mailId, com, mailVo.getMailNo(), "query");
return redisUtils.getMailTrackCache(mailId);
}
if (Boolean.TRUE.equals(sub.getNeedResubscribe())) {
String com = resolveAndPersistCom(orderId, mailVo);
doSubscribe(orderId, mailId, mailVo.getMailNo(), com, cache);
queryAndOverwriteTrack(orderId, mailId, com, mailVo.getMailNo(), "query");
return redisUtils.getMailTrackCache(mailId);
}
return cache;
/** 是否已有可用轨迹点(仅有 subscribe、track 为空不算) */
private boolean hasTrackData(GoblinMailTrackCache cache) {
return cache != null
&& cache.getTrack() != null
&& !CollectionUtils.isEmpty(cache.getTrack().getData());
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment