salix/modules/route/back/methods/roadmapStop/getPalletMatchState.js

63 lines
2.5 KiB
JavaScript
Raw Normal View History

2024-06-03 16:39:11 +00:00
module.exports = Self => {
Self.remoteMethod('getPalletMatchState', {
2024-07-02 06:39:42 +00:00
description: 'Get list of pallet from roadMapStop with true or false if state is matched',
2024-06-03 16:39:11 +00:00
accessType: 'WRITE',
accepts: [{
arg: 'roadMapStopFk',
type: 'number',
required: true,
description: 'The roadmapFk id'
},
{
arg: 'state',
type: 'string',
required: true,
description: 'State code'
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/getPalletMatchState`,
verb: 'GET'
}
});
Self.getPalletMatchState = async(roadMapStopFk, state, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const result = await Self.rawSql(`
WITH tPallet AS(
2024-07-02 06:39:42 +00:00
SELECT ep.id pallet, e.id expedition, e.stateTypeFk
2024-06-03 16:39:11 +00:00
FROM vn.expeditionPallet ep
JOIN vn.expeditionScan es ON es.palletFk = ep.id
JOIN expedition e ON e.id = es.expeditionFk
WHERE ep.truckFk = ?
),totalPalletExpedition AS(
SELECT t.*, COUNT(expedition) totalPalletExpedition
FROM tPallet t
GROUP BY expedition
),totalPalletExpeditionCode AS(
SELECT t.*, COUNT(expedition) totalPalletExpeditionCode
FROM tPallet t
JOIN vn.expeditionStateType est ON est.id = t.stateTypeFk
WHERE code = ?
GROUP BY expedition
)
2024-07-02 06:39:42 +00:00
SELECT t.pallet,
tpe.totalPalletExpedition = tpec.totalPalletExpeditionCode hasMatchStateCode
2024-06-03 16:39:11 +00:00
FROM tPallet t
LEFT JOIN totalPalletExpedition tpe ON tpe.expedition = t.expedition
LEFT JOIN totalPalletExpeditionCode tpec ON tpec.expedition = t.expedition
GROUP BY t.pallet;`,
[roadMapStopFk, state],
myOptions);
return result;
};
};