feat(审核): 已映射行也可「改映射」;绑定前清理旧镜像
用户要求:供应商侧审核时要能调整我方商品(自动配对之后仍可改)。 - 面板:所有行(含已映射/自动匹配)显示「改映射」,复用选择器 - 服务:绑定前先把同一配送 SKU 的旧镜像行清空(partial unique 要求)
This commit is contained in:
@@ -433,10 +433,28 @@ export async function listLocalSkuMappings(input: {
|
||||
LIMIT $${params.length}`,
|
||||
params
|
||||
);
|
||||
/**
|
||||
* FE-3(2026-10-19):summary 必须与**当前筛选**(status/keyword)同口径,
|
||||
* 否则「只看未映射」时表头仍显示全表数字。WHERE 与上面的列表查询逐条一致、参数同序。
|
||||
*/
|
||||
const countParams: unknown[] = [];
|
||||
const countWhere: string[] = [];
|
||||
if (status) {
|
||||
countParams.push(status);
|
||||
countWhere.push(`status = $${countParams.length}`);
|
||||
}
|
||||
if (keyword) {
|
||||
countParams.push(`%${keyword}%`);
|
||||
countWhere.push(
|
||||
`(supplier_sku_code ILIKE $${countParams.length} OR supplier_sku_name ILIKE $${countParams.length} OR delivery_sku_code ILIKE $${countParams.length} OR delivery_sku_name ILIKE $${countParams.length})`
|
||||
);
|
||||
}
|
||||
const counts = await pool.query<{ total: number; mapped: number }>(
|
||||
`SELECT count(*)::int AS total,
|
||||
count(*) FILTER (WHERE status = 'active' AND delivery_sku_code IS NOT NULL)::int AS mapped
|
||||
FROM main_system_sku_mappings`
|
||||
FROM main_system_sku_mappings
|
||||
${countWhere.length ? `WHERE ${countWhere.join(' AND ')}` : ''}`,
|
||||
countParams
|
||||
);
|
||||
const total = Number(counts.rows[0]?.total) || 0;
|
||||
const mapped = Number(counts.rows[0]?.mapped) || 0;
|
||||
@@ -587,6 +605,13 @@ export async function bindMappingForDeliverySku(input: {
|
||||
const deliverySkuName = remote && remote.delivery_sku_name != null ? String(remote.delivery_sku_name) : null;
|
||||
|
||||
await runWithTenantDbContext(branchCode, async () => {
|
||||
// 改绑:同一配送 SKU 原先挂在别的我方 SKU 上时,先把旧镜像行清空(partial unique 要求同一时刻只有一个 active)
|
||||
await pool.query(
|
||||
`UPDATE main_system_sku_mappings
|
||||
SET status = 'pending', delivery_sku_code = NULL, delivery_sku_name = NULL, updated_at = NOW()
|
||||
WHERE delivery_sku_code = $1 AND supplier_sku_code <> $2`,
|
||||
[deliverySkuCode, supplierSkuCode]
|
||||
);
|
||||
await pool.query(
|
||||
`INSERT INTO main_system_sku_mappings
|
||||
(supplier_sku_code, supplier_sku_name, supplier_unit, delivery_sku_code, delivery_sku_name, status, synced_at, updated_at)
|
||||
|
||||
@@ -190,6 +190,7 @@ export const quotes: MessageDict = {
|
||||
'priceProposal.col.itemCount': 'Items',
|
||||
'priceProposal.col.status': 'Status',
|
||||
'priceProposal.col.priceChange': 'Before → After',
|
||||
'priceProposal.action.remap': 'Change mapping',
|
||||
'priceProposal.action.pickProduct': 'Pick item',
|
||||
'priceProposal.autoMatched': 'Auto-matched: {name}',
|
||||
'priceProposal.action.useSuggestion': 'Use',
|
||||
|
||||
@@ -195,6 +195,7 @@ export const quotes: MessageDict = {
|
||||
'priceProposal.col.itemCount': 'Item',
|
||||
'priceProposal.col.status': 'Status',
|
||||
'priceProposal.col.priceChange': 'Sebelum → Sesudah',
|
||||
'priceProposal.action.remap': 'Ubah pemetaan',
|
||||
'priceProposal.action.pickProduct': 'Pilih item',
|
||||
'priceProposal.autoMatched': 'Cocok otomatis: {name}',
|
||||
'priceProposal.action.useSuggestion': 'Pakai',
|
||||
|
||||
@@ -186,6 +186,7 @@ export const quotes: MessageDict = {
|
||||
'priceProposal.col.itemCount': '商品数',
|
||||
'priceProposal.col.status': '状态',
|
||||
'priceProposal.col.priceChange': '原价 → 新价',
|
||||
'priceProposal.action.remap': '改映射',
|
||||
'priceProposal.action.pickProduct': '选择商品',
|
||||
'priceProposal.autoMatched': '自动匹配:{name}',
|
||||
'priceProposal.action.useSuggestion': '采用',
|
||||
|
||||
@@ -409,6 +409,19 @@ export const QuoteDeliveryPriceProposalsPanel: React.FC<QuoteDeliveryPricePropos
|
||||
<span className="ml-1 font-mono text-gray-400">
|
||||
{line.supplier_sku_code || line.sku_code}
|
||||
</span>
|
||||
{canApprove && line.delivery_sku_code ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setPickerKey(lineKey);
|
||||
setPickerQ('');
|
||||
setPickerOptions([]);
|
||||
}}
|
||||
className="ml-2 rounded border border-gray-300 px-1.5 py-0.5 text-[11px] text-gray-600 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-800"
|
||||
>
|
||||
{t('quotes.priceProposal.action.remap')}
|
||||
</button>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user