dbmsv3 init...1

This commit is contained in:
choi.jh 2025-10-27 17:15:47 +09:00
parent c71efa7eb5
commit 5ab978b3cb
23 changed files with 498 additions and 1135 deletions

View File

@ -5,7 +5,6 @@ namespace App\Controllers\Admin\Customer;
use App\Entities\Customer\ServiceEntity;
use App\Entities\Equipment\ServerEntity;
use App\Services\Customer\ServiceService;
use App\Services\PaymentService;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
@ -13,7 +12,6 @@ use Psr\Log\LoggerInterface;
class ServiceController extends CustomerController
{
private ?PaymentService $_paymentService = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
@ -150,7 +148,7 @@ class ServiceController extends CustomerController
if (!$entity instanceof ServiceEntity) {
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
}
$this->entity = $this->getService()->addServer($entity, $this->getService()->getFormDatas());
$this->entity = $this->getService()->addeAlternativeServer($entity, $this->getService()->getFormDatas());
$db->transCommit();
return "<script>alert('대체서버추가가 완료되었습니다.'); history.back();</script>";
} catch (\Exception $e) {
@ -178,7 +176,7 @@ class ServiceController extends CustomerController
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
}
//서버정보설정
$this->getService()->changeServer($entity, $this->getService()->getFormDatas());
$this->getService()->replaceMainServer($entity, $this->getService()->getFormDatas());
$db->transCommit();
return $this->getResultSuccess('메인서버 설정이 바뀌었습니다.');
} catch (\Exception $e) {

File diff suppressed because one or more lines are too long

View File

@ -1,5 +0,0 @@
<?php
namespace App\Interfaces\Equipment;
interface EquipmentInterface {}

View File

@ -5,8 +5,8 @@ namespace App\Interfaces\Equipment;
use App\Entities\Customer\ServiceEntity;
use App\Entities\Equipment\ServerEntity;
interface ServerInterface extends EquipmentInterface
interface ServerInterface
{
public function attachToService(ServiceEntity $service, string $serverinfo_uid, array $formDatas = []): ServerEntity;
public function attachToService(ServiceEntity $serviceEntity, string $serverinfo_uid, array $formDatas = []): ServerEntity;
public function detachFromService(string $serverinfo_uid): ServerEntity;
}

View File

@ -2,10 +2,10 @@
namespace App\Interfaces\Equipment;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Equipment\ServerEntity;
interface ServerPartInterface extends EquipmentInterface
interface ServerPartInterface
{
public function setServerPart(ServerPartEntity $serverPartEntity): void;
public function unsetServerPart(ServerPartEntity $serverPartEntity): void;
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): void;
public function detachFromServer(ServerEntity $serverEntity): void;
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Interfaces\Part;
use App\Entities\Equipment\ServerEntity;
interface IPInterface
{
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): void;
public function detachFromServer(ServerEntity $serverEntity): void;
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Interfaces\Part;
use App\Entities\Equipment\ServerPartEntity;
interface PartInterface
{
public function attachToServerPart(ServerPartEntity $serverPartEntity): mixed;
public function detachFromServerPart(ServerPartEntity $serverPartEntity): mixed;
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Interfaces\Part;
use App\Entities\Equipment\ServerEntity;
interface SWITCHInterface
{
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): void;
public function detachFromServer(ServerEntity $serverEntity): void;
}

View File

@ -3,11 +3,19 @@
namespace App\Interfaces;
use App\Entities\Customer\ServiceEntity;
use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\PaymentEntity;
interface PaymentInterface
{
//서비스 결제(월과금 서비스 사용)
public function createForService(ServiceEntity $service, int $amount): PaymentEntity;
public function updateForService(ServiceEntity $service, string $payment_uid, int $amount): PaymentEntity;
public function unlinkFromService(string $payment_uid): PaymentEntity;
//서버 파트 결제(파트/기타 일회성 서비스 사용)
public function createForServerPart(ServerPartEntity $serverPart, int $amount): PaymentEntity;
public function updateForServerPart(ServerPartEntity $serverPart, string $payment_uid, int $amount): PaymentEntity;
public function unlinkFromServerPart(string $payment_uid): PaymentEntity;
}

View File

@ -4,128 +4,49 @@ namespace App\Processors\Customer;
use App\Entities\Customer\ServiceEntity;
use App\Entities\Equipment\ServerEntity;
use App\Entities\PaymentEntity;
use App\Services\Customer\ServiceService;
use App\Services\Equipment\ServerService;
use App\Services\MyLogService;
use App\Services\PaymentService;
use CodeIgniter\Database\BaseConnection;
use DateTimeImmutable;
use DateTimeZone;
use RuntimeException;
class ServiceV1Processor
{
public function __construct(
private BaseConnection $db,
private ServiceService $serviceService,
private ServiceService $service,
private ServerService $serverService,
private PaymentService $paymentService,
private MyLogService $logService,
) {}
/** 서버 연결 */
public function setServer(ServiceEntity $entity, string $serverinfo_uid, array $formDatas = []): ServerEntity
{
$serverEntity = $this->serverService->getEntity($serverinfo_uid);
if (!$serverEntity instanceof ServerEntity) {
throw new RuntimeException("[{$serverinfo_uid}]에 대한 서버정보를 찾을 수 없습니다.");
}
$formDatas['clientinfo_uid'] = $entity->getClientInfoUID();
$formDatas['serviceinfo_uid'] = $entity->getPK();
$formDatas['status'] = STATUS['OCCUPIED'];
return $this->serverService->getModel()->modify($serverEntity, $formDatas);
}
/** 서버 연결 해지 */
public function unsetServer(string $serverinfo_uid): ServerEntity
{
$serverEntity = $this->serverService->getEntity($serverinfo_uid);
if (!$serverEntity instanceof ServerEntity) {
throw new RuntimeException("[{$serverinfo_uid}]에 대한 서버정보를 찾을 수 없습니다.");
}
return $this->serverService->getModel()->modify($serverEntity, [
'clientinfo_uid' => null,
'serviceinfo_uid' => null,
'format_at' => date("Y-m-d"),
'status' => STATUS['AVAILABLE'],
]);
}
/** 결제 생성 */
public function createPayment(ServiceEntity $entity, int $amount): PaymentEntity
{
$billingAt = new DateTimeImmutable($entity->getBillingAt(), new DateTimeZone('Asia/Tokyo'));
return $this->paymentService->getModel()->create([
'clientinfo_uid' => $entity->getClientInfoUID(),
'serviceinfo_uid' => $entity->getPK(),
'serverinfo_uid' => $entity->getServerInfoUID(), //서버정보 번호
'title' => sprintf('[%s] %s 서비스비용', $entity->getTitle(), $billingAt->format('Y년 n월')),
'amount' => $amount,
'billing' => PAYMENT['BILLING']['MONTH'],
'billing_at' => $billingAt->format('Y-m-d'),
]);
}
/** 결제 수정 */
public function modifyPayment(ServiceEntity $entity, string $payment_uid, int $amount): PaymentEntity
{
$paymentEntity = $this->paymentService->getEntity($payment_uid);
if (!$paymentEntity instanceof PaymentEntity) {
throw new RuntimeException("[{$payment_uid}]에 대한 결제정보를 찾을 수 없습니다.");
}
$billingAt = new DateTimeImmutable($entity->getBillingAt(), new DateTimeZone('Asia/Tokyo'));
return $this->paymentService->getModel()->modify($paymentEntity, [
'clientinfo_uid' => $entity->getClientInfoUID(),
'serviceinfo_uid' => $entity->getPK(),
'serverinfo_uid' => $entity->getServerInfoUID(),
'title' => sprintf('[%s] %s 서비스비용', $entity->getTitle(), $billingAt->format('Y년 n월')),
'amount' => $amount,
'billing' => PAYMENT['BILLING']['MONTH'],
'billing_at' => $billingAt->format('Y-m-d'),
]);
}
/** 결제 삭제(서비스UID,서버UID만 NULL 처리하고 다른정보는 그냥 두고 수정한다.) */
public function deletePayment(string $payment_uid): PaymentEntity
{
$paymentEntity = $this->paymentService->getEntity($payment_uid);
if (!$paymentEntity instanceof PaymentEntity) {
throw new RuntimeException("[{$payment_uid}]에 대한 결제정보를 찾을 수 없습니다.");
}
return $this->paymentService->getModel()->modify($paymentEntity, [
'serviceinfo_uid' => null,
'serverinfo_uid' => null,
]);
}
/** 로그 생성*/
public function addLog(string $title, string $status): void
{
$this->logService->getModel()->create(['title' => $title, 'status' => $status,]);
}
/** 최종 결과만 필요할 때 */
public function createService(array $formDatas): ServiceEntity
public function create(array $formDatas): ServiceEntity
{
$this->db->transStart();
if (!isset($formDatas['serverinfo_uid'])) {
throw new RuntimeException('서버가 지정되지 않았습니다.');
}
// 1) 서비스 추가
$entity = $this->serviceService->getModel()->create($formDatas);
// 1) 서비스 생성
$entity = $this->service->getModel()->create($formDatas);
// 2) 서버 연결
$serverEntity = $this->setServer($entity, $entity->getServerInfoUID());
// 3) 금액 계산
$amount = $this->serviceService->getCalculatedAmount($entity, $serverEntity);
// 4) 결제 생성
$paymentEntity = $this->createPayment($entity, $amount);
// 5) 로그 (필요 시 이벤트로 대체)
$this->addLog("{$entity->getCustomTitle()} 서비스 추가", $entity->getStatus());
// 6) 서비스 갱신(FK 반영)
$this->serviceService->getModel()->modify($entity, [
'title' => $entity->getCustomTitle(),
$serverEntity = $this->serverService->attachToService(
$entity,
$entity->getServerInfoUID()
);
// 3) 금액 계산 + 반영
$amount = $this->service->getCalculatedAmount($entity, $serverEntity);
$this->service->getModel()->modify($entity, ['amount' => $amount]);
// 4) 결제 생성
$paymentEntity = $this->paymentService->createForService($entity, $amount);
// 5) 서비스 FK 동기화
$entity = $this->service->getModel()->modify($entity, [
'title' => $entity->getTitle(),
'serverinfo_id' => $serverEntity->getPK(),
'payment_uid' => $paymentEntity->getPK(),
]);
// 6) 로그
$this->logService->create([
'title' => "{$entity->getTitle()} 서비스 추가",
'status' => $entity->getStatus(),
]);
$this->db->transComplete();
if ($this->db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패');
@ -133,31 +54,35 @@ class ServiceV1Processor
return $entity;
}
public function modifyService(ServiceEntity $entity, array $formDatas): ServiceEntity
public function modify(ServiceEntity $entity, array $formDatas): ServiceEntity
{
$this->db->transStart();
if (!isset($formDatas['serverinfo_uid'])) {
throw new RuntimeException('변경할 서버가 지정되지 않았습니다.');
}
// 서버번호가 변경되었다면 기존 서버 연결 해지
// 서버 변경이면 기존 서버 해지
if ($entity->getServerInfoUID() !== null && $entity->getServerInfoUID() !== $formDatas['serverinfo_uid']) {
$this->unsetServer($entity->getServerInfoUID());
$this->serverService->detachFromService($entity->getServerInfoUID());
}
// 1) 서비스정보 수정
$entity = $this->serviceService->getModel()->modify($entity, $formDatas);
// 2) 서버 재연결
$serverEntity = $this->setServer($entity, $entity->getServerInfoUID());
// 3) 금액 계산
$amount = $this->serviceService->getCalculatedAmount($entity, $serverEntity);
// 4) 결제 정보 수정
$paymentEntity = $this->modifyPayment($entity, $entity->getPaymentUID(), $amount);
// 5) 로그
$this->addLog("{$entity->getCustomTitle()} 서비스 수정", $entity->getStatus());
// 6) FK 반영
$this->serviceService->getModel()->modify($entity, [
'title' => $entity->getCustomTitle(),
// 1) 서비스 정보 수정
$entity = $this->service->getModel()->modify($entity, $formDatas);
// 2) 서버 재지정
$serverEntity = $this->serverService->attachToService(
$entity,
$entity->getServerInfoUID()
);
// 3) 금액 재계산 + 반영
$amount = $this->service->getCalculatedAmount($entity, $serverEntity);
$this->service->getModel()->modify($entity, ['amount' => $amount]);
// 4) 결제 수정
$payment = $this->paymentService->updateForService($entity, $entity->getPaymentUID(), $amount);
// 5) 서비스 FK 동기화
$entity = $this->service->getModel()->modify($entity, [
'title' => $entity->getTitle(),
'serverinfo_id' => $serverEntity->getPK(),
'payment_uid' => $paymentEntity->getPK(),
'payment_uid' => $payment->getPK(),
]);
// 6) 로그
$this->logService->create(formDatas: [
'title' => "{$entity->getTitle()} 서비스 수정",
'status' => $entity->getStatus(),
]);
$this->db->transComplete();
if ($this->db->transStatus() === false) {
@ -166,21 +91,106 @@ class ServiceV1Processor
return $entity;
}
public function deleteService(ServiceEntity $entity): ServiceEntity
public function delete(ServiceEntity $entity): ServiceEntity
{
$this->db->transStart();
// 1) 결제정보 분리
// 1) 결제 분리
if ($entity->getPaymentUID()) {
$this->deletePayment($entity->getPaymentUID());
$this->paymentService->unlinkFromService($entity->getPaymentUID());
}
// 2) 연결된 모든 서버 해지 (★ 오타 수정: serviceinfo_uid)
foreach ($this->serverService->getEntities(['serviceinfo_uid' => $entity->getPK()]) as $serverEntity) {
$this->unsetServer($serverEntity->getPK()); // PK가 uid면 OK
// 2) 연결된 모든 서버 해지
foreach ($this->serverService->getEntities($entity->getPK()) as $serverEntity) {
$this->serverService->detachFromService($serverEntity->getPK());
}
// 3) 로그
$this->addLog("[{$entity->getCustomTitle()}] 서비스 해지", $entity->getStatus());
// 4) 서비스 삭제
$this->serviceService->delete($entity);
// 3) 서비스 삭제
$this->service->getModel()->delete($entity);
// 4) 로그
$this->logService->create([
'title' => "[{$entity->getTitle()}] 서비스 해지",
'status' => $entity->getStatus(),
]);
$this->db->transComplete();
if ($this->db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패');
}
return $entity;
}
public function addeAlternativeServer(ServiceEntity $entity, string $serverinfo_uid): ServiceEntity
{
if (!$serverinfo_uid) {
throw new \Exception("대체 서버의 UID[{$serverinfo_uid}]값이 비정상적입니다.");
}
$this->db->transStart();
// 1) 대체서버 추가
$this->serverService->attachToService(
$entity,
$serverinfo_uid,
[
'type' => SERVER['TYPES']['ALTERNATIVE'],
]
);
// 2) 로그
$this->logService->create([
'title' => "[{$entity->getTitle()}] 대체서버 추가",
'status' => $entity->getStatus(),
]);
$this->db->transComplete();
if ($this->db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패');
}
return $entity;
}
public function replaceMainServer(ServiceEntity $entity, string $serverinfo_uid): ServiceEntity
{
$this->db->transStart();
// 1) 기존 메인서버정보 가져오기
$serverEntity = $this->serverService->getEntity($entity->getServerInfoUID());
if (!$serverEntity instanceof ServerEntity) {
throw new \Exception(__METHOD__ . "에서 오류발생: {$entity->getServerInfoUID()}에 대한 서버정보를 찾을수 없습니다.");
}
// 2) 메인서버 변경
$this->serverService->attachToService(
$entity,
$serverinfo_uid,
['type' => $serverEntity->getType()]
);
// 3) 금액 재계산 + 반영
$amount = $this->service->getCalculatedAmount($entity, $serverEntity);
$this->service->getModel()->modify($entity, ['amount' => $amount]);
// 4) 결제 수정
$payment = $this->paymentService->updateForService($entity, $entity->getPaymentUID(), $amount);
// 4) 서비스 FK 동기화
$entity = $this->service->getModel()->modify($entity, [
'title' => $entity->getTitle(),
'serverinfo_id' => $serverEntity->getPK(),
'payment_uid' => $payment->getPK(),
]);
// 5) 로그
$this->logService->create([
'title' => "[{$entity->getTitle()}] 메인서버변경",
'status' => $entity->getStatus(),
]);
$this->db->transComplete();
if ($this->db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패');
}
return $entity;
}
public function terminateServer(ServiceEntity $entity, string $serverinfo_uid): ServiceEntity
{
if ($entity->getServerInfoUID() === $serverinfo_uid) {
throw new \Exception(__METHOD__ . "에서 오류발생: 서비스의 메인 서버정보는 해지할 수 없습니다.");
}
$this->db->transStart();
$this->serverService->detachFromService($serverinfo_uid);
// 4) 로그
$this->logService->create([
'title' => "[{$entity->getTitle()}] 대체서버 해지",
'status' => $entity->getStatus(),
]);
$this->db->transComplete();
if ($this->db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패');

View File

@ -0,0 +1,111 @@
<?php
namespace App\Processors\Equipment;
use App\Entities\Equipment\ServerEntity;
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 App\Services\PaymentService;
use CodeIgniter\Database\BaseConnection;
use RuntimeException;
class ServerV1Processor
{
public function __construct(
private BaseConnection $db,
private ServerService $service,
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) Log처리
$this->logService->create([
'title' => "[{$entity->getTitle()}] 서버 정보변경",
'status' => $entity->getStatus()
]);
$this->db->transComplete();
if ($this->db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패');
}
return $entity;
}
}

View File

@ -24,7 +24,7 @@ abstract class CommonService
}
abstract public function getFormFields(): array;
abstract public function getFormFilters(): array;
final protected function getModel(): mixed
final public function getModel(): mixed
{
if (!$this->_model instanceof CommonModel) {
throw new \Exception(__METHOD__ . "에서 오류발생:Model이 정의되지 않았습니다. ");

View File

@ -11,7 +11,7 @@ use App\Services\Equipment\ServerService;
use App\Services\PaymentService;
use DateTimeImmutable;
use DateTimeZone;
use App\Processors\Customer\ServiceV1Processor as Proceessor;
class ServiceService extends CustomerService
{
@ -198,109 +198,41 @@ class ServiceService extends CustomerService
//생성
public function create(array $formDatas): ServiceEntity
{
$db = \Config\Database::connect();
$db->transStart();
if (!isset($formDatas['serverinfo_uid'])) {
throw new \Exception('서버가 지정되지 않았습니다.');
throw new \Exception('변경할 서버가 지정되지 않았습니다.');
}
// 1) 서비스 생성
$entity = $this->getModel()->create($formDatas);
// 2) 서버 연결
$serverEntity = $this->getServerService()->attachToService($entity, $entity->getServerInfoUID());
// 3) 금액 계산 + 반영
$amount = $this->getCalculatedAmount($entity, $serverEntity);
$this->getModel()->modify($entity, ['amount' => $amount]);
// 4) 결제 생성
$paymentEntity = $this->getPaymentService()->createForService($entity, $amount);
// 5) 로그
$this->getMyLogService()->create([
'title' => "{$entity->getCustomTitle()} 서비스 추가",
'status' => $entity->getStatus(),
]);
// 6) 서비스 FK 동기화
$entity = $this->getModel()->modify($entity, [
'title' => $entity->getCustomTitle(),
'serverinfo_id' => $serverEntity->getPK(),
'payment_uid' => $paymentEntity->getPK(),
]);
$db->transComplete();
if ($db->transStatus() === false) {
throw new \Exception('트랜잭션 실패');
}
return $entity;
$processor = new Proceessor(
\Config\Database::connect(),
$this,
$this->getServerService(),
$this->getPaymentService(),
$this->getMylogService()
);
return $processor->create($formDatas);
}
//수정
public function modify(mixed $entity, array $formDatas): ServiceEntity
{
if (!$entity instanceof ServiceEntity) {
$entity = $this->getEntity((int)$entity);
}
$db = \Config\Database::connect();
$db->transStart();
if (!isset($formDatas['serverinfo_uid'])) {
throw new \Exception('변경할 서버가 지정되지 않았습니다.');
}
// 서버 변경이면 기존 서버 해지
if ($entity->getServerInfoUID() !== null && $entity->getServerInfoUID() !== $formDatas['serverinfo_uid']) {
$this->getServerService()->detachFromService($entity->getServerInfoUID());
}
// 1) 서비스 정보 수정
$entity = $this->getModel()->modify($entity, $formDatas);
// 2) 서버 재지정
$serverEntity = $this->getServerService()->attachToService($entity, $entity->getServerInfoUID());
// 3) 금액 재계산 + 반영
$amount = $this->getCalculatedAmount($entity, $serverEntity);
$this->getModel()->modify($entity, ['amount' => $amount]);
// 4) 결제 수정 (표준 메서드)
$billingAt = new DateTimeImmutable($entity->getBillingAt(), new DateTimeZone('Asia/Tokyo'));
$payment = $this->getPaymentService()->updateForService($entity, $entity->getPaymentUID(), $amount);
// 5) 로그
$this->getMyLogService()->create([
'title' => "{$entity->getCustomTitle()} 서비스 수정",
'status' => $entity->getStatus(),
]);
// 6) 서비스 FK 동기화
$entity = $this->getModel()->modify($entity, [
'title' => $entity->getCustomTitle(),
'serverinfo_id' => $serverEntity->getPK(),
'payment_uid' => $payment->getPK(),
]);
$db->transComplete();
if ($db->transStatus() === false) {
throw new \Exception('트랜잭션 실패');
}
return $entity;
$processor = new Proceessor(
\Config\Database::connect(),
$this,
$this->getServerService(),
$this->getPaymentService(),
$this->getMylogService()
);
return $processor->modify($entity, $formDatas);
}
//삭제
public function delete(mixed $entity): ServiceEntity
{
if (!$entity instanceof ServiceEntity) {
$entity = $this->getEntity((int)$entity);
}
$db = \Config\Database::connect();
$db->transStart();
// 1) 결제 분리
if ($entity->getPaymentUID()) {
$this->getPaymentService()->unlinkFromService($entity->getPaymentUID());
}
// 2) 연결된 모든 서버 해지
foreach ($this->getServerService()->getEntities($entity->getPK()) as $serverEntity) {
$this->getServerService()->detachFromService($serverEntity->getPK());
}
// 3) 로그
$this->getMyLogService()->create([
'title' => "[{$entity->getCustomTitle()}] 서비스 해지",
'status' => $entity->getStatus(),
]);
// 4) 서비스 삭제
parent::delete($entity);
$db->transComplete();
if ($db->transStatus() === false) {
throw new \Exception('트랜잭션 실패');
}
return $entity;
$processor = new Proceessor(
\Config\Database::connect(),
$this,
$this->getServerService(),
$this->getPaymentService(),
$this->getMylogService()
);
return $processor->delete($entity);
}
//비고(History)설정
public function history(mixed $entity, array $formDatas): ServiceEntity
@ -308,32 +240,33 @@ class ServiceService extends CustomerService
return parent::modify($entity, $formDatas);
}
//대체서버추가
public function addServer(ServiceEntity $entity, array $formDatas): ServiceEntity
public function addeAlternativeServer(ServiceEntity $entity, array $formDatas): ServiceEntity
{
if (!array_key_exists('serverinfo_uid', $formDatas)) {
throw new \Exception(__METHOD__ . "에서 오류발생:대체서버가 지정되지 않았습니다.");
}
$this->getServerService()->attachToService($entity, $formDatas['serverinfo_uid'], [
'type' => SERVER['TYPES']['ALTERNATIVE'],
]);
return $entity;
$processor = new Proceessor(
\Config\Database::connect(),
$this,
$this->getServerService(),
$this->getPaymentService(),
$this->getMylogService()
);
return $processor->addeAlternativeServer($entity, $formDatas['serverinfo_uid']);
}
public function changeServer(ServiceEntity $entity, array $formDatas): ServiceEntity
public function replaceMainServer(ServiceEntity $entity, array $formDatas): ServiceEntity
{
if (!array_key_exists('serverinfo_uid', $formDatas)) {
throw new \Exception(__METHOD__ . "에서 오류발생:메인서버로 전환할 대체서버가 지정되지 않았습니다.");
}
$serverEntity = $this->getServerService()->getEntity($entity->getServerInfoUID());
if (!$serverEntity instanceof ServerEntity) {
throw new \Exception(__METHOD__ . "에서 오류발생: {$entity->getServerInfoUID()}에 대한 서버정보를 찾을수 없습니다.");
}
$this->getServerService()->attachToService(
$entity,
$formDatas['serverinfo_uid'],
['type' => $serverEntity->getType()]
$processor = new Proceessor(
\Config\Database::connect(),
$this,
$this->getServerService(),
$this->getPaymentService(),
$this->getMylogService()
);
// 메인 서버 변경에 따른 금액/결제/링크 동기화를 위해 modify 흐름 재사용
return $this->modify($entity, $formDatas);
return $processor->replaceMainServer($entity, $formDatas['serverinfo_uid']);
}
public function terminateServer(ServiceEntity $entity, array $formDatas): ServiceEntity
@ -341,9 +274,6 @@ class ServiceService extends CustomerService
if (!array_key_exists('serverinfo_uid', $formDatas)) {
throw new \Exception(__METHOD__ . "에서 오류발생:메인서버로 전환할 대체서버가 지정되지 않았습니다.");
}
if ($entity->getServerInfoUID() === $formDatas['serverinfo_uid']) {
throw new \Exception(__METHOD__ . "에서 오류발생: 서비스의 메인 서버정보는 해지할 수 없습니다.");
}
$this->getServerService()->detachFromService($formDatas['serverinfo_uid']);
return $entity;
}

View File

@ -5,6 +5,7 @@ namespace App\Services\Equipment;
use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Helpers\Equipment\ServerPartHelper;
use App\Interfaces\Equipment\ServerPartInterface;
use App\Models\Equipment\ServerPartModel;
use App\Services\Customer\ServiceService;
use App\Services\Equipment\EquipmentService;
@ -18,7 +19,7 @@ use App\Services\Part\SOFTWAREService;
use App\Services\Part\SWITCHService;
use App\Services\PaymentService;
class ServerPartService extends EquipmentService
class ServerPartService extends EquipmentService implements ServerPartInterface
{
private ?ServiceService $_serviceService = null;
private ?ServerService $_serverService = null;
@ -187,53 +188,44 @@ class ServerPartService extends EquipmentService
}
return $service;
}
//서버 코드의 Type에 따라 서버파트 등록
private function setDefaultPartByServer(string $parttype, array $formDatas): array
//서버관련 작업
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): void
{
if (!array_key_exists('part_uid', $formDatas)) {
throw new \Exception(__METHOD__ . "에서 오류발생: 파트번호를 지정하지 않으셨습니다.");
}
$partEntity = $this->getPartService($parttype)->getEntity($formDatas['part_uid']);
if (!$partEntity) {
throw new \Exception(__METHOD__ . "에서 오류발생: 파트기본정보를 찾을수 없습니다.");
}
$formDatas['title'] = $partEntity->getTitle();
$formDatas['amount'] = $partEntity->getPrice();
return $formDatas;
}
//서버정보 설정
public function setServer(ServerEntity $serverEntity): void
{
$server_type = $serverEntity->getTitle(); //대소문자구분 필요->서버의 Title로 구분해서 기본부품 추가
//대소문자구분 필요->서버의 Title로 구분해서 기본부품 추가
$server_model = $serverEntity->getTitle();
foreach (SERVERPART['SERVER_PARTTYPES'] as $parttype) {
//해당 server_type의 정의된 상수값이 있으면
if (array_key_exists($server_type, SERVERPART[$parttype])) {
foreach (SERVERPART[$parttype][$server_type] as $serverpart) {
if (array_key_exists($server_model, SERVERPART[$parttype])) {
foreach (SERVERPART[$parttype][$server_model] as $part) {
$partEntity = $this->getPartService($server_model)->getEntity($part['UID']);
//해당 파트정보 가져오기
$formDatas = [];
$formDatas['serverinfo_uid'] = $serverEntity->getPK();
$formDatas["part_uid"] = $serverpart["UID"];
$formDatas["part_uid"] = $partEntity->getPK();
$formDatas['billing'] = PAYMENT['BILLING']['BASE'];
$formDatas['type'] = $parttype;
$formDatas['cnt'] = $serverpart["CNT"];
$formDatas['extra'] = $serverpart["EXTRA"];
$formDatas = $this->setDefaultPartByServer($parttype, $formDatas);
$formDatas['title'] = $partEntity->getTitle(); //파트 제목
$formDatas['amount'] = $partEntity->getPrice(); //파트 금액
$formDatas['cnt'] = $part["CNT"];
$formDatas['extra'] = $part["EXTRA"];
//서버연결정보 생성
parent::create($formDatas);
$serverPartEntity = parent::create($formDatas);
$partEntity = $this->getPartService($parttype)->attachToServerPart($serverPartEntity);
}
}
}
}
public function unsetServer(ServerEntity $serverEntity): void
public function detachFromServer(ServerEntity $serverEntity): void
{
//서버정보에 해당하는 ServerPart정보 모두 회수처리 후 서버정보에 기본 ServerPart를 다시 등록해준다.
foreach ($this->getEntities(['serverinfo_uid' => $serverEntity->getPK()]) as $entity) {
//Type에 따른 부품서비스 정의
$this->getPartService($entity->getType())->unsetServerPart($entity);
$this->getPartService($entity->getType())->detachFromServerPart($entity);
//서버연결정보 식제
parent::delete($entity);
}
//서버정보에 기본 ServerPart를 다시 등록해준다.
$this->setServer($serverEntity);
$this->attachToServer($serverEntity);
}
//기본 기능부분
// FieldForm관련용

View File

@ -12,6 +12,7 @@ use App\Services\Equipment\EquipmentService;
use App\Services\Equipment\ServerPartService;
use App\Services\Part\IPService;
use App\Services\Part\SWITCHService;
use App\Processors\Equipment\ServerV1Processor as Proceessor;
class ServerService extends EquipmentService implements ServerInterface
{
@ -227,22 +228,15 @@ class ServerService extends EquipmentService implements ServerInterface
}
public function create(array $formDatas): ServerEntity
{
//서버정보 생성
$entity = parent::create($formDatas);
//서버의 Type별 서버파트정보등록(서버파트연결 자동등록용)
$this->getServerPartService()->setServer($entity);
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;
$processor = new Proceessor(
\Config\Database::connect(),
$this,
$this->getServerPartService(),
$this->getIPService(),
$this->getSwitchService(),
$this->getMylogService()
);
return $processor->create($formDatas);
}
//수정
public function modify(mixed $entity, array $formDatas): ServerEntity

View File

@ -2,7 +2,6 @@
namespace App\Services;
use App\Entities\Customer\ServiceEntity;
use App\Entities\MyLogEntity;
use App\Helpers\MyLogHelper;
use App\Models\MyLogModel;
@ -10,10 +9,22 @@ use App\Services\CommonService;
class MyLogService extends CommonService
{
private $_myAuth = null;
private $_myAuthUID = null;
public function __construct()
{
parent::__construct(new MyLogModel(), new MyLogHelper());
$this->addClassName('MyLog');
if ($this->getMyAuth()->isLoggedIn()) {
$this->_myAuthUID = $this->getMyAuth()->getUIDByAuthInfo();
}
}
final public function getMyAuth(): mixed
{
if (!$this->_myAuth) {
$this->_myAuth = service('myauth');
}
return $this->_myAuth;
}
public function getFormFields(): array
{
@ -42,4 +53,10 @@ class MyLogService extends CommonService
$this->getModel()->orLike($this->getModel()::TABLE . "." . $this->getModel()::TITLE, $word, 'both');
$this->getModel()->orLike($this->getModel()::TABLE . '.content', $word, 'both');
}
public function create(array $formDatas): MyLogEntity
{
//관리자(작업자정보) 등록
$formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo();
return parent::create($formDatas);
}
}

View File

@ -2,6 +2,7 @@
namespace App\Services\Part;
use App\Entities\Equipment\ServerPartEntity;
use App\Helpers\Part\CPUHelper;
use App\Models\Part\CPUModel;

View File

@ -2,6 +2,7 @@
namespace App\Services\Part;
use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\CSEntity;
use App\Helpers\Part\CSHelper;
@ -95,7 +96,7 @@ class CSService extends PartService
}
//서버파트관련 작업
public function setServerPart(ServerPartEntity $serverPartEntity): void
public function attachToServerPart(ServerPartEntity $serverPartEntity): CSEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
@ -108,12 +109,19 @@ class CSService extends PartService
//CS정보가져오기
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof CSEntity) {
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 CS정보를 찾을수없습니다.");
throw new \Exception(message: "{$serverPartEntity->getPartUID()}에 해당하는 CS정보를 찾을수없습니다.");
}
//CS정보 수정
parent::modify($entity, $formDatas);
//CS정보에서 해당하는 CS가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if ($entity instanceof CSEntity) {
if ($entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception(__METHOD__ . ":에서 오류발생: {$serverPartEntity->getTitle()}는 사용중입니다.");
}
$entity = parent::modify($entity, $formDatas);
}
return $entity;
}
public function unsetServerPart(ServerPartEntity $serverPartEntity): void
public function detachFromServerPart(ServerPartEntity $serverPartEntity): CSEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = null;
@ -129,6 +137,6 @@ class CSService extends PartService
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 CS정보를 찾을수없습니다.");
}
//CS정보 수정
parent::modify($entity, $formDatas);
return parent::modify($entity, $formDatas);
}
}

View File

@ -2,7 +2,9 @@
namespace App\Services\Part;
use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\DISKEntity;
use App\Helpers\Part\DISKHelper;
use App\Models\Part\DISKModel;
@ -54,17 +56,17 @@ class DISKService extends PartService
}
//서버파트관련 작업
public function unsetServerPart(ServerPartEntity $serverPartEntity): void
public function detachFromServerPart(ServerPartEntity $serverPartEntity): DiskEntity
{
//부품정보가져오기
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity) {
if (!$entity instanceof DISKEntity) {
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다.");
}
//부품정보에 서버정보 설정 및 서비스,고객정보 정의
if ($entity->getStock() < $serverPartEntity->getCnt()) {
throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
}
parent::modify($entity, ['format' => $entity->getFormat() + $serverPartEntity->getCnt()]);
return parent::modify($entity, ['format' => $entity->getFormat() + $serverPartEntity->getCnt()]);
}
}

View File

@ -6,13 +6,14 @@ use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\IPEntity;
use App\Helpers\Part\IPHelper;
use App\Interfaces\Part\IPInterface;
use App\Models\Part\IPModel;
use App\Services\Customer\ServiceService;
use App\Services\Equipment\LineService;
use App\Services\Equipment\ServerService;
use App\Services\Part\PartService;
class IPService extends PartService
class IPService extends PartService implements IPInterface
{
private ?LineService $_lineService = null;
private ?ServiceService $_serviceService = null;
@ -111,82 +112,70 @@ class IPService extends PartService
parent::setOrderBy($field, $value);
}
//서버관련 작업
public function setServer(ServerEntity $serverEntity): void
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): void
{
$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__ . ":에서 오류발생: IP상태가 설정되지 않았습니다.");
}
//IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity(['ip' => $serverEntity->getIP()]);
if ($entity instanceof IPEntity) {
if ($entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception(__METHOD__ . ":에서 오류발생: {$serverEntity->getIP()}는 사용중인 IP입니다.");
throw new \Exception(__METHOD__ . ":에서 오류발생: {$serverEntity->getTitle()}는 사용중입니다.");
}
$entity = parent::modify($entity, $formDatas);
}
}
public function unsetServer(ServerEntity $serverEntity): void
public function detachFromServer(ServerEntity $serverEntity): void
{
$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__ . ":에서 오류발생: IP상태가 설정되지 않았습니다.");
}
//IP정보가져와서 있으면 수정
$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) {
$entity = parent::modify($entity, $formDatas);
if (!$entity instanceof IPEntity) {
throw new \Exception("{$serverEntity->getIP()}에 해당하는 IP정보를 찾을수없습니다.");
}
//IP정보 수정
parent::modify($entity, $formDatas);
}
//서버파트관련 작업
public function setServerPart(ServerPartEntity $serverPartEntity): void
public function attachToServerPart(ServerPartEntity $serverPartEntity): IPEntity
{
$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__ . ":에서 오류발생: IP상태가 설정되지 않았습니다.");
}
//IP정보가져오기
//IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof IPEntity) {
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 IP정보를 찾을수없습니다.");
if ($entity instanceof IPEntity) {
if ($entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception(__METHOD__ . ":에서 오류발생: {$entity->getTitle()}는 사용중입니다.");
}
$entity = parent::modify($entity, $formDatas);
}
if ($entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception(__METHOD__ . ":에서 오류발생: {$entity->getIP()}는 사용중인 IP입니다.");
}
//IP정보 수정
parent::modify($entity, $formDatas);
return $entity;
}
public function unsetServerPart(ServerPartEntity $serverPartEntity): void
public function detachFromServerPart(ServerPartEntity $serverPartEntity): 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'];
if (!array_key_exists('status', $formDatas)) {
throw new \Exception(__METHOD__ . ":에서 오류발생: IP상태가 설정되지 않았습니다.");
}
$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정보 수정
parent::modify($entity, $formDatas);
return parent::modify($entity, $formDatas);
}
}

View File

@ -4,11 +4,11 @@ namespace App\Services\Part;
use App\Entities\Equipment\ServerPartEntity;
use App\Helpers\CommonHelper;
use App\Interfaces\Equipment\ServerPartInterface;
use App\Interfaces\Part\PartInterface;
use App\Models\CommonModel;
use App\Services\CommonService;
abstract class PartService extends CommonService implements ServerPartInterface
abstract class PartService extends CommonService implements PartInterface
{
protected function __construct(CommonModel $model, CommonHelper $helper)
{
@ -17,7 +17,7 @@ abstract class PartService extends CommonService implements ServerPartInterface
}
//서버파트관련 작업
public function setServerPart(ServerPartEntity $serverPartEntity): void
public function attachToServerPart(ServerPartEntity $serverPartEntity): mixed
{
//부품정보가져오기
$entity = $this->getEntity($serverPartEntity->getPartUID());
@ -25,12 +25,12 @@ abstract class PartService extends CommonService implements ServerPartInterface
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다.");
}
//부품정보에 서버정보 설정 및 서비스,고객정보 정의
if ($entity->getStock() < $serverPartEntity->getCnt()) {
if ($entity->getStock() < $serverPartEntity->getCnt()) {
throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
}
parent::modify($entity, ['stock' => $entity->getStock() - $serverPartEntity->getCnt()]);
return parent::modify($entity, ['stock' => $entity->getStock() - $serverPartEntity->getCnt()]);
}
public function unsetServerPart(ServerPartEntity $serverPartEntity): void
public function detachFromServerPart(ServerPartEntity $serverPartEntity): mixed
{
//부품정보가져오기
$entity = $this->getEntity($serverPartEntity->getPartUID());
@ -41,6 +41,6 @@ abstract class PartService extends CommonService implements ServerPartInterface
if ($entity->getStock() < $serverPartEntity->getCnt()) {
throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
}
parent::modify($entity, ['stock' => $entity->getStock() + $serverPartEntity->getCnt()]);
return parent::modify($entity, ['stock' => $entity->getStock() + $serverPartEntity->getCnt()]);
}
}

View File

@ -6,12 +6,13 @@ use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\SWITCHEntity;
use App\Helpers\Part\SWITCHHelper;
use App\Interfaces\Part\SWITCHInterface;
use App\Models\Part\SWITCHModel;
use App\Services\Customer\ServiceService;
use App\Services\Equipment\ServerService;
use App\Services\Part\PartService;
class SWITCHService extends PartService
class SWITCHService extends PartService implements SWITCHInterface
{
private ?ServiceService $_serviceService = null;
private ?ServerService $_serverService = null;
@ -90,7 +91,7 @@ class SWITCHService extends PartService
parent::setOrderBy($field, $value);
}
//서버관련 작업
public function setServer(ServerEntity $serverEntity): void
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): void
{
$formDatas = [];
$formDatas['clientinfo_uid'] = $serverEntity->getClientInfoUID();
@ -100,34 +101,36 @@ class SWITCHService extends PartService
if (!array_key_exists('status', $formDatas)) {
throw new \Exception(__METHOD__ . ":에서 오류발생: Switch상태가 설정되지 않았습니다.");
}
//Switch정보에서 해당하는 Switch가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity(['code' => $serverEntity->getSwitch()]);
//Switch정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity(['code' => $serverEntity->getCode()]);
if ($entity instanceof SWITCHEntity) {
if ($entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception(__METHOD__ . ":에서 오류발생: {$serverEntity->getSwitch()}는 사용중인 Switch입니다.");
throw new \Exception(__METHOD__ . ":에서 오류발생: {$serverEntity->getTitle()}는 사용중입니다.");
}
$entity = parent::modify($entity, $formDatas);
}
}
public function unsetServer(ServerEntity $serverEntity): void
public function detachFromServer(ServerEntity $serverEntity): void
{
$formDatas = [];
$formDatas['clientinfo_uid'] = null;
$formDatas['serviceinfo_uid'] = null;
$formDatas['serverinfo_uid'] = null;
$formDatas['old_clientinfo_uid'] = $serverEntity->getClientInfoUID() ?? null;
$formDatas['status'] = STATUS['AVAILABLE'];
$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(['code' => $serverEntity->getSwitch()]);
if ($entity instanceof SWITCHEntity) {
$entity = parent::modify($entity, $formDatas);
//Switch정보가져오기
$entity = $this->getEntity(['code' => $serverEntity->getCode()]);
if (!$entity instanceof SWITCHEntity) {
throw new \Exception("{$serverEntity->getIP()}에 해당하는 IP정보를 찾을수없습니다.");
}
//Switch정보 수정
parent::modify($entity, $formDatas);
}
//서버파트관련 작업
public function setServerPart(ServerPartEntity $serverPartEntity): void
public function attachToServerPart(ServerPartEntity $serverPartEntity): SWITCHEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
@ -135,32 +138,34 @@ class SWITCHService extends PartService
$formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID();
$formDatas['status'] = STATUS['OCCUPIED'];
if (!array_key_exists('status', $formDatas)) {
throw new \Exception(__METHOD__ . "에서 오류발생: SWITCH상태가 설정되지 않았습니다.");
throw new \Exception(__METHOD__ . ":에서 오류발생: Switch상태가 설정되지 않았습니다.");
}
//SWITCH정보가져오기
//SWITCH정보에서 해당하는 SWITCH가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof SWITCHEntity) {
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 SWITCH정보를 찾을수없습니다.");
if ($entity instanceof SWITCHEntity) {
if ($entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception(__METHOD__ . ":에서 오류발생: {$entity->getTitle()}는 사용중입니다.");
}
$entity = parent::modify($entity, $formDatas);
}
//SWITCH정보 수정
parent::modify($entity, $formDatas);
return $entity;
}
public function unsetServerPart(ServerPartEntity $serverPartEntity): void
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상태가 설정되지 않았습니다.");
throw new \Exception(__METHOD__ . ":에서 오류발생: Switch상태가 설정되지 않았습니다.");
}
//SWITCH정보가져오기
//Switch정보가져와서 있으면 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof SWITCHEntity) {
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 SWITCH정보를 찾을수없습니다.");
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 Switch정보를 찾을수없습니다.");
}
//SWITCH정보 수정
parent::modify($entity, $formDatas);
return $entity;
}
}

View File

@ -14,12 +14,14 @@ use App\Services\CommonService;
use App\Services\Customer\AccountService;
use App\Services\Customer\ServiceService;
use App\Services\Equipment\ServerPartService;
use App\Services\Equipment\ServerService;
use DateTimeImmutable;
use DateTimeZone;
class PaymentService extends CommonService implements PaymentInterface
{
private ?ServiceService $_serviceService = null;
private ?ServerService $_serverService = null;
private ?ServerPartService $_serverPartService = null;
private ?AccountService $_accountService = null;
public function __construct()
@ -83,6 +85,13 @@ class PaymentService extends CommonService implements PaymentInterface
}
return $this->_serviceService;
}
public function getServerService(): ServerService
{
if (!$this->_serverService) {
$this->_serverService = new ServerService();
}
return $this->_serverService;
}
final public function getServerPartService(): ServerPartService
{
if (!$this->_serverPartService) {
@ -159,7 +168,7 @@ class PaymentService extends CommonService implements PaymentInterface
}
//서버파트(일회성과금)
final public function createServerPart(ServerPartEntity $serverPartEntity): PaymentEntity
final public function createForServerPart(ServerPartEntity $serverPartEntity, int $amount): PaymentEntity
{
$formDatas = [];
$formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
@ -174,7 +183,7 @@ class PaymentService extends CommonService implements PaymentInterface
$formDatas['billing_at'] = date("Y-m-d");
return parent::create($formDatas);
}
final public function modifyServerPart(ServerPartEntity $serverPartEntity): PaymentEntity
final public function updateForServerPart(ServerPartEntity $serverPartEntity): PaymentEntity
{
if ($serverPartEntity->getPaymentUID() === null) {
throw new \Exception(__METHOD__ . "에서 오류발생:일회성서비스정보에 결제정보가 정의되지 않았습니다.");
@ -223,8 +232,9 @@ class PaymentService extends CommonService implements PaymentInterface
];
}
if (!array_key_exists($serviceEntity->getPK(), $rows[$clientEntity->getPK()]['services'])) {
$serverEntity = $this->getEntity($serviceEntity->getServerInfoUID());
$serverEntity = $this->getServerService()->getEntity($serviceEntity->getServerInfoUID());
if (!$serverEntity instanceof ServerEntity) {
dd($serverEntity);
throw new \Exception("[{$serviceEntity->getServerInfoUID()}]에 대한 서버정보를 찾을 수 없습니다.");
}
$rows[$clientEntity->getPK()]['services'][$serviceEntity->getPK()] = [