From 8376e03aa9640632f19a155023fba98fe3c350e6 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Wed, 18 Nov 2026 11:23:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=88=9B=E5=BB=BA=E4=BB=A3?= =?UTF-8?q?=E5=8F=91=E5=BF=85=E7=BB=91=EF=BC=8C=E8=A7=A3=E7=BB=91=E5=9B=9E?= =?UTF-8?q?=E9=80=80=E7=9B=B4=E5=8F=91=E5=B9=B6=E8=A1=A5=E4=BA=8B=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 绑定保存/清空/扣减与删单走事务;工作台与 status-counts 不再统计 pendingBind。 Co-authored-by: Cursor --- .../Orders/FulfillWorkplaceStatsOutput.cs | 2 +- .../Services/Orders/OrderService.StockBind.cs | 50 +++++++++++++------ .../Services/Orders/OrderService.Workplace.cs | 3 +- .../Services/Orders/OrderService.cs | 5 ++ .../Orders/PlatformStoreOrderService.cs | 38 ++++++++++---- .../Consts/FulfillmentProgressCodes.cs | 4 +- .../Orders/OrderRepository.cs | 2 +- 7 files changed, 75 insertions(+), 29 deletions(-) diff --git a/src/Oms.Application/Dtos/Orders/FulfillWorkplaceStatsOutput.cs b/src/Oms.Application/Dtos/Orders/FulfillWorkplaceStatsOutput.cs index e269cb6..c7757ba 100644 --- a/src/Oms.Application/Dtos/Orders/FulfillWorkplaceStatsOutput.cs +++ b/src/Oms.Application/Dtos/Orders/FulfillWorkplaceStatsOutput.cs @@ -5,7 +5,7 @@ namespace Oms.Application.Dtos.Orders; /// public class FulfillWorkplaceStatsOutput { - /// 待绑定包裹/库存。 + /// 历史字段:创建代发必绑后工作台恒为 0,保留兼容旧前端。 public int PendingBind { get; set; } /// 国内快递在途。 diff --git a/src/Oms.Application/Services/Orders/OrderService.StockBind.cs b/src/Oms.Application/Services/Orders/OrderService.StockBind.cs index a9abbc2..16e8b09 100644 --- a/src/Oms.Application/Services/Orders/OrderService.StockBind.cs +++ b/src/Oms.Application/Services/Orders/OrderService.StockBind.cs @@ -1,5 +1,7 @@ +using System.Data; using Fake.Application; using Fake.Domain.Exceptions; +using Fake.UnitOfWork; using Microsoft.AspNetCore.Mvc; using Oms.Application.Dtos.Orders; using Oms.Application.Dtos.Shared; @@ -189,20 +191,23 @@ public partial class OrderService /// 保存绑定(全量覆盖 + 冻结)。 /// [HttpPost("/order/stock-bind/save")] + [UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)] public async Task SaveStockBindAsync([FromBody] OrderStockBindSaveInput input) { var order = await GetOrderOrThrowAsync(input.OrderId); EnsureOrderCanBindStock(order); await EnsureNoDeductedBindsAsync(order.Id); - var customerId = await ResolveStockBindCustomerIdAsync(order); - var warehouseId = ResolveBindWarehouseId(order, null); var items = input.Items ?? []; - if (items.Count > 0) + // 空明细 = 清空绑定:仓内代发不可处于「已建单未绑定」,清空后回退直发 + if (items.Count == 0) { - await EnsureProxyPackingConfiguredForOrderAsync(order); + return await ClearStockBindCoreAsync(order); } + var customerId = await ResolveStockBindCustomerIdAsync(order); + var warehouseId = ResolveBindWarehouseId(order, null); + await EnsureProxyPackingConfiguredForOrderAsync(order); await ReleaseBoundBindsAsync(order.Id); foreach (var item in items) @@ -234,19 +239,16 @@ public partial class OrderService needOrderUpdate = true; } - if (items.Count > 0) + if (!FulfillmentTypeCodes.IsWarehouse(order.FulfillmentType)) { - if (!FulfillmentTypeCodes.IsWarehouse(order.FulfillmentType)) - { - order.FulfillmentType = FulfillmentTypeCodes.Warehouse; - needOrderUpdate = true; - } + order.FulfillmentType = FulfillmentTypeCodes.Warehouse; + needOrderUpdate = true; + } - if (string.IsNullOrWhiteSpace(order.FulfillmentSource)) - { - order.FulfillmentSource = FulfillmentSourceCodes.PostBind; - needOrderUpdate = true; - } + if (string.IsNullOrWhiteSpace(order.FulfillmentSource)) + { + order.FulfillmentSource = FulfillmentSourceCodes.PostBind; + needOrderUpdate = true; } if (needOrderUpdate) @@ -261,16 +263,31 @@ public partial class OrderService } /// - /// 清空绑定并释放冻结。 + /// 清空绑定并释放冻结;若原为仓内代发则回退为直发(创建代发必绑,禁止无绑定的 warehouse 单)。 /// [HttpPost("/order/stock-bind/clear")] + [UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)] public async Task ClearStockBindAsync([FromBody] OrderStockBindOrderInput input) { var order = await GetOrderOrThrowAsync(input.OrderId); EnsureOrderCanBindStock(order); await EnsureNoDeductedBindsAsync(order.Id); + return await ClearStockBindCoreAsync(order); + } + + private async Task ClearStockBindCoreAsync(Order order) + { await ReleaseBoundBindsAsync(order.Id); order = await GetOrderOrThrowAsync(order.Id); + + if (FulfillmentTypeCodes.IsWarehouse(order.FulfillmentType)) + { + order.FulfillmentType = FulfillmentTypeCodes.Direct; + order.FulfillmentSource = null; + await UpdateOrderAsync(order); + order = await GetOrderOrThrowAsync(order.Id); + } + await SyncProxyPackingFeeByStockBindAsync(order); return await BuildStockBindDetailAsync(order); } @@ -279,6 +296,7 @@ public partial class OrderService /// 确认扣减:将 bound 明细转为 deducted,扣减实物并释放冻结。 /// [HttpPost("/order/stock-bind/confirm-deduct")] + [UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)] public async Task ConfirmStockBindDeductAsync([FromBody] OrderStockBindOrderInput input) { var order = await GetOrderOrThrowAsync(input.OrderId); diff --git a/src/Oms.Application/Services/Orders/OrderService.Workplace.cs b/src/Oms.Application/Services/Orders/OrderService.Workplace.cs index 3c3ee54..47e9618 100644 --- a/src/Oms.Application/Services/Orders/OrderService.Workplace.cs +++ b/src/Oms.Application/Services/Orders/OrderService.Workplace.cs @@ -101,7 +101,8 @@ public partial class OrderService StoreOrderPending = storeOrderPending, Fulfill = new FulfillWorkplaceStatsOutput { - PendingBind = FulfillCount(FulfillmentProgressCodes.PendingBind), + // 创建代发必绑:工作台不再统计「待绑定」 + PendingBind = 0, DomesticInTransit = FulfillCount(FulfillmentProgressCodes.DomesticInTransit), ArrivedPendingPick = FulfillCount(FulfillmentProgressCodes.ArrivedPendingPick), OutboundDone = FulfillCount(FulfillmentProgressCodes.OutboundDone), diff --git a/src/Oms.Application/Services/Orders/OrderService.cs b/src/Oms.Application/Services/Orders/OrderService.cs index 9088641..4ca0c09 100644 --- a/src/Oms.Application/Services/Orders/OrderService.cs +++ b/src/Oms.Application/Services/Orders/OrderService.cs @@ -478,6 +478,7 @@ public partial class OrderService : ApplicationService /// 入参:订单操作参数。 /// 无返回体,仅完成删除订单。 [HttpPost("/order/delete")] + [UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)] public async Task DeleteAsync(OrderActionInput input) { var order = await GetOrderOrThrowAsync(input.Id); @@ -486,6 +487,10 @@ public partial class OrderService : ApplicationService throw new BusinessException("仅草稿或已预报订单可删除"); } + // 删除前释放库存/包裹冻结;仓内代发回退直发,避免删单后冻结残留 + await ClearStockBindCoreAsync(order); + order = await GetOrderOrThrowAsync(input.Id); + // 业务删除:只改 OrderStatus=deleted,不做 IsDeleted 软删,否则「已删除」Tab 因全局软删过滤永远查不到。 order.OrderStatus = OrderStatusCodes.Deleted; if (order.IsPaid > 0 && order.CustomerId.HasValue) diff --git a/src/Oms.Application/Services/Orders/PlatformStoreOrderService.cs b/src/Oms.Application/Services/Orders/PlatformStoreOrderService.cs index acda47b..9a89851 100644 --- a/src/Oms.Application/Services/Orders/PlatformStoreOrderService.cs +++ b/src/Oms.Application/Services/Orders/PlatformStoreOrderService.cs @@ -623,19 +623,13 @@ public class PlatformStoreOrderService : ApplicationService try { - // 确保物流单带仓库,绑定校验依赖 WarehouseId + // 先只落仓库,FulfillmentType 在绑定成功后写入,避免出现「warehouse 但未绑定」 if (resolvedWarehouseId is > 0) { var logisticsOrder = await OrderRepository.FirstOrDefaultAsync(x => x.Id == parcelOutput.OrderId); - if (logisticsOrder != null) + if (logisticsOrder != null && logisticsOrder.WarehouseId is not > 0) { - if (logisticsOrder.WarehouseId is not > 0) - { - logisticsOrder.WarehouseId = resolvedWarehouseId; - } - - logisticsOrder.FulfillmentType = FulfillmentTypeCodes.Warehouse; - logisticsOrder.FulfillmentSource = FulfillmentSourceCodes.StoreFulfill; + logisticsOrder.WarehouseId = resolvedWarehouseId; await OrderRepository.UpdateAsync(logisticsOrder); } } @@ -645,6 +639,32 @@ public class PlatformStoreOrderService : ApplicationService OrderId = parcelOutput.OrderId, Items = bindItems }); + + var boundOrder = await OrderRepository.FirstOrDefaultAsync(x => x.Id == parcelOutput.OrderId); + if (boundOrder != null) + { + var needUpdate = false; + if (!string.Equals( + boundOrder.FulfillmentSource, + FulfillmentSourceCodes.StoreFulfill, + StringComparison.OrdinalIgnoreCase)) + { + boundOrder.FulfillmentSource = FulfillmentSourceCodes.StoreFulfill; + needUpdate = true; + } + + if (!FulfillmentTypeCodes.IsWarehouse(boundOrder.FulfillmentType)) + { + boundOrder.FulfillmentType = FulfillmentTypeCodes.Warehouse; + needUpdate = true; + } + + if (needUpdate) + { + await OrderRepository.UpdateAsync(boundOrder); + } + } + return parcelOutput; } catch (Exception) diff --git a/src/Oms.Domain/OrdersAggregate/Consts/FulfillmentProgressCodes.cs b/src/Oms.Domain/OrdersAggregate/Consts/FulfillmentProgressCodes.cs index 6bc3904..3836b4f 100644 --- a/src/Oms.Domain/OrdersAggregate/Consts/FulfillmentProgressCodes.cs +++ b/src/Oms.Domain/OrdersAggregate/Consts/FulfillmentProgressCodes.cs @@ -5,7 +5,9 @@ namespace Oms.Domain.OrdersAggregate.Consts; /// public static class FulfillmentProgressCodes { - /// 待绑定包裹/库存。 + /// + /// 历史兼容:仓内代发但无绑定明细。现网「创建代发必绑」,新单不应再落入此进度。 + /// public const string PendingBind = "pendingBind"; /// 国内快递在途,未到仓。 diff --git a/src/Oms.SqlSugarCore/Orders/OrderRepository.cs b/src/Oms.SqlSugarCore/Orders/OrderRepository.cs index daf4ba9..929073f 100644 --- a/src/Oms.SqlSugarCore/Orders/OrderRepository.cs +++ b/src/Oms.SqlSugarCore/Orders/OrderRepository.cs @@ -1616,10 +1616,10 @@ public class OrderRepository : OmsSqlSugarRepository, IOrderRepository, I return await query.CountAsync(cancellationToken); } + // 创建代发必绑:进度聚合不再返回 pendingBind(筛选接口仍兼容该值) var result = new Dictionary(StringComparer.OrdinalIgnoreCase) { ["all"] = await CountAsync(null), - [FulfillmentProgressCodes.PendingBind] = await CountAsync(FulfillmentProgressCodes.PendingBind), [FulfillmentProgressCodes.DomesticInTransit] = await CountAsync(FulfillmentProgressCodes.DomesticInTransit), [FulfillmentProgressCodes.ArrivedPendingPick] = await CountAsync(FulfillmentProgressCodes.ArrivedPendingPick), [FulfillmentProgressCodes.OutboundDone] = await CountAsync(FulfillmentProgressCodes.OutboundDone), -- 2.45.2 From cbe22652c07ba7ac7b7f18b7e3f77bed267fbed4 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Wed, 18 Nov 2026 11:48:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E5=AE=A1=E6=89=B9=E7=BB=88=E5=AE=A1?= =?UTF-8?q?=E5=90=8E=E8=87=AA=E5=8A=A8=E5=B0=86=E5=BE=85=E5=AE=A1=E6=89=B9?= =?UTF-8?q?=E7=AB=99=E5=86=85=E4=BF=A1=E6=A0=87=E4=B8=BA=E5=B7=B2=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 避免候选人通过/驳回/撤回后仍需单独点已读。 Co-authored-by: Cursor --- .../Services/Approval/ApprovalEngineCore.cs | 28 ++++++++ .../Services/Approval/ApprovalNotifier.cs | 68 ++++++++++++++++++- 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/src/Oms.Application/Services/Approval/ApprovalEngineCore.cs b/src/Oms.Application/Services/Approval/ApprovalEngineCore.cs index ffb6721..4c4e277 100644 --- a/src/Oms.Application/Services/Approval/ApprovalEngineCore.cs +++ b/src/Oms.Application/Services/Approval/ApprovalEngineCore.cs @@ -224,6 +224,16 @@ public class ApprovalEngineCore( // 通知失败不影响审批 } + try + { + // 终审后清掉候选人侧「待审批」未读,避免还要再点一次已读 + await approvalNotifier.MarkPendingApprovalNoticesReadAsync(instance.Id); + } + catch + { + // 已读标记失败不影响审批 + } + await ExecuteHandlerAsync(instance, mapId, guid); } @@ -281,6 +291,15 @@ public class ApprovalEngineCore( // 通知失败不影响审批 } + try + { + await approvalNotifier.MarkPendingApprovalNoticesReadAsync(instance.Id); + } + catch + { + // 已读标记失败不影响审批 + } + await InvokeRejectOrWithdrawHandlerAsync(instance, mapId, guid, name, isReject: true, comment.Trim()); } @@ -325,6 +344,15 @@ public class ApprovalEngineCore( name, comment?.Trim() ?? "撤回"); + try + { + await approvalNotifier.MarkPendingApprovalNoticesReadAsync(instance.Id); + } + catch + { + // 已读标记失败不影响撤回 + } + await InvokeRejectOrWithdrawHandlerAsync( instance, mapId, diff --git a/src/Oms.Application/Services/Approval/ApprovalNotifier.cs b/src/Oms.Application/Services/Approval/ApprovalNotifier.cs index 44b4625..874ba45 100644 --- a/src/Oms.Application/Services/Approval/ApprovalNotifier.cs +++ b/src/Oms.Application/Services/Approval/ApprovalNotifier.cs @@ -14,11 +14,13 @@ namespace Oms.Application.Services.Approval; /// public class ApprovalNotifier( INoticeRepository noticeRepository, + INoticeReadRepository noticeReadRepository, FakeRbacDbContext rbacDbContext, ILogger logger) : IScopedDependency { private const string NoticeTypeMessage = "message"; private const string ReceiverTypeUser = "user"; + private const string PendingTitlePrefix = "待审批:"; /// /// 通知审批候选人:有待办需处理。 @@ -37,13 +39,13 @@ public class ApprovalNotifier( return; } - var title = $"待审批:{instance.Title}"; + var title = $"{PendingTitlePrefix}{instance.Title}"; var content = $"审批单 {instance.InstanceNo} 待你处理。\n" + $"操作:{instance.OperationCode}\n" + $"申请人:{instance.ApplicantUserName ?? instance.ApplicantUserGuid}\n" + $"请到「系统管理 / 审批待办」处理。\n" + - $"[OMS_APPROVAL:id={instance.Id}&tab=todo]"; + BuildApprovalToken(instance.Id, "todo"); await noticeRepository.InsertAsync(new Notice { @@ -86,7 +88,7 @@ public class ApprovalNotifier( $"操作:{instance.OperationCode}\n" + (string.IsNullOrWhiteSpace(comment) ? string.Empty : $"意见:{comment.Trim()}\n") + $"可在「系统管理 / 审批待办 → 我发起的」查看详情。\n" + - $"[OMS_APPROVAL:id={instance.Id}&tab=submitted]"; + BuildApprovalToken(instance.Id, "submitted"); await noticeRepository.InsertAsync(new Notice { @@ -99,6 +101,66 @@ public class ApprovalNotifier( }, cancellationToken); } + /// + /// 将指定审批实例的「待审批」站内信标为已读(所有定向接收人)。 + /// 通过 / 驳回 / 撤回后调用,避免候选人侧仍残留未读待办。 + /// + public async Task MarkPendingApprovalNoticesReadAsync( + int instanceId, + CancellationToken cancellationToken = default) + { + if (instanceId <= 0) + { + return; + } + + var token = $"[OMS_APPROVAL:id={instanceId}"; + var notices = await noticeRepository.GetListAsync(x => + x.NoticeType == NoticeTypeMessage + && x.Title != null + && x.Title.StartsWith(PendingTitlePrefix) + && x.Content != null + && x.Content.Contains(token)); + if (notices.Count == 0) + { + return; + } + + var now = DateTime.Now; + foreach (var notice in notices) + { + var receiverIds = OmsDocHelper.DeserializeJson>(notice.ReceiverIds) ?? []; + foreach (var receiverId in receiverIds.Distinct()) + { + if (receiverId <= 0) + { + continue; + } + + var existed = await noticeReadRepository.GetByNoticeReceiverAsync( + notice.Id, + ReceiverTypeUser, + receiverId, + cancellationToken); + if (existed != null) + { + continue; + } + + await noticeReadRepository.InsertAsync(new NoticeRead + { + NoticeId = notice.Id, + ReceiverType = ReceiverTypeUser, + ReceiverId = receiverId, + ReadTime = now + }); + } + } + } + + private static string BuildApprovalToken(int instanceId, string tab) => + $"[OMS_APPROVAL:id={instanceId}&tab={tab}]"; + private async Task> ResolveMapUserIdsAsync( IReadOnlyCollection userGuids, CancellationToken cancellationToken) -- 2.45.2