From a45ca84e7fe576adc4566cd9bacc1e2cc0b0f6e2 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 21 Nov 2019 14:23:22 +0100 Subject: [PATCH 1/3] workerTimeControlCalculate procedure refactor --- .../00-workerTimeControlCalculate.sql | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 db/changes/10110-postCampaign/00-workerTimeControlCalculate.sql diff --git a/db/changes/10110-postCampaign/00-workerTimeControlCalculate.sql b/db/changes/10110-postCampaign/00-workerTimeControlCalculate.sql new file mode 100644 index 000000000..ef058acb1 --- /dev/null +++ b/db/changes/10110-postCampaign/00-workerTimeControlCalculate.sql @@ -0,0 +1,42 @@ +DROP procedure IF EXISTS `vn`.`timeControl_calculate`; + +DELIMITER $$ +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`timeControl_calculate`(vDatedFrom DATETIME, vDatedTo DATETIME) +BEGIN + SET @vIsOdd := TRUE; + SET @vUser := NULL; + SET @vDated := NULL; + + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate; + + CREATE TEMPORARY TABLE tmp.timeControlCalculate + SELECT userFk, + dated, + IF( timeWork >= 18000, @timeWork:=timeWork + 1200, @timeWork:=timeWork) timeWorkSeconds, + SEC_TO_TIME(@timeWork ) timeWorkSexagesimal, + @timeWork / 3600 timeWorkDecimal + FROM (SELECT SUM(timeWork) timeWork, + userFk, + dated + FROM (SELECT IF(@vUser = wtc.userFk, @vUser :=@vUser, @vUser := wtc.userFk ), + IF(@vIsOdd, @vIsOdd := FALSE, @vIsOdd := TRUE ), + IF(direction='in', @vIsOdd := TRUE, @vIsOdd := @vIsOdd ), + IF(@vIsOdd, @vLastTimed:=UNIX_TIMESTAMP(timed),@vLastTimed:=@vLastTimed), + IF(@vIsOdd, 0, UNIX_TIMESTAMP(timed)-@vLastTimed) timeWork, + IF(direction='in', @vDated := DATE(wtc.timed), @vDated :=@vDated) dated, + wtc.userFk, + wtc.timed timed, + direction + FROM workerTimeControl wtc + JOIN tmp.`user` w ON w.userFk = wtc.userFk + WHERE wtc.timed BETWEEN vDatedFrom AND vDatedTo + ORDER BY userFk, timed + ) sub + GROUP BY userFk, dated + ORDER BY userFk, dated + )sub2; + +END$$ + +DELIMITER ; + From 33e9cf98163eecd2d7cb9e20f78a9c899705684c Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 21 Nov 2019 14:39:09 +0100 Subject: [PATCH 2/3] Javi validation --- .../00-workerTimeControlCalculate.sql | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/db/changes/10110-postCampaign/00-workerTimeControlCalculate.sql b/db/changes/10110-postCampaign/00-workerTimeControlCalculate.sql index ef058acb1..c51647727 100644 --- a/db/changes/10110-postCampaign/00-workerTimeControlCalculate.sql +++ b/db/changes/10110-postCampaign/00-workerTimeControlCalculate.sql @@ -19,18 +19,17 @@ BEGIN userFk, dated FROM (SELECT IF(@vUser = wtc.userFk, @vUser :=@vUser, @vUser := wtc.userFk ), - IF(@vIsOdd, @vIsOdd := FALSE, @vIsOdd := TRUE ), - IF(direction='in', @vIsOdd := TRUE, @vIsOdd := @vIsOdd ), - IF(@vIsOdd, @vLastTimed:=UNIX_TIMESTAMP(timed),@vLastTimed:=@vLastTimed), - IF(@vIsOdd, 0, UNIX_TIMESTAMP(timed)-@vLastTimed) timeWork, - IF(direction='in', @vDated := DATE(wtc.timed), @vDated :=@vDated) dated, + IF(wtc.direction='in', @vIsOdd := TRUE, @vIsOdd := !@vIsOdd), + IF(@vIsOdd, @vLastTimed:=UNIX_TIMESTAMP(wtc.timed), TRUE), + IF(@vIsOdd, 0, UNIX_TIMESTAMP(wtc.timed)-@vLastTimed) timeWork, + IF(wtc.direction='in', @vDated := DATE(wtc.timed), @vDated) dated, wtc.userFk, wtc.timed timed, - direction + wtc.direction FROM workerTimeControl wtc JOIN tmp.`user` w ON w.userFk = wtc.userFk - WHERE wtc.timed BETWEEN vDatedFrom AND vDatedTo - ORDER BY userFk, timed + WHERE wtc.timed BETWEEN curdate()-1 AND curdate() + ORDER BY wtc.userFk, wtc.timed ) sub GROUP BY userFk, dated ORDER BY userFk, dated @@ -38,5 +37,4 @@ BEGIN END$$ -DELIMITER ; - +DELIMITER ; \ No newline at end of file From dca7dd5fc7a74fdde20a279eaddac32f10eaf642 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 21 Nov 2019 14:51:11 +0100 Subject: [PATCH 3/3] rejected last modifications --- .../00-workerTimeControlCalculate.sql | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/db/changes/10110-postCampaign/00-workerTimeControlCalculate.sql b/db/changes/10110-postCampaign/00-workerTimeControlCalculate.sql index c51647727..8e8c7471b 100644 --- a/db/changes/10110-postCampaign/00-workerTimeControlCalculate.sql +++ b/db/changes/10110-postCampaign/00-workerTimeControlCalculate.sql @@ -19,17 +19,18 @@ BEGIN userFk, dated FROM (SELECT IF(@vUser = wtc.userFk, @vUser :=@vUser, @vUser := wtc.userFk ), - IF(wtc.direction='in', @vIsOdd := TRUE, @vIsOdd := !@vIsOdd), - IF(@vIsOdd, @vLastTimed:=UNIX_TIMESTAMP(wtc.timed), TRUE), - IF(@vIsOdd, 0, UNIX_TIMESTAMP(wtc.timed)-@vLastTimed) timeWork, - IF(wtc.direction='in', @vDated := DATE(wtc.timed), @vDated) dated, + IF(@vIsOdd, @vIsOdd := FALSE, @vIsOdd := TRUE ), + IF(direction='in', @vIsOdd := TRUE, @vIsOdd := @vIsOdd ), + IF(@vIsOdd, @vLastTimed:=UNIX_TIMESTAMP(timed),@vLastTimed:=@vLastTimed), + IF(@vIsOdd, 0, UNIX_TIMESTAMP(timed)-@vLastTimed) timeWork, + IF(direction='in', @vDated := DATE(wtc.timed), @vDated :=@vDated) dated, wtc.userFk, wtc.timed timed, - wtc.direction + direction FROM workerTimeControl wtc JOIN tmp.`user` w ON w.userFk = wtc.userFk - WHERE wtc.timed BETWEEN curdate()-1 AND curdate() - ORDER BY wtc.userFk, wtc.timed + WHERE wtc.timed BETWEEN vDatedFrom AND vDatedTo + ORDER BY userFk, timed ) sub GROUP BY userFk, dated ORDER BY userFk, dated