Compare commits

...

12 Commits

Author SHA1 Message Date
Jing Li 40df91fcc6 同步比昂水质设备数据 2024-01-29 12:44:23 +08:00
Jing Li 7daf2e52f3 Update 2024-01-20 16:12:55 +08:00
Jing Li fb09582af1 Update 2024-01-20 15:33:26 +08:00
Jing Li 50e4d6189b Update 2024-01-16 11:16:52 +08:00
Jing Li da30fb9eb4 Update 2024-01-16 11:14:49 +08:00
Jing Li 5bd37b9ce4 优化命令 2024-01-10 15:07:23 +08:00
Jing Li 9407d89f23 Update 2024-01-10 14:51:17 +08:00
Jing Li 8cbe7fd09b 移动千里眼播放地址的代理 2024-01-03 14:54:01 +08:00
Jing Li 1593990351 Update 2024-01-03 11:12:53 +08:00
Jing Li ae7cde35c0 Update 2024-01-02 15:28:45 +08:00
Jing Li 153eded62a Update 2024-01-02 14:54:07 +08:00
Jing Li d67acaf7c0 电信监控设备播放地址优化 2024-01-02 14:43:39 +08:00
16 changed files with 135 additions and 81 deletions

View File

@ -12,6 +12,7 @@ use App\Models\SoilMonitoringDailyLog;
use App\Models\SoilMonitoringLog; use App\Models\SoilMonitoringLog;
use App\Services\BiAngDeviceService; use App\Services\BiAngDeviceService;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Throwable;
class DeviceLogDailyReportCommand extends Command class DeviceLogDailyReportCommand extends Command
{ {
@ -43,12 +44,16 @@ class DeviceLogDailyReportCommand extends Command
$sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 300, $this->option('sleep')); $sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 300, $this->option('sleep'));
while (true) { while (true) {
try {
/** @var \Illuminate\Database\Eloquent\Collection */ /** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy("device-supplier-biang")->get(); $devices = Device::supplierBy("device-supplier-biang")->get();
foreach ($devices as $device) { foreach ($devices as $device) {
$this->createReport($device); $this->createReport($device);
} }
} catch (Throwable $e) {
report($e);
}
sleep($sleep); sleep($sleep);
}; };

View File

@ -10,6 +10,7 @@ use App\Models\MeteorologicalMonitoringLog;
use App\Models\SoilMonitoringLog; use App\Models\SoilMonitoringLog;
use App\Services\BiAngDeviceService; use App\Services\BiAngDeviceService;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Throwable;
class DeviceLogReportCommand extends Command class DeviceLogReportCommand extends Command
{ {
@ -41,12 +42,16 @@ class DeviceLogReportCommand extends Command
$sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 300, $this->option('sleep')); $sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 300, $this->option('sleep'));
while (true) { while (true) {
try {
/** @var \Illuminate\Database\Eloquent\Collection */ /** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy("device-supplier-biang")->get(); $devices = Device::supplierBy("device-supplier-biang")->get();
foreach ($devices as $device) { foreach ($devices as $device) {
$this->createReport($device); $this->createReport($device);
} }
} catch (Throwable $e) {
report($e);
}
sleep($sleep); sleep($sleep);
}; };

View File

@ -39,7 +39,11 @@ class DeviceLogSyncCommand extends Command
$sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 60, $this->option('sleep')); $sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 60, $this->option('sleep'));
while (true) { while (true) {
try {
$this->sync(); $this->sync();
} catch (Throwable $e) {
report($e);
}
sleep($sleep); sleep($sleep);
}; };
@ -66,6 +70,7 @@ class DeviceLogSyncCommand extends Command
if (! in_array($device->type, [ if (! in_array($device->type, [
DeviceType::Monitor, DeviceType::Monitor,
DeviceType::Soil, DeviceType::Soil,
DeviceType::WaterQuality,
DeviceType::Meteorological, DeviceType::Meteorological,
DeviceType::Worm, DeviceType::Worm,
DeviceType::InsectSexLure, DeviceType::InsectSexLure,
@ -80,6 +85,7 @@ class DeviceLogSyncCommand extends Command
$this->info('设备类型: ' . match ($device->type) { $this->info('设备类型: ' . match ($device->type) {
DeviceType::Monitor => '苗情设备', DeviceType::Monitor => '苗情设备',
DeviceType::Soil => '土壤设备', DeviceType::Soil => '土壤设备',
DeviceType::WaterQuality => '水质设备',
DeviceType::Meteorological => '气象设备', DeviceType::Meteorological => '气象设备',
DeviceType::Worm => '虫情设备', DeviceType::Worm => '虫情设备',
DeviceType::InsectSexLure => '昆虫性诱设备', DeviceType::InsectSexLure => '昆虫性诱设备',
@ -98,61 +104,26 @@ class DeviceLogSyncCommand extends Command
]); ]);
break; break;
case DeviceType::Soil: case DeviceType::Soil:
$data = $httpClient->getLatestSoilReport($device->sn); case DeviceType::WaterQuality:
if (empty($data)) {
$device->update([
'status' => DeviceStatus::Offline,
]);
$this->warn('设备数据为空');
break;
}
$log = DeviceLog::firstOrCreate([
'device_id' => $device->id,
'reported_at' => $data['time'],
], [
'data' => Arr::except($data, ['deviceId', 'time']),
]);
$device->update([
'status' => $now->copy()->subMinutes(60)->lt($log->reported_at) ? DeviceStatus::Online : DeviceStatus::Offline,
]);
break;
case DeviceType::Meteorological: case DeviceType::Meteorological:
$data = $httpClient->getLatestMeteorologicalReport($device->sn);
if (empty($data)) {
$device->update([
'status' => DeviceStatus::Offline,
]);
$this->warn('设备数据为空');
break;
}
$log = DeviceLog::firstOrCreate([
'device_id' => $device->id,
'reported_at' => $data['time'],
], [
'data' => Arr::except($data, ['deviceId', 'time']),
]);
$device->update([
'status' => $now->copy()->subMinutes(60)->lt($log->reported_at) ? DeviceStatus::Online : DeviceStatus::Offline,
]);
break;
case DeviceType::InsecticidalLamp: case DeviceType::InsecticidalLamp:
$data = $httpClient->getLatestLampReport($device->sn); $data = match ($device->type) {
DeviceType::Soil => $httpClient->getLatestSoilReport($device->sn),
DeviceType::WaterQuality => $httpClient->getLatestWaterDeviceReport($device->sn),
DeviceType::Meteorological => $httpClient->getLatestMeteorologicalReport($device->sn),
DeviceType::InsecticidalLamp => $httpClient->getLatestLampReport($device->sn),
};
if (empty($data)) { if (empty($data)) {
$device->update([ $device->update([
'status' => DeviceStatus::Offline, 'status' => DeviceStatus::Offline,
]); ]);
$this->warn('设备数据为空'); $this->warn('设备数据: 无');
break; break;
} else {
$this->info('设备数据: '.json_encode($data));
} }
$log = DeviceLog::firstOrCreate([ $log = DeviceLog::firstOrCreate([
@ -179,8 +150,10 @@ class DeviceLogSyncCommand extends Command
$device->update([ $device->update([
'status' => DeviceStatus::Offline, 'status' => DeviceStatus::Offline,
]); ]);
$this->warn('设备数据为空'); $this->warn('设备数据: 无');
break; break;
} else {
$this->info('设备数据: '.json_encode($data));
} }
foreach ($data['imgUrl'] as $item) { foreach ($data['imgUrl'] as $item) {
@ -211,6 +184,16 @@ class DeviceLogSyncCommand extends Command
break; break;
} }
switch ($device->status) {
case DeviceStatus::Online:
$this->info('设备状态: 在线');
break;
case DeviceStatus::Offline:
$this->warn('设备状态: 离线');
break;
}
$this->info('同步成功!'); $this->info('同步成功!');
} catch (Throwable $e) { } catch (Throwable $e) {
report($e); report($e);

View File

@ -64,7 +64,7 @@ class MonitorDeviceHealthCommand extends Command
); );
foreach ($result['data'] as $item) { foreach ($result['data'] as $item) {
Device::where('sn', $item['deviceId']) Device::where('sn', str_replace('xxxxS_', '', $item['deviceId']))
->where('supplier_key', 'device-supplier-yidong') ->where('supplier_key', 'device-supplier-yidong')
->where('type', DeviceType::Monitor) ->where('type', DeviceType::Monitor)
->whereIn('status', [DeviceStatus::Online, DeviceStatus::Offline]) ->whereIn('status', [DeviceStatus::Online, DeviceStatus::Offline])

View File

@ -8,6 +8,7 @@ use App\Models\InsecticidalLampDailyReport;
use App\Models\InsecticidalLampReport; use App\Models\InsecticidalLampReport;
use App\Services\YunFeiDeviceService; use App\Services\YunFeiDeviceService;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Throwable;
class DeviceLogDailyReportCommand extends Command class DeviceLogDailyReportCommand extends Command
{ {
@ -39,12 +40,16 @@ class DeviceLogDailyReportCommand extends Command
$seconds = (int) value(fn ($seconds) => is_numeric($seconds) ? $seconds : 300, $this->option('sleep')); $seconds = (int) value(fn ($seconds) => is_numeric($seconds) ? $seconds : 300, $this->option('sleep'));
while (true) { while (true) {
try {
/** @var \Illuminate\Database\Eloquent\Collection */ /** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy('device-supplier-yunfei')->get(); $devices = Device::supplierBy('device-supplier-yunfei')->get();
foreach ($devices as $device) { foreach ($devices as $device) {
$this->createReport($device); $this->createReport($device);
} }
} catch (Throwable $e) {
report($e);
}
sleep($seconds); sleep($seconds);
}; };

View File

@ -8,6 +8,7 @@ use App\Models\DeviceLog;
use App\Models\InsecticidalLampReport; use App\Models\InsecticidalLampReport;
use App\Services\YunFeiDeviceService; use App\Services\YunFeiDeviceService;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Throwable;
class DeviceLogReportCommand extends Command class DeviceLogReportCommand extends Command
{ {
@ -39,12 +40,16 @@ class DeviceLogReportCommand extends Command
$seconds = (int) value(fn ($seconds) => is_numeric($seconds) ? $seconds : 300, $this->option('sleep')); $seconds = (int) value(fn ($seconds) => is_numeric($seconds) ? $seconds : 300, $this->option('sleep'));
while (true) { while (true) {
try {
/** @var \Illuminate\Database\Eloquent\Collection */ /** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy('device-supplier-yunfei')->get(); $devices = Device::supplierBy('device-supplier-yunfei')->get();
foreach ($devices as $device) { foreach ($devices as $device) {
$this->createReport($device); $this->createReport($device);
} }
} catch (Throwable $e) {
report($e);
}
sleep($seconds); sleep($seconds);
}; };

View File

@ -11,6 +11,7 @@ use Illuminate\Console\Command;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Throwable;
class WormReportCommand extends Command class WormReportCommand extends Command
{ {
@ -37,6 +38,7 @@ class WormReportCommand extends Command
$seconds = (int) value(fn ($seconds) => is_numeric($seconds) ? $seconds : 60, $this->option('sleep')); $seconds = (int) value(fn ($seconds) => is_numeric($seconds) ? $seconds : 60, $this->option('sleep'));
while (true) { while (true) {
try {
/** @var \Illuminate\Database\Eloquent\Collection */ /** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::with(['project']) $devices = Device::with(['project'])
->supplierBy('device-supplier-yunfei') ->supplierBy('device-supplier-yunfei')
@ -47,6 +49,9 @@ class WormReportCommand extends Command
$this->info('=================================='); $this->info('==================================');
$this->createReport($device); $this->createReport($device);
} }
} catch (Throwable $e) {
report($e);
}
sleep($seconds); sleep($seconds);
} }

View File

@ -24,11 +24,11 @@ class Kernel extends ConsoleKernel
->runInBackground(); ->runInBackground();
$schedule->command(Commands\MonitorDeviceHealthCommand::class, ['yidong']) $schedule->command(Commands\MonitorDeviceHealthCommand::class, ['yidong'])
->everyFiveMinutes() ->everyTenMinutes()
->runInBackground(); ->runInBackground();
$schedule->command(Commands\MonitorDeviceHealthCommand::class, ['dianxin']) $schedule->command(Commands\MonitorDeviceHealthCommand::class, ['dianxin'])
->everyFiveMinutes() ->everyTenMinutes()
->runInBackground(); ->runInBackground();
} }

View File

@ -763,9 +763,14 @@ class DeviceController extends Controller
], ],
); );
$address = (string) data_get($result, 'data.url');
if (config('services.ydqly.play_proxy')) {
$address = str_replace('open.andmu.cn', 'lcyd.peidikeji.cn', $address);
}
return [ return [
'type' => 'iframe', 'type' => 'iframe',
'address' => (string) data_get($result, 'data.url'), 'address' => $address,
'expires' => data_get($result, 'data.expiresIn'), 'expires' => data_get($result, 'data.expiresIn'),
]; ];
@ -783,6 +788,7 @@ class DeviceController extends Controller
[ [
'transType' => 4, 'transType' => 4,
'natType' => 1, 'natType' => 1,
'nAudioType' => 1,
], ],
); );
$address = data_get($result, 'data.playUrl'); $address = data_get($result, 'data.playUrl');

View File

@ -11,10 +11,11 @@ class UserController extends Controller
{ {
public function info() public function info()
{ {
/** @var \App\Models\AdminUser */
$user = auth('api')->user(); $user = auth('api')->user();
$permissionsQuery = AdminPermission::query(); $permissionsQuery = AdminPermission::query();
if($user->id != 1){ if(! $user->isAdministrator()){
$permissions = $permissionsQuery->whereIn('id', $user->permissionIds()); $permissions = $permissionsQuery->whereIn('id', $user->permissionIds());
} }
$permissions = $permissionsQuery->pluck('slug')->toArray(); $permissions = $permissionsQuery->pluck('slug')->toArray();

View File

@ -31,6 +31,21 @@ class HttpClient
return $result['data'] ?? []; return $result['data'] ?? [];
} }
/**
* 获取最新的水质设备数据
*/
public function getLatestWaterDeviceReport(string $deviceId)
{
$result = $this->get(
$this->apiUrl('/api/open-api/open/getWaterDeviceData'),
[
'deviceId' => $deviceId,
]
);
return $result['data'] ?? [];
}
/** /**
* 获取最新的气象数据 * 获取最新的气象数据
*/ */

View File

@ -6,4 +6,8 @@ use EloquentFilter\ModelFilter;
class AdminRoleFilter extends ModelFilter class AdminRoleFilter extends ModelFilter
{ {
public function name($name)
{
return $this->where('name', 'like', '%'.$name.'%');
}
} }

View File

@ -6,8 +6,8 @@ use EloquentFilter\ModelFilter;
class AdminUserFilter extends ModelFilter class AdminUserFilter extends ModelFilter
{ {
public function name($name) public function name($username)
{ {
return $this->where('username', 'like', '%'.$name.'%'); return $this->where('username', 'like', '%'.$username.'%');
} }
} }

View File

@ -41,6 +41,8 @@ return [
'appid' => env('YDQLY_APPID'), 'appid' => env('YDQLY_APPID'),
'secret' => env('YDQLY_SECRET'), 'secret' => env('YDQLY_SECRET'),
'rsa' => env('YDQLY_RSA'), 'rsa' => env('YDQLY_RSA'),
// 播放地址缓存
'play_proxy' => env('YDQLY_PLAY_PROXY'),
], ],
// 中国电信魔镜 // 中国电信魔镜

View File

@ -123,7 +123,9 @@ class EndpointPermissionSeeder extends Seeder
'name' => '账号管理', 'name' => '账号管理',
'curd' => true, 'curd' => true,
'children' => [ 'children' => [
'edit_password' => '修改密码', 'enable' => '启用/禁用', 'edit_password' => '修改密码',
'enable' => '启用/禁用',
'unban' => '解封',
] ]
], ],
'operation_log' => ['name' => '系统日志', 'curd' => ['index']], 'operation_log' => ['name' => '系统日志', 'curd' => ['index']],

View File

@ -87,6 +87,22 @@ class KeywordsTableSeeder extends Seeder
'password' => '888888', 'password' => '888888',
]), ]),
], ],
[
'key' => 'device-project-xszlylzw',
'name' => '响石镇粮油作物病虫害监测站',
'value' => json_encode([
'username' => '响石镇粮油作物病虫害监测站',
'password' => '888888',
]),
],
[
'key' => 'device-project-ydsctfkj',
'name' => '(移动)四川太飞科技有限公司',
'value' => json_encode([
'username' => '四川太飞科技有限公司',
'password' => '123456',
]),
],
['key' => 'device-project-other', 'name' => '其它', 'value' => ''], ['key' => 'device-project-other', 'name' => '其它', 'value' => ''],
], ],
] ]