dbmsv4 init...3

This commit is contained in:
최준흠 2025-12-16 15:25:23 +09:00
parent 45a8b92528
commit 9c573df584
25 changed files with 87 additions and 169 deletions

View File

@ -2,6 +2,7 @@
namespace App\Controllers;
use App\Entities\CommonEntity;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\Validation\Exceptions\ValidationException;
use RuntimeException;
@ -39,7 +40,7 @@ abstract class AbstractCRUDController extends AbstractWebController
return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 생성폼 오류:" . $e->getMessage());
}
}
protected function create_process(array $formDatas): object
protected function create_process(array $formDatas): CommonEntity
{
// POST 데이터를 DTO 객체로 변환
$dto = $this->service->createDTO($formDatas);
@ -78,7 +79,7 @@ abstract class AbstractCRUDController extends AbstractWebController
}
// --- 수정 (Modify) ---
protected function modify_form_process($uid): object
protected function modify_form_process($uid): CommonEntity
{
return $this->service->getEntity($uid);
}
@ -105,7 +106,7 @@ abstract class AbstractCRUDController extends AbstractWebController
}
}
protected function modify_process($uid, array $formDatas): object
protected function modify_process($uid, array $formDatas): CommonEntity
{
// POST 데이터를 DTO 객체로 변환
$formDatas[$this->service->getPKField()] = $uid;
@ -143,7 +144,7 @@ abstract class AbstractCRUDController extends AbstractWebController
}
// --- 삭제 (Delete) ---
protected function delete_process($uid): object
protected function delete_process($uid): CommonEntity
{
return $this->service->delete($uid);
}
@ -167,7 +168,7 @@ abstract class AbstractCRUDController extends AbstractWebController
}
// --- 상세보기 (View) ---
protected function view_process($uid): object
protected function view_process($uid): CommonEntity
{
return $this->service->getEntity($uid);
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -79,19 +79,23 @@ class ClientEntity extends CustomerEntity
public function setRole(mixed $role)
{
$roleArray = [];
// 입력된 데이터가 문자열인 경우에만 trim 및 explode 처리
if (is_string($role)) {
// 1. 양쪽의 불필요한 따옴표와 공백을 제거하여 깨끗한 문자열 확보
// trim()은 여기서 안전하게 호출됩니다.
$cleanRoleString = trim($role, " \t\n\r\0\x0B\"");
if (!empty($cleanRoleString)) {
$role = explode(DEFAULTS["DELIMITER_ROLE"], $cleanRoleString);
// 문자열을 구분자로 분리하여 배열로 만듭니다.
$roleArray = explode(DEFAULTS["DELIMITER_ROLE"], $cleanRoleString);
}
}
if (is_array($role)) {
//배열에도 불필요한 따옴표와 공백을 제거
$cleanedRoles = array_map(fn($item) => trim($item, " \t\n\r\0\x0B\""), $role);
$roleArray = array_filter($cleanedRoles);
// 입력된 데이터가 이미 배열인 경우 (modify_process에서 $formDatas가 배열로 넘어옴)
elseif (is_array($role)) {
$roleArray = $role;
}
// 💡 핵심: 최종적으로 DB에 삽입될 단일 CSV 문자열로 변환하여 저장합니다.
// 배열의 각 요소를 정리
$cleanedRoles = array_map(fn($item) => trim($item, " \t\n\r\0\x0B\""), $roleArray);
$roleArray = array_filter($cleanedRoles);
// 최종적으로 DB에 삽입될 단일 CSV 문자열로 변환하여 저장합니다.
$this->attributes['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $roleArray);
}
}

View File

@ -54,10 +54,12 @@ class UserEntity extends CommonEntity
}
// --- Setter Methods ---
public function setPasswd(string $password)
public function setPasswd(string|null $password = null)
{
// 비밀번호를 암호화하여 저장합니다.
$this->attributes['passwd'] = password_hash($password, PASSWORD_BCRYPT);
// 입력된 비밀번호가 null이 아니고 비어있지 않을 때만 해시 처리
if (!empty($password)) {
$this->attributes['passwd'] = password_hash($password, PASSWORD_BCRYPT);
}
}
/**
@ -68,19 +70,23 @@ class UserEntity extends CommonEntity
public function setRole(mixed $role)
{
$roleArray = [];
// 입력된 데이터가 문자열인 경우에만 trim 및 explode 처리
if (is_string($role)) {
// 1. 양쪽의 불필요한 따옴표와 공백을 제거하여 깨끗한 문자열 확보
// trim()은 여기서 안전하게 호출됩니다.
$cleanRoleString = trim($role, " \t\n\r\0\x0B\"");
if (!empty($cleanRoleString)) {
$role = explode(DEFAULTS["DELIMITER_ROLE"], $cleanRoleString);
// 문자열을 구분자로 분리하여 배열로 만듭니다.
$roleArray = explode(DEFAULTS["DELIMITER_ROLE"], $cleanRoleString);
}
}
if (is_array($role)) {
//배열에도 불필요한 따옴표와 공백을 제거
$cleanedRoles = array_map(fn($item) => trim($item, " \t\n\r\0\x0B\""), $role);
$roleArray = array_filter($cleanedRoles);
// 입력된 데이터가 이미 배열인 경우 (modify_process에서 $formDatas가 배열로 넘어옴)
elseif (is_array($role)) {
$roleArray = $role;
}
// 💡 핵심: 최종적으로 DB에 삽입될 단일 CSV 문자열로 변환하여 저장합니다.
// 배열의 각 요소를 정리
$cleanedRoles = array_map(fn($item) => trim($item, " \t\n\r\0\x0B\""), $roleArray);
$roleArray = array_filter($cleanedRoles);
// 최종적으로 DB에 삽입될 단일 CSV 문자열로 변환하여 저장합니다.
$this->attributes['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $roleArray);
}
}

View File

@ -59,7 +59,7 @@ abstract class CommonService
* 단일 엔티티를 조회합니다.
*/
abstract protected function getEntity_process(CommonEntity $entity): CommonEntity;
final public function getEntity(string|int|array $where, ?string $message = null): ?object
final public function getEntity(string|int|array $where, ?string $message = null): ?CommonEntity
{
try {
$entity = is_array($where) ? $this->model->where($where)->first() : $this->model->find($where);
@ -161,7 +161,7 @@ abstract class CommonService
return $pk;
}
protected function save_process(CommonEntity $entity): object
protected function save_process(CommonEntity $entity): CommonEntity
{
// INSERT 시 Entity의 PK는 0 또는 NULL이어야 함 (DB가 ID를 생성하도록)
$initialPK = $entity->getPK();
@ -175,7 +175,7 @@ abstract class CommonService
}
//생성용
protected function create_process(array $formDatas): object
protected function create_process(array $formDatas): CommonEntity
{
// 데이터 검증
$this->getFormService()->validate($formDatas);
@ -187,7 +187,7 @@ abstract class CommonService
}
return $this->save_process($entity);
}
final public function create(array $formDatas): object
final public function create(array $formDatas): CommonEntity
{
$db = \Config\Database::connect();
try {
@ -213,25 +213,18 @@ abstract class CommonService
}
//수정용
protected function modify_process($entity, array $formDatas): object
protected function modify_process($entity, array $formDatas): CommonEntity
{
foreach ($this->model->getAllowedFields() as $key) {
$formDatas[$key] = $formDatas[$key] ?? $entity->$key;
}
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
// 데이터 검증
// var_dump($this->getFormService()->getFormRules());
// dd($formDatas);
$this->getFormService()->validate($formDatas);
foreach ($formDatas as $key => $value) {
$entity->$key = $value;
}
// 2. 폼 데이터를 엔티티에 병합합니다. (fill() 사용)
$entity->fill($formDatas);
// var_dump($formDatas);
// dd($entity);
return $this->save_process($entity);
}
final public function modify(string|int $uid, array $formDatas): object
final public function modify(string|int $uid, array $formDatas): CommonEntity
{
$db = \Config\Database::connect();
try {
@ -240,11 +233,6 @@ abstract class CommonService
if (!$entity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 정보을 찾을수 없습니다.");
}
// 💡 동적으로 가져온 Entity 클래스 이름으로 instanceof 검사
$entityClass = $this->getEntityClass();
if (!$entity instanceof $entityClass) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 {$entityClass}만 가능");
}
//관리자 정보추가용
$formDatas['user_uid'] = $this->getAuthContext()->getUID();
$entity = $this->modify_process($entity, $formDatas);
@ -266,7 +254,7 @@ abstract class CommonService
}
//배치 작업용 수정
protected function batchjob_process($entity, array $formDatas): object
protected function batchjob_process($entity, array $formDatas): CommonEntity
{
$entity = $this->modify_process($entity, $formDatas);
return $entity;
@ -290,7 +278,7 @@ abstract class CommonService
}
//관리자 정보추가용
$formDatas['user_uid'] = $this->getAuthContext()->getUID();
$entities[] = $this->modify_process($entity, $formDatas);
$entities[] = $this->batchjob_process($entity, $formDatas);
}
return $entities;
} catch (\Throwable $e) {
@ -300,7 +288,7 @@ abstract class CommonService
}
//삭제용 (일반)
protected function delete_process($entity): object
protected function delete_process($entity): CommonEntity
{
$result = $this->model->delete($entity->getPK());
log_message('debug', $this->model->getLastQuery());
@ -311,7 +299,7 @@ abstract class CommonService
}
return $entity;
}
final public function delete(string|int $uid): object
final public function delete(string|int $uid): CommonEntity
{
$db = \Config\Database::connect();
try {
@ -347,7 +335,7 @@ abstract class CommonService
}
//삭제용 (배치 작업)
protected function batchjob_delete_process($entity): object
protected function batchjob_delete_process($entity): CommonEntity
{
$entity = $this->delete_process($entity);
return $entity;

View File

@ -115,14 +115,6 @@ class ClientService extends CustomerService
{
return $entity;
}
protected function create_process(array $formDatas): ClientEntity
{
return parent::create_process($formDatas);
}
protected function modify_process($entity, array $formDatas): ClientEntity
{
return parent::modify_process($entity, $formDatas);
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리

View File

@ -3,6 +3,7 @@
namespace App\Services\Customer\Wallet;
use App\DTOs\Customer\Wallet\AccountDTO;
use App\Entities\CommonEntity;
use App\Entities\Customer\ClientEntity;
use App\Entities\Customer\Wallet\AccountEntity;
use App\Forms\Customer\Wallet\AccountForm;
@ -118,12 +119,7 @@ class AccountService extends WalletService
{
return $entity;
}
protected function create_process(array $formDatas): AccountEntity
{
$entity = parent::create_process($formDatas);
return $entity;
}
protected function modify_process($entity, array $formDatas): AccountEntity
protected function modify_process($entity, array $formDatas): CommonEntity
{
throw new RuntimeException("예치금정보는 수정이 불가합니다.");
}

View File

@ -3,6 +3,7 @@
namespace App\Services\Customer\Wallet;
use App\DTOs\Customer\Wallet\CouponDTO;
use App\Entities\CommonEntity;
use App\Entities\Customer\ClientEntity;
use App\Entities\Customer\Wallet\CouponEntity;
use App\Forms\Customer\Wallet\CouponForm;
@ -109,12 +110,7 @@ class CouponService extends WalletService
{
return $entity;
}
protected function create_process(array $formDatas): CouponEntity
{
$entity = parent::create_process($formDatas);
return $entity;
}
protected function modify_process($entity, array $formDatas): CouponEntity
protected function modify_process($entity, array $formDatas): CommonEntity
{
throw new RuntimeException("쿠폰정보는 수정이 불가합니다.");
}

View File

@ -3,6 +3,7 @@
namespace App\Services\Customer\Wallet;
use App\DTOs\Customer\Wallet\PointDTO;
use App\Entities\CommonEntity;
use App\Entities\Customer\ClientEntity;
use App\Entities\Customer\Wallet\PointEntity;
use App\Forms\Customer\Wallet\PointForm;
@ -109,12 +110,7 @@ class PointService extends WalletService
{
return $entity;
}
protected function create_process(array $formDatas): PointEntity
{
$entity = parent::create_process($formDatas);
return $entity;
}
protected function modify_process($entity, array $formDatas): PointEntity
protected function modify_process($entity, array $formDatas): CommonEntity
{
throw new RuntimeException("포인트정보는 수정이 불가합니다.");
}

View File

@ -2,6 +2,7 @@
namespace App\Services\Customer\Wallet;
use App\Entities\CommonEntity;
use App\Entities\Customer\ClientEntity;
use App\Entities\PaymentEntity;
use App\Models\CommonModel;
@ -17,7 +18,7 @@ abstract class WalletService extends CustomerService
}
//기본기능
//생성
protected function create_process(array $formDatas): object
protected function create_process(array $formDatas): CommonEntity
{
if (!array_key_exists('clientinfo_uid', $formDatas)) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 고객정보가 정의되지 않았습니다.");

View File

@ -3,6 +3,7 @@
namespace App\Services\Equipment;
use App\DTOs\Equipment\CHASSISDTO;
use App\Entities\CommonEntity;
use App\Entities\Equipment\CHASSISEntity;
use App\Entities\Equipment\ServerEntity;
use App\Forms\Equipment\CHASSISForm;
@ -98,14 +99,6 @@ class CHASSISService extends EquipmentService
{
return $entity;
}
protected function create_process(array $formDatas): CHASSISEntity
{
return parent::create_process($formDatas);
}
protected function modify_process($entity, array $formDatas): CHASSISEntity
{
return parent::modify_process($entity, $formDatas);
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리
@ -126,7 +119,7 @@ class CHASSISService extends EquipmentService
}
return $entity;
}
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): CHASSISEntity
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): CommonEntity
{
//부품정보가져오기
/** @var CHASSISEntity $entity IDE에 entity type알려주기*/
@ -139,7 +132,7 @@ class CHASSISService extends EquipmentService
return parent::modify_process($entity, $formDatas);
}
public function detachFromServer(ServerEntity $serverEntity, array $formDatas = []): CHASSISEntity
public function detachFromServer(ServerEntity $serverEntity, array $formDatas = []): CommonEntity
{
//부품정보가져오기
/** @var CHASSISEntity $entity IDE에 entity type알려주기*/

View File

@ -101,14 +101,6 @@ class LineService extends EquipmentService
{
return $entity;
}
protected function create_process(array $formDatas): LineEntity
{
return parent::create_process($formDatas);
}
protected function modify_process($entity, array $formDatas): LineEntity
{
return parent::modify_process($entity, $formDatas);
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리

View File

@ -2,15 +2,16 @@
namespace App\Services\Equipment;
use RuntimeException;
use App\Services\Part\PartService;
use App\Models\Equipment\ServerPartModel;
use App\Helpers\Equipment\ServerPartHelper;
use App\Forms\Equipment\ServerPartForm;
use App\Entities\Part\PartEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Equipment\ServerEntity;
use App\DTOs\Equipment\ServerPartDTO;
use App\Entities\CommonEntity;
use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\PartEntity;
use App\Forms\Equipment\ServerPartForm;
use App\Helpers\Equipment\ServerPartHelper;
use App\Models\Equipment\ServerPartModel;
use App\Services\Part\PartService;
use RuntimeException;
class ServerPartService extends EquipmentService
{
@ -115,7 +116,7 @@ class ServerPartService extends EquipmentService
{
return $entity;
}
protected function create_process(array $formDatas): ServerPartEntity
protected function create_process(array $formDatas): CommonEntity
{
if (!array_key_exists('type', $formDatas)) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:부품형식이 지정되지 않았습니다.");
@ -144,7 +145,7 @@ class ServerPartService extends EquipmentService
}
return $entity;
}
protected function modify_process($entity, array $formDatas): ServerPartEntity
protected function modify_process($entity, array $formDatas): CommonEntity
{
if (!array_key_exists('type', $formDatas)) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:부품형식이 지정되지 않았습니다.");
@ -155,6 +156,9 @@ class ServerPartService extends EquipmentService
$formDatas['title'] = $partEntity->getTitle();
//서버파트 수정
$entity = parent::modify_process($entity, $formDatas);
if (!$entity instanceof ServerPartEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 PaymentEntity만 가능");
}
//서비스가 정의 되어 있으면
if ($entity->getServiceInfoUID() !== null) {
//월비용 서버파트 인경우 서비스 금액 재설정
@ -168,10 +172,13 @@ class ServerPartService extends EquipmentService
}
return $entity;
}
protected function delete_process($entity): ServerPartEntity
protected function delete_process($entity): CommonEntity
{
$this->getPartService($entity->getType())->detachFromServerPart($entity);
$entity = parent::delete_process($entity);
if (!$entity instanceof ServerPartEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 PaymentEntity만 가능");
}
//서비스가 정의 되어 있으면
if ($entity->getServiceInfoUID() !== null) {
//월비용 서버파트 인경우 서비스 금액 재설정

View File

@ -98,14 +98,6 @@ class CPUService extends PartType1Service
{
return $entity;
}
protected function create_process(array $formDatas): CPUEntity
{
return parent::create_process($formDatas);
}
protected function modify_process($entity, array $formDatas): CPUEntity
{
return parent::modify_process($entity, $formDatas);
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리

View File

@ -126,14 +126,6 @@ class CSService extends PartType2Service
{
return $entity;
}
protected function create_process(array $formDatas): CSEntity
{
return parent::create_process($formDatas);
}
protected function modify_process($entity, array $formDatas): CSEntity
{
return parent::modify_process($entity, $formDatas);
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리

View File

@ -101,14 +101,6 @@ class DISKService extends PartType1Service
{
return $entity;
}
protected function create_process(array $formDatas): DISKEntity
{
return parent::create_process($formDatas);
}
protected function modify_process($entity, array $formDatas): DISKEntity
{
return parent::modify_process($entity, $formDatas);
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리

View File

@ -117,14 +117,6 @@ class IPService extends PartType3Service
{
return $entity;
}
protected function create_process(array $formDatas): IPEntity
{
return parent::create_process($formDatas);
}
protected function modify_process($entity, array $formDatas): IPEntity
{
return parent::modify_process($entity, $formDatas);
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리

View File

@ -99,14 +99,6 @@ class RAMService extends PartType1Service
{
return $entity;
}
protected function create_process(array $formDatas): RAMEntity
{
return parent::create_process($formDatas);
}
protected function modify_process($entity, array $formDatas): RAMEntity
{
return parent::modify_process($entity, $formDatas);
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리

View File

@ -99,14 +99,6 @@ class SOFTWAREService extends PartType1Service
{
return $entity;
}
protected function create_process(array $formDatas): SOFTWAREEntity
{
return parent::create_process($formDatas);
}
protected function modify_process($entity, array $formDatas): SOFTWAREEntity
{
return parent::modify_process($entity, $formDatas);
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리

View File

@ -119,14 +119,6 @@ class SWITCHService extends PartType3Service
{
return $entity;
}
protected function create_process(array $formDatas): SWITCHEntity
{
return parent::create_process($formDatas);
}
protected function modify_process($entity, array $formDatas): SWITCHEntity
{
return parent::modify_process($entity, $formDatas);
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리

View File

@ -74,7 +74,7 @@
<div class="text-center fw-bold">고객 비고</div>
</div>
<div class="col-10">
<textarea name="history" class="form-control note-box"><?= $viewDatas['entity']->getHistory() ?></textarea>
<?= $viewDatas['helper']->getFieldForm('history', $viewDatas['entity']->getHistory(), $viewDatas) ?>
</div>
<div class="col-1">
<?= form_submit('', '저장', array("class" => "btn btn-outline btn-primary")); ?>

View File

@ -23,7 +23,7 @@
<td class="text-center" nowrap><?= view_cell("\App\Cells\Equipment\ServerCell::detail", ['serviceEntity' => $entity]) ?></td>
<td class="text-center" nowrap>
<?= form_open("/admin/customer/service/history/{$entity->getPK()}?return_url=" . urlencode(current_url()), ['method' => "post"]) ?>
<textarea name="history" class="form-control note-box"><?= $entity->getHistory() ?></textarea>
<?= $serviceCellDatas['helper']->getFieldForm('history', $entity->getHistory(), $serviceCellDatas) ?>
<?= form_submit('', '저장', array("class" => "btn btn-outline btn-primary m-3")); ?>
<?= form_close() ?>
</td>

View File

@ -115,7 +115,7 @@
if (typeof tinymce !== 'undefined') {
tinymce.remove(); // 모든 에디터 제거 후 재초기화
tinymce.init({
selector: 'textarea',
selector: 'textarea.tinymce',
license_key: 'gpl',
height: 250,
plugins: 'advlist autolink lists link image charmap preview anchor',

View File

@ -15,7 +15,7 @@ window.initFormModal = function (context) {
if (typeof tinymce !== "undefined") {
tinymce.remove(); // 기존 인스턴스 제거
tinymce.init({
selector: ".tinymce",
selector: "textarea.tinymce",
license_key: "gpl",
height: 250,
plugins: "advlist autolink lists link image charmap preview anchor",