refs #5858 feat: use notification system
This commit is contained in:
parent
e5b7395e5c
commit
337190ef6d
|
@ -1,8 +1,8 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getCollisions`()
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneIncluded_checkCollisions`()
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Calcula si para un mismo codigo postal y dia
|
* Calcula si para un mismo codigo postal y dia
|
||||||
* hay mas de una zona configurada y manda correo
|
* hay mas de una zona configurada y manda correo
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -10,17 +10,18 @@ BEGIN
|
||||||
DECLARE vZoneFk INT;
|
DECLARE vZoneFk INT;
|
||||||
DECLARE vIsDone INT DEFAULT FALSE;
|
DECLARE vIsDone INT DEFAULT FALSE;
|
||||||
DECLARE vTableCollisions TEXT;
|
DECLARE vTableCollisions TEXT;
|
||||||
|
DECLARE json_data JSON;
|
||||||
DECLARE cur1 CURSOR FOR SELECT zoneFk from tmp.zoneOption;
|
DECLARE cur1 CURSOR FOR SELECT zoneFk from tmp.zoneOption;
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.zone;
|
DROP TEMPORARY TABLE IF EXISTS tmp.zone;
|
||||||
CREATE TEMPORARY TABLE tmp.zone
|
CREATE TEMPORARY TABLE tmp.zone
|
||||||
SELECT z.id
|
SELECT z.id
|
||||||
FROM zone z
|
FROM zone z
|
||||||
JOIN agencyMode am ON am.id = z.agencyModeFk
|
JOIN agencyMode am ON am.id = z.agencyModeFk
|
||||||
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
||||||
WHERE dm.code IN ('AGENCY','DELIVERY');
|
WHERE dm.code IN ('AGENCY','DELIVERY');
|
||||||
|
|
||||||
CALL zone_getOptionsForShipment(util.VN_CURDATE(),FALSE);
|
CALL zone_getOptionsForShipment(util.VN_CURDATE(),FALSE);
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ BEGIN
|
||||||
PRIMARY KEY zoneFkk (zoneFk, geoFk),
|
PRIMARY KEY zoneFkk (zoneFk, geoFk),
|
||||||
INDEX(geoFk))
|
INDEX(geoFk))
|
||||||
ENGINE = MyISAM;
|
ENGINE = MyISAM;
|
||||||
|
|
||||||
OPEN cur1;
|
OPEN cur1;
|
||||||
cur1Loop: LOOP
|
cur1Loop: LOOP
|
||||||
SET vIsDone = FALSE;
|
SET vIsDone = FALSE;
|
||||||
|
@ -43,83 +44,62 @@ BEGIN
|
||||||
IF vIsDone THEN
|
IF vIsDone THEN
|
||||||
LEAVE cur1Loop;
|
LEAVE cur1Loop;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
CALL zone_getLeaves(vZoneFk, NULL, NULL, TRUE);
|
CALL zone_getLeaves(vZoneFk, NULL, NULL, TRUE);
|
||||||
|
|
||||||
myLoop: LOOP
|
myLoop: LOOP
|
||||||
SET vGeoFk = NULL;
|
SET vGeoFk = NULL;
|
||||||
SELECT geoFk INTO vGeoFk
|
SELECT geoFk INTO vGeoFk
|
||||||
FROM tmp.zoneNodes zn
|
FROM tmp.zoneNodes zn
|
||||||
WHERE NOT isChecked
|
WHERE NOT isChecked
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
IF vGeoFk IS NULL THEN
|
IF vGeoFk IS NULL THEN
|
||||||
LEAVE myLoop;
|
LEAVE myLoop;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
CALL zone_getLeaves(vZoneFk, vGeoFk, NULL, TRUE);
|
CALL zone_getLeaves(vZoneFk, vGeoFk, NULL, TRUE);
|
||||||
UPDATE tmp.zoneNodes
|
UPDATE tmp.zoneNodes
|
||||||
SET isChecked = TRUE
|
SET isChecked = TRUE
|
||||||
WHERE geoFk = vGeoFk;
|
WHERE geoFk = vGeoFk;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
|
|
||||||
END LOOP;
|
END LOOP;
|
||||||
CLOSE cur1;
|
CLOSE cur1;
|
||||||
DELETE FROM tmp.zoneNodes
|
DELETE FROM tmp.zoneNodes
|
||||||
WHERE sons > 0;
|
WHERE sons > 0;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS geoCollision;
|
DROP TEMPORARY TABLE IF EXISTS geoCollision;
|
||||||
CREATE TEMPORARY TABLE geoCollision
|
CREATE TEMPORARY TABLE geoCollision
|
||||||
SELECT z.agencyModeFk, zn.geoFk, zw.warehouseFk
|
SELECT z.agencyModeFk, zn.geoFk, zw.warehouseFk
|
||||||
FROM tmp.zoneNodes zn
|
FROM tmp.zoneNodes zn
|
||||||
JOIN zone z ON z.id = zn.zoneFk
|
JOIN zone z ON z.id = zn.zoneFk
|
||||||
JOIN zoneWarehouse zw ON z.id = zw.zoneFk
|
JOIN zoneWarehouse zw ON z.id = zw.zoneFk
|
||||||
GROUP BY z.agencyModeFk, zn.geoFk, zw.warehouseFk
|
GROUP BY z.agencyModeFk, zn.geoFk, zw.warehouseFk
|
||||||
HAVING count(*) > 1;
|
HAVING count(*) > 1;
|
||||||
|
|
||||||
SELECT '<table cellspacing="10">
|
SELECT JSON_ARRAYAGG(
|
||||||
<tr>
|
JSON_OBJECT(
|
||||||
<th>C.Postal</th>
|
'zoneFk', zoneFk,
|
||||||
<th>Número de zona</th>
|
'zn', JSON_OBJECT('name', zn.name),
|
||||||
<th>Precio</th>
|
'z', JSON_OBJECT('name', z.name,'price', z.price),
|
||||||
<th>Zona</th>
|
'w', JSON_OBJECT('name', w.name)
|
||||||
<th>Almacén</th>
|
)
|
||||||
<th>Salix</th>
|
) FROM tmp.zoneNodes zn
|
||||||
</tr>' INTO vTableCollisions;
|
JOIN zone z ON z.id = zn.zoneFk
|
||||||
|
JOIN geoCollision gc ON gc.agencyModeFk = z.agencyModeFk AND zn.geoFk = gc.geoFk
|
||||||
INSERT INTO mail (receiver,replyTo,subject,body)
|
JOIN warehouse w ON w.id = gc.warehouseFk
|
||||||
SELECT 'pepe@verdnatura.es' receiver,
|
INTO json_data;
|
||||||
'noreply@verdnatura.es' replyTo,
|
|
||||||
CONCAT('Colisiones en zonas ', util.VN_CURDATE()) subject,
|
SELECT util.notification_send(
|
||||||
CONCAT(vTableCollisions,
|
'zone-included',
|
||||||
GROUP_CONCAT(sub.td SEPARATOR ''),
|
JSON_OBJECT('zoneCollisions',json_data),
|
||||||
'</table>') body
|
account.myUser_getId()
|
||||||
FROM(SELECT
|
);
|
||||||
CONCAT('<tr>
|
|
||||||
<td>', zn.name, '</td>
|
DROP TEMPORARY TABLE
|
||||||
<td>', zoneFk,'</td>
|
geoCollision,
|
||||||
<td>', z.price,'</td>
|
|
||||||
<td>', z.name,'</td>
|
|
||||||
<td>', w.name, '</td>
|
|
||||||
<td>', CONCAT('<a href="https://salix.verdnatura.es/#!/zone/',
|
|
||||||
zoneFk,
|
|
||||||
'/location?q=%7B%22search%22:%22',
|
|
||||||
zn.name,
|
|
||||||
'%22%7D">'
|
|
||||||
'https://salix.verdnatura.es/#!/zone/',
|
|
||||||
zoneFk,
|
|
||||||
'/location?q=%7B%22search%22:%22',
|
|
||||||
zn.name,
|
|
||||||
'%22%7D</a>'),'</td>
|
|
||||||
</tr>') td
|
|
||||||
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) sub;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE
|
|
||||||
geoCollision,
|
|
||||||
tmp.zone,
|
tmp.zone,
|
||||||
tmp.zoneNodes;
|
tmp.zoneNodes;
|
||||||
END$$
|
END ;;
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue