Merge pull request '20261118' (#25) from test into master
All checks were successful
Build and Deploy / deploy (push) Successful in 2m2s

Reviewed-on: https://git.ideship.com/ideship/admin/pulls/25
This commit is contained in:
zzh 2026-11-18 12:06:59 +08:00
commit 739f86ade0
9 changed files with 168 additions and 32 deletions

View File

@ -5,7 +5,7 @@ namespace Oms.Application.Dtos.Orders;
/// </summary>
public class FulfillWorkplaceStatsOutput
{
/// <summary>待绑定包裹/库存。</summary>
/// <summary>历史字段:创建代发必绑后工作台恒为 0,保留兼容旧前端。</summary>
public int PendingBind { get; set; }
/// <summary>国内快递在途。</summary>

View File

@ -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,

View File

@ -14,11 +14,13 @@ namespace Oms.Application.Services.Approval;
/// </summary>
public class ApprovalNotifier(
INoticeRepository noticeRepository,
INoticeReadRepository noticeReadRepository,
FakeRbacDbContext rbacDbContext,
ILogger<ApprovalNotifier> logger) : IScopedDependency
{
private const string NoticeTypeMessage = "message";
private const string ReceiverTypeUser = "user";
private const string PendingTitlePrefix = "待审批:";
/// <summary>
/// 通知审批候选人:有待办需处理。
@ -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);
}
/// <summary>
/// 将指定审批实例的「待审批」站内信标为已读(所有定向接收人)。
/// 通过 / 驳回 / 撤回后调用,避免候选人侧仍残留未读待办。
/// </summary>
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<List<int>>(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<List<int>> ResolveMapUserIdsAsync(
IReadOnlyCollection<string> userGuids,
CancellationToken cancellationToken)

View File

@ -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
/// 保存绑定(全量覆盖 + 冻结)。
/// </summary>
[HttpPost("/order/stock-bind/save")]
[UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)]
public async Task<OrderStockBindDetailOutput> 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
}
/// <summary>
/// 清空绑定并释放冻结。
/// 清空绑定并释放冻结;若原为仓内代发则回退为直发(创建代发必绑,禁止无绑定的 warehouse 单)。
/// </summary>
[HttpPost("/order/stock-bind/clear")]
[UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)]
public async Task<OrderStockBindDetailOutput> ClearStockBindAsync([FromBody] OrderStockBindOrderInput input)
{
var order = await GetOrderOrThrowAsync(input.OrderId);
EnsureOrderCanBindStock(order);
await EnsureNoDeductedBindsAsync(order.Id);
return await ClearStockBindCoreAsync(order);
}
private async Task<OrderStockBindDetailOutput> 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,扣减实物并释放冻结。
/// </summary>
[HttpPost("/order/stock-bind/confirm-deduct")]
[UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)]
public async Task<OrderStockBindDetailOutput> ConfirmStockBindDeductAsync([FromBody] OrderStockBindOrderInput input)
{
var order = await GetOrderOrThrowAsync(input.OrderId);

View File

@ -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),

View File

@ -478,6 +478,7 @@ public partial class OrderService : ApplicationService
/// <param name="input">入参:订单操作参数。</param>
/// <returns>无返回体,仅完成删除订单。</returns>
[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)

View File

@ -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)

View File

@ -5,7 +5,9 @@ namespace Oms.Domain.OrdersAggregate.Consts;
/// </summary>
public static class FulfillmentProgressCodes
{
/// <summary>待绑定包裹/库存。</summary>
/// <summary>
/// 历史兼容:仓内代发但无绑定明细。现网「创建代发必绑」,新单不应再落入此进度。
/// </summary>
public const string PendingBind = "pendingBind";
/// <summary>国内快递在途,未到仓。</summary>

View File

@ -1616,10 +1616,10 @@ public class OrderRepository : OmsSqlSugarRepository<Order>, IOrderRepository, I
return await query.CountAsync(cancellationToken);
}
// 创建代发必绑:进度聚合不再返回 pendingBind(筛选接口仍兼容该值)
var result = new Dictionary<string, int>(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),