dbmsv2 init...1

This commit is contained in:
choi.jh 2025-09-08 14:21:14 +09:00
parent 37a859fb57
commit 9aaae852cd
22 changed files with 152 additions and 123 deletions

View File

@ -365,7 +365,7 @@ define('DEFAULT_LIST_PERPAGE', $_ENV['LIST_PERPAGE'] ?? $_SERVER['LIST_PERPAGE']
//STATUS
define("STATUS", [
'AVAIABLE' => "available",
'AVAILABLE' => "available",
'FORBIDDEN' => "forbidden",
'OCCUPIED' => "occupied",
'SUCCESS' => "success",
@ -387,8 +387,8 @@ define("SERVICE", [
//서버파트 관련
define("SERVERPART", [
"CNT_RANGE" => array_combine(range(1, 10), range(1, 10)),
"SERVER_PARTTTYPES" => ['CPU', 'RAM', 'DISK'],
"SERVICE_PARTTTYPES" => ['SWITCH', 'IP', 'OS', 'SOFTWARE'],
"SERVER_PARTTYPES" => ['CPU', 'RAM', 'DISK'],
"SERVICE_PARTTYPES" => ['SWITCH', 'IP', 'OS', 'SOFTWARE', 'CS'],
"PARTTYPES" => ['CPU', 'RAM', 'DISK', 'OS', 'DB', 'SOFTWARE', 'SWITCH', 'IP', 'CS'],
]);
//결제 관련

View File

@ -3,7 +3,6 @@
namespace App\Entities\Customer;
use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\SwitchEntity;
use App\Models\Customer\ServiceModel;
class ServiceEntity extends CustomerEntity
@ -11,9 +10,10 @@ class ServiceEntity extends CustomerEntity
const PK = ServiceModel::PK;
const TITLE = ServiceModel::TITLE;
const DEFAULT_STATUS = STATUS['NORMAL'];
public function setServerEntity(ServerEntity $entity): void
public function setServerEntity(ServerEntity $entity): ServiceEntity
{
$this->attributes['serverEntity'] = $entity;
return $this;
}
public function getServerEntity(): ServerEntity
{

View File

@ -8,5 +8,5 @@ class CSEntity extends EquipmentEntity
{
const PK = CSModel::PK;
const TITLE = CSModel::TITLE;
const DEFAULT_STATUS = STATUS['AVAIABLE'];
const DEFAULT_STATUS = STATUS['AVAILABLE'];
}

View File

@ -8,7 +8,7 @@ class IPEntity extends EquipmentEntity
{
const PK = IPModel::PK;
const TITLE = IPModel::TITLE;
const DEFAULT_STATUS = STATUS['AVAIABLE'];
const DEFAULT_STATUS = STATUS['AVAILABLE'];
public function getIP(): string
{
return $this->attributes['ip'];

View File

@ -8,7 +8,7 @@ class LineEntity extends EquipmentEntity
{
const PK = LineModel::PK;
const TITLE = LineModel::TITLE;
const DEFAULT_STATUS = STATUS['AVAIABLE'];
const DEFAULT_STATUS = STATUS['AVAILABLE'];
public function getBandwith(): string
{
return $this->attributes['bandwith'];

View File

@ -8,7 +8,7 @@ class PartEntity extends EquipmentEntity
{
const PK = PartModel::PK;
const TITLE = PartModel::TITLE;
const DEFAULT_STATUS = STATUS['AVAIABLE'];
const DEFAULT_STATUS = STATUS['AVAILABLE'];
public function getType(): string
{

View File

@ -9,8 +9,8 @@ class ServerEntity extends EquipmentEntity
{
const PK = ServerModel::PK;
const TITLE = ServerModel::TITLE;
const DEFAULT_STATUS = STATUS['AVAIABLE'];
public function addServerPartEntity(string $partType, ServerPartEntity $entity): void
const DEFAULT_STATUS = STATUS['AVAILABLE'];
public function addServerPartEntity(string $partType, ServerPartEntity $entity): ServerEntity
{
if (!array_key_exists('serverPartEntities', $this->attributes)) {
$this->attributes['serverPartEntities'] = [];
@ -19,13 +19,15 @@ class ServerEntity extends EquipmentEntity
$this->attributes['serverPartEntities'][$partType] = [];
}
$this->attributes['serverPartEntities'][$partType][] = $entity;
return $this;
}
public function setServerPartEntities(string $partType, array $serverPartEntities): void
public function setServerPartEntities(string $partType, array $serverPartEntities): ServerEntity
{
if (!array_key_exists('serverPartEntities', $this->attributes)) {
$this->attributes['serverPartEntities'] = [];
}
$this->attributes['serverPartEntities'][$partType] = $serverPartEntities;
return $this;
}
public function getServerPartEntities(string $partType): array
{

View File

@ -10,9 +10,10 @@ class ServerPartEntity extends EquipmentEntity
const TITLE = ServerPartModel::TITLE;
const DEFAULT_STATUS = null;
public function setPartEntity(mixed $entity): void
public function setPartEntity(mixed $entity): ServerPartEntity
{
$this->attributes['partEntity'] = $entity;
return $this;
}
public function getPartEntity(): mixed
{

View File

@ -8,7 +8,7 @@ class SwitchEntity extends EquipmentEntity
{
const PK = SwitchModel::PK;
const TITLE = SwitchModel::TITLE;
const DEFAULT_STATUS = STATUS['AVAIABLE'];
const DEFAULT_STATUS = STATUS['AVAILABLE'];
public function getCode(): string
{

View File

@ -22,7 +22,7 @@ return [
"KT-CS" => "KT-CS",
],
"STATUS" => [
STATUS['AVAIABLE'] => "사용가능",
STATUS['AVAILABLE'] => "사용가능",
STATUS['OCCUPIED'] => "서비스중",
STATUS['FORBIDDEN'] => "사용불가",
],

View File

@ -16,7 +16,7 @@ return [
'deleted_at' => "삭제일",
],
"STATUS" => [
STATUS['AVAIABLE'] => "사용가능",
STATUS['AVAILABLE'] => "사용가능",
STATUS['OCCUPIED'] => "서비스중",
STATUS['FORBIDDEN'] => "사용불가",
],

View File

@ -18,7 +18,7 @@ return [
"dedicated" => "전용",
],
"STATUS" => [
STATUS['AVAIABLE'] => "사용가능",
STATUS['AVAILABLE'] => "사용가능",
STATUS['OCCUPIED'] => "서비스중",
STATUS['FORBIDDEN'] => "사용불가",
],

View File

@ -20,7 +20,7 @@ return [
"SOFTWARE" => "소프트웨어",
],
"STATUS" => [
STATUS['AVAIABLE'] => "사용가능",
STATUS['AVAILABLE'] => "사용가능",
STATUS['FORBIDDEN'] => "사용불가",
],
];

View File

@ -42,7 +42,7 @@ return [
"etc" => "조립",
],
"STATUS" => [
STATUS['AVAIABLE'] => "사용가능",
STATUS['AVAILABLE'] => "사용가능",
STATUS['OCCUPIED'] => "서비스중",
STATUS['FORBIDDEN'] => "사용불가",
],

View File

@ -12,7 +12,7 @@ return [
'deleted_at' => "삭제일",
],
"STATUS" => [
STATUS['AVAIABLE'] => "사용가능",
STATUS['AVAILABLE'] => "사용가능",
STATUS['OCCUPIED'] => "서비스중",
STATUS['FORBIDDEN'] => "사용불가",
],

View File

@ -3,6 +3,7 @@
namespace App\Services\Customer;
use App\Entities\Customer\ServiceEntity;
use App\Entities\Equipment\ServerEntity;
use App\Models\Customer\ServiceModel;
use App\Services\Equipment\ServerService;
use App\Traits\IPTrait;
@ -92,11 +93,11 @@ class ServiceService extends CustomerService
protected function getEntity_process(mixed $entity): ServiceEntity
{
//서버정보 정의
$serverEntityy = $this->getServerService()->getEntity(['serviceinfo_uid' => $entity->getPK()]);
if ($serverEntityy !== null) {
$entity->setServerEntity($serverEntityy);
$serverEntity = $this->getServerService()->getEntity(['serviceinfo_uid' => $entity->getPK()]);
if (!($serverEntity instanceof ServerEntity)) {
throw new \Exception("{$entity->getPK()}에 해당하는 서버정보를 찾을수없습니다.");
}
return $entity;
return $entity->setServerEntity($serverEntity);
}
//기본 기능부분
public function getFormOption(string $field, array $options = []): array
@ -166,63 +167,50 @@ class ServiceService extends CustomerService
return $this->getModel()->query($sql, [$billing_at, $status]);
}
//서버설정용
private function setServerEntity(ServiceEntity $entity, array $formDatas): ServiceEntity
//서버정보 상태설정용
private function setServer_process(ServiceEntity $entity, string $status): ServerEntity
{
//서버경우 서비스중으로 설정
$serverEntity = $this->getServerService()->getEntity($formDatas['serverinfo_uid']);
if (!$serverEntity) {
throw new \Exception("{$formDatas['serverinfo_uid']}에 대한 서버정보를 찾을수 없습니다.");
$serverEntity = $this->getServerService()->getEntity(['serviceinfo_uid' => $entity->getPK()]);
if (!($serverEntity instanceof ServerEntity)) {
throw new \Exception("{$entity->getPK()}에 해당하는 서버정보를 찾을수없습니다.");
}
$serverFormDatas = [];
$serverFormDatas["clientinfo_uid"] = $entity->getClientInfoUID();
$serverFormDatas["serviceinfo_uid"] = $entity->getPK();
$serverFormDatas["status"] = STATUS['OCCUPIED'];
$serverEntity = $this->getServerService()->modify($serverEntity, $serverFormDatas);
$entity->setServerEntity($serverEntity);
return $entity;
}
private function unsetServerEntity(ServiceEntity $entity): ServiceEntity
{
//기존 Server정보와 다른경우 사용가능상태로 변경
$serverEntity = $entity->getServerEntity();
if ($serverEntity !== null) {
$serverFormDatas = [];
$serverFormDatas["clientinfo_uid"] = null;
$serverFormDatas["serviceinfo_uid"] = null;
$serverFormDatas["status"] = STATUS['AVAIABLE'];
$serverEntity = $this->getServerService()->modify($serverEntity, $serverFormDatas);
$entity->setServerEntity($serverEntity);
}
return $entity;
//서버정보 상태수정
$serverEntity = $this->getServerService()->modify(
$serverEntity,
['serviceEntity' => $entity, 'status' => $status],
);
return $serverEntity;
}
//생성
public function create(array $formDatas): ServiceEntity
{
$entity = parent::create($formDatas);
if (!array_key_exists('serverinfo_uid', $formDatas)) {
throw new \Exception("서버가 지정되지 않았습니다.");
}
//신규정보 Enable
return $this->setServerEntity($entity, $formDatas);
$entity = parent::create($formDatas);
$serverEntity = $this->setServer_process($entity, STATUS['OCCUPIED']);
return $entity->setServerEntity($serverEntity);
}
//수정
public function modify(mixed $entity, array $formDatas): ServiceEntity
{
if (!array_key_exists('serverinfo_uid', $formDatas)) {
throw new \Exception("서버가 지정되지 않았습니다.");
throw new \Exception("신규 서버가 지정되지 않았습니다.");
}
//기존정보 Disable
$entity = $this->unsetServerEntity($entity);
//신규정보 Enable
$this->setServerEntity($entity, $formDatas);
return parent::modify($entity, $formDatas);
//기존서버정보 사용가능으로 설정
$this->setServer_process($entity, STATUS['AVAILABLE']);
//서비스 정보수정
$entity = parent::modify($entity, $formDatas);
//신규서버정보 사용중으로 설정
$serverEntity = $this->setServer_process($entity, STATUS['OCCUPIED']);
return $entity->setServerEntity($serverEntity);
}
//삭제
public function delete(mixed $entity): ServiceEntity
{
//기존정보 Disable
$entity = $this->unsetServerEntity($entity);
//기존서버정보 사용가능으로 설정
$this->setServer_process($entity, STATUS['AVAILABLE']);
return parent::delete($entity);
}
}

View File

@ -140,7 +140,7 @@ class ServerPartService extends EquipmentService
}
return $options;
}
private function action_process(ServerPartEntity $entity, mixed $part_uid, string $status): mixed
private function setPart_process(ServerPartEntity $entity, mixed $part_uid, string $status): mixed
{
//Type에 따른 부품서비스 정의
switch ($entity->getType()) {
@ -170,14 +170,15 @@ class ServerPartService extends EquipmentService
case 'SWITCH':
case 'CS':
//부품정보에 서버정보 설정 및 서비스,고객정보 정의
if ($status === STATUS['OCCUPIED']) {
$formDatas['clientinfo_uid'] = $entity->getClientInfoUID();
$formDatas['serviceinfo_uid'] = $entity->getServiceInfoUID();
$formDatas['serverinfo_uid'] = $entity->getServerInfoUID();
} else {
if ($formDatas['status'] === STATUS['AVAILABLE']) {
//사용가능
$formDatas['clientinfo_uid'] = null;
$formDatas['serviceinfo_uid'] = null;
$formDatas['serverinfo_uid'] = null;
} else {
$formDatas['clientinfo_uid'] = $entity->getClientInfoUID();
$formDatas['serviceinfo_uid'] = $entity->getServiceInfoUID();
$formDatas['serverinfo_uid'] = $entity->getServerInfoUID();
}
$formDatas['part_uid'] = $part_uid;
$formDatas['status'] = $status;
@ -189,28 +190,72 @@ class ServerPartService extends EquipmentService
//부품연결정보생성
public function create(array $formDatas): ServerPartEntity
{
//서버정보가져오기
$serverEntity = null;
if (array_key_exists('serverEntity', $formDatas)) {
$serverEntity = $formDatas['serverEntity'];
} else {
if (!array_key_exists('serverinfo_uid', $formDatas)) {
throw new \Exception("서버 정보가 지정되지 않았습니다.");
}
$serverEntity = $this->getServiceService()->getEntity($formDatas['serviceinfo_uid']);
}
if (!($serverEntity instanceof ServerEntity)) {
throw new \Exception("서버 정보가 지정되지 않았습니다.");
}
$formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
$formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
$formDatas["serverinfo_uid"] = $serverEntity->getPK();
$entity = parent::create($formDatas);
//부품연결정보에 부품정보 정의
$entity->setPartEntity($this->action_process($entity, $entity->getPartUID(), STATUS['OCCUPIED']));
return $entity;
return $entity->setPartEntity($this->setPart_process(
$entity,
$formDatas['part_uid'],
STATUS['OCCUPIED']
));
}
//수정
public function modify(mixed $entity, array $formDatas): ServerPartEntity
{
//기존과 신규의 Type이 같고, 기존 Part_UID와 신규 Part_UID가 다르면 부품정보에 서버정보 설정 및 서비스,고객정보 정의 기존 Part정보 사용가능으로 변경
if ($entity->getType() == $formDatas['type'] && $entity->getPartUID() != $formDatas['part_uid']) {
$entity->setPartEntity($this->action_process($entity, $entity->getPartUID(), STATUS['AVAIABLE']));
//서버정보가져오기
$serverEntity = null;
if (array_key_exists('serverEntity', $formDatas)) {
$serverEntity = $formDatas['serverEntity'];
} else {
if (!array_key_exists('serverinfo_uid', $formDatas)) {
throw new \Exception("서버 정보가 지정되지 않았습니다.");
}
$serverEntity = $this->getServiceService()->getEntity($formDatas['serviceinfo_uid']);
}
if (!($serverEntity instanceof ServerEntity)) {
throw new \Exception("서버 정보가 지정되지 않았습니다.");
}
if ($formDatas['status'] === STATUS['OCCUPIED']) {
$formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
$formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
$formDatas["serverinfo_uid"] = $serverEntity->getPK();
} else {
$formDatas["clientinfo_uid"] = null;
$formDatas["serviceinfo_uid"] = null;
$formDatas["serverinfo_uid"] = null;
}
//기존 Part_UID와 신규 Part_UID가 다르면 기존 Part정보 사용가능으로 변경
if ($entity->getPartUID() != $formDatas['part_uid']) {
$this->setPart_process($entity, $entity->getPartUID(), STATUS['AVAILABLE']);
}
//기존 정보변경
$entity = parent::modify($entity, $formDatas);
//기존과 신규의 Type이 같고, 기존 Part_UID와 신규 Part_UID가 다르면 부품정보에 서버정보 설정 및 서비스,고객정보 정의 Part정보 사용중으로 변경
$entity->setPartEntity($this->action_process($entity, $formDatas['part_uid'], STATUS['OCCUPIED']));
return $entity;
//부품연결정보에 부품정보 정의
return $entity->setPartEntity($this->setPart_process(
$entity,
$formDatas['part_uid'],
STATUS['OCCUPIED']
));
}
//삭제
public function delete(mixed $entity): ServerPartEntity
{
$this->action_process($entity, $entity->getPartUID(), STATUS['AVAIABLE']);
$this->setPart_process($entity, $entity->getPartUID(), STATUS['AVAILABLE']);
return parent::delete($entity);
}
}

View File

@ -2,6 +2,7 @@
namespace App\Services\Equipment;
use App\Entities\Customer\ServiceEntity;
use App\Entities\Equipment\ServerEntity;
use App\Models\Equipment\ServerModel;
use App\Services\Equipment\EquipmentService;
@ -83,7 +84,7 @@ class ServerService extends EquipmentService
//부품연결정보 정의
foreach (SERVERPART['PARTTYPES'] as $partType) {
foreach ($this->getServerPartService()->getEntities(['serverinfo_uid' => $entity->getPK(), 'type' => $partType]) as $serverPartEntity) {
$entity->addServerPartEntity($partType, $serverPartEntity);
$entity = $entity->addServerPartEntity($partType, $serverPartEntity);
}
}
return $entity;
@ -137,55 +138,47 @@ class ServerService extends EquipmentService
{
$entity = parent::create($formDatas);
//신규 ServerPart정보 생성
foreach (SERVERPART['PARTTYPES'] as $partType) {
if (array_key_exists($partType, $formDatas)) {
foreach (SERVERPART['SERVER_PARTTYPES'] as $partType) {
$serverPartFormDatas = [];
$serverPartFormDatas["part_uid"] = $formDatas[$partType];
$serverPartFormDatas["clientinfo_uid"] = $entity->getClientInfoUID();
$serverPartFormDatas["serviceinfo_uid"] = $entity->getServiceInfoUID();
$serverPartFormDatas["serverinfo_uid"] = $entity->getPK();
$serverPartFormDatas["type"] = $partType;
$serverPartFormDatas["billing"] = null;
$serverPartFormDatas["amount"] = 0;
$serverPartFormDatas['serverEntity'] = $entity;
$serverPartFormDatas['type'] = $partType;
$serverPartFormDatas['part_uid'] = $partType . "_uid";
$serverPartFormDatas["billing"] = array_key_exists("{$partType}_billing", $formDatas) ? $formDatas["{$partType}_billing"] : null;
$serverPartFormDatas["amount"] = array_key_exists("{$partType}_amount", $formDatas) ? $formDatas["{$partType}_amount"] : 0;
$serverPartFormDatas["cnt"] = array_key_exists("{$partType}_cnt", $formDatas) ? $formDatas["{$partType}_cnt"] : 1;
$serverPartFormDatas["extra"] = array_key_exists("{$partType}_extra", $formDatas) ? $formDatas["{$partType}_extra"] : null;
$serverPartEntity = $this->getServerPartService()->create($serverPartFormDatas);
$entity->addServerPartEntity($serverPartEntity->getType(), $serverPartEntity);
$this->getServerPartService()->create($serverPartFormDatas);
}
}
return $entity;
return $entity->getEntity_process($entity);
}
//Service별 수정
public function modify(mixed $entity, array $formDatas): ServerEntity
{
$entity = parent::modify($entity, $formDatas);
if (!array_key_exists('status', $formDatas)) {
throw new \Exception(__METHOD__ . "에서 상태정보가 정의되지 않았습니다.");
}
//부품연결정보에 서버정보 설정 및 서비스,고객정보 정의
$partFormDatas = [
'serverinfo_uid' => $entity->getPK(),
'status' => $formDatas['status'],
];
if ($partFormDatas['status'] === STATUS['OCCUPIED']) {
$partFormDatas['clientinfo_uid'] = $entity->getClientInfoUID();
$partFormDatas['serviceinfo_uid'] = $entity->getServiceInfoUID();
foreach ($this->getServerPartService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $serverPartEntity) {
$entity->addServerPartEntity(
$serverPartEntity->getType(),
$this->getServerPartService()->modify($serverPartEntity, $partFormDatas)
);
}
//서비스정보가져오기
$serviceEntity = null;
if (array_key_exists('serviceEntity', $formDatas)) {
$serviceEntity = $formDatas['serviceEntity'];
} else {
$partFormDatas['clientinfo_uid'] = null;
$partFormDatas['serviceinfo_uid'] = null;
$entities = [];
foreach ($this->getServerPartService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $serverPartEntity) {
$entities[] = $this->getServerPartService()->modify($serverPartEntity, $partFormDatas);
if (!array_key_exists('serviceinfo_uid', $formDatas)) {
throw new \Exception("서비스 정보가 지정되지 않았습니다.");
}
$entity->setServerPartEntities($entities);
$serviceEntity = $this->getServiceService()->getEntity($formDatas['serviceinfo_uid']);
}
return $entity;
if (!($serviceEntity instanceof ServiceEntity)) {
throw new \Exception("서비스 정보가 지정되지 않았습니다.");
}
//서비스상태에 따라
if ($formDatas['status'] === STATUS['AVAILABLE']) {
//사용가능
$formDatas["clientinfo_uid"] = null;
$formDatas["serviceinfo_uid"] = null;
} else {
//사용중 , 일시정지
$formDatas["clientinfo_uid"] = $serviceEntity->getClientInfoUID();
$formDatas["serviceinfo_uid"] = $serviceEntity->getPK();
}
//서버정보수정
return $this->getEntity_process(parent::modify($entity, $formDatas));
}
//삭제
public function delete(mixed $entity): ServerEntity

View File

@ -48,10 +48,10 @@ class UserService extends CommonService
}
//기본 기능부분
public function create(array $formDatas): UserEntity
public function create(array $formDatas, mixed $parentEntity = null): UserEntity
{
$formDatas['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $formDatas['role']);
return parent::create($formDatas);
return parent::create($formDatas, $parentEntity);
}
public function modify(mixed $entity, array $formDatas): UserEntity
{

View File

@ -26,7 +26,7 @@
</td>
<td>
<table class="table table-bordered">
<?php foreach (SERVERPART['SERVER_PARTTTYPES'] as $field): ?>
<?php foreach (SERVERPART['SERVER_PARTTYPES'] as $field): ?>
<tr>
<th nowrap class="text-end"><?= $viewDatas['helper']->getFieldLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?></th>
<td nowrap class="text-start">

View File

@ -81,7 +81,7 @@
<td><?= $viewDatas['helper']->getFieldView('status', $entity->status, $viewDatas) ?></td>
<td nowrap>
<table class="table table-bordered table-striped m-0 p-0">
<?php foreach (SERVERPART['SERVER_PARTTTYPES'] as $partType): ?>
<?php foreach (SERVERPART['SERVER_PARTTYPES'] as $partType): ?>
<tr class="m-0 p-0">
<th class="text-end m-0 p-0"><?= $viewDatas['helper']->getListButton($partType, $partType, $viewDatas) ?></th>
<td class="text-start m-0 p-0"><?= $viewDatas['helper']->getFieldView($partType, "", $viewDatas) ?></td>

View File

@ -86,7 +86,7 @@
</td>
<td nowrap>
<table class="table table-bordered table-striped m-0 p-0">
<?php foreach (SERVERPART['SERVICE_PARTTTYPES'] as $partType): ?>
<?php foreach (SERVERPART['SERVICE_PARTTYPES'] as $partType): ?>
<tr class="m-0 p-0">
<th class="m-0 p-0"><?= $viewDatas['helper']->getListButton($partType, $partType, $viewDatas) ?></th>
<td class="m-0 p-0"><?= $viewDatas['helper']->getFieldView($partType, "", $viewDatas) ?></td>