feat: 工作台接入 BI 增量计算健康度(滞后/暂停/空闲)与按店明细恢复

This commit is contained in:
2026-09-03 14:44:57 +08:00
parent fa1e5ac4ad
commit f104e5882b
14 changed files with 821 additions and 31 deletions
@@ -0,0 +1,33 @@
import type { BiOrderStatIncHealthVO } from './types';
import { requestClient } from '#/api/request';
/** BI 增量计算健康度摘要 */
export async function getBiOrderStatIncHealthApi() {
return requestClient.get<BiOrderStatIncHealthVO.HealthSummary>(
'/bi/order-stat/inc/health',
);
}
/** BI 增量计算按店明细 */
export async function listBiOrderStatIncShopsApi() {
return requestClient.get<BiOrderStatIncHealthVO.ShopRow[]>(
'/bi/order-stat/inc/shops',
);
}
/** 批量恢复暂停店 */
export async function resumeBiOrderStatIncPausedApi() {
return requestClient.post<BiOrderStatIncHealthVO.ResumePausedResult>(
'/bi/order-stat/inc/resume-paused',
);
}
/** 恢复单店增量计算 */
export async function resumeBiOrderStatIncShopApi(shopId: number) {
return requestClient.post(
'/bi/order-stat/inc/resume',
undefined,
{ params: { shopId } },
);
}
@@ -0,0 +1,2 @@
export * from './apis';
export type * from './types';
@@ -0,0 +1 @@
export type * from './types.vo';
@@ -0,0 +1,34 @@
export namespace BiOrderStatIncHealthVO {
export interface HealthSummary {
shopCount: number;
okCount: number;
idleCount: number;
laggedCount: number;
pausedCount: number;
worstLagMinutes?: number;
lagThresholdMinutes: number;
activityWindowHours: number;
healthy: boolean;
}
export interface ShopRow {
shopId: number;
shopName?: string;
platformCode?: string;
status?: number;
/** OK / IDLE / LAGGED / PAUSED */
healthKind: string;
lagMinutes?: number;
lastSuccessTime?: string;
lastStatDate?: string;
lastSummary?: string;
lastError?: string;
recentOrderActivity?: boolean;
recentIncSuccess?: boolean;
}
export interface ResumePausedResult {
resumedCount: number;
shopIds: number[];
}
}
@@ -1,5 +1,6 @@
<script lang="ts" setup>
import type { BiOrderStatDirtyVO } from '#/api/bi/order-stat/dirty';
import type { BiOrderStatIncHealthVO } from '#/api/bi/order-stat/inc';
import { computed, ref, watch } from 'vue';
@@ -12,9 +13,14 @@ import {
getBiOrderStatDirtyHealthApi,
listBiOrderStatDirtyPendingApi,
} from '#/api/bi/order-stat/dirty';
import {
getBiOrderStatIncHealthApi,
resumeBiOrderStatIncPausedApi,
} from '#/api/bi/order-stat/inc';
import BiHealthDimensionCard from './BiHealthDimensionCard.vue';
import BiDirtyDayModal from './BiDirtyDayModal.vue';
import BiHealthDimensionCard from './BiHealthDimensionCard.vue';
import BiIncHealthModal from './BiIncHealthModal.vue';
defineOptions({ name: 'BiDataHealthToolbarButton' });
@@ -34,11 +40,14 @@ const HeartPulseIcon = createIconifyIcon('lucide:heart-pulse');
const RefreshCwIcon = createIconifyIcon('lucide:refresh-cw');
const health = ref<BiOrderStatDirtyVO.HealthSummary | null>(null);
const incHealth = ref<BiOrderStatIncHealthVO.HealthSummary | null>(null);
const previewRows = ref<BiOrderStatDirtyVO.PendingRow[]>([]);
const loading = ref(false);
const previewLoading = ref(false);
const applying = ref(false);
const resumingInc = ref(false);
const dirtyModalRef = ref<InstanceType<typeof BiDirtyDayModal> | null>(null);
const incModalRef = ref<InstanceType<typeof BiIncHealthModal> | null>(null);
const showLoading = computed(() => loading.value || !!props.syncRefreshing);
@@ -50,31 +59,55 @@ const dirtyStatus = computed<'ok' | 'pending' | 'running' | 'loading'>(() => {
return 'pending';
});
const overallAttention = computed(() => dirtyStatus.value !== 'ok');
const incStatus = computed<'ok' | 'pending' | 'error' | 'loading'>(() => {
if (showLoading.value && !incHealth.value) return 'loading';
const h = incHealth.value;
if (!h) return 'ok';
if (h.pausedCount > 0) return 'error';
if (h.laggedCount > 0) return 'pending';
return 'ok';
});
const incStatusLabel = computed(() => {
const h = incHealth.value;
if (!h) return undefined;
if (h.pausedCount > 0) return `${h.pausedCount} 店暂停`;
if (h.laggedCount > 0) return `${h.laggedCount} 店滞后`;
if (h.idleCount > 0 && h.okCount === 0) return '空闲';
return '正常';
});
const overallAttention = computed(
() => dirtyStatus.value !== 'ok' || incStatus.value !== 'ok',
);
const triggerDotClass = computed(() => {
switch (dirtyStatus.value) {
case 'pending': {
return 'bg-amber-500';
}
case 'running': {
return 'bg-blue-500 animate-pulse';
}
case 'ok': {
return 'bg-emerald-500';
}
default: {
return 'bg-slate-300';
}
if (incStatus.value === 'error' || dirtyStatus.value === 'pending') {
return incStatus.value === 'error' ? 'bg-red-500' : 'bg-amber-500';
}
if (dirtyStatus.value === 'running' || incStatus.value === 'pending') {
return dirtyStatus.value === 'running'
? 'bg-blue-500 animate-pulse'
: 'bg-amber-500';
}
if (dirtyStatus.value === 'ok' && incStatus.value === 'ok') {
return 'bg-emerald-500';
}
return 'bg-slate-300';
});
const triggerLabel = computed(() => {
const h = health.value;
if (showLoading.value && !h) return 'BI健康';
if (!h || h.pendingDayCount <= 0) return 'BI健康';
if (h.hasRunning) return `重算中·${h.pendingDayCount}`;
return `待重算·${h.pendingDayCount}`;
if (showLoading.value && !health.value && !incHealth.value) return 'BI健康';
const dirty = health.value;
const inc = incHealth.value;
if (inc && inc.pausedCount > 0) return `增量暂停·${inc.pausedCount}`;
if (dirty && dirty.pendingDayCount > 0) {
return dirty.hasRunning
? `重算中·${dirty.pendingDayCount}`
: `待重算·${dirty.pendingDayCount}`;
}
if (inc && inc.laggedCount > 0) return `增量滞后·${inc.laggedCount}`;
return 'BI健康';
});
const dirtyMetrics = computed(() => {
@@ -92,6 +125,41 @@ const dirtyMetrics = computed(() => {
return rows;
});
const incMetrics = computed(() => {
const h = incHealth.value;
if (!h) {
return [{ label: '状态', value: '加载中…' }];
}
if (h.healthy) {
return [
{
label: '店铺',
value: `${h.shopCount} 家(空闲 ${h.idleCount})`,
},
{
label: '阈值阈值',
value: `${h.lagThresholdMinutes} 分钟`,
},
];
}
const rows: { label: string; value: string }[] = [
{ label: '店铺', value: `${h.shopCount} 家` },
];
if (h.pausedCount > 0) {
rows.push({ label: '暂停', value: `${h.pausedCount} 家` });
}
if (h.laggedCount > 0) {
rows.push({
label: '滞后',
value:
h.worstLagMinutes != null
? `${h.laggedCount} 家(最差 ${h.worstLagMinutes} 分)`
: `${h.laggedCount} 家`,
});
}
return rows;
});
const previewPending = computed(
() => previewRows.value.filter((r) => r.status === 'PENDING').length,
);
@@ -106,17 +174,38 @@ const primaryDisabled = computed(
() => !health.value || health.value.pendingDayCount <= 0,
);
const incPrimaryLabel = computed(() =>
(incHealth.value?.pausedCount ?? 0) > 0 ? '恢复暂停店' : undefined,
);
const incPrimaryDisabled = computed(
() => (incHealth.value?.pausedCount ?? 0) <= 0,
);
const reasonLabels: Record<string, string> = {
COST: '成本',
PRODUCT_DIM: '迁品',
};
async function refreshHealth() {
loading.value = true;
async function refreshDirtyHealth() {
try {
health.value = (await getBiOrderStatDirtyHealthApi()) ?? null;
} catch {
health.value = null;
}
}
async function refreshIncHealth() {
try {
incHealth.value = (await getBiOrderStatIncHealthApi()) ?? null;
} catch {
incHealth.value = null;
}
}
async function refreshHealth() {
loading.value = true;
try {
await Promise.all([refreshDirtyHealth(), refreshIncHealth()]);
} finally {
loading.value = false;
}
@@ -149,11 +238,16 @@ function handlePopoverOpen(open: boolean) {
}
}
function openDetailModal() {
function openDirtyDetailModal() {
emit('update:open', false);
void dirtyModalRef.value?.open();
}
function openIncDetailModal() {
emit('update:open', false);
void incModalRef.value?.open();
}
async function handleQuickApply() {
if (primaryDisabled.value) {
message.info('当前没有待处理的脏日');
@@ -177,10 +271,31 @@ async function handleQuickApply() {
}
}
async function handleResumeIncPaused() {
if (incPrimaryDisabled.value) {
message.info('没有暂停中的店铺');
return;
}
resumingInc.value = true;
try {
const result = await resumeBiOrderStatIncPausedApi();
message.success(`已恢复 ${result?.resumedCount ?? 0} 家暂停店`);
await refreshAll();
} catch (e) {
console.error(e);
} finally {
resumingInc.value = false;
}
}
function onModalApplied() {
void refreshAll();
}
function onIncRefreshed() {
void refreshHealth();
}
watch(
() => props.open,
(open) => {
@@ -207,7 +322,7 @@ defineExpose({ refresh: refreshSummary, refreshAll });
BI 数据健康度
</div>
<div class="text-xs text-slate-500 dark:text-slate-400">
多维度监测;当前已接入统计重算
脏日重算与增量计算
</div>
</div>
<button
@@ -235,7 +350,7 @@ defineExpose({ refresh: refreshSummary, refreshAll });
:primary-loading="applying"
:primary-disabled="primaryDisabled"
@primary="handleQuickApply"
@secondary="openDetailModal"
@secondary="openDirtyDetailModal"
>
<div
v-if="health && health.pendingDayCount > 0"
@@ -273,7 +388,8 @@ defineExpose({ refresh: refreshSummary, refreshAll });
{{
(row.reasons ?? [])
.map((r) => reasonLabels[r] ?? r)
.join('/') || (row.status === 'RUNNING' ? '重算' : '待算')
.join('/') ||
(row.status === 'RUNNING' ? '重算' : '待算')
}}
</span>
</li>
@@ -289,11 +405,18 @@ defineExpose({ refresh: refreshSummary, refreshAll });
</BiHealthDimensionCard>
<BiHealthDimensionCard
title="增量同步"
title="BI 增量计算"
icon="lucide:radio"
status="soon"
coming-soon
description="监测订单增量、广告费转换等管线是否滞后或暂停。"
:status="incStatus"
:status-label="incStatusLabel"
description="日常订单增量是否及时灌入统计;暂停优先于滞后,安静店不计不健康。"
:metrics="incMetrics"
:primary-action-label="incPrimaryLabel"
secondary-action-label="查看明细"
:primary-loading="resumingInc"
:primary-disabled="incPrimaryDisabled"
@primary="handleResumeIncPaused"
@secondary="openIncDetailModal"
/>
<BiHealthDimensionCard
@@ -343,6 +466,7 @@ defineExpose({ refresh: refreshSummary, refreshAll });
</Popover>
<BiDirtyDayModal ref="dirtyModalRef" @applied="onModalApplied" />
<BiIncHealthModal ref="incModalRef" @refreshed="onIncRefreshed" />
</template>
<style>
@@ -14,7 +14,7 @@ export interface HealthMetric {
export interface HealthDimensionCardProps {
title: string;
icon: string;
status?: 'ok' | 'pending' | 'running' | 'loading' | 'soon';
status?: 'ok' | 'pending' | 'running' | 'loading' | 'soon' | 'error';
statusLabel?: string;
description?: string;
metrics?: HealthMetric[];
@@ -48,6 +48,7 @@ const statusColor = {
running: 'processing',
loading: 'default',
soon: 'default',
error: 'error',
} as const;
const statusText = {
@@ -56,6 +57,7 @@ const statusText = {
running: '重算中',
loading: '加载中',
soon: '即将推出',
error: '异常',
} as const;
</script>
@@ -0,0 +1,217 @@
<script lang="ts" setup>
import type { BiOrderStatIncHealthVO } from '#/api/bi/order-stat/inc';
import { h, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { Alert, Button, Table, Tag, message } from 'ant-design-vue';
import {
listBiOrderStatIncShopsApi,
resumeBiOrderStatIncPausedApi,
resumeBiOrderStatIncShopApi,
} from '#/api/bi/order-stat/inc';
defineOptions({ name: 'BiIncHealthModal' });
const emit = defineEmits<{
refreshed: [];
}>();
const [IncModal, incModalApi] = useVbenModal({
title: 'BI 增量计算 · 店铺明细',
class: 'w-[920px] max-w-[calc(100vw-2rem)]',
draggable: true,
contentClass: 'px-5 py-4 min-h-[360px]',
showCancelButton: true,
cancelText: '关闭',
showConfirmButton: false,
});
const loading = ref(false);
const resumingAll = ref(false);
const resumingShopId = ref<number | null>(null);
const rows = ref<BiOrderStatIncHealthVO.ShopRow[]>([]);
const pausedCount = () =>
rows.value.filter((r) => r.healthKind === 'PAUSED').length;
const kindMeta: Record<
string,
{ color: string; label: string }
> = {
PAUSED: { color: 'error', label: '暂停' },
LAGGED: { color: 'warning', label: '滞后' },
IDLE: { color: 'default', label: '空闲' },
OK: { color: 'success', label: '正常' },
};
function formatLag(minutes?: number | null) {
if (minutes == null) return '—';
if (minutes < 60) return `${minutes} 分`;
const h = Math.floor(minutes / 60);
const m = minutes % 60;
return m > 0 ? `${h} 时 ${m} 分` : `${h} 时`;
}
const columns = [
{
title: '店铺',
key: 'shop',
width: 160,
customRender: ({ record }: { record: BiOrderStatIncHealthVO.ShopRow }) =>
record.shopName || `#${record.shopId}`,
},
{
title: '状态',
key: 'healthKind',
width: 90,
customRender: ({ record }: { record: BiOrderStatIncHealthVO.ShopRow }) => {
const meta = kindMeta[record.healthKind] ?? {
color: 'default',
label: record.healthKind,
};
return h(Tag, { color: meta.color }, () => meta.label);
},
},
{
title: '滞后',
key: 'lag',
width: 100,
customRender: ({ record }: { record: BiOrderStatIncHealthVO.ShopRow }) =>
formatLag(record.lagMinutes),
},
{
title: '最近成功',
dataIndex: 'lastSuccessTime',
key: 'lastSuccessTime',
width: 170,
customRender: ({ text }: { text?: string }) => text || '—',
},
{
title: '统计日',
dataIndex: 'lastStatDate',
key: 'lastStatDate',
width: 110,
customRender: ({ text }: { text?: string }) => text || '—',
},
{
title: '摘要',
key: 'summary',
ellipsis: true,
customRender: ({ record }: { record: BiOrderStatIncHealthVO.ShopRow }) =>
record.lastError || record.lastSummary || '—',
},
{
title: '操作',
key: 'action',
width: 90,
customRender: ({ record }: { record: BiOrderStatIncHealthVO.ShopRow }) => {
if (record.healthKind !== 'PAUSED') {
return '—';
}
return h(
Button,
{
type: 'link',
size: 'small',
loading: resumingShopId.value === record.shopId,
onClick: () => void handleResumeOne(record.shopId),
},
() => '恢复',
);
},
},
];
async function reload() {
loading.value = true;
try {
rows.value = (await listBiOrderStatIncShopsApi()) ?? [];
} catch {
rows.value = [];
message.error('加载增量店态失败');
} finally {
loading.value = false;
}
}
async function open() {
incModalApi.open();
await reload();
}
async function handleResumeOne(shopId: number) {
resumingShopId.value = shopId;
try {
await resumeBiOrderStatIncShopApi(shopId);
message.success('已恢复该店增量计算');
await reload();
emit('refreshed');
} catch (e) {
console.error(e);
} finally {
resumingShopId.value = null;
}
}
async function handleResumeAll() {
if (pausedCount() === 0) {
message.info('没有暂停中的店铺');
return;
}
resumingAll.value = true;
try {
const result = await resumeBiOrderStatIncPausedApi();
message.success(`已恢复 ${result?.resumedCount ?? 0} 家暂停店`);
await reload();
emit('refreshed');
} catch (e) {
console.error(e);
} finally {
resumingAll.value = false;
}
}
defineExpose({ open, reload });
</script>
<template>
<IncModal>
<Alert
type="info"
show-icon
class="mb-4"
message="暂停优先于滞后。近 24 小时无订单且无成功增量的店标为空闲,不计入不健康。"
/>
<div class="mb-3 flex items-center justify-between gap-2">
<span class="text-sm text-slate-600 dark:text-slate-300">
共 {{ rows.length }} 家店铺
<template v-if="pausedCount() > 0">
· 暂停 {{ pausedCount() }}
</template>
</span>
<Button
type="primary"
danger
:loading="resumingAll"
:disabled="pausedCount() === 0"
@click="handleResumeAll"
>
恢复全部暂停
</Button>
</div>
<Table
size="small"
:loading="loading"
:columns="columns"
:data-source="rows"
:pagination="{ pageSize: 10, showSizeChanger: false }"
row-key="shopId"
:scroll="{ y: 360 }"
/>
</IncModal>
</template>