155 lines
5.7 KiB
PHP
155 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Equipment;
|
|
|
|
use App\DTOs\Equipment\CHASSISDTO;
|
|
use App\Entities\Equipment\CHASSISEntity;
|
|
use App\Entities\Equipment\ServerEntity;
|
|
use App\Forms\Equipment\CHASSISForm;
|
|
use App\Helpers\Equipment\CHASSISHelper;
|
|
use App\Models\Equipment\CHASSISModel;
|
|
use RuntimeException;
|
|
|
|
class CHASSISService extends EquipmentService
|
|
{
|
|
private $_form = null;
|
|
private $_helper = null;
|
|
public function __construct(CHASSISModel $model)
|
|
{
|
|
parent::__construct($model);
|
|
$this->addClassPaths('CHASSIS');
|
|
}
|
|
protected function getDTOClass(): string
|
|
{
|
|
return CHASSISDTO::class;
|
|
}
|
|
public function createDTO(array $formDatas): CHASSISDTO
|
|
{
|
|
return new CHASSISDTO($formDatas);
|
|
}
|
|
public function getEntityClass(): string
|
|
{
|
|
return CHASSISEntity::class;
|
|
}
|
|
public function getFormService(): CHASSISForm
|
|
{
|
|
if ($this->_form === null) {
|
|
$this->_form = new CHASSISForm();
|
|
$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(): CHASSISHelper
|
|
{
|
|
if ($this->_helper === null) {
|
|
$this->_helper = new CHASSISHelper();
|
|
$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 = [
|
|
"title",
|
|
"price",
|
|
"stock",
|
|
];
|
|
$filters = [
|
|
"status",
|
|
];
|
|
$indexFilter = $filters;
|
|
$batchjobFilters = ['status'];
|
|
switch ($action) {
|
|
case 'create':
|
|
case 'create_form':
|
|
case 'modify':
|
|
case 'modify_form':
|
|
$fields = [...$fields, 'status'];
|
|
break;
|
|
case 'view':
|
|
$fields = [...$fields, 'status', 'created_at'];
|
|
break;
|
|
case 'index':
|
|
case 'download':
|
|
$fields = [...$fields, 'status', '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);
|
|
}
|
|
//기본 기능부분
|
|
protected function getEntity_process(mixed $entity): CHASSISEntity
|
|
{
|
|
return $entity;
|
|
}
|
|
protected function create_process(array $formDatas): CHASSISEntity
|
|
{
|
|
return parent::create_process($formDatas);
|
|
}
|
|
protected function modify_process($entity, array $formDatas): CHASSISEntity
|
|
{
|
|
return parent::modify_process($entity, $formDatas);
|
|
}
|
|
//List 검색용
|
|
//FormFilter 조건절 처리
|
|
//검색어조건절처리
|
|
//OrderBy 처리
|
|
public function setOrderBy(mixed $field = null, mixed $value = null): void
|
|
{
|
|
$this->model->orderBy('title ASC');
|
|
parent::setOrderBy($field, $value);
|
|
}
|
|
//서버관련 작업
|
|
//파트정보가져오기
|
|
public function getPartEntityByServer(ServerEntity $serverEntity): CHASSISEntity
|
|
{
|
|
//IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
|
|
$entity = $this->getEntity($serverEntity->getChassisInfoUID());
|
|
if (!$entity instanceof CHASSISEntity) {
|
|
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 {$serverEntity->getChassisInfoUID()}에 해당하는 샷시정보를 찾을수없습니다.");
|
|
}
|
|
return $entity;
|
|
}
|
|
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): CHASSISEntity
|
|
{
|
|
//부품정보가져오기
|
|
/** @var CHASSISEntity $entity IDE에 entity type알려주기*/
|
|
$entity = $this->getEntity($serverEntity->getChassisInfoUID());
|
|
//파트정보의 사용가능한 갯수 , 사용갯수 비교
|
|
if ($entity->getAvailable() < 1) {
|
|
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 현재 사용가능한 {$serverEntity->getTitle()} 샷시가 없습니다.");
|
|
}
|
|
$formDatas['used'] = $entity->getUsed() + 1;
|
|
return parent::modify_process($entity, $formDatas);
|
|
}
|
|
|
|
public function detachFromServer(ServerEntity $serverEntity, array $formDatas = []): CHASSISEntity
|
|
{
|
|
//부품정보가져오기
|
|
/** @var CHASSISEntity $entity IDE에 entity type알려주기*/
|
|
$entity = $this->getEntity($serverEntity->getChassisInfoUID());
|
|
//파트정보의 사용된 갯수 , 회수용 갯수 비교
|
|
if ($entity->getUsed() < 1) {
|
|
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 현재 사용한 {$serverEntity->getTitle()} 샷시가 없습니다.");
|
|
}
|
|
$formDatas['used'] = $entity->getUsed() - 1;
|
|
return parent::modify_process($entity, $formDatas);
|
|
}
|
|
}
|