addClassName('Server'); } public function getFormFields(): array { return [ "code", "type", "title", "price", "amount", "manufactur_at", "format_at", "status", "partinfo_uid_CPU", "partinfo_uid_CPU_cnt", "partinfo_uid_RAM", "partinfo_uid_RAM_cnt", "partinfo_uid_DISK", "partinfo_uid_DISK_cnt", "partinfo_uid_DISK_extra", ]; } public function getFormFilters(): array { return [ "clientinfo_uid", "serviceinfo_uid", "type", "title", "partinfo_uid_CPU", "partinfo_uid_RAM", "partinfo_uid_DISK", "partinfo_uid_DISK_extra", "status" ]; } public function getIndexFields(): array { return [ 'clientinfo_uid', 'serviceinfo_uid', "type", 'title', 'price', 'amount', 'manufactur_at', "format_at", 'status', ]; } public function getIndexFilters(): array { return [ 'clientinfo_uid', 'serviceinfo_uid', 'type', 'status' ]; } public function getBatchjobFields(): array { return ['clientinfo_uid', 'status']; } final public function getServerPartService(): ServerPartService { if (!$this->_serverPartService) { $this->_serverPartService = new ServerPartService(); } return $this->_serverPartService; } final public function getIPService(): IPService { if (!$this->_ipService) { $this->_ipService = new IPService(); } return $this->_ipService; } final public function getCSService(): CSService { if (!$this->_csService) { $this->_csService = new CSService(); } return $this->_csService; } //partEntity 정보 추가 protected function getEntity_process(mixed $entity): ServerEntity { //부품연결정보 정의 foreach (SERVER['PARTTYPES'] as $partType) { $serverPartEntity = $this->getServerPartService()->getEntity(['serverinfo_uid' => $entity->getPK(), 'type' => $partType]); if ($serverPartEntity) { $entity->addServerPartEntity($partType, $serverPartEntity); } } //Switch정보 정의 $switchEntity = $this->getSwitchService()->getEntity(['serverinfo_uid' => $entity->getPK()]); $entity->setSwitchEntity($switchEntity); //IP정보 정의 foreach ($this->getIPService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $ipEntity) { $entity->addIPEntity($ipEntity); } //CS정보 정의 foreach ($this->getCSService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $csEntity) { $entity->addCSEntity($csEntity); } return $entity; } //기본 기능부분 public function getFormOption(string $field, array $options = []): array { switch ($field) { case 'partinfo_uid_CPU': $options = $this->getServerPartService()->getFormOption('partinfo_uid_CPU'); break; case 'partinfo_uid_RAM': $options = $this->getServerPartService()->getFormOption('partinfo_uid_RAM'); break; case 'partinfo_uid_DISK': $options = $this->getServerPartService()->getFormOption('partinfo_uid_DISK'); break; case 'partinfo_uid_OS': $options = $this->getServerPartService()->getFormOption('partinfo_uid_OS'); break; case 'partinfo_uid_DB': $options = $this->getServerPartService()->getFormOption('partinfo_uid_DB'); break; case 'partinfo_uid_SOFTWARE': $options = $this->getServerPartService()->getFormOption('partinfo_uid_SOFTWARE'); break; case 'ipinfo_uid': //수정때문에 전체가 필요 $options = $this->getIPService()->getEntities(); break; case 'csinfo_uid': //수정때문에 전체가 필요 $options = $this->getCSService()->getEntities(); break; default: $options = parent::getFormOption($field, $options); break; } return $options; } //FieldForm관련용 //create용 장비코드 마지막번호 가져오기 final public function getLastestCode(string $format, int $default): string { return $this->getModel()->getLastestCode($format, $default); } final public function codeCheck(array $formDatas) { //코드 패턴체크 $pattern = env("Server.Prefix.code.pattern", false); if (!$pattern) { throw new \Exception(__METHOD__ . "에서 code의 prefix[Server.Prefix.code.pattern]가 정의되지 않았습니다."); } if (!array_key_exists('code', $formDatas)) { throw new \Exception("Server코드가 정의되지 않았습니다"); } if (!preg_match($pattern, $formDatas['code'])) { throw new \Exception("Server코드[{$formDatas['code']}의 형식이 맞지않습니다"); } } //생성 public function create(array $formDatas): ServerEntity { $entity = parent::create($formDatas); //ServerPart정보 생성 foreach (SERVER['PARTTYPES'] as $partType) { foreach ($this->getServerPartService()->createByServer($entity, $formDatas) as $serverPartEntity) { $entity->addServerPartEntity($serverPartEntity->getType(), $serverPartEntity); }; } return $entity; } //수정 public function modify(mixed $entity, array $formDatas): ServerEntity { $entity = parent::modify($entity, $formDatas); // ServerPart정보 수정 foreach ($this->getServerPartService()->modifyByServer($entity, $formDatas) as $serverPartEntity) { $entity->addServerPartEntity($serverPartEntity->getType(), $serverPartEntity); }; return $entity; } //삭제 public function delete(mixed $entity): ServerEntity { $entity = parent::delete($entity); // ServerPart정보 수정 foreach ($this->getServerPartService()->deleteByServer($entity) as $serverPartEntity) { $entity->addServerPartEntity($serverPartEntity->getType(), $serverPartEntity); }; return $entity; } //List 검색용 //OrderBy 처리 public function setOrderBy(mixed $field = null, mixed $value = null): void { $this->getModel()->orderBy("code ASC,title ASC"); parent::setOrderBy($field, $value); } public function enableService(ServiceEntity $serviceEntity, ServerEntity $entity, array $formDatas): ServerEntity { $formDatas = []; $formDatas["clientinfo_uid"] = $serviceEntity->getClientInfoUID(); $formDatas["serviceinfo_uid"] = $serviceEntity->getPK(); $formDatas['status'] = ServerEntity::STATUS_OCCUPIED; $entity = parent::modify($entity, $formDatas); //Switch경우 서비스중으로 설정 if (array_key_exists('switchinfo_uid', $formDatas)) { $switchEntity = $this->getSwitchService()->getEntity($formDatas['switchinfo_uid']); if (!$switchEntity) { throw new \Exception("{$formDatas['switchinfo_uid']}에 대한 스위치정보를 찾을수 없습니다."); } $switchEntity = $this->getSwitchService()->enableService($entity, $switchEntity); $entity->setSwitchEntity($switchEntity); } //IP정보 서비스중으로 설정 if (array_key_exists('ipinfo_uid', $formDatas)) { $ipEntity = $this->getIPService()->getEntity($formDatas['ipinfo_uid']); if (!$ipEntity) { throw new \Exception("{$formDatas['ipinfo_uid']}에 대한 IP정보를 찾을수 없습니다."); } $ipEntity = $this->getIPService()->enableService($entity, $ipEntity); $entity->addIPEntity($ipEntity); } //CS정보 서비스중으로 설정 if (array_key_exists('csinfo_uid', $formDatas)) { $csEntity = $this->getCSService()->getEntity($formDatas['csinfo_uid']); if (!$csEntity) { throw new \Exception("{$formDatas['csinfo_uid']}에 대한 CS정보를 찾을수 없습니다."); } $csEntity = $this->getCSService()->enableService($entity, $csEntity); $entity->addCSEntity($csEntity); } return $entity; } public function disableService(ServerEntity $entity): ServerEntity { //서비스 해지시 기존 Switch정보를 사용가능 상태로 변경 $switchEntity = $entity->getSwitchEntity(); if ($switchEntity !== null) { $this->getSwitchService()->disableService($switchEntity); $entity->setSwitchEntity(null); } //서비스 해지시 기존 IP정보를 사용가능 상태로 변경 foreach ($entity->getIPEntities() as $ipEntity) { $this->getIPService()->disableService($ipEntity); } $entity->setIPEntities([]); //서비스 해지시 기존 CS정보를 사용가능 상태로 변경 foreach ($entity->getCSEntities() as $csEntity) { $this->getCSService()->disableService($csEntity); } $entity->setCSEntities([]); $formDatas = []; $formDatas["clientinfo_uid"] = null; $formDatas["serviceinfo_uid"] = null; $formDatas['status'] = ServerEntity::STATUS_AVAILABLE; return parent::modify($entity, $formDatas); } }