8093-devToTest_2442_3 #3100
|
@ -0,0 +1,32 @@
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
DECLARE vNewQueue VARCHAR(10);
|
||||||
|
DECLARE vExtension VARCHAR(10);
|
||||||
|
DECLARE vPrevQueue VARCHAR(10);
|
||||||
|
|
||||||
|
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) VALUES (vNewQueue, vExtension);
|
||||||
|
ELSE
|
||||||
|
UPDATE pbx.queueMember SET queue = vNewQueue WHERE extension = vExtension COLLATE utf8_general_ci;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -21,6 +21,8 @@ BEGIN
|
||||||
SET businessFk = vNewBusinessFk
|
SET businessFk = vNewBusinessFk
|
||||||
WHERE id = vSelf;
|
WHERE id = vSelf;
|
||||||
|
|
||||||
|
CALL queueMember_updateQueue(vNewBusinessFk);
|
||||||
|
|
||||||
IF vOldBusinessFk IS NULL THEN
|
IF vOldBusinessFk IS NULL THEN
|
||||||
CALL account.account_enable(vSelf);
|
CALL account.account_enable(vSelf);
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`business_afterUpdate`
|
||||||
AFTER UPDATE ON `business`
|
AFTER UPDATE ON `business`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE vnIsActive INT;
|
DECLARE vIsActive BOOL;
|
||||||
DECLARE vnExtension VARCHAR(10);
|
DECLARE vExtension VARCHAR(10);
|
||||||
DECLARE vnQueue VARCHAR(10);
|
|
||||||
|
|
||||||
CALL worker_updateBusiness(NEW.workerFk);
|
CALL worker_updateBusiness(NEW.workerFk);
|
||||||
|
|
||||||
|
@ -13,13 +12,11 @@ BEGIN
|
||||||
CALL worker_updateBusiness(OLD.workerFk);
|
CALL worker_updateBusiness(OLD.workerFk);
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
SELECT COUNT(*) INTO vnIsActive FROM vn.worker WHERE businessFk = NEW.id;
|
IF NOT (OLD.departmentFk <=> NEW.departmentFk) THEN
|
||||||
|
SELECT COUNT(*) INTO vIsActive FROM worker WHERE businessFk = NEW.id;
|
||||||
IF(vnIsActive) THEN
|
IF vIsActive THEN
|
||||||
SELECT extension INTO vnExtension FROM pbx.sip WHERE user_id = NEW.workerFk COLLATE utf8mb3_general_ci;
|
CALL queueMember_updateQueue(NEW.id);
|
||||||
SELECT pbxQueue INTO vnQueue FROM vn.department WHERE id = NEW.departmentFk COLLATE utf8mb3_general_ci;
|
END IF;
|
||||||
|
|
||||||
UPDATE pbx.queueMember SET queue = vnQueue WHERE extension = vnExtension;
|
|
||||||
END IF;
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue