forked from SimplesIP/pabx-app
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.5 KiB
105 lines
3.5 KiB
<?php |
|
|
|
namespace service; |
|
|
|
use app\Models\Atendimento; |
|
use app\Models\Parametros; |
|
use app\Models\SupervisorModel; |
|
|
|
class ServiceSupervisorPBx implements IService |
|
{ |
|
/** @var SupervisorModel $supervisorModel model do supervisor */ |
|
private $supervisorModel; |
|
|
|
function run() |
|
{ |
|
try { |
|
$this->supervisorModel = new SupervisorModel; |
|
$agentes = $this->supervisorModel->listaAgentesDisponivel(null, false); |
|
foreach ($agentes as $key => $agente) { |
|
if ($this->validaInatividade($agente->duracao)) { |
|
$agentPbx = $this->validaAgentCriado($agente->matricula); |
|
if (!$agentPbx) { |
|
$this->criaRegistroSupervisor($agente); |
|
} else { |
|
$this->atualizaTabelaSupervisor($agente, $agentPbx); |
|
} |
|
} else { |
|
$this->supervisorModel->deleteAgent($agente->matricula); |
|
} |
|
} |
|
|
|
$agentesPbx = $this->supervisorModel->findAllAgentesPBX(null, CONF_MEDIA_PBX); |
|
foreach ($agentesPbx as $key => $pbx) { |
|
$age = $this->supervisorModel->findAgentByMatricula($pbx->matricula); |
|
if (empty($age)) { |
|
$this->supervisorModel->deleteAgentPbx($pbx->matricula); |
|
} |
|
} |
|
} catch (\Exception $ex) { |
|
logger('ServiceSupervisorPBx')->info($ex->getMessage(), debug_backtrace()); |
|
} |
|
} |
|
|
|
function atualizaTabelaSupervisor($agente, $agentePbx) |
|
{ |
|
$this->supervisorModel->updateAgent2( |
|
$agente->matricula, |
|
$agente->ramal, |
|
$agente->fila, |
|
$agente->status, |
|
$agente->status != $agentePbx->status, |
|
$agente->motivo_pausa, |
|
$this->retornaQuantidadeAtendimento($agente->matricula), |
|
$this->statusDisponivelFila($agente) |
|
); |
|
} |
|
|
|
function criaRegistroSupervisor($agente) |
|
{ |
|
$this->supervisorModel->addAgent2( |
|
$agente->nome, |
|
$agente->matricula, |
|
$agente->ramal, |
|
$agente->fila, |
|
$agente->tempo_login, |
|
$agente->status, |
|
$agente->motivo_pausa, |
|
$this->retornaQuantidadeAtendimento($agente->matricula) |
|
); |
|
} |
|
|
|
function retornaQuantidadeAtendimento($matricula, $retornaBool = false) |
|
{ |
|
$atendimentoModel = new Atendimento(); |
|
$paratroModel = new Parametros(); |
|
$atendimentos = $atendimentoModel->getAtendimentoAbertoByAgente($matricula); |
|
$parametros = $paratroModel->findProtocolByParams(); |
|
$count = count($atendimentos); |
|
if ($retornaBool) { |
|
return $count < $parametros->prm_media_simultaneo; |
|
} |
|
return "$count/{$parametros->prm_media_simultaneo}"; |
|
} |
|
|
|
function validaAgentCriado($matricula) |
|
{ |
|
return $this->supervisorModel->findAgentByMatriculaPbx($matricula); |
|
} |
|
function statusDisponivelFila($agente) |
|
{ |
|
if ($agente->status == 'LIVRE' && $this->retornaQuantidadeAtendimento($agente->matricula, true)) { |
|
return 1; |
|
} |
|
return 0; |
|
} |
|
|
|
function validaInatividade($dateTime) |
|
{ |
|
$timealert = strtotime($dateTime . '+70 seconds'); |
|
if ($timealert < strtotime(date('Y-m-d H:i:s'))) { |
|
return false; |
|
} |
|
return true; |
|
} |
|
} |