48 lines
1.6 KiB
MySQL
48 lines
1.6 KiB
MySQL
|
DELIMITER $$
|
||
|
CREATE OR REPLACE DEFINER=`root`@`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 vn.itemShelving.isChecked
|
||
|
*
|
||
|
* param vShelvingFk Identificador de vn.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 vn.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 COUNT(*) INTO vIsChecked
|
||
|
FROM vn.itemShelving
|
||
|
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
|
||
|
AND itemFk = vItemFk;
|
||
|
END IF;
|
||
|
|
||
|
IF NOT (vIsChecking AND vIsChecked) THEN
|
||
|
CALL vn.itemShelving_add(vShelvingFk, vBarcode, 1, NULL, NULL, NULL, vWarehouseFk);
|
||
|
END IF;
|
||
|
|
||
|
UPDATE vn.itemShelving
|
||
|
SET isChecked = vIsChecked
|
||
|
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
|
||
|
AND itemFk = vItemFk;
|
||
|
|
||
|
SET vCounter = vCounter + 1;
|
||
|
END WHILE;
|
||
|
END$$
|
||
|
DELIMITER ;
|