Files
order-notification-automation/web/modules/order-rules/preview.js
T

22 lines
5.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
(() => {
'use strict';
const labels={orderNo:'订单号',appDate:'申请日期',customer:'客户',productLine:'产品线',quantity:'数量',changeReason:'更改原因',changeContent:'更改内容',totalAmount:'总金额',brief:'订单摘要'};
const value=v=>v===undefined||v===null?'未取得':typeof v==='object'?JSON.stringify(v):String(v);
const plain=text=>String(text).replace(/connectionId/g,'BPM连接').replace(/instanceId/g,'流程编号').replace(/taskId/g,'待办编号').replace(/revision/g,'订单版本').replace(/processVersion/g,'表单版本').replace(/processName/g,'流程名称').replace(/nodeName/g,'节点名称').replace(/receivedAt/g,'接收时间').replace(/serialNum/g,'流水编号').replace(/orderNo/g,'订单号').replace(/quantity/g,'数量').replace(/source 必须为 todo(待办)/g,'订单必须来自 BPM 待办').replace(/字段适配器?/g,'订单识别配置').replace(/brief/g,'订单摘要');
function panel(sources,{esc,operator}){
return `<div class="rule-recognition-check"><label class="form-label" for="order-rule-sample-source">已采集的 BPM 订单</label><div class="d-flex flex-wrap gap-2"><select class="form-select flex-fill" id="order-rule-sample-source"><option value="">请选择真实订单</option>${sources.map(a=>`<option value="${esc(a.id)}">${esc(a.label)}</option>`).join('')}</select>${operator?`<button class="btn btn-primary" type="button" id="order-rule-preview" ${sources.length?'':'disabled'}>检查识别结果</button>`:''}</div><div id="rule-recognition-empty" class="rule-empty-recognition mt-3" ${sources.length?'hidden':''}><strong>本类别还没有真实订单可检查</strong><p class="small text-secondary mt-2 mb-0">先在<a href="#order-execution">订单执行</a>中采集 BPM 待办,再回到这里刷新。Excel 导入的是分类规则,不代替真实订单检查。</p></div><div id="order-rule-adapter" class="small text-secondary mt-2"></div><div id="order-rule-preview-result" class="mt-3" aria-live="polite"></div></div>`;
}
function adapter(a,{esc}){return a?`<span>${esc(a.processName)} · 表单 ${esc(a.sample?.processVersion||'待识别')} · 节点 ${esc(a.sample?.nodeName||'未取得')}</span>`:'';}
function result(r,{esc,ruleName=''}){
const trial=r.trial?`<div class="alert alert-${r.trial.publishEvidence?'success':'info'}">${r.trial.publishEvidence?'已保存规则通过真实订单检查,可以继续核对并发布。':r.trial.saved?'订单检查完成,请确认识别内容。':'这是尚未保存的配置结果;保存后请再次检查。'}</div>`:'';
const rows=(r.fieldTrace||[]).filter(f=>labels[f.key]);
const event=`<div class="rule-result-heading"><span class="badge bg-${r.valid?'green':'yellow'}-lt">${r.valid?'识别通过':'需要处理'}</span><strong>${esc(ruleName||'当前分类')}</strong></div>${rows.length?`<div class="table-responsive mt-3"><table class="table table-sm"><thead><tr><th>订单信息</th><th>识别内容</th></tr></thead><tbody>${rows.map(f=>`<tr><td>${esc(labels[f.key])}</td><td class="text-break">${esc(value(f.value))}</td></tr>`).join('')}</tbody></table></div>`:''}`;
const title=r.event?.rawTitle!==undefined?`<div class="mt-3"><strong class="small">从标题整理的订单内容</strong><pre class="rule-business-summary mt-2">${esc(r.event.brief||'未取得')}</pre>${r.event.factoryHints?.length?'<div class="alert alert-warning">识别到惠州相关信息,额外通知规则尚未确认,不会自动多发。</div>':''}<details><summary>查看 BPM 原始标题</summary><div class="text-break small mt-2">${esc(r.event.rawTitle)}</div></details></div>`:'';
const plan=r.effects;
const effects=plan?`<div class="rule-effect-preview mt-3"><h4>归档与邮件预览</h4><dl><dt>PDF 文件名</dt><dd>${esc(plan.filename||'请补全识别内容')}</dd><dt>PDF 存放位置</dt><dd>${esc(plan.path||'请在第03步选择存储位置')}</dd>${plan.mail?`<dt>邮件主题</dt><dd>${esc(plan.mail.subject)}</dd><dt>收件人</dt><dd>${esc(plan.mail.to.join(';'))}</dd><dt>抄送</dt><dd>${esc(plan.mail.cc.join(';')||'无')}</dd><dt>邮件附件</dt><dd>${esc(plan.mail.attachments.join(';')||'不附带 PDF')}</dd>`:''}</dl>${plan.mail?`<details><summary>查看邮件正文预览</summary><pre class="rule-business-summary mt-2">${esc(plan.mail.text)}</pre></details>`:''}<p class="small text-secondary mb-0 mt-3">仅预览,不生成文件或发信;实际归档时会检查目录权限和文件内容。</p>${plan.issues?.length?`<ul class="small text-warning mt-2">${plan.issues.map(v=>`<li>${esc(plain(v))}</li>`).join('')}</ul>`:''}</div>`:'';
return trial+event+title+effects+(r.issues?.length?`<div class="alert alert-warning mt-3"><strong>需要修复</strong><ul class="mb-0 mt-2">${r.issues.map(v=>`<li>${esc(plain(typeof v==='string'?v:v.message||v.detail||'订单信息不完整'))}</li>`).join('')}</ul><a href="#rule-fields">检查 BPM 信息识别配置</a></div>`:'');
}
function proposal(p,{esc,ruleName}){return '<div class="alert alert-info">当前订单只读预览 · 尚未保存/未执行;不作为发布凭据。</div><p class="small">分类状态:'+esc(({matched:'命中当前类别',candidate:'字段已识别,尚未加入此类别',history:'历史仅核字段',conflict:'分类冲突',none:'未命中'})[p.classification.status])+'</p>'+result({...p.recognition,valid:p.classification.status==='matched'&&p.recognition.valid,effects:p.effects,issues:p.blockedReasons},{esc,ruleName});}
window.OrderRulePreview={panel,adapter,result,proposal};
})();