55 lines
1.6 KiB
SQL
55 lines
1.6 KiB
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_addList`(
|
|
vShelvingFk VARCHAR(3),
|
|
vList TEXT,
|
|
vIsChecking BOOL,
|
|
vWarehouseFk INT
|
|
)
|
|
BEGIN
|
|
/**
|
|
* Recorre cada elemento en la colección vList.
|
|
* Si el parámetro isChecking = FALSE, llama a itemShelving_add.
|
|
*
|
|
* Cuando es TRUE sólo inserta los elementos de la colección que no están ya en
|
|
* ese shelving, actualizando los valores del campo itemShelving.isChecked
|
|
*
|
|
* @param vShelvingFk Identificador de shelving
|
|
* @param vList JSON array con esta estructura: '[value1, value2, ...]'
|
|
* @param vIsChecking Define si hay que añadir o comprobar los items
|
|
* @param vWarehouseFk Identificador de warehouse
|
|
*/
|
|
DECLARE vListLength INT DEFAULT JSON_LENGTH(vList);
|
|
DECLARE vCounter INT DEFAULT 0;
|
|
DECLARE vBarcode VARCHAR(22);
|
|
DECLARE vPath VARCHAR(6);
|
|
DECLARE vItemFk INT;
|
|
DECLARE vIsChecked BOOL;
|
|
|
|
WHILE vCounter < vListLength DO
|
|
SET vPath = CONCAT('$[', vCounter, ']');
|
|
SET vBarcode = JSON_EXTRACT(vList, vPath);
|
|
SET vIsChecked = NULL;
|
|
IF vIsChecking THEN
|
|
SELECT barcodeToItem(vBarcode) INTO vItemFk;
|
|
|
|
SELECT IF(COUNT(*), TRUE, FALSE) INTO vIsChecked
|
|
FROM itemShelving
|
|
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
|
|
AND itemFk = vItemFk;
|
|
END IF;
|
|
|
|
IF NOT vIsChecking OR NOT vIsChecked THEN
|
|
CALL itemShelving_add(vShelvingFk, vBarcode, 1, NULL, NULL, NULL, vWarehouseFk);
|
|
END IF;
|
|
|
|
UPDATE itemShelving
|
|
SET isChecked = vIsChecked
|
|
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
|
|
AND itemFk = vItemFk
|
|
AND isChecked IS NULL;
|
|
|
|
SET vCounter = vCounter + 1;
|
|
END WHILE;
|
|
END$$
|
|
DELIMITER ;
|