feat: persist captured order execution and controlled batch resend

This commit is contained in:
abaishu0730 committed 2026-10-19 13:37:32 +08:00
1 parent b8cb1e11c6
commit 20589dd950
12 files changed
+419 -42

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
'use strict';
const {fail}=require('../order-rules/validation.cjs');
async function orderExecutionApi({execution,orderRules,dispatcher,workspace,user,sessionId,route,method,body,reply}){
const task=/^\/api\/order-execution\/tasks\/([\w-]+)\/retry$/.exec(route),resend=/^\/api\/order-rules\/batches\/([\w-]+)\/resend$/.exec(route);
if(!route.startsWith('/api/order-execution')&&!['/api/order-rules/fields','/api/order-rules/adapters'].includes(route)&&!resend)return false;
if(!execution||!orderRules)fail('订单执行服务未启动。',503);
if(method==='GET'&&route==='/api/order-execution'){reply(200,execution.snapshot({user,sessionId}));return true;}
if(method==='GET'&&route==='/api/order-rules/fields'){reply(200,execution.snapshot({user,sessionId}).fields);return true;}
if(method!=='POST')fail('未找到执行操作。',404);
if(user?.role==='viewer')fail('只读成员不能执行此操作。',403);
const principal={user,sessionId};let result;
if(route==='/api/order-execution/scan'){
if(!body||Object.keys(body).some(k=>!['connectionId','idempotencyKey'].includes(k)))fail('扫描参数无效。');result=await execution.scan(body,principal);
}else if(task){if(!body||Object.keys(body).some(k=>!['version','idempotencyKey','note'].includes(k)))fail('重试参数无效。');result=await execution.retry(task[1],body,principal);}
else{
if(user?.role!=='admin')fail('仅管理员可维护字段适配或人工补发。',403);
if(route==='/api/order-rules/adapters')result=orderRules.saveAdapter(body,user);
else if(resend){if(!dispatcher)fail('分类发信服务未启动。',503);if(!body||Object.keys(body).some(k=>!['version','idempotencyKey','note'].includes(k)))fail('补发参数无效。');result=await dispatcher.resend(resend[1],body,user);}
else fail('未找到执行操作。',404);
}
workspace?.record?.(user,'维护订单执行',route);reply(200,result);return true;
}
module.exports={orderExecutionApi};