379 lines
20 KiB
TypeScript
379 lines
20 KiB
TypeScript
/**
|
||
* 配置中心 · 四轴配置面板(caliber 页签 · W4-A,建议书 §5.2.2 / 规划书附录 E)。
|
||
*
|
||
* 承载配置中心除「口径字典与版本治理」(CaliberVersionPanel)外的四条配置轴:
|
||
* ① 三层参数重算(断言②):试改 C27/C28 五个参数 → runDekDay 重算 →
|
||
* 理论/计划档 OEE 移动、**实际档实测不动**;版本标签随修订递增(沙箱)。
|
||
* ② 算法模板:三区域不同构(SRF 缓冲解耦 / FT 多因子连乘 / ASLT 事件驱动),
|
||
* 只展示口径与算式骨架,**不嵌任何 POC 结果数字**(数字在「工序·工位对比」页现算)。
|
||
* ③ 间隙阈值(断言⑤):逐台公式默认值 max(5,3×ICT/60) vs 台账校准值,台账值优先。
|
||
* ④ 优先级权重 A/B:两套并列可切换(默认 B),compareSchemes 看名次是否变化。
|
||
*
|
||
* 四条诚实性纪律:
|
||
* 1. **页面本地沙箱**:参数试算不改全局 OEE_PARAMS、不改缓存当日读数、不改顶栏筛选口径版本
|
||
* (normalizeFilter 锁定 caliberVersion 单一来源)。数据血缘口径版本仅在 D 类补录时递增。
|
||
* 2. **实际档不随参数变**:actualTier 由实测 RT/PPT、N×ICT/RT、良品/N 算出,与 C27/C28 无关;
|
||
* 参数只动 theoretical/planned。UI 必须如实显示实际档 Δ=0,不得假装三档一起动。
|
||
* 3. **P0 待 IE 签字**:本次不安排口径工作坊,C27/C28 标灰「待 IE 签字」,不标绿。
|
||
* 4. **数字只从 L3 取**:runDekDay / dayByDate / defaultGapThresholdMin / compareSchemes /
|
||
* priorityStats 一律走 oeeService;设备台账字典(DEVICES/deviceStats)按 ADR-02 可直接读 data 层。
|
||
*/
|
||
import { useState, type CSSProperties } from 'react';
|
||
import {
|
||
SlidersHorizontal, RotateCcw, Layers, Ruler, Scale, ArrowRightLeft,
|
||
CheckCircle2, FlaskConical,
|
||
} from 'lucide-react';
|
||
import { useTheme } from '../../context/ThemeContext';
|
||
import {
|
||
OEE_PARAMS, PARAMS_SIGNOFF_NOTE, runDekDay, dayByDate, bumpVersion, CALIBER_VERSION,
|
||
defaultGapThresholdMin, WEIGHT_SCHEMES, DEFAULT_WEIGHT_SCHEME, compareSchemes, priorityStats,
|
||
PRIORITY_CANDIDATES, type ThreeTierParams, type WeightSchemeId,
|
||
} from '../../lib/oeeService';
|
||
import { TEMPLATE_LABEL, type RegionTemplate } from '../../types/oee';
|
||
import { DEVICES, deviceStats } from '../../data/oee/devices';
|
||
import {
|
||
Card, Table, Th, Td, Chip, Note, GapBox, EmptyBox, grid2, grid3, pct,
|
||
} from '../workspace/oeeUi';
|
||
|
||
/* ── 三层参数元数据:键 / 中文名 / 口径项 / 单位 / 驱动哪一档 / 输入步长 ── */
|
||
interface ParamMeta {
|
||
key: keyof ThreeTierParams;
|
||
label: string;
|
||
caliber: 'C27' | 'C28';
|
||
unit: string;
|
||
drives: string;
|
||
step: number;
|
||
}
|
||
const PARAM_META: ParamMeta[] = [
|
||
{ key: 'designYield', label: '设计良率 Q_design', caliber: 'C27', unit: '比率 0–1', drives: '理论档 Q', step: 0.001 },
|
||
{ key: 'planPerformanceRate', label: '计划性能率 P_plan', caliber: 'C27', unit: '比率 0–1', drives: '计划档 P', step: 0.001 },
|
||
{ key: 'targetYield', label: '目标良率 Q_plan', caliber: 'C27', unit: '比率 0–1', drives: '计划档 Q', step: 0.001 },
|
||
{ key: 'dailyUnavoidableStopSec', label: '日不可避免停机', caliber: 'C27', unit: '秒/日', drives: '理论档 A', step: 10 },
|
||
{ key: 'monthlyPlannedStopRate', label: 'IE 月度计划停机率', caliber: 'C28', unit: '比率 0–1', drives: '计划档 A', step: 0.001 },
|
||
];
|
||
|
||
/* ── 三区域算法模板:只录口径骨架,不嵌 POC 结果数字(templates.ts 文件头) ── */
|
||
interface TemplateDesc {
|
||
id: RegionTemplate;
|
||
a: string;
|
||
p: string;
|
||
q: string;
|
||
caliber: string;
|
||
}
|
||
const TEMPLATE_DESC: TemplateDesc[] = [
|
||
{
|
||
id: 'SRF_BUFFER',
|
||
a: '缓冲解耦:上游最长停机 ≤ B×下游ICT 时不传导到全线',
|
||
p: '性能率按瓶颈工位节拍推算',
|
||
q: '良率按串联工位连乘',
|
||
caliber: '零缓冲是理论下界,非本线口径;B(缓冲容量)由数据层注入',
|
||
},
|
||
{
|
||
id: 'FT_MULTIPLY',
|
||
a: 'A=(1−Down率)(1−SetupLoss)(1−Corr)−计划损失',
|
||
p: 'P=1−(OE+Index+Jam)',
|
||
q: 'Q=1−(Rescreen×良率损失)',
|
||
caliber: '多因子连乘,A 不是 RT/PPT;SetupLoss 五操作数含义待 IE 确认',
|
||
},
|
||
{
|
||
id: 'ASLT_EVENT',
|
||
a: 'A=运行时长/活跃窗口(>60min 间隔切窗)',
|
||
p: 'P=12站使能总时长/(12×活跃窗口)',
|
||
q: 'Q=(FT合格+RC复测合格)/FT投入',
|
||
caliber: '事件驱动;站别汇总与活跃窗口两套口径各自标,禁止交叉配对',
|
||
},
|
||
];
|
||
|
||
const TIER_ROWS = [
|
||
{ key: 'theoretical', label: '理论 OEE', note: 'A 由日不可避免停机决定,P=100%,Q=设计良率' },
|
||
{ key: 'planned', label: '计划 OEE', note: 'C27/C28 附录 E 默认值,待 IE 签字' },
|
||
{ key: 'actual', label: '实际 OEE', note: '实测 A=RT/PPT,P=N×ICT/RT,Q=良品/N' },
|
||
] as const;
|
||
|
||
export default function ConfigAxesPanel({ bizDate }: { bizDate: string }) {
|
||
const { tokens } = useTheme();
|
||
|
||
/* ① 三层参数重算:页面本地沙箱 */
|
||
const [draft, setDraft] = useState<ThreeTierParams>({ ...OEE_PARAMS });
|
||
const [applied, setApplied] = useState<{ params: ThreeTierParams; revision: number } | null>(null);
|
||
const [revision, setRevision] = useState(0);
|
||
const [paramMsg, setParamMsg] = useState<string | null>(null);
|
||
|
||
const baseline = dayByDate(bizDate);
|
||
const recomputed = applied && baseline
|
||
? runDekDay(baseline.seed, { params: applied.params, revision: applied.revision })
|
||
: null;
|
||
const versionTag = applied ? bumpVersion(CALIBER_VERSION, applied.revision) : CALIBER_VERSION;
|
||
|
||
const paramsEqual = (a: ThreeTierParams, b: ThreeTierParams) =>
|
||
PARAM_META.every((m) => a[m.key] === b[m.key]);
|
||
|
||
const applyParams = () => {
|
||
const ref = applied?.params ?? OEE_PARAMS;
|
||
if (paramsEqual(draft, ref)) {
|
||
setParamMsg('参数取值未变,不产生新试算版本(与口径字典同一纪律)。');
|
||
return;
|
||
}
|
||
const rev = revision + 1;
|
||
setRevision(rev);
|
||
setApplied({ params: { ...draft }, revision: rev });
|
||
setParamMsg(`已按修订 r${rev} 重算:理论/计划档随参数移动,实际档为实测值不变。`);
|
||
};
|
||
const resetParams = () => {
|
||
setDraft({ ...OEE_PARAMS });
|
||
setApplied(null);
|
||
setRevision(0);
|
||
setParamMsg(null);
|
||
};
|
||
|
||
/* ④ 优先级权重 A/B */
|
||
const [scheme, setScheme] = useState<WeightSchemeId>(DEFAULT_WEIGHT_SCHEME);
|
||
const cmp = compareSchemes(PRIORITY_CANDIDATES);
|
||
const ps = priorityStats();
|
||
const ws = WEIGHT_SCHEMES[scheme];
|
||
const rankAOf = (id: string) => cmp.rankA.find((r) => r.item.id === id)?.rank ?? 0;
|
||
const rankBOf = (id: string) => cmp.rankB.find((r) => r.item.id === id)?.rank ?? 0;
|
||
|
||
/* ③ 间隙阈值 */
|
||
const ds = deviceStats();
|
||
|
||
const inputStyle: CSSProperties = {
|
||
width: '100%', minWidth: 0, boxSizing: 'border-box',
|
||
background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`, borderRadius: 7,
|
||
padding: '4px 7px', fontSize: 11.5, color: tokens.text, outline: 'none',
|
||
fontVariantNumeric: 'tabular-nums',
|
||
};
|
||
const toggleBtn = (id: WeightSchemeId): CSSProperties => ({
|
||
fontSize: 11, fontWeight: 700, padding: '3px 11px', borderRadius: 8, cursor: 'pointer',
|
||
border: `1px solid ${scheme === id ? tokens.accent : tokens.border}`,
|
||
background: scheme === id ? tokens.accentBg : 'transparent',
|
||
color: scheme === id ? tokens.accent : tokens.textSub,
|
||
});
|
||
const actionBtn = (primary: boolean): CSSProperties => ({
|
||
fontSize: 11, fontWeight: 700, padding: '5px 12px', borderRadius: 8, cursor: 'pointer',
|
||
display: 'inline-flex', alignItems: 'center', gap: 5,
|
||
border: `1px solid ${primary ? tokens.accent : tokens.border}`,
|
||
background: primary ? tokens.accentBg : 'transparent',
|
||
color: primary ? tokens.accent : tokens.textSub,
|
||
});
|
||
|
||
return (
|
||
<>
|
||
{/* ① 三层参数重算(断言②) */}
|
||
<Card
|
||
full
|
||
title="三层参数重算 · 断言②(切换触发重算)"
|
||
icon={<SlidersHorizontal size={14} color={tokens.accent} />}
|
||
right={<Chip color={tokens.textMuted} title="页面本地沙箱:不改全局 OEE_PARAMS、不改缓存当日读数、不改顶栏口径版本">沙箱试算 · 不写全局</Chip>}
|
||
note={
|
||
<>
|
||
试改 C27/C28 五个参数 → <code>runDekDay(seed, {'{params, revision}'})</code> 重算。
|
||
<strong> 实际档由实测算出(RT/PPT、N×ICT/RT、良品/N),与参数无关,Δ 恒为 0</strong>;
|
||
参数只移动理论/计划档。试算版本标签 <code>{versionTag}</code> 为沙箱修订号;
|
||
数据血缘口径版本(caliberVersion)仅在 D 类补录时递增,治理见上方「口径字典与版本」。
|
||
</>
|
||
}
|
||
>
|
||
{baseline ? (
|
||
<div style={grid2}>
|
||
{/* 左:参数编辑器 */}
|
||
<div style={{ minWidth: 0, display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||
<Table head={<>
|
||
<Th>参数(口径项)</Th><Th>驱动</Th><Th right>试改值</Th>
|
||
</>}>
|
||
{PARAM_META.map((m) => (
|
||
<tr key={m.key}>
|
||
<Td bold>
|
||
{m.label}
|
||
<div style={{ marginTop: 2 }}>
|
||
<Chip color={tokens.textMuted} title={PARAMS_SIGNOFF_NOTE}>{m.caliber} · 待 IE 签字</Chip>
|
||
</div>
|
||
</Td>
|
||
<Td color={tokens.textSub}>{m.drives}<div style={{ fontSize: 10, color: tokens.textMuted }}>{m.unit}</div></Td>
|
||
<Td right>
|
||
<input
|
||
type="number"
|
||
step={m.step}
|
||
value={draft[m.key]}
|
||
style={inputStyle}
|
||
onChange={(e) => {
|
||
const v = Number(e.target.value);
|
||
setDraft((d) => ({ ...d, [m.key]: Number.isFinite(v) ? v : d[m.key] }));
|
||
}}
|
||
/>
|
||
<div style={{ fontSize: 9.5, color: tokens.textMuted, marginTop: 2 }}>默认 {OEE_PARAMS[m.key]}</div>
|
||
</Td>
|
||
</tr>
|
||
))}
|
||
</Table>
|
||
<div style={{ display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' }}>
|
||
<button style={actionBtn(true)} onClick={applyParams}><FlaskConical size={13} />应用并重算</button>
|
||
<button style={actionBtn(false)} onClick={resetParams}><RotateCcw size={13} />恢复默认</button>
|
||
<span style={{ flex: 1 }} />
|
||
<Chip color={applied ? tokens.accent : tokens.textMuted}>修订 r{revision}</Chip>
|
||
</div>
|
||
{paramMsg && (
|
||
<div style={{ fontSize: 10.5, color: tokens.textSub, lineHeight: 1.55, display: 'flex', gap: 6, alignItems: 'flex-start' }}>
|
||
<CheckCircle2 size={13} color={tokens.accent} style={{ flexShrink: 0, marginTop: 1 }} />{paramMsg}
|
||
</div>
|
||
)}
|
||
</div>
|
||
{/* 右:三档对照 */}
|
||
<div style={{ minWidth: 0, display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||
<Table head={<>
|
||
<Th>口径档</Th><Th right>基线</Th><Th right>重算</Th><Th right>Δ(pp)</Th>
|
||
</>}>
|
||
{TIER_ROWS.map((r) => {
|
||
const b = baseline.tiers[r.key].oee;
|
||
const n = recomputed ? recomputed.tiers[r.key].oee : b;
|
||
const d = (n - b) * 100;
|
||
const isActual = r.key === 'actual';
|
||
return (
|
||
<tr key={r.key}>
|
||
<Td bold>
|
||
{r.label}
|
||
<div style={{ fontSize: 9.5, color: tokens.textMuted, fontWeight: 400 }}>{r.note}</div>
|
||
</Td>
|
||
<Td right mono>{pct(b)}%</Td>
|
||
<Td right mono color={recomputed && !isActual ? tokens.accent : tokens.textSub}>{pct(n)}%</Td>
|
||
<Td right mono color={isActual ? tokens.textMuted : d === 0 ? tokens.textSub : d > 0 ? tokens.success : tokens.warning}>
|
||
{isActual ? '0.00 · 实测' : `${d >= 0 ? '+' : ''}${d.toFixed(2)}`}
|
||
</Td>
|
||
</tr>
|
||
);
|
||
})}
|
||
</Table>
|
||
<GapBox
|
||
missing="C27/C28 无人签字"
|
||
dependsOn="IE 提供设计良率/计划性能率/目标良率/日不可避免停机/月度计划停机率"
|
||
stage="口径工作坊(本次未安排)"
|
||
note={PARAMS_SIGNOFF_NOTE + '。附录 E 默认值生效中,标灰不标绿;试算仅演示重算链路,不代表客户确认口径。'}
|
||
/>
|
||
</div>
|
||
</div>
|
||
) : (
|
||
<EmptyBox>业务日 {bizDate} 无锚点单机种子,无法重算。请在顶栏选择已接入的锚点设备日。</EmptyBox>
|
||
)}
|
||
</Card>
|
||
|
||
{/* ② 算法模板 · 三区域不同构 */}
|
||
<Card
|
||
full
|
||
title="算法模板 · 三区域不同构(不可一套通用式套三站)"
|
||
icon={<Layers size={14} color={tokens.accent} />}
|
||
right={<Chip color={tokens.textMuted} title="只录口径骨架;操作数与锚点由数据层注入,结果数字在「工序·工位对比」页现算">口径骨架 · 不嵌结果数字</Chip>}
|
||
note="三站分母与算式不同构:SRF 缓冲解耦、FT 多因子连乘(A 不是 RT/PPT)、ASLT 事件驱动(活跃窗口)。每个中间量带 formula+operands+source,可在「工序·工位对比」页逐项展开复核(断言①)。"
|
||
>
|
||
<div style={grid3}>
|
||
{TEMPLATE_DESC.map((t) => (
|
||
<div key={t.id} style={{
|
||
minWidth: 0, padding: '9px 11px', borderRadius: 9,
|
||
background: tokens.panelBgAlt, border: `1px solid ${tokens.borderSub}`,
|
||
display: 'flex', flexDirection: 'column', gap: 6,
|
||
}}>
|
||
<div style={{ fontSize: 12, fontWeight: 700, color: tokens.text }}>{TEMPLATE_LABEL[t.id]}</div>
|
||
{([['A', t.a], ['P', t.p], ['Q', t.q]] as const).map(([f, txt]) => (
|
||
<div key={f} style={{ display: 'flex', gap: 6, alignItems: 'flex-start' }}>
|
||
<Chip color={f === 'A' ? '#f87171' : f === 'P' ? '#38bdf8' : '#a78bfa'}>{f}</Chip>
|
||
<span style={{ fontSize: 10.5, color: tokens.textSub, lineHeight: 1.5, minWidth: 0 }}>{txt}</span>
|
||
</div>
|
||
))}
|
||
<div style={{ fontSize: 10, color: tokens.textMuted, lineHeight: 1.5, marginTop: 2, borderTop: `1px dashed ${tokens.border}`, paddingTop: 6 }}>
|
||
{t.caliber}
|
||
</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</Card>
|
||
|
||
{/* ③ 间隙阈值 + ④ 优先级权重:两卡并列,内容量相近,stretch 底边对齐 */}
|
||
<div style={grid2}>
|
||
<Card
|
||
title="间隙阈值 · 台账值优先(断言⑤)"
|
||
icon={<Ruler size={14} color={tokens.accent} />}
|
||
right={<Chip color={tokens.accent} title="gapSource=POC 的设备由客户单列阈值,优先于公式默认值">POC 单列 {ds.gapFromPoc} 台</Chip>}
|
||
note="公式默认 max(5min, 3×ICT/60);台账校准值优先。kohyoung AOI001=15min(公式 18)、Jetting JET001=3min(公式 5)两处≠默认值,逐台对照如下。ICT=0 的设备公式默认落 5min。阈值为主数据,编辑在「主数据」页。"
|
||
>
|
||
<Table maxHeight={300} head={<>
|
||
<Th>设备</Th><Th>区域</Th><Th right>ICT(s)</Th><Th right>公式默认</Th><Th right>台账值</Th><Th>来源</Th>
|
||
</>}>
|
||
{DEVICES.map((d) => {
|
||
const formula = defaultGapThresholdMin(d.ictSec);
|
||
const overridden = d.gapSource === 'POC' && Math.abs(formula - d.gapThresholdMin) > 1e-9;
|
||
return (
|
||
<tr key={d.id} style={{ opacity: d.countsForOee ? 1 : 0.6 }}>
|
||
<Td bold>
|
||
<span style={{ fontFamily: 'ui-monospace, monospace' }}>{d.id}</span>
|
||
<div style={{ fontSize: 9.5, color: tokens.textMuted, fontWeight: 400 }}>{d.name}</div>
|
||
</Td>
|
||
<Td color={tokens.textSub}>{d.region}</Td>
|
||
<Td right mono color={d.ictSec > 0 ? tokens.textSub : tokens.textMuted}>{d.ictSec > 0 ? d.ictSec : '—'}</Td>
|
||
<Td right mono color={tokens.textMuted}>{formula.toFixed(1)}</Td>
|
||
<Td right mono bold color={overridden ? tokens.accent : tokens.textSub}>{d.gapThresholdMin}</Td>
|
||
<Td>
|
||
<Chip color={d.gapSource === 'POC' ? tokens.accent : tokens.textMuted} title={d.gapSource === 'POC' ? 'POC 单列阈值,优先于公式' : '规划书未单列,取公式默认值'}>
|
||
{d.gapSource === 'POC' ? 'POC' : '默认'}
|
||
</Chip>
|
||
{overridden && <div style={{ marginTop: 2 }}><Chip color={tokens.warning}>≠公式</Chip></div>}
|
||
</Td>
|
||
</tr>
|
||
);
|
||
})}
|
||
</Table>
|
||
</Card>
|
||
|
||
<Card
|
||
title="优先级权重 · A/B 双方案(默认 B)"
|
||
icon={<Scale size={14} color={tokens.accent} />}
|
||
right={
|
||
<span style={{ display: 'flex', gap: 6, alignItems: 'center' }}>
|
||
{(['A', 'B'] as WeightSchemeId[]).map((id) => (
|
||
<button key={id} style={toggleBtn(id)} onClick={() => setScheme(id)} title={WEIGHT_SCHEMES[id].source}>{id}</button>
|
||
))}
|
||
</span>
|
||
}
|
||
note={`当前 ${ws.label}(${ws.source})。A/B 五维互不重叠(${ps.schemesDisjoint ? '已校验' : '异常'}),权重之和 A=${ps.weightSumA.toFixed(2)} / B=${ps.weightSumB.toFixed(2)}。完整逐项 weight×factor 贡献在「优先处理清单」页展开(断言⑧)。`}
|
||
>
|
||
<Note>下表 A/B 名次对比为演示沙箱(PRIORITY_CANDIDATES demo 候选 C1–C6)。</Note>
|
||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, minWidth: 0 }}>
|
||
<Table head={<>
|
||
<Th>当前方案维度</Th><Th right>权重</Th>
|
||
</>}>
|
||
{ws.dims.map((dim) => (
|
||
<tr key={dim.key}>
|
||
<Td bold>{dim.label}</Td>
|
||
<Td right mono color={tokens.accent}>{dim.weight.toFixed(2)}</Td>
|
||
</tr>
|
||
))}
|
||
</Table>
|
||
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||
<ArrowRightLeft size={13} color={tokens.textMuted} />
|
||
<span style={{ fontSize: 10.5, color: tokens.textSub }}>换权重排序:</span>
|
||
<Chip color={cmp.orderChanged ? tokens.warning : tokens.textSub}>{cmp.orderChanged ? '名次变化' : '名次未变'}</Chip>
|
||
</div>
|
||
<Table head={<>
|
||
<Th>候选项</Th><Th right>A 名次</Th><Th right>B 名次</Th><Th right>变化</Th>
|
||
</>}>
|
||
{PRIORITY_CANDIDATES.map((c) => {
|
||
const ra = rankAOf(c.id);
|
||
const rb = rankBOf(c.id);
|
||
const moved = ra !== rb;
|
||
return (
|
||
<tr key={c.id}>
|
||
<Td>
|
||
<span style={{ fontFamily: 'ui-monospace, monospace', color: tokens.textSub }}>{c.id}</span>
|
||
<div style={{ fontSize: 9.5, color: tokens.textMuted, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', maxWidth: 180 }}>{c.title}</div>
|
||
</Td>
|
||
<Td right mono color={scheme === 'A' ? tokens.accent : tokens.textSub}>{ra}</Td>
|
||
<Td right mono color={scheme === 'B' ? tokens.accent : tokens.textSub}>{rb}</Td>
|
||
<Td right mono color={moved ? tokens.warning : tokens.textMuted}>{moved ? `${ra}→${rb}` : '—'}</Td>
|
||
</tr>
|
||
);
|
||
})}
|
||
</Table>
|
||
</div>
|
||
</Card>
|
||
</div>
|
||
</>
|
||
);
|
||
} |