Compare commits

..

No commits in common. "40df91fcc68d8a2f00d5d4cea982333a3fd9d42d" and "f190913eaddea6f32f3d2e8693f0862e93e9cbde" have entirely different histories.

16 changed files with 83 additions and 137 deletions

View File

@ -12,7 +12,6 @@ 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
{ {
@ -44,16 +43,12 @@ 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,7 +10,6 @@ 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
{ {
@ -42,16 +41,12 @@ 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,11 +39,7 @@ 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);
}; };
@ -70,7 +66,6 @@ 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,
@ -85,7 +80,6 @@ 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 => '昆虫性诱设备',
@ -104,26 +98,61 @@ class DeviceLogSyncCommand extends Command
]); ]);
break; break;
case DeviceType::Soil: case DeviceType::Soil:
case DeviceType::WaterQuality: $data = $httpClient->getLatestSoilReport($device->sn);
case DeviceType::Meteorological:
case DeviceType::InsecticidalLamp:
$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;
}
$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:
$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);
if (empty($data)) {
$device->update([
'status' => DeviceStatus::Offline,
]);
$this->warn('设备数据为空');
break; break;
} else {
$this->info('设备数据: '.json_encode($data));
} }
$log = DeviceLog::firstOrCreate([ $log = DeviceLog::firstOrCreate([
@ -150,10 +179,8 @@ 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) {
@ -184,16 +211,6 @@ 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', str_replace('xxxxS_', '', $item['deviceId'])) Device::where('sn', $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,7 +8,6 @@ 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
{ {
@ -40,16 +39,12 @@ 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,7 +8,6 @@ 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
{ {
@ -40,16 +39,12 @@ 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,7 +11,6 @@ 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
{ {
@ -38,7 +37,6 @@ 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')
@ -49,9 +47,6 @@ 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'])
->everyTenMinutes() ->everyFiveMinutes()
->runInBackground(); ->runInBackground();
$schedule->command(Commands\MonitorDeviceHealthCommand::class, ['dianxin']) $schedule->command(Commands\MonitorDeviceHealthCommand::class, ['dianxin'])
->everyTenMinutes() ->everyFiveMinutes()
->runInBackground(); ->runInBackground();
} }

View File

@ -763,14 +763,9 @@ 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' => $address, 'address' => (string) data_get($result, 'data.url'),
'expires' => data_get($result, 'data.expiresIn'), 'expires' => data_get($result, 'data.expiresIn'),
]; ];
@ -788,7 +783,6 @@ 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,11 +11,10 @@ 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->isAdministrator()){ if($user->id != 1){
$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,21 +31,6 @@ 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,8 +6,4 @@ 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($username) public function name($name)
{ {
return $this->where('username', 'like', '%'.$username.'%'); return $this->where('username', 'like', '%'.$name.'%');
} }
} }

View File

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

View File

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