using Cksoft.Unity; using Cksoft.Unity.Log4NetConfig; using DllEapBll; using DllEapDal.OFILM; using DllUfpDal; using Hangfire; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace WebMainFrameForEap.Config { /// /// 管理服务启动项111 /// public class TaskLaunchManager { public IConfiguration Configuration { get; set; } private ILogger myloger = AppConfigurtaionServices.MyLog; public TaskLaunchManager(IConfiguration configuration) { Configuration = configuration; } /// /// 启动任务 /// public void LaunchTask() { if (Configuration["CollectEapData"] != null && Convert.ToBoolean(Configuration["CollectEapData"]) == true) { this.StartCollectEapAlarmData(); this.StartHandleFailCollection(); } if (Configuration["DisconnectionNotice"] != null && Convert.ToBoolean(Configuration["DisconnectionNotice"]) == true) { this.IPDifferentNotice(); this.AAMaterialNotice(); } if (Configuration["PushBIData"] != null && Convert.ToBoolean(Configuration["PushBIData"]) == true) { // this.StartPushBIStatusData(); this.StartPushBIOutput(); } if (Convert.ToBoolean(Configuration["SyncEmployee"]) == true) { StartSyncEmployee(); } if (Convert.ToBoolean(Configuration["SyncSample"])) { StartSample(); } if (Configuration["ClearTempView"] == "true") { ClearTempViews(); } if (Configuration["SyncMacLastStatus"] == "true") { SyncMacLastStatus(); } if (Configuration["SyncMacOutPutTime"] == "true") { SyncMacOutPutTime(); } } private void SyncMacOutPutTime() { var cron = $"0 01 0/1 * * ?"; MacOutPutTimeDal dal = new MacOutPutTimeDal(); RecurringJob.AddOrUpdate(() => dal.SetData(), cron, TimeZoneInfo.Local); } /// /// Sample校验 /// private void StartSample() { var cron = $"0 0/10 * * * ?"; SamplePara sample = new SamplePara(); RecurringJob.AddOrUpdate(() => sample.Get(), cron); } /// /// 定时汇总机台报警等数据 /// public void StartCollectEapAlarmData() { var hour = Convert.ToInt32(Configuration["ColllectTimeSpan:Hour"]); var minute = Convert.ToInt32(Configuration["ColllectTimeSpan:Minute"]); // 设置汇总报警等数据定时任务 var cron = $"0 */{minute} {hour} * * ?"; if (hour == 0) { cron = $"0 */{minute} * * * ?"; } // RecurringJob.AddOrUpdate(() => EapDataCollectBll.CollectEapData(), cron); } /// /// BI失败数据处理 /// public void StartHandleFailCollection() { BackgroundJob.Enqueue(() => EapDataCollectBll.HandleFailCollection()); } /// /// 同步员工账号 /// public void StartSyncEmployee() { var cron = $"0 0 2 1 * *"; var service = new OfilmRzSyncService(); RecurringJob.AddOrUpdate(() => service.Sync(), cron); } /// /// BI产量数据 /// public void StartPushBIOutput() { var cron = $"0 */10 * * * ?"; RecurringJob.AddOrUpdate(() => EapDataCollectBll.PushBIOutput(), cron); // BackgroundJob.Enqueue(() => EapDataCollectBll.PushBIOutput()); } /// /// 断线通知 /// public void DisconnectionNotice() { myloger.LogError($"机台断线邮件定时任务开始"); var cron = Configuration["DisConnNoticeCron"].ToString(); RecurringJob.AddOrUpdate(() => MailNotice.DisconnectionNotice(1), cron, TimeZoneInfo.Local); myloger.LogError($"机台断线邮件定时任务结束"); } /// /// ip地址不一致通知 /// public void IPDifferentNotice() { myloger.LogError($"ip地址不一致邮件定时任务开始"); var cron = Configuration["DisConnNoticeCron"].ToString(); RecurringJob.AddOrUpdate(() => MailNotice.IPDifferentAndDiconnectionNotice(), cron, TimeZoneInfo.Local); myloger.LogError($"ip地址不一致邮件定时任务结束"); } /// /// AA抛料率未上传预警 /// public void AAMaterialNotice() { myloger.LogError($"AA抛料率预警邮件定时任务开始"); var cron = Configuration["AAMaterialNoticeCron"].ToString(); RecurringJob.AddOrUpdate(() => MailNotice.AAMaterialUploadErrorNotice(), cron, TimeZoneInfo.Local); myloger.LogError($"AA抛料率预警邮件定时任务结束"); } /// /// 删除因查询看板生成的临时视图 /// public void ClearTempViews() { var cron = $"0 0/15 * * * *"; MacStatusTotalDal dal = new MacStatusTotalDal(); RecurringJob.AddOrUpdate(() => dal.ClearTempViews(), cron); } /// /// 计算 /// 5 public void SyncMacLastStatus() { myloger.LogError($"计算机台当班最后状态开始"); var cron = Configuration["SyncLastStatusCron"].ToString(); var dal = new MacLastStatusDal(); RecurringJob.AddOrUpdate(() => dal.SyncLastStatus(), cron, TimeZoneInfo.Local); myloger.LogError($"计算机台当班最后状态结束"); } } }