feat: 订单转换和计算侧增加手动创建全量任务功能

This commit is contained in:
2026-08-23 03:02:41 +08:00
parent af4008ae4c
commit d57745effb
14 changed files with 1429 additions and 1162 deletions
@@ -26,3 +26,15 @@ export async function listBiOrderStatFullCalcTasksApi(
{ params: { shopId, limit } },
);
}
/** 手动创建 BI 全量计算任务 */
export async function createBiOrderStatFullCalcTaskApi(data: {
shopId: number;
dateFrom: string;
dateTo: string;
}) {
return requestClient.post<BiOrderStatCalcVO.FullTask>(
'/bi/order-stat/calc/full-task',
data,
);
}
@@ -26,3 +26,15 @@ export async function listPddOrderConvertFullTasksApi(
{ params: { shopId, limit } },
);
}
/** 手动创建全量转换任务(按渠道镜像扫日) */
export async function createPddOrderConvertFullTaskApi(data: {
shopId: number;
dateFrom: string;
dateTo: string;
}) {
return requestClient.post<PddOrderConvertVO.FullTask>(
'/channel/pdd/order/convert/full-task',
data,
);
}
@@ -1,254 +0,0 @@
<script lang="ts" setup>
import type { ShopVO } from '#/api/ec/shop/types';
import type { BiOrderStatCalcVO } from '#/api/bi/order-stat-calc';
import { computed, ref } from 'vue';
import {
Alert,
Button,
Card,
Descriptions,
Empty,
List,
Modal,
Progress,
Space,
Tag,
Typography,
message,
} from 'ant-design-vue';
import dayjs from 'dayjs';
import {
getBiOrderStatIncCalcStatusApi,
listBiOrderStatFullCalcTasksApi,
resumeBiOrderStatIncCalcApi,
} from '#/api/bi/order-stat-calc';
defineOptions({ name: 'BiOrderStatCalcModal' });
const emit = defineEmits<{ success: [] }>();
const openFlag = ref(false);
const shop = ref<null | ShopVO.Info>(null);
const loading = ref(false);
const listLoading = ref(false);
const resuming = ref(false);
const incremental = ref<null | BiOrderStatCalcVO.IncStatus>(null);
const fullTasks = ref<BiOrderStatCalcVO.FullTask[]>([]);
const title = computed(() =>
shop.value ? `BI 计算 - ${shop.value.name}` : 'BI 计算',
);
const statusLabel = computed(() => {
const s = incremental.value?.status;
if (s === 2) return '出错暂停';
if (s === 1) return '正常';
return '未开始';
});
const statusColor = computed(() => {
const s = incremental.value?.status;
if (s === 2) return 'error';
if (s === 1) return 'success';
return 'default';
});
function formatTime(time?: null | string) {
if (!time) return '-';
const d = dayjs(time);
return d.isValid() ? d.format('YYYY-MM-DD HH:mm:ss') : '-';
}
function statusTag(status: string) {
const map: Record<string, { color: string; text: string }> = {
PENDING: { color: 'default', text: '等待中' },
RUNNING: { color: 'processing', text: '执行中' },
SUCCESS: { color: 'success', text: '成功' },
FAILED: { color: 'error', text: '失败' },
CANCELLED: { color: 'warning', text: '已取消' },
};
return map[status] || { color: 'default', text: status };
}
function taskProgressPercent(task: BiOrderStatCalcVO.FullTask) {
if (!task.totalDays) return 0;
return Math.min(100, Math.round((task.doneDays / task.totalDays) * 100));
}
async function loadInc() {
if (!shop.value) return;
try {
incremental.value = await getBiOrderStatIncCalcStatusApi(shop.value.id);
} catch (error) {
console.error('加载 BI 计算店态失败:', error);
}
}
async function loadFullTasks() {
if (!shop.value) return;
try {
listLoading.value = true;
fullTasks.value = await listBiOrderStatFullCalcTasksApi(shop.value.id, 30);
} catch (error) {
console.error('加载全量计算任务失败:', error);
} finally {
listLoading.value = false;
}
}
async function handleResume() {
if (!shop.value) return;
try {
resuming.value = true;
incremental.value = await resumeBiOrderStatIncCalcApi(shop.value.id);
message.success('已恢复计算');
emit('success');
} catch (error) {
console.error('恢复计算失败:', error);
message.error('恢复计算失败');
} finally {
resuming.value = false;
}
}
function handleClose() {
openFlag.value = false;
}
async function open(record: ShopVO.Info) {
shop.value = record;
incremental.value = null;
fullTasks.value = [];
openFlag.value = true;
loading.value = true;
try {
await Promise.all([loadInc(), loadFullTasks()]);
} finally {
loading.value = false;
}
}
defineExpose({ open, close: handleClose });
</script>
<template>
<Modal
v-model:open="openFlag"
:title="title"
:width="720"
:footer="null"
destroy-on-close
@cancel="handleClose"
>
<Space direction="vertical" :size="16" class="w-full">
<Card size="small">
<template #title>
<Space>
<span>增量计算</span>
<Tag :color="statusColor">{{ statusLabel }}</Tag>
</Space>
</template>
<template #extra>
<Button
v-if="incremental?.status === 2"
size="small"
type="primary"
:loading="resuming"
@click="handleResume"
>
恢复运行
</Button>
</template>
<Space direction="vertical" :size="12" class="w-full">
<Typography.Text type="secondary">
将转换侧 delta 累加到 BI 日汇聚;出错暂停后需人工恢复。
</Typography.Text>
<Descriptions bordered size="small" :column="1">
<Descriptions.Item label="上次成功">
{{ formatTime(incremental?.lastSuccessTime) }}
</Descriptions.Item>
<Descriptions.Item label="最近统计日">
{{ incremental?.lastStatDate || '-' }}
</Descriptions.Item>
<Descriptions.Item label="最近订单">
{{
incremental?.lastAppliedOrderId
? `#${incremental.lastAppliedOrderId}`
: '-'
}}
</Descriptions.Item>
</Descriptions>
<Alert
v-if="incremental?.lastSummary"
:type="incremental?.status === 2 ? 'error' : 'info'"
show-icon
:message="incremental.lastSummary"
/>
</Space>
</Card>
<Card size="small" title="全量计算任务">
<template #extra>
<Button size="small" :loading="listLoading" @click="loadFullTasks">
刷新
</Button>
</template>
<List
v-if="fullTasks.length > 0"
:data-source="fullTasks"
:loading="listLoading"
item-layout="vertical"
size="small"
class="max-h-[40vh] overflow-y-auto"
>
<template #renderItem="{ item: task }">
<List.Item>
<List.Item.Meta>
<template #title>
<Space wrap>
<span>#{{ task.id }}</span>
<Tag :color="statusTag(task.status).color">
{{ statusTag(task.status).text }}
</Tag>
<Typography.Text type="secondary">
{{ task.doneDays }}/{{ task.totalDays }} 天
</Typography.Text>
</Space>
</template>
<template #description>
<div>区间 {{ task.dateFrom }} ~ {{ task.dateTo }}</div>
<div>
创建 {{ formatTime(task.createTime) }}
<template v-if="task.finishTime">
· 结束 {{ formatTime(task.finishTime) }}
</template>
</div>
</template>
</List.Item.Meta>
<Progress
v-if="task.status === 'RUNNING' || task.status === 'SUCCESS'"
:percent="taskProgressPercent(task)"
size="small"
/>
<Alert
v-if="task.lastError"
class="mt-2"
type="error"
show-icon
:message="task.lastError"
/>
</List.Item>
</template>
</List>
<Empty
v-else
:image="Empty.PRESENTED_IMAGE_SIMPLE"
description="暂无全量计算任务"
/>
</Card>
</Space>
</Modal>
</template>
@@ -1,250 +0,0 @@
<script lang="ts" setup>
import type { ShopVO } from '#/api/ec/shop/types';
import type { PddOrderConvertVO } from '#/api/channel/pdd/order-convert';
import { computed, ref } from 'vue';
import {
Alert,
Button,
Card,
Descriptions,
Empty,
List,
Modal,
Progress,
Space,
Tag,
Typography,
message,
} from 'ant-design-vue';
import dayjs from 'dayjs';
import {
getPddOrderConvertIncStatusApi,
listPddOrderConvertFullTasksApi,
resumePddOrderConvertIncApi,
} from '#/api/channel/pdd/order-convert';
defineOptions({ name: 'PddOrderConvertModal' });
const emit = defineEmits<{ success: [] }>();
const openFlag = ref(false);
const shop = ref<null | ShopVO.Info>(null);
const loading = ref(false);
const listLoading = ref(false);
const resuming = ref(false);
const incremental = ref<null | PddOrderConvertVO.IncStatus>(null);
const fullTasks = ref<PddOrderConvertVO.FullTask[]>([]);
const title = computed(() =>
shop.value ? `订单转换 - ${shop.value.name}` : '订单转换',
);
const statusLabel = computed(() => {
const s = incremental.value?.status;
if (s === 2) return '出错暂停';
if (s === 1) return '正常';
return '未开始';
});
const statusColor = computed(() => {
const s = incremental.value?.status;
if (s === 2) return 'error';
if (s === 1) return 'success';
return 'default';
});
function formatTime(time?: null | string) {
if (!time) return '-';
const d = dayjs(time);
return d.isValid() ? d.format('YYYY-MM-DD HH:mm:ss') : '-';
}
function statusTag(status: string) {
const map: Record<string, { color: string; text: string }> = {
PENDING: { color: 'default', text: '等待中' },
RUNNING: { color: 'processing', text: '执行中' },
SUCCESS: { color: 'success', text: '成功' },
FAILED: { color: 'error', text: '失败' },
CANCELLED: { color: 'warning', text: '已取消' },
};
return map[status] || { color: 'default', text: status };
}
function taskProgressPercent(task: PddOrderConvertVO.FullTask) {
if (!task.totalDays) return 0;
return Math.min(100, Math.round((task.doneDays / task.totalDays) * 100));
}
async function loadInc() {
if (!shop.value) return;
try {
incremental.value = await getPddOrderConvertIncStatusApi(shop.value.id);
} catch (error) {
console.error('加载转换店态失败:', error);
}
}
async function loadFullTasks() {
if (!shop.value) return;
try {
listLoading.value = true;
fullTasks.value = await listPddOrderConvertFullTasksApi(shop.value.id, 30);
} catch (error) {
console.error('加载全量转换任务失败:', error);
} finally {
listLoading.value = false;
}
}
async function handleResume() {
if (!shop.value) return;
try {
resuming.value = true;
incremental.value = await resumePddOrderConvertIncApi(shop.value.id);
message.success('已恢复转换');
emit('success');
} catch (error) {
console.error('恢复转换失败:', error);
message.error('恢复转换失败');
} finally {
resuming.value = false;
}
}
function handleClose() {
openFlag.value = false;
}
async function open(record: ShopVO.Info) {
shop.value = record;
incremental.value = null;
fullTasks.value = [];
openFlag.value = true;
loading.value = true;
try {
await Promise.all([loadInc(), loadFullTasks()]);
} finally {
loading.value = false;
}
}
defineExpose({ open, close: handleClose });
</script>
<template>
<Modal
v-model:open="openFlag"
:title="title"
:width="720"
:footer="null"
destroy-on-close
@cancel="handleClose"
>
<Space direction="vertical" :size="16" class="w-full">
<Card size="small">
<template #title>
<Space>
<span>增量转换</span>
<Tag :color="statusColor">{{ statusLabel }}</Tag>
</Space>
</template>
<template #extra>
<Button
v-if="incremental?.status === 2"
size="small"
type="primary"
:loading="resuming"
@click="handleResume"
>
恢复运行
</Button>
</template>
<Space direction="vertical" :size="12" class="w-full">
<Typography.Text type="secondary">
将渠道订单写入内部订单;出错暂停后需人工恢复才会继续消费。
</Typography.Text>
<Descriptions bordered size="small" :column="1">
<Descriptions.Item label="上次成功">
{{ formatTime(incremental?.lastSuccessTime) }}
</Descriptions.Item>
<Descriptions.Item label="转换游标">
{{ formatTime(incremental?.lastCursorAt) }}
</Descriptions.Item>
<Descriptions.Item label="最近批次单数">
{{ incremental?.lastConvertedCount ?? '-' }}
</Descriptions.Item>
</Descriptions>
<Alert
v-if="incremental?.lastSummary"
:type="incremental?.status === 2 ? 'error' : 'info'"
show-icon
:message="incremental.lastSummary"
/>
</Space>
</Card>
<Card size="small" title="全量转换任务">
<template #extra>
<Button size="small" :loading="listLoading" @click="loadFullTasks">
刷新
</Button>
</template>
<List
v-if="fullTasks.length > 0"
:data-source="fullTasks"
:loading="listLoading"
item-layout="vertical"
size="small"
class="max-h-[40vh] overflow-y-auto"
>
<template #renderItem="{ item: task }">
<List.Item>
<List.Item.Meta>
<template #title>
<Space wrap>
<span>#{{ task.id }}</span>
<Tag :color="statusTag(task.status).color">
{{ statusTag(task.status).text }}
</Tag>
<Typography.Text type="secondary">
{{ task.doneDays }}/{{ task.totalDays }} 天
</Typography.Text>
</Space>
</template>
<template #description>
<div>区间 {{ task.dateFrom }} ~ {{ task.dateTo }}</div>
<div>
创建 {{ formatTime(task.createTime) }}
<template v-if="task.finishTime">
· 结束 {{ formatTime(task.finishTime) }}
</template>
</div>
</template>
</List.Item.Meta>
<Progress
v-if="task.status === 'RUNNING' || task.status === 'SUCCESS'"
:percent="taskProgressPercent(task)"
size="small"
/>
<Alert
v-if="task.lastError"
class="mt-2"
type="error"
show-icon
:message="task.lastError"
/>
</List.Item>
</template>
</List>
<Empty
v-else
:image="Empty.PRESENTED_IMAGE_SIMPLE"
description="暂无全量转换任务"
/>
</Card>
</Space>
</Modal>
</template>
@@ -1,628 +0,0 @@
<script lang="ts" setup>
import type { ShopVO } from '#/api/ec/shop/types';
import type { PddOrderSyncVO } from '#/api/channel/pdd/order-sync';
import type { Dayjs } from 'dayjs';
import { computed, onBeforeUnmount, ref } from 'vue';
import {
Alert,
Button,
Card,
DatePicker,
Descriptions,
Empty,
Form,
List,
Modal,
Progress,
Radio,
Space,
Switch,
Tag,
Typography,
message,
} from 'ant-design-vue';
import dayjs from 'dayjs';
import {
cancelPddFullSyncTaskApi,
createPddFullSyncTaskApi,
getPddFullSyncTaskApi,
getPddIncrementalSyncStatusApi,
listPddFullSyncTasksApi,
resumePddFullSyncTaskApi,
syncPddOrdersIncrementalApi,
togglePddIncrementalSyncApi,
} from '#/api/channel/pdd/order-sync';
import { RealtimeSseEvent } from '#/api/notify/sse';
import { useRealtimeStore } from '#/store';
defineOptions({ name: 'PddOrderSyncModal' });
interface Emits {
(e: 'success'): void;
}
const emit = defineEmits<Emits>();
const FULL_SYNC_MAX_CALENDAR_DAYS = 90;
function fullSyncEarliest(): Dayjs {
return dayjs().startOf('day').subtract(FULL_SYNC_MAX_CALENDAR_DAYS - 1, 'day');
}
function fullSyncLatest(): Dayjs {
return dayjs().startOf('day');
}
function disabledFullSyncDate(current: Dayjs) {
if (!current) return false;
const d = current.startOf('day');
return d.isBefore(fullSyncEarliest()) || d.isAfter(fullSyncLatest());
}
const openFlag = ref(false);
const shop = ref<null | ShopVO.Info>(null);
const loading = ref(false);
const listLoading = ref(false);
const incSubmitting = ref(false);
const createSubmitting = ref(false);
const createModalOpen = ref(false);
const createMode = ref<'day' | 'range'>('range');
const confirmDate = ref<Dayjs>(dayjs().startOf('day'));
const range = ref<[Dayjs, Dayjs]>([fullSyncEarliest(), fullSyncLatest()]);
const incremental = ref<null | PddOrderSyncVO.IncrementalStatus>(null);
const fullTasks = ref<PddOrderSyncVO.FullTask[]>([]);
let pollTimer: null | ReturnType<typeof setInterval> = null;
let unsubProgress: (() => void) | null = null;
const terminalNotifiedTaskIds = new Set<number>();
const modalTitle = computed(() =>
shop.value ? `同步拼多多订单 - ${shop.value.name}` : '同步拼多多订单',
);
const hasActiveFullTask = computed(() =>
fullTasks.value.some((t) => t.status === 'PENDING' || t.status === 'RUNNING'),
);
const incHealthLabel = computed(() => {
const health = incremental.value?.health;
const map: Record<string, string> = {
OFF: '已关闭',
OK: '正常',
LAGGING: '游标滞后',
PAUSED: '出错暂停',
};
return health ? map[health] || health : '-';
});
const incHealthColor = computed(() => {
const health = incremental.value?.health;
if (health === 'PAUSED') return 'error';
if (health === 'LAGGING') return 'warning';
if (health === 'OK') return 'success';
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);
return d.isValid() ? d.format('YYYY-MM-DD HH:mm:ss') : '-';
}
function taskProgressPercent(task: PddOrderSyncVO.FullTask) {
if (!task.totalDays) return 0;
return Math.min(100, Math.round((task.doneDays / task.totalDays) * 100));
}
function statusTag(status: string) {
const map: Record<string, { color: string; text: string }> = {
PENDING: { color: 'default', text: '等待中' },
RUNNING: { color: 'processing', text: '执行中' },
SUCCESS: { color: 'success', text: '成功' },
FAILED: { color: 'error', text: '失败' },
CANCELLED: { color: 'warning', text: '已取消' },
};
return map[status] || { color: 'default', text: status };
}
function isTaskActive(task: PddOrderSyncVO.FullTask) {
return task.status === 'PENDING' || task.status === 'RUNNING';
}
function stopPoll() {
if (pollTimer) {
clearInterval(pollTimer);
pollTimer = null;
}
}
function unsubscribeProgress() {
unsubProgress?.();
unsubProgress = null;
}
function upsertTaskInList(task: PddOrderSyncVO.FullTask) {
const idx = fullTasks.value.findIndex((t) => t.id === task.id);
if (idx === -1) {
fullTasks.value.unshift(task);
} else {
fullTasks.value[idx] = task;
}
}
function applyFullTaskUpdate(task: PddOrderSyncVO.FullTask) {
if (!shop.value || task.shopId !== shop.value.id) {
return;
}
upsertTaskInList(task);
const terminal =
task.status === 'SUCCESS' ||
task.status === 'FAILED' ||
task.status === 'CANCELLED';
if (!terminal) {
return;
}
if (!hasActiveFullTask.value) {
stopPoll();
}
loading.value = false;
if (terminalNotifiedTaskIds.has(task.id)) {
return;
}
terminalNotifiedTaskIds.add(task.id);
if (task.status === 'SUCCESS') {
message.success(`全量任务 #${task.id} 完成:${task.doneDays}/${task.totalDays} 天`);
emit('success');
} else if (task.status === 'FAILED') {
message.error(task.lastError || `全量任务 #${task.id} 失败`);
emit('success');
} else {
message.info(`全量任务 #${task.id} 已取消`);
emit('success');
}
}
function subscribeProgress() {
unsubscribeProgress();
const realtime = useRealtimeStore();
unsubProgress = realtime.on(
RealtimeSseEvent.PDD_ORDER_FULL_SYNC_PROGRESS,
(event) => {
try {
const data = JSON.parse(event.data);
if (data.task) {
applyFullTaskUpdate(data.task as PddOrderSyncVO.FullTask);
}
} catch (error) {
console.error('解析全量同步进度失败:', error);
}
},
);
}
async function loadIncrementalStatus() {
if (!shop.value) return;
try {
incremental.value = await getPddIncrementalSyncStatusApi(shop.value.id);
} catch (error) {
console.error('加载增量状态失败:', error);
}
}
async function loadFullTasks() {
if (!shop.value) return;
try {
listLoading.value = true;
fullTasks.value = await listPddFullSyncTasksApi(shop.value.id, 30);
const active = fullTasks.value.find((t) => isTaskActive(t));
if (active) {
watchActiveTasks();
} else {
stopPoll();
}
} catch (error) {
console.error('加载全量任务列表失败:', error);
} finally {
listLoading.value = false;
}
}
async function handleToggleIncremental(checked: boolean | string | number) {
if (!shop.value) return;
const enabled = !!checked;
const prev = incremental.value;
try {
incremental.value = await togglePddIncrementalSyncApi({
shopId: shop.value.id,
enabled,
});
message.success(enabled ? '已开启增量同步' : '已关闭增量同步');
emit('success');
} catch (error) {
incremental.value = prev;
console.error('切换增量开关失败:', error);
message.error('切换增量开关失败');
}
}
async function handleManualIncremental() {
if (!shop.value) return;
try {
incSubmitting.value = true;
await syncPddOrdersIncrementalApi(shop.value.id);
message.success('已入队,后台增量同步中');
emit('success');
await loadIncrementalStatus();
} catch (error) {
console.error('手动增量失败:', error);
} finally {
incSubmitting.value = false;
}
}
/** SSE 为主,低频轮询活跃任务兜底 */
function watchActiveTasks() {
stopPoll();
subscribeProgress();
pollTimer = setInterval(async () => {
const actives = fullTasks.value.filter((t) => isTaskActive(t));
if (actives.length === 0) {
stopPoll();
return;
}
await Promise.all(
actives.map(async (t) => {
try {
applyFullTaskUpdate(await getPddFullSyncTaskApi(t.id));
} catch (error) {
console.error('轮询全量任务失败:', error);
}
}),
);
}, 10_000);
}
async function handleCancelFull(task: PddOrderSyncVO.FullTask) {
try {
loading.value = true;
applyFullTaskUpdate(await cancelPddFullSyncTaskApi(task.id));
message.success(`已取消全量任务 #${task.id}`);
emit('success');
} catch (error) {
console.error('取消全量任务失败:', error);
message.error('取消全量任务失败');
} finally {
loading.value = false;
}
}
async function handleResumeFull(task: PddOrderSyncVO.FullTask) {
try {
loading.value = true;
terminalNotifiedTaskIds.delete(task.id);
const updated = await resumePddFullSyncTaskApi(task.id);
upsertTaskInList(updated);
message.success(`全量任务 #${task.id} 已续跑入队`);
watchActiveTasks();
} catch (error) {
console.error('续跑全量任务失败:', error);
message.error('续跑全量任务失败');
} finally {
loading.value = false;
}
}
function openCreateModal() {
createMode.value = 'range';
confirmDate.value = fullSyncLatest();
range.value = [fullSyncEarliest(), fullSyncLatest()];
createModalOpen.value = true;
}
async function handleCreateTask() {
if (!shop.value) return;
if (createMode.value === 'day' && !confirmDate.value) {
message.warning('请选择成交日期');
return;
}
if (createMode.value === 'range' && (!range.value?.[0] || !range.value?.[1])) {
message.warning('请选择全量同步日期区间');
return;
}
const dateFromDayjs =
createMode.value === 'day' ? confirmDate.value : range.value[0];
const dateToDayjs =
createMode.value === 'day' ? confirmDate.value : range.value[1];
if (
disabledFullSyncDate(dateFromDayjs) ||
disabledFullSyncDate(dateToDayjs) ||
dateToDayjs.isBefore(dateFromDayjs, 'day')
) {
message.warning('日期须在近 90 天内(含今天),且结束不早于开始');
return;
}
if (hasActiveFullTask.value) {
message.warning('该店铺已有进行中的全量任务,请先等待或取消');
return;
}
try {
createSubmitting.value = true;
const dateFrom =
createMode.value === 'day'
? confirmDate.value.format('YYYY-MM-DD')
: range.value[0].format('YYYY-MM-DD');
const dateTo =
createMode.value === 'day'
? confirmDate.value.format('YYYY-MM-DD')
: range.value[1].format('YYYY-MM-DD');
const task = await createPddFullSyncTaskApi({
shopId: shop.value.id,
dateFrom,
dateTo,
});
terminalNotifiedTaskIds.delete(task.id);
upsertTaskInList(task);
createModalOpen.value = false;
message.success(
createMode.value === 'day'
? '单日全量任务已创建,正在后台执行'
: '全量同步任务已创建,正在后台执行',
);
watchActiveTasks();
emit('success');
} catch (error) {
console.error('创建全量任务失败:', error);
} finally {
createSubmitting.value = false;
}
}
function handleClose() {
stopPoll();
unsubscribeProgress();
createModalOpen.value = false;
openFlag.value = false;
}
async function open(record: ShopVO.Info) {
shop.value = record;
fullTasks.value = [];
incremental.value = null;
loading.value = false;
createSubmitting.value = false;
incSubmitting.value = false;
createModalOpen.value = false;
terminalNotifiedTaskIds.clear();
stopPoll();
subscribeProgress();
openFlag.value = true;
await Promise.all([loadIncrementalStatus(), loadFullTasks()]);
}
onBeforeUnmount(() => {
stopPoll();
unsubscribeProgress();
});
defineExpose({ open, close: handleClose });
</script>
<template>
<Modal
v-model:open="openFlag"
:title="modalTitle"
:width="720"
:footer="null"
destroy-on-close
:mask-closable="!hasActiveFullTask"
@cancel="handleClose"
>
<Space direction="vertical" :size="16" class="w-full">
<Card size="small">
<template #title>
<Space>
<span>增量同步</span>
<Tag :color="incHealthColor">{{ incHealthLabel }}</Tag>
</Space>
</template>
<Space direction="vertical" :size="12" class="w-full">
<Space wrap align="center">
<Switch
:checked="!!incremental?.enabled"
checked-children="开"
un-checked-children="关"
@change="handleToggleIncremental"
/>
<Typography.Text type="secondary">
开启后定时 Job 拉取增量并转换
</Typography.Text>
<Button
size="small"
type="primary"
ghost
:loading="incSubmitting"
@click="handleManualIncremental"
>
手动增量一次
</Button>
</Space>
<Descriptions bordered size="small" :column="1">
<Descriptions.Item label="游标">
{{ formatTime(incremental?.lastCursorAt) }}
</Descriptions.Item>
<Descriptions.Item label="上次成功">
{{ formatTime(incremental?.lastSuccessTime) }}
</Descriptions.Item>
</Descriptions>
<Alert
v-if="incStatusMessage"
:type="incStatusAlertType"
show-icon
:message="incStatusMessage"
/>
</Space>
</Card>
<Card size="small" title="全量同步任务">
<template #extra>
<Space size="small">
<Button size="small" :loading="listLoading" @click="loadFullTasks">
刷新
</Button>
<Button
size="small"
type="primary"
:disabled="hasActiveFullTask"
@click="openCreateModal"
>
创建全量任务
</Button>
</Space>
</template>
<List
v-if="fullTasks.length > 0"
:data-source="fullTasks"
:loading="listLoading"
item-layout="vertical"
size="small"
class="max-h-[40vh] overflow-y-auto"
>
<template #renderItem="{ item: task }">
<List.Item>
<template #actions>
<Button
v-if="isTaskActive(task)"
size="small"
danger
:loading="loading"
@click="handleCancelFull(task)"
>
取消
</Button>
<Button
v-if="task.status === 'FAILED'"
size="small"
type="primary"
:loading="loading"
:disabled="hasActiveFullTask"
@click="handleResumeFull(task)"
>
续跑
</Button>
</template>
<List.Item.Meta>
<template #title>
<Space wrap>
<span>#{{ task.id }}</span>
<Tag :color="statusTag(task.status).color">
{{ statusTag(task.status).text }}
</Tag>
<Typography.Text type="secondary">
{{ task.doneDays }}/{{ task.totalDays }} 天
<template v-if="task.failedDays">
· 失败日 {{ task.failedDays }}
</template>
</Typography.Text>
</Space>
</template>
<template #description>
<div>
区间 {{ task.dateFrom }} ~ {{ task.dateTo }}
<template v-if="task.currentDate">
· 当前 {{ task.currentDate }}
</template>
</div>
<div>
创建 {{ formatTime(task.createTime) }}
<template v-if="task.finishTime">
· 结束 {{ formatTime(task.finishTime) }}
</template>
</div>
</template>
</List.Item.Meta>
<Progress
v-if="isTaskActive(task) || task.status === 'SUCCESS'"
:percent="taskProgressPercent(task)"
size="small"
:status="task.status === 'FAILED' ? 'exception' : undefined"
/>
<Alert
v-if="task.lastError"
class="mt-2"
type="error"
show-icon
:message="task.lastError"
/>
</List.Item>
</template>
</List>
<Empty
v-else
:image="Empty.PRESENTED_IMAGE_SIMPLE"
description="暂无全量任务"
/>
</Card>
</Space>
</Modal>
<Modal
v-model:open="createModalOpen"
title="创建全量同步任务"
:confirm-loading="createSubmitting"
ok-text="创建并开始"
destroy-on-close
@ok="handleCreateTask"
>
<Form layout="vertical" class="mt-2">
<Form.Item label="任务类型">
<Radio.Group v-model:value="createMode">
<Radio value="range">按成交日区间</Radio>
<Radio value="day">按成交日单日</Radio>
</Radio.Group>
</Form.Item>
<Form.Item
v-if="createMode === 'range'"
label="成交日期区间"
extra="仅近 90 天(含今天);选到今天时,当日按当前时刻拉取。每天成功后进入转换与 BI"
>
<DatePicker.RangePicker
v-model:value="range"
class="w-full"
:allow-clear="false"
:disabled-date="disabledFullSyncDate"
format="YYYY-MM-DD"
/>
</Form.Item>
<Form.Item
v-else
label="成交日期"
extra="仅近 90 天(含今天);选今天时按当前时刻拉取。若进行中任务已涵盖该日则不会重复创建"
>
<DatePicker
v-model:value="confirmDate"
class="w-full"
:allow-clear="false"
:disabled-date="disabledFullSyncDate"
format="YYYY-MM-DD"
/>
</Form.Item>
</Form>
</Modal>
</template>
@@ -23,10 +23,8 @@ import {
getPlatformTagColor,
} from '#/utils/platform-display';
import BiOrderStatCalcModal from './components/BiOrderStatCalcModal.vue';
import PddOrderConvertModal from './components/PddOrderConvertModal.vue';
import PddOrderSyncModal from './components/PddOrderSyncModal.vue';
import ShopFormModal from './components/ShopFormModal.vue';
import ShopOrderPipelineDrawer from './components/ShopOrderPipelineDrawer.vue';
import PddShopDetailModal from '#/views/channel/pdd/shop/components/PddShopDetailModal.vue';
defineOptions({ name: 'ShopManagement' });
@@ -39,9 +37,7 @@ const loading = ref(false);
const authorizing = ref(false);
const shopFormModalRef = ref();
const pddShopDetailModalRef = ref();
const pddOrderSyncModalRef = ref();
const pddOrderConvertModalRef = ref();
const biOrderStatCalcModalRef = ref();
const pipelineDrawerRef = ref<InstanceType<typeof ShopOrderPipelineDrawer>>();
/** shopId -> 同步/转换/计算摘要 */
const syncStatusMap = ref<Record<number, PddOrderSyncVO.ShopStatus>>({});
@@ -455,15 +451,7 @@ function openPipelineStage(shop: ShopVO.Info, stage: PipelineStageKey) {
message.warning('请先完成拼多多授权绑定');
return;
}
if (stage === 'sync') {
pddOrderSyncModalRef.value?.open(shop);
return;
}
if (stage === 'convert') {
pddOrderConvertModalRef.value?.open(shop);
return;
}
biOrderStatCalcModalRef.value?.open(shop);
pipelineDrawerRef.value?.open(shop, stage);
}
function refreshTable() {
@@ -707,16 +695,8 @@ onUnmounted(() => {
<ShopFormModal ref="shopFormModalRef" @success="handleModalSuccess" />
<PddShopDetailModal ref="pddShopDetailModalRef" />
<PddOrderSyncModal
ref="pddOrderSyncModalRef"
@success="handleModalSuccess"
/>
<PddOrderConvertModal
ref="pddOrderConvertModalRef"
@success="handleModalSuccess"
/>
<BiOrderStatCalcModal
ref="biOrderStatCalcModalRef"
<ShopOrderPipelineDrawer
ref="pipelineDrawerRef"
@success="handleModalSuccess"
/>
</Page>