From 757df14d4773d796c5d441313fa3aede4630d501 Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Mon, 1 Sep 2025 18:41:54 +0900 Subject: [PATCH] dbmsv2 init...1 --- app/Config/Constants.php | 2 +- app/Controllers/CommonController.php | 33 ++++-- app/Helpers/Equipment/SwitchHelper.php | 17 +++ app/Services/CommonService.php | 112 +++++++----------- app/Services/Customer/CustomerService.php | 2 + app/Services/Customer/ServiceService.php | 5 +- app/Services/Equipment/EquipmentService.php | 1 + app/Services/Equipment/ServerPartService.php | 60 +++++----- app/Services/Equipment/ServerService.php | 23 +++- app/Services/Equipment/SwitchService.php | 12 +- app/Services/UserService.php | 7 +- app/Traits/IPTrait.php | 25 ++++ app/Views/admin/server/create_form.php | 16 --- app/Views/admin/server/modify_form.php | 20 ---- .../templates/admin/index_content_top.php | 6 +- 15 files changed, 167 insertions(+), 174 deletions(-) create mode 100644 app/Traits/IPTrait.php diff --git a/app/Config/Constants.php b/app/Config/Constants.php index 8ff9571..3022aef 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -367,7 +367,7 @@ define('SERVICE_NEW_INTERVAL', $_ENV['SERVICE_NEW_INTERVAL'] ?? $_SERVER['SERVIC //서버 PartType define("SERVER", [ - "PARTTYPES" => ['CPU', 'RAM', 'DISK', 'OS', 'SOFTWARE'], + "PARTTYPES" => ['CPU', 'RAM', 'DISK'], ]); //결제관련 diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 7ed3beb..ad7f1a5 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -353,7 +353,7 @@ abstract class CommonController extends BaseController if (!$entity) { throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } - $this->entity = $this->modify_form_process($uid); + $this->entity = $this->modify_form_process($entity); helper(['form']); $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; return $this->getResultSuccess(); @@ -426,7 +426,7 @@ abstract class CommonController extends BaseController { return $this->getService()->modify($entity, $formDatas); } - protected function batchjob_pre_process(): array + private function batchjob_pre_process(): array { $selectedFields = []; //getBatchJobFields를 이용해서 선택된 Field 와 값정의 @@ -509,7 +509,7 @@ abstract class CommonController extends BaseController { return $this->getService()->delete($entity); } - protected function batchjob_delete_pre_process(): array + private function batchjob_delete_pre_process(): array { //변경할 UIDS $uids = $this->request->getPost('batchjob_uids[]'); @@ -576,17 +576,30 @@ abstract class CommonController extends BaseController //조건절 처리 protected function index_condition_process(): void { + //Filter조건절 처리 + $index_filters = []; + foreach ($this->getControlDatas('actionFilters') as $field) { + $value = $this->request->getGet($field); + if ($value) { + $this->getService()->index_condition_filterField($field, $value); + $index_filters[$field] = $value; + } + } + $this->setControlDatas('index_filters', $index_filters); //검색어조건절 처리 - $this->word = $this->request->getVar('word'); - if ($this->word !== null && $this->word !== '') { - $this->getService()->index_condition_filterWord($this->word); + $index_word = $this->request->getVar('index_word'); + if ($index_word !== null && $index_word !== '') { + $this->getService()->index_condition_filterWord($index_word); } + $this->setControlDatas('index_word', $index_word); //날자검색 - $this->start = $this->request->getVar('start'); - $this->end = $this->request->getVar('end'); - if ($this->start !== null && $this->start !== '' && $this->end !== null && $this->end !== '') { - $this->getService()->index_condition_filterDate($this->start, $this->end); + $index_start = $this->request->getVar('index_start'); + $index_end = $this->request->getVar('index_end'); + if ($index_start !== null && $index_start !== '' && $index_end !== null && $index_end !== '') { + $this->getService()->index_condition_filterDate($index_start, $index_end); } + $this->setControlDatas('index_start', $index_start); + $this->setControlDatas('index_end', $index_end); } //PageNation 처리 protected function index_pagenation_process($pager_group = 'default', int $segment = 0, $template = 'bootstrap_full') diff --git a/app/Helpers/Equipment/SwitchHelper.php b/app/Helpers/Equipment/SwitchHelper.php index 16f1fae..d99d501 100644 --- a/app/Helpers/Equipment/SwitchHelper.php +++ b/app/Helpers/Equipment/SwitchHelper.php @@ -11,4 +11,21 @@ class SwitchHelper extends EquipmentHelper parent::__construct(); $this->setTitleField(field: SwitchModel::TITLE); } + + public function getListButton(string $action, string $label, array $viewDatas, array $extras = []): string + { + switch ($action) { + case 'modify': + if (!$this->getMyAuth()->isAccessRole(['security'])) { + $action = $viewDatas['entity']->getCode(); + } else { + $action = parent::getListButton($action, $viewDatas['entity']->getCode(), $viewDatas, $extras); + } + break; + default: + $action = parent::getListButton($action, $label, $viewDatas, $extras); + break; + } + return $action; + } } diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 0c47816..2d2fb43 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -10,25 +10,12 @@ abstract class CommonService { private $_model = null; private $_classNames = []; - private $_serviceDatas = []; protected function __construct(Model $model) { $this->_model = $model; } abstract public function getFormFields(): array; abstract public function getFormFilters(): array; - //기본 기능부분 - final public function __get($name) - { - if (!array_key_exists($name, $this->_serviceDatas)) { - return null; - } - return $this->_serviceDatas[$name]; - } - final public function __set($name, $value): void - { - $this->_serviceDatas[$name] = $value; - } final protected function addClassName(string $className): void { $this->_classNames[] = $className; @@ -65,7 +52,12 @@ abstract class CommonService final public function getEntities(mixed $where = null, array $columns = ['*']): array { try { - return $this->getEntities_process($where, $columns); + $entities = $this->getEntities_process($where, $columns); + $debug = sprintf("debug.%s.%s", str_replace("\\", ".", get_class($this)), __FUNCTION__); + if (env($debug, false)) { + echo $this->getModel()->getLastQuery() . "
"; + } + return $entities; } catch (\Exception $e) { $message = sprintf( "\n------%s SQL오류-----
\n%s
\n%s
\n------------------------------\n", @@ -76,62 +68,6 @@ abstract class CommonService throw new \Exception($message); } } // - //삭제 - final public function delete(mixed $entity): mixed - { - try { - $message = "[{$entity->getTitle()}]" . MESSAGES["DELETED"] . ":"; - $result = $this->getModel()->delete($entity->getPK()); - if (!$result) { - throw new \Exception($message); - } - LogCollector::info($message); - return $entity; - } catch (\Exception $e) { - $message = sprintf( - "\n------%s SQL오류-----
\n%s
\n%s
\n------------------------------\n", - __FUNCTION__, - $this->getModel()->getLastQuery(), - $e->getMessage() - ); - throw new \Exception($message); - } - } - //Index용 - final public function getTotalCount(): int - { - return $this->getModel()->countAllResults(false); - } - //Limit처리 - final public function setLimit(int $per_page): void - { - $this->getModel()->limit($per_page); - } - //Offset처리 - final public function setOffset(int $offset): void - { - $this->getModel()->offset($offset); - } - final public function isIPAddress(string $ip, $type = false): bool - { - switch ($type) { - case 'ipv4': - $result = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); - break; - case 'ipv6': - $result = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); - break; - case 'all': - $result = filter_var($ip, FILTER_VALIDATE_IP); - break; - default: - $result = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE); - break; - } - return $result; - } - //기본기능 - //개별기능 //Entity별로 작업처리시 protected function getEntity_process(mixed $entity): mixed { @@ -228,7 +164,43 @@ abstract class CommonService LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["UPDATED"] . ":"); return $entity; } + //삭제 + public function delete(mixed $entity): mixed + { + try { + $message = "[{$entity->getTitle()}]" . MESSAGES["DELETED"] . ":"; + $result = $this->getModel()->delete($entity->getPK()); + if (!$result) { + throw new \Exception($message); + } + LogCollector::info($message); + return $entity; + } catch (\Exception $e) { + $message = sprintf( + "\n------%s SQL오류-----
\n%s
\n%s
\n------------------------------\n", + __FUNCTION__, + $this->getModel()->getLastQuery(), + $e->getMessage() + ); + throw new \Exception($message); + } + } ////Index 검색용 + //Index용 + final public function getTotalCount(): int + { + return $this->getModel()->countAllResults(false); + } + //Limit처리 + final public function setLimit(int $per_page): void + { + $this->getModel()->limit($per_page); + } + //Offset처리 + final public function setOffset(int $offset): void + { + $this->getModel()->offset($offset); + } //FormFilter 조건절 처리 public function index_condition_filterField(string $field, mixed $filter_value): void { diff --git a/app/Services/Customer/CustomerService.php b/app/Services/Customer/CustomerService.php index 1bf80c3..172afec 100644 --- a/app/Services/Customer/CustomerService.php +++ b/app/Services/Customer/CustomerService.php @@ -14,7 +14,9 @@ abstract class CustomerService extends CommonService { private ?UserService $_userService = null; private ?ClientService $_clientService = null; + private ?ServiceService $_serviceService = null; private ?ServerService $_serverService = null; + private $_equipmentService = []; protected function __construct(Model $model) { diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index 37a219f..8dd6f95 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -3,11 +3,12 @@ namespace App\Services\Customer; use App\Entities\Customer\ServiceEntity; -use App\Entities\Equipment\ServerEntity; use App\Models\Customer\ServiceModel; +use App\Traits\IPTrait; class ServiceService extends CustomerService { + use IPTrait; private ?string $_searchIP = null; public function __construct() { @@ -141,7 +142,7 @@ class ServiceService extends CustomerService //검색어조건절처리 public function index_condition_filterWord(string $word): void { - if ($this->isIPAddress($word, 'ipv4')) { + if ($this->isIPAddressTrait($word, 'ipv4')) { $this->setSearchIp($word); } else { parent::index_condition_filterWord($word); diff --git a/app/Services/Equipment/EquipmentService.php b/app/Services/Equipment/EquipmentService.php index e9b9521..9e0d7d9 100644 --- a/app/Services/Equipment/EquipmentService.php +++ b/app/Services/Equipment/EquipmentService.php @@ -15,6 +15,7 @@ abstract class EquipmentService extends CommonService { private ?UserService $_userService = null; private ?ClientService $_clientService = null; + private ?ServiceService $_serviceService = null; private ?ServerService $_serverService = null; private $_equipmentService = []; protected function __construct(Model $model) diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index 6cef680..50cecb8 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -90,49 +90,43 @@ class ServerPartService extends EquipmentService } return $options; } - - //서버별 부품연결정보 생성 - private function createByServer_process(ServerEntity $serverEntity, string $partType, array $formDatas): ServerPartEntity + //생성 + public function createByServer(ServerEntity $serverEntity, array $formDatas): ServerPartEntity { - $serverPartFormDatas = [ - "partinfo_uid" => $formDatas["partinfo_uid_{$partType}"], - "serverinfo_uid" => $serverEntity->getPK(), - "serviceinfo_uid" => $serverEntity->getServiceInfoUID(), - "type" => $partType, - "billing" => array_key_exists("serverinfopartinfo_uid_{$partType}_billing", $formDatas) ? $formDatas["serverinfopartinfo_uid_{$partType}_billing"] : null, - "amount" => array_key_exists("serverinfopartinfo_uid_{$partType}_amount", $formDatas) ? $formDatas["serverinfopartinfo_uid_{$partType}_amount"] : 0, - "cnt" => array_key_exists("serverinfopartinfo_uid_{$partType}_cnt", $formDatas) ? $formDatas["serverinfopartinfo_uid_{$partType}_cnt"] : null, - "extra" => array_key_exists("serverinfopartinfo_uid_{$partType}_extra", $formDatas) ? $formDatas["serverinfopartinfo_uid_{$partType}_extra"] : null - ]; - $entity = parent::create($serverPartFormDatas); - //부품정보 정의 - $partEntity = $this->getPartService()->getEntity($entity->getPartInfoUID()); - if ($partEntity) { - $entity->setPartEntity($partEntity); + foreach (SERVER['PARTTYPES'] as $partType) { + $serverPartFormDatas = []; + $serverPartFormDatas["partinfo_uid"] = $formDatas["partinfo_uid_{$partType}"]; + $serverPartFormDatas["serverinfo_uid"] = $serverEntity->getPK(); + $serverPartFormDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID(); + $serverPartFormDatas["type"] = $partType; + $serverPartFormDatas["billing"] = array_key_exists("serverinfopartinfo_uid_{$partType}_billing", $formDatas) ? $formDatas["serverinfopartinfo_uid_{$partType}_billing"] : null; + $serverPartFormDatas["amount"] = array_key_exists("serverinfopartinfo_uid_{$partType}_amount", $formDatas) ? $formDatas["serverinfopartinfo_uid_{$partType}_amount"] : 0; + $serverPartFormDatas["cnt"] = array_key_exists("serverinfopartinfo_uid_{$partType}_cnt", $formDatas) ? $formDatas["serverinfopartinfo_uid_{$partType}_cnt"] : null; + $serverPartFormDatas["extra"] = array_key_exists("serverinfopartinfo_uid_{$partType}_extra", $formDatas) ? $formDatas["serverinfopartinfo_uid_{$partType}_extra"] : null; + $entity = parent::create($serverPartFormDatas); + //부품정보 정의 + $partEntity = $this->getPartService()->getEntity($entity->getPartInfoUID()); + if ($partEntity) { + $entity->setPartEntity($partEntity); + } } return $entity; } - //생성 - public function createByServer(ServerEntity $serverEntity, array $formDatas): array - { - $entities = []; - foreach (SERVER['PARTTYPES'] as $partType) { - //파트정보 선택했는지 여부에따라 처리 - if (array_key_exists("partinfo_uid_{$partType}", $formDatas) && $formDatas["partinfo_uid_{$partType}"]) { - $entities[] = $this->createByServer_process($serverEntity, $partType, $formDatas); - } - } - return $entities; - } //수정 - public function modifyByServer(ServerEntity $serverEntity, array $formDatas): array + public function modifyByServer(ServerEntity $serverEntity, array $formDatas): ServerPartEntity + { + //삭제후생성 + $this->deleteByServer($serverEntity); + return $this->createByServer($serverEntity, $formDatas); + } + //삭제 + public function deleteByServer(ServerEntity $serverEntity): array { //기존 서벼별 부품연결정보 삭제 후 $entities = $this->getEntities(['serverinfo_uid' => $serverEntity->getPK()]); foreach ($entities as $entity) { $this->delete($entity); } - //서버별 부품연결정보 생성 - return $this->createByServer($serverEntity, $formDatas); + return $entities; } } diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index c2e10f7..914731c 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -4,12 +4,13 @@ namespace App\Services\Equipment; use App\Entities\Equipment\ServerEntity; use App\Models\Equipment\ServerModel; -use App\Models\Equipment\ServerPartModel; use App\Services\Equipment\EquipmentService; class ServerService extends EquipmentService { private ?ServerPartService $_serverPartService = null; + private ?IPService $_ipService = null; + private ?CSService $_csService = null; public function __construct() { parent::__construct(new ServerModel()); @@ -189,11 +190,14 @@ class ServerService extends EquipmentService { $entity = parent::create($formDatas); //ServerPart정보 생성 - foreach ($this->getServerPartService()->createByServer($entity, $formDatas) as $serverPartEntity) { - $entity->addServerPartEntity($serverPartEntity->getType(), $serverPartEntity); - }; + 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); @@ -203,7 +207,16 @@ class ServerService extends EquipmentService }; 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 diff --git a/app/Services/Equipment/SwitchService.php b/app/Services/Equipment/SwitchService.php index 0cf5c13..69568ee 100644 --- a/app/Services/Equipment/SwitchService.php +++ b/app/Services/Equipment/SwitchService.php @@ -31,22 +31,12 @@ class SwitchService extends EquipmentService ]; } public function getIndexFields(): array - { - return [ - 'code', - 'status', - 'clientinfo_uid', - 'serviceinfo_uid', - 'serverinfo_uid' - ]; - } - public function getIndexFilters(): array { return [ 'clientinfo_uid', 'serviceinfo_uid', 'serverinfo_uid', - 'status' + 'status', ]; } public function getBatchjobFields(): array diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 5abaa32..59cf13f 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -21,14 +21,14 @@ class UserService extends CommonService 'name', 'email', 'mobile', - 'role' + 'role', ]; } public function getFormFilters(): array { return [ 'role', - 'status' + 'status', ]; } public function getIndexFields(): array @@ -38,7 +38,8 @@ class UserService extends CommonService 'name', 'email', 'mobile', - 'role' + 'role', + 'status', ]; } public function getBatchjobFields(): array diff --git a/app/Traits/IPTrait.php b/app/Traits/IPTrait.php new file mode 100644 index 0000000..1b2bda2 --- /dev/null +++ b/app/Traits/IPTrait.php @@ -0,0 +1,25 @@ + getFieldForm("serverinfopartinfo_uid_{$partType}_extra", old("serverinfopartinfo_uid_{$partType}_extra") ?? ($viewDatas['control']['form_datas']["serverinfopartinfo_uid_{$partType}_extra"] ?? null), $viewDatas) ?> - ,금액 getFieldForm("serverinfopartinfo_uid_{$partType}_amount", old("serverinfopartinfo_uid_{$partType}_amount") ?? ($viewDatas['control']['form_datas']["serverinfopartinfo_uid_{$partType}_amount"] ?? null), $viewDatas) ?> - - - getFieldLabel("ipinfo_uid", lang("{$viewDatas['class_path']}.label.ipinfo_uid"), $viewDatas) ?> - - getFieldForm("ipinfo_uid", old("ipinfo_uid") ?? ($viewDatas['control']['form_datas']["ipinfo_uid"] ?? null), $viewDatas) ?> - ,금액 getFieldForm("ipinfo_uid_amount", old("ipinfo_uid_amount") ?? ($viewDatas['control']['form_datas']["ipinfo_uid_amount"] ?? null), $viewDatas) ?> - - - - getFieldLabel("csinfo_uid", lang("{$viewDatas['class_path']}.label.csinfo_uid"), $viewDatas) ?> - - getFieldForm("csinfo_uid", old("csinfo_uid") ?? ($viewDatas['control']['form_datas']["csinfo_uid"] ?? null), $viewDatas) ?> - ,금액 getFieldForm("csinfo_uid_amount", old("csinfo_uid_amount") ?? ($viewDatas['control']['form_datas']["csinfo_uid_amount"] ?? null), $viewDatas) ?> - - diff --git a/app/Views/admin/server/modify_form.php b/app/Views/admin/server/modify_form.php index 5ff75e5..601b9e8 100644 --- a/app/Views/admin/server/modify_form.php +++ b/app/Views/admin/server/modify_form.php @@ -35,29 +35,9 @@ getFieldForm("serverinfopartinfo_uid_{$partType}_extra", old("serverinfopartinfo_uid_{$partType}_extra") ?? ($viewDatas['entity']->getServerPartEntity($partType) ? $viewDatas['entity']->getServerPartEntity($partType)->getExtra() : ($viewDatas['control']['form_datas']["serverinfopartinfo_uid_{$partType}_extra"] ?? null)), $viewDatas) ?> - ,금액 getFieldForm("serverinfopartinfo_uid_{$partType}_amount", ($viewDatas['entity']->getServerPartEntity($partType) ? $viewDatas['entity']->getServerPartEntity($partType)->getAmount() : ($viewDatas['control']['form_datas']["serverinfopartinfo_uid_{$partType}_amount"] ?? null)), $viewDatas) ?> - - - getFieldLabel("ipinfo_uid", lang("{$viewDatas['class_path']}.label.ipinfo_uid"), $viewDatas) ?> - - getIPEntities() as $entity): ?> - getFieldForm("ipinfo_uid", old("ipinfo_uid") ?? ($viewDatas['control']['form_datas']["ipinfo_uid"] ?? null), $viewDatas) ?> - ,금액 getFieldForm("ipinfo_uid_amount", ($ipEntity ? $ipEntity->getAmount() : ($viewDatas['control']['form_datas']["ipinfo_amount"] ?? null)), $viewDatas) ?> - - - - - getFieldLabel("csinfo_uid", lang("{$viewDatas['class_path']}.label.csinfo_uid"), $viewDatas) ?> - - getCSEntities() as $entity): ?> - getFieldForm("csinfo_uid", old("csinfo_uid") ?? ($viewDatas['control']['form_datas']["csinfo_uid"] ?? null), $viewDatas) ?> - ,금액 getFieldForm("csinfo_uid_amount", ($entity ? $entity->getAmount() : ($viewDatas['control']['form_datas']["csinfo_amount"] ?? null)), $viewDatas) ?> - - - diff --git a/app/Views/templates/admin/index_content_top.php b/app/Views/templates/admin/index_content_top.php index 87095f0..88f6161 100644 --- a/app/Views/templates/admin/index_content_top.php +++ b/app/Views/templates/admin/index_content_top.php @@ -4,12 +4,12 @@