/** * 从原始解析数据中构建 SS 材质的规格字符串 * 格式:ASTM A312 GRADE TP304/304L-ASME B36.19M */ function buildSSSpecFromRaw($data) { $astm = ''; $grade = ''; $asme = ''; // 将 materialSpec 字符串按空格拆分为数组 $specParts = explode(' ', $data['materialSpec']); $allItems = $specParts; if (!empty($data['techStandard']) && $data['techStandard'] !== 'UNKNOWN') { $allItems[] = $data['techStandard']; } $allItems = array_unique($allItems); // 定义正则 $astmPattern = '/^(ASTM\s+[A-Z0-9]+(?:\.[0-9]+[A-Z]?)?)$/i'; $asmePattern = '/^(ASME\s+[A-Z0-9]+\.[0-9]+[A-Z]?)$/i'; $gradePattern = '/^(GRADE\s+TP[0-9]+\/[0-9]+[A-Z]*|TP[0-9]+\/[0-9]+[A-Z]*)$/i'; foreach ($allItems as $item) { $item = trim($item); if (empty($item)) continue; if (preg_match($astmPattern, $item, $matches)) { $astm = $matches[1]; } elseif (preg_match($asmePattern, $item, $matches)) { $asme = $matches[1]; } elseif (preg_match($gradePattern, $item, $matches)) { $grade = $matches[1]; } } // 如果 grade 仍未匹配到,尝试从任何项中提取 TP 牌号 if (empty($grade)) { foreach ($allItems as $item) { if (preg_match('/TP[0-9]+\/[0-9]+[A-Z]*/i', $item, $m)) { $grade = $m[0]; break; } } } // 组合结果 $parts = array(); if (!empty($astm)) $parts[] = $astm; if (!empty($grade)) $parts[] = $grade; $spec = implode(' ', $parts); if (!empty($asme)) { if (!empty($spec)) $spec .= '-'; $spec .= $asme; } return $spec; }