From 9c5371bcaab7a2e78f1758382515a47c491eb7fa Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Tue, 26 Aug 2025 18:42:05 +0900 Subject: [PATCH] dbmsv2 init...1 --- .../Admin/Equipment/ServerController.php | 30 ++++---- app/Controllers/CommonController.php | 29 +++++--- app/Entities/Equipment/ServerEntity.php | 9 +++ app/Helpers/CommonHelper.php | 7 +- app/Helpers/Equipment/ServerHelper.php | 29 +++++++- app/Services/Equipment/ServerService.php | 39 +++++------ app/Views/admin/server/index.php | 70 ------------------- app/Views/admin/server/view.php | 28 -------- 8 files changed, 99 insertions(+), 142 deletions(-) delete mode 100644 app/Views/admin/server/index.php delete mode 100644 app/Views/admin/server/view.php diff --git a/app/Controllers/Admin/Equipment/ServerController.php b/app/Controllers/Admin/Equipment/ServerController.php index e8b378d..ca2f5d9 100644 --- a/app/Controllers/Admin/Equipment/ServerController.php +++ b/app/Controllers/Admin/Equipment/ServerController.php @@ -40,19 +40,6 @@ class ServerController extends EquipmentController } //Index,FieldForm관련 - protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string - { - switch ($this->getAction()) { - case 'index': - case 'view': - $result = parent::getResultSuccess($message, $this->request->getVar('ActionTemplate') ?? $actionTemplate ?? 'server'); - break; - default: - $result = parent::getResultSuccess($message, $actionTemplate); - break; - } - return $result; - } //생성 protected function create_form_process(): void { @@ -90,4 +77,21 @@ class ServerController extends EquipmentController $this->serverPartEntities = $this->getService()->createServerParts($entity, $partDatas); return $entity; } + protected function index_process(array $entities = []): array + { + // //부품정보 FormOption 설정용 + // $this->serverBaseParts = $this->getService()::BaseParts; + // foreach ($this->getService()::BaseParts as $basePart) { + // $this->setFormFieldOptions("partinfo_{$basePart}_uid", $this->getFormFieldOption_process("partinfo_{$basePart}_uid")); + // } + // + foreach (parent::index_process($entities) as $entity) { + //서버 부품정보 정의 + $entity->setServerParts($this->getService()->getServerParts($entity)); + //서버 IP정보 정의 + //서버 CS정보 정의 + $entities[] = $entity; + } + return $entities; + } } diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 8d6a3d6..7ff832c 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -102,20 +102,17 @@ abstract class CommonController extends BaseController //Filters 정의 $this->setControlDatas('actionFilters', array_key_exists('filters', $actionFields) ? $actionFields['filters'] : []); //Field Rule정의 - $temps = []; foreach ($this->getControlDatas('actionFields') as $field) { - $temps[$field] = $this->getFormFieldRule_process($this->getAction(), $field); + $this->setFormFielRule($field, $this->getFormFieldRule_process($this->getAction(), $field)); } - $this->setControlDatas('field_rules', $temps); //Form용 Options정의 - $temps = []; foreach ($this->getControlDatas('actionFilters') as $field) { - $temps[$field] = []; - foreach ($this->getFormFieldOption_process($field) as $option) { - $temps[$field][$option->getPK()] = $option; + $options = []; + foreach ($this->getFormFieldOption_process($field) as $entity) { + $options[$entity->getPK()] = $entity; } + $this->setFormFieldOptions($field, $options); } - $this->setControlDatas('filter_optons', $temps); //일괄작업용 Fields정의 $this->setControlDatas( 'batchjob_fields', @@ -127,6 +124,22 @@ abstract class CommonController extends BaseController array_key_exists('batchjob_buttions', $actionFields) ? $actionFields['batchjob_buttions'] : $this->getService()->getBatchjobButtons() ); } + //FormRules정의 + final protected function setFormFielRule($field, string $rule) + { + //기존 Filter Rules 가져와서 field에 해당하는 rule이 없으면 field를 filter_rules 전체 적용 + $allRules = $this->getControlDatas('field_rules') ?? []; + $allRules[$field] = $rule; + $this->setControlDatas('field_rules', $allRules); + } + //FormOptions정의 + final protected function setFormFieldOptions($field, array $options) + { + //기존 Filter Options 가져와서 field에 해당하는 option이 없으면 field를 key로 배열추가 후 다시 filter_options 전체 적용 + $allOptions = $this->getControlDatas('filter_optons') ?? []; + $allOptions[$field] = $options; + $this->setControlDatas('filter_optons', $allOptions); + } //전체 FormDatas 전달값받기 final protected function getFormDatas(array $fields, array $requestDatas, array $formDatas = []): array { diff --git a/app/Entities/Equipment/ServerEntity.php b/app/Entities/Equipment/ServerEntity.php index fa85b9b..6ba6497 100644 --- a/app/Entities/Equipment/ServerEntity.php +++ b/app/Entities/Equipment/ServerEntity.php @@ -25,4 +25,13 @@ class ServerEntity extends EquipmentEntity { return $this->attributes['serviceinfo_uid'] ?? null; } + + public function setServerParts(array $datas): void + { + $this->attributes['server_parts'] = $datas; + } + public function getServerParts(): array + { + return $this->attributes['server_parts'] ?? []; + } } diff --git a/app/Helpers/CommonHelper.php b/app/Helpers/CommonHelper.php index 376c128..3ec5fa6 100644 --- a/app/Helpers/CommonHelper.php +++ b/app/Helpers/CommonHelper.php @@ -307,8 +307,13 @@ class CommonHelper } $value = implode(" , ", $roles); break; - case 'created_at': + case 'issue_at': + case 'expired_at': + case 'billing_at': + case 'start_at': + case 'end_at': case 'updated_at': + case 'created_at': case 'deleted_at': $value = $value ? date("Y-m-d", strtotime($value)) : ""; break; diff --git a/app/Helpers/Equipment/ServerHelper.php b/app/Helpers/Equipment/ServerHelper.php index 6b42864..d801597 100644 --- a/app/Helpers/Equipment/ServerHelper.php +++ b/app/Helpers/Equipment/ServerHelper.php @@ -21,8 +21,10 @@ class ServerHelper extends EquipmentHelper break; case 'partinfo_cpu_uid': case 'partinfo_ram_uid': - case 'partinfo_software_uid': case 'partinfo_disk_uid': + case 'partinfo_software_uid': + case 'partinfo_os_uid': + case 'partinfo_db_uid': $form = $this->form_dropdown_custom($field, $value, $viewDatas, $extras); $form .= " " . form_dropdown("{$field}_cnt", $viewDatas['partinfo_cnt_range'], $value ?? 1) . "개"; if ($field === 'partinfo_disk_uid') { @@ -43,6 +45,31 @@ class ServerHelper extends EquipmentHelper } return $form; } + public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null + { + switch ($field) { + case 'manufactur_at': + case 'format_at': + $value = $value ? date("Y-m-d", strtotime($value)) : ""; + break; + case 'partinfo_uid': + $value = ""; + foreach ($viewDatas['entity']->getServerParts() as $part) { + // $value .= "
" . $this->getFieldForm("partinfo_" . strtolower($part->type) . "_uid", $part->partinfo_uid, $viewDatas, $extras) . "
"; + $value .= sprintf("
%s%s %s
", $part->title, $part->cnt > 1 ? "*" . $part->cnt . "개" : "", $part->extra ?? ""); + } + // dd($value); + break; + default: + $value = parent::getFieldView($field, $value, $viewDatas, $extras); + break; + } + if (is_array($value)) { + echo __METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다"; + exit; + } + return $value; + } public function getListFilter(string $field, mixed $value, array $viewDatas, array $extras = []): string { switch ($field) { diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index 2c40177..1c2d9ef 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -14,7 +14,6 @@ class ServerService extends EquipmentService private ?CSService $_csService = null; private ?ServerPartModel $_serverPartModel = null; const BaseParts = ['cpu', 'ram', 'disk', 'os']; - const AddtionalParts = ['ram', 'disk', 'db', 'software', 'ip', 'cs']; public function __construct() { parent::__construct(new ServerModel()); @@ -32,6 +31,7 @@ class ServerService extends EquipmentService "partinfo_disk_uid", "partinfo_os_uid", "price", + "amount", "manufactur_at", "format_at", "status", @@ -55,10 +55,11 @@ class ServerService extends EquipmentService 'fields' => [ 'clientinfo_uid', 'serviceinfo_uid', - 'partinfo_uid', "type", 'title', + "partinfo_uid", 'price', + 'amount', 'manufactur_at', "format_at", 'status' @@ -104,34 +105,22 @@ class ServerService extends EquipmentService { switch ($field) { case 'partinfo_cpu_uid': - $options = $this->getPartService()->getEntities([ - 'type' => 'CPU' - ]); + $options = $this->getPartService()->getEntities(['type' => 'CPU']); break; case 'partinfo_ram_uid': - $options = $this->getPartService()->getEntities([ - 'type' => 'RAM' - ]); + $options = $this->getPartService()->getEntities(['type' => 'RAM']); break; case 'partinfo_disk_uid': - $options = $this->getPartService()->getEntities([ - 'type' => 'DISK' - ]); + $options = $this->getPartService()->getEntities(['type' => 'DISK']); break; case 'partinfo_os_uid': - $options = $this->getPartService()->getEntities([ - 'type' => 'OS' - ]); + $options = $this->getPartService()->getEntities(['type' => 'OS']); break; case 'partinfo_db_uid': - $options = $this->getPartService()->getEntities([ - 'type' => 'DB' - ]); + $options = $this->getPartService()->getEntities(['type' => 'DB']); break; case 'partinfo_software_uid': - $options = $this->getPartService()->getEntities([ - 'type' => 'SOFTWARE' - ]); + $options = $this->getPartService()->getEntities(['type' => 'SOFTWARE']); break; case 'partinfo_uid': //수정때문에 전체가 필요 $options = $this->getPartService()->getEntities(); @@ -154,6 +143,7 @@ class ServerService extends EquipmentService return $this->getModel()->getLastestCode($format, $default); } + //Server Part별 저장 public function createServerParts(ServerEntity $entity, array $partDatas): array { $serverPartEntities = []; @@ -162,9 +152,16 @@ class ServerService extends EquipmentService $partDatas[$basePart]["serviceinfo_uid"] = $entity->getServiceInfoUID(); $serverPartEntities[] = $this->getServerPartModel()->create($partDatas[$basePart]); } - // dd($serverPartEntities); return $serverPartEntities; } + //Server Part별 정보가져오기 + public function getServerParts(ServerEntity $entity): array + { + $sql = "SELECT serverinfo_partinfo.*,partinfo.title as title,partinfo.price,partinfo.type FROM serverinfo_partinfo + LEFT JOIN partinfo ON serverinfo_partinfo.partinfo_uid = partinfo.uid + WHERE serverinfo_partinfo.serverinfo_uid = ?"; + return $this->getModel()->query($sql, [$entity->getPK()])->getResult(); + } //List 검색용 //OrderBy 처리 diff --git a/app/Views/admin/server/index.php b/app/Views/admin/server/index.php deleted file mode 100644 index 265a5dd..0000000 --- a/app/Views/admin/server/index.php +++ /dev/null @@ -1,70 +0,0 @@ -extend(LAYOUTS[$viewDatas['layout']]['path']) ?> -section('content') ?> -alert($error) ?> -
include(LAYOUTS[$viewDatas['layout']]['path'] . '/top'); ?>
- - - - - - -
- - include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?> - - - -
include("templates/{$viewDatas['layout']}/index_header"); ?>
-
- -
- include("templates/{$viewDatas['layout']}/index_content_top"); ?> - 'batchjob_form', 'method' => "post"]) ?> - - - - - - - - - - - - - - - getListRowColor($entity) ?>> - - - - - - - - - - - - - -
번호getListLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?>작업
getListButton('modify', '', $viewDatas) ?>getFieldView($field, $entity->$field, $viewDatas) ?> - getListButton('view', '', $viewDatas) ?>  - getListButton('history', '', $viewDatas) ?>  - getListButton('delete', '', $viewDatas) ?> -
- - $label): ?> - $label): ?> -
getFieldLabel($item_type, $label, $viewDatas) ?>
getFieldView($item_type, $entity->$item_type, $viewDatas) ?>
-
- include("templates/{$viewDatas['layout']}/index_content_bottom"); ?> - -
-
- - -
- -
include(LAYOUTS[$viewDatas['layout']]['path'] . '/bottom'); ?>
-endSection() ?> \ No newline at end of file diff --git a/app/Views/admin/server/view.php b/app/Views/admin/server/view.php deleted file mode 100644 index 6f005e7..0000000 --- a/app/Views/admin/server/view.php +++ /dev/null @@ -1,28 +0,0 @@ -extend(LAYOUTS[$viewDatas['layout']]['path']) ?> -section('content') ?> -alert($error) ?> -
-
-
- - - - - - - -
getFieldLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?>getFieldView($field, $viewDatas['entity']->$field, $viewDatas) ?>
-
-
- - $label): ?> - - - - - -
getFieldLabel($item_type, $label, $viewDatas) ?>getFieldView($item_type, $viewDatas['entity']->$item_type, $viewDatas) ?>
-
-
-
-endSection() ?> \ No newline at end of file