dbmsv4 init...1

This commit is contained in:
최준흠 2025-11-27 13:02:09 +09:00
parent bb1e450b6c
commit aba499d74e
14 changed files with 252 additions and 271 deletions

View File

@ -123,9 +123,7 @@ abstract class CommonService
$errorMsg = is_array($errors) ? implode(", ", $errors) : "DB 저장 작업이 실패했습니다.";
throw new RuntimeException(__METHOD__ . "에서 오류발생: " . $errorMsg);
}
$pk = $uid; // 기본적으로 기존 $uid (업데이트의 경우)
// AUTO_INCREMENT 필드를 사용하는 경우, INSERT 작업이라면 새로 생성된 ID를 가져옵니다.
// INSERT 작업은 보통 $uid가 0 또는 null/빈 문자열일 때 실행됩니다.
if ($this->model->useAutoIncrement() && (empty($uid) || $uid === 0)) {
@ -138,7 +136,6 @@ abstract class CommonService
// save()가 성공적인 INSERT 후 PK를 반환하는 경우를 대비 (CI4의 동작)
$pk = (int)$result;
}
// 최종적으로 PK가 유효한지 확인합니다.
if (empty($pk)) {
$errors = $this->model->errors();
@ -154,7 +151,7 @@ abstract class CommonService
$initialPK = $entity->getPK();
$result = $this->model->save($entity);
// 최종적으로 DB에 반영된 PK를 반환받습니다. (UPDATE이면 기존 PK, INSERT이면 새 PK)
$finalPK = $this->handle_save_result($result, $initialPK);
$entity->{$this->model->getPKField()} = $this->handle_save_result($result, $initialPK);
// handle_save_result에서 확인된 최종 PK를 사용하여 DB에서 최신 엔티티를 가져옴
return $entity;
}
@ -185,6 +182,7 @@ abstract class CommonService
if (!$this->getFormService()->validate($formDatas)) {
throw new ValidationException(implode("\n", service('validation')->getErrors()));
}
dd($formDatas);
// NOTE: create_process에서 엔티티를 생성할 때, 자동 증가(AUTO_INCREMENT) 필드는
// DB가 처리하도록 NULL이나 빈 값(0)으로 두는 것이 일반적입니다.
$entity = $this->create_process($formDatas);

View File

@ -173,7 +173,9 @@ class ServerPartService extends EquipmentService
$formDatas['cnt'] = $part["CNT"];
$formDatas['extra'] = $part["EXTRA"];
//action 초기화
$this->action_init_process('create');
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('create', $fields);
$entity = $this->create($this->createDTO($formDatas));
if (!$entity instanceof ServerPartEntity) {
throw new \Exception(__METHOD__ . "에서 오류발생: Return Type은 ServerPartEntity만 가능합니다.");

View File

@ -131,7 +131,7 @@ class ServerService extends EquipmentService
//서버추가시 서버파트 자동추가용
service('part_ipservice')->attachToServer($entity);
service('part_switchservice')->attachToServer($entity);
// service('equipment_serverpartservice')->attachToServer($entity);
service('equipment_serverpartservice')->attachToServer($entity);
return $entity;
}
protected function modify_process($uid, array $formDatas): ServerEntity

View File

@ -3,13 +3,14 @@
namespace App\Services\Part;
use App\DTOs\Part\CPUDTO;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\CPUEntity;
use App\Forms\Part\CPUForm;
use App\Helpers\Part\CPUHelper;
use App\Models\Part\CPUModel;
use RuntimeException;
class CPUService extends PartService
class CPUService extends PartType1Service
{
private $_form = null;
private $_helper = null;
@ -122,4 +123,15 @@ class CPUService extends PartService
$this->model->orderBy('title ASC');
parent::setOrderBy($field, $value);
}
//서버파트관련 작업
//파트정보가져오기
public function getPartEntityByServerPart(ServerPartEntity $serverPartEntity): CPUEntity
{
//IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof CPUEntity) {
throw new \Exception(message: "{$serverPartEntity->getPartUID()}에 해당하는 CPUEntity정보를 찾을수없습니다.");
}
return $entity;
}
}

View File

