/** * 四域十九对象(docs/MVP示例工作流.html · 动态数据 + 静态底座;定价审批表落审批机制,不入台账)。 * * 划分原则(产品决策,2026-07-27):**流转单据(过程)归 project;沉淀资产按内容归 * customer / intel / supplier**。声明只写活动**要用**的字段;物化走安装通道的声明合并 * (最大化合并、只增不破坏),这里不建表 —— 建表是 ledger 的事。 */ import { objectDeclarationSchema } from '@contracts'; import type { LedgerFieldType, ObjectDeclaration } from '@contracts'; const f = (name: string, type: LedgerFieldType, label: string, primaryKey = false) => ({ name, type, label, primaryKey, masked: false, }); const obj = (domain: string, object: string, label: string, fields: ReturnType[]) => objectDeclarationSchema.parse({ domain, object, label, fields }); export const MVP_OBJECTS: readonly ObjectDeclaration[] = [ /* ── project:每一单的流转单据(位置签 输入/过程/输出) ─────────────── */ obj('project', 'rfq_file', 'RFQ/BOM文件', [ f('rfq_ref', 'text', '询价单号', true), f('pn', 'text', 'PN', true), f('qty_eau', 'text', '数量/EAU'), f('brand', 'text', '厂牌'), f('analog_flag', 'boolean', 'Analog'), f('aec_cert', 'text', 'AEC认证'), f('target_price', 'number', '目标价'), f('lead_time', 'text', '交期'), ]), obj('project', 'intake_record', '统一受理记录', [ f('customer_code', 'text', '客户码', true), f('pn', 'text', 'PN', true), f('brand', 'text', '厂牌'), f('eau', 'text', 'EAU'), f('type_tag', 'text', 'Type标'), f('target_price', 'number', '目标价'), f('status', 'text', '状态'), ]), obj('project', 'pn_class', '料号分类表', [ f('pn', 'text', 'PN', true), f('type_tag', 'text', 'Type标'), f('basis', 'text', '分级依据'), f('history_hit', 'boolean', '历史价命中'), f('review_note', 'text', '复核结论'), ]), /* * 受理结论 —— **一单一行**(主键只有询价单号),不是一料一行。 * * 它承载 A1 出口的两枚去向旗。为什么必须单独一个对象、不能挂在按料号分行的 * 「统一受理记录」上:出口载荷的标量字段取自 `landed.flat`,而 `flat` 是把这一单 * **所有**落地行 reduce 展开成一个平对象(`wiring/engines.ts`)。旗挂在按料号分的行上, * 六个料号就有六行同名列,**最后合并的那行赢** —— 而归并规则是「任一条命中 C 即需选型」, * last-write-wins 会静默给出错的去向,网关照着错值分叉,没人看得出来。 * * 一单一行就没有这个歧义:G1 / G2 读的是同一行的同一个值。 * 逐料号的判定仍写「料号分类表」,这里只放归并后的结论。 */ obj('project', 'intake_verdict', '受理结论', [ f('rfq_ref', 'text', '询价单号', true), f('need_alternative', 'boolean', '需选型'), f('need_sourcing', 'boolean', '需寻源'), f('c_count', 'number', 'C类条数'), f('status', 'text', '状态'), ]), obj('project', 'alt_request', '替代评估请求', [ f('material', 'text', '初选物料', true), f('chip_type', 'text', '芯片类型'), f('spec_params', 'text', '参数规格'), f('scenario', 'text', '应用场景'), f('requester', 'text', '需求人'), ]), obj('project', 'inquiry_request', '询价请求', [ f('pn', 'text', 'PN', true), f('brand', 'text', 'Brand'), f('era', 'text', 'ERA'), f('project_stage', 'text', '项目阶段'), f('accept_alt', 'boolean', '接受替代'), f('unit_usage', 'text', '单机用量'), f('tp', 'number', 'TP'), f('scenario', 'text', '场景'), ]), obj('project', 'supplier_floor', '供应商底价表', [ f('pn', 'text', 'PN', true), f('supplier', 'text', '供应商', true), f('floor_price', 'number', '底价'), f('moq', 'text', 'MOQ'), f('lead_time', 'text', '交期'), ]), obj('project', 'alt_benchmark', '替代对标表', [ f('original_pn', 'text', '原型号', true), f('candidate_pn', 'text', '候选型号', true), f('alt_grade', 'text', '替代等级'), f('param_diff', 'text', '参数差异项'), f('diff_risk', 'text', '差异风险'), f('mod_eval', 'text', '改动评估'), f('verify_advice', 'text', '验证建议'), ]), obj('project', 'sourcing_compare', '寻源比价表', [ f('pn', 'text', 'PN', true), f('supplier', 'text', '供应商', true), f('quote_price', 'number', '报价'), f('moq', 'text', 'MOQ'), f('lead_time', 'text', '交期'), f('channel_grade', 'text', '渠道等级'), f('condition', 'text', '成色'), f('verdict', 'text', '结论'), ]), obj('project', 'quote_draft', '报价草案', [ f('pn', 'text', 'PN', true), f('proposed_price', 'number', '拟报单价'), f('margin', 'number', '毛利率'), f('deviation', 'number', '偏离度'), ]), obj('project', 'formal_quote', '正式报价单', [ f('pn', 'text', 'PN', true), f('unit_price_cny', 'number', '单价CNY'), f('lead_time', 'text', '交期'), f('spq', 'text', 'SPQ'), f('moq', 'text', 'MOQ'), f('trade_terms', 'text', '贸易条款'), f('valid_until', 'date', '有效期'), ]), obj('project', 'followup', '跟进提醒', [ f('quote_no', 'text', '报价单号', true), f('customer_code', 'text', '客户'), f('d3', 'date', 'D+3'), f('d7', 'date', 'D+7'), f('reply_status', 'text', '回复状态'), ]), obj('project', 'landing_stats', '报价落地率统计', [ f('period', 'text', '期', true), f('landing_rate', 'number', '落地率'), f('type_a_hit', 'number', 'TypeA命中'), f('d3_reply_rate', 'number', 'D+3回复率'), f('return_rate', 'number', '退回率'), ]), /* ── customer:客户信息 ────────────────────────────────────────────── */ obj('customer', 'profile', '客户资料库', [ f('customer_code', 'text', '客户码', true), f('grade', 'text', '客户等级'), f('tags', 'text', '画像标签'), f('payment_terms', 'text', '付款条款'), f('industry', 'text', '行业属性'), f('risk_level', 'text', '风险等级'), f('annual_purchase', 'number', '年采购额'), ]), /* ── intel:市场与销售情报 ─────────────────────────────────────────── */ obj('intel', 'history_price', '历史价格情报', [ f('pn', 'text', 'PN', true), f('quoted_at', 'timestamp', '报价日期', true), f('brand', 'text', '厂牌'), f('unit_price_cny', 'number', '单价CNY'), f('lead_time', 'text', '交期'), f('moq', 'text', 'MOQ'), f('valid_until', 'date', '有效期'), ]), obj('intel', 'chip_spec', '芯片规格书', [ f('pn', 'text', 'PN', true), f('key_params', 'text', '关键参数'), f('package', 'text', '封装'), f('version_date', 'date', '版本日期'), ]), obj('intel', 'public_select', '公网选型库', [ f('alt_relation', 'text', '替代关系', true), f('param_compare', 'text', '参数对比'), f('spec_ref', 'text', '规格书'), f('lifecycle', 'text', '生命周期'), f('price_ref', 'text', '价格参考'), ]), /* ── supplier:供应商信息 ─────────────────────────────────────────── */ obj('supplier', 'channel_dir', '供应商渠道目录', [ f('supplier', 'text', '供应商', true), f('channel_type', 'text', '渠道类型'), f('brand_lines', 'text', '品牌线'), f('contact', 'text', '联系人'), ]), obj('supplier', 'dead_stock', '呆滞库存表', [ f('pn', 'text', 'PN', true), f('stock_qty', 'number', '库存量'), f('stock_age', 'text', '库龄'), f('cost_price', 'number', '成本价'), ]), ]; export function declarationsFor(objects: readonly `${string}.${string}`[]): ObjectDeclaration[] { return objects.map((key) => { const [domain, object] = key.split('.'); const hit = MVP_OBJECTS.find((o) => o.domain === domain && o.object === object); if (hit === undefined) throw new Error(`未知对象:${key} —— 先在 MVP_OBJECTS 登记`); return hit; }); }