Skip to content

Commit

Permalink
2.0.0-Balance release
Browse files Browse the repository at this point in the history
  • Loading branch information
RPGMais committed Jan 7, 2025
1 parent 6c5babd commit 6967bac
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 32 deletions.
90 changes: 62 additions & 28 deletions inc/TicketHookHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<<EOT
SELECT tu.users_id, COUNT(t.id) AS active_tickets
FROM glpi_tickets_users tu
JOIN glpi_tickets t ON tu.tickets_id = t.id
JOIN glpi_groups_users gu ON tu.users_id = gu.users_id
JOIN glpi_groups_tickets gt ON t.id = gt.tickets_id
WHERE tu.type = 2
AND t.status NOT IN (5, 6)
AND t.is_deleted = 0
AND gu.groups_id = 15
AND gt.groups_id = 15
AND gt.type = 2 -- Adicionando a verificação para `type = 2`
GROUP BY tu.users_id
ORDER BY active_tickets ASC, tu.users_id ASC
LIMIT 10;
EOT;
$resultCollection = $this->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);
Expand Down
2 changes: 1 addition & 1 deletion inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/';
Expand Down
2 changes: 1 addition & 1 deletion inc/config.form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function displayContent() {
echo "</th></tr>";

echo "<tr><th colspan='4'>";
echo "Atribuição do tecnico por Rodizio ou Balanceamento? (EM CONSTRUÇÃO) &nbsp;&nbsp;";
echo "Atribuição do tecnico por Rodizio ou Balanceamento? &nbsp;&nbsp;";
echo "<input type='radio' name='auto_assign_mode' value='1'" . ($auto_assign_mode ? " checked='checked'" : "") . "> Rodizio&nbsp;&nbsp;";
echo "<input type='radio' name='auto_assign_mode' value='0'" . (!$auto_assign_mode ? " checked='checked'" : "") . "> Balanceamento";
echo "<br><span style='font-size: 12px; color: #555;'>Quando Rodizio, a divisão é feita igualitariamente. Quando Balanceamento, a divisão é feita com base no tecnico com menos chamados abertos na fila.</span>";
Expand Down
4 changes: 2 additions & 2 deletions smartassign.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
</authors>
<versions>
<version>
<num>1.2.1</num>
<num>2.0.0</num>
<compatibility>9.5, ~10.0</compatibility>
<download_url>https://github.com/RPGMais/smartassign/releases/download/v1.2.1-beta/smartassign-v1.2.1.tar.gz</download_url>
<download_url>https://github.com/RPGMais/smartassign/releases/download/v2.0.0-beta/smartassign-v2.0.0.tar.gz</download_url>
</version>
</versions>
<langs>
Expand Down

0 comments on commit 6967bac

Please sign in to comment.