From e47b8c10568d4453bb7ce16fe4059dd9c980c8de Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 26 Mar 2024 08:52:01 +0100 Subject: [PATCH 1/3] fix: solo un trabajador por fallo --- .../vn/procedures/productionError_add.sql | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/db/routines/vn/procedures/productionError_add.sql b/db/routines/vn/procedures/productionError_add.sql index 5e0ce93f0..a872ca511 100644 --- a/db/routines/vn/procedures/productionError_add.sql +++ b/db/routines/vn/procedures/productionError_add.sql @@ -34,16 +34,22 @@ BEGIN -- Rellena la tabla tmp.errorsByChecker con fallos de revisores CREATE OR REPLACE TEMPORARY TABLE tmp.errorsByChecker ENGINE = MEMORY - SELECT st.workerFk, - COUNT(t.id) errors - FROM saleMistake sm - JOIN saleTracking st ON sm.saleFk = st.saleFk - JOIN `state` s2 ON s2.id = st.stateFk - JOIN sale s ON s.id = sm.saleFk - JOIN ticket t on t.id = s.ticketFk - WHERE (t.shipped BETWEEN vDatedFrom AND vDatedTo) - AND s2.code IN ('OK','PREVIOUS_PREPARATION','PREPARED','CHECKED') - GROUP BY st.workerFk; + WITH rankedWorkers AS ( + SELECT sm.id, + st.workerFk, + ROW_NUMBER() OVER(PARTITION BY sm.id ORDER BY s2.`order`) AS rnk + FROM saleMistake sm + JOIN saleTracking st ON sm.saleFk = st.saleFk + JOIN `state` s2 ON s2.id = st.stateFk + JOIN sale s ON s.id = sm.saleFk + JOIN ticket t ON t.id = s.ticketFk + WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo + AND s2.code IN ('OK', 'PREVIOUS_PREPARATION', 'PREPARED', 'CHECKED') + ) + SELECT workerFk, COUNT(*) AS errors + FROM rankedWorkers + WHERE rnk = 1 + GROUP BY workerFk; -- Rellena la tabla tmp.expeditionErrors con fallos de expediciones CREATE OR REPLACE TEMPORARY TABLE tmp.expeditionErrors -- 2.40.1 From b978833a64151646a1587138dfcf05f39656dd6b Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 26 Mar 2024 09:46:53 +0100 Subject: [PATCH 2/3] fix: #6782 with con esquema --- db/routines/vn/procedures/productionError_add.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/productionError_add.sql b/db/routines/vn/procedures/productionError_add.sql index a872ca511..dcbe379dc 100644 --- a/db/routines/vn/procedures/productionError_add.sql +++ b/db/routines/vn/procedures/productionError_add.sql @@ -38,11 +38,11 @@ BEGIN SELECT sm.id, st.workerFk, ROW_NUMBER() OVER(PARTITION BY sm.id ORDER BY s2.`order`) AS rnk - FROM saleMistake sm - JOIN saleTracking st ON sm.saleFk = st.saleFk - JOIN `state` s2 ON s2.id = st.stateFk - JOIN sale s ON s.id = sm.saleFk - JOIN ticket t ON t.id = s.ticketFk + FROM vn.saleMistake sm + JOIN vn.saleTracking st ON sm.saleFk = st.saleFk + JOIN vn.`state` s2 ON s2.id = st.stateFk + JOIN vn.sale s ON s.id = sm.saleFk + JOIN vn.ticket t ON t.id = s.ticketFk WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND s2.code IN ('OK', 'PREVIOUS_PREPARATION', 'PREPARED', 'CHECKED') ) -- 2.40.1 From 1472fc6fc24a45798946a67096468e96e25697d9 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 26 Mar 2024 14:02:47 +0100 Subject: [PATCH 3/3] feat: #6782 sin as --- db/routines/vn/procedures/productionError_add.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/productionError_add.sql b/db/routines/vn/procedures/productionError_add.sql index dcbe379dc..e29accac9 100644 --- a/db/routines/vn/procedures/productionError_add.sql +++ b/db/routines/vn/procedures/productionError_add.sql @@ -37,7 +37,7 @@ BEGIN WITH rankedWorkers AS ( SELECT sm.id, st.workerFk, - ROW_NUMBER() OVER(PARTITION BY sm.id ORDER BY s2.`order`) AS rnk + ROW_NUMBER() OVER(PARTITION BY sm.id ORDER BY s2.`order`) rnk FROM vn.saleMistake sm JOIN vn.saleTracking st ON sm.saleFk = st.saleFk JOIN vn.`state` s2 ON s2.id = st.stateFk @@ -46,7 +46,7 @@ BEGIN WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND s2.code IN ('OK', 'PREVIOUS_PREPARATION', 'PREPARED', 'CHECKED') ) - SELECT workerFk, COUNT(*) AS errors + SELECT workerFk, COUNT(*) errors FROM rankedWorkers WHERE rnk = 1 GROUP BY workerFk; -- 2.40.1