dbms_init...1

This commit is contained in:
choi.jh 2025-07-11 14:34:34 +09:00
parent b07ea18f34
commit 6f0792d53e
38 changed files with 276 additions and 217 deletions

View File

@ -100,17 +100,6 @@ class ServiceController extends CustomerController
parent::delete_process($entity); parent::delete_process($entity);
} }
//List 관련 //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 protected function index_process(): void
{ {
//서비스별 미납 Count //서비스별 미납 Count

View File

@ -35,10 +35,4 @@ class StorageController extends PartController
return $this->_helper; return $this->_helper;
} }
//Index,FieldForm관련 //Index,FieldForm관련
protected function setOrderByForList(): void
{
//OrderBy 처리
$this->getService()->getModel()->orderBy('model', 'ASC', false);
parent::setOrderByForList();
}
} }

View File

@ -14,6 +14,7 @@ use App\Services\UserService;
class UserController extends AdminController class UserController extends AdminController
{ {
private $_db;
private $_service = null; private $_service = null;
private $_helper = null; private $_helper = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
@ -23,7 +24,7 @@ class UserController extends AdminController
$this->class_path .= $this->getService()->getClassName(); $this->class_path .= $this->getService()->getClassName();
$this->uri_path .= strtolower($this->getService()->getClassName('/')) . '/'; $this->uri_path .= strtolower($this->getService()->getClassName('/')) . '/';
// $this->view_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR; // $this->view_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR;
$this->_db = \Config\Database::connect();
} }
final public function getService(): UserService final public function getService(): UserService
{ {
@ -119,7 +120,7 @@ class UserController extends AdminController
final public function profile_modify(int $uid): RedirectResponse|string final public function profile_modify(int $uid): RedirectResponse|string
{ {
//Transaction Start //Transaction Start
$this->getService()->getModel()->transStart(); $this->_db->transStart();
try { try {
//각 Field 초기화 //각 Field 초기화
$fields = [ $fields = [
@ -141,10 +142,10 @@ class UserController extends AdminController
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
} }
$this->entity = $this->profile_modify_process($entity, $formDatas); $this->entity = $this->profile_modify_process($entity, $formDatas);
$this->getService()->getModel()->transCommit(); $this->_db->transCommit();
return $this->getResultSuccess(); return $this->getResultSuccess();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->getService()->getModel()->transRollback(); $this->_db->transRollback();
return $this->getResultFail($e->getMessage()); return $this->getResultFail($e->getMessage());
} }
} }

View File

@ -13,12 +13,14 @@ use Psr\Log\LoggerInterface;
class Payment extends BaseController class Payment extends BaseController
{ {
private $_db;
private ?ServiceService $_serviceService = null; private ?ServiceService $_serviceService = null;
private ?ServiceItemService $_servicItemeService = null; private ?ServiceItemService $_servicItemeService = null;
private ?ServicePaymentService $_servicePaymentService = null; private ?ServicePaymentService $_servicePaymentService = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->_db = \Config\Database::connect();
} }
public function getServiceService(): ServiceService public function getServiceService(): ServiceService
{ {
@ -44,7 +46,7 @@ class Payment extends BaseController
public function billing(): void public function billing(): void
{ {
//Transaction Start //Transaction Start
$this->getServiceService()->getModel()->transStart(); $this->_db->transStart();
try { try {
//서비스중 결제일이 오늘이고, 상태가 사용중이 경우만 서비스 모두 연장처리 //서비스중 결제일이 오늘이고, 상태가 사용중이 경우만 서비스 모두 연장처리
$this->getServiceService()->extendBillingAt(date('Y-m-d'), DEFAULTS['STATUS']); $this->getServiceService()->extendBillingAt(date('Y-m-d'), DEFAULTS['STATUS']);
@ -62,10 +64,10 @@ class Payment extends BaseController
} }
// echo $this->getServiceService()->getModel()->getLastQuery() . "\n"; // echo $this->getServiceService()->getModel()->getLastQuery() . "\n";
log_message("notice", "Billing 작업을 완료하였습니다."); log_message("notice", "Billing 작업을 완료하였습니다.");
$this->getServiceService()->getModel()->transCommit(); $this->_db->transCommit();
} catch (\Exception $e) { } catch (\Exception $e) {
//Transaction Rollback //Transaction Rollback
$this->getServiceService()->getModel()->transRollback(); $this->_db->transRollback();
log_message( log_message(
"error", "error",
"Billing 작업을 실패하였습니다.\n--------------\n" . "Billing 작업을 실패하였습니다.\n--------------\n" .

View File

@ -21,6 +21,7 @@ use Psr\Log\LoggerInterface;
abstract class CommonController extends BaseController abstract class CommonController extends BaseController
{ {
private $_db;
private $_myAuth = null; private $_myAuth = null;
private ?MyLogService $_myLogService = null; private ?MyLogService $_myLogService = null;
private $_viewDatas = []; private $_viewDatas = [];
@ -37,6 +38,7 @@ abstract class CommonController extends BaseController
$this->myAuthName = $this->getMyAuth()->getNameByAuthInfo(); $this->myAuthName = $this->getMyAuth()->getNameByAuthInfo();
$this->myAuthUID = $this->getMyAuth()->getUIDByAuthInfo(); $this->myAuthUID = $this->getMyAuth()->getUIDByAuthInfo();
} }
$this->_db = \Config\Database::connect();
} }
final public function __get($name) final public function __get($name)
{ {
@ -316,7 +318,7 @@ abstract class CommonController extends BaseController
} }
final public function create(): RedirectResponse|string final public function create(): RedirectResponse|string
{ {
$this->getService()->getModel()->transStart(); $this->_db->transStart();
try { try {
//각 Field 초기화 //각 Field 초기화
$this->initAction(__FUNCTION__); $this->initAction(__FUNCTION__);
@ -327,10 +329,10 @@ abstract class CommonController extends BaseController
} }
// dd($formDatas); // dd($formDatas);
$this->create_process($formDatas); $this->create_process($formDatas);
$this->getService()->getModel()->transCommit(); $this->_db->transCommit();
return $this->getResultSuccess(); return $this->getResultSuccess();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->getService()->getModel()->transRollback(); $this->_db->transRollback();
return $this->getResultFail($e->getMessage()); return $this->getResultFail($e->getMessage());
} }
} }
@ -369,7 +371,7 @@ abstract class CommonController extends BaseController
final public function modify(int $uid): RedirectResponse|string final public function modify(int $uid): RedirectResponse|string
{ {
//Transaction Start //Transaction Start
$this->getService()->getModel()->transStart(); $this->_db->transStart();
try { try {
//각 Field 초기화 //각 Field 초기화
$this->initAction(__FUNCTION__); $this->initAction(__FUNCTION__);
@ -384,10 +386,10 @@ abstract class CommonController extends BaseController
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
} }
$this->modify_process($entity, $formDatas); $this->modify_process($entity, $formDatas);
$this->getService()->getModel()->transCommit(); $this->_db->transCommit();
return $this->getResultSuccess(); return $this->getResultSuccess();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->getService()->getModel()->transRollback(); $this->_db->transRollback();
return $this->getResultFail($e->getMessage()); return $this->getResultFail($e->getMessage());
} }
} }
@ -401,7 +403,7 @@ abstract class CommonController extends BaseController
final public function toggle(mixed $uid, string $field): RedirectResponse|string final public function toggle(mixed $uid, string $field): RedirectResponse|string
{ {
//Transaction Start //Transaction Start
$this->getService()->getModel()->transStart(); $this->_db->transStart();
try { try {
//각 Field 초기화:조건항목 Field는 한개만 존재하므로 Field와 Rule을 정의 //각 Field 초기화:조건항목 Field는 한개만 존재하므로 Field와 Rule을 정의
$this->setAction(__FUNCTION__); $this->setAction(__FUNCTION__);
@ -415,10 +417,10 @@ abstract class CommonController extends BaseController
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
} }
$this->toggle_process($entity, $formDatas); $this->toggle_process($entity, $formDatas);
$this->getService()->getModel()->transCommit(); $this->_db->transCommit();
return $this->getResultSuccess(); return $this->getResultSuccess();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->getService()->getModel()->transRollback(); $this->_db->transRollback();
return $this->getResultFail($e->getMessage()); return $this->getResultFail($e->getMessage());
} }
} }
@ -442,7 +444,7 @@ abstract class CommonController extends BaseController
final public function batchjob(): RedirectResponse|string final public function batchjob(): RedirectResponse|string
{ {
//Transaction Start //Transaction Start
$this->getService()->getModel()->transStart(); $this->_db->transStart();
try { try {
$selectedFields = []; $selectedFields = [];
//getBatchJobFields를 이용해서 선택된 Field 와 값정의 //getBatchJobFields를 이용해서 선택된 Field 와 값정의
@ -469,11 +471,11 @@ abstract class CommonController extends BaseController
$this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field)); $this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field));
} }
$this->batchjob_process($uids, $formDatas); $this->batchjob_process($uids, $formDatas);
$this->getService()->getModel()->transCommit(); $this->_db->transCommit();
LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄작업을 완료하였습니다.", __METHOD__, count($uids), count($this->entities))); LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄작업을 완료하였습니다.", __METHOD__, count($uids), count($this->entities)));
return $this->getResultSuccess(); return $this->getResultSuccess();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->getService()->getModel()->transRollback(); $this->_db->transRollback();
return $this->getResultFail($e->getMessage()); return $this->getResultFail($e->getMessage());
} }
} }
@ -486,7 +488,7 @@ abstract class CommonController extends BaseController
final public function delete(mixed $uid): RedirectResponse|string final public function delete(mixed $uid): RedirectResponse|string
{ {
//Transaction Start //Transaction Start
$this->getService()->getModel()->transStart(); $this->_db->transStart();
try { try {
//각 Field 초기화:삭제는 다른 초기화 필요없음 //각 Field 초기화:삭제는 다른 초기화 필요없음
$this->setAction(__FUNCTION__); $this->setAction(__FUNCTION__);
@ -496,10 +498,10 @@ abstract class CommonController extends BaseController
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
} }
$this->delete_process($entity); $this->delete_process($entity);
$this->getService()->getModel()->transCommit(); $this->_db->transCommit();
return $this->getResultSuccess(); return $this->getResultSuccess();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->getService()->getModel()->transRollback(); $this->_db->transRollback();
return $this->getResultFail($e->getMessage()); return $this->getResultFail($e->getMessage());
} }
} }
@ -521,7 +523,7 @@ abstract class CommonController extends BaseController
final public function batchjob_delete(): RedirectResponse|string final public function batchjob_delete(): RedirectResponse|string
{ {
//Transaction Start //Transaction Start
$this->getService()->getModel()->transStart(); $this->_db->transStart();
try { try {
//변경할 UIDS //변경할 UIDS
$uids = $this->request->getPost('batchjob_uids[]'); $uids = $this->request->getPost('batchjob_uids[]');
@ -531,11 +533,11 @@ abstract class CommonController extends BaseController
//각 Field 초기화:삭제는 다른 초기화 필요없음 //각 Field 초기화:삭제는 다른 초기화 필요없음
$this->setAction(__FUNCTION__); $this->setAction(__FUNCTION__);
$this->batchjob_delete_process($uids); $this->batchjob_delete_process($uids);
$this->getService()->getModel()->transCommit(); $this->_db->transCommit();
LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄삭제를 완료하였습니다.", __METHOD__, count($uids), count($this->entities))); LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄삭제를 완료하였습니다.", __METHOD__, count($uids), count($this->entities)));
return $this->getResultSuccess(); return $this->getResultSuccess();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->getService()->getModel()->transRollback(); $this->_db->transRollback();
return $this->getResultFail($e->getMessage()); return $this->getResultFail($e->getMessage());
} }
} }
@ -579,19 +581,19 @@ abstract class CommonController extends BaseController
foreach ($this->getFilterFields() as $field) { foreach ($this->getFilterFields() as $field) {
$filter_value = $this->getFilterValues($field); $filter_value = $this->getFilterValues($field);
if ($filter_value !== null && $filter_value !== '') { 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'); $this->word = $this->request->getVar('word');
if ($this->word !== null && $this->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->start = $this->request->getVar('start');
$this->end = $this->request->getVar('end'); $this->end = $this->request->getVar('end');
if ($this->start !== null && $this->start !== '' && $this->end !== null && $this->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 처리 //PageNation 처리
@ -613,7 +615,6 @@ abstract class CommonController extends BaseController
// 2.app/Config/Pager.php/$templates에 'bootstrap_full => 'Pagers\bootstrap_full', // 2.app/Config/Pager.php/$templates에 'bootstrap_full => 'Pagers\bootstrap_full',
// 'bootstrap_simple' => 'Pagers\bootstrap_simple', 추가 // 'bootstrap_simple' => 'Pagers\bootstrap_simple', 추가
$pager = service("pager"); $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); $pager->makeLinks($this->page, $this->per_page, $this->total_count, $template, $segment, $pager_group);
$this->page = $pager->getCurrentPage($pager_group); $this->page = $pager->getCurrentPage($pager_group);
$this->total_page = $pager->getPageCount($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_field = $this->request->getVar('order_field');
$this->order_value = $this->request->getVar('order_value'); $this->order_value = $this->request->getVar('order_value');
if ($this->order_field !== null && $this->order_field !== '') { 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()->setLimit($this->per_page);
$this->getService()->getModel()->offset(($this->page - 1) * $this->per_page); $this->getService()->setOffset(($this->page - 1) * $this->per_page);
$this->entities = $this->getService()->getEntities(); $this->entities = $this->getService()->getEntities();
} }
public function index(): RedirectResponse|string public function index(): RedirectResponse|string
@ -648,7 +649,7 @@ abstract class CommonController extends BaseController
//조건절 처리 //조건절 처리
$this->setConditionForList(); $this->setConditionForList();
//TotalCount (SoftDelete적용이 되려면 countAllResults를 사용해야함) //TotalCount (SoftDelete적용이 되려면 countAllResults를 사용해야함)
$this->total_count = $this->getService()->getModel()->selectCount('*', 'cnt')->countAllResults(); $this->total_count = $this->getService()->getTotalCount();
//Pagination 처리 //Pagination 처리
$this->pagination = $this->getPaginationForList(); $this->pagination = $this->getPaginationForList();
//줄수 처리용 //줄수 처리용

View File

@ -49,8 +49,6 @@ abstract class GoogleSocket extends MySocket
//이미 등록된 사용자인지 확인 후 없으면 등록 처리리 //이미 등록된 사용자인지 확인 후 없으면 등록 처리리
$entity = $this->getService()->getEntity([Model::SITE => $this->getSite(), 'id' => $id], false); $entity = $this->getService()->getEntity([Model::SITE => $this->getSite(), 'id' => $id], false);
if (!$entity) { if (!$entity) {
//Transaction Start
$this->getService()->getModel()->transStart();
try { try {
//없다면 새로 등록 //없다면 새로 등록
$formDatas = [ $formDatas = [
@ -62,10 +60,8 @@ abstract class GoogleSocket extends MySocket
'status' => 'unuse', 'status' => 'unuse',
]; ];
$entity = $this->getService()->create($formDatas); $entity = $this->getService()->create($formDatas);
$this->getService()->getModel()->transCommit();
} catch (\Exception $e) { } catch (\Exception $e) {
//Transaction Rollback //Transaction Rollback
$this->getService()->getModel()->transRollback();
log_message("error", $e->getMessage()); log_message("error", $e->getMessage());
throw new \Exception(__FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage()); throw new \Exception(__FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
} }

View File

@ -213,29 +213,11 @@ abstract class CommonModel extends Model
//List 검색용 //List 검색용
//FormFilter 조건절 처리 //FormFilter 조건절 처리
public function setList_FormFilter(string $field, mixed $filter_value): void final public function setList_FormFilter(string $field, mixed $filter_value): void {}
{
switch ($field) {
default:
//일반검색
$this->where("{$this->getTable()}.{$field}", $filter_value);
break;
}
}
//검색어조건절처리 //검색어조건절처리
public function setList_WordFilter(string $word): void final public function setList_WordFilter(string $word): void {}
{
$this->orLike($this->getTable() . "." . $this->getTitleField(), $word, 'both');
}
//날자검색 //날자검색
public function setList_DateFilter(string $start, string $end): void final 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));
}
//OrderBy 처리 //OrderBy 처리
public function setOrderBy(string $field, $value): void final public function setOrderBy(string $field, $value): void {}
{
$this->orderBy(sprintf("%s.%s %s", $this->getTable(), $field, $value ?: "DESC"));
}
} }

View File

@ -45,10 +45,4 @@ class AccountModel extends CustomerModel
} }
return $rule; return $rule;
} }
//List 검색용
public function setList_WordFilter(string $word): void
{
$this->orLike(self::TABLE . '.alias', $word, 'both');
parent::setList_WordFilter($word);
}
} }

