Skip to content

Commit 6967bac

Browse files
committed
2.0.0-Balance release
1 parent 6c5babd commit 6967bac

4 files changed

+66
-32
lines changed

inc/TicketHookHandler.class.php

+62-28
Original file line numberDiff line numberDiff line change
@@ -63,41 +63,75 @@ public function getGroupsUsersByCategory($categoryId) {
6363

6464
protected function assignTicket(CommonDBTM $item) {
6565
$itilcategoriesId = $this->getTicketCategory($item);
66-
if (($lastAssignmentIndex = $this->getLastAssignmentIndex($item)) === false) {
67-
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - nothing to to (category is disabled or not configured; getLastAssignmentIndex: ' . $lastAssignmentIndex);
68-
return;
69-
}
70-
$categoryGroupMembers = $this->getGroupsUsersByCategory($this->getTicketCategory($item));
71-
if (count($categoryGroupMembers) === 0) {
72-
/**
73-
* category w/o group, or group w/o users
74-
*/
75-
return;
76-
}
77-
$newAssignmentIndex = isset($lastAssignmentIndex) ? $lastAssignmentIndex + 1 : 0;
78-
/**
79-
* round robin
80-
*/
81-
if ($newAssignmentIndex > (count($categoryGroupMembers) - 1)) {
82-
$newAssignmentIndex = $newAssignmentIndex % count($categoryGroupMembers);
66+
67+
if ($this->rrAssignmentsEntity->getOptionAutoAssignMode() === 0) {
68+
// Modo balanceamento ativo
69+
$groupId = $this->rrAssignmentsEntity->getGroupByItilCategory($itilcategoriesId);
70+
71+
if ($groupId === false) {
72+
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - Grupo não encontrado para a categoria: ' . $itilcategoriesId);
73+
return;
74+
}
75+
76+
$sql = <<<EOT
77+
SELECT tu.users_id, COUNT(t.id) AS active_tickets
78+
FROM glpi_tickets_users tu
79+
JOIN glpi_tickets t ON tu.tickets_id = t.id
80+
JOIN glpi_groups_users gu ON tu.users_id = gu.users_id
81+
JOIN glpi_groups_tickets gt ON t.id = gt.tickets_id
82+
WHERE tu.type = 2
83+
AND t.status NOT IN (5, 6)
84+
AND t.is_deleted = 0
85+
AND gu.groups_id = 15
86+
AND gt.groups_id = 15
87+
AND gt.type = 2 -- Adicionando a verificação para `type = 2`
88+
GROUP BY tu.users_id
89+
ORDER BY active_tickets ASC, tu.users_id ASC
90+
LIMIT 10;
91+
EOT;
92+
$resultCollection = $this->DB->queryOrDie($sql, $this->DB->error());
93+
$resultArray = iterator_to_array($resultCollection);
94+
95+
if (count($resultArray) === 0) {
96+
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - Nenhum técnico disponível no grupo: ' . $groupId);
97+
return;
98+
}
99+
100+
$userId = $resultArray[0]['users_id'];
101+
} else {
102+
// Modo rodízio
103+
if (($lastAssignmentIndex = $this->getLastAssignmentIndex($item)) === false) {
104+
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - Nada a fazer (categoria desativada ou não configurada; índice: ' . $lastAssignmentIndex . ')');
105+
return;
106+
}
107+
108+
$categoryGroupMembers = $this->getGroupsUsersByCategory($this->getTicketCategory($item));
109+
if (count($categoryGroupMembers) === 0) {
110+
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - Categoria sem grupo ou grupo sem usuários');
111+
return;
112+
}
113+
114+
$newAssignmentIndex = isset($lastAssignmentIndex) ? $lastAssignmentIndex + 1 : 0;
115+
83116
if ($newAssignmentIndex > (count($categoryGroupMembers) - 1)) {
84-
$newAssignmentIndex = 0;
117+
$newAssignmentIndex = $newAssignmentIndex % count($categoryGroupMembers);
118+
}
119+
120+
if ($this->rrAssignmentsEntity->getOptionAutoAssignType() === 1) {
121+
$this->rrAssignmentsEntity->updateLastAssignmentIndexCategoria($itilcategoriesId, $newAssignmentIndex);
122+
} else {
123+
$this->rrAssignmentsEntity->updateLastAssignmentIndexGrupo($itilcategoriesId, $newAssignmentIndex);
85124
}
125+
126+
$userId = $categoryGroupMembers[$newAssignmentIndex]['UserId'];
86127
}
87-
if ($this->rrAssignmentsEntity->getOptionAutoAssignType() === 1) {
88-
$this->rrAssignmentsEntity->updateLastAssignmentIndexCategoria($itilcategoriesId, $newAssignmentIndex);
89-
} else {
90-
$this->rrAssignmentsEntity->updateLastAssignmentIndexGrupo($itilcategoriesId, $newAssignmentIndex);
91-
}
92-
93-
/**
94-
* set the assignment
95-
*/
128+
129+
// Atribuir o ticket ao técnico selecionado
96130
$ticketId = $this->getTicketId($item);
97-
$userId = $categoryGroupMembers[$newAssignmentIndex]['UserId'];
98131
$this->setAssignment($ticketId, $userId, $itilcategoriesId);
99132
return $userId;
100133
}
134+
101135

102136
protected function getLastAssignmentIndex(CommonDBTM $item) {
103137
$itilcategoriesId = $this->getTicketCategory($item);

inc/config.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class SmartAssignConfigClass {
55
public static $PLUGIN_SMARTASSIGN_ENV = 'desenvolvimento';
66
public static $PLUGIN_SMARTASSIGN_NAME = 'Smart Assign';
77
public static $PLUGIN_SMARTASSIGN_CODE = 'smartassign';
8-
public static $PLUGIN_SMARTASSIGN_VERSION = '1.2.1';
8+
public static $PLUGIN_SMARTASSIGN_VERSION = '2.0.0';
99
public static $PLUGIN_SMARTASSIGN_AUTHOR = 'Richard Loureiro';
1010
public static $PLUGIN_SMARTASSIGN_LICENSE = 'GPLv3';
1111
public static $PLUGIN_SMARTASSIGN_HOME_PAGE = 'https://www.linkedin.com/in/richard-ti/';

inc/config.form.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function displayContent() {
7777
echo "</th></tr>";
7878

7979
echo "<tr><th colspan='4'>";
80-
echo "Atribuição do tecnico por Rodizio ou Balanceamento? (EM CONSTRUÇÃO) &nbsp;&nbsp;";
80+
echo "Atribuição do tecnico por Rodizio ou Balanceamento? &nbsp;&nbsp;";
8181
echo "<input type='radio' name='auto_assign_mode' value='1'" . ($auto_assign_mode ? " checked='checked'" : "") . "> Rodizio&nbsp;&nbsp;";
8282
echo "<input type='radio' name='auto_assign_mode' value='0'" . (!$auto_assign_mode ? " checked='checked'" : "") . "> Balanceamento";
8383
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>";

smartassign.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
</authors>
3030
<versions>
3131
<version>
32-
<num>1.2.1</num>
32+
<num>2.0.0</num>
3333
<compatibility>9.5, ~10.0</compatibility>
34-
<download_url>https://github.com/RPGMais/smartassign/releases/download/v1.2.1-beta/smartassign-v1.2.1.tar.gz</download_url>
34+
<download_url>https://github.com/RPGMais/smartassign/releases/download/v2.0.0-beta/smartassign-v2.0.0.tar.gz</download_url>
3535
</version>
3636
</versions>
3737
<langs>

0 commit comments

Comments
 (0)