From 2e1ab3af206ad21a14d9fb5f3046fc2dfb2587b3 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 25 Jun 2024 14:00:46 +0200 Subject: [PATCH] refs #7486 Fix same assign collection --- .../vn/procedures/collection_assign.sql | 50 +++++++++++++++++-- db/routines/vn/procedures/collection_new.sql | 3 +- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/collection_assign.sql b/db/routines/vn/procedures/collection_assign.sql index fc9f9a711..84067e7d8 100644 --- a/db/routines/vn/procedures/collection_assign.sql +++ b/db/routines/vn/procedures/collection_assign.sql @@ -13,12 +13,39 @@ 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 30; + DECLARE vErrorNumber INT; + DECLARE vErrorMsg TEXT; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + GET DIAGNOSTICS CONDITION 1 + vErrorNumber = MYSQL_ERRNO, + vErrorMsg = MESSAGE_TEXT; + + IF vLockName IS NOT NULL THEN + DO RELEASE_LOCK(vLockName); + CALL util.debugAdd('collection_assign', JSON_OBJECT( + 'errorNumber', vErrorNumber, + 'errorMsg', vErrorMsg, + 'lockName', vLockName, + 'userFk', vUserFk + )); -- Tmp + END IF; + + RESIGNAL; + END; -- Si hay colecciones sin terminar, sale del proceso CALL collection_get(vUserFk); - SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0 - INTO vHasTooMuchCollections + SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0, + collection_assign_lockname + INTO vHasTooMuchCollections, + vLockName FROM productionConfig pc LEFT JOIN tCollection ON TRUE; @@ -28,6 +55,21 @@ BEGIN CALL util.throw('Hay colecciones pendientes'); END IF; + SELECT warehouseFk, itemPackingTypeFk + INTO vWarehouseFk, vItemPackingTypeFk + FROM operator + WHERE workerFk = vUserFk; + + SET vLockName = CONCAT_WS('/', + vLockName, + vWarehouseFk, + vItemPackingTypeFk + ); + + IF NOT GET_LOCK(vLockName, vLockTime) THEN + CALL util.throw(CONCAT('Cannot get lock: ', vLockName)); + END IF; + -- Se eliminan las colecciones sin asignar que estan obsoletas INSERT INTO ticketTracking(stateFk, ticketFk) SELECT s.id, tc.ticketFk @@ -35,7 +77,7 @@ BEGIN JOIN ticketCollection tc ON tc.collectionFk = c.id JOIN `state` s ON s.code = 'PRINTED_AUTO' JOIN productionConfig pc - WHERE c.workerFk IS NULL + WHERE c.workerFk IS NULL AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; DELETE c.* @@ -75,5 +117,7 @@ BEGIN UPDATE `collection` SET workerFk = vUserFk WHERE id = vCollectionFk; + + 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 b022d8dcc..029427306 100644 --- a/db/routines/vn/procedures/collection_new.sql +++ b/db/routines/vn/procedures/collection_new.sql @@ -59,7 +59,8 @@ BEGIN 'errorNumber', vErrorNumber, 'errorMsg', vErrorMsg, 'lockName', vLockName, - 'userFk', vUserFk + 'userFk', vUserFk, + 'ticketFk', vTicketFk )); -- Tmp END IF;