dbmsv4/app/Services/Equipment/ServerPartService.php
2025-11-25 12:31:32 +09:00

140 lines
4.8 KiB
PHP

<?php
namespace App\Services\Equipment;
use App\DTOs\Equipment\ServerPartDTO;
use App\DTOs\UserDTO;
use App\Entities\Equipment\ServerPartEntity;
use App\Forms\Equipment\ServerPartForm;
use App\Helpers\Equipment\ServerPartHelper;
use App\Models\Equipment\ServerPartModel;
use App\Services\CommonService;
use RuntimeException;
class ServerPartService extends EquipmentService
{
private $_form = null;
private $_helper = null;
public function __construct(ServerPartModel $model)
{
parent::__construct($model);
$this->addClassPaths('ServerPart');
}
protected function getDTOClass(): string
{
return ServerPartDTO::class;
}
public function createDTO(array $formDatas): ServerPartDTO
{
return new ServerPartDTO($formDatas);
}
public function getFormService(): ServerPartForm
{
if ($this->_form === null) {
$this->_form = new ServerPartForm();
$this->_form->setAttributes([
'pk_field' => $this->model->getPKField(),
'title_field' => $this->model->getTitleField(),
'table' => $this->model->getTable(),
'useAutoIncrement' => $this->model->useAutoIncrement(),
'class_path' => $this->getClassPaths(false)
]);
}
return $this->_form;
}
public function getHelper(): ServerPartHelper
{
if ($this->_helper === null) {
$this->_helper = new ServerPartHelper();
$this->_helper->setAttributes([
'pk_field' => $this->model->getPKField(),
'title_field' => $this->model->getTitleField(),
'table' => $this->model->getTable(),
'useAutoIncrement' => $this->model->useAutoIncrement(),
'class_path' => $this->getClassPaths(false)
]);
}
return $this->_helper;
}
public function action_init_process(string $action, array $formDatas = []): void
{
$fields = [
"serverinfo_uid",
"type",
"billing",
"part_uid",
"cnt",
"extra",
"amount",
];
$filters = [
"serverinfo_uid",
"type",
"part_uid",
"billing",
];
$indexFilter = [
"serverinfo_uid",
"type",
"billing",
];
$batchjobFilters = ['billing', 'type'];
switch ($action) {
case 'create':
case 'create_form':
case 'modify':
case 'modify_form':
break;
case 'view':
$fields = [...$fields, 'created_at'];
break;
case 'index':
case 'download':
$fields = [...$fields, 'created_at'];
break;
}
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules($action, $fields);
$this->getFormService()->setFormFilters($filters);
$this->getFormService()->setFormOptions($action, $filters, $formDatas);
$this->getFormService()->setIndexFilters($indexFilter);
$this->getFormService()->setBatchjobFilters($batchjobFilters);
}
//기본 기능부분
private function getPartService(string $type): CommonService
{
return service('part_' . strtolower($type) . 'service');
}
protected function getEntity_process(mixed $entity): ServerPartEntity
{
return $entity;
}
protected function create_process(array $formDatas): ServerPartEntity
{
if (!array_key_exists('title', $formDatas)) {
if (!array_key_exists('type', $formDatas)) {
throw new \Exception(__METHOD__ . "에서 오류발생:부품형식이 지정되지 않았습니다.");
}
$formDatas['title'] = $this->getPartService($formDatas['type']->getTitle());
}
return new ServerPartEntity($formDatas);
}
protected function modify_process($uid, array $formDatas): ServerPartEntity
{
if (!array_key_exists('title', $formDatas)) {
if (!array_key_exists('type', $formDatas)) {
throw new \Exception(__METHOD__ . "에서 오류발생:부품형식이 지정되지 않았습니다.");
}
$formDatas['title'] = $this->getPartService($formDatas['type']->getTitle());
}
$entity = parent::modify_process($uid, $formDatas);
if (!$entity instanceof ServerPartEntity) {
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServerPartEntity만 가능");
}
return $entity;
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리
}