diff --git a/app/Config/Constants.php b/app/Config/Constants.php index 7cb3cb8..8c8a177 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -476,57 +476,6 @@ define("SERVERPART", [ "SERVER_PARTTYPES" => ['CPU', 'RAM', 'DISK'], "SERVICE_PARTTYPES" => ['SOFTWARE', 'CS', 'IP'], "ALL_PARTTYPES" => ['CPU', 'RAM', 'DISK', 'SOFTWARE', 'IP', 'CS'], - "CPU" => [ - 1 => [["UID" => 1, "CNT" => 2, "EXTRA" => ""]], - 2 => [["UID" => 2, "CNT" => 2, "EXTRA" => ""]], - 3 => [["UID" => 3, "CNT" => 2, "EXTRA" => ""]], - 4 => [["UID" => 3, "CNT" => 2, "EXTRA" => ""]], - 5 => [["UID" => 4, "CNT" => 2, "EXTRA" => ""]], - 6 => [["UID" => 4, "CNT" => 2, "EXTRA" => ""]], - 7 => [["UID" => 5, "CNT" => 2, "EXTRA" => ""]], - 8 => [["UID" => 5, "CNT" => 2, "EXTRA" => ""]], - 101 => [["UID" => 7, "CNT" => 1, "EXTRA" => ""]], - 102 => [["UID" => 8, "CNT" => 1, "EXTRA" => ""]], - 103 => [["UID" => 9, "CNT" => 1, "EXTRA" => ""]], - 111 => [["UID" => 10, "CNT" => 1, "EXTRA" => ""]], - 112 => [["UID" => 11, "CNT" => 1, "EXTRA" => ""]], - 113 => [["UID" => 12, "CNT" => 1, "EXTRA" => ""]], - 201 => [["UID" => 9, "CNT" => 1, "EXTRA" => ""]], - ], - "RAM" => [ - 1 => [["UID" => 2, "CNT" => 1, "EXTRA" => ""]], - 2 => [["UID" => 2, "CNT" => 2, "EXTRA" => ""]], - 3 => [["UID" => 2, "CNT" => 2, "EXTRA" => ""]], - 4 => [["UID" => 3, "CNT" => 2, "EXTRA" => ""]], - 5 => [["UID" => 3, "CNT" => 4, "EXTRA" => ""]], - 6 => [["UID" => 4, "CNT" => 4, "EXTRA" => ""]], - 7 => [["UID" => 5, "CNT" => 2, "EXTRA" => ""]], - 8 => [["UID" => 5, "CNT" => 2, "EXTRA" => ""]], - 101 => [["UID" => 9, "CNT" => 1, "EXTRA" => ""]], - 102 => [["UID" => 9, "CNT" => 1, "EXTRA" => ""]], - 103 => [["UID" => 10, "CNT" => 1, "EXTRA" => ""]], - 111 => [["UID" => 9, "CNT" => 1, "EXTRA" => ""]], - 112 => [["UID" => 9, "CNT" => 1, "EXTRA" => ""]], - 113 => [["UID" => 10, "CNT" => 1, "EXTRA" => ""]], - 201 => [["UID" => 11, "CNT" => 1, "EXTRA" => ""]], - ], - "DISK" => [ - 1 => [["UID" => 8, "CNT" => 2, "EXTRA" => "RAID1"], ["UID" => 9, "CNT" => 2, "EXTRA" => "RAID1"],], - 2 => [["UID" => 8, "CNT" => 2, "EXTRA" => "RAID1"], ["UID" => 9, "CNT" => 2, "EXTRA" => "RAID1"],], - 3 => [["UID" => 8, "CNT" => 2, "EXTRA" => "RAID1"], ["UID" => 9, "CNT" => 2, "EXTRA" => "RAID1"],], - 4 => [["UID" => 8, "CNT" => 2, "EXTRA" => "RAID1"], ["UID" => 9, "CNT" => 2, "EXTRA" => "RAID1"],], - 5 => [["UID" => 8, "CNT" => 2, "EXTRA" => "RAID1"], ["UID" => 9, "CNT" => 2, "EXTRA" => "RAID1"],], - 6 => [["UID" => 8, "CNT" => 2, "EXTRA" => "RAID1"], ["UID" => 9, "CNT" => 2, "EXTRA" => "RAID1"],], - 7 => [["UID" => 8, "CNT" => 2, "EXTRA" => "RAID1"], ["UID" => 9, "CNT" => 2, "EXTRA" => "RAID1"],], - 8 => [["UID" => 8, "CNT" => 2, "EXTRA" => "RAID1"], ["UID" => 9, "CNT" => 2, "EXTRA" => "RAID1"],], - 101 => [["UID" => 8, "CNT" => 1, "EXTRA" => ""]], - 102 => [["UID" => 8, "CNT" => 1, "EXTRA" => ""]], - 103 => [["UID" => 9, "CNT" => 1, "EXTRA" => ""]], - 111 => [["UID" => 8, "CNT" => 1, "EXTRA" => ""]], - 112 => [["UID" => 8, "CNT" => 1, "EXTRA" => ""]], - 113 => [["UID" => 9, "CNT" => 1, "EXTRA" => ""]], - 201 => [["UID" => 9, "CNT" => 1, "EXTRA" => ""]], - ] ]); //결제 관련 define("PAYMENT", [ diff --git a/app/DTOs/Equipment/CHASSISDTO.php b/app/DTOs/Equipment/CHASSISDTO.php index 88c203c..9568c41 100644 --- a/app/DTOs/Equipment/CHASSISDTO.php +++ b/app/DTOs/Equipment/CHASSISDTO.php @@ -12,6 +12,12 @@ class CHASSISDTO extends CommonDTO public int $used = 0; public int $stock = 0; public string $status = ''; + public int $cpuinfo_uid = 0; + public int $cpu_cnt = 0; + public int $raminfo_uid = 0; + public int $ram_cnt = 0; + public int $diskinfo_uid = 0; + public int $disk_cnt = 0; public function __construct(array $datas = []) { diff --git a/app/Entities/Equipment/CHASSISEntity.php b/app/Entities/Equipment/CHASSISEntity.php index 816dec1..8439082 100644 --- a/app/Entities/Equipment/CHASSISEntity.php +++ b/app/Entities/Equipment/CHASSISEntity.php @@ -14,11 +14,26 @@ class CHASSISEntity extends EquipmentEntity 'used' => 0, 'stock' => 0, 'status' => '', + 'cpu_cnt' => 0, + 'ram_cnt' => 0, + 'disk_cnt' => 0, ]; public function __construct(array|null $data = null) { parent::__construct($data); } + public function getCPUInfoUid(): int|null + { + return $this->attributes['cpuinfo_uid'] ?? null; + } + public function getRAMInfoUid(): int|null + { + return $this->attributes['raminfo_uid'] ?? null; + } + public function getDISKInfoUid(): int|null + { + return $this->attributes['diskinfo_uid'] ?? null; + } //기본기능 public function getPrice(): int { @@ -36,4 +51,16 @@ class CHASSISEntity extends EquipmentEntity { return $this->getStock() - $this->getUsed(); } + public function getCPUCnt(): int + { + return $this->attributes['cpu_cnt'] ?? 0; + } + public function getRAMCnt(): int + { + return $this->attributes['ram_cnt'] ?? 0; + } + public function getDISKCnt(): int + { + return $this->attributes['disk_cnt'] ?? 0; + } } diff --git a/app/Forms/Equipment/CHASSISForm.php b/app/Forms/Equipment/CHASSISForm.php index 30ab0ab..7621a8e 100644 --- a/app/Forms/Equipment/CHASSISForm.php +++ b/app/Forms/Equipment/CHASSISForm.php @@ -15,8 +15,17 @@ class CHASSISForm extends EquipmentForm "price", "used", "stock", + "cpuinfo_uid", + "cpu_cnt", + "raminfo_uid", + "ram_cnt", + "diskinfo_uid", + "disk_cnt", ]; $filters = [ + "cpuinfo_uid", + "raminfo_uid", + "diskinfo_uid", "status", ]; $indexFilter = $filters; @@ -55,10 +64,49 @@ class CHASSISForm extends EquipmentForm case "stock": $formRules[$field] = "required|numeric"; break; + case "cpuinfo_uid": + case "raminfo_uid": + case "diskinfo_uid": + case "cpu_cnt": + case "ram_cnt": + case "disk_cnt": + $formRules[$field] = "permit_empty|numeric"; + break; default: $formRules = parent::getFormRule($action, $field, $formRules); break; } return $formRules; } + public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'atttributes' => []]): array + { + $tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"]; + switch ($field) { + case "cpuinfo_uid": + foreach ($this->getFormOption_process(service('part_cpuservice'), $action, $field, $formDatas) as $tempEntity) { + $tempOptions[$tempEntity->getPK()] = $tempEntity->getTitle(); + // $options['attributes'][$tempEntity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $tempEntity->getRole())]; + } + $options['options'] = $tempOptions; + break; + case "raminfo_uid": + foreach ($this->getFormOption_process(service('part_ramservice'), $action, $field, $formDatas) as $tempEntity) { + $tempOptions[$tempEntity->getPK()] = $tempEntity->getTitle(); + // $options['attributes'][$tempEntity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $tempEntity->getRole())]; + } + $options['options'] = $tempOptions; + break; + case "diskinfo_uid": + foreach ($this->getFormOption_process(service('part_diskservice'), $action, $field, $formDatas) as $tempEntity) { + $tempOptions[$tempEntity->getPK()] = $tempEntity->getTitle(); + // $options['attributes'][$tempEntity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $tempEntity->getRole())]; + } + $options['options'] = $tempOptions; + break; + default: + $options = parent::getFormOption($action, $field, $formDatas, $options); + break; + } + return $options; + } } diff --git a/app/Helpers/Equipment/CHASSISHelper.php b/app/Helpers/Equipment/CHASSISHelper.php index 072e8bb..e1403fe 100644 --- a/app/Helpers/Equipment/CHASSISHelper.php +++ b/app/Helpers/Equipment/CHASSISHelper.php @@ -10,6 +10,21 @@ class CHASSISHelper extends EquipmentHelper { parent::__construct(); } + public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string + { + switch ($field) { + case 'cpuinfo_uid': + case 'raminfo_uid': + case 'diskinfo_uid': + $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field'; + $form = form_dropdown($field, $viewDatas['formOptions'][$field]['options'], $value, $extras); + break; + default: + $form = parent::getFieldForm($field, $value, $viewDatas, $extras); + break; + } + return $form; + } public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null { switch ($field) { diff --git a/app/Language/ko/Equipment/CHASSIS.php b/app/Language/ko/Equipment/CHASSIS.php index 91eb9a7..4cdbadb 100644 --- a/app/Language/ko/Equipment/CHASSIS.php +++ b/app/Language/ko/Equipment/CHASSIS.php @@ -7,6 +7,12 @@ return [ 'used' => "사용갯수", 'stock' => "재고", 'status' => "상태", + 'cpuinfo_uid' => "CPU", + 'cpu_cnt' => "CPU수", + 'raminfo_uid' => "RAM", + 'ram_cnt' => "RAM수", + 'diskinfo_uid' => "DISK", + 'disk_cnt' => "DISK수", 'updated_at' => "수정일", 'created_at' => "작성일", 'deleted_at' => "삭제일", diff --git a/app/Models/Equipment/CHASSISModel.php b/app/Models/Equipment/CHASSISModel.php index 06cedcf..0b366b2 100644 --- a/app/Models/Equipment/CHASSISModel.php +++ b/app/Models/Equipment/CHASSISModel.php @@ -19,6 +19,12 @@ class CHASSISModel extends EquipmentModel "price", "used", "stock", + "cpuinfo_uid", + "cpu_cnt", + "raminfo_uid", + "ram_cnt", + "diskinfo_uid", + "disk_cnt", "status", ]; public function __construct() diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index 254109b..d8749c1 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -195,29 +195,31 @@ class ServerPartService extends EquipmentService //서버추가시 기본파트 자동추가용 public function attachToServer(ServerEntity $serverEntity): void { - //*서버의 Title 대소문자구분 필요->서버의 Title로 구분해서 기본부품 추가 + $chassisEntity = service("equipment_chassisservice")->getEntity($serverEntity->getChassisInfoUid()); + //해당 서버의 chassis_uid에 해당하는 Default값이 있는지 체크 후 서버파트 추가 foreach (SERVERPART['SERVER_PARTTYPES'] as $parttype) { - //해당 서버의 chassis_uid에 해당하는 Default값이 있는지 체크 후 서버파트 추가 - if (array_key_exists($serverEntity->getChassisInfoUid(), SERVERPART[$parttype])) { - foreach (SERVERPART[$parttype][$serverEntity->getChassisInfoUid()] as $part) { - //해당 파트정보 가져오기 - $partEntity = $this->getPartService($parttype)->getEntity($part['UID']); - if (!$partEntity instanceof PartEntity) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$part['UID']} 파트정보를 찾을수 없습니다."); - } - //서버파트정보 생성 - $formDatas = []; - $formDatas['serverinfo_uid'] = $serverEntity->getPK(); - $formDatas["part_uid"] = $partEntity->getPK(); - $formDatas['billing'] = PAYMENT['BILLING']['BASE']; - $formDatas['type'] = $parttype; - $formDatas['title'] = $partEntity->getTitle(); //파트 제목 - $formDatas['amount'] = $partEntity->getPrice(); //파트 금액 - $formDatas['cnt'] = $part["CNT"]; - $formDatas['extra'] = $part["EXTRA"]; - $this->create_process($formDatas); - } + $uid_function = "get{$parttype}InfoUid"; + $cnt_function = "get{$parttype}Cnt"; + $uid = $chassisEntity->$uid_function(); + $cnt = $chassisEntity->$cnt_function(); + if ($uid === null) { + continue; } + //해당 파트정보 가져오기 + $partEntity = $this->getPartService($parttype)->getEntity($uid); + if (!$partEntity instanceof PartEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 {$parttype} 파트정보를 찾을수 없습니다."); + } + //서버파트정보 생성 + $formDatas = []; + $formDatas['serverinfo_uid'] = $serverEntity->getPK(); + $formDatas["part_uid"] = $partEntity->getPK(); + $formDatas['billing'] = PAYMENT['BILLING']['BASE']; + $formDatas['type'] = $parttype; + $formDatas['title'] = $partEntity->getTitle(); //파트 제목 + $formDatas['amount'] = $partEntity->getPrice(); //파트 금액 + $formDatas['cnt'] = $cnt; + $this->create_process($formDatas); } } public function detachFromServer(ServerEntity $serverEntity): void