dbms_init...1

This commit is contained in:
choi.jh 2025-06-16 19:36:30 +09:00
parent 112f304d09
commit 052f0e2145
13 changed files with 140 additions and 23 deletions

View File

@ -3,12 +3,13 @@
namespace App\Controllers\Admin\Customer;
use App\Controllers\Admin\AdminController;
use App\Entities\Equipment\Part\IpEntity;
use App\Services\Customer\ClientService;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Services\Customer\ClientService;
abstract class CustomerController extends AdminController
{
private ?ClientService $_clientService = null;
@ -30,9 +31,23 @@ abstract class CustomerController extends AdminController
{
//$item_type(CPU,RAM,STORAGE등)에 따라 선언된 getFormFieldOption용
foreach (SERVICE_ITEM_TYPES as $item_type => $label) {
if ($item_type == 'IP') {
$occupied_ips = [];
$forbidden_ips = [];
}
$options = [];
foreach ($this->getService()->getEquipmentService($item_type)->getEntities() as $entity) {
$options[$entity->getPK()] = $entity->getTitle();
if ($item_type == 'IP') {
if ($entity->getStatus() === IpEntity::STATUS_OCCUPIED) {
$occupied_ips[] = $entity->getPK();
}
if ($entity->getStatus() === IpEntity::STATUS_FORBIDDEN) {
$forbidden_ips[] = $entity->getPK();
}
$this->occupied_ips = $occupied_ips;
$this->forbidden_ips = $forbidden_ips;
}
}
$this->setFilterFieldOption($item_type, $options);
}

View File

@ -107,7 +107,7 @@ class ServicePaymentController extends CustomerController
private function getServices(ServiceEntity $serviceEntity): array
{
$temps = [
'serial' => $serviceEntity->getSerialCode(),
'code' => $serviceEntity->getTitle(),
'billing_at' => $serviceEntity->getBillingAt(),
'items' => []
];

View File

@ -2,14 +2,14 @@
namespace App\Controllers\Admin\Equipment\Part;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Helpers\Equipment\Part\IpHelper;
use App\Services\Equipment\Part\IpService;
use App\Services\Equipment\Part\LineService;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class IpController extends PartController
{

View File

@ -25,7 +25,7 @@ class ServiceEntity extends CustomerEntity
$this->_ownerEntity = $ownerEntity;
}
//타 객체정의 부분
public function getSerialCode(): string
public function getTitle(): string
{
return "S" . $this->getPK();
}

View File

@ -8,4 +8,7 @@ class IpEntity extends PartEntity
{
const PK = IpModel::PK;
const TITLE = IpModel::TITLE;
const STATUS_AVAILABLE = "default";
const STATUS_OCCUPIED = "occupied";
const STATUS_FORBIDDEN = "forbidden";
}

View File

@ -29,6 +29,22 @@ class ServiceItemHelper extends CustomerHelper
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
}
break;
case 'IP':
if (!is_array($viewDatas['control']['filter_optons'][$field])) {
throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다.");
}
//CodeIgniter 4의 form_dropdown()은 options 배열로만 값을 받기 때문에, disabled 속성 같은 개별 옵션에 대한 HTML 속성 추가는 기본적으로 지원하지 않습니다.
$form_temps = ["<select name=\"{$field}\" class=\"select-field\"" . (isset($extras['onChange']) ? " onChange=\"{$extras['onChange']}\"" : "") . ">"];
$form_temps[] = "<option value=\"\">" . lang($viewDatas['class_path'] . '.label.' . $field) . " 선택</option>";
foreach ($viewDatas['control']['filter_optons'][$field] as $key => $label) {
$disabled = in_array($key, $viewDatas['occupied_ips']) || in_array($key, $viewDatas['forbidden_ips']) ? 'disabled="disabled"' : '';
$selected = ($value === $key) ? 'selected="selected"' : '';
$form_temps[] = "<option value=\"{$key}\"{$selected} {$disabled}>{$label}</option>";
}
$form_temps[] = '</select>';
$form = implode("", $form_temps);
//dd($viewDatas['occupied_ips']);
break;
default:
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
break;

View File

@ -16,8 +16,8 @@ return [
"STATUS" => [
'default' => "사용가능",
"pause" => "일시정지",
"occupied" => "사용",
"forbidden" => "사용금지됨",
"occupied" => "서비스",
"forbidden" => "금지됨",
"delete" => "삭제",
],
];

View File

@ -8,14 +8,13 @@ class ServiceModel extends CustomerModel
{
const TABLE = "serviceinfo";
const PK = "uid";
const TITLE = "title";
const TITLE = "uid";
protected $table = self::TABLE;
protected $primaryKey = self::PK;
protected $returnType = ServiceEntity::class;
protected $allowedFields = [
"clientinfo_uid",
"ownerinfo_uid",
"title",
"type",
"location",
"switch",
@ -40,7 +39,6 @@ class ServiceModel extends CustomerModel
case "ownerinfo_uid":
$rule = "required|numeric";
break;
case "title":
case "type":
case "location":
case "switch":

View File

@ -0,0 +1,49 @@
<?php
namespace App\Services\Customer\ServiceItem;
use App\Entities\Equipment\Part\IpEntity;
use App\Services\Equipment\Part\IpService;
use CodeIgniter\HTTP\IncomingRequest;
class ServiceItemIpService extends ServiceItemService
{
protected ?IncomingRequest $request = null;
private ?IpService $_ipService = null;
public function __construct(?IncomingRequest $request = null)
{
parent::__construct($request);
}
public function getIpService(): IpService
{
if (!$this->_ipService) {
$this->_ipService = new IpService($this->request);
}
return $this->_ipService;
}
public function create(array $formDatas, mixed $entity = null): ServiceItemEntity
{
//ip의 경우 서비스중으로 설정작업
$entity = parent::create($formDatas, $entity);
$this->getIpService()->setStatus($formDatas['code'], IpEntity::STATUS_OCCUPIED);
}
public function modify(mixed $entity, array $formDatas): ServiceEntity
{
//code가 기존과 다를경우 //toggle,batchjob의 경우 $formDatas에 code가 없을수도 있음
if (array_key_exists('code', $formDatas) && $formDatas['code'] !== $entity->getCode()) {
//code의 경우 기존code는 사용가능으로 설정작업
$this->getCodeService()->setStatus($entity->getCode(), IpEntity::STATUS_AVAILABLE);
//coded의 경우 변경된 code는 서비스중으로 설정작업
$this->getCodeService()->setStatus($formDatas['code'], IpEntity::STATUS_OCCUPIED);
}
return parent::modify($entity, $formDatas);
}
final public function delete(mixed $entity): bool
{
//code의 경우 기존code는 사용가능으로 설정작업
$this->getCodeService()->setStatus($entity->getCode(), IpEntity::STATUS_AVAILABLE);
return parent::delete($entity);
}
}

View File

@ -1,12 +1,13 @@
<?php
namespace App\Services\Customer;
namespace App\Services\Customer\ServiceItem;
use CodeIgniter\HTTP\IncomingRequest;
use App\Models\Customer\ServiceItemModel;
use App\Entities\Customer\ServiceItemEntity;
use App\Models\Customer\ServiceItemModel;
use App\Services\Customer\CustomerService;
use App\Services\Customer\ServicePaymentService;
use App\Services\Customer\ServiceService;
use CodeIgniter\HTTP\IncomingRequest;
class ServiceItemService extends CustomerService
{
@ -88,3 +89,29 @@ class ServiceItemService extends CustomerService
return parent::delete($entity);
}
}
// public function create(array $formDatas, mixed $entity = null): ServiceEntity
// {
// //code의 경우 서비스중으로 설정작업
// $this->getCodeService()->setStatus($formDatas['code'], CodeEntity::STATUS_OCCUPIED);
// return parent::create($formDatas, $entity);
// }
// public function modify(mixed $entity, array $formDatas): ServiceEntity
// {
// //code가 기존과 다를경우 //toggle,batchjob의 경우 $formDatas에 code가 없을수도 있음
// if (array_key_exists('code', $formDatas) && $formDatas['code'] !== $entity->getCode()) {
// //code의 경우 기존code는 사용가능으로 설정작업
// $this->getCodeService()->setStatus($entity->getCode(), CodeEntity::STATUS_AVAILABLE);
// //coded의 경우 변경된 code는 서비스중으로 설정작업
// $this->getCodeService()->setStatus($formDatas['code'], CodeEntity::STATUS_OCCUPIED);
// }
// return parent::modify($entity, $formDatas);
// }
// final public function delete(mixed $entity): bool
// {
// //code의 경우 기존code는 사용가능으로 설정작업
// $this->getCodeService()->setStatus($entity->getCode(), CodeEntity::STATUS_AVAILABLE);
// return parent::delete($entity);
// }

View File

@ -8,7 +8,6 @@ use CodeIgniter\HTTP\IncomingRequest;
use App\Entities\Equipment\CodeEntity;
use App\Services\Equipment\CodeService;
use PhpOffice\PhpSpreadsheet\Calculation\Web\Service;
class ServiceService extends CustomerService
{
@ -32,7 +31,6 @@ class ServiceService extends CustomerService
return [
"clientinfo_uid",
"ownerinfo_uid",
"title",
"type",
"location",
"switch",
@ -53,7 +51,7 @@ class ServiceService extends CustomerService
}
public function getIndexFields(): array
{
return ['clientinfo_uid', 'ownerinfo_uid', 'title', 'type', 'location', 'switch', 'code', 'raid', 'billing_at', 'start_at', 'updated_at', 'status'];
return ['clientinfo_uid', 'ownerinfo_uid', 'type', 'location', 'switch', 'code', 'raid', 'billing_at', 'start_at', 'updated_at', 'status'];
}
public function getCodeService(): CodeService
{

View File

@ -52,4 +52,15 @@ class IpService extends PartService
$formDatas['status'] = DEFAULTS['STATUS'];
return $this->create($formDatas, new IpEntity());
}
//상태변경
public function setStatus(int $uid, string $status): IpEntity
{
//code의 경우 사용가능/사용중으로 설정작업
$entity = $this->getEntity($uid);
if (!$entity) {
throw new \Exception("{$uid}에 대한 IP정보를 찾을수 없습니다.");
}
return $this->getModel()->modify($entity, ['status' => $status]);
}
}

View File

@ -34,7 +34,7 @@
<table class="table table-bordered text-center">
<?php foreach ($entity['services'] as $service): ?>
<tr>
<th>서비스: <?= $service['serial'] ?></th>
<th>서비스: <?= $service['code'] ?></th>
<th class="text-end">지급기한: <?= $service['billing_at'] ?></th>
</tr>
<tr>
@ -42,8 +42,8 @@
<td>
<ol>
<?php foreach ($service['items'] as $item): ?>
<li class="text-start"><?= $item['item_type'] ?> :<?= $item['item_uid'] ?> [<?= number_format($item['amount']) ?>원]<\ /li>
<?php endforeach; ?>
<li class="text-start"><?= $item['item_type'] ?> :<?= $item['item_uid'] ?> [<?= number_format($item['amount']) ?>원]</li>
<?php endforeach; ?>
</ol>
</td>
</tr>