207 lines
6.5 KiB
PHP
207 lines
6.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Equipment;
|
|
|
|
use App\Entities\Equipment\ServerEntity;
|
|
use App\Models\Equipment\ServerModel;
|
|
use App\Models\Equipment\ServerPartModel;
|
|
use App\Services\Equipment\EquipmentService;
|
|
|
|
class ServerService extends EquipmentService
|
|
{
|
|
private ?ServerPartService $_serverPartService = null;
|
|
public function __construct()
|
|
{
|
|
parent::__construct(new ServerModel());
|
|
$this->addClassName('Server');
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
'fields' => [
|
|
"code",
|
|
"type",
|
|
"title",
|
|
"CPU",
|
|
"RAM",
|
|
"DISK",
|
|
"OS",
|
|
"ipinfo_uid",
|
|
"price",
|
|
"amount",
|
|
"manufactur_at",
|
|
"format_at",
|
|
"status",
|
|
],
|
|
'filters' => [
|
|
"clientinfo_uid",
|
|
"serviceinfo_uid",
|
|
"type",
|
|
"title",
|
|
"CPU",
|
|
"RAM",
|
|
"DISK",
|
|
"OS",
|
|
"ipinfo_uid",
|
|
"status"
|
|
],
|
|
];
|
|
}
|
|
public function getViewFields(): array
|
|
{
|
|
return [
|
|
'fields' => [
|
|
'clientinfo_uid',
|
|
'serviceinfo_uid',
|
|
"type",
|
|
'title',
|
|
'price',
|
|
'amount',
|
|
"serverpartinfo",
|
|
"ipinfo_uid",
|
|
"csinfo_uid",
|
|
'manufactur_at',
|
|
"format_at",
|
|
'status'
|
|
],
|
|
'filters' => [
|
|
'clientinfo_uid',
|
|
'serviceinfo_uid',
|
|
'type',
|
|
"ipinfo_uid",
|
|
"csinfo_uid",
|
|
'status'
|
|
],
|
|
];
|
|
}
|
|
public function getIndexFields(): array
|
|
{
|
|
return [
|
|
'fields' => [
|
|
'clientinfo_uid',
|
|
'serviceinfo_uid',
|
|
"type",
|
|
'title',
|
|
'price',
|
|
'amount',
|
|
"serverpartinfo",
|
|
"ipinfo_uid",
|
|
"csinfo_uid",
|
|
'manufactur_at',
|
|
"format_at",
|
|
'status'
|
|
],
|
|
'filters' => [
|
|
'clientinfo_uid',
|
|
'serviceinfo_uid',
|
|
'type',
|
|
"ipinfo_uid",
|
|
"csinfo_uid",
|
|
'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) {
|
|
$serverPartEnty = $this->getServerPartService()->getEntity(['serverinfo_uid' => $entity->getPK(), 'type' => $partType]);
|
|
if ($serverPartEnty) {
|
|
$entity->setServerPartEntity($partType, $serverPartEnty);
|
|
}
|
|
}
|
|
//서버 IP정보 정의
|
|
$entity->setIPEntities($this->getIPService()->getEntities(['serverinfo_uid' => $entity->getPK()]));
|
|
//서버 CS정보 정의
|
|
$entity->setCSEntities($this->getCSService()->getEntities(['serverinfo_uid' => $entity->getPK()]));
|
|
return $entity;
|
|
}
|
|
//기본 기능부분
|
|
public function getFormFieldOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case 'CPU':
|
|
$options = $this->getServerPartService()->getFormFieldOption('partinfo_CPU_uid');
|
|
break;
|
|
case 'RAM':
|
|
$options = $this->getServerPartService()->getFormFieldOption('partinfo_RAM_uid');
|
|
break;
|
|
case 'DISK':
|
|
$options = $this->getServerPartService()->getFormFieldOption('partinfo_DISK_uid');
|
|
break;
|
|
case 'OS':
|
|
$options = $this->getServerPartService()->getFormFieldOption('partinfo_OS_uid');
|
|
break;
|
|
case 'DB':
|
|
$options = $this->getServerPartService()->getFormFieldOption('partinfo_DB_uid');
|
|
break;
|
|
case 'SOFTWARE':
|
|
$options = $this->getServerPartService()->getFormFieldOption('partinfo_SOFTWARE_uid');
|
|
break;
|
|
case 'ipinfo_uid': //수정때문에 전체가 필요
|
|
$options = $this->getIPService()->getEntities();
|
|
break;
|
|
case 'csinfo_uid': //수정때문에 전체가 필요
|
|
$options = $this->getCSService()->getEntities();
|
|
break;
|
|
default:
|
|
$options = parent::getFormFieldOption($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']}의 형식이 맞지않습니다");
|
|
}
|
|
}
|
|
//List 검색용
|
|
//OrderBy 처리
|
|
public function setOrderBy(mixed $field = null, mixed $value = null): void
|
|
{
|
|
$this->getModel()->orderBy("code ASC,title ASC");
|
|
parent::setOrderBy($field, $value);
|
|
}
|
|
}
|