270 lines
9.6 KiB
PHP
270 lines
9.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Equipment;
|
|
|
|
use App\Services\Equipment\EquipmentService;
|
|
use App\Entities\Equipment\ServerEntity;
|
|
use App\Entities\Equipment\ServerPartEntity;
|
|
use App\Helpers\Equipment\ServerPartHelper;
|
|
use App\Models\Equipment\ServerPartModel;
|
|
use App\Services\PaymentService;
|
|
|
|
class ServerPartService extends EquipmentService
|
|
{
|
|
private ?SwitchService $_switchService = null;
|
|
private ?PartService $_partService = null;
|
|
private ?IPService $_ipService = null;
|
|
private ?CSService $_csService = null;
|
|
private ?PaymentService $_paymentService = null;
|
|
public function __construct()
|
|
{
|
|
parent::__construct(new ServerPartModel(), new ServerPartHelper());
|
|
$this->addClassName('ServerPart');
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
"serverinfo_uid",
|
|
"type",
|
|
"billing",
|
|
"part_uid",
|
|
"title",
|
|
"cnt",
|
|
"extra",
|
|
"amount",
|
|
];
|
|
}
|
|
public function getFormFilters(): array
|
|
{
|
|
return [
|
|
"serverinfo_uid",
|
|
"type",
|
|
"part_uid",
|
|
"billing",
|
|
];
|
|
}
|
|
|
|
public function getIndexFields(): array
|
|
{
|
|
return [
|
|
"serverinfo_uid",
|
|
"type",
|
|
"part_uid",
|
|
"billing",
|
|
"amount",
|
|
"cnt",
|
|
"extra",
|
|
];
|
|
}
|
|
public function getIndexFilters(): array
|
|
{
|
|
return [
|
|
"serverinfo_uid",
|
|
"type",
|
|
"part_uid",
|
|
"billing",
|
|
];
|
|
}
|
|
public function getBatchjobFields(): array
|
|
{
|
|
return ['billing', 'type'];
|
|
}
|
|
final public function getSwitchService(): SwitchService
|
|
{
|
|
if (!$this->_switchService) {
|
|
$this->_switchService = new SwitchService();
|
|
}
|
|
return $this->_switchService;
|
|
}
|
|
final public function getPartService(): PartService
|
|
{
|
|
if (!$this->_partService) {
|
|
$this->_partService = new PartService();
|
|
}
|
|
return $this->_partService;
|
|
}
|
|
final public function getIPService(): IPService
|
|
{
|
|
if (!$this->_ipService) {
|
|
$this->_ipService = new IPService();
|
|
}
|
|
return $this->_ipService;
|
|
}
|
|
final public function getCSService(): CSService
|
|
{
|
|
if (!$this->_csService) {
|
|
$this->_csService = new CSService();
|
|
}
|
|
return $this->_csService;
|
|
}
|
|
|
|
final public function getPaymentService(): PaymentService
|
|
{
|
|
if (!$this->_paymentService) {
|
|
$this->_paymentService = new PaymentService();
|
|
}
|
|
return $this->_paymentService;
|
|
}
|
|
//partEntity 정보 추가
|
|
protected function getEntity_process(mixed $entity): ServerPartEntity
|
|
{
|
|
if (!($entity instanceof ServerPartEntity)) {
|
|
throw new \Exception(__METHOD__ . "에서 형식오류:ServicePartEntity만 허용됩니다.");
|
|
}
|
|
switch ($entity->getType()) {
|
|
case 'CPU':
|
|
case 'RAM':
|
|
case 'DISK':
|
|
case 'OS':
|
|
case 'DB':
|
|
case 'SOFTWARE':
|
|
$partService = $this->getPartService();
|
|
$entity->setPartEntity($partService->getEntity($entity->getPartUID()));
|
|
break;
|
|
case 'SWITCH':
|
|
$partService = $this->getSwitchService();
|
|
$entity->setPartEntity($partService->getEntity($entity->getPartUID()));
|
|
break;
|
|
case 'IP':
|
|
$partService = $this->getIPService();
|
|
$entity->setPartEntity($partService->getEntity($entity->getPartUID()));
|
|
break;
|
|
case 'CS':
|
|
$partService = $this->getCSService();
|
|
$entity->setPartEntity($partService->getEntity($entity->getPartUID()));
|
|
break;
|
|
}
|
|
return $entity;
|
|
}
|
|
//기본 기능부분
|
|
// FieldForm관련용
|
|
public function getFormOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case 'part_uid':
|
|
$partOptions = [];
|
|
foreach (SERVERPART['ALL_PARTTYPES'] as $partType) {
|
|
switch ($partType) {
|
|
case 'CPU':
|
|
case 'RAM':
|
|
case 'DISK':
|
|
case 'OS':
|
|
case 'DB':
|
|
case 'SOFTWARE':
|
|
$partOptions[$partType] = $this->getPartService()->getEntities(['type' => $partType]);
|
|
break;
|
|
case 'SWITCH':
|
|
$partOptions[$partType] = $this->getSwitchService()->getEntities();
|
|
break;
|
|
case 'IP':
|
|
$partOptions[$partType] = $this->getIPService()->getEntities();
|
|
break;
|
|
case 'CS':
|
|
$partOptions[$partType] = $this->getCSService()->getEntities();
|
|
break;
|
|
default:
|
|
$partOptions[$partType] = [];
|
|
break;
|
|
}
|
|
}
|
|
$options = $partOptions;
|
|
// dd($options);
|
|
break;
|
|
default:
|
|
$options = parent::getFormOption($field, $options);
|
|
break;
|
|
}
|
|
if (!is_array($options)) {
|
|
throw new \Exception(__FUNCTION__ . "에서 {$field}의 options 값이 array가 아닙니다.\n" . var_export($options, true));
|
|
}
|
|
return $options;
|
|
}
|
|
//파트별정보 설정
|
|
private function setServerPart(ServerPartEntity $entity, array $formDatas): ServerPartEntity
|
|
{
|
|
//Type에 따른 부품서비스 정의
|
|
switch ($entity->getType()) {
|
|
case 'CPU':
|
|
case 'RAM':
|
|
case 'DISK':
|
|
case 'OS':
|
|
case 'DB':
|
|
case 'SOFTWARE':
|
|
$entity = $this->getPartService()->setServerPart($entity, $formDatas);
|
|
break;
|
|
case 'SWITCH':
|
|
$entity = $this->getSwitchService()->setServerPart($entity, $formDatas);
|
|
break;
|
|
case 'IP':
|
|
$entity = $this->getIPService()->setServerPart($entity, $formDatas);
|
|
break;
|
|
case 'CS':
|
|
$entity = $this->getCSService()->setServerPart($entity, $formDatas);
|
|
break;
|
|
}
|
|
return $entity;
|
|
}
|
|
//부품연결정보생성
|
|
public function create(array $formDatas): ServerPartEntity
|
|
{
|
|
//서버정보가져오기
|
|
$serverEntity = null;
|
|
if (array_key_exists('serverEntity', $formDatas)) {
|
|
$serverEntity = $formDatas['serverEntity'];
|
|
} else {
|
|
if (!array_key_exists('serverinfo_uid', $formDatas)) {
|
|
throw new \Exception("서버 정보가 지정되지 않았습니다.");
|
|
}
|
|
$serverEntity = $this->getServerService()->getEntity($formDatas['serverinfo_uid']);
|
|
}
|
|
if (!($serverEntity instanceof ServerEntity)) {
|
|
throw new \Exception("서버 정보가 지정되지 않았습니다.");
|
|
}
|
|
//생성작업
|
|
$formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
|
|
$formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
|
|
$formDatas["serverinfo_uid"] = $serverEntity->getPK();
|
|
$entity = parent::create($formDatas);
|
|
//부품정보 설정
|
|
$entity = $this->setServerPart($entity, ['part_uid' => $formDatas['part_uid'], 'status' => STATUS['OCCUPIED']]);
|
|
//결제관련정보 설정
|
|
$entity = $this->getPaymentService()->setServerPart($entity);
|
|
return $entity;
|
|
}
|
|
//수정
|
|
public function modify(mixed $entity, array $formDatas): ServerPartEntity
|
|
{
|
|
//서버정보가져오기
|
|
if (!array_key_exists('serverinfo_uid', $formDatas)) {
|
|
throw new \Exception("서버 정보가 지정되지 않았습니다.");
|
|
}
|
|
$serverEntity = $this->getServerService()->getEntity($formDatas['serverinfo_uid']);
|
|
if (!($serverEntity instanceof ServerEntity)) {
|
|
throw new \Exception("서버 정보가 지정되지 않았습니다.");
|
|
}
|
|
//부품연결정보에 부품정보가 변경된 경우(기존것은 AVAILABLE로 변경)
|
|
if ($entity->getPartUID() != $formDatas['part_uid']) {
|
|
$entity = $this->setServerPart($entity, ['part_uid' => $entity->getPartUID(), 'status' => STATUS['AVAILABLE']]);
|
|
}
|
|
//수정작업
|
|
$formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
|
|
$formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
|
|
$formDatas["serverinfo_uid"] = $serverEntity->getPK();
|
|
$entity = parent::modify($entity, $formDatas);
|
|
//부품연결정보에 부품정보가 변경된 경우 OCCUPIED로 변경
|
|
if ($entity->getPartUID() != $formDatas['part_uid']) {
|
|
$entity = $this->setServerPart($entity, ['part_uid' => $formDatas['part_uid'], 'status' => STATUS['OCCUPIED']]);
|
|
}
|
|
//결제관련정보 정의
|
|
$entity = $this->getPaymentService()->setServerPart($entity, ['action' => __FUNCTION__]);
|
|
return $entity;
|
|
}
|
|
//삭제
|
|
public function delete(mixed $entity): ServerPartEntity
|
|
{
|
|
//부품연결정보에 부품정보 정의
|
|
$entity = $this->setServerPart($entity, ['part_uid' => $entity->getPartUID(), 'status' => STATUS['AVAILABLE']]);
|
|
return parent::delete($entity);
|
|
}
|
|
}
|