feat(shipping-notice): 新增库存确认来源接口及相关逻辑
This commit is contained in:
1 parent
a31735b689
commit
0a9bd6415d
69 files changed
+8442
-775
No files matched your search
+10
-5
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/composables/schedule-admin/useScheduleAdminDeepLink.ts
|
||||
* 用途:解析企微深链 query,定位排程执行记录并标记原始库存手动下载入口。
|
||||
* 用途:解析企微深链 query,定位排程执行记录并在登录后自动下载原始库存包。
|
||||
* 依赖:vue-router、schedule-admin.state、useScheduleAdminRuns。
|
||||
* 逻辑:SchedulesPage onMounted 在 loadAll 后调用;消费 task_id/run_id/raw_zip,不自动下载。
|
||||
* 逻辑:SchedulesPage onMounted 在 loadAll 后调用;消费 task_id/run_id/raw_zip/download,自动下载失败时保留手动入口。
|
||||
*/
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import type { ScheduleAdminState } from './schedule-admin.state';
|
||||
@@ -15,12 +15,12 @@ function parsePositiveInt(raw: unknown): number | null {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据路由 query 打开工作台执行记录;raw_zip=1 时仅展开 run 并突出手动下载按钮。
|
||||
* 核心逻辑:不自动触发下载,避免企微内置浏览器拦截异步下载。
|
||||
* 根据路由 query 打开工作台执行记录;raw_zip=1 时展开 run 并保留手动下载按钮。
|
||||
* 核心逻辑:download=inventory_raw_zip 时登录后自动下载一次;若企微内置浏览器拦截,用户仍可点醒目按钮重试。
|
||||
*/
|
||||
export function useScheduleAdminDeepLink(
|
||||
state: ScheduleAdminState,
|
||||
runs: Pick<ScheduleAdminRuns, 'viewScheduleRuns'>,
|
||||
runs: Pick<ScheduleAdminRuns, 'viewScheduleRuns' | 'downloadScheduleInventoryRawZip'>,
|
||||
) {
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
@@ -31,6 +31,7 @@ export function useScheduleAdminDeepLink(
|
||||
|
||||
const runId = parsePositiveInt(route.query.run_id);
|
||||
const rawZipPrompt = String(route.query.raw_zip || '') === '1';
|
||||
const shouldAutoDownloadRawZip = rawZipPrompt && String(route.query.download || '') === 'inventory_raw_zip';
|
||||
|
||||
state.scheduleViewMode.value = 'workbench';
|
||||
state.selectedScheduleId.value = taskId;
|
||||
@@ -43,6 +44,9 @@ export function useScheduleAdminDeepLink(
|
||||
const target = state.selectedScheduleRuns.value.find((item) => item.id === runId);
|
||||
if (target?.inventory_raw_zip_available) {
|
||||
state.wecomRawZipPromptRunId.value = runId;
|
||||
if (shouldAutoDownloadRawZip) {
|
||||
await runs.downloadScheduleInventoryRawZip(runId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,6 +55,7 @@ export function useScheduleAdminDeepLink(
|
||||
delete nextQuery.task_id;
|
||||
delete nextQuery.run_id;
|
||||
delete nextQuery.raw_zip;
|
||||
delete nextQuery.download;
|
||||
await router.replace({ path: route.path, query: nextQuery });
|
||||
};
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ watch(
|
||||
:ref="bindShippingPickerRef"
|
||||
type="file"
|
||||
class="hidden"
|
||||
accept=".xlsx,.xls,.csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,text/csv"
|
||||
accept=".xlsx,.csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,text/csv"
|
||||
@change="emit('shipping-inventory-selected', $event)"
|
||||
/>
|
||||
|
||||
|
||||
@@ -324,6 +324,21 @@ const resolveTaskDiagnosis = (task: ShippingTaskSummary | ShippingTaskDetail) =>
|
||||
advice: t('chat.shippingNoticeUi.diagnosisReservationRequiredAdvice'),
|
||||
};
|
||||
}
|
||||
if (reason === 'inventory_source_unresolved') {
|
||||
const resolution = (task as ShippingTaskDetail).inventory_source_resolution;
|
||||
const status = resolution && typeof resolution === 'object'
|
||||
? String((resolution as { status?: unknown }).status || '').trim()
|
||||
: '';
|
||||
const isAmbiguous = status === 'ambiguous';
|
||||
return {
|
||||
title: t(isAmbiguous
|
||||
? 'chat.shippingNoticeUi.diagnosisInventorySourceAmbiguousTitle'
|
||||
: 'chat.shippingNoticeUi.diagnosisInventorySourceTitle'),
|
||||
advice: t(isAmbiguous
|
||||
? 'chat.shippingNoticeUi.diagnosisInventorySourceAmbiguousAdvice'
|
||||
: 'chat.shippingNoticeUi.diagnosisInventorySourceAdvice'),
|
||||
};
|
||||
}
|
||||
if (reason === 'map_infer' || processStatus === 'waiting_inventory') {
|
||||
return {
|
||||
title: t('chat.shippingNoticeUi.diagnosisInventoryWaitingTitle'),
|
||||
@@ -352,6 +367,9 @@ const resolveSuggestedAction = (task: ShippingTaskSummary | ShippingTaskDetail)
|
||||
if (reason === 'low_confidence' || reviewStatus === 'parse_review') {
|
||||
return t('chat.shippingNoticeUi.suggestReviewParse');
|
||||
}
|
||||
if (reason === 'inventory_source_unresolved') {
|
||||
return t('chat.shippingNoticeUi.suggestConfirmInventorySource');
|
||||
}
|
||||
if (isFailedTask(task)) {
|
||||
return t('chat.shippingNoticeUi.suggestRetryStep');
|
||||
}
|
||||
|
||||
@@ -130,6 +130,7 @@ function deriveCurrentIndex(task: ShippingTaskStepperSource | null | undefined):
|
||||
|| reviewStatus === 'rsv_required'
|
||||
|| pendingReason === 'low_confidence'
|
||||
|| pendingReason === 'rsv_required'
|
||||
|| pendingReason === 'inventory_source_unresolved'
|
||||
) {
|
||||
return 1;
|
||||
}
|
||||
@@ -159,7 +160,12 @@ export function buildShippingWorkflowSteps(
|
||||
}
|
||||
|
||||
if (
|
||||
(index === 1 && (reviewStatus === 'parse_review' || pendingReason === 'low_confidence' || pendingReason === 'rsv_required'))
|
||||
(index === 1 && (
|
||||
reviewStatus === 'parse_review'
|
||||
|| pendingReason === 'low_confidence'
|
||||
|| pendingReason === 'rsv_required'
|
||||
|| pendingReason === 'inventory_source_unresolved'
|
||||
))
|
||||
|| (index === 2 && (pendingReason === 'inv_unavail' || pendingReason === 'rpa_exhausted'))
|
||||
|| (index === 3 && (reviewStatus === 'align_review' || pendingReason === 'align_review'))
|
||||
|| (index === 4 && (reviewStatus === 'shortage_review' || pendingReason === 'shortage_review' || pendingReason === 'shortage'))
|
||||
|
||||
@@ -32,7 +32,7 @@ export interface ShippingMenuHandlerContext {
|
||||
refreshShippingActions: () => Promise<void>;
|
||||
startChatTurn: (options: StartChatTurnOptions) => Promise<boolean>;
|
||||
msg: { warning: (text: string) => void; info: (text: string) => void };
|
||||
t: (key: string) => string;
|
||||
t: (key: string, ...args: unknown[]) => string;
|
||||
}
|
||||
|
||||
export interface HandleShippingMenuActionOptions {
|
||||
@@ -97,8 +97,8 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
if (!turnSpec) return false;
|
||||
const displayBase = String(action.message || actionId || '操作').trim();
|
||||
const displayText = actionId === 'confirm_inventory_source'
|
||||
? `${displayBase}\n任务编号:${taskId}`
|
||||
: `${displayBase}(任务编号:${taskId})`;
|
||||
? ctx.t('chat.shippingNoticeUi.inventorySource.confirmWithTask', { taskId })
|
||||
: ctx.t('chat.shippingNoticeUi.inventorySource.actionWithTask', { message: displayBase, taskId });
|
||||
await ctx.startChatTurn({
|
||||
agentId: ctx.currentAgentId.value,
|
||||
inputType: 'action',
|
||||
@@ -168,7 +168,7 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
sourceCode = await resolveInventorySourceCodeFromContext(taskId);
|
||||
}
|
||||
if (!sourceCode) {
|
||||
ctx.msg.warning('请直接输入要使用的库存源线索,例如 AWSDU、Dublin 或 Singapore。');
|
||||
ctx.msg.warning(ctx.t('chat.shippingNoticeUi.inventorySource.inputHint'));
|
||||
if (chatMsg) chatMsg.shipping_actions_used = false;
|
||||
return;
|
||||
}
|
||||
@@ -179,7 +179,7 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
}
|
||||
const label = String(('label' in action ? action.label : '') || sourceCode).trim();
|
||||
const displayMessage = action.id === 'confirm_inventory_source'
|
||||
? `确认库存查询来源:${label || sourceCode}`
|
||||
? ctx.t('chat.shippingNoticeUi.inventorySource.confirmDisplay', { label: label || sourceCode })
|
||||
: action.message;
|
||||
await runShippingActionTurn(
|
||||
{ ...action, message: displayMessage },
|
||||
@@ -195,7 +195,7 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
|
||||
if (action.id === 'retry_resolve_inventory_source') {
|
||||
await ctx.refreshShippingActions();
|
||||
ctx.msg.info('已重新刷新库存源状态');
|
||||
ctx.msg.info(ctx.t('chat.shippingNoticeUi.inventorySource.retryResolveDone'));
|
||||
return;
|
||||
}
|
||||
if (action.id === 'edit_inventory_mapping') {
|
||||
|
||||
@@ -66,7 +66,7 @@ export interface ShippingSendHandlerContext {
|
||||
isShippingShortageQueryIntent: (text: string) => boolean;
|
||||
queryShippingShortageDetails: (taskNo?: string, displayText?: string) => Promise<boolean>;
|
||||
msg: { warning: (text: string) => void; info: (text: string) => void };
|
||||
t: (key: string) => string;
|
||||
t: (key: string, ...args: unknown[]) => string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,13 +114,13 @@ export function createShippingSendHandlers(ctx: ShippingSendHandlerContext) {
|
||||
const label = String(hit?.display_name || sourceCode).trim();
|
||||
await ctx.handleShippingMenuAction({
|
||||
id: 'confirm_inventory_source',
|
||||
message: `确认库存查询来源:${label}`,
|
||||
message: ctx.t('chat.shippingNoticeUi.inventorySource.confirmDisplay', { label }),
|
||||
label,
|
||||
source_code: sourceCode,
|
||||
});
|
||||
return true;
|
||||
} catch (e: unknown) {
|
||||
const errorMessage = e instanceof Error ? e.message : '确认库存源失败';
|
||||
const errorMessage = e instanceof Error ? e.message : ctx.t('chat.shippingNoticeUi.inventorySource.confirmFailed');
|
||||
ctx.msg.warning(errorMessage);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,42 @@
|
||||
* 依赖:无(纯类型模块)。
|
||||
* 逻辑:shipping.api.ts 与 Chat/工作台组件统一引用本文件 DTO 类型。
|
||||
*/
|
||||
export type InventorySourceStatus =
|
||||
| 'unresolved'
|
||||
| 'ambiguous'
|
||||
| 'resolved'
|
||||
| 'user_confirmed'
|
||||
| 'invalid'
|
||||
| 'conflicted';
|
||||
|
||||
export type InventorySourceMethod =
|
||||
| 'rule_exact'
|
||||
| 'rule_combined'
|
||||
| 'user_confirmed'
|
||||
| 'legacy_migrated';
|
||||
|
||||
export interface ShippingInventorySourceCandidate {
|
||||
source_code: string;
|
||||
display_name?: string | null;
|
||||
site_id?: string | null;
|
||||
warehouse_id?: string | null;
|
||||
source_type?: string | null;
|
||||
match_score?: number | null;
|
||||
matched_by?: string | null;
|
||||
}
|
||||
|
||||
export interface ShippingInventorySourceResolution {
|
||||
status?: InventorySourceStatus | null;
|
||||
method?: InventorySourceMethod | null;
|
||||
reason?: string | null;
|
||||
candidates?: ShippingInventorySourceCandidate[];
|
||||
destination_candidates?: string[];
|
||||
evidence?: Record<string, unknown>[];
|
||||
conflicts?: string[];
|
||||
config_version?: string | null;
|
||||
routing_fingerprint?: string | null;
|
||||
}
|
||||
|
||||
export interface ShippingInventorySnapshot {
|
||||
inventory_file_no?: string | null;
|
||||
source_code?: string | null;
|
||||
@@ -48,7 +84,21 @@ export interface ShippingTaskSummary {
|
||||
};
|
||||
rpa_runtime?: ShippingRpaRuntime | null;
|
||||
rpa_inventory_source?: Record<string, unknown> | null;
|
||||
inventory_source_resolution?: Record<string, unknown> | null;
|
||||
inventory_source_resolution?: ShippingInventorySourceResolution | null;
|
||||
destination_code?: string | null;
|
||||
destination_city?: string | null;
|
||||
destination_country?: string | null;
|
||||
warehouse_hint?: string | null;
|
||||
inventory_source_code?: string | null;
|
||||
inventory_source_type?: string | null;
|
||||
inventory_site_id?: string | null;
|
||||
inventory_warehouse_id?: string | null;
|
||||
inventory_source_status?: InventorySourceStatus | null;
|
||||
inventory_source_method?: InventorySourceMethod | null;
|
||||
inventory_source_config_version?: string | null;
|
||||
inventory_routing_fingerprint?: string | null;
|
||||
inventory_source_confirmed_at?: string | null;
|
||||
inventory_source_confirmed_by?: number | null;
|
||||
inventory_snapshot?: ShippingInventorySnapshot | null;
|
||||
created_at?: string | null;
|
||||
updated_at?: string | null;
|
||||
|
||||
@@ -141,6 +141,31 @@ const inventorySnapshotLabel = (triggerType?: string | null) => {
|
||||
return map[key] || map.on_demand;
|
||||
};
|
||||
|
||||
const inventorySourceStatusLabel = (status?: string | null) => {
|
||||
const key = String(status || '').trim();
|
||||
if (!key) return '—';
|
||||
const i18nKey = `workspace.shippingNotice.inventorySource.statusLabels.${key}`;
|
||||
return te(i18nKey) ? t(i18nKey) : key;
|
||||
};
|
||||
|
||||
const inventorySourceMethodLabel = (method?: string | null) => {
|
||||
const key = String(method || '').trim();
|
||||
if (!key) return '—';
|
||||
const i18nKey = `workspace.shippingNotice.inventorySource.methodLabels.${key}`;
|
||||
return te(i18nKey) ? t(i18nKey) : key;
|
||||
};
|
||||
|
||||
const hasInventorySourceFields = computed(() => {
|
||||
const item = detail.value;
|
||||
if (!item) return false;
|
||||
return !!(
|
||||
item.inventory_source_code
|
||||
|| item.inventory_site_id
|
||||
|| item.inventory_warehouse_id
|
||||
|| item.inventory_source_status
|
||||
);
|
||||
});
|
||||
|
||||
const loadCases = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
@@ -388,6 +413,45 @@ onMounted(async () => {
|
||||
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.freightRef') }}</dt><dd>{{ detail.freight_ref_no || '—' }}</dd></div>
|
||||
</dl>
|
||||
|
||||
<div
|
||||
v-if="hasInventorySourceFields"
|
||||
class="rounded-2xl border border-default/80 bg-surface px-4 py-3 text-sm"
|
||||
>
|
||||
<h3 class="mb-2 text-sm font-semibold text-secondary">
|
||||
{{ $t('workspace.shippingNotice.inventorySource.title') }}
|
||||
</h3>
|
||||
<dl class="grid gap-2 sm:grid-cols-2">
|
||||
<div>
|
||||
<dt class="text-xs text-muted">{{ $t('workspace.shippingNotice.inventorySource.sourceCode') }}</dt>
|
||||
<dd class="font-mono">{{ detail.inventory_source_code || '—' }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="text-xs text-muted">{{ $t('workspace.shippingNotice.inventorySource.status') }}</dt>
|
||||
<dd>{{ inventorySourceStatusLabel(detail.inventory_source_status) }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="text-xs text-muted">{{ $t('workspace.shippingNotice.inventorySource.siteId') }}</dt>
|
||||
<dd class="font-mono">{{ detail.inventory_site_id || '—' }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="text-xs text-muted">{{ $t('workspace.shippingNotice.inventorySource.warehouseId') }}</dt>
|
||||
<dd class="font-mono">{{ detail.inventory_warehouse_id || '—' }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="text-xs text-muted">{{ $t('workspace.shippingNotice.inventorySource.method') }}</dt>
|
||||
<dd>{{ inventorySourceMethodLabel(detail.inventory_source_method) }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="text-xs text-muted">{{ $t('workspace.shippingNotice.inventorySource.configVersion') }}</dt>
|
||||
<dd class="font-mono text-xs">{{ detail.inventory_source_config_version || '—' }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="text-xs text-muted">{{ $t('workspace.shippingNotice.inventorySource.confirmedBy') }}</dt>
|
||||
<dd class="font-mono">{{ detail.inventory_source_confirmed_by ?? '—' }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="detail.inventory_snapshot"
|
||||
class="rounded-2xl border border-default/80 bg-surface px-4 py-3 text-sm"
|
||||
|
||||
Reference in new issue
Block a user