dbmsv4/app/Services/Equipment/CHASSISService.php
2025-12-18 13:57:44 +09:00

114 lines
4.3 KiB
PHP

<?php
namespace App\Services\Equipment;
use App\DTOs\Equipment\CHASSISDTO;
use App\Entities\CommonEntity;
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');
}
public 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->getPKField(),
'title_field' => $this->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->getPKField(),
'title_field' => $this->getTitleField(),
'table' => $this->model->getTable(),
'useAutoIncrement' => $this->model->useAutoIncrement(),
'class_path' => $this->getClassPaths(false)
]);
}
return $this->_helper;
}
//기본 기능부분
protected function getEntity_process(mixed $entity): CHASSISEntity
{
return $entity;
}
//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 = []): CommonEntity
{
//부품정보가져오기
/** @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 = []): CommonEntity
{
//부품정보가져오기
/** @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);
}
}