From fa39511b13cb52d8fe334dedfd71aac228ca2060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Wed, 4 Feb 2026 11:18:22 +0900 Subject: [PATCH] dbmsv4 init...5 --- app/Entities/BoardEntity.php | 12 +++-- app/Entities/CommonEntity.php | 44 +++++++++++++++++-- app/Entities/Customer/ClientEntity.php | 6 +++ app/Entities/Customer/ServiceEntity.php | 35 +++++++++------ .../Customer/Wallet/AccountEntity.php | 10 ++--- app/Entities/Equipment/CHASSISEntity.php | 8 ++++ app/Entities/Equipment/LineEntity.php | 16 ++++--- app/Entities/Equipment/ServerEntity.php | 34 +++++++++----- app/Entities/Equipment/ServerPartEntity.php | 21 +++++---- app/Entities/MylogEntity.php | 8 ++++ app/Entities/PaymentEntity.php | 23 +++++++--- app/Entities/UserEntity.php | 9 ++-- app/Models/BoardModel.php | 6 ++- app/Models/CommonModel.php | 37 +++++++++++++++- app/Models/Customer/ClientModel.php | 10 +++-- app/Models/Customer/ServiceModel.php | 10 +++-- app/Models/Customer/Wallet/AccountModel.php | 5 ++- app/Models/Equipment/CHASSISModel.php | 11 +++-- app/Models/Equipment/LineModel.php | 10 +++-- app/Models/Equipment/ServerModel.php | 10 +++++ app/Models/Equipment/ServerPartModel.php | 13 ++++-- app/Models/MylogModel.php | 9 ++-- app/Models/PaymentModel.php | 11 +++-- app/Models/UserModel.php | 9 ++-- app/Services/CommonService.php | 1 + app/Services/Customer/ClientService.php | 3 -- app/Services/Equipment/ServerService.php | 36 ++++++++++++--- 27 files changed, 307 insertions(+), 100 deletions(-) diff --git a/app/Entities/BoardEntity.php b/app/Entities/BoardEntity.php index 7057d77..252f2a4 100644 --- a/app/Entities/BoardEntity.php +++ b/app/Entities/BoardEntity.php @@ -9,7 +9,13 @@ class BoardEntity extends CommonEntity { const PK = Model::PK; const TITLE = Model::TITLE; + protected array $nullableFields = [ + 'user_uid', + 'worker_uid', + ]; protected $attributes = [ + 'user_uid' => null, + 'worker_uid' => null, 'category' => '', 'title' => '', 'status' => '', @@ -19,15 +25,15 @@ class BoardEntity extends CommonEntity { parent::__construct($data); } - final public function getUserUid(): int|null + public function getUserUid(): int|null { return $this->user_uid ?? null; } - final public function getWorkerUid(): int|null + public function getWorkerUid(): int|null { return $this->worker_uid ?? null; } - final public function getCaregory(): string + public function getCaregory(): string { return $this->category ?? ""; } diff --git a/app/Entities/CommonEntity.php b/app/Entities/CommonEntity.php index 7f32162..578b6f8 100644 --- a/app/Entities/CommonEntity.php +++ b/app/Entities/CommonEntity.php @@ -8,45 +8,83 @@ abstract class CommonEntity extends Entity { protected $datamap = []; protected $dates = ['created_at', 'updated_at', 'deleted_at']; - //사용법 : $client->created_at->format('Y-m-d') - //비교방법 : if ($client->created_at < new \DateTime('2024-01-01')) { + + /** + * 이 엔티티에서 "빈문자/공백 입력은 NULL로 저장"해야 하는 필드 목록. + * 기본은 빈 배열이고, 각 Entity에서 필요한 것만 override해서 채우면 됨. + */ + protected array $nullableFields = []; + public function __construct(array|null $data = null) { parent::__construct($data); } - public function __get(string $key) + + final public function __get(string $key) { if (array_key_exists($key, $this->attributes)) { return $this->attributes[$key]; } return parent::__get($key); } + + /** + * 중요: Entity에 값이 들어오는 "모든 경로" (new Entity($data), fill(), $entity->field=...) + * 에서 공통 규칙을 적용하기 위해 __set을 정의. + */ + final public function __set(string $key, $value = null) + { + if (array_key_exists($key, $this->attributes)) { + + // 이 엔티티에서 NULL로 보정할 필드만 처리 (화이트리스트) + if (!empty($this->nullableFields) && in_array($key, $this->nullableFields, true)) { + if (is_string($value)) { + $value = trim($value); + } + $this->attributes[$key] = ($value === '' || $value === null) ? null : $value; + return; + } + + // 기본: 그대로 저장 + $this->attributes[$key] = $value; + return; + } + + parent::__set($key, $value); + } + final public function getPK(): int|string { $field = constant("static::PK"); return $this->attributes[$field] ?? ""; } + final public function getTitle(): string { $field = constant("static::TITLE"); return $this->attributes[$field] ?? ""; } + public function getCustomTitle(): string { return $this->getTitle(); } + final public function getStatus(): string { return $this->status ?? ""; } + final public function getUpdatedAt(): string { return $this->updated_at ?? ""; } + final public function getCreatedAt(): string { return $this->created_at ?? ""; } + final public function getDeletedAt(): string { return $this->deleted_at ?? ""; diff --git a/app/Entities/Customer/ClientEntity.php b/app/Entities/Customer/ClientEntity.php index a2a19e4..54cfb03 100644 --- a/app/Entities/Customer/ClientEntity.php +++ b/app/Entities/Customer/ClientEntity.php @@ -8,7 +8,13 @@ class ClientEntity extends CustomerEntity { const PK = ClientModel::PK; const TITLE = ClientModel::TITLE; + protected array $nullableFields = [ + 'id', + 'passwd', + ]; protected $attributes = [ + 'id' => null, + 'passwd' => null, 'site' => '', 'name' => '', 'phone' => '', diff --git a/app/Entities/Customer/ServiceEntity.php b/app/Entities/Customer/ServiceEntity.php index e41e5c0..9af46e5 100644 --- a/app/Entities/Customer/ServiceEntity.php +++ b/app/Entities/Customer/ServiceEntity.php @@ -8,7 +8,12 @@ class ServiceEntity extends CustomerEntity { const PK = ServiceModel::PK; const TITLE = ServiceModel::TITLE; + protected array $nullableFields = [ + 'serverinfo_uid', + 'end_at' + ]; protected $attributes = [ + 'serverinfo_uid' => null, 'code' => '', 'title' => '', 'site' => '', @@ -20,7 +25,7 @@ class ServiceEntity extends CustomerEntity 'sale' => 0, 'amount' => 0, 'start_at' => '', - 'end_at' => '', + 'end_at' => null, 'status' => '', 'history' => '' ]; @@ -28,58 +33,62 @@ class ServiceEntity extends CustomerEntity { parent::__construct($data); } - final public function getUserUid(): int|null + public function getUserUid(): int|null { return $this->user_uid ?? null; } - final public function getClientInfoUid(): int|null + public function getClientInfoUid(): int|null { return $this->clientinfo_uid ?? null; } - final public function getServerInfoUid(): int|null + public function getServerInfoUid(): int|null { return $this->serverinfo_uid ?? null; } //기본기능용 - final public function getCode(): string + public function getCode(): string { return $this->code ?? ''; } - final public function getSite(): string + public function getSite(): string { return $this->site ?? ''; } - final public function getLocation(): string + public function getLocation(): string { return $this->location ?? ''; } - final public function getBillingAt(): string + public function getBillingAt(): string { return $this->billing_at ?? ''; } //청구금액->기본:상면비+회선비+서버금액(price)+서버파트연결(월비용)-할인액 //상면비 - final public function getRack(): int + public function getRack(): int { return $this->rack ?? 0; } //회선비 - final public function getLine(): int + public function getLine(): int { return $this->line ?? 0; } - final public function getSale(): int + public function getSale(): int { return $this->sale ?? 0; } - final public function getAmount(): int + public function getAmount(): int { return $this->amount ?? 0; } - final public function getStartAt(): string + public function getStartAt(): string { return $this->start_at ?? ''; } + public function getEndAt(): string|null + { + return $this->end_at ?? null; + } public function getHistory(): string { return $this->history ?? ''; diff --git a/app/Entities/Customer/Wallet/AccountEntity.php b/app/Entities/Customer/Wallet/AccountEntity.php index 086c7e8..1977577 100644 --- a/app/Entities/Customer/Wallet/AccountEntity.php +++ b/app/Entities/Customer/Wallet/AccountEntity.php @@ -8,16 +8,14 @@ class AccountEntity extends WalletEntity { const PK = AccountModel::PK; const TITLE = AccountModel::TITLE; - protected $casts = [ - 'clientinfo_uid' => 'integer', - 'user_uid' => '?integer', + protected array $nullableFields = [ + 'alias' ]; + protected $attributes = [ - 'clientinfo_uid' => null, - 'user_uid' => null, 'title' => '', 'bank' => '', - 'alias' => '', + 'alias' => null, 'issue_at' => '', 'amount' => 0, 'balance' => 0, diff --git a/app/Entities/Equipment/CHASSISEntity.php b/app/Entities/Equipment/CHASSISEntity.php index c467a81..5c4ea80 100644 --- a/app/Entities/Equipment/CHASSISEntity.php +++ b/app/Entities/Equipment/CHASSISEntity.php @@ -8,14 +8,22 @@ class CHASSISEntity extends EquipmentEntity { const PK = CHASSISModel::PK; const TITLE = CHASSISModel::TITLE; + protected array $nullableFields = [ + 'cpuinfo_uid', + 'raminfo_uid', + 'diskinfo_uid', + ]; protected $attributes = [ 'title' => '', 'price' => 0, 'used' => 0, 'stock' => 0, 'status' => '', + 'cpuinfo_uid' => null, 'cpu_cnt' => 0, + 'raminfo_uid' => null, 'ram_cnt' => 0, + 'diskinfo_uid' => null, 'disk_cnt' => 0, ]; public function __construct(array|null $data = null) diff --git a/app/Entities/Equipment/LineEntity.php b/app/Entities/Equipment/LineEntity.php index c373429..466c889 100644 --- a/app/Entities/Equipment/LineEntity.php +++ b/app/Entities/Equipment/LineEntity.php @@ -7,13 +7,17 @@ use App\Models\Equipment\LineModel; class LineEntity extends EquipmentEntity { const PK = LineModel::PK; + protected array $nullableFields = [ + 'start_at', + 'end_at', + ]; protected $attributes = [ 'title' => '', 'type' => '', 'protocol' => '', 'bandwith' => '', - 'start_at' => 0, - 'end_at' => 0, + 'start_at' => null, + 'end_at' => null, 'status' => '', 'content' => '', ]; @@ -34,13 +38,13 @@ class LineEntity extends EquipmentEntity { return $this->bandwith ?? ''; } - public function getStartAt(): string + public function getStartAt(): string|null { - return $this->start_at ?? ''; + return $this->start_at ?? null; } - public function getEndAt(): string + public function getEndAt(): string|null { - return $this->end_at ?? ''; + return $this->end_at ?? null; } public function getContent(): string { diff --git a/app/Entities/Equipment/ServerEntity.php b/app/Entities/Equipment/ServerEntity.php index 73084aa..03c0cf7 100644 --- a/app/Entities/Equipment/ServerEntity.php +++ b/app/Entities/Equipment/ServerEntity.php @@ -9,8 +9,18 @@ class ServerEntity extends EquipmentEntity const PK = ServerModel::PK; const TITLE = ServerModel::TITLE; + protected array $nullableFields = [ + 'clientinfo_uid', + 'serviceinfo_uid', + 'chassisinfo_uid', + 'switchinfo_uid', + 'ip', + 'viewer', + 'os', + 'format_at', + ]; + protected $attributes = [ - 'user_uid' => null, 'clientinfo_uid' => null, 'serviceinfo_uid' => null, 'chassisinfo_uid' => null, @@ -23,7 +33,7 @@ class ServerEntity extends EquipmentEntity 'os' => null, 'price' => 0, 'manufactur_at' => '', - 'format_at' => '', + 'format_at' => null, 'status' => '', ]; public function __construct(array|null $data = null) @@ -65,21 +75,23 @@ class ServerEntity extends EquipmentEntity { return $this->code ?? null; } - public function getType(): string + public function getType(): ?string { return $this->type ?? null; } - public function getIP(): string + public function getIP(): ?string { - return $this->ip ?? ''; + return $this->ip ?? null; } - public function getViewer(): string + + public function getViewer(): ?string { - return $this->viewer ?? ''; + return $this->viewer ?? null; } - public function getOS(): string + + public function getOS(): ?string { - return $this->os ?? ''; + return $this->os ?? null; } public function getPrice(): int { @@ -89,8 +101,8 @@ class ServerEntity extends EquipmentEntity { return $this->manufactur_at ?? ''; } - public function getFormatAt(): string + public function getFormatAt(): ?string { - return $this->format_at ?? ''; + return $this->format_at ?? null; } } diff --git a/app/Entities/Equipment/ServerPartEntity.php b/app/Entities/Equipment/ServerPartEntity.php index 536a0b9..5c244b1 100644 --- a/app/Entities/Equipment/ServerPartEntity.php +++ b/app/Entities/Equipment/ServerPartEntity.php @@ -8,19 +8,24 @@ class ServerPartEntity extends EquipmentEntity { const PK = ServerPartModel::PK; const TITLE = ServerPartModel::TITLE; - + protected array $nullableFields = [ + 'clientinfo_uid', + 'part_uid', + 'serviceinfo_uid', + 'billing_at', + 'extra', + ]; protected $attributes = [ 'clientinfo_uid' => null, 'part_uid' => null, - 'serverinfo_uid' => null, 'serviceinfo_uid' => null, 'title' => '', 'type' => '', 'billing' => '', - 'billing_at' => '', + 'billing_at' => null, 'cnt' => 0, 'amount' => 0, - 'extra' => '', + 'extra' => null, ]; public function __construct(array|null $data = null) { @@ -79,9 +84,9 @@ class ServerPartEntity extends EquipmentEntity { return $this->billing ?? ""; } - public function getBillingAt(): string + public function getBillingAt(): string|null { - return $this->billing_at ?? ""; + return $this->billing_at ?? null; } public function getCnt(): int { @@ -91,8 +96,8 @@ class ServerPartEntity extends EquipmentEntity { return $this->amount ?? 0; } - public function getExtra(): string + public function getExtra(): string|null { - return $this->extra ?? ''; + return $this->extra ?? null; } } diff --git a/app/Entities/MylogEntity.php b/app/Entities/MylogEntity.php index 56be51e..1be3558 100644 --- a/app/Entities/MylogEntity.php +++ b/app/Entities/MylogEntity.php @@ -8,7 +8,11 @@ class MylogEntity extends CommonEntity { const PK = Model::PK; const TITLE = Model::TITLE; + protected array $nullableFields = [ + 'user_uid', + ]; protected $attributes = [ + 'user_uid' => null, 'title' => '', 'status' => '', 'content' => '' @@ -19,4 +23,8 @@ class MylogEntity extends CommonEntity } //공통부분 //Common Function + public function getUserUid(): int|null + { + return $this->user_uid ?? null; + } } diff --git a/app/Entities/PaymentEntity.php b/app/Entities/PaymentEntity.php index d7f1206..2983661 100644 --- a/app/Entities/PaymentEntity.php +++ b/app/Entities/PaymentEntity.php @@ -9,13 +9,20 @@ class PaymentEntity extends CommonEntity { const PK = PaymentModel::PK; const TITLE = PaymentModel::TITLE; + protected array $nullableFields = [ + 'serviceinfo_uid', + 'serverpartinfo_uid', + 'pay', + ]; protected $attributes = [ + 'serviceinfo_uid' => null, + 'serverpartinfo_uid' => null, 'title' => '', 'amount' => 0, 'billing' => "", 'billing_at' => "", 'billing_month' => 0, - 'pay' => "", + 'pay' => null, 'status' => '', 'content' => '' ]; @@ -23,18 +30,22 @@ class PaymentEntity extends CommonEntity { parent::__construct($data); } - final public function getUserUid(): int|null + public function getUserUid(): int|null { return $this->user_uid ?? null; } - final public function getClientInfoUid(): int|null + public function getClientInfoUid(): int|null { return $this->clientinfo_uid ?? null; } - final public function getServiceInfoUid(): int|null + public function getServiceInfoUid(): int|null { return $this->serviceinfo_uid ?? null; } + public function getServerPartInfoUid(): int|null + { + return $this->serverpartinfo_uid ?? null; + } //기본기능 public function getCustomTitle(): string { @@ -56,9 +67,9 @@ class PaymentEntity extends CommonEntity { return $this->billing_month ?? 0; } - public function getPay(): string + public function getPay(): int|null { - return $this->pay ?? ""; + return $this->pay ?? null; } public function getContent(): string { diff --git a/app/Entities/UserEntity.php b/app/Entities/UserEntity.php index d66143d..e5b8862 100644 --- a/app/Entities/UserEntity.php +++ b/app/Entities/UserEntity.php @@ -9,18 +9,15 @@ class UserEntity extends CommonEntity { const PK = Model::PK; const TITLE = Model::TITLE; - /** - * @var array DB 컬럼 타입이 VARCHAR(255)이고 CSV 형식으로 통일하기 위해 json-array 캐스팅을 제거합니다. - */ - protected $casts = [ - // 'role' => 'json-array', // 🚫 CSV 형식 저장을 위해 제거 + protected array $nullableFields = [ + 'mobile', ]; protected $attributes = [ 'id' => '', 'passwd' => '', 'name' => "", 'email' => "", - 'mobile' => '', + 'mobile' => null, 'role' => "", 'status' => '', ]; diff --git a/app/Models/BoardModel.php b/app/Models/BoardModel.php index 6139bfd..f0bc64d 100644 --- a/app/Models/BoardModel.php +++ b/app/Models/BoardModel.php @@ -7,11 +7,15 @@ use App\Entities\BoardEntity; class BoardModel extends CommonModel { const TABLE = "boardinfo"; - const PK = "uid"; + const PK = "uid"; const TITLE = "title"; protected $table = self::TABLE; protected $primaryKey = self::PK; protected $returnType = BoardEntity::class; + protected array $nullableFields = [ + 'user_uid', + 'worker_uid', + ]; protected $allowedFields = [ "uid", "user_uid", diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index 057f3ed..2c60d32 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -43,14 +43,16 @@ abstract class CommonModel extends Model // Callbacks protected $allowCallbacks = true; - protected $beforeInsert = []; //Field 값이 NULL일 경우 DB Default값 적용용 + protected $beforeInsert = ['emptyStringToNull']; //Field 값이 NULL일 경우 DB Default값 적용용 protected $afterInsert = []; - protected $beforeUpdate = []; //Field 값이 NULL일 경우 DB Default값 적용용 + protected $beforeUpdate = ['emptyStringToNull']; //Field 값이 NULL일 경우 DB Default값 적용용 protected $afterUpdate = []; protected $beforeFind = []; protected $afterFind = []; protected $beforeDelete = []; protected $afterDelete = []; + + protected array $nullableFields = []; // 모델별로 override protected function __construct() { parent::__construct(); @@ -75,4 +77,35 @@ abstract class CommonModel extends Model { return $this->allowedFields; } + + protected function emptyStringToNull(array $data): array + { + if (!isset($data['data']) || !is_array($data['data'])) { + return $data; + } + + // 공통 모델에서는 아무 필드도 강제하지 않음 (안전) + if (empty($this->nullableFields)) { + return $data; + } + + foreach ($this->nullableFields as $field) { + if (array_key_exists($field, $data['data'])) { + $v = $data['data'][$field]; + + // 문자열이면 trim 후, 빈문자면 null + if (is_string($v)) { + $v = trim($v); + $data['data'][$field] = ($v === '') ? null : $v; + } else { + // 문자열이 아닌데도 '' 같은 케이스 방어 (거의 없음) + if ($v === '') + $data['data'][$field] = null; + } + } + } + + return $data; + } + } diff --git a/app/Models/Customer/ClientModel.php b/app/Models/Customer/ClientModel.php index 13a0c59..00773a3 100644 --- a/app/Models/Customer/ClientModel.php +++ b/app/Models/Customer/ClientModel.php @@ -9,10 +9,14 @@ class ClientModel extends CustomerModel const TABLE = "clientinfo"; const PK = "uid"; const TITLE = "name"; - protected $table = self::TABLE; + protected $table = self::TABLE; // protected $useAutoIncrement = false; - protected $primaryKey = self::PK; - protected $returnType = ClientEntity::class; + protected $primaryKey = self::PK; + protected $returnType = ClientEntity::class; + protected array $nullableFields = [ + 'id', + 'passwd', + ]; protected $allowedFields = [ "uid", "user_uid", diff --git a/app/Models/Customer/ServiceModel.php b/app/Models/Customer/ServiceModel.php index b3e693d..4389e4e 100644 --- a/app/Models/Customer/ServiceModel.php +++ b/app/Models/Customer/ServiceModel.php @@ -10,10 +10,14 @@ class ServiceModel extends CustomerModel const TABLE = "serviceinfo"; const PK = "uid"; const TITLE = "title"; - protected $table = self::TABLE; + protected $table = self::TABLE; // protected $useAutoIncrement = false; - protected $primaryKey = self::PK; - protected $returnType = ServiceEntity::class; + protected $primaryKey = self::PK; + protected $returnType = ServiceEntity::class; + protected array $nullableFields = [ + 'serverinfo_uid', + 'end_at' + ]; protected $allowedFields = [ "uid", "user_uid", diff --git a/app/Models/Customer/Wallet/AccountModel.php b/app/Models/Customer/Wallet/AccountModel.php index 5b3a23e..699be35 100644 --- a/app/Models/Customer/Wallet/AccountModel.php +++ b/app/Models/Customer/Wallet/AccountModel.php @@ -7,11 +7,14 @@ use App\Entities\Customer\Wallet\AccountEntity; class AccountModel extends WalletModel { const TABLE = "accountinfo"; - const PK = "uid"; + const PK = "uid"; const TITLE = "title"; protected $table = self::TABLE; protected $primaryKey = self::PK; protected $returnType = AccountEntity::class; + protected array $nullableFields = [ + 'alias' + ]; protected $allowedFields = [ "uid", "user_uid", diff --git a/app/Models/Equipment/CHASSISModel.php b/app/Models/Equipment/CHASSISModel.php index 0b366b2..2be40ef 100644 --- a/app/Models/Equipment/CHASSISModel.php +++ b/app/Models/Equipment/CHASSISModel.php @@ -9,10 +9,15 @@ class CHASSISModel extends EquipmentModel const TABLE = "chassisinfo"; const PK = "uid"; const TITLE = "title"; - protected $table = self::TABLE; - protected $primaryKey = self::PK; + protected $table = self::TABLE; + protected $primaryKey = self::PK; // protected $useAutoIncrement = false; - protected $returnType = CHASSISEntity::class; + protected $returnType = CHASSISEntity::class; + protected array $nullableFields = [ + 'cpuinfo_uid', + 'raminfo_uid', + 'diskinfo_uid', + ]; protected $allowedFields = [ "uid", "title", diff --git a/app/Models/Equipment/LineModel.php b/app/Models/Equipment/LineModel.php index 1804c49..9a9a9ca 100644 --- a/app/Models/Equipment/LineModel.php +++ b/app/Models/Equipment/LineModel.php @@ -9,9 +9,13 @@ class LineModel extends EquipmentModel const TABLE = "lineinfo"; const PK = "uid"; const TITLE = "title"; - protected $table = self::TABLE; - protected $primaryKey = self::PK; - protected $returnType = LineEntity::class; + protected $table = self::TABLE; + protected $primaryKey = self::PK; + protected $returnType = LineEntity::class; + protected array $nullableFields = [ + 'start_at', + 'end_at', + ]; protected $allowedFields = [ "uid", "type", diff --git a/app/Models/Equipment/ServerModel.php b/app/Models/Equipment/ServerModel.php index c5fd8e1..6a2a27e 100644 --- a/app/Models/Equipment/ServerModel.php +++ b/app/Models/Equipment/ServerModel.php @@ -13,6 +13,16 @@ class ServerModel extends EquipmentModel // protected $useAutoIncrement = false; protected $primaryKey = self::PK; protected $returnType = ServerEntity::class; + protected array $nullableFields = [ + 'clientinfo_uid', + 'serviceinfo_uid', + 'chassisinfo_uid', + 'switchinfo_uid', + 'ip', + 'viewer', + 'os', + 'format_at', + ]; protected $allowedFields = [ "uid", "user_uid", diff --git a/app/Models/Equipment/ServerPartModel.php b/app/Models/Equipment/ServerPartModel.php index d1adf3b..2605501 100644 --- a/app/Models/Equipment/ServerPartModel.php +++ b/app/Models/Equipment/ServerPartModel.php @@ -9,9 +9,16 @@ class ServerPartModel extends EquipmentModel const TABLE = "serverpartinfo"; const PK = "uid"; const TITLE = "title"; - protected $table = self::TABLE; - protected $primaryKey = self::PK; - protected $returnType = ServerPartEntity::class; + protected $table = self::TABLE; + protected $primaryKey = self::PK; + protected $returnType = ServerPartEntity::class; + protected array $nullableFields = [ + 'clientinfo_uid', + 'part_uid', + 'serviceinfo_uid', + 'billing_at', + 'extra', + ]; protected $allowedFields = [ "uid", "part_uid", diff --git a/app/Models/MylogModel.php b/app/Models/MylogModel.php index 05f5caf..61e2ee8 100644 --- a/app/Models/MylogModel.php +++ b/app/Models/MylogModel.php @@ -9,9 +9,12 @@ class MylogModel extends CommonModel const TABLE = "mylog"; const PK = "uid"; const TITLE = "title"; - protected $table = self::TABLE; - protected $primaryKey = self::PK; - protected $returnType = MylogEntity::class; + protected $table = self::TABLE; + protected $primaryKey = self::PK; + protected $returnType = MylogEntity::class; + protected array $nullableFields = [ + 'user_uid', + ]; protected $allowedFields = [ "uid", "user_uid", diff --git a/app/Models/PaymentModel.php b/app/Models/PaymentModel.php index 3db1eda..dd11da8 100644 --- a/app/Models/PaymentModel.php +++ b/app/Models/PaymentModel.php @@ -9,9 +9,14 @@ class PaymentModel extends CommonModel const TABLE = "payment"; const PK = "uid"; const TITLE = "title"; - protected $table = self::TABLE; - protected $primaryKey = self::PK; - protected $returnType = PaymentEntity::class; + protected $table = self::TABLE; + protected $primaryKey = self::PK; + protected $returnType = PaymentEntity::class; + protected array $nullableFields = [ + 'serviceinfo_uid', + 'serverpartinfo_uid', + 'pay', + ]; protected $allowedFields = [ "uid", "user_uid", diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index 762b3f3..7ab2521 100644 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -9,9 +9,12 @@ class UserModel extends CommonModel const TABLE = "user"; const PK = "uid"; const TITLE = "name"; - protected $table = self::TABLE; - protected $primaryKey = self::PK; - protected $returnType = UserEntity::class; + protected $table = self::TABLE; + protected $primaryKey = self::PK; + protected $returnType = UserEntity::class; + protected array $nullableFields = [ + 'mobile', + ]; protected $allowedFields = [ "uid", "id", diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index de43a2d..1e1c906 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -238,6 +238,7 @@ abstract class CommonService try { // INSERT 시 Entity의 PK는 0 또는 NULL이어야 함 (DB가 ID를 생성하도록) $initialPK = $entity->getPK(); + // dd($entity); $result = $this->model->save($entity); // 최종적으로 DB에 반영된 PK를 반환받습니다. (UPDATE이면 기존 PK, INSERT이면 새 PK) $entity->{$this->getPKField()} = $this->handle_save_result($result, $initialPK); diff --git a/app/Services/Customer/ClientService.php b/app/Services/Customer/ClientService.php index 6b711f9..90f750c 100644 --- a/app/Services/Customer/ClientService.php +++ b/app/Services/Customer/ClientService.php @@ -62,9 +62,6 @@ class ClientService extends CustomerService ))); $formDatas[$field] = $value; break; - case "format_at": - $formDatas[$field] = $value === '' ? null : $value; - break; default: $formDatas = parent::action_process_fieldhook($field, $value, $formDatas); break; diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index 4a2cd3d..5a7e51e 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -120,21 +120,33 @@ class ServerService extends EquipmentService { return $entity; } + + protected function action_process_fieldhook(string $field, $value, array $formDatas): array + { + switch ($field) { + default: + $formDatas = parent::action_process_fieldhook($field, $value, $formDatas); + break; + } + return $formDatas; + } protected function create_process(array $formDatas): ServerEntity { $entity = parent::create_process($formDatas); if (!$entity instanceof ServerEntity) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServerEntity만 가능"); } - //서버추가시 서버파트 자동추가용 - // dd($entity); + //새로운 IP 추가 (IP가 정의 되어 있으면) if ($entity->getIP()) { service('part_ipservice')->attachToServer($entity); } + //새로운 Switch 추가 (Switch가 정의 되어 있으면) if ($entity->getSwitchInfoUid()) { service('part_switchservice')->attachToServer($entity); } + //새로운 Chassis 추가 (Chassis가 정의 되어 있으면) service('equipment_chassisservice')->attachToServer($entity); + //새로운 ServerPart 추가 (ServerPart가 정의 되어 있으면) service('equipment_serverpartservice')->attachToServer($entity); return $entity; } @@ -150,22 +162,32 @@ class ServerService extends EquipmentService if (!$entity instanceof ServerEntity) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServerEntity만 가능"); } - //서버정보변경시 서버파트 정보변경용 //IP변경 if ($oldEntity->getIP() !== $entity->getIP()) { + //기존 IP 제거 service('part_ipservice')->detachFromServer($oldEntity); - service('part_ipservice')->attachToServer($entity); + //새로운 IP 추가 (IP가 정의 되어 있으면) + if ($entity->getIP()) { + service('part_ipservice')->attachToServer($entity); + } } //SWITCH변경 if ($oldEntity->getSwitchInfoUid() !== $entity->getSwitchInfoUid()) { service('part_switchservice')->detachFromServer($oldEntity); - service('part_switchservice')->attachToServer($entity); + //새로운 Switch 추가 (Switch가 정의 되어 있으면) + if ($entity->getSwitchInfoUid()) { + service('part_switchservice')->attachToServer($entity); + } } //샷시변경 - if ($oldEntity->getSwitchInfoUid() !== $entity->getSwitchInfoUid()) { + if ($oldEntity->getChassisInfoUid() !== $entity->getChassisInfoUid()) { service('equipment_chassisservice')->detachFromServer($oldEntity); - service('equipment_chassisservice')->attachToServer($entity); + //새로운 Chassis 추가 (Chassis가 정의 되어 있으면) + if ($entity->getChassisInfoUid()) { + service('equipment_chassisservice')->attachToServer($entity); + } } + //서비스변경 if ($entity->getServiceInfoUid() !== null) { //서비스가 정의 되어 있으면 $serviceEntity = service('customer_serviceservice')->getEntity($entity->getServiceInfoUid()); if (!$serviceEntity instanceof ServiceEntity) {