2024-11-14 16:47:47 +08:00

57 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Infrastructure;
using Infrastructure.Attribute;
using Microsoft.Extensions.DependencyInjection;
using Quartz;
using Quartz.Impl.Triggers;
using Quartz.Impl;
using SqlSugar.IOC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DOAN.Model.System;
using DOAN.Service.MES.dev.IService;
using DOAN.Service.MES.mm.IService;
namespace DOAN.Tasks.TaskScheduler
{
[AppService(ServiceType = typeof(Job_MovSlow_Execute), ServiceLifetime = LifeTime.Scoped)]
public class Job_MovSlow_Execute : JobBase, IJob
{
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private readonly IMmSlowMoveMaterialService MmSlowMoveMaterialService;
public Job_MovSlow_Execute(IMmSlowMoveMaterialService MmSlowMoveMaterialService)
{
this.MmSlowMoveMaterialService = MmSlowMoveMaterialService;
}
public async Task Execute(IJobExecutionContext context)
{
await ExecuteJob(context, async () => await Run(context));
}
public async Task Run(IJobExecutionContext context)
{
AbstractTrigger trigger = (context as JobExecutionContextImpl).Trigger as AbstractTrigger;
//var info = await tasksQzService.CopyNew().GetByIdAsync(trigger.JobName);
// CopyNew 在多线程环境中,为每个线程或任务创建新的 SugarScope 实例以避免线程安全问题
var info = await DbScoped.SugarScope.CopyNew().Queryable<SysTasks>().FirstAsync(f => f.ID == trigger.JobName);
if (info == null)
{
throw new CustomException($"任务{trigger?.JobName}呆滞品任务调度请求执行失败,任务不存在");
}
bool result = MmSlowMoveMaterialService.GenerateShopFloorSluggishProducts(DateTime.Today, "任务调度");
logger.Info($"job任务【{info.Name}】设备管理调度请求执行结果=" + result);
}
}
}