refactor: refs #7567 Fix and improvement #2699

Merged
guillermo merged 8 commits from 7567-movingCleanFix into dev 2024-08-23 07:13:36 +00:00
3 changed files with 48 additions and 43 deletions
Showing only changes of commit 4757ce11a3 - Show all commits

View File

@ -5,9 +5,5 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `srt`.`moving_clean`
ON COMPLETION PRESERVE ON COMPLETION PRESERVE
ENABLE ENABLE
COMMENT 'Llama a srt.moving_clean para que elimine y notifique de registr' COMMENT 'Llama a srt.moving_clean para que elimine y notifique de registr'
DO BEGIN DO CALL srt.moving_clean()$$
CALL srt.moving_clean();
END$$
DELIMITER ; DELIMITER ;

View File

@ -3,61 +3,69 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`moving_clean`()
BEGIN BEGIN
/** /**
* Elimina movimientos por inactividad * Elimina movimientos por inactividad
*
*/ */
DECLARE vExpeditionFk INT; DECLARE vExpeditionFk INT;
DECLARE vBufferToFk INT; DECLARE vBufferToFk INT;
guillermo marked this conversation as resolved
Review

esta es gastaba en el correu, pero com l'has llevat, sobra

esta es gastaba en el correu, pero com l'has llevat, sobra
DECLARE vBufferFromFk INT; DECLARE vBufferFromFk INT;
DECLARE done BOOL DEFAULT FALSE; DECLARE vDone BOOL DEFAULT FALSE;
DECLARE vSorter CURSOR FOR
DECLARE cur CURSOR FOR
SELECT m.expeditionFk, m.bufferToFk, m.bufferFromFk SELECT m.expeditionFk, m.bufferToFk, m.bufferFromFk
FROM srt.moving m FROM moving m
JOIN srt.config c JOIN (
JOIN (SELECT bufferFk, SUM(isActive) hasBox SELECT bufferFk, SUM(isActive) hasBox
FROM srt.photocell FROM photocell
GROUP BY bufferFk) sub ON sub.bufferFk = m.bufferFromFk GROUP BY bufferFk
WHERE m.created < TIMESTAMPADD(MINUTE, - c.movingMaxLife , util.VN_NOW()) ) sub ON sub.bufferFk = m.bufferFromFk
WHERE m.created < (util.VN_NOW() - INTERVAL (SELECT movingMaxLife FROM config) MINUTE)
AND NOT sub.hasBox; AND NOT sub.hasBox;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
OPEN cur; DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
bucle: LOOP OPEN vSorter;
l: LOOP
SET vDone = FALSE;
FETCH vSorter INTO vExpeditionFk, vBufferToFk, vBufferFromFk;
FETCH cur INTO vExpeditionFk, vBufferToFk, vBufferFromFk; IF vDone THEN
LEAVE l;
IF done THEN
LEAVE bucle;
END IF; END IF;
DELETE FROM srt.moving START TRANSACTION;
SELECT id
FROM moving
WHERE expeditionFk = vExpeditionFk
FOR UPDATE;
DELETE FROM moving
WHERE expeditionFk = vExpeditionFk; WHERE expeditionFk = vExpeditionFk;
UPDATE srt.expedition e SELECT id
JOIN srt.expeditionState es ON es.description = 'OUT' FROM expedition
SET WHERE id = vExpeditionFk
bufferFk = NULL, OR (bufferFk = vBufferFromFk AND `position` > 0)
FOR UPDATE;
UPDATE expedition
SET bufferFk = NULL,
`position` = NULL, `position` = NULL,
stateFk = es.id stateFk = (SELECT id FROM expeditionState WHERE `description` = 'OUT')
WHERE e.id = vExpeditionFk; WHERE id = vExpeditionFk;
UPDATE srt.expedition e UPDATE expedition
SET e.`position` = e.`position` - 1 SET `position` = `position` - 1
WHERE e.bufferFk = vBufferFromFk WHERE bufferFk = vBufferFromFk
AND e.`position` > 0; AND `position` > 0;
CALL vn.mail_insert( COMMIT;
'pako@verdnatura.es, carles@verdnatura.es',
NULL,
CONCAT('Moving_clean. Expedition: ', vExpeditionFk, ' estaba parada'),
CONCAT('Expedition: ', vExpeditionFk,' vBufferToFk: ', vBufferToFk)
);
END LOOP bucle;
CLOSE cur;
END LOOP l;
CLOSE vSorter;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -0,0 +1 @@
ALTER TABLE srt.moving DROP INDEX moving_fk1_idx;