View File

@ -58,26 +58,4 @@ class ClientModel extends CustomerModel
} }
return $rule; 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);
}
} }

View File

@ -62,11 +62,4 @@ class ServicePaymentModel extends CustomerModel
} }
return $rule; return $rule;
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->orderBy('billing_at', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -40,11 +40,4 @@ class CodeModel extends EquipmentModel
} }
return $rule; return $rule;
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->getModel()->orderBy('code', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -40,11 +40,4 @@ class CpuModel extends PartModel
} }
return $rule; return $rule;
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->orderBy('model', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -51,11 +51,4 @@ class DefenceModel extends PartModel
} }
return $rule; return $rule;
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->orderBy('INET_ATON(ip)', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -40,11 +40,4 @@ class DomainModel extends PartModel
} }
return $rule; return $rule;
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->orderBy('domain', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -44,11 +44,4 @@ class IpModel extends PartModel
} }
return $rule; return $rule;
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->orderBy('INET_ATON(ip)', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -41,11 +41,4 @@ class RamModel extends PartModel
} }
return $rule; return $rule;
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->getModel()->orderBy('model', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -45,11 +45,4 @@ class SoftwareModel extends PartModel
} }
return $rule; return $rule;
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->getModel()->orderBy('model', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -41,11 +41,4 @@ class ServerModel extends EquipmentModel
} }
return $rule; return $rule;
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->getModel()->orderBy('model', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -41,11 +41,4 @@ class SwitchModel extends EquipmentModel
} }
return $rule; return $rule;
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->getModel()->orderBy('code', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -40,10 +40,4 @@ class MyLogModel extends CommonModel
} }
return $rule; 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');
}
} }

View File

@ -70,26 +70,4 @@ class UserModel extends CommonModel
} }
return $convertedData; 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');
}
} }

View File

@ -43,7 +43,7 @@ abstract class CommonService
{ {
return implode($delimeter, $this->_classNames); return implode($delimeter, $this->_classNames);
} }
final public function getModel(): mixed final protected function getModel(): mixed
{ {
if (!$this->_model) { if (!$this->_model) {
$this->_model = $this->getModelClass(); $this->_model = $this->getModelClass();
@ -52,11 +52,21 @@ abstract class CommonService
} }
final public function getEntity(mixed $where, ?string $message = null): mixed final public function getEntity(mixed $where, ?string $message = null): mixed
{ {
$entity = is_array($where) ? $this->getModel()->where($where)->first() : $this->getModel()->find($where); try {
if (!$entity) { $entity = is_array($where) ? $this->getModel()->where($where)->first() : $this->getModel()->find($where);
throw new \Exception($message ?? __METHOD__ . "에서 해당 정보가 존재하지 않습니다"); 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 protected function findAllDatas(array $columns = ['*']): mixed
{ {
@ -64,18 +74,43 @@ abstract class CommonService
} }
final public function getEntities(mixed $where = null, array $columns = ['*']): array final public function getEntities(mixed $where = null, array $columns = ['*']): array
{ {
if ($where) { try {
$this->getModel()->where($where); 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;
}
if (env('app.debug.index')) {
echo $this->getModel()->getLastQuery() . "<BR>";
}
return $entities;
} // } //
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;
}
//기본 기능부분 //기본 기능부분
//FieldForm관련용 //FieldForm관련용
@ -134,4 +169,46 @@ abstract class CommonService
LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["DELETED"] . ":"); LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["DELETED"] . ":");
return $entity; 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"));
}
} }

View File

@ -62,4 +62,10 @@ class AccountService extends CustomerService
$this->setBalance($formDatas); $this->setBalance($formDatas);
return parent::create($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);
}
} }

View File

@ -110,4 +110,26 @@ class ClientService extends CustomerService
} }
return parent::modify($entity, $formDatas); 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);
}
} }

View File

@ -105,4 +105,11 @@ class ServicePaymentService extends CustomerService
$this->modify($entity, ['ownerinfo_uid' => $ownerinfo_uid]); $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);
}
} }

View File

@ -225,4 +225,14 @@ class ServiceService extends CustomerService
} }
return parent::delete($entity); 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);
}
}
} }

View File

@ -50,4 +50,11 @@ class CodeService extends EquipmentService
} }
return $this->getModel()->modify($entity, ['status' => $status]); 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);
}
} }

View File

@ -39,4 +39,11 @@ class CpuService extends PartService
{ {
return ['model', 'status']; return ['model', 'status'];
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->getModel()->orderBy('model', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -43,4 +43,11 @@ class DefenceService extends PartService
{ {
return ['type', 'ip', 'accountid', 'domain', 'status']; 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);
}
} }

View File

@ -40,4 +40,11 @@ class DomainService extends PartService
{ {
return ['domain', 'status']; return ['domain', 'status'];
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->getModel()->orderBy('domain', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -84,4 +84,11 @@ class IpService extends PartService
} }
return $this->getModel()->modify($entity, ['status' => $status]); 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);
}
} }

