1
0
Fork 0

设备数据下行

develop
李静 2023-07-17 12:53:17 +08:00
parent ff775ec9d5
commit 1414cfae3d
3 changed files with 30 additions and 10 deletions

View File

@ -5,7 +5,6 @@ namespace App\Console\Commands;
use App\Models\Device; use App\Models\Device;
use App\Services\DeviceLogService; use App\Services\DeviceLogService;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Throwable; use Throwable;
class DeviceLogSyncCommand extends Command class DeviceLogSyncCommand extends Command

View File

@ -26,7 +26,7 @@ class HttpClient
* @param int $perPage * @param int $perPage
* @return array * @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', [ $result = $this->post('/api/deviceFlow/v1/list', [
'device_id' => $deviceId, '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']; 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 string $url
* @param array $data * @param array $data
@ -77,13 +104,7 @@ class HttpClient
'Signature' => $this->sign(compact('nonce', 'timestamp')), 'Signature' => $this->sign(compact('nonce', 'timestamp')),
])->baseUrl(self::ENDPOINT_URL)->send($method, $url, $options); ])->baseUrl(self::ENDPOINT_URL)->send($method, $url, $options);
$result = $response->throw()->json(); return $response->throw()->json();
if (data_get($result, 'success') !== true) {
throw new RuntimeException(data_get($result, 'msg', '出错啦!'));
}
return $result;
} }
/** /**

View File

@ -41,7 +41,7 @@ class DeviceLogService
$perPage = 50; $perPage = 50;
do { do {
$data = $httpClient->getDeviceFlowList( $data = $httpClient->deviceFlowList(
$device->sn, $start, $end, $page, $perPage $device->sn, $start, $end, $page, $perPage
); );