fix: refs #7781 prevent pallet merge #2792

Merged
pablone merged 13 commits from 7781-fixPalletMerge into master 2024-10-04 06:17:57 +00:00
1 changed files with 57 additions and 38 deletions

View File

@ -5,22 +5,26 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`expeditionPallet_buil
vWorkerFk INT, vWorkerFk INT,
OUT vPalletFk INT OUT vPalletFk INT
) )
BEGIN proc: BEGIN
/** Construye un pallet de expediciones. /**
* Builds an expedition pallet.
* *
* Primero comprueba si esas expediciones ya pertenecen a otro pallet, * First, it checks if these expeditions already belong to another pallet,
* en cuyo caso actualiza ese pallet. * in which case it returns an error.
* *
* @param vExpeditions JSON_ARRAY con esta estructura [exp1, exp2, exp3, ...] * @param vExpeditions JSON_ARRAY with this structure [exp1, exp2, exp3, ...]
* @param vArcId INT Identificador de arcRead * @param vArcId INT Identifier of arcRead
* @param vWorkerFk INT Identificador de worker * @param vWorkerFk INT Identifier of worker
* @param out vPalletFk Identificador de expeditionPallet * @param out vPalletFk Identifier of expeditionPallet
*/ */
DECLARE vCounter INT; DECLARE vCounter INT;
DECLARE vExpeditionFk INT; DECLARE vExpeditionFk INT;
DECLARE vTruckFk INT; DECLARE vTruckFk INT;
DECLARE vPrinterFk INT; DECLARE vPrinterFk INT;
DECLARE vExpeditionStateTypeFk INT; DECLARE vExpeditionStateTypeFk INT;
DECLARE vFreeExpeditionCount INT;
DECLARE vExpeditionWithPallet INT;
CREATE OR REPLACE TEMPORARY TABLE tExpedition ( CREATE OR REPLACE TEMPORARY TABLE tExpedition (
expeditionFk INT, expeditionFk INT,
@ -44,23 +48,35 @@ BEGIN
WHERE e.id = vExpeditionFk; WHERE e.id = vExpeditionFk;
END WHILE; END WHILE;
pablone marked this conversation as resolved Outdated
Outdated
Review

La variable es tipo INT.... ¿ que sentido tiene el group_concat ?

La variable es tipo INT.... ¿ que sentido tiene el group_concat ?
SELECT palletFk INTO vPalletFk SELECT COUNT(expeditionFk) INTO vFreeExpeditionCount
FROM (
SELECT palletFk, count(*) n
FROM tExpedition FROM tExpedition
WHERE palletFk > 0 WHERE palletFk IS NULL;
GROUP BY palletFk
ORDER BY n DESC SELECT COUNT(expeditionFk) INTO vExpeditionWithPallet
LIMIT 100 FROM tExpedition
) sub WHERE palletFk;
LIMIT 1;
IF vExpeditionWithPallet THEN
UPDATE arcRead
SET error = (
SELECT GROUP_CONCAT(expeditionFk SEPARATOR ', ')
FROM tExpedition
WHERE palletFk
)
WHERE id = vArcId;
LEAVE proc;
END IF;
IF NOT vFreeExpeditionCount THEN
CALL util.throw ('NO_FREE_EXPEDITIONS');
END IF;
IF vPalletFk IS NULL THEN
SELECT roadmapStopFk INTO vTruckFk SELECT roadmapStopFk INTO vTruckFk
FROM ( FROM (
SELECT rm.roadmapStopFk, count(*) n SELECT rm.roadmapStopFk, count(*) n
FROM routesMonitor rm FROM routesMonitor rm
JOIN tExpedition e ON e.routeFk = rm.routeFk JOIN tExpedition e ON e.routeFk = rm.routeFk
WHERE e.palletFk IS NULL
GROUP BY roadmapStopFk GROUP BY roadmapStopFk
ORDER BY n DESC ORDER BY n DESC
LIMIT 1 LIMIT 1
@ -73,19 +89,22 @@ BEGIN
INSERT INTO expeditionPallet SET truckFk = vTruckFk; INSERT INTO expeditionPallet SET truckFk = vTruckFk;
SET vPalletFk = LAST_INSERT_ID(); SET vPalletFk = LAST_INSERT_ID();
END IF;
INSERT INTO expeditionScan(expeditionFk, palletFk, workerFk) INSERT INTO expeditionScan(expeditionFk, palletFk, workerFk)
pablone marked this conversation as resolved Outdated
Outdated
Review

Si dalt se ha fet IF NOT vExpeditionWithPallet no entrarà mai per el else.
Volies ficar vExpeditionWithOutPallet ?

Si dalt se ha fet `IF NOT vExpeditionWithPallet` no entrarà mai per el else. Volies ficar `vExpeditionWithOutPallet` ?

si

si
SELECT expeditionFk, vPalletFk, vWorkerFk SELECT expeditionFk, vPalletFk, vWorkerFk
FROM tExpedition FROM tExpedition
ON DUPLICATE KEY UPDATE palletFk = vPalletFk, workerFk = vWorkerFk; WHERE palletFk IS NULL;
SELECT id INTO vExpeditionStateTypeFk SELECT id INTO vExpeditionStateTypeFk
FROM expeditionStateType FROM expeditionStateType
WHERE code = 'PALLETIZED'; WHERE code = 'PALLETIZED';
INSERT INTO expeditionState(expeditionFk, typeFk) INSERT INTO expeditionState(expeditionFk, typeFk)
SELECT expeditionFk, vExpeditionStateTypeFk FROM tExpedition; SELECT expeditionFk, vExpeditionStateTypeFk
FROM tExpedition
WHERE palletFk IS NULL;
UPDATE arcRead SET error = NULL WHERE id = vArcId;
SELECT printerFk INTO vPrinterFk FROM arcRead WHERE id = vArcId; SELECT printerFk INTO vPrinterFk FROM arcRead WHERE id = vArcId;