feat: add PriceAdjustmentLine repository to PriceAdjustmentService and optimize pending item query
This commit is contained in:
@@ -25,6 +25,7 @@ public sealed class PriceAdjustmentService : IPriceAdjustmentService
|
|||||||
public const string ApprovalNavCode = "products.price-adjustments";
|
public const string ApprovalNavCode = "products.price-adjustments";
|
||||||
|
|
||||||
private readonly IRepository<PriceAdjustment> _adjustments;
|
private readonly IRepository<PriceAdjustment> _adjustments;
|
||||||
|
private readonly IRepository<PriceAdjustmentLine> _lines;
|
||||||
private readonly IRepository<Item> _items;
|
private readonly IRepository<Item> _items;
|
||||||
private readonly IRepository<ItemPriceHistory> _history;
|
private readonly IRepository<ItemPriceHistory> _history;
|
||||||
private readonly IRepository<User> _users;
|
private readonly IRepository<User> _users;
|
||||||
@@ -36,11 +37,13 @@ public sealed class PriceAdjustmentService : IPriceAdjustmentService
|
|||||||
private readonly IUnitOfWork _uow;
|
private readonly IUnitOfWork _uow;
|
||||||
|
|
||||||
public PriceAdjustmentService(
|
public PriceAdjustmentService(
|
||||||
IRepository<PriceAdjustment> adjustments, IRepository<Item> items, IRepository<ItemPriceHistory> history,
|
IRepository<PriceAdjustment> adjustments, IRepository<PriceAdjustmentLine> lines, IRepository<Item> items,
|
||||||
IRepository<User> users, IRepository<ApprovalConfig> config, IApprovalService approvals,
|
IRepository<ItemPriceHistory> history, IRepository<User> users, IRepository<ApprovalConfig> config,
|
||||||
INotificationService notifications, INumberSequenceService numbers, ICurrentUser currentUser, IUnitOfWork uow)
|
IApprovalService approvals, INotificationService notifications, INumberSequenceService numbers,
|
||||||
|
ICurrentUser currentUser, IUnitOfWork uow)
|
||||||
{
|
{
|
||||||
_adjustments = adjustments;
|
_adjustments = adjustments;
|
||||||
|
_lines = lines;
|
||||||
_items = items;
|
_items = items;
|
||||||
_history = history;
|
_history = history;
|
||||||
_users = users;
|
_users = users;
|
||||||
@@ -92,10 +95,14 @@ public sealed class PriceAdjustmentService : IPriceAdjustmentService
|
|||||||
|
|
||||||
var ids = request.Lines.Select(l => l.ItemId).ToList();
|
var ids = request.Lines.Select(l => l.ItemId).ToList();
|
||||||
var items = await _items.Query().Where(i => ids.Contains(i.ItemId)).ToDictionaryAsync(i => i.ItemId, ct);
|
var items = await _items.Query().Where(i => ids.Contains(i.ItemId)).ToDictionaryAsync(i => i.ItemId, ct);
|
||||||
var pendingItemIds = await _adjustments.Query().AsNoTracking()
|
// Queried from the line side (not PriceAdjustment.Lines via SelectMany) so this stays a
|
||||||
.Where(p => p.Status == PriceAdjustmentStatus.PendingApproval || p.Status == PriceAdjustmentStatus.PendingSecondApproval)
|
// plain join — a SelectMany over a to-many navigation generates a CROSS APPLY that
|
||||||
.SelectMany(p => p.Lines.Select(l => new { l.ItemId, p.DocNo }))
|
// Pomelo/MySQL can't translate (it works fine against PostgreSQL, which is what this
|
||||||
.Where(x => ids.Contains(x.ItemId))
|
// predates — 2026-10-16 MySQL-port regression).
|
||||||
|
var pendingItemIds = await _lines.Query().AsNoTracking()
|
||||||
|
.Where(l => ids.Contains(l.ItemId)
|
||||||
|
&& (l.PriceAdjustment!.Status == PriceAdjustmentStatus.PendingApproval || l.PriceAdjustment!.Status == PriceAdjustmentStatus.PendingSecondApproval))
|
||||||
|
.Select(l => new { l.ItemId, DocNo = l.PriceAdjustment!.DocNo })
|
||||||
.ToListAsync(ct);
|
.ToListAsync(ct);
|
||||||
|
|
||||||
var lines = new List<PriceAdjustmentLine>();
|
var lines = new List<PriceAdjustmentLine>();
|
||||||
|
|||||||
Reference in New Issue
Block a user