View File

@ -39,4 +39,11 @@ class RamService extends PartService
{ {
return ['model', 'status']; return ['model', 'status'];
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->getModel()->orderBy('model', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -41,4 +41,11 @@ class SoftwareService extends PartService
{ {
return ['type', 'model', 'status']; return ['type', 'model', 'status'];
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->getModel()->orderBy('model', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -39,4 +39,11 @@ class StorageService extends PartService
{ {
return ['model', 'status']; return ['model', 'status'];
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->getModel()->orderBy('model', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -41,4 +41,11 @@ class ServerService extends EquipmentService
{ {
return ['model', 'status']; return ['model', 'status'];
} }
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->getModel()->orderBy('model', 'ASC', false);
parent::setOrderBy($field, $value);
}
} }

View File

@ -50,4 +50,11 @@ class SwitchService extends EquipmentService
} }
return $this->getModel()->modify($entity, ['status' => $status]); 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);
}
} }

View File

@ -81,4 +81,10 @@ class MyLogService extends CommonService
LogCollector::clear(); LogCollector::clear();
return $this->create($formDatas); 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');
}
} }

View File

@ -61,4 +61,26 @@ class UserService extends CommonService
// die(var_export($formDatas, true)); // die(var_export($formDatas, true));
return parent::modify($entity, $formDatas); 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');
}
} }