From d5dc057c361c2ff91831c954b65fa30ace7453db Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 18 Apr 2024 13:52:30 +0200 Subject: [PATCH] hotfix: changes --- .../vn/procedures/collection_assign.sql | 24 +++++++++++++++---- db/routines/vn/procedures/collection_new.sql | 15 ++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/collection_assign.sql b/db/routines/vn/procedures/collection_assign.sql index 49b4eb7bb..bfc7b0f93 100644 --- a/db/routines/vn/procedures/collection_assign.sql +++ b/db/routines/vn/procedures/collection_assign.sql @@ -13,11 +13,16 @@ proc:BEGIN * @param vCollectionFk Id de colección */ DECLARE vHasTooMuchCollections BOOL; + DECLARE vItemPackingTypeFk VARCHAR(1); + DECLARE vWarehouseFk INT; + DECLARE vLockName VARCHAR(215); DECLARE vLockTime INT DEFAULT 15; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - DO RELEASE_LOCK('collection_assign'); + IF vLockName IS NOT NULL THEN + DO RELEASE_LOCK(vLockName); + END IF; RESIGNAL; END; @@ -28,7 +33,7 @@ proc:BEGIN SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0 INTO vHasTooMuchCollections FROM tCollection - JOIN productionConfig pc ; + JOIN productionConfig pc; DROP TEMPORARY TABLE tCollection; @@ -37,7 +42,18 @@ proc:BEGIN LEAVE proc; END IF; - IF NOT GET_LOCK('collection_assign',vLockTime) THEN + SELECT warehouseFk, itemPackingTypeFk + INTO vWarehouseFk, vItemPackingTypeFk + FROM operator + WHERE workerFk = vUserFk; + + SET vLockName = CONCAT_WS('/', + 'collection_assign', + vWarehouseFk, + vItemPackingTypeFk + ); + + IF NOT GET_LOCK(vLockName, vLockTime) THEN LEAVE proc; END IF; @@ -90,6 +106,6 @@ proc:BEGIN SET workerFk = vUserFk WHERE id = vCollectionFk; - DO RELEASE_LOCK('collection_assign'); + DO RELEASE_LOCK(vLockName); END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/collection_new.sql b/db/routines/vn/procedures/collection_new.sql index d4e896473..1292707af 100644 --- a/db/routines/vn/procedures/collection_new.sql +++ b/db/routines/vn/procedures/collection_new.sql @@ -45,6 +45,15 @@ proc:BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + IF vLockName IS NOT NULL THEN + DO RELEASE_LOCK(vLockName); + END IF; + + RESIGNAL; + END; + SELECT pc.ticketTrolleyMax * o.numberOfWagons, pc.hasUniqueCollectionTime, w.code, @@ -70,6 +79,12 @@ proc:BEGIN JOIN state st ON st.`code` = 'ON_PREPARATION' JOIN operator o ON o.workerFk = vUserFk; + SET vLockName = CONCAT_WS('/', + 'collection_new', + vWarehouseFk, + vItemPackingTypeFk + ); + IF NOT GET_LOCK(vLockName, vLockTime) THEN LEAVE proc; END IF;