refs #5858 perf: update db/changes
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
5b6112720f
commit
a31b689ae2
|
@ -1,60 +1,107 @@
|
||||||
DROP PROCEDURE IF EXISTS vn.zoneIncluded_checkCollisions;
|
DROP PROCEDURE IF EXISTS vn.zoneIncluded_checkCollisions;
|
||||||
|
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
$$
|
|
||||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneIncluded_checkCollisions`()
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneIncluded_checkCollisions`()
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE zic_id, zic_zone, zic_geoFk, zic_action, zic_zoneFk, zic_userFk INT;
|
/**
|
||||||
DECLARE zic2_geoFk, zic2_zoneFk INT;
|
* Calcula si para un mismo codigo postal y dia
|
||||||
DECLARE z_name VARCHAR(255);
|
* hay mas de una zona configurada y manda correo
|
||||||
DECLARE g_name VARCHAR(255);
|
*
|
||||||
DECLARE vDone boolean;
|
*/
|
||||||
|
DECLARE vGeoFk INT DEFAULT NULL;
|
||||||
|
DECLARE vZoneFk INT;
|
||||||
|
DECLARE vIsDone INT DEFAULT FALSE;
|
||||||
|
DECLARE vTableCollisions TEXT;
|
||||||
|
DECLARE json_data JSON;
|
||||||
|
DECLARE cur1 CURSOR FOR SELECT zoneFk from tmp.zoneOption;
|
||||||
|
|
||||||
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE;
|
||||||
|
|
||||||
DECLARE cur CURSOR FOR
|
DROP TEMPORARY TABLE IF EXISTS tmp.zone;
|
||||||
SELECT zic.id, z.name , zg.name ,zic.zoneFK, zic.geoFk ,zic.`action` , zic.userFK
|
CREATE TEMPORARY TABLE tmp.zone
|
||||||
FROM vn.zoneIncludedCheck zic, vn.`zone` z, vn.zoneGeo zg
|
SELECT z.id
|
||||||
WHERE zic.zoneFK =z.id AND zic.geoFK = zg.id and zic.action ='insert';
|
FROM zone z
|
||||||
|
JOIN agencyMode am ON am.id = z.agencyModeFk
|
||||||
|
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
||||||
|
WHERE dm.code IN ('AGENCY','DELIVERY');
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
CALL zone_getOptionsForShipment(util.VN_CURDATE(),FALSE);
|
||||||
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;
|
|
||||||
-- 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;
|
|
||||||
|
|
||||||
BLOCK2: BEGIN
|
DROP TEMPORARY TABLE IF EXISTS tmp.zoneNodes;
|
||||||
DECLARE vDone2 boolean;
|
CREATE TEMPORARY TABLE tmp.zoneNodes (
|
||||||
DECLARE cur2 CURSOR FOR
|
geoFk INT,
|
||||||
SELECT zi.zoneFk,zi.geoFk
|
name VARCHAR(100),
|
||||||
FROM vn.zoneIncluded zi, vn.zone z
|
parentFk INT,
|
||||||
where z.id = zi.zoneFk and zi.zoneFk=zic_zoneFk and zi.geoFk=zic_geoFk and zi.isIncluded = 1;
|
sons INT,
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone2 = TRUE;
|
isChecked BOOL DEFAULT 0,
|
||||||
SET vDone2 := FALSE;
|
zoneFk INT,
|
||||||
OPEN cur2;
|
PRIMARY KEY zoneFkk (zoneFk, geoFk),
|
||||||
LOOP2: LOOP
|
INDEX(geoFk))
|
||||||
FETCH cur2 INTO zic2_zoneFk, zic2_geoFk ;
|
ENGINE = MyISAM;
|
||||||
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',
|
OPEN cur1;
|
||||||
JSON_OBJECT('zoneSelected', z_name, 'geoSelected', g_name),
|
cur1Loop: LOOP
|
||||||
account.myUser_getId()
|
SET vIsDone = FALSE;
|
||||||
);
|
FETCH cur1 INTO vZoneFk;
|
||||||
END LOOP LOOP2;
|
IF vIsDone THEN
|
||||||
END BLOCK2;
|
LEAVE cur1Loop;
|
||||||
END LOOP LOOP1;
|
END IF;
|
||||||
END
|
|
||||||
$$
|
CALL zone_getLeaves(vZoneFk, NULL, NULL, TRUE);
|
||||||
|
|
||||||
|
myLoop: LOOP
|
||||||
|
SET vGeoFk = NULL;
|
||||||
|
SELECT geoFk INTO vGeoFk
|
||||||
|
FROM tmp.zoneNodes zn
|
||||||
|
WHERE NOT isChecked
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
IF vGeoFk IS NULL THEN
|
||||||
|
LEAVE myLoop;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
CALL zone_getLeaves(vZoneFk, vGeoFk, NULL, TRUE);
|
||||||
|
UPDATE tmp.zoneNodes
|
||||||
|
SET isChecked = TRUE
|
||||||
|
WHERE geoFk = vGeoFk;
|
||||||
|
END LOOP;
|
||||||
|
|
||||||
|
END LOOP;
|
||||||
|
CLOSE cur1;
|
||||||
|
DELETE FROM tmp.zoneNodes
|
||||||
|
WHERE sons > 0;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS geoCollision;
|
||||||
|
CREATE TEMPORARY TABLE geoCollision
|
||||||
|
SELECT z.agencyModeFk, zn.geoFk, zw.warehouseFk
|
||||||
|
FROM tmp.zoneNodes zn
|
||||||
|
JOIN zone z ON z.id = zn.zoneFk
|
||||||
|
JOIN zoneWarehouse zw ON z.id = zw.zoneFk
|
||||||
|
GROUP BY z.agencyModeFk, zn.geoFk, zw.warehouseFk
|
||||||
|
HAVING count(*) > 1;
|
||||||
|
|
||||||
|
SELECT JSON_ARRAYAGG(
|
||||||
|
JSON_OBJECT(
|
||||||
|
'zoneFk', zoneFk,
|
||||||
|
'zn', JSON_OBJECT('name', zn.name),
|
||||||
|
'z', JSON_OBJECT('name', z.name,'price', z.price),
|
||||||
|
'w', JSON_OBJECT('name', w.name)
|
||||||
|
)
|
||||||
|
) FROM tmp.zoneNodes zn
|
||||||
|
JOIN zone z ON z.id = zn.zoneFk
|
||||||
|
JOIN geoCollision gc ON gc.agencyModeFk = z.agencyModeFk AND zn.geoFk = gc.geoFk
|
||||||
|
JOIN warehouse w ON w.id = gc.warehouseFk
|
||||||
|
INTO json_data;
|
||||||
|
|
||||||
|
SELECT util.notification_send(
|
||||||
|
'zone-included',
|
||||||
|
JSON_OBJECT('zoneCollisions',json_data),
|
||||||
|
account.myUser_getId()
|
||||||
|
);
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE
|
||||||
|
geoCollision,
|
||||||
|
tmp.zone,
|
||||||
|
tmp.zoneNodes;
|
||||||
|
END ;;
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
INSERT INTO util.notification (name,description)
|
INSERT INTO util.notification (id, name,description)
|
||||||
VALUES ('zone-included','An email to notify zoneCollisions');
|
VALUES (
|
||||||
|
(SELECT MAX(id)+1 from util.notification n) , 'zone-included','An email to notify zoneCollisions');
|
||||||
|
|
||||||
INSERT INTO util.notificationSubscription (notificationFk,userFk)
|
INSERT INTO util.notificationSubscription (notificationFk,userFk)
|
||||||
SELECT id, account.myUser_getId() FROM util.notification WHERE name= "zone-included";
|
SELECT id, account.myUser_getId() FROM util.notification WHERE name= "zone-included";
|
||||||
|
|
Loading…
Reference in New Issue