feat: refresh business home with Tabler workflow visuals

This commit is contained in:
abaishu0730 committed 2026-10-27 14:02:19 +08:00
1 parent 069a69af93
commit 1cacbec132
11 files changed
+165 -11

No files matched your search

+8
View File
@@ -132,6 +132,14 @@ function summary(context,user){
const count=(items,status)=>items.filter(i=>status.includes(i.status)).length;
result.scans=context.orderRules.all('execution-scans').filter(s=>canReadConnection(context.workspace,user,s.connectionId||s.id)).map(s=>pick(s,['id','connectionId','status','startedAt','finishedAt','rowCount','targetCount','error']));
result.counts={orders:rows.length,blocked:rows.filter(row=>['blocked','failed'].includes(row.status)||row.notifications?.huizhou?.status==='blocked').length,unknown:count(batches,['unknown']),activeBatches:count(batches,['collecting','prepared','sending','unknown','failed'])};
const authorized=new Set(batches),current=collecting.filter(batch=>authorized.has(batch));
result.home={
pendingOrders:new Set(current.flatMap(batch=>batch.orderIds||[])).size,
collectingBatches:current.length,
carriedOrders:new Set(current.flatMap(batch=>batch.carriedOrderIds||[])).size,
batches:current.slice(0,4).map(batch=>({id:batch.id,categoryId:batch.categoryId,categoryName:batch.ruleSnapshot?.name||batch.categoryId,notificationMode:modeOf(batch),orderCount:batch.orderIds?.length||0,carryCount:batch.carriedOrderIds?.length||0,cutoff:batch.cutoff,error:batch.error||null})),
lastScanAt:result.scans.filter(scan=>scan.status==='complete'&&Number.isFinite(Date.parse(scan.finishedAt))).sort((a,b)=>Date.parse(b.finishedAt)-Date.parse(a.finishedAt))[0]?.finishedAt||null
};
result.issues=data.issues.filter(issue=>!['resolved','retired'].includes(issue.status)).filter(issue=>user.role==='admin'||((issue.orderIds?.length||issue.taskIds?.length)&& (issue.orderIds||[]).every(id=>canReadOrder(context.workspace,user,context.orderRules.get('orders',id)))&&(issue.taskIds||[]).every(id=>canReadConnection(context.workspace,user,context.orderRules.get('execution-tasks',id)?.connectionId)))).slice(-50).map(i=>{const linked=context.workspace?.businessIssue?.(i.id);return pick(linked?{...i,status:linked.status,owner:linked.owner,exceptionId:linked.id}:i,['id','status','type','message','error','component','notificationMode','owner','owners','exceptionId','createdAt','batchId','orderIds','taskIds']);}).filter(i=>!['resolved','retired'].includes(i.status));
result.templateUsage=context.orderRules.all('rules').map(r=>({categoryId:r.published?.categoryId||r.draft?.categoryId,name:r.draft?.name,templateId:r.published?.bodyTemplateId||'',huizhouEnabled:r.published?.huizhouEnabled===true,huizhouTemplateId:r.published?.huizhouTemplateId||'',legacyBinding:!!r.published&&r.published.bodyTemplateId===undefined,publishedVersion:r.published?.version||null,status:r.published?.status||'draft'}));
result.revision=crypto.createHash('sha256').update(publicRevision(context,user)+JSON.stringify([result.window,result.issues])).digest('hex').slice(0,24);