From 3638e9abb6f125fb04c7478083ad5d0a2daaa4a7 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 3 Oct 2024 16:50:31 +0200 Subject: [PATCH] refactor: refs #7207 simplify code --- .../vn/procedures/queueMember_updateQueue.sql | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/db/routines/vn/procedures/queueMember_updateQueue.sql b/db/routines/vn/procedures/queueMember_updateQueue.sql index d6f2a5d1e..b330eed66 100644 --- a/db/routines/vn/procedures/queueMember_updateQueue.sql +++ b/db/routines/vn/procedures/queueMember_updateQueue.sql @@ -1,36 +1,30 @@ DELIMITER $$ + CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`queueMember_updateQueue`( vBusinessFk INT ) BEGIN -/** -* Replace the queue of a worker with the queue of the new department. -* -* @param vBusinessFk business id -*/ + /** + * Elimina la entrada de la cola anterior y luego inserta la nueva para un trabajador. + * + * @param vBusinessFk ID del negocio + */ DECLARE vNewQueue VARCHAR(10); DECLARE vExtension VARCHAR(10); DECLARE vPrevQueue VARCHAR(10); - SELECT d.pbxQueue, s.extension, qm.queue INTO vNewQueue, vExtension, vPrevQueue + SELECT d.pbxQueue, s.extension, qm.queue + INTO vNewQueue, vExtension, vPrevQueue FROM business b JOIN department d ON d.id = b.departmentFk - JOIN pbx.sip s ON s.user_id = b.workerFk + JOIN pbx.sip s ON s.user_id = b.workerFk LEFT JOIN pbx.queueMember qm ON qm.extension = s.extension - WHERE b.id = vBusinessFk; + WHERE b.id = vBusinessFk; - IF vNewQueue IS NULL THEN - DELETE FROM pbx.queueMember - WHERE extension = vExtension COLLATE utf8_general_ci; - ELSE - IF vPrevQueue IS NULL THEN - INSERT INTO pbx.queueMember (queue, extension) - VALUES (vNewQueue, vExtension); - ELSE - UPDATE pbx.queueMember - SET queue = vNewQueue - WHERE extension = vExtension COLLATE utf8_general_ci; - END IF; - END IF; + DELETE FROM pbx.queueMember + WHERE extension = vExtension COLLATE utf8_general_ci; + + INSERT IGNORE INTO pbx.queueMember (queue, extension) + VALUES (vNewQueue, vExtension); END$$ DELIMITER ; \ No newline at end of file