feat(shipping-notice): 增强发货通知与订单抽取功能,支持多进程处理与紧急停止

- 移除不再使用的 SHIPPING_NOTICE_LAYOUT_PARSER_REVISION 配置
- 在环境配置中新增 SHIPPING_NOTICE_WORKER_CONCURRENCY 和 SHIPPING_NOTICE_JOB_RUNNING_TIMEOUT_SECONDS
- 实现发货通知 worker 进程,支持并发处理订单抽取任务
- 引入紧急停止功能,允许管理员在运行中控制订单解析状态
- 更新相关 API,支持读取与设置紧急停止状态
- 增强文档与代码注释,反映新的业务逻辑与功能要求
This commit is contained in:
hugo committed 2026-07-31 18:00:49 +08:00
1 parent d0fe084999
commit b352c281d5
149 files changed
+12550 -1874

No files matched your search

@@ -0,0 +1,251 @@
<!--
features/chat/components/shipping-review/ReviewLlmSuggestionPanel.vue
用途:复核工作台内嵌 AI 建议入口、列表与裁决触发(非顶级导航)。
依赖:vue-i18n、ReviewLlmSuggestionDialog、ShippingOrderReview* 类型。
逻辑:请求/裁决由父级 composable 执行;仅 validated 可接受;validation_failed 单独列表仅可拒绝;
证据按 field_id + line_key/line_index 绑定;打开弹窗时按建议字段解析当前草稿值。
-->
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import type {
ShippingOrderReviewCase,
ShippingOrderReviewEvidence,
ShippingOrderReviewLlmAdjudicationPayload,
ShippingOrderReviewLlmSuggestion,
} from '../../types/shipping.api.types';
import ReviewLlmSuggestionDialog from './ReviewLlmSuggestionDialog.vue';
const props = defineProps<{
activeCase?: ShippingOrderReviewCase | null;
evidence?: ShippingOrderReviewEvidence[] | null;
editable?: boolean;
saving?: boolean;
suggestions?: ShippingOrderReviewLlmSuggestion[];
suggestionLoading?: boolean;
focusedFieldId?: string | null;
focusedLineKey?: string | null;
/** 父级传入的聚焦字段草稿;弹窗优先用建议字段自身解析值。 */
draftValue?: unknown;
}>();
const emit = defineEmits<{
requestSuggestion: [];
adjudicate: [payload: {
suggestion: ShippingOrderReviewLlmSuggestion;
body: ShippingOrderReviewLlmAdjudicationPayload;
}];
}>();
const { t, te } = useI18n();
const dialogOpen = ref(false);
const selected = ref<ShippingOrderReviewLlmSuggestion | null>(null);
/** 仅已通过逐字校验的建议可进入 accept/modify 待裁决列表。 */
const pendingSuggestions = computed(() =>
(props.suggestions || []).filter((item) => String(item.status || '') === 'validated' && !item.decision),
);
/** 验证失败建议仅可查看/拒绝,不进入可接受列表。 */
const failedSuggestions = computed(() =>
(props.suggestions || []).filter((item) => String(item.status || '') === 'validation_failed' && !item.decision),
);
const statusLabel = computed(() => {
if (props.suggestionLoading) return t('chat.shippingOrderReview.llmSuggestion.status.pending');
const latest = (props.suggestions || [])[0];
const code = String(latest?.status || latest?.decision || 'idle');
const key = `chat.shippingOrderReview.llmSuggestion.status.${code}`;
return te(key) ? t(key) : code;
});
const canRequest = computed(() =>
Boolean(props.editable && props.activeCase && props.focusedFieldId && !props.suggestionLoading && !props.saving),
);
/**
* 证据须同时匹配 field_id 与明细行(machine-N → line_index)。
*/
function evidenceMatchesFieldLine(
item: ShippingOrderReviewEvidence,
fieldId: string,
lineKey: string | null | undefined,
): boolean {
if (String(item.field_id || '') !== fieldId) return false;
const key = String(lineKey || '').trim();
if (!key) {
return item.line_index == null || item.line_index === undefined;
}
const matched = /^machine-(\d+)$/i.exec(key);
if (matched) {
const idx = Number(matched[1]) - 1;
return Number(item.line_index) === idx;
}
return false;
}
const selectedEvidence = computed(() => {
const items = props.evidence || [];
const fieldId = String(selected.value?.field_id || props.focusedFieldId || '');
const lineKey = selected.value?.line_key ?? props.focusedLineKey;
return items.find((item) => evidenceMatchesFieldLine(item, fieldId, lineKey)) || null;
});
/**
* 从草稿容器读取字段当前值(人工值优先,否则机器投影)。
*/
function readContainerDraftValue(container: Record<string, unknown> | null | undefined, fieldId: string): unknown {
if (!container || !fieldId) return null;
const values = container.values as Record<string, { value?: unknown }> | undefined;
if (values?.[fieldId] && 'value' in values[fieldId]) return values[fieldId].value ?? null;
const machine = Array.isArray(container.machine_fields)
? (container.machine_fields as Array<Record<string, unknown>>)
: [];
const hit = machine.find((item) => String(item.field_id || '') === fieldId);
return hit?.value ?? null;
}
/**
* 按建议(或聚焦字段)解析当前草稿值,供三方对比。
*/
const dialogDraftValue = computed(() => {
const fieldId = String(selected.value?.field_id || props.focusedFieldId || '');
const lineKey = selected.value?.line_key ?? props.focusedLineKey;
const draft = props.activeCase?.draft;
if (!draft || !fieldId) return props.draftValue ?? null;
if (lineKey) {
const lines = Array.isArray(draft.lines) ? draft.lines : [];
const line = lines.find((item) => String((item as { line_key?: string }).line_key || '') === String(lineKey));
return readContainerDraftValue(line as Record<string, unknown> | undefined, fieldId);
}
return readContainerDraftValue(draft.header_values as Record<string, unknown> | undefined, fieldId);
});
/**
* 打开指定建议的对比裁决对话框。
*/
function openSuggestion(item: ShippingOrderReviewLlmSuggestion) {
selected.value = item;
dialogOpen.value = true;
}
/**
* 将建议字段解析为 Schema 展示名;缺失时回退 field_id。
*/
function suggestionFieldLabel(item: ShippingOrderReviewLlmSuggestion): string {
const fieldId = String(item.field_id || '').trim();
const fields = props.activeCase?.schema?.fields || [];
const hit = fields.find((field) => String(field.field_id || '') === fieldId);
const name = String(hit?.display_name || hit?.field_code || '').trim();
if (name && item.line_key) {
return `${name} · ${item.line_key}`;
}
return name || fieldId || '—';
}
/**
* 将证据等级转为业务文案,避免直接展示 L1_field。
*/
function evidenceLevelLabel(level?: string | null): string {
const code = String(level || 'L1_field').trim() || 'L1_field';
const key = `chat.shippingOrderReview.llmSuggestion.evidenceLevel.${code}`;
return te(key) ? t(key) : t('chat.shippingOrderReview.llmSuggestion.scope', { level: code });
}
/**
* 将对话框裁决转发给父级。
*/
function onDecide(payload: { decision: 'accept' | 'modify' | 'reject'; reason: string; value?: unknown }) {
if (!selected.value) return;
emit('adjudicate', {
suggestion: selected.value,
body: {
decision: payload.decision,
reason: payload.reason || undefined,
value: payload.value,
expected_draft_version: props.activeCase?.draft?.draft_version,
},
});
dialogOpen.value = false;
}
</script>
<template>
<section class="rounded-xl border border-slate-200 bg-white p-3 text-sm shadow-sm dark:border-slate-800 dark:bg-slate-900">
<div class="flex flex-wrap items-center justify-between gap-2">
<div>
<div class="font-semibold">{{ t('chat.shippingOrderReview.llmSuggestion.panelTitle') }}</div>
<div class="mt-1 text-xs text-slate-500">
{{ t('chat.shippingOrderReview.llmSuggestion.panelHint') }}
· {{ evidenceLevelLabel(selected?.evidence_level || 'L1_field') }}
· {{ statusLabel }}
<span v-if="suggestions?.length">· {{ suggestions.length }}</span>
</div>
</div>
<button
type="button"
class="rounded border px-2 py-1 text-xs disabled:opacity-50"
:disabled="!canRequest"
data-testid="review-llm-request"
@click="emit('requestSuggestion')"
>
{{
suggestionLoading
? t('chat.shippingOrderReview.llmSuggestion.requesting')
: t('chat.shippingOrderReview.llmSuggestion.request')
}}
</button>
</div>
<p v-if="!pendingSuggestions.length && !failedSuggestions.length" class="mt-3 text-xs text-slate-500">
{{ t('chat.shippingOrderReview.llmSuggestion.empty') }}
</p>
<ul v-if="pendingSuggestions.length" class="mt-3 space-y-2">
<li
v-for="item in pendingSuggestions"
:key="item.suggestion_no"
class="flex items-center justify-between gap-2 rounded border border-slate-200 px-2 py-1.5 dark:border-slate-700"
>
<div class="min-w-0 truncate text-xs">
<span class="font-medium">{{ suggestionFieldLabel(item) }}</span>
<span class="ml-2 opacity-70">{{ item.suggested_value ?? '—' }}</span>
</div>
<button type="button" class="shrink-0 rounded border px-2 py-0.5 text-xs" @click="openSuggestion(item)">
{{ t('chat.shippingOrderReview.llmSuggestion.review') }}
</button>
</li>
</ul>
<ul v-if="failedSuggestions.length" class="mt-3 space-y-2" data-testid="review-llm-failed-list">
<li
v-for="item in failedSuggestions"
:key="item.suggestion_no"
class="flex items-center justify-between gap-2 rounded border border-amber-200 bg-amber-50/50 px-2 py-1.5 dark:border-amber-900 dark:bg-amber-950/30"
>
<div class="min-w-0 truncate text-xs">
<span class="font-medium">{{ suggestionFieldLabel(item) }}</span>
<span class="ml-2 text-amber-700 dark:text-amber-300">
{{ t('chat.shippingOrderReview.llmSuggestion.verbatimFailed') }}
</span>
</div>
<button
type="button"
class="shrink-0 rounded border px-2 py-0.5 text-xs"
data-testid="review-llm-open-failed"
@click="openSuggestion(item)"
>
{{ t('chat.shippingOrderReview.llmSuggestion.review') }}
</button>
</li>
</ul>
<ReviewLlmSuggestionDialog
:open="dialogOpen"
:suggestion="selected"
:evidence="selectedEvidence"
:draft-value="dialogDraftValue"
:field-label="selected ? suggestionFieldLabel(selected) : ''"
@close="dialogOpen = false"
@decide="onDecide"
/>
</section>
</template>