diff --git a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs index ef481d06..5460ce3c 100644 --- a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs @@ -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, 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 }); } /// @@ -81,41 +81,45 @@ AND `a`.`IsDeleted` = 0 AND `b`.`IsDeleted` = 0 limit @pageSize", new { pageSize /// /// /// - public async Task PushWarnOrdersAsync(int pageSize,int pageindex, DateTime createTime) + public async Task PushWarnOrdersAsync(int pageSize, int pageindex, DateTime createTime) { - var ordersToUpdate = await Context.Queryable() - .LeftJoin((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() + .InnerJoin((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(); var questionZeroIds = new LinkedList(); 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 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 订单关联