feat(shipping-notice): 收料异动解析配置闭环与按需触发FK违例修复
- 收料单元 schedule_run_id 改可空,修复按需触发 FK 违例 - 收料配置绑定已发布异动解析规则(校验/回显/审计快照) - 预检未绑异动规则 fail-closed,不再徒劳触发 RPA - 标准异动字段目录只读接口;解析规则用途切换与批号映射表单(四语言) - movement 解析规则可发布(跳过订单匹配键校验);站点启停门禁仅限库存站点页签 - 只读映射卡三列布局修复
This commit is contained in:
1 parent
ab57ab3b1f
commit
20835dcfc0
28 files changed
+987
-73
No files matched your search
@@ -288,6 +288,10 @@ export const createShippingInventoryStructureAnalysis = (file: File) => {
|
||||
method: 'POST', body: form, ...auth(),
|
||||
});
|
||||
};
|
||||
/** 读取标准异动字段目录(只读领域契约,供收料异动解析规则映射表单)。 */
|
||||
export const fetchMovementFields = () => requestJson<Array<{ code: string; value_type: string; required: boolean; is_identity: boolean }>>(
|
||||
'/api/admin/shipping-notice/movement-fields', auth(),
|
||||
);
|
||||
/** 用已分析的真实栏位创建库存文件解析方案草稿。 */
|
||||
export const createShippingInventoryParsingDraftFromAnalysis = (id: number, payload: Record<string, unknown>) => requestJson<unknown>(
|
||||
`/api/admin/shipping-notice/inventory-structure-analyses/${id}/create-profile-draft`,
|
||||
|
||||
@@ -124,7 +124,7 @@
|
||||
<label><span>{{ t('admin.shippingInventory.inventorySiteName') }}</span><input v-model="source.display_name" class="input-field" required></label>
|
||||
<label><span>{{ t('admin.shippingInventory.connectorType') }}</span><select v-model="source.connector_type" class="select-field"><option value="dbs">{{ t('admin.shippingInventory.platform.dbs') }}</option><option value="crane">{{ t('admin.shippingInventory.platform.crane') }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingInventory.connection') }}</span><select v-model.number="source.rpa_profile_id" class="select-field" required><option :value="0">{{ t('admin.shippingInventory.chooseConnection') }}</option><option v-for="item in compatibleProfiles" :key="String(item.id)" :value="Number(item.id)">{{ item.display_name || item.profile_code }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingInventory.parsingProfiles') }}</span><select v-model.number="source.parsing_profile_id" class="select-field" :disabled="source.enabled"><option :value="0">{{ t('admin.shippingInventory.notConfigured') }}</option><option v-for="item in parsingProfiles.filter((row) => row.status === 'published')" :key="String(item.id)" :value="Number(item.id)">{{ item.display_name || item.profile_code }} V{{ item.version }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingInventory.parsingProfiles') }}</span><select v-model.number="source.parsing_profile_id" class="select-field" :disabled="source.enabled"><option :value="0">{{ t('admin.shippingInventory.notConfigured') }}</option><option v-for="item in parsingProfiles.filter((row) => row.status === 'published' && row.purpose !== 'movement')" :key="String(item.id)" :value="Number(item.id)">{{ item.display_name || item.profile_code }} V{{ item.version }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingInventory.excelTemplates') }}</span><select v-model.number="source.excel_template_id" class="select-field"><option :value="0">{{ t('admin.shippingInventory.notConfigured') }}</option><option v-for="item in excelTemplates.filter((row) => row.status === 'published')" :key="String(item.id)" :value="Number(item.id)">{{ item.display_name || item.template_code }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingInventory.warehouseResolution') }}</span><select v-model="source.warehouse_resolution_mode" class="select-field"><option value="fixed">{{ t('admin.shippingInventory.fixedWarehouse') }}</option><option value="inventory_match">{{ t('admin.shippingInventory.inventoryMatch') }}</option></select></label>
|
||||
<label v-if="source.warehouse_resolution_mode === 'fixed'"><span>{{ t('admin.shippingInventory.warehouse') }}</span><input v-model="source.fixed_warehouse_id" class="input-field" required></label>
|
||||
@@ -178,6 +178,7 @@
|
||||
<button type="button" class="btn-secondary btn-sm full" @click="addReceiptParameter">{{ t('admin.shippingInventory.addParameter') }}</button>
|
||||
</template>
|
||||
<p v-else class="form-tip full">{{ t('admin.shippingInventory.receiptCraneFixedPath') }}</p>
|
||||
<label class="full"><span>{{ t('admin.shippingInventory.movementBindingLabel') }}</span><select v-model.number="receiptConfig.parsing_profile_id" class="select-field"><option :value="null">{{ t('admin.shippingInventory.movementBindingNone') }}</option><option v-for="item in parsingProfiles.filter((row) => row.status === 'published' && row.purpose === 'movement')" :key="`movement-bind-${item.id}`" :value="Number(item.id)">{{ item.display_name || item.profile_code }} V{{ item.version }}</option></select><small>{{ t('admin.shippingInventory.movementBindingHint') }}</small></label>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -185,21 +186,32 @@
|
||||
<template v-else-if="activeTab === 'parsing'">
|
||||
<template v-if="parsingReadOnly">
|
||||
<section class="parsing-summary full">
|
||||
<div><span>{{ t('admin.shippingInventory.parsingPurposeLabel') }}</span><strong>{{ t(`admin.shippingInventory.parsingPurpose.${parsing.purpose === 'movement' ? 'movement' : 'inventory'}`) }}</strong></div>
|
||||
<div><span>{{ t('admin.shippingInventory.fileFormat') }}</span><strong>{{ parsing.file_format.toUpperCase() }}</strong></div>
|
||||
<div><span>{{ t('admin.shippingInventory.sheetName') }}</span><strong>{{ parsing.sheet_name || t('admin.shippingInventory.csvFile') }}</strong></div>
|
||||
<div><span>{{ t('admin.shippingInventory.headerRowIndex') }}</span><strong>{{ t('admin.shippingInventory.headerRowOption', { row: parsing.header_row_index }) }}</strong></div>
|
||||
</section>
|
||||
<section class="readonly-mapping-section full">
|
||||
<div class="subsection">{{ t('admin.shippingInventory.fieldMappings') }}</div>
|
||||
<p class="section-hint">{{ t('admin.shippingInventory.readonlyFieldMappingsHint') }}</p>
|
||||
<div v-for="(item, index) in parsing.field_mappings" :key="`readonly-field-${index}`" class="parsing-mapping-card">
|
||||
<div class="mapping-title"><strong>{{ t('admin.shippingInventory.mappingItem', { number: index + 1 }) }}</strong></div>
|
||||
<div class="mapping-display"><span>{{ t('admin.shippingInventory.inventoryField') }}</span><b>{{ inventoryFieldName(item.inventory_field) }}</b><small>{{ inventoryFieldDescription(item.inventory_field) }}</small></div>
|
||||
<div class="mapping-arrow" aria-hidden="true">→</div>
|
||||
<div class="mapping-display"><span>{{ t('admin.shippingInventory.sourceHeader') }}</span><b>{{ item.source_header }}</b></div>
|
||||
</div>
|
||||
<div class="subsection">{{ t(`admin.shippingInventory.${parsingLabelNs}.fieldMappings`) }}</div>
|
||||
<p class="section-hint">{{ t(parsing.purpose === 'movement' ? 'admin.shippingInventory.movementMappingHint' : 'admin.shippingInventory.readonlyFieldMappingsHint') }}</p>
|
||||
<template v-if="parsing.purpose === 'movement'">
|
||||
<div v-for="(item, index) in parsing.movement_mappings" :key="`readonly-movement-${item.code}`" class="parsing-mapping-card">
|
||||
<div class="mapping-title"><strong>{{ t('admin.shippingInventory.mappingItem', { number: index + 1 }) }}</strong></div>
|
||||
<div class="mapping-display"><span>{{ t('admin.shippingInventory.movementStandardField') }}</span><b>{{ t(`admin.shippingInventory.movementFields.${item.code}`) }}</b><small><b v-if="item.required">{{ t('admin.shippingInventory.movementRequiredMark') }}</b><template v-if="item.required && item.is_identity"> · </template><b v-if="item.is_identity">{{ t('admin.shippingInventory.movementIdentityMark') }}</b></small></div>
|
||||
<div class="mapping-arrow" aria-hidden="true">→</div>
|
||||
<div class="mapping-display"><span>{{ t(`admin.shippingInventory.${parsingLabelNs}.sourceHeader`) }}</span><b>{{ item.alias || '-' }}</b></div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div v-for="(item, index) in parsing.field_mappings" :key="`readonly-field-${index}`" class="parsing-mapping-card">
|
||||
<div class="mapping-title"><strong>{{ t('admin.shippingInventory.mappingItem', { number: index + 1 }) }}</strong></div>
|
||||
<div class="mapping-display"><span>{{ t('admin.shippingInventory.inventoryField') }}</span><b>{{ inventoryFieldName(item.inventory_field) }}</b><small>{{ inventoryFieldDescription(item.inventory_field) }}</small></div>
|
||||
<div class="mapping-arrow" aria-hidden="true">→</div>
|
||||
<div class="mapping-display"><span>{{ t('admin.shippingInventory.sourceHeader') }}</span><b>{{ item.source_header }}</b></div>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
<section class="readonly-mapping-section full">
|
||||
<section v-if="parsing.purpose !== 'movement'" class="readonly-mapping-section full">
|
||||
<div class="subsection">{{ t('admin.shippingInventory.matchKeys') }}</div>
|
||||
<p class="section-hint">{{ t('admin.shippingInventory.readonlyMatchKeysHint') }}</p>
|
||||
<div v-for="(item, index) in parsing.match_keys" :key="`readonly-match-${index}`" class="parsing-mapping-card match-key-card">
|
||||
@@ -213,12 +225,13 @@
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<label><span>{{ t('admin.shippingInventory.parsingProfileCode') }}</span><input v-model="parsing.profile_code" class="input-field" :disabled="Boolean(selectedId)" required></label>
|
||||
<label><span>{{ t('admin.shippingInventory.parsingProfileName') }}</span><input v-model="parsing.display_name" class="input-field" required></label>
|
||||
<label><span>{{ t(`admin.shippingInventory.${parsingLabelNs}.code`) }}</span><input v-model="parsing.profile_code" class="input-field" :disabled="Boolean(selectedId)" required></label>
|
||||
<label><span>{{ t(`admin.shippingInventory.${parsingLabelNs}.name`) }}</span><input v-model="parsing.display_name" class="input-field" required></label>
|
||||
<label><span>{{ t('admin.shippingInventory.parsingPurposeLabel') }}</span><select v-model="parsing.purpose" class="select-field" :disabled="Boolean(selectedId)" @change="resetMappingRowsForPurpose"><option value="inventory">{{ t('admin.shippingInventory.parsingPurpose.inventory') }}</option><option value="movement">{{ t('admin.shippingInventory.parsingPurpose.movement') }}</option></select><small>{{ t('admin.shippingInventory.parsingPurposeHint') }}</small></label>
|
||||
<label><span>{{ t('admin.shippingInventory.fileFormat') }}</span><select v-model="parsing.file_format" class="select-field"><option value="xls">xls</option><option value="xlsx">xlsx</option><option value="csv">csv</option></select></label>
|
||||
<label v-if="!selectedId" class="full"><span>{{ t('admin.shippingInventory.temporaryInventorySession') }}</span><select v-model="selectedTemporaryInventorySession" class="select-field" @change="loadTemporaryInventorySession"><option value="">{{ t('admin.shippingInventory.temporaryInventorySessionNone') }}</option><option v-for="item in temporaryInventorySessions" :key="item.session_no" :value="item.session_no">{{ item.source_file_name }} · {{ item.session_no }}</option></select><small>{{ t('admin.shippingInventory.temporaryInventorySessionHint') }}</small></label>
|
||||
<label v-if="!selectedId && parsing.purpose !== 'movement'" class="full"><span>{{ t('admin.shippingInventory.temporaryInventorySession') }}</span><select v-model="selectedTemporaryInventorySession" class="select-field" @change="loadTemporaryInventorySession"><option value="">{{ t('admin.shippingInventory.temporaryInventorySessionNone') }}</option><option v-for="item in temporaryInventorySessions" :key="item.session_no" :value="item.session_no">{{ item.source_file_name }} · {{ item.session_no }}</option></select><small>{{ t('admin.shippingInventory.temporaryInventorySessionHint') }}</small></label>
|
||||
<div v-if="temporaryInventorySessionSelected" class="form-tip full">{{ t('admin.shippingInventory.temporaryInventorySessionSelected', { mapping: temporaryInventorySessionSelected.confirmed_usage?.mapping_origin || '-' }) }}</div>
|
||||
<label v-if="!selectedId" class="full"><span>{{ t('admin.shippingInventory.inventorySampleFile') }}</span><input type="file" accept=".xls,.xlsx,.csv" :disabled="analysisLoading || Boolean(temporaryInventorySessionSelected)" @change="analyseInventorySample"><small>{{ t('admin.shippingInventory.inventorySampleFileHint') }}</small></label>
|
||||
<label v-if="!selectedId" class="full"><span>{{ t(`admin.shippingInventory.${parsingLabelNs}.sampleFile`) }}</span><input type="file" accept=".xls,.xlsx,.csv" :disabled="analysisLoading || Boolean(temporaryInventorySessionSelected)" @change="analyseInventorySample"><small>{{ t(`admin.shippingInventory.${parsingLabelNs}.sampleFileHint`) }}</small></label>
|
||||
<section v-else-if="structureAnalysis" class="sample-evidence-card full">
|
||||
<div>
|
||||
<strong>{{ pendingSampleReplacement ? t('admin.shippingInventory.pendingInventorySampleReplacement') : t('admin.shippingInventory.savedInventorySample') }}</strong>
|
||||
@@ -236,28 +249,37 @@
|
||||
<template v-if="structureAnalysis">
|
||||
<label><span>{{ t('admin.shippingInventory.sheetName') }}</span><select v-model="parsing.sheet_name" class="select-field" @change="applyAnalysisCandidate"><option v-for="candidate in analysisCandidates" :key="candidateKey(candidate)" :value="candidate.sheet_name || ''">{{ candidate.sheet_name || t('admin.shippingInventory.csvFile') }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingInventory.headerRowIndex') }}</span><select v-model.number="parsing.header_row_index" class="select-field" @change="applyAnalysisCandidate"><option v-for="candidate in analysisCandidatesForSheet" :key="candidateKey(candidate)" :value="candidate.header_row_index">{{ t('admin.shippingInventory.headerRowOption', { row: candidate.header_row_index }) }}</option></select></label>
|
||||
<section class="analysis-preview full"><strong>{{ t('admin.shippingInventory.inventoryAnalysisPreview') }}</strong><p>{{ t('admin.shippingInventory.inventoryAnalysisSummary', structureAnalysis.validation_summary) }}</p><div class="analysis-columns"><span v-for="column in selectedAnalysisColumns" :key="`${column.index}-${column.header}`"><b>{{ column.header || t('admin.shippingInventory.emptyHeader') }}</b><small>{{ column.inferred_type }} · {{ column.sample_values?.join(' / ') || '-' }}</small></span></div></section>
|
||||
<section v-if="structureAnalysis.match_result?.candidates?.length" class="analysis-preview full"><strong>{{ t('admin.shippingInventory.parsingPlanRecommendation') }}</strong><div class="recommendation-list"><article v-for="candidate in structureAnalysis.match_result.candidates" :key="candidate.profile_id"><b>{{ candidate.display_name }} V{{ candidate.version }}</b><small>{{ t(`admin.shippingInventory.recommendationLevel.${candidate.level}`) }} · {{ t('admin.shippingInventory.usedBySites', { count: candidate.source_count }) }}</small><p v-if="candidate.difference?.added_columns?.length">{{ t('admin.shippingInventory.addedColumns', { columns: candidate.difference.added_columns.join('、') }) }}</p><p v-if="candidate.difference?.column_order_changed?.length">{{ t('admin.shippingInventory.columnOrderChanged') }}</p><button type="button" class="btn-secondary btn-sm" @click="adoptRecommendedProfile(candidate.profile_id)">{{ t('admin.shippingInventory.adoptParsingPlan') }}</button></article></div></section>
|
||||
<section class="analysis-preview full"><strong>{{ t(`admin.shippingInventory.${parsingLabelNs}.analysisPreview`) }}</strong><p>{{ t('admin.shippingInventory.inventoryAnalysisSummary', structureAnalysis.validation_summary) }}</p><div class="analysis-columns"><span v-for="column in selectedAnalysisColumns" :key="`${column.index}-${column.header}`"><b>{{ column.header || t('admin.shippingInventory.emptyHeader') }}</b><small>{{ column.inferred_type }} · {{ column.sample_values?.join(' / ') || '-' }}</small></span></div></section>
|
||||
<section v-if="parsing.purpose !== 'movement' && structureAnalysis.match_result?.candidates?.length" class="analysis-preview full"><strong>{{ t('admin.shippingInventory.parsingPlanRecommendation') }}</strong><div class="recommendation-list"><article v-for="candidate in structureAnalysis.match_result.candidates" :key="candidate.profile_id"><b>{{ candidate.display_name }} V{{ candidate.version }}</b><small>{{ t(`admin.shippingInventory.recommendationLevel.${candidate.level}`) }} · {{ t('admin.shippingInventory.usedBySites', { count: candidate.source_count }) }}</small><p v-if="candidate.difference?.added_columns?.length">{{ t('admin.shippingInventory.addedColumns', { columns: candidate.difference.added_columns.join('、') }) }}</p><p v-if="candidate.difference?.column_order_changed?.length">{{ t('admin.shippingInventory.columnOrderChanged') }}</p><button type="button" class="btn-secondary btn-sm" @click="adoptRecommendedProfile(candidate.profile_id)">{{ t('admin.shippingInventory.adoptParsingPlan') }}</button></article></div></section>
|
||||
</template>
|
||||
<div v-else class="form-tip full">{{ t(`admin.shippingInventory.${parsingLabelNs}.sampleRequired`) }}</div>
|
||||
<template v-if="parsing.purpose === 'movement'">
|
||||
<div class="subsection full">{{ t(`admin.shippingInventory.${parsingLabelNs}.fieldMappings`) }}<small>{{ t('admin.shippingInventory.movementMappingHint') }}</small></div>
|
||||
<div v-for="item in parsing.movement_mappings" :key="`movement-${item.code}`" class="parsing-mapping-card full">
|
||||
<div class="mapping-title"><strong>{{ t(`admin.shippingInventory.movementFields.${item.code}`) }}</strong><small><b v-if="item.required">{{ t('admin.shippingInventory.movementRequiredMark') }}</b><template v-if="item.required && item.is_identity"> · </template><b v-if="item.is_identity">{{ t('admin.shippingInventory.movementIdentityMark') }}</b></small></div>
|
||||
<label class="full"><span>{{ t(`admin.shippingInventory.${parsingLabelNs}.sourceHeader`) }}</span><select v-model="item.alias" class="select-field" :disabled="!structureAnalysis" :required="item.required"><option value="">{{ t('admin.shippingInventory.chooseSourceHeader') }}</option><option v-for="header in selectedAnalysisHeaders" :key="header" :value="header">{{ header }}</option></select></label>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="subsection full">{{ t('admin.shippingInventory.fieldMappings') }}</div>
|
||||
<div v-for="(item, index) in parsing.field_mappings" :key="`field-${index}`" class="parsing-mapping-card full">
|
||||
<div class="mapping-title"><strong>{{ t('admin.shippingInventory.mappingItem', { number: index + 1 }) }}</strong><button type="button" class="btn-danger btn-sm" @click="parsing.field_mappings.splice(index, 1)">{{ t('admin.delete') }}</button></div>
|
||||
<label><span>{{ t('admin.shippingInventory.inventoryField') }}</span><select v-model="item.inventory_field" class="select-field" required><option value="">{{ t('admin.shippingInventory.chooseInventoryField') }}</option><option v-for="field in activeInventoryFields" :key="field.id" :value="String(field.id)">{{ inventoryFieldOptionLabel(field) }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingInventory.sourceHeader') }}</span><select v-model="item.source_header" class="select-field" :disabled="!structureAnalysis" required><option value="">{{ t('admin.shippingInventory.chooseSourceHeader') }}</option><option v-for="header in selectedAnalysisHeaders" :key="header" :value="header">{{ header }}</option></select></label>
|
||||
<small v-if="item.inventory_field" class="mapping-help">{{ inventoryFieldDescription(item.inventory_field) }}</small>
|
||||
</div>
|
||||
<button type="button" class="btn-secondary btn-sm full" :disabled="!structureAnalysis" @click="addParsingFieldMapping">{{ t('admin.shippingInventory.addFieldMapping') }}</button>
|
||||
<div class="subsection full">{{ t('admin.shippingInventory.matchKeys') }}<small>{{ t('admin.shippingInventory.matchKeysHint') }}</small></div>
|
||||
<div v-for="(item, index) in parsing.match_keys" :key="`match-${index}`" class="parsing-mapping-card match-key-card full">
|
||||
<div class="mapping-title"><strong>{{ t('admin.shippingInventory.mappingItem', { number: index + 1 }) }}</strong><button type="button" class="btn-danger btn-sm" @click="parsing.match_keys.splice(index, 1)">{{ t('admin.delete') }}</button></div>
|
||||
<label><span>{{ t('admin.shippingInventory.orderField') }}</span><select v-model="item.order_field_id" class="select-field" required><option value="">{{ t('admin.shippingInventory.chooseOrderField') }}</option><option v-for="field in matchingOrderFields" :key="field.field_id" :value="field.field_id">{{ orderFieldOptionLabel(field) }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingInventory.inventoryField') }}</span><select v-model="item.inventory_field" class="select-field" required><option value="">{{ t('admin.shippingInventory.chooseInventoryField') }}</option><option v-for="field in mappedMatchingInventoryFields" :key="field.id" :value="String(field.id)">{{ inventoryFieldOptionLabel(field) }}</option></select></label>
|
||||
<small v-if="item.inventory_field" class="mapping-help">{{ inventoryFieldDescription(item.inventory_field) }}</small>
|
||||
</div>
|
||||
<button type="button" class="btn-secondary btn-sm full" :disabled="!canAddParsingMatchKey" @click="addParsingMatchKey">{{ t('admin.shippingInventory.addMatchKey') }}</button>
|
||||
<p v-if="!unusedMatchingInventoryFields.length || !unusedOrderMatchFields.length" class="match-key-tip full">{{ t('admin.shippingInventory.matchKeysComplete') }}</p>
|
||||
<p v-else-if="!structureAnalysis" class="match-key-tip full">{{ t('admin.shippingInventory.matchKeysAnalysisRequired') }}</p>
|
||||
</template>
|
||||
<div v-else class="form-tip full">{{ t('admin.shippingInventory.inventorySampleRequired') }}</div>
|
||||
<div class="subsection full">{{ t('admin.shippingInventory.fieldMappings') }}</div>
|
||||
<div v-for="(item, index) in parsing.field_mappings" :key="`field-${index}`" class="parsing-mapping-card full">
|
||||
<div class="mapping-title"><strong>{{ t('admin.shippingInventory.mappingItem', { number: index + 1 }) }}</strong><button type="button" class="btn-danger btn-sm" @click="parsing.field_mappings.splice(index, 1)">{{ t('admin.delete') }}</button></div>
|
||||
<label><span>{{ t('admin.shippingInventory.inventoryField') }}</span><select v-model="item.inventory_field" class="select-field" required><option value="">{{ t('admin.shippingInventory.chooseInventoryField') }}</option><option v-for="field in activeInventoryFields" :key="field.id" :value="String(field.id)">{{ inventoryFieldOptionLabel(field) }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingInventory.sourceHeader') }}</span><select v-model="item.source_header" class="select-field" :disabled="!structureAnalysis" required><option value="">{{ t('admin.shippingInventory.chooseSourceHeader') }}</option><option v-for="header in selectedAnalysisHeaders" :key="header" :value="header">{{ header }}</option></select></label>
|
||||
<small v-if="item.inventory_field" class="mapping-help">{{ inventoryFieldDescription(item.inventory_field) }}</small>
|
||||
</div>
|
||||
<button type="button" class="btn-secondary btn-sm full" :disabled="!structureAnalysis" @click="addParsingFieldMapping">{{ t('admin.shippingInventory.addFieldMapping') }}</button>
|
||||
<div class="subsection full">{{ t('admin.shippingInventory.matchKeys') }}<small>{{ t('admin.shippingInventory.matchKeysHint') }}</small></div>
|
||||
<div v-for="(item, index) in parsing.match_keys" :key="`match-${index}`" class="parsing-mapping-card match-key-card full">
|
||||
<div class="mapping-title"><strong>{{ t('admin.shippingInventory.mappingItem', { number: index + 1 }) }}</strong><button type="button" class="btn-danger btn-sm" @click="parsing.match_keys.splice(index, 1)">{{ t('admin.delete') }}</button></div>
|
||||
<label><span>{{ t('admin.shippingInventory.orderField') }}</span><select v-model="item.order_field_id" class="select-field" required><option value="">{{ t('admin.shippingInventory.chooseOrderField') }}</option><option v-for="field in matchingOrderFields" :key="field.field_id" :value="field.field_id">{{ orderFieldOptionLabel(field) }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingInventory.inventoryField') }}</span><select v-model="item.inventory_field" class="select-field" required><option value="">{{ t('admin.shippingInventory.chooseInventoryField') }}</option><option v-for="field in mappedMatchingInventoryFields" :key="field.id" :value="String(field.id)">{{ inventoryFieldOptionLabel(field) }}</option></select></label>
|
||||
<small v-if="item.inventory_field" class="mapping-help">{{ inventoryFieldDescription(item.inventory_field) }}</small>
|
||||
</div>
|
||||
<button type="button" class="btn-secondary btn-sm full" :disabled="!canAddParsingMatchKey" @click="addParsingMatchKey">{{ t('admin.shippingInventory.addMatchKey') }}</button>
|
||||
<p v-if="!unusedMatchingInventoryFields.length || !unusedOrderMatchFields.length" class="match-key-tip full">{{ t('admin.shippingInventory.matchKeysComplete') }}</p>
|
||||
<p v-else-if="!structureAnalysis" class="match-key-tip full">{{ t('admin.shippingInventory.matchKeysAnalysisRequired') }}</p>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
@@ -333,7 +355,7 @@
|
||||
<div class="switch-field"><span>{{ t('admin.shippingInventory.enabled') }}</span><button type="button" class="status-switch" :class="{ on: mapping.enabled }" role="switch" :aria-checked="mapping.enabled" @click="mapping.enabled = !mapping.enabled"><i></i><b>{{ mapping.enabled ? t('admin.shippingInventory.enabledState') : t('admin.shippingInventory.disabledState') }}</b></button></div>
|
||||
</template>
|
||||
|
||||
<section v-if="selectedId" class="readiness-card full" :class="{ ready: source.enabled }">
|
||||
<section v-if="activeTab === 'sources' && selectedId" class="readiness-card full" :class="{ ready: source.enabled }">
|
||||
<div class="readiness-inline">
|
||||
<template v-if="source.enabled">
|
||||
<span class="readiness-marker is-passed" aria-hidden="true">✓</span>
|
||||
@@ -423,7 +445,7 @@
|
||||
<header class="clone-template-header"><div><h3 id="bulk-parsing-binding-title">{{ t('admin.shippingInventory.bulkBindParsingProfile') }}</h3><p>{{ t('admin.shippingInventory.bulkBindParsingProfileHint') }}</p></div><button type="button" class="drawer-close" :aria-label="t('admin.close')" @click="closeBulkParsingBinding">×</button></header>
|
||||
<form class="clone-template-form" @submit.prevent="submitBulkParsingBinding">
|
||||
<label><span>{{ t('admin.shippingInventory.inventorySites') }}</span><select v-model="bulkBinding.sourceIds" class="select-field" multiple required><option v-for="item in sources.filter((row) => !row.enabled)" :key="String(item.id)" :value="Number(item.id)">{{ item.display_name || item.source_code }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingInventory.parsingProfiles') }}</span><select v-model.number="bulkBinding.profileId" class="select-field" required><option :value="0">{{ t('admin.shippingInventory.notConfigured') }}</option><option v-for="item in parsingProfiles.filter((row) => row.status === 'published')" :key="String(item.id)" :value="Number(item.id)">{{ item.display_name || item.profile_code }} V{{ item.version }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingInventory.parsingProfiles') }}</span><select v-model.number="bulkBinding.profileId" class="select-field" required><option :value="0">{{ t('admin.shippingInventory.notConfigured') }}</option><option v-for="item in parsingProfiles.filter((row) => row.status === 'published' && row.purpose !== 'movement')" :key="String(item.id)" :value="Number(item.id)">{{ item.display_name || item.profile_code }} V{{ item.version }}</option></select></label>
|
||||
<div class="clone-template-actions"><button type="button" class="btn-ghost btn-sm" :disabled="bulkBinding.saving" @click="closeBulkParsingBinding">{{ t('admin.cancel') }}</button><button type="submit" class="btn-primary" :disabled="bulkBinding.saving">{{ bulkBinding.saving ? t('admin.shippingInventory.saving') : t('admin.shippingInventory.bulkBindParsingProfile') }}</button></div>
|
||||
</form>
|
||||
</section>
|
||||
@@ -479,6 +501,7 @@ import {
|
||||
getShippingExcelTemplateLayout,
|
||||
createShippingInventoryStructureAnalysis,
|
||||
createShippingInventoryParsingDraftFromAnalysis,
|
||||
fetchMovementFields,
|
||||
previewShippingInventorySampleReplacement,
|
||||
createShippingParsingDraftFromTemporarySession,
|
||||
adoptShippingInventoryParsingProfile,
|
||||
@@ -512,6 +535,7 @@ import type { ShippingInventoryConfigurationTest, ShippingInventoryReadinessChec
|
||||
import { isConfigurationTestRunning, needsReadinessAction, readinessMarkerKind } from './shippingInventoryReadiness';
|
||||
import { normaliseInventoryReportPath } from './shippingInventorySourceForm';
|
||||
import { buildReceiptReportConfigPayload } from './receiptReportConfigForm';
|
||||
import { buildMovementFieldMapping } from './movementParsingProfileForm';
|
||||
|
||||
type TabKey = 'profiles' | 'parsing' | 'inventoryFields' | 'templates' | 'sources' | 'rules' | 'snapshots' | 'exports' | 'mappings';
|
||||
type Item = Record<string, any>;
|
||||
@@ -617,7 +641,13 @@ const successTextsInput = computed<string>({
|
||||
get: () => (profile.upload_config_json.success_texts || []).join('\n'),
|
||||
set: (value) => { profile.upload_config_json.success_texts = String(value || '').split(/\r?\n/).map((item) => item.trim()).filter(Boolean); },
|
||||
});
|
||||
const parsing = reactive({ profile_code: '', display_name: '', file_format: 'xlsx', sheet_name: '', header_row_index: 1, field_mappings: [] as ParsingFieldMapping[], match_keys: [] as ParsingMatchKey[] });
|
||||
const parsing = reactive({
|
||||
profile_code: '', display_name: '', file_format: 'xlsx', sheet_name: '', header_row_index: 1,
|
||||
purpose: 'inventory' as 'inventory' | 'movement',
|
||||
field_mappings: [] as ParsingFieldMapping[], match_keys: [] as ParsingMatchKey[],
|
||||
movement_mappings: [] as Array<{ code: string; alias: string; required: boolean; is_identity: boolean }>,
|
||||
});
|
||||
const movementFields = ref<Array<{ code: string; value_type: string; required: boolean; is_identity: boolean }>>([]);
|
||||
const inventoryField = reactive<InventoryFieldForm>({ display_name: '', description: '', value_type: 'text', usage_type: 'general', sort_order: 100, status: 'active' });
|
||||
const excelTemplate = reactive({ template_code: '', display_name: '', filename_pattern: '{business_no}.xlsx', mappings: [] as TemplateMapping[], file: null as File | null });
|
||||
const templateClone = reactive({ visible: false, template_code: '', display_name: '', saving: false });
|
||||
@@ -625,7 +655,7 @@ const bulkBinding = reactive({ visible: false, sourceIds: [] as number[], profil
|
||||
const batchValidation = reactive({ visible: false, sourceIds: [] as number[], query: '', statusFilter: 'all' as 'all' | 'processing' | 'completed' | 'completed_empty' | 'failed', saving: false, result: null as ShippingInventoryValidationBatch | null });
|
||||
let batchValidationTimer: number | null = null;
|
||||
const source = reactive({ source_code: '', display_name: '', connector_type: 'dbs', rpa_profile_id: 0, parsing_profile_id: 0, excel_template_id: 0, warehouse_resolution_mode: 'fixed', fixed_warehouse_id: '', snapshot_ttl_seconds: 86400, report_path_json: { program_group: '', program_label: '', report_group: 'Inventory', report_name: '' }, query_parameters_json: [] as Parameter[], enabled: false, activation: { ready: false, checks: [] as ShippingInventoryReadinessCheck[], missing_requirements: [] as string[] } as SourceActivation });
|
||||
const receiptConfig = reactive({ report_path_json: { program_group: '', program_label: '', report_group: 'Inbound', report_name: '' } as Record<string, string>, query_parameters_json: [] as Parameter[] });
|
||||
const receiptConfig = reactive({ report_path_json: { program_group: '', program_label: '', report_group: 'Inbound', report_name: '' } as Record<string, string>, query_parameters_json: [] as Parameter[], parsing_profile_id: null as number | null });
|
||||
const receiptConfigExists = ref(false);
|
||||
const receiptSectionTouched = ref(false);
|
||||
const receiptSectionOpen = ref(false);
|
||||
@@ -720,6 +750,8 @@ const ruleReadOnly = computed(() => ['published', 'retired'].includes(selectedRu
|
||||
const selectedTemplateStatus = computed(() => excelTemplates.value.find((item) => Number(item.id) === selectedId.value)?.status || 'draft');
|
||||
const selectedParsingStatus = computed(() => parsingProfiles.value.find((item) => Number(item.id) === selectedId.value)?.status || 'draft');
|
||||
const parsingReadOnly = computed(() => activeTab.value === 'parsing' && ['published', 'retired'].includes(selectedParsingStatus.value));
|
||||
/** 按规则用途切换弹窗标签命名空间:收料异动模式下不再出现"库存"措辞。 */
|
||||
const parsingLabelNs = computed(() => parsing.purpose === 'movement' ? 'movementParsing' : 'inventoryParsing');
|
||||
const inventoryFieldReadOnly = computed(() => activeTab.value === 'inventoryFields' && inventoryField.status !== 'active');
|
||||
const analysisCandidates = computed<Item[]>(() => structureAnalysis.value?.structure?.candidates || []);
|
||||
const analysisCandidatesForSheet = computed<Item[]>(() => analysisCandidates.value.filter((item) => String(item.sheet_name || '') === parsing.sheet_name));
|
||||
@@ -817,12 +849,13 @@ const filteredBatchValidationRuns = computed(() => {
|
||||
/** 加载服务端配置与运行审计投影,页面不保留第二份真相。 */
|
||||
async function load(): Promise<void> {
|
||||
try {
|
||||
const [[profileRows, sourceRows, ruleRows, mappingRows, snapshotRows, exportRows, parsingRows, templateRows], inventoryFieldRows, fieldCatalog, configurationCatalog, temporarySessions] = await Promise.all([
|
||||
getShippingInventoryConfig(), getShippingInventoryFields(), getShippingInventoryRoutingFields(), getShippingInventoryConfigurationCatalog(), listShippingTemporaryInventorySessions(),
|
||||
const [[profileRows, sourceRows, ruleRows, mappingRows, snapshotRows, exportRows, parsingRows, templateRows], inventoryFieldRows, fieldCatalog, configurationCatalog, temporarySessions, movementFieldRows] = await Promise.all([
|
||||
getShippingInventoryConfig(), getShippingInventoryFields(), getShippingInventoryRoutingFields(), getShippingInventoryConfigurationCatalog(), listShippingTemporaryInventorySessions(), fetchMovementFields(),
|
||||
]);
|
||||
profiles.value = profileRows as Item[]; sources.value = sourceRows as Item[]; rules.value = ruleRows as Item[];
|
||||
mappings.value = mappingRows as Item[]; snapshots.value = snapshotRows as Item[]; exports.value = exportRows as Item[];
|
||||
parsingProfiles.value = parsingRows as Item[];
|
||||
movementFields.value = movementFieldRows;
|
||||
inventoryFields.value = inventoryFieldRows as Item[];
|
||||
excelTemplates.value = templateRows as Item[];
|
||||
temporaryInventorySessions.value = temporarySessions as Item[];
|
||||
@@ -845,6 +878,7 @@ function resetReceiptConfig(connectorType: unknown): void {
|
||||
? { report_name: 'Inbound Details' }
|
||||
: { program_group: '', program_label: '', report_group: 'Inbound', report_name: '' },
|
||||
query_parameters_json: [],
|
||||
parsing_profile_id: null,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -864,6 +898,7 @@ async function loadReceiptConfig(sourceId: number, connectorType: unknown): Prom
|
||||
? { report_name: 'Inbound Details' }
|
||||
: { program_group: '', program_label: '', report_group: 'Inbound', report_name: '', ...((config.report_path_json || {}) as Record<string, string>) },
|
||||
query_parameters_json: Array.isArray(config.query_parameters_json) ? config.query_parameters_json.map((parameter) => ({ ...parameter })) : [],
|
||||
parsing_profile_id: config.parsing_profile_id ? Number(config.parsing_profile_id) : null,
|
||||
});
|
||||
receiptConfigExists.value = true;
|
||||
receiptSectionOpen.value = true;
|
||||
@@ -924,7 +959,7 @@ function selectInventoryMappingTab(tab: 'parsing' | 'inventoryFields'): void {
|
||||
function createNew(): void {
|
||||
selectedId.value = null;
|
||||
if (activeTab.value === 'profiles') Object.assign(profile, { profile_code: '', display_name: '', connector_type: 'dbs', login_url: '', username: '', password: '', login_config_json: { auth_mode: 'password' }, enabled: true, upload_config_json: defaultUploadConfig('dbs') });
|
||||
if (activeTab.value === 'parsing') { Object.assign(parsing, { profile_code: '', display_name: '', file_format: 'xlsx', sheet_name: '', header_row_index: 1, field_mappings: [], match_keys: [] }); structureAnalysis.value = null; pendingSampleReplacement.value = null; sampleReplacementConfirmed.value = false; selectedTemporaryInventorySession.value = ''; }
|
||||
if (activeTab.value === 'parsing') { Object.assign(parsing, { profile_code: '', display_name: '', file_format: 'xlsx', sheet_name: '', header_row_index: 1, purpose: 'inventory', field_mappings: [], match_keys: [], movement_mappings: [] }); structureAnalysis.value = null; pendingSampleReplacement.value = null; sampleReplacementConfirmed.value = false; selectedTemporaryInventorySession.value = ''; }
|
||||
if (activeTab.value === 'inventoryFields') Object.assign(inventoryField, { display_name: '', description: '', value_type: 'text', usage_type: 'general', sort_order: 100, status: 'active' });
|
||||
if (activeTab.value === 'templates') {
|
||||
Object.assign(excelTemplate, { template_code: '', display_name: '', filename_pattern: '{business_no}.xlsx', mappings: [], file: null });
|
||||
@@ -953,8 +988,10 @@ function selectItem(item: Item): void {
|
||||
if (activeTab.value === 'parsing') Object.assign(parsing, {
|
||||
profile_code: item.profile_code, display_name: item.display_name, file_format: item.file_format,
|
||||
sheet_name: item.definition?.sheet_name || '', header_row_index: item.definition?.header_row_index ?? 0,
|
||||
purpose: item.purpose === 'movement' ? 'movement' : 'inventory',
|
||||
field_mappings: Object.entries(item.definition?.field_mapping || {}).map(([inventory_field, source_header]) => ({ inventory_field, source_header: String(source_header) })),
|
||||
match_keys: (item.definition?.match_keys || []).map((entry: Record<string, unknown>) => ({ order_field_id: String(entry.order_field_id || ''), inventory_field: String(entry.inventory_field_id || entry.inventory_field || '') })),
|
||||
movement_mappings: buildMovementMappings(item),
|
||||
});
|
||||
if (activeTab.value === 'parsing') {
|
||||
// 草稿恢复保存的最小化样本证据,而不是要求管理员再次上传原始库存文件。
|
||||
@@ -1120,7 +1157,13 @@ async function saveCurrent(): Promise<void> {
|
||||
try {
|
||||
if (activeTab.value === 'profiles') await saveShippingRpaProfile({ ...profile, display_name: profile.display_name || profile.profile_code, upload_config_json: profile.upload_config_json }, selectedId.value || undefined);
|
||||
if (activeTab.value === 'parsing') {
|
||||
const payload = {
|
||||
const payload = parsing.purpose === 'movement' ? {
|
||||
profile_code: parsing.profile_code, display_name: parsing.display_name || parsing.profile_code, file_format: parsing.file_format,
|
||||
purpose: 'movement', sheet_name: parsing.sheet_name || null, header_row_index: parsing.header_row_index,
|
||||
// 标准异动字段契约:code 由只读目录下发,这里只裁剪/校验别名映射。
|
||||
field_mapping: buildMovementFieldMapping(parsing.movement_mappings),
|
||||
match_keys: [] as string[],
|
||||
} : {
|
||||
profile_code: parsing.profile_code, display_name: parsing.display_name || parsing.profile_code, file_format: parsing.file_format,
|
||||
sheet_name: parsing.sheet_name || null, header_row_index: parsing.header_row_index,
|
||||
field_mapping: Object.fromEntries(parsing.field_mappings.map((item) => [item.inventory_field, item.source_header])),
|
||||
@@ -1364,6 +1407,31 @@ async function refreshSelectedSource(): Promise<void> {
|
||||
|
||||
/** 新增一行结构化 DBS 查询参数,避免要求管理员编辑 JSON。 */
|
||||
function addParameter(): void { source.query_parameters_json.push({ name: '', mode: 'single', values: [], required: false, select_all: false }); }
|
||||
/** 把已保存 movement 规则的定义与只读字段目录合并为可编辑映射行;目录缺失时退化为纯 code 行。 */
|
||||
function buildMovementMappings(item: Item) {
|
||||
const saved = (item.definition?.field_mapping || {}) as Record<string, unknown>;
|
||||
const catalog = movementFields.value.length
|
||||
? movementFields.value
|
||||
: Object.keys(saved).map((code) => ({ code, required: false, is_identity: false }));
|
||||
return catalog.map((field) => ({
|
||||
code: field.code, alias: String(saved[field.code] || ''),
|
||||
required: Boolean(field.required), is_identity: Boolean(field.is_identity),
|
||||
}));
|
||||
}
|
||||
|
||||
/** 切换用途时初始化对应映射行:movement 预填标准字段目录,inventory 清空自由映射。 */
|
||||
function resetMappingRowsForPurpose(): void {
|
||||
if (parsing.purpose === 'movement') {
|
||||
parsing.movement_mappings = movementFields.value.map((field) => ({
|
||||
code: field.code, alias: '', required: Boolean(field.required), is_identity: Boolean(field.is_identity),
|
||||
}));
|
||||
parsing.field_mappings = [];
|
||||
parsing.match_keys = [];
|
||||
} else {
|
||||
parsing.movement_mappings = [];
|
||||
}
|
||||
}
|
||||
|
||||
function addParsingFieldMapping(): void {
|
||||
if (!structureAnalysis.value) {
|
||||
message.warning(t('admin.shippingInventory.inventorySampleRequired'));
|
||||
@@ -1531,6 +1599,8 @@ function rowTitle(item: Item): string { return String(item.display_name || item.
|
||||
function rowMeta(item: Item): string {
|
||||
if (activeTab.value === 'inventoryFields') return `${t(`admin.shippingInventory.inventoryFieldType.${item.value_type || 'text'}`)} · ${t(`admin.shippingInventory.inventoryFieldPurposeOption.${item.usage_type || 'general'}`)}`;
|
||||
if (item.connector_type) return String(item.display_name ? t(`admin.shippingInventory.platform.${item.connector_type}`) : item.connector_type);
|
||||
// 解析规则列表带出用途徽标文案,库存/异动两种规则在列表一眼可分。
|
||||
if (activeTab.value === 'parsing') return `${t(`admin.shippingInventory.parsingPurpose.${item.purpose === 'movement' ? 'movement' : 'inventory'}`)} · V${item.version ?? '-'}`;
|
||||
return String(item.source_code || item.profile_code || item.rule_code || item.external_warehouse_code || '-');
|
||||
}
|
||||
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* features/admin/modules/shipping-inventory/movementParsingProfileForm.spec.ts
|
||||
* 用途:覆盖收料异动解析规则映射的组装边界。
|
||||
* 依赖:movementParsingProfileForm、vitest。
|
||||
* 逻辑:标准异动字段是只读领域契约——映射键必须是契约 code,必填字段缺失要阻断保存。
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { buildMovementFieldMapping, REQUIRED_MOVEMENT_FIELD_CODES } from './movementParsingProfileForm';
|
||||
|
||||
describe('movementParsingProfileForm', () => {
|
||||
it('exports the fixed required movement field codes', () => {
|
||||
// 关键断言:必填集是后端契约的镜像,变更必须显式同步。
|
||||
expect(REQUIRED_MOVEMENT_FIELD_CODES).toEqual(['doc_no', 'material_code', 'quantity', 'movement_date']);
|
||||
});
|
||||
|
||||
it('builds code-keyed mapping, trims aliases and drops empty optional rows', () => {
|
||||
const mapping = buildMovementFieldMapping([
|
||||
{ code: 'doc_no', alias: ' 单据编号 ', required: true, is_identity: true },
|
||||
{ code: 'line_no', alias: '', required: false, is_identity: false },
|
||||
{ code: 'material_code', alias: '料号', required: true, is_identity: true },
|
||||
{ code: 'quantity', alias: '数量', required: true, is_identity: false },
|
||||
{ code: 'movement_date', alias: '异动日期', required: true, is_identity: true },
|
||||
]);
|
||||
expect(mapping).toEqual({ doc_no: '单据编号', material_code: '料号', quantity: '数量', movement_date: '异动日期' });
|
||||
});
|
||||
|
||||
it('rejects saving when a required movement field has no alias', () => {
|
||||
// 关键断言:缺必填映射必须抛错并点名缺失字段,不允许带着残缺契约提交。
|
||||
expect(() => buildMovementFieldMapping([
|
||||
{ code: 'doc_no', alias: '单据编号', required: true, is_identity: true },
|
||||
{ code: 'material_code', alias: '', required: true, is_identity: true },
|
||||
{ code: 'quantity', alias: '数量', required: true, is_identity: false },
|
||||
{ code: 'movement_date', alias: '', required: true, is_identity: true },
|
||||
])).toThrowError(/material_code, movement_date/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* features/admin/modules/shipping-inventory/movementParsingProfileForm.ts
|
||||
* 用途:组装收料异动解析规则(purpose='movement')的标准字段映射载荷。
|
||||
* 依赖:无外部依赖。
|
||||
* 逻辑:标准异动字段目录由后端 /admin/shipping-notice/movement-fields 只读下发,
|
||||
* 本模块只做裁剪与校验——映射键是契约 code,必填字段缺失阻断保存;
|
||||
* 不提供任何自定义字段的入口(业务领域字段不允许用户自定义)。
|
||||
*/
|
||||
|
||||
/** 与后端 movement_contract.MOVEMENT_FIELDS 的 required 标记保持一致,变更必须双向同步。 */
|
||||
export const REQUIRED_MOVEMENT_FIELD_CODES = ['doc_no', 'material_code', 'quantity', 'movement_date'] as const;
|
||||
|
||||
/** 标准异动字段映射行(目录行 + 管理员选择的报表表头别名)。 */
|
||||
export type MovementFieldMapping = {
|
||||
code: string;
|
||||
alias: string;
|
||||
required: boolean;
|
||||
is_identity: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* 构造异动解析定义的 field_mapping({契约code: 报表表头别名})。
|
||||
* 核心逻辑:别名 trim 后为空的行视为未映射——可选字段直接剔除,
|
||||
* 必填字段缺失则抛错点名,禁止带着残缺契约提交到后端。
|
||||
* @param mappings - 异动字段映射行(来自只读字段目录 + 用户选择)。
|
||||
* @returns 可直接放入保存载荷的 field_mapping 对象。
|
||||
*/
|
||||
export function buildMovementFieldMapping(mappings: MovementFieldMapping[]): Record<string, string> {
|
||||
const mapping: Record<string, string> = {};
|
||||
for (const item of mappings || []) {
|
||||
const alias = String(item.alias || '').trim();
|
||||
if (!alias) continue;
|
||||
mapping[String(item.code).trim()] = alias;
|
||||
}
|
||||
const missing = REQUIRED_MOVEMENT_FIELD_CODES.filter((code) => !mapping[code]);
|
||||
if (missing.length) throw new Error(`missing required movement fields: ${missing.join(', ')}`);
|
||||
return mapping;
|
||||
}
|
||||
+18
@@ -31,10 +31,28 @@ describe('receiptReportConfigForm', () => {
|
||||
{ name: 'Warehouse', mode: 'multi_text', values: ['AWSDU', 'AWSDU-02'], required: false, select_all: false },
|
||||
{ name: 'Owner', mode: 'single', values: ['AWS'], required: false, select_all: false },
|
||||
],
|
||||
// 关键断言:载荷契约固定三元——未绑定时异动解析绑定显式为 null,不缺键。
|
||||
parsing_profile_id: null,
|
||||
});
|
||||
expect(payload).not.toHaveProperty('source_code');
|
||||
expect(payload).not.toHaveProperty('snapshot_ttl_seconds');
|
||||
expect(payload).not.toHaveProperty('enabled');
|
||||
expect(payload).not.toHaveProperty('warehouse_ids_json');
|
||||
});
|
||||
|
||||
it('carries movement profile binding and normalizes absent id to explicit unbind', () => {
|
||||
// 关键断言:异动解析绑定随配置提交;未绑定时必须显式提交 null(解绑),不能省略键。
|
||||
const bound = buildReceiptReportConfigPayload({
|
||||
report_path_json: { report_name: 'Inbound Details' },
|
||||
query_parameters_json: [],
|
||||
parsing_profile_id: 7,
|
||||
});
|
||||
expect(bound.parsing_profile_id).toBe(7);
|
||||
|
||||
const unbound = buildReceiptReportConfigPayload({
|
||||
report_path_json: { report_name: 'Inbound Details' },
|
||||
query_parameters_json: [],
|
||||
});
|
||||
expect(unbound.parsing_profile_id).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -9,11 +9,14 @@
|
||||
export type ReceiptReportConfigInput = {
|
||||
report_path_json: Record<string, unknown>;
|
||||
query_parameters_json: Array<Record<string, unknown>>;
|
||||
/** 收料异动解析规则绑定;0/undefined 视为未绑定并归一为 null(显式解绑)。 */
|
||||
parsing_profile_id?: number | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 构造独立收料配置保存载荷。
|
||||
* 核心逻辑:白名单复制可配置业务字段,不允许调用方把库存源、Profile 或启停字段带入收料 API。
|
||||
* 核心逻辑:白名单复制可配置业务字段,不允许调用方把库存源、Profile 或启停字段带入收料 API;
|
||||
* 异动解析绑定随配置一并提交(null=解绑)。
|
||||
* @param input - 抽屉中的收料配置表单状态。
|
||||
* @returns 仅包含收料配置 API 支持字段的深拷贝载荷。
|
||||
*/
|
||||
@@ -21,5 +24,6 @@ export function buildReceiptReportConfigPayload(input: ReceiptReportConfigInput)
|
||||
return {
|
||||
report_path_json: { ...(input.report_path_json || {}) },
|
||||
query_parameters_json: (input.query_parameters_json || []).map((item) => ({ ...item })),
|
||||
parsing_profile_id: input.parsing_profile_id ? Number(input.parsing_profile_id) : null,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user