mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
feat: 三侧增量态表增加最后摘要
This commit is contained in:
@@ -44,7 +44,8 @@ CREATE TABLE `bi_order_stat_inc_calc` (
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '内部店铺ID(ec_shop.id)',
|
||||
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1正常 2出错暂停',
|
||||
`last_error` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最近一次错误信息',
|
||||
`last_error` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最后一次错误详情(运维排查)',
|
||||
`last_summary` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最后一次计算摘要(成功说明或失败提示;展示优先;成功时清空 last_error)',
|
||||
`last_success_time` datetime NULL DEFAULT NULL COMMENT '最近一次成功应用时间',
|
||||
`last_stat_date` date NULL DEFAULT NULL COMMENT '最近一次成功应用的统计日',
|
||||
`last_applied_order_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '最近一次成功应用的内部订单ID(展示用)',
|
||||
|
||||
@@ -41,7 +41,8 @@ CREATE TABLE `channel_pdd_order_inc_convert` (
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '渠道店铺ID(channel_pdd_shop.id)',
|
||||
`last_cursor_at` datetime NULL DEFAULT NULL COMMENT '已成功转换到的渠道订单更新时间游标(展示/滞后判断;对齐 pdd_updated_at)',
|
||||
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1正常 2出错暂停',
|
||||
`last_error` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最近一次错误信息',
|
||||
`last_error` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最后一次错误详情(运维排查)',
|
||||
`last_summary` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最后一次转换摘要(成功说明或失败提示;展示优先;成功时清空 last_error)',
|
||||
`last_success_time` datetime NULL DEFAULT NULL COMMENT '最近一次成功完成时间',
|
||||
`last_converted_count` int NOT NULL DEFAULT 0 COMMENT '最近一次批次成功转换单数(展示用)',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
|
||||
@@ -40,7 +40,8 @@ CREATE TABLE `channel_pdd_order_inc_sync` (
|
||||
`last_cursor_at` datetime NULL DEFAULT NULL COMMENT '已成功同步到的更新时间游标',
|
||||
`overlap_seconds` int NOT NULL DEFAULT 120 COMMENT '窗口重叠秒数(防边界漏单,默认 120)',
|
||||
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1正常 2出错暂停',
|
||||
`last_error` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最近一次错误信息',
|
||||
`last_error` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最后一次错误详情(运维排查)',
|
||||
`last_summary` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最后一次同步摘要(成功说明或失败提示;展示优先;成功时清空 last_error)',
|
||||
`last_success_time` datetime NULL DEFAULT NULL COMMENT '最近一次成功完成时间',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
-- 增量店态三表增加 last_summary(成功摘要;成功写摘要时清空 last_error)
|
||||
|
||||
DROP PROCEDURE IF EXISTS `tmp_add_col_if_missing`;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE PROCEDURE `tmp_add_col_if_missing`(
|
||||
IN p_table VARCHAR(64),
|
||||
IN p_column VARCHAR(64),
|
||||
IN p_ddl TEXT
|
||||
)
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = p_table
|
||||
AND COLUMN_NAME = p_column
|
||||
) THEN
|
||||
SET @sql = CONCAT('ALTER TABLE `', p_table, '` ', p_ddl);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
||||
CALL `tmp_add_col_if_missing`(
|
||||
'channel_pdd_order_inc_sync',
|
||||
'last_summary',
|
||||
'ADD COLUMN `last_summary` varchar(500) NULL DEFAULT NULL COMMENT ''最近一次成功摘要'' AFTER `last_error`'
|
||||
);
|
||||
|
||||
CALL `tmp_add_col_if_missing`(
|
||||
'channel_pdd_order_inc_convert',
|
||||
'last_summary',
|
||||
'ADD COLUMN `last_summary` varchar(500) NULL DEFAULT NULL COMMENT ''最近一次成功摘要'' AFTER `last_error`'
|
||||
);
|
||||
|
||||
CALL `tmp_add_col_if_missing`(
|
||||
'bi_order_stat_inc_calc',
|
||||
'last_summary',
|
||||
'ADD COLUMN `last_summary` varchar(500) NULL DEFAULT NULL COMMENT ''最近一次成功摘要'' AFTER `last_error`'
|
||||
);
|
||||
|
||||
DROP PROCEDURE IF EXISTS `tmp_add_col_if_missing`;
|
||||
+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;
|
||||
|
||||
@@ -34,6 +34,8 @@ export namespace PddOrderSyncVO {
|
||||
enabled: boolean;
|
||||
cursorStatus?: number;
|
||||
lastError?: string;
|
||||
/** 最后一次同步摘要(成功说明或失败提示;展示优先于 lastError) */
|
||||
lastSummary?: string;
|
||||
lastCursorAt?: string;
|
||||
lastSuccessTime?: string;
|
||||
overlapSeconds?: number;
|
||||
|
||||
+13
-3
@@ -106,6 +106,16 @@ const incHealthColor = computed(() => {
|
||||
return 'default';
|
||||
});
|
||||
|
||||
/** 只展示摘要(含失败提示);完整 lastError 不在抽屉展示 */
|
||||
const incStatusMessage = computed(() => incremental.value?.lastSummary || '');
|
||||
|
||||
const incStatusAlertType = computed(() => {
|
||||
const s = incremental.value?.lastSummary || '';
|
||||
if (s.includes('失败') || s.includes('限流')) return 'error';
|
||||
if (s) return 'info';
|
||||
return 'info';
|
||||
});
|
||||
|
||||
function formatTime(time?: null | string) {
|
||||
if (!time) return '-';
|
||||
const d = dayjs(time);
|
||||
@@ -459,10 +469,10 @@ defineExpose({ open, close: handleClose });
|
||||
</Descriptions>
|
||||
|
||||
<Alert
|
||||
v-if="incremental?.lastError"
|
||||
type="error"
|
||||
v-if="incStatusMessage"
|
||||
:type="incStatusAlertType"
|
||||
show-icon
|
||||
:message="incremental.lastError"
|
||||
:message="incStatusMessage"
|
||||
/>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user