212 lines
7.5 KiB
PHP
212 lines
7.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 ?PartService $_partService = null;
|
|
private ?IPService $_ipService = null;
|
|
private ?CSService $_csService = null;
|
|
private ?ServerPartModel $_serverPartModel = null;
|
|
const BasePartLists = ['cpu', 'ram', 'disk', 'os'];
|
|
const AddtionalPartLists = ['ram', 'disk', 'db', 'software', 'ip', 'cs'];
|
|
public function __construct()
|
|
{
|
|
parent::__construct(new ServerModel());
|
|
$this->addClassName('Server');
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
'fields' => [
|
|
"code",
|
|
"type",
|
|
"title",
|
|
"partinfo_cpu_uid",
|
|
"partinfo_ram_uid",
|
|
"partinfo_disk_uid",
|
|
"partinfo_os_uid",
|
|
"price",
|
|
"manufactur_at",
|
|
"format_at",
|
|
"status",
|
|
],
|
|
'filters' => [
|
|
"clientinfo_uid",
|
|
"serviceinfo_uid",
|
|
"type",
|
|
"title",
|
|
"partinfo_cpu_uid",
|
|
"partinfo_ram_uid",
|
|
"partinfo_disk_uid",
|
|
"partinfo_os_uid",
|
|
"status"
|
|
],
|
|
];
|
|
}
|
|
public function getIndexFields(): array
|
|
{
|
|
return [
|
|
'fields' => [
|
|
'clientinfo_uid',
|
|
'serviceinfo_uid',
|
|
'partinfo_uid',
|
|
"type",
|
|
'title',
|
|
'price',
|
|
'total_price',
|
|
'manufactur_at',
|
|
"format_at",
|
|
'status'
|
|
],
|
|
'filters' => ['clientinfo_uid', 'serviceinfo_uid', 'type', 'partinfo_uid', 'status'],
|
|
'batchjob_fields' => ['clientinfo_uid', 'partinfo_uid', 'status'],
|
|
'batchjob_buttions' => [
|
|
'batchjob' => '일괄 처리',
|
|
'batchjob_delete' => '일괄 삭제',
|
|
]
|
|
];
|
|
}
|
|
final public function getPartService(): PartService
|
|
{
|
|
if (!$this->_partService) {
|
|
$this->_partService = new PartService();
|
|
}
|
|
return $this->_partService;
|
|
}
|
|
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;
|
|
}
|
|
final public function getServerPartModel(): ServerPartModel
|
|
{
|
|
if (!$this->_serverPartModel) {
|
|
$this->_serverPartModel = new ServerPartModel();
|
|
}
|
|
return $this->_serverPartModel;
|
|
}
|
|
//기본 기능부분
|
|
//FieldForm관련용
|
|
public function getFormFieldOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case 'partinfo_cpu_uid':
|
|
$options = $this->getPartService()->getEntities([
|
|
'type' => 'CPU'
|
|
]);
|
|
break;
|
|
case 'partinfo_ram_uid':
|
|
$options = $this->getPartService()->getEntities([
|
|
'type' => 'RAM'
|
|
]);
|
|
break;
|
|
case 'partinfo_disk_uid':
|
|
$options = $this->getPartService()->getEntities([
|
|
'type' => 'DISK'
|
|
]);
|
|
break;
|
|
case 'partinfo_os_uid':
|
|
$options = $this->getPartService()->getEntities([
|
|
'type' => 'OS'
|
|
]);
|
|
break;
|
|
case 'partinfo_db_uid':
|
|
$options = $this->getPartService()->getEntities([
|
|
'type' => 'DB'
|
|
]);
|
|
break;
|
|
case 'partinfo_software_uid':
|
|
$options = $this->getPartService()->getEntities([
|
|
'type' => 'SOFTWARE'
|
|
]);
|
|
break;
|
|
case 'partinfo_uid': //수정때문에 전체가 필요
|
|
$options = $this->getPartService()->getEntities();
|
|
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;
|
|
}
|
|
//create용 장비코드 마지막번호 가져오기
|
|
final public function getLastestCode(string $format, int $default): string
|
|
{
|
|
return $this->getModel()->getLastestCode($format, $default);
|
|
}
|
|
private function getConvertedFormDatas(array $formDatas): array
|
|
{
|
|
$convertedFormDatas = [];
|
|
$convertedFormDatas['code'] = $formDatas['code'];
|
|
$convertedFormDatas['type'] = $formDatas['type'];
|
|
$convertedFormDatas['title'] = $formDatas['title'];
|
|
$convertedFormDatas['price'] = $formDatas['price'];
|
|
$convertedFormDatas['manufactur_at'] = $formDatas['manufactur_at'];
|
|
if (array_key_exists('format_at', $formDatas) && $formDatas['format_at']) {
|
|
$convertedFormDatas['format_at'] = $formDatas['format_at'];
|
|
}
|
|
$convertedFormDatas['status'] = $formDatas['status'];
|
|
return $convertedFormDatas;
|
|
}
|
|
private function getPartLinkFormDatas(ServerEntity $entity, array $formDatas): array
|
|
{
|
|
$partFormDatas = [];
|
|
$partFormDatas["serverinfo_uid"] = $entity->getPK();
|
|
if ($entity->getServiceInfoUID()) { //서비스정보가 있다면
|
|
$partFormDatas["serviceinfo_uid"] = $entity->getServiceInfoUID();
|
|
}
|
|
$partFormDatas["billing_method"] = PAYMENT['BILLING']['METHOD_MONTH'];
|
|
$partLinkFormDatas = [];
|
|
foreach (self::BasePartLists as $field) {
|
|
$partFormDatas["partinfo_uid"] = $formDatas["partinfo_{$field}_uid"];
|
|
$partFormDatas["cnt"] = array_key_exists("partinfo_{$field}_cnt", $formDatas) ? $formDatas["partinfo_{$field}_cnt"] : 1;
|
|
$partFormDatas["extra"] = array_key_exists("partinfo_{$field}_extra", $formDatas) ? $formDatas["partinfo_{$field}_extra"] : "";
|
|
//part별로 link용 추가
|
|
$partLinkFormDatas[] = $partFormDatas;
|
|
}
|
|
return $partLinkFormDatas;
|
|
}
|
|
|
|
public function create(array $formDatas): ServerEntity
|
|
{
|
|
//입력된 데이터를 기준으로 서버정보 재정의
|
|
$convertedFormDatas = $this->getConvertedFormDatas($formDatas);
|
|
$entity = parent::create($convertedFormDatas);
|
|
//파트정보 가져오기
|
|
$partLinkFormDatas = $this->getPartLinkFormDatas($entity, $formDatas);
|
|
foreach ($partLinkFormDatas as $partLinkFormData) {
|
|
$this->getServerPartModel()->create($partLinkFormData);
|
|
}
|
|
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);
|
|
}
|
|
}
|