Merge pull request 'refactor: refs #7398 Refactor and change ekt_scan' (!2494) from 7398-ektScan into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2494 Reviewed-by: Pako Natek <pako@verdnatura.es>
This commit is contained in:
commit
a52b9b6d2e
|
@ -23,42 +23,39 @@ BEGIN
|
|||
DECLARE vXtraLongAgj INT;
|
||||
DECLARE vDefaultKlo INT;
|
||||
|
||||
SELECT
|
||||
ec.usefulAuctionLeftSegmentLength,
|
||||
ec.standardBarcodeLength,
|
||||
ec.floridayBarcodeLength,
|
||||
ec.floramondoBarcodeLength,
|
||||
ec.defaultKlo
|
||||
INTO
|
||||
vUsefulAuctionLeftSegmentLength,
|
||||
SELECT usefulAuctionLeftSegmentLength,
|
||||
standardBarcodeLength,
|
||||
floridayBarcodeLength,
|
||||
floramondoBarcodeLength,
|
||||
defaultKlo
|
||||
INTO vUsefulAuctionLeftSegmentLength,
|
||||
vStandardBarcodeLength,
|
||||
vFloridayBarcodeLength,
|
||||
vFloramondoBarcodeLength,
|
||||
vDefaultKlo
|
||||
FROM edi.ektConfig ec;
|
||||
FROM ektConfig;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ekt;
|
||||
CREATE TEMPORARY TABLE tmp.ekt
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ekt
|
||||
ENGINE = MEMORY
|
||||
SELECT id ektFk FROM ekt LIMIT 0;
|
||||
|
||||
CASE
|
||||
CASE
|
||||
WHEN LENGTH(vBarcode) <= vFloridayBarcodeLength THEN
|
||||
INSERT INTO tmp.ekt
|
||||
SELECT id
|
||||
FROM edi.ektRecent e
|
||||
FROM ektRecent e
|
||||
WHERE e.cps = vBarcode
|
||||
OR e.batchNumber = vBarcode;
|
||||
|
||||
WHEN LENGTH(vBarcode) = vFloramondoBarcodeLength THEN
|
||||
INSERT INTO tmp.ekt
|
||||
SELECT e.id
|
||||
FROM edi.ektRecent e
|
||||
FROM ektRecent e
|
||||
WHERE e.pro = MID(vBarcode,2,6)
|
||||
AND CAST(e.ptd AS SIGNED) = MID(vBarcode,8,5);
|
||||
AND CAST(e.ptd AS SIGNED) = MID(vBarcode, 8, 5);
|
||||
|
||||
ELSE
|
||||
SET vBarcode = LPAD(vBarcode,vStandardBarcodeLength,'0');
|
||||
SET vBarcode = LPAD(vBarcode, vStandardBarcodeLength, '0');
|
||||
SET vAuction = MID(vBarcode, 1, 3);
|
||||
SET vKlo = MID(vBarcode, 4, 2);
|
||||
SET vFec = MAKEDATE(YEAR(util.VN_CURDATE()), MID(vBarcode, 6, 3));
|
||||
|
@ -69,21 +66,23 @@ BEGIN
|
|||
-- Clásico de subasta
|
||||
-- Trade standard
|
||||
-- Trade que construye como la subasta
|
||||
-- Trade como el anterior pero sin trade code
|
||||
-- Trade como el anterior pero sin trade code
|
||||
INSERT INTO tmp.ekt
|
||||
SELECT id
|
||||
FROM ekt
|
||||
WHERE fec >= vFec - INTERVAL 1 DAY
|
||||
AND ((
|
||||
vKlo = vDefaultKlo
|
||||
AND (
|
||||
(vKlo = vDefaultKlo
|
||||
AND (klo = vKlo OR klo IS NULL OR klo = 0)
|
||||
AND agj IN (vShortAgj, vLongAgj, vXtraLongAgj))
|
||||
OR (klo = vKlo
|
||||
AND agj IN (vShortAgj, vLongAgj, vXtraLongAgj)
|
||||
) OR (
|
||||
klo = vKlo
|
||||
AND auction = vAuction
|
||||
AND agj = vShortAgj)
|
||||
AND agj = vShortAgj
|
||||
)
|
||||
)
|
||||
ORDER BY agj DESC, fec DESC
|
||||
LIMIT 1;
|
||||
ORDER BY agj DESC, fec DESC
|
||||
LIMIT 1;
|
||||
|
||||
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
||||
|
||||
|
@ -91,9 +90,11 @@ BEGIN
|
|||
IF NOT vIsFound THEN
|
||||
INSERT INTO tmp.ekt
|
||||
SELECT id
|
||||
FROM edi.ektRecent e
|
||||
WHERE e.batchNumber
|
||||
= LEFT(vBarcode,vUsefulAuctionLeftSegmentLength)
|
||||
FROM ektRecent e
|
||||
WHERE e.batchNumber = LEFT(
|
||||
vBarcode,
|
||||
vUsefulAuctionLeftSegmentLength
|
||||
)
|
||||
AND e.batchNumber > 0;
|
||||
|
||||
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
||||
|
@ -103,7 +104,7 @@ BEGIN
|
|||
IF NOT vIsFound THEN
|
||||
INSERT INTO tmp.ekt
|
||||
SELECT id
|
||||
FROM edi.ektRecent e
|
||||
FROM ektRecent e
|
||||
WHERE e.putOrderFk = vBarcode;
|
||||
|
||||
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
||||
|
@ -113,18 +114,28 @@ BEGIN
|
|||
IF NOT vIsFound THEN
|
||||
INSERT INTO tmp.ekt
|
||||
SELECT id
|
||||
FROM edi.ektRecent e
|
||||
WHERE e.deliveryNumber
|
||||
= MID(vBarcode, 4, 13)
|
||||
FROM ektRecent e
|
||||
WHERE e.deliveryNumber = MID(vBarcode, 4, 13)
|
||||
AND e.deliveryNumber > 0;
|
||||
|
||||
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
||||
END IF;
|
||||
|
||||
-- Solo campo agj
|
||||
IF NOT vIsFound THEN
|
||||
INSERT INTO tmp.ekt
|
||||
SELECT id
|
||||
FROM ektRecent
|
||||
WHERE agj = vShortAgj;
|
||||
|
||||
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
||||
END IF;
|
||||
|
||||
END CASE;
|
||||
|
||||
IF vIsFound THEN
|
||||
UPDATE ekt e
|
||||
JOIN tmp.ekt t ON t.ektFk = e.id
|
||||
JOIN tmp.ekt t ON t.ektFk = e.id
|
||||
SET e.scanned = TRUE;
|
||||
END IF;
|
||||
END$$
|
||||
|
|
Loading…
Reference in New Issue