From ff775ec9d59293df43d867f019ee02a1ad6046ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 17 Jul 2023 12:00:06 +0800 Subject: [PATCH 1/9] Fix --- app/Services/DeviceLogService.php | 87 +++++++------------------------ 1 file changed, 19 insertions(+), 68 deletions(-) diff --git a/app/Services/DeviceLogService.php b/app/Services/DeviceLogService.php index 478f7cd..a345dd9 100644 --- a/app/Services/DeviceLogService.php +++ b/app/Services/DeviceLogService.php @@ -56,74 +56,25 @@ class DeviceLogService continue; } - if ($device->isTypeSoil()) { - // 如果包含气象设备监测字段,则跳过 - if (Arr::hasAny($item['data'], [ - 'day_rainfall', - 'accumulate_rainfall', - 'potassium_content', - 'moment_rainfall', - 'pm10_concentration', - 'pm25_concentration', - 'box_noise', - 'box_carbon', - 'box_humidity', - 'box_pressure', - 'box_temperature', - 'box_illumination', - 'wind_power', - 'wind_speed', - 'wind_degree', - 'wind_direction', - ])) { - continue; - } - } elseif ($device->isTypeMeteorological()) { - // 如果包含土壤设备监测字段,则跳过 - if (Arr::hasAny($item['data'], [ - 'nitrogen_content', - 'phosphorus_content', - 'potassium_content', - 'conductivity', - 'soil_humidity', - 'soil_temperature', - ])) { - continue; - } - } - - if ( - $device->isTypeSoil() && Arr::hasAny($item['data'], [ - - ]) - ) { - - } elseif ( - $device->isTypeMeteorological() && - Arr::hasAny( - $item['data'], - [ - 'nitrogen_content', - 'phosphorus_content', - 'potassium_content', - 'conductivity', - 'soil_humidity', - 'soil_temperature', - ] - ) - ) { - continue; - } - - $isSoilMonitoring = Arr::hasAny($item['data'], [ - 'soil_humidity', - 'soil_temperature', - 'nitrogen_content', - 'potassium_content', - 'phosphorus_content', - ]); - - if (($device->isTypeSoil() && ! $isSoilMonitoring) || (! $device->isTypeSoil() && $isSoilMonitoring)) { + // 如果多合一气象监测器包含土壤监控时,需过滤掉气象监控的数据 + if ($device->isTypeSoil() && Arr::hasAny($item['data'], [ + 'current_rainfall', + 'day_rainfall', + 'accumulate_rainfall', + 'moment_rainfall', + 'pm10_concentration', + 'pm25_concentration', + 'box_illumination', + 'box_pressure', + 'box_carbon', + 'box_temperature', + 'box_humidity', + 'box_noise', + 'wind_degree', + 'wind_direction', + 'wind_power', + 'wind_speed', + ])) { continue; } From 1414cfae3de00176888a076cdcd1a59f8fb08953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 17 Jul 2023 12:53:17 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=B8=8B=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/DeviceLogSyncCommand.php | 1 - app/Iot/Linkos/HttpClient.php | 37 +++++++++++++++---- app/Services/DeviceLogService.php | 2 +- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/Console/Commands/DeviceLogSyncCommand.php b/app/Console/Commands/DeviceLogSyncCommand.php index 8a900ea..28020b0 100644 --- a/app/Console/Commands/DeviceLogSyncCommand.php +++ b/app/Console/Commands/DeviceLogSyncCommand.php @@ -5,7 +5,6 @@ namespace App\Console\Commands; use App\Models\Device; use App\Services\DeviceLogService; use Illuminate\Console\Command; -use Illuminate\Support\Carbon; use Throwable; class DeviceLogSyncCommand extends Command diff --git a/app/Iot/Linkos/HttpClient.php b/app/Iot/Linkos/HttpClient.php index 1b01273..0d3a725 100644 --- a/app/Iot/Linkos/HttpClient.php +++ b/app/Iot/Linkos/HttpClient.php @@ -26,7 +26,7 @@ class HttpClient * @param int $perPage * @return array */ - public function getDeviceFlowList(string $deviceId, Carbon $start, Carbon $end, int $page = 1, int $perPage = 50): array + public function deviceFlowList(string $deviceId, Carbon $start, Carbon $end, int $page = 1, int $perPage = 50): array { $result = $this->post('/api/deviceFlow/v1/list', [ 'device_id' => $deviceId, @@ -38,9 +38,36 @@ class HttpClient ], ]); + if (data_get($result, 'success') !== true) { + throw new RuntimeException(data_get($result, 'msg', '出错啦!')); + } + return $result['data']; } + /** + * 设备数据下行 + * + * @param string $deviceId + * @param string $service + * @param array $data + * @param boolean $confirm + * @param boolean $clear + * @param boolean $schedule + * @return array + */ + public function deviceDataDownlink(string $deviceId, string $service, array $data = [], bool $confirm = true, bool $clear = true, bool $schedule = false): array + { + return $this->post('/api/down', [ + 'device_id' => $deviceId, + 'service_id' => $service, + 'parameter' => $data, + 'clear' => (int) $clear, + 'schedule' => (int) $schedule, + 'confirm' => (int) $confirm, + ]); + } + /** * @param string $url * @param array $data @@ -77,13 +104,7 @@ class HttpClient 'Signature' => $this->sign(compact('nonce', 'timestamp')), ])->baseUrl(self::ENDPOINT_URL)->send($method, $url, $options); - $result = $response->throw()->json(); - - if (data_get($result, 'success') !== true) { - throw new RuntimeException(data_get($result, 'msg', '出错啦!')); - } - - return $result; + return $response->throw()->json(); } /** diff --git a/app/Services/DeviceLogService.php b/app/Services/DeviceLogService.php index a345dd9..f5dfe3a 100644 --- a/app/Services/DeviceLogService.php +++ b/app/Services/DeviceLogService.php @@ -41,7 +41,7 @@ class DeviceLogService $perPage = 50; do { - $data = $httpClient->getDeviceFlowList( + $data = $httpClient->deviceFlowList( $device->sn, $start, $end, $page, $perPage ); From aec3b6a338797482cfd21e124f263e7067f5fabf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 17 Jul 2023 13:35:40 +0800 Subject: [PATCH 3/9] Update --- app/Http/Controllers/Callback/LinkosCallbackController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Callback/LinkosCallbackController.php b/app/Http/Controllers/Callback/LinkosCallbackController.php index 1ccabcf..d3d2938 100644 --- a/app/Http/Controllers/Callback/LinkosCallbackController.php +++ b/app/Http/Controllers/Callback/LinkosCallbackController.php @@ -10,7 +10,7 @@ class LinkosCallbackController extends Controller { public function __invoke(Request $request) { - logger()->info('linkos callback parameters -------->', $request->input()); + logger()->debug('linkos callback parameters -------->', $request->input()); if ($request->filled('notify_type')) { switch ($request->notify_type) { From 132c36e9eff65b419df8b2a705322f1db92de717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 17 Jul 2023 13:50:17 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E9=80=9A=E9=A3=8E=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=83=A8=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/DeviceLogSyncCommand.php | 6 ++++++ app/Models/Device.php | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/app/Console/Commands/DeviceLogSyncCommand.php b/app/Console/Commands/DeviceLogSyncCommand.php index 28020b0..02bc61c 100644 --- a/app/Console/Commands/DeviceLogSyncCommand.php +++ b/app/Console/Commands/DeviceLogSyncCommand.php @@ -63,7 +63,13 @@ class DeviceLogSyncCommand extends Command /** @var \Illuminate\Database\Eloquent\Collection */ $devices = Device::with(['factory'])->poweredBy($factory)->get(); + /** @var \App\Models\Device */ foreach ($devices as $device) { + // 忽略通风设备 + if ($device->isTypeAir()) { + continue; + } + $this->info('=========================================='); $this->info('设备编号: ' . $device->sn); $this->info('设备名称: ' . $device->name); diff --git a/app/Models/Device.php b/app/Models/Device.php index 0afe60b..4ed8252 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -87,4 +87,9 @@ class Device extends Model { return $this->type === static::TYPE_METEOROLOGICAL; } + + public function isTypeAir(): bool + { + return $this->type === static::TYPE_AIR; + } } From f11d16251de89234276da6abd69f98f1036d887c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 24 Jul 2023 14:13:20 +0800 Subject: [PATCH 5/9] Update --- app/Services/DeviceLogService.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Services/DeviceLogService.php b/app/Services/DeviceLogService.php index f5dfe3a..e3c35d2 100644 --- a/app/Services/DeviceLogService.php +++ b/app/Services/DeviceLogService.php @@ -448,6 +448,10 @@ class DeviceLogService switch ($key) { case 'wind_samples': $attributes['wind_degree'] = value(function (array $windSamples) { + if (empty($windSamples)) { + return null; + } + $x = 0; $y = 0; @@ -477,6 +481,10 @@ class DeviceLogService }, $item); $attributes['wind_direction'] = value(function ($windDegree) { + if (is_null($windDegree)) { + return null; + } + if ($windDegree >= 22.5 && $windDegree < 67.5) { return MeteorologicalDailyReport::WIND_DIRECTION_NORTHEAST; } elseif ($windDegree >= 67.5 && $windDegree < 112.5) { From 151f7877e4f62d00404567d6953071c8ccd2a6aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Thu, 27 Jul 2023 15:47:40 +0800 Subject: [PATCH 6/9] Update --- app/Iot/Linkos/HttpClient.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Iot/Linkos/HttpClient.php b/app/Iot/Linkos/HttpClient.php index 0d3a725..758fed8 100644 --- a/app/Iot/Linkos/HttpClient.php +++ b/app/Iot/Linkos/HttpClient.php @@ -68,6 +68,13 @@ class HttpClient ]); } + public function get(string $url, array $query = []): array + { + return $this->request('GET', $url, [ + 'query' => $query, + ]); + } + /** * @param string $url * @param array $data From 8da20ed9adb496fc3346159a132bce94941ef630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Thu, 27 Jul 2023 15:52:32 +0800 Subject: [PATCH 7/9] Update --- app/Iot/Linkos/HttpClient.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/Iot/Linkos/HttpClient.php b/app/Iot/Linkos/HttpClient.php index 758fed8..7900a4e 100644 --- a/app/Iot/Linkos/HttpClient.php +++ b/app/Iot/Linkos/HttpClient.php @@ -68,6 +68,23 @@ class HttpClient ]); } + /** + * 获取设备最新属性数据 + */ + public function getDeviceStatus(string $deviceId, array $props): array + { + $result = $this->get('/api/deviceStatus/v1/getDeviceStatus', [ + 'deviceCode' => $deviceId, + 'prop' => implode(",", $props), + ]); + + if (data_get($result, 'success') !== true) { + throw new RuntimeException(data_get($result, 'msg', '出错啦!')); + } + + return $result['data']; + } + public function get(string $url, array $query = []): array { return $this->request('GET', $url, [ From b0d9dbe3f6c3863dd067104c4637bfa54b1e9df3 Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Fri, 28 Jul 2023 12:14:09 +0800 Subject: [PATCH 8/9] monitor history --- app/Http/Controllers/Controller.php | 4 ++-- app/Services/Admin/DeviceService.php | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 359e510..d05436b 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -7,7 +7,7 @@ use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Routing\Controller as BaseController; use Illuminate\Pagination\LengthAwarePaginator; -use Illuminate\Http\Resources\Json\ResourceCollection ; +use Illuminate\Http\Resources\Json\ResourceCollection; use Illuminate\Support\Arr; class Controller extends BaseController @@ -16,7 +16,7 @@ class Controller extends BaseController public function json($data, $code = 0, $message = '') { - if ($data instanceof ResourceCollection ) { + if ($data instanceof ResourceCollection) { $data = $data->resource; } $result = ['data' => $data ?: '', 'status' => $code, 'msg' => $message]; diff --git a/app/Services/Admin/DeviceService.php b/app/Services/Admin/DeviceService.php index 6cc14d2..73579dc 100644 --- a/app/Services/Admin/DeviceService.php +++ b/app/Services/Admin/DeviceService.php @@ -35,9 +35,11 @@ class DeviceService extends BaseService $url = data_get($item->extends, $history ? 'rtsp_history' : 'rtsp_url'); $src = null; if ($base && $url) { - // 查看历史监控 + // 查看历史监控 &starttime=2023_02_02_14_00_00&endtime=2023_02_02_15_00_00 if ($history && $start && $end) { - $url .= '?start=' . date('Y-m-d', $start) . '&end=' . data('Y-m-d', $end); + $start_format = Carbon::createFromTimestamp($start)->startOfDay()->format('Y_m_d_H_i_s'); + $end_format = Carbon::createFromTimestamp($end)->endOfDay()->format('Y_m_d_H_i_s'); + $url .= (str_contains($url, '?') ? '&' : '?') .'starttime=' . $start_format . '&endtime=' . $end_format; } $src = $base . base64_encode($url); } From 09a24aaa83307bbbc0f29ada6d0fcb687ab16378 Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Fri, 28 Jul 2023 12:22:17 +0800 Subject: [PATCH 9/9] monitor history --- app/Admin/Controllers/DeviceController.php | 4 ++-- app/Services/Admin/DeviceService.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Admin/Controllers/DeviceController.php b/app/Admin/Controllers/DeviceController.php index 8abac77..322a918 100644 --- a/app/Admin/Controllers/DeviceController.php +++ b/app/Admin/Controllers/DeviceController.php @@ -2,7 +2,7 @@ namespace App\Admin\Controllers; -use Slowlyo\OwlAdmin\Renderers\{Button, Form, Page, TableColumn, TextControl, Json, Component, CRUDTable, Card, Video, DateRangeControl, Mapping, SelectControl}; +use Slowlyo\OwlAdmin\Renderers\{Button, Form, Page, TableColumn, TextControl, Json, Component, CRUDTable, Card, Video, InputDatetimeRange, DateTimeControl, Mapping, SelectControl}; use Slowlyo\OwlAdmin\Controllers\AdminController; use App\Services\Admin\DeviceService; use App\Admin\Components; @@ -153,7 +153,7 @@ class DeviceController extends AdminController ->headerToolbar([]) ->filter($this->baseFilter()->actions([])->body([ amisMake()->SelectControl('monitor_mode', '点位名称')->size('md')->options($query->toArray())->selectFirst(true), - DateRangeControl::make()->name('date')->label('日期')->maxDate('now')->size('md'), + InputDatetimeRange::make()->name('date')->label('日期')->maxDate('now')->size('md'), Button::make()->label(__('admin.reset'))->actionType('clear-and-submit'), Component::make()->setType('submit')->label(__('admin.search'))->level('primary'), ])) diff --git a/app/Services/Admin/DeviceService.php b/app/Services/Admin/DeviceService.php index 73579dc..f93034f 100644 --- a/app/Services/Admin/DeviceService.php +++ b/app/Services/Admin/DeviceService.php @@ -37,8 +37,8 @@ class DeviceService extends BaseService if ($base && $url) { // 查看历史监控 &starttime=2023_02_02_14_00_00&endtime=2023_02_02_15_00_00 if ($history && $start && $end) { - $start_format = Carbon::createFromTimestamp($start)->startOfDay()->format('Y_m_d_H_i_s'); - $end_format = Carbon::createFromTimestamp($end)->endOfDay()->format('Y_m_d_H_i_s'); + $start_format = Carbon::createFromTimestamp($start)->format('Y_m_d_H_i_s'); + $end_format = Carbon::createFromTimestamp($end)->format('Y_m_d_H_i_s'); $url .= (str_contains($url, '?') ? '&' : '?') .'starttime=' . $start_format . '&endtime=' . $end_format; } $src = $base . base64_encode($url);