@ -10,7 +10,7 @@ use App\Helpers\Part\CSHelper;
use App\Models\Part\CSModel;
use RuntimeException;
class CSService extends PartService
class CSService extends PartType2Service
{
private $_form = null;
private $_helper = null;
@ -152,59 +152,14 @@ class CSService extends PartService
}
//서버파트관련 작업
public function attachToServerPart(ServerPartEntity $serverPartEntity): CSEntity
//파트정보가져오기
public function getPartEntityByServerPart(ServerPartEntity $serverPartEntity): CSEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
$formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID();
$formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID();
$formDatas['status'] = STATUS['OCCUPIED'];
if (!array_key_exists('status', $formDatas)) {
throw new \Exception(__METHOD__ . "에서 오류발생: CS상태가 설정되지 않았습니다.");
}
//CS정보가져오기
//IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof CSEntity) {
throw new \Exception(message: "{$serverPartEntity->getPartUID()}에 해당하는 CS정보를 찾을수없습니다.");
}
//CS정보에서 해당하는 CS가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if ($entity instanceof CSEntity) {
if ($entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception(__METHOD__ . ":에서 오류발생: {$serverPartEntity->getTitle()}는 사용중입니다.");
}
//CS 정보 수정
//초기화
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
/** @var CSEntity $entity IDE에 entity type알려주기*/
$entity = $this->modify($entity->getPK(), $this->createDTO($formDatas));
}
return $entity;
}
public function detachFromServerPart(ServerPartEntity $serverPartEntity): CSEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = null;
$formDatas['serviceinfo_uid'] = null;
$formDatas['serverinfo_uid'] = null;
$formDatas['status'] = STATUS['AVAILABLE'];
if (!array_key_exists('status', $formDatas)) {
throw new \Exception(__METHOD__ . "에서 오류발생: CS상태가 설정되지 않았습니다.");
}
//CS정보가져오기
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof CSEntity) {
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 CS정보를 찾을수없습니다.");
}
//CS 정보 수정
//초기화
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
/** @var CSEntity $entity IDE에 entity type알려주기*/
$entity = $this->modify($entity->getPK(), $this->createDTO($formDatas));
return $entity;
}
}

View File

@ -10,7 +10,7 @@ use App\Helpers\Part\DISKHelper;
use App\Models\Part\DISKModel;
use RuntimeException;
class DISKService extends PartService
class DISKService extends PartType1Service
{
private $_form = null;
private $_helper = null;
@ -127,19 +127,21 @@ class DISKService extends PartService
}
//서버파트관련 작업
public function detachFromServerPart(ServerPartEntity $serverPartEntity): DiskEntity
//파트정보가져오기
public function getPartEntityByServerPart(ServerPartEntity $serverPartEntity): DISKEntity
{
/** @var DiskEntity $entity IDE에 entity type알려주기*/
$entity = parent::detachFromServerPart($serverPartEntity);
$formDatas = ['format' => $entity->getFormat() + $serverPartEntity->getCnt()];
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
$entity = $this->modify($entity->getPK(), $this->createDTO($formDatas));
//IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof DISKEntity) {
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 DISKEntity만 가능");
throw new \Exception(message: "{$serverPartEntity->getPartUID()}에 해당하는 DISKEntity정보를 찾을수없습니다.");
}
return $entity;
}
public function detachFromServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): DiskEntity
{
/** @var DiskEntity $entity IDE에 entity type알려주기*/
$entity = $this->getPartEntityByServerPart($serverPartEntity);
$formDatas['format'] = $entity->getFormat() + $serverPartEntity->getCnt();
return parent::detachFromServerPart($serverPartEntity, $formDatas);
}
}

View File

