408 lines
16 KiB
PHP
408 lines
16 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Equipment;
|
|
|
|
use App\Entities\Equipment\ServerEntity;
|
|
use App\Entities\Equipment\ServerPartEntity;
|
|
use App\Entities\Part\CPUEntity;
|
|
use App\Entities\Part\DISKEntity;
|
|
use App\Entities\Part\RAMEntity;
|
|
use App\Entities\PaymentEntity;
|
|
use App\Helpers\Equipment\ServerPartHelper;
|
|
use App\Models\Equipment\ServerPartModel;
|
|
use App\Services\Customer\ServiceService;
|
|
use App\Services\Equipment\EquipmentService;
|
|
use App\Services\Equipment\ServerService;
|
|
use App\Services\Part\CPUService;
|
|
use App\Services\Part\CSService;
|
|
use App\Services\Part\DISKService;
|
|
use App\Services\Part\IPService;
|
|
use App\Services\Part\OSService;
|
|
use App\Services\Part\RAMService;
|
|
use App\Services\Part\SOFTWAREService;
|
|
use App\Services\Part\SWITCHService;
|
|
use App\Services\PaymentService;
|
|
|
|
class ServerPartService extends EquipmentService
|
|
{
|
|
private ?ServiceService $_serviceService = null;
|
|
private ?ServerService $_serverService = null;
|
|
private ?PaymentService $_paymentService = null;
|
|
private ?CPUService $_cpuService = null;
|
|
private ?RAMService $_ramService = null;
|
|
private ?DISKService $_diskService = null;
|
|
private ?OSService $_osService = null;
|
|
private ?SOFTWAREService $_softwareService = null;
|
|
private ?SWITCHService $_switchService = null;
|
|
private ?IPService $_ipService = null;
|
|
private ?CSService $_csService = null;
|
|
|
|
private $_partServices = [];
|
|
public function __construct()
|
|
{
|
|
parent::__construct(new ServerPartModel(), new ServerPartHelper());
|
|
$this->addClassName('ServerPart');
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
"serverinfo_uid",
|
|
"type",
|
|
"billing",
|
|
"part_uid",
|
|
"title",
|
|
"cnt",
|
|
"extra",
|
|
"amount",
|
|
];
|
|
}
|
|
public function getFormFilters(): array
|
|
{
|
|
return [
|
|
"serverinfo_uid",
|
|
"type",
|
|
"part_uid",
|
|
"billing",
|
|
];
|
|
}
|
|
|
|
public function getIndexFields(): array
|
|
{
|
|
return [
|
|
"serverinfo_uid",
|
|
"type",
|
|
"title",
|
|
"billing",
|
|
"amount",
|
|
"cnt",
|
|
"extra",
|
|
];
|
|
}
|
|
public function getIndexFilters(): array
|
|
{
|
|
return [
|
|
"serverinfo_uid",
|
|
"type",
|
|
"part_uid",
|
|
"billing",
|
|
];
|
|
}
|
|
public function getBatchjobFields(): array
|
|
{
|
|
return ['billing', 'type'];
|
|
}
|
|
final public function getServiceService(): ServiceService
|
|
{
|
|
if (!$this->_serviceService) {
|
|
$this->_serviceService = new ServiceService();
|
|
}
|
|
return $this->_serviceService;
|
|
}
|
|
final public function getServerService(): ServerService
|
|
{
|
|
if (!$this->_serverService) {
|
|
$this->_serverService = new ServerService();
|
|
}
|
|
return $this->_serverService;
|
|
}
|
|
final public function getPaymentService(): PaymentService
|
|
{
|
|
if (!$this->_paymentService) {
|
|
$this->_paymentService = new PaymentService();
|
|
}
|
|
return $this->_paymentService;
|
|
}
|
|
final public function getCPUService(): CPUService
|
|
{
|
|
if (!$this->_cpuService) {
|
|
$this->_cpuService = new CPUService();
|
|
}
|
|
return $this->_cpuService;
|
|
}
|
|
final public function getRAMService(): RAMService
|
|
{
|
|
if (!$this->_ramService) {
|
|
$this->_ramService = new RAMService();
|
|
}
|
|
return $this->_ramService;
|
|
}
|
|
final public function getDISKService(): DISKService
|
|
{
|
|
if (!$this->_diskService) {
|
|
$this->_diskService = new DISKService();
|
|
}
|
|
return $this->_diskService;
|
|
}
|
|
final public function getOSService(): OSService
|
|
{
|
|
if (!$this->_osService) {
|
|
$this->_osService = new OSService();
|
|
}
|
|
return $this->_osService;
|
|
}
|
|
final public function getSOFTWAREService(): SOFTWAREService
|
|
{
|
|
if (!$this->_softwareService) {
|
|
$this->_softwareService = new SOFTWAREService();
|
|
}
|
|
return $this->_softwareService;
|
|
}
|
|
final public function getCSService(): CSService
|
|
{
|
|
if (!$this->_csService) {
|
|
$this->_csService = new CSService();
|
|
}
|
|
return $this->_csService;
|
|
}
|
|
|
|
final public function getIPService(): IPService
|
|
{
|
|
if (!$this->_ipService) {
|
|
$this->_ipService = new IPService();
|
|
}
|
|
return $this->_ipService;
|
|
}
|
|
|
|
final public function getSWITCHService(): SWITCHService
|
|
{
|
|
if (!$this->_switchService) {
|
|
$this->_switchService = new SWITCHService();
|
|
}
|
|
return $this->_switchService;
|
|
}
|
|
final public function getPartService(string $type)
|
|
{
|
|
switch ($type) {
|
|
case 'CPU':
|
|
$service = $this->getCPUService();
|
|
break;
|
|
case 'RAM':
|
|
$service = $this->getRAMService();
|
|
break;
|
|
case 'DISK':
|
|
$service = $this->getDISKService();
|
|
break;
|
|
case 'OS':
|
|
$service = $this->getOSService();
|
|
break;
|
|
case 'SOFTWARE':
|
|
$service = $this->getSOFTWAREService();
|
|
break;
|
|
case 'IP':
|
|
$service = $this->getIPService();
|
|
break;
|
|
case 'CS':
|
|
$service = $this->getCSService();
|
|
break;
|
|
case 'SWITCH':
|
|
$service = $this->getSWITCHService();
|
|
break;
|
|
default:
|
|
throw new \Exception(__METHOD__ . "에서 오류발생: {$type} 지정되지 않은 형식입니다.");
|
|
// break;
|
|
}
|
|
return $service;
|
|
}
|
|
//서버 코드의 Type에 따라 서버파트 등록
|
|
private function setDefaultPartByServer(string $parttype, array $formDatas): array
|
|
{
|
|
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;
|
|
}
|
|
//서버정보 설정
|
|
final public function setServer(string $action, ServerEntity $serverEntity, array $serverFormDatas): void
|
|
{
|
|
switch ($action) {
|
|
case 'create':
|
|
// 각 변수에 배정
|
|
$codes = str_split($serverEntity->getCode());
|
|
// $server_ year = $codes[0].$codes[1]; // 1,2번째(ex: 21-> 21년)
|
|
// $server_quarter = $codes[2]; // 3번째(ex: 1-> 1분기)
|
|
// $server_brand = $codes[3]; // 4번째(ex: 6-> HP DL360 Gen6)
|
|
$server_type = strtoupper($codes[4]) . "TYPE"; // 5번째(ex: A-> ATYPE Server)
|
|
foreach (SERVERPART['SERVER_PARTTYPES'] as $parttype) {
|
|
foreach (SERVERPART[$parttype][$server_type] as $serverpart) {
|
|
$formDatas = [];
|
|
$formDatas['serverinfo_uid'] = $serverEntity->getPK();
|
|
$formDatas["part_uid"] = $serverpart["UID"];
|
|
$formDatas['billing'] = PAYMENT['BILLING']['BASE'];
|
|
$formDatas['type'] = $parttype;
|
|
$formDatas['cnt'] = $serverpart["CNT"];
|
|
$formDatas['extra'] = $serverpart["EXTRA"];
|
|
$formDatas = $this->setDefaultPartByServer($parttype, $formDatas);
|
|
$this->create($formDatas);
|
|
}
|
|
}
|
|
break;
|
|
case 'delete':
|
|
//서버정보에 해당하는 ServerPart정보 모두 회수처리 후 서버정보에 기본 ServerPart를 다시 등록해준다.
|
|
foreach ($this->getEntities(['serverinfo_uid' => $serverEntity->getPK()]) as $entity) {
|
|
//Type에 따른 부품서비스 정의
|
|
$this->getPartService($entity->getType())->setServerPart('delete', $entity, $entity, []);
|
|
//서버연결정보 식제
|
|
parent::delete($entity);
|
|
}
|
|
//서버정보에 기본 ServerPart를 다시 등록해준다.
|
|
$this->setServer('create', $serverEntity, []);
|
|
break;
|
|
default:
|
|
throw new \Exception(__METHOD__ . "에서 오류발생:{$action}은 정의되지 않은 작업입니다.");
|
|
// break;
|
|
}
|
|
}
|
|
//partEntity 정보 추가
|
|
protected function getEntity_process(mixed $entity): ServerPartEntity
|
|
{
|
|
if (!$entity instanceof ServerPartEntity) {
|
|
throw new \Exception(__METHOD__ . "에서 형식오류:ServicePartEntity만 허용됩니다.");
|
|
}
|
|
//각 파트서비스 정의
|
|
$entity->setPartEntity($this->getPartService($entity->getType())->getEntity($entity->getPartUID()));
|
|
//결제정보 정의
|
|
if ($entity->getPaymentUID()) {
|
|
$paymentEntity = $this->getPaymentService()->getEntity($entity->getPaymentUID());
|
|
if ($paymentEntity instanceof PaymentEntity) {
|
|
$entity->setPaymentEntity($paymentEntity);
|
|
}
|
|
}
|
|
return $entity;
|
|
}
|
|
//기본 기능부분
|
|
// FieldForm관련용
|
|
public function getFormOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case 'serverinfo_uid':
|
|
$options = $this->getServerService()->getEntities();
|
|
break;
|
|
case 'part_uid':
|
|
$partOptions = [];
|
|
foreach (SERVERPART['ALL_PARTTYPES'] as $partType) {
|
|
$partOptions[$partType] = $this->getPartService($partType)->getEntities();
|
|
}
|
|
$options = $partOptions;
|
|
// dd($options);
|
|
break;
|
|
default:
|
|
$options = parent::getFormOption($field, $options);
|
|
break;
|
|
}
|
|
if (!is_array($options)) {
|
|
throw new \Exception(__FUNCTION__ . "에서 {$field}의 options 값이 array가 아닙니다.\n" . var_export($options, true));
|
|
}
|
|
return $options;
|
|
}
|
|
//부품연결정보생성
|
|
public function create(array $formDatas): ServerPartEntity
|
|
{
|
|
//서버정보가져오기
|
|
if (!array_key_exists('serverinfo_uid', $formDatas)) {
|
|
throw new \Exception("서버 정보가 지정되지 않았습니다.");
|
|
}
|
|
$serverEntity = $this->getServerService()->getEntity($formDatas['serverinfo_uid']);
|
|
if (!$serverEntity instanceof ServerEntity) {
|
|
throw new \Exception("서버 정보가 지정되지 않았습니다.");
|
|
}
|
|
//서비스정의확인(기본은 제외)
|
|
if ($formDatas['billing'] !== PAYMENT['BILLING']['BASE'] && $serverEntity->getServiceInfoUID() === null) {
|
|
throw new \Exception(__METHOD__ . "에서 오류발생:{월,일회성 과금용은 서비스가 지정되어야 작업이 가능합니다.");
|
|
}
|
|
//생성작업
|
|
$formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
|
|
$formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
|
|
$formDatas["serverinfo_uid"] = $serverEntity->getPK();
|
|
$entity = parent::create($formDatas);
|
|
//후처리작업
|
|
//Type에 따른 부품서비스 정의
|
|
$this->getPartService($entity->getType())->setServerPart('create', $entity, $entity, $formDatas);
|
|
//서비스 및 결제정보 처리
|
|
switch ($entity->getBilling()) {
|
|
case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리
|
|
if ($entity->getServiceInfoUID() === null) {
|
|
throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다.");
|
|
}
|
|
//서비스 금액만 재계산변경
|
|
$this->getServiceService()->setAmount($this->getServiceService()->getEntity($entity->getServiceInfoUID()));
|
|
break;
|
|
case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리
|
|
$entity->setPaymentEntity($this->getPaymentService()->setServerPart('create', $entity, $formDatas));
|
|
//결제정보PK정의
|
|
$entity = parent::modify($entity, ['payment_uid' => $entity->getPaymentEntity()->getPK()]);
|
|
break;
|
|
case PAYMENT['BILLING']['BASE']: //기본처리
|
|
//아무처리 않함
|
|
break;
|
|
default:
|
|
throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다.");
|
|
// break;
|
|
}
|
|
return $entity;
|
|
}
|
|
//수정
|
|
public function modify(mixed $entity, array $formDatas): ServerPartEntity
|
|
{
|
|
//서버정보가져오기
|
|
if (!array_key_exists('serverinfo_uid', $formDatas)) {
|
|
throw new \Exception("서버 정보가 지정되지 않았습니다.");
|
|
}
|
|
$serverEntity = $this->getServerService()->getEntity($formDatas['serverinfo_uid']);
|
|
if (!$serverEntity instanceof ServerEntity) {
|
|
throw new \Exception("서버 정보가 지정되지 않았습니다.");
|
|
}
|
|
//수정전 정보
|
|
$oldEntity = clone $entity; //반드시 clone 할것
|
|
//서버연결정보 수정
|
|
$formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
|
|
$formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
|
|
$formDatas["serverinfo_uid"] = $serverEntity->getPK();
|
|
$entity = parent::modify($entity, $formDatas);
|
|
//후처리작업
|
|
//Type에 따른 부품서비스 정의
|
|
$this->getPartService($entity->getType())->setServerPart('modify', $oldEntity, $entity, $formDatas);
|
|
//서비스 및 결제정보 처리
|
|
switch ($entity->getBilling()) {
|
|
case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리
|
|
if ($entity->getServiceInfoUID() !== null) { //서비스가 정의되어 있으면
|
|
//서비스 금액만 재계산변경
|
|
$this->getServiceService()->setAmount($this->getServiceService()->getEntity($entity->getServiceInfoUID()));
|
|
}
|
|
break;
|
|
case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리
|
|
if ($entity->getPaymentUID() !== null) { //결제정보가 정의되어 있으면
|
|
$entity->setPaymentEntity($this->getPaymentService()->setServerPart('modify', $entity, $formDatas));
|
|
}
|
|
break;
|
|
case PAYMENT['BILLING']['BASE']: //기본처리
|
|
//아무처리 않함
|
|
break;
|
|
default:
|
|
throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다.");
|
|
// break;
|
|
}
|
|
return $entity;
|
|
}
|
|
//삭제
|
|
public function delete(mixed $entity): ServerPartEntity
|
|
{
|
|
//Type에 따른 부품서비스 정의
|
|
$this->getPartService($entity->getType())->setServerPart('delete', $entity, $entity, []);
|
|
//삭제시는 월비용 서비스만 처리
|
|
if ($entity->getBilling() === PAYMENT['BILLING']['MONTH']) {
|
|
//서비스가 정의되어 있으면 실행
|
|
if ($entity->getServiceInfoUID() !== null) {
|
|
$serviceEntity = $this->getServiceService()->getEntity($entity->getServiceInfoUID());
|
|
$entity = $this->getServiceService()->setAmount($serviceEntity);
|
|
}
|
|
}
|
|
return parent::delete($entity);
|
|
}
|
|
}
|