dbmsv2 init...1

This commit is contained in:
choi.jh 2025-08-27 11:14:41 +09:00
parent 9c5371bcaa
commit eb36d74033
15 changed files with 269 additions and 142 deletions

View File

@ -368,13 +368,13 @@ define('SERVICE_NEW_INTERVAL', $_ENV['SERVICE_NEW_INTERVAL'] ?? $_SERVER['SERVIC
//결제관련 //결제관련
define("PAYMENT", [ define("PAYMENT", [
'BILLING' => [ 'BILLING' => [
'METHOD_MONTH' => 'month', 'MONTH' => 'month',
'METHOD_ONETIME' => 'onetime' 'ONETIME' => 'onetime'
], ],
'PAY' => [ 'PAY' => [
'METHOD_ACCOUNT' => 'account', 'ACCOUNT' => 'account',
'METHOD_COUPON' => 'coupon', 'COUPON' => 'coupon',
'METHOD_POINT' => 'point' 'POINT' => 'point'
] ]
]); ]);

View File

@ -3,9 +3,11 @@
namespace App\Controllers\Admin\Equipment; namespace App\Controllers\Admin\Equipment;
use App\Entities\Equipment\ServerEntity; use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Helpers\Equipment\ServerHelper; use App\Helpers\Equipment\ServerHelper;
use App\Services\Equipment\ServerService;
use App\Services\Equipment\ServerPartService;
use App\Services\Equipment\ServerService;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
@ -13,6 +15,7 @@ use Psr\Log\LoggerInterface;
class ServerController extends EquipmentController class ServerController extends EquipmentController
{ {
private ?ServerPartService $_serverPartService = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
@ -21,8 +24,8 @@ class ServerController extends EquipmentController
$this->uri_path .= strtolower($this->getService()->getClassName('/')) . '/'; $this->uri_path .= strtolower($this->getService()->getClassName('/')) . '/';
// $this->view_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR; // $this->view_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR;
$this->partinfo_cnt_range = array_combine(range(0, 10), range(0, 10)); $this->serverpartinfo_cnt_range = array_combine(range(0, 10), range(0, 10));
$this->partinfo_extra_options = array_merge(["" => "RAID 선택"], lang("{$this->getService()->getClassName()}.EXTRAS")); $this->serverpartinfo_extra_options = array_merge(["" => "RAID 선택"], lang("{$this->getService()->getClassName()}.EXTRAS"));
} }
public function getService(): ServerService public function getService(): ServerService
{ {
@ -38,7 +41,13 @@ class ServerController extends EquipmentController
} }
return $this->_helper; return $this->_helper;
} }
final public function getServerPartService(): ServerPartService
{
if (!$this->_serverPartService) {
$this->_serverPartService = new ServerPartService();
}
return $this->_serverPartService;
}
//Index,FieldForm관련 //Index,FieldForm관련
//생성 //생성
protected function create_form_process(): void protected function create_form_process(): void
@ -50,6 +59,24 @@ class ServerController extends EquipmentController
$this->setFieldDefaultValue('code', $this->getService()->getLastestCode($format, (int)env("Server.Default.code", 0))); $this->setFieldDefaultValue('code', $this->getService()->getLastestCode($format, (int)env("Server.Default.code", 0)));
parent::create_form_process(); parent::create_form_process();
} }
//추가 파트정보 생성
private function createServerParts(ServerEntity $entity): array
{
$serverPartEntities = [];
foreach (ServerPartService::BaseParts as $basePart) {
$formDatas = [
"partinfo_uid" => $this->request->getPost(["serverpartinfo_{$basePart}_uid"]),
"serverinfo_uid" => $entity->getPK(),
"serviceinfo_uid" => $entity->getServiceInfoUID(),
"billing" => ServerPartENtity::DEFAULT_BILLING,
"amount" => $this->request->getPost("amount") ?? 0,
"cnt" => $this->request->getPost("serverpartinfo_{$basePart}_uid_cnt") ?? 1,
"extra" => $this->request->getPost("serverpartinfo_{$basePart}_uid_extra") ?? ""
];
$serverPartEntities[] = $this->getServerPartService()->create($formDatas);
}
return $serverPartEntities;
}
protected function create_process(array $formDatas): ServerEntity protected function create_process(array $formDatas): ServerEntity
{ {
//코드 패턴체크 //코드 패턴체크
@ -64,30 +91,15 @@ class ServerController extends EquipmentController
throw new \Exception("Server코드[{$formDatas['code']}의 형식이 맞지않습니다"); throw new \Exception("Server코드[{$formDatas['code']}의 형식이 맞지않습니다");
} }
$entity = parent::create_process($formDatas); $entity = parent::create_process($formDatas);
//추가 파트정보 생성 후 ServerEntity 에 설정
//추가 파트정보 생성 $entity->setServerParts($this->createServerParts($entity));
$partDatas = [];
foreach ($this->getService()::BaseParts as $basePart) {
$partDatas[$basePart] = [
"partinfo_uid" => $formDatas["partinfo_{$basePart}_uid"],
"cnt" => $this->request->getPost(index: "partinfo_{$basePart}_uid_cnt") ?? 1,
"extra" => $this->request->getPost("partinfo_{$basePart}_uid_extra") ?? ""
];
}
$this->serverPartEntities = $this->getService()->createServerParts($entity, $partDatas);
return $entity; return $entity;
} }
protected function index_process(array $entities = []): array protected function index_process(array $entities = []): array
{ {
// //부품정보 FormOption 설정용
// $this->serverBaseParts = $this->getService()::BaseParts;
// foreach ($this->getService()::BaseParts as $basePart) {
// $this->setFormFieldOptions("partinfo_{$basePart}_uid", $this->getFormFieldOption_process("partinfo_{$basePart}_uid"));
// }
//
foreach (parent::index_process($entities) as $entity) { foreach (parent::index_process($entities) as $entity) {
//서버 부품정보 정의 //서버 부품정보 정의
$entity->setServerParts($this->getService()->getServerParts($entity)); $entity->setServerParts($this->getServerPartService()->getEntities(['serverinfo_uid' => $entity->getPK()]));
//서버 IP정보 정의 //서버 IP정보 정의
//서버 CS정보 정의 //서버 CS정보 정의
$entities[] = $entity; $entities[] = $entity;

View File

@ -48,7 +48,10 @@ abstract class AuthController extends CommonController
} }
return $result; return $result;
} }
final protected function create_validate_process(array $formDatas): array
{
return $formDatas;
}
//로그인화면 //로그인화면
public function create_form_process(): void public function create_form_process(): void
{ {

View File

@ -41,11 +41,11 @@ class GoogleController extends AuthController
} }
//로그인처리 //로그인처리
protected function create_process(array $formDatas): void protected function create_process(array $formDatas): UserEntity
{ {
if (!array_key_exists('access_code', $formDatas) || !$formDatas['access_code']) { if (!array_key_exists('access_code', $formDatas) || !$formDatas['access_code']) {
throw new \Exception("구글 로그인 실패"); throw new \Exception("구글 로그인 실패");
} }
$this->entity = $this->getService()->login($formDatas); return $this->getService()->login($formDatas);
} }
} }

View File

@ -29,8 +29,8 @@ class LocalController extends AuthController
return ""; return "";
} }
//로그인처리 //로그인처리
protected function create_process(array $formDatas): void protected function create_process(array $formDatas): UserEntity
{ {
$this->entity = $this->getService()->login($formDatas); return $this->getService()->login($formDatas);
} }
} }

View File

@ -462,7 +462,7 @@ abstract class CommonController extends BaseController
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
} }
$this->entity = $entity; $this->entity = $entity;
list($file_name, $uploaded_filename) = $this->entity->getDownlaodFile(); list($file_name, $uploaded_filename) = $entity->getDownlaodFile();
$full_path = WRITEPATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . $uploaded_filename; $full_path = WRITEPATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . $uploaded_filename;
break; break;
} }

View File

@ -13,6 +13,15 @@ class ServerEntity extends EquipmentEntity
const STATUS_FORBIDDEN = "forbidden"; const STATUS_FORBIDDEN = "forbidden";
const DEFAULT_STATUS = self::STATUS_AVAILABLE; const DEFAULT_STATUS = self::STATUS_AVAILABLE;
public function setServerParts(array $datas): void
{
$this->attributes['server_parts'] = $datas;
}
public function getServerParts(): array
{
return $this->attributes['server_parts'] ?? [];
}
//기본기능용
public function getCode(): string public function getCode(): string
{ {
return $this->attributes['code']; return $this->attributes['code'];
@ -25,13 +34,4 @@ class ServerEntity extends EquipmentEntity
{ {
return $this->attributes['serviceinfo_uid'] ?? null; return $this->attributes['serviceinfo_uid'] ?? null;
} }
public function setServerParts(array $datas): void
{
$this->attributes['server_parts'] = $datas;
}
public function getServerParts(): array
{
return $this->attributes['server_parts'] ?? [];
}
} }

View File

@ -8,4 +8,51 @@ class ServerPartEntity extends EquipmentEntity
{ {
const PK = ServerPartModel::PK; const PK = ServerPartModel::PK;
const TITLE = ServerPartModel::TITLE; const TITLE = ServerPartModel::TITLE;
const DEFAULT_BILLING = PAYMENT['BILLING']['MONTH'];
public function setPartEntity(PartEntity $entity): void
{
$this->attributes['part'] = $entity;
}
public function getTitle(): string
{
return $this->getPartEntity()->getTitle();
}
public function getPrice(): string
{
return $this->getPartEntity()->getPrice();
}
//기본기능용
public function getPartEntity(): PartEntity
{
return $this->attributes['part'] ?? [];
}
public function getPartInfoUID(): int
{
return $this->attributes['partinfo_uid'];
}
public function getServerInfoUID(): int
{
return $this->attributes['serverinfo_uid'];
}
public function getServiceInfoUID(): int|null
{
return $this->attributes['serviceinfo_uid'] ?? null;
}
public function getBilling(): string
{
return $this->attributes['billing'];
}
public function getAmount(): int
{
return $this->attributes['amount'];
}
public function getCnt(): int
{
return $this->attributes['cnt'];
}
public function getExtra(): string|null
{
return $this->attributes['extra'] ?? null;
}
} }

View File

@ -19,21 +19,18 @@ class ServerHelper extends EquipmentHelper
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' calender' : 'calender'; $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' calender' : 'calender';
$form = form_input($field, $value ?? "", $extras); $form = form_input($field, $value ?? "", $extras);
break; break;
case 'partinfo_cpu_uid': case 'serverpartinfo_cpu_uid':
case 'partinfo_ram_uid': case 'serverpartinfo_ram_uid':
case 'partinfo_disk_uid': case 'serverpartinfo_disk_uid':
case 'partinfo_software_uid': case 'serverpartinfo_software_uid':
case 'partinfo_os_uid': case 'serverpartinfo_os_uid':
case 'partinfo_db_uid': case 'serverpartinfo_db_uid':
$form = $this->form_dropdown_custom($field, $value, $viewDatas, $extras); $form = $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
$form .= " " . form_dropdown("{$field}_cnt", $viewDatas['partinfo_cnt_range'], $value ?? 1) . ""; $form .= " " . form_dropdown("{$field}_cnt", $viewDatas['serverpartinfo_cnt_range'], old("{$field}_cnt") ?? $viewDatas['entity']->$field ?? 1) . "";
if ($field === 'partinfo_disk_uid') { if ($field === 'serverpartinfo_disk_uid') {
$form .= form_dropdown("{$field}_extra", $viewDatas['partinfo_extra_options'], $value ?? 1); $form .= form_dropdown("{$field}_extra", $viewDatas['serverpartinfo_extra_options'], old("{$field}_extra") ?? $viewDatas['entity']->$field ?? 1);
} }
break; break;
case 'partinfo_uid':
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
$form = $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
case 'ipinfo_uid': case 'ipinfo_uid':
case 'csinfo_uid': case 'csinfo_uid':
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field'; $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
@ -52,11 +49,15 @@ class ServerHelper extends EquipmentHelper
case 'format_at': case 'format_at':
$value = $value ? date("Y-m-d", strtotime($value)) : ""; $value = $value ? date("Y-m-d", strtotime($value)) : "";
break; break;
case 'partinfo_uid': case 'serverpartinfo':
$value = ""; $value = "";
foreach ($viewDatas['entity']->getServerParts() as $part) { foreach ($viewDatas['entity']->getServerParts() as $serverPart) {
// $value .= "<div>" . $this->getFieldForm("partinfo_" . strtolower($part->type) . "_uid", $part->partinfo_uid, $viewDatas, $extras) . "</div>"; $value .= sprintf(
$value .= sprintf("<div>%s%s %s</div>", $part->title, $part->cnt > 1 ? "*" . $part->cnt . "" : "", $part->extra ?? ""); "<div>%s%s %s</div>",
$serverPart->getTitle(),
$serverPart->getCnt() > 1 ? "*" . $serverPart->getCnt() . "" : "",
$serverPart->getExtra() ?? ""
);
} }
// dd($value); // dd($value);
break; break;
@ -78,10 +79,6 @@ class ServerHelper extends EquipmentHelper
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field'; $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
$form = parent::getListFilter($field, $value, $viewDatas, $extras); $form = parent::getListFilter($field, $value, $viewDatas, $extras);
break; break;
case 'partinfo_uid':
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
$form = $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
break;
default: default:
$form = parent::getListFilter($field, $value, $viewDatas, $extras); $form = parent::getListFilter($field, $value, $viewDatas, $extras);
break; break;

View File

@ -15,15 +15,15 @@ return [
'updated_at' => "수정일", 'updated_at' => "수정일",
'created_at' => "작성일", 'created_at' => "작성일",
'deleted_at' => "삭제일", 'deleted_at' => "삭제일",
"partinfo_uid" => "부품정보", "serverpartinfo" => "부품정보",
"ipinfo_uid" => "IP정보", "ipinfo_uid" => "IP정보",
"csinfo_uid" => "CS정보", "csinfo_uid" => "CS정보",
'partinfo_cpu_uid' => "CPU", 'serverpartinfo_cpu_uid' => "CPU",
'partinfo_ram_uid' => "RAM", 'serverpartinfo_ram_uid' => "RAM",
'partinfo_disk_uid' => "DISK", 'serverpartinfo_disk_uid' => "DISK",
'partinfo_os_uid' => "OS", 'serverpartinfo_os_uid' => "OS",
'partinfo_db_uid' => "DB", 'serverpartinfo_db_uid' => "DB",
'partinfo_software_uid' => "기타SW", 'serverpartinfo_software_uid' => "기타SW",
], ],
"TITLE" => [ "TITLE" => [
'HP DL360 Gen6' => "HP DL360 Gen6", 'HP DL360 Gen6' => "HP DL360 Gen6",

View File

@ -8,7 +8,7 @@ class ServerPartModel extends EquipmentModel
{ {
const TABLE = "serverinfo_partinfo"; const TABLE = "serverinfo_partinfo";
const PK = "uid"; const PK = "uid";
const TITLE = "partinfo_uio"; const TITLE = "uid";
protected $table = self::TABLE; protected $table = self::TABLE;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = ServerPartEntity::class; protected $returnType = ServerPartEntity::class;
@ -34,8 +34,8 @@ class ServerPartModel extends EquipmentModel
case "partinfo_uid": case "partinfo_uid":
case "serverinfo_uid": case "serverinfo_uid":
case "billing": case "billing":
case "amount":
case "cnt": case "cnt":
case "amount":
$rule = "required|numeric"; $rule = "required|numeric";
break; break;
case "serviceinfo_uid": case "serviceinfo_uid":

View File

@ -83,7 +83,12 @@ abstract class AuthService extends CommonService
final protected function login_process(UserEntity $entity): UserEntity final protected function login_process(UserEntity $entity): UserEntity
{ {
$this->getSession()->set(SESSION_NAMES['ISLOGIN'], true); $this->getSession()->set(SESSION_NAMES['ISLOGIN'], true);
$this->getSession()->set(SESSION_NAMES['AUTH'], ['uid' => $entity->getPK(), 'id' => $entity->getID(), 'name' => $entity->getTitle(), 'role' => $entity->role]); $this->getSession()->set(SESSION_NAMES['AUTH'], [
'uid' => $entity->getPK(),
'id' => $entity->getID(),
'name' => $entity->getTitle(),
'role' => $entity->role
]);
return $entity; return $entity;
} }
final public function logout(): void final public function logout(): void
@ -96,7 +101,15 @@ abstract class AuthService extends CommonService
// 세션 쿠키 삭제 // 세션 쿠키 삭제
if (ini_get("session.use_cookies")) { if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params(); $params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]); setcookie(
session_name(),
'',
time() - 42000,
$params["path"],
$params["domain"],
$params["secure"],
$params["httponly"]
);
} }
// 세션 재생성 // 세션 재생성
session_start(); session_start();

View File

@ -72,15 +72,16 @@ abstract class CommonService
if ($where) { if ($where) {
$this->getModel()->where($where); $this->getModel()->where($where);
} }
return $this->getModel()->select(implode(',', $columns))->findAll(); $entities = [];
foreach ($this->getModel()->select(implode(',', $columns))->findAll() as $entity) {
$entities[$entity->getPK()] = $this->getEntity_process($entity);
}
return $entities;
} }
final public function getEntities(mixed $where = null, array $columns = ['*']): array final public function getEntities(mixed $where = null, array $columns = ['*']): array
{ {
try { try {
$entities = []; $entities = $this->getEntities_process($where, $columns);
foreach ($this->getEntities_process($where, $columns) as $entity) {
$entities[$entity->getPK()] = $this->getEntity_process($entity);
}
$debug = sprintf("debug.%s.%s", $this->getClassName(), __FUNCTION__); $debug = sprintf("debug.%s.%s", $this->getClassName(), __FUNCTION__);
if (env($debug, false)) { if (env($debug, false)) {
echo $debug . "=>" . $this->getModel()->getLastQuery() . "<BR>"; echo $debug . "=>" . $this->getModel()->getLastQuery() . "<BR>";

View File

@ -0,0 +1,89 @@
<?php
namespace App\Services\Equipment;
use App\Models\Equipment\ServerPartModel;
use App\Services\Equipment\EquipmentService;
class ServerPartService extends EquipmentService
{
const BaseParts = ['cpu', 'ram', 'disk', 'os'];
private ?PartService $_partService = null;
public function __construct()
{
parent::__construct(new ServerPartModel());
$this->addClassName('Server');
}
public function getFormFields(): array
{
return [
'fields' => [
"partinfo_uid",
"serverinfo_uid",
"serviceinfo_uid",
"billing",
"amount",
"cnt",
"extra",
],
'filters' => [
"partinfo_uid",
"serverinfo_uid",
"serviceinfo_uid",
],
];
}
public function getIndexFields(): array
{
return $this->getFormFields();
}
public function getBatchjobFields(): array
{
return ['partinfo_uid', "serverinfo_uid", "serviceinfo_uid",];
}
final public function getPartService(): PartService
{
if (!$this->_partService) {
$this->_partService = new PartService();
}
return $this->_partService;
}
//기본 기능부분
//FieldForm관련용
public function getFormFieldOption(string $field, array $options = []): array
{
switch ($field) {
case 'partinfo_cpu_uid':
$options = $this->getPartService()->getEntities(['type' => 'CPU']);
break;
case 'partinfo_ram_uid':
$options = $this->getPartService()->getEntities(['type' => 'RAM']);
break;
case 'partinfo_disk_uid':
$options = $this->getPartService()->getEntities(['type' => 'DISK']);
break;
case 'partinfo_os_uid':
$options = $this->getPartService()->getEntities(['type' => 'OS']);
break;
case 'partinfo_db_uid':
$options = $this->getPartService()->getEntities(['type' => 'DB']);
break;
case 'partinfo_software_uid':
$options = $this->getPartService()->getEntities(['type' => 'SOFTWARE']);
break;
case 'partinfo_uid': //수정때문에 전체가 필요
$options = $this->getPartService()->getEntities();
break;
default:
$options = parent::getFormFieldOption($field, $options);
break;
}
return $options;
}
//partEntity 정보 추가
protected function getEntity_process(mixed $entity): mixed
{
$entity->setPartEntity($this->getPartService()->getEntity($entity->getPartInfoUID()));
return $entity;
}
}

View File

@ -9,11 +9,7 @@ use App\Services\Equipment\EquipmentService;
class ServerService extends EquipmentService class ServerService extends EquipmentService
{ {
private ?PartService $_partService = null; private ?ServerPartService $_serverPartService = null;
private ?IPService $_ipService = null;
private ?CSService $_csService = null;
private ?ServerPartModel $_serverPartModel = null;
const BaseParts = ['cpu', 'ram', 'disk', 'os'];
public function __construct() public function __construct()
{ {
parent::__construct(new ServerModel()); parent::__construct(new ServerModel());
@ -26,10 +22,10 @@ class ServerService extends EquipmentService
"code", "code",
"type", "type",
"title", "title",
"partinfo_cpu_uid", "serverpartinfo_cpu_uid",
"partinfo_ram_uid", "serverpartinfo_ram_uid",
"partinfo_disk_uid", "serverpartinfo_disk_uid",
"partinfo_os_uid", "serverpartinfo_os_uid",
"price", "price",
"amount", "amount",
"manufactur_at", "manufactur_at",
@ -41,10 +37,10 @@ class ServerService extends EquipmentService
"serviceinfo_uid", "serviceinfo_uid",
"type", "type",
"title", "title",
"partinfo_cpu_uid", "serverpartinfo_cpu_uid",
"partinfo_ram_uid", "serverpartinfo_ram_uid",
"partinfo_disk_uid", "serverpartinfo_disk_uid",
"partinfo_os_uid", "serverpartinfo_os_uid",
"status" "status"
], ],
]; ];
@ -57,26 +53,26 @@ class ServerService extends EquipmentService
'serviceinfo_uid', 'serviceinfo_uid',
"type", "type",
'title', 'title',
"partinfo_uid", "serverpartinfo",
'price', 'price',
'amount', 'amount',
'manufactur_at', 'manufactur_at',
"format_at", "format_at",
'status' 'status'
], ],
'filters' => ['clientinfo_uid', 'serviceinfo_uid', 'type', 'partinfo_uid', 'status'], 'filters' => ['clientinfo_uid', 'serviceinfo_uid', 'type', 'status'],
]; ];
} }
public function getBatchjobFields(): array public function getBatchjobFields(): array
{ {
return ['clientinfo_uid', 'partinfo_uid', 'status']; return ['clientinfo_uid', 'status'];
} }
final public function getPartService(): PartService final public function getServerPartService(): ServerPartService
{ {
if (!$this->_partService) { if (!$this->_serverPartService) {
$this->_partService = new PartService(); $this->_serverPartService = new ServerPartService();
} }
return $this->_partService; return $this->_serverPartService;
} }
final public function getIPService(): IPService final public function getIPService(): IPService
{ {
@ -92,38 +88,27 @@ class ServerService extends EquipmentService
} }
return $this->_csService; return $this->_csService;
} }
final public function getServerPartModel(): ServerPartModel
{
if (!$this->_serverPartModel) {
$this->_serverPartModel = new ServerPartModel();
}
return $this->_serverPartModel;
}
//기본 기능부분 //기본 기능부분
//FieldForm관련용
public function getFormFieldOption(string $field, array $options = []): array public function getFormFieldOption(string $field, array $options = []): array
{ {
switch ($field) { switch ($field) {
case 'partinfo_cpu_uid': case 'serverpartinfo_cpu_uid':
$options = $this->getPartService()->getEntities(['type' => 'CPU']); $options = $this->getServerPartService()->getFormFieldOption('partinfo_cpu_uid');
break; break;
case 'partinfo_ram_uid': case 'serverpartinfo_ram_uid':
$options = $this->getPartService()->getEntities(['type' => 'RAM']); $options = $this->getServerPartService()->getFormFieldOption('partinfo_ram_uid');
break; break;
case 'partinfo_disk_uid': case 'serverpartinfo_disk_uid':
$options = $this->getPartService()->getEntities(['type' => 'DISK']); $options = $this->getServerPartService()->getFormFieldOption('partinfo_disk_uid');
break; break;
case 'partinfo_os_uid': case 'serverpartinfo_os_uid':
$options = $this->getPartService()->getEntities(['type' => 'OS']); $options = $this->getServerPartService()->getFormFieldOption('partinfo_os_uid');
break; break;
case 'partinfo_db_uid': case 'serverpartinfo_db_uid':
$options = $this->getPartService()->getEntities(['type' => 'DB']); $options = $this->getServerPartService()->getFormFieldOption('partinfo_db_uid');
break; break;
case 'partinfo_software_uid': case 'serverpartinfo_software_uid':
$options = $this->getPartService()->getEntities(['type' => 'SOFTWARE']); $options = $this->getServerPartService()->getFormFieldOption('partinfo_software_uid');
break;
case 'partinfo_uid': //수정때문에 전체가 필요
$options = $this->getPartService()->getEntities();
break; break;
case 'ipinfo_uid': //수정때문에 전체가 필요 case 'ipinfo_uid': //수정때문에 전체가 필요
$options = $this->getIPService()->getEntities(); $options = $this->getIPService()->getEntities();
@ -137,32 +122,12 @@ class ServerService extends EquipmentService
} }
return $options; return $options;
} }
//FieldForm관련용
//create용 장비코드 마지막번호 가져오기 //create용 장비코드 마지막번호 가져오기
final public function getLastestCode(string $format, int $default): string final public function getLastestCode(string $format, int $default): string
{ {
return $this->getModel()->getLastestCode($format, $default); return $this->getModel()->getLastestCode($format, $default);
} }
//Server Part별 저장
public function createServerParts(ServerEntity $entity, array $partDatas): array
{
$serverPartEntities = [];
foreach (self::BaseParts as $basePart) {
$partDatas[$basePart]["serverinfo_uid"] = $entity->getPK();
$partDatas[$basePart]["serviceinfo_uid"] = $entity->getServiceInfoUID();
$serverPartEntities[] = $this->getServerPartModel()->create($partDatas[$basePart]);
}
return $serverPartEntities;
}
//Server Part별 정보가져오기
public function getServerParts(ServerEntity $entity): array
{
$sql = "SELECT serverinfo_partinfo.*,partinfo.title as title,partinfo.price,partinfo.type FROM serverinfo_partinfo
LEFT JOIN partinfo ON serverinfo_partinfo.partinfo_uid = partinfo.uid
WHERE serverinfo_partinfo.serverinfo_uid = ?";
return $this->getModel()->query($sql, [$entity->getPK()])->getResult();
}
//List 검색용 //List 검색용
//OrderBy 처리 //OrderBy 처리
public function setOrderBy(mixed $field = null, mixed $value = null): void public function setOrderBy(mixed $field = null, mixed $value = null): void