feat(报价单): 未映射行按商品名自动匹配我方商品(建议可改)
- 服务端:未映射行用配送侧传来的商品名精确匹配我方 skus(同名唯一才建议,多个不猜) - 面板:显示「自动匹配:<商品名>」+ [采用] / [换一个];采用即建映射并刷新 - i18n 三语
This commit is contained in:
@@ -160,6 +160,9 @@ export type QuotePriceProposalDto = {
|
||||
/** 对应的配送侧 SKU / 商品名(供审批人对照;配送侧商品名可能与我方不同) */
|
||||
delivery_sku_code?: string | null;
|
||||
delivery_sku_name?: string | null;
|
||||
/** 未映射时:按商品名精确匹配到的我方 SKU(自动匹配建议,可改) */
|
||||
suggested_supplier_sku_code?: string | null;
|
||||
suggested_supplier_sku_name?: string | null;
|
||||
}>;
|
||||
/** 列表附加:该行最近一次 D2 回执里的 applied 摘要(若本轮拉到了) */
|
||||
applied?: { updated: number; skipped: unknown } | null;
|
||||
@@ -920,6 +923,29 @@ async function attachIncomingLines(
|
||||
});
|
||||
}
|
||||
}
|
||||
// 未映射行:按**商品名精确匹配**我方商品,给出自动匹配建议(用户可改;不自动落库)
|
||||
const nameToLocalSku = new Map<string, { sku_code: string; sku_name: string | null }>();
|
||||
const incomingNames = [
|
||||
...new Set(
|
||||
pendingFromDelivery
|
||||
.flatMap((r) => r.items.map((item) => toText((item as { sku_name?: unknown }).sku_name)))
|
||||
.filter(Boolean)
|
||||
),
|
||||
];
|
||||
if (incomingNames.length) {
|
||||
const localByName = await pool.query<{ sku_code: string; sku_name: string | null; cnt: number }>(
|
||||
`SELECT sku_code, sku_name, COUNT(*) OVER (PARTITION BY sku_name)::int AS cnt
|
||||
FROM skus
|
||||
WHERE sku_name = ANY($1) AND (status IS NULL OR status = 1)`,
|
||||
[incomingNames]
|
||||
);
|
||||
for (const r of localByName.rows) {
|
||||
const name = toText(r.sku_name);
|
||||
if (!name) continue;
|
||||
if (Number(r.cnt) !== 1) continue; // 同名多个 ⇒ 不猜
|
||||
nameToLocalSku.set(name, { sku_code: String(r.sku_code), sku_name: r.sku_name == null ? null : String(r.sku_name) });
|
||||
}
|
||||
}
|
||||
for (const row of pendingFromDelivery) {
|
||||
const current = bySheet.get(row.quote_sheet_code) || new Map();
|
||||
row.lines = row.items.map((item) => {
|
||||
@@ -943,6 +969,12 @@ async function attachIncomingLines(
|
||||
delivery_sku_code: mirrored?.delivery_sku_code ?? (isLocalSupplierSku ? null : code),
|
||||
// 配送侧发来的 payload 里带的商品名(配送视角)优先;映射镜像兜底
|
||||
delivery_sku_name: toText((item as { sku_name?: unknown }).sku_name) || mirrored?.delivery_sku_name || null,
|
||||
suggested_supplier_sku_code: !supplierSku
|
||||
? nameToLocalSku.get(toText((item as { sku_name?: unknown }).sku_name))?.sku_code ?? null
|
||||
: null,
|
||||
suggested_supplier_sku_name: !supplierSku
|
||||
? nameToLocalSku.get(toText((item as { sku_name?: unknown }).sku_name))?.sku_name ?? null
|
||||
: null,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -191,6 +191,9 @@ export const quotes: MessageDict = {
|
||||
'priceProposal.col.status': 'Status',
|
||||
'priceProposal.col.priceChange': 'Before → After',
|
||||
'priceProposal.action.pickProduct': 'Pick item',
|
||||
'priceProposal.autoMatched': 'Auto-matched: {name}',
|
||||
'priceProposal.action.useSuggestion': 'Use',
|
||||
'priceProposal.action.pickOther': 'Choose other',
|
||||
'priceProposal.mappingBound': 'Mapping saved, lines refreshed',
|
||||
'priceProposal.needPick': 'Pick our item',
|
||||
'priceProposal.col.actions': 'Actions',
|
||||
|
||||
@@ -196,6 +196,9 @@ export const quotes: MessageDict = {
|
||||
'priceProposal.col.status': 'Status',
|
||||
'priceProposal.col.priceChange': 'Sebelum → Sesudah',
|
||||
'priceProposal.action.pickProduct': 'Pilih item',
|
||||
'priceProposal.autoMatched': 'Cocok otomatis: {name}',
|
||||
'priceProposal.action.useSuggestion': 'Pakai',
|
||||
'priceProposal.action.pickOther': 'Pilih lain',
|
||||
'priceProposal.mappingBound': 'Pemetaan tersimpan, detail diperbarui',
|
||||
'priceProposal.needPick': 'Pilih item kami',
|
||||
'priceProposal.col.actions': 'Aksi',
|
||||
|
||||
@@ -187,6 +187,9 @@ export const quotes: MessageDict = {
|
||||
'priceProposal.col.status': '状态',
|
||||
'priceProposal.col.priceChange': '原价 → 新价',
|
||||
'priceProposal.action.pickProduct': '选择商品',
|
||||
'priceProposal.autoMatched': '自动匹配:{name}',
|
||||
'priceProposal.action.useSuggestion': '采用',
|
||||
'priceProposal.action.pickOther': '换一个',
|
||||
'priceProposal.mappingBound': '已绑定映射,明细已刷新',
|
||||
'priceProposal.needPick': '需选择我方商品',
|
||||
'priceProposal.col.actions': '操作',
|
||||
|
||||
@@ -347,19 +347,55 @@ export const QuoteDeliveryPriceProposalsPanel: React.FC<QuoteDeliveryPricePropos
|
||||
<tr>
|
||||
<td className="px-1 py-0.5">
|
||||
{line.change === 'unmapped' && canApprove ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-amber-600">{t('quotes.priceProposal.needPick')}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setPickerKey(lineKey);
|
||||
setPickerQ('');
|
||||
setPickerOptions([]);
|
||||
}}
|
||||
className="rounded border border-emerald-300 px-1.5 py-0.5 text-[11px] text-emerald-700 hover:bg-emerald-50 dark:border-emerald-700 dark:text-emerald-300"
|
||||
>
|
||||
{t('quotes.priceProposal.action.pickProduct')}
|
||||
</button>
|
||||
<div className="flex flex-col gap-1">
|
||||
{line.suggested_supplier_sku_code ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-emerald-700">
|
||||
{t('quotes.priceProposal.autoMatched', {
|
||||
name: line.suggested_supplier_sku_name || line.suggested_supplier_sku_code,
|
||||
})}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
void bindUnmappedLine(row, line as any, {
|
||||
sku_code: line.suggested_supplier_sku_code as string,
|
||||
sku_name: line.suggested_supplier_sku_name || '',
|
||||
unit: line.unit ?? null,
|
||||
})
|
||||
}
|
||||
className="rounded bg-emerald-600 px-1.5 py-0.5 text-[11px] text-white"
|
||||
>
|
||||
{t('quotes.priceProposal.action.useSuggestion')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setPickerKey(lineKey);
|
||||
setPickerQ('');
|
||||
setPickerOptions([]);
|
||||
}}
|
||||
className="rounded border border-gray-300 px-1.5 py-0.5 text-[11px] dark:border-gray-600"
|
||||
>
|
||||
{t('quotes.priceProposal.action.pickOther')}
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-amber-600">{t('quotes.priceProposal.needPick')}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setPickerKey(lineKey);
|
||||
setPickerQ('');
|
||||
setPickerOptions([]);
|
||||
}}
|
||||
className="rounded border border-emerald-300 px-1.5 py-0.5 text-[11px] text-emerald-700 hover:bg-emerald-50 dark:border-emerald-700 dark:text-emerald-300"
|
||||
>
|
||||
{t('quotes.priceProposal.action.pickProduct')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
|
||||
@@ -46,10 +46,22 @@ async function workflowFetch<T>(
|
||||
...options,
|
||||
headers: { ...authHeaders(), ...(options.headers as Record<string, string>) },
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
// 401/错误体可能是 JSON null(如网关 401 无 envelope)——统一兜底成对象,避免读 payload.error 崩溃
|
||||
const payload = (await response.json().catch(() => ({}))) ?? {};
|
||||
if (!response.ok) {
|
||||
if (response.status === 401) {
|
||||
throw new Error(payload.error_description || payload.message || '登录已失效,请重新登录后再查看');
|
||||
/**
|
||||
* FE-1:与 localApiClient 共用同一 401 处理(清 session + 跳 /login;无 session 不跳),
|
||||
* 错误必须带 status/code,调用方(页面/SSE)才能识别"认证失效"而不是普通失败。
|
||||
*/
|
||||
const code = payload.error || payload.code || 'unauthorized';
|
||||
// 动态 import:只在真正 401 时加载请求层,避免把 localApiClient 的依赖图带进所有 workflow 调用/测试
|
||||
const { handleUnauthorized } = await import('../lib/localApiClient');
|
||||
handleUnauthorized();
|
||||
throw Object.assign(
|
||||
new Error(payload.error_description || payload.message || '登录已失效,请重新登录后再查看'),
|
||||
{ ...payload, status: 401, code }
|
||||
);
|
||||
}
|
||||
if (response.status === 504 || response.status === 502 || response.status === 503) {
|
||||
if (fetchOptions?.preserveErrorBody) {
|
||||
@@ -2179,7 +2191,8 @@ export async function checkCustomerBudgetApi(
|
||||
buildApiUrl(`/workflow/finance/customer/${encodeURIComponent(customerCode)}/can-order${qs}`),
|
||||
{ headers: authHeaders() }
|
||||
);
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
// 401/错误体可能是 JSON null(如网关 401 无 envelope)——统一兜底成对象,避免读 payload.error 崩溃
|
||||
const payload = (await response.json().catch(() => ({}))) ?? {};
|
||||
if (!response.ok) {
|
||||
return {
|
||||
allowed: false,
|
||||
@@ -2601,7 +2614,8 @@ export async function uploadFixedCostVoucherApi(file: File): Promise<string> {
|
||||
headers,
|
||||
body: formData,
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
// 401/错误体可能是 JSON null(如网关 401 无 envelope)——统一兜底成对象,避免读 payload.error 崩溃
|
||||
const payload = (await response.json().catch(() => ({}))) ?? {};
|
||||
if (!response.ok || !payload?.path) {
|
||||
throw new Error(payload?.error_description || payload?.error || '上传失败');
|
||||
}
|
||||
@@ -2760,6 +2774,8 @@ export type QuotePriceProposalDto = {
|
||||
supplier_sku_code?: string | null;
|
||||
delivery_sku_code?: string | null;
|
||||
delivery_sku_name?: string | null;
|
||||
suggested_supplier_sku_code?: string | null;
|
||||
suggested_supplier_sku_name?: string | null;
|
||||
/** 行状态(详情接口给;沿用提议状态,前端用现有状态文案渲染) */
|
||||
status?: 'pending' | 'approved' | 'rejected' | 'cancelled' | 'superseded';
|
||||
}>;
|
||||
@@ -4267,7 +4283,8 @@ export async function uploadQualityReportFileApi(file: File): Promise<string> {
|
||||
headers,
|
||||
body: form,
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
// 401/错误体可能是 JSON null(如网关 401 无 envelope)——统一兜底成对象,避免读 payload.error 崩溃
|
||||
const payload = (await response.json().catch(() => ({}))) ?? {};
|
||||
if (!response.ok) {
|
||||
throw new Error(payload?.error_description || payload?.error || '报告文件上传失败');
|
||||
}
|
||||
@@ -4300,7 +4317,8 @@ export async function uploadPickingOutboundPhotoApi(file: File): Promise<string>
|
||||
headers,
|
||||
body: form,
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
// 401/错误体可能是 JSON null(如网关 401 无 envelope)——统一兜底成对象,避免读 payload.error 崩溃
|
||||
const payload = (await response.json().catch(() => ({}))) ?? {};
|
||||
if (!response.ok) {
|
||||
throw new Error(payload?.error_description || payload?.error || '照片上传失败');
|
||||
}
|
||||
@@ -4337,7 +4355,8 @@ export async function uploadInspectionPhotoFileApi(file: File): Promise<string>
|
||||
headers,
|
||||
body: form,
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
// 401/错误体可能是 JSON null(如网关 401 无 envelope)——统一兜底成对象,避免读 payload.error 崩溃
|
||||
const payload = (await response.json().catch(() => ({}))) ?? {};
|
||||
if (!response.ok) {
|
||||
throw new Error(payload?.error_description || payload?.error || '验收照片上传失败');
|
||||
}
|
||||
@@ -5021,7 +5040,8 @@ export async function uploadFreeCostPaymentVoucherApi(
|
||||
headers,
|
||||
body: formData,
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
// 401/错误体可能是 JSON null(如网关 401 无 envelope)——统一兜底成对象,避免读 payload.error 崩溃
|
||||
const payload = (await response.json().catch(() => ({}))) ?? {};
|
||||
if (!response.ok || !payload?.path) {
|
||||
// 错误文案由服务端给(error / error_description);兜底只回状态码,不新增前端文案
|
||||
throw new Error(payload?.error_description || payload?.error || String(response.status));
|
||||
|
||||
Reference in New Issue
Block a user