refactor: refs #7398 Refactor and change ekt_scan #2494

Merged
guillermo merged 2 commits from 7398-ektScan into dev 2024-05-22 06:31:07 +00:00
1 changed files with 43 additions and 32 deletions

View File

@ -23,42 +23,39 @@ BEGIN
DECLARE vXtraLongAgj INT; DECLARE vXtraLongAgj INT;
DECLARE vDefaultKlo INT; DECLARE vDefaultKlo INT;
SELECT SELECT usefulAuctionLeftSegmentLength,
ec.usefulAuctionLeftSegmentLength, standardBarcodeLength,
ec.standardBarcodeLength, floridayBarcodeLength,
ec.floridayBarcodeLength, floramondoBarcodeLength,
ec.floramondoBarcodeLength, defaultKlo
ec.defaultKlo INTO vUsefulAuctionLeftSegmentLength,
INTO
vUsefulAuctionLeftSegmentLength,
vStandardBarcodeLength, vStandardBarcodeLength,
vFloridayBarcodeLength, vFloridayBarcodeLength,
vFloramondoBarcodeLength, vFloramondoBarcodeLength,
vDefaultKlo vDefaultKlo
FROM edi.ektConfig ec; FROM ektConfig;
DROP TEMPORARY TABLE IF EXISTS tmp.ekt; CREATE OR REPLACE TEMPORARY TABLE tmp.ekt
CREATE TEMPORARY TABLE tmp.ekt
ENGINE = MEMORY ENGINE = MEMORY
SELECT id ektFk FROM ekt LIMIT 0; SELECT id ektFk FROM ekt LIMIT 0;
CASE CASE
WHEN LENGTH(vBarcode) <= vFloridayBarcodeLength THEN WHEN LENGTH(vBarcode) <= vFloridayBarcodeLength THEN
INSERT INTO tmp.ekt INSERT INTO tmp.ekt
SELECT id SELECT id
FROM edi.ektRecent e FROM ektRecent e
WHERE e.cps = vBarcode WHERE e.cps = vBarcode
OR e.batchNumber = vBarcode; OR e.batchNumber = vBarcode;
WHEN LENGTH(vBarcode) = vFloramondoBarcodeLength THEN WHEN LENGTH(vBarcode) = vFloramondoBarcodeLength THEN
INSERT INTO tmp.ekt INSERT INTO tmp.ekt
SELECT e.id SELECT e.id
FROM edi.ektRecent e FROM ektRecent e
WHERE e.pro = MID(vBarcode,2,6) 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 ELSE
SET vBarcode = LPAD(vBarcode,vStandardBarcodeLength,'0'); SET vBarcode = LPAD(vBarcode, vStandardBarcodeLength, '0');
SET vAuction = MID(vBarcode, 1, 3); SET vAuction = MID(vBarcode, 1, 3);
SET vKlo = MID(vBarcode, 4, 2); SET vKlo = MID(vBarcode, 4, 2);
SET vFec = MAKEDATE(YEAR(util.VN_CURDATE()), MID(vBarcode, 6, 3)); SET vFec = MAKEDATE(YEAR(util.VN_CURDATE()), MID(vBarcode, 6, 3));
@ -69,21 +66,23 @@ BEGIN
-- Clásico de subasta -- Clásico de subasta
-- Trade standard -- Trade standard
-- Trade que construye como la subasta -- 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 INSERT INTO tmp.ekt
SELECT id SELECT id
FROM ekt FROM ekt
WHERE fec >= vFec - INTERVAL 1 DAY WHERE fec >= vFec - INTERVAL 1 DAY
AND (( AND (
vKlo = vDefaultKlo (vKlo = vDefaultKlo
AND (klo = vKlo OR klo IS NULL OR klo = 0) AND (klo = vKlo OR klo IS NULL OR klo = 0)
AND agj IN (vShortAgj, vLongAgj, vXtraLongAgj)) AND agj IN (vShortAgj, vLongAgj, vXtraLongAgj)
OR (klo = vKlo ) OR (
klo = vKlo
AND auction = vAuction AND auction = vAuction
AND agj = vShortAgj) AND agj = vShortAgj
)
) )
ORDER BY agj DESC, fec DESC ORDER BY agj DESC, fec DESC
LIMIT 1; LIMIT 1;
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound; SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
@ -91,9 +90,11 @@ BEGIN
IF NOT vIsFound THEN IF NOT vIsFound THEN
INSERT INTO tmp.ekt INSERT INTO tmp.ekt
SELECT id SELECT id
FROM edi.ektRecent e FROM ektRecent e
WHERE e.batchNumber WHERE e.batchNumber = LEFT(
= LEFT(vBarcode,vUsefulAuctionLeftSegmentLength) vBarcode,
vUsefulAuctionLeftSegmentLength
)
AND e.batchNumber > 0; AND e.batchNumber > 0;
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound; SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
@ -103,7 +104,7 @@ BEGIN
IF NOT vIsFound THEN IF NOT vIsFound THEN
INSERT INTO tmp.ekt INSERT INTO tmp.ekt
SELECT id SELECT id
FROM edi.ektRecent e FROM ektRecent e
WHERE e.putOrderFk = vBarcode; WHERE e.putOrderFk = vBarcode;
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound; SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
@ -113,18 +114,28 @@ BEGIN
IF NOT vIsFound THEN IF NOT vIsFound THEN
INSERT INTO tmp.ekt INSERT INTO tmp.ekt
SELECT id SELECT id
FROM edi.ektRecent e FROM ektRecent e
WHERE e.deliveryNumber WHERE e.deliveryNumber = MID(vBarcode, 4, 13)
= MID(vBarcode, 4, 13)
AND e.deliveryNumber > 0; AND e.deliveryNumber > 0;
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound; SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
END IF; 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; END CASE;
IF vIsFound THEN IF vIsFound THEN
UPDATE ekt e 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; SET e.scanned = TRUE;
END IF; END IF;
END$$ END$$