using cylsg.Core; using cylsg.Model.OrderModel; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace cylsg.Application.Timers { public class TimedBackgroundService : IHostedService, IDisposable { private Timer _timer; public Task StartAsync(CancellationToken cancellationToken) { _timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromSeconds(60*60)); return Task.CompletedTask; } private async void DoWork(object? state) { var orderBiddingRes = new BaseRepository(); var orderRes = new BaseRepository(); var orderBiddingDetailRes = new BaseRepository(); var orders = await orderRes.GetListAsync(x => x.OrderStatus < 2 && x.IsEn == true && x.IsDeleted == false && x.WordEndTime <= DateTime.Now.AddDays(-1)); foreach (var order in orders) { var sss = await orderBiddingRes.GetListAsync(x => x.OrderId == order.Id && x.IsEn == true && x.IsDeleted == false && x.IsSelected == true); var bbb = sss.Select(x => x.Id).ToList(); var oCount = await orderBiddingDetailRes.CountAsync(x => bbb.Contains(x.OrderBiddingId) && x.IsEn == true && x.IsDeleted == false && x.IsShenPi != (int)IsShenPis.yishenpi); if (oCount == 0) { order.OrderStatus = (int)OrderStatuses.jiesuanwanbi; var res = await orderRes.UpdateAsync(order); } } } public Task StopAsync(CancellationToken cancellationToken) { Console.WriteLine("StopAsync"); return Task.CompletedTask; } public void Dispose() { _timer?.Dispose(); } } }