dbmsv4 init...3

This commit is contained in:
최준흠 2025-12-12 15:39:12 +09:00
parent 27ac89e228
commit e7c1da7ec1
16 changed files with 99 additions and 147 deletions

View File

@ -41,8 +41,14 @@ abstract class AbstractCRUDController extends AbstractWebController
} }
protected function create_process(array $formDatas): object protected function create_process(array $formDatas): object
{ {
// POST 데이터를 DTO 객체로 변환 (getPost()는 POST 요청 본문만 가져옵니다.) // POST 데이터를 DTO 객체로 변환
return $this->service->create($this->service->createDTO($formDatas)); $dto = $this->service->createDTO($formDatas);
//DTO 타입 체크 로직을 일반화
$dtoClass = $this->service->getDTOClass();
if (!$dto instanceof $dtoClass) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)");
}
return $this->service->create($dto->toArray());
} }
protected function create_result_process($entity, ?string $redirect_url = null): string|RedirectResponse protected function create_result_process($entity, ?string $redirect_url = null): string|RedirectResponse
@ -102,7 +108,13 @@ abstract class AbstractCRUDController extends AbstractWebController
protected function modify_process($uid, array $formDatas): object protected function modify_process($uid, array $formDatas): object
{ {
// POST 데이터를 DTO 객체로 변환 // POST 데이터를 DTO 객체로 변환
return $this->service->modify($uid, $this->service->createDTO($formDatas)); $dto = $this->service->createDTO($formDatas);
//DTO 타입 체크 로직을 일반화
$dtoClass = $this->service->getDTOClass();
if (!$dto instanceof $dtoClass) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)");
}
return $this->service->modify($uid, $dto->toArray());
} }
protected function modify_result_process($entity, ?string $redirect_url = null): string|RedirectResponse protected function modify_result_process($entity, ?string $redirect_url = null): string|RedirectResponse

View File

@ -55,11 +55,11 @@ class ClientController extends CustomerController
public function history(int $uid): RedirectResponse|string public function history(int $uid): RedirectResponse|string
{ {
try { try {
$action = __FUNCTION__; $history = $this->request->getPost('history');
$fields = ['history']; if (!$history) {
$this->service->getFormService()->setFormFields($fields); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 비고가 정의되지 않았습니다.");
$this->service->getFormService()->setFormRules($action, $fields); }
$this->addViewDatas('entity', $this->service->modify($uid, $this->service->createDTO($this->request->getPost()))); $this->addViewDatas('entity', $this->service->modify($uid, $history));
return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 비고설정이 완료되었습니다."); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 비고설정이 완료되었습니다.");
} catch (\Throwable $e) { } catch (\Throwable $e) {
return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 비고설정 오류:" . $e->getMessage()); return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 비고설정 오류:" . $e->getMessage());

View File

@ -2,6 +2,7 @@
namespace App\Controllers\Admin\Customer; namespace App\Controllers\Admin\Customer;
use App\Entities\Customer\ServiceEntity;
use App\Entities\Equipment\ServerEntity; use App\Entities\Equipment\ServerEntity;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
@ -45,6 +46,10 @@ class ServiceController extends CustomerController
public function history(int $uid): RedirectResponse|string public function history(int $uid): RedirectResponse|string
{ {
try { try {
$history = $this->request->getPost('history');
if (!$history) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 비고가 정의되지 않았습니다.");
}
$this->addViewDatas('entity', parent::modify_process($uid, $this->request->getPost())); $this->addViewDatas('entity', parent::modify_process($uid, $this->request->getPost()));
return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 비고설정이 완료되었습니다."); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 비고설정이 완료되었습니다.");
} catch (\Throwable $e) { } catch (\Throwable $e) {
@ -54,6 +59,10 @@ class ServiceController extends CustomerController
public function billingat(int $uid): RedirectResponse|string public function billingat(int $uid): RedirectResponse|string
{ {
try { try {
$billing_at = $this->request->getPost('billing_at');
if (!$billing_at) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 결제일이 정의되지 않았습니다.");
}
$this->addViewDatas('entity', parent::modify_process($uid, $this->request->getPost())); $this->addViewDatas('entity', parent::modify_process($uid, $this->request->getPost()));
return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 결제일 변경이 완료되었습니다."); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 결제일 변경이 완료되었습니다.");
} catch (\Throwable $e) { } catch (\Throwable $e) {
@ -65,9 +74,8 @@ class ServiceController extends CustomerController
public function alternative_create_form(int $uid): string|RedirectResponse public function alternative_create_form(int $uid): string|RedirectResponse
{ {
try { try {
$action = __FUNCTION__; $this->action_init_process(__FUNCTION__, $this->request->getVar());
$this->action_init_process($action, $this->request->getVar()); return $this->action_render_process(__FUNCTION__, $this->getViewDatas(), $this->request->getVar('ActionTemplate') ?? 'server');
return $this->action_render_process($action, $this->getViewDatas(), $this->request->getVar('ActionTemplate') ?? 'server');
} catch (\Throwable $e) { } catch (\Throwable $e) {
return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 추가폼 오류:" . $e->getMessage()); return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 추가폼 오류:" . $e->getMessage());
} }
@ -75,14 +83,15 @@ class ServiceController extends CustomerController
public function alternative_create(int $uid): string|RedirectResponse public function alternative_create(int $uid): string|RedirectResponse
{ {
try { try {
$action = __FUNCTION__; //추가할 대체서버 정의
$fields = ['serverinfo_uid']; $serverinfo_uid = $this->request->getGet('serverinfo_uid');
$this->service->getFormService()->setFormFields($fields); if (!$serverinfo_uid) {
$this->service->getFormService()->setFormRules($action, $fields); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 변경할 대체서버가 정의되지 않았습니다.");
}
//서비스정보 가져오기 //서비스정보 가져오기
$entity = $this->service->getEntity($uid); $entity = $this->service->getEntity($uid);
//대체서버 추가 //대체서버 추가
service('equipment_serverservice')->attachToService($entity, $this->request->getPost('serverinfo_uid')); service('equipment_serverservice')->attachToService($entity, $serverinfo_uid);
return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 추가가 완료되었습니다."); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 추가가 완료되었습니다.");
} catch (\Throwable $e) { } catch (\Throwable $e) {
return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 추가 오류:" . $e->getMessage()); return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 추가 오류:" . $e->getMessage());
@ -93,20 +102,22 @@ class ServiceController extends CustomerController
public function alternative_modify(int $uid): string|RedirectResponse public function alternative_modify(int $uid): string|RedirectResponse
{ {
try { try {
$action = __FUNCTION__; //변경할 대체서버 정의
$fields = ['serverinfo_uid']; $serverinfo_uid = $this->request->getGet('serverinfo_uid');
$this->service->getFormService()->setFormFields($fields); if (!$serverinfo_uid) {
$this->service->getFormService()->setFormRules($action, $fields); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 변경할 대체서버가 정의되지 않았습니다.");
//변경값 정의 }
$formDatas = $this->request->getGet();
//서버 타이틀을 서비스 타이틀로 변경하기 위함 //서버 타이틀을 서비스 타이틀로 변경하기 위함
$serverEntity = service('equipment_serverservice')->getEntity($formDatas['serverinfo_uid']); $serverEntity = service('equipment_serverservice')->getEntity($serverinfo_uid);
if (!$serverEntity instanceof ServerEntity) { if (!$serverEntity instanceof ServerEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 해당하는 서버정보을 찾을수 없습니다."); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 해당하는 서버정보을 찾을수 없습니다.");
} }
//서버번호 와 서비스 제목 설정용
$formDatas = [];
$formDatas['serverinfo_uid'] = $serverinfo_uid;
$formDatas['title'] = $serverEntity->getCustomTitle(); $formDatas['title'] = $serverEntity->getCustomTitle();
//대체서버를 메인서버로 설정 //대체서버를 메인서버로 설정
$this->service->modify($uid, $this->service->createDTO($formDatas)); $this->service->modify($uid, $formDatas);
return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 메인서버 설정이 완료되었습니다."); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 메인서버 설정이 완료되었습니다.");
} catch (\Throwable $e) { } catch (\Throwable $e) {
return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 메인서버 설정 오류:" . $e->getMessage()); return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 메인서버 설정 오류:" . $e->getMessage());
@ -115,14 +126,18 @@ class ServiceController extends CustomerController
public function alternative_delete(int $uid): string|RedirectResponse public function alternative_delete(int $uid): string|RedirectResponse
{ {
try { try {
$action = __FUNCTION__; //해지할 대체서버 정의
$fields = ['serverinfo_uid']; $serverinfo_uid = $this->request->getGet('serverinfo_uid');
$this->service->getFormService()->setFormFields($fields); if (!$serverinfo_uid) {
$this->service->getFormService()->setFormRules($action, $fields); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 해지할 대체서버가 정의되지 않았습니다.");
}
//서비스정보 가져오기 //서비스정보 가져오기
$entity = $this->service->getEntity($uid); $entity = $this->service->getEntity($uid);
if (!$entity instanceof ServiceEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 해당하는 서비스정보을 찾을수 없습니다.");
}
//대체서버 해지 //대체서버 해지
service('equipment_serverservice')->detachFromService($entity, $this->request->getGet('serverinfo_uid')); service('equipment_serverservice')->detachFromService($entity, $serverinfo_uid);
return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 해지가 완료되었습니다."); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 해지가 완료되었습니다.");
} catch (\Throwable $e) { } catch (\Throwable $e) {
return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 해지 오류:" . $e->getMessage()); return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 해지 오류:" . $e->getMessage());

View File

@ -133,7 +133,7 @@ class PaymentController extends AdminController
final public function paid($uid): string|RedirectResponse final public function paid($uid): string|RedirectResponse
{ {
try { try {
$entity = $this->service->modify($uid, $this->service->createDTO(['status' => STATUS['PAID']])); $entity = $this->service->modify($uid, ['status' => STATUS['PAID']]);
return $this->action_redirect_process('info', "{$this->getTitle()}에서 {$entity->getTitle()} 결체처리가 완료되었습니다."); return $this->action_redirect_process('info', "{$this->getTitle()}에서 {$entity->getTitle()} 결체처리가 완료되었습니다.");
} catch (\Throwable $e) { } catch (\Throwable $e) {
return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 결제 오류:" . $e->getMessage()); return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 결제 오류:" . $e->getMessage());

View File

@ -27,7 +27,7 @@ class Invoice extends BaseController
foreach ($this->service->getEntities(['billing_at' => date("Y-m-d"), 'status' => STATUS['AVAILABLE']]) as $entity) { foreach ($this->service->getEntities(['billing_at' => date("Y-m-d"), 'status' => STATUS['AVAILABLE']]) as $entity) {
try { try {
service('paymentservice')->createByService($entity); service('paymentservice')->createByService($entity);
$entity = $this->service->updateBillingAt($entity, $this->service->getNextMonthDate($entity)); $entity = $this->service->modify($entity, ['billing_at' => $this->service->getNextMonthDate($entity)]);
log_message('info', "{$entity->getServerTitle()} 청구서 발행 완료: 다음달 청구일:{$entity->getBillingAt()} 입니다."); log_message('info', "{$entity->getServerTitle()} 청구서 발행 완료: 다음달 청구일:{$entity->getBillingAt()} 입니다.");
} catch (\Throwable $e) { } catch (\Throwable $e) {
$error++; $error++;

View File

@ -16,7 +16,6 @@ use RuntimeException;
abstract class CommonController extends AbstractCRUDController abstract class CommonController extends AbstractCRUDController
{ {
// --- 일괄 작업 (Batch Job) --- // --- 일괄 작업 (Batch Job) ---
protected function batchjob_pre_process(array $postDatas): array protected function batchjob_pre_process(array $postDatas): array
{ {
// 1. postDatas에서 선택된 uids 정보 추출 // 1. postDatas에서 선택된 uids 정보 추출
@ -31,8 +30,7 @@ abstract class CommonController extends AbstractCRUDController
throw new RuntimeException("{$this->getTitle()}에서 일괄작업에 변경할 조건항목을 선택하셔야합니다."); throw new RuntimeException("{$this->getTitle()}에서 일괄작업에 변경할 조건항목을 선택하셔야합니다.");
} }
// 3. 데이터가 있는 필드 추출 // 3. 데이터가 있는 필드 추출
$selectedFields = array_keys($formDatas); return array($uids, $formDatas);
return array($uids, $selectedFields, $formDatas);
} }
protected function batchjob_process(array $uids, array $formDatas): array protected function batchjob_process(array $uids, array $formDatas): array
@ -54,11 +52,7 @@ abstract class CommonController extends AbstractCRUDController
try { try {
$action = __FUNCTION__; $action = __FUNCTION__;
// 사전작업 및 데이터 추출 초기화 // 사전작업 및 데이터 추출 초기화
list($uids, $selectedFields, $formDatas) = $this->batchjob_pre_process($this->request->getPost()); list($uids, $formDatas) = $this->batchjob_pre_process($this->request->getPost());
$this->service->getFormService()->setFormFields($selectedFields);
$this->service->getFormService()->setFormRules($action, $selectedFields);
$this->service->getFormService()->setFormFilters($selectedFields);
$this->service->getFormService()->setFormOptions($action, $selectedFields);
$entities = $this->batchjob_process($uids, $formDatas); $entities = $this->batchjob_process($uids, $formDatas);
return $this->batchjob_result_process($uids, $entities); return $this->batchjob_result_process($uids, $entities);
} catch (\Throwable $e) { } catch (\Throwable $e) {

View File

@ -2,11 +2,9 @@
namespace App\Services; namespace App\Services;
use RuntimeException;
use App\Models\BoardModel; use App\Models\BoardModel;
use App\Helpers\BoardHelper; use App\Helpers\BoardHelper;
use App\Forms\BoardForm; use App\Forms\BoardForm;
use App\Entities\CommonEntity;
use App\Entities\BoardEntity; use App\Entities\BoardEntity;
use App\DTOs\BoardDTO; use App\DTOs\BoardDTO;
@ -19,9 +17,9 @@ class BoardService extends CommonService
parent::__construct($model); parent::__construct($model);
$this->addClassPaths('Board'); $this->addClassPaths('Board');
} }
protected function getDTOClass(): string public function getDTOClass(): string
{ {
return BOARDDTO::class; return BoardDTO::class;
} }
public function createDTO(array $formDatas): BoardDTO public function createDTO(array $formDatas): BoardDTO
{ {

View File

@ -4,7 +4,6 @@ namespace App\Services;
use App\DTOs\CommonDTO; use App\DTOs\CommonDTO;
use App\Entities\CommonEntity; use App\Entities\CommonEntity;
use App\Entities\PaymentEntity;
use App\Libraries\AuthContext; use App\Libraries\AuthContext;
use App\Models\CommonModel; use App\Models\CommonModel;
use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Database\Exceptions\DatabaseException;
@ -22,7 +21,7 @@ abstract class CommonService
protected $title = null; protected $title = null;
protected function __construct(protected CommonModel $model) {} protected function __construct(protected CommonModel $model) {}
abstract public function action_init_process(string $action, array $formDatas = []): void; abstract public function action_init_process(string $action, array $formDatas = []): void;
abstract protected function getDTOClass(): string; abstract public function getDTOClass(): string;
abstract public function createDTO(array $formDatas): CommonDTO; abstract public function createDTO(array $formDatas): CommonDTO;
abstract public function getEntityClass(): string; abstract public function getEntityClass(): string;
abstract public function getFormService(): mixed; abstract public function getFormService(): mixed;
@ -187,18 +186,13 @@ abstract class CommonService
log_message('debug', var_export($entity->toArray(), true)); log_message('debug', var_export($entity->toArray(), true));
return $entity; return $entity;
} }
final public function create(object $dto): object final public function create(array $formDatas): object
{ {
$db = \Config\Database::connect(); $db = \Config\Database::connect();
try { try {
//트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정 //트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정
$db->transException(true)->transStart(); $db->transException(true)->transStart();
//DTO 타입 체크 로직을 일반화 $entity = $this->create_process($formDatas);
$dtoClass = $this->getDTOClass();
if (!$dto instanceof $dtoClass) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)");
}
$entity = $this->create_process($dto->toArray());
$db->transComplete(); $db->transComplete();
return $entity; return $entity;
} catch (DatabaseException $e) { } catch (DatabaseException $e) {
@ -247,16 +241,11 @@ abstract class CommonService
return $entity; return $entity;
} }
final public function modify(string|int $uid, object $dto): object final public function modify(string|int $uid, array $formDatas): object
{ {
$db = \Config\Database::connect(); $db = \Config\Database::connect();
try { try {
$db->transException(true)->transStart(); $db->transException(true)->transStart();
//DTO 타입 체크 로직을 일반화
$dtoClass = $this->getDTOClass();
if (!$dto instanceof $dtoClass) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)");
}
$entity = $this->getEntity($uid); $entity = $this->getEntity($uid);
if (!$entity) { if (!$entity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 정보을 찾을수 없습니다."); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 정보을 찾을수 없습니다.");
@ -266,7 +255,7 @@ abstract class CommonService
if (!$entity instanceof $entityClass) { if (!$entity instanceof $entityClass) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 {$entityClass}만 가능"); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 {$entityClass}만 가능");
} }
$entity = $this->modify_process($entity, $dto->toArray()); $entity = $this->modify_process($entity, $formDatas);
// 트랜잭션 완료 및 커밋 // 트랜잭션 완료 및 커밋
$db->transComplete(); $db->transComplete();
return $entity; return $entity;
@ -280,47 +269,22 @@ abstract class CommonService
), $e->getCode(), $e); ), $e->getCode(), $e);
} catch (\Throwable $e) { } catch (\Throwable $e) {
$db->transRollback(); // 예외 발생 시 수동으로 롤백 $db->transRollback(); // 예외 발생 시 수동으로 롤백
throw new RuntimeException($e->getMessage(), 0, $e); throw new RuntimeException($e->getMessage());
} }
} }
//배치 작업용 수정 //배치 작업용 수정
protected function batchjob_process($entity, array $formDatas): object protected function batchjob_process($entity, array $formDatas): object
{ {
$fields = array_keys($formDatas); $entity = $this->modify_process($entity, $formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
// 검증
if (!$this->getFormService()->validate($formDatas)) {
throw new ValidationException(
implode("\n", service('validation')->getErrors())
);
}
//관리자 정보추가용
$formDatas['user_uid'] = $this->getAuthContext()->getUID();
//PK 추가
$pkField = $this->model->getPKField();
if (!isset($formDatas[$pkField]) && !empty($entity->getPK())) {
// original에 있는 PK 값을 attributes에 명시적으로 복사합니다.
$formDatas[$pkField] = $entity->getPK();
}
foreach ($formDatas as $key => $value) {
if ($value !== null) {
$entity->$key = $value;
}
}
$entity = $this->save_process($entity);
//입력/출력데이터 확인용
log_message('debug', var_export($formDatas, true));
log_message('debug', var_export($entity->toArray(), true));
return $entity; return $entity;
} }
final public function batchjob(array $uids, array $formDatas): array final public function batchjob(array $uids, array $formDatas): array
{ {
$db = \Config\Database::connect(); $db = \Config\Database::connect();
try { try {
//트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정
$db->transException(true)->transStart(); $db->transException(true)->transStart();
//일괄작업처리
$entities = []; $entities = [];
foreach ($uids as $uid) { foreach ($uids as $uid) {
$entity = $this->getEntity($uid); $entity = $this->getEntity($uid);
@ -332,29 +296,18 @@ abstract class CommonService
if (!$entity instanceof $entityClass) { if (!$entity instanceof $entityClass) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 {$entityClass}만 가능"); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 {$entityClass}만 가능");
} }
$entities[] = $this->batchjob_process($entity, $formDatas); $entities[] = $this->modify_process($entity, $formDatas);
} }
// 트랜잭션 완료 및 커밋
$db->transComplete();
return $entities; return $entities;
} catch (DatabaseException $e) {
// DatabaseException을 포착하면 자동으로 롤백 처리됨
throw new RuntimeException(sprintf(
"\n----[%s]에서 트랜잭션 실패: DB 오류----\n%s\n%s\n------------------------------\n",
__METHOD__,
$this->model->getLastQuery(),
$e->getMessage()
), $e->getCode(), $e);
} catch (\Throwable $e) { } catch (\Throwable $e) {
$db->transRollback(); // 예외 발생 시 수동으로 롤백 $db->transRollback(); // 예외 발생 시 수동으로 롤백
throw new RuntimeException($e->getMessage(), 0, $e); throw new RuntimeException($e->getMessage());
} }
} }
//삭제용 (일반) //삭제용 (일반)
protected function delete_process($entity): object protected function delete_process($entity): object
{ {
//삭제
$result = $this->model->delete($entity->getPK()); $result = $this->model->delete($entity->getPK());
log_message('debug', $this->model->getLastQuery()); log_message('debug', $this->model->getLastQuery());
if ($result === false) { if ($result === false) {
@ -395,14 +348,13 @@ abstract class CommonService
), $e->getCode(), $e); ), $e->getCode(), $e);
} catch (\Throwable $e) { } catch (\Throwable $e) {
$db->transRollback(); // 예외 발생 시 수동으로 롤백 $db->transRollback(); // 예외 발생 시 수동으로 롤백
throw new RuntimeException($e->getMessage(), 0, $e); throw new RuntimeException($e->getMessage());
} }
} }
//삭제용 (배치 작업) //삭제용 (배치 작업)
protected function batchjob_delete_process($entity): object protected function batchjob_delete_process($entity): object
{ {
// delete_process를 호출하여 로직 재사용 (CommonEntity 로드 및 유효성 검사)
$entity = $this->delete_process($entity); $entity = $this->delete_process($entity);
return $entity; return $entity;
} }
@ -439,7 +391,7 @@ abstract class CommonService
), $e->getCode(), $e); ), $e->getCode(), $e);
} catch (\Throwable $e) { } catch (\Throwable $e) {
$db->transRollback(); // 예외 발생 시 수동으로 롤백 $db->transRollback(); // 예외 발생 시 수동으로 롤백
throw new RuntimeException($e->getMessage(), 0, $e); throw new RuntimeException($e->getMessage());
} }
} }

View File

@ -19,7 +19,7 @@ class ClientService extends CustomerService
parent::__construct($model); parent::__construct($model);
$this->addClassPaths('Client'); $this->addClassPaths('Client');
} }
protected function getDTOClass(): string public function getDTOClass(): string
{ {
return ClientDTO::class; return ClientDTO::class;
} }

View File

@ -23,7 +23,7 @@ class ServiceService extends CustomerService
parent::__construct($model); parent::__construct($model);
$this->addClassPaths('Service'); $this->addClassPaths('Service');
} }
protected function getDTOClass(): string public function getDTOClass(): string
{ {
return ServiceDTO::class; return ServiceDTO::class;
} }
@ -175,32 +175,23 @@ class ServiceService extends CustomerService
// 최종 결과 리턴 (YYYY-MM-DD) // 최종 결과 리턴 (YYYY-MM-DD)
return $date->format('Y-m-d'); return $date->format('Y-m-d');
} }
//결제일 변경관련처리
final public function updateBillingAt(int|ServiceEntity $uid, string $billing_at): ServiceEntity
{
$entity = is_int($uid) ? $this->getEntity($uid) : $uid;
if (!$entity instanceof ServiceEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보를 찾을수 없습니다.");
}
//총 서비스금액 설정
$formDatas = ['billing_at' => $billing_at];
return parent::modify_process($entity, $formDatas);
}
// 서비스금액관련처리 // 서비스금액관련처리
final public function updateAmount(int|ServiceEntity $uid): ServiceEntity private function updateAmount(ServiceEntity $entity): ServiceEntity
{ {
$entity = is_int($uid) ? $this->getEntity($uid) : $uid;
if (!$entity instanceof ServiceEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보를 찾을수 없습니다.");
}
//총 서비스금액 구하기 //총 서비스금액 구하기
$server_amount = service('equipment_serverservice')->getCalculatedAmount($entity->getServerInfoUID()); $server_amount = service('equipment_serverservice')->getCalculatedAmount($entity->getServerInfoUID());
//기본:서버금액(서버비+서버파트(월비용))+상면비+회선비-할인액 //기본:서버금액(서버비+서버파트(월비용))+상면비+회선비-할인액
$caculatedAmount = (int)$server_amount + $entity->getRack() + $entity->getLine() - $entity->getSale(); $caculatedAmount = (int)$server_amount + $entity->getRack() + $entity->getLine() - $entity->getSale();
//총 서비스금액 설정 //총 서비스금액 설정
$formDatas = ['amount' => $caculatedAmount]; return parent::modify_process($entity, ['amount' => $caculatedAmount]);
return parent::modify_process($entity, $formDatas); }
final public function updateAmountByPK(int $uid): ServiceEntity
{
$entity = $this->getEntity($uid);
if (!$entity instanceof ServiceEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServiceEntity만 가능");
}
return $this->updateAmount($entity);
} }
//기본 기능부분 //기본 기능부분
protected function getEntity_process(mixed $entity): ServiceEntity protected function getEntity_process(mixed $entity): ServiceEntity

View File

@ -21,7 +21,7 @@ class AccountService extends WalletService
parent::__construct($model); parent::__construct($model);
$this->addClassPaths('Account'); $this->addClassPaths('Account');
} }
protected function getDTOClass(): string public function getDTOClass(): string
{ {
return AccountDTO::class; return AccountDTO::class;
} }

View File

@ -20,7 +20,7 @@ class CouponService extends WalletService
parent::__construct($model); parent::__construct($model);
$this->addClassPaths('Coupon'); $this->addClassPaths('Coupon');
} }
protected function getDTOClass(): string public function getDTOClass(): string
{ {
return CouponDTO::class; return CouponDTO::class;
} }

View File

@ -20,7 +20,7 @@ class PointService extends WalletService
parent::__construct($model); parent::__construct($model);
$this->addClassPaths('Point'); $this->addClassPaths('Point');
} }
protected function getDTOClass(): string public function getDTOClass(): string
{ {
return PointDTO::class; return PointDTO::class;
} }

View File

@ -21,7 +21,7 @@ class ServerPartService extends EquipmentService
parent::__construct($model); parent::__construct($model);
$this->addClassPaths('ServerPart'); $this->addClassPaths('ServerPart');
} }
protected function getDTOClass(): string public function getDTOClass(): string
{ {
return ServerPartDTO::class; return ServerPartDTO::class;
} }
@ -135,7 +135,7 @@ class ServerPartService extends EquipmentService
if ($entity->getServiceInfoUID() !== null) { if ($entity->getServiceInfoUID() !== null) {
//Billing형식이 Month이면 서비스 금액설정 호출 //Billing형식이 Month이면 서비스 금액설정 호출
if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) { if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) {
service('customer_serviceservice')->updateAmount($entity->getServiceInfoUID()); service('customer_serviceservice')->updateAmountByPK($entity->getServiceInfoUID());
} }
//Billing형식이 Onetime이면 일회성결제 추가 //Billing형식이 Onetime이면 일회성결제 추가
if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) { if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) {
@ -159,7 +159,7 @@ class ServerPartService extends EquipmentService
if ($entity->getServiceInfoUID() !== null) { if ($entity->getServiceInfoUID() !== null) {
//월비용 서버파트 인경우 서비스 금액 재설정 //월비용 서버파트 인경우 서비스 금액 재설정
if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) { if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) {
service('customer_serviceservice')->updateAmount($entity->getServiceInfoUID()); service('customer_serviceservice')->updateAmountByPK($entity->getServiceInfoUID());
} }
//Billing형식이 Onetime이면 일회성결제 수정 (필요없는듯 하여 주석처리) //Billing형식이 Onetime이면 일회성결제 수정 (필요없는듯 하여 주석처리)
// if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) { // if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) {
@ -176,7 +176,7 @@ class ServerPartService extends EquipmentService
if ($entity->getServiceInfoUID() !== null) { if ($entity->getServiceInfoUID() !== null) {
//월비용 서버파트 인경우 서비스 금액 재설정 //월비용 서버파트 인경우 서비스 금액 재설정
if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) { if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) {
service('customer_serviceservice')->updateAmount($entity->getServiceInfoUID()); service('customer_serviceservice')->updateAmountByPK($entity->getServiceInfoUID());
} }
//Billing형식이 Onetime이면 일회성결제 수정 (필요없는듯 하여 주석처리) //Billing형식이 Onetime이면 일회성결제 수정 (필요없는듯 하여 주석처리)
// if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) { // if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) {

View File

@ -19,7 +19,7 @@ class ServerService extends EquipmentService
parent::__construct($model); parent::__construct($model);
$this->addClassPaths('Server'); $this->addClassPaths('Server');
} }
protected function getDTOClass(): string public function getDTOClass(): string
{ {
return ServerDTO::class; return ServerDTO::class;
} }
@ -249,7 +249,7 @@ class ServerService extends EquipmentService
service('equipment_chassisservice')->attachToServer($entity); service('equipment_chassisservice')->attachToServer($entity);
} }
if ($entity->getServiceInfoUID() !== null) { //서비스가 정의 되어 있으면 if ($entity->getServiceInfoUID() !== null) { //서비스가 정의 되어 있으면
service('customer_serviceservice')->updateAmount($entity->getServiceInfoUID()); service('customer_serviceservice')->updateAmountByPK($entity->getServiceInfoUID());
} }
return $entity; return $entity;
} }

View File

@ -24,7 +24,7 @@ class PaymentService extends CommonService
parent::__construct($model); parent::__construct($model);
$this->addClassPaths('Payment'); $this->addClassPaths('Payment');
} }
protected function getDTOClass(): string public function getDTOClass(): string
{ {
return PaymentDTO::class; return PaymentDTO::class;
} }
@ -213,7 +213,7 @@ class PaymentService extends CommonService
} }
//선결제인경우 서비스정보에 결제일 변경용 //선결제인경우 서비스정보에 결제일 변경용
if ($entity->getBilling() === PAYMENT['BILLING']['PREPAYMENT']) { if ($entity->getBilling() === PAYMENT['BILLING']['PREPAYMENT']) {
service('customer_serviceservice')->updateBillingAt($entity->getServiceInfoUID(), $entity->getBillingAt()); service('customer_serviceservice')->modify($entity->getServiceInfoUID(), ['billing_at' => $entity->getBillingAt()]);
} }
return $entity; return $entity;
} }
@ -234,7 +234,7 @@ class PaymentService extends CommonService
} }
//선결제인경우 서비스정보에 결제일 변경용 //선결제인경우 서비스정보에 결제일 변경용
if ($entity->getBilling() === PAYMENT['BILLING']['PREPAYMENT']) { if ($entity->getBilling() === PAYMENT['BILLING']['PREPAYMENT']) {
service('customer_serviceservice')->updateBillingAt($entity->getServiceInfoUID(), $entity->getBillingAt()); service('customer_serviceservice')->modify($entity->getServiceInfoUID(), ['billing_at' => $entity->getBillingAt()]);
} }
return $entity; return $entity;
} }
@ -245,17 +245,7 @@ class PaymentService extends CommonService
} }
return parent::delete_process($entity); return parent::delete_process($entity);
} }
//지불 관련
//일괄 지불용
protected function batchjob_process($entity, array $formDatas): object
{
// modify_process를 호출하여 로직 재사용 (PK 로드 및 PK 제거/방어 로직 포함)
$entity = parent::batchjob_process($entity, $formDatas);
if ($entity->getStatus() === STATUS['PAID']) {
$this->setWallet($entity);
}
return $entity;
}
//청구서 관련 //청구서 관련
public function getInvoices(ClientEntity $clientEntity, ServiceEntity $serviceEntity, PaymentEntity $entity, array $rows): array public function getInvoices(ClientEntity $clientEntity, ServiceEntity $serviceEntity, PaymentEntity $entity, array $rows): array
{ {