trafficmonitor init...2

This commit is contained in:
choi.jh 2025-11-12 11:03:09 +09:00
parent b0e304592a
commit c18a8bb859
8 changed files with 169 additions and 214 deletions

View File

@ -9,6 +9,7 @@ use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\RedirectResponse;
use App\Entities\CommonEntity;
use App\Controllers\CommonController;
use App\DTOs\CommonDTO;
use CodeIgniter\Validation\Exceptions\ValidationException;
use CodeIgniter\HTTP\DownloadResponse;
use PhpOffice\PhpSpreadsheet\IOFactory;
@ -18,15 +19,24 @@ use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
abstract class AdminController extends CommonController
{
public const PATH = 'admin';
private ?string $_title = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->addActionPaths(self::PATH);
}
abstract protected function createDTO(array $formDatas): CommonDTO;
final protected function getLayout(): string
{
return 'admin';
}
protected function getTitle(): string
{
if ($this->_title === null) {
$this->_title = lang("{$this->service->getClassPaths()}.title");
}
return $this->_title;
}
protected function action_init_process(string $action): void
{
$this->addViewDatas('layout', $this->getLayout());
@ -39,101 +49,117 @@ abstract class AdminController extends CommonController
$this->addViewDatas('index_batchjobButtions', $this->service->getFormService()->getBatchjobButtons());
parent::action_init_process($action);
}
abstract protected function create_form_process(): void;
final public function create_form(): string
protected function create_form_process(array $formDatas = []): array
{
$action = __FUNCTION__;
try {
//초기화
$this->action_init_process($action);
$this->create_form_process();
} catch (\Exception $e) {
log_message('error', $e->getMessage());
session()->setFlashdata('message', $e->getMessage());
}
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
//Form Default값 설정
return $formDatas;
}
final public function create_form(): string|RedirectResponse
{
try {
$action = __FUNCTION__;
$this->action_init_process($action);
$formDatas = $this->create_form_process();
$this->addViewDatas('formDatas', $formDatas);
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
} catch (\Exception $e) {
return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성폼 오류:" . $e->getMessage());
}
}
protected function create_process(): CommonEntity
{
//요청 데이터를 DTO 객체로 변환
$dto = $this->createDTO($this->request->getPost());
return $this->service->create($dto);
}
abstract protected function create_process(): array;
final public function create(): string|RedirectResponse
{
$action = __FUNCTION__;
try {
//초기화
$this->action_init_process($action);
list($entity, $message) = $this->create_process();
return $this->action_modal_process($message);
$this->action_init_process(__FUNCTION__);
$entity = $this->create_process();
return $this->action_modal_process("{$this->getTitle()}에서 생성이 완료되었습니다.");
} catch (ValidationException $e) {
// 검증 실패 시 폼으로 돌아가서 오류 메시지 표시
log_message('error', $e->getMessage());
return redirect()->back()->withInput()->with('message', $e->getMessage());
return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 검증오류:" . $e->getMessage());
} catch (\Exception $e) {
log_message('error', $e->getMessage());
return redirect()->back()->withInput()->with('message', $e->getMessage());
return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 오류:" . $e->getMessage());
}
}
abstract protected function modify_form_process($uid): void;
final public function modify_form($uid): string
protected function modify_form_process($uid): CommonEntity
{
$action = __FUNCTION__;
try {
//초기화
$this->action_init_process($action);
$this->modify_form_process($uid);
} catch (\Exception $e) {
log_message('error', $e->getMessage());
session()->setFlashdata('message', $e->getMessage());
if (!$uid) {
throw new \Exception("{$this->getTitle()}에 번호가 정의 되지 않았습니다.");
}
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
$entity = $this->service->getEntity($uid);
if (!$entity instanceof CommonEntity) {
throw new \Exception("{$uid}에 해당하는 {$this->getTitle()}을 찾을수 없습니다.");
}
return $entity;
}
final public function modify_form($uid): string|RedirectResponse
{
try {
$action = __FUNCTION__;
$this->action_init_process($action);
$entity = $this->modify_form_process($uid);
$this->addViewDatas('entity', $entity);
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
} catch (\Exception $e) {
return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정폼 오류:" . $e->getMessage());
}
}
protected function modify_process($uid): CommonEntity
{
//요청 데이터를 DTO 객체로 변환
$dto = $this->createDTO($this->request->getPost());
return $this->service->modify($uid, $dto);
}
abstract protected function modify_process($uid): array;
final public function modify($uid): string|RedirectResponse
{
$action = __FUNCTION__;
try {
//초기화
$this->action_init_process($action);
list($entity, $message) = $this->modify_process($uid);
return $this->action_modal_process($message);
$this->action_init_process(__FUNCTION__);
$entity = $this->modify_process($uid);
return $this->action_modal_process("{$this->getTitle()}에서 {$uid} 수정이 완료되었습니다.");
} catch (ValidationException $e) {
// 검증 실패 시 폼으로 돌아가서 오류 메시지 표시
log_message('error', $e->getMessage());
return redirect()->back()->withInput()->with('message', $e->getMessage());
return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage());
} catch (\Exception $e) {
log_message('error', $e->getMessage());
return redirect()->back()->withInput()->with('message', $e->getMessage());
return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage());
}
}
abstract protected function delete_process($uid): array;
protected function delete_process($uid): CommonEntity
{
return $this->service->delete($uid);
}
final public function delete($uid): RedirectResponse
{
$action = __FUNCTION__;
try {
list($entity, $message) = $this->delete_process($uid);
$redirect_url = $this->getAuthContext()->popPreviousUrl() ?? implode(DIRECTORY_SEPARATOR, $this->getActionPaths());
return redirect()->to($redirect_url)->with('message', $message);
} catch (ValidationException $e) {
// 검증 실패 시 폼으로 돌아가서 오류 메시지 표시
log_message('error', $e->getMessage());
return redirect()->back()->withInput()->with('message', $e->getMessage());
$entity = $this->delete_process($uid);
return $this->action_redirect_process('info', "{$this->getTitle()}에서 {$entity->getTitle()} 삭제가 완료되었습니다.");
} catch (\Exception $e) {
log_message('error', $e->getMessage());
return redirect()->back()->withInput()->with('message', $e->getMessage());
return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage());
}
}
abstract protected function view_process($uid): CommonEntity;
final public function view($uid): string
protected function view_process($uid): CommonEntity
{
if (!$uid) {
throw new \Exception("{$this->getTitle()}에 번호가 정의 되지 않았습니다.");
}
$entity = $this->service->getEntity($uid);
if (!$entity instanceof CommonEntity) {
throw new \Exception("{$uid}에 해당하는 {$this->getTitle()}을 찾을수 없습니다.");
}
return $entity;
}
final public function view($uid): string|RedirectResponse
{
$action = __FUNCTION__;
try {
//초기화
$action = __FUNCTION__;
$this->action_init_process($action);
$entity = $this->view_process($uid);
$this->addViewDatas('entity', $entity);
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
} catch (\Exception $e) {
log_message('error', $e->getMessage());
session()->setFlashdata('message', $e->getMessage());
return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 상세보기 오류:" . $e->getMessage());
}
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
}
//리스트관련
//조건절 처리

View File

@ -19,6 +19,10 @@ class CollectorController extends AdminController
}
$this->addActionPaths($this::PATH);
}
protected function createDTO(array $formDatas): CollectorDTO
{
return parent::createDTO($formDatas);
}
protected function action_init_process(string $action): void
{
$fields = ['trafficinfo_uid', 'in', 'out', 'raw_in', 'raw_out',];
@ -47,52 +51,24 @@ class CollectorController extends AdminController
$this->service->getFormService()->setBatchjobFilters($filters);
parent::action_init_process($action);
}
//Action작업관련
protected function create_form_process(): void
protected function create_process(): CollectorEntity
{
//Form Default값 설정
$formDatas = [];
$this->addViewDatas('formDatas', $formDatas);
return parent::create_process();
}
protected function create_process(): array
protected function modify_form_process($uid): CollectorEntity
{
//요청 데이터를 DTO 객체로 변환
$dto = new CollectorDTO($this->request->getPost());
$entity = $this->service->create($dto);
return array($entity, "{$entity->getTitle()} 수집정보 생성이 완료되었습니다.");
return parent::modify_form_process($uid);
}
protected function modify_form_process($uid): void
protected function modify_process($uid): CollectorEntity
{
if (!$uid) {
throw new \Exception("수집정보 번호가 정의 되지 않았습니다.");
}
$entity = $this->service->getEntity($uid);
if (!$entity instanceof CollectorEntity) {
throw new \Exception("{$uid}에 해당하는 수집정보를 찾을수 없습니다.");
}
$this->addViewDatas('entity', $entity);
return parent::modify_process($uid);
}
protected function modify_process($uid): array
protected function delete_process($uid): CollectorEntity
{
//요청 데이터를 DTO 객체로 변환
$dto = new CollectorDTO($this->request->getPost());
$entity = $this->service->modify($uid, $dto);
return array($entity, "{$entity->getTitle()} 수집정보 수정이 완료되었습니다.");
}
protected function delete_process($uid): array
{
$entity = $this->service->delete($uid);
return array($entity, "{$entity->getTitle()} 수집정보 삭제 완료되었습니다.");
return parent::delete_process($uid);
}
protected function view_process($uid): CollectorEntity
{
if (!$uid) {
throw new \Exception("수집정보 번호가 정의 되지 않았습니다.");
}
$entity = $this->service->getEntity($uid);
if (!$entity instanceof CollectorEntity) {
throw new \Exception("{$uid}에 해당하는 수집정보를 찾을수 없습니다.");
}
return $entity;
return parent::view_process($uid);
}
}

View File

@ -19,6 +19,10 @@ class MylogController extends AdminController
}
$this->addActionPaths($this::PATH);
}
protected function createDTO(array $formDatas): MylogDTO
{
return parent::createDTO($formDatas);
}
protected function action_init_process(string $action): void
{
$fields = ['title', 'content'];
@ -47,52 +51,24 @@ class MylogController extends AdminController
$this->service->getFormService()->setBatchjobFilters($filters);
parent::action_init_process($action);
}
//Action작업관련
protected function create_form_process(): void
protected function create_process(): MylogEntity
{
//Form Default값 설정
$formDatas = [];
$this->addViewDatas('formDatas', $formDatas);
return parent::create_process();
}
protected function create_process(): array
protected function modify_form_process($uid): MylogEntity
{
//요청 데이터를 DTO 객체로 변환
$dto = new MylogDTO($this->request->getPost());
$entity = $this->service->create($dto);
return array($entity, "{$entity->getTitle()} 로그 생성이 완료되었습니다.");
return parent::modify_form_process($uid);
}
protected function modify_form_process($uid): void
protected function modify_process($uid): MylogEntity
{
if (!$uid) {
throw new \Exception("로그 번호가 정의 되지 않았습니다.");
}
$entity = $this->service->getEntity($uid);
if (!$entity instanceof MylogEntity) {
throw new \Exception("{$uid}에 해당하는 로그를 찾을수 없습니다.");
}
$this->addViewDatas('entity', $entity);
return parent::modify_process($uid);
}
protected function modify_process($uid): array
protected function delete_process($uid): MylogEntity
{
//요청 데이터를 DTO 객체로 변환
$dto = new MylogDTO($this->request->getPost());
$entity = $this->service->modify($uid, $dto);
return array($entity, "{$entity->getTitle()} 로그 수정이 완료되었습니다.");
}
protected function delete_process($uid): array
{
$entity = $this->service->delete($uid);
return array($entity, "{$entity->getTitle()} 로그정보 삭제 완료되었습니다.");
return parent::delete_process($uid);
}
protected function view_process($uid): MylogEntity
{
if (!$uid) {
throw new \Exception("로그정보 번호가 정의 되지 않았습니다.");
}
$entity = $this->service->getEntity($uid);
if (!$entity instanceof MylogEntity) {
throw new \Exception("{$uid}에 해당하는 로그정보를 찾을수 없습니다.");
}
return $entity;
return parent::view_process($uid);
}
}

View File

@ -19,6 +19,10 @@ class TrafficController extends AdminController
}
$this->addActionPaths($this::PATH);
}
protected function createDTO(array $formDatas): TrafficDTO
{
return parent::createDTO($formDatas);
}
protected function action_init_process(string $action): void
{
$fields = ['client', 'switch', 'ip', 'interface', 'status'];
@ -46,52 +50,24 @@ class TrafficController extends AdminController
$this->service->getFormService()->setBatchjobFilters($filters);
parent::action_init_process($action);
}
//Action작업관련
protected function create_form_process(): void
protected function create_process(): TrafficEntity
{
//Form Default값 설정
$formDatas = [];
$this->addViewDatas('formDatas', $formDatas);
return parent::create_process();
}
protected function create_process(): array
protected function modify_form_process($uid): TrafficEntity
{
//요청 데이터를 DTO 객체로 변환
$dto = new TrafficDTO($this->request->getPost());
$entity = $this->service->create($dto);
return array($entity, "{$entity->getTitle()} 트래픽정보 생성이 완료되었습니다.");
return parent::modify_form_process($uid);
}
protected function modify_form_process($uid): void
protected function modify_process($uid): TrafficEntity
{
if (!$uid) {
throw new \Exception("트래픽정보 번호가 정의 되지 않았습니다.");
}
$entity = $this->service->getEntity($uid);
if (!$entity instanceof TrafficEntity) {
throw new \Exception("{$uid}에 해당하는 트래픽정보를 찾을수 없습니다.");
}
$this->addViewDatas('entity', $entity);
return parent::modify_process($uid);
}
protected function modify_process($uid): array
protected function delete_process($uid): TrafficEntity
{
//요청 데이터를 DTO 객체로 변환
$dto = new TrafficDTO($this->request->getPost());
$entity = $this->service->modify($uid, $dto);
return array($entity, "{$entity->getTitle()} 트래픽정보 수정이 완료되었습니다.");
}
protected function delete_process($uid): array
{
$entity = $this->service->delete($uid);
return array($entity, "{$entity->getTitle()} 트래픽정보 삭제 완료되었습니다.");
return parent::delete_process($uid);
}
protected function view_process($uid): TrafficEntity
{
if (!$uid) {
throw new \Exception("트래픽정보 번호가 정의 되지 않았습니다.");
}
$entity = $this->service->getEntity($uid);
if (!$entity instanceof TrafficEntity) {
throw new \Exception("{$uid}에 해당하는 트래픽정보를 찾을수 없습니다.");
}
return $entity;
return parent::view_process($uid);
}
}

View File

@ -19,6 +19,10 @@ class UserController extends AdminController
}
$this->addActionPaths($this::PATH);
}
protected function createDTO(array $formDatas): UserDTO
{
return parent::createDTO($formDatas);
}
//Action작업관련
protected function action_init_process(string $action): void
{
@ -47,51 +51,29 @@ class UserController extends AdminController
$this->service->getFormService()->setBatchjobFilters($filters);
parent::action_init_process($action);
}
protected function create_form_process(): void
protected function create_form_process(array $formDatas = []): array
{
//Form Default값 설정
$formDatas = ['role' => [ROLE['USER']['MANAGER']]];
$this->addViewDatas('formDatas', $formDatas);
return parent::create_form_process($formDatas);
}
protected function create_process(): array
protected function create_process(): UserEntity
{
//요청 데이터를 DTO 객체로 변환
$dto = new UserDTO($this->request->getPost());
$entity = $this->service->create($dto);
return array($entity, "{$entity->getTitle()} 계정 생성이 완료되었습니다.");
return parent::create_process();
}
protected function modify_form_process($uid): void
protected function modify_form_process($uid): UserEntity
{
if (!$uid) {
throw new \Exception("계정 번호가 정의 되지 않았습니다.");
}
$entity = $this->service->getEntity($uid);
if (!$entity instanceof UserEntity) {
throw new \Exception("{$uid}에 해당하는 계정을 찾을수 없습니다.");
}
$this->addViewDatas('entity', $entity);
return parent::modify_form_process($uid);
}
protected function modify_process($uid): array
protected function modify_process($uid): UserEntity
{
//요청 데이터를 DTO 객체로 변환
$dto = new UserDTO($this->request->getPost());
$entity = $this->service->modify($uid, $dto);
return array($entity, "{$entity->getTitle()} 계정 수정이 완료되었습니다.");
return parent::modify_process($uid);
}
protected function delete_process($uid): array
protected function delete_process($uid): UserEntity
{
$entity = $this->service->delete($uid);
return array($entity, "{$entity->getTitle()} 계정 삭제 완료되었습니다.");
return parent::delete_process($uid);
}
protected function view_process($uid): UserEntity
{
if (!$uid) {
throw new \Exception("계정 번호가 정의 되지 않았습니다.");
}
$entity = $this->service->getEntity($uid);
if (!$entity instanceof UserEntity) {
throw new \Exception("{$uid}에 해당하는 계정을 찾을수 없습니다.");
}
return $entity;
return parent::view_process($uid);
}
}

View File

@ -80,9 +80,27 @@ abstract class CommonController extends BaseController
</script>
";
}
protected function action_redirect_process(string $redirect_url, string $message): RedirectResponse
protected function action_redirect_process(string $type, string $message, ?string $redirect_url = null): RedirectResponse
{
return redirect()->to($redirect_url)->with('message', $message);
switch ($type) {
case 'warning':
case 'error':
case 'critical':
case 'alert':
case 'emergency':
log_message($type, $message);
$result = $redirect_url ? $result = redirect()->to($redirect_url)->with('message', $message) : redirect()->back()->withInput()->with('message', $message);
break;
case 'debug':
case 'info':
case 'notice':
default:
log_message($type, $message);
$redirect_url = $redirect_url ?? $this->getAuthContext()->popPreviousUrl() ?? implode(DIRECTORY_SEPARATOR, $this->getActionPaths());
$result = redirect()->to($redirect_url)->with('message', $message);
break;
}
return $result;
}
protected function action_render_process(array $view_paths, string $view_file, array $viewDatas): string
{

View File

@ -192,7 +192,12 @@ abstract class CommonService
if (!$entity instanceof CommonEntity) {
throw new \Exception(__METHOD__ . "에서 오류발생: {$uid}에 해당하는 정보을 찾을수 없습니다.");
}
$result = $this->model->delete($uid);
return $entity;
}
final public function delete($uid): CommonEntity
{
$entity = $this->delete_process($uid);
$result = $this->model->delete($entity->getPK());
if ($result === false) {
$errors = $this->model->errors();
$errorMsg = is_array($errors) ? implode(", ", $errors) : "모델 삭제 작업이 실패했습니다.";
@ -200,10 +205,6 @@ abstract class CommonService
}
return $entity;
}
final public function delete($uid): CommonEntity
{
return $this->delete_process($uid);
}
//Index용
final public function getTotalCount(): int
{