using SJZY.Track.Domain.Aggregates.ForewarningAggregate; using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Dtos.Forewarning; namespace SJZY.Track.Application.Services.TrackOrders; /// /// 订单预警服务 /// [ApiExplorerSettings(GroupName = "轨迹订单")] [Route("/Track/Order")] public class OrderWarningService : ApplicationService { private readonly IOrderRepository _orderRepository; private readonly IWarningRecordEsRepository _warningRecordEsRepository; public OrderWarningService(IWarningRecordEsRepository warningRecordEsRepository, IOrderRepository orderRepository) { _warningRecordEsRepository = warningRecordEsRepository; _orderRepository = orderRepository; } /// /// 获取订单运输时效预警分页列表 /// /// /// /// [HttpGet("GetOrderWarningPageList/{userId:int?}")] [HttpPost("GetOrderWarningPageList")] public async Task> GetOrderWarningPageListAsync( [FromBody] GetOrderWarningPageListVo inputVo, [FromQuery] int? userId) { if (userId != null) inputVo.NotifyUserId = userId; var result = await _warningRecordEsRepository.GetOrderWarningPageListAsync(inputVo); var orderIds = result.list.Select(x => x.OrderId).ToList(); var orders = await _orderRepository.GetListAsync(x => orderIds.Contains(x.Id), x => new { x.Id, x.LatestTrackContent, x.LatestTrackTime, x.LatestTrackPlace }); var list = new List(); result.list.ForEach(x => { var item = new GetOrderWarningPageOutput { SubSystemName = x.SubSystemName, Rule = x.Rule, Counter = x.Counter, IsLast = x.IsLast, WarningName = x.WarningName, WarningStatus = x.WarningStatus, CreateTime = x.CreateTime, NotifyUser = x.NotifyUserName, CustomName = x.CustomName, }; var order = orders.FirstOrDefault(o => o.Id == x.OrderId); if (order == default) return; item.LatestTrackTime = order.LatestTrackTime; item.LatestTrackPlace = order.LatestTrackPlace; item.LatestTrackContent = order.LatestTrackContent; list.Add(item); }); return new UnifyPageResultDto(list, inputVo.PageIndex, inputVo.PageSize, (int) result.total); } }