60 lines
1.5 KiB
JavaScript
Executable File
60 lines
1.5 KiB
JavaScript
Executable File
const db = require(`../config/dbMysqlConn`);
|
|
|
|
const OrderStatusModels = (module.exports = {
|
|
GetList: async function () {
|
|
return new Promise((resolve, reject) => {
|
|
const query = `
|
|
SELECT
|
|
tv.id,
|
|
tv.name,
|
|
tv.is_in_ord,
|
|
tv.ord_id,
|
|
tv.ord_code,
|
|
tv.device_id,
|
|
tz.boundary_latlngs AS pck_latlng,
|
|
tz.boundary_type AS pck_type,
|
|
tz.boundary_radius AS pck_radius,
|
|
tz2.boundary_latlngs AS drp_latlng,
|
|
tz2.boundary_type AS drp_type,
|
|
tz2.boundary_radius AS drp_radius,
|
|
to2.status,
|
|
tgt.latitude,
|
|
tgt.longitude,
|
|
tgt.crt_format
|
|
FROM
|
|
t_vehicles tv
|
|
LEFT JOIN t_orders to2 ON to2.code = tv.ord_code
|
|
INNER JOIN (
|
|
SELECT tg1.device_id, tg1.latitude, tg1.longitude, tg1.crt_format
|
|
FROM t_gps_tracks tg1
|
|
INNER JOIN (
|
|
SELECT device_id, MAX(crt_format) AS max_crt
|
|
FROM t_gps_tracks
|
|
WHERE action = 'location'
|
|
GROUP BY device_id
|
|
) tg2 ON tg1.device_id = tg2.device_id AND tg1.crt_format = tg2.max_crt
|
|
WHERE tg1.action = 'location'
|
|
) tgt ON tgt.device_id = tv.device_id
|
|
LEFT JOIN t_orders_pck_drop topd ON topd.ord_code = tv.ord_code
|
|
LEFT JOIN t_zones tz ON tz.id = topd.pck_id
|
|
LEFT JOIN t_zones tz2 ON tz2.id = topd.drop_id
|
|
WHERE
|
|
tv.is_in_ord = 1
|
|
AND tv.ord_id != 0
|
|
AND tv.ord_code IS NOT NULL
|
|
ORDER BY tgt.crt_format DESC;
|
|
`;
|
|
|
|
db.query(query, (err, result) => {
|
|
if (err) {
|
|
return reject(err);
|
|
}
|
|
resolve({
|
|
rowCount: result.length,
|
|
rows: result,
|
|
});
|
|
});
|
|
});
|
|
},
|
|
});
|