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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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