diff --git a/src/Oms.Application/Dtos/Channels/SalesProductPublishResultOutput.cs b/src/Oms.Application/Dtos/Channels/SalesProductPublishResultOutput.cs
new file mode 100644
index 0000000..bb0eb35
--- /dev/null
+++ b/src/Oms.Application/Dtos/Channels/SalesProductPublishResultOutput.cs
@@ -0,0 +1,21 @@
+namespace Oms.Application.Dtos.Channels;
+
+///
+/// 销售产品发布结果(可能 Bypass 直接发布,或进入审批)。
+///
+public class SalesProductPublishResultOutput
+{
+ ///
+ /// Bypass=未启用审批已直接发布;PendingApproval=已提交审批;Executed=审批后执行成功(一般不由发布接口返回)。
+ ///
+ public string Decision { get; set; } = string.Empty;
+
+ /// 审批实例 Id(PendingApproval 时有值)。
+ public int? ApprovalInstanceId { get; set; }
+
+ /// 审批单号。
+ public string? ApprovalInstanceNo { get; set; }
+
+ /// 说明。
+ public string? Message { get; set; }
+}
diff --git a/src/Oms.Application/Services/Approval/ApprovalOperationCatalog.cs b/src/Oms.Application/Services/Approval/ApprovalOperationCatalog.cs
index 5464027..3d2a0e0 100644
--- a/src/Oms.Application/Services/Approval/ApprovalOperationCatalog.cs
+++ b/src/Oms.Application/Services/Approval/ApprovalOperationCatalog.cs
@@ -38,11 +38,11 @@ public static class ApprovalOperationCatalog
SupportsCondition: false,
ConditionHint: "业务接入后可按金额等配置条件"),
new(
- "Channel.SalesProduct.PublishPrice",
+ ApprovalCodes.SalesProductPublishPrice,
"销售产品价格发布",
"Channel",
SupportsCondition: false,
- ConditionHint: "业务接入后可按价差等配置条件"),
+ ConditionHint: "已接入发布接口;未配置或未启用不拦截,启用后提交审批"),
new(
"Order.Refund.Apply",
"订单退款",
diff --git a/src/Oms.Application/Services/Approval/README.md b/src/Oms.Application/Services/Approval/README.md
index 2da627b..868e916 100644
--- a/src/Oms.Application/Services/Approval/README.md
+++ b/src/Oms.Application/Services/Approval/README.md
@@ -9,4 +9,7 @@
3. 实现 `IApprovalOperationHandler`(`OperationCode` 匹配),终审通过后引擎调用 `ExecuteAsync`;Handler 内须再次校验业务状态后落账/发布。
4. 若操作需条件公式,再实现 `IApprovalConditionContextFactory`,并将目录项 `SupportsCondition` 改为 true。
-一期不改造充值/提现/价格发布等现有审核接口。联调可用「模拟提交」+ 操作码 `System.Approval.Simulate`。
+已接入:`Channel.SalesProduct.PublishPrice`(`/channel/sales-product/publish`,operatorType=price)。
+未配置审批定义或未启用时 Bypass 直接发布;启用后冻结快照建单,终审由 `SalesProductPricePublishApprovalHandler` 落发布记录。
+
+联调也可用「模拟提交」+ 操作码 `System.Approval.Simulate`。
diff --git a/src/Oms.Application/Services/Channels/SalesProductPricePublishApprovalHandler.cs b/src/Oms.Application/Services/Channels/SalesProductPricePublishApprovalHandler.cs
new file mode 100644
index 0000000..5baf5b4
--- /dev/null
+++ b/src/Oms.Application/Services/Channels/SalesProductPricePublishApprovalHandler.cs
@@ -0,0 +1,88 @@
+using System.Text.Json;
+using Fake.Application;
+using Fake.DependencyInjection;
+using Oms.Application.Services.Approval.Contracts;
+using Oms.Domain.ApprovalAggregate.Consts;
+using Oms.Domain.ChannelsAggregate.Entities;
+using Oms.Domain.ChannelsAggregate.Repositories;
+using Oms.Domain.Shared.Enums;
+
+namespace Oms.Application.Services.Channels;
+
+///
+/// 销售产品价格发布审批终审执行器:按冻结快照写入发布记录。
+///
+public class SalesProductPricePublishApprovalHandler(
+ ISalesProductRepository salesProductRepository) : IApprovalOperationHandler, ITransientDependency
+{
+ private static readonly JsonSerializerOptions JsonOptions = new()
+ {
+ PropertyNameCaseInsensitive = true
+ };
+
+ ///
+ public string OperationCode => ApprovalCodes.SalesProductPublishPrice;
+
+ ///
+ public async Task ExecuteAsync(ApprovalExecutionContext context, CancellationToken cancellationToken = default)
+ {
+ if (string.IsNullOrWhiteSpace(context.PayloadJson))
+ {
+ throw new BusinessException("价格发布审批载荷为空");
+ }
+
+ var payload = JsonSerializer.Deserialize(context.PayloadJson, JsonOptions)
+ ?? throw new BusinessException("价格发布审批载荷无效");
+
+ if (payload.SalesProductId <= 0 || string.IsNullOrWhiteSpace(payload.Content))
+ {
+ throw new BusinessException("价格发布审批载荷缺少产品或快照");
+ }
+
+ var product = await salesProductRepository.FirstOrDefaultAsync(
+ x => x.Id == payload.SalesProductId,
+ cancellationToken);
+ if (product == null)
+ {
+ throw new BusinessException("销售产品不存在");
+ }
+
+ var publishUser = string.IsNullOrWhiteSpace(payload.ApplicantUserName)
+ ? (string.IsNullOrWhiteSpace(context.ApplicantUserGuid)
+ ? context.ApplicantUserId.ToString()
+ : context.ApplicantUserGuid)
+ : payload.ApplicantUserName.Trim();
+
+ var description = string.IsNullOrWhiteSpace(payload.Description)
+ ? $"审批通过发布 {context.InstanceNo}"
+ : $"{payload.Description.Trim()}(审批单 {context.InstanceNo})";
+
+ await salesProductRepository.InsertPublishRecordAsync(new SalesProductPublishRecord
+ {
+ SalesProductId = payload.SalesProductId,
+ Version = DateTime.Now.ToString("yyyyMMddHHmmss"),
+ OperatorType = "price",
+ Status = EsSnapshotStatus.Active,
+ PublishUser = publishUser,
+ PublishTime = DateTime.Now,
+ Description = description,
+ AiAnalysisReport = string.IsNullOrWhiteSpace(payload.AiAnalysisReport)
+ ? null
+ : payload.AiAnalysisReport.Trim(),
+ Content = payload.Content
+ }, cancellationToken);
+ }
+
+ private sealed class PricePublishPayload
+ {
+ public int SalesProductId { get; set; }
+
+ public string? Description { get; set; }
+
+ public string? AiAnalysisReport { get; set; }
+
+ public string? Content { get; set; }
+
+ public string? ApplicantUserName { get; set; }
+ }
+}
diff --git a/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs b/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs
index d7bc155..62f4166 100644
--- a/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs
+++ b/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs
@@ -1,7 +1,9 @@
using Oms.Application.Dtos.Channels;
using Oms.Application.Dtos.Orders;
using Oms.Application.Dtos.Shared;
+using Oms.Application.Services.Approval.Contracts;
using Oms.Application.Shared;
+using Oms.Domain.ApprovalAggregate.Consts;
using Oms.Domain.ChannelsAggregate.Consts;
using Oms.Domain.ChannelsAggregate.Entities;
using Oms.Domain.Shared;
@@ -418,6 +420,94 @@ public partial class SalesProductService
? OmsDocHelper.CanonicalizeSalesProductPriceSnapshotJson(snapshot)
: OmsDocHelper.CanonicalizeSalesProductRulesSnapshotJson(snapshot);
+ await InsertPublishRecordCoreAsync(
+ salesProductId,
+ operatorType,
+ description,
+ aiAnalysisReport,
+ content,
+ ResolvePublishUserName());
+ }
+
+ ///
+ /// 价格发布:先冻结快照,再经审批门面(未配置则直接落库)。
+ ///
+ private async Task PublishPriceWithApprovalAsync(
+ int salesProductId,
+ string? description,
+ string? aiAnalysisReport)
+ {
+ var product = await GetProductOrThrowAsync(salesProductId);
+ var priceSnapshot = await BuildPricePublishSnapshotAsync(salesProductId);
+ ValidateBillingPriceItemRules(
+ priceSnapshot.Prices.Select(p => MapPriceSaveInput(p, salesProductId)).ToList());
+ var content = OmsDocHelper.CanonicalizeSalesProductPriceSnapshotJson(priceSnapshot);
+ var contentHash = ComputeContentHash(content);
+ var publishUser = ResolvePublishUserName();
+
+ var payload = new
+ {
+ salesProductId,
+ productCode = product.ProductCode,
+ productName = product.ProductName,
+ operatorType = PriceOperatorType,
+ description,
+ aiAnalysisReport,
+ content,
+ contentHash,
+ applicantUserName = publishUser
+ };
+
+ var gateResult = await ApprovalGate.CheckAndSubmitOrBypassAsync(new ApprovalSubmitRequest
+ {
+ OperationCode = ApprovalCodes.SalesProductPublishPrice,
+ BizKey = $"SalesProduct.PricePublish:{salesProductId}",
+ Title = $"价格发布 - {product.ProductCode} {product.ProductName}".Trim(),
+ PayloadJson = OmsDocHelper.SerializeJson(payload),
+ Summary = new
+ {
+ salesProductId,
+ product.ProductCode,
+ product.ProductName,
+ contentHash,
+ description
+ }
+ });
+
+ if (gateResult.Decision == ApprovalGateDecision.PendingApproval)
+ {
+ return new SalesProductPublishResultOutput
+ {
+ Decision = nameof(ApprovalGateDecision.PendingApproval),
+ ApprovalInstanceId = gateResult.InstanceId,
+ ApprovalInstanceNo = gateResult.InstanceNo,
+ Message = $"已提交审批({gateResult.InstanceNo}),通过后生效"
+ };
+ }
+
+ await InsertPublishRecordCoreAsync(
+ salesProductId,
+ PriceOperatorType,
+ description,
+ aiAnalysisReport,
+ content,
+ publishUser);
+
+ return new SalesProductPublishResultOutput
+ {
+ Decision = nameof(ApprovalGateDecision.Bypass),
+ Message = gateResult.Message ?? "未启用审批,已直接发布"
+ };
+ }
+
+ private async Task InsertPublishRecordCoreAsync(
+ int salesProductId,
+ string operatorType,
+ string? description,
+ string? aiAnalysisReport,
+ string? content,
+ string publishUser)
+ {
// Content 中保存完整快照,回滚时直接从快照恢复,避免依赖当前库内状态。
await SalesProductRepository.InsertPublishRecordAsync(new SalesProductPublishRecord
{
@@ -425,7 +515,7 @@ public partial class SalesProductService
Version = DateTime.Now.ToString("yyyyMMddHHmmss"),
OperatorType = operatorType,
Status = EsSnapshotStatus.Active,
- PublishUser = string.IsNullOrWhiteSpace(CurrentUser.UserName) ? CurrentUser.GetId().ToString() : CurrentUser.UserName!,
+ PublishUser = publishUser,
PublishTime = DateTime.Now,
Description = description,
AiAnalysisReport = string.IsNullOrWhiteSpace(aiAnalysisReport) ? null : aiAnalysisReport.Trim(),
@@ -433,6 +523,11 @@ public partial class SalesProductService
});
}
+ private string ResolvePublishUserName() =>
+ string.IsNullOrWhiteSpace(CurrentUser.UserName)
+ ? CurrentUser.GetId().ToString()
+ : CurrentUser.UserName!;
+
///
/// 按发布记录回滚价格或规则配置。
///
diff --git a/src/Oms.Application/Services/Channels/SalesProductService.cs b/src/Oms.Application/Services/Channels/SalesProductService.cs
index bba0e20..5ca0bb0 100644
--- a/src/Oms.Application/Services/Channels/SalesProductService.cs
+++ b/src/Oms.Application/Services/Channels/SalesProductService.cs
@@ -3,6 +3,7 @@ using Fake.Application;
using Microsoft.AspNetCore.Mvc;
using Oms.Application.Dtos.Channels;
using Oms.Application.Dtos.Shared;
+using Oms.Application.Services.Approval.Contracts;
using Oms.Application.Shared;
using Oms.Domain.ChannelsAggregate.Entities;
using Oms.Domain.ChannelsAggregate.Repositories;
@@ -29,6 +30,8 @@ public partial class SalesProductService : ApplicationService
private OmsRbacUserDisplayNameResolver UserDisplayNameResolver =>
LazyServiceProvider.GetRequiredService();
+ private IApprovalGate ApprovalGate => LazyServiceProvider.GetRequiredService();
+
///
/// 查询销售产品列表。
///
@@ -316,9 +319,8 @@ public partial class SalesProductService : ApplicationService
throw new Fake.Application.BusinessException("价格发布前须完成 AI 风险分析并保存报告");
}
- await CreatePublishRecordAsync(
+ await PublishPriceWithApprovalAsync(
input.SalesProductId,
- PriceOperatorType,
"保存并发布价格",
input.AiAnalysisReport);
}
@@ -471,17 +473,25 @@ public partial class SalesProductService : ApplicationService
}
///
- /// 执行销售产品发布。
+ /// 执行销售产品发布。价格发布会走审批门面:未配置/未命中则直接发布,否则创建审批单。
///
/// 入参:销售产品发布参数。
- /// 无返回体,仅完成销售产品发布处理。
+ /// 发布结果(直接发布或待审批)。
[HttpPost("/channel/sales-product/publish")]
- public async Task PublishAsync(SalesProductPublishInput input)
+ public async Task PublishAsync(SalesProductPublishInput input)
{
var operatorType = NormalizeOperatorType(input.OperatorType);
- if (operatorType == PriceOperatorType && string.IsNullOrWhiteSpace(input.AiAnalysisReport))
+ if (operatorType == PriceOperatorType)
{
- throw new Fake.Application.BusinessException("价格发布前须完成 AI 风险分析并保存报告");
+ if (string.IsNullOrWhiteSpace(input.AiAnalysisReport))
+ {
+ throw new Fake.Application.BusinessException("价格发布前须完成 AI 风险分析并保存报告");
+ }
+
+ return await PublishPriceWithApprovalAsync(
+ input.SalesProductId,
+ input.Description,
+ input.AiAnalysisReport);
}
await CreatePublishRecordAsync(
@@ -489,6 +499,11 @@ public partial class SalesProductService : ApplicationService
operatorType,
input.Description,
input.AiAnalysisReport);
+ return new SalesProductPublishResultOutput
+ {
+ Decision = "Bypass",
+ Message = "规则发布已完成"
+ };
}
///
diff --git a/src/Oms.Domain/ApprovalAggregate/Consts/ApprovalCodes.cs b/src/Oms.Domain/ApprovalAggregate/Consts/ApprovalCodes.cs
index 9a89237..5c42efd 100644
--- a/src/Oms.Domain/ApprovalAggregate/Consts/ApprovalCodes.cs
+++ b/src/Oms.Domain/ApprovalAggregate/Consts/ApprovalCodes.cs
@@ -34,6 +34,9 @@ public static class ApprovalCodes
/// 模拟提交操作编码(引擎自测)。
public const string SimOperationCode = "System.Approval.Simulate";
+
+ /// 销售产品价格发布。
+ public const string SalesProductPublishPrice = "Channel.SalesProduct.PublishPrice";
}
///