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`.`routeGuessPriority`(IN vRuta INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/* Usa los valores del ultimo año para adivinar el orden de los tickets en la ruta
|
|
|
|
* vRuta id ruta
|
|
|
|
*/
|
|
|
|
|
|
|
|
UPDATE ticket mt
|
|
|
|
JOIN (
|
|
|
|
SELECT tt.addressFk, ROUND(IFNULL(AVG(t.priority),0),0) AS priority
|
|
|
|
FROM ticket t
|
|
|
|
JOIN ticket tt ON tt.addressFk = t.addressFk
|
|
|
|
WHERE t.shipped > TIMESTAMPADD(YEAR,-1,util.VN_CURDATE())
|
|
|
|
AND tt.routeFk = vRuta
|
|
|
|
GROUP BY addressFk
|
|
|
|
) sub ON sub.addressFk = mt.addressFk
|
|
|
|
SET mt.priority = sub.priority
|
|
|
|
WHERE mt.routeFk = vRuta;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|