diff --git a/app/Entities/Customer/ServiceEntity.php b/app/Entities/Customer/ServiceEntity.php
index 379997b..afce01d 100644
--- a/app/Entities/Customer/ServiceEntity.php
+++ b/app/Entities/Customer/ServiceEntity.php
@@ -25,17 +25,6 @@ class ServiceEntity extends CustomerEntity
}
return $this->attributes['serverEntity'];
}
- public function setSwitchEntity(SwitchEntity|null $entity): void
- {
- $this->attributes['switchEntity'] = $entity;
- }
- public function getSwitchEntity(): SwitchEntity|null
- {
- if (!array_key_exists('switchEntity', $this->attributes)) {
- return null;
- }
- return $this->attributes['switchEntity'];
- }
public function getCode(): string
{
return $this->attributes['code'] ?? "null";
diff --git a/app/Entities/Equipment/ServerEntity.php b/app/Entities/Equipment/ServerEntity.php
index 83c0d99..e552d7d 100644
--- a/app/Entities/Equipment/ServerEntity.php
+++ b/app/Entities/Equipment/ServerEntity.php
@@ -13,7 +13,17 @@ class ServerEntity extends EquipmentEntity
const STATUS_OCCUPIED = "occupied";
const STATUS_FORBIDDEN = "forbidden";
const DEFAULT_STATUS = self::STATUS_AVAILABLE;
-
+ public function setSwitchEntity(SwitchEntity|null $entity): void
+ {
+ $this->attributes['switchEntity'] = $entity;
+ }
+ public function getSwitchEntity(): SwitchEntity|null
+ {
+ if (!array_key_exists('switchEntity', $this->attributes)) {
+ return null;
+ }
+ return $this->attributes['switchEntity'];
+ }
public function addServerPartEntity(string $partType, ServerPartEntity $entity): void
{
if (!array_key_exists('serverPartEntities', $this->attributes)) {
@@ -38,6 +48,10 @@ class ServerEntity extends EquipmentEntity
}
$this->attributes['ipEntities'][] = $entity;
}
+ public function setIPEntities(array $ipEntities): void
+ {
+ $this->attributes['ipEntities'] = $ipEntities;
+ }
public function getIPEntities(): array
{
return $this->attributes['ipEntities'] ?? [];
@@ -49,6 +63,10 @@ class ServerEntity extends EquipmentEntity
}
$this->attributes['csEntities'] = $entity;
}
+ public function setCSEntities(array $csEntities): void
+ {
+ $this->attributes['csEntities'] = $csEntities;
+ }
public function getCSEntities(): array
{
return $this->attributes['csEntities'] ?? [];
diff --git a/app/Helpers/Customer/ServiceHelper.php b/app/Helpers/Customer/ServiceHelper.php
index c11dd74..cf5f738 100644
--- a/app/Helpers/Customer/ServiceHelper.php
+++ b/app/Helpers/Customer/ServiceHelper.php
@@ -11,48 +11,48 @@ class ServiceHelper extends CustomerHelper
parent::__construct();
$this->setTitleField(field: ServiceModel::TITLE);
}
- public function getFieldLabel(string $field, string $label, array $viewDatas, array $extras = []): string
- {
- switch ($field) {
- case "LINE":
- case "IP":
- case "SERVER":
- case "CPU":
- case "RAM":
- case "DISK":
- case "OS":
- case "SOFTWARE":
- case "DEFENCE":
- case "DOMAIN":
- $label = form_label(lang("{$viewDatas['class_path']}.label.{$field}"), $field, $extras);
- $extras = ["class" => "btn btn-light btn-circle", "target" => "_self", ...$extras];
- $label .= form_label(
- ICONS['SETUP'],
- $field,
- [
- "data-src" => "/admin/customer/serviceitem?serviceinfo_uid={$viewDatas['entity']->getPK()}&item_type={$field}",
- "data-bs-toggle" => "modal",
- "data-bs-target" => "#index_action_form",
- ...$extras
- ]
- );
- break;
- default:
- $label = parent::getFieldLabel($field, $label, $viewDatas, $extras);
- break;
- }
- return $label;
- }
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{
switch ($field) {
case 'serverinfo_uid':
+ if (array_key_exists('entity', $viewDatas)) {
+ $value = $viewDatas['entity']->getServerEntity() !== null ? $viewDatas['entity']->getServerEntity()->getPK() : $value;
+ }
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
- $form = $this->form_dropdown_custom($field, array_key_exists('entity', $viewDatas) ? ($viewDatas['entity']->getServerEntity() !== null ? $viewDatas['entity']->getServerEntity()->getPK() : $value) : $value, $viewDatas, $extras);
+ $form = $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
break;
case 'switchinfo_uid':
+ if (array_key_exists('entity', $viewDatas)) {
+ if ($viewDatas['entity']->getServerEntity() !== null) {
+ $value = $viewDatas['entity']->getServerEntity()->getSwitchEntity() !== null ? $viewDatas['entity']->getServerEntity()->getSwitchEntity()->getPK() : $value;
+ }
+ }
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
- $form = $this->form_dropdown_custom($field, array_key_exists('entity', $viewDatas) ? ($viewDatas['entity']->getSwitchEntity() !== null ? $viewDatas['entity']->getSwitchEntity()->getPK() : $value) : $value, $viewDatas, $extras);
+ $form = $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
+ break;
+ case 'ipinfo_uid':
+ $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
+ $form = "";
+ if (array_key_exists('entity', $viewDatas)) {
+ if ($viewDatas['entity']->getServerEntity() !== null) {
+ foreach ($viewDatas['entity']->getServerEntity()->getIPEntities() as $ipEntity) {
+ $form .= "
" . $this->form_dropdown_custom($field, $ipEntity->getPK(), $viewDatas, $extras) . "
";
+ }
+ }
+ }
+ $form .= $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
+ break;
+ case 'csinfo_uid':
+ $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
+ $form = "";
+ if (array_key_exists('entity', $viewDatas)) {
+ if ($viewDatas['entity']->getServerEntity() !== null) {
+ foreach ($viewDatas['entity']->getServerEntity()->getCSEntities() as $csEntity) {
+ $form .= "" . $this->form_dropdown_custom($field, $csEntity->getPK(), $viewDatas, $extras) . "
";
+ }
+ }
+ }
+ $form .= $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
break;
default:
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
diff --git a/app/Language/en/Customer/Service.php b/app/Language/en/Customer/Service.php
index 4f1e44c..bfb3a06 100644
--- a/app/Language/en/Customer/Service.php
+++ b/app/Language/en/Customer/Service.php
@@ -6,6 +6,8 @@ return [
'clientinfo_uid' => "고객",
'switchinfo_uid' => "스위치포트",
'serverinfo_uid' => "서버",
+ 'ipinfo_uid' => "IP정보",
+ 'csinfo_uid' => "CS정보",
'site' => "사이트",
'code' => "코드",
'type' => "형식",
diff --git a/app/Services/Customer/CustomerService.php b/app/Services/Customer/CustomerService.php
index 345956d..490dea7 100644
--- a/app/Services/Customer/CustomerService.php
+++ b/app/Services/Customer/CustomerService.php
@@ -16,8 +16,8 @@ abstract class CustomerService extends CommonService
private ?UserService $_userService = null;
private ?ClientService $_clientService = null;
private ?ServiceService $_serviceService = null;
- private ?SwitchService $_switchService = null;
private ?ServerService $_serverService = null;
+ private ?SwitchService $_switchService = null;
private $_equipmentService = [];
protected function __construct(Model $model)
@@ -75,12 +75,12 @@ abstract class CustomerService extends CommonService
case 'serviceinfo_uid':
$options = $this->getServiceService()->getEntities();
break;
- case 'switchinfo_uid':
- $options = $this->getSwitchService()->getEntities();
- break;
case 'serverinfo_uid':
$options = $this->getServerService()->getEntities();
break;
+ case 'switchinfo_uid':
+ $options = $this->getSwitchService()->getEntities();
+ break;
default:
$options = parent::getFormOption($field, $options);
break;
diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php
index c84346f..f3dd5bd 100644
--- a/app/Services/Customer/ServiceService.php
+++ b/app/Services/Customer/ServiceService.php
@@ -2,15 +2,17 @@
namespace App\Services\Customer;
-use App\Entities\Customer\ServiceEntity;
-use App\Entities\Equipment\ServerEntity;
-use App\Entities\Equipment\SwitchEntity;
-use App\Models\Customer\ServiceModel;
use App\Traits\IPTrait;
+use App\Services\Equipment\IPService;
+use App\Services\Equipment\CSService;
+use App\Models\Customer\ServiceModel;
+use App\Entities\Customer\ServiceEntity;
class ServiceService extends CustomerService
{
use IPTrait;
+ private ?IPService $_ipService = null;
+ private ?CSService $_csService = null;
public function __construct()
{
parent::__construct(new ServiceModel());
@@ -25,6 +27,8 @@ class ServiceService extends CustomerService
"clientinfo_uid",
"switchinfo_uid",
"serverinfo_uid",
+ "ipinfo_uid",
+ "csinfo_uid",
"billing_at",
"amount",
"start_at",
@@ -41,6 +45,8 @@ class ServiceService extends CustomerService
'clientinfo_uid',
"switchinfo_uid",
'serverinfo_uid',
+ "ipinfo_uid",
+ "csinfo_uid",
'status',
];
}
@@ -101,21 +107,38 @@ class ServiceService extends CustomerService
if ($serverEntityy !== null) {
$entity->setServerEntity($serverEntityy);
}
- $switchEntityy = $this->getSwitchService()->getEntity(['serviceinfo_uid' => $entity->getPK()]);
- if ($switchEntityy !== null) {
- $entity->setSwitchEntity($switchEntityy);
- }
- // //IP정보 정의
- // foreach ($this->getIPService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $ipEntity) {
- // $entity->addIPEntity($ipEntity);
- // }
- // //CS정보 정의
- // foreach ($this->getCSService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $csEntity) {
- // $entity->addCSEntity($csEntity);
- // }
return $entity;
}
+ 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;
+ }
//기본 기능부분
+ public function getFormOption(string $field, array $options = []): array
+ {
+ switch ($field) {
+ case 'ipinfo_uid': //수정때문에 전체가 필요
+ $options = $this->getIPService()->getEntities();
+ break;
+ case 'csinfo_uid': //수정때문에 전체가 필요
+ $options = $this->getCSService()->getEntities();
+ break;
+ default:
+ $options = parent::getFormOption($field, $options);
+ break;
+ }
+ return $options;
+ }
//FieldForm관련용
//interval을 기준으로 최근 신규 서비스정보 가져오기
final public function getEntitiesByNewService(int $interval, string $status = ServiceEntity::DEFAULT_STATUS): array
@@ -172,12 +195,6 @@ class ServiceService extends CustomerService
$serverEntity = $this->getServerService()->disableService($serverEntity);
$entity->setServerEntity(null);
}
- //기존 Switch정보와 다른경우 사용가능상태로 변경
- $switchEntity = $entity->getSwitchEntity();
- if ($switchEntity !== null) {
- $switchEntity = $this->getSwitchService()->disableService($switchEntity);
- $entity->setSwitchEntity(null);
- }
return $entity;
}
private function enableService(ServiceEntity $entity, array $formDatas): ServiceEntity
@@ -187,15 +204,8 @@ class ServiceService extends CustomerService
if (!$serverEntity) {
throw new \Exception("{$formDatas['serverinfo_uid']}에 대한 서버정보를 찾을수 없습니다.");
}
- $serverEntity = $this->getServerService()->enableService($entity, $serverEntity);
+ $serverEntity = $this->getServerService()->enableService($entity, $serverEntity, $formDatas);
$entity->setServerEntity($serverEntity);
- //Switch경우 서비스중으로 설정
- $switchEntity = $this->getServerService()->getEntity($formDatas['switchinfo_uid']);
- if (!$switchEntity) {
- throw new \Exception("{$formDatas['switchinfo_uid']}에 대한 스위치정보를 찾을수 없습니다.");
- }
- $switchEntity = $this->getSwitchService()->enableService($entity, $switchEntity);
- $entity->setSwitchEntity($switchEntity);
return $entity;
}
//생성
@@ -214,7 +224,6 @@ class ServiceService extends CustomerService
//수정
public function modify(mixed $entity, array $formDatas): ServiceEntity
{
- $entity = parent::modify($entity, $formDatas);
if (!array_key_exists('serverinfo_uid', $formDatas)) {
throw new \Exception("서버가 지정되지 않았습니다.");
}
@@ -224,7 +233,8 @@ class ServiceService extends CustomerService
//기존정보 Disable
$entity = $this->disableService($entity);
//신규정보 Enable
- return $this->enableService($entity, $formDatas);
+ $this->enableService($entity, $formDatas);
+ return parent::modify($entity, $formDatas);
}
//삭제
public function delete(mixed $entity): ServiceEntity
diff --git a/app/Services/Equipment/CSService.php b/app/Services/Equipment/CSService.php
index b757624..63a6b73 100644
--- a/app/Services/Equipment/CSService.php
+++ b/app/Services/Equipment/CSService.php
@@ -2,8 +2,9 @@
namespace App\Services\Equipment;
-use App\Entities\Equipment\CSEntity;
use App\Models\Equipment\CSModel;
+use App\Entities\Equipment\ServerEntity;
+use App\Entities\Equipment\CSEntity;
class CSService extends EquipmentService
{
@@ -60,4 +61,23 @@ class CSService extends EquipmentService
$this->getModel()->orderBy('INET_ATON(ip)', 'ASC');
parent::setOrderBy($field, $value);
}
+
+ public function enableService(ServerEntity $serverEntity, CSEntity $entity): CSEntity
+ {
+ $formDatas = [];
+ $formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
+ $formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
+ $formDatas["serverinfo_uid"] = $serverEntity->getPK();
+ $formDatas['status'] = CSEntity::STATUS_OCCUPIED;
+ return parent::modify($entity, $formDatas);
+ }
+ public function disableService(CSEntity $entity): CSEntity
+ {
+ $formDatas = [];
+ $formDatas["clientinfo_uid"] = null;
+ $formDatas["serviceinfo_uid"] = null;
+ $formDatas["serverinfo_uid"] = null;
+ $formDatas['status'] = CSEntity::STATUS_AVAILABLE;
+ return parent::modify($entity, $formDatas);
+ }
}
diff --git a/app/Services/Equipment/EquipmentService.php b/app/Services/Equipment/EquipmentService.php
index 9e0d7d9..fd5c536 100644
--- a/app/Services/Equipment/EquipmentService.php
+++ b/app/Services/Equipment/EquipmentService.php
@@ -17,7 +17,7 @@ abstract class EquipmentService extends CommonService
private ?ClientService $_clientService = null;
private ?ServiceService $_serviceService = null;
private ?ServerService $_serverService = null;
- private $_equipmentService = [];
+ private ?SwitchService $_switchService = null;
protected function __construct(Model $model)
{
parent::__construct($model);
@@ -51,6 +51,13 @@ abstract class EquipmentService extends CommonService
}
return $this->_serverService;
}
+ final public function getSwitchService(): SwitchService
+ {
+ if (!$this->_switchService) {
+ $this->_switchService = new SwitchService();
+ }
+ return $this->_switchService;
+ }
//기본기능
//FieldForm관련용
public function getFormOption(string $field, array $options = []): array
@@ -68,6 +75,9 @@ abstract class EquipmentService extends CommonService
case 'serverinfo_uid':
$options = $this->getServerService()->getEntities();
break;
+ case 'switchinfo_uid':
+ $options = $this->getSwitchService()->getEntities();
+ break;
default:
$options = parent::getFormOption($field, $options);
break;
diff --git a/app/Services/Equipment/IPService.php b/app/Services/Equipment/IPService.php
index d7673ec..74ea1ec 100644
--- a/app/Services/Equipment/IPService.php
+++ b/app/Services/Equipment/IPService.php
@@ -122,4 +122,23 @@ class IPService extends EquipmentService
$this->getModel()->orderBy('INET_ATON(ip)', 'ASC');
parent::setOrderBy($field, $value);
}
+
+ public function enableService(ServerEntity $serverEntity, IPEntity $entity): IPEntity
+ {
+ $formDatas = [];
+ $formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
+ $formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
+ $formDatas["serverinfo_uid"] = $serverEntity->getPK();
+ $formDatas['status'] = IPEntity::STATUS_OCCUPIED;
+ return parent::modify($entity, $formDatas);
+ }
+ public function disableService(IPEntity $entity): IPEntity
+ {
+ $formDatas = [];
+ $formDatas["clientinfo_uid"] = null;
+ $formDatas["serviceinfo_uid"] = null;
+ $formDatas["serverinfo_uid"] = null;
+ $formDatas['status'] = IPEntity::STATUS_AVAILABLE;
+ return parent::modify($entity, $formDatas);
+ }
}
diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php
index 5e9d419..19cd239 100644
--- a/app/Services/Equipment/ServerService.php
+++ b/app/Services/Equipment/ServerService.php
@@ -119,6 +119,9 @@ class ServerService extends EquipmentService
$entity->addServerPartEntity($partType, $serverPartEntity);
}
}
+ //Switch정보 정의
+ $switchEntity = $this->getSwitchService()->getEntity(['serverinfo_uid' => $entity->getPK()]);
+ $entity->setSwitchEntity($switchEntity);
//IP정보 정의
foreach ($this->getIPService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $ipEntity) {
$entity->addIPEntity($ipEntity);
@@ -223,16 +226,64 @@ class ServerService extends EquipmentService
parent::setOrderBy($field, $value);
}
- public function enableService(ServiceEntity $serviceEntity, ServerEntity $entity): ServerEntity
+ public function enableService(ServiceEntity $serviceEntity, ServerEntity $entity, array $formDatas): ServerEntity
{
$formDatas = [];
$formDatas["clientinfo_uid"] = $serviceEntity->getClientInfoUID();
$formDatas["serviceinfo_uid"] = $serviceEntity->getPK();
$formDatas['status'] = ServerEntity::STATUS_OCCUPIED;
- return parent::modify($entity, $formDatas);
+ $entity = parent::modify($entity, $formDatas);
+
+ //Switch경우 서비스중으로 설정
+ if (array_key_exists('switchinfo_uid', $formDatas)) {
+ $switchEntity = $this->getSwitchService()->getEntity($formDatas['switchinfo_uid']);
+ if (!$switchEntity) {
+ throw new \Exception("{$formDatas['switchinfo_uid']}에 대한 스위치정보를 찾을수 없습니다.");
+ }
+ $switchEntity = $this->getSwitchService()->enableService($entity, $switchEntity);
+ $entity->setSwitchEntity($switchEntity);
+ }
+ //IP정보 서비스중으로 설정
+ if (array_key_exists('ipinfo_uid', $formDatas)) {
+ $ipEntity = $this->getIPService()->getEntity($formDatas['ipinfo_uid']);
+ if (!$ipEntity) {
+ throw new \Exception("{$formDatas['ipinfo_uid']}에 대한 IP정보를 찾을수 없습니다.");
+ }
+ $ipEntity = $this->getIPService()->enableService($entity, $ipEntity);
+ $entity->addIPEntity($ipEntity);
+ }
+ //CS정보 서비스중으로 설정
+ if (array_key_exists('csinfo_uid', $formDatas)) {
+ $csEntity = $this->getCSService()->getEntity($formDatas['csinfo_uid']);
+ if (!$csEntity) {
+ throw new \Exception("{$formDatas['csinfo_uid']}에 대한 CS정보를 찾을수 없습니다.");
+ }
+ $csEntity = $this->getCSService()->enableService($entity, $csEntity);
+ $entity->addCSEntity($csEntity);
+ }
+ return $entity;
}
public function disableService(ServerEntity $entity): ServerEntity
{
+ //서비스 해지시 기존 Switch정보를 사용가능 상태로 변경
+ $switchEntity = $entity->getSwitchEntity();
+ if ($switchEntity !== null) {
+ $this->getSwitchService()->disableService($switchEntity);
+ $entity->setSwitchEntity(null);
+ }
+
+ //서비스 해지시 기존 IP정보를 사용가능 상태로 변경
+ foreach ($entity->getIPEntities() as $ipEntity) {
+ $this->getIPService()->disableService($ipEntity);
+ }
+ $entity->setIPEntities([]);
+
+ //서비스 해지시 기존 CS정보를 사용가능 상태로 변경
+ foreach ($entity->getCSEntities() as $csEntity) {
+ $this->getCSService()->disableService($csEntity);
+ }
+ $entity->setCSEntities([]);
+
$formDatas = [];
$formDatas["clientinfo_uid"] = null;
$formDatas["serviceinfo_uid"] = null;
diff --git a/app/Services/Equipment/SwitchService.php b/app/Services/Equipment/SwitchService.php
index cbf9166..80eaa64 100644
--- a/app/Services/Equipment/SwitchService.php
+++ b/app/Services/Equipment/SwitchService.php
@@ -2,10 +2,10 @@
namespace App\Services\Equipment;
-use App\Entities\Customer\ServiceEntity;
-use App\Entities\Equipment\SwitchEntity;
-use App\Models\Equipment\SwitchModel;
use App\Services\Equipment\EquipmentService;
+use App\Models\Equipment\SwitchModel;
+use App\Entities\Equipment\SwitchEntity;
+use App\Entities\Equipment\ServerEntity;
class SwitchService extends EquipmentService
{
@@ -64,12 +64,12 @@ class SwitchService extends EquipmentService
parent::setOrderBy($field, $value);
}
- public function enableService(ServiceEntity $serviceEntity, SwitchEntity $entity): SwitchEntity
+ public function enableService(ServerEntity $serverEntity, SwitchEntity $entity): SwitchEntity
{
$formDatas = [];
- $formDatas["clientinfo_uid"] = $serviceEntity->getClientInfoUID();
- $formDatas["serviceinfo_uid"] = $serviceEntity->getPK();
- $formDatas["serverinfo_uid"] = $serviceEntity->getServerEntity()->getPK();
+ $formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
+ $formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
+ $formDatas["serverinfo_uid"] = $serverEntity->getPK();
$formDatas['status'] = SwitchEntity::STATUS_OCCUPIED;
return parent::modify($entity, $formDatas);
}