fix(hrms): fallback location sites when inventory schema is unavailable
Prod DB users often lack SELECT on inventory.location_site. When that join fails, load distinct location sites from hrms.employee instead of failing the whole dropdown. Site names fall back to Site {id} when inventory titles are unavailable.
main
parent
ffaede8a10
commit
252e1b0b80
|
|
@ -20,15 +20,38 @@ public sealed class HrmsEmployeeService
|
||||||
|
|
||||||
public async Task<IReadOnlyList<LocationSite>> GetLocationSitesAsync(CancellationToken cancellationToken)
|
public async Task<IReadOnlyList<LocationSite>> GetLocationSitesAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
const string sql = """
|
const string inventoryTitleSql = """
|
||||||
SELECT DISTINCT e.location_site_id,
|
SELECT DISTINCT e.location_site_id,
|
||||||
COALESCE(ls.title, CONCAT('Site ', e.location_site_id)) AS site_title
|
COALESCE(ls.title, CONCAT('Site ', e.location_site_id)) AS site_title
|
||||||
FROM hrms.employee e
|
FROM hrms.employee e
|
||||||
LEFT JOIN inventory.location_site ls ON ls.id = e.location_site_id
|
LEFT JOIN inventory.location_site ls ON ls.id = e.location_site_id
|
||||||
WHERE e.location_site_id IS NOT NULL
|
WHERE e.location_site_id IS NOT NULL AND e.location_site_id > 0
|
||||||
ORDER BY site_title
|
ORDER BY site_title
|
||||||
""";
|
""";
|
||||||
return await QuerySitesAsync(sql, null, cancellationToken);
|
try
|
||||||
|
{
|
||||||
|
var sites = await QuerySitesAsync(inventoryTitleSql, null, cancellationToken);
|
||||||
|
if (sites.Count > 0)
|
||||||
|
{
|
||||||
|
AppLogger.Info($"[HRMS] Loaded {sites.Count} location site(s) via inventory.location_site.");
|
||||||
|
return sites;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
AppLogger.Warning("Location site load via inventory.location_site failed; falling back to employee-derived sites. " + ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
const string employeeFallbackSql = """
|
||||||
|
SELECT DISTINCT e.location_site_id,
|
||||||
|
CONCAT('Site ', e.location_site_id) AS site_title
|
||||||
|
FROM hrms.employee e
|
||||||
|
WHERE e.location_site_id IS NOT NULL AND e.location_site_id > 0
|
||||||
|
ORDER BY e.location_site_id
|
||||||
|
""";
|
||||||
|
var fallbackSites = await QuerySitesAsync(employeeFallbackSql, null, cancellationToken);
|
||||||
|
AppLogger.Info($"[HRMS] Loaded {fallbackSites.Count} location site(s) from hrms.employee fallback.");
|
||||||
|
return fallbackSites;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IReadOnlyList<HrmsDepartment>> GetActiveDepartmentsBySiteAsync(long siteId, CancellationToken cancellationToken)
|
public async Task<IReadOnlyList<HrmsDepartment>> GetActiveDepartmentsBySiteAsync(long siteId, CancellationToken cancellationToken)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue