定时任务推送预警(》12小时没有推送的)

This commit is contained in:
钟喜旺 2024-08-01 09:26:01 +08:00
parent 8f8d7b2a44
commit 5cd6c4f6c6
3 changed files with 54 additions and 1 deletions

View File

@ -98,10 +98,12 @@ public class TrackPushService : ApplicationService
foreach (var dateTime in dateTimes)
{
var rows = 0;
var pageindex = 1;
do
{
rows = await _orderRepository.PushWarnOrdersAsync(pageSize,dateTime);
rows = await _orderRepository.PushWarnOrdersAsync(pageSize,pageindex,dateTime);
total+=rows;
pageindex++;
await Task.Delay(waitTime);
}while (rows!= pageSize);
}

View File

@ -31,6 +31,12 @@ public interface IOrderRepository : IBasicRepository<OrderEntity>
/// <returns></returns>
Task<int> PushWarnOrdersAsync(int pageSize,DateTime createTime);
/// <summary>
/// 更新推送预警单
/// </summary>
/// <returns></returns>
Task<int> PushWarnOrdersAsync(int pageSize, int pageindex, DateTime createTime);
/// <summary>
/// 更新缺失标记,时区缺失和发生地缺失标记,1表示时区,2表示发生地,3表示两种
/// </summary>

View File

@ -1,5 +1,6 @@
using SJZY.Track.Domain;
using SJZY.Track.Domain.Aggregates.OrderAggregate;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
using SJZY.Track.Domain.Consts;
using SJZY.Track.Domain.Dtos.Order;
@ -73,6 +74,50 @@ WHERE `b`.`IsCompleted` = 0 AND `b`.`QuestionType` != 1 AND `b`.`CreateTime` < @
AND `a`.`IsDeleted` = 0 AND `b`.`IsDeleted` = 0 limit @pageSize", new { pageSize,createTime });
}
/// <summary>
/// 更新推送预警单
/// </summary>
/// <param name="pageSize"></param>
/// <param name="pageindex"></param>
/// <param name="createTime"></param>
/// <returns></returns>
public async Task<int> PushWarnOrdersAsync(int pageSize,int pageindex, DateTime createTime)
{
var ordersToUpdate = await Context.Queryable<OrderEntity>()
.LeftJoin<TrackPushConfigEntity>((b, a) => a.SubSystemId == b.SubSystemId && a.CustomId == b.CustomId)
.Where((b, a) =>
!b.IsCompleted
&& b.QuestionType != 1
&& b.CreateTime < createTime
&& !a.IsDeleted
&& !b.IsDeleted)
.Select((b, a) => b)
.ToPageListAsync(pageindex,pageSize);
var latestPushTimeIds = new LinkedList<int>();
var questionZeroIds = new LinkedList<int>();
foreach (var item in ordersToUpdate)
{
var questionType = item.LatestPushTime == null
|| item.LatestPushTime < DateTime.Now.AddHours(-12) ? 2 : 0;
if(item.QuestionType== questionType) continue;
if(questionType==2) latestPushTimeIds.AddLast(item.Id);
else questionZeroIds.AddLast(item.Id);
}
int rows = 0;
if(latestPushTimeIds.Count>0)rows+= UpdateOrderQuestionType(2, latestPushTimeIds);
if(questionZeroIds.Count>0)rows+= UpdateOrderQuestionType(0, questionZeroIds);
return rows;
}
private int UpdateOrderQuestionType(int questionType, IEnumerable<int> ids)
{
var idsString = string.Join(",", ids);
return Context.Ado.ExecuteCommand(
$"UPDATE `t_order` SET `QuestionType` = @questionType ,UpdateTime= current_timestamp WHERE `Id` IN ({idsString})", new { questionType });
}
#region 订单关联
public async Task<List<LinkedOrderVO>> GetLinkedOrdersAsync(int[] orderIds)