From 6967bac6957742c29434a80374907e8ca1d89eb9 Mon Sep 17 00:00:00 2001 From: RPGMais Date: Tue, 7 Jan 2025 15:38:44 -0300 Subject: [PATCH] 2.0.0-Balance release --- inc/TicketHookHandler.class.php | 90 +++++++++++++++++++++++---------- inc/config.class.php | 2 +- inc/config.form.class.php | 2 +- smartassign.xml | 4 +- 4 files changed, 66 insertions(+), 32 deletions(-) diff --git a/inc/TicketHookHandler.class.php b/inc/TicketHookHandler.class.php index e6d6003..871eef0 100644 --- a/inc/TicketHookHandler.class.php +++ b/inc/TicketHookHandler.class.php @@ -63,41 +63,75 @@ public function getGroupsUsersByCategory($categoryId) { protected function assignTicket(CommonDBTM $item) { $itilcategoriesId = $this->getTicketCategory($item); - if (($lastAssignmentIndex = $this->getLastAssignmentIndex($item)) === false) { - PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - nothing to to (category is disabled or not configured; getLastAssignmentIndex: ' . $lastAssignmentIndex); - return; - } - $categoryGroupMembers = $this->getGroupsUsersByCategory($this->getTicketCategory($item)); - if (count($categoryGroupMembers) === 0) { - /** - * category w/o group, or group w/o users - */ - return; - } - $newAssignmentIndex = isset($lastAssignmentIndex) ? $lastAssignmentIndex + 1 : 0; - /** - * round robin - */ - if ($newAssignmentIndex > (count($categoryGroupMembers) - 1)) { - $newAssignmentIndex = $newAssignmentIndex % count($categoryGroupMembers); + + if ($this->rrAssignmentsEntity->getOptionAutoAssignMode() === 0) { + // Modo balanceamento ativo + $groupId = $this->rrAssignmentsEntity->getGroupByItilCategory($itilcategoriesId); + + if ($groupId === false) { + PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - Grupo não encontrado para a categoria: ' . $itilcategoriesId); + return; + } + + $sql = <<DB->queryOrDie($sql, $this->DB->error()); + $resultArray = iterator_to_array($resultCollection); + + if (count($resultArray) === 0) { + PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - Nenhum técnico disponível no grupo: ' . $groupId); + return; + } + + $userId = $resultArray[0]['users_id']; + } else { + // Modo rodízio + if (($lastAssignmentIndex = $this->getLastAssignmentIndex($item)) === false) { + PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - Nada a fazer (categoria desativada ou não configurada; índice: ' . $lastAssignmentIndex . ')'); + return; + } + + $categoryGroupMembers = $this->getGroupsUsersByCategory($this->getTicketCategory($item)); + if (count($categoryGroupMembers) === 0) { + PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - Categoria sem grupo ou grupo sem usuários'); + return; + } + + $newAssignmentIndex = isset($lastAssignmentIndex) ? $lastAssignmentIndex + 1 : 0; + if ($newAssignmentIndex > (count($categoryGroupMembers) - 1)) { - $newAssignmentIndex = 0; + $newAssignmentIndex = $newAssignmentIndex % count($categoryGroupMembers); + } + + if ($this->rrAssignmentsEntity->getOptionAutoAssignType() === 1) { + $this->rrAssignmentsEntity->updateLastAssignmentIndexCategoria($itilcategoriesId, $newAssignmentIndex); + } else { + $this->rrAssignmentsEntity->updateLastAssignmentIndexGrupo($itilcategoriesId, $newAssignmentIndex); } + + $userId = $categoryGroupMembers[$newAssignmentIndex]['UserId']; } - if ($this->rrAssignmentsEntity->getOptionAutoAssignType() === 1) { - $this->rrAssignmentsEntity->updateLastAssignmentIndexCategoria($itilcategoriesId, $newAssignmentIndex); - } else { - $this->rrAssignmentsEntity->updateLastAssignmentIndexGrupo($itilcategoriesId, $newAssignmentIndex); - } - - /** - * set the assignment - */ + + // Atribuir o ticket ao técnico selecionado $ticketId = $this->getTicketId($item); - $userId = $categoryGroupMembers[$newAssignmentIndex]['UserId']; $this->setAssignment($ticketId, $userId, $itilcategoriesId); return $userId; } + protected function getLastAssignmentIndex(CommonDBTM $item) { $itilcategoriesId = $this->getTicketCategory($item); diff --git a/inc/config.class.php b/inc/config.class.php index c2f46b8..8413ea0 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -5,7 +5,7 @@ class SmartAssignConfigClass { public static $PLUGIN_SMARTASSIGN_ENV = 'desenvolvimento'; public static $PLUGIN_SMARTASSIGN_NAME = 'Smart Assign'; public static $PLUGIN_SMARTASSIGN_CODE = 'smartassign'; - public static $PLUGIN_SMARTASSIGN_VERSION = '1.2.1'; + public static $PLUGIN_SMARTASSIGN_VERSION = '2.0.0'; public static $PLUGIN_SMARTASSIGN_AUTHOR = 'Richard Loureiro'; public static $PLUGIN_SMARTASSIGN_LICENSE = 'GPLv3'; public static $PLUGIN_SMARTASSIGN_HOME_PAGE = 'https://www.linkedin.com/in/richard-ti/'; diff --git a/inc/config.form.class.php b/inc/config.form.class.php index 2eef6b6..f8c9686 100644 --- a/inc/config.form.class.php +++ b/inc/config.form.class.php @@ -77,7 +77,7 @@ public function displayContent() { echo ""; echo ""; - echo "Atribuição do tecnico por Rodizio ou Balanceamento? (EM CONSTRUÇÃO)   "; + echo "Atribuição do tecnico por Rodizio ou Balanceamento?   "; echo " Rodizio  "; echo " Balanceamento"; echo "
Quando Rodizio, a divisão é feita igualitariamente. Quando Balanceamento, a divisão é feita com base no tecnico com menos chamados abertos na fila."; diff --git a/smartassign.xml b/smartassign.xml index 341f3e3..47c0125 100644 --- a/smartassign.xml +++ b/smartassign.xml @@ -29,9 +29,9 @@ - 1.2.1 + 2.0.0 9.5, ~10.0 - https://github.com/RPGMais/smartassign/releases/download/v1.2.1-beta/smartassign-v1.2.1.tar.gz + https://github.com/RPGMais/smartassign/releases/download/v2.0.0-beta/smartassign-v2.0.0.tar.gz