fix: 审批 Handler 注入与价格失败态重提支持
All checks were successful
Build and Deploy / deploy (push) Successful in 1m18s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m18s
显式注册 IApprovalOperationHandler,稳定 sync 哈希,并回填驳回/执行失败供重提。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
d83d290ccb
commit
6e061323e9
@ -23,12 +23,20 @@ public class SalesProductPublishSyncStatusOutput
|
|||||||
/// <summary>是否存在在途价格审批(Pending)。</summary>
|
/// <summary>是否存在在途价格审批(Pending)。</summary>
|
||||||
public bool ApprovalPending { get; set; }
|
public bool ApprovalPending { get; set; }
|
||||||
|
|
||||||
/// <summary>在途审批实例 Id。</summary>
|
/// <summary>
|
||||||
|
/// 无在途单时,最近一次终态是否为失败可重提(驳回 / 撤回 / 执行失败)。
|
||||||
|
/// </summary>
|
||||||
|
public bool ApprovalFailed { get; set; }
|
||||||
|
|
||||||
|
/// <summary>关联审批实例 Id(在途或最近失败单)。</summary>
|
||||||
public int? ApprovalInstanceId { get; set; }
|
public int? ApprovalInstanceId { get; set; }
|
||||||
|
|
||||||
/// <summary>在途审批单号。</summary>
|
/// <summary>关联审批单号。</summary>
|
||||||
public string? ApprovalInstanceNo { get; set; }
|
public string? ApprovalInstanceNo { get; set; }
|
||||||
|
|
||||||
/// <summary>在途审批状态名。</summary>
|
/// <summary>审批状态名(待审批 / 已驳回 / 已撤回 / 执行失败)。</summary>
|
||||||
public string? ApprovalStatusName { get; set; }
|
public string? ApprovalStatusName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>驳回意见或执行失败信息(失败态时)。</summary>
|
||||||
|
public string? ApprovalComment { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,10 @@ using Oms.Application.Integrations.Itfx;
|
|||||||
using Oms.Application.Integrations.PlatformShop;
|
using Oms.Application.Integrations.PlatformShop;
|
||||||
using Oms.Application.Labeling;
|
using Oms.Application.Labeling;
|
||||||
using Oms.Application.Labeling.Hiprint;
|
using Oms.Application.Labeling.Hiprint;
|
||||||
|
using Oms.Application.Services.Approval;
|
||||||
|
using Oms.Application.Services.Approval.Contracts;
|
||||||
|
using Oms.Application.Services.Channels;
|
||||||
|
using Oms.Application.Services.Recharge;
|
||||||
using Oms.Application.Services.Storage;
|
using Oms.Application.Services.Storage;
|
||||||
using Oms.Application.Shared;
|
using Oms.Application.Shared;
|
||||||
using Oms.Application.Workers;
|
using Oms.Application.Workers;
|
||||||
@ -53,6 +57,12 @@ public class OmsApplicationModule : FakeModule
|
|||||||
context.Services.AddTransient<ILabelPdfRenderer, QuestPdfLabelRenderer>();
|
context.Services.AddTransient<ILabelPdfRenderer, QuestPdfLabelRenderer>();
|
||||||
context.Services.AddTransient<LabelPdfGenerationService>();
|
context.Services.AddTransient<LabelPdfGenerationService>();
|
||||||
|
|
||||||
|
// 审批终审 Handler:约定注册只暴露 I{类名},须显式挂到 IApprovalOperationHandler,
|
||||||
|
// 否则 Approve 会空跑成 Executed、不落发布/入账。
|
||||||
|
context.Services.AddTransient<IApprovalOperationHandler, SalesProductPricePublishApprovalHandler>();
|
||||||
|
context.Services.AddTransient<IApprovalOperationHandler, RechargeCreditApprovalHandler>();
|
||||||
|
context.Services.AddTransient<IApprovalOperationHandler, NoopApprovalHandler>();
|
||||||
|
|
||||||
context.Services.AddHttpClient(FileStorageService.UrlFetchClientName, client =>
|
context.Services.AddHttpClient(FileStorageService.UrlFetchClientName, client =>
|
||||||
{
|
{
|
||||||
client.Timeout = TimeSpan.FromSeconds(60);
|
client.Timeout = TimeSpan.FromSeconds(60);
|
||||||
|
|||||||
@ -341,9 +341,13 @@ public class ApprovalEngineCore(
|
|||||||
{
|
{
|
||||||
var instance = await instanceRepository.FirstOrDefaultAsync(x => x.Id == instanceId)
|
var instance = await instanceRepository.FirstOrDefaultAsync(x => x.Id == instanceId)
|
||||||
?? throw new BusinessException("审批实例不存在");
|
?? throw new BusinessException("审批实例不存在");
|
||||||
if (instance.Status is not (ApprovalInstanceStatus.Approved or ApprovalInstanceStatus.ExecuteFailed))
|
// Executed 也允许重试:兼容 Handler 未注册时空跑成 Executed、业务未落库的历史单
|
||||||
|
if (instance.Status is not (
|
||||||
|
ApprovalInstanceStatus.Approved
|
||||||
|
or ApprovalInstanceStatus.ExecuteFailed
|
||||||
|
or ApprovalInstanceStatus.Executed))
|
||||||
{
|
{
|
||||||
throw new BusinessException("仅已通过或执行失败的实例可重试执行");
|
throw new BusinessException("仅已通过、已执行或执行失败的实例可重试执行");
|
||||||
}
|
}
|
||||||
|
|
||||||
var mapId = OmsSessionHelper.ResolveMapUserId(currentUser);
|
var mapId = OmsSessionHelper.ResolveMapUserId(currentUser);
|
||||||
@ -368,15 +372,17 @@ public class ApprovalEngineCore(
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_handlers.TryGetValue(instance.OperationCode, out var handler))
|
if (!_handlers.TryGetValue(instance.OperationCode, out var handler))
|
||||||
{
|
{
|
||||||
await handler.ExecuteAsync(BuildExecutionContext(
|
throw new BusinessException($"未注册业务执行器:{instance.OperationCode}");
|
||||||
instance,
|
|
||||||
operatorMapId,
|
|
||||||
operatorGuid,
|
|
||||||
currentUser.UserName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await handler.ExecuteAsync(BuildExecutionContext(
|
||||||
|
instance,
|
||||||
|
operatorMapId,
|
||||||
|
operatorGuid,
|
||||||
|
currentUser.UserName));
|
||||||
|
|
||||||
instance.Status = ApprovalInstanceStatus.Executed;
|
instance.Status = ApprovalInstanceStatus.Executed;
|
||||||
instance.ExecutedTime = DateTime.Now;
|
instance.ExecutedTime = DateTime.Now;
|
||||||
instance.ExecuteMessage = "执行成功";
|
instance.ExecuteMessage = "执行成功";
|
||||||
|
|||||||
@ -7,6 +7,7 @@ namespace Oms.Application.Services.Approval;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模拟操作的空执行器(终审通过后仅记 Executed)。
|
/// 模拟操作的空执行器(终审通过后仅记 Executed)。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ExposeServices(typeof(IApprovalOperationHandler))]
|
||||||
public class NoopApprovalHandler : IApprovalOperationHandler, ITransientDependency
|
public class NoopApprovalHandler : IApprovalOperationHandler, ITransientDependency
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
1. 在操作入口组装 `ApprovalSubmitRequest`,调用 `IApprovalGate.CheckAndSubmitOrBypassAsync`。
|
1. 在操作入口组装 `ApprovalSubmitRequest`,调用 `IApprovalGate.CheckAndSubmitOrBypassAsync`。
|
||||||
2. `Bypass`:业务立即执行;`PendingApproval`:业务进入自有「待审批」中间态,等待终审。
|
2. `Bypass`:业务立即执行;`PendingApproval`:业务进入自有「待审批」中间态,等待终审。
|
||||||
3. 实现 `IApprovalOperationHandler`(`OperationCode` 匹配),终审通过后引擎调用 `ExecuteAsync`;Handler 内须再次校验业务状态后落账/发布。
|
3. 实现 `IApprovalOperationHandler`(`OperationCode` 匹配)并 `[ExposeServices(typeof(IApprovalOperationHandler))]`(或在 `OmsApplicationModule` 显式 `AddTransient<IApprovalOperationHandler, ...>`),终审通过后引擎调用 `ExecuteAsync`;Handler 内须再次校验业务状态后落账/发布。约定注册不会自动挂到该接口,漏注册会导致 Approve 空跑成 Executed、业务不落库。
|
||||||
4. 若操作需条件公式,再实现 `IApprovalConditionContextFactory`,并将目录项 `SupportsCondition` 改为 true。
|
4. 若操作需条件公式,再实现 `IApprovalConditionContextFactory`,并将目录项 `SupportsCondition` 改为 true。
|
||||||
|
|
||||||
已接入:
|
已接入:
|
||||||
|
|||||||
@ -12,14 +12,10 @@ namespace Oms.Application.Services.Channels;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 销售产品价格发布审批终审执行器:按冻结快照写入发布记录。
|
/// 销售产品价格发布审批终审执行器:按冻结快照写入发布记录。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ExposeServices(typeof(IApprovalOperationHandler))]
|
||||||
public class SalesProductPricePublishApprovalHandler(
|
public class SalesProductPricePublishApprovalHandler(
|
||||||
ISalesProductRepository salesProductRepository) : IApprovalOperationHandler, ITransientDependency
|
ISalesProductRepository salesProductRepository) : IApprovalOperationHandler, ITransientDependency
|
||||||
{
|
{
|
||||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
|
||||||
{
|
|
||||||
PropertyNameCaseInsensitive = true
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string OperationCode => ApprovalCodes.SalesProductPublishPrice;
|
public string OperationCode => ApprovalCodes.SalesProductPublishPrice;
|
||||||
|
|
||||||
@ -31,58 +27,120 @@ public class SalesProductPricePublishApprovalHandler(
|
|||||||
throw new BusinessException("价格发布审批载荷为空");
|
throw new BusinessException("价格发布审批载荷为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
var payload = JsonSerializer.Deserialize<PricePublishPayload>(context.PayloadJson, JsonOptions)
|
using var document = JsonDocument.Parse(context.PayloadJson);
|
||||||
?? throw new BusinessException("价格发布审批载荷无效");
|
var root = document.RootElement;
|
||||||
|
var salesProductId = ReadInt32(root, "salesProductId", "SalesProductId");
|
||||||
if (payload.SalesProductId <= 0 || string.IsNullOrWhiteSpace(payload.Content))
|
var content = ReadJsonPayload(root, "content", "Content");
|
||||||
|
if (salesProductId <= 0 || string.IsNullOrWhiteSpace(content))
|
||||||
{
|
{
|
||||||
throw new BusinessException("价格发布审批载荷缺少产品或快照");
|
throw new BusinessException("价格发布审批载荷缺少产品或快照");
|
||||||
}
|
}
|
||||||
|
|
||||||
var product = await salesProductRepository.FirstOrDefaultAsync(
|
var product = await salesProductRepository.FirstOrDefaultAsync(
|
||||||
x => x.Id == payload.SalesProductId,
|
x => x.Id == salesProductId,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
if (product == null)
|
if (product == null)
|
||||||
{
|
{
|
||||||
throw new BusinessException("销售产品不存在");
|
throw new BusinessException("销售产品不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
var publishUser = string.IsNullOrWhiteSpace(payload.ApplicantUserName)
|
var applicantUserName = ReadString(root, "applicantUserName", "ApplicantUserName");
|
||||||
|
var publishUser = string.IsNullOrWhiteSpace(applicantUserName)
|
||||||
? (string.IsNullOrWhiteSpace(context.ApplicantUserGuid)
|
? (string.IsNullOrWhiteSpace(context.ApplicantUserGuid)
|
||||||
? context.ApplicantUserId.ToString()
|
? context.ApplicantUserId.ToString()
|
||||||
: context.ApplicantUserGuid)
|
: context.ApplicantUserGuid)
|
||||||
: payload.ApplicantUserName.Trim();
|
: applicantUserName.Trim();
|
||||||
|
|
||||||
var description = string.IsNullOrWhiteSpace(payload.Description)
|
var descriptionRaw = ReadString(root, "description", "Description");
|
||||||
|
var description = string.IsNullOrWhiteSpace(descriptionRaw)
|
||||||
? $"审批通过发布 {context.InstanceNo}"
|
? $"审批通过发布 {context.InstanceNo}"
|
||||||
: $"{payload.Description.Trim()}(审批单 {context.InstanceNo})";
|
: $"{descriptionRaw.Trim()}(审批单 {context.InstanceNo})";
|
||||||
|
|
||||||
|
var aiReport = ReadString(root, "aiAnalysisReport", "AiAnalysisReport");
|
||||||
|
|
||||||
await salesProductRepository.InsertPublishRecordAsync(new SalesProductPublishRecord
|
await salesProductRepository.InsertPublishRecordAsync(new SalesProductPublishRecord
|
||||||
{
|
{
|
||||||
SalesProductId = payload.SalesProductId,
|
SalesProductId = salesProductId,
|
||||||
Version = DateTime.Now.ToString("yyyyMMddHHmmss"),
|
Version = DateTime.Now.ToString("yyyyMMddHHmmss"),
|
||||||
OperatorType = "price",
|
OperatorType = "price",
|
||||||
Status = EsSnapshotStatus.Active,
|
Status = EsSnapshotStatus.Active,
|
||||||
PublishUser = publishUser,
|
PublishUser = publishUser,
|
||||||
PublishTime = DateTime.Now,
|
PublishTime = DateTime.Now,
|
||||||
Description = description,
|
Description = description,
|
||||||
AiAnalysisReport = string.IsNullOrWhiteSpace(payload.AiAnalysisReport)
|
AiAnalysisReport = string.IsNullOrWhiteSpace(aiReport) ? null : aiReport.Trim(),
|
||||||
? null
|
Content = content
|
||||||
: payload.AiAnalysisReport.Trim(),
|
|
||||||
Content = payload.Content
|
|
||||||
}, cancellationToken);
|
}, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class PricePublishPayload
|
private static int ReadInt32(JsonElement root, params string[] names)
|
||||||
{
|
{
|
||||||
public int SalesProductId { get; set; }
|
foreach (var name in names)
|
||||||
|
{
|
||||||
|
if (!root.TryGetProperty(name, out var el))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
public string? Description { get; set; }
|
if (el.ValueKind == JsonValueKind.Number && el.TryGetInt32(out var n))
|
||||||
|
{
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
public string? AiAnalysisReport { get; set; }
|
if (el.ValueKind == JsonValueKind.String && int.TryParse(el.GetString(), out n))
|
||||||
|
{
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string? Content { get; set; }
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public string? ApplicantUserName { get; set; }
|
private static string? ReadString(JsonElement root, params string[] names)
|
||||||
|
{
|
||||||
|
foreach (var name in names)
|
||||||
|
{
|
||||||
|
if (!root.TryGetProperty(name, out var el))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (el.ValueKind == JsonValueKind.String)
|
||||||
|
{
|
||||||
|
return el.GetString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (el.ValueKind is not (JsonValueKind.Null or JsonValueKind.Undefined))
|
||||||
|
{
|
||||||
|
return el.GetRawText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// content 可能是 JSON 字符串,也可能是对象(历史/异常序列化);统一成快照正文。
|
||||||
|
/// </summary>
|
||||||
|
private static string? ReadJsonPayload(JsonElement root, params string[] names)
|
||||||
|
{
|
||||||
|
foreach (var name in names)
|
||||||
|
{
|
||||||
|
if (!root.TryGetProperty(name, out var el))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (el.ValueKind == JsonValueKind.String)
|
||||||
|
{
|
||||||
|
return el.GetString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (el.ValueKind is JsonValueKind.Object or JsonValueKind.Array)
|
||||||
|
{
|
||||||
|
return el.GetRawText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,8 @@ public partial class SalesProductService : ApplicationService
|
|||||||
private IApprovalGate ApprovalGate => LazyServiceProvider.GetRequiredService<IApprovalGate>();
|
private IApprovalGate ApprovalGate => LazyServiceProvider.GetRequiredService<IApprovalGate>();
|
||||||
private IApprovalInstanceRepository ApprovalInstanceRepository =>
|
private IApprovalInstanceRepository ApprovalInstanceRepository =>
|
||||||
LazyServiceProvider.GetRequiredService<IApprovalInstanceRepository>();
|
LazyServiceProvider.GetRequiredService<IApprovalInstanceRepository>();
|
||||||
|
private IApprovalTaskRepository ApprovalTaskRepository =>
|
||||||
|
LazyServiceProvider.GetRequiredService<IApprovalTaskRepository>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询销售产品列表。
|
/// 查询销售产品列表。
|
||||||
@ -436,25 +438,22 @@ public partial class SalesProductService : ApplicationService
|
|||||||
? OmsDocHelper.HashSalesProductPriceSnapshotForSync(currentSnapshot)
|
? OmsDocHelper.HashSalesProductPriceSnapshotForSync(currentSnapshot)
|
||||||
: OmsDocHelper.HashSalesProductRulesSnapshotForSync(currentSnapshot));
|
: OmsDocHelper.HashSalesProductRulesSnapshotForSync(currentSnapshot));
|
||||||
|
|
||||||
// 价格:附带在途审批,供前端展示「待审批 + 审批号」
|
// 价格:在途审批,或最近一次失败终态(驳回/撤回/执行失败)供重新提交引导
|
||||||
|
var approvalPending = false;
|
||||||
|
var approvalFailed = false;
|
||||||
int? approvalInstanceId = null;
|
int? approvalInstanceId = null;
|
||||||
string? approvalInstanceNo = null;
|
string? approvalInstanceNo = null;
|
||||||
string? approvalStatusName = null;
|
string? approvalStatusName = null;
|
||||||
var approvalPending = false;
|
string? approvalComment = null;
|
||||||
if (normalized == PriceOperatorType)
|
if (normalized == PriceOperatorType)
|
||||||
{
|
{
|
||||||
var bizKey = $"SalesProduct.PricePublish:{salesProductId}";
|
var approvalState = await ResolvePricePublishApprovalStateAsync(salesProductId);
|
||||||
var pendingApproval = await ApprovalInstanceRepository.FirstOrDefaultAsync(x =>
|
approvalPending = approvalState.Pending;
|
||||||
x.OperationCode == ApprovalCodes.SalesProductPublishPrice
|
approvalFailed = approvalState.Failed;
|
||||||
&& x.BizKey == bizKey
|
approvalInstanceId = approvalState.InstanceId;
|
||||||
&& x.Status == ApprovalInstanceStatus.Pending);
|
approvalInstanceNo = approvalState.InstanceNo;
|
||||||
if (pendingApproval != null)
|
approvalStatusName = approvalState.StatusName;
|
||||||
{
|
approvalComment = approvalState.Comment;
|
||||||
approvalPending = true;
|
|
||||||
approvalInstanceId = pendingApproval.Id;
|
|
||||||
approvalInstanceNo = pendingApproval.InstanceNo;
|
|
||||||
approvalStatusName = "待审批";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生效 = 最新 Active 发布记录 Content
|
// 生效 = 最新 Active 发布记录 Content
|
||||||
@ -462,43 +461,113 @@ public partial class SalesProductService : ApplicationService
|
|||||||
salesProductId,
|
salesProductId,
|
||||||
normalized,
|
normalized,
|
||||||
DateTime.Now);
|
DateTime.Now);
|
||||||
|
bool contentPending;
|
||||||
|
string? onlineVersion = null;
|
||||||
|
DateTime? onlinePublishTime = null;
|
||||||
|
string? onlineContentHash = null;
|
||||||
if (onlineRecord == null || string.IsNullOrWhiteSpace(onlineRecord.Content))
|
if (onlineRecord == null || string.IsNullOrWhiteSpace(onlineRecord.Content))
|
||||||
{
|
{
|
||||||
return new SalesProductPublishSyncStatusOutput
|
contentPending = true;
|
||||||
{
|
}
|
||||||
Pending = true,
|
else
|
||||||
OnlineVersion = null,
|
{
|
||||||
OnlinePublishTime = null,
|
onlineVersion = onlineRecord.Version;
|
||||||
PendingContentHash = currentHash,
|
onlinePublishTime = onlineRecord.PublishTime;
|
||||||
OnlineContentHash = null,
|
onlineContentHash = ComputeContentHash(
|
||||||
ApprovalPending = approvalPending,
|
normalized == PriceOperatorType
|
||||||
ApprovalInstanceId = approvalInstanceId,
|
? OmsDocHelper.HashSalesProductPriceSnapshotForSync(
|
||||||
ApprovalInstanceNo = approvalInstanceNo,
|
OmsDocHelper.DeserializePriceSnapshot(onlineRecord.Content))
|
||||||
ApprovalStatusName = approvalStatusName
|
: OmsDocHelper.HashSalesProductRulesSnapshotForSync(
|
||||||
};
|
OmsDocHelper.DeserializeRulesSnapshot(onlineRecord.Content)));
|
||||||
|
contentPending = !string.Equals(currentHash, onlineContentHash, StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
var onlineHash = ComputeContentHash(
|
// 内容已与线上一致时,旧驳回/撤回不再当失败引导;执行失败仍展示(可能空跑未落库)
|
||||||
normalized == PriceOperatorType
|
if (!contentPending
|
||||||
? OmsDocHelper.HashSalesProductPriceSnapshotForSync(
|
&& approvalFailed
|
||||||
OmsDocHelper.DeserializePriceSnapshot(onlineRecord.Content))
|
&& !string.Equals(approvalStatusName, "执行失败", StringComparison.Ordinal))
|
||||||
: OmsDocHelper.HashSalesProductRulesSnapshotForSync(
|
{
|
||||||
OmsDocHelper.DeserializeRulesSnapshot(onlineRecord.Content)));
|
approvalFailed = false;
|
||||||
|
approvalInstanceId = null;
|
||||||
|
approvalInstanceNo = null;
|
||||||
|
approvalStatusName = null;
|
||||||
|
approvalComment = null;
|
||||||
|
}
|
||||||
|
|
||||||
return new SalesProductPublishSyncStatusOutput
|
return new SalesProductPublishSyncStatusOutput
|
||||||
{
|
{
|
||||||
Pending = !string.Equals(currentHash, onlineHash, StringComparison.Ordinal),
|
Pending = contentPending,
|
||||||
OnlineVersion = onlineRecord.Version,
|
OnlineVersion = onlineVersion,
|
||||||
OnlinePublishTime = onlineRecord.PublishTime,
|
OnlinePublishTime = onlinePublishTime,
|
||||||
PendingContentHash = currentHash,
|
PendingContentHash = currentHash,
|
||||||
OnlineContentHash = onlineHash,
|
OnlineContentHash = onlineContentHash,
|
||||||
ApprovalPending = approvalPending,
|
ApprovalPending = approvalPending,
|
||||||
|
ApprovalFailed = approvalFailed,
|
||||||
ApprovalInstanceId = approvalInstanceId,
|
ApprovalInstanceId = approvalInstanceId,
|
||||||
ApprovalInstanceNo = approvalInstanceNo,
|
ApprovalInstanceNo = approvalInstanceNo,
|
||||||
ApprovalStatusName = approvalStatusName
|
ApprovalStatusName = approvalStatusName,
|
||||||
|
ApprovalComment = approvalComment
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解析价格发布审批态:优先 Pending;否则最近一条驳回/撤回/执行失败。
|
||||||
|
/// </summary>
|
||||||
|
private async Task<(
|
||||||
|
bool Pending,
|
||||||
|
bool Failed,
|
||||||
|
int? InstanceId,
|
||||||
|
string? InstanceNo,
|
||||||
|
string? StatusName,
|
||||||
|
string? Comment)> ResolvePricePublishApprovalStateAsync(int salesProductId)
|
||||||
|
{
|
||||||
|
var bizKey = $"SalesProduct.PricePublish:{salesProductId}";
|
||||||
|
var pendingApproval = await ApprovalInstanceRepository.FirstOrDefaultAsync(x =>
|
||||||
|
x.OperationCode == ApprovalCodes.SalesProductPublishPrice
|
||||||
|
&& x.BizKey == bizKey
|
||||||
|
&& x.Status == ApprovalInstanceStatus.Pending);
|
||||||
|
if (pendingApproval != null)
|
||||||
|
{
|
||||||
|
return (true, false, pendingApproval.Id, pendingApproval.InstanceNo, "待审批", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
var failedList = await ApprovalInstanceRepository.GetListAsync(x =>
|
||||||
|
x.OperationCode == ApprovalCodes.SalesProductPublishPrice
|
||||||
|
&& x.BizKey == bizKey
|
||||||
|
&& (x.Status == ApprovalInstanceStatus.Rejected
|
||||||
|
|| x.Status == ApprovalInstanceStatus.Withdrawn
|
||||||
|
|| x.Status == ApprovalInstanceStatus.ExecuteFailed));
|
||||||
|
var failed = failedList
|
||||||
|
.OrderByDescending(x => x.CompletedTime ?? x.CreateTime)
|
||||||
|
.ThenByDescending(x => x.Id)
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (failed == null)
|
||||||
|
{
|
||||||
|
return (false, false, null, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
var statusName = failed.Status switch
|
||||||
|
{
|
||||||
|
ApprovalInstanceStatus.Rejected => "已驳回",
|
||||||
|
ApprovalInstanceStatus.Withdrawn => "已撤回",
|
||||||
|
ApprovalInstanceStatus.ExecuteFailed => "执行失败",
|
||||||
|
_ => failed.Status.ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
string? comment = null;
|
||||||
|
if (failed.Status == ApprovalInstanceStatus.ExecuteFailed)
|
||||||
|
{
|
||||||
|
comment = string.IsNullOrWhiteSpace(failed.ExecuteMessage) ? null : failed.ExecuteMessage.Trim();
|
||||||
|
}
|
||||||
|
else if (failed.CurrentTaskId is int taskId)
|
||||||
|
{
|
||||||
|
var task = await ApprovalTaskRepository.FirstOrDefaultAsync(x => x.Id == taskId);
|
||||||
|
comment = string.IsNullOrWhiteSpace(task?.Comment) ? null : task!.Comment!.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (false, true, failed.Id, failed.InstanceNo, statusName, comment);
|
||||||
|
}
|
||||||
|
|
||||||
private static string ComputeContentHash(string content)
|
private static string ComputeContentHash(string content)
|
||||||
{
|
{
|
||||||
var hash = global::System.Security.Cryptography.SHA256.HashData(
|
var hash = global::System.Security.Cryptography.SHA256.HashData(
|
||||||
|
|||||||
@ -13,6 +13,7 @@ namespace Oms.Application.Services.Recharge;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 充值入账审批:通过后入账;驳回/撤回同步充值记录状态。
|
/// 充值入账审批:通过后入账;驳回/撤回同步充值记录状态。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ExposeServices(typeof(IApprovalOperationHandler))]
|
||||||
public class RechargeCreditApprovalHandler(
|
public class RechargeCreditApprovalHandler(
|
||||||
IRechargeRecordRepository rechargeRecordRepository,
|
IRechargeRecordRepository rechargeRecordRepository,
|
||||||
ICustomerRepository customerRepository,
|
ICustomerRepository customerRepository,
|
||||||
|
|||||||
@ -316,7 +316,9 @@ public static class OmsDocHelper
|
|||||||
|
|
||||||
private static object? ConvertJsonElement(JsonElement element) => element.ValueKind switch
|
private static object? ConvertJsonElement(JsonElement element) => element.ValueKind switch
|
||||||
{
|
{
|
||||||
|
// MySQL JSON 列会重排 object key;按名字排序后再入 Dictionary,避免 sync-status 误报待发布
|
||||||
JsonValueKind.Object => element.EnumerateObject()
|
JsonValueKind.Object => element.EnumerateObject()
|
||||||
|
.OrderBy(property => property.Name, StringComparer.Ordinal)
|
||||||
.ToDictionary(property => property.Name, property => ConvertJsonElement(property.Value)),
|
.ToDictionary(property => property.Name, property => ConvertJsonElement(property.Value)),
|
||||||
JsonValueKind.Array => element.EnumerateArray()
|
JsonValueKind.Array => element.EnumerateArray()
|
||||||
.Select(ConvertJsonElement)
|
.Select(ConvertJsonElement)
|
||||||
|
|||||||
@ -201,6 +201,75 @@ public class OmsDocHelperTests
|
|||||||
liveHash.Should().NotContain("0.0000");
|
liveHash.Should().NotContain("0.0000");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void HashSalesProductPriceSnapshotForSync_ShouldIgnoreJsonObjectKeyOrder()
|
||||||
|
{
|
||||||
|
// LIVE 明细原文 key 顺序 vs MySQL JSON 列重排后的顺序
|
||||||
|
var live = """
|
||||||
|
{
|
||||||
|
"salesProductId": 8,
|
||||||
|
"priceAreaRefs": [],
|
||||||
|
"prices": [
|
||||||
|
{
|
||||||
|
"id": 13,
|
||||||
|
"serialNumber": 1,
|
||||||
|
"status": 2,
|
||||||
|
"priceName": "运费",
|
||||||
|
"costItem": "freight",
|
||||||
|
"costUnit": "kg",
|
||||||
|
"currency": "CNY",
|
||||||
|
"factors": [],
|
||||||
|
"details": [
|
||||||
|
{
|
||||||
|
"id": 1511,
|
||||||
|
"priceId": 13,
|
||||||
|
"factorValuesJson": { "仓库": "2", "重量": "(0-0.5]" },
|
||||||
|
"calculationFormula": "total",
|
||||||
|
"calculatedValue": 10,
|
||||||
|
"customerGroupValues": { "全部客户": 10, "VIP": 12 }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
var onlineFromMysqlJson = """
|
||||||
|
{
|
||||||
|
"salesProductId": 8,
|
||||||
|
"priceAreaRefs": [],
|
||||||
|
"prices": [
|
||||||
|
{
|
||||||
|
"id": 13,
|
||||||
|
"serialNumber": 1,
|
||||||
|
"status": 2,
|
||||||
|
"priceName": "运费",
|
||||||
|
"costItem": "freight",
|
||||||
|
"costUnit": "kg",
|
||||||
|
"currency": "CNY",
|
||||||
|
"factors": [],
|
||||||
|
"details": [
|
||||||
|
{
|
||||||
|
"id": 1511,
|
||||||
|
"priceId": 13,
|
||||||
|
"factorValuesJson": { "重量": "(0-0.5]", "仓库": "2" },
|
||||||
|
"calculationFormula": "total",
|
||||||
|
"calculatedValue": 10,
|
||||||
|
"customerGroupValues": { "VIP": 12, "全部客户": 10 }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
|
var liveHash = OmsDocHelper.HashSalesProductPriceSnapshotForSync(
|
||||||
|
OmsDocHelper.DeserializePriceSnapshot(live));
|
||||||
|
var onlineHash = OmsDocHelper.HashSalesProductPriceSnapshotForSync(
|
||||||
|
OmsDocHelper.DeserializePriceSnapshot(onlineFromMysqlJson));
|
||||||
|
|
||||||
|
liveHash.Should().Be(onlineHash);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DeserializeJsonObject_ShouldCoerceIntegerValuedDecimalsToLong()
|
public void DeserializeJsonObject_ShouldCoerceIntegerValuedDecimalsToLong()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user