dbmsv2/app/Services/Equipment/ServerPart/CPUService.php
2025-09-25 15:34:52 +09:00

54 lines
2.1 KiB
PHP

<?php
namespace App\Services\Equipment\ServerPart;
use App\Entities\Equipment\ServerPartEntity;
use App\Interfaces\Equipment\ServerPartInterface;
use App\Services\Part\CPUService as ParentService;
use App\Entities\Part\CPUEntity;
class CPUService extends ParentService implements ServerPartInterface
{
public function __construct()
{
parent::__construct();
}
//서버연결정보용 등록
private function action_process(ServerPartEntity $serverPartEntity, string $action): CPUEntity
{
//부품정보가져오기
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof CPUEntity) {
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다.");
}
//부품정보에 서버정보 설정 및 서비스,고객정보 정의
$formDatas = [];
if ($action === "return") { //해지된 부품 재고 반납 처리
$formDatas['stock'] = $entity->getStock() + $serverPartEntity->getCnt();
}
if ($action === "use") { //사용된 부품 재고 사용처리
if ($entity->getStock() < $serverPartEntity->getCnt()) {
throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
}
$formDatas['stock'] = $entity->getStock() - $serverPartEntity->getCnt();
}
return $this->getModel()->modify($entity, $formDatas);
}
public function createServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity
{
$entity = $this->action_process($serverPartEntity, "use");
return $serverPartEntity->setPartEntity($entity);
}
public function modifyServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity
{
return $this->createServerPart($serverPartEntity,);
}
public function deleteServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity
{
$entity = $this->action_process($serverPartEntity, "return");
return $serverPartEntity->setPartEntity($entity);
}
}