|
@@ -1,3 +1,5 @@
|
|
|
|
|
+using Admin.NET.Core.Service;
|
|
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
using System.Text.Json;
|
|
using System.Text.Json;
|
|
|
|
|
|
|
|
namespace Admin.NET.Plugin.AiDOP.MaterialWarehouse;
|
|
namespace Admin.NET.Plugin.AiDOP.MaterialWarehouse;
|
|
@@ -12,14 +14,24 @@ namespace Admin.NET.Plugin.AiDOP.MaterialWarehouse;
|
|
|
public class S5MdpSyncTransformService : ITransient
|
|
public class S5MdpSyncTransformService : ITransient
|
|
|
{
|
|
{
|
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly ISqlSugarClient _db;
|
|
|
|
|
+ private readonly SysNoticeService _sysNoticeService;
|
|
|
|
|
+ private readonly ILogger<S5MdpSyncTransformService> _logger;
|
|
|
private const string JobCode = "S5_MDP_SYNC_TRANSFORM";
|
|
private const string JobCode = "S5_MDP_SYNC_TRANSFORM";
|
|
|
private const string JobName = "S5 物料仓储 MDP 同步与转换";
|
|
private const string JobName = "S5 物料仓储 MDP 同步与转换";
|
|
|
private const string T8ConfigId = "t8_v5";
|
|
private const string T8ConfigId = "t8_v5";
|
|
|
private const string ModuleCode = "S5";
|
|
private const string ModuleCode = "S5";
|
|
|
-
|
|
|
|
|
- public S5MdpSyncTransformService(ISqlSugarClient db)
|
|
|
|
|
|
|
+ // FAILURE-NOTIFICATION-1:超级管理员 superAdmin.NET(AccountType=999)
|
|
|
|
|
+ private const long NoticeReceiverUserId = 1300000000101L;
|
|
|
|
|
+ private const string NoticeReceiverUserName = "超级管理员";
|
|
|
|
|
+
|
|
|
|
|
+ public S5MdpSyncTransformService(
|
|
|
|
|
+ ISqlSugarClient db,
|
|
|
|
|
+ SysNoticeService sysNoticeService,
|
|
|
|
|
+ ILogger<S5MdpSyncTransformService> logger)
|
|
|
{
|
|
{
|
|
|
_db = db;
|
|
_db = db;
|
|
|
|
|
+ _sysNoticeService = sysNoticeService;
|
|
|
|
|
+ _logger = logger;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public async Task<S5MdpSyncTransformResult> RunFullAsync(
|
|
public async Task<S5MdpSyncTransformResult> RunFullAsync(
|
|
@@ -72,7 +84,7 @@ public class S5MdpSyncTransformService : ITransient
|
|
|
}
|
|
}
|
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
|
{
|
|
{
|
|
|
- await MarkTransformRunFailedAsync(runLogId, now, ex.Message);
|
|
|
|
|
|
|
+ await MarkTransformRunFailedAsync(runLogId, now, ex.Message, batchId);
|
|
|
throw;
|
|
throw;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -484,8 +496,9 @@ WHERE id=@Id",
|
|
|
new SugarParameter("@Id", runLogId));
|
|
new SugarParameter("@Id", runLogId));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private async Task MarkTransformRunFailedAsync(long runLogId, DateTime startedAt, string message)
|
|
|
|
|
|
|
+ private async Task MarkTransformRunFailedAsync(long runLogId, DateTime startedAt, string message, string batchId)
|
|
|
{
|
|
{
|
|
|
|
|
+ bool runLogUpdated = false;
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
var finishedAt = DateTime.Now;
|
|
var finishedAt = DateTime.Now;
|
|
@@ -498,12 +511,33 @@ WHERE id=@Id",
|
|
|
new SugarParameter("@DurationMs", (int)(finishedAt - startedAt).TotalMilliseconds),
|
|
new SugarParameter("@DurationMs", (int)(finishedAt - startedAt).TotalMilliseconds),
|
|
|
new SugarParameter("@ErrorMessage", Truncate(message, 2000)),
|
|
new SugarParameter("@ErrorMessage", Truncate(message, 2000)),
|
|
|
new SugarParameter("@Id", runLogId));
|
|
new SugarParameter("@Id", runLogId));
|
|
|
|
|
+ runLogUpdated = true;
|
|
|
}
|
|
}
|
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
|
{
|
|
{
|
|
|
// 写库本身失败兜底:远端 MySQL 瞬断导致 MarkFailed 自身也连不上
|
|
// 写库本身失败兜底:远端 MySQL 瞬断导致 MarkFailed 自身也连不上
|
|
|
Console.Error.WriteLine($"[S5MdpSyncTransform] MarkTransformRunFailed write failed (runLogId={runLogId}): {ex.Message}");
|
|
Console.Error.WriteLine($"[S5MdpSyncTransform] MarkTransformRunFailed write failed (runLogId={runLogId}): {ex.Message}");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // FAILURE-NOTIFICATION-1:写库 FAILED 成功后发通知给超级管理员;通知失败不影响主流程
|
|
|
|
|
+ if (!runLogUpdated) return;
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ await _sysNoticeService.AddNotice(new AddNoticeInput
|
|
|
|
|
+ {
|
|
|
|
|
+ Title = "S5 物料仓储 T8 KPI 跑批失败",
|
|
|
|
|
+ Content = $"模块:S5 物料仓储\n批次ID:{batchId}\n失败时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}\n错误信息:{Truncate(message, 1000)}\n\n请查看 mdp_transform_run_log 获取完整错误与重试记录。",
|
|
|
|
|
+ Type = NoticeTypeEnum.NOTICE,
|
|
|
|
|
+ PublicTime = DateTime.Now,
|
|
|
|
|
+ Status = NoticeStatusEnum.PUBLIC,
|
|
|
|
|
+ PublicUserId = NoticeReceiverUserId,
|
|
|
|
|
+ PublicUserName = NoticeReceiverUserName
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception notifyEx)
|
|
|
|
|
+ {
|
|
|
|
|
+ _logger.LogError(notifyEx, "[S5MdpSyncTransform] SysNotice 发送失败 (runLogId={RunLogId}, batchId={BatchId})", runLogId, batchId);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static string BuildRunSummaryJson(S5MdpSyncTransformResult r)
|
|
private static string BuildRunSummaryJson(S5MdpSyncTransformResult r)
|