dbmsv2/app/Services/Equipment/ServerPartService.php
2025-08-28 13:37:11 +09:00

123 lines
4.0 KiB
PHP

<?php
namespace App\Services\Equipment;
use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Models\Equipment\ServerPartModel;
use App\Services\Equipment\EquipmentService;
class ServerPartService extends EquipmentService
{
private ?PartService $_partService = null;
public function __construct()
{
parent::__construct(new ServerPartModel());
$this->addClassName('Server');
}
public function getFormFields(): array
{
return [
'fields' => [
"partinfo_uid",
"serverinfo_uid",
"serviceinfo_uid",
"type",
"billing",
"amount",
"cnt",
"extra",
],
'filters' => [
"partinfo_uid",
"serverinfo_uid",
"serviceinfo_uid",
"type"
],
];
}
public function getIndexFields(): array
{
return $this->getFormFields();
}
public function getBatchjobFields(): array
{
return ['partinfo_uid', "serverinfo_uid", "serviceinfo_uid",];
}
final public function getPartService(): PartService
{
if (!$this->_partService) {
$this->_partService = new PartService();
}
return $this->_partService;
}
//partEntity 정보 추가
protected function getEntity_process(mixed $entity): ServerPartEntity
{
$entity->setPartEntity($this->getPartService()->getEntity($entity->getPartInfoUID()));
return $entity;
}
//기본 기능부분
//FieldForm관련용
public function getFormFieldOption(string $field, array $options = []): array
{
switch ($field) {
case 'partinfo_CPU_uid':
$options = $this->getPartService()->getEntities(['type' => 'CPU']);
break;
case 'partinfo_RAM_uid':
$options = $this->getPartService()->getEntities(['type' => 'RAM']);
break;
case 'partinfo_DISK_uid':
$options = $this->getPartService()->getEntities(['type' => 'DISK']);
break;
case 'partinfo_OS_uid':
$options = $this->getPartService()->getEntities(['type' => 'OS']);
break;
case 'partinfo_DB_uid':
$options = $this->getPartService()->getEntities(['type' => 'DB']);
break;
case 'partinfo_SOFTWARE_uid':
$options = $this->getPartService()->getEntities(['type' => 'SOFTWARE']);
break;
case 'partinfo_uid': //수정때문에 전체가 필요
$options = $this->getPartService()->getEntities();
break;
default:
$options = parent::getFormFieldOption($field, $options);
break;
}
return $options;
}
private function getFormDatasByServer(ServerEntity $serverEntity, string $partType, array $formDatas): array
{
$temps = [
"partinfo_uid" => $formDatas(["serverpartinfo_{$partType}_uid"]),
"serverinfo_uid" => $serverEntity->getPK(),
"serviceinfo_uid" => $serverEntity->getServiceInfoUID(),
"type" => $partType,
"billing" => $formDatas['billing'] ?? ServerPartENtity::DEFAULT_BILLING,
"amount" => $formDatas["amount"] ?? 0,
"cnt" => $formDatas["serverpartinfo_{$partType}_uid_cnt"] ?? 1,
"extra" => $formDatas["serverpartinfo_{$partType}_uid_extra"] ?? ""
];
return $temps;
}
//생성
public function createByServer(ServerEntity $serverEntity, array $formDatas): array
{
$entities = [];
foreach (SERVER['PARTTYPES'] as $partType) {
$entities[] = parent::create(
$this->getFormDatasByServer(
$serverEntity,
$partType,
$formDatas
)
);
}
return $entities;
}
}