refactor: refs #7207 simplify code
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2024-10-03 16:50:31 +02:00
parent 23d2d2b1ea
commit 3638e9abb6
1 changed files with 15 additions and 21 deletions

View File

@ -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.
* Elimina la entrada de la cola anterior y luego inserta la nueva para un trabajador.
*
* @param vBusinessFk business id
* @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
LEFT JOIN pbx.queueMember qm ON qm.extension = s.extension
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)
INSERT IGNORE 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;
END$$
DELIMITER ;