@ -11,7 +11,7 @@ use App\Helpers\Part\IPHelper;
use App\Models\Part\IPModel;
use RuntimeException;
class IPService extends PartService
class IPService extends PartType3Service
{
private $_form = null;
private $_helper = null;
@ -144,97 +144,40 @@ class IPService extends PartService
}
//서버관련 작업
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): IPEntity
//파트정보가져오기
public function getPartEntityByServer(ServerEntity $serverEntity): IPEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = $serverEntity->getClientInfoUID();
$formDatas['serviceinfo_uid'] = $serverEntity->getServiceInfoUID();
$formDatas['serverinfo_uid'] = $serverEntity->getPK();
$formDatas['status'] = STATUS['OCCUPIED'];
//IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity(['ip' => $serverEntity->getIP()]);
if (!$entity instanceof IPEntity) {
throw new \Exception("{$serverEntity->getIP()}에 해당하는 IP정보를 찾을수없습니다.");
}
if ($entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception(__METHOD__ . ":에서 오류발생: {$serverEntity->getTitle()}는 사용중입니다.");
}
//IP 정보 수정
//초기화
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
/** @var IPEntity $entity IDE에 entity type알려주기*/
$entity = $this->modify($entity->getPK(), $this->createDTO($formDatas));
return $entity;
}
public function detachFromServer(ServerEntity $serverEntity): IPEntity
public function detachFromServer(ServerEntity $serverEntity, array $formDatas = []): IPEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = null;
$formDatas['serviceinfo_uid'] = null;
$formDatas['serverinfo_uid'] = null;
$formDatas['old_clientinfo_uid'] = $serverEntity->getClientInfoUID() ?? null;
$formDatas['status'] = STATUS['AVAILABLE'];
//IP정보가져오기
$entity = $this->getEntity(['ip' => $serverEntity->getIP()]);
if (!$entity instanceof IPEntity) {
throw new \Exception("{$serverEntity->getIP()}에 해당하는 IP정보를 찾을수없습니다.");
}
//IP정보 수정
//초기화
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
/** @var IPEntity $entity IDE에 entity type알려주기*/
$entity = $this->modify($entity->getPK(), $this->createDTO($formDatas));
return $entity;
$entity = $this->getPartEntityByServer($serverEntity);
$formDatas['old_clientinfo_uid'] = $entity->getClientInfoUID();
return parent::detachFromServer($serverEntity, $formDatas);
}
//서버파트관련 작업
public function attachToServerPart(ServerPartEntity $serverPartEntity): IPEntity
//파트정보가져오기
public function getPartEntityByServerPart(ServerPartEntity $serverPartEntity): IPEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
$formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID();
$formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID();
$formDatas['status'] = STATUS['OCCUPIED'];
//IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if ($entity instanceof IPEntity) {
if ($entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception(__METHOD__ . ":에서 오류발생: {$entity->getTitle()}는 사용중입니다.");
}
//IP 정보 수정
//초기화
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
/** @var IPEntity $entity IDE에 entity type알려주기*/
$entity = $this->modify($entity->getPK(), $this->createDTO($formDatas));
if (!$entity instanceof IPEntity) {
throw new \Exception(message: "{$serverPartEntity->getPartUID()}에 해당하는 IP정보를 찾을수없습니다.");
}
return $entity;
}
public function detachFromServerPart(ServerPartEntity $serverPartEntity): IPEntity
//사용했던 고객정보 남기기위해 추가
public function detachFromServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): IPEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = null;
$formDatas['serviceinfo_uid'] = null;
$formDatas['serverinfo_uid'] = null;
$formDatas['old_clientinfo_uid'] = $serverPartEntity->getClientInfoUID() ?? null;
$formDatas['status'] = STATUS['AVAILABLE'];
//IP정보가져오기
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof IPEntity) {
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 IP정보를 찾을수없습니다.");
}
//IP 정보 수정
//초기화
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
/** @var IPEntity $entity IDE에 entity type알려주기*/
$entity = $this->modify($entity->getPK(), $this->createDTO($formDatas));
return $entity;
$entity = $this->getPartEntityByServerPart($serverPartEntity);
$formDatas['old_clientinfo_uid'] = $entity->getClientInfoUID();
return parent::detachFromServerPart($serverPartEntity, $formDatas);
}
}

View File

@ -14,44 +14,17 @@ abstract class PartService extends CommonService
parent::__construct($model);
$this->addClassPaths('Part');
}
public function getEntity(string|int|array $where, ?string $message = null): ?PartEntity
abstract public function attachToServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): PartEntity;
abstract public function detachFromServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): PartEntity;
final protected function updatePart(PartEntity $entity, array $formDatas): PartEntity
{
return parent::getEntity($where, $message);
}
//서버파트관련 작업
public function attachToServerPart(ServerPartEntity $serverPartEntity): PartEntity
{
//부품정보가져오기
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity) {
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다.");
$updateResult = $this->model->update($entity->getPK(), $formDatas);
if ($updateResult === false || $updateResult === 0) {
// 업데이트 실패 시 예외 처리
$errors = $this->model->errors();
$errorMsg = is_array($errors) ? implode(", ", $errors) : "DB 업데이트 실패 또는 변경된 행 없음.";
throw new \Exception(__METHOD__ . ": " . $errorMsg);
}
//부품정보에 서버정보 설정 및 서비스,고객정보 정의
if ($entity->getAvailable() < $serverPartEntity->getCnt()) {
throw new \Exception("현재 사용가능 갯수[{$entity->getAvailable()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
}
$formDatas = ['used' => $entity->getUsed() + $serverPartEntity->getCnt()];
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
return $this->modify($entity->getPK(), $this->createDTO($formDatas));
}
public function detachFromServerPart(ServerPartEntity $serverPartEntity): PartEntity
{
//부품정보가져오기
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity) {
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다.");
}
//부품정보에 서버정보 설정 및 서비스,고객정보 정의
if ($entity->getUsed() < $serverPartEntity->getCnt()) {
throw new \Exception("현재 사용된 갯수[{$entity->getUsed()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
}
$formDatas = ['used' => $entity->getUsed() - $serverPartEntity->getCnt()];
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
return $this->modify($entity->getPK(), $this->createDTO($formDatas));
return $entity;
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace App\Services\Part;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\PartEntity;
use App\Models\CommonModel;
abstract class PartType1Service extends PartService
{
protected function __construct(CommonModel $model)
{
parent::__construct($model);
}
abstract public function getPartEntityByServerPart(ServerPartEntity $serverPartEntity): PartEntity;
//서버파트관련 작업
public function attachToServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): PartEntity
{
//부품정보가져오기
/** @var PartEntity $entity IDE에 entity type알려주기*/
$entity = $this->getPartEntityByServerPart($serverPartEntity);
//파트정보의 사용가능한 갯수 , 사용갯수 비교
if ($entity->getAvailable() < $serverPartEntity->getCnt()) {
throw new \Exception("현재 사용가능 갯수[{$entity->getAvailable()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
}
$formDatas['used'] = $entity->getUsed() + $serverPartEntity->getCnt();
$entity = $this->updatePart($entity, $formDatas);
$entity->fill($formDatas);
return $entity;
}
public function detachFromServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): PartEntity
{
//부품정보가져오기
/** @var PartEntity $entity IDE에 entity type알려주기*/
$entity = $this->getPartEntityByServerPart($serverPartEntity);
//파트정보의 사용된 갯수 , 회수용 갯수 비교
if ($entity->getUsed() < $serverPartEntity->getCnt()) {
throw new \Exception("현재 사용된 갯수[{$entity->getUsed()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
}
$formDatas['used'] = $entity->getUsed() - $serverPartEntity->getCnt();
$entity = $this->updatePart($entity, $formDatas);
$entity->fill($formDatas);
return $entity;
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace App\Services\Part;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\PartEntity;
use App\Models\CommonModel;
abstract class PartType2Service extends PartService
{
protected function __construct(CommonModel $model)
{
parent::__construct($model);
}
abstract public function getPartEntityByServerPart(ServerPartEntity $serverPartEntity): PartEntity;
//서버파트관련 작업
public function attachToServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): PartEntity
{
$formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
$formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID();
$formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID();
$formDatas['status'] = STATUS['OCCUPIED'];
//파트정보가져오기
$entity = $this->getPartEntityByServerPart($serverPartEntity);
//상태확인
if ($entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception(__METHOD__ . ":에서 오류발생: {$entity->getTitle()}는 사용중입니다.");
}
//파트정보 수정
// model->update()는 영향을 받은 row 수를 반환하므로, 반환 타입 맞추기 위해 엔티티 갱신 로직 추가
$updateResult = $this->model->update($entity->getPK(), $formDatas);
if ($updateResult === false || $updateResult === 0) {
// 업데이트 실패 시 예외 처리
$errors = $this->model->errors();
$errorMsg = is_array($errors) ? implode(", ", $errors) : "DB 업데이트 실패 또는 변경된 행 없음.";
throw new \Exception(__METHOD__ . ": " . $errorMsg);
}
// DB 재조회 없이 엔티티 객체의 데이터 갱신 (트랜잭션 안전성 확보)
$entity->fill($formDatas);
return $entity;
}
public function detachFromServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): PartEntity
{
$formDatas['clientinfo_uid'] = null;
$formDatas['serviceinfo_uid'] = null;
$formDatas['serverinfo_uid'] = null;
$formDatas['status'] = STATUS['AVAILABLE'];
//파트정보가져오기
$entity = $this->getPartEntityByServerPart($serverPartEntity);
//파트정보 수정
$updateResult = $this->model->update($entity->getPK(), $formDatas);
if ($updateResult === false || $updateResult === 0) {
// 업데이트 실패 시 예외 처리
$errors = $this->model->errors();
$errorMsg = is_array($errors) ? implode(", ", $errors) : "DB 업데이트 실패 또는 변경된 행 없음.";
throw new \Exception(__METHOD__ . ": " . $errorMsg);
}
// DB 재조회 없이 엔티티 객체의 데이터 갱신 (트랜잭션 안전성 확보)
$entity->fill($formDatas);
return $entity;
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace App\Services\Part;
use App\Entities\Equipment\ServerEntity;
use App\Entities\Part\PartEntity;
use App\Models\CommonModel;
abstract class PartType3Service extends PartType2Service
{
protected function __construct(CommonModel $model)
{
parent::__construct($model);
}
abstract public function getPartEntityByServer(ServerEntity $serverEntity): PartEntity;
//서버관련 작업
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): PartEntity
{
$formDatas['clientinfo_uid'] = $serverEntity->getClientInfoUID();
$formDatas['serviceinfo_uid'] = $serverEntity->getServiceInfoUID();
$formDatas['serverinfo_uid'] = $serverEntity->getPK();
$formDatas['status'] = STATUS['OCCUPIED'];
//파트정보가져오기
$entity = $this->getPartEntityByServer($serverEntity);
if ($entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception(__METHOD__ . ":에서 오류발생: {$entity->getTitle()}는 사용중입니다.");
}
//파트정보 수정
/** @var PartEntity $entity IDE에 entity type알려주기*/
$entity = $this->model->update($entity->getPK(), $formDatas);
return $entity;
}
public function detachFromServer(ServerEntity $serverEntity, array $formDatas = []): PartEntity
{
$formDatas['clientinfo_uid'] = null;
$formDatas['serviceinfo_uid'] = null;
$formDatas['serverinfo_uid'] = null;
$formDatas['status'] = STATUS['AVAILABLE'];
//파트정보가져오기
$entity = $this->getPartEntityByServer($serverEntity);
//파트정보 수정
/** @var PartEntity $entity IDE에 entity type알려주기*/
$entity = $this->model->update($entity->getPK(), $formDatas);
return $entity;
}
}

View File

@ -3,13 +3,14 @@
namespace App\Services\Part;
use App\DTOs\Part\RAMDTO;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\RAMEntity;
use App\Forms\Part\RAMForm;
use App\Helpers\Part\RAMHelper;
use App\Models\Part\RAMModel;
use RuntimeException;
class RAMService extends PartService
class RAMService extends PartType1Service
{
private $_form = null;
private $_helper = null;
@ -122,4 +123,15 @@ class RAMService extends PartService
$this->model->orderBy('title ASC');
parent::setOrderBy($field, $value);
}
//서버파트관련 작업
//파트정보가져오기
public function getPartEntityByServerPart(ServerPartEntity $serverPartEntity): RAMEntity
{
//IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof RAMEntity) {
throw new \Exception(message: "{$serverPartEntity->getPartUID()}에 해당하는 RAMEntity정보를 찾을수없습니다.");
}
return $entity;
}
}

View File

@ -3,13 +3,14 @@
namespace App\Services\Part;
use App\DTOs\Part\SOFTWAREDTO;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\SOFTWAREEntity;
use App\Forms\Part\SOFTWAREForm;
use App\Helpers\Part\SOFTWAREHelper;
use App\Models\Part\SOFTWAREModel;
use RuntimeException;
class SOFTWAREService extends PartService
class SOFTWAREService extends PartType1Service
{
private $_form = null;
private $_helper = null;
@ -122,4 +123,15 @@ class SOFTWAREService extends PartService
$this->model->orderBy('title ASC');
parent::setOrderBy($field, $value);
}
//서버파트관련 작업
//파트정보가져오기
public function getPartEntityByServerPart(ServerPartEntity $serverPartEntity): SOFTWAREEntity
{
//IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof SOFTWAREEntity) {
throw new \Exception(message: "{$serverPartEntity->getPartUID()}에 해당하는 SOFTWAREEntity정보를 찾을수없습니다.");
}
return $entity;
}
}

View File

@ -11,7 +11,7 @@ use App\Helpers\Part\SWITCHHelper;
use App\Models\Part\SWITCHModel;
use RuntimeException;
class SWITCHService extends PartService
class SWITCHService extends PartType3Service
{
private $_form = null;
private $_helper = null;
@ -145,108 +145,25 @@ class SWITCHService extends PartService
}
//서버관련 작업
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): SWITCHEntity
//파트정보가져오기
public function getPartEntityByServer(ServerEntity $serverEntity): SWITCHEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = $serverEntity->getClientInfoUID();
$formDatas['serviceinfo_uid'] = $serverEntity->getServiceInfoUID();
$formDatas['serverinfo_uid'] = $serverEntity->getPK();
$formDatas['status'] = STATUS['OCCUPIED'];
if (!array_key_exists('status', $formDatas)) {
throw new \Exception(__METHOD__ . ":에서 오류발생: Switch상태가 설정되지 않았습니다.");
}
//Switch정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
//IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverEntity->getSwitchInfoUID());
if (!$entity instanceof SWITCHEntity) {
throw new \Exception("{$serverEntity->getSwitchInfoUID()}에 해당하는 Switch정보를 찾을수없습니다.");
throw new \Exception("{$serverEntity->getSwitchInfoUID()}에 해당하는 IP정보를 찾을수없습니다.");
}
if ($entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception(__METHOD__ . ":에서 오류발생: {$serverEntity->getTitle()}는 사용중입니다.");
}
//SWITCH 정보 수정
//초기화
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
/** @var SWITCHEntity $entity IDE에 entity type알려주기*/
$entity = $this->modify($entity->getPK(), $this->createDTO($formDatas));
return $entity;
}
public function detachFromServer(ServerEntity $serverEntity): SWITCHEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = null;
$formDatas['serviceinfo_uid'] = null;
$formDatas['serverinfo_uid'] = null;
$formDatas['old_clientinfo_uid'] = $serverEntity->getClientInfoUID() ?? null;
$formDatas['status'] = STATUS['AVAILABLE'];
if (!array_key_exists('status', $formDatas)) {
throw new \Exception(__METHOD__ . ":에서 오류발생: Switch상태가 설정되지 않았습니다.");
}
//Switch정보가져오기
$entity = $this->getEntity($serverEntity->getSwitchInfoUID());
if (!$entity instanceof SWITCHEntity) {
throw new \Exception("{$serverEntity->getSwitchInfoUID()}에 해당하는 Switch정보를 찾을수없습니다.");
}
//SWITCH 정보 수정
//초기화
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
/** @var SWITCHEntity $entity IDE에 entity type알려주기*/
$entity = $this->modify($entity->getPK(), $this->createDTO($formDatas));
return $entity;
}
//서버파트관련 작업
public function attachToServerPart(ServerPartEntity $serverPartEntity): SWITCHEntity
//파트정보가져오기
public function getPartEntityByServerPart(ServerPartEntity $serverPartEntity): SWITCHEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
$formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID();
$formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID();
$formDatas['status'] = STATUS['OCCUPIED'];
if (!array_key_exists('status', $formDatas)) {
throw new \Exception(__METHOD__ . ":에서 오류발생: Switch상태가 설정되지 않았습니다.");
}
//SWITCH정보에서 해당하는 SWITCH가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if ($entity instanceof SWITCHEntity) {
if ($entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception(__METHOD__ . ":에서 오류발생: {$entity->getTitle()}는 사용중입니다.");
}
//SWITCH 정보 수정
//초기화
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
/** @var SWITCHEntity $entity IDE에 entity type알려주기*/
$entity = $this->modify($entity->getPK(), $this->createDTO($formDatas));
}
return $entity;
}
public function detachFromServerPart(ServerPartEntity $serverPartEntity): SWITCHEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = null;
$formDatas['serviceinfo_uid'] = null;
$formDatas['serverinfo_uid'] = null;
$formDatas['old_clientinfo_uid'] = $serverPartEntity->getClientInfoUID() ?? null;
$formDatas['status'] = STATUS['AVAILABLE'];
if (!array_key_exists('status', $formDatas)) {
throw new \Exception(__METHOD__ . ":에서 오류발생: Switch상태가 설정되지 않았습니다.");
}
//Switch정보가져와서 있으면 수정
//IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof SWITCHEntity) {
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 Switch정보를 찾을수없습니다.");
throw new \Exception(message: "{$serverPartEntity->getPartUID()}에 해당하는 Switch정보를 찾을수없습니다.");
}
//SWITCH 정보 수정
//초기화
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
/** @var SWITCHEntity $entity IDE에 entity type알려주기*/
$entity = $this->modify($entity->getPK(), $this->createDTO($formDatas));
return $entity;
}
}