MVP底座④:统一报价 1:1 流程包单实例 —— 四域物化,种子整体切换

14 语义节点/16 边:A5 是内置审批点(驳回走 reject 声明 reopen A4),
G2 的两条互斥分支显式汇合于 G2J —— 隐式合并过不了闭合校验(实测)。
顺手修 graph-to-pkg:卡点带 to 时还原成语义边,否则回边画成卡点一存盘就没了。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
This commit is contained in:
2026-07-28 01:49:49 +08:00
co-authored by Claude Fable 5
parent 90ca92aa0e
commit 0fe5222f79
7 changed files with 662 additions and 356 deletions
+387
View File
@@ -0,0 +1,387 @@
/**
* 「统一报价」流程包 —— 与 `docs/MVP示例工作流.html` 的 FIG.1 一比一。
*
* 语义 14 节点:起点 · A1 · G1 · A2 · G2 · A3 · G2J · A4 · **A5 审批点** · A6 · G4 · A7 · 双终点。
* 手绘几何(`diagram`)逐点取自 MVP 的 SVG:节点坐标与折线路径原样搬,
* x 统一去掉 4.7 的偏移吸附到 10px 珊格,y 不动 —— 图看起来就是那张图。
*
* 两处与 MVP 图的**语义同构、呈现有别**(已与用户确认):
* · A5 定价审批是**内置审批点**(审批不是任务,零开发、不入活动库);
* · 因此 MVP 图上的 G3「审批结果」被审批点吸收 —— 通过走出边,驳回走 `reject` 声明,
* 图上仍以「退回调整→A4」卡点标出那条路。全图因此少一颗菱形。
* · 反过来多一颗:G2 的两条互斥分支必须显式汇合于 G2J —— MVP 图把它画成两条线各扎进 A4,
* 语义上那是隐式合并,闭合校验不收(见下 joinNode 注释)。
*
* 回边的画法:MVP 用**卡点**表示回跳(不画长线)。卡点带 `to`,
* `mergeGraphIntoPackage` 会把「X → 卡点(to: Y)」还原成语义边 X→Y,所以编辑器保存不丢回边。
*/
import { processPackageSchema, triggerConfigSchema } from '@contracts';
import type { ProcessPackage } from '@contracts';
import type { Container } from './container.ts';
/** 活动节点:岗位独任、失败即终止 —— 槽位期不谈容忍 */
const activityNode = (
id: string,
label: string,
activityId: string,
position: string,
col: number,
row: number,
x: number,
y: number,
) => ({
id,
kind: 'activity' as const,
label,
sub: position,
activityId,
owner: { position, strategy: 'sole' as const },
failure: { kind: 'terminate' as const },
layout: { row, col, x, y },
});
/** 判断网关:异或分叉,判据人读、条件在出边 */
const gatewayNode = (id: string, label: string, basis: string, col: number, row: number, x: number, y: number) => ({
id,
kind: 'gateway' as const,
label,
gateway: 'exclusive' as const,
mode: 'fork' as const,
basis,
layout: { row, col, x, y },
});
/**
* 异或汇合点 —— 两条互斥分支重新并回一条路。
*
* MVP 图上这里是两条线各自扎进 A4(隐式合并);语义上必须显式:
* 不给汇合点,A4 就有两条同名映射的入边,闭合校验按「不做隐式合并」拦下(实测)。
* 分叉必有汇合是 BPMN 的正解,本仓 v1 的 G2/G2J 即此先例。
*/
const joinNode = (id: string, label: string, col: number, row: number, x: number, y: number) => ({
id,
kind: 'gateway' as const,
label,
gateway: 'exclusive' as const,
mode: 'join' as const,
layout: { row, col, x, y },
});
/** 受理口的两枚去向旗与记录 —— A4 重新入场(回边 / 驳回)时照此装配 */
const REENTER_A4 = [
{ target: 'records', source: { from: 'output-port' as const, port: 'intake', path: 'records' } },
{ target: 'customerCode', source: { from: 'initiation' as const, path: 'customerCode' } },
];
export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
id: 'unified-quote',
name: '统一报价',
version: 1,
state: 'draft',
callInterface: {
input: {
type: 'object',
required: ['customerCode', 'rfqRef'],
properties: {
customerCode: { type: 'string' },
rfqRef: { type: 'string' },
subject: { type: 'string' },
body: { type: 'string' },
quotedAt: { type: 'string' },
},
},
output: { type: 'object', properties: { landingRate: { type: 'number' } } },
},
nodes: [
{ id: 'start', kind: 'start', label: '客户RFQ询价', layout: { row: 0, col: 0, x: 30, y: 70 } },
activityNode('A1', '客户RFQ受理', 'rfq-intake', 'BD', 1, 0, 150, 60),
gatewayNode('G1', '是否需要选型', '受理判定:该条是否要先选替代料(needAlternative)', 2, 0, 290, 60),
activityNode('A2', '替代选型', 'alt-selection', 'FAE', 3, 0, 390, 60),
gatewayNode('G2', '是否需要寻源', '受理判定:该条是否要向渠道询底价(needSourcing)', 4, 0, 550, 60),
activityNode('A3', '寻源询价', 'sourcing-inquiry', 'PRM', 5, 0, 660, 60),
joinNode('G2J', '寻源汇合', 6, 0, 760, 150),
activityNode('A4', '成本定价', 'cost-pricing', 'BD', 7, 0, 810, 60),
{
id: 'A5',
kind: 'approval',
label: '定价审批',
sub: 'PM',
approver: { position: 'PM', strategy: 'sole' },
// 驳回走向声明式,不由临场决定:退回 A4 重新定价(图上「退回调整→A4」卡点即此)
reject: { kind: 'reopen', nodeId: 'A4', mapping: REENTER_A4 },
nudge: { steps: [{ after: 'PT20M', action: 'nudge' }], deadline: 'PT30M' },
layout: { row: 1, col: 6, x: 810, y: 260 },
},
activityNode('A6', '报价议价', 'quote-negotiation', 'BD', 3, 1, 370, 260),
gatewayNode('G4', '议价结果', 'A6 办结的去向:成交 / 有异议 / 拒绝或超时(outcome)', 2, 1, 180, 260),
activityNode('A7', '情报归档', 'intel-archive', 'BD', 1, 2, 150, 170),
{ id: 'end_won', kind: 'end', label: '转订单履约', layout: { row: 1, col: 0, x: 30, y: 270 } },
{ id: 'end_arch', kind: 'end', label: '归档闭环', layout: { row: 2, col: 0, x: 30, y: 180 } },
],
edges: [
{
id: 'e-start-a1',
from: 'start',
to: 'A1',
mapping: [
{ target: 'customerCode', source: { from: 'initiation', path: 'customerCode' } },
{ target: 'rfqRef', source: { from: 'initiation', path: 'rfqRef' } },
// 主题与正文是归一步唯一的原始素材:只给单号,模型没有可拆解的东西
{ target: 'subject', source: { from: 'initiation', path: 'subject' } },
{ target: 'body', source: { from: 'initiation', path: 'body' } },
{ target: 'quotedAt', source: { from: 'initiation', path: 'quotedAt' } },
],
reopen: false,
},
{ id: 'e-a1-g1', from: 'A1', to: 'G1', mapping: [], label: '统一受理记录', reopen: false },
{
id: 'e-g1-a2',
from: 'G1',
to: 'A2',
condition: 'needAlternative = true',
label: '需要选型',
mapping: [
{ target: 'material', source: { from: 'output-port', port: 'intake', path: 'pn' } },
// 选型完了还要不要寻源,这枚旗得跟着走 —— G2 在本路径上读的是 A2 的载荷
{ target: 'needSourcing', source: { from: 'output-port', port: 'intake', path: 'needSourcing' } },
],
reopen: false,
},
{ id: 'e-g1-g2', from: 'G1', to: 'G2', condition: 'needAlternative = false', label: '不需要选型', mapping: [], reopen: false },
{ id: 'e-a2-g2', from: 'A2', to: 'G2', mapping: [], label: '替代对标表', reopen: false },
{
id: 'e-g2-a3',
from: 'G2',
to: 'A3',
condition: 'needSourcing = true',
label: '需要寻源',
mapping: [{ target: 'pn', source: { from: 'output-port', port: 'intake', path: 'pn' } }],
reopen: false,
},
{
id: 'e-g2-j',
from: 'G2',
to: 'G2J',
condition: 'needSourcing = false',
label: '不需要寻源',
mapping: [],
reopen: false,
},
{ id: 'e-a3-j', from: 'A3', to: 'G2J', mapping: [], label: '供应商底价表', reopen: false },
{
id: 'e-j-a4',
from: 'G2J',
to: 'A4',
mapping: [
...REENTER_A4,
// 底价只在寻源那条路上有;直通路径取不到即为空,A4 的 floors 非必填
{ target: 'floors', source: { from: 'output-port', port: 'compare', path: 'floors' } },
],
reopen: false,
},
{ id: 'e-a4-a5', from: 'A4', to: 'A5', mapping: [], label: '报价草案提审', reopen: false },
{
id: 'e-a5-a6',
from: 'A5',
to: 'A6',
label: '通过',
tone: 'ok',
mapping: [
{ target: 'rows', source: { from: 'output-port', port: 'draft', path: 'rows' } },
{ target: 'quote_no', source: { from: 'output-port', port: 'draft', path: 'quote_no' } },
{ target: 'customerCode', source: { from: 'initiation', path: 'customerCode' } },
],
reopen: false,
},
{ id: 'e-a6-g4', from: 'A6', to: 'G4', mapping: [], label: '正式报价单', reopen: false },
{
id: 'e-g4-won',
from: 'G4',
to: 'end_won',
condition: 'outcome = "won"',
label: '成交',
tone: 'ok',
mapping: [],
reopen: false,
},
{
id: 'e-g4-a4',
from: 'G4',
to: 'A4',
condition: 'outcome = "revise"',
label: '有异议',
tone: 'bad',
mapping: REENTER_A4,
// 回边:人裁决后重开新任务实例(同节点、新任务 ID、留痕关联)
reopen: true,
},
{
id: 'e-g4-a7',
from: 'G4',
to: 'A7',
condition: 'outcome = "lost"',
label: '拒绝/超时',
tone: 'bad',
mapping: [
{ target: 'outcome', source: { from: 'output-port', port: 'formal', path: 'outcome' } },
{ target: 'quote_no', source: { from: 'output-port', port: 'formal', path: 'quote_no' } },
{ target: 'customer_code', source: { from: 'output-port', port: 'formal', path: 'customer_code' } },
{ target: 'quotedAt', source: { from: 'initiation', path: 'quotedAt' } },
],
reopen: false,
},
{ id: 'e-a7-end', from: 'A7', to: 'end_arch', mapping: [], label: '归档闭环', reopen: false },
],
variables: [],
/*
* 手绘几何存证 —— 呈现以它为真相(不走自动布局)。
* 坐标与折线取自 MVP 的 SVG;卡点是回跳的呈现(带 to,不画长线)。
*/
diagram: {
manual: true,
rows: [],
anchors: [],
nodes: [
{ id: 'start', kind: 'start', label: '客户RFQ询价', x: 30, y: 70, lx: 44, ly: 104 },
{ id: 'A1', kind: 'activity', label: '客户RFQ受理', code: 'A1', owner: 'BD', x: 150, y: 60 },
{ id: 'G1', kind: 'gateway', label: '是否需要选型', mode: 'x', x: 290, y: 60, lx: 314, ly: 130 },
{ id: 'A2', kind: 'activity', label: '替代选型', code: 'A2', owner: 'FAE', flavor: 'case', x: 390, y: 60 },
{ id: 'G2', kind: 'gateway', label: '是否需要寻源', mode: 'x', x: 550, y: 60, lx: 574, ly: 130 },
{ id: 'A3', kind: 'activity', label: '寻源询价', code: 'A3', owner: 'PRM', flavor: 'case', x: 660, y: 60 },
{ id: 'G2J', kind: 'gateway', label: '寻源汇合', mode: 'x', x: 760, y: 150, lx: 780, ly: 205 },
{ id: 'A4', kind: 'activity', label: '成本定价', code: 'A4', owner: 'BD', x: 810, y: 60 },
{ id: 'A5', kind: 'activity', label: '定价审批', code: 'A5', owner: 'PM', flavor: 'approval', x: 810, y: 260 },
{ id: 'A6', kind: 'activity', label: '报价议价', code: 'A6', owner: 'BD', flavor: 'case', x: 370, y: 260 },
{ id: 'G4', kind: 'gateway', label: '议价结果', mode: 'x', x: 180, y: 260, lx: 234, ly: 314 },
{ id: 'A7', kind: 'activity', label: '情报归档', code: 'A7', owner: 'BD', x: 150, y: 170 },
{ id: 'end_won', kind: 'end', label: '转订单履约', x: 30, y: 270, lx: 44, ly: 304 },
{ id: 'end_arch', kind: 'end-bad', label: '归档闭环', x: 30, y: 180, lx: 44, ly: 214 },
{ id: 'c_reject', kind: 'callout', label: '退回调整', to: 'A4', x: 590, y: 370 },
{ id: 'c_revise', kind: 'callout', label: '返回调整', to: 'A4', x: 150, y: 370 },
],
edges: [
{ from: 'start', to: 'A1', points: [{ x: 50, y: 80 }, { x: 150, y: 80 }] },
{ from: 'A1', to: 'G1', points: [{ x: 250, y: 80 }, { x: 290, y: 80 }] },
{ from: 'G1', to: 'A2', label: '需要选型', points: [{ x: 330, y: 80 }, { x: 390, y: 80 }] },
{
from: 'G1',
to: 'G2',
label: '不需要选型',
points: [{ x: 310, y: 60 }, { x: 310, y: 20 }, { x: 570, y: 20 }, { x: 570, y: 60 }],
},
{ from: 'A2', to: 'G2', points: [{ x: 490, y: 80 }, { x: 550, y: 80 }] },
{ from: 'G2', to: 'A3', label: '需要寻源', points: [{ x: 590, y: 80 }, { x: 660, y: 80 }] },
{
from: 'G2',
to: 'G2J',
label: '不需要寻源',
points: [{ x: 570, y: 100 }, { x: 570, y: 170 }, { x: 760, y: 170 }],
},
{ from: 'A3', to: 'G2J', points: [{ x: 710, y: 100 }, { x: 710, y: 170 }, { x: 760, y: 170 }] },
{ from: 'G2J', to: 'A4', points: [{ x: 800, y: 170 }, { x: 860, y: 170 }, { x: 860, y: 100 }] },
{
from: 'A4',
to: 'A5',
points: [{ x: 910, y: 80 }, { x: 990, y: 80 }, { x: 990, y: 280 }, { x: 910, y: 280 }],
},
// 审批通过:MVP 图上这条线经过 G3 的位置,G3 被审批点吸收后连成一条
{ from: 'A5', to: 'A6', label: '通过', tone: 'ok', points: [{ x: 810, y: 280 }, { x: 470, y: 280 }] },
// 审批驳回:走 reject 声明,图上以卡点标出(不画到 A4 的长线)
{
from: 'A5',
to: 'c_reject',
label: '不通过',
tone: 'bad',
points: [{ x: 860, y: 300 }, { x: 860, y: 340 }, { x: 640, y: 340 }, { x: 640, y: 370 }],
},
{ from: 'A6', to: 'G4', points: [{ x: 370, y: 280 }, { x: 220, y: 280 }] },
{ from: 'G4', to: 'end_won', label: '成交', tone: 'ok', points: [{ x: 180, y: 280 }, { x: 50, y: 280 }] },
{ from: 'G4', to: 'c_revise', label: '有异议', tone: 'bad', points: [{ x: 200, y: 300 }, { x: 200, y: 370 }] },
{ from: 'G4', to: 'A7', label: '拒绝/超时', tone: 'bad', points: [{ x: 200, y: 260 }, { x: 200, y: 210 }] },
{ from: 'A7', to: 'end_arch', points: [{ x: 150, y: 190 }, { x: 50, y: 190 }] },
],
},
});
/** 事件触发器:投进公司询价邮箱且主题含询价/RFQ 的自动起单 */
const TRIGGER_EVENT = triggerConfigSchema.parse({
id: 'trg-rfq',
name: '客户RFQ询价',
enabled: true,
processPackageId: 'unified-quote',
mapping: [
{ target: 'customerCode', source: { from: 'expression', sfeel: 'keys.customerCode' } },
{ target: 'rfqRef', source: { from: 'expression', sfeel: 'keys.rfqRef' } },
{ target: 'subject', source: { from: 'expression', sfeel: 'subject' } },
{ target: 'body', source: { from: 'expression', sfeel: 'body' } },
// 单据日期取入站时刻:`intel.history_price` 的主键是 (pn, quoted_at),归档拿不到日期就写不进去
{ target: 'quotedAt', source: { from: 'expression', sfeel: 'occurredAt' } },
],
// 按**通道**收口:同一封信投到「询价待确认邮箱」不命中,落人工确认那条路
spec: {
kind: 'event',
rule: 'channelId = "ch-rfq-mail" and (contains(subject, "询价") or contains(subject, "RFQ"))',
eventType: 'data',
},
});
/** 登记触发器:人确认后起单,「登记人即来源」—— 表单由调用接口 schema 自动渲染 */
const TRIGGER_REGISTRATION = triggerConfigSchema.parse({
id: 'trg-rfq-manual',
name: '人工登记起单(统一报价)',
enabled: true,
processPackageId: 'unified-quote',
mapping: [],
spec: { kind: 'registration' },
});
export async function seedMvpFlow(container: Container): Promise<void> {
const log = (line: string) => process.stdout.write(line + '\n');
await container.process.savePackage(MVP_PACKAGE);
const report = await container.process.validate(MVP_PACKAGE);
if (!report.publishable) {
log(' 闭合校验未过,不得发布:' + report.violations.map((v) => v.message).join('; '));
} else {
await container.process.publish(MVP_PACKAGE.id, MVP_PACKAGE.version);
log(`④ 流程包「统一报价」v${MVP_PACKAGE.version} 已发布 —— ${MVP_PACKAGE.nodes.length} 节点,边映射闭合校验通过`);
}
await container.trigger.upsert(TRIGGER_EVENT);
await container.trigger.upsert(TRIGGER_REGISTRATION);
log(' 触发器已配置:客户RFQ询价(事件)· 人工登记起单(登记)');
/* 邮件通道两条:自动起单的与人工确认的 —— 同一封 RFQ 两条路,起不起单由通道定 */
const { positions } = await container.org.listStaff();
const op = positions.find((p) => p.code === 'OP');
const pm = positions.find((p) => p.code === 'PM');
const extract = [
{ key: 'customerCode', regex: '\\bC\\d{3}\\b', source: 'both' as const },
{ key: 'rfqRef', regex: 'RFQ-[A-Z0-9]+', source: 'both' as const },
];
await container.channel.upsert({
id: 'ch-rfq-mail',
name: '公司询价邮箱',
kind: 'mail',
address: 'rfq@we.com',
enabled: true,
extract: [...extract, { key: 'quoteNo', regex: 'Q\\d{6}', source: 'both' }],
mapping: [],
...(op === undefined ? {} : { fallbackPosition: op.id }),
addressWindowMs: 7 * 86_400_000,
});
await container.channel.upsert({
id: 'ch-rfq-review',
name: '询价待确认邮箱',
kind: 'mail',
address: 'rfq-review@we.com',
enabled: true,
extract,
mapping: [],
...(pm === undefined ? {} : { fallbackPosition: pm.id }),
addressWindowMs: 7 * 86_400_000,
});
log(' 邮件通道已配置:公司询价邮箱(OP 兜底)· 询价待确认邮箱(PM 兜底)');
}