dbmsv4 init...5

This commit is contained in:
최준흠 2026-02-04 11:18:22 +09:00
parent 777ea0f2ff
commit fa39511b13
27 changed files with 307 additions and 100 deletions

View File

@ -9,7 +9,13 @@ class BoardEntity extends CommonEntity
{ {
const PK = Model::PK; const PK = Model::PK;
const TITLE = Model::TITLE; const TITLE = Model::TITLE;
protected array $nullableFields = [
'user_uid',
'worker_uid',
];
protected $attributes = [ protected $attributes = [
'user_uid' => null,
'worker_uid' => null,
'category' => '', 'category' => '',
'title' => '', 'title' => '',
'status' => '', 'status' => '',
@ -19,15 +25,15 @@ class BoardEntity extends CommonEntity
{ {
parent::__construct($data); parent::__construct($data);
} }
final public function getUserUid(): int|null public function getUserUid(): int|null
{ {
return $this->user_uid ?? null; return $this->user_uid ?? null;
} }
final public function getWorkerUid(): int|null public function getWorkerUid(): int|null
{ {
return $this->worker_uid ?? null; return $this->worker_uid ?? null;
} }
final public function getCaregory(): string public function getCaregory(): string
{ {
return $this->category ?? ""; return $this->category ?? "";
} }

View File

@ -8,45 +8,83 @@ abstract class CommonEntity extends Entity
{ {
protected $datamap = []; protected $datamap = [];
protected $dates = ['created_at', 'updated_at', 'deleted_at']; 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) public function __construct(array|null $data = null)
{ {
parent::__construct($data); parent::__construct($data);
} }
public function __get(string $key)
final public function __get(string $key)
{ {
if (array_key_exists($key, $this->attributes)) { if (array_key_exists($key, $this->attributes)) {
return $this->attributes[$key]; return $this->attributes[$key];
} }
return parent::__get($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 final public function getPK(): int|string
{ {
$field = constant("static::PK"); $field = constant("static::PK");
return $this->attributes[$field] ?? ""; return $this->attributes[$field] ?? "";
} }
final public function getTitle(): string final public function getTitle(): string
{ {
$field = constant("static::TITLE"); $field = constant("static::TITLE");
return $this->attributes[$field] ?? ""; return $this->attributes[$field] ?? "";
} }
public function getCustomTitle(): string public function getCustomTitle(): string
{ {
return $this->getTitle(); return $this->getTitle();
} }
final public function getStatus(): string final public function getStatus(): string
{ {
return $this->status ?? ""; return $this->status ?? "";
} }
final public function getUpdatedAt(): string final public function getUpdatedAt(): string
{ {
return $this->updated_at ?? ""; return $this->updated_at ?? "";
} }
final public function getCreatedAt(): string final public function getCreatedAt(): string
{ {
return $this->created_at ?? ""; return $this->created_at ?? "";
} }
final public function getDeletedAt(): string final public function getDeletedAt(): string
{ {
return $this->deleted_at ?? ""; return $this->deleted_at ?? "";

View File

@ -8,7 +8,13 @@ class ClientEntity extends CustomerEntity
{ {
const PK = ClientModel::PK; const PK = ClientModel::PK;
const TITLE = ClientModel::TITLE; const TITLE = ClientModel::TITLE;
protected array $nullableFields = [
'id',
'passwd',
];
protected $attributes = [ protected $attributes = [
'id' => null,
'passwd' => null,
'site' => '', 'site' => '',
'name' => '', 'name' => '',
'phone' => '', 'phone' => '',

View File

@ -8,7 +8,12 @@ class ServiceEntity extends CustomerEntity
{ {
const PK = ServiceModel::PK; const PK = ServiceModel::PK;
const TITLE = ServiceModel::TITLE; const TITLE = ServiceModel::TITLE;
protected array $nullableFields = [
'serverinfo_uid',
'end_at'
];
protected $attributes = [ protected $attributes = [
'serverinfo_uid' => null,
'code' => '', 'code' => '',
'title' => '', 'title' => '',
'site' => '', 'site' => '',
@ -20,7 +25,7 @@ class ServiceEntity extends CustomerEntity
'sale' => 0, 'sale' => 0,
'amount' => 0, 'amount' => 0,
'start_at' => '', 'start_at' => '',
'end_at' => '', 'end_at' => null,
'status' => '', 'status' => '',
'history' => '' 'history' => ''
]; ];
@ -28,58 +33,62 @@ class ServiceEntity extends CustomerEntity
{ {
parent::__construct($data); parent::__construct($data);
} }
final public function getUserUid(): int|null public function getUserUid(): int|null
{ {
return $this->user_uid ?? null; return $this->user_uid ?? null;
} }
final public function getClientInfoUid(): int|null public function getClientInfoUid(): int|null
{ {
return $this->clientinfo_uid ?? null; return $this->clientinfo_uid ?? null;
} }
final public function getServerInfoUid(): int|null public function getServerInfoUid(): int|null
{ {
return $this->serverinfo_uid ?? null; return $this->serverinfo_uid ?? null;
} }
//기본기능용 //기본기능용
final public function getCode(): string public function getCode(): string
{ {
return $this->code ?? ''; return $this->code ?? '';
} }
final public function getSite(): string public function getSite(): string
{ {
return $this->site ?? ''; return $this->site ?? '';
} }
final public function getLocation(): string public function getLocation(): string
{ {
return $this->location ?? ''; return $this->location ?? '';
} }
final public function getBillingAt(): string public function getBillingAt(): string
{ {
return $this->billing_at ?? ''; return $this->billing_at ?? '';
} }
//청구금액->기본:상면비+회선비+서버금액(price)+서버파트연결(월비용)-할인액 //청구금액->기본:상면비+회선비+서버금액(price)+서버파트연결(월비용)-할인액
//상면비 //상면비
final public function getRack(): int public function getRack(): int
{ {
return $this->rack ?? 0; return $this->rack ?? 0;
} }
//회선비 //회선비
final public function getLine(): int public function getLine(): int
{ {
return $this->line ?? 0; return $this->line ?? 0;
} }
final public function getSale(): int public function getSale(): int
{ {
return $this->sale ?? 0; return $this->sale ?? 0;
} }
final public function getAmount(): int public function getAmount(): int
{ {
return $this->amount ?? 0; return $this->amount ?? 0;
} }
final public function getStartAt(): string public function getStartAt(): string
{ {
return $this->start_at ?? ''; return $this->start_at ?? '';
} }
public function getEndAt(): string|null
{
return $this->end_at ?? null;
}
public function getHistory(): string public function getHistory(): string
{ {
return $this->history ?? ''; return $this->history ?? '';

View File

@ -8,16 +8,14 @@ class AccountEntity extends WalletEntity
{ {
const PK = AccountModel::PK; const PK = AccountModel::PK;
const TITLE = AccountModel::TITLE; const TITLE = AccountModel::TITLE;
protected $casts = [ protected array $nullableFields = [
'clientinfo_uid' => 'integer', 'alias'
'user_uid' => '?integer',
]; ];
protected $attributes = [ protected $attributes = [
'clientinfo_uid' => null,
'user_uid' => null,
'title' => '', 'title' => '',
'bank' => '', 'bank' => '',
'alias' => '', 'alias' => null,
'issue_at' => '', 'issue_at' => '',
'amount' => 0, 'amount' => 0,
'balance' => 0, 'balance' => 0,

View File

@ -8,14 +8,22 @@ class CHASSISEntity extends EquipmentEntity
{ {
const PK = CHASSISModel::PK; const PK = CHASSISModel::PK;
const TITLE = CHASSISModel::TITLE; const TITLE = CHASSISModel::TITLE;
protected array $nullableFields = [
'cpuinfo_uid',
'raminfo_uid',
'diskinfo_uid',
];
protected $attributes = [ protected $attributes = [
'title' => '', 'title' => '',
'price' => 0, 'price' => 0,
'used' => 0, 'used' => 0,
'stock' => 0, 'stock' => 0,
'status' => '', 'status' => '',
'cpuinfo_uid' => null,
'cpu_cnt' => 0, 'cpu_cnt' => 0,
'raminfo_uid' => null,
'ram_cnt' => 0, 'ram_cnt' => 0,
'diskinfo_uid' => null,
'disk_cnt' => 0, 'disk_cnt' => 0,
]; ];
public function __construct(array|null $data = null) public function __construct(array|null $data = null)

View File

@ -7,13 +7,17 @@ use App\Models\Equipment\LineModel;
class LineEntity extends EquipmentEntity class LineEntity extends EquipmentEntity
{ {
const PK = LineModel::PK; const PK = LineModel::PK;
protected array $nullableFields = [
'start_at',
'end_at',
];
protected $attributes = [ protected $attributes = [
'title' => '', 'title' => '',
'type' => '', 'type' => '',
'protocol' => '', 'protocol' => '',
'bandwith' => '', 'bandwith' => '',
'start_at' => 0, 'start_at' => null,
'end_at' => 0, 'end_at' => null,
'status' => '', 'status' => '',
'content' => '', 'content' => '',
]; ];
@ -34,13 +38,13 @@ class LineEntity extends EquipmentEntity
{ {
return $this->bandwith ?? ''; 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 public function getContent(): string
{ {

View File

@ -9,8 +9,18 @@ class ServerEntity extends EquipmentEntity
const PK = ServerModel::PK; const PK = ServerModel::PK;
const TITLE = ServerModel::TITLE; const TITLE = ServerModel::TITLE;
protected array $nullableFields = [
'clientinfo_uid',
'serviceinfo_uid',
'chassisinfo_uid',
'switchinfo_uid',
'ip',
'viewer',
'os',
'format_at',
];
protected $attributes = [ protected $attributes = [
'user_uid' => null,
'clientinfo_uid' => null, 'clientinfo_uid' => null,
'serviceinfo_uid' => null, 'serviceinfo_uid' => null,
'chassisinfo_uid' => null, 'chassisinfo_uid' => null,
@ -23,7 +33,7 @@ class ServerEntity extends EquipmentEntity
'os' => null, 'os' => null,
'price' => 0, 'price' => 0,
'manufactur_at' => '', 'manufactur_at' => '',
'format_at' => '', 'format_at' => null,
'status' => '', 'status' => '',
]; ];
public function __construct(array|null $data = null) public function __construct(array|null $data = null)
@ -65,21 +75,23 @@ class ServerEntity extends EquipmentEntity
{ {
return $this->code ?? null; return $this->code ?? null;
} }
public function getType(): string public function getType(): ?string
{ {
return $this->type ?? null; 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 public function getPrice(): int
{ {
@ -89,8 +101,8 @@ class ServerEntity extends EquipmentEntity
{ {
return $this->manufactur_at ?? ''; return $this->manufactur_at ?? '';
} }
public function getFormatAt(): string public function getFormatAt(): ?string
{ {
return $this->format_at ?? ''; return $this->format_at ?? null;
} }
} }

View File

@ -8,19 +8,24 @@ class ServerPartEntity extends EquipmentEntity
{ {
const PK = ServerPartModel::PK; const PK = ServerPartModel::PK;
const TITLE = ServerPartModel::TITLE; const TITLE = ServerPartModel::TITLE;
protected array $nullableFields = [
'clientinfo_uid',
'part_uid',
'serviceinfo_uid',
'billing_at',
'extra',
];
protected $attributes = [ protected $attributes = [
'clientinfo_uid' => null, 'clientinfo_uid' => null,
'part_uid' => null, 'part_uid' => null,
'serverinfo_uid' => null,
'serviceinfo_uid' => null, 'serviceinfo_uid' => null,
'title' => '', 'title' => '',
'type' => '', 'type' => '',
'billing' => '', 'billing' => '',
'billing_at' => '', 'billing_at' => null,
'cnt' => 0, 'cnt' => 0,
'amount' => 0, 'amount' => 0,
'extra' => '', 'extra' => null,
]; ];
public function __construct(array|null $data = null) public function __construct(array|null $data = null)
{ {
@ -79,9 +84,9 @@ class ServerPartEntity extends EquipmentEntity
{ {
return $this->billing ?? ""; 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 public function getCnt(): int
{ {
@ -91,8 +96,8 @@ class ServerPartEntity extends EquipmentEntity
{ {
return $this->amount ?? 0; return $this->amount ?? 0;
} }
public function getExtra(): string public function getExtra(): string|null
{ {
return $this->extra ?? ''; return $this->extra ?? null;
} }
} }

View File

@ -8,7 +8,11 @@ class MylogEntity extends CommonEntity
{ {
const PK = Model::PK; const PK = Model::PK;
const TITLE = Model::TITLE; const TITLE = Model::TITLE;
protected array $nullableFields = [
'user_uid',
];
protected $attributes = [ protected $attributes = [
'user_uid' => null,
'title' => '', 'title' => '',
'status' => '', 'status' => '',
'content' => '' 'content' => ''
@ -19,4 +23,8 @@ class MylogEntity extends CommonEntity
} }
//공통부분 //공통부분
//Common Function //Common Function
public function getUserUid(): int|null
{
return $this->user_uid ?? null;
}
} }

View File

@ -9,13 +9,20 @@ class PaymentEntity extends CommonEntity
{ {
const PK = PaymentModel::PK; const PK = PaymentModel::PK;
const TITLE = PaymentModel::TITLE; const TITLE = PaymentModel::TITLE;
protected array $nullableFields = [
'serviceinfo_uid',
'serverpartinfo_uid',
'pay',
];
protected $attributes = [ protected $attributes = [
'serviceinfo_uid' => null,
'serverpartinfo_uid' => null,
'title' => '', 'title' => '',
'amount' => 0, 'amount' => 0,
'billing' => "", 'billing' => "",
'billing_at' => "", 'billing_at' => "",
'billing_month' => 0, 'billing_month' => 0,
'pay' => "", 'pay' => null,
'status' => '', 'status' => '',
'content' => '' 'content' => ''
]; ];
@ -23,18 +30,22 @@ class PaymentEntity extends CommonEntity
{ {
parent::__construct($data); parent::__construct($data);
} }
final public function getUserUid(): int|null public function getUserUid(): int|null
{ {
return $this->user_uid ?? null; return $this->user_uid ?? null;
} }
final public function getClientInfoUid(): int|null public function getClientInfoUid(): int|null
{ {
return $this->clientinfo_uid ?? null; return $this->clientinfo_uid ?? null;
} }
final public function getServiceInfoUid(): int|null public function getServiceInfoUid(): int|null
{ {
return $this->serviceinfo_uid ?? null; return $this->serviceinfo_uid ?? null;
} }
public function getServerPartInfoUid(): int|null
{
return $this->serverpartinfo_uid ?? null;
}
//기본기능 //기본기능
public function getCustomTitle(): string public function getCustomTitle(): string
{ {
@ -56,9 +67,9 @@ class PaymentEntity extends CommonEntity
{ {
return $this->billing_month ?? 0; 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 public function getContent(): string
{ {

View File

@ -9,18 +9,15 @@ class UserEntity extends CommonEntity
{ {
const PK = Model::PK; const PK = Model::PK;
const TITLE = Model::TITLE; const TITLE = Model::TITLE;
/** protected array $nullableFields = [
* @var array DB 컬럼 타입이 VARCHAR(255)이고 CSV 형식으로 통일하기 위해 json-array 캐스팅을 제거합니다. 'mobile',
*/
protected $casts = [
// 'role' => 'json-array', // 🚫 CSV 형식 저장을 위해 제거
]; ];
protected $attributes = [ protected $attributes = [
'id' => '', 'id' => '',
'passwd' => '', 'passwd' => '',
'name' => "", 'name' => "",
'email' => "", 'email' => "",
'mobile' => '', 'mobile' => null,
'role' => "", 'role' => "",
'status' => '', 'status' => '',
]; ];

View File

@ -7,11 +7,15 @@ use App\Entities\BoardEntity;
class BoardModel extends CommonModel class BoardModel extends CommonModel
{ {
const TABLE = "boardinfo"; const TABLE = "boardinfo";
const PK = "uid"; const PK = "uid";
const TITLE = "title"; const TITLE = "title";
protected $table = self::TABLE; protected $table = self::TABLE;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = BoardEntity::class; protected $returnType = BoardEntity::class;
protected array $nullableFields = [
'user_uid',
'worker_uid',
];
protected $allowedFields = [ protected $allowedFields = [
"uid", "uid",
"user_uid", "user_uid",

View File

@ -43,14 +43,16 @@ abstract class CommonModel extends Model
// Callbacks // Callbacks
protected $allowCallbacks = true; protected $allowCallbacks = true;
protected $beforeInsert = []; //Field 값이 NULL일 경우 DB Default값 적용용 protected $beforeInsert = ['emptyStringToNull']; //Field 값이 NULL일 경우 DB Default값 적용용
protected $afterInsert = []; protected $afterInsert = [];
protected $beforeUpdate = []; //Field 값이 NULL일 경우 DB Default값 적용용 protected $beforeUpdate = ['emptyStringToNull']; //Field 값이 NULL일 경우 DB Default값 적용용
protected $afterUpdate = []; protected $afterUpdate = [];
protected $beforeFind = []; protected $beforeFind = [];
protected $afterFind = []; protected $afterFind = [];
protected $beforeDelete = []; protected $beforeDelete = [];
protected $afterDelete = []; protected $afterDelete = [];
protected array $nullableFields = []; // 모델별로 override
protected function __construct() protected function __construct()
{ {
parent::__construct(); parent::__construct();
@ -75,4 +77,35 @@ abstract class CommonModel extends Model
{ {
return $this->allowedFields; 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;
}
} }

View File

@ -9,10 +9,14 @@ class ClientModel extends CustomerModel
const TABLE = "clientinfo"; const TABLE = "clientinfo";
const PK = "uid"; const PK = "uid";
const TITLE = "name"; const TITLE = "name";
protected $table = self::TABLE; protected $table = self::TABLE;
// protected $useAutoIncrement = false; // protected $useAutoIncrement = false;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = ClientEntity::class; protected $returnType = ClientEntity::class;
protected array $nullableFields = [
'id',
'passwd',
];
protected $allowedFields = [ protected $allowedFields = [
"uid", "uid",
"user_uid", "user_uid",

View File

@ -10,10 +10,14 @@ class ServiceModel extends CustomerModel
const TABLE = "serviceinfo"; const TABLE = "serviceinfo";
const PK = "uid"; const PK = "uid";
const TITLE = "title"; const TITLE = "title";
protected $table = self::TABLE; protected $table = self::TABLE;
// protected $useAutoIncrement = false; // protected $useAutoIncrement = false;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = ServiceEntity::class; protected $returnType = ServiceEntity::class;
protected array $nullableFields = [
'serverinfo_uid',
'end_at'
];
protected $allowedFields = [ protected $allowedFields = [
"uid", "uid",
"user_uid", "user_uid",

View File

@ -7,11 +7,14 @@ use App\Entities\Customer\Wallet\AccountEntity;
class AccountModel extends WalletModel class AccountModel extends WalletModel
{ {
const TABLE = "accountinfo"; const TABLE = "accountinfo";
const PK = "uid"; const PK = "uid";
const TITLE = "title"; const TITLE = "title";
protected $table = self::TABLE; protected $table = self::TABLE;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = AccountEntity::class; protected $returnType = AccountEntity::class;
protected array $nullableFields = [
'alias'
];
protected $allowedFields = [ protected $allowedFields = [
"uid", "uid",
"user_uid", "user_uid",

View File

@ -9,10 +9,15 @@ class CHASSISModel extends EquipmentModel
const TABLE = "chassisinfo"; const TABLE = "chassisinfo";
const PK = "uid"; const PK = "uid";
const TITLE = "title"; const TITLE = "title";
protected $table = self::TABLE; protected $table = self::TABLE;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
// protected $useAutoIncrement = false; // protected $useAutoIncrement = false;
protected $returnType = CHASSISEntity::class; protected $returnType = CHASSISEntity::class;
protected array $nullableFields = [
'cpuinfo_uid',
'raminfo_uid',
'diskinfo_uid',
];
protected $allowedFields = [ protected $allowedFields = [
"uid", "uid",
"title", "title",

View File

@ -9,9 +9,13 @@ class LineModel extends EquipmentModel
const TABLE = "lineinfo"; const TABLE = "lineinfo";
const PK = "uid"; const PK = "uid";
const TITLE = "title"; const TITLE = "title";
protected $table = self::TABLE; protected $table = self::TABLE;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = LineEntity::class; protected $returnType = LineEntity::class;
protected array $nullableFields = [
'start_at',
'end_at',
];
protected $allowedFields = [ protected $allowedFields = [
"uid", "uid",
"type", "type",

View File

@ -13,6 +13,16 @@ class ServerModel extends EquipmentModel
// protected $useAutoIncrement = false; // protected $useAutoIncrement = false;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = ServerEntity::class; protected $returnType = ServerEntity::class;
protected array $nullableFields = [
'clientinfo_uid',
'serviceinfo_uid',
'chassisinfo_uid',
'switchinfo_uid',
'ip',
'viewer',
'os',
'format_at',
];
protected $allowedFields = [ protected $allowedFields = [
"uid", "uid",
"user_uid", "user_uid",

View File

@ -9,9 +9,16 @@ class ServerPartModel extends EquipmentModel
const TABLE = "serverpartinfo"; const TABLE = "serverpartinfo";
const PK = "uid"; const PK = "uid";
const TITLE = "title"; const TITLE = "title";
protected $table = self::TABLE; protected $table = self::TABLE;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = ServerPartEntity::class; protected $returnType = ServerPartEntity::class;
protected array $nullableFields = [
'clientinfo_uid',
'part_uid',
'serviceinfo_uid',
'billing_at',
'extra',
];
protected $allowedFields = [ protected $allowedFields = [
"uid", "uid",
"part_uid", "part_uid",

View File

@ -9,9 +9,12 @@ class MylogModel extends CommonModel
const TABLE = "mylog"; const TABLE = "mylog";
const PK = "uid"; const PK = "uid";
const TITLE = "title"; const TITLE = "title";
protected $table = self::TABLE; protected $table = self::TABLE;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = MylogEntity::class; protected $returnType = MylogEntity::class;
protected array $nullableFields = [
'user_uid',
];
protected $allowedFields = [ protected $allowedFields = [
"uid", "uid",
"user_uid", "user_uid",

View File

@ -9,9 +9,14 @@ class PaymentModel extends CommonModel
const TABLE = "payment"; const TABLE = "payment";
const PK = "uid"; const PK = "uid";
const TITLE = "title"; const TITLE = "title";
protected $table = self::TABLE; protected $table = self::TABLE;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = PaymentEntity::class; protected $returnType = PaymentEntity::class;
protected array $nullableFields = [
'serviceinfo_uid',
'serverpartinfo_uid',
'pay',
];
protected $allowedFields = [ protected $allowedFields = [
"uid", "uid",
"user_uid", "user_uid",

View File

@ -9,9 +9,12 @@ class UserModel extends CommonModel
const TABLE = "user"; const TABLE = "user";
const PK = "uid"; const PK = "uid";
const TITLE = "name"; const TITLE = "name";
protected $table = self::TABLE; protected $table = self::TABLE;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = UserEntity::class; protected $returnType = UserEntity::class;
protected array $nullableFields = [
'mobile',
];
protected $allowedFields = [ protected $allowedFields = [
"uid", "uid",
"id", "id",

View File

@ -238,6 +238,7 @@ abstract class CommonService
try { try {
// INSERT 시 Entity의 PK는 0 또는 NULL이어야 함 (DB가 ID를 생성하도록) // INSERT 시 Entity의 PK는 0 또는 NULL이어야 함 (DB가 ID를 생성하도록)
$initialPK = $entity->getPK(); $initialPK = $entity->getPK();
// dd($entity);
$result = $this->model->save($entity); $result = $this->model->save($entity);
// 최종적으로 DB에 반영된 PK를 반환받습니다. (UPDATE이면 기존 PK, INSERT이면 새 PK) // 최종적으로 DB에 반영된 PK를 반환받습니다. (UPDATE이면 기존 PK, INSERT이면 새 PK)
$entity->{$this->getPKField()} = $this->handle_save_result($result, $initialPK); $entity->{$this->getPKField()} = $this->handle_save_result($result, $initialPK);

View File

@ -62,9 +62,6 @@ class ClientService extends CustomerService
))); )));
$formDatas[$field] = $value; $formDatas[$field] = $value;
break; break;
case "format_at":
$formDatas[$field] = $value === '' ? null : $value;
break;
default: default:
$formDatas = parent::action_process_fieldhook($field, $value, $formDatas); $formDatas = parent::action_process_fieldhook($field, $value, $formDatas);
break; break;

View File

@ -120,21 +120,33 @@ class ServerService extends EquipmentService
{ {
return $entity; 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 protected function create_process(array $formDatas): ServerEntity
{ {
$entity = parent::create_process($formDatas); $entity = parent::create_process($formDatas);
if (!$entity instanceof ServerEntity) { if (!$entity instanceof ServerEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServerEntity만 가능"); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServerEntity만 가능");
} }
//서버추가시 서버파트 자동추가용 //새로운 IP 추가 (IP가 정의 되어 있으면)
// dd($entity);
if ($entity->getIP()) { if ($entity->getIP()) {
service('part_ipservice')->attachToServer($entity); service('part_ipservice')->attachToServer($entity);
} }
//새로운 Switch 추가 (Switch가 정의 되어 있으면)
if ($entity->getSwitchInfoUid()) { if ($entity->getSwitchInfoUid()) {
service('part_switchservice')->attachToServer($entity); service('part_switchservice')->attachToServer($entity);
} }
//새로운 Chassis 추가 (Chassis가 정의 되어 있으면)
service('equipment_chassisservice')->attachToServer($entity); service('equipment_chassisservice')->attachToServer($entity);
//새로운 ServerPart 추가 (ServerPart가 정의 되어 있으면)
service('equipment_serverpartservice')->attachToServer($entity); service('equipment_serverpartservice')->attachToServer($entity);
return $entity; return $entity;
} }
@ -150,22 +162,32 @@ class ServerService extends EquipmentService
if (!$entity instanceof ServerEntity) { if (!$entity instanceof ServerEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServerEntity만 가능"); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServerEntity만 가능");
} }
//서버정보변경시 서버파트 정보변경용
//IP변경 //IP변경
if ($oldEntity->getIP() !== $entity->getIP()) { if ($oldEntity->getIP() !== $entity->getIP()) {
//기존 IP 제거
service('part_ipservice')->detachFromServer($oldEntity); service('part_ipservice')->detachFromServer($oldEntity);
service('part_ipservice')->attachToServer($entity); //새로운 IP 추가 (IP가 정의 되어 있으면)
if ($entity->getIP()) {
service('part_ipservice')->attachToServer($entity);
}
} }
//SWITCH변경 //SWITCH변경
if ($oldEntity->getSwitchInfoUid() !== $entity->getSwitchInfoUid()) { if ($oldEntity->getSwitchInfoUid() !== $entity->getSwitchInfoUid()) {
service('part_switchservice')->detachFromServer($oldEntity); 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')->detachFromServer($oldEntity);
service('equipment_chassisservice')->attachToServer($entity); //새로운 Chassis 추가 (Chassis가 정의 되어 있으면)
if ($entity->getChassisInfoUid()) {
service('equipment_chassisservice')->attachToServer($entity);
}
} }
//서비스변경
if ($entity->getServiceInfoUid() !== null) { //서비스가 정의 되어 있으면 if ($entity->getServiceInfoUid() !== null) { //서비스가 정의 되어 있으면
$serviceEntity = service('customer_serviceservice')->getEntity($entity->getServiceInfoUid()); $serviceEntity = service('customer_serviceservice')->getEntity($entity->getServiceInfoUid());
if (!$serviceEntity instanceof ServiceEntity) { if (!$serviceEntity instanceof ServiceEntity) {