using System; using System.Linq; using System.Threading.Tasks; using HHWMS.Web.Models; using Quartz; using WalkingTec.Mvvm.Core; using WalkingTec.Mvvm.Core.Support.Quartz; namespace HHWMS.Web { [PersistJobDataAfterExecution] [DisallowConcurrentExecution] public class AddSaleOutJob : WtmJob { public override async Task Execute(IJobExecutionContext context) { try { var unitWork = new UnitWork(Wtm); var first = unitWork.Find(x => x.Type == InventoryTranType.出库 && x.BillType == InventoryTransaction.ErpSaleOutBillType && x.UploadErpFlag != 1 && x.UploadErpFlag != null) .OrderBy(x => x.ID) .FirstOrDefault(); if (first != null) { var transactions = unitWork.Find(x => x.Type == InventoryTranType.出库 && x.BillType == InventoryTransaction.ErpSaleOutBillType && x.BillCode == first.BillCode && x.UploadErpFlag != 1) .ToList(); var vm = Wtm.CreateVM(); await vm.ProcessErpSaleOut(transactions, true); } var job = unitWork.FindSingle(x => x.JobName == context.JobDetail.Key.Name); if (job != null) { job.LastFireTime = TimeZoneInfo.ConvertTimeFromUtc( context.FireTimeUtc.DateTime, TimeZoneInfo.Local); if (context.NextFireTimeUtc != null) { job.NextFireTime = TimeZoneInfo.ConvertTimeFromUtc( context.NextFireTimeUtc.Value.DateTime, TimeZoneInfo.Local); } unitWork.Update(job); } } catch (Exception ex) { Wtm.DoLog("ERP成品出库补传失败", ActionLogTypesEnum.Job, "AddSaleOutJob", request: "error", result: ex.Message); } } } }