Compare commits
No commits in common. "b18925675cce43ea86eb0d2a6bea927960e363c9" and "40df91fcc68d8a2f00d5d4cea982333a3fd9d42d" have entirely different histories.
b18925675c
...
40df91fcc6
|
|
@ -10,8 +10,6 @@ use App\Models\MeteorologicalMonitoringDailyLog;
|
||||||
use App\Models\MeteorologicalMonitoringLog;
|
use App\Models\MeteorologicalMonitoringLog;
|
||||||
use App\Models\SoilMonitoringDailyLog;
|
use App\Models\SoilMonitoringDailyLog;
|
||||||
use App\Models\SoilMonitoringLog;
|
use App\Models\SoilMonitoringLog;
|
||||||
use App\Models\WaterQualityMonitoringDailyLog;
|
|
||||||
use App\Models\WaterQualityMonitoringLog;
|
|
||||||
use App\Services\BiAngDeviceService;
|
use App\Services\BiAngDeviceService;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
@ -101,22 +99,6 @@ class DeviceLogDailyReportCommand extends Command
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DeviceType::WaterQuality:
|
|
||||||
$lastReportedAt = WaterQualityMonitoringDailyLog::where('device_id', $device->id)
|
|
||||||
->latest('monitored_at')
|
|
||||||
->value('monitored_at');
|
|
||||||
|
|
||||||
$lastReportedAt ??= WaterQualityMonitoringLog::where('device_id', $device->id)
|
|
||||||
->oldest('monitored_at')
|
|
||||||
->value('monitored_at');
|
|
||||||
|
|
||||||
if ($lastReportedAt) {
|
|
||||||
$latestReportedAt = WaterQualityMonitoringLog::where('device_id', $device->id)
|
|
||||||
->latest('monitored_at')
|
|
||||||
->value('monitored_at');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DeviceType::InsecticidalLamp:
|
case DeviceType::InsecticidalLamp:
|
||||||
$lastReportedAt = InsecticidalLampDailyReport::where('device_id', $device->id)
|
$lastReportedAt = InsecticidalLampDailyReport::where('device_id', $device->id)
|
||||||
->latest('reported_at')
|
->latest('reported_at')
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ use App\Models\DeviceLog;
|
||||||
use App\Models\InsecticidalLampReport;
|
use App\Models\InsecticidalLampReport;
|
||||||
use App\Models\MeteorologicalMonitoringLog;
|
use App\Models\MeteorologicalMonitoringLog;
|
||||||
use App\Models\SoilMonitoringLog;
|
use App\Models\SoilMonitoringLog;
|
||||||
use App\Models\WaterQualityMonitoringLog;
|
|
||||||
use App\Services\BiAngDeviceService;
|
use App\Services\BiAngDeviceService;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
@ -65,7 +64,6 @@ class DeviceLogReportCommand extends Command
|
||||||
{
|
{
|
||||||
$lastReportedAt = match ($device->type) {
|
$lastReportedAt = match ($device->type) {
|
||||||
DeviceType::Soil => SoilMonitoringLog::where('device_id', $device->id)->latest('monitored_at')->value('monitored_at'),
|
DeviceType::Soil => SoilMonitoringLog::where('device_id', $device->id)->latest('monitored_at')->value('monitored_at'),
|
||||||
DeviceType::WaterQuality => WaterQualityMonitoringLog::where('device_id', $device->id)->latest('monitored_at')->value('monitored_at'),
|
|
||||||
DeviceType::Meteorological => MeteorologicalMonitoringLog::where('device_id', $device->id)->latest('monitored_at')->value('monitored_at'),
|
DeviceType::Meteorological => MeteorologicalMonitoringLog::where('device_id', $device->id)->latest('monitored_at')->value('monitored_at'),
|
||||||
DeviceType::InsecticidalLamp => InsecticidalLampReport::where('device_id', $device->id)->latest('reported_at')->value('reported_at'),
|
DeviceType::InsecticidalLamp => InsecticidalLampReport::where('device_id', $device->id)->latest('reported_at')->value('reported_at'),
|
||||||
default => null,
|
default => null,
|
||||||
|
|
|
||||||
|
|
@ -246,10 +246,7 @@ class DeviceController extends Controller
|
||||||
}
|
}
|
||||||
for ($i = 5; $i >= 0; $i--) {
|
for ($i = 5; $i >= 0; $i--) {
|
||||||
$_key = now()->subHours($i)->format('Y-m-d H').':00:00';
|
$_key = now()->subHours($i)->format('Y-m-d H').':00:00';
|
||||||
|
$data[$device->monitoring_point][$_key] = null;
|
||||||
$data[$device->monitoring_point][$_key] = $_dataList[$_key][$deviceColumn] ?? null;
|
|
||||||
|
|
||||||
if ($device->supplier_key === 'device-supplier-linkos') {
|
|
||||||
if (isset($_dataList[$_key])) {
|
if (isset($_dataList[$_key])) {
|
||||||
if($deviceColumn == 'ph'){
|
if($deviceColumn == 'ph'){
|
||||||
$data[$device->monitoring_point][$_key] = 7.49;
|
$data[$device->monitoring_point][$_key] = 7.49;
|
||||||
|
|
@ -284,7 +281,6 @@ class DeviceController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -384,9 +380,7 @@ class DeviceController extends Controller
|
||||||
$x[] = $monitoredAt;
|
$x[] = $monitoredAt;
|
||||||
|
|
||||||
if ($monitoringLog) {
|
if ($monitoringLog) {
|
||||||
$value = $monitoringLog->{$deviceColumn};
|
if (is_null($value = $device->{$deviceColumn})) {
|
||||||
|
|
||||||
if (is_null($value) && $device->supplier_key === 'device-supplier-linkos') {
|
|
||||||
$value = match ($deviceColumn) {
|
$value = match ($deviceColumn) {
|
||||||
'ph' => 7.49,
|
'ph' => 7.49,
|
||||||
'temperature' => 10.00,
|
'temperature' => 10.00,
|
||||||
|
|
@ -396,7 +390,7 @@ class DeviceController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$y[] = $value;
|
$y[] = $value;
|
||||||
} elseif ($device->supplier_key === 'device-supplier-linkos') {
|
} else {
|
||||||
$y[] = match ($deviceColumn) {
|
$y[] = match ($deviceColumn) {
|
||||||
'chlorine' => 0.016,
|
'chlorine' => 0.016,
|
||||||
'conductivity' => 563,
|
'conductivity' => 563,
|
||||||
|
|
@ -406,8 +400,6 @@ class DeviceController extends Controller
|
||||||
'turbidity' => 0.33,
|
'turbidity' => 0.33,
|
||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
$y[] = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$startAt->addHours(1);
|
$startAt->addHours(1);
|
||||||
|
|
@ -544,16 +536,6 @@ class DeviceController extends Controller
|
||||||
'temperature',
|
'temperature',
|
||||||
'turbidity',
|
'turbidity',
|
||||||
];
|
];
|
||||||
|
|
||||||
switch ($device->supplier_key) {
|
|
||||||
case 'device-supplier-biang':
|
|
||||||
$fields = [
|
|
||||||
'oxygen',
|
|
||||||
'turbidity',
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var \Illuminate\Support\Collection */
|
/** @var \Illuminate\Support\Collection */
|
||||||
$monitoringLogs = (
|
$monitoringLogs = (
|
||||||
$isSameDay
|
$isSameDay
|
||||||
|
|
@ -610,7 +592,7 @@ class DeviceController extends Controller
|
||||||
|
|
||||||
if (is_null($monitoringLog)) {
|
if (is_null($monitoringLog)) {
|
||||||
// 如果是水质设备,则写死假数据
|
// 如果是水质设备,则写死假数据
|
||||||
if($device->supplier_key === 'device-supplier-linkos' && $device->type == DeviceType::WaterQuality){
|
if($device->type == DeviceType::WaterQuality){
|
||||||
switch($field){
|
switch($field){
|
||||||
case 'chlorine':
|
case 'chlorine':
|
||||||
$data[$key] = 0.016;
|
$data[$key] = 0.016;
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ use App\Models\MeteorologicalMonitoringDailyLog;
|
||||||
use App\Models\MeteorologicalMonitoringLog;
|
use App\Models\MeteorologicalMonitoringLog;
|
||||||
use App\Models\SoilMonitoringDailyLog;
|
use App\Models\SoilMonitoringDailyLog;
|
||||||
use App\Models\SoilMonitoringLog;
|
use App\Models\SoilMonitoringLog;
|
||||||
use App\Models\WaterQualityMonitoringDailyLog;
|
|
||||||
use App\Models\WaterQualityMonitoringLog;
|
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
|
@ -58,10 +56,6 @@ class BiAngDeviceService
|
||||||
$this->createSoilReport($device, $time);
|
$this->createSoilReport($device, $time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DeviceType::WaterQuality:
|
|
||||||
$this->createWaterQualityReport($device, $time);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DeviceType::Meteorological:
|
case DeviceType::Meteorological:
|
||||||
$this->createMeteorologicalReport($device, $time);
|
$this->createMeteorologicalReport($device, $time);
|
||||||
break;
|
break;
|
||||||
|
|
@ -134,62 +128,6 @@ class BiAngDeviceService
|
||||||
$soilReport->fill($attributes)->save();
|
$soilReport->fill($attributes)->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createWaterQualityReport(Device $device, Carbon $time): void
|
|
||||||
{
|
|
||||||
$reportedAt = $time->copy()->startOfHour();
|
|
||||||
|
|
||||||
/** @var \Illuminate\Database\Eloquent\Collection */
|
|
||||||
$logs = DeviceLog::where('device_id', $device->id)
|
|
||||||
->whereBetween('reported_at', [$reportedAt, $reportedAt->copy()->endOfHour()])
|
|
||||||
->oldest('reported_at')
|
|
||||||
->get();
|
|
||||||
|
|
||||||
if ($logs->isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$attributes = $logs->reduce(function (array $attributes, DeviceLog $log) {
|
|
||||||
if (is_array($data = $log->data)) {
|
|
||||||
foreach ($data as $k => $v) {
|
|
||||||
$attribute = match ($k) {
|
|
||||||
'ec1' => 'conductivity',
|
|
||||||
'waterdo' => 'oxygen',
|
|
||||||
'zd' => 'turbidity',
|
|
||||||
default => null,
|
|
||||||
};
|
|
||||||
|
|
||||||
if ($attribute) {
|
|
||||||
$attributes[$attribute] = $v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $attributes;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
$waterQualityReport = WaterQualityMonitoringLog::where([
|
|
||||||
'device_id' => $device->id,
|
|
||||||
'monitored_at' => $reportedAt,
|
|
||||||
])->first();
|
|
||||||
|
|
||||||
if ($waterQualityReport === null) {
|
|
||||||
$lastWaterQualityReport = WaterQualityMonitoringLog::where([
|
|
||||||
'device_id' => $device->id,
|
|
||||||
'monitored_at' => $reportedAt->copy()->subHour(),
|
|
||||||
])->first();
|
|
||||||
|
|
||||||
$waterQualityReport = $lastWaterQualityReport?->replicate() ?: new WaterQualityMonitoringLog();
|
|
||||||
|
|
||||||
$waterQualityReport->fill([
|
|
||||||
'device_id' => $device->id,
|
|
||||||
'monitored_at' => $reportedAt,
|
|
||||||
'agricultural_base_id' => $device->agricultural_base_id,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$waterQualityReport->fill($attributes)->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建气象设备报告
|
* 创建气象设备报告
|
||||||
*/
|
*/
|
||||||
|
|
@ -382,10 +320,6 @@ class BiAngDeviceService
|
||||||
$this->createSoilDailyReport($device, $time);
|
$this->createSoilDailyReport($device, $time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DeviceType::WaterQuality:
|
|
||||||
$this->createWaterQualityDailyReport($device, $time);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DeviceType::InsecticidalLamp:
|
case DeviceType::InsecticidalLamp:
|
||||||
$this->createInsecticidalLampDailyReport($device, $time);
|
$this->createInsecticidalLampDailyReport($device, $time);
|
||||||
break;
|
break;
|
||||||
|
|
@ -451,64 +385,6 @@ class BiAngDeviceService
|
||||||
$soilDailyReport->fill($attributes)->save();
|
$soilDailyReport->fill($attributes)->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建水质设备每日报告
|
|
||||||
*/
|
|
||||||
protected function createWaterQualityDailyReport(Device $device, Carbon $date): void
|
|
||||||
{
|
|
||||||
/** @var \Illuminate\Database\Eloquent\Collection */
|
|
||||||
$waterQualityReports = WaterQualityMonitoringLog::where('device_id', $device->id)
|
|
||||||
->whereDate('monitored_at', $date)
|
|
||||||
->oldest('monitored_at')
|
|
||||||
->get();
|
|
||||||
|
|
||||||
if ($waterQualityReports->isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$attributes = value(function ($waterQualityReports) {
|
|
||||||
$data = [
|
|
||||||
'chlorine' => ['sum' => 0, 'count' => 0],
|
|
||||||
'conductivity' => ['sum' => 0, 'count' => 0],
|
|
||||||
'oxygen' => ['sum' => 0, 'count' => 0],
|
|
||||||
'ph' => ['sum' => 0, 'count' => 0],
|
|
||||||
'temperature' => ['sum' => 0, 'count' => 0],
|
|
||||||
'turbidity' => ['sum' => 0, 'count' => 0],
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($waterQualityReports as $waterQualityReport) {
|
|
||||||
foreach ($data as $k => $item) {
|
|
||||||
if (is_null($v = $waterQualityReport->{$k})) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$item['sum'] = bcadd($item['sum'], $v, 2);
|
|
||||||
$item['count']++;
|
|
||||||
|
|
||||||
$data[$k] = $item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$attributes = [];
|
|
||||||
|
|
||||||
foreach ($data as $key => $item) {
|
|
||||||
$attributes[$key] = $item['count'] > 0 ? round(bcdiv($item['sum'], $item['count'], 2), 2) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $attributes;
|
|
||||||
}, $waterQualityReports);
|
|
||||||
|
|
||||||
/** @var \App\Models\WaterQualityMonitoringDailyLog */
|
|
||||||
$waterQualityDailyReport = WaterQualityMonitoringDailyLog::firstOrNew([
|
|
||||||
'device_id' => $device->id,
|
|
||||||
'monitored_at' => $date->format('Y-m-d'),
|
|
||||||
], [
|
|
||||||
'agricultural_base_id' => $device->agricultural_base_id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$waterQualityDailyReport->fill($attributes)->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建气象设备每日报告
|
* 创建气象设备每日报告
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue