salix/db/routines/vn/procedures/queueMember_updateQueue.sql

29 lines
755 B
MySQL
Raw Normal View History

DELIMITER $$
2024-10-03 14:50:31 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`queueMember_updateQueue`(
vBusinessFk INT
)
BEGIN
2024-10-03 14:50:31 +00:00
/**
* 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);
2024-10-04 14:48:38 +00:00
DECLARE exit handler FOR SQLEXCEPTION
SELECT d.pbxQueue, s.extension
INTO vNewQueue, vExtension
FROM business b
JOIN department d ON d.id = b.departmentFk
2024-10-03 14:50:31 +00:00
JOIN pbx.sip s ON s.user_id = b.workerFk
WHERE b.id = vBusinessFk;
DELETE FROM pbx.queueMember
WHERE extension = vExtension COLLATE utf8_general_ci;
2024-10-03 14:50:31 +00:00
INSERT IGNORE INTO pbx.queueMember (queue, extension)
VALUES (vNewQueue, vExtension);
END$$
DELIMITER ;