186 lines
6.2 KiB
PHP
186 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Equipment;
|
|
|
|
use App\Entities\Equipment\ServerEntity;
|
|
use App\Helpers\Equipment\ServerHelper;
|
|
use App\Models\Equipment\ServerModel;
|
|
use App\Services\Equipment\Server\ServiceService;
|
|
use App\Services\Equipment\Server\ServerPartService;
|
|
use App\Services\Equipment\EquipmentService;
|
|
|
|
class ServerService extends EquipmentService
|
|
{
|
|
private ?ServiceService $_serviceService = null;
|
|
private ?ServerPartService $_serverPartService = null;
|
|
public function __construct()
|
|
{
|
|
parent::__construct(new ServerModel(), new ServerHelper());
|
|
$this->addClassName('Server');
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
"code",
|
|
"type",
|
|
"title",
|
|
"price",
|
|
"manufactur_at",
|
|
];
|
|
}
|
|
public function getFormFilters(): array
|
|
{
|
|
return [
|
|
"type",
|
|
"title",
|
|
"status"
|
|
];
|
|
}
|
|
public function getIndexFields(): array
|
|
{
|
|
return [
|
|
'clientinfo_uid',
|
|
'serviceinfo_uid',
|
|
"type",
|
|
'title',
|
|
'price',
|
|
'manufactur_at',
|
|
"format_at",
|
|
'status',
|
|
];
|
|
}
|
|
public function getIndexFilters(): array
|
|
{
|
|
return [
|
|
'clientinfo_uid',
|
|
'serviceinfo_uid',
|
|
'type',
|
|
"title",
|
|
'status'
|
|
];
|
|
}
|
|
public function getBatchjobFields(): array
|
|
{
|
|
return ['clientinfo_uid', 'status'];
|
|
}
|
|
final public function getServiceService(): ServiceService
|
|
{
|
|
if ($this->_serviceService === null) {
|
|
$this->_serviceService = new ServiceService();
|
|
}
|
|
return $this->_serviceService;
|
|
}
|
|
final public function getServerPartService(): ServerPartService
|
|
{
|
|
if (!$this->_serverPartService) {
|
|
$this->_serverPartService = new ServerPartService();
|
|
}
|
|
return $this->_serverPartService;
|
|
}
|
|
//partEntity 정보 추가
|
|
protected function getEntity_process(mixed $entity): ServerEntity
|
|
{
|
|
if (!$entity instanceof ServerEntity) {
|
|
throw new \Exception(__METHOD__ . "에서 형식오류:ServerEntity만 허용됩니다.");
|
|
}
|
|
return $entity;
|
|
}
|
|
final public function getTotalServiceCount(array $where = []): array
|
|
{
|
|
$totalCounts = [
|
|
'chiba_summary' => 0,
|
|
'tokyo_summary' => 0,
|
|
'all_summary' => 0,
|
|
'normal' => ['chiba' => 0, 'tokyo' => 0, 'summary' => 0],
|
|
'defence' => ['chiba' => 0, 'tokyo' => 0, 'summary' => 0],
|
|
'dedicated' => ['chiba' => 0, 'tokyo' => 0, 'summary' => 0],
|
|
'vpn' => ['chiba' => 0, 'tokyo' => 0, 'summary' => 0],
|
|
'event' => ['chiba' => 0, 'tokyo' => 0, 'summary' => 0],
|
|
'test' => ['chiba' => 0, 'tokyo' => 0, 'summary' => 0],
|
|
'alternative' => ['chiba' => 0, 'tokyo' => 0, 'summary' => 0],
|
|
];
|
|
$rows = $this->getModel()
|
|
->select("serverinfo.type,
|
|
COUNT(CASE WHEN serviceinfo.location = 'chiba' THEN 1 END) AS chiba,
|
|
COUNT(CASE WHEN serviceinfo.location = 'tokyo' THEN 1 END) AS tokyo,
|
|
COUNT(CASE WHEN serviceinfo.location IN ('chiba', 'tokyo') THEN 1 END) AS summary")
|
|
->join('serviceinfo', 'serviceinfo.uid = serverinfo.serviceinfo_uid') // JOIN 조건
|
|
->where($where)
|
|
->groupBy('serverinfo.type')
|
|
->get()
|
|
->getResult();
|
|
foreach ($rows as $row) {
|
|
$totalCounts[$row->type]['chiba'] = $row->chiba;
|
|
$totalCounts[$row->type]['tokyo'] = $row->tokyo;
|
|
$totalCounts[$row->type]['summary'] = $row->summary;
|
|
$totalCounts['chiba_summary'] += $row->chiba;
|
|
$totalCounts['tokyo_summary'] += $row->tokyo;
|
|
$totalCounts['all_summary'] = $totalCounts['chiba_summary'] + $totalCounts['tokyo_summary'];
|
|
}
|
|
// dd($totalCounts);
|
|
return $totalCounts;
|
|
}
|
|
//기본 기능부분
|
|
//FieldForm관련용
|
|
public function getFormOption(string $field, $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case 'serviceinfo_uid':
|
|
$options = $this->getServiceService()->getEntities();
|
|
break;
|
|
default:
|
|
$options = parent::getFormOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
public function setFormData(string $field, array $requestDatas, array $formDatas): array
|
|
{
|
|
switch ($field) {
|
|
case 'CPU':
|
|
case 'RAM':
|
|
$formDatas[$field] = $requestDatas[$field] ?? null;
|
|
$formDatas["{$field}_cnt"] = $requestDatas["{$field}_cnt"] ?? null;
|
|
break;
|
|
case 'DISK':
|
|
$formDatas[$field] = $requestDatas[$field] ?? null;
|
|
$formDatas["{$field}_cnt"] = $requestDatas["{$field}_cnt"] ?? null;
|
|
$formDatas["{$field}_extra"] = $requestDatas["{$field}_extra"] ?? null;
|
|
break;
|
|
default:
|
|
$formDatas = parent::setFormData($field, $requestDatas, $formDatas);
|
|
}
|
|
return $formDatas;
|
|
}
|
|
//Action 기능
|
|
private function action_process(ServerEntity $entity, string $action): ServerEntity
|
|
{
|
|
//서비스정보수정(청구액수정)
|
|
$entity = $this->getServiceService()->$action($entity);
|
|
$entity = $this->getServerPartService()->$action($entity);
|
|
return $entity;
|
|
}
|
|
//수정
|
|
public function modify(mixed $entity, array $formDatas): ServerEntity
|
|
{
|
|
//서버정보 수정
|
|
$entity = parent::modify($entity, $formDatas);
|
|
//후처리작업
|
|
return $this->action_process($entity, __FUNCTION__ . 'Server');
|
|
}
|
|
//삭제
|
|
public function delete(mixed $entity): ServerEntity
|
|
{
|
|
//선처리작업
|
|
$entity = $this->action_process($entity, __FUNCTION__ . 'Server');
|
|
return parent::delete($entity);
|
|
}
|
|
//List 검색용
|
|
//OrderBy 처리
|
|
public function setOrderBy(mixed $field = null, mixed $value = null): void
|
|
{
|
|
$this->getModel()->orderBy("code ASC,title ASC");
|
|
parent::setOrderBy($field, $value);
|
|
}
|
|
}
|