2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`machineWorker_update`(vPlate VARCHAR(10), vWorkerFk INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actualiza el registro correspondiente si el vWorkerFk se ha registrado en las últimas horas (campo maxHours de machineWorkerConfig) con vPlate,
|
|
|
|
*
|
|
|
|
* @param vPlate número de matrícula
|
|
|
|
* @param vWorkerFk id del trabajador
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
DECLARE vMachineFk INT(10);
|
|
|
|
DECLARE vMaxHours INT(10);
|
|
|
|
|
|
|
|
SELECT m.id INTO vMachineFk
|
|
|
|
FROM machine m
|
|
|
|
WHERE m.plate = vPlate;
|
|
|
|
|
|
|
|
SELECT maxHours INTO vMaxHours
|
|
|
|
FROM machineWorkerConfig;
|
|
|
|
|
|
|
|
IF (SELECT COUNT(*)
|
|
|
|
FROM machineWorker m
|
|
|
|
WHERE m.workerFk = vWorkerFk
|
|
|
|
AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) AND ISNULL(m.outTimed)) THEN
|
|
|
|
|
|
|
|
UPDATE machineWorker m
|
|
|
|
SET m.outTimed = CURRENT_TIMESTAMP()
|
|
|
|
WHERE m.workerFk = vWorkerFk
|
|
|
|
AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW())
|
|
|
|
AND ISNULL(m.outTimed)
|
|
|
|
AND m.machineFk = vMachineFk;
|
|
|
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|