156 lines
5.3 KiB
PHP
156 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Part;
|
|
|
|
use App\Entities\Equipment\ServerPartEntity;
|
|
use App\Entities\Part\CSEntity;
|
|
use App\Helpers\Part\CSHelper;
|
|
use App\Interfaces\Equipment\ServerPartInterface;
|
|
use App\Models\Part\CSModel;
|
|
use App\Services\Customer\ClientService;
|
|
use App\Services\Customer\ServiceService;
|
|
use App\Services\Equipment\ServerService;
|
|
|
|
class CSService extends PartService implements ServerPartInterface
|
|
{
|
|
private ?ClientService $_clientService = null;
|
|
private ?ServiceService $_serviceService = null;
|
|
private ?ServerService $_serverService = null;
|
|
public function __construct()
|
|
{
|
|
parent::__construct(new CSModel(), new CSHelper());
|
|
$this->addClassName('CS');
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
"serverinfo_uid",
|
|
"type",
|
|
"ip",
|
|
"accountid",
|
|
"domain",
|
|
"price",
|
|
"status",
|
|
];
|
|
}
|
|
public function getFormFilters(): array
|
|
{
|
|
return [
|
|
"clientinfo_uid",
|
|
'serverinfo_uid',
|
|
'type',
|
|
'status'
|
|
];
|
|
}
|
|
public function getIndexFields(): array
|
|
{
|
|
return [
|
|
"clientinfo_uid",
|
|
'serverinfo_uid',
|
|
'type',
|
|
'ip',
|
|
'accountid',
|
|
'domain',
|
|
'price',
|
|
'status',
|
|
];
|
|
}
|
|
public function getBatchjobFields(): array
|
|
{
|
|
return ['type', 'status'];
|
|
}
|
|
final public function getClientService(): ClientService
|
|
{
|
|
if (!$this->_clientService) {
|
|
$this->_clientService = new ClientService();
|
|
}
|
|
return $this->_clientService;
|
|
}
|
|
public function getServiceService(): ServiceService
|
|
{
|
|
if (!$this->_serviceService) {
|
|
$this->_serviceService = new ServiceService();
|
|
}
|
|
return $this->_serviceService;
|
|
}
|
|
public function getServerService(): ServerService
|
|
{
|
|
if (!$this->_serverService) {
|
|
$this->_serverService = new ServerService();
|
|
}
|
|
return $this->_serverService;
|
|
}
|
|
//기본 기능부분
|
|
//FieldForm관련용
|
|
public function getFormOption(string $field, $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case 'serviceinfo_uid':
|
|
$options = $this->getServiceService()->getEntities();
|
|
break;
|
|
case 'serverinfo_uid':
|
|
$options = $this->getServerService()->getEntities();
|
|
break;
|
|
default:
|
|
$options = parent::getFormOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
//List 검색용
|
|
//OrderBy 처리
|
|
public function setOrderBy(mixed $field = null, mixed $value = null): void
|
|
{
|
|
$this->getModel()->orderBy('INET_ATON(ip)', 'ASC');
|
|
parent::setOrderBy($field, $value);
|
|
}
|
|
|
|
//서버파트관련 작업
|
|
public function setServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity
|
|
{
|
|
$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정보가져오기
|
|
$entity = $this->getEntity($serverPartEntity->getPartUID());
|
|
if (!$entity instanceof CSEntity) {
|
|
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 CS정보를 찾을수없습니다.");
|
|
}
|
|
//CS정보 수정
|
|
return $serverPartEntity->setPartEntity(parent::modify($entity, $formDatas));
|
|
}
|
|
public function changeServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity
|
|
{
|
|
|
|
//수정 전 부품연결정보관련 정보처리 파트정보가 달라졌을경우 (회수 -> 사용 처리)
|
|
if ($oldServerPartEntity->getPartUID() !== $serverPartEntity->getPartUID()) {
|
|
$this->unsetServerPart($oldServerPartEntity, $serverPartDatas);
|
|
}
|
|
//신규것 사용처리
|
|
return $this->setServerPart($serverPartEntity, $serverPartDatas);
|
|
}
|
|
public function unsetServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity
|
|
{
|
|
$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정보 수정
|
|
return $serverPartEntity->setPartEntity(parent::modify($entity, $formDatas));
|
|
}
|
|
}
|