fix: keep unmatched BPM records out of the order center

This commit is contained in:
abaishu0730 committed 2026-10-23 15:39:38 +08:00
1 parent 8b2339ec81
commit 5c34851347
5 files changed
+21 -17

No files matched your search

+2
View File
@@ -2,6 +2,8 @@
## 当前:Excel规则已接入测试执行链
订单中心仅展示有分类匹配证据的订单和执行任务;未匹配候选、不带分类的识别失败记录不进入列表、统计或订单详情。已匹配但缺字段、归档失败或待核验的订单继续显示。原到达与候选数据保留,不删除或重做业务。本机14e48339目录保留为基础版本路径,后续视图补丁按当前分支提交覆盖,不再把目录名当成完整代码版本。默认核心测试另纳入10项订单查询回归;本次查询专项10项通过,不声称重跑旧全量。
本机运行 `%LOCALAPPDATA%/OrderNotificationAutomationReleases/test-excel-import-20261023-14e48339`,代码树 `14e483398ff3d44f4f0948009e6cbac2c5033092`。原76版本保留作回退,正式服务机未操作。
- Excel预览后可“确认导入并应用到测试”;编辑则“保存草稿 → 应用到测试”。直接复用既有匹配、详情采集、PDF归档、批次与调度器,不增加第二套业务链。规则仍严格按Excel流程和节点,不添加节点别名。
+1 -1
View File
@@ -13,7 +13,7 @@
"service:stop": "node scripts/service.cjs stop",
"service:restart": "node scripts/service.cjs restart",
"test": "npm run test:business",
"test:business": "node --test --test-concurrency=1 tests/order-rules/excel-import-contract.test.cjs tests/order-rules/excel-execution-bridge.test.cjs tests/order-rules/excel-import-flow-ui.test.cjs tests/order-rules/scheduled-mail-policy.test.cjs",
"test:business": "node --test --test-concurrency=1 tests/order-rules/excel-import-contract.test.cjs tests/order-rules/excel-execution-bridge.test.cjs tests/order-rules/excel-import-flow-ui.test.cjs tests/order-rules/query.test.cjs tests/order-rules/scheduled-mail-policy.test.cjs",
"test:full": "node --test --test-concurrency=2 \"tests/**/*.test.cjs\""
},
"engines": {
+7 -8
View File
@@ -10,7 +10,7 @@ function records(store){
const revision=store.queryRevision?.();
const saved=cache.get(store);
if(revision!==undefined&&saved?.revision===revision)return saved;
const value={revision:revision??Date.now(),orders:store.all('orders'),batches:store.all('batches'),tasks:store.all('execution-tasks'),candidates:store.all('execution-candidates')||[],issues:store.all('business-issues')};
const value={revision:revision??Date.now(),orders:store.all('orders'),batches:store.all('batches'),tasks:store.all('execution-tasks'),issues:store.all('business-issues')};
if(revision!==undefined)cache.set(store,value);
return value;
}
@@ -41,17 +41,16 @@ function orderRow(order,task){
return {...event,...pick(order,['id','status','categoryId','error','reason','batchId','createdAt','updatedAt','orderNo','receivedAt']),...(order?{notifications:notifications(order),...(order.ruleSnapshot?.testRunId?{testRunId:order.ruleSnapshot.testRunId}:{})}:{}),
id:order?.id||'task:'+task.id,connectionId:order?.sample?.connectionId||event.connectionId||task?.connectionId,
error:task?.error||order?.error,executionTaskId:task?.id,executionStatus:task?.status,exceptionId:task?.exceptionId,orderNo:order?.orderNo||event.orderNo||event.serialNum||event.taskId,
categoryId:order?.categoryId||task?.categoryIds?.[0]||'',status:task&&['failed','blocked','unknown','capturing','archiving'].includes(task.status)?task.status:order?.status||task?.status};
categoryId:order?.categoryId||order?.ruleSnapshot?.categoryId||order?.ruleSnapshot?.id||task?.categoryIds?.[0]||'',status:task&&['failed','blocked','unknown','capturing','archiving'].includes(task.status)?task.status:order?.status||task?.status};
}
function currentTasks(context,user){
const tasks=new Map();for(const task of records(context.orderRules).tasks){if(task.supersededBy||!task.orderId||!canReadConnection(context.workspace,user,task.connectionId))continue;const old=tasks.get(task.orderId);if(!old||Number(!!task.conflict)>Number(!!old.conflict)||!!task.conflict===!!old.conflict&&String(task.createdAt||'')>=String(old.createdAt||''))tasks.set(task.orderId,task);}return tasks;
}
function candidateRow(candidate){const row=identity(candidate.row);return {...row,id:'candidate:'+candidate.id,connectionId:candidate.connectionId,orderNo:row.orderNo||row.serialNum||row.taskId,status:'candidate',reason:candidate.reason,createdAt:candidate.createdAt,updatedAt:candidate.updatedAt,categoryId:''};}
const classified=(order,task)=>!!(order?.categoryId||order?.ruleSnapshot?.categoryId||order?.ruleSnapshot?.id||task?.categoryIds?.length);
function visibleOrders(context,user){
const data=records(context.orderRules),tasks=currentTasks(context,user);
const rows=data.orders.filter(o=>canReadOrder(context.workspace,user,o)).map(o=>orderRow(o,tasks.get(o.id)));
for(const task of data.tasks)if(!task.orderId&&!task.supersededBy&&canReadConnection(context.workspace,user,task.connectionId))rows.push(orderRow(null,task));
for(const candidate of data.candidates)if(candidate.status==='candidate'&&canReadConnection(context.workspace,user,candidate.connectionId))rows.push(candidateRow(candidate));
const rows=data.orders.filter(o=>classified(o,tasks.get(o.id))&&canReadOrder(context.workspace,user,o)).map(o=>orderRow(o,tasks.get(o.id)));
for(const task of data.tasks)if(!task.orderId&&!task.supersededBy&&classified(null,task)&&canReadConnection(context.workspace,user,task.connectionId))rows.push(orderRow(null,task));
return rows;
}
function page(rows,input,revision){
@@ -87,10 +86,10 @@ function queryBatches(context,input,user){
return page(rows,f,publicRevision(context,user));
}
function orderDetail(context,id,user){
if(id.startsWith('candidate:')){const candidate=records(context.orderRules).candidates.find(row=>row.id===id.slice(10)&&row.status==='candidate');if(!candidate||!canReadConnection(context.workspace,user,candidate.connectionId))fail('候选记录不存在或无权查看。',404);return {...candidateRow(candidate),event:identity(candidate.row),executionTask:null,files:[],batches:[]};}
if(id.startsWith('candidate:'))fail('未匹配分类规则的记录不属于订单中心。',404);
const data=records(context.orderRules),task=id.startsWith('task:')?data.tasks.find(t=>t.id===id.slice(5)):currentTasks(context,user).get(id);
const order=id.startsWith('task:')?null:context.orderRules.get('orders',id);
if(order?!canReadOrder(context.workspace,user,order):!task||!canReadConnection(context.workspace,user,task.connectionId))fail('订单不存在或无权查看。',404);
if(!classified(order,task)||(order?!canReadOrder(context.workspace,user,order):!task||!canReadConnection(context.workspace,user,task.connectionId)))fail('订单不存在或无权查看。',404);
const files=(order?.archive?.files||[]).map((file,index)=>({...pick(file,['name','size','sha256','kind']),index,url:'/api/order-rules/orders/'+encodeURIComponent(id)+'/files/'+index}));
return {...orderRow(order,task),event:identity(order?.event||task?.row),executionTask:taskEvidence(task,context,user),files,archivedAt:order?.archive?.archivedAt,archiveGeneration:order?.archiveGeneration||1,ruleVersion:order?.ruleSnapshot?.version,batches:data.batches.filter(b=>b.orderIds?.includes(id)&&canReadBatch(context.workspace,user,b,context.orderRules)).map(b=>batchRow(context,b))};
}
+10 -7
View File
@@ -1,11 +1,11 @@
'use strict';
const test=require('node:test'),assert=require('node:assert/strict');
const {queryOrders,queryBatches,orderDetail,batchDetail,readOrderFile}=require('../../src/modules/order-rules/query.cjs');
const {queryOrders,queryBatches,orderDetail,batchDetail,readOrderFile,summary}=require('../../src/modules/order-rules/query.cjs');
function fixture(){
const rows=Array.from({length:83},(_,i)=>({id:'o'+i,status:'pending',categoryId:'cat',event:{connectionId:'a',orderNo:'NO'+i,receivedAt:'2026-10-20T10:00:00Z',fields:{secret:'raw'}},sample:{connectionId:'a',fields:{secret:'raw'}}}));
rows.push({id:'foreign',sample:{connectionId:'b'},event:{orderNo:'PRIVATE'},status:'blocked'});
const records={orders:rows,batches:[{id:'old',orderIds:['o0'],status:'prepared',windowStart:'2020-01-01',text:'frozen'},{id:'mixed',orderIds:['o0','foreign'],status:'unknown',text:'SECRET'}],'execution-tasks':[], 'execution-candidates':[], 'business-issues':[]};
const store={all:k=>records[k]||[],get:(k,id)=>(records[k]||[]).find(r=>r.id===id),queryRevision:()=>1};
const store={all:k=>records[k]||[],get:(k,id)=>(records[k]||[]).find(r=>r.id===id),queryRevision:()=>1,snapshot:()=>({rules:[]})};
return {orderRules:store,workspace:{recordSources:()=>[{id:'a',owner:'alice'},{id:'b',owner:'bob'}]},execution:{archive:{read:async()=>Buffer.from('%PDF-x')}}};
}
const user={username:'alice',role:'operator'};
@@ -20,14 +20,17 @@ test('old prepared remains active, mixed source evidence is denied and permissio
c.workspace.recordSources=()=>[{id:'a',owner:'bob'}];assert.equal(queryOrders(c,{},user).total,0);
});
test('task-only blocked work remains visible and private raw fields never leave detail',()=>{
const c=fixture();c.orderRules.all('execution-tasks').push({id:'task',connectionId:'a',status:'blocked',row:{orderNo:'MISSED',fields:{secret:'raw'}},missedWindow:{start:'2020'}});
const c=fixture();c.orderRules.all('execution-tasks').push({id:'task',connectionId:'a',categoryIds:['cat'],status:'blocked',row:{orderNo:'MISSED',fields:{secret:'raw'}},missedWindow:{start:'2020'}});
assert.equal(queryOrders(c,{},user).total,84);assert.equal(orderDetail(c,'task:task',user).executionTask.id,'task');assert.equal(JSON.stringify(orderDetail(c,'o0',user)).includes('raw'),false);
});
test('unconfirmed notification candidates are visible with reasons and retain connection permissions',()=>{
test('unmatched arrivals never enter order lists, counts or details while classified failures remain visible',()=>{
const c=fixture();c.orderRules.all('execution-candidates').push({id:'candidate-a',connectionId:'a',status:'candidate',reason:'未确认通知节点,需要核验',row:{source:'todo',taskId:'T-A',processName:'海外运营订单评审',nodeName:'订单专员(生效)',receivedAt:'2026-10-23T00:00:00Z',fields:{secret:'raw'}}},{id:'candidate-b',connectionId:'b',status:'candidate',reason:'PRIVATE',row:{taskId:'T-B'}});
const result=queryOrders(c,{status:'candidate'},user);assert.equal(result.total,1);assert.equal(result.items[0].id,'candidate:candidate-a');assert.equal(result.items[0].reason,'未确认通知节点,需要核验');assert.equal(result.items[0].nodeName,'订单专员(生效)');
const detail=orderDetail(c,result.items[0].id,user);assert.equal(detail.status,'candidate');assert.equal(detail.executionTask,null);assert.deepEqual(detail.files,[]);assert.deepEqual(detail.batches,[]);assert.equal(JSON.stringify(detail).includes('raw'),false);assert.throws(()=>orderDetail(c,'candidate:candidate-b',user));
c.orderRules.all('orders').push({id:'unmatched-order',status:'blocked',categoryId:'',sample:{connectionId:'a'},event:{taskId:'not-an-order'}});
c.orderRules.all('execution-tasks').push({id:'unmatched-task',connectionId:'a',categoryIds:[],status:'blocked',row:{taskId:'not-a-rule'}});
assert.equal(queryOrders(c,{status:'candidate'},user).total,0);assert.equal(queryOrders(c,{},user).total,83);assert.equal(summary(c,user).counts.orders,83);
for(const id of ['candidate:candidate-a','candidate:candidate-b','unmatched-order','task:unmatched-task'])assert.throws(()=>orderDetail(c,id,user),e=>e.status===404);
assert.equal(c.orderRules.all('execution-candidates').length,2);assert.equal(c.orderRules.get('orders','unmatched-order').status,'blocked');
});
test('file endpoint reauthorizes and validates bytes against durable evidence',async()=>{
const c=fixture(),bytes=Buffer.from('%PDF-x');c.orderRules.get('orders','o0').archive={files:[{name:'a.pdf',path:'server-only',size:bytes.length,sha256:require('node:crypto').createHash('sha256').update(bytes).digest('hex')}]};
@@ -45,7 +48,7 @@ test('HTTP query routing rejects missing services, invalid parameters and malfor
assert.equal(await invoke('/api/unrelated'),false);
});
test('date filters use the displayed Beijing business day rather than UTC midnight',()=>{
const c=fixture();c.orderRules.all('orders').push({id:'night',status:'pending',sample:{connectionId:'a'},event:{connectionId:'a',orderNo:'NIGHT',receivedAt:'2026-10-20T16:30:00Z'}});
const c=fixture();c.orderRules.all('orders').push({id:'night',categoryId:'cat',status:'pending',sample:{connectionId:'a'},event:{connectionId:'a',orderNo:'NIGHT',receivedAt:'2026-10-20T16:30:00Z'}});
assert.equal(queryOrders(c,{from:'2026-10-21',to:'2026-10-21'},user).total,1);
assert.equal(queryOrders(c,{from:'2026-10-20',to:'2026-10-20'},user).total,83);
});
+1 -1
View File
@@ -2,7 +2,7 @@
window.BusinessRecordViews=(()=>{
async function render(container,options,kind){
const {api,esc,formatDate,user,isActive}=options,view=kind==='orders'?'notification-orders':'notification-batches',filters=window.RecordState.read(view);
const states=kind==='orders'?['candidate','identified','preparing','archived','pending','batched','blocked','failed','unknown','sent','capturing','archiving','ignored']:['prepared','sending','unknown','failed','sent','cancelled'];
const states=kind==='orders'?['identified','preparing','archived','pending','batched','blocked','failed','unknown','sent','capturing','archiving','ignored']:['prepared','sending','unknown','failed','sent','cancelled'];
const labels={candidate:'未匹配通知规则',disabled:'未开启',empty:'无匹配惠州明细',not_applicable:'历史订单,不追加通知',ignored:'历史保留,不自动补发',identified:'已识别',preparing:'准备归档',archived:'已归档',pending:'等待汇总',batched:'已编入批次',blocked:'受阻',failed:'失败',unknown:'待核实',sent:'已提交邮件服务器',capturing:'采集中',archiving:'归档中',prepared:'已冻结待发',sending:'发送中',cancelled:'已取消'};
const catalogs={categories:new Map(),connections:new Map()};
const select=(name,label)=>`<label class="small" for="business-${name}">${label}</label><select class="form-select" id="business-${name}" name="${name}"><option value="">全部</option>${filters[name]?`<option selected value="${esc(filters[name])}">${esc(filters[name])}</option>`:''}</select>`;