@@ -14,6 +14,7 @@ import { usePageCache } from './pageCache';
import { useDelayedBusy , useDelayedIndicator } from './useDelayedBusy' ;
import { useVisiblePolling } from './useVisiblePolling' ;
import { runImportPollFollowup } from './importLifecycleGuards' ;
import { configureSourceBatch } from './sourceBatchConfigure' ;
import './no-code-data-workflow.css' ;
type Row = Record < string , unknown > ;
@@ -43,28 +44,28 @@ function WorkflowOperationFeedback({ operation, error, busy, onResume }: { opera
const status = String ( operation ? . status || '' ) . toUpperCase ( ) ;
const errors = Array . isArray ( operation ? . errors ) ? operation . errors . map ( item = > item . message ) . filter ( Boolean ) : [ ] ;
return < section className = "nc-operation-status panel" >
{ error && < Alert showIcon type = "error" message = { status === 'FAILED' ? '操作未完成' : '进度读取失败' } description = { [ . . . errors , error ] . filter ( Boolean ) . join ( '; ' ) } action = { operation ? . operationId ? < Button size = "small" onClick = { onResume } > 重 试 读 取 进 度 < / Button > : undefined } / > }
{ error && < Alert showIcon type = "error" message = { status === 'FAILED' || ! operation ? '操作未完成' : '进度读取失败' } description = { [ . . . new Set ( [ . . . errors , error ] . filter ( Boolean ) ) ] . join ( '; ' ) } action = { operation ? . operationId ? < Button size = "small" onClick = { onResume } > 重 试 读 取 进 度 < / Button > : undefined } / > }
< div > < strong > { workflowStageLabel [ String ( operation ? . stage || operation ? . status ) ] || ( busy ? '正在处理' : status === 'COMPLETED' ? '报表已更新' : '操作状态' ) } < / strong > < / div >
< Progress percent = { busy ? undefined : status === 'COMPLETED' ? 100 : 0 } status = { status === 'FAILED' ? 'exception' : status === 'COMPLETED' ? 'success' : 'active' } / >
< / section > ;
}
export type PendingSourceDeletion = { ids : string [ ] ; releaseId : string | null } ;
type SourceDraft = { id : string ; file : File ; workbook : WorkbookPreview ; stage : DataStage ; year : number ; month : number ; sheetName : string ; headerRow : number ; fieldMap : Record < string , string > ; mode : 'AD D' | 'REPLACE' ; targetId : string ; scopeCode : string } ;
type SourceDraft = { id : string ; file : File ; workbook : WorkbookPreview ; stage : DataStage ; year : number ; month : number ; sheetName : string ; headerRow : number ; fieldMap : Record < string , string > ; mode : 'APPEN D' | 'REPLACE' ; fileId : string ; targetId : string ; scopeCode : string } ;
type WizardFileDraft = { id : string ; file : File ; workbook : WorkbookPreview ; sheetName : string ; headerRow : number ; fieldMap : Record < string , string > ; fileId : string } ;
function SimplifiedDataWorkflow ( { options , workflowStatus , pendingDeletion , onDeleted , onBusyChange , onUnauthorized , onRefresh } : { options : SourceUploadOptions ; workflowStatus : DataWorkflowStatus ; pendingDeletion : PendingSourceDeletion ; onDeleted : ( ids : string [ ] ) = > void ; onBusyChange : ( busy : boolean ) = > void ; onUnauthorized : ( error : unknown ) = > boolean ; onRefresh : ( ) = > void } ) {
function SimplifiedDataWorkflow ( { options , workflowStatus , pendingDeletion , onBusyChange , onUnauthorized , onRefresh } : { options : SourceUploadOptions ; workflowStatus : DataWorkflowStatus ; pendingDeletion : PendingSourceDeletion ; onBusyChange : ( busy : boolean ) = > void ; onUnauthorized : ( error : unknown ) = > boolean ; onRefresh : ( ) = > void } ) {
const confirmDelete = useDeleteConfirmation ( ) ;
const { message } = App . useApp ( ) ;
const input = useRef < HTMLInputElement > ( null ) ;
const configured = useRef ( new Map < string , { signature : string ; sourceId : string } > ( ) ) ;
const consumed = useRef ( new Set < string > ( ) ) ;
const [ drafts , setDrafts ] = useState < SourceDraft [ ] > ( [ ] ) ;
const [ activeId , setActiveId ] = useState ( '' ) ;
const [ reading , setReading ] = useState < { done : number ; total : number } | null > ( null ) ;
const [ busy , setBusy ] = useState ( false ) ; const [ error , setError ] = useState ( '' ) ;
const actionLock = useRef ( false ) ;
const uploadOperation = useDataWorkflowOperation ( 'source-import' , ( ) = > { setDrafts ( [ ] ) ; setActiveId ( '' ) ; configured . current . clear ( ) ; consumed . current . clear ( ) ; onRefresh ( ) ; message . success ( '所选来源已统一导入,报表已更新' ) ; } ) ;
const recalcOperation = useDataWorkflowOperation ( 'recalculate' , value = > { if ( Array . isArray ( value . sourceIds ) ) onDeleted ( value . sourceIds . map ( String ) ) ; onRefresh ( ) ; message . success ( '报表已更新' ) ; } ) ;
const uploadOperation = useDataWorkflowOperation ( 'source-import' , ( ) = > { setDrafts ( [ ] ) ; setActiveId ( '' ) ; configured . current . clear ( ) ; onRefresh ( ) ; message . success ( '所选来源已统一导入,报表已更新' ) ; } ) ;
const recalcOperation = useDataWorkflowOperation ( 'recalculate' , ( ) = > { onRefresh ( ) ; message . success ( '报表已更新' ) ; } ) ;
const active = drafts . find ( item = > item . id === activeId ) || drafts [ 0 ] ;
const workbook = active ? . workbook || null ;
const stage = active ? . stage || 'black' ; const year = active ? . year || new Date ( ) . getFullYear ( ) ; const month = active ? . month || 1 ;
@@ -72,19 +73,28 @@ function SimplifiedDataWorkflow({ options, workflowStatus, pendingDeletion, onDe
const mode = active ? . mode || 'ADD' ; const targetId = active ? . targetId || '' ; const scopeCode = active ? . scopeCode || options . scopes [ 0 ] || 'ALL' ;
const patch = ( values : Partial < SourceDraft > ) = > { if ( active ) setDrafts ( previous = > previous . map ( item = > item . id === active . id ? { . . . item , . . . values } : item ) ) ; } ;
const setWorkbook = ( value : WorkbookPreview ) = > patch ( { workbook : value } ) ;
const setStage = ( value : DataStage ) = > patch ( { stage : value } ) ; const setYear = ( value : number ) = > patch ( { year : value } ) ; const setMonth = ( value : number ) = > patch ( { month : value } ) ;
const setStage = ( value : DataStage ) = > patch ( { stage : value , targetId : '' } ) ; const setYear = ( value : number ) = > patch ( { year : value , targetId : '' } ) ; const setMonth = ( value : number ) = > patch ( { month : value , targetId : '' } ) ;
const setSheetName = ( value : string ) = > patch ( { sheetName : value } ) ; const setHeaderRow = ( value : number ) = > patch ( { headerRow : value } ) ;
const setFieldMap = ( value : Record < string , string > ) = > patch ( { fieldMap : value } ) ; const setMode = ( value : 'AD D' | 'REPLACE' ) = > patch ( { mode : value } ) ;
const setTargetId = ( value : string ) = > patch ( { targetId : value } ) ; const setScopeCode = ( value : string ) = > patch ( { scopeCode : value } ) ;
const setFieldMap = ( value : Record < string , string > ) = > patch ( { fieldMap : value } ) ; const setMode = ( value : 'APPEN D' | 'REPLACE' ) = > patch ( { mode : value , targetId : '' } ) ;
const setTargetId = ( value : string ) = > patch ( { targetId : value } ) ; const setScopeCode = ( value : string ) = > patch ( { scopeCode : value , targetId : '' } ) ;
const fields = options . fields [ stage ] || [ ] ; const headers = workbook ? . preview . headers || [ ] ;
const missing = fields . filter ( field = > field . required && ! fieldMap [ field . name ] ) ; const duplicate = Object . values ( fieldMap ) . length !== new Set ( Object . values ( fieldMap ) ) . size ;
const importBusy = busy || uploadOperation . busy || recalcOperation . busy ;
useEffect ( ( ) = > { onBusyChange ( importBusy ) ; return ( ) = > onBusyChange ( false ) ; } , [ importBusy , onBusyChange ] ) ;
const hasImportCapability = workflowStatus . capabilities ? . canImport !== false ;
const draftReady = ( item : SourceDraft ) = > ( options . fields [ item . stage ] || [ ] ) . filter ( field = > field . required ) . every ( field = > item . fieldMap [ field . name ] ) && Object . values ( item . fieldMap ) . length === new Set ( Object . values ( item . fieldMap ) ) . size && ( item . mode ! == 'REPLACE' || options . targets . some ( target = > target . documentId === item . targetId ) ) ;
const slots = drafts . map ( item = > ` ${ item . year } : ${ item . month } : ${ item . stage } : ${ item . scopeCode } ` ) ;
const duplicateSlots = new Set ( slots ) . size !== slots . length ;
const canImport = hasImportCapability && drafts . length > 0 && drafts . every ( draftReady ) && ! duplicateSlots && ! pendingDeletion . ids . length ;
const targetFor = ( item : SourceDraft ) = > options . targets . find ( target = > target . documentId === item . targetId && target . year === item . year && target . month = == item . month && target . stage === item . stage && target . scopeCode === item . scopeCode ) ;
const hasMainSource = ( item : Pick < SourceDraft , 'year' | 'month' | 'stage' | 'scopeCode' > ) = > options . targets . some ( target = > ! target . fileId && target . sourceMode !== 'MONTHLY_SNAPSHOT' && target . year === item . year && target . month === item . month && target . stage === item . stage && target . scopeCode === item . scopeCode ) ;
const draftReady = ( item : SourceDraft ) = > {
const target = targetFor ( item ) ;
const matched = ( options . fields [ item . stage ] || [ ] ) . filter ( field = > field . required ) . every ( field = > item . fieldMap [ field . name ] ) && Object . values ( item . fieldMap ) . length === new Set ( Object . values ( item . fieldMap ) ) . size ;
return matched && ( item . mode === 'APPEND' ? ! hasMainSource ( item ) : Boolean ( target ) && ( target ? . sourceMode !== 'APPEND_SNAPSHOT' || Boolean ( target . fileId ) ) ) ;
} ;
const replacementTargets = active ? options . targets . filter ( item = > item . year === year && item . month === month && item . stage === stage && item . scopeCode === scopeCode ) : [ ] ;
const activeHasMainSource = active ? hasMainSource ( active ) : false ;
const configuredActive = Boolean ( active && configured . current . has ( active . id ) ) ;
const configuredReplacement = configuredActive && mode === 'REPLACE' ;
const repeatedReplacement = drafts . filter ( item = > item . mode === 'REPLACE' && item . targetId ) . length !== new Set ( drafts . filter ( item = > item . mode === 'REPLACE' && item . targetId ) . map ( item = > item . targetId ) ) . size ;
const canImport = hasImportCapability && drafts . length > 0 && drafts . every ( draftReady ) && ! repeatedReplacement && ! pendingDeletion . ids . length ;
const reportError = ( value : unknown ) = > { if ( ! onUnauthorized ( value ) ) setError ( failure ( value ) ) ; } ;
const removeDraft = ( id : string ) = > confirmDelete ( { title : ` 移除文件“ ${ drafts . find ( item = > item . id === id ) ? . workbook . sourceFile || "选中的文件" } ”? ` , description : "仅从本次导入列表移除,此文件的字段对应设置也将移除。电脑上的原文件及已接收来源保留。" , confirmText : "确认移除" , onConfirm : ( ) = > { setDrafts ( previous = > previous . filter ( item = > item . id !== id ) ) ; configured . current . delete ( id ) ; } } ) ;
const readFiles = async ( files : File [ ] ) = > {
@@ -102,7 +112,7 @@ function SimplifiedDataWorkflow({ options, workflowStatus, pendingDeletion, onDe
const { workbook : result , stage : detected } = await detectSourceWorkbook ( uploaded , options . fields , api . sourceWorkbookPreview ) ;
const nextMonth = Number ( file . name . match ( /(?:^|\D)(0?[1-9]|1[0-2])月/ ) ? . [ 1 ] || new Date ( ) . getMonth ( ) + 1 ) ;
const nextYear = Number ( file . name . match ( /(20\d{2})年/ ) ? . [ 1 ] || new Date ( ) . getFullYear ( ) ) ;
return { id : crypto.randomUUID ( ) , file , workbook : result , stage : detected , year : nextYear , month : nextMonth , sheetName : result.preview.sheetName , headerRow : result.preview.headerRow , fieldMap : matchFields ( options . fields [ detected ] || [ ] , result . preview . headers ) , mode : 'AD D' as const , targetId : '' , scopeCode : options.scopes [ 0 ] || 'ALL' } ;
return { id : crypto.randomUUID ( ) , file , workbook : result , stage : detected , year : nextYear , month : nextMonth , sheetName : result.preview.sheetName , headerRow : result.preview.headerRow , fieldMap : matchFields ( options . fields [ detected ] || [ ] , result . preview . headers ) , mode : 'APPEN D' as const , fileId : crypto.randomUUID ( ) , targetId : '' , scopeCode : options.scopes [ 0 ] || 'ALL' } ;
} catch ( value ) { if ( ! onUnauthorized ( value ) ) failures . push ( ` ${ file . name } : ${ failure ( value ) } ` ) ; return null ; }
} ) ) ;
const ready = results . filter ( item = > item !== null ) ;
@@ -124,58 +134,50 @@ function SimplifiedDataWorkflow({ options, workflowStatus, pendingDeletion, onDe
const importAndUpdate = async ( ) = > {
if ( ! canImport || importBusy || actionLock . current ) return ; actionLock . current = true ; setBusy ( true ) ; setError ( '' ) ;
try {
const sourceIds : string [ ] = [ ] ;
for ( const draft of drafts ) {
const target = options . targets . find ( item = > item . documentId === draft . targetId ) ;
const body = { stage : draft.stage , year : draft.year , month : draft.month , sheetName : draft.sheetName , headerRow : draft.headerRow , fieldMap : draft.fieldMap , mode : draft.mode , expectedCurrentReleaseId : workflowStatus.currentReleaseId ? ? options . currentReleaseId , . . . ( draft . mode === 'REPLACE' && target ? { targetDocumentId : target.documentId , targetRevisionId : target.revisionId } : { } ) , reason : '批量导入来源数据' , scopeCode : draft.scopeCode } ;
const signature = JSON . stringify ( body ) ; const prior = configured . current . get ( draft . id ) ;
if ( prior ? . signature === signature ) { sourceIds . push ( prior . sourceId ) ; continue ; }
let uploadId = draft . workbook . uploadId ;
if ( consumed . current . has ( uploadId ) ) uploadId = ( await api . previewSourceWorkbook ( draft . file ) ) . uploadId ;
const result = await api . configureSourceWorkbook ( { . . . body , uploadId } ) ;
consumed . current . add ( uploadId ) ; configured . current . set ( draft . id , { signature , sourceId : result.source.id } ) ; sourceIds . push ( result . source . id ) ;
}
const items = drafts . map ( draft = > {
const target = targetFor ( draft ) ;
return { id : draft.id , body : { uploadId : draft.workbook.uploadId , stage : draft.stage , year : draft.year , month : draft.month , sheetName : draft.sheetName , headerRow : draft.headerRow , fieldMap : draft.fieldMap , mode : draft.mode , . . . ( draft . mode === 'APPEND' ? { fileId : draft.fileId } : target ? . fileId ? { fileId : target.fileId } : { } ) , expectedCurrentReleaseId : workflowStatus.currentReleaseId ? ? options . currentReleaseId , . . . ( draft . mode === 'REPLACE' && target ? { targetDocumentId : target.documentId , targetRevisionId : target.revisionId } : { } ) , reason : draft.mode === 'APPEND' ? '按独立批次追加,不覆盖旧文件' : '替换所选来源文件' , scopeCode : draft.scopeCode } } ;
} ) ;
const sourceIds = await configureSourceBatch ( items , configured . current , body = > api . configureSourceWorkbook ( body ) ) ;
await uploadOperation . start ( ( ) = > api . importDataWorkflow ( { sourceIds } ) ) ;
} catch ( value ) { reportError ( value ) ; } finally { actionLock . current = false ; setBusy ( false ) ; }
} ;
const performRecalculation = async ( ) = > {
if ( actionLock . current ) return ; actionLock . current = true ;
if ( actionLock . current || pendingDeletion . ids . length ) return ; actionLock . current = true ;
setError ( '' ) ;
try { await recalcOperation . start ( ( ) = > pendingDeletion . ids . length ? api . deleteDataWorkflowSources ( { sourceIds : pendingDeletion.ids , expectedCurrentReleaseId : pendingDeletion.releaseId } ) : api . recalculateDataWorkflow ( ) ) ; }
try { await recalcOperation . start ( ( ) = > api . recalculateDataWorkflow ( ) ) ; }
catch ( value ) { reportError ( value ) ; }
finally { actionLock . current = false ; }
} ;
const recalculate = ( ) = > {
if ( actionLock . current ) return ;
if ( ! pendingDeletion . ids . length ) return performRecalculation ( ) ;
confirmDelete ( { title : ` 删除 ${ pendingDeletion . ids . length } 个来源并更新报表? ` , description : < > < p > 将 从 当 前 查 询 结 果 移 除 以 下 来 源 并 更 新 报 表 , 原 文 件 和 处 理 记 录 保 留 。 < / p > < ul > { pendingDeletion . ids . slice ( 0 , 10 ) . map ( ( id , index ) = > < li key = { id } > { options . targets . find ( item = > item . documentId === id ) ? . sourceFile || ` 第 ${ index + 1 } 个待删除来源 ` } < / li > ) } < / ul > { pendingDeletion . ids . length > 10 && < p > 另 有 { pendingDeletion . ids . length - 10 } 个 待 删 除 来 源 。 < / p > } < / > , confirmText : '确认删除并更新' , onConfirm :performRecalculation } ) ;
} ;
return < div className = "nc-simplified-intake" >
< section className = "panel nc-simple-upload-panel" >
< div className = "nc-simple-upload-heading" > < div > < span className = "nc-eyebrow" > 测 试 数 据 维 护 < / span > < h2 > 导 入 来 源 并 更 新 报 表 < / h2 > < p > 支 持 一 次 选 择 多 个 Excel 文 件 , 分 别 核 对 年 月 与 阶 段 后 统 一 导 入 。 < / p > < / div > < div className = "nc-simple-upload-actions" > { workflowStatus . capabilities ? . canRecalculate !== false && < Button icon = { < ReloadOutlined / > } disabled = { importBusy } loading = { recalcOperation . busy } onClick = { ( ) = > void recalculate ( ) } > { pendingDeletion . ids . length ? ` 更新报表( ${ pendingDeletion . ids . length } 项删除) ` : '更新报表' } < / Button > } < / div > < / div >
< div className = "nc-simple-upload-heading" > < div > < span className = "nc-eyebrow" > 测 试 数 据 维 护 < / span > < h2 > 导 入 来 源 并 更 新 报 表 < / h2 > < p > 同 一 月 份 可 分 批 添 加 多 个 文 件 ; 相 同 文 件 内 容 不 会 重 复 计 入 。 < / p > < / div > < div className = "nc-simple-upload-actions" > { workflowStatus . capabilities ? . canRecalculate !== false && < Button icon = { < ReloadOutlined / > } disabled = { importBusy || pendingDeletion . ids . length > 0 } loading = { recalcOperation . busy } onClick = { ( ) = > void performRecalculation ( ) } > 更 新 报 表 < / Button > } < / div > < / div >
{ ! hasImportCapability && < Alert showIcon type = "info" message = "当前账号没有导入权限" description = "可查看来源;导入和更新报表需要发布权限。" / > }
{ error && < Alert showIcon type = "error" message = "操作未完成,输入内容已保留" description = { error } / > }
< input className = "visually-hidden-file" ref = { input } type = "file" multiple accept = ".xlsx" onChange = { event = > void readFiles ( Array . from ( event . target . files || [ ] ) ) } aria-label = "选择质量数据Excel文件" / >
{ pendingDeletion . ids . length > 0 && < Alert type = "warning" showIcon message = { ` 有 ${ pendingDeletion . ids . length } 个来源待删除,报表尚未改变 ` } description = "可继续标记或撤销删除,完成后点击“更新报表”。请先处理待删除文件 ,再导入新文件。" / > }
{ pendingDeletion . ids . length > 0 && < Alert type = "warning" showIcon message = { ` 有 ${ pendingDeletion . ids . length } 个来源待删除,报表尚未改变 ` } description = "请到“来源文件”页确认或撤销删除 ,再导入新文件。" / > }
{ reading && < div className = "nc-section-title" > < Spin size = "small" / > < span > 正 在 上 传 并 识 别 文 件 { reading . done } / { reading . total } < / span > < / div > }
{ drafts . length > 0 && < > < div className = "nc-section-title" > < strong > 待 导 入 文 件 · { drafts . length } 个 < / strong > < Button disabled = { importBusy } icon = { < UploadOutlined / > } onClick = { ( ) = > input . current ? . click ( ) } > 继 续 添 加 文 件 < / Button > < / div > < Table size = "small" rowKey = "id" pagination = { false } scroll = { { x : 700 } } dataSource = { drafts } columns = { [
{ title : '文件' , key : 'file' , render : ( _ , item ) = > < Button type = "link" onClick = { ( ) = > setActiveId ( item . id ) } > { item . workbook . sourceFile } < / Button > } ,
{ title : '文件' , key : 'file' , render : ( _ , item ) = > < Button type = "link" onClick = { ( ) = > setActiveId ( item . id ) } > { item . workbook . sourceFile } · { item . id . slice ( 0 , 8 ) } < / Button > } ,
{ title : '阶段' , key : 'stage' , render : ( _ , item ) = > stageName ( item . stage ) } ,
{ title : '统计期间' , key : 'period' , render : ( _ , item ) = > ` ${ item . year } 年 ${ item . month } 月 ` } ,
{ title : '识别结果' , key : 'validation' , render : ( _ , item ) = > draftReady ( item ) ? < Tag color = "green" > 已 识 别 < / Tag > : < Tag color = "orange" > 需 核 对 列 或 替 换 对 象 < / Tag > } ,
{ title : '操作' , key : 'action' , render : ( _ , item ) = > < Button type = "link" disabled = { importBusy } onClick = { ( ) = > removeDraft ( item . id ) } > 移 除 < / Button > } ,
{ title : '操作' , key : 'action' , render : ( _ , item ) = > configured . current . has ( item . id ) ? < Tag color = "blue" > 已 接 收 待 导 入 < / Tag > : < Button type = "link" disabled = { importBusy } onClick = { ( ) = > removeDraft ( item . id ) } > 移 除 < / Button > } ,
] } / > < / > }
{ duplicateSlots && < Alert type = "warning" showIcon message = "多个文件对应同一期间、阶段和范围,请调整或移除重复文件后再导入" / > }
{ ! workbook ? < div className = "nc-file-drop nc-simple-file-drop" > < FileExcelOutlined / > < h3 > 选 择 Excel 来 源 文 件 < / h3 > < p > 可 多 选 文 件 ; 系 统 自 动 识 别 阶 段 和 月 份 , 每 个 文 件 都 可 单 独 调 整 。 < / p > { hasImportCapability && < Button type = "primary" icon = { < UploadOutlined / > } loading = { busy } onClick = { ( ) = > input . current ? . click ( ) } > 选 择 Excel 文 件 < / Button > } < / div > : < >
< div className = "nc-simple-file-line" > < FileExcelOutlined / > < strong > { workbook . sourceFile } < / strong > { hasImportCapability && < Button type = "link" disabled = { importBusy } onClick = { ( ) = > { if ( active ) removeDraft ( active . id ) ; } } > 移 除 此 文 件 < / Button > } < / div >
< div className = "nc-simple-upload-fields" >
< label > 导 入 方 式 < Select disabled = { importBusy } value = { mode } options = { [ { value : 'AD D' , label : '新增数据 ' } , { value : 'REPLACE' , label : '替换已有数据 ' } ] } onChange = { value = > { setMode ( value ) ; } } / > < / label >
< label > 数 据 阶 段 < Select disabled = { importBusy } value = { stage } options = { [ { value : 'black' , label : '黑片' } , { value : 'bright' , label : '亮片' } ] } onChange = { value = > { setStage ( value ) ; setFieldMap ( matchFields ( options . fields [ value ] || [ ] , headers ) ) ; } } / > < / label >
< label > 统 计 年 份 < InputNumber disabled = { importBusy } min = { 2000 } max = { 2100 } value = { year } onChange = { value = > { if ( value ) setYear ( value ) ; } } / > < / label >
< label > 统 计 月 份 < Select disabled = { importBusy } value = { month } options = { Array . from ( { length : 12 } , ( _ , index ) = > ( { value : index + 1 , label : ` ${ index + 1 } 月 ` } ) ) } onChange = { value = > { setMonth ( value ) ; } } / > < / label >
{ options . scopes . length > 1 && < label > 数 据 范 围 < Select disabled = { importBusy } value = { scopeCode } options = { options . scopes . map ( value = > ( { value , label : value === 'ALL' ? '全部范围' : value } ) ) } onChange = { value = > { setScopeCode ( value ) ; } } / > < / label > }
{ mode === 'REPLACE' && < label className = "nc-simple-replace-target" > 替 换 对 象 < Select { ...readableSelectPopup } disabled = { importBusy } showSearch optionFilterProp = "label" value = { targetId || undefined } placeholder = "选择已发布期间和阶段 " options = { options . targets . map ( item = > ( { value : item.documentId , label : ` ${ item . year } 年 ${ item . month } 月 · ${ stageName ( item . stage ) } · ${ item . sourceFile } ` } ) ) } onChange = { value = > { setTargetId ( value ) ; } } / > < / label > }
< label > 导 入 方 式 < Select disabled = { importBusy || configuredActive } value = { mode } options = { [ { value : 'APPEN D' , label : '追加文件并合并统计 ' } , { value : 'REPLACE' , label : '替换一份已有文件 ' } ] } onChange = { setMode } / > < / label >
< label > 数 据 阶 段 < Select disabled = { importBusy || configuredReplacement } value = { stage } options = { [ { value : 'black' , label : '黑片' } , { value : 'bright' , label : '亮片' } ] } onChange = { value = > { setStage ( value ) ; setFieldMap ( matchFields ( options . fields [ value ] || [ ] , headers ) ) ; } } / > < / label >
< label > 统 计 年 份 < InputNumber disabled = { importBusy || configuredReplacement } min = { 2000 } max = { 2100 } value = { year } onChange = { value = > { if ( value ) setYear ( value ) ; } } / > < / label >
< label > 统 计 月 份 < Select disabled = { importBusy || configuredReplacement } value = { month } options = { Array . from ( { length : 12 } , ( _ , index ) = > ( { value : index + 1 , label : ` ${ index + 1 } 月 ` } ) ) } onChange = { value = > { setMonth ( value ) ; } } / > < / label >
{ options . scopes . length > 1 && < label > 数 据 范 围 < Select disabled = { importBusy || configuredReplacement } value = { scopeCode } options = { options . scopes . map ( value = > ( { value , label : value === 'ALL' ? '全部范围' : value } ) ) } onChange = { value = > { setScopeCode ( value ) ; } } / > < / label > }
{ mode === 'REPLACE' && < label className = "nc-simple-replace-target" > 替 换 对 象 < Select { ...readableSelectPopup } disabled = { importBusy || configuredReplacement } showSearch optionFilterProp = "label" value = { targetId || undefined } placeholder = "选择同期间的一份文件 " options = { replacementTargets . map ( item = > ( { value : item.documentId , label : ` ${ item . sourceFile } · ${ item . fileId ? ` 分批文件 ${ item . fileId . slice ( 0 , 8 ) } ` : '整月文件' } ` } ) ) } onChange = { setTargetId } / > < / label > }
< / div >
{ mode === 'APPEND' && activeHasMainSource && < Alert type = "warning" showIcon message = "该月份目前是整月文件,不能与分批文件混合累计" description = "如需修订,请改用“替换一份已有文件”;整月文件替换会替换该月份的完整数据。" / > }
{ mode === 'REPLACE' && replacementTargets . length === 0 && < Alert type = "info" showIcon message = "这个年月、阶段和范围没有可替换的已发布文件" / > }
{ repeatedReplacement && < Alert type = "warning" showIcon message = "同一份已有文件只能替换一次,请为每个待替换文件选择不同目标。" / > }
< p className = "nc-note" > 请 确 保 文 件 范 围 内 的 记 录 不 重 叠 ; 相 同 文 件 内 容 会 被 系 统 阻 止 , 不 同 文 件 里 的 重 复 业 务 行 无 法 自 动 识 别 。 < / p >
< details className = "nc-advanced-import-settings" > < summary > 列 识 别 与 预 览 < / summary >
< div className = "nc-form-grid" > < label > 工 作 表 < Select disabled = { importBusy } value = { sheetName } options = { workbook . sheets . map ( item = > ( { value : item.sheetName , label : item.sheetName } ) ) } onChange = { value = > void changePreview ( value ) } / > < / label > < label > 表 头 所 在 行 < InputNumber disabled = { importBusy } min = { 1 } max = { 100 } value = { headerRow } onChange = { value = > { if ( value ) setHeaderRow ( value ) ; } } onBlur = { ( ) = > { if ( workbook . preview . headerRow !== headerRow ) void changePreview ( sheetName , headerRow ) ; } } / > < / label > < / div >
< div className = "nc-section-title" > < h3 > 业 务 字 段 对 应 Excel 列 < / h3 > < span > { missing . length ? ` 还有 ${ missing . length } 个必填字段待匹配 ` : duplicate ? '同一 Excel 列不能重复对应' : '已匹配' } < / span > < / div > < ColumnMatching disabled = { importBusy } fields = { fields } headers = { headers } value = { fieldMap } onChange = { value = > { setFieldMap ( value ) ; } } / >
@@ -196,7 +198,7 @@ function ValidationNotice({ value }: { value: unknown }) {
return errors . length ? < Alert showIcon type = "warning" message = "校验仍有需要处理的事项" description = { < ul className = "nc-issue-list" > { errors . map ( ( item , index ) = > < li key = { index } > { txt ( item ) } < / li > ) } < / ul > } / > : result . complete === true ? < Alert showIcon type = "success" message = "来源及对应关系校验通过" / > : result . complete === false ? < Alert showIcon type = "warning" message = "候选校验尚未通过" description = "请核对来源是否齐备,以及基础数据和对应关系是否完整。" / > : null ;
}
export function DataWorkflowHub ( { user , sources , currentReleaseId , pendingDeletion , onDeleted , onBusyChange , onUnauthorized , onRefresh } : { user : AuthUser ; sources : SourceItem [ ] ; currentReleaseId : string | null ; pendingDeletion : PendingSourceDeletion ; onDeleted : ( ids : string [ ] ) = > void ; onBusyChange : ( busy : boolean ) = > void ; onUnauthorized : ( error : unknown ) = > boolean ; onRefresh : ( ) = > void } ) {
export function DataWorkflowHub ( { user , sources , currentReleaseId , pendingDeletion , onBusyChange , onUnauthorized , onRefresh } : { user : AuthUser ; sources : SourceItem [ ] ; currentReleaseId : string | null ; pendingDeletion : PendingSourceDeletion ; onBusyChange : ( busy : boolean ) = > void ; onUnauthorized : ( error : unknown ) = > boolean ; onRefresh : ( ) = > void } ) {
const { message } = App . useApp ( ) ;
const { active } = usePageCache ( ) ;
const [ mode , setMode ] = useState < 'ADD' | 'REPLACE' | 'REBUILD' | null > ( null ) ;
@@ -238,7 +240,7 @@ export function DataWorkflowHub({ user, sources, currentReleaseId, pendingDeleti
const opened = mode !== null || Boolean ( resumeId ) ;
const open = ( next : 'ADD' | 'REPLACE' | 'REBUILD' ) = > { setMode ( next ) ; setResumeId ( '' ) ; if ( ! options ) { optionsAttempted . current = true ; void loadOptions ( ) ; } } ;
if ( ! workflowStatusLoaded ) return < section className = "panel nc-operation-status" > { statusRead . busy ? < div > < strong > 读 取 当 前 维 护 模 式 < / strong > < span > 正 在 加 载 可 执 行 操 作 < / span > < Spin / > < / div > : workflowStatusError ? < Alert showIcon type = "error" message = "维护模式读取失败" description = { workflowStatusError } action = { < Button size = "small" onClick = { ( ) = > void loadWorkflowStatus ( ) } > 重 试 < / Button > } / > : null } < / section > ;
if ( workflowStatus ? . simplified === true && workflowStatus . mode === 'TEST' && options ) return < SimplifiedDataWorkflow options = { options } workflowStatus = { workflowStatus } pendingDeletion = { pendingDeletion } onDeleted = { onDeleted } onBusyChange = { onBusyChange } onUnauthorized = { onUnauthorized } onRefresh = { onRefresh } / > ;
if ( workflowStatus ? . simplified === true && workflowStatus . mode === 'TEST' && options ) return < SimplifiedDataWorkflow options = { options } workflowStatus = { workflowStatus } pendingDeletion = { pendingDeletion } onBusyChange = { onBusyChange } onUnauthorized = { onUnauthorized } onRefresh = { onRefresh } / > ;
return < >
< section className = "nc-intake-start panel" >
< div className = "nc-intake-intro" > < span className = "nc-eyebrow" > 日 常 数 据 维 护 < / span > < h2 > 选 择 文 件 , 核 对 后 发 布 < / h2 > < p > 文 件 名 可 以 保 持 原 样 。 黑 片 或 亮 片 、 统 计 年 月 和 表 头 均 在 下 一 步 选 择 。 < / p > < / div >
@@ -255,7 +257,7 @@ export function DataWorkflowHub({ user, sources, currentReleaseId, pendingDeleti
< / > ;
}
export function SourceFilesPanel ( { user , sources , sourcesLoaded , loading , pendingIds , maintenanceBusy , onToggleDelete , onClearDeletes , onUnauthorized , onRefresh } : { user : AuthUser ; sources : SourceItem [ ] ; sourcesLoaded : boolean ; loading : boolean ; pendingIds : string [ ] ; maintenanceBusy : boolean ; onToggleDelete : ( id : string ) = > void ; onClearDeletes : ( ) = > void ; onUnauthorized : ( error : unknown ) = > boolean ; onRefresh : ( ) = > void } ) {
export function SourceFilesPanel ( { user , sources , sourcesLoaded , loading , pendingIds , pendingReleaseId , maintenanceBusy , onDeleted , onBusyChange , onToggleDelete , onClearDeletes , onUnauthorized , onRefresh } : { user : AuthUser ; sources : SourceItem [ ] ; sourcesLoaded : boolean ; loading : boolean ; pendingIds : string [ ] ; pendingReleaseId : string | null ; maintenanceBusy : boolean ; onDeleted : ( ids : string [ ] ) = > void ; onBusyChange : ( busy : boolean ) = > void ; onToggleDelete : ( id : string ) = > void ; onClearDeletes : ( ) = > void ; onUnauthorized : ( error : unknown ) = > boolean ; onRefresh : ( ) = > void } ) {
const confirmDelete = useDeleteConfirmation ( ) ;
const { message } = App . useApp ( ) ;
const { active } = usePageCache ( ) ;
@@ -276,9 +278,11 @@ export function SourceFilesPanel({ user, sources, sourcesLoaded, loading, pendin
catch ( value ) { if ( ! onUnauthorized ( value ) ) setDeletedError ( failure ( value ) ) ; }
} ) , [ deletedRead . run , onUnauthorized ] ) ;
const sourceOperation = useDataWorkflowOperation ( 'source-maintenance' , value = > {
if ( Array . isArray ( value . sourceIds ) ) onDeleted ( value . sourceIds . map ( String ) ) ;
onRefresh ( ) ; if ( showDeleted ) void loadDeleted ( ) ;
message . success ( String ( value . operationType || '' ) . toUpperCase ( ) . includes ( 'RESTORE' ) ? '来源已恢复,报表已更新' : '来源已删除,报表已更新' ) ;
} ) ;
useEffect ( ( ) = > { onBusyChange ( sourceOperation . busy ) ; return ( ) = > onBusyChange ( false ) ; } , [ sourceOperation . busy , onBusyChange ] ) ;
const loadMetadata = useCallback ( async ( ) = > {
const [ status , options ] = await Promise . allSettled ( [ api . dataWorkflowStatus ( ) , api . sourceUploadOptions ( ) ] ) ;
const errors : string [ ] = [ ] ;
@@ -301,14 +305,24 @@ export function SourceFilesPanel({ user, sources, sourcesLoaded, loading, pendin
try { await sourceOperation . start ( ( ) = > restore ? api . restoreDataWorkflowSource ( id ) : api . deleteDataWorkflowSource ( id ) ) ; }
catch ( value ) { if ( ! onUnauthorized ( value ) ) setDeletedError ( failure ( value ) ) ; }
} ;
const confirmPendingDeletion = ( ) = > {
if ( ! pendingIds . length || sourceOperation . busy || maintenanceBusy || loading ) return ;
const sourceIds = [ . . . pendingIds ] ;
confirmDelete ( {
title : ` 确认删除 ${ sourceIds . length } 个来源并更新报表? ` ,
description : < > < p > 将 从 当 前 查 询 结 果 移 除 以 下 来 源 , 原 文 件 和 处 理 记 录 保 留 。 < / p > < ul > { sourceIds . slice ( 0 , 10 ) . map ( id = > < li key = { id } > { sources . find ( source = > source . id === id ) ? . sourceFile || id } < / li > ) } < / ul > { sourceIds . length > 10 && < p > 另 有 { sourceIds . length - 10 } 个 待 删 除 来 源 。 < / p > } < / > ,
confirmText : '确认删除并更新' ,
onConfirm : ( ) = > sourceOperation . start ( ( ) = > api . deleteDataWorkflowSources ( { sourceIds , expectedCurrentReleaseId : pendingReleaseId } ) ) ,
} ) ;
} ;
return < >
< section className = "panel section-panel nc-source-files" >
< div className = "resource-toolbar" > < strong > { showDeleted ? '已删除的来源文件' : '已接收的来源文件' } < / strong > < span > { showDeleted ? ` ${ deleted . length } 个文件 · 原件和处理记录保留 ` : simplified ? ` ${ sources . length } 个文件 ${ pendingIds . length ? ` · ${ pendingIds . length } 个待删除 ` : '' } ` : ` ${ sources . length } 个文件 · 上传或接收不等于已经发布 ` } < / span > { canOperate && < Checkbox checked = { showDeleted } onChange = { event = > setShowDeleted ( event . target . checked ) } > 查 看 已 删 除 来 源 < / Checkbox > } < / div >
{ simplified && < p className = "nc-source-maintenance-note" > 删 除 先 标 记 为 待 删 除 , 可 连 续 操 作 和 撤 销 , 点 击 上 方 “ 更 新 报 表 ” 后 统 一 生 效 。 原 文 件 和 处 理 记 录 保 留 。 < / p > }
{ simplified && pendingIds . length > 0 && < div className = "nc-source-maintenance-note " > < Button disabled = { maintenanceBusy } onClick = { onClearDeletes } > 撤 销 全 部 待 删 除 ( { pendingIds . length } ) < / Button > < / div > }
{ simplified && < p className = "nc-source-maintenance-note" > 删 除 先 标 记 为 待 删 除 , 可 连 续 操 作 和 撤 销 , 点 击 “ 确 认 删 除 并 更 新 报 表 ” 后 统 一 生 效 。 原 文 件 和 处 理 记 录 保 留 。 < / p > }
{ simplified && ! showDeleted && canOperate && pendingIds . length > 0 && < div className = "nc-source-maintenance-actions " > < Button type = "primary" danger icon = { < DeleteOutlined / > } disabled = { maintenanceBusy || loading || workflowStatus ? . capabilities ? . canDeleteSource === false } loading = { sourceOperation . busy } onClick = { confirmPendingDeletion } > 确 认 删 除 并 更 新 报 表 ( { pendingIds . length } ) < / Button > < Button disabled = { sourceOperation . busy || maintenanceBusy || loading } onClick = { onClearDeletes } > 撤 销 全 部 待 删 除 ( { pendingIds . length } ) < / Button > < / div > }
{ deletedError && < Alert showIcon type = "error" message = "已删除来源读取失败" description = { deletedLoaded ? ` ${ deletedError } ;上次成功读取的来源仍保留。 ` : deletedError } action = { < Button size = "small" onClick = { ( ) = > void loadDeleted ( ) } > 重 试 < / Button > } / > }
{ metadataError && < Alert showIcon type = "error" message = "来源操作信息读取失败" description = { workflowStatusLoaded || currentSourceIds !== null ? ` ${ metadataError } ;已成功读取的状态仍保留。 ` : metadataError } action = { < Button size = "small" onClick = { ( ) = > { metadataAttempted . current = true ; setMetadataError ( '' ) ; void loadMetadata ( ) ; } } > 重 试 < / Button > } / > }
{ sourceOperation . operation && < WorkflowOperationFeedback operation = { sourceOperation . operation } error = { sourceOperation . error } busy = { sourceOperation . busy } onResume = { sourceOperation . resume } / > }
{ ( sourceOperation . operation || sourceOperation . error ) && < WorkflowOperationFeedback operation = { sourceOperation . operation } error = { sourceOperation . error } busy = { sourceOperation . busy } onResume = { sourceOperation . resume } / > }
{ ( ! showDeleted && sourcesLoaded ) || ( showDeleted && ( deletedLoaded || deletedRead . busy ) ) ? < Table < DeletionSource > size = "small" bordered loading = { showDeleted ? deletedRead.busy : loading } dataSource = { showDeleted ? deleted . map ( item = > item . source ) : sources } rowKey = "id" pagination = { { pageSize : 15 , showSizeChanger : false } } scroll = { { x : 980 } } columns = { [
{ title : '来源文件' , dataIndex : 'sourceFile' , key : 'sourceFile' , width : 340 , ellipsis : true } ,
{ title : '阶段' , dataIndex : 'stage' , key : 'stage' , align : 'center' , width : 90 , render : value = > < Tag > { stageName ( value ) } < / Tag > } ,
@@ -319,7 +333,7 @@ export function SourceFilesPanel({ user, sources, sourcesLoaded, loading, pendin
const onCurrentRelease = currentSourceIds ? . includes ( row . id ) ? ? false ;
const permitted = ! simplified || ( showDeleted ? workflowStatus ? . capabilities ? . canRestoreSource !== false : currentSourceIds !== null && workflowStatus ? . capabilities ? . canDeleteSource !== false && ( ! onCurrentRelease || workflowStatus ? . capabilities ? . canDeleteCurrentSource !== false ) ) ;
if ( ! workflowStatusLoaded || ! canOperate || ! permitted ) return null ;
return < Button type = "link" danger = { ! showDeleted } icon = { showDeleted ? < UndoOutlined / > : < DeleteOutlined / > } disabled = { sourceOperation . busy || maintenanceBusy || loading } onClick = { ( ) = > { if ( ! simplified ) { setSelected ( { id :row.id , restore :showDeleted } ) ; return ; } if ( showDeleted ) { void runSourceOperation ( row . id , true ) ; return ; } if ( pendingIds . includes ( row . id ) ) { onToggleDelete ( row . id ) ; return ; } confirmDelete ( { title : ` 删除来源“ ${ row . sourceFile } ”? ` , description : "将标记为待删除,当前报表暂不改变。点击“ 更新报表”后才生效,原文件和处理记录保留。" , confirmText : "标记删除" , onConfirm : ( ) = > onToggleDelete ( row . id ) } ) ; } } > { simplified ? showDeleted ? '恢复并更新报表' : pendingIds . includes ( row . id ) ? '撤销删除' : '删除' : showDeleted ? '恢复' : '删除' } < / Button > ;
return < Button type = "link" danger = { ! showDeleted } icon = { showDeleted ? < UndoOutlined / > : < DeleteOutlined / > } disabled = { sourceOperation . busy || maintenanceBusy || loading } onClick = { ( ) = > { if ( ! simplified ) { setSelected ( { id :row.id , restore :showDeleted } ) ; return ; } if ( showDeleted ) { void runSourceOperation ( row . id , true ) ; return ; } if ( pendingIds . includes ( row . id ) ) { onToggleDelete ( row . id ) ; return ; } confirmDelete ( { title : ` 删除来源“ ${ row . sourceFile } ”? ` , description : "将标记为待删除,当前报表暂不改变。在本页点击“确认删除并 更新报表”后才生效,原文件和处理记录保留。" , confirmText : "标记删除" , onConfirm : ( ) = > onToggleDelete ( row . id ) } ) ; } } > { simplified ? showDeleted ? '恢复并更新报表' : pendingIds . includes ( row . id ) ? '撤销删除' : '删除' : showDeleted ? '恢复' : '删除' } < / Button > ;
} } ,
] } locale = { { emptyText : showDeleted ? '没有已删除的来源。' : '尚无来源文件,点击“上传新数据”开始。' } } / > : null }
< / section >
@@ -416,11 +430,15 @@ function DataUploadWizard({ user, mode, purpose, handoffSourceId, initialReason,
const runStorageKey = ` quality-import-run: ${ user . id } ` ;
const [ storedRunId ] = useState ( ( ) = > { try { return localStorage . getItem ( runStorageKey ) || '' ; } catch { return '' ; } } ) ;
const [ step , setStep ] = useState ( resumeId ? 4 : storedRunId ? 3 : 0 ) ; const [ busy , setBusy ] = useState ( Boolean ( storedRunId ) ) ; const [ error , setError ] = useState ( '' ) ;
const [ workbook , setWorkbook ] = useState < WorkbookPreview | null > ( null ) ; const [ stage , setStage ] = useState < DataStage > ( 'black' ) ;
const [ wizardFiles , setWizardFiles ] = useState < WizardFileDraft [ ] > ( [ ] ) ; const [ wizardFileId , setWizardFileId ] = useState ( '' ) ; const [ stage , setStage ] = useState < DataStage > ( 'black' ) ;
const [ year , setYear ] = useState ( new Date ( ) . getFullYear ( ) ) ; const [ month , setMonth ] = useState ( new Date ( ) . getMonth ( ) + 1 ) ;
const [ scopeCode , setScopeCode ] = useState ( options . scopes [ 0 ] || 'ALL' ) ; const [ targetId , setTargetId ] = useState ( '' ) ;
const [ sheetName , setSheetName ] = useState ( '' ) ; const [ headerRow , setHeaderRow ] = useState ( 1 ) ; const [ fieldMap , setFieldMap ] = useState < Record < string , string > > ( { } ) ;
const [ configuredSourceId , setConfiguredSourceId ] = useState ( '' ) ;
const activeWizardFile = wizardFiles . find ( item = > item . id === wizardFileId ) || wizardFiles [ 0 ] ;
const workbook = activeWizardFile ? . workbook || null ;
const sheetName = activeWizardFile ? . sheetName || '' ; const headerRow = activeWizardFile ? . headerRow || 1 ; const fieldMap = activeWizardFile ? . fieldMap || { } ;
const patchWizardFile = ( values : Partial < WizardFileDraft > , id = activeWizardFile ? . id ) = > { if ( id ) setWizardFiles ( previous = > previous . map ( item = > item . id === id ? { . . . item , . . . values } : item ) ) ; } ;
const setHeaderRow = ( value : number ) = > patchWizardFile ( { headerRow : value } ) ; const setFieldMap = ( value : Record < string , string > ) = > patchWizardFile ( { fieldMap : value } ) ;
const configuredByFile = useRef ( new Map < string , { signature : string ; sourceId : string } > ( ) ) ;
const [ reason , setReason ] = useState ( initialReason || '' ) ; const [ run , setRun ] = useState < Row | null > ( ( ) = > storedRunId ? { id : storedRunId , status : 'RUNNING' } : null ) ; const [ release , setRelease ] = useState < Row | null > ( null ) ;
const [ runTerminalId , setRunTerminalId ] = useState ( '' ) ;
const completionNotified = useRef ( new Set < string > ( ) ) ;
@@ -492,25 +510,49 @@ function DataUploadWizard({ user, mode, purpose, handoffSourceId, initialReason,
}
} , [ loadCandidate , onComplete , reportError , runId , runStorageKey ] ) ;
useVisiblePolling ( pollRun , 2000 , active && Boolean ( runId ) && runTerminalId !== runId , true ) ;
const readFile = async ( file? : File ) = > {
if ( ! file || actionLock . current ) return ; actionLock . current = true ; setBusy ( true ) ; setError ( '' ) ; const ownGeneration = generation . current ;
try { const result = await api . previewSourceWorkbook ( file ) ; if ( ownGeneration !== generation . current ) return ; setWorkbook ( result ) ; setSheetName ( result . preview . sheetName ) ; setHeaderRow ( result . preview . headerRow ) ; setFieldMap ( matchFields ( options . fields [ stage ] || [ ] , result . preview . headers ) ) ; setStep ( 1 ) ; }
const readFiles = async ( selected : File [ ] ) = > {
if ( ! selected . length || actionLock . current ) return ; actionLock . current = true ; setBusy ( true ) ; setError ( '' ) ; const ownGeneration = generation . current ;
try {
if ( mode === 'REPLACE' && ( selected . length > 1 || wizardFiles . length > 0 ) ) throw new Error ( '替换时请选择一份文件;要追加多份文件,请返回“上传新数据”。' ) ;
if ( selected . length + wizardFiles . length > 50 ) throw new Error ( '一次最多选择50个文件。' ) ;
const known = new Set ( wizardFiles . map ( item = > ` ${ item . file . name } : ${ item . file . size } : ${ item . file . lastModified } ` ) ) ;
const files = selected . filter ( file = > { const key = ` ${ file . name } : ${ file . size } : ${ file . lastModified } ` ; if ( known . has ( key ) ) return false ; known . add ( key ) ; return true ; } ) ;
const ready : WizardFileDraft [ ] = [ ] ; const failures : string [ ] = [ ] ; let detectedStage : DataStage | null = wizardFiles . length ? stage : null ;
for ( const file of files ) {
try {
const uploaded = await api . previewSourceWorkbook ( file ) ;
const detected = await detectSourceWorkbook ( uploaded , options . fields , api . sourceWorkbookPreview ) ;
if ( ! detectedStage ) detectedStage = detected . stage ;
ready . push ( { id : crypto.randomUUID ( ) , file , workbook : detected.workbook , sheetName : detected.workbook.preview.sheetName , headerRow : detected.workbook.preview.headerRow , fieldMap : matchFields ( options . fields [ detectedStage ] || [ ] , detected . workbook . preview . headers ) , fileId : crypto.randomUUID ( ) } ) ;
} catch ( value ) { if ( ! onUnauthorized ( value ) ) failures . push ( ` ${ file . name } : ${ failure ( value ) } ` ) ; }
}
if ( ownGeneration !== generation . current ) return ;
if ( ready . length ) {
setWizardFiles ( previous = > [ . . . previous , . . . ready ] ) ;
setWizardFileId ( previous = > previous || ready [ 0 ] . id ) ;
if ( detectedStage ) setStage ( detectedStage ) ;
setStep ( 1 ) ;
}
if ( failures . length ) setError ( ` 以下文件未加入本次导入,可重新选择: ${ failures . join ( '; ' ) } ` ) ;
else if ( ! ready . length && ! wizardFiles . length ) setError ( '没有可加入的文件。' ) ;
}
catch ( value ) { reportError ( value ) ; } finally { actionLock . current = false ; setBusy ( false ) ; if ( input . current ) input . current . value = '' ; }
} ;
const changePreview = async ( nextSheet : string , nextHeader : number , nextStage = stage , preferredMap? : Record < string , string > ) = > {
if ( ! workbook || actionLock . current ) return ; actionLock . current = true ; setBusy ( true ) ; setError ( '' ) ;
try { const result = await api . sourceWorkbookPreview ( workbook . uploadId , { sheetName : nextSheet , headerRow : nextHeader , stage : nextStage } ) ; setWorkbook ( result ) ; setSheetName ( result . preview . sheetName ) ; setHeaderRow ( result . preview . headerRow ) ; const chosen = preferredMap || fieldMap ; setFieldMap ( { . . . matchFields ( options . fields [ nextStage ] || [ ] , result . preview . headers ) , . . . Object . fromEntries ( Object . entries ( chosen ) . filter ( ( [ , header ] ) = > result . preview . headers . includes ( header ) ) ) } ) ; }
try { const result = await api . sourceWorkbookPreview ( workbook . uploadId , { sheetName : nextSheet , headerRow : nextHeader , stage : nextStage } ) ; const chosen = preferredMap || fieldMap ; patchWizardFile ( { workbook : result , sheetName : result.preview.sheetName , headerRow : result.preview.headerRow , fieldMap : { . . . matchFields ( options . fields [ nextStage ] || [ ] , result . preview . headers ) , . . . Object . fromEntries ( Object . entries ( chosen ) . filter ( ( [ , header ] ) = > result . preview . headers . includes ( header ) ) ) } } ) ; }
catch ( value ) { reportError ( value ) ; } finally { actionLock . current = false ; setBusy ( false ) ; }
} ;
const chooseTarget = ( id : string ) = > { const selected = options . targets . find ( item = > item . documentId = == id ) ; setTargetId ( id ) ; if ( selected ) { setStage ( selected . stage ) ; setYear ( selected . year ) ; setMonth ( selected . month ) ; setScopeCode ( selected . scopeCode ) ; setFieldMap ( matchFields ( options . fields [ selected . stage ] || [ ] , headers ) ) ; } } ;
const removeWizardFile = ( id : string ) = > { const next = wizardFiles . filter ( item = > item . id ! == id ) ; setWizardFiles ( next ) ; if ( wizardFileId === id ) setWizardFileId ( next [ 0 ] ? . id || '' ) ; if ( ! next . length ) setStep ( 0 ) ; configuredByFile . current . delete ( id ) ; } ;
const chooseTarget = ( id : string ) = > { const selected = options . targets . find ( item = > item . documentId === id ) ; setTargetId ( id ) ; if ( selected ) { setStage ( selected . stage ) ; setYear ( selected . year ) ; setMonth ( selected . month ) ; setScopeCode ( selected . scopeCode ) ; setWizardFiles ( previous = > previous . map ( item = > ( { . . . item , fieldMap : matchFields ( options . fields [ selected . stage ] || [ ] , item . workbook . preview . headers ) } ) ) ) ; } } ;
const beginImport = async ( ) = > {
if ( ! active || ! workbook || missingFields . length || ( mode === 'REPLACE' && ! target ) || actionLock . current ) return ;
if ( ! active || ! wizardFiles . length || wizardFiles . some ( item = > ( options . fields [ stage ] || [ ] ) . some ( field = > field . required && ! item . fieldMap [ field . name ] ) || Object . values ( item . fieldMap ) . length !== new Set ( Object . values ( item . fieldMap ) ) . size ) || ( mode === 'REPLACE' && ( ! target || wizardFiles . length !== 1 ) ) || actionLock . current ) return ;
actionLock . current = true ;
setBusy ( true ) ; setError ( '' ) ;
try {
const configured = configuredSourceId ? { source : { id : configuredSourceId } } : await api . configureSourceWorkbook ( { uploadId : workbook.uploadId , stage , year , month , sheetName , headerRow , fieldMap , mode : mode === 'REPLACE' ? 'REPLACE' : 'ADD' , expectedCurrentReleaseId : options.currentReleaseId , . . . ( target ? { targetDocumentId : target.documentId , targetRevisionId : target.revisionId } : { } ) , reason : reason.trim ( ) || ` 新增 ${ year } 年 ${ month } 月 ${ stageName ( stage ) } 数据 ` , scopeCode } ) ;
setConfiguredSourceId ( configured . source . id ) ;
const created = asRow ( await api . startImport ( { sourceIds : [ configured . source . id ] , expectedCurrentReleaseId : options.currentReleaseId , idempotencyKey : importKey.current } ) ) ; const nextRun = asRow ( created . run || created ) ; setRun ( nextRun ) ;
const items = wizardFiles . map ( item = > ( { id : item.id , body : { uploadId : item.workbook.uploadId , stage , year , month , sheetName : item.sheetName , headerRow : item.headerRow , fieldMap : item.fieldMap , mode : mode === 'REPLACE' ? 'REPLACE' as const : 'APPEND' as const , . . . ( mode === 'REPLACE' && target ? . fileId ? { fileId : target.fileId } : mode === 'ADD' ? { fileId : item.fileId } : { } ) , expectedCurrentReleaseId : options.currentReleaseId , . . . ( mode === 'REPLACE' && target ? { targetDocumentId : target.documentId , targetRevisionId : target.revisionId } : { } ) , reason : reason.trim ( ) || ` ${ mode === 'REPLACE' ? '替换' : '追加' } ${ year } 年 ${ month } 月 ${ stageName ( stage ) } 文件 ` , scopeCode } } ) ) ;
const sourceIds = await configureSourceBatch ( items , configuredByFile . current , body = > api . configureSourceWorkbook ( body ) ) ;
const created = asRow ( await api . startImport ( { sourceIds , expectedCurrentReleaseId : options.currentReleaseId , idempotencyKey : importKey.current } ) ) ; const nextRun = asRow ( created . run || created ) ; setRun ( nextRun ) ;
if ( ! nextRun . id ) throw new Error ( '服务端未返回计算任务,已接收的来源可稍后重新校验' ) ;
try { localStorage . setItem ( runStorageKey , String ( nextRun . id ) ) ; } catch { /* Server task history remains available if local storage is unavailable. */ }
} catch ( value ) { reportError ( value ) ; setBusy ( false ) ; }
@@ -549,13 +591,15 @@ function DataUploadWizard({ user, mode, purpose, handoffSourceId, initialReason,
const publishReady = release ? . complete === true && reconciliation ? . publishReady === true ;
const steps = purpose === 'WITHDRAW' ? [ '确认来源' , '提交申请' , '审批与候选' , '来源校验' , '对账与发布' ] : mode === 'REBUILD' ? [ '确认重算' , '选择期间' , '表头匹配' , '计算校验' , '对账与发布' ] : [ '选择文件' , '确认期间' , '工作表与表头' , '预览与校验' , '对账与发布' ] ;
const close = ( ) = > { generation . current ++ ; onClose ( ) ; } ;
return < Modal className = "management-modal nc-workflow-modal" open width = { 1120 } title = { published ? purpose === 'WITHDRAW' ? '来源删除已发布' : '数据已发布' : purpose === 'WITHDRAW' ? '核对并发布删除候选' : resumeId ? '继续处理候选数据' : mode === 'REPLACE' ? '替换已有数据' : mode === 'REBUILD' ? '按当前来源重新计算' : '上传新数据' } onCancel = { close } maskClosable = { ! busy } footer = { < div className = "nc-modal-footer" > < span > { runId ? '关闭后任务继续,可在“数据接入”的“导入记录”查看;完成后从候选继续。' : '确认发布前,当前查询结果保持不变。' } < / span > < div > { step > 0 && step < 4 && ! runId && ! configuredSourceId && ! busy && < Button onClick = { ( ) = > { setStep ( step - 1 ) ; setError ( '' ) ; } } > 上 一 步 < / Button > } < Button onClick = { close } > { published ? '完成' : busy ? '关闭并稍后查看' : '关闭' } < / Button > { ! published && step === 1 && < Button type = "primary" disabled = { mode === 'REPLACE' && ! target } loading = { busy } onClick = { ( ) = > { setStep ( 2 ) ; void changePreview ( sheetName , headerRow ) ; } } > 下 一 步 : 匹 配 表 头 < / Button > } { ! published && step === 2 && < Button type = "primary" loading = { busy } disabled = { Boolean ( missingFields . length ) || duplicateColumns || ! sheetName } onClick = { ( ) = > { if ( workbook && ( workbook . preview . headerRow !== headerRow || workbook . preview . sheetName !== sheetName ) ) { void changePreview ( sheetName , headerRow ) ; return ; } setStep ( 3 ) ; } } > 下 一 步 : 预 览 验 证 < / Button > } { ! published && step === 3 && ! runId && mode !== 'REBUILD' && < Button type = "primary" loading = { busy } disabled = { mode === 'REPLACE' && ! reason . trim ( ) } onClick = { ( ) = > void beginImport ( ) } > 确 认 导 入 并 校 验 < / Button > } < / div > < / div > } >
return < Modal className = "management-modal nc-workflow-modal" open width = { 1120 } title = { published ? purpose === 'WITHDRAW' ? '来源删除已发布' : '数据已发布' : purpose === 'WITHDRAW' ? '核对并发布删除候选' : resumeId ? '继续处理候选数据' : mode === 'REPLACE' ? '替换已有数据' : mode === 'REBUILD' ? '按当前来源重新计算' : '上传新数据' } onCancel = { close } maskClosable = { ! busy } footer = { < div className = "nc-modal-footer" > < span > { runId ? '关闭后任务继续,可在“数据接入”的“导入记录”查看;完成后从候选继续。' : '确认发布前,当前查询结果保持不变。' } < / span > < div > { step > 0 && step < 4 && ! runId && ! busy && < Button onClick = { ( ) = > { setStep ( step - 1 ) ; setError ( '' ) ; } } > 上 一 步 < / Button > } < Button onClick = { close } > { published ? '完成' : busy ? '关闭并稍后查看' : '关闭' } < / Button > { ! published && step === 1 && < Button type = "primary" disabled = { ( mode === 'REPLACE' && ! target ) || ! wizardFiles . length } loading = { busy } onClick = { ( ) = > { setStep ( 2 ) ; if ( workbook ) void changePreview ( sheetName , headerRow ) ; } } > 下 一 步 : 匹 配 表 头 < / Button > } { ! published && step === 2 && < Button type = "primary" loading = { busy } disabled = { wizardFiles . some ( item = > ( options . fields [ stage ] || [ ] ) . some ( field = > field . required && ! item . fieldMap [ field . name ] ) || Object . values ( item . fieldMap ) . length !== new Set ( Object . values ( item . fieldMap ) ) . size ) || ! sheetName } onClick = { ( ) = > { if ( workbook && ( workbook . preview . headerRow !== headerRow || workbook . preview . sheetName !== sheetName ) ) { void changePreview ( sheetName , headerRow ) ; return ; } setStep ( 3 ) ; } } > 下 一 步 : 预 览 验 证 < / Button > } { ! published && step === 3 && ! runId && mode !== 'REBUILD' && < Button type = "primary" loading = { busy } disabled = { ( mode === 'REPLACE' && ! reason . trim ( ) ) || ! wizardFiles . length } onClick = { ( ) = > void beginImport ( ) } > 确 认 导 入 并 校 验 < / Button > } < / div > < / div > } >
< Steps className = "nc-steps" current = { published ? 5 : step } size = "small" items = { steps . map ( title = > ( { title } ) ) } / >
{ mode !== 'REBUILD' && ! purpose && < input className = "visually-hidden-file" ref = { input } type = "file" multiple = { mode === 'ADD' } accept = ".xlsx" onChange = { event = > void readFiles ( Array . from ( event . target . files || [ ] ) ) } aria-label = { mode === 'REPLACE' ? '选择要替换的质量数据Excel文件' : '选择要追加的质量数据Excel文件' } / > }
{ error && < Alert showIcon type = "error" message = "本次操作未完成" description = { error } action = { resumeId && step === 4 ? < Button size = "small" disabled = { ! active || busy || candidateReadLock . current } onClick = { ( ) = > { if ( ! activeRef . current || candidateReadLock . current ) return ; candidateReadLock . current = true ; setBusy ( true ) ; loadCandidate ( resumeId ) . catch ( reportError ) . finally ( ( ) = > { candidateReadLock . current = false ; setBusy ( false ) ; } ) ; } } > 重 试 读 取 候 选 < / Button > : runId ? < Button size = "small" disabled = { ! active || busy || pollLock . current } onClick = { ( ) = > { if ( ! activeRef . current || pollLock . current ) return ; setBusy ( true ) ; void pollRun ( ) ; } } > 重 新 获 取 处 理 结 果 < / Button > : undefined } / > }
{ published ? < div className = "nc-success" > < FileExcelOutlined / > < h2 > { purpose === 'WITHDRAW' ? '该来源已从当前查询结果移除' : '当前查询数据已更新' } < / h2 > < p > 来 源 原 件 和 本 次 对 账 记 录 均 已 保 留 。 < / p > < / div > : < >
{ step === 0 && ( mode === 'REBUILD' ? < div className = "nc-rebuild-confirm" > < h3 > 使 用 当 前 数 据 所 用 的 全 部 来 源 重 新 计 算 < / h3 > < p > 计 算 使 用 当 前 启 用 的 基 础 数 据 、 对 应 关 系 和 规 则 。 完 成 后 先 生 成 候 选 , 核 对 差 异 后 再 发 布 。 < / p > < div className = "nc-target-list" > { options . targets . map ( item = > < div key = { item . documentId } > < Tag > { stageName ( item . stage ) } < / Tag > < strong > { item . year } 年 { item . month } 月 < / strong > < span > { item . sourceFile } < / span > < / div > ) } < / div > < Button type = "primary" loading = { busy } disabled = { ! options . targets . length } onClick = { ( ) = > void rebuild ( ) } > 开 始 重 新 计 算 < / Button > < / div > : < div className = "nc-file-drop" > < FileExcelOutlined / > < h3 > 选 择 要 { mode === 'REPLACE' ? '替换' : '上传 ' } 的 Excel 文 件 < / h3 > < p > 支 持 . xlsx ; 保 留 你 的 文 件 名 , 接 下 来 选 择 数 据 期 间 和 表 头 。 < / p > < input className = "visually-hidden-file" ref = { input } type = "file" accept = ".xlsx" onChange = { event = > void readFile ( event . target . files ? . [ 0 ] ) } aria-label = "选择质量数据Excel文件" / > < Button type = "primary" icon = { < UploadOutlined / > } loading = { busy } onClick = { ( ) = > input . current ? . click ( ) } > 选 择 Excel 文 件 < / Button > < / div > ) }
{ step === 0 && ( mode === 'REBUILD' ? < div className = "nc-rebuild-confirm" > < h3 > 使 用 当 前 数 据 所 用 的 全 部 来 源 重 新 计 算 < / h3 > < p > 计 算 使 用 当 前 启 用 的 基 础 数 据 、 对 应 关 系 和 规 则 。 完 成 后 先 生 成 候 选 , 核 对 差 异 后 再 发 布 。 < / p > < div className = "nc-target-list" > { options . targets . map ( item = > < div key = { item . documentId } > < Tag > { stageName ( item . stage ) } < / Tag > < strong > { item . year } 年 { item . month } 月 < / strong > < span > { item . sourceFile } < / span > < / div > ) } < / div > < Button type = "primary" loading = { busy } disabled = { ! options . targets . length } onClick = { ( ) = > void rebuild ( ) } > 开 始 重 新 计 算 < / Button > < / div > : < div className = "nc-file-drop" > < FileExcelOutlined / > < h3 > 选 择 要 { mode === 'REPLACE' ? '替换' : '追加 ' } 的 Excel 文 件 < / h3 > < p > { mode === 'REPLACE' ? '替换一份已发布文件,其他来源保留。' : '文件会作为独立来源加入所选月份,并与已有来源合并统计。' } 请 确 保 业 务 记 录 不 与 其 他 文 件 重 叠 。 < / p > < Button type = "primary" icon = { < UploadOutlined / > } loading = { busy } onClick = { ( ) = > input . current ? . click ( ) } > { mode === 'REPLACE' ? '选择替换文件' : '选择文件(可多选)' } < / Button > < / div > ) }
{ workbook && step > 0 && step < 4 && < div className = "nc-file-summary" > < FileExcelOutlined / > < strong > { workbook . sourceFile } < / strong > < span > { stageName ( stage ) } · { year } 年 { month } 月 < / span > < / div > }
{ step === 1 && < Form layout = "vertical" > < div className = "nc-form-grid" > { mode === 'REPLACE' ? < Form.Item className = "nc-full-width" label = "选择当前数据中的替换目标" required > < Select { ...readableSelectPopup } aria-label = "选择当前数据中的替换目标" showSearch optionFilterProp = "label" value = { targetId || undefined } placeholder = "选择年月、阶段和原文件" options = { options . targets . map ( item = > ( { value : item.documentId , label : ` ${ item . year } 年 ${ item . month } 月 · ${ stageName ( item . stage ) } · ${ item . sourceFile } ` } ) ) } onChange = { chooseTarget } / > < / Form.Item > : < > < Form.Item label = "数据阶段" required > < Select aria-label = "数据阶段 " value = { stage } options = { [ { value : 'black' , label : '黑片' } , { value : 'bright ' , label : '亮片' } ] } onChange = { value = > { setStage ( value ) ; setFieldMap ( matchFields ( options . fields [ value ] || [ ] , headers ) ) ; } } / > < / Form.Item > < Form.Item label = "统计年份" required > < InputNumber aria-label = "统计年份 " min = { 2000 } max = { 2100 } value = { year } onChange = { value = > { if ( value ) setYear ( value ) ; } } / > < / Form.Item > < Form.Item label = "统计月份" required > < Select aria-label = "统计月份" value = { month } options = { Array . from ( { length : 12 } , ( _ , index ) = > ( { value : index + 1 , label : ` ${ index + 1 } 月 ` } ) ) } onChange = { setMonth } / > < / Form.Item > { options . scopes . length > 1 && < Form.Item label = "数据范围" required > < Select aria-label = "数据范围" value = { scopeCode } options = { options . scopes . map ( value = > ( { value , label : value === 'ALL' ? '全部范围' : value } ) ) } onChange = { setScopeCode } / > < / Form.Item > } < / > } < / div > { target && < div className = "nc-replacem ent "> < span > 原 文 件 < / span > < strong > { target . sourceFile } < / strong > < ArrowRightOutlined / > < span > 新 文 件 < / span > < strong > { workbook ? . sourceFile } < / strong > < / div > } < Form.Item label = { mode === 'REPLACE' ? '替换理由' : '本次说明' } required = { mode === 'REPLACE' } > < Input.TextArea aria-label = { mode === 'REPLACE' ? '替换理由' : '本次说明' } value = { reason } rows = { 2 } maxLength = { 1000 } placeholder = { mode === 'REPLACE' ? '例如:补齐遗漏记录,使用更新后的完整月表' : '可填写本次数据说明 '} onChange = { event = > setReason ( event . target . value ) } / > < / Form.Item > < / Form > }
{ wizardFiles . length > 0 && step > 0 && step < 4 && < > < div className = "nc-section-title" > < strong > 本 次 文 件 · { wizardFiles . length } 份 < / strong > { mode === 'ADD' && step === 1 && < Button disabled = { busy } icon = { < UploadOutlined / > } onClick = { ( ) = > input . current ? . click ( ) } > 继 续 添 加 本 月 文 件 < / Button > } < / div > < Table size = "small" rowKey = "id " pagination = { false } scroll = { { x : 600 } } dataSource = { wizardFiles } columns = { [ { title : '文件 ' , key : 'file' , render : ( _ , item ) = > < Button type = "link " onClick = { ( ) = > setWizardFileId ( item . id ) } > { item . workbook . sourceFile } · { item . fileId . slice ( 0 , 8 ) } < / Button > } , { title : '字段匹配' , key : 'mapping' , render : ( _ , item ) = > ( options . fields [ stage ] || [ ] ) . filter ( field = > field . required ) . every ( field = > item . fieldMap [ field . name ] ) ? < Tag color = "gre en"> 已 完 成 < / Tag > : < Tag color = "orange" > 需 核 对 < / Tag > } , { title : '操作' , key : 'action' , render : ( _ , item ) = > configuredByFile . current . has ( item . id ) ? < Tag color = "blue" > 已 接 收 待 导 入 < / Tag > : < Button type = "link" disabled = { busy || mode === 'REPLACE '} onClick = { ( ) = > removeWizardFile ( item . id ) } > 移 除 < / Button > } ] } / > < / > }
{ step === 1 && < Form layout = "vertical" > < div className = "nc-form-grid" > { mode === 'REPLACE' ? < Form.Item className = "nc-full-width" label = "选择要替换的具体文件" required > < Select { ...readableSelectPopup } aria-label = "选择要替换的具体文件" disabled = { Boolean ( activeWizardFile && configuredByFile . current . has ( activeWizardFile . id ) ) } showSearch optionFilterProp = "label" value = { targetId || undefined } placeholder = "选择年月、阶段、范围和文件" options = { options . targets . map ( item = > ( { value : item.documentId , label : ` ${ item . year } 年 ${ item . month } 月 · ${ stageName ( item . stage ) } · ${ item . scopeCode } · ${ item . sourceFile } · ${ item . fileId ? ` 分批 ${ item . fileId . slice ( 0 , 8 ) } ` : '整月文件' } ( ${ item . documentId . slice ( - 6 ) } ) ` } ) ) } onChange = { chooseTarget } / > < / Form.Item > : < > < Form.Item label = "数据阶段" required > < Select aria-label = "数据阶段" value = { stage } options = { [ { value : 'black' , label : '黑片' } , { value : 'bright' , label : '亮片' } ] } onChange = { value = > { setStage ( value ) ; setWizardFiles ( previous = > previous . map ( item = > ( { . . . item , fieldMap : matchFields ( options . fields [ value ] || [ ] , item . workbook . preview . headers ) } ) ) ) ; } } / > < / Form.Item > < Form.Item label = "统计年份" required > < InputNumber aria-label = "统计年份" min = { 2000 } max = { 2100 } value = { year } onChange = { value = > { if ( value ) setYear ( value ) ; } } / > < / Form.Item > < Form.Item label = "统计月份" required > < Select aria-label = "统计月份" value = { month } options = { Array . from ( { length : 12 } , ( _ , index ) = > ( { value : index + 1 , label : ` ${ index + 1 } 月 ` } ) ) } onChange = { setMonth } / > < / Form.Item > { options . scopes . length > 1 && < Form.Item label = "数据范围" required > < Select aria-label = "数据范围" value = { scopeCode } options = { options . scopes . map ( value = > ( { value , label : value === 'ALL' ? '全部范围' : value } ) ) } onChange = { setScopeCode } / > < / Form.Item > } < / > } < / div > { target && < div className = "nc-replacement" > < span > 原 文 件 < / span > < strong > { target . sourceFile } · { target . fileId ? ` 分批 ${ target . fileId . slice ( 0 , 8 ) } ` : '整月文件' } < / strong > < ArrowRightOutlined / > < span > 新 文 件 < / span > < strong > { workbook ? . sourceFile } < / strong > < / div > } < Form.Item label = { mode === 'REPLACE' ? '替换理由' : '本次说明' } required = { mode === 'REPLACE' } > < Input.TextArea aria-label = { mode === 'REPLACE' ? '替换理由' : '本次说明' } value = { reason } rows = { 2 } maxLength = { 1000 } placeholder = { mode === 'REPLACE' ? '例如:修订这份文件中的记录,其他来源保留' : '可填写本次数据说明' } onChange = { event = > setReason ( event . target . value ) } / > < / Form.Item > < / Form > }
{ step === 2 && workbook && < > < div className = "nc-form-grid" > < Form.Item label = "工作表" required > < Select aria-label = "数据工作表" value = { sheetName } options = { workbook . sheets . map ( sheet = > ( { value : sheet.sheetName , label : sheet.sheetName } ) ) } onChange = { value = > void changePreview ( value , headerRow ) } / > < / Form.Item > < Form.Item label = "表头在第几行" required > < InputNumber aria-label = "表头所在行" min = { 1 } max = { 100 } value = { headerRow } onChange = { value = > { if ( value ) setHeaderRow ( value ) ; } } onBlur = { ( ) = > { if ( headerRow !== workbook . preview . headerRow ) void changePreview ( sheetName , headerRow ) ; } } onPressEnter = { ( ) = > void changePreview ( sheetName , headerRow ) } / > < / Form.Item > < / div > < div className = "nc-section-title" > < h3 > 业 务 字 段 对 应 Excel 中 哪 一 列 < / h3 > < span > { duplicateColumns ? '同一 Excel 列不能对应多个业务字段' : missingFields . length ? ` 还需选择 ${ missingFields . length } 个必填字段 ` : '必填字段已全部匹配' } < / span > < / div > < Spin spinning = { busy } > < ColumnMatching fields = { fields } headers = { headers } value = { fieldMap } onChange = { setFieldMap } / > < / Spin > < h3 > 原 表 前 几 行 < / h3 > < SampleTable headers = { headers } rows = { workbook . preview . sampleRows . map ( row = > row . values ) } / > < / > }
{ step === 3 && < > { ! runId && workbook && < > < div className = "nc-review-facts" > < div > < small > 统 计 期 间 < / small > < strong > { year } 年 { month } 月 · { stageName ( stage ) } < / strong > < / div > < div > < small > 工 作 表 与 表 头 < / small > < strong > { sheetName } · 第 { headerRow } 行 < / strong > < / div > < div > < small > 已 匹 配 字 段 < / small > < strong > { Object . keys ( fieldMap ) . length } 项 < / strong > < / div > < / div > { target && < Alert type = "warning" showIcon message = "即将使用新文件替换该期间的完整数据" description = { ` 原文件: ${ target . sourceFile } ;新文件: ${ workbook . sourceFile } 。本次先生成候选,最后发布后才更新查询结果。 ` } / > } < SampleTable headers = { Object . keys ( fieldMap ) } rows = { workbook . preview . sampleRows . map ( row = > Object . fromEntries ( Object . entries ( fieldMap ) . map ( ( [ field , header ] ) = > [ field , row . values [ header ] ] ) ) ) } / > < p className = "nc-note" > 确 认 后 由 系 统 校 验 文 件 内 容 、 数 据 范 围 及 对 应 关 系 , 并 计 算 候 选 结 果 。 < / p > < / > } { ( runId || ( busy && mode === 'REBUILD' ) ) && < div className = "nc-processing" > < Spin spinning = { busy } / > < h3 > { statusLabel [ String ( run ? . status ) ] || '正在创建计算任务' } < / h3 > < Progress percent = { Number ( run ? . total ) > 0 ? Math . min ( 100 , Math . round ( Number ( run ? . processed || 0 ) / Number ( run ? . total ) * 100 ) ) : 0 } status = { run ? . status === 'FAILED' ? 'exception' : 'active' } / > < p > 已 处 理 { txt ( run ? . processed || 0 ) } / { txt ( run ? . total ) } 行 < / p > { run ? . errorMessage ? < Alert type = "error" showIcon message = { txt ( run . errorMessage ) } / > : null } { ! busy && runId && ! [ 'FAILED' , 'CANCELLED' ] . includes ( String ( run ? . status ) ) && < Button disabled = { ! active || pollLock . current } onClick = { ( ) = > { if ( ! activeRef . current || pollLock . current ) return ; setBusy ( true ) ; void pollRun ( ) ; } } > 重 新 获 取 处 理 结 果 < / Button > } < / div > } < ValidationNotice value = { run ? . validation } / > < / > }
{ step === 4 && < Spin spinning = { busy } > < div className = "nc-review-facts" > < div > < small > 候 选 数 据 < / small > < strong > 待 核 对 < / strong > < / div > < div > < small > 来 源 校 验 < / small > < strong > { release ? . complete === true ? '通过' : '尚未通过' } < / strong > < / div > < div > < small > 基 线 对 账 < / small > < strong > { statusLabel [ String ( reconciliation ? . status ) ] || '待执行' } < / strong > < / div > < / div > < ValidationNotice value = { release ? . validation || run ? . validation } / > { reconciliationErrors . length > 0 && < Alert showIcon type = "error" message = "对账存在阻断事项" description = { reconciliationErrors . map ( txt ) . join ( '; ' ) } / > } < div className = "nc-section-title" > < h3 > 与 当 前 数 据 的 差 异 < / h3 > < Button icon = { < ReloadOutlined / > } loading = { busy } disabled = { ! release ? . id } onClick = { ( ) = > void reconcile ( ) } > { reconciliation ? '重新对账' : '执行基线对账' } < / Button > < / div > { comparisons . length > 0 ? < Table size = "small" bordered dataSource = { comparisons } rowKey = { ( row , index ) = > ` ${ row . dimension } : ${ row . key } : ${ index } ` } pagination = { { pageSize : 15 , showSizeChanger : false } } scroll = { { x : 900 } } columns = { [ { title : '期间' , width : 130 , render : ( _ , row ) = > { const period = asRow ( row . period ) ; return ` ${ txt ( period . year ) } 年 ${ period . month ? ` ${ txt ( period . month ) } 月 ` : period . quarter ? ` 第 ${ txt ( period . quarter ) } 季度 ` : '全年' } ` ; } } , { title : '维度 / 对象' , width : 200 , render : ( _ , row ) = > ` ${ ( { overall : '总体' , department : '产业部' , group : '业务分组' , product : '产品' , projectGroup : '项目组' } as Record<string, string>)[String(row.dimension)] || txt(row.dimension)} / ${ txt ( row . key ) } ` } , { title : '原综合率' , width : 120 , render : ( _ , row ) = > ratio ( asRow ( row . before ) . compositeRate ) } , { title : '新综合率' , width : 120 , render : ( _ , row ) = > ratio ( asRow ( row . after ) . compositeRate ) } , { title : '差异' , render : ( _ , row ) = > asRows ( row . differences ) . map ( item = > ` ${ metricLabel ( item . path ) } : ${ txt ( item . before ) } → ${ txt ( item . after ) } ` ) . join ( '; ' ) || '一致' } ] } / > : < Empty image = { Empty . PRESENTED_IMAGE_SIMPLE } description = { reconciliation ? '本次没有可展示的期间比较;以对账结论为准' : '执行对账后在这里查看期间和指标差异' } / > } { reconciliation ? . status === 'REVIEW_REQUIRED' && < div className = "nc-difference-confirm" > < Alert type = "warning" showIcon message = { ` 发现 ${ txt ( evidence . differenceCount ) } 项差异,需要发布者确认 ` } / > { canPublish ? < > < Input.TextArea aria-label = "业务差异确认理由" rows = { 2 } value = { differenceReason } maxLength = { 1000 } placeholder = "填写差异原因及确认依据" onChange = { event = > setDifferenceReason ( event . target . value ) } / > < Checkbox checked = { confirmDifferences } onChange = { event = > setConfirmDifferences ( event . target . checked ) } > 我 已 核 对 上 方 差 异 , 并 确 认 新 数 据 正 确 < / Checkbox > < Button type = "primary" disabled = { ! confirmDifferences || ! differenceReason . trim ( ) || busy } onClick = { ( ) = > void confirm ( ) } > 确 认 差 异 并 验 收 < / Button > < / > : < p > 候 选 已 保 存 , 请 交 由 有 数 据 发 布 权 限 的 同 事 完 成 差 异 确 认 。 < / p > } < / div > } { canPublish ? < div className = "nc-publish-confirm" > < Checkbox disabled = { ! publishReady } checked = { publishConfirmed } onChange = { event = > setPublishConfirmed ( event . target . checked ) } > { purpose === 'WITHDRAW' ? '我确认发布此删除候选,从当前查询结果移除已批准的来源' : '我确认将此候选发布为当前查询数据' } { target ? ` ,替换 ${ target . year } 年 ${ target . month } 月 ${ stageName ( target . stage ) } ` : '' } < / Checkbox > < Button size = "large" type = "primary" disabled = { ! publishReady || ! publishConfirmed || busy } onClick = { ( ) = > void publish ( ) } > 确 认 发 布 < / Button > { ! publishReady && < span > 来 源 校 验 和 基 线 对 账 通 过 后 可 发 布 。 < / span > } < / div > : < Alert showIcon type = "info" message = "候选数据已保存,等待有权限的同事发布" description = { < > < span > 当 前 账 号 没 有 数 据 发 布 权 限 。 可 复 制 处 理 链 接 交 接 , 正 式 查 询 数 据 尚 未 更 新 。 < / span > < Button type = "link" onClick = { ( ) = > { const link = new URL ( window . location . href ) ; link . searchParams . set ( 'page' , 'sources' ) ; if ( handoffSourceId ) { link . searchParams . set ( 'sourceDeleteId' , handoffSourceId ) ; link . searchParams . delete ( 'candidateReleaseId' ) ; } else { link . searchParams . set ( 'candidateReleaseId' , String ( release ? . id || '' ) ) ; link . searchParams . delete ( 'sourceDeleteId' ) ; } void navigator . clipboard . writeText ( link . toString ( ) ) . then ( ( ) = > message . success ( '处理链接已复制' ) ) . catch ( reportError ) ; } } > 复 制 处 理 链 接 < / Button > < / > } / > } < / Spin > }