87 lines
3.2 KiB
PHP
87 lines
3.2 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
|
|
{
|
|
protected string $formClass = CHASSISForm::class;
|
|
protected string $helperClass = CHASSISHelper::class;
|
|
|
|
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;
|
|
}
|
|
//기본 기능부분
|
|
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);
|
|
}
|
|
}
|