Revert "refactor: refs #4502 Deleted zoneEstimatedDelivery"
gitea/salix/pipeline/head This commit looks good Details

This reverts commit bfd6e1f398.
This commit is contained in:
Guillermo Bonet 2023-11-17 07:17:29 +01:00
parent bfd6e1f398
commit 2f611391b9
4 changed files with 105 additions and 112 deletions

View File

@ -163,14 +163,17 @@ module.exports = Self => {
const stmts = [];
let stmt;
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.filter');
stmts.push(`SET @_optimizer_search_depth = @@optimizer_search_depth`);
stmts.push(`SET SESSION optimizer_search_depth = 0`);
stmt = new ParameterizedSQL(`
CREATE OR REPLACE TEMPORARY TABLE tmp.filter
stmt = new ParameterizedSQL(
`CREATE TEMPORARY TABLE tmp.filter
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT t.id,
SELECT
t.id,
t.shipped,
CAST(DATE(t.shipped) AS CHAR) AS shippedDate,
t.nickname,
@ -180,27 +183,27 @@ module.exports = Self => {
t.clientFk,
t.totalWithoutVat,
t.totalWithVat,
io.id invoiceOutId,
io.id AS invoiceOutId,
a.provinceFk,
p.name province,
w.name warehouse,
am.name agencyMode,
am.id agencyModeFk,
st.name state,
wk.lastName salesPerson,
ts.stateFk stateFk,
ts.alertLevel alertLevel,
ts.code alertLevelCode,
u.name userName,
p.name AS province,
w.name AS warehouse,
am.name AS agencyMode,
am.id AS agencyModeFk,
st.name AS state,
wk.lastName AS salesPerson,
ts.stateFk AS stateFk,
ts.alertLevel AS alertLevel,
ts.code AS alertLevelCode,
u.name AS userName,
c.salesPersonFk,
c.credit,
z.hour zoneLanding,
z.name zoneName,
z.id zoneFk,
z.hour AS zoneLanding,
z.name AS zoneName,
z.id AS zoneFk,
st.classColor,
TIME_FORMAT(t.shipped, '%H:%i') preparationHour,
TIME_FORMAT(z.hour, '%H:%i') theoreticalhour,
TIME_FORMAT(zed.etc, '%H:%i') practicalHour
TIME_FORMAT(t.shipped, '%H:%i') AS preparationHour,
TIME_FORMAT(z.hour, '%H:%i') AS theoreticalhour,
TIME_FORMAT(zed.etc, '%H:%i') AS practicalHour
FROM ticket t
LEFT JOIN invoiceOut io ON t.refFk = io.ref
LEFT JOIN zone z ON z.id = t.zoneFk
@ -213,33 +216,7 @@ module.exports = Self => {
LEFT JOIN client c ON c.id = t.clientFk
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
LEFT JOIN account.user u ON u.id = wk.id
LEFT JOIN (
SELECT zoneFk,
CAST(zoneHour + remainingVolume * 60 / speed AS time) etc
FROM (
SELECT t.zoneFk,
IFNULL(zc.hour, z.hour) zoneHour,
SUM(IF(al.hasToRecalcPrice, sv.volume, 0)) remainingVolume,
GREATEST(IFNULL(lhp.m3, 0), IFNULL(dl.minSpeed, 0)) speed
FROM ticket t
JOIN ticketStateToday tst ON tst.ticket = t.id
JOIN state s ON s.id = tst.state
JOIN saleVolume sv ON sv.ticketFk = t.id
LEFT JOIN lastHourProduction lhp ON lhp.warehouseFk = t.warehouseFk
JOIN warehouse w ON w.id = t.warehouseFk
JOIN warehouseAlias wa ON wa.id = w.aliasFk
STRAIGHT_JOIN zone z ON z.id = t.zoneFk
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
AND zc.dated = util.VN_CURDATE()
LEFT JOIN cache.departure_limit dl ON dl.warehouse_id = t.warehouseFk
AND dl.fecha = util.VN_CURDATE()
JOIN alertLevel al ON al.id = s.alertLevel
WHERE w.hasProduction
AND DATE(t.shipped) = util.VN_CURDATE()
GROUP BY t.zoneFk
) sub
) zed ON zed.zoneFk = t.zoneFk`
);
LEFT JOIN zoneEstimatedDelivery zed ON zed.zoneFk = t.zoneFk`);
if (args.orderFk) {
stmt.merge({

View File

@ -140,11 +140,12 @@ module.exports = Self => {
const stmts = [];
let stmt;
stmt = new ParameterizedSQL(`
CREATE OR REPLACE TEMPORARY TABLE tmp.filter
stmt = new ParameterizedSQL(
`CREATE OR REPLACE TEMPORARY TABLE tmp.filter
(INDEX (id))
ENGINE = MEMORY
SELECT o.id,
SELECT
o.id,
o.total,
o.date_send landed,
o.date_make created,
@ -162,7 +163,7 @@ module.exports = Self => {
zed.zoneFk,
zed.hourTheoretical,
zed.hourEffective,
am.name agencyName
am.name AS agencyName
FROM hedera.order o
LEFT JOIN address a ON a.id = o.address_id
LEFT JOIN agencyMode am ON am.id = o.agency_id
@ -172,39 +173,7 @@ module.exports = Self => {
LEFT JOIN company co ON co.id = o.company_id
LEFT JOIN orderTicket ot ON ot.orderFk = o.id
LEFT JOIN ticket t ON t.id = ot.ticketFk
LEFT JOIN (
SELECT zoneFk,
CAST(
util.VN_CURDATE() +
INTERVAL HOUR(zoneHour) * 60 + MINUTE(zoneHour) MINUTE
AS time
) hourTheoretical,
CAST(zoneHour + remainingVolume * 60 / speed AS time) hourEffective
FROM (
SELECT t.zoneFk,
IFNULL(zc.hour, z.hour) zoneHour,
CAST(SUM(sv.volume) AS DECIMAL(5, 1)) totalVolume,
SUM(IF(al.hasToRecalcPrice, sv.volume, 0)) remainingVolume,
GREATEST(IFNULL(lhp.m3, 0), IFNULL(dl.minSpeed, 0)) speed
FROM ticket t
JOIN ticketStateToday tst ON tst.ticket = t.id
JOIN state s ON s.id = tst.state
JOIN saleVolume sv ON sv.ticketFk = t.id
LEFT JOIN lastHourProduction lhp ON lhp.warehouseFk = t.warehouseFk
JOIN warehouse w ON w.id = t.warehouseFk
JOIN warehouseAlias wa ON wa.id = w.aliasFk
STRAIGHT_JOIN zone z ON z.id = t.zoneFk
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
AND zc.dated = util.VN_CURDATE()
LEFT JOIN cache.departure_limit dl ON dl.warehouse_id = t.warehouseFk
AND dl.fecha = util.VN_CURDATE()
JOIN alertLevel al ON al.id = s.alertLevel
WHERE w.hasProduction
AND DATE(t.shipped) = util.VN_CURDATE()
GROUP BY t.zoneFk
) sub
) zed ON zed.zoneFk = t.zoneFk
`);
LEFT JOIN zoneEstimatedDelivery zed ON zed.zoneFk = t.zoneFk`);
stmt.merge(conn.makeWhere(filter.where));
stmt.merge(`GROUP BY id`);

View File

@ -35,6 +35,9 @@
"ZoneWarehouse": {
"dataSource": "vn"
},
"ZoneEstimatedDelivery": {
"dataSource": "vn"
},
"ZoneLog": {
"dataSource": "vn"
}

View File

@ -0,0 +1,44 @@
{
"name": "ZoneEstimatedDelivery",
"base": "VnModel",
"options": {
"mysql": {
"table": "zoneEstimatedDelivery"
}
},
"properties": {
"zoneFk": {
"id": true,
"type": "number"
},
"hourTheoretical": {
"type": "date"
},
"totalVolume": {
"type": "number"
},
"remainingVolume": {
"type": "number"
},
"speed": {
"type": "number"
},
"hourEffective": {
"type": "date"
},
"minutesLess": {
"type": "date"
},
"etc": {
"type": "date"
}
},
"relations": {
"zone": {
"type": "belongsTo",
"model": "Zone",
"foreignKey": "zoneFk"
}
}
}