using System.Globalization;
using System.Text.Json;
using Admin.NET.Plugin.AiDOP.Infrastructure;
using Admin.NET.Plugin.AiDOP.Order;
using Admin.NET.Plugin.AiDOP.WorkOrder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Admin.NET.Plugin.AiDOP.Production;
/// 工单排产动作:生成排程、优先级调整并重检。
[ApiDescriptionSettings(Order = 264, Description = "工单排产动作")]
[Route("api/Production")]
[AllowAnonymous]
[NonUnify]
public class ProductionSchedulingActionService : IDynamicApiController, ITransient
{
private readonly ISqlSugarClient _db;
private readonly UserManager _userManager;
private readonly ProductionScheduleGenerationService _scheduleGen;
private readonly WorkOrderRoutingSyncService _routingSync;
private readonly AidopActionRunLogWriter _runLog;
private readonly MdpRefreshDispatcher _dispatcher;
private readonly ILogger _logger;
/// RUNNING 超过此时长视为僵死并自动关闭(防单飞永久堵死)。
private static readonly TimeSpan StaleRunningAge = TimeSpan.FromHours(3);
public ProductionSchedulingActionService(
ISqlSugarClient db,
UserManager userManager,
ProductionScheduleGenerationService scheduleGen,
WorkOrderRoutingSyncService routingSync,
AidopActionRunLogWriter runLog,
MdpRefreshDispatcher dispatcher,
ILogger logger)
{
_db = db;
_userManager = userManager;
_scheduleGen = scheduleGen;
_routingSync = routingSync;
_runLog = runLog;
_dispatcher = dispatcher;
_logger = logger;
}
public const string ActionScheduleGenerate = "S2_SCHEDULE_GENERATE";
///
/// 提交全量生产排程(异步)。立即返回 runId,后台执行;前端轮询 status。
///
[DisplayName("生成生产排程")]
[HttpPost("scheduling/generate")]
public async Task