54 lines
2.1 KiB
PHP
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\SOFTWAREService as ParentService;
|
|
use App\Entities\Part\SOFTWAREEntity;
|
|
|
|
class SOFTWAREService extends ParentService implements ServerPartInterface
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
//서버연결정보용 등록
|
|
private function action_process(ServerPartEntity $serverPartEntity, string $action): SOFTWAREEntity
|
|
{
|
|
//부품정보가져오기
|
|
$entity = $this->getEntity($serverPartEntity->getPartUID());
|
|
if (!$entity instanceof SOFTWAREEntity) {
|
|
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 parent::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);
|
|
}
|
|
}
|