129 lines
3.8 KiB
PHP
129 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
|
|
class MonitorMode extends Model
|
|
{
|
|
use Filterable;
|
|
|
|
protected $fillable = [
|
|
'name', 'type',
|
|
'is_enable', 'sort', 'is_recommend',
|
|
'group_tags'
|
|
];
|
|
|
|
protected $appends = ['tags'];
|
|
|
|
public const TYPE_MONITOR = 1; //视频监控
|
|
public const TYPE_SOIL = 2; //土壤监测
|
|
public const TYPE_WATER_QUALITY = 3; //水质监测
|
|
public const TYPE_METEOROLOGICAL = 4; //气象监测
|
|
public const TYPE_AIR = 5; //通风控制
|
|
public const TYPE_ATOMIZING = 6; //喷雾控制
|
|
public const TYPE_INSECT = 7; //虫情监测
|
|
|
|
public static function typeMap()
|
|
{
|
|
return [
|
|
self::TYPE_MONITOR => '视频监控',
|
|
self::TYPE_SOIL => '土壤监测',
|
|
// self::TYPE_WATER_QUALITY => '水质监测',
|
|
self::TYPE_METEOROLOGICAL => '气象监测',
|
|
self::TYPE_AIR => '通风控制',
|
|
self::TYPE_ATOMIZING => '喷雾控制',
|
|
self::TYPE_INSECT => '虫情监测',
|
|
];
|
|
}
|
|
|
|
public static function fieldMap($type)
|
|
{
|
|
$arr = [];
|
|
switch ($type) {
|
|
case self::TYPE_SOIL:
|
|
$arr = [
|
|
'conductivity'=>'导电率',
|
|
'humidity'=>'湿度',
|
|
'temperature'=>'温度',
|
|
'n'=>'氮',
|
|
'p'=>'磷',
|
|
'k'=>'钾'
|
|
];
|
|
break;
|
|
case self::TYPE_WATER_QUALITY:
|
|
$arr = [
|
|
];
|
|
break;
|
|
case self::TYPE_METEOROLOGICAL:
|
|
$arr = [
|
|
'box_temperature' => '温度',
|
|
'box_humidity' => '湿度',
|
|
'box_illumination' => '光照强度',
|
|
'moment_rainfall' => '降雨量',
|
|
'wind_speed' => '风速',
|
|
'wind_direction' => '风向',
|
|
'box_noise' => '噪音',
|
|
'pm10' => 'PM10',
|
|
'pm25' => 'PM25',
|
|
'box_co2' => 'CO2'
|
|
];
|
|
break;
|
|
}
|
|
return $arr;
|
|
}
|
|
|
|
public static function fieldUnitMap($type)
|
|
{
|
|
$arr = [];
|
|
switch ($type) {
|
|
case self::TYPE_SOIL:
|
|
$arr = [
|
|
'conductivity'=>'us/cm',
|
|
'humidity'=>'%RH',
|
|
'temperature'=>'℃',
|
|
'n'=>'n',
|
|
'p'=>'p',
|
|
'k'=>'k'
|
|
];
|
|
break;
|
|
case self::TYPE_WATER_QUALITY:
|
|
$arr = [
|
|
];
|
|
break;
|
|
case self::TYPE_METEOROLOGICAL:
|
|
$arr = [
|
|
'box_temperature' => '℃',
|
|
'box_humidity' => '%RH',
|
|
'box_illumination' => 'Lux',
|
|
'moment_rainfall' => 'mm',
|
|
'wind_speed' => 'm/s',
|
|
'wind_direction' => '',
|
|
'box_noise' => 'db',
|
|
'pm10' => 'ug/m3',
|
|
'pm25' => 'ug/m3',
|
|
'box_co2' => 'ppm'
|
|
];
|
|
break;
|
|
}
|
|
return $arr;
|
|
}
|
|
|
|
protected function serializeDate(\DateTimeInterface $date){
|
|
return $date->format('Y-m-d H:i:s');
|
|
}
|
|
|
|
protected function tags():Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn($value) => $this->group_tags ? explode(',', $this->group_tags) : [],
|
|
);
|
|
}
|
|
|
|
public function devices(){
|
|
return $this->belongsToMany(Device::class, MonitorDevice::class, 'monitor_id', 'device_id')->withPivot('fields');
|
|
}
|
|
}
|