Merge pull request 'fix: solo un trabajador por fallo' (!2210) from 6782-productionError_add into dev
gitea/salix/pipeline/head This commit looks good Details
gitea/salix/pipeline/pr-dev This commit looks good Details

Reviewed-on: #2210
Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
Javi Gallego 2024-03-27 06:24:25 +00:00
commit 075259dee9
1 changed files with 16 additions and 10 deletions

View File

@ -34,16 +34,22 @@ BEGIN
-- Rellena la tabla tmp.errorsByChecker con fallos de revisores -- Rellena la tabla tmp.errorsByChecker con fallos de revisores
CREATE OR REPLACE TEMPORARY TABLE tmp.errorsByChecker CREATE OR REPLACE TEMPORARY TABLE tmp.errorsByChecker
ENGINE = MEMORY ENGINE = MEMORY
SELECT st.workerFk, WITH rankedWorkers AS (
COUNT(t.id) errors SELECT sm.id,
FROM saleMistake sm st.workerFk,
JOIN saleTracking st ON sm.saleFk = st.saleFk ROW_NUMBER() OVER(PARTITION BY sm.id ORDER BY s2.`order`) rnk
JOIN `state` s2 ON s2.id = st.stateFk FROM vn.saleMistake sm
JOIN sale s ON s.id = sm.saleFk JOIN vn.saleTracking st ON sm.saleFk = st.saleFk
JOIN ticket t on t.id = s.ticketFk JOIN vn.`state` s2 ON s2.id = st.stateFk
WHERE (t.shipped BETWEEN vDatedFrom AND vDatedTo) JOIN vn.sale s ON s.id = sm.saleFk
AND s2.code IN ('OK','PREVIOUS_PREPARATION','PREPARED','CHECKED') JOIN vn.ticket t ON t.id = s.ticketFk
GROUP BY st.workerFk; WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo
AND s2.code IN ('OK', 'PREVIOUS_PREPARATION', 'PREPARED', 'CHECKED')
)
SELECT workerFk, COUNT(*) errors
FROM rankedWorkers
WHERE rnk = 1
GROUP BY workerFk;
-- Rellena la tabla tmp.expeditionErrors con fallos de expediciones -- Rellena la tabla tmp.expeditionErrors con fallos de expediciones
CREATE OR REPLACE TEMPORARY TABLE tmp.expeditionErrors CREATE OR REPLACE TEMPORARY TABLE tmp.expeditionErrors