username@email.com
2024-09-03 b53678eec74cadc4d8d5773343b10ffa2adc5330
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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<OrderBidding>();
            var orderRes = new BaseRepository<Order>();
            var orderBiddingDetailRes = new BaseRepository<OrderBiddingDetail>();
            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();
        }
 
 
        
    }
}