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 $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`queueMember_updateQueue`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`queueMember_updateQueue`(
vBusinessFk INT vBusinessFk INT
) )
BEGIN 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 vNewQueue VARCHAR(10);
DECLARE vExtension VARCHAR(10); DECLARE vExtension VARCHAR(10);
DECLARE vPrevQueue 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 FROM business b
JOIN department d ON d.id = b.departmentFk 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 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
DELETE FROM pbx.queueMember WHERE extension = vExtension COLLATE utf8_general_ci;
WHERE extension = vExtension COLLATE utf8_general_ci;
ELSE INSERT IGNORE INTO pbx.queueMember (queue, extension)
IF vPrevQueue IS NULL THEN VALUES (vNewQueue, vExtension);
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;
END$$ END$$
DELIMITER ; DELIMITER ;