33 lines
741 B
MySQL
33 lines
741 B
MySQL
|
USE `vn`;
|
||
|
DROP function IF EXISTS `worker_isWorking`;
|
||
|
|
||
|
DELIMITER $$
|
||
|
USE `vn`$$
|
||
|
CREATE DEFINER=`root`@`%` FUNCTION `worker_isWorking`(vWorkerFk INT) RETURNS tinyint(1)
|
||
|
READS SQL DATA
|
||
|
BEGIN
|
||
|
/**
|
||
|
* Comprueba si el trabajador está trabajando en el momento de la consulta
|
||
|
* @return Devuelve TRUE en caso de que este trabajando. Si se encuentra en un descanso devolverá FALSE
|
||
|
*/
|
||
|
DECLARE vLastIn DATETIME ;
|
||
|
|
||
|
SELECT MAX(timed) INTO vLastIn
|
||
|
FROM vn.workerTimeControl
|
||
|
WHERE userFk = vWorkerFk AND
|
||
|
direction = 'in';
|
||
|
|
||
|
IF (SELECT MOD(COUNT(*),2)
|
||
|
FROM vn.workerTimeControl
|
||
|
WHERE userFk = vWorkerFk AND
|
||
|
timed >= vLastIn
|
||
|
) THEN
|
||
|
RETURN TRUE;
|
||
|
ELSE
|
||
|
RETURN FALSE;
|
||
|
END IF;
|
||
|
END$$
|
||
|
|
||
|
DELIMITER ;
|
||
|
|