137 lines
5.0 KiB
PHP
137 lines
5.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('ServerPart');
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
"serverinfo_uid",
|
|
"type",
|
|
"partinfo_uid",
|
|
"billing",
|
|
"amount",
|
|
"cnt",
|
|
"extra",
|
|
];
|
|
}
|
|
public function getFormFilters(): array
|
|
{
|
|
return [
|
|
"serverinfo_uid",
|
|
"type",
|
|
"partinfo_uid",
|
|
"billing",
|
|
];
|
|
}
|
|
public function getBatchjobFields(): array
|
|
{
|
|
return ['billing', 'type', 'partinfo_uid'];
|
|
}
|
|
final public function getPartService(): PartService
|
|
{
|
|
if (!$this->_partService) {
|
|
$this->_partService = new PartService();
|
|
}
|
|
return $this->_partService;
|
|
}
|
|
//partEntity 정보 추가
|
|
protected function getEntity_process(mixed $entity): ServerPartEntity
|
|
{
|
|
//부품정보 정의
|
|
$partEntity = $this->getPartService()->getEntity($entity->getPartInfoUID());
|
|
if ($entity) {
|
|
$entity->setPartEntity($partEntity);
|
|
}
|
|
return $entity;
|
|
}
|
|
//기본 기능부분
|
|
// FieldForm관련용
|
|
public function getFormOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case 'CPU':
|
|
$options = $this->getPartService()->getEntities(['type' => 'CPU']);
|
|
break;
|
|
case 'RAM':
|
|
$options = $this->getPartService()->getEntities(['type' => 'RAM']);
|
|
break;
|
|
case 'DISK':
|
|
$options = $this->getPartService()->getEntities(['type' => 'DISK']);
|
|
break;
|
|
case 'OS':
|
|
$options = $this->getPartService()->getEntities(['type' => 'OS']);
|
|
break;
|
|
case 'DB':
|
|
$options = $this->getPartService()->getEntities(['type' => 'DB']);
|
|
break;
|
|
case 'SOFTWARE':
|
|
$options = $this->getPartService()->getEntities(['type' => 'SOFTWARE']);
|
|
break;
|
|
case 'partinfo_uid': //수정때문에 전체가 필요
|
|
$options = $this->getPartService()->getEntities();
|
|
break;
|
|
default:
|
|
$options = parent::getFormOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
//서버별생성
|
|
public function createByServer(ServerEntity $serverEntity, array $formDatas): ServerPartEntity
|
|
{
|
|
foreach (SERVER['PARTTYPES'] as $partType) {
|
|
$serverPartFormDatas = [];
|
|
$serverPartFormDatas["partinfo_uid"] = $formDatas["{$partType}"];
|
|
$serverPartFormDatas["serverinfo_uid"] = $serverEntity->getPK();
|
|
$serverPartFormDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
|
|
$serverPartFormDatas["type"] = $partType;
|
|
$serverPartFormDatas["billing"] = array_key_exists("{$partType}_billing", $formDatas) ? $formDatas["{$partType}_billing"] : null;
|
|
$serverPartFormDatas["amount"] = array_key_exists("{$partType}_amount", $formDatas) ? $formDatas["{$partType}_amount"] : 0;
|
|
$serverPartFormDatas["cnt"] = array_key_exists("{$partType}_cnt", $formDatas) ? $formDatas["{$partType}_cnt"] : null;
|
|
$serverPartFormDatas["extra"] = array_key_exists("{$partType}_extra", $formDatas) ? $formDatas["{$partType}_extra"] : null;
|
|
$entity = parent::create($serverPartFormDatas);
|
|
//부품정보 정의
|
|
$partEntity = $this->getPartService()->getEntity($entity->getPartInfoUID());
|
|
if ($partEntity) {
|
|
$entity->setPartEntity($partEntity);
|
|
}
|
|
}
|
|
return $entity;
|
|
}
|
|
//서버별삭제
|
|
public function deleteByServer(ServerEntity $serverEntity): void
|
|
{
|
|
//기존 서벼별 부품연결정보 삭제 후
|
|
foreach ($this->getEntities(['serverinfo_uid' => $serverEntity->getPK()]) as $entity) {
|
|
$this->delete($entity);
|
|
}
|
|
}
|
|
//서비스연결
|
|
public function enableService(ServerEntity $serverEntity, ServerPartEntity $entity): ServerPartEntity
|
|
{
|
|
$formDatas = [];
|
|
$formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
|
|
return parent::modify($entity, $formDatas);
|
|
}
|
|
//서비스해지
|
|
public function disableService(ServerPartEntity $entity): ServerPartEntity
|
|
{
|
|
$formDatas = [];
|
|
$formDatas["serviceinfo_uid"] = null;
|
|
return parent::modify($entity, $formDatas);
|
|
}
|
|
}
|