2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`manaSpellersRequery`(vWorkerFk INTEGER)
|
2024-01-15 11:31:03 +00:00
|
|
|
`whole_proc`:
|
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Guarda en workerMana el mana consumido por un trabajador
|
|
|
|
*
|
|
|
|
* @param vWorkerFk Id Trabajador
|
|
|
|
*/
|
|
|
|
DECLARE vWorkerIsExcluded BOOLEAN;
|
|
|
|
|
|
|
|
SELECT COUNT(*) INTO vWorkerIsExcluded
|
|
|
|
FROM workerManaExcluded
|
|
|
|
WHERE workerFk = vWorkerFk;
|
|
|
|
|
|
|
|
IF vWorkerIsExcluded THEN
|
|
|
|
LEAVE whole_proc;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.client
|
|
|
|
SELECT id
|
|
|
|
FROM client
|
|
|
|
WHERE salesPersonFk = vWorkerFk;
|
|
|
|
|
|
|
|
CALL client_getMana();
|
|
|
|
|
|
|
|
INSERT INTO workerMana (workerFk, amount)
|
|
|
|
SELECT vWorkerFk, sum(mana)
|
|
|
|
FROM tmp.clientMana
|
|
|
|
ON DUPLICATE KEY UPDATE amount = VALUES(amount);
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE
|
|
|
|
tmp.client,
|
|
|
|
tmp.clientMana;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|