From 6f0792d53e961c833ce4899ef4e568c608c34915 Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Fri, 11 Jul 2025 14:34:34 +0900 Subject: [PATCH] dbms_init...1 --- .../Admin/Customer/ServiceController.php | 11 -- .../Equipment/Part/StorageController.php | 6 - app/Controllers/Admin/UserController.php | 9 +- app/Controllers/CLI/Payment.php | 8 +- app/Controllers/CommonController.php | 53 ++++----- .../MySocket/GoogleSocket/GoogleSocket.php | 4 - app/Models/CommonModel.php | 26 +---- app/Models/Customer/AccountModel.php | 6 - app/Models/Customer/ClientModel.php | 22 ---- app/Models/Customer/ServicePaymentModel.php | 7 -- app/Models/Equipment/CodeModel.php | 7 -- app/Models/Equipment/Part/CpuModel.php | 7 -- app/Models/Equipment/Part/DefenceModel.php | 7 -- app/Models/Equipment/Part/DomainModel.php | 7 -- app/Models/Equipment/Part/IpModel.php | 7 -- app/Models/Equipment/Part/RamModel.php | 7 -- app/Models/Equipment/Part/SoftwareModel.php | 7 -- app/Models/Equipment/ServerModel.php | 7 -- app/Models/Equipment/SwitchModel.php | 7 -- app/Models/MyLogModel.php | 6 - app/Models/UserModel.php | 22 ---- app/Services/CommonService.php | 107 +++++++++++++++--- app/Services/Customer/AccountService.php | 6 + app/Services/Customer/ClientService.php | 22 ++++ .../Customer/ServicePaymentService.php | 7 ++ app/Services/Customer/ServiceService.php | 10 ++ app/Services/Equipment/CodeService.php | 7 ++ app/Services/Equipment/Part/CpuService.php | 7 ++ .../Equipment/Part/DefenceService.php | 7 ++ app/Services/Equipment/Part/DomainService.php | 7 ++ app/Services/Equipment/Part/IpService.php | 7 ++ app/Services/Equipment/Part/RamService.php | 7 ++ .../Equipment/Part/SoftwareService.php | 7 ++ .../Equipment/Part/StorageService.php | 7 ++ app/Services/Equipment/ServerService.php | 7 ++ app/Services/Equipment/SwitchService.php | 7 ++ app/Services/MyLogService.php | 6 + app/Services/UserService.php | 22 ++++ 38 files changed, 276 insertions(+), 217 deletions(-) diff --git a/app/Controllers/Admin/Customer/ServiceController.php b/app/Controllers/Admin/Customer/ServiceController.php index 76f1eca..95e20aa 100644 --- a/app/Controllers/Admin/Customer/ServiceController.php +++ b/app/Controllers/Admin/Customer/ServiceController.php @@ -100,17 +100,6 @@ class ServiceController extends CustomerController parent::delete_process($entity); } //List 관련 - protected function setWordConditionForList(): void - { - $this->word = $this->request->getVar('word'); - if ($this->word !== null && $this->word !== '') { - if ($this->getHelper()->isIPAddress($this->word, 'ipv4')) { - $this->getService()->setSearchIp($this->word); - } else { - $this->getService()->getModel()->setList_WordFilter($this->word); - } - } - } protected function index_process(): void { //서비스별 미납 Count diff --git a/app/Controllers/Admin/Equipment/Part/StorageController.php b/app/Controllers/Admin/Equipment/Part/StorageController.php index 29eca95..e4fc128 100644 --- a/app/Controllers/Admin/Equipment/Part/StorageController.php +++ b/app/Controllers/Admin/Equipment/Part/StorageController.php @@ -35,10 +35,4 @@ class StorageController extends PartController return $this->_helper; } //Index,FieldForm관련 - protected function setOrderByForList(): void - { - //OrderBy 처리 - $this->getService()->getModel()->orderBy('model', 'ASC', false); - parent::setOrderByForList(); - } } diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index d423087..9e0cf70 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -14,6 +14,7 @@ use App\Services\UserService; class UserController extends AdminController { + private $_db; private $_service = null; private $_helper = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) @@ -23,7 +24,7 @@ class UserController extends AdminController $this->class_path .= $this->getService()->getClassName(); $this->uri_path .= strtolower($this->getService()->getClassName('/')) . '/'; // $this->view_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR; - + $this->_db = \Config\Database::connect(); } final public function getService(): UserService { @@ -119,7 +120,7 @@ class UserController extends AdminController final public function profile_modify(int $uid): RedirectResponse|string { //Transaction Start - $this->getService()->getModel()->transStart(); + $this->_db->transStart(); try { //각 Field 초기화 $fields = [ @@ -141,10 +142,10 @@ class UserController extends AdminController throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } $this->entity = $this->profile_modify_process($entity, $formDatas); - $this->getService()->getModel()->transCommit(); + $this->_db->transCommit(); return $this->getResultSuccess(); } catch (\Exception $e) { - $this->getService()->getModel()->transRollback(); + $this->_db->transRollback(); return $this->getResultFail($e->getMessage()); } } diff --git a/app/Controllers/CLI/Payment.php b/app/Controllers/CLI/Payment.php index af4de16..21281e9 100644 --- a/app/Controllers/CLI/Payment.php +++ b/app/Controllers/CLI/Payment.php @@ -13,12 +13,14 @@ use Psr\Log\LoggerInterface; class Payment extends BaseController { + private $_db; private ?ServiceService $_serviceService = null; private ?ServiceItemService $_servicItemeService = null; private ?ServicePaymentService $_servicePaymentService = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); + $this->_db = \Config\Database::connect(); } public function getServiceService(): ServiceService { @@ -44,7 +46,7 @@ class Payment extends BaseController public function billing(): void { //Transaction Start - $this->getServiceService()->getModel()->transStart(); + $this->_db->transStart(); try { //서비스중 결제일이 오늘이고, 상태가 사용중이 경우만 서비스 모두 연장처리 $this->getServiceService()->extendBillingAt(date('Y-m-d'), DEFAULTS['STATUS']); @@ -62,10 +64,10 @@ class Payment extends BaseController } // echo $this->getServiceService()->getModel()->getLastQuery() . "\n"; log_message("notice", "Billing 작업을 완료하였습니다."); - $this->getServiceService()->getModel()->transCommit(); + $this->_db->transCommit(); } catch (\Exception $e) { //Transaction Rollback - $this->getServiceService()->getModel()->transRollback(); + $this->_db->transRollback(); log_message( "error", "Billing 작업을 실패하였습니다.\n--------------\n" . diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 8eff49b..e47b44b 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -21,6 +21,7 @@ use Psr\Log\LoggerInterface; abstract class CommonController extends BaseController { + private $_db; private $_myAuth = null; private ?MyLogService $_myLogService = null; private $_viewDatas = []; @@ -37,6 +38,7 @@ abstract class CommonController extends BaseController $this->myAuthName = $this->getMyAuth()->getNameByAuthInfo(); $this->myAuthUID = $this->getMyAuth()->getUIDByAuthInfo(); } + $this->_db = \Config\Database::connect(); } final public function __get($name) { @@ -316,7 +318,7 @@ abstract class CommonController extends BaseController } final public function create(): RedirectResponse|string { - $this->getService()->getModel()->transStart(); + $this->_db->transStart(); try { //각 Field 초기화 $this->initAction(__FUNCTION__); @@ -327,10 +329,10 @@ abstract class CommonController extends BaseController } // dd($formDatas); $this->create_process($formDatas); - $this->getService()->getModel()->transCommit(); + $this->_db->transCommit(); return $this->getResultSuccess(); } catch (\Exception $e) { - $this->getService()->getModel()->transRollback(); + $this->_db->transRollback(); return $this->getResultFail($e->getMessage()); } } @@ -369,7 +371,7 @@ abstract class CommonController extends BaseController final public function modify(int $uid): RedirectResponse|string { //Transaction Start - $this->getService()->getModel()->transStart(); + $this->_db->transStart(); try { //각 Field 초기화 $this->initAction(__FUNCTION__); @@ -384,10 +386,10 @@ abstract class CommonController extends BaseController throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } $this->modify_process($entity, $formDatas); - $this->getService()->getModel()->transCommit(); + $this->_db->transCommit(); return $this->getResultSuccess(); } catch (\Exception $e) { - $this->getService()->getModel()->transRollback(); + $this->_db->transRollback(); return $this->getResultFail($e->getMessage()); } } @@ -401,7 +403,7 @@ abstract class CommonController extends BaseController final public function toggle(mixed $uid, string $field): RedirectResponse|string { //Transaction Start - $this->getService()->getModel()->transStart(); + $this->_db->transStart(); try { //각 Field 초기화:조건항목 Field는 한개만 존재하므로 Field와 Rule을 정의 $this->setAction(__FUNCTION__); @@ -415,10 +417,10 @@ abstract class CommonController extends BaseController throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } $this->toggle_process($entity, $formDatas); - $this->getService()->getModel()->transCommit(); + $this->_db->transCommit(); return $this->getResultSuccess(); } catch (\Exception $e) { - $this->getService()->getModel()->transRollback(); + $this->_db->transRollback(); return $this->getResultFail($e->getMessage()); } } @@ -442,7 +444,7 @@ abstract class CommonController extends BaseController final public function batchjob(): RedirectResponse|string { //Transaction Start - $this->getService()->getModel()->transStart(); + $this->_db->transStart(); try { $selectedFields = []; //getBatchJobFields를 이용해서 선택된 Field 와 값정의 @@ -469,11 +471,11 @@ abstract class CommonController extends BaseController $this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field)); } $this->batchjob_process($uids, $formDatas); - $this->getService()->getModel()->transCommit(); + $this->_db->transCommit(); LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄작업을 완료하였습니다.", __METHOD__, count($uids), count($this->entities))); return $this->getResultSuccess(); } catch (\Exception $e) { - $this->getService()->getModel()->transRollback(); + $this->_db->transRollback(); return $this->getResultFail($e->getMessage()); } } @@ -486,7 +488,7 @@ abstract class CommonController extends BaseController final public function delete(mixed $uid): RedirectResponse|string { //Transaction Start - $this->getService()->getModel()->transStart(); + $this->_db->transStart(); try { //각 Field 초기화:삭제는 다른 초기화 필요없음 $this->setAction(__FUNCTION__); @@ -496,10 +498,10 @@ abstract class CommonController extends BaseController throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } $this->delete_process($entity); - $this->getService()->getModel()->transCommit(); + $this->_db->transCommit(); return $this->getResultSuccess(); } catch (\Exception $e) { - $this->getService()->getModel()->transRollback(); + $this->_db->transRollback(); return $this->getResultFail($e->getMessage()); } } @@ -521,7 +523,7 @@ abstract class CommonController extends BaseController final public function batchjob_delete(): RedirectResponse|string { //Transaction Start - $this->getService()->getModel()->transStart(); + $this->_db->transStart(); try { //변경할 UIDS $uids = $this->request->getPost('batchjob_uids[]'); @@ -531,11 +533,11 @@ abstract class CommonController extends BaseController //각 Field 초기화:삭제는 다른 초기화 필요없음 $this->setAction(__FUNCTION__); $this->batchjob_delete_process($uids); - $this->getService()->getModel()->transCommit(); + $this->_db->transCommit(); LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄삭제를 완료하였습니다.", __METHOD__, count($uids), count($this->entities))); return $this->getResultSuccess(); } catch (\Exception $e) { - $this->getService()->getModel()->transRollback(); + $this->_db->transRollback(); return $this->getResultFail($e->getMessage()); } } @@ -579,19 +581,19 @@ abstract class CommonController extends BaseController foreach ($this->getFilterFields() as $field) { $filter_value = $this->getFilterValues($field); if ($filter_value !== null && $filter_value !== '') { - $this->getService()->getModel()->setList_FormFilter($field, $filter_value); + $this->getService()->setList_FormFilter($field, $filter_value); } } //검색어조건절 처리 $this->word = $this->request->getVar('word'); if ($this->word !== null && $this->word !== '') { - $this->getService()->getModel()->setList_WordFilter($this->word); + $this->getService()->setList_WordFilter($this->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()->getModel()->setList_DateFilter($this->start, $this->end); + $this->getService()->setList_DateFilter($this->start, $this->end); } } //PageNation 처리 @@ -613,7 +615,6 @@ abstract class CommonController extends BaseController // 2.app/Config/Pager.php/$templates에 'bootstrap_full => 'Pagers\bootstrap_full', // 'bootstrap_simple' => 'Pagers\bootstrap_simple', 추가 $pager = service("pager"); - // $this->getService()->getModel()->paginate($this->per_page, $pager_group, $this->page, $segment); $pager->makeLinks($this->page, $this->per_page, $this->total_count, $template, $segment, $pager_group); $this->page = $pager->getCurrentPage($pager_group); $this->total_page = $pager->getPageCount($pager_group); @@ -626,10 +627,10 @@ abstract class CommonController extends BaseController $this->order_field = $this->request->getVar('order_field'); $this->order_value = $this->request->getVar('order_value'); if ($this->order_field !== null && $this->order_field !== '') { - $this->getService()->getModel()->setOrderBy($this->order_field, $this->order_value); + $this->getService()->setOrderBy($this->order_field, $this->order_value); } - $this->getService()->getModel()->limit($this->per_page); - $this->getService()->getModel()->offset(($this->page - 1) * $this->per_page); + $this->getService()->setLimit($this->per_page); + $this->getService()->setOffset(($this->page - 1) * $this->per_page); $this->entities = $this->getService()->getEntities(); } public function index(): RedirectResponse|string @@ -648,7 +649,7 @@ abstract class CommonController extends BaseController //조건절 처리 $this->setConditionForList(); //TotalCount (SoftDelete적용이 되려면 countAllResults를 사용해야함) - $this->total_count = $this->getService()->getModel()->selectCount('*', 'cnt')->countAllResults(); + $this->total_count = $this->getService()->getTotalCount(); //Pagination 처리 $this->pagination = $this->getPaginationForList(); //줄수 처리용 diff --git a/app/Libraries/MySocket/GoogleSocket/GoogleSocket.php b/app/Libraries/MySocket/GoogleSocket/GoogleSocket.php index e099443..23c7a39 100644 --- a/app/Libraries/MySocket/GoogleSocket/GoogleSocket.php +++ b/app/Libraries/MySocket/GoogleSocket/GoogleSocket.php @@ -49,8 +49,6 @@ abstract class GoogleSocket extends MySocket //이미 등록된 사용자인지 확인 후 없으면 등록 처리리 $entity = $this->getService()->getEntity([Model::SITE => $this->getSite(), 'id' => $id], false); if (!$entity) { - //Transaction Start - $this->getService()->getModel()->transStart(); try { //없다면 새로 등록 $formDatas = [ @@ -62,10 +60,8 @@ abstract class GoogleSocket extends MySocket 'status' => 'unuse', ]; $entity = $this->getService()->create($formDatas); - $this->getService()->getModel()->transCommit(); } catch (\Exception $e) { //Transaction Rollback - $this->getService()->getModel()->transRollback(); log_message("error", $e->getMessage()); throw new \Exception(__FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage()); } diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index 90a77c2..4ef7686 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -213,29 +213,11 @@ abstract class CommonModel extends Model //List 검색용 //FormFilter 조건절 처리 - public function setList_FormFilter(string $field, mixed $filter_value): void - { - switch ($field) { - default: - //일반검색 - $this->where("{$this->getTable()}.{$field}", $filter_value); - break; - } - } + final public function setList_FormFilter(string $field, mixed $filter_value): void {} //검색어조건절처리 - public function setList_WordFilter(string $word): void - { - $this->orLike($this->getTable() . "." . $this->getTitleField(), $word, 'both'); - } + final public function setList_WordFilter(string $word): void {} //날자검색 - public function setList_DateFilter(string $start, string $end): void - { - $this->where(sprintf("%s.created_at >= '%s 00:00:00'", $this->getTable(), $start)); - $this->where(sprintf("%s.created_at <= '%s 23:59:59'", $this->getTable(), $end)); - } + final public function setList_DateFilter(string $start, string $end): void {} //OrderBy 처리 - public function setOrderBy(string $field, $value): void - { - $this->orderBy(sprintf("%s.%s %s", $this->getTable(), $field, $value ?: "DESC")); - } + final public function setOrderBy(string $field, $value): void {} } diff --git a/app/Models/Customer/AccountModel.php b/app/Models/Customer/AccountModel.php index 824568d..802be0e 100644 --- a/app/Models/Customer/AccountModel.php +++ b/app/Models/Customer/AccountModel.php @@ -45,10 +45,4 @@ class AccountModel extends CustomerModel } return $rule; } - //List 검색용 - public function setList_WordFilter(string $word): void - { - $this->orLike(self::TABLE . '.alias', $word, 'both'); - parent::setList_WordFilter($word); - } } diff --git a/app/Models/Customer/ClientModel.php b/app/Models/Customer/ClientModel.php index acfeb5c..ea81ed5 100644 --- a/app/Models/Customer/ClientModel.php +++ b/app/Models/Customer/ClientModel.php @@ -58,26 +58,4 @@ class ClientModel extends CustomerModel } return $rule; } - //Create용 - //FormFilter 조건절 처리 - public function setList_FormFilter(string $field, mixed $filter_value): void - { - switch ($field) { - case 'role': - $where = "FIND_IN_SET(" . $this->escape($filter_value) . ", {$this->getTable()}.{$field}) > 0"; - //FIND_IN_SET()은 MySQL 함수이므로 CodeIgniter가 이를 일반 컬럼명으로 착각하고 escape하게 되면 오류가 발생합니다. 따라서 ->where($sql, null, false)로 명시하여 escape를 꺼줘야 정상 작동 - $this->where($where, null, false); - break; - default: - parent::setList_FormFilter($field, $filter_value); - break; - } - } - //검색어조건절처리 - //List 검색용 - public function setList_WordFilter(string $word): void - { - $this->orLike(self::TABLE . '.email', $word, 'both'); - parent::setList_WordFilter($word); - } } diff --git a/app/Models/Customer/ServicePaymentModel.php b/app/Models/Customer/ServicePaymentModel.php index 1994124..7fa5916 100644 --- a/app/Models/Customer/ServicePaymentModel.php +++ b/app/Models/Customer/ServicePaymentModel.php @@ -62,11 +62,4 @@ class ServicePaymentModel extends CustomerModel } return $rule; } - //List 검색용 - //OrderBy 처리 - public function setOrderBy(string $field, $value): void - { - $this->orderBy('billing_at', 'ASC', false); - parent::setOrderBy($field, $value); - } } diff --git a/app/Models/Equipment/CodeModel.php b/app/Models/Equipment/CodeModel.php index 7172c43..b3ca413 100644 --- a/app/Models/Equipment/CodeModel.php +++ b/app/Models/Equipment/CodeModel.php @@ -40,11 +40,4 @@ class CodeModel extends EquipmentModel } return $rule; } - //List 검색용 - //OrderBy 처리 - public function setOrderBy(string $field, $value): void - { - $this->getModel()->orderBy('code', 'ASC', false); - parent::setOrderBy($field, $value); - } } diff --git a/app/Models/Equipment/Part/CpuModel.php b/app/Models/Equipment/Part/CpuModel.php index 6e34355..59f4cde 100644 --- a/app/Models/Equipment/Part/CpuModel.php +++ b/app/Models/Equipment/Part/CpuModel.php @@ -40,11 +40,4 @@ class CpuModel extends PartModel } return $rule; } - //List 검색용 - //OrderBy 처리 - public function setOrderBy(string $field, $value): void - { - $this->orderBy('model', 'ASC', false); - parent::setOrderBy($field, $value); - } } diff --git a/app/Models/Equipment/Part/DefenceModel.php b/app/Models/Equipment/Part/DefenceModel.php index 11f1b1c..bd561f2 100644 --- a/app/Models/Equipment/Part/DefenceModel.php +++ b/app/Models/Equipment/Part/DefenceModel.php @@ -51,11 +51,4 @@ class DefenceModel extends PartModel } return $rule; } - //List 검색용 - //OrderBy 처리 - public function setOrderBy(string $field, $value): void - { - $this->orderBy('INET_ATON(ip)', 'ASC', false); - parent::setOrderBy($field, $value); - } } diff --git a/app/Models/Equipment/Part/DomainModel.php b/app/Models/Equipment/Part/DomainModel.php index e4514f2..da47962 100644 --- a/app/Models/Equipment/Part/DomainModel.php +++ b/app/Models/Equipment/Part/DomainModel.php @@ -40,11 +40,4 @@ class DomainModel extends PartModel } return $rule; } - //List 검색용 - //OrderBy 처리 - public function setOrderBy(string $field, $value): void - { - $this->orderBy('domain', 'ASC', false); - parent::setOrderBy($field, $value); - } } diff --git a/app/Models/Equipment/Part/IpModel.php b/app/Models/Equipment/Part/IpModel.php index c7bbee5..2088b5d 100644 --- a/app/Models/Equipment/Part/IpModel.php +++ b/app/Models/Equipment/Part/IpModel.php @@ -44,11 +44,4 @@ class IpModel extends PartModel } return $rule; } - //List 검색용 - //OrderBy 처리 - public function setOrderBy(string $field, $value): void - { - $this->orderBy('INET_ATON(ip)', 'ASC', false); - parent::setOrderBy($field, $value); - } } diff --git a/app/Models/Equipment/Part/RamModel.php b/app/Models/Equipment/Part/RamModel.php index 3a7e9f5..5e0a085 100644 --- a/app/Models/Equipment/Part/RamModel.php +++ b/app/Models/Equipment/Part/RamModel.php @@ -41,11 +41,4 @@ class RamModel extends PartModel } return $rule; } - //List 검색용 - //OrderBy 처리 - public function setOrderBy(string $field, $value): void - { - $this->getModel()->orderBy('model', 'ASC', false); - parent::setOrderBy($field, $value); - } } diff --git a/app/Models/Equipment/Part/SoftwareModel.php b/app/Models/Equipment/Part/SoftwareModel.php index 4890fa9..f473147 100644 --- a/app/Models/Equipment/Part/SoftwareModel.php +++ b/app/Models/Equipment/Part/SoftwareModel.php @@ -45,11 +45,4 @@ class SoftwareModel extends PartModel } return $rule; } - //List 검색용 - //OrderBy 처리 - public function setOrderBy(string $field, $value): void - { - $this->getModel()->orderBy('model', 'ASC', false); - parent::setOrderBy($field, $value); - } } diff --git a/app/Models/Equipment/ServerModel.php b/app/Models/Equipment/ServerModel.php index ddb20f2..6962fc1 100644 --- a/app/Models/Equipment/ServerModel.php +++ b/app/Models/Equipment/ServerModel.php @@ -41,11 +41,4 @@ class ServerModel extends EquipmentModel } return $rule; } - //List 검색용 - //OrderBy 처리 - public function setOrderBy(string $field, $value): void - { - $this->getModel()->orderBy('model', 'ASC', false); - parent::setOrderBy($field, $value); - } } diff --git a/app/Models/Equipment/SwitchModel.php b/app/Models/Equipment/SwitchModel.php index 8860981..ebf8099 100644 --- a/app/Models/Equipment/SwitchModel.php +++ b/app/Models/Equipment/SwitchModel.php @@ -41,11 +41,4 @@ class SwitchModel extends EquipmentModel } return $rule; } - //List 검색용 - //OrderBy 처리 - public function setOrderBy(string $field, $value): void - { - $this->getModel()->orderBy('code', 'ASC', false); - parent::setOrderBy($field, $value); - } } diff --git a/app/Models/MyLogModel.php b/app/Models/MyLogModel.php index b08ec37..33d2c43 100644 --- a/app/Models/MyLogModel.php +++ b/app/Models/MyLogModel.php @@ -40,10 +40,4 @@ class MyLogModel extends CommonModel } return $rule; } - //List 검색용 - public function setList_WordFilter(string $word): void - { - $this->orLike(self::TABLE . "." . self::TITLE, $word, 'both'); - $this->orLike(self::TABLE . '.content', $word, 'both'); - } } diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index fc1d66e..719c418 100644 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -70,26 +70,4 @@ class UserModel extends CommonModel } return $convertedData; } - //List 검색용 - //FormFilter 조건절 처리 - public function setList_FormFilter(string $field, mixed $filter_value): void - { - switch ($field) { - case 'role': - $where = "FIND_IN_SET(" . $this->escape($filter_value) . ", {$this->getTable()}.{$field}) > 0"; - //FIND_IN_SET()은 MySQL 함수이므로 CodeIgniter가 이를 일반 컬럼명으로 착각하고 escape하게 되면 오류가 발생합니다. 따라서 ->where($sql, null, false)로 명시하여 escape를 꺼줘야 정상 작동 - $this->where($where, null, false); - break; - default: - parent::setList_FormFilter($field, $filter_value); - break; - } - } - //검색어조건절처리 - public function setList_WordFilter(string $word): void - { - $this->orLike(self::TABLE . '.id', $word, 'both'); - $this->orLike(self::TABLE . "." . self::TITLE, $word, 'both'); - $this->orLike(self::TABLE . '.email', $word, 'both'); - } } diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 10517f4..b0e6b49 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -43,7 +43,7 @@ abstract class CommonService { return implode($delimeter, $this->_classNames); } - final public function getModel(): mixed + final protected function getModel(): mixed { if (!$this->_model) { $this->_model = $this->getModelClass(); @@ -52,11 +52,21 @@ abstract class CommonService } final public function getEntity(mixed $where, ?string $message = null): mixed { - $entity = is_array($where) ? $this->getModel()->where($where)->first() : $this->getModel()->find($where); - if (!$entity) { - throw new \Exception($message ?? __METHOD__ . "에서 해당 정보가 존재하지 않습니다"); + try { + $entity = is_array($where) ? $this->getModel()->where($where)->first() : $this->getModel()->find($where); + if (!$entity) { + throw new \Exception($message ?? __METHOD__ . "에서 해당 정보가 존재하지 않습니다"); + } + return $entity; + } catch (\Exception $e) { + $message = sprintf( + "\n------%s SQL오류-----\n%s\n------------------------------\n", + __FUNCTION__, + $this->getModel()->getLastQuery() + ); + LogCollector::error($message); + throw new \Exception($message); } - return $entity; } protected function findAllDatas(array $columns = ['*']): mixed { @@ -64,18 +74,43 @@ abstract class CommonService } final public function getEntities(mixed $where = null, array $columns = ['*']): array { - if ($where) { - $this->getModel()->where($where); + try { + if ($where) { + $this->getModel()->where($where); + } + $entities = []; + foreach ($this->findAllDatas($columns) as $entity) { + $entities[$entity->getPK()] = $entity; + } + return $entities; + } catch (\Exception $e) { + $message = sprintf( + "\n------%s SQL오류-----\n%s\n------------------------------\n", + __FUNCTION__, + $this->getModel()->getLastQuery() + ); + LogCollector::error($message); + throw new \Exception($message); } - $entities = []; - foreach ($this->findAllDatas($columns) as $entity) { - $entities[$entity->getPK()] = $entity; + } // + 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; } - if (env('app.debug.index')) { - echo $this->getModel()->getLastQuery() . "
"; - } - return $entities; - } // + return $result; + } //기본 기능부분 //FieldForm관련용 @@ -134,4 +169,46 @@ abstract class CommonService LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["DELETED"] . ":"); return $entity; } + + //List 검색용 + 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 setList_FormFilter(string $field, mixed $filter_value): void + { + switch ($field) { + default: + //일반검색 + $this->getModel()->where("{$this->getModel()->getTable()}.{$field}", $filter_value); + break; + } + } + //검색어조건절처리 + public function setList_WordFilter(string $word): void + { + $this->getModel()->orLike($this->getModel()->getTable() . "." . $this->getModel()->getTitleField(), $word, 'both'); + } + //날자검색 + public function setList_DateFilter(string $start, string $end): void + { + $this->getModel()->where(sprintf("%s.created_at >= '%s 00:00:00'", $this->getModel()->getTable(), $start)); + $this->getModel()->where(sprintf("%s.created_at <= '%s 23:59:59'", $this->getModel()->getTable(), $end)); + } + //OrderBy 처리 + public function setOrderBy(string $field, $value): void + { + $this->getModel()->orderBy(sprintf("%s.%s %s", $this->getModel()->getTable(), $field, $value ?: "DESC")); + } } diff --git a/app/Services/Customer/AccountService.php b/app/Services/Customer/AccountService.php index deb977d..bc0d76d 100644 --- a/app/Services/Customer/AccountService.php +++ b/app/Services/Customer/AccountService.php @@ -62,4 +62,10 @@ class AccountService extends CustomerService $this->setBalance($formDatas); return parent::create($formDatas); } + //List 검색용 + public function setList_WordFilter(string $word): void + { + $this->getModel()->orLike($this->getModel()->getTable() . '.alias', $word, 'both'); + parent::setList_WordFilter($word); + } } diff --git a/app/Services/Customer/ClientService.php b/app/Services/Customer/ClientService.php index 6b8e1ae..031d003 100644 --- a/app/Services/Customer/ClientService.php +++ b/app/Services/Customer/ClientService.php @@ -110,4 +110,26 @@ class ClientService extends CustomerService } return parent::modify($entity, $formDatas); } + + //List 검색용 + //FormFilter 조건절 처리 + public function setList_FormFilter(string $field, mixed $filter_value): void + { + switch ($field) { + case 'role': + $where = "FIND_IN_SET(" . $this->getModel()->escape($filter_value) . ", {$this->getModel()->getTable()}.{$field}) > 0"; + //FIND_IN_SET()은 MySQL 함수이므로 CodeIgniter가 이를 일반 컬럼명으로 착각하고 escape하게 되면 오류가 발생합니다. 따라서 ->where($sql, null, false)로 명시하여 escape를 꺼줘야 정상 작동 + $this->getModel()->where($where, null, false); + break; + default: + parent::setList_FormFilter($field, $filter_value); + break; + } + } + //검색어조건절처리 + public function setList_WordFilter(string $word): void + { + $this->getModel()->orLike($this->getModel()->getTable() . '.email', $word, 'both'); + parent::setList_WordFilter($word); + } } diff --git a/app/Services/Customer/ServicePaymentService.php b/app/Services/Customer/ServicePaymentService.php index 883cccb..461cdaa 100644 --- a/app/Services/Customer/ServicePaymentService.php +++ b/app/Services/Customer/ServicePaymentService.php @@ -105,4 +105,11 @@ class ServicePaymentService extends CustomerService $this->modify($entity, ['ownerinfo_uid' => $ownerinfo_uid]); } } + //List 검색용 + //OrderBy 처리 + public function setOrderBy(string $field, $value): void + { + $this->getModel()->orderBy('billing_at', 'ASC', false); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index 0011a46..ab64f29 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -225,4 +225,14 @@ class ServiceService extends CustomerService } return parent::delete($entity); } + //List 검색용 + //검색어조건절처리 + public function setList_WordFilter(string $word): void + { + if ($this->isIPAddress($word, 'ipv4')) { + $this->setSearchIp($word); + } else { + parent::setList_WordFilter($word); + } + } } diff --git a/app/Services/Equipment/CodeService.php b/app/Services/Equipment/CodeService.php index 4ff2519..70209d9 100644 --- a/app/Services/Equipment/CodeService.php +++ b/app/Services/Equipment/CodeService.php @@ -50,4 +50,11 @@ class CodeService extends EquipmentService } return $this->getModel()->modify($entity, ['status' => $status]); } + //List 검색용 + //OrderBy 처리 + public function setOrderBy(string $field, $value): void + { + $this->getModel()->orderBy('code', 'ASC', false); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Equipment/Part/CpuService.php b/app/Services/Equipment/Part/CpuService.php index 8b97546..78f8095 100644 --- a/app/Services/Equipment/Part/CpuService.php +++ b/app/Services/Equipment/Part/CpuService.php @@ -39,4 +39,11 @@ class CpuService extends PartService { return ['model', 'status']; } + //List 검색용 + //OrderBy 처리 + public function setOrderBy(string $field, $value): void + { + $this->getModel()->orderBy('model', 'ASC', false); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Equipment/Part/DefenceService.php b/app/Services/Equipment/Part/DefenceService.php index 7345f22..e1dfbdf 100644 --- a/app/Services/Equipment/Part/DefenceService.php +++ b/app/Services/Equipment/Part/DefenceService.php @@ -43,4 +43,11 @@ class DefenceService extends PartService { return ['type', 'ip', 'accountid', 'domain', 'status']; } + //List 검색용 + //OrderBy 처리 + public function setOrderBy(string $field, $value): void + { + $this->getModel()->orderBy('INET_ATON(ip)', 'ASC', false); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Equipment/Part/DomainService.php b/app/Services/Equipment/Part/DomainService.php index 5c65815..edd27a0 100644 --- a/app/Services/Equipment/Part/DomainService.php +++ b/app/Services/Equipment/Part/DomainService.php @@ -40,4 +40,11 @@ class DomainService extends PartService { return ['domain', 'status']; } + //List 검색용 + //OrderBy 처리 + public function setOrderBy(string $field, $value): void + { + $this->getModel()->orderBy('domain', 'ASC', false); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Equipment/Part/IpService.php b/app/Services/Equipment/Part/IpService.php index 36f29e2..5a1fe72 100644 --- a/app/Services/Equipment/Part/IpService.php +++ b/app/Services/Equipment/Part/IpService.php @@ -84,4 +84,11 @@ class IpService extends PartService } return $this->getModel()->modify($entity, ['status' => $status]); } + //List 검색용 + //OrderBy 처리 + public function setOrderBy(string $field, $value): void + { + $this->getModel()->orderBy('INET_ATON(ip)', 'ASC', false); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Equipment/Part/RamService.php b/app/Services/Equipment/Part/RamService.php index 7019e69..be53f13 100644 --- a/app/Services/Equipment/Part/RamService.php +++ b/app/Services/Equipment/Part/RamService.php @@ -39,4 +39,11 @@ class RamService extends PartService { return ['model', 'status']; } + //List 검색용 + //OrderBy 처리 + public function setOrderBy(string $field, $value): void + { + $this->getModel()->orderBy('model', 'ASC', false); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Equipment/Part/SoftwareService.php b/app/Services/Equipment/Part/SoftwareService.php index 13a8117..9c8a996 100644 --- a/app/Services/Equipment/Part/SoftwareService.php +++ b/app/Services/Equipment/Part/SoftwareService.php @@ -41,4 +41,11 @@ class SoftwareService extends PartService { return ['type', 'model', 'status']; } + //List 검색용 + //OrderBy 처리 + public function setOrderBy(string $field, $value): void + { + $this->getModel()->orderBy('model', 'ASC', false); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Equipment/Part/StorageService.php b/app/Services/Equipment/Part/StorageService.php index 578f458..0017ea8 100644 --- a/app/Services/Equipment/Part/StorageService.php +++ b/app/Services/Equipment/Part/StorageService.php @@ -39,4 +39,11 @@ class StorageService extends PartService { return ['model', 'status']; } + //List 검색용 + //OrderBy 처리 + public function setOrderBy(string $field, $value): void + { + $this->getModel()->orderBy('model', 'ASC', false); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index 895b96b..88a0d99 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -41,4 +41,11 @@ class ServerService extends EquipmentService { return ['model', 'status']; } + //List 검색용 + //OrderBy 처리 + public function setOrderBy(string $field, $value): void + { + $this->getModel()->orderBy('model', 'ASC', false); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Equipment/SwitchService.php b/app/Services/Equipment/SwitchService.php index 35ccfa3..01b87fc 100644 --- a/app/Services/Equipment/SwitchService.php +++ b/app/Services/Equipment/SwitchService.php @@ -50,4 +50,11 @@ class SwitchService extends EquipmentService } return $this->getModel()->modify($entity, ['status' => $status]); } + //List 검색용 + //OrderBy 처리 + public function setOrderBy(string $field, $value): void + { + $this->getModel()->orderBy('code', 'ASC', false); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/MyLogService.php b/app/Services/MyLogService.php index b2ef938..6300eed 100644 --- a/app/Services/MyLogService.php +++ b/app/Services/MyLogService.php @@ -81,4 +81,10 @@ class MyLogService extends CommonService LogCollector::clear(); return $this->create($formDatas); } + //List 검색용 + public function setList_WordFilter(string $word): void + { + $this->getModel()->orLike($this->getModel()::TABLE . "." . $this->getModel()::TITLE, $word, 'both'); + $this->getModel()->orLike($this->getModel()::TABLE . '.content', $word, 'both'); + } } diff --git a/app/Services/UserService.php b/app/Services/UserService.php index f5c72dc..071e617 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -61,4 +61,26 @@ class UserService extends CommonService // die(var_export($formDatas, true)); return parent::modify($entity, $formDatas); } + //List 검색용 + //FormFilter 조건절 처리 + public function setList_FormFilter(string $field, mixed $filter_value): void + { + switch ($field) { + case 'role': + $where = "FIND_IN_SET(" . $this->getModel()->escape($filter_value) . ", {$this->getModel()->getTable()}.{$field}) > 0"; + //FIND_IN_SET()은 MySQL 함수이므로 CodeIgniter가 이를 일반 컬럼명으로 착각하고 escape하게 되면 오류가 발생합니다. 따라서 ->where($sql, null, false)로 명시하여 escape를 꺼줘야 정상 작동 + $this->getModel()->where($where, null, false); + break; + default: + parent::setList_FormFilter($field, $filter_value); + break; + } + } + //검색어조건절처리 + public function setList_WordFilter(string $word): void + { + $this->getModel()->orLike($this->getModel()->getTable() . '.id', $word, 'both'); + $this->getModel()->orLike($this->getModel()->getTable() . "." . $this->getModel()::TITLE, $word, 'both'); + $this->getModel()->orLike($this->getModel()->getTable() . '.email', $word, 'both'); + } }