Итерация 3: инвентарь устройств
- Миграция devices (name, type, ip, mac, hostname, vendor, os, location, importance, status) - Device model + DeviceRepository с полным CRUD - DeviceService для бизнес-логики - MergeSuggestionService для предложений объединения (MAC→90%, hostname→60%) - DeviceController: список, создание, редактирование, карточка, удаление, создание из discovered_host - Шаблоны: devices/index, devices/form, devices/show - Dashboard с реальными счётчиками (устройства, новые находки) - Кнопка «Создать устройство» в Discovery для новых хостов - DeviceRepository + DeviceService + DeviceController в DI
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Domovoy\Services\Inventory;
|
||||
|
||||
use Domovoy\Models\DiscoveredHost;
|
||||
use Domovoy\Repositories\DeviceRepository;
|
||||
|
||||
class MergeSuggestionService
|
||||
{
|
||||
private DeviceRepository $deviceRepository;
|
||||
|
||||
public function __construct(DeviceRepository $deviceRepository)
|
||||
{
|
||||
$this->deviceRepository = $deviceRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find merge suggestions for a discovered host.
|
||||
* Returns array of ['device' => Device, 'confidence' => int, 'reason' => string]
|
||||
*/
|
||||
public function findSuggestions(DiscoveredHost $host): array
|
||||
{
|
||||
$suggestions = [];
|
||||
|
||||
// High confidence: MAC address match
|
||||
if ($host->macAddress !== null) {
|
||||
$device = $this->deviceRepository->findByMac($host->macAddress);
|
||||
if ($device !== null) {
|
||||
$suggestions[] = [
|
||||
'device' => $device,
|
||||
'confidence' => 90,
|
||||
'reason' => 'MAC адрес совпадает',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Medium confidence: hostname match
|
||||
if ($host->hostname !== null) {
|
||||
$device = $this->deviceRepository->findByName($host->hostname);
|
||||
if ($device !== null) {
|
||||
$suggestions[] = [
|
||||
'device' => $device,
|
||||
'confidence' => 60,
|
||||
'reason' => 'Hostname совпадает',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Low confidence: IP match
|
||||
if ($host->primaryIp !== null) {
|
||||
// Would need findByIp in repository — skip for now
|
||||
}
|
||||
|
||||
return $suggestions;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user