Update
parent
b44d7b0055
commit
1dffa74e6f
|
|
@ -98,7 +98,7 @@ class DeviceController extends Controller
|
||||||
$parent = $request->input('parent', 0);
|
$parent = $request->input('parent', 0);
|
||||||
|
|
||||||
$query = Device::query();
|
$query = Device::query();
|
||||||
|
|
||||||
if($parent){
|
if($parent){
|
||||||
$baseIds = AgriculturalBase::where('parent_id', $parent)->pluck('id')->toArray();
|
$baseIds = AgriculturalBase::where('parent_id', $parent)->pluck('id')->toArray();
|
||||||
if(count($baseIds) > 0){
|
if(count($baseIds) > 0){
|
||||||
|
|
@ -266,7 +266,7 @@ class DeviceController extends Controller
|
||||||
break;
|
break;
|
||||||
case 'turbidity':
|
case 'turbidity':
|
||||||
$data[$device->monitoring_point][$_key] = 0.33;
|
$data[$device->monitoring_point][$_key] = 0.33;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -277,6 +277,77 @@ class DeviceController extends Controller
|
||||||
return $this->json($data);
|
return $this->json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function baseDataStaticsV2(Request $request)
|
||||||
|
{
|
||||||
|
$baseId = $request->base_id;
|
||||||
|
$deviceType = DeviceType::tryFrom($request->device_type);
|
||||||
|
$deviceColumns = $request->whenFilled(
|
||||||
|
'device_columns',
|
||||||
|
fn ($deviceColumns) => explode(',', $deviceColumns),
|
||||||
|
fn () => []
|
||||||
|
);
|
||||||
|
|
||||||
|
$devices = Device::where([
|
||||||
|
'agricultural_base_id' => $baseId,
|
||||||
|
'type' => $deviceType,
|
||||||
|
])->orderBy('sort', 'desc')->get();
|
||||||
|
|
||||||
|
switch ($deviceType) {
|
||||||
|
case DeviceType::Soil:
|
||||||
|
$end = now()->startOfHour();
|
||||||
|
$start = $end->copy()->subHours(5);
|
||||||
|
|
||||||
|
$monitoringLogGroups = SoilMonitoringLog::where('agricultural_base_id', $baseId)
|
||||||
|
->where('monitored_at', '>=', $start)
|
||||||
|
->get()
|
||||||
|
->groupBy('device_id');
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
foreach ($deviceColumns as $deviceColumn) {
|
||||||
|
$x = [];
|
||||||
|
$series = [];
|
||||||
|
|
||||||
|
foreach ($devices as $device) {
|
||||||
|
$monitoringLogMap = $monitoringLogGroups->get($device->id)->keyBy('monitored_at');
|
||||||
|
|
||||||
|
$startAt = $start->copy();
|
||||||
|
|
||||||
|
$y = [];
|
||||||
|
|
||||||
|
while ($startAt->lte($end)) {
|
||||||
|
$monitoringLog = $monitoringLogMap->get(
|
||||||
|
$monitoredAt = $startAt->format('Y-m-d H:i:s')
|
||||||
|
);
|
||||||
|
|
||||||
|
$x[] = $monitoredAt;
|
||||||
|
$y[] = $monitoringLog?->{$deviceColumn};
|
||||||
|
|
||||||
|
$startAt->addHours(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$series[] = [
|
||||||
|
'name' => $device->monitoring_point,
|
||||||
|
'data' => $y,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data[$deviceColumn] = [
|
||||||
|
'x_axis' => $x,
|
||||||
|
'series' => $series,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
|
||||||
|
case DeviceType::WaterQuality:
|
||||||
|
return [];
|
||||||
|
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询设备今天(按天),近一周(按天),近一个月(按天)
|
* 查询设备今天(按天),近一周(按天),近一个月(按天)
|
||||||
*/
|
*/
|
||||||
|
|
@ -329,7 +400,7 @@ class DeviceController extends Controller
|
||||||
'noise',
|
'noise',
|
||||||
'illumination',
|
'illumination',
|
||||||
'pm25',
|
'pm25',
|
||||||
'pm10',
|
'pm10',
|
||||||
];
|
];
|
||||||
if($diffDays) {
|
if($diffDays) {
|
||||||
$getArr[] = 'daily_rainfall';
|
$getArr[] = 'daily_rainfall';
|
||||||
|
|
@ -397,7 +468,7 @@ class DeviceController extends Controller
|
||||||
break;
|
break;
|
||||||
case 'turbidity':
|
case 'turbidity':
|
||||||
$data[$column][$key] = 0.33;
|
$data[$column][$key] = 0.33;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
// if($datalist[$key][$column] ?? null){//如果存在数据则暂存该值
|
// if($datalist[$key][$column] ?? null){//如果存在数据则暂存该值
|
||||||
|
|
@ -429,7 +500,7 @@ class DeviceController extends Controller
|
||||||
|
|
||||||
$setting = Setting::where('slug', 'ffmpeg_websocket_ip')->first();
|
$setting = Setting::where('slug', 'ffmpeg_websocket_ip')->first();
|
||||||
$dataValue = $setting?->value ?? '{"ip":"127.0.0.1", "port":"80"}';
|
$dataValue = $setting?->value ?? '{"ip":"127.0.0.1", "port":"80"}';
|
||||||
|
|
||||||
$data = json_decode($dataValue);
|
$data = json_decode($dataValue);
|
||||||
|
|
||||||
return $this->json($data);
|
return $this->json($data);
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ Route::group(['middleware' => 'auth:sanctum'], function () {
|
||||||
Route::get('crop-yield-total-chart', [CropYieldController::class, 'totalStaticsChart']); //城镇统计产值
|
Route::get('crop-yield-total-chart', [CropYieldController::class, 'totalStaticsChart']); //城镇统计产值
|
||||||
Route::get('device-data-statics', [DeviceController::class, 'dataStatics']); //指定设备,当天的设备数据
|
Route::get('device-data-statics', [DeviceController::class, 'dataStatics']); //指定设备,当天的设备数据
|
||||||
Route::get('device-base-data-statics', [DeviceController::class, 'baseDataStatics']);
|
Route::get('device-base-data-statics', [DeviceController::class, 'baseDataStatics']);
|
||||||
|
Route::get('device-base-data-statics-v2', [DeviceController::class, 'baseDataStaticsV2']);
|
||||||
|
|
||||||
/** 系统管理 **/
|
/** 系统管理 **/
|
||||||
Route::apiResource('admin-users', AdminUserController::class)->names('admin_users');
|
Route::apiResource('admin-users', AdminUserController::class)->names('admin_users');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue