dbmsv4 init...2

This commit is contained in:
최준흠 2025-12-03 09:58:57 +09:00
parent 0e72ca6428
commit fba37415c4
3 changed files with 57 additions and 25 deletions

View File

@ -255,7 +255,16 @@ abstract class CommonService
if (!$dto instanceof $dtoClass) { if (!$dto instanceof $dtoClass) {
throw new RuntimeException(__METHOD__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)"); throw new RuntimeException(__METHOD__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)");
} }
$entity = $this->modify_process($this->getEntity($uid), $dto->toArray()); $entity = $this->getEntity($uid);
if (!$entity) {
throw new \Exception(__METHOD__ . "에서 오류발생: {$uid}에 해당하는 정보을 찾을수 없습니다.");
}
// 💡 동적으로 가져온 Entity 클래스 이름으로 instanceof 검사
$entityClass = $this->getEntityClass();
if (!$entity instanceof $entityClass) {
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 {$entityClass}만 가능");
}
$entity = $this->modify_process($entity, $dto->toArray());
// 트랜잭션 완료 및 커밋 // 트랜잭션 완료 및 커밋
$db->transComplete(); $db->transComplete();
return $entity; return $entity;
@ -274,10 +283,10 @@ abstract class CommonService
} }
//배치 작업용 수정 //배치 작업용 수정
protected function batchjob_process(string|int $uid, array $formDatas): object protected function batchjob_process($entity, array $formDatas): object
{ {
// modify_process를 호출하여 로직 재사용 (PK 로드 및 PK 제거/방어 로직 포함) // modify_process를 호출하여 로직 재사용 (PK 로드 및 PK 제거/방어 로직 포함)
$entity = $this->modify_process($this->getEntity($uid), $formDatas); $entity = $this->modify_process($entity, $formDatas);
return $entity; return $entity;
} }
final public function batchjob(array $uids, object $dto): array final public function batchjob(array $uids, object $dto): array
@ -293,7 +302,16 @@ abstract class CommonService
//일괄작업처리 //일괄작업처리
$entities = []; $entities = [];
foreach ($uids as $uid) { foreach ($uids as $uid) {
$entities[] = $this->batchjob_process($uid, $dto->toArray()); $entity = $this->getEntity($uid);
if (!$entity) {
throw new \Exception(__METHOD__ . "에서 오류발생: {$uid}에 해당하는 정보을 찾을수 없습니다.");
}
// 💡 동적으로 가져온 Entity 클래스 이름으로 instanceof 검사
$entityClass = $this->getEntityClass();
if (!$entity instanceof $entityClass) {
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 {$entityClass}만 가능");
}
$entities[] = $this->batchjob_process($entity, $dto->toArray());
} }
// 트랜잭션 완료 및 커밋 // 트랜잭션 완료 및 커밋
$db->transComplete(); $db->transComplete();
@ -313,20 +331,8 @@ abstract class CommonService
} }
//삭제용 (일반) //삭제용 (일반)
protected function delete_process(string|int $uid): object protected function delete_process($entity): object
{ {
if (!$uid) {
throw new \Exception("삭제에 필요한 PrimaryKey 가 정의 되지 않았습니다.");
}
$entity = $this->getEntity($uid);
if (!$entity) {
throw new \Exception(__METHOD__ . "에서 오류발생: {$uid}에 해당하는 정보을 찾을수 없습니다.");
}
// 💡 동적으로 가져온 Entity 클래스 이름으로 instanceof 검사
$entityClass = $this->getEntityClass();
if (!$entity instanceof $entityClass) {
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 {$entityClass}만 가능");
}
//삭제 //삭제
$result = $this->model->delete($entity->getPK()); $result = $this->model->delete($entity->getPK());
log_message('debug', $this->model->getLastQuery()); log_message('debug', $this->model->getLastQuery());
@ -341,8 +347,20 @@ abstract class CommonService
{ {
$db = \Config\Database::connect(); $db = \Config\Database::connect();
try { try {
if (!$uid) {
throw new \Exception("삭제에 필요한 PrimaryKey 가 정의 되지 않았습니다.");
}
$entity = $this->getEntity($uid);
if (!$entity) {
throw new \Exception(__METHOD__ . "에서 오류발생: {$uid}에 해당하는 정보을 찾을수 없습니다.");
}
// 💡 동적으로 가져온 Entity 클래스 이름으로 instanceof 검사
$entityClass = $this->getEntityClass();
if (!$entity instanceof $entityClass) {
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 {$entityClass}만 가능");
}
$db->transException(true)->transStart(); $db->transException(true)->transStart();
$entity = $this->delete_process($uid); $entity = $this->delete_process($entity);
// 트랜잭션 완료 및 커밋 // 트랜잭션 완료 및 커밋
$db->transComplete(); $db->transComplete();
return $entity; return $entity;
@ -361,10 +379,10 @@ abstract class CommonService
} }
//삭제용 (배치 작업) //삭제용 (배치 작업)
protected function batchjob_delete_process(string|int $uid): object protected function batchjob_delete_process($entity): object
{ {
// delete_process를 호출하여 로직 재사용 (CommonEntity 로드 및 유효성 검사) // delete_process를 호출하여 로직 재사용 (CommonEntity 로드 및 유효성 검사)
$entity = $this->delete_process($uid); $entity = $this->delete_process($entity);
return $entity; return $entity;
} }
@ -376,7 +394,16 @@ abstract class CommonService
//일괄작업처리 //일괄작업처리
$entities = []; $entities = [];
foreach ($uids as $uid) { foreach ($uids as $uid) {
$entities[] = $this->batchjob_delete_process($uid); $entity = $this->getEntity($uid);
if (!$entity) {
throw new \Exception(__METHOD__ . "에서 오류발생: {$uid}에 해당하는 정보을 찾을수 없습니다.");
}
// 💡 동적으로 가져온 Entity 클래스 이름으로 instanceof 검사
$entityClass = $this->getEntityClass();
if (!$entity instanceof $entityClass) {
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 {$entityClass}만 가능");
}
$entities[] = $this->batchjob_delete_process($entity);
} }
// 트랜잭션 완료 및 커밋 // 트랜잭션 완료 및 커밋
$db->transComplete(); $db->transComplete();

View File

@ -146,6 +146,11 @@ class ServerPartService extends EquipmentService
//서버파트 수정 //서버파트 수정
return parent::modify_process($entity, $formDatas); return parent::modify_process($entity, $formDatas);
} }
protected function delete_process($entity): ServerPartEntity
{
$this->getPartService($entity->getType())->detachFromServerPart($entity);
return parent::delete_process($entity);
}
//List 검색용 //List 검색용
//FormFilter 조건절 처리 //FormFilter 조건절 처리
//검색어조건절처리 //검색어조건절처리
@ -195,7 +200,7 @@ class ServerPartService extends EquipmentService
]) as $entity ]) as $entity
) { ) {
$this->getPartService($entity->getType())->detachFromServerPart($entity); $this->getPartService($entity->getType())->detachFromServerPart($entity);
parent::delete($entity->getPK()); parent::delete_process($entity);
} }
} }
} }

View File

@ -268,8 +268,8 @@ class ServerService extends EquipmentService
$this->getFormService()->setFormRules('modify', $fields); $this->getFormService()->setFormRules('modify', $fields);
parent::modify_process($entity, $formDatas); parent::modify_process($entity, $formDatas);
//서버파트정보처리 //서버파트정보처리
service('part_ipservice')->detachFromService($entity); service('part_ipservice')->detachFromServer($entity);
service('part_switchservice')->detachFromService($entity); service('part_switchservice')->detachFromServer($entity);
service('equipment_serverpartservice')->detachFromService($entity); service('equipment_serverpartservice')->detachFromServer($entity);
} }
} }