dbmsv3 init...1

This commit is contained in:
choi.jh 2025-10-27 18:18:29 +09:00
parent 5ab978b3cb
commit 48538d8ffb
4 changed files with 193 additions and 54 deletions

View File

@ -0,0 +1,140 @@
<?php
namespace App\Processors\Equipment;
use App\Entities\Equipment\ServerEntity;
use App\Services\Customer\ServiceService;
use App\Services\Equipment\ServerPartService;
use App\Services\Equipment\ServerService;
use App\Services\MyLogService;
use App\Services\Part\IPService;
use App\Services\Part\SWITCHService;
use CodeIgniter\Database\BaseConnection;
use RuntimeException;
class ServerPartV1Processor
{
public function __construct(
private BaseConnection $db,
private ServerService $service,
private ServiceService $serviceService,
private ServerPartService $serverPartService,
private IPService $ipService,
private SWITCHService $switchService,
private MyLogService $logService,
) {}
public function create(array $formDatas): ServerEntity
{
$this->db->transStart();
//1) 서버정보 생성
//switch값이 없으면 null처리
if (array_key_exists('switch', $formDatas) && !$formDatas['switch']) {
$formDatas['switch'] = null;
}
//ip값이 없으면 null처리
if (array_key_exists('ip', $formDatas) && !$formDatas['ip']) {
$formDatas['ip'] = null;
}
$entity = $this->service->getModel()->create($formDatas);
//2) 서버의 Type별 서버파트정보등록(서버파트연결 자동등록용)
$this->serverPartService->attachToServer($entity);
//3) Switch가 정의되어 있으면
if ($entity->getSwitch() !== null) { //
$this->switchService->attachToServer($entity);
}
//4) //IP가 정의되어 있으면
if ($entity->getIP() !== null) {
$this->ipService->attachToServer($entity);
}
//5) Log처리
$this->logService->create([
'title' => "[{$entity->getTitle()}] 서버 추가",
'status' => $entity->getStatus()
]);
$this->db->transComplete();
if ($this->db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패');
}
return $entity;
}
public function modify(ServerEntity $entity, array $formDatas): ServerEntity
{
$this->db->transStart();
//1) 사전처리 작업
//Switch값이 정의되어 있으면
$formDatas['switch'] = null; //기본Switch 정보 유지
$isChangedSwitch = false;
if (array_key_exists('switch', $formDatas) && !$formDatas['switch']) {
//기존 Switch값과 다르면
if ($entity->getSwitch() != $formDatas['switch']) {
//기존 Switch값이 있으면 해지
if ($entity->getSwitch() != null) {
$this->switchService->detachFromServer($entity);
}
$isChangedSwitch = true;
}
}
//IP값이 정의되어 있으면
$formDatas['ip'] = null; //기본IPh 정보 유지
$isChangedIP = false;
if (array_key_exists('ip', $formDatas) && !$formDatas['ip']) {
//기존 IP값과 다르면
if ($entity->getSwitch() != $formDatas['ip']) {
//기존 IP값이 있으면 해지
if ($entity->getIP() != null) {
$this->ipService->detachFromServer($entity);
}
$isChangedIP = true;
}
}
//2) 서버정보 수정
$entity = $this->service->getModel()->modify($entity, $formDatas);
//3) Switch값이 있고 신규값인경우
if ($entity->getSwitch() && $isChangedSwitch) {
$this->switchService->attachToServer($entity);
}
//3) IP값이 있고 신규값인경우
if ($entity->getIP() && $isChangedIP) {
$this->ipService->attachToServer($entity);
}
//5) 서비스금액 설정:서비스가 연결되어 있고 대체서버가 아니면, 서비스정보수정(청구액수정)
if ($entity->getServiceInfoUID() !== null && $entity->getType() !== SERVER['TYPES']['ALTERNATIVE']) {
$this->serviceService->setAmount($entity->getServiceInfoUID());
}
//5) Log처리
$this->logService->create([
'title' => "[{$entity->getTitle()}] 서버 정보변경",
'status' => $entity->getStatus()
]);
$this->db->transComplete();
if ($this->db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패');
}
return $entity;
}
public function delete(ServerEntity $entity): ServerEntity
{
//서비스가 연결되어있거나 , 사용가능 상태가 아니면 삭제불가
if ($entity->getServiceInfoUID() !== null || $entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception("서비스중인 서버는 삭제하실수 없습니다.");
}
$this->db->transStart();
//기존 Switch값이 있으면 해지
if ($entity->getSwitch() != null) {
$this->switchService->detachFromServer($entity);
}
//기존 IP값이 있으면 해지
if ($entity->getIP() != null) {
$this->ipService->detachFromServer($entity);
}
//기존 서버파트 해지
$this->serverPartService->detachFromServer($entity);
$this->db->transComplete();
if ($this->db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패');
}
return $entity;
}
}

View File

@ -3,12 +3,12 @@
namespace App\Processors\Equipment; namespace App\Processors\Equipment;
use App\Entities\Equipment\ServerEntity; use App\Entities\Equipment\ServerEntity;
use App\Services\Customer\ServiceService;
use App\Services\Equipment\ServerPartService; use App\Services\Equipment\ServerPartService;
use App\Services\Equipment\ServerService; use App\Services\Equipment\ServerService;
use App\Services\MyLogService; use App\Services\MyLogService;
use App\Services\Part\IPService; use App\Services\Part\IPService;
use App\Services\Part\SWITCHService; use App\Services\Part\SWITCHService;
use App\Services\PaymentService;
use CodeIgniter\Database\BaseConnection; use CodeIgniter\Database\BaseConnection;
use RuntimeException; use RuntimeException;
@ -17,6 +17,7 @@ class ServerV1Processor
public function __construct( public function __construct(
private BaseConnection $db, private BaseConnection $db,
private ServerService $service, private ServerService $service,
private ServiceService $serviceService,
private ServerPartService $serverPartService, private ServerPartService $serverPartService,
private IPService $ipService, private IPService $ipService,
private SWITCHService $switchService, private SWITCHService $switchService,
@ -97,6 +98,10 @@ class ServerV1Processor
if ($entity->getIP() && $isChangedIP) { if ($entity->getIP() && $isChangedIP) {
$this->ipService->attachToServer($entity); $this->ipService->attachToServer($entity);
} }
//5) 서비스금액 설정:서비스가 연결되어 있고 대체서버가 아니면, 서비스정보수정(청구액수정)
if ($entity->getServiceInfoUID() !== null && $entity->getType() !== SERVER['TYPES']['ALTERNATIVE']) {
$this->serviceService->setAmount($entity->getServiceInfoUID());
}
//5) Log처리 //5) Log처리
$this->logService->create([ $this->logService->create([
'title' => "[{$entity->getTitle()}] 서버 정보변경", 'title' => "[{$entity->getTitle()}] 서버 정보변경",
@ -108,4 +113,28 @@ class ServerV1Processor
} }
return $entity; return $entity;
} }
public function delete(ServerEntity $entity): ServerEntity
{
//서비스가 연결되어있거나 , 사용가능 상태가 아니면 삭제불가
if ($entity->getServiceInfoUID() !== null || $entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception("서비스중인 서버는 삭제하실수 없습니다.");
}
$this->db->transStart();
//기존 Switch값이 있으면 해지
if ($entity->getSwitch() != null) {
$this->switchService->detachFromServer($entity);
}
//기존 IP값이 있으면 해지
if ($entity->getIP() != null) {
$this->ipService->detachFromServer($entity);
}
//기존 서버파트 해지
$this->serverPartService->detachFromServer($entity);
$this->db->transComplete();
if ($this->db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패');
}
return $entity;
}
} }

View File

@ -166,7 +166,8 @@ class ServiceService extends CustomerService
{ {
return $entity->getRack() + $entity->getLine() + $this->getServerService()->getCalculatedAmount($serverEntity) - $entity->getSale(); return $entity->getRack() + $entity->getLine() + $this->getServerService()->getCalculatedAmount($serverEntity) - $entity->getSale();
} }
public function setAmount(int $uid): PaymentEntity //서비스금액변경
public function setAmount(string $uid): PaymentEntity
{ {
$entity = $this->getEntity($uid); $entity = $this->getEntity($uid);
if (!$entity instanceof ServiceEntity) { if (!$entity instanceof ServiceEntity) {

View File

@ -231,6 +231,7 @@ class ServerService extends EquipmentService implements ServerInterface
$processor = new Proceessor( $processor = new Proceessor(
\Config\Database::connect(), \Config\Database::connect(),
$this, $this,
$this->getServiceService(),
$this->getServerPartService(), $this->getServerPartService(),
$this->getIPService(), $this->getIPService(),
$this->getSwitchService(), $this->getSwitchService(),
@ -241,62 +242,30 @@ class ServerService extends EquipmentService implements ServerInterface
//수정 //수정
public function modify(mixed $entity, array $formDatas): ServerEntity public function modify(mixed $entity, array $formDatas): ServerEntity
{ {
//수정전 정보 $processor = new Proceessor(
//Switch정보 수정 \Config\Database::connect(),
if ($entity->getSwitch() !== null) { //기존 서버정보에 Switch가 정의되어 있으면 $this,
$this->getSwitchService()->unsetServer($entity); $this->getServiceService(),
} $this->getServerPartService(),
//IP정보 수정 $this->getIPService(),
if ($entity->getSwitch() !== null) { //기존 서버정보에 IP가 정의되어 있으면 $this->getSwitchService(),
$this->getIPService()->unsetServer($entity); $this->getMylogService()
} );
//ip값이 없으면 null처리 return $processor->modify($entity, $formDatas);
if (array_key_exists('ip', $formDatas) && !$formDatas['ip']) {
$formDatas['ip'] = null;
}
//서버정보 수정
$entity = parent::modify($entity, $formDatas);
//서비스가 연결되어 있고 대체서버가 아니면, 서비스정보수정(청구액수정)
if ($entity->getServiceInfoUID() !== null && $entity->getType() !== SERVER['TYPES']['ALTERNATIVE']) {
$this->getServiceService()->setAmount($entity->getServiceInfoUID());
}
if ($entity->getSwitch() !== null) { //Switch가 정의되어 있으면
$this->getSwitchService()->setServer($entity);
}
if ($entity->getIP() !== null) { //IP가 정의되어 있으면
$this->getIPService()->setServer($entity);
}
//Log처리
$this->getMylogService()->create([
'title' => "[{$entity->getTitle()}] 서버 수정",
'status' => $entity->getStatus()
]);
return $entity;
} }
//삭제 //삭제
public function delete(mixed $entity): ServerEntity public function delete(mixed $entity): ServerEntity
{ {
//서비스가 연결되어있거나 , 사용가능 상태가 아니면 삭제불가 $processor = new Proceessor(
if ($entity->getServiceInfoUID() !== null || $entity->getStatus() !== STATUS['AVAILABLE']) { \Config\Database::connect(),
throw new \Exception("서비스중인 서버는 삭제하실수 없습니다."); $this,
} $this->getServiceService(),
//Switch정보 해지 $this->getServerPartService(),
if ($entity->getSwitch() !== null) { //기존 서버정보에 Switch가 정의되어 있으면 $this->getIPService(),
$this->getSwitchService()->unsetServer($entity); $this->getSwitchService(),
} $this->getMylogService()
//IP정보해지 );
if ($entity->getIP() !== null) { //기존 서버정보에 IP가 정의되어 있으면 return $processor->delete($entity);
$this->getIPService()->unsetServer($entity);
}
//서버파트정보해지
$this->getServerPartService()->unsetServer($entity);
$entity = parent::delete($entity);
//Log처리
$this->getMylogService()->create([
'title' => "[{$entity->getTitle()}] 서버 삭제",
'status' => $entity->getStatus()
]);
return $entity;
} }
//List 검색용 //List 검색용
//OrderBy 처리 //OrderBy 처리