Truck inquiry: match legacy searchTruckDistribution exactly

- Status and company come from the first (oldest) permit row of the truck, as in the legacy unordered query
- Truck locations listed in allowed-list order, unknown locations kept as empty names

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Samer Salameh 2026-11-18 14:25:54 +03:00
parent 0eb83d3bb5
commit e487c05248
2 changed files with 5 additions and 3 deletions

View File

@ -367,7 +367,8 @@ public sealed class DistributionService(
? await destinations.GetTruckDestinationsAsync(tn, ct) ? await destinations.GetTruckDestinationsAsync(tn, ct)
: company is long c ? await destinations.GetCompanyLocationsAsync(c, ct) : []; : company is long c ? await destinations.GetCompanyLocationsAsync(c, ct) : [];
var names = await repo.GetLocationNamesAsync(locations, ct); var names = await repo.GetLocationNamesAsync(locations, ct);
result.CompanyLocations = string.Concat(names.Select(n => " - " + n.Name)); // legacy loops the allowed ids in list order and appends " - " + name (empty when the location is unknown)
result.CompanyLocations = string.Concat(locations.Select(id => " - " + names.FirstOrDefault(n => n.Id == id).Name));
var orders = await repo.GetActiveOrdersInWindowAsync(new ShiftWindow var orders = await repo.GetActiveOrdersInWindowAsync(new ShiftWindow
{ {

View File

@ -405,14 +405,15 @@ internal sealed class DistributionRepository(IDbSession session, ILogger<Distrib
public long? Scrn { get; set; } public long? Scrn { get; set; }
} }
// legacy searchTruckDistribution reads the FIRST row of the unordered qry_truckDetails (oldest permit), not the latest
public Task<string?> GetTruckLatestStatusCaptionAsync(string tn, CancellationToken ct = default) => QueryFirstAsync<string>(""" public Task<string?> GetTruckLatestStatusCaptionAsync(string tn, CancellationToken ct = default) => QueryFirstAsync<string>("""
SELECT s.description FROM PERMITS p, STATUS s SELECT s.description FROM PERMITS p, STATUS s
WHERE p.domain = 'GN' AND p.tn = :Tn AND p.shipmentstatuscode = s.code AND s.domain = 'GN' ORDER BY p.id DESC WHERE p.domain = 'GN' AND p.tn = :Tn AND p.shipmentstatuscode = s.code AND s.domain = 'GN' ORDER BY p.id
""", new { Tn = tn }, ct); """, new { Tn = tn }, ct);
public Task<long?> GetTruckLatestCompanyAsync(string tn, CancellationToken ct = default) => QueryFirstAsync<long?>(""" public Task<long?> GetTruckLatestCompanyAsync(string tn, CancellationToken ct = default) => QueryFirstAsync<long?>("""
SELECT p.companycode FROM PERMITS p, STATUS s SELECT p.companycode FROM PERMITS p, STATUS s
WHERE p.domain = 'GN' AND p.tn = :Tn AND p.shipmentstatuscode = s.code AND s.domain = 'GN' ORDER BY p.id DESC WHERE p.domain = 'GN' AND p.tn = :Tn AND p.shipmentstatuscode = s.code AND s.domain = 'GN' ORDER BY p.id
""", new { Tn = tn }, ct); """, new { Tn = tn }, ct);
public Task<IReadOnlyList<OpenOrderBrief>> GetActiveOrdersInWindowAsync(ShiftWindow window, CancellationToken ct = default) => public Task<IReadOnlyList<OpenOrderBrief>> GetActiveOrdersInWindowAsync(ShiftWindow window, CancellationToken ct = default) =>