mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 03:19:18 +08:00
feat: 三侧增量态表增加最后摘要
This commit is contained in:
+4
@@ -34,6 +34,10 @@ public class BiOrderStatIncCalcPO {
|
||||
@TableField("last_error")
|
||||
private String lastError;
|
||||
|
||||
/** 最后一次计算摘要(成功说明或失败提示;展示优先) */
|
||||
@TableField("last_summary")
|
||||
private String lastSummary;
|
||||
|
||||
@TableField("last_success_time")
|
||||
private LocalDateTime lastSuccessTime;
|
||||
|
||||
|
||||
+7
-1
@@ -142,6 +142,10 @@ public class BiOrderStatCalcTaskService {
|
||||
state.setLastAppliedOrderId(orderId);
|
||||
}
|
||||
state.setLastSkipped(skipped ? 1 : 0);
|
||||
state.setLastSummary(skipped
|
||||
? ("计算跳过(快照内),统计日 " + (statDate != null ? statDate : "-"))
|
||||
: ("计算已累加,统计日 " + (statDate != null ? statDate : "-")
|
||||
+ (orderId != null ? ",订单#" + orderId : "")));
|
||||
incCalcMapper.updateById(state);
|
||||
}
|
||||
|
||||
@@ -152,7 +156,9 @@ public class BiOrderStatCalcTaskService {
|
||||
}
|
||||
BiOrderStatIncCalcPO state = getOrCreateInc(companyId, internalShopId);
|
||||
state.setStatus(BiOrderStatIncCalcPO.STATUS_PAUSED);
|
||||
state.setLastError(truncate(error, 1000));
|
||||
String detail = truncate(error, 1000);
|
||||
state.setLastError(detail);
|
||||
state.setLastSummary(truncate("计算失败:" + (detail != null ? detail : "未知错误"), 500));
|
||||
incCalcMapper.updateById(state);
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -36,6 +36,10 @@ public class PddOrderIncConvertPO {
|
||||
@TableField("last_error")
|
||||
private String lastError;
|
||||
|
||||
/** 最后一次转换摘要(成功说明或失败提示;展示优先) */
|
||||
@TableField("last_summary")
|
||||
private String lastSummary;
|
||||
|
||||
@TableField("last_success_time")
|
||||
private LocalDateTime lastSuccessTime;
|
||||
|
||||
|
||||
+6
-2
@@ -182,8 +182,10 @@ public class PddOrderFullConvertTaskService {
|
||||
PddOrderIncConvertPO state = getOrCreateInc(channelShopId, companyId);
|
||||
state.setStatus(PddOrderIncConvertPO.STATUS_OK);
|
||||
state.setLastError(null);
|
||||
int n = Math.max(convertedCount, 0);
|
||||
state.setLastConvertedCount(n);
|
||||
state.setLastSummary("本批转换完成:" + n + " 单");
|
||||
state.setLastSuccessTime(LocalDateTime.now());
|
||||
state.setLastConvertedCount(Math.max(convertedCount, 0));
|
||||
if (lastCursorAt != null) {
|
||||
state.setLastCursorAt(lastCursorAt);
|
||||
}
|
||||
@@ -197,7 +199,9 @@ public class PddOrderFullConvertTaskService {
|
||||
}
|
||||
PddOrderIncConvertPO state = getOrCreateInc(channelShopId, companyId);
|
||||
state.setStatus(PddOrderIncConvertPO.STATUS_PAUSED);
|
||||
state.setLastError(truncate(error, 1000));
|
||||
String detail = truncate(error, 1000);
|
||||
state.setLastError(detail);
|
||||
state.setLastSummary(truncate("转换失败:" + (detail != null ? detail : "未知错误"), 500));
|
||||
incConvertMapper.updateById(state);
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -37,6 +37,10 @@ public class PddOrderIncSyncPO {
|
||||
@TableField("last_error")
|
||||
private String lastError;
|
||||
|
||||
/** 最后一次同步摘要(成功说明或失败提示;展示优先) */
|
||||
@TableField("last_summary")
|
||||
private String lastSummary;
|
||||
|
||||
@TableField("last_success_time")
|
||||
private LocalDateTime lastSuccessTime;
|
||||
|
||||
|
||||
+2
@@ -18,6 +18,8 @@ public class PddOrderIncrementalStatusVO {
|
||||
/** 1=正常 2=出错暂停 */
|
||||
private Integer cursorStatus;
|
||||
private String lastError;
|
||||
/** 最后一次同步摘要(成功说明或失败提示;展示优先于 lastError) */
|
||||
private String lastSummary;
|
||||
private LocalDateTime lastCursorAt;
|
||||
private LocalDateTime lastSuccessTime;
|
||||
private Integer overlapSeconds;
|
||||
|
||||
+1
@@ -451,6 +451,7 @@ public class PddOrderFullSyncTaskService {
|
||||
.enabled(enabled)
|
||||
.cursorStatus(state != null ? state.getStatus() : null)
|
||||
.lastError(state != null ? state.getLastError() : null)
|
||||
.lastSummary(state != null ? state.getLastSummary() : null)
|
||||
.lastCursorAt(state != null ? state.getLastCursorAt() : null)
|
||||
.lastSuccessTime(state != null ? state.getLastSuccessTime() : null)
|
||||
.overlapSeconds(state != null ? state.getOverlapSeconds() : null)
|
||||
|
||||
+6
-2
@@ -78,14 +78,18 @@ public class PddOrderSyncAuthFailureHandler {
|
||||
.last("LIMIT 1"));
|
||||
if (state != null) {
|
||||
state.setStatus(PddOrderIncSyncPO.STATUS_PAUSED);
|
||||
state.setLastError(msg != null ? msg : "拼多多授权失效,请重新授权");
|
||||
String detail = msg != null ? msg : "拼多多授权失效,请重新授权";
|
||||
state.setLastError(truncate(detail, 1000));
|
||||
state.setLastSummary(truncate("同步失败:" + detail, 500));
|
||||
incSyncMapper.updateById(state);
|
||||
} else {
|
||||
PddOrderIncSyncPO neu = new PddOrderIncSyncPO();
|
||||
neu.setCompanyId(companyId);
|
||||
neu.setShopId(resolvedChannel);
|
||||
neu.setStatus(PddOrderIncSyncPO.STATUS_PAUSED);
|
||||
neu.setLastError(msg != null ? msg : "拼多多授权失效,请重新授权");
|
||||
String detail = msg != null ? msg : "拼多多授权失效,请重新授权";
|
||||
neu.setLastError(truncate(detail, 1000));
|
||||
neu.setLastSummary(truncate("同步失败:" + detail, 500));
|
||||
incSyncMapper.insert(neu);
|
||||
}
|
||||
}
|
||||
|
||||
+25
-4
@@ -362,6 +362,8 @@ public class PddOrderSyncService {
|
||||
endTs = startTs + 1;
|
||||
}
|
||||
|
||||
int windowFetched = 0;
|
||||
int windowUpserted = 0;
|
||||
int page = 1;
|
||||
boolean hasNext = true;
|
||||
while (hasNext) {
|
||||
@@ -370,6 +372,7 @@ public class PddOrderSyncService {
|
||||
List<ChannelOrderRef> pageRefs = new ArrayList<>();
|
||||
for (PddOrderPopApiClient.RawOrder raw : pageData.orders()) {
|
||||
fetched++;
|
||||
windowFetched++;
|
||||
PddOrderUpsertService.UpsertResult ur =
|
||||
upsertService.upsertWithMeta(ctx, raw.snapshot(), raw.raw(), false);
|
||||
if (ur != null && ur.id() != null && ur.changed()) {
|
||||
@@ -379,6 +382,7 @@ public class PddOrderSyncService {
|
||||
}
|
||||
upsertedIds.add(ur.id());
|
||||
upserted++;
|
||||
windowUpserted++;
|
||||
}
|
||||
}
|
||||
if (!pageRefs.isEmpty()) {
|
||||
@@ -387,7 +391,7 @@ public class PddOrderSyncService {
|
||||
hasNext = pageData.hasNext();
|
||||
page++;
|
||||
}
|
||||
saveIncSuccess(ctx, windowEnd);
|
||||
saveIncSuccess(ctx, windowEnd, windowFetched, windowUpserted);
|
||||
windowStart = windowEnd;
|
||||
}
|
||||
} catch (PddPopRateLimitedException e) {
|
||||
@@ -434,11 +438,17 @@ public class PddOrderSyncService {
|
||||
return state;
|
||||
}
|
||||
|
||||
private void saveIncSuccess(PddOrderSyncShopContext ctx, LocalDateTime cursorAt) {
|
||||
private void saveIncSuccess(PddOrderSyncShopContext ctx, LocalDateTime cursorAt,
|
||||
int windowFetched, int windowUpserted) {
|
||||
PddOrderIncSyncPO state = getOrCreateIncState(ctx);
|
||||
state.setLastCursorAt(cursorAt);
|
||||
state.setStatus(PddOrderIncSyncPO.STATUS_OK);
|
||||
state.setLastError(null);
|
||||
state.setLastSummary(truncateSummary(String.format(
|
||||
"窗口同步完成:拉取 %d,变更 %d,游标至 %s",
|
||||
Math.max(windowFetched, 0),
|
||||
Math.max(windowUpserted, 0),
|
||||
cursorAt != null ? cursorAt.format(java.time.format.DateTimeFormatter.ofPattern("MM-dd HH:mm")) : "-")));
|
||||
state.setLastSuccessTime(LocalDateTime.now(ZONE));
|
||||
state.setOverlapSeconds(syncProperties.getOverlapSeconds());
|
||||
incSyncMapper.updateById(state);
|
||||
@@ -448,7 +458,9 @@ public class PddOrderSyncService {
|
||||
try {
|
||||
PddOrderIncSyncPO state = getOrCreateIncState(ctx);
|
||||
state.setStatus(PddOrderIncSyncPO.STATUS_PAUSED);
|
||||
state.setLastError(truncateError(error));
|
||||
String detail = truncateError(error);
|
||||
state.setLastError(detail);
|
||||
state.setLastSummary(truncateSummary("同步失败:" + (detail != null ? detail : "未知错误")));
|
||||
incSyncMapper.updateById(state);
|
||||
} catch (Exception e) {
|
||||
log.warn("写入增量状态错误失败: {}", e.getMessage());
|
||||
@@ -487,7 +499,9 @@ public class PddOrderSyncService {
|
||||
if (state.getStatus() == null || state.getStatus() == 0) {
|
||||
state.setStatus(PddOrderIncSyncPO.STATUS_OK);
|
||||
}
|
||||
state.setLastError(truncateError(error));
|
||||
String detail = truncateError(error);
|
||||
state.setLastError(detail);
|
||||
state.setLastSummary(truncateSummary("同步限流:" + (detail != null ? detail : "触限")));
|
||||
incSyncMapper.updateById(state);
|
||||
} catch (Exception e) {
|
||||
log.warn("写入增量限流备注失败: {}", e.getMessage());
|
||||
@@ -501,6 +515,13 @@ public class PddOrderSyncService {
|
||||
return error.length() > 900 ? error.substring(0, 900) : error;
|
||||
}
|
||||
|
||||
private static String truncateSummary(String summary) {
|
||||
if (summary == null) {
|
||||
return null;
|
||||
}
|
||||
return summary.length() > 500 ? summary.substring(0, 500) : summary;
|
||||
}
|
||||
|
||||
private void notifyListeners(PddOrderSyncShopContext ctx, List<Long> ids, String mode) {
|
||||
if (ids == null || ids.isEmpty() || afterSyncListeners.isEmpty()) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user