refactor: refs #7580 Fix and improvement #2700
|
@ -1,15 +1,18 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_setParking`(IN `vCollectionFk` VARCHAR(8), IN `vParkingFk` INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_setParking`(
|
||||||
proc: BEGIN
|
vSelf INT,
|
||||||
|
vParkingFk INT
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Aparca una colección en un parking.
|
* Aparca una colección en un parking.
|
||||||
*
|
*
|
||||||
* @param vCollectionFk Id de la colección
|
* @param vSelf Id colección
|
||||||
* @param vParkingFk Id del parking
|
* @param vParkingFk Id parking
|
||||||
*/
|
*/
|
||||||
REPLACE vn.ticketParking(ticketFk, parkingFk)
|
REPLACE ticketParking(ticketFk, parkingFk)
|
||||||
SELECT tc.ticketFk, vParkingFk
|
SELECT tc.ticketFk, vParkingFk
|
||||||
FROM vn.ticketCollection tc
|
FROM ticketCollection tc
|
||||||
WHERE tc.collectionFk = vCollectionFk;
|
WHERE tc.collectionFk = vSelf;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -1,17 +1,25 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_setParking`(IN `vSaleGroupFk` VARCHAR(8), IN `vParkingFk` INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_setParking`(
|
||||||
proc: BEGIN
|
vSaleGroupFk VARCHAR(8),
|
||||||
|
vParkingFk INT
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Aparca una preparación previa en un parking
|
* Aparca una preparación previa en un parking.
|
||||||
*
|
*
|
||||||
* @param vSaleGroupFk id de la preparación previa
|
* @param vSaleGroupFk id de la preparación previa
|
||||||
* @param vParkingFk id del parking
|
* @param vParkingFk id del parking
|
||||||
*/
|
*/
|
||||||
UPDATE vn.saleGroup sg
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
|
UPDATE saleGroup sg
|
||||||
SET sg.parkingFk = vParkingFk
|
SET sg.parkingFk = vParkingFk
|
||||||
WHERE sg.id = vSaleGroupFk
|
WHERE sg.id = vSaleGroupFk
|
||||||
AND sg.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE());
|
AND sg.created >= util.VN_CURDATE() - INTERVAL 1 WEEK;
|
||||||
|
|
||||||
CALL vn.ticket_setNextState(vn.ticket_get(vSaleGroupFk));
|
CALL ticket_setNextState(ticket_get(vSaleGroupFk));
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`setParking`(IN `vParam` VARCHAR(8), IN `vParkingCode` VARCHAR(8))
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`setParking`(
|
||||||
proc: BEGIN
|
vParam VARCHAR(8),
|
||||||
|
vParkingCode VARCHAR(8)
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Aparca una colección, un ticket, un saleGroup o un shelving en un parking
|
* Aparca una colección, un ticket, un saleGroup o un shelving en un parking
|
||||||
*
|
*
|
||||||
|
@ -8,56 +11,40 @@ proc: BEGIN
|
||||||
* @param vParkingCode código del parking
|
* @param vParkingCode código del parking
|
||||||
*/
|
*/
|
||||||
DECLARE vParkingFk INT;
|
DECLARE vParkingFk INT;
|
||||||
DECLARE vIsSaleGroup BOOL;
|
DECLARE vLastWeek DATE;
|
||||||
DECLARE vIsTicket BOOL;
|
|
||||||
DECLARE vIsCollection BOOL;
|
|
||||||
|
|
||||||
SET vParkingCode = replace(vParkingCode,' ','');
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
ROLLBACK;
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
|
SET vParkingCode = REPLACE(vParkingCode, ' ', '');
|
||||||
|
|
||||||
SELECT id INTO vParkingFk
|
SELECT id INTO vParkingFk
|
||||||
FROM vn.parking
|
FROM parking
|
||||||
WHERE code = vParkingCode COLLATE utf8_unicode_ci;
|
WHERE code = vParkingCode COLLATE utf8_unicode_ci;
|
||||||
|
|
||||||
IF vParkingFk IS NULL THEN
|
IF vParkingFk IS NULL THEN
|
||||||
CALL util.throw('parkingNotExist');
|
CALL util.throw('parkingNotExist');
|
||||||
LEAVE proc;
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF vParam REGEXP '^[0-9]+$' THEN
|
IF vParam REGEXP '^[0-9]+$' THEN
|
||||||
-- Se comprueba si es una preparación previa
|
SET vLastWeek = util.VN_CURDATE() - INTERVAL 1 WEEK;
|
||||||
SELECT COUNT(*) INTO vIsSaleGroup
|
|
||||||
FROM vn.saleGroup sg
|
|
||||||
WHERE sg.id = vParam;
|
|
||||||
|
|
||||||
IF vIsSaleGroup THEN
|
-- Comprobamos si es una prep. previa, ticket o colección
|
||||||
CALL vn.saleGroup_setParking(vParam, vParkingFk);
|
IF (SELECT TRUE FROM saleGroup sg WHERE sg.id = vParam) THEN
|
||||||
LEAVE proc;
|
CALL saleGroup_setParking(vParam, vParkingFk);
|
||||||
END IF;
|
ELSEIF (SELECT TRUE FROM ticket WHERE id = vParam shipped >= vLastWeek) THEN
|
||||||
|
CALL ticket_setParking(vParam, vParkingFk);
|
||||||
-- Se comprueba si es un ticket
|
ELSEIF (SELECT TRUE FROM `collection` WHERE id = vParam AND created >= vLastWeek) THEN
|
||||||
SELECT COUNT(*) INTO vIsTicket
|
CALL collection_setParking(vParam, vParkingFk);
|
||||||
FROM vn.ticket t
|
|
||||||
WHERE t.id = vParam
|
|
||||||
AND t.shipped >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE());
|
|
||||||
|
|
||||||
IF vIsTicket THEN
|
|
||||||
CALL vn.ticket_setParking(vParam, vParkingFk);
|
|
||||||
LEAVE proc;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
-- Se comprueba si es una coleccion de tickets
|
|
||||||
SELECT COUNT(*) INTO vIsCollection
|
|
||||||
FROM vn.collection c
|
|
||||||
WHERE c.id = vParam
|
|
||||||
AND c.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE());
|
|
||||||
|
|
||||||
IF vIsCollection THEN
|
|
||||||
CALL vn.collection_setParking(vParam, vParkingFk);
|
|
||||||
LEAVE proc;
|
|
||||||
END IF;
|
END IF;
|
||||||
ELSE
|
ELSE
|
||||||
-- Por descarte, se considera una matrícula
|
-- Por descarte, se considera una matrícula
|
||||||
CALL vn.shelving_setParking(vParam, vParkingFk);
|
CALL shelving_setParking(vParam, vParkingFk);
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
guillermo marked this conversation as resolved
Outdated
|
|||||||
|
COMMIT;
|
||||||
guillermo marked this conversation as resolved
Outdated
carlosap
commented
No hay START TRANSACTION No hay START TRANSACTION
|
|||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setNextState`(vSelf INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setNextState`(
|
||||||
|
vSelf INT
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Cambia el estado del ticket al siguiente estado según la tabla state
|
* Cambia el estado del ticket al siguiente estado según la tabla state.
|
||||||
*
|
*
|
||||||
* @param vSelf id dle ticket
|
* @param vSelf Id ticket
|
||||||
*/
|
*/
|
||||||
DECLARE vStateFk INT;
|
DECLARE vStateFk INT;
|
||||||
DECLARE vNewStateFk INT;
|
DECLARE vNewStateFk INT;
|
||||||
|
|
||||||
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
SELECT stateFk INTO vStateFk
|
SELECT stateFk INTO vStateFk
|
||||||
FROM ticketState
|
FROM ticketState
|
||||||
WHERE ticketFk = vSelf;
|
WHERE ticketFk = vSelf;
|
||||||
|
@ -17,6 +24,10 @@ BEGIN
|
||||||
FROM state
|
FROM state
|
||||||
WHERE id = vStateFk;
|
WHERE id = vStateFk;
|
||||||
|
|
||||||
|
IF vNewStateFk IS NULL THEN
|
||||||
|
CALL util.throw('The ticket not have next state');
|
||||||
|
END IF;
|
||||||
|
|
||||||
INSERT INTO ticketTracking(stateFk, ticketFk, userFk)
|
INSERT INTO ticketTracking(stateFk, ticketFk, userFk)
|
||||||
VALUES (vNewStateFk, vSelf, account.myUser_getId());
|
VALUES (vNewStateFk, vSelf, account.myUser_getId());
|
||||||
END$$
|
END$$
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setParking`(IN `vTicketFk` VARCHAR(8), IN `vParkingFk` INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setParking`(
|
||||||
proc: BEGIN
|
vSelf INT,
|
||||||
|
vParkingFk INT
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Aparca un ticket en un parking
|
* Aparca un ticket en un parking.
|
||||||
*
|
*
|
||||||
* @param vTicketFk id del ticket
|
* @param vSelf Id ticket
|
||||||
* @param vParkingFk id del parking
|
* @param vParkingFk Id parking
|
||||||
*/
|
*/
|
||||||
DECLARE vDone INT DEFAULT FALSE;
|
DECLARE vDone INT DEFAULT FALSE;
|
||||||
DECLARE vCollectionTicketFk INT;
|
DECLARE vCollectionTicketFk INT;
|
||||||
|
@ -14,16 +17,21 @@ proc: BEGIN
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id
|
LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id
|
||||||
LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk
|
LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk
|
||||||
WHERE t.id = vTicketFk;
|
WHERE t.id = vSelf;
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
INSERT INTO vn.ticketParking(ticketFk, parkingFk)
|
INSERT INTO vn.ticketParking(ticketFk, parkingFk)
|
||||||
SELECT IFNULL(tc2.ticketFk, t.id), vParkingFk
|
SELECT IFNULL(tc2.ticketFk, t.id), vParkingFk
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id
|
LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id
|
||||||
LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk
|
LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk
|
||||||
WHERE t.id = vTicketFk
|
WHERE t.id = vSelf
|
||||||
ON DUPLICATE KEY UPDATE parkingFk = vParkingFk;
|
ON DUPLICATE KEY UPDATE parkingFk = vParkingFk;
|
||||||
|
|
||||||
OPEN vCursor;
|
OPEN vCursor;
|
||||||
|
|
Loading…
Reference in New Issue
Para que se quede mejor el procedimiento, como ya lo estamos refactorizando en el ELSE pondríamos un THROW y la opción del shelving haríamos lo mismo que en las anteriores, comprobar con la SELECT si existe antes de llamarlo