refs #5858 feat: update procedure zoneIncluded_getCollisions

This commit is contained in:
Javier Segarra 2023-12-01 09:39:21 +01:00
parent c40dc134f8
commit 60fbb1d56e
8 changed files with 55 additions and 167 deletions

View File

@ -1,33 +1,60 @@
DROP PROCEDURE IF EXISTS `vn`.`zoneIncluded_checkCollisions`; DROP PROCEDURE IF EXISTS vn.zoneIncluded_checkCollisions;
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneIncluded_checkCollisions`(IN zi_zone INT, IN zi_geo INT) DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneIncluded_checkCollisions`()
BEGIN BEGIN
DECLARE done INT DEFAULT 0; DECLARE zic_id, zic_zone, zic_geoFk, zic_action, zic_zoneFk, zic_userFk INT;
DECLARE zic_id, zic_zone, zic_geo, zic_action, zic_userFk INT; DECLARE zic2_geoFk, zic2_zoneFk INT;
DECLARE z_name VARCHAR(255); DECLARE z_name VARCHAR(255);
DECLARE g_name VARCHAR(255); DECLARE g_name VARCHAR(255);
DECLARE vDone boolean;
DECLARE my_cur CURSOR FOR
SELECT zic.id, z.name , zg.name , zic.geoFk ,zic.`action` , zic.userFK FROM vn.zoneIncludedCheck zic, vn.`zone` z, vn.zoneGeo zg WHERE zic.zoneFK =z.id AND zic.geoFK = zg.id ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN my_cur; DECLARE cur CURSOR FOR
my_cur_loop: SELECT zic.id, z.name , zg.name ,zic.zoneFK, zic.geoFk ,zic.`action` , zic.userFK
LOOP FETCH my_cur INTO zic_id, z_name,g_name, zic_geo, zic_action, zic_userFk ; FROM vn.zoneIncludedCheck zic, vn.`zone` z, vn.zoneGeo zg
IF done = 1 THEN WHERE zic.zoneFK =z.id AND zic.geoFK = zg.id and zic.action ='insert';
select concat('NO REDCORDS' ) AS '** DEBUG:';
LEAVE my_cur_loop; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
SET vDone := FALSE;
OPEN cur;
LOOP1: LOOP
SET vDone := FALSE;
FETCH cur INTO zic_id, z_name, g_name, zic_zoneFk, zic_geoFk, zic_action, zic_userFk ;
IF vDone THEN
select concat('NO RECORDS LOOP 1' ) AS '** DEBUG:';
CLOSE cur;
LEAVE LOOP1;
END IF; END IF;
SELECT concat('** ', zic_id, '** ',z_name, '** ',g_name,'**',zic_geo,'** ', zic_action,'** ', zic_userFk ) AS '** DEBUG:'; -- SELECT concat('** ', zic_id, '** ',z_name, '** ',g_name,'**',zic_zoneFk,'**',zic_geoFk,'** ', zic_action,'** ', zic_userFk ) AS '** DEBUG:';
DELETE FROM vn.zoneIncludedCheck WHERE id =zic_id; DELETE FROM vn.zoneIncludedCheck WHERE id =zic_id;
BLOCK2: BEGIN
DECLARE vDone2 boolean;
DECLARE cur2 CURSOR FOR
SELECT zi.zoneFk,zi.geoFk
FROM vn.zoneIncluded zi, vn.zone z
where z.id = zi.zoneFk and zi.zoneFk=zic_zoneFk and zi.geoFk=zic_geoFk and zi.isIncluded = 1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone2 = TRUE;
SET vDone2 := FALSE;
OPEN cur2;
LOOP2: LOOP
FETCH cur2 INTO zic2_zoneFk, zic2_geoFk ;
IF vDone2 THEN
select concat('NO RECORDS LOOP 2' ) AS '** DEBUG:';
CLOSE cur2;
LEAVE LOOP2;
END IF;
SELECT concat('COLLISION DETECTED', zic2_zoneFk, zic2_geoFk ) AS '** DEBUG:';
SELECT util.notification_send('zone-included', SELECT util.notification_send('zone-included',
JSON_OBJECT('zoneSelected', z_name, 'geoSelected', g_name), JSON_OBJECT('zoneSelected', z_name, 'geoSelected', g_name),
account.myUser_getId() account.myUser_getId()
); );
END LOOP my_cur_loop; END LOOP LOOP2;
CLOSE my_cur; END BLOCK2;
END LOOP LOOP1;
END
END$$ $$
DELIMITER ; DELIMITER ;

View File

@ -1,73 +0,0 @@
DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterInsert`;
USE `vn`;
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterInsert`
AFTER INSERT ON `zoneIncluded`
FOR EACH ROW
BEGIN
INSERT INTO zoneLog
SET `action` = 'insert',
`changedModel` = 'zoneIncluded',
`changedModelId` = NEW.zoneFk,
`userFk` = account.myUser_getId();
INSERT INTO zoneIncludedCheck
SET
`action`= 'insert',
`zoneFk` = NEW.zoneFk,
`geoFk` = NEW.geoFk,
`userFk` = account.myUser_getId();
-- CALL `vn`.`zoneIncluded_checkCollisions`(NEW.zoneFk, NEW.geoFk);
END$$
DELIMITER ;
DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterUpdate`;
USE `vn`;
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterUpdate`
AFTER UPDATE ON `zoneIncluded`
FOR EACH ROW
BEGIN
INSERT INTO zoneLog
SET `action` = 'update',
`changedModel` = 'zoneIncluded',
`changedModelId` = OLD.zoneFk,
`userFk` = account.myUser_getId();
INSERT INTO zoneIncludedCheck
SET
`action`= 'update',
`zoneFk` = NEW.zoneFk,
`geoFk` = NEW.geoFk,
`userFk` = account.myUser_getId();
-- CALL `vn`.`zoneIncluded_checkCollisions`();
END$$
DELIMITER ;
DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterDelete`;
USE `vn`;
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterDelete`
AFTER DELETE ON `zoneIncluded`
FOR EACH ROW
BEGIN
INSERT INTO zoneLog
SET `action` = 'delete',
`changedModel` = 'zoneIncluded',
`changedModelId` = OLD.zoneFk,
`userFk` = account.myUser_getId();
INSERT INTO zoneIncludedCheck
SET
`action`= 'delete',
`zoneFk` = OLD.zoneFk,
`geoFk` = OLD.geoFk,
`userFk` = account.myUser_getId();
-- CALL `vn`.`zoneIncluded_checkCollisions`();
END$$
DELIMITER ;

View File

@ -1,14 +0,0 @@
CREATE TABLE `vn`.`zoneIncludedCheck` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`zoneFK` int(11) NOT NULL,
`geoFK` int(11) NOT NULL,
`userFK` int(10) unsigned NOT NULL,
`action`set('insert','update','delete') NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `user_FK` FOREIGN KEY (`userFK`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `zone_FK` FOREIGN KEY (`zoneFK`) REFERENCES `vn`.`zone` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `geo_FK` FOREIGN KEY (`geoFK`) REFERENCES `vn`.`zoneGeo` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
UNIQUE INDEX (`zoneFK`, `geoFK`, `userFK`, `action`)
)
comment 'Table to save temporarily zone changes';

View File

@ -1,5 +0,0 @@
USE vn;
CREATE EVENT zoneCollisionsCheck
ON SCHEDULE AT CURRENT_TIMESTAMP
DISABLE ON SLAVE
DO SELECT vn.zoneIncluded_checkCollisions;

View File

@ -1,33 +0,0 @@
DROP PROCEDURE IF EXISTS `vn`.`zoneIncluded_checkCollisions`;
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneIncluded_checkCollisions`()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE zic_id, zic_zone, zic_geo, zic_action, zic_userFk INT;
DECLARE z_name VARCHAR(255);
DECLARE g_name VARCHAR(255);
DECLARE my_cur CURSOR FOR
SELECT zic.id, z.name , zg.name , zic.geoFk ,zic.`action` , zic.userFK FROM vn.zoneIncludedCheck zic, vn.`zone` z, vn.zoneGeo zg WHERE zic.zoneFK =z.id AND zic.geoFK = zg.id ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN my_cur;
my_cur_loop:
LOOP FETCH my_cur INTO zic_id, z_name,g_name, zic_geo, zic_action, zic_userFk ;
IF done = 1 THEN
select concat('NO REDCORDS' ) AS '** DEBUG:';
LEAVE my_cur_loop;
END IF;
SELECT concat('** ', zic_id, '** ',z_name, '** ',g_name,'**',zic_geo,'** ', zic_action,'** ', zic_userFk ) AS '** DEBUG:';
DELETE FROM vn.zoneIncludedCheck WHERE id =zic_id;
SELECT util.notification_send('zone-included',
JSON_OBJECT('zoneSelected', z_name, 'geoSelected', g_name),
account.myUser_getId()
);
END LOOP my_cur_loop;
CLOSE my_cur;
END$$
DELIMITER ;

View File

@ -1,2 +0,0 @@
DELETE FROM bs.nightTask
WHERE `procedure` ='zone_getCollisions';

View File

@ -1 +0,0 @@
DROP PROCEDURE vn.zone_getCollisions;

View File

@ -1,11 +0,0 @@
-- Auto-generated SQL script #202311241021
INSERT INTO util.notification (name,description)
VALUES ('zone-included','An email to notify zoneCollisions');
-- Auto-generated SQL script #202311241051
INSERT INTO util.notificationSubscription (notificationFk,userFk)
SELECT id, account.myUser_getId() FROM util.notification WHERE name= "zone-included"
INSERT INTO util.notificationAcl (notificationFk,roleFk)
SELECT id, account.role FROM util.notification WHERE name= "zone-included"