diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md index 29216eb..8a32038 100644 --- a/docs/HANDOFF.md +++ b/docs/HANDOFF.md @@ -1,5 +1,12 @@ # 开发交接(2026-10-23) +## 2026-10-26 邮件批次待发送/已发送分离 + +- 邮件批次以 Tabler 页签提供待发送、已发送、全部;替代原范围下拉。待发送含收集中、已冻结、发送中、失败及结果待核实;已发送仅显示 sent,取消记录在全部中保留。 +- 修复默认 active 与 status=sent 相交导致历史不可见;服务端和地址状态均将该旧查询规范到 sent 范围。范围在权限筛选后分页,不改冻结正文、收件人、发送回执或发送行为。切换清除状态并回第一页,刷新/前后退恢复地址;点击当前页签不重复加载。 +- 批次列表和详情显示发送时间(缺失不造时间);已发送正文和订单详情继续可查,只读且不提供编辑/补发。实机核对当前业务批次表为空,邮箱存在两条独立 sends 回执,不伪造为业务批次历史。 +- 验证使用隔离批次与账号,未发送邮件、未办理 BPM、未调整自动处理或发信设置;相关查询/分页/导航/弹窗30项通过。用户三份本地业务设计草稿保持不动。 + ## 2026-10-26 订单采集失败修复与剩余边界 - 修复动态明细 datamap 包含合法隐藏列时被误判的问题:额外列必须有同表隐藏控件,且每条后端记录都确有对应列;仍拒绝跨表映射、不明确行关系及缺少可见字段。 diff --git a/src/modules/order-rules/query.cjs b/src/modules/order-rules/query.cjs index b05cdb4..085d59f 100644 --- a/src/modules/order-rules/query.cjs +++ b/src/modules/order-rules/query.cjs @@ -21,7 +21,8 @@ function filters(input={},kind){ for(const name of ['page','pageSize']){result[name]=Number(result[name]);if(!Number.isSafeInteger(result[name])||result[name]<1)fail('页码或分页大小无效。');} if(![25,50,100].includes(result.pageSize))fail('每页仅支持25、50或100条。'); if(result.status&&!(kind==='batches'?batchStates:orderStates).includes(result.status))fail('状态筛选无效。'); - if(kind==='batches'&&!['active','all'].includes(result.scope))fail('批次范围无效。'); + if(kind==='batches'&&!['active','sent','all'].includes(result.scope))fail('批次范围无效。'); + if(kind==='batches'&&result.status==='sent'&&result.scope==='active')result.scope='sent'; for(const key of ['q','categoryId','connectionId'])if(result[key]!==undefined&&(typeof result[key]!=='string'||result[key].length>200))fail('查询内容过长或无效。'); for(const key of ['from','to'])if(result[key]&&(!/^\d{4}-\d{2}-\d{2}$/.test(result[key])||!Number.isFinite(Date.parse(result[key]))||new Date(result[key]).toISOString().slice(0,10)!==result[key]))fail('日期筛选无效。'); if(result.from&&result.to&&result.from>result.to)fail('开始日期不能晚于结束日期。'); @@ -90,11 +91,11 @@ 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','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),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); - const rows=[...data.batches,...require('./collecting-batches.cjs').list(context.orderRules)].filter(b=>canReadBatch(context.workspace,user,b,context.orderRules)&&(f.scope==='all'||!['sent','cancelled'].includes(b.status))).map(b=>batchRow(context,b)); + const rows=[...data.batches,...require('./collecting-batches.cjs').list(context.orderRules)].filter(b=>canReadBatch(context.workspace,user,b,context.orderRules)&&(f.scope==='all'||(f.scope==='sent'?b.status==='sent':!['sent','cancelled'].includes(b.status)))).map(b=>batchRow(context,b)); return page(rows,f,crypto.createHash('sha256').update(publicRevision(context,user)+JSON.stringify(rows)).digest('hex').slice(0,24)); } function orderDetail(context,id,user){ diff --git a/tests/order-rules/batch-history-ui.test.cjs b/tests/order-rules/batch-history-ui.test.cjs new file mode 100644 index 0000000..e45e0ed --- /dev/null +++ b/tests/order-rules/batch-history-ui.test.cjs @@ -0,0 +1,15 @@ +'use strict'; +const test=require('node:test'),assert=require('node:assert/strict'); +const {orderDrivenUI}=require('../fixtures/order-driven-ui.cjs'); +test('batch tabs separate sent history, survive reload/back and keep sent content read-only',{timeout:60000},async t=>{ + const {page,runtime,base,sample}=await orderDrivenUI(t,'#notification-batches'),s=runtime.orderRules; + s.put('orders',{id:'history-order',categoryId:'bs-change',orderNo:'HISTORY-1',status:'sent',sample:{connectionId:sample.connectionId},event:{connectionId:sample.connectionId}}); + for(const [id,status]of [['pending-batch','prepared'],['sent-batch','sent'],['cancelled-batch','cancelled']])s.put('batches',{id,status,version:1,orderIds:['history-order'],orderNos:['HISTORY-1'],categoryId:'bs-change',subject:id,createdAt:'2026-10-26T02:00:00Z',sentAt:status==='sent'?'2026-10-26T03:00:00Z':undefined,text:'Frozen body',to:['2639266652@qq.com'],cc:[],attachments:[]}); + await page.getByRole('button',{name:'刷新数据',exact:true}).click(); + const pending=page.getByRole('tab',{name:'待发送',exact:true}),sent=page.getByRole('tab',{name:'已发送',exact:true});await pending.waitFor();await page.getByText('pending-batch',{exact:true}).waitFor();assert.equal(await page.getByText('sent-batch',{exact:true}).count(),0); + await sent.click();await page.getByText('sent-batch',{exact:true}).waitFor();assert.match(page.url(),/scope=sent/);assert.equal(await sent.getAttribute('aria-selected'),'true');assert.equal(await page.getByText('pending-batch',{exact:true}).count(),0); + await page.getByRole('button',{name:'查看详情',exact:true}).click();const dialog=page.getByRole('dialog',{name:'业务详情',exact:true});await dialog.getByText('Frozen body',{exact:true}).waitFor();await dialog.getByText('发送时间',{exact:true}).waitFor();assert.equal(await dialog.getByRole('button',{name:'保存批次内容',exact:true}).count(),0);assert.equal(await dialog.getByRole('button',{name:'人工补发原冻结批次',exact:true}).count(),0);await dialog.getByRole('button',{name:'关闭详情',exact:true}).click(); + await page.reload();await page.getByText('sent-batch',{exact:true}).waitFor();await page.getByRole('tab',{name:'待发送',exact:true}).click();await page.getByText('pending-batch',{exact:true}).waitFor();await page.goBack();await page.getByText('sent-batch',{exact:true}).waitFor(); + await page.goto(base+'/#notification-batches?status=sent');await page.getByText('sent-batch',{exact:true}).waitFor();assert.equal(await page.getByRole('tab',{name:'已发送',exact:true}).getAttribute('aria-selected'),'true'); + await page.getByRole('tab',{name:'全部',exact:true}).click();await page.getByText('cancelled-batch',{exact:true}).waitFor(); +}); diff --git a/tests/order-rules/query.test.cjs b/tests/order-rules/query.test.cjs index 67928c8..ab47355 100644 --- a/tests/order-rules/query.test.cjs +++ b/tests/order-rules/query.test.cjs @@ -60,6 +60,16 @@ test('batch pagination covers more than three pages and scope all retains comple const c=fixture();for(let i=0;i<85;i++)c.orderRules.all('batches').push({id:'b'+i,orderIds:['o0'],status:i===0?'sent':'prepared',subject:'Batch '+i}); const active=queryBatches(c,{page:999,pageSize:25},user);assert.equal(active.page,4);assert.equal(active.total,85);assert.equal(active.items.length,10);assert.equal(queryBatches(c,{scope:'all'},user).total,86); }); + +test('sent batches have a dedicated history scope and status-only links never hide sent records',()=>{ + const c=fixture(),batches=c.orderRules.all('batches'); + batches.push({id:'delivered',orderIds:['o0'],status:'sent',subject:'Sent notice',sentAt:'2026-10-26T03:00:00Z'},{id:'cancelled',orderIds:['o0'],status:'cancelled'},{id:'private-sent',orderIds:['foreign'],status:'sent'}); + const history=queryBatches(c,{scope:'sent'},user);assert.deepEqual(history.items.map(b=>b.id),['delivered']);assert.equal(history.items[0].sentAt,'2026-10-26T03:00:00Z'); + assert.deepEqual(queryBatches(c,{status:'sent'},user).items.map(b=>b.id),['delivered']); + assert.deepEqual(queryBatches(c,{},user).items.map(b=>b.id),['old']); + assert.equal(queryBatches(c,{scope:'all'},user).total,3); + assert.equal(queryBatches(c,{scope:'sent',status:'unknown'},user).total,0); +}); test('HTTP query routing rejects missing services, invalid parameters and malformed encoding',async()=>{ const {orderRuleQueryApi}=require('../../src/modules/order-rules/query-api.cjs');const c=fixture(),invoke=(route,extra={})=>orderRuleQueryApi({...c,user,route,method:'GET',url:new URL(route,'http://localhost'),reply(){},...extra}); await assert.rejects(()=>invoke('/api/order-rules/orders?unused=1',{route:'/api/order-rules/orders'}),e=>e.status===400||e.statusCode===400); diff --git a/web/modules/order-notifications/detail.js b/web/modules/order-notifications/detail.js index cc4eed5..0966e10 100644 --- a/web/modules/order-notifications/detail.js +++ b/web/modules/order-notifications/detail.js @@ -23,7 +23,7 @@ window.BusinessRecordDetail=(()=>{ if(d.status==='candidate')return '
当前流程或节点未命中 Excel 通知规则,不会归档或发送邮件。
${esc(e.brief||e.title||'未取得摘要')}归档代次 ${esc(d.archiveGeneration)} · ${esc(formatDate(d.archivedAt))}
${d.files.map(f=>`${esc(f.name||'下载归档 PDF')} · ${esc(f.size)} 字节
`).join('')||'尚无可验证归档文件
'}· ${b.notificationMode==='huizhou'?'惠州通知':'普通通知'} · ${esc(statuses[b.status]||b.status)}
`).join('')||'尚未编入批次
'}${t?.exceptionId?`处理关联异常`:''}${t?.revisionEvidence?`| 信息 | 原修订 | 新修订 |
|---|---|---|
| ${esc(key)} | ${esc(t.revisionEvidence.previous[key]||'—')} | ${esc(t.revisionEvidence.incoming[key]||'—')} |
${esc(d.text||'无正文')}${esc(a.name||a.filename)} · ${esc(a.size||'—')} 字节
`).join('')||'无附件'}SMTP 接受不代表最终送达。结果不明时必须先核验,不会自动补发。
${user.role==='admin'&&d.status==='unknown'?form('resolve','保存核验结论',''):''}${user.role==='admin'&&d.status==='failed'?form('resend','人工补发原冻结批次'):''}`;} + function batchBody(d){return `${esc(d.text||'无正文')}${esc(a.name||a.filename)} · ${esc(a.size||'—')} 字节
`).join('')||'无附件'}SMTP 接受不代表最终送达。结果不明时必须先核验,不会自动补发。
${user.role==='admin'&&d.status==='unknown'?form('resolve','保存核验结论',''):''}${user.role==='admin'&&d.status==='failed'?form('resend','人工补发原冻结批次'):''}`;} async function load(kind,id,trigger,back=null){ const request=++revision;editor?.dispose();controller?.abort();controller=new AbortController();panel.show('正在加载详情…
',trigger); try{const d=await api('/order-rules/'+kind+'/'+encodeURIComponent(id),undefined,{signal:controller.signal});if(!isActive()||request!==revision)return; diff --git a/web/modules/order-notifications/records.js b/web/modules/order-notifications/records.js index af30c36..673dae3 100644 --- a/web/modules/order-notifications/records.js +++ b/web/modules/order-notifications/records.js @@ -7,11 +7,20 @@ window.BusinessRecordViews=(()=>{ const catalogs={categories:new Map(),connections:new Map()}; const select=(name,label)=>``; const input=(name,label,type='text')=>``; - container.innerHTML=`读取授权待办、采集真实字段、生成 PDF 并归档;BPM 节点由人工办理。邮件按独立开关和批次调度发送。
读取授权待办、采集真实字段、生成 PDF 并归档;BPM 节点由人工办理。邮件按独立开关和批次调度发送。
| ${kind==='orders'?'订单 / 类别':'主题 / 类别'} | 状态与原因 | 接收 / 创建时间 | 详情 |
|---|---|---|---|
| ${esc(row.orderNo||row.subject||row.id)} ${esc(catalogs.categories.get(row.categoryId)||row.categoryName||row.categoryId||'未分类')} ${row.testRunId?'受限测试':''}${kind==='batches'?''+Number(row.orderCount||0)+' 个订单 · '+esc(formatDate(row.windowEnd||row.cutoff))+' 截止 ':(row.collectingBatches||[]).map(b=>'').join('')}${kind==='batches'?''+(row.notificationMode==='huizhou'?'惠州通知':'普通通知')+'':''} | ${esc(labels[row.status]||row.status)}${kind==='orders'&&row.notifications?['normal','huizhou'].map(mode=>{const notice=row.notifications[mode];return notice?' '+(mode==='huizhou'?'惠州通知':'普通通知')+':'+esc(labels[notice.status]||notice.status)+' ':'';}).join(''):''}'+esc(notice.error||'')+' '+(notice.issues?.length?''+notice.issues.map(esc).join(';')+' ':'')+'${esc(row.error||row.reason||'')} | ${esc(formatDate(row.receivedAt||row.createdAt))} | |
| 暂无匹配记录 | |||
| ${kind==='orders'?'订单 / 类别':'主题 / 类别'} | 状态与原因 | ${kind==='batches'?'创建 / 发送时间':'接收 / 创建时间'} | 详情 |
|---|---|---|---|
| ${esc(row.orderNo||row.subject||row.id)} ${esc(catalogs.categories.get(row.categoryId)||row.categoryName||row.categoryId||'未分类')} ${row.testRunId?'受限测试':''}${kind==='batches'?''+Number(row.orderCount||0)+' 个订单 · '+esc(formatDate(row.windowEnd||row.cutoff))+' 截止 ':(row.collectingBatches||[]).map(b=>'').join('')}${kind==='batches'?''+(row.notificationMode==='huizhou'?'惠州通知':'普通通知')+'':''} | ${esc(labels[row.status]||row.status)}${kind==='orders'&&row.notifications?['normal','huizhou'].map(mode=>{const notice=row.notifications[mode];return notice?' '+(mode==='huizhou'?'惠州通知':'普通通知')+':'+esc(labels[notice.status]||notice.status)+' ':'';}).join(''):''}'+esc(notice.error||'')+' '+(notice.issues?.length?''+notice.issues.map(esc).join(';')+' ':'')+'${esc(row.error||row.reason||'')} | ${esc(formatDate(row.receivedAt||row.createdAt))}${kind==='batches'&&row.status==='sent'?' 发送:'+esc(formatDate(row.sentAt||row.resolvedAt)||'未记录')+' ':''} | |
| 暂无匹配记录 | |||