Merge pull request 'feat: refs #7681 Optimization and refactor' (!2707) from 7681-routeUpdateM3 into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2707
Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
Guillermo Bonet 2024-07-19 11:12:21 +00:00
commit b72923f160
1 changed files with 13 additions and 9 deletions

View File

@ -1,14 +1,18 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_updateM3`(vRoute INT)
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_updateM3`(
vSelf INT
)
BEGIN
/**
* Actualiza el volumen de la ruta.
*
* @param vSelf Id ruta
*/
DECLARE vVolume DECIMAL(10,1)
DEFAULT (SELECT SUM(volume) FROM saleVolume WHERE routeFk = vSelf);
UPDATE vn.route r
LEFT JOIN (
SELECT routeFk, SUM(volume) AS m3
FROM saleVolume
WHERE routeFk = vRoute
) v ON v.routeFk = r.id
SET r.m3 = IFNULL(v.m3,0)
WHERE r.id =vRoute;
UPDATE `route`
SET m3 = IFNULL(vVolume, 0)
WHERE id = vSelf;
END$$
DELIMITER ;