321
This commit is contained in:
parent
6f75dfbabd
commit
09018795bf
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<NuGetAuditMode>all</NuGetAuditMode>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using Hangfire;
|
using Hangfire;
|
||||||
|
|
||||||
namespace CoreCms.Net.Task
|
namespace CoreCms.Net.Task
|
||||||
|
|
@ -65,6 +66,9 @@ namespace CoreCms.Net.Task
|
||||||
//定时刷新获取微信AccessToken
|
//定时刷新获取微信AccessToken
|
||||||
RecurringJob.AddOrUpdate<RefreshWeChatAccessTokenJob>(s => s.Execute(), "0 0/4 * * * ? ", TimeZoneInfo.Local); // 每2分钟刷新获取微信AccessToken
|
RecurringJob.AddOrUpdate<RefreshWeChatAccessTokenJob>(s => s.Execute(), "0 0/4 * * * ? ", TimeZoneInfo.Local); // 每2分钟刷新获取微信AccessToken
|
||||||
|
|
||||||
|
// 预约状态处理(每分钟执行一次)
|
||||||
|
RecurringJob.AddOrUpdate<SQReservationJob>(s => s.Execute(), "0 0/1 * * * ? ", TimeZoneInfo.Local);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,18 @@
|
||||||
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using CoreCms.Net.Caching.AutoMate.RedisCache;
|
using CoreCms.Net.Caching.AutoMate.RedisCache;
|
||||||
using CoreCms.Net.Configuration;
|
using CoreCms.Net.Configuration;
|
||||||
using CoreCms.Net.IServices;
|
using CoreCms.Net.IServices;
|
||||||
using CoreCms.Net.Model.Entities;
|
using CoreCms.Net.Model.Entities;
|
||||||
using CoreCms.Net.WeChat.Service.HttpClients;
|
using CoreCms.Net.WeChat.Service.HttpClients;
|
||||||
using CoreCms.Net.WeChat.Service.Options;
|
using CoreCms.Net.WeChat.Service.Options;
|
||||||
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
using SKIT.FlurlHttpClient;
|
using SKIT.FlurlHttpClient;
|
||||||
using SKIT.FlurlHttpClient.Wechat;
|
using SKIT.FlurlHttpClient.Wechat;
|
||||||
using SKIT.FlurlHttpClient.Wechat.Api;
|
using SKIT.FlurlHttpClient.Wechat.Api;
|
||||||
|
|
@ -53,6 +57,7 @@ namespace CoreCms.Net.Task
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("刷新微信token");
|
||||||
//微信公众号刷新
|
//微信公众号刷新
|
||||||
if (!string.IsNullOrEmpty(_weChatOptions.WeiXinAppId) && !string.IsNullOrEmpty(_weChatOptions.WeiXinAppSecret))
|
if (!string.IsNullOrEmpty(_weChatOptions.WeiXinAppId) && !string.IsNullOrEmpty(_weChatOptions.WeiXinAppSecret))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
89
CoreCms.Net.Task/SQReservationJob.cs
Normal file
89
CoreCms.Net.Task/SQReservationJob.cs
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
using CoreCms.Net.IServices;
|
||||||
|
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace CoreCms.Net.Task
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 预约定时清理
|
||||||
|
/// </summary>
|
||||||
|
public class SQReservationJob
|
||||||
|
{
|
||||||
|
private readonly ISQReservationsServices _reservationsServices;
|
||||||
|
private readonly ISQReservationParticipantsServices _participantsServices;
|
||||||
|
public SQReservationJob(ISQReservationsServices reservationsServices,
|
||||||
|
ISQReservationParticipantsServices participantsServices)
|
||||||
|
{
|
||||||
|
_reservationsServices = reservationsServices;
|
||||||
|
_participantsServices = participantsServices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async System.Threading.Tasks.Task Execute()
|
||||||
|
{
|
||||||
|
|
||||||
|
Console.WriteLine("SQReservationJob");
|
||||||
|
var now = DateTime.Now;
|
||||||
|
Console.WriteLine("将已到结束时间的预约置为已结束(3)");
|
||||||
|
// 1) 将已到结束时间的预约置为已结束(3)
|
||||||
|
var endedList = await _reservationsServices.QueryListByClauseAsync(
|
||||||
|
r => r.status == 2 && r.end_time <= now,
|
||||||
|
r => r.id, OrderByType.Asc);
|
||||||
|
if (endedList != null && endedList.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var item in endedList)
|
||||||
|
{
|
||||||
|
item.status = 3;
|
||||||
|
item.updated_at = now;
|
||||||
|
}
|
||||||
|
await _reservationsServices.UpdateAsync(endedList);
|
||||||
|
}
|
||||||
|
Console.WriteLine("将开始时间已到且未结束的预约置为进行中");
|
||||||
|
// 2) 将开始时间已到且未结束的预约置为进行中(2)
|
||||||
|
var startedList = await _reservationsServices.QueryListByClauseAsync(
|
||||||
|
r => r.status == 1 && r.start_time <= now && r.end_time > now,
|
||||||
|
r => r.id, OrderByType.Asc);
|
||||||
|
if (startedList != null && startedList.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var item in startedList)
|
||||||
|
{
|
||||||
|
item.status = 2;
|
||||||
|
item.updated_at = now;
|
||||||
|
}
|
||||||
|
await _reservationsServices.UpdateAsync(startedList);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3) 开始前30分钟内,人数已凑齐则置为锁定(1)
|
||||||
|
Console.WriteLine("开始前30分钟内,人数已凑齐则置为锁定(1)");
|
||||||
|
var threshold = now.AddMinutes(30);
|
||||||
|
var toLockList = await _reservationsServices.QueryListByClauseAsync(
|
||||||
|
r => r.status == 0 && r.start_time > now && r.start_time <= threshold,
|
||||||
|
r => r.id, OrderByType.Asc);
|
||||||
|
if (toLockList != null && toLockList.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var item in toLockList)
|
||||||
|
{
|
||||||
|
// 当前有效参与人数(未退出)
|
||||||
|
var count = await _participantsServices.GetCountAsync(p => p.reservation_id == item.id && p.status == 0);
|
||||||
|
if (count >= item.player_count)
|
||||||
|
{
|
||||||
|
item.status = 1;
|
||||||
|
item.updated_at = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 仅更新被修改的项
|
||||||
|
var changed = toLockList.Where(x => x.status == 1).ToList();
|
||||||
|
if (changed.Count > 0)
|
||||||
|
{
|
||||||
|
await _reservationsServices.UpdateAsync(changed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user