feat: 销售产品价格发布接入审批门面
All checks were successful
Build and Deploy / deploy (push) Successful in 1m16s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m16s
启用 Channel.SalesProduct.PublishPrice 后冻结快照建单,终审通过再落发布记录;未配置则 Bypass 直发。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
649b84c1b0
commit
c3283f110f
@ -0,0 +1,21 @@
|
||||
namespace Oms.Application.Dtos.Channels;
|
||||
|
||||
/// <summary>
|
||||
/// 销售产品发布结果(可能 Bypass 直接发布,或进入审批)。
|
||||
/// </summary>
|
||||
public class SalesProductPublishResultOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// Bypass=未启用审批已直接发布;PendingApproval=已提交审批;Executed=审批后执行成功(一般不由发布接口返回)。
|
||||
/// </summary>
|
||||
public string Decision { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>审批实例 Id(PendingApproval 时有值)。</summary>
|
||||
public int? ApprovalInstanceId { get; set; }
|
||||
|
||||
/// <summary>审批单号。</summary>
|
||||
public string? ApprovalInstanceNo { get; set; }
|
||||
|
||||
/// <summary>说明。</summary>
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
@ -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",
|
||||
"订单退款",
|
||||
|
||||
@ -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`。
|
||||
|
||||
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 销售产品价格发布审批终审执行器:按冻结快照写入发布记录。
|
||||
/// </summary>
|
||||
public class SalesProductPricePublishApprovalHandler(
|
||||
ISalesProductRepository salesProductRepository) : IApprovalOperationHandler, ITransientDependency
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
/// <inheritdoc />
|
||||
public string OperationCode => ApprovalCodes.SalesProductPublishPrice;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task ExecuteAsync(ApprovalExecutionContext context, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(context.PayloadJson))
|
||||
{
|
||||
throw new BusinessException("价格发布审批载荷为空");
|
||||
}
|
||||
|
||||
var payload = JsonSerializer.Deserialize<PricePublishPayload>(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; }
|
||||
}
|
||||
}
|
||||
@ -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());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 价格发布:先冻结快照,再经审批门面(未配置则直接落库)。
|
||||
/// </summary>
|
||||
private async Task<SalesProductPublishResultOutput> 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<int>().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<int>().ToString()
|
||||
: CurrentUser.UserName!;
|
||||
|
||||
/// <summary>
|
||||
/// 按发布记录回滚价格或规则配置。
|
||||
/// </summary>
|
||||
|
||||
@ -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<OmsRbacUserDisplayNameResolver>();
|
||||
|
||||
private IApprovalGate ApprovalGate => LazyServiceProvider.GetRequiredService<IApprovalGate>();
|
||||
|
||||
/// <summary>
|
||||
/// 查询销售产品列表。
|
||||
/// </summary>
|
||||
@ -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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行销售产品发布。
|
||||
/// 执行销售产品发布。价格发布会走审批门面:未配置/未命中则直接发布,否则创建审批单。
|
||||
/// </summary>
|
||||
/// <param name="input">入参:销售产品发布参数。</param>
|
||||
/// <returns>无返回体,仅完成销售产品发布处理。</returns>
|
||||
/// <returns>发布结果(直接发布或待审批)。</returns>
|
||||
[HttpPost("/channel/sales-product/publish")]
|
||||
public async Task PublishAsync(SalesProductPublishInput input)
|
||||
public async Task<SalesProductPublishResultOutput> 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 = "规则发布已完成"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -34,6 +34,9 @@ public static class ApprovalCodes
|
||||
|
||||
/// <summary>模拟提交操作编码(引擎自测)。</summary>
|
||||
public const string SimOperationCode = "System.Approval.Simulate";
|
||||
|
||||
/// <summary>销售产品价格发布。</summary>
|
||||
public const string SalesProductPublishPrice = "Channel.SalesProduct.PublishPrice";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user