feat: expose independent Huizhou notification controls and results

This commit is contained in:
abaishu0730 committed 2026-10-21 15:46:39 +08:00
1 parent c74ee87b0e
commit 90b7e50036
8 files changed
+116 -15

No files matched your search

+8 -3
View File
@@ -3,13 +3,18 @@ window.BusinessRecordDetail=(()=>{
function mount(container,{api,esc,formatDate,user,isActive,onChanged}){
const panel=window.RecordUi.details(container,'业务详情');let revision=0,controller;
const field=(label,value)=>window.RecordUi.field(esc,label,value);
const statuses={pending:'等待汇总',identified:'已识别',preparing:'准备归档',archived:'已归档',batched:'已编入批次',blocked:'受阻',failed:'失败',unknown:'结果待核实',sent:'已提交邮件服务器',prepared:'已冻结待发',sending:'发送中',cancelled:'已取消'};
const statuses={disabled:'未开启',empty:'无匹配惠州明细',not_applicable:'历史订单,不追加通知',ignored:'历史保留,不自动补发',pending:'等待汇总',identified:'已识别',preparing:'准备归档',archived:'已归档',batched:'已编入批次',blocked:'受阻',failed:'失败',unknown:'结果待核实',sent:'已提交邮件服务器',prepared:'已冻结待发',sending:'发送中',cancelled:'已取消'};
function form(action,label,options=''){return `<form data-business-action="${action}" class="mt-3"><h3 class="h4">${label}</h3>${options}<label class="form-label">操作依据<textarea name="note" class="form-control" minlength="5" maxlength="2000" required></textarea></label><button class="btn btn-primary" type="submit">${label}</button><div role="alert" class="small mt-2"></div></form>`;}
function notificationBody(mode,notice){
if(!notice)return '';
const batch=notice.batchId?'<a href="#notification-batches?scope=all&q='+encodeURIComponent(notice.batchId)+'">'+esc(notice.batchId)+'</a>':'尚未编入批次';
return '<section class="mt-3"><h3 class="h4">'+(mode==='huizhou'?'惠州通知':'普通通知')+'</h3><dl>'+field('状态',statuses[notice.status]||notice.status)+field('原因',notice.error)+(mode==='huizhou'?field('入选惠州订单',(notice.orderNos||[]).join('、')):'')+'<dt>邮件批次</dt><dd class="text-break">'+batch+'</dd></dl>'+(notice.issues?.length?'<ul class="small text-warning">'+notice.issues.map(issue=>'<li>'+esc(issue)+'</li>').join('')+'</ul>':'')+'</section>';
}
function orderBody(d){
const t=d.executionTask,e=d.event||{};
return `<h3 class="h4">处理进度</h3><dl>${field('订单',d.orderNo)}${field('状态',statuses[d.status]||d.status)}${field('原因',t?.error||d.error||d.reason)}${field('执行步骤',t?.step)}${field('执行任务',t?.id)}${field('规则版本',d.ruleVersion)}</dl><h3 class="h4">来源</h3><dl>${field('连接',d.connectionId)}${field('流程',e.processName)}${field('节点',e.nodeName)}${field('流程实例',e.instanceId)}${field('BPM任务',e.taskId)}${field('来源版本',e.revision)}${field('接收时间',formatDate(e.receivedAt))}</dl><h3 class="h4">PDF / 归档</h3><p>归档代次 ${esc(d.archiveGeneration)} · ${esc(formatDate(d.archivedAt))}</p>${d.files.map(f=>`<p><a href="${esc(f.url)}">${esc(f.name||'下载归档 PDF')}</a> · ${esc(f.size)} 字节</p>`).join('')||'<p class="text-secondary">尚无可验证归档文件</p>'}<h3 class="h4">邮件批次</h3>${d.batches.map(b=>`<p><a href="#notification-batches?scope=all&q=${encodeURIComponent(b.id)}">${esc(b.subject||b.id)}</a> · ${esc(statuses[b.status]||b.status)}</p>`).join('')||'<p class="text-secondary">尚未编入批次</p>'}${t?.exceptionId?`<a href="#exceptions?id=${encodeURIComponent(t.exceptionId)}">处理关联异常</a>`:''}${t?.revisionEvidence?`<h3 class="h4 mt-3">修订核对</h3><div class="table-responsive"><table class="table"><thead><tr><th>信息</th><th>原修订</th><th>新修订</th></tr></thead><tbody>${['revision','orderNo','title','receivedAt','processName','nodeName','quantity','brief'].map(key=>`<tr><td>${esc(key)}</td><td>${esc(t.revisionEvidence.previous[key]||'—')}</td><td>${esc(t.revisionEvidence.incoming[key]||'—')}</td></tr>`).join('')}</tbody></table></div>`:''}${user.role==='admin'&&t?.conflict&&!t.missedWindow&&!['unknown','sent','sending','batched'].includes(d.status)?form('revision','保存修订核对','<select name="resolution" class="form-select"><option value="adopt">采用新修订</option><option value="ignore">忽略该变更</option></select>'):''}${user.role!=='viewer'&&t&&!t.conflict&&!t.missedWindow&&['failed','blocked'].includes(t.status)?form('retry','重试失败任务'):''}`;
return `<h3 class="h4">处理进度</h3><dl>${field('订单',d.orderNo)}${field('状态',statuses[d.status]||d.status)}${field('原因',t?.error||d.error||d.reason)}${field('执行步骤',t?.step)}${field('执行任务',t?.id)}${field('规则版本',d.ruleVersion)}</dl>${notificationBody('normal',d.notifications?.normal)}${notificationBody('huizhou',d.notifications?.huizhou)}<h3 class="h4">来源</h3><dl>${field('连接',d.connectionId)}${field('流程',e.processName)}${field('节点',e.nodeName)}${field('流程实例',e.instanceId)}${field('BPM任务',e.taskId)}${field('来源版本',e.revision)}${field('接收时间',formatDate(e.receivedAt))}</dl><h3 class="h4">PDF / 归档</h3><p>归档代次 ${esc(d.archiveGeneration)} · ${esc(formatDate(d.archivedAt))}</p>${d.files.map(f=>`<p><a href="${esc(f.url)}">${esc(f.name||'下载归档 PDF')}</a> · ${esc(f.size)} 字节</p>`).join('')||'<p class="text-secondary">尚无可验证归档文件</p>'}<h3 class="h4">邮件批次</h3>${d.batches.map(b=>`<p><a href="#notification-batches?scope=all&q=${encodeURIComponent(b.id)}">${esc(b.subject||b.id)}</a> · ${b.notificationMode==='huizhou'?'惠州通知':'普通通知'} · ${esc(statuses[b.status]||b.status)}</p>`).join('')||'<p class="text-secondary">尚未编入批次</p>'}${t?.exceptionId?`<a href="#exceptions?id=${encodeURIComponent(t.exceptionId)}">处理关联异常</a>`:''}${t?.revisionEvidence?`<h3 class="h4 mt-3">修订核对</h3><div class="table-responsive"><table class="table"><thead><tr><th>信息</th><th>原修订</th><th>新修订</th></tr></thead><tbody>${['revision','orderNo','title','receivedAt','processName','nodeName','quantity','brief'].map(key=>`<tr><td>${esc(key)}</td><td>${esc(t.revisionEvidence.previous[key]||'—')}</td><td>${esc(t.revisionEvidence.incoming[key]||'—')}</td></tr>`).join('')}</tbody></table></div>`:''}${user.role==='admin'&&t?.conflict&&!t.missedWindow&&!['unknown','sent','sending','batched'].includes(d.status)?form('revision','保存修订核对','<select name="resolution" class="form-select"><option value="adopt">采用新修订</option><option value="ignore">忽略该变更</option></select>'):''}${user.role!=='viewer'&&t&&!t.conflict&&!t.missedWindow&&['failed','blocked'].includes(t.status)?form('retry','重试失败任务'):''}`;
}
function batchBody(d){return `<dl>${field('主题',d.subject)}${field('状态',statuses[d.status]||d.status)}${field('原因 / 超时说明',d.error)}${field('时段开始',formatDate(d.windowStart||d.window?.start))}${field('截止时间',formatDate(d.windowEnd||d.cutoff||d.window?.end))}${field('收件人',(d.to||[]).join('、'))}${field('抄送',(d.cc||[]).join('、'))}</dl><h3 class="h4">冻结正文</h3><pre class="notification-brief">${esc(d.text||'无正文')}</pre><h3 class="h4">冻结附件</h3>${d.attachments.map(a=>`<p>${esc(a.name||a.filename)} · ${esc(a.size||'—')} 字节</p>`).join('')||'无附件'}<h3 class="h4 mt-3">关联订单</h3>${d.orders.map(o=>`<p><a href="#notification-orders?q=${encodeURIComponent(o.id)}">${esc(o.orderNo||o.id)}</a></p>`).join('')}<p class="small text-secondary">SMTP 接受不代表最终送达。结果不明时必须先核验,不会自动补发。</p>${user.role==='admin'&&d.status==='unknown'?form('resolve','保存核验结论','<select name="resolution" class="form-select"><option value="sent">已核实邮件服务器接受</option><option value="retry">已核实未发送,允许重试</option></select>'):''}${user.role==='admin'&&d.status==='failed'?form('resend','人工补发原冻结批次'):''}`;}
function batchBody(d){return `<dl>${field('主题',d.subject)}${field('通知模式',d.notificationMode==='huizhou'?'惠州通知':'普通通知')}${field('类别',d.categoryId)}${field('状态',statuses[d.status]||d.status)}${field('原因 / 超时说明',d.error)}${field('时段开始',formatDate(d.windowStart||d.window?.start))}${field('截止时间',formatDate(d.windowEnd||d.cutoff||d.window?.end))}${field('收件人',(d.to||[]).join('、'))}${field('抄送',(d.cc||[]).join('、'))}</dl><h3 class="h4">冻结正文</h3><pre class="notification-brief">${esc(d.text||'无正文')}</pre><h3 class="h4">冻结附件</h3>${d.attachments.map(a=>`<p>${esc(a.name||a.filename)} · ${esc(a.size||'—')} 字节</p>`).join('')||'无附件'}<h3 class="h4 mt-3">关联订单</h3>${d.orders.map(o=>`<p><a href="#notification-orders?q=${encodeURIComponent(o.id)}">${esc(o.orderNo||o.id)}</a></p>`).join('')}<p class="small text-secondary">SMTP 接受不代表最终送达。结果不明时必须先核验,不会自动补发。</p>${user.role==='admin'&&d.status==='unknown'?form('resolve','保存核验结论','<select name="resolution" class="form-select"><option value="sent">已核实邮件服务器接受</option><option value="retry">已核实未发送,允许重试</option></select>'):''}${user.role==='admin'&&d.status==='failed'?form('resend','人工补发原冻结批次'):''}`;}
async function load(kind,id,trigger){
const request=++revision;controller?.abort();controller=new AbortController();panel.show('<p>正在加载详情…</p>',trigger);
try{const d=await api('/order-rules/'+kind+'/'+encodeURIComponent(id),undefined,{signal:controller.signal});if(!isActive()||request!==revision)return;
+2 -2
View File
@@ -3,13 +3,13 @@ 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'?['identified','preparing','archived','pending','batched','blocked','failed','unknown','sent','capturing','archiving','ignored']:['prepared','sending','unknown','failed','sent','cancelled'];
const labels={ignored:'历史保留,不自动补发',identified:'已识别',preparing:'准备归档',archived:'已归档',pending:'等待汇总',batched:'已编入批次',blocked:'受阻',failed:'失败',unknown:'待核实',sent:'已提交邮件服务器',capturing:'采集中',archiving:'归档中',prepared:'已冻结待发',sending:'发送中',cancelled:'已取消'};
const labels={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>`;
const input=(name,label,type='text')=>`<label class="small">${label}<input class="form-control" type="${type}" name="${name}" maxlength="200" value="${esc(filters[name]||'')}"></label>`;
container.innerHTML=`<div class="alert alert-warning" data-record-error hidden role="alert"></div><section class="card"><div class="card-header flex-wrap gap-2"><h2 class="card-title">${kind==='orders'?'订单中心':'邮件批次'}</h2><div class="btn-list ms-auto"></div></div><div class="card-body record-filters"><div class="row g-2"><div class="col-12 col-md-4">${input('q','搜索订单 / 标识 / 主题')}</div><div class="col-6 col-md-2">${select('categoryId','类别')}</div><div class="col-6 col-md-2">${select('connectionId','来源连接')}</div><div class="col-6 col-md-2"><label class="small">状态<select class="form-select" name="status"><option value="">全部状态</option>${states.map(s=>`<option value="${s}" ${filters.status===s?'selected':''}>${labels[s]}</option>`).join('')}</select></label></div>${kind==='batches'?`<div class="col-6 col-md-2"><label class="small">范围<select class="form-select" name="scope"><option value="active" ${filters.scope==='active'?'selected':''}>未终结批次</option><option value="all" ${filters.scope==='all'?'selected':''}>全部批次</option></select></label></div>`:''}<div class="col-6 col-md-3">${input('from',kind==='batches'?'窗口截止日期从(北京时间)':'接收日期从(北京时间)','date')}</div><div class="col-6 col-md-3">${input('to',kind==='batches'?'窗口截止日期至':'接收日期至','date')}</div><div class="col-12 col-md-2 align-self-end"><button class="btn" data-record-query type="button">查询</button></div></div></div><div data-arrival-list></div>${window.RecordUi.footer}</section>${kind==='orders'&&user.role!=='viewer'?'<section class="card mt-3"><div class="card-body"><h3 class="h4">扫描并处理订单</h3><p class="text-secondary">读取授权待办、采集真实字段、生成 PDF 并归档;BPM 节点由人工办理。邮件按独立开关和批次调度发送。</p><form data-business-scan><label class="form-label" for="business-scan-connection">扫描连接</label><select id="business-scan-connection" class="form-select" name="scanConnectionId" required><option value="">正在读取授权连接</option></select><button class="btn" type="submit">扫描并处理订单</button><div role="alert"></div></form></div></section>':''}`;
let table;const detail=window.BusinessRecordDetail.mount(container,{...options,onChanged:()=>{const error=container.querySelector('[data-record-error]');error.hidden=false;error.textContent='业务状态已变化,请刷新记录核对。';}});
function draw(data){const host=container.querySelector('[data-arrival-list]');host.innerHTML=`<div class="table-responsive"><table class="table table-vcenter card-table"><thead><tr><th>${kind==='orders'?'订单 / 类别':'主题 / 类别'}</th><th>状态与原因</th><th>接收 / 创建时间</th><th>详情</th></tr></thead><tbody>${data.items.map((row,index)=>`<tr><td class="text-break"><strong>${esc(row.orderNo||row.subject||row.id)}</strong><div class="small text-secondary">${esc(catalogs.categories.get(row.categoryId)||row.categoryId||'未分类')}</div></td><td>${esc(labels[row.status]||row.status)}<div class="small text-danger">${esc(row.error||row.reason||'')}</div></td><td class="small">${esc(formatDate(row.receivedAt||row.createdAt))}</td><td><button class="btn btn-sm" type="button" data-business-detail="${index}">查看详情</button></td></tr>`).join('')||'<tr><td colspan="4" class="text-secondary">暂无匹配记录</td></tr>'}</tbody></table></div>`;host.querySelectorAll('[data-business-detail]').forEach(button=>button.onclick=()=>detail.open(kind,data.items[Number(button.dataset.businessDetail)].id,button));}
function draw(data){const host=container.querySelector('[data-arrival-list]');host.innerHTML=`<div class="table-responsive"><table class="table table-vcenter card-table"><thead><tr><th>${kind==='orders'?'订单 / 类别':'主题 / 类别'}</th><th>状态与原因</th><th>接收 / 创建时间</th><th>详情</th></tr></thead><tbody>${data.items.map((row,index)=>`<tr><td class="text-break"><strong>${esc(row.orderNo||row.subject||row.id)}</strong><div class="small text-secondary">${esc(catalogs.categories.get(row.categoryId)||row.categoryId||'未分类')}</div>${kind==='batches'?'<span class="badge bg-blue-lt mt-1">'+(row.notificationMode==='huizhou'?'惠州通知':'普通通知')+'</span>':''}</td><td>${esc(labels[row.status]||row.status)}${kind==='orders'&&row.notifications?['normal','huizhou'].map(mode=>{const notice=row.notifications[mode];return notice?'<div class="small mt-1"><strong>'+(mode==='huizhou'?'惠州通知':'普通通知')+'</strong>:'+esc(labels[notice.status]||notice.status)+'<div class="text-danger text-break">'+esc(notice.error||'')+'</div>'+(notice.issues?.length?'<div class="text-warning text-break">'+notice.issues.map(esc).join(';')+'</div>':'')+'</div>':'';}).join(''):''}<div class="small text-danger text-break">${esc(row.reason||(!row.notifications?row.error:'')||'')}</div></td><td class="small">${esc(formatDate(row.receivedAt||row.createdAt))}</td><td><button class="btn btn-sm" type="button" data-business-detail="${index}">查看详情</button></td></tr>`).join('')||'<tr><td colspan="4" class="text-secondary">暂无匹配记录</td></tr>'}</tbody></table></div>`;host.querySelectorAll('[data-business-detail]').forEach(button=>button.onclick=()=>detail.open(kind,data.items[Number(button.dataset.businessDetail)].id,button));}
const names=Object.keys(filters).filter(k=>!['page','pageSize'].includes(k));
table=window.RecordTable.mount({view,container,isActive,api,endpoint:'/order-rules/'+kind,render:draw,readDraft:()=>Object.fromEntries(names.map(k=>[k,container.querySelector('[name="'+k+'"]').value.trim()])),writeDraft(next){for(const k of names)container.querySelector('[name="'+k+'"]').value=next[k];}});
const workspaceRead=api('/workspace');