dbmsv3 init...1

This commit is contained in:
choi.jh 2025-10-29 13:14:37 +09:00
parent 7483a019b1
commit 7298defef6
12 changed files with 193 additions and 126 deletions

View File

@ -153,8 +153,6 @@ abstract class CommonController extends BaseController
}
public function create(): RedirectResponse|string
{
$db = \Config\Database::connect();
$db->transStart();
try {
$this->getService()->setAction(__FUNCTION__);
$this->getService()->setFormFields();
@ -164,10 +162,8 @@ abstract class CommonController extends BaseController
$this->getService()->setFormRules();
$this->doValidations();
$this->entity = $this->create_process($this->getService()->getFormDatas());
$db->transCommit();
return $this->getResultSuccess();
} catch (\Exception $e) {
$db->transRollback();
return $this->getResultFail($e->getMessage());
}
}
@ -205,9 +201,6 @@ abstract class CommonController extends BaseController
}
public function modify(int $uid): RedirectResponse|string
{
//Transaction Start
$db = \Config\Database::connect();
$db->transStart();
try {
$this->getService()->setAction(__FUNCTION__);
$this->getService()->setFormFields();
@ -222,10 +215,8 @@ abstract class CommonController extends BaseController
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
}
$this->entity = $this->modify_process($entity, $this->getService()->getFormDatas());
$db->transCommit();
return $this->getResultSuccess();
} catch (\Exception $e) {
$db->transRollback();
return $this->getResultFail($e->getMessage());
}
}
@ -236,9 +227,6 @@ abstract class CommonController extends BaseController
}
public function toggle(mixed $uid, string $field): RedirectResponse|string
{
//Transaction Start
$db = \Config\Database::connect();
$db->transStart();
try {
$this->getService()->setAction(__FUNCTION__);
$this->getService()->setFormFields([$field]);
@ -254,10 +242,8 @@ abstract class CommonController extends BaseController
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
}
$this->entity = $this->toggle_process($entity, $this->getService()->getFormDatas());
$db->transCommit();
return $this->getResultSuccess();
} catch (\Exception $e) {
$db->transRollback();
return $this->getResultFail($e->getMessage());
}
}
@ -289,9 +275,6 @@ abstract class CommonController extends BaseController
}
public function batchjob(): RedirectResponse|string
{
//Transaction Start
$db = \Config\Database::connect();
$db->transStart();
try {
$this->getService()->setAction(__FUNCTION__);
list($selectedFields, $formDatas, $uids) = $this->batchjob_pre_process();
@ -312,11 +295,13 @@ abstract class CommonController extends BaseController
$entities[] = $this->batchjob_process($entity, $formDatas);
}
$this->entities = $entities;
$db->transCommit();
LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄작업을 완료하였습니다.", __METHOD__, count($uids), count($this->entities)));
return $this->getResultSuccess();
return $this->getResultSuccess(sprintf(
"%s에서 총 %s개중 %s개 일괄작업을 완료하였습니다.",
__METHOD__,
count($uids),
count($this->entities)
));
} catch (\Exception $e) {
$db->transRollback();
return $this->getResultFail($e->getMessage());
}
}
@ -327,9 +312,6 @@ abstract class CommonController extends BaseController
}
public function delete(mixed $uid): RedirectResponse|string
{
//Transaction Start
$db = \Config\Database::connect();
$db->transStart();
try {
$this->getService()->setAction(__FUNCTION__);
//기존 Entity 가져오기
@ -338,10 +320,8 @@ abstract class CommonController extends BaseController
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
}
$this->delete_process($entity);
$db->transCommit();
return $this->getResultSuccess();
} catch (\Exception $e) {
$db->transRollback();
return $this->getResultFail($e->getMessage());
}
}
@ -361,9 +341,6 @@ abstract class CommonController extends BaseController
}
public function batchjob_delete(): RedirectResponse|string
{
//Transaction Start
$db = \Config\Database::connect();
$db->transStart();
try {
$this->getService()->setAction(__FUNCTION__);
$uids = $this->batchjob_delete_pre_process();
@ -377,11 +354,13 @@ abstract class CommonController extends BaseController
$entities[] = $this->batchjob_delete_process($entity);
}
$this->entities = $entities;
$db->transCommit();
LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄삭제를 완료하였습니다.", __METHOD__, count($uids), count($this->entities)));
return $this->getResultSuccess();
return $this->getResultSuccess(sprintf(
"%s에서 총 %s개중 %s개 일괄삭제를 완료하였습니다.",
__METHOD__,
count($uids),
count($this->entities)
));
} catch (\Exception $e) {
$db->transRollback();
return $this->getResultFail($e->getMessage());
}
}

File diff suppressed because one or more lines are too long

View File

@ -7,6 +7,7 @@ use App\Models\CommonModel;
use App\Services\Customer\ClientService;
use App\Services\UserService;
use App\Services\MyLogService;
use RuntimeException;
abstract class CommonService
{
@ -299,51 +300,135 @@ abstract class CommonService
return $formDatas;
}
//생성
protected function create_process(array $formDatas): mixed
{
return $this->getModel()->create($formDatas);
}
public function create(array $formDatas): mixed
{
$entity = $this->getEntity_process($this->getModel()->create($formDatas));
// LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["CREATED"] . ":");
return $entity;
}
//수정
public function modify(mixed $entity, array $formDatas): mixed
{
$entity = $this->getEntity_process($this->getModel()->modify($entity, $formDatas));
// LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["UPDATED"] . ":");
return $entity;
}
//단일작업
public function toggle(mixed $entity, array $formDatas): mixed
{
$entity = $this->getEntity_process($this->getModel()->modify($entity, $formDatas));
// LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["UPDATED"] . ":");
return $entity;
}
//일괄처리작업
public function batchjob(mixed $entity, array $formDatas): mixed
{
$entity = $this->getEntity_process($this->getModel()->modify($entity, $formDatas));
// LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["UPDATED"] . ":");
return $entity;
}
//삭제
public function delete(mixed $entity): mixed
{
$db = \Config\Database::connect();
$db->transStart();
try {
$message = "[{$entity->getTitle()}]" . MESSAGES["DELETED"] . ":";
if (!$this->getModel()->delete($entity->getPK())) {
throw new \Exception(var_export($this->getModel()->errors(), true));
$entity = $this->create_process($formDatas);
$db->transComplete();
if ($db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패: DB 상태 문제');
}
// LogCollector::info($message);
return $entity;
} catch (\Exception $e) {
$message = sprintf(
"\n------%s SQL오류-----\n%s\n%s\n------------------------------\n",
__FUNCTION__,
} catch (\Throwable $e) {
$db->transRollback(); // 예외 발생 시 수동으로 롤백
throw new RuntimeException(sprintf(
"\n------%s-----\n%s\n%s\n------------------------------\n",
__METHOD__,
$this->getModel()->getLastQuery(),
$e->getMessage()
);
throw new \Exception($message);
), 0, $e);
}
}
//수정
protected function modify_process(mixed $entity, array $formDatas): mixed
{
return $this->getModel()->modify($entity, $formDatas);
}
public function modify(mixed $entity, array $formDatas): mixed
{
$db = \Config\Database::connect();
$db->transStart();
try {
$entity = $this->modify_process($entity, $formDatas);
$db->transComplete();
if ($db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패: DB 상태 문제');
}
return $entity;
} catch (\Throwable $e) {
$db->transRollback(); // 예외 발생 시 수동으로 롤백
throw new RuntimeException(sprintf(
"\n------%s-----\n%s\n%s\n------------------------------\n",
__METHOD__,
$this->getModel()->getLastQuery(),
$e->getMessage()
), 0, $e);
}
}
//단일작업
protected function toggle_process(mixed $entity, array $formDatas): mixed
{
return $this->getModel()->modify($entity, $formDatas);
}
public function toggle(mixed $entity, array $formDatas): mixed
{
$db = \Config\Database::connect();
$db->transStart();
try {
$entity = $this->toggle_process($entity, $formDatas);
$db->transComplete();
if ($db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패: DB 상태 문제');
}
return $entity;
} catch (\Throwable $e) {
$db->transRollback(); // 예외 발생 시 수동으로 롤백
throw new RuntimeException(sprintf(
"\n------%s-----\n%s\n%s\n------------------------------\n",
__METHOD__,
$this->getModel()->getLastQuery(),
$e->getMessage()
), 0, $e);
}
}
//일괄처리작업
protected function batchjob_process(mixed $entity, array $formDatas): mixed
{
return $this->getModel()->modify($entity, $formDatas);
}
public function batchjob(mixed $entity, array $formDatas): mixed
{
$db = \Config\Database::connect();
$db->transStart();
try {
$entity = $this->batchjob_process($entity, $formDatas);
$db->transComplete();
if ($db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패: DB 상태 문제');
}
return $entity;
} catch (\Throwable $e) {
$db->transRollback(); // 예외 발생 시 수동으로 롤백
throw new RuntimeException(sprintf(
"\n------%s-----\n%s\n%s\n------------------------------\n",
__METHOD__,
$this->getModel()->getLastQuery(),
$e->getMessage()
), 0, $e);
}
}
//삭제
protected function delete_process(string $uid): bool
{
return $this->getModel()->delete($uid);
}
public function delete(mixed $entity): mixed
{
$db = \Config\Database::connect();
$db->transStart();
try {
if (!$this->delete_process($entity->getPK())) {
throw new RuntimeException(var_export($this->getModel()->errors(), true));
}
$db->transComplete();
if ($db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패: DB 상태 문제');
}
return $entity;
} catch (\Throwable $e) {
$db->transRollback(); // 예외 발생 시 수동으로 롤백
throw new RuntimeException(sprintf(
"\n------%s-----\n%s\n%s\n------------------------------\n",
__METHOD__,
$this->getModel()->getLastQuery(),
$e->getMessage()
), 0, $e);
}
}
////Index 검색용

View File

@ -64,21 +64,21 @@ class AccountService extends CustomerService
'status' => STATUS['WITHDRAWAL'],
];
$this->setBalance($formDatas);
return parent::create($formDatas);
return $this->getModel()->create($formDatas)($formDatas);
}
//기본 기능부분
//생성
public function create(array $formDatas): AccountEntity
protected function create_process(array $formDatas): AccountEntity
{
$this->setBalance($formDatas);
$entity = parent::create($formDatas);
//Log처리
$this->getMylogService()->create([
'title' => "[{$entity->getTitle()}] 예치금 처리",
'status' => $entity->getStatus()
]);
$entity = parent::create_process($formDatas)($formDatas);
return $entity;
}
//수정
public function modify(mixed $entity, array $formDatas): AccountEntity
{
throw new \Exception("예치금은 수정하실 수 없습니다.");
}
//List 검색용
public function index_condition_filterWord(string $word): void
{

View File

@ -146,25 +146,21 @@ class ClientService extends CustomerService
}
//기본 기능부분
//생성
public function create(array $formDatas): ClientEntity
protected function create_process(array $formDatas): ClientEntity
{
$formDatas['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $formDatas['role']);
return parent::create($formDatas);
$entity = parent::create_process($formDatas);
return $entity;
}
public function modify(mixed $entity, array $formDatas): ClientEntity
protected function modify_process(mixed $entity, array $formDatas): ClientEntity
{
//Role을 지정이 있을경우에만 , toggle이나 batcjhjob에서는 없을수도 있으므로
if (isset($formDatas['role'])) {
$formDatas['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $formDatas['role']);
}
return parent::modify($entity, $formDatas);
$entity = parent::modify_process($entity, $formDatas);
return $entity;
}
//비고(History)설정
public function history(mixed $entity, array $formDatas): ClientEntity
{
return parent::modify($entity, $formDatas);
}
//List 검색용
//FormFilter 조건절 처리
public function index_condition_filterField(string $field, mixed $filter_value): void
@ -192,4 +188,9 @@ class ClientService extends CustomerService
$this->getModel()->orderBy("site ASC,name ASC");
parent::setOrderBy($field, $value);
}
//비고(History)설정
public function history(mixed $entity, array $formDatas): ClientEntity
{
return $this->getModel()->modify($entity, $formDatas);
}
}

View File

@ -48,13 +48,16 @@ class CouponService extends CustomerService
return $this->getClientService()->setCoupon($formDatas['status'], $entity, intval($formDatas['cnt']));
}
//기본 기능부분
public function create(array $formDatas): CouponEntity
protected function create_process(array $formDatas): CouponEntity
{
// dd($formDatas);
$this->setBalance($formDatas);
$entity = parent::create($formDatas);
//Log처리
$this->getMylogService()->create(['title' => "[{$entity->getTitle()}] 쿠폰 처리", 'status' => $entity->getStatus()]);
$entity = parent::create_process($formDatas);
return $entity;
}
//수정
public function modify(mixed $entity, array $formDatas): CouponEntity
{
throw new \Exception("쿠폰은 수정하실 수 없습니다.");
}
}

View File

@ -48,12 +48,15 @@ class PointService extends CustomerService
return $this->getClientService()->setPoint($formDatas['status'], $entity, intval($formDatas['amount']));
}
//기본 기능부분
public function create(array $formDatas): PointEntity
protected function create_process(array $formDatas): PointEntity
{
$this->setBalance($formDatas);
$entity = parent::create($formDatas);
//Log처리
$this->getMylogService()->create(['title' => "[{$entity->getTitle()}] 포인트 처리", 'status' => $entity->getStatus()]);
$entity = parent::create_process($formDatas);
return $entity;
}
//수정
public function modify(mixed $entity, array $formDatas): PointEntity
{
throw new \Exception("포인트는 수정하실 수 없습니다.");
}
}

View File

@ -4,7 +4,6 @@ namespace App\Services\Customer;
use App\Entities\Customer\ServiceEntity;
use App\Entities\Equipment\ServerEntity;
use App\Entities\PaymentEntity;
use App\Helpers\Customer\ServiceHelper;
use App\Models\Customer\ServiceModel;
use App\Services\Equipment\ServerService;
@ -198,7 +197,7 @@ class ServiceService extends CustomerService
return $options;
}
//생성
public function create(array $formDatas): ServiceEntity
protected function create_process(array $formDatas): ServiceEntity
{
if (!isset($formDatas['serverinfo_uid'])) {
throw new \Exception('변경할 서버가 지정되지 않았습니다.');
@ -213,7 +212,7 @@ class ServiceService extends CustomerService
return $processor->create($formDatas);
}
//수정
public function modify(mixed $entity, array $formDatas): ServiceEntity
protected function modify_process(mixed $entity, array $formDatas): ServiceEntity
{
$processor = new Proceessor(
\Config\Database::connect(),
@ -236,11 +235,6 @@ class ServiceService extends CustomerService
);
return $processor->delete($entity);
}
//비고(History)설정
public function history(mixed $entity, array $formDatas): ServiceEntity
{
return parent::modify($entity, $formDatas);
}
//대체서버추가
public function addeAlternativeServer(ServiceEntity $entity, array $formDatas): ServiceEntity
{
@ -279,4 +273,9 @@ class ServiceService extends CustomerService
$this->getServerService()->detachFromService($formDatas['serverinfo_uid']);
return $entity;
}
//비고(History)설정
public function history(mixed $entity, array $formDatas): ServiceEntity
{
return $this->getModel()->modify($entity, $formDatas);
}
}

View File

@ -45,10 +45,10 @@ class LineService extends EquipmentService
return $this->_ipService;
}
//기본 기능부분
public function create(array $formDatas): LineEntity
protected function create_process(array $formDatas): LineEntity
{
//서버정보 생성
$entity = parent::create($formDatas);
$entity = parent::create_process($formDatas);
//Prefixed IP to array 자동 등록
foreach ($this->getHelper()->cidrToIpRange($formDatas['bandwith']) as $ip) {
$this->getIPService()->create([

View File

@ -53,10 +53,10 @@ class MyLogService extends CommonService
$this->getModel()->orLike($this->getModel()::TABLE . "." . $this->getModel()::TITLE, $word, 'both');
$this->getModel()->orLike($this->getModel()::TABLE . '.content', $word, 'both');
}
public function create(array $formDatas): MyLogEntity
protected function create_process(array $formDatas): MyLogEntity
{
//관리자(작업자정보) 등록
$formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo();
return parent::create($formDatas);
return parent::create_process($formDatas);
}
}

View File

@ -282,7 +282,7 @@ class PaymentService extends CommonService implements PaymentInterface
}
//Action 기능
//일회성용 결제처리 등록(일회성은 예치금에 관련된것만 등록한다.)
public function create(array $formDatas): PaymentEntity
protected function create_process(array $formDatas): PaymentEntity
{
if (!array_key_exists('serviceinfo_uid', $formDatas)) {
throw new \Exception("서비스정보가 없습니다.");
@ -294,12 +294,7 @@ class PaymentService extends CommonService implements PaymentInterface
}
//결제 완료 처리 후 추가정보 처리
$formDatas['clientinfo_uid'] = $serviceEntity->getClientInfoUID();
$entity = parent::create($formDatas);
//Log처리
$this->getMylogService()->create([
'title' => "[{$entity->getTitle()}] 일회성 추가",
'status' => $entity->getStatus()
]);
$entity = parent::create_process($formDatas);
return $entity;
}
//결제정보 삭제

View File

@ -50,12 +50,13 @@ class UserService extends CommonService
}
//기본 기능부분
public function create(array $formDatas): UserEntity
protected function create_process(array $formDatas): UserEntity
{
$formDatas['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $formDatas['role']);
return parent::create($formDatas);
$entity = parent::create_process($formDatas);
return $entity;
}
public function modify(mixed $entity, array $formDatas): UserEntity
protected function modify_process(mixed $entity, array $formDatas): UserEntity
{
// die(var_export($formDatas, true));
//암호를 입력하지 않았을시는 변경하기 않게 하기위함
@ -68,7 +69,8 @@ class UserService extends CommonService
$formDatas['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $formDatas['role']);
}
// die(var_export($formDatas, true));
return parent::modify($entity, $formDatas);
$entity = parent::modify_process($entity, $formDatas);
return $entity;
}
//List 검색용
//FormFilter 조건절 처리