Merge pull request '2956 - Fix for extra community report' (#659) from 2956-extraCommunity_hotfix into master
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #659
This commit is contained in:
Carlos Jimenez Ruiz 2021-06-16 11:16:09 +00:00
commit da2d62899f
4 changed files with 45 additions and 60 deletions

View File

@ -24,7 +24,7 @@ module.exports = {
* *
* @return {Object} - Pool connection * @return {Object} - Pool connection
*/ */
getConnection(name) { getConnection(name = 'default') {
let pool = this.pool; let pool = this.pool;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
pool.getConnection(name, function(error, connection) { pool.getConnection(name, function(error, connection) {

View File

@ -15,22 +15,11 @@ module.exports = {
continent: this.continent continent: this.continent
}; };
const connection = await db.pool.getConnection(); const travels = await this.fetchTravels(args);
const travelIds = travels.map(travel => travel.id);
await this.fetchTravels(args, connection); const entries = await this.fetchEntries(travelIds);
const travels = await this.rawSql(`
SELECT * FROM tmp.travel`, connection);
const entries = await this.fetchEntries(connection);
await this.rawSql(`
DROP TEMPORARY TABLE
tmp.travel`, connection);
await connection.release();
const map = new Map(); const map = new Map();
for (let travel of travels) for (let travel of travels)
map.set(travel.id, travel); map.set(travel.id, travel);
@ -71,7 +60,7 @@ module.exports = {
} }
}, },
methods: { methods: {
fetchTravels(args, connection) { fetchTravels(args) {
const where = db.buildWhere(args, (key, value) => { const where = db.buildWhere(args, (key, value) => {
switch (key) { switch (key) {
case 'shippedFrom': case 'shippedFrom':
@ -91,14 +80,11 @@ module.exports = {
query = db.merge(query, where); query = db.merge(query, where);
query = db.merge(query, 'GROUP BY t.id'); query = db.merge(query, 'GROUP BY t.id');
return this.rawSql(query, connection); return this.rawSql(query);
}, },
fetchEntries(connection) { fetchEntries(travelIds) {
let query = this.getSqlFromDef('entries'); return this.rawSqlFromDef('entries', [travelIds]);
query = db.merge(query, 'GROUP BY e.id');
return this.rawSql(query, connection);
} }
}, },
components: { components: {

View File

@ -1,15 +1,17 @@
SELECT SELECT
e.id, e.id,
e.travelFk, e.travelFk,
e.ref, e.ref,
s.name AS supplierName, s.name AS supplierName,
SUM(b.stickers) AS stickers, SUM(b.stickers) AS stickers,
CAST(SUM(i.density * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000 ) as DECIMAL(10,0)) as loadedKg, CAST(SUM(i.density * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000 ) as DECIMAL(10,0)) as loadedKg,
CAST(SUM(167.5 * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000 ) as DECIMAL(10,0)) as volumeKg CAST(SUM(167.5 * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000 ) as DECIMAL(10,0)) as volumeKg
FROM tmp.travel t FROM travel t
JOIN entry e ON e.travelFk = t.id JOIN entry e ON e.travelFk = t.id
JOIN buy b ON b.entryFk = e.id JOIN buy b ON b.entryFk = e.id
JOIN packaging pkg ON pkg.id = b.packageFk JOIN packaging pkg ON pkg.id = b.packageFk
JOIN item i ON i.id = b.itemFk JOIN item i ON i.id = b.itemFk
JOIN itemType it ON it.id = i.typeFk JOIN itemType it ON it.id = i.typeFk
JOIN supplier s ON s.id = e.supplierFk JOIN supplier s ON s.id = e.supplierFk
WHERE t.id IN(?)
GROUP BY e.id

View File

@ -1,24 +1,21 @@
CREATE TEMPORARY TABLE tmp.travel SELECT
(INDEX (id)) t.id,
ENGINE = MEMORY t.ref,
SELECT t.shipped,
t.id, t.landed,
t.ref, t.kg,
t.shipped, SUM(b.stickers) AS stickers,
t.landed, CAST(SUM(i.density * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000 ) as DECIMAL(10,0)) as loadedKg,
t.kg, CAST(SUM(167.5 * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000 ) as DECIMAL(10,0)) as volumeKg
SUM(b.stickers) AS stickers, FROM travel t
CAST(SUM(i.density * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000 ) as DECIMAL(10,0)) as loadedKg, LEFT JOIN supplier s ON s.id = t.cargoSupplierFk
CAST(SUM(167.5 * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000 ) as DECIMAL(10,0)) as volumeKg LEFT JOIN entry e ON e.travelFk = t.id
FROM travel t LEFT JOIN buy b ON b.entryFk = e.id
LEFT JOIN supplier s ON s.id = t.cargoSupplierFk LEFT JOIN packaging pkg ON pkg.id = b.packageFk
LEFT JOIN entry e ON e.travelFk = t.id LEFT JOIN item i ON i.id = b.itemFk
LEFT JOIN buy b ON b.entryFk = e.id LEFT JOIN itemType it ON it.id = i.typeFk
LEFT JOIN packaging pkg ON pkg.id = b.packageFk JOIN warehouse w ON w.id = t.warehouseInFk
LEFT JOIN item i ON i.id = b.itemFk JOIN warehouse wo ON wo.id = t.warehouseOutFk
LEFT JOIN itemType it ON it.id = i.typeFk JOIN country c ON c.id = wo.countryFk
JOIN warehouse w ON w.id = t.warehouseInFk LEFT JOIN continent cnt ON cnt.id = c.continentFk
JOIN warehouse wo ON wo.id = t.warehouseOutFk JOIN agencyMode am ON am.id = t.agencyFk
JOIN country c ON c.id = wo.countryFk
LEFT JOIN continent cnt ON cnt.id = c.continentFk
JOIN agencyMode am ON am.id = t.agencyFk