trafficmonitor init...2

This commit is contained in:
choi.jh 2025-11-17 12:46:48 +09:00
parent c8aee38ff5
commit 3f171c19a6
2 changed files with 153 additions and 101 deletions

View File

@ -139,20 +139,23 @@ abstract class CommonController extends BaseController
helper(['form', __FUNCTION__]); helper(['form', __FUNCTION__]);
return view($full_path . DIRECTORY_SEPARATOR . $view_file, ['viewDatas' => $view_datas]); return view($full_path . DIRECTORY_SEPARATOR . $view_file, ['viewDatas' => $view_datas]);
} }
//생성
protected function create_form_process(array $formDatas = []): array protected function create_form_process(array $formDatas = []): array
{ {
//Form Default값 설정 //Form Default값 설정
return $formDatas; return $formDatas;
} }
protected function create_form_result_process(string $action): string|RedirectResponse
{
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
}
final public function create_form(): string|RedirectResponse final public function create_form(): string|RedirectResponse
{ {
try { try {
$action = __FUNCTION__; $action = __FUNCTION__;
$this->action_init_process($action); $this->action_init_process($action);
$formDatas = $this->create_form_process(); $this->addViewDatas('formDatas', $this->create_form_process());
$this->addViewDatas('formDatas', $formDatas); return $this->create_form_result_process($action);
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성폼 오류:" . $e->getMessage()); return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성폼 오류:" . $e->getMessage());
} }
@ -163,18 +166,22 @@ abstract class CommonController extends BaseController
$dto = $this->service->createDTO($this->request->getPost()); $dto = $this->service->createDTO($this->request->getPost());
return $this->service->create($dto); return $this->service->create($dto);
} }
protected function create_result_process(CommonEntity $entity): string|RedirectResponse
{
return $this->action_modal_process("{$this->getTitle()}에서 {$entity->getTitle()} 생성이 완료되었습니다.");
}
final public function create(): string|RedirectResponse final public function create(): string|RedirectResponse
{ {
try { try {
$this->action_init_process(__FUNCTION__); $this->action_init_process(__FUNCTION__);
$entity = $this->create_process(); return $this->create_result_process($this->create_process());
return $this->action_modal_process("{$this->getTitle()}에서 생성이 완료되었습니다.");
} catch (ValidationException $e) { } catch (ValidationException $e) {
return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 검증오류:" . $e->getMessage()); return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 검증오류:" . $e->getMessage());
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 오류:" . $e->getMessage()); return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 오류:" . $e->getMessage());
} }
} }
//수정
protected function modify_form_process($uid): CommonEntity protected function modify_form_process($uid): CommonEntity
{ {
if (!$uid) { if (!$uid) {
@ -186,14 +193,17 @@ abstract class CommonController extends BaseController
} }
return $entity; return $entity;
} }
protected function modify_form_result_process(string $action): string|RedirectResponse
{
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
}
final public function modify_form($uid): string|RedirectResponse final public function modify_form($uid): string|RedirectResponse
{ {
try { try {
$action = __FUNCTION__; $action = __FUNCTION__;
$this->action_init_process($action); $this->action_init_process($action);
$entity = $this->modify_form_process($uid); $this->addViewDatas('entity', $this->modify_form_process($uid));
$this->addViewDatas('entity', $entity); return $this->modify_form_result_process($action);
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정폼 오류:" . $e->getMessage()); return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정폼 오류:" . $e->getMessage());
} }
@ -204,26 +214,27 @@ abstract class CommonController extends BaseController
$dto = $this->service->createDTO($this->request->getPost()); $dto = $this->service->createDTO($this->request->getPost());
return $this->service->modify($uid, $dto); return $this->service->modify($uid, $dto);
} }
protected function modify_result_process(CommonEntity $entity): string|RedirectResponse
{
return $this->action_modal_process("{$this->getTitle()}에서 {$entity->getTitle()} 수정이 완료되었습니다.");
}
final public function modify($uid): string|RedirectResponse final public function modify($uid): string|RedirectResponse
{ {
try { try {
$this->action_init_process(__FUNCTION__); $this->action_init_process(__FUNCTION__);
$entity = $this->modify_process($uid); return $this->modify_result_process($this->modify_process($uid));
return $this->action_modal_process("{$this->getTitle()}에서 {$uid} 수정이 완료되었습니다.");
} catch (ValidationException $e) { } catch (ValidationException $e) {
return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage()); return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage());
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage()); return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage());
} }
} }
protected function batchjob_process($uid, array $formDatas): CommonEntity //일괄처리
protected function batchjob_pre_process(array $postDatas = []): array
{ {
return $this->service->batchjob($uid, $formDatas); foreach ($this->request->getPost() as $field => $value) {
$postDatas[$field] = $value;
} }
final public function batchjob(): string|RedirectResponse
{
try {
$postDatas = $this->request->getPost();
//1. postDatas에서 선택된 uids 정보 추출 //1. postDatas에서 선택된 uids 정보 추출
$uids = []; $uids = [];
if (isset($postDatas['batchjob_uids'])) { if (isset($postDatas['batchjob_uids'])) {
@ -247,55 +258,70 @@ abstract class CommonController extends BaseController
} }
//4. 데이터가 있는 필드 추출 //4. 데이터가 있는 필드 추출
$selectedFields = array_keys($formDatas); $selectedFields = array_keys($formDatas);
return array($uids, $selectedFields, $formDatas);
}
protected function batchjob_process($uid, array $formDatas): CommonEntity
{
return $this->service->batchjob($uid, $formDatas);
}
protected function batchjob_result_process(array $uids, array $entities, array $errors): string|RedirectResponse
{
return $this->action_redirect_process('info', sprintf(
"%s에서 %s개 처리완료, %s개 오류, 총:%s개 수정이 완료되었습니다.",
$this->getTitle(),
count($entities),
count($errors),
count($uids)
));
}
final public function batchjob(): string|RedirectResponse
{
try {
//사전작업
list($uids, $selectedFields, $formDatas) = $this->batchjob_pre_process();
//초기화 //초기화
$this->service->getFormService()->setFormFields($selectedFields); $this->service->getFormService()->setFormFields($selectedFields);
$this->service->getFormService()->setFormRules(__FUNCTION__, $selectedFields); $this->service->getFormService()->setFormRules(__FUNCTION__, $selectedFields);
$this->service->getFormService()->setFormFilters($selectedFields); $this->service->getFormService()->setFormFilters($selectedFields);
$this->service->getFormService()->setFormOptions($selectedFields); $this->service->getFormService()->setFormOptions($selectedFields);
$entities = []; $entities = [];
$error = 0; $errors = [];
foreach ($uids as $uid) { foreach ($uids as $uid) {
try { try {
$entities[] = $this->batchjob_process($uid, $formDatas); $entities[] = $this->batchjob_process($uid, $formDatas);
} catch (ValidationException $e) { } catch (ValidationException $e) {
log_message('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage()); log_message('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage());
$error++; $errors[] = $e->getMessage();
} catch (\Exception $e) { } catch (\Exception $e) {
log_message('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage()); log_message('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage());
$error++; $errors[] = $e->getMessage();
} }
} }
return $this->action_redirect_process('info', sprintf( return $this->batchjob_result_process($uids, $entities, $errors);
"%s에서 %s개 처리완료, %s개 오류, 총:%s개 수정이 완료되었습니다.",
$this->getTitle(),
count($entities),
$error,
count($uids)
));
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄작업처리 오류:" . $e->getMessage()); return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄작업처리 오류:" . $e->getMessage());
} }
} }
//삭제
protected function delete_process($uid): CommonEntity protected function delete_process($uid): CommonEntity
{ {
return $this->service->delete($uid); return $this->service->delete($uid);
} }
protected function delete_result_process(CommonEntity $entity): string|RedirectResponse
{
return $this->action_redirect_process('info', "{$this->getTitle()}에서 {$entity->getTitle()} 삭제가 완료되었습니다.");
}
final public function delete($uid): RedirectResponse final public function delete($uid): RedirectResponse
{ {
try { try {
$entity = $this->delete_process($uid); return $this->delete_result_process($this->delete_process($uid));
return $this->action_redirect_process('info', "{$this->getTitle()}에서 {$entity->getTitle()} 삭제가 완료되었습니다.");
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage()); return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage());
} }
} }
protected function batchjob_delete_process($uid): CommonEntity //일괄삭제
protected function batchjob_delete_pre_process(): array
{ {
return $this->service->batchjob_delete($uid);
}
final public function batchjob_delete(): string|RedirectResponse
{
try {
$postDatas = $this->request->getPost(); $postDatas = $this->request->getPost();
//1. postDatas에서 선택된 uids 정보 추출 //1. postDatas에서 선택된 uids 정보 추출
$uids = []; $uids = [];
@ -306,27 +332,42 @@ abstract class CommonController extends BaseController
if (empty($uids)) { if (empty($uids)) {
throw new \Exception("삭제할 리스트을 선택하셔야합니다."); throw new \Exception("삭제할 리스트을 선택하셔야합니다.");
} }
return array($uids);
}
protected function batchjob_delete_result_process(array $uids, array $entities, array $errors): string|RedirectResponse
{
return $this->action_redirect_process('info', sprintf(
"%s에서 %s개 처리완료, %s개 오류, 총:%s개 일괄삭제가 완료되었습니다.",
$this->getTitle(),
count($entities),
count($errors),
count($uids)
));
}
protected function batchjob_delete_process($uid): CommonEntity
{
return $this->service->delete($uid);
}
final public function batchjob_delete(): string|RedirectResponse
{
try {
$uids = $this->batchjob_delete_pre_process();
$entities = []; $entities = [];
$error = 0; $errors = [];
foreach ($uids as $uid) { foreach ($uids as $uid) {
try { try {
$entities[] = $this->batchjob_delete_process($uid); $entities[] = $this->batchjob_delete_process($uid);
} catch (\Exception $e) { } catch (\Exception $e) {
log_message('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage()); log_message('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage());
$error++; $errors[] = $e->getMessage();
} }
} }
return $this->action_redirect_process('info', sprintf( return $this->batchjob_delete_result_process($uids, $entities, $errors);
"%s에서 %s개 처리완료, %s개 오류, 총:%s개 일괄삭제가 완료되었습니다.",
$this->getTitle(),
count($entities),
$error,
count($uids)
));
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄삭제 오류:" . $e->getMessage()); return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄삭제 오류:" . $e->getMessage());
} }
} }
//상세보기
protected function view_process($uid): CommonEntity protected function view_process($uid): CommonEntity
{ {
if (!$uid) { if (!$uid) {
@ -338,14 +379,17 @@ abstract class CommonController extends BaseController
} }
return $entity; return $entity;
} }
protected function view_result_process(string $action): string
{
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
}
final public function view($uid): string|RedirectResponse final public function view($uid): string|RedirectResponse
{ {
try { try {
$action = __FUNCTION__; $action = __FUNCTION__;
$this->action_init_process($action); $this->action_init_process($action);
$entity = $this->view_process($uid); $this->addViewDatas('entity', $this->view_process($uid));
$this->addViewDatas('entity', $entity); return $this->view_result_process($action);
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 상세보기 오류:" . $e->getMessage()); return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 상세보기 오류:" . $e->getMessage());
} }
@ -417,6 +461,10 @@ abstract class CommonController extends BaseController
} }
return $entities; return $entities;
} }
protected function index_result_process(string $action): string
{
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
}
public function index(): string public function index(): string
{ {
$action = __FUNCTION__; $action = __FUNCTION__;
@ -448,13 +496,13 @@ abstract class CommonController extends BaseController
} }
//현재 URL을 세션에 저장 //현재 URL을 세션에 저장
$this->getAuthContext()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "")); $this->getAuthContext()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : ""));
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas()); return $this->index_result_process($action);
} }
//OUPUT Document 관련 //OUPUT Document 관련
protected function download_process(string $document_type, mixed $loaded_data): array protected function downloadByDocumentType(string $document_type, mixed $loaded_data): array
{ {
$full_path = WRITEPATH . DIRECTORY_SEPARATOR . "excel"; $full_path = WRITEPATH . DIRECTORY_SEPARATOR . "download";
switch ($document_type) { switch ($document_type) {
case 'excel': case 'excel':
$file_name = sprintf("%s_%s.xlsx", $this->service->getClassPaths(false, "_"), date('Y-m-d_Hm')); $file_name = sprintf("%s_%s.xlsx", $this->service->getClassPaths(false, "_"), date('Y-m-d_Hm'));
@ -469,13 +517,8 @@ abstract class CommonController extends BaseController
} }
return array($full_path, $file_name); return array($full_path, $file_name);
} }
// Download protected function download_process(string $action, string $output_type, mixed $uid = null): DownloadResponse|RedirectResponse|string
public function download(string $output_type, mixed $uid = false): DownloadResponse|RedirectResponse|string
{ {
$action = __FUNCTION__;
try {
//초기화
$this->action_init_process($action);
switch ($output_type) { switch ($output_type) {
case 'excel': case 'excel':
case 'pdf': case 'pdf':
@ -486,7 +529,7 @@ abstract class CommonController extends BaseController
//data loading //data loading
$reader = new Html(); $reader = new Html();
$loaded_data = $reader->loadFromString($html); $loaded_data = $reader->loadFromString($html);
list($full_path, $file_name) = $this->download_process($output_type, $loaded_data); list($full_path, $file_name) = $this->downloadByDocumentType($output_type, $loaded_data);
$full_path .= DIRECTORY_SEPARATOR . $file_name; $full_path .= DIRECTORY_SEPARATOR . $file_name;
break; break;
default: default:
@ -503,6 +546,15 @@ abstract class CommonController extends BaseController
break; break;
} }
return $this->response->download($full_path, null)->setFileName($file_name); return $this->response->download($full_path, null)->setFileName($file_name);
}
// Download
final public function download(string $output_type, mixed $uid = false): DownloadResponse|RedirectResponse|string
{
$action = __FUNCTION__;
try {
//초기화
$this->action_init_process($action);
return $this->download_process($action, $output_type, $uid);
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->action_redirect_process('error', "{$this->getTitle()}에서 오류:" . $e->getMessage()); return $this->action_redirect_process('error', "{$this->getTitle()}에서 오류:" . $e->getMessage());
} }