refactor: separate notification distribution from field mapping
This commit is contained in:
1 parent
3748d05d96
commit
c53da6f025
25 files changed
+773
-118
No files matched your search
@@ -1,11 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
// Fixed field boundaries keep extraction deterministic; raw title stays on the event.
|
||||
const retained=new Set(['订单号','机芯号','产品型号','客户简称','总数量','订单类别']);
|
||||
const summaryKeys={'机芯号':'coreNo','产品型号':'productModel','客户简称':'customerShort','出货方式':'shippingMethod','总数量':'totalQuantity','订单类别':'orderCategory'};
|
||||
const retained=new Set(['订单号',...Object.keys(summaryKeys)]);
|
||||
function extractTitle(title){
|
||||
const raw=typeof title==='string'?title:'';
|
||||
const text=raw.replace(/<br\s*\/?\s*>/gi,'\n').replace(/ | | /gi,' ');
|
||||
const matches=[...text.matchAll(/(客户等级|毛利|订单号|机芯号|产品型号|客户简称|总数量|订单类别|订单类型|业务模式)\s*[::]/gu)];
|
||||
const matches=[...text.matchAll(/(客户等级|毛利|订单号|机芯号|产品型号|客户简称|出货方式|总数量|订单类别|订单类型|业务模式)\s*[::]/gu)];
|
||||
const orders=[],factoryHints=[],issues=[];let current=null;
|
||||
for(let i=0;i<matches.length;i++){
|
||||
const match=matches[i],label=match[1],value=text.slice(match.index+match[0].length,matches[i+1]?.index??text.length).trim();
|
||||
@@ -17,7 +18,7 @@ function extractTitle(title){
|
||||
current={orderNo:identifier,text:''};orders.push(current);
|
||||
if(!value)issues.push('标题中的订单号为空,不能遗漏该订单段落');
|
||||
}
|
||||
if(current&&retained.has(label))current.text+=`${label}:${value}`;
|
||||
if(current&&retained.has(label)){current.text+=`${label}:${value}`;if(summaryKeys[label])current[summaryKeys[label]]=value;}
|
||||
}
|
||||
if(!orders.length)issues.push('标题中没有可识别的“订单号:”段落');
|
||||
return {rawTitle:raw,orders,brief:orders.map(order=>order.text).join('\n'),factoryHints,issues};
|
||||
|
||||
Reference in new issue
Block a user