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

View File

@ -10,6 +10,7 @@ use App\Models\MeteorologicalMonitoringLog;
use App\Models\SoilMonitoringLog;
use App\Services\BiAngDeviceService;
use Illuminate\Console\Command;
use Throwable;
class DeviceLogReportCommand extends Command
{
@ -41,11 +42,15 @@ class DeviceLogReportCommand extends Command
$sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 300, $this->option('sleep'));
while (true) {
/** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy("device-supplier-biang")->get();
try {
/** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy("device-supplier-biang")->get();
foreach ($devices as $device) {
$this->createReport($device);
foreach ($devices as $device) {
$this->createReport($device);
}
} catch (Throwable $e) {
report($e);
}
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'));
while (true) {
$this->sync();
try {
$this->sync();
} catch (Throwable $e) {
report($e);
}
sleep($sleep);
};
@ -66,6 +70,7 @@ class DeviceLogSyncCommand extends Command
if (! in_array($device->type, [
DeviceType::Monitor,
DeviceType::Soil,
DeviceType::WaterQuality,
DeviceType::Meteorological,
DeviceType::Worm,
DeviceType::InsectSexLure,
@ -80,6 +85,7 @@ class DeviceLogSyncCommand extends Command
$this->info('设备类型: ' . match ($device->type) {
DeviceType::Monitor => '苗情设备',
DeviceType::Soil => '土壤设备',
DeviceType::WaterQuality => '水质设备',
DeviceType::Meteorological => '气象设备',
DeviceType::Worm => '虫情设备',
DeviceType::InsectSexLure => '昆虫性诱设备',
@ -98,61 +104,26 @@ class DeviceLogSyncCommand extends Command
]);
break;
case DeviceType::Soil:
$data = $httpClient->getLatestSoilReport($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::WaterQuality:
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:
$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)) {
$device->update([
'status' => DeviceStatus::Offline,
]);
$this->warn('设备数据为空');
$this->warn('设备数据: 无');
break;
} else {
$this->info('设备数据: '.json_encode($data));
}
$log = DeviceLog::firstOrCreate([
@ -179,8 +150,10 @@ class DeviceLogSyncCommand extends Command
$device->update([
'status' => DeviceStatus::Offline,
]);
$this->warn('设备数据为空');
$this->warn('设备数据: 无');
break;
} else {
$this->info('设备数据: '.json_encode($data));
}
foreach ($data['imgUrl'] as $item) {
@ -211,6 +184,16 @@ class DeviceLogSyncCommand extends Command
break;
}
switch ($device->status) {
case DeviceStatus::Online:
$this->info('设备状态: 在线');
break;
case DeviceStatus::Offline:
$this->warn('设备状态: 离线');
break;
}
$this->info('同步成功!');
} catch (Throwable $e) {
report($e);

View File

@ -64,7 +64,7 @@ class MonitorDeviceHealthCommand extends Command
);
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('type', DeviceType::Monitor)
->whereIn('status', [DeviceStatus::Online, DeviceStatus::Offline])

View File

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

View File

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

View File

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

View File

@ -24,11 +24,11 @@ class Kernel extends ConsoleKernel
->runInBackground();
$schedule->command(Commands\MonitorDeviceHealthCommand::class, ['yidong'])
->everyFiveMinutes()
->everyTenMinutes()
->runInBackground();
$schedule->command(Commands\MonitorDeviceHealthCommand::class, ['dianxin'])
->everyFiveMinutes()
->everyTenMinutes()
->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 [
'type' => 'iframe',
'address' => (string) data_get($result, 'data.url'),
'address' => $address,
'expires' => data_get($result, 'data.expiresIn'),
];
@ -783,6 +788,7 @@ class DeviceController extends Controller
[
'transType' => 4,
'natType' => 1,
'nAudioType' => 1,
],
);
$address = data_get($result, 'data.playUrl');

View File

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

View File

@ -31,6 +31,21 @@ class HttpClient
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
{
public function name($name)
{
return $this->where('name', 'like', '%'.$name.'%');
}
}

View File

@ -6,8 +6,8 @@ use EloquentFilter\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'),
'secret' => env('YDQLY_SECRET'),
'rsa' => env('YDQLY_RSA'),
// 播放地址缓存
'play_proxy' => env('YDQLY_PLAY_PROXY'),
],
// 中国电信魔镜

View File

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

View File

@ -87,6 +87,22 @@ class KeywordsTableSeeder extends Seeder
'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' => ''],
],
]