76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace lib\Services;
|
|
|
|
use lib\Entities\ServerEntity as Entity;
|
|
use lib\Models\ServerModel as Model;
|
|
|
|
class ServerService extends CommonService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
final public function getClassName(): string
|
|
{
|
|
return "Server";
|
|
}
|
|
final public function getClassPath(): string
|
|
{
|
|
return $this->getClassName();
|
|
}
|
|
public function getModelClass(): string
|
|
{
|
|
return Model::class;
|
|
}
|
|
public function getEntityClass(): string
|
|
{
|
|
return Entity::class;
|
|
}
|
|
public function getCountByServiceCode(string $service_code): int
|
|
{
|
|
$this->getModel()->where("service_code", $service_code);
|
|
return $this->getCount();
|
|
}
|
|
|
|
public function getCountByMode(string $mode, string $cpu, ?string $spec = null): int
|
|
{
|
|
switch ($mode) {
|
|
case 'all':
|
|
$this->getModel()->like(["server_cpuname" => "%$cpu%", "server_spec" => "%$spec%"]);
|
|
break;
|
|
case 'use':
|
|
$this->getModel()->where("server_use_status", "n");
|
|
$this->getModel()->like(["server_cpuname" => "%$cpu%", "server_spec" => "%$spec%"]);
|
|
break;
|
|
case 'empty':
|
|
$this->getModel()->where("server_use_status", "y");
|
|
$this->getModel()->like(["server_cpuname" => "%$cpu%", "server_spec" => "%$spec%"]);
|
|
break;
|
|
case 'format':
|
|
$this->getModel()->where("server_use_status", "y");
|
|
$this->getModel()->where("server_fomat_date !='NULL'");
|
|
$this->getModel()->like(["server_cpuname" => "%$cpu%"]);
|
|
break;
|
|
default:
|
|
throw new \InvalidArgumentException("Invalid mode: $mode");
|
|
}
|
|
return $this->getCount();
|
|
}
|
|
|
|
//사용자별 서비스리스트트
|
|
public function getEntitiesByClient(int $curPage, int $perPage, ?string $client_code = null): array
|
|
{
|
|
if ($client_code) {
|
|
$this->getModel()->where("client_code", $client_code);
|
|
}
|
|
//Query문 Rest여부 -> 같은조건에 Count 받고, 결과값을 받고 싶을때는 continue()
|
|
$this->getModel()->setContinue(true);
|
|
$total = $this->getCount();
|
|
//limit, offset 설정
|
|
$this->getModel()->limit($perPage);
|
|
$this->getModel()->offset(($curPage - 1) * $perPage);
|
|
return [$total, $this->getEntities()];
|
|
}
|
|
}
|