Merge branch 'dev' into 7758-Add_code_mandateType_accountDetailType
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
commit
754792e3b5
|
@ -1,13 +1,9 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `srt`.`moving_clean`
|
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `srt`.`moving_clean`
|
||||||
ON SCHEDULE EVERY 5 MINUTE
|
ON SCHEDULE EVERY 15 MINUTE
|
||||||
STARTS '2022-01-21 00:00:00.000'
|
STARTS '2022-01-21 00:00:00.000'
|
||||||
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 ;
|
||||||
|
|
|
@ -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 vBufferFromFk INT;
|
DECLARE vBufferFromFk INT;
|
||||||
DECLARE done BOOL DEFAULT FALSE;
|
DECLARE vStateOutFk INT
|
||||||
|
DEFAULT (SELECT id FROM expeditionState WHERE `description` = 'OUT');
|
||||||
DECLARE cur CURSOR FOR
|
DECLARE vDone BOOL;
|
||||||
SELECT m.expeditionFk, m.bufferToFk, m.bufferFromFk
|
DECLARE vSorter CURSOR FOR
|
||||||
FROM srt.moving m
|
SELECT m.expeditionFk, m.bufferFromFk
|
||||||
JOIN srt.config c
|
FROM moving m
|
||||||
JOIN (SELECT bufferFk, SUM(isActive) hasBox
|
JOIN (
|
||||||
FROM srt.photocell
|
SELECT bufferFk, SUM(isActive) hasBox
|
||||||
GROUP BY bufferFk) sub ON sub.bufferFk = m.bufferFromFk
|
FROM photocell
|
||||||
WHERE m.created < TIMESTAMPADD(MINUTE, - c.movingMaxLife , util.VN_NOW())
|
GROUP BY bufferFk
|
||||||
|
) 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, 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 = vStateOutFk
|
||||||
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(
|
|
||||||
'pako@verdnatura.es, carles@verdnatura.es',
|
|
||||||
NULL,
|
|
||||||
CONCAT('Moving_clean. Expedition: ', vExpeditionFk, ' estaba parada'),
|
|
||||||
CONCAT('Expedition: ', vExpeditionFk,' vBufferToFk: ', vBufferToFk)
|
|
||||||
);
|
|
||||||
|
|
||||||
END LOOP bucle;
|
|
||||||
|
|
||||||
CLOSE cur;
|
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
END LOOP l;
|
||||||
|
CLOSE vSorter;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE srt.moving DROP INDEX moving_fk1_idx;
|
Loading…
Reference in New Issue