feat(testing): 增加质检报告独立编辑与详情页面,不再使用弹窗
这个提交包含在:
@@ -5,6 +5,12 @@ namespace app\common\library;
|
||||
/** Numeric warning rules shared by the editor and persistence layer. */
|
||||
class QualityRule
|
||||
{
|
||||
public static function isNumber($value)
|
||||
{
|
||||
return (is_int($value) || is_float($value) || is_string($value))
|
||||
&& is_numeric($value) && is_finite((float)$value);
|
||||
}
|
||||
|
||||
public static function direction($item)
|
||||
{
|
||||
if (isset($item['direction']) && in_array($item['direction'], ['upper', 'lower'], true)) {
|
||||
@@ -12,14 +18,22 @@ class QualityRule
|
||||
}
|
||||
$warning = isset($item['warning']) ? $item['warning'] : null;
|
||||
$alert = isset($item['alert']) ? $item['alert'] : null;
|
||||
return is_numeric($warning) && is_numeric($alert) && $warning > $alert ? 'lower' : 'upper';
|
||||
return self::isNumber($warning) && self::isNumber($alert) && $warning > $alert ? 'lower' : 'upper';
|
||||
}
|
||||
|
||||
public static function validate($content)
|
||||
public static function validate($content, $originalRules = [])
|
||||
{
|
||||
if (!is_array($content) || empty($content)) {
|
||||
return '请填写检测参数';
|
||||
}
|
||||
$numericRules = [];
|
||||
foreach ($originalRules as $original) {
|
||||
if (isset($original['warning'], $original['alert'])
|
||||
&& self::isNumber($original['warning']) && self::isNumber($original['alert'])) {
|
||||
$key = !empty($original['id']) ? 'id:' . $original['id'] : 'num:' . $original['num'];
|
||||
$numericRules[$key] = true;
|
||||
}
|
||||
}
|
||||
foreach ($content as $item) {
|
||||
if (!is_array($item)) {
|
||||
return '检测参数格式无效';
|
||||
@@ -30,7 +44,23 @@ class QualityRule
|
||||
if (!isset($item['warning'], $item['alert'])) {
|
||||
return '请填写预警值和警告值';
|
||||
}
|
||||
if (is_numeric($item['warning']) && is_numeric($item['alert'])) {
|
||||
$warningNumeric = self::isNumber($item['warning']);
|
||||
$alertNumeric = self::isNumber($item['alert']);
|
||||
$numeric = $warningNumeric && $alertNumeric;
|
||||
$key = !empty($item['id']) ? 'id:' . $item['id'] : 'num:' . (isset($item['num']) ? $item['num'] : '');
|
||||
$expectsNumeric = isset($numericRules[$key]) || (isset($item['is_number']) && (string)$item['is_number'] === '1')
|
||||
|| $warningNumeric || $alertNumeric;
|
||||
if ($expectsNumeric && !$numeric) {
|
||||
return $item['name'] . ':预警值和警告值必须都是有限数字';
|
||||
}
|
||||
if (!isset($item['val']) || (is_string($item['val']) && trim($item['val']) === '')) {
|
||||
return $item['name'] . ':请填写检测值,缺测可填 /';
|
||||
}
|
||||
if ($numeric && !self::isNumber($item['val'])
|
||||
&& !preg_match('/^(?:\/|--?|未检测|未提供|暂无|未检出|未检出\s*ND|ND)$/ui', trim((string)$item['val']))) {
|
||||
return $item['name'] . ':检测值必须是有限数字,缺测可填 /';
|
||||
}
|
||||
if ($numeric) {
|
||||
$upper = self::direction($item) === 'upper';
|
||||
if (($upper && $item['warning'] > $item['alert'])
|
||||
|| (!$upper && $item['warning'] < $item['alert'])) {
|
||||
|
||||
在新工单中引用
屏蔽一个用户