feat: 修复更新推送预警单bug

This commit is contained in:
钟喜旺 2024-08-06 22:14:57 +08:00
parent 8bcef37b74
commit f50d427325

View File

@ -1,7 +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;
namespace SJZY.Track.Repository.Repositories;
@ -25,7 +24,8 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
{
var idsString = string.Join(",", ids);
return Context.Ado.ExecuteCommandAsync(
$"UPDATE `t_order` SET `DeficiencyTag` = @newValue ,UpdateTime= current_timestamp WHERE `Id` IN ({idsString})", new { newValue });
$"UPDATE `t_order` SET `DeficiencyTag` = @newValue ,UpdateTime= current_timestamp WHERE `Id` IN ({idsString})",
new { newValue });
}
public async Task UpdateOrderAsync(OrderEntity order)
@ -71,7 +71,7 @@ SET `b`.`QuestionType` = CASE
WHEN `b`.`LatestPushTime` < DATE_SUB(NOW(), INTERVAL 12 HOUR) THEN 2
ELSE 0 END
WHERE `b`.`IsCompleted` = 0 AND `b`.`QuestionType` != 1 AND `b`.`CreateTime` < @createTime
AND `a`.`IsDeleted` = 0 AND `b`.`IsDeleted` = 0 limit @pageSize", new { pageSize,createTime });
AND `a`.`IsDeleted` = 0 AND `b`.`IsDeleted` = 0 limit @pageSize", new { pageSize, createTime });
}
/// <summary>
@ -81,41 +81,45 @@ AND `a`.`IsDeleted` = 0 AND `b`.`IsDeleted` = 0 limit @pageSize", new { pageSize
/// <param name="pageindex"></param>
/// <param name="createTime"></param>
/// <returns></returns>
public async Task<int> PushWarnOrdersAsync(int pageSize,int pageindex, DateTime createTime)
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
var ordersToUpdate = await Context.Queryable<OrderEntity>()
.InnerJoin<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);
.Select((b, a) => new { Order = 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);
var order = item.Order;
var questionType = !order.LatestPushTime.HasValue
|| order.LatestPushTime < DateTime.Now.AddHours(-12)
? 2
: 0;
if (order.QuestionType == questionType) continue;
if (questionType == 2) latestPushTimeIds.AddLast(order.Id);
else questionZeroIds.AddLast(order.Id);
}
int rows = 0;
if(latestPushTimeIds.Count>0)rows+= UpdateOrderQuestionType(2, latestPushTimeIds);
if(questionZeroIds.Count>0)rows+= UpdateOrderQuestionType(0, questionZeroIds);
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 });
$"UPDATE `t_order` SET `QuestionType` = @questionType ,UpdateTime= current_timestamp WHERE `Id` IN ({idsString})",
new { questionType });
}
#region 订单关联