feat: 完善仓库建筑绑定、质检预警规则与大屏展示
这个提交包含在:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\library;
|
||||
|
||||
/** 建筑位置独立于仓号,修改仓号不会移动大屏标记。 */
|
||||
class GranaryScreen
|
||||
{
|
||||
public static function extraPositions()
|
||||
{
|
||||
return [
|
||||
'center_upper_left' => ['x' => 46.8, 'y' => 28.4],
|
||||
'center_lower_right' => ['x' => 58.8, 'y' => 34.1],
|
||||
];
|
||||
}
|
||||
|
||||
public static function resolve($item, $coords)
|
||||
{
|
||||
$content = is_array($item['content']) ? $item['content'] : json_decode($item['content'], true);
|
||||
$position = isset($content['screenPosition']) ? $content['screenPosition'] : '';
|
||||
$extra = self::extraPositions();
|
||||
if (isset($extra[$position])) {
|
||||
return $extra[$position];
|
||||
}
|
||||
// 历史记录按数据库 id 锚定原建筑,避免改号后套用另一栋仓库的位置。
|
||||
$originalNumbers = [27 => 30, 29 => 31, 30 => 32, 31 => 10, 33 => 42,
|
||||
34 => 33, 36 => 35, 37 => 36, 38 => 12, 39 => 39, 40 => 40,
|
||||
42 => 41, 43 => 14, 44 => 37, 45 => 15, 46 => 44, 47 => 16,
|
||||
48 => 17, 49 => 18, 50 => 38, 51 => 43];
|
||||
$num = isset($originalNumbers[$item['id']]) ? $originalNumbers[$item['id']] : null;
|
||||
return $num !== null && isset($coords[$num]) ? $coords[$num] : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\library;
|
||||
|
||||
/** Numeric warning rules shared by the editor and persistence layer. */
|
||||
class QualityRule
|
||||
{
|
||||
public static function direction($item)
|
||||
{
|
||||
if (isset($item['direction']) && in_array($item['direction'], ['upper', 'lower'], true)) {
|
||||
return $item['direction'];
|
||||
}
|
||||
$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';
|
||||
}
|
||||
|
||||
public static function validate($content)
|
||||
{
|
||||
if (!is_array($content) || empty($content)) {
|
||||
return '请填写检测参数';
|
||||
}
|
||||
foreach ($content as $item) {
|
||||
if (!is_array($item)) {
|
||||
return '检测参数格式无效';
|
||||
}
|
||||
if (isset($item['direction']) && !in_array($item['direction'], ['upper', 'lower'], true)) {
|
||||
return '预警方向无效';
|
||||
}
|
||||
if (!isset($item['warning'], $item['alert'])) {
|
||||
return '请填写预警值和警告值';
|
||||
}
|
||||
if (is_numeric($item['warning']) && is_numeric($item['alert'])) {
|
||||
$upper = self::direction($item) === 'upper';
|
||||
if (($upper && $item['warning'] > $item['alert'])
|
||||
|| (!$upper && $item['warning'] < $item['alert'])) {
|
||||
return $item['name'] . ($upper
|
||||
? ':越小越好指标要求预警值 ≤ 警告值(高值预警)'
|
||||
: ':越大越好指标要求预警值 ≥ 警告值(低值预警)');
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -799,6 +799,13 @@ class TestingModel extends Model
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($typeArr as &$type) {
|
||||
foreach ($type['content'] as &$item) {
|
||||
$item['direction'] = \app\common\library\QualityRule::direction($item);
|
||||
}
|
||||
unset($item);
|
||||
}
|
||||
unset($type);
|
||||
return $typeArr;
|
||||
}
|
||||
|
||||
@@ -914,6 +921,7 @@ class TestingModel extends Model
|
||||
'val' => $v['val'],
|
||||
'warning' => $v['warning'],
|
||||
'alert' => $v['alert'],
|
||||
'direction' => \app\common\library\QualityRule::direction($v),
|
||||
'test_date' => $data['test_date'],
|
||||
'year' => $data['year'],
|
||||
'season' => $data['season'],
|
||||
@@ -956,6 +964,7 @@ class TestingModel extends Model
|
||||
'val' => $v['val'],
|
||||
'warning' => $v['warning'],
|
||||
'alert' => $v['alert'],
|
||||
'direction' => \app\common\library\QualityRule::direction($v),
|
||||
'test_date' => $data['test_date'],
|
||||
'year' => $data['year'],
|
||||
'season' => $data['season'],
|
||||
@@ -1013,4 +1022,4 @@ class TestingModel extends Model
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户