Compare commits
12 Commits
f190913ead
...
40df91fcc6
| Author | SHA1 | Date |
|---|---|---|
|
|
40df91fcc6 | |
|
|
7daf2e52f3 | |
|
|
fb09582af1 | |
|
|
50e4d6189b | |
|
|
da30fb9eb4 | |
|
|
5bd37b9ce4 | |
|
|
9407d89f23 | |
|
|
8cbe7fd09b | |
|
|
1593990351 | |
|
|
ae7cde35c0 | |
|
|
153eded62a | |
|
|
d67acaf7c0 |
|
|
@ -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,12 +44,16 @@ 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();
|
||||
|
||||
foreach ($devices as $device) {
|
||||
$this->createReport($device);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
|
||||
sleep($sleep);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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,12 +42,16 @@ 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();
|
||||
|
||||
foreach ($devices as $device) {
|
||||
$this->createReport($device);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
|
||||
sleep($sleep);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -39,7 +39,11 @@ 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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -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,12 +40,16 @@ 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();
|
||||
|
||||
foreach ($devices as $device) {
|
||||
$this->createReport($device);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
|
||||
sleep($seconds);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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,12 +40,16 @@ 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();
|
||||
|
||||
foreach ($devices as $device) {
|
||||
$this->createReport($device);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
|
||||
sleep($seconds);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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,6 +38,7 @@ 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')
|
||||
|
|
@ -47,6 +49,9 @@ class WormReportCommand extends Command
|
|||
$this->info('==================================');
|
||||
$this->createReport($device);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
|
||||
sleep($seconds);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最新的气象数据
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -6,4 +6,8 @@ use EloquentFilter\ModelFilter;
|
|||
|
||||
class AdminRoleFilter extends ModelFilter
|
||||
{
|
||||
public function name($name)
|
||||
{
|
||||
return $this->where('name', 'like', '%'.$name.'%');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.'%');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ return [
|
|||
'appid' => env('YDQLY_APPID'),
|
||||
'secret' => env('YDQLY_SECRET'),
|
||||
'rsa' => env('YDQLY_RSA'),
|
||||
// 播放地址缓存
|
||||
'play_proxy' => env('YDQLY_PLAY_PROXY'),
|
||||
],
|
||||
|
||||
// 中国电信魔镜
|
||||
|
|
|
|||
|
|
@ -123,7 +123,9 @@ class EndpointPermissionSeeder extends Seeder
|
|||
'name' => '账号管理',
|
||||
'curd' => true,
|
||||
'children' => [
|
||||
'edit_password' => '修改密码', 'enable' => '启用/禁用',
|
||||
'edit_password' => '修改密码',
|
||||
'enable' => '启用/禁用',
|
||||
'unban' => '解封',
|
||||
]
|
||||
],
|
||||
'operation_log' => ['name' => '系统日志', 'curd' => ['index']],
|
||||
|
|
|
|||
|
|
@ -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' => ''],
|
||||
],
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in New Issue