243 lines
8.2 KiB
PHP
243 lines
8.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Equipment;
|
|
|
|
use App\Entities\Customer\ServiceEntity;
|
|
use App\Entities\Equipment\ServerEntity;
|
|
use App\Models\Equipment\ServerModel;
|
|
use App\Services\Equipment\EquipmentService;
|
|
|
|
class ServerService extends EquipmentService
|
|
{
|
|
private ?ServerPartService $_serverPartService = null;
|
|
private ?IPService $_ipService = null;
|
|
private ?CSService $_csService = null;
|
|
public function __construct()
|
|
{
|
|
parent::__construct(new ServerModel());
|
|
$this->addClassName('Server');
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
"code",
|
|
"type",
|
|
"title",
|
|
"price",
|
|
"amount",
|
|
"manufactur_at",
|
|
"format_at",
|
|
"status",
|
|
"partinfo_uid_CPU",
|
|
"partinfo_uid_CPU_cnt",
|
|
"partinfo_uid_RAM",
|
|
"partinfo_uid_RAM_cnt",
|
|
"partinfo_uid_DISK",
|
|
"partinfo_uid_DISK_cnt",
|
|
"partinfo_uid_DISK_extra",
|
|
"partinfo_uid_OS",
|
|
"partinfo_uid_OS_cnt",
|
|
"partinfo_uid_SOFTWARE",
|
|
"partinfo_uid_SOFTWARE_cnt",
|
|
"ipinfo_uid",
|
|
"csinfo_uid",
|
|
];
|
|
}
|
|
public function getFormFilters(): array
|
|
{
|
|
return [
|
|
"clientinfo_uid",
|
|
"serviceinfo_uid",
|
|
"type",
|
|
"title",
|
|
"partinfo_uid_CPU",
|
|
"partinfo_uid_RAM",
|
|
"partinfo_uid_DISK",
|
|
"partinfo_uid_DISK_extra",
|
|
"partinfo_uid_OS",
|
|
"partinfo_uid_SOFTWARE",
|
|
"ipinfo_uid",
|
|
"csinfo_uid",
|
|
"status"
|
|
];
|
|
}
|
|
public function getIndexFields(): array
|
|
{
|
|
return [
|
|
'clientinfo_uid',
|
|
'serviceinfo_uid',
|
|
"type",
|
|
'title',
|
|
'price',
|
|
'amount',
|
|
'manufactur_at',
|
|
"format_at",
|
|
'status',
|
|
];
|
|
}
|
|
public function getIndexFilters(): array
|
|
{
|
|
return [
|
|
'clientinfo_uid',
|
|
'serviceinfo_uid',
|
|
'type',
|
|
'status'
|
|
];
|
|
}
|
|
public function getBatchjobFields(): array
|
|
{
|
|
return ['clientinfo_uid', 'status'];
|
|
}
|
|
final public function getServerPartService(): ServerPartService
|
|
{
|
|
if (!$this->_serverPartService) {
|
|
$this->_serverPartService = new ServerPartService();
|
|
}
|
|
return $this->_serverPartService;
|
|
}
|
|
final public function getIPService(): IPService
|
|
{
|
|
if (!$this->_ipService) {
|
|
$this->_ipService = new IPService();
|
|
}
|
|
return $this->_ipService;
|
|
}
|
|
final public function getCSService(): CSService
|
|
{
|
|
if (!$this->_csService) {
|
|
$this->_csService = new CSService();
|
|
}
|
|
return $this->_csService;
|
|
}
|
|
//partEntity 정보 추가
|
|
protected function getEntity_process(mixed $entity): ServerEntity
|
|
{
|
|
//부품연결정보 정의
|
|
foreach (SERVER['PARTTYPES'] as $partType) {
|
|
$serverPartEntity = $this->getServerPartService()->getEntity(['serverinfo_uid' => $entity->getPK(), 'type' => $partType]);
|
|
if ($serverPartEntity) {
|
|
$entity->addServerPartEntity($partType, $serverPartEntity);
|
|
}
|
|
}
|
|
//IP정보 정의
|
|
foreach ($this->getIPService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $ipEntity) {
|
|
$entity->addIPEntity($ipEntity);
|
|
}
|
|
//CS정보 정의
|
|
foreach ($this->getCSService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $csEntity) {
|
|
$entity->addCSEntity($csEntity);
|
|
}
|
|
return $entity;
|
|
}
|
|
//기본 기능부분
|
|
public function getFormOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case 'partinfo_uid_CPU':
|
|
$options = $this->getServerPartService()->getFormOption('partinfo_uid_CPU');
|
|
break;
|
|
case 'partinfo_uid_RAM':
|
|
$options = $this->getServerPartService()->getFormOption('partinfo_uid_RAM');
|
|
break;
|
|
case 'partinfo_uid_DISK':
|
|
$options = $this->getServerPartService()->getFormOption('partinfo_uid_DISK');
|
|
break;
|
|
case 'partinfo_uid_OS':
|
|
$options = $this->getServerPartService()->getFormOption('partinfo_uid_OS');
|
|
break;
|
|
case 'partinfo_uid_DB':
|
|
$options = $this->getServerPartService()->getFormOption('partinfo_uid_DB');
|
|
break;
|
|
case 'partinfo_uid_SOFTWARE':
|
|
$options = $this->getServerPartService()->getFormOption('partinfo_uid_SOFTWARE');
|
|
break;
|
|
case 'ipinfo_uid': //수정때문에 전체가 필요
|
|
$options = $this->getIPService()->getEntities();
|
|
break;
|
|
case 'csinfo_uid': //수정때문에 전체가 필요
|
|
$options = $this->getCSService()->getEntities();
|
|
break;
|
|
default:
|
|
$options = parent::getFormOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
//FieldForm관련용
|
|
//create용 장비코드 마지막번호 가져오기
|
|
final public function getLastestCode(string $format, int $default): string
|
|
{
|
|
return $this->getModel()->getLastestCode($format, $default);
|
|
}
|
|
final public function codeCheck(array $formDatas)
|
|
{
|
|
//코드 패턴체크
|
|
$pattern = env("Server.Prefix.code.pattern", false);
|
|
if (!$pattern) {
|
|
throw new \Exception(__METHOD__ . "에서 code의 prefix[Server.Prefix.code.pattern]가 정의되지 않았습니다.");
|
|
}
|
|
if (!array_key_exists('code', $formDatas)) {
|
|
throw new \Exception("Server코드가 정의되지 않았습니다");
|
|
}
|
|
if (!preg_match($pattern, $formDatas['code'])) {
|
|
throw new \Exception("Server코드[{$formDatas['code']}의 형식이 맞지않습니다");
|
|
}
|
|
}
|
|
//생성
|
|
public function create(array $formDatas): ServerEntity
|
|
{
|
|
$entity = parent::create($formDatas);
|
|
//ServerPart정보 생성
|
|
foreach (SERVER['PARTTYPES'] as $partType) {
|
|
foreach ($this->getServerPartService()->createByServer($entity, $formDatas) as $serverPartEntity) {
|
|
$entity->addServerPartEntity($serverPartEntity->getType(), $serverPartEntity);
|
|
};
|
|
}
|
|
return $entity;
|
|
}
|
|
//수정
|
|
public function modify(mixed $entity, array $formDatas): ServerEntity
|
|
{
|
|
$entity = parent::modify($entity, $formDatas);
|
|
// ServerPart정보 수정
|
|
foreach ($this->getServerPartService()->modifyByServer($entity, $formDatas) as $serverPartEntity) {
|
|
$entity->addServerPartEntity($serverPartEntity->getType(), $serverPartEntity);
|
|
};
|
|
return $entity;
|
|
}
|
|
//삭제
|
|
public function delete(mixed $entity): ServerEntity
|
|
{
|
|
$entity = parent::delete($entity);
|
|
// ServerPart정보 수정
|
|
foreach ($this->getServerPartService()->deleteByServer($entity) as $serverPartEntity) {
|
|
$entity->addServerPartEntity($serverPartEntity->getType(), $serverPartEntity);
|
|
};
|
|
return $entity;
|
|
}
|
|
//List 검색용
|
|
//OrderBy 처리
|
|
public function setOrderBy(mixed $field = null, mixed $value = null): void
|
|
{
|
|
$this->getModel()->orderBy("code ASC,title ASC");
|
|
parent::setOrderBy($field, $value);
|
|
}
|
|
|
|
public function enableService(ServiceEntity $serviceEntity, ServerEntity $entity): ServerEntity
|
|
{
|
|
$formDatas = [];
|
|
$formDatas["clientinfo_uid"] = $serviceEntity->getClientInfoUID();
|
|
$formDatas["serviceinfo_uid"] = $serviceEntity->getPK();
|
|
$formDatas['status'] = ServerEntity::STATUS_OCCUPIED;
|
|
return parent::modify($entity, $formDatas);
|
|
}
|
|
public function disableService(ServerEntity $entity): ServerEntity
|
|
{
|
|
$formDatas = [];
|
|
$formDatas["clientinfo_uid"] = null;
|
|
$formDatas["serviceinfo_uid"] = null;
|
|
$formDatas['status'] = ServerEntity::STATUS_AVAILABLE;
|
|
return parent::modify($entity, $formDatas);
|
|
}
|
|
}
|