fix: close order intake five minutes before scheduled mail
This commit is contained in:
1 parent
5fe461c77d
commit
4d8f393895
17 files changed
+137
-24
No files matched your search
@@ -40,7 +40,7 @@ function buildBatch(rule,orders,cutoff,{maxMessageBytes=20971520,window,notifica
|
||||
if(order.ruleSnapshot[binding]!==rule[binding])fail('同一批次不能混合不同模板绑定。');
|
||||
if(order.status&&order.status!=='pending')fail('此类别包含未准备完成的订单。');
|
||||
const received=Date.parse(store?require('./restricted-test.cjs').orderTime(store,order):order.event?.receivedAt);
|
||||
if(window&&(store?!require('./restricted-test.cjs').orderInWindow(store,order,window):!Number.isFinite(received)||received<start||received>=end))fail('订单接收时间不属于本批时段窗口。');
|
||||
if(window&&(store?!require('./restricted-test.cjs').orderInWindow(store,order,window):!require('./window.cjs').inWindow(order.event?.receivedAt,window)))fail('订单接收时间不属于本批时段窗口。');
|
||||
if(!Number.isFinite(received)||received>limit)fail('订单接收时间超出本批截止范围。');
|
||||
const number=order.event?.orderNo;
|
||||
if(typeof number!=='string'||!number.trim()||/[\r\n\x00-\x1f]/.test(number))fail('订单号无效。');
|
||||
|
||||
@@ -32,7 +32,7 @@ const pick=(row,keys)=>Object.fromEntries(keys.filter(k=>row?.[k]!==undefined).m
|
||||
const identity=row=>pick(row,['source','connectionId','instanceId','taskId','revision','processName','nodeName','orderNo','serialNum','receivedAt','quantity','brief','model','project','title']);
|
||||
function taskEvidence(task,context,user){
|
||||
if(!task)return null;
|
||||
const value=pick(task,['id','version','connectionId','status','step','error','errorCode','retryPolicy','nextRetryAt','exceptionId','conflict','missedWindow','recovery','updatedAt','createdAt']);
|
||||
const value=pick(task,['id','version','connectionId','status','step','error','errorCode','retryPolicy','nextRetryAt','deferredUntil','deferredSendAt','exceptionId','conflict','missedWindow','recovery','updatedAt','createdAt']);
|
||||
if(Array.isArray(task.diagnostics))value.diagnostics=task.diagnostics.slice(0,100).map(d=>pick(d,['code','reason','message','table','path','field','rowCount','expectedRows','actualRows']));
|
||||
if(task.captureDiagnostics)value.captureDiagnostics=pick(task.captureDiagnostics,['reason','tableName','dynamicArea','backendRows','domRows','fieldPaths']);
|
||||
const previous=(task.history||[]).findLast(h=>h.step==='capture'&&h.error&&h.error!==task.error&&['failed','blocked'].includes(h.status));
|
||||
@@ -51,7 +51,7 @@ function orderRow(order,task){
|
||||
const event=identity(order?.event||task?.row);
|
||||
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,
|
||||
error:task?.error||order?.error,executionTaskId:task?.id,executionStatus:task?.status,executionStep:task?.step,deferredUntil:task?.deferredUntil,deferredSendAt:task?.deferredSendAt,exceptionId:task?.exceptionId,orderNo:order?.orderNo||event.orderNo||event.serialNum||event.taskId,
|
||||
categoryName:order?.ruleSnapshot?.name||'',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){
|
||||
@@ -91,7 +91,7 @@ function publicRevision(context,user){
|
||||
}
|
||||
function queryOrders(context,input,user){const rows=visibleOrders(context,user),revision=crypto.createHash('sha256').update(publicRevision(context,user)+JSON.stringify(rows.map(r=>[r.id,r.collectingBatches]))).digest('hex').slice(0,24);return page(rows,filters(input,'orders'),revision);}
|
||||
function batchRow(context,batch){
|
||||
return {...pick(batch,['id','version','categoryId','subject','status','error','createdAt','sentAt','resolvedAt','windowStart','windowEnd','cutoff','orderNos','testRunId']),categoryName:batch.ruleSnapshot?.name||context.orderRules.get('rules',batch.categoryId)?.draft?.name||batch.categoryId,notificationMode:modeOf(batch),windowStart:batch.windowStart||batch.window?.start,windowEnd:batch.windowEnd||batch.window?.end||batch.cutoff,orderCount:batch.orderIds?.length||0,connectionIds:[...new Set((batch.orderIds||[]).map(id=>{const o=context.orderRules.get('orders',id);return o?.sample?.connectionId||o?.event?.connectionId||o?.connectionId;}).filter(Boolean))]};
|
||||
return {...pick(batch,['id','version','categoryId','subject','status','error','createdAt','sentAt','resolvedAt','windowStart','windowEnd','cutoff','orderNos','testRunId']),categoryName:batch.ruleSnapshot?.name||context.orderRules.get('rules',batch.categoryId)?.draft?.name||batch.categoryId,notificationMode:modeOf(batch),collectionStart:batch.window?.collectionStart,collectionEnd:batch.window?.collectionEnd,windowStart:batch.windowStart||batch.window?.start,windowEnd:batch.windowEnd||batch.window?.end||batch.cutoff,orderCount:batch.orderIds?.length||0,connectionIds:[...new Set((batch.orderIds||[]).map(id=>{const o=context.orderRules.get('orders',id);return o?.sample?.connectionId||o?.event?.connectionId||o?.connectionId;}).filter(Boolean))]};
|
||||
}
|
||||
function queryBatches(context,input,user){
|
||||
const f=filters(input,'batches'),data=records(context.orderRules);
|
||||
|
||||
@@ -146,7 +146,7 @@ function eventInWindow(store,row,window){
|
||||
const at=eventTime(store,row);
|
||||
if(isAdmitted(store,row)){
|
||||
const current=require('./window.cjs').upcomingWindow(store.clock(),store.schedule(),store.calendar());
|
||||
return !!current&¤t.end===window.end&&Date.parse(at)<Date.parse(window.end);
|
||||
return !!current&¤t.end===window.end&&Date.parse(at)<Date.parse(require('./window.cjs').collectionBounds(window).end);
|
||||
}
|
||||
return require('./window.cjs').inWindow(at,window);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ const {seedRules}=require('./catalog.cjs');const registry=require('./registry.cj
|
||||
const {transition}=require('./state.cjs');
|
||||
const {composeBatch}=require('./template.cjs');
|
||||
const {fail,validateRule,publicationIssues}=require('./validation.cjs');
|
||||
const {windowForCutoff,upcomingWindow,inWindow}=require('./window.cjs');
|
||||
const {windowForCutoff,upcomingWindow,inWindow,collectionBounds}=require('./window.cjs');
|
||||
const {matchesScope,scopesOverlap}=require('./scopes.cjs');
|
||||
const {initialNotification,ordersForMode}=require('./huizhou.cjs');
|
||||
const {modeOf,delivery,updateDelivery}=require('./delivery.cjs');
|
||||
@@ -155,7 +155,7 @@ class RuleStore{
|
||||
order.notifications={huizhou:initialNotification(rule,order.event)};
|
||||
const window=upcomingWindow(this.clock(),this.schedule(),this.calendar());
|
||||
const eligibleAt=eligibility.eventTime(this,sample);
|
||||
if(window&&validDate(eligibleAt)&&Date.parse(eligibleAt)<Date.parse(window.start)&&!eligibility.isAdmitted(this,sample)){order.status='ignored';order.error='早于当前处理时段的历史订单,不归档、不补发。';}
|
||||
if(window&&validDate(eligibleAt)&&Date.parse(eligibleAt)<Date.parse(collectionBounds(window).start)&&!eligibility.isAdmitted(this,sample)){order.status='ignored';order.error='早于当前处理时段的历史订单,不归档、不补发。';}
|
||||
const frozen=this.all('batches').find(b=>b.categoryId===order.categoryId&&b.window&&eligibility.eventInWindow(this,sample,b.window));
|
||||
if(frozen){order.status='blocked';order.blockedByBatchId=frozen.id;order.error='本接收时段的类别已冻结,新增订单须负责人核验,不能混入已冻结邮件。';this.put('orders',order);this.recordIssue('late:'+order.id,{component:'rules',error:order.error,batchId:frozen.id,orderIds:[order.id]});}
|
||||
this.put('orders',order);this.audit(actor,'识别订单任务',id);return order;
|
||||
@@ -168,7 +168,7 @@ class RuleStore{
|
||||
if(!stale){
|
||||
if(!['identified','preparing'].includes(order.status))fail('当前状态不允许记录归档结果。',409);
|
||||
const window=upcomingWindow(this.clock(),this.schedule(),this.calendar());
|
||||
if(window&&Date.parse(eligibility.orderTime(this,order))<Date.parse(window.start)&&!eligibility.isAdmitted(this,order.sample||order.event))fail('该订单已超出当前时段,不再自动归档或补发。',409);
|
||||
if(window&&Date.parse(eligibility.orderTime(this,order))<Date.parse(collectionBounds(window).start)&&!eligibility.isAdmitted(this,order.sample||order.event))fail('该订单已超出当前时段,不再自动归档或补发。',409);
|
||||
}
|
||||
if(!evidence||!validDate(evidence.archivedAt)||!Array.isArray(evidence.files)||!evidence.files.length||evidence.files.some(f=>!f||typeof f.name!=='string'||!f.name||/[\\/\x00-\x1f]/.test(f.name)||typeof f.path!=='string'||!path.win32.isAbsolute(f.path)||! /^[a-f0-9]{64}$/i.test(f.sha256)||!Number.isSafeInteger(f.size)||f.size<1||!['pdf','notice'].includes(f.kind)))fail('归档证据不完整。');
|
||||
if(stale){
|
||||
@@ -266,7 +266,7 @@ class RuleStore{
|
||||
if(!state||!['identified','preparing','archived','pending','blocked'].includes(state.status)||!order.categoryId||order.blockedByBatchId||order.missedWindow||order.status==='ignored')continue;
|
||||
if(mode==='huizhou'&&(order.ruleSnapshot?.huizhouEnabled!==true||(!state.orderNos?.length&&!state.issues?.length)))continue;
|
||||
const at=eligibility.orderTime(this,order);
|
||||
if(validDate(at)&&Date.parse(at)<Date.parse(window.start)&&!eligibility.isAdmitted(this,order.sample||order.event)){this.recordIssue('missed:'+order.id+':'+mode,{component:'rules',notificationMode:mode,error:'错过整理时点,等待人工处理。',orderIds:[order.id]});updateDelivery(order,mode,{status:'ignored',error:'早于本时段的历史订单,不补发。'});this.put('orders',order);continue;}
|
||||
if(validDate(at)&&Date.parse(at)<Date.parse(collectionBounds(window).start)&&!eligibility.isAdmitted(this,order.sample||order.event)){this.recordIssue('missed:'+order.id+':'+mode,{component:'rules',notificationMode:mode,error:'错过整理时点,等待人工处理。',orderIds:[order.id]});updateDelivery(order,mode,{status:'ignored',error:'早于本时段的历史订单,不补发。'});this.put('orders',order);continue;}
|
||||
if(!eligibility.orderInWindow(this,order,window))continue;
|
||||
const key=order.categoryId+':'+mode;if(!grouped.has(key))grouped.set(key,{mode,orders:[]});grouped.get(key).orders.push(order);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ function windowForCutoff(cutoff,schedule,overrides=[]){
|
||||
}
|
||||
}
|
||||
const fmt=value=>new Intl.DateTimeFormat('zh-CN',{timeZone:'Asia/Shanghai',month:'2-digit',day:'2-digit',hour:'2-digit',minute:'2-digit',hour12:false}).format(new Date(value));
|
||||
return {start,end,label:fmt(start)+' 至 '+fmt(end)+'(北京时间,含起点、不含终点)',startInclusive:true,endInclusive:false};
|
||||
const collectionStart=new Date(Date.parse(start)-300000).toISOString(),collectionEnd=new Date(Date.parse(end)-300000).toISOString();
|
||||
return {start,end,collectionStart,collectionEnd,collectionLeadMinutes:5,policyVersion:2,label:fmt(collectionStart)+' 至 '+fmt(collectionEnd)+' 到达 · '+fmt(end)+' 发送(北京时间,含起点、不含终点)',startInclusive:true,endInclusive:false};
|
||||
}
|
||||
function upcomingWindow(now,schedule,overrides=[]){
|
||||
const times=timesOf(schedule),day=dayOf(now);
|
||||
@@ -34,5 +35,6 @@ function upcomingWindow(now,schedule,overrides=[]){
|
||||
if(!cutoff)return null;
|
||||
return {...windowForCutoff(cutoff,schedule,overrides),available:Boolean(due&&cutoff===due)};
|
||||
}
|
||||
function inWindow(receivedAt,window){const value=Date.parse(receivedAt);return Number.isFinite(value)&&value>=Date.parse(window.start)&&value<Date.parse(window.end);}
|
||||
module.exports={windowForCutoff,upcomingWindow,inWindow};
|
||||
function collectionBounds(window){return {start:window.collectionStart||window.start,end:window.collectionEnd||window.end};}
|
||||
function inWindow(receivedAt,window){const value=Date.parse(receivedAt),bounds=collectionBounds(window);return Number.isFinite(value)&&value>=Date.parse(bounds.start)&&value<Date.parse(bounds.end);}
|
||||
module.exports={windowForCutoff,upcomingWindow,inWindow,collectionBounds};
|
||||
Reference in new issue
Block a user