admin/src/Oms.Application/Services/Orders/OrderService.OperationLog.cs
zzh 2b0158acb4
All checks were successful
Build and Deploy / deploy (push) Successful in 1m0s
feat: 运单操作日志 MVP,记录编辑/件重尺/重算/排货字段变更
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-09 17:32:33 +08:00

56 lines
1.9 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Oms.Application.Dtos.Orders;
using Oms.Domain.OrdersAggregate.Entities;
namespace Oms.Application.Services.Orders;
public partial class OrderService
{
private OrderOperationLogWriter OperationLogWriter =>
LazyServiceProvider.GetRequiredService<OrderOperationLogWriter>();
/// <summary>
/// 运单操作日志列表(按时间倒序)。
/// </summary>
[HttpGet("/order/operation-log/list")]
public async Task<OrderOperationLogListOutput> GetOperationLogListAsync([FromQuery] int orderId)
{
await GetOrderOrThrowAsync(orderId);
return await OperationLogWriter.ListByOrderIdAsync(orderId);
}
private async Task<Dictionary<string, string?>> CaptureOrderAuditSnapshotAsync(
Order order,
bool includeParties = false,
bool includeWeights = false,
bool includeFees = false)
{
var parts = new List<IReadOnlyDictionary<string, string?>>
{
OrderOperationLogSnapshot.CaptureOrder(order)
};
if (includeParties)
{
var senders = await OrderRepository.GetSendersByOrderIdsAsync([order.Id]);
var recipients = await OrderRepository.GetRecipientsByOrderIdsAsync([order.Id]);
parts.Add(OrderOperationLogSnapshot.CaptureSender(senders.FirstOrDefault()));
parts.Add(OrderOperationLogSnapshot.CaptureReceiver(recipients.FirstOrDefault()));
}
if (includeWeights)
{
var weights = await OrderRepository.GetWeightsByOrderIdsAsync([order.Id]);
parts.Add(OrderOperationLogSnapshot.CaptureWeights(weights));
}
if (includeFees)
{
var fees = await OrderRepository.GetFeesByOrderIdsAsync([order.Id]);
parts.Add(OrderOperationLogSnapshot.CaptureFeeTotals(fees));
}
return OrderOperationLogSnapshot.Merge(parts.ToArray());
}
}