From c6a3004d1202d4065963126eb654ae95b0e8eba5 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 24 Sep 2024 10:15:01 +0200 Subject: [PATCH] feat: refs #7207 allocate new queue on dept change --- db/dump/fixtures.before.sql | 15 +++++++++------ db/routines/vn/triggers/business_afterUpdate.sql | 13 +++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index c01a7d584..8d1943667 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3982,12 +3982,15 @@ INSERT INTO pbx.queueMultiConfig maxLen = 0, ringInUse = 0; -INSERT IGNORE INTO pbx.queue - SET description = 'X-men', - name = '1000', - config = 1; +INSERT INTO pbx.queue (description, name, config) + VALUES ('X-men', '1000', 1), + ('Avengers', '2000', 1); INSERT IGNORE INTO pbx.queueMember - SET queue = '1000', - extension = '1010'; + SET queue = '1000', + extension = '1010'; + +UPDATE vn.department SET pbxQueue = '1000' WHERE name = "CAMARA"; +UPDATE vn.department SET pbxQueue = '2000' WHERE name = "VENTAS"; + diff --git a/db/routines/vn/triggers/business_afterUpdate.sql b/db/routines/vn/triggers/business_afterUpdate.sql index 888308b9a..255fdd9f5 100644 --- a/db/routines/vn/triggers/business_afterUpdate.sql +++ b/db/routines/vn/triggers/business_afterUpdate.sql @@ -3,10 +3,23 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`business_afterUpdate` AFTER UPDATE ON `business` FOR EACH ROW BEGIN + DECLARE vnIsActive INT; + DECLARE vnExtension VARCHAR(10); + DECLARE vnQueue VARCHAR(10); + CALL worker_updateBusiness(NEW.workerFk); IF NOT (OLD.workerFk <=> NEW.workerFk) THEN CALL worker_updateBusiness(OLD.workerFk); END IF; + + SELECT COUNT(*) INTO vnIsActive FROM vn.worker WHERE businessFk = NEW.id; + + IF(vnIsActive) THEN + SELECT extension INTO vnExtension FROM pbx.sip WHERE user_id = NEW.workerFk COLLATE utf8mb3_general_ci; + SELECT pbxQueue INTO vnQueue FROM vn.department WHERE id = NEW.departmentFk COLLATE utf8mb3_general_ci; + + UPDATE pbx.queueMember SET queue = vnQueue WHERE extension = vnExtension; + END IF; END$$ DELIMITER ;