From 91ad7eebb8fb022a0598b7e70222198351d5bf02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=86=9B?= <2357729423@qq.com> Date: Fri, 15 Mar 2024 14:49:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TrackPushContentConfigDto.cs | 44 +++++ .../Events/TrackUpsertEvent.cs | 4 +- .../Events/UpdateOrderTrackEvent.cs | 5 + .../Services/ITrackPushCacheService.cs | 18 +- .../OrderLinkAfterFillTrackHandler.cs | 4 +- .../EventHandlers/TrackRefreshEventHandler.cs | 4 +- .../EventHandlers/TrackUpsertEventHandler.cs | 21 ++- .../Services/ProvideServices/TrackService.cs | 8 +- .../TrackPush/TrackPushCacheService.cs | 33 +--- .../Services/TrackPush/TrackPushService.cs | 173 ++++++++++-------- .../Aggregates/OrderAggregate/OrderEntity.cs | 8 +- .../TrackDetailsIndex.cs | 5 + .../Dtos/Order/LinkedOrderVO.cs | 10 +- .../Dtos/TrackDetails/MatchTrackContentDto.cs | 5 + .../Enums/TrackProblemType.cs | 15 ++ src/SJZY.Track.Domain/GlobalConst.cs | 5 + .../Queries/ProvideQueries.cs | 1 + .../Repositories/OrderRepository.cs | 2 +- 18 files changed, 234 insertions(+), 131 deletions(-) create mode 100644 src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs create mode 100644 src/SJZY.Track.Domain/Enums/TrackProblemType.cs diff --git a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs new file mode 100644 index 00000000..ed2e02d0 --- /dev/null +++ b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs @@ -0,0 +1,44 @@ +namespace SJZY.Track.Application.Contract.Dtos.ProvideServices; + +public class TrackPushContentConfigDto +{ + /// + /// 扩展字段参数值 + /// + public string? ExpandFieldsValue { get; set; } + + /// + /// 推送单号类型(主数据枚举TrackOrderType) + /// + public int OrderType { get; set; } + + /// + /// 轨迹代码参数值 + /// + public string? TrackContentCodeValue { get; set; } + + /// + /// 轨迹内容id + /// + public int TrackContentId { get; set; } + + /// + /// 轨迹内容参数值 + /// + public string? TrackContentValue { get; set; } + + /// + /// 轨迹内容英文参数值 + /// + public string? TrackEnContentValue { get; set; } + + /// + /// 轨迹状态参数值 + /// + public string? TrackStatusValue { get; set; } + + /// + /// 轨迹时区GMT + /// + public double? TrackTimeZone { get; set; } +} \ No newline at end of file diff --git a/src/SJZY.Track.Application.Contract/Events/TrackUpsertEvent.cs b/src/SJZY.Track.Application.Contract/Events/TrackUpsertEvent.cs index 04f91415..56032acb 100644 --- a/src/SJZY.Track.Application.Contract/Events/TrackUpsertEvent.cs +++ b/src/SJZY.Track.Application.Contract/Events/TrackUpsertEvent.cs @@ -20,9 +20,9 @@ public class TrackUpsertEvent : UpsertTrackInput public int SubSystemId { get; set; } /// - /// 订单是否推送完成(异步维护) + /// 最新推送代码(异步维护) /// - public bool IsPushCompleted { get; set; } + public int? LatestPushTrackContentId { get; set; } /// /// 上游子系统id diff --git a/src/SJZY.Track.Application.Contract/Events/UpdateOrderTrackEvent.cs b/src/SJZY.Track.Application.Contract/Events/UpdateOrderTrackEvent.cs index 779415e2..7daa9a7d 100644 --- a/src/SJZY.Track.Application.Contract/Events/UpdateOrderTrackEvent.cs +++ b/src/SJZY.Track.Application.Contract/Events/UpdateOrderTrackEvent.cs @@ -41,4 +41,9 @@ public class UpdateOrderTrackEvent /// 轨迹时区 /// public float TrackTimeZone { get; set; } + + /// + /// 轨迹代码 + /// + public string TrackCode { get; set; } = null!; } \ No newline at end of file diff --git a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs index 378d2d02..acc00b72 100644 --- a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs +++ b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs @@ -1,4 +1,6 @@ -namespace SJZY.Track.Application.Contract.Services; +using SJZY.Track.Application.Contract.Dtos.ProvideServices; + +namespace SJZY.Track.Application.Contract.Services; public interface ITrackPushCacheService { @@ -10,12 +12,22 @@ public interface ITrackPushCacheService Task IsPushAsync(int customId); /// - /// 判断客户是否需要推送 + /// 获取服务商拉取配置 + /// + /// 子系统id + /// 服务商id + /// + Task> GetPushContentConfigsAsync(int subSystemId, int customId); + + /// + /// 根据轨迹代码推断下一个(升序)要推送的内容,如果找不到或者已经是最后一个了,返回null /// /// /// + /// /// - Task IsPushAsync(int subSystemId, int customId); + Task InferNextPushContentOrNullAsync(int subSystemId, int customId, + int? trackContentId); /// /// 更新缓存 diff --git a/src/SJZY.Track.Application/EventHandlers/OrderLinkAfterFillTrackHandler.cs b/src/SJZY.Track.Application/EventHandlers/OrderLinkAfterFillTrackHandler.cs index 4a014b49..80c5dda8 100644 --- a/src/SJZY.Track.Application/EventHandlers/OrderLinkAfterFillTrackHandler.cs +++ b/src/SJZY.Track.Application/EventHandlers/OrderLinkAfterFillTrackHandler.cs @@ -31,7 +31,7 @@ public class OrderLinkAfterFillTrackHandler : ITransientDependency, ICapSubscrib var order = await _orderRepository.GetFirstAsync(x => x.Id == linkOrderId, x => new { - x.OrderType, x.OrderNo, x.CustomId, x.IsPushCompleted, x.SubSystemId + x.OrderType, x.OrderNo, x.CustomId, LatestPushCode = x.LatestPushTrackContentId, x.SubSystemId }); if (order == default) continue; @@ -50,7 +50,7 @@ public class OrderLinkAfterFillTrackHandler : ITransientDependency, ICapSubscrib OrderId = linkOrderId, CustomId = order.CustomId, SubSystemId = order.SubSystemId, - IsPushCompleted = order.IsPushCompleted, + LatestPushTrackContentId = order.LatestPushCode, UpSubSystemId = @event.SubSystemId, }; diff --git a/src/SJZY.Track.Application/EventHandlers/TrackRefreshEventHandler.cs b/src/SJZY.Track.Application/EventHandlers/TrackRefreshEventHandler.cs index b3864e55..5d74b758 100644 --- a/src/SJZY.Track.Application/EventHandlers/TrackRefreshEventHandler.cs +++ b/src/SJZY.Track.Application/EventHandlers/TrackRefreshEventHandler.cs @@ -63,7 +63,7 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe var order = await _orderRepository.GetFirstAsync(x => x.OrderType == orderType && x.OrderNo == orderNo, x => new { - x.Id, x.SubSystemId, x.IsPushCompleted, x.CustomId + x.Id, x.SubSystemId, LatestPushCode = x.LatestPushTrackContentId, x.CustomId }); if (order == default) return; @@ -73,7 +73,7 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe { OrderId = order.Id, SubSystemId = order.SubSystemId, - IsPushCompleted = order.IsPushCompleted, + LatestPushTrackContentId = order.LatestPushCode, CustomId = order.CustomId, OrderType = orderType, OrderNo = orderNo!, diff --git a/src/SJZY.Track.Application/EventHandlers/TrackUpsertEventHandler.cs b/src/SJZY.Track.Application/EventHandlers/TrackUpsertEventHandler.cs index fd33d3e1..7c6f3159 100644 --- a/src/SJZY.Track.Application/EventHandlers/TrackUpsertEventHandler.cs +++ b/src/SJZY.Track.Application/EventHandlers/TrackUpsertEventHandler.cs @@ -88,6 +88,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe TrackStatus = trackContent.Status, TrackCode = @event.TrackCode, TrackContent = trackContent.Content, + TrackContentId = trackContent.Id, IsCompleted = orderIsCompleted, TrackEnContent = trackContent.EnContent, TrackPlace = @event.TrackPlace, @@ -97,13 +98,6 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe CreateUser = CurrentUserRequest.CurrentUser.Name, CreateTime = DateTime.Now }; - - // todo:推送只做新增的,更新和删除的不做先 - if (!@event.IsPushCompleted && - await _trackPushCacheService.IsPushAsync(@event.SubSystemId, @event.CustomId)) - { - //await PushTrack(); - } } else { @@ -114,13 +108,24 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe track.UpdateTime = DateTime.Now; } + // upsert es轨迹 await _trackDetailsRepository.UpsertAsync(track); + // 触发轨迹推送事件 + var content = await _trackPushCacheService.InferNextPushContentOrNullAsync( + @event.SubSystemId, @event.CustomId, @event.LatestPushTrackContentId); + if (content != default && content.TrackContentId == track.TrackContentId && + content.OrderType == @event.OrderType) + { + //await PushTrack(content); + } + // 触发订单主表更新事件 await _capPublisher.PublishAsync(GlobalConst.UpdateOrderTrackSubscribe, new UpdateOrderTrackEvent { OrderId = track.OrderId, IsCompleted = orderIsCompleted, + TrackCode = track.TrackCode, TrackContent = track.TrackContent, TrackEnContent = track.TrackEnContent, TrackPlace = track.TrackPlace, @@ -137,7 +142,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe nextEvent.OrderType = linkedOrder.OrderType; nextEvent.OrderNo = linkedOrder.OrderNo; nextEvent.SubSystemId = linkedOrder.SubSystemId; - nextEvent.IsPushCompleted = linkedOrder.IsPushCompleted; + nextEvent.LatestPushTrackContentId = linkedOrder.LatestPushTrackContentId; nextEvent.CustomId = linkedOrder.CustomId; nextEvent.UpSubSystemId = @event.SubSystemId; await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, nextEvent); diff --git a/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs b/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs index 4c3d1a45..b1c809d3 100644 --- a/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs +++ b/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs @@ -41,7 +41,7 @@ public partial class TrackService : ApplicationService, ITrackService var order = await _orderRepository.GetFirstAsync(x => x.OrderType == input.OrderType && x.OrderNo == input.OrderNo, x => new { - x.Id, x.SubSystemId, x.IsPushCompleted, x.CustomId + x.Id, x.SubSystemId, LatestPushCode = x.LatestPushTrackContentId, x.CustomId }); if (order == default) { @@ -52,7 +52,7 @@ public partial class TrackService : ApplicationService, ITrackService var @event = ObjectMapper.Map(input); @event.OrderId = order.Id; @event.SubSystemId = order.SubSystemId; - @event.IsPushCompleted = order.IsPushCompleted; + @event.LatestPushTrackContentId = order.LatestPushCode; @event.CustomId = order.CustomId; await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, @event); return true; @@ -76,7 +76,7 @@ public partial class TrackService : ApplicationService, ITrackService var orders = await _orderRepository.GetListAsync(x => x.OrderType == input.OrderType && input.OrderNos.Contains(x.OrderNo), x => new { - x.Id, x.OrderNo, x.SubSystemId, x.IsPushCompleted, x.CustomId + x.Id, x.OrderNo, x.SubSystemId, LatestPushCode = x.LatestPushTrackContentId, x.CustomId }); foreach (var order in orders) @@ -92,7 +92,7 @@ public partial class TrackService : ApplicationService, ITrackService OrderNo = order.OrderNo, OrderId = order.Id, SubSystemId = order.SubSystemId, - IsPushCompleted = order.IsPushCompleted, + LatestPushTrackContentId = order.LatestPushCode, CustomId = order.CustomId }; await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, @event); diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs index ba084f93..eb11ae2c 100644 --- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs +++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs @@ -1,4 +1,5 @@ using SJZY.Expand.ABP.Core; +using SJZY.Track.Application.Contract.Dtos.ProvideServices; using SJZY.Track.Application.Contract.Services; using SJZY.Track.Domain.Aggregates.TrackPushAggregate; using SJZY.Track.Domain.Queries; @@ -17,34 +18,20 @@ public class TrackPushCacheService : ITrackPushCacheService, ITransientDependenc _trackPushConfigQuery = trackPushConfigQuery; } - public async Task IsPushAsync(int customId) + public Task IsPushAsync(int customId) { - var isPush = - await RedisHelper.Client.GetAsync(RedisKey(customId)); - - if (isPush == null) - { - isPush = await _trackPushConfigQuery.GetFirstAsync(x => x.CustomId == customId, - x => x.IsAutoPush); - await RedisHelper.Client.SetAsync(RedisKey(customId), isPush); - } - - return (bool)isPush; + throw new NotImplementedException(); } - public async Task IsPushAsync(int subSystemId, int customId) + public Task> GetPushContentConfigsAsync(int subSystemId, int customId) { - var isPush = - await RedisHelper.Client.GetAsync(RedisKey(customId)); + throw new NotImplementedException(); + } - if (isPush == null) - { - isPush = await _trackPushConfigQuery.GetFirstAsync(x => x.CustomId == customId, - x => x.IsAutoPush); - await RedisHelper.Client.SetAsync(RedisKey(customId), isPush); - } - - return (bool)isPush; + public Task InferNextPushContentOrNullAsync(int subSystemId, int customId, + int? trackContentId) + { + throw new NotImplementedException(); } public async Task UpdateAsync(int customId, bool isPush) diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs index 1ecb8f41..34903f75 100644 --- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs +++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Localization; +using System.Linq.Expressions; +using Microsoft.Extensions.Localization; using SJZY.Expand.ABP.Core.Localization; using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Track.Application.Contract.Dtos.TrackPush; @@ -9,9 +10,6 @@ using SJZY.Track.Domain.Aggregates.TrackPushAggregate; using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate; using SJZY.Track.Domain.Dtos.Common; using SJZY.Track.Domain.Dtos.TrackPush; -using SqlSugar; -using System.Linq.Expressions; -using Volo.Abp.DependencyInjection; namespace SJZY.Track.Application.Services.TrackPush; @@ -20,11 +18,10 @@ namespace SJZY.Track.Application.Services.TrackPush; /// [ApiExplorerSettings(GroupName = "轨迹推送")] [Route("/Track/PushConfig")] -public class TrackPushService : ApplicationService, ITransientDependency +public class TrackPushService : ApplicationService { private readonly IStringLocalizer _stringLocalizer; private readonly ITrackPushConfigRepository _trackPushConfigRepository; - private readonly ITrackTemplateRepository _trackTemplateRepository; private readonly ITrackPullConfigRepository _trackPullConfigRepository; private readonly ITrackPushCacheService _trackPushCacheService; @@ -37,7 +34,6 @@ public class TrackPushService : ApplicationService, ITransientDependency { _stringLocalizer = stringLocalizer; _trackPushConfigRepository = trackPushConfigRepository; - _trackTemplateRepository = trackTemplateRepository; _trackPullConfigRepository = trackPullConfigRepository; _trackPushCacheService = trackPushCacheService; } @@ -59,7 +55,8 @@ public class TrackPushService : ApplicationService, ITransientDependency /// /// [HttpPost("GetContentPage")] - public async Task> GetContentPageAsync([FromBody] GetTrackPushContentPageInputVO input) + public async Task> GetContentPageAsync( + [FromBody] GetTrackPushContentPageInputVO input) { return await _trackPushConfigRepository.GetContentPageAsync(input); } @@ -97,71 +94,79 @@ public class TrackPushService : ApplicationService, ITransientDependency if (input.Options != OptionTypeNoNull.删除) { Expression> isAnyExp = x => - x.SubSystemId == input.SubSystemId && x.CustomId == input.CustomId && x.ServiceProviderId == input.ServiceProviderId; + x.SubSystemId == input.SubSystemId && x.CustomId == input.CustomId && + x.ServiceProviderId == input.ServiceProviderId; if (input.Options == OptionTypeNoNull.修改) isAnyExp = isAnyExp.And(x => x.Id != input.Id); - if (await _trackPushConfigRepository.IsAnyAsync(isAnyExp)) throw new BusinessException(message: _stringLocalizer["IsTrackPushConfigAny"]); + if (await _trackPushConfigRepository.IsAnyAsync(isAnyExp)) + throw new BusinessException(message: _stringLocalizer["IsTrackPushConfigAny"]); } switch (input.Options) { case OptionTypeNoNull.新增: + { + var trackPushEntity = ObjectMapper.Map(input); + var trackPushParamsEntity = + ObjectMapper.Map(input); + + using (var ts = TransactionScopeHelper.Create()) { - var trackPushEntity = ObjectMapper.Map(input); - var trackPushParamsEntity = ObjectMapper.Map(input); + int id = await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity); - using (var ts = TransactionScopeHelper.Create()) - { - int id = await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity); + trackPushParamsEntity.PullOrPushConfigId = id; + await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity); - trackPushParamsEntity.PullOrPushConfigId = id; - await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity); + if (input.IsAutoPush!.Value) await _trackPushCacheService.IsPushAsync(input.CustomId!.Value); - if (input.IsAutoPush!.Value) await _trackPushCacheService.IsPushAsync(input.CustomId!.Value); - - ts.Complete(); - } + ts.Complete(); } + } break; case OptionTypeNoNull.修改: + { + var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? + throw new BusinessException(message: _stringLocalizer["NotFindData"]); + + int oldCustomId = oldTrackPushEntity.CustomId; + + var oldTrackPushParamsEntity = + await _trackPullConfigRepository.GetParamsSingleAsync(x => + x.PullOrPushConfigId == input.Id && x.IsPush); + + ObjectMapper.Map(input, oldTrackPushEntity); + ObjectMapper.Map(input, oldTrackPushParamsEntity); + + using (var ts = TransactionScopeHelper.Create()) { - var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]); + await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity); + await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPushParamsEntity); - int oldCustomId = oldTrackPushEntity.CustomId; + await _trackPushCacheService.UpdateAsync(oldCustomId, false); + if (input.IsAutoPush!.Value) await _trackPushCacheService.IsPushAsync(input.CustomId!.Value); - var oldTrackPushParamsEntity = await _trackPullConfigRepository.GetParamsSingleAsync(x => x.PullOrPushConfigId == input.Id && x.IsPush); - - ObjectMapper.Map(input, oldTrackPushEntity); - ObjectMapper.Map(input, oldTrackPushParamsEntity); - - using (var ts = TransactionScopeHelper.Create()) - { - await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity); - await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPushParamsEntity); - - await _trackPushCacheService.UpdateAsync(oldCustomId, false); - if (input.IsAutoPush!.Value) await _trackPushCacheService.IsPushAsync(input.CustomId!.Value); - - ts.Complete(); - } + ts.Complete(); } + } break; case OptionTypeNoNull.删除: + { + var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? + throw new BusinessException(message: _stringLocalizer["NotFindData"]); + + using (var ts = TransactionScopeHelper.Create()) { - var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]); + await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id); + await _trackPullConfigRepository.SoftDeleteParamsAsync(x => + x.PullOrPushConfigId == input.Id && x.IsPush); + await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id); + await _trackPushCacheService.UpdateAsync(oldTrackPushEntity.CustomId, false); - using (var ts = TransactionScopeHelper.Create()) - { - await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id); - await _trackPullConfigRepository.SoftDeleteParamsAsync(x => x.PullOrPushConfigId == input.Id && x.IsPush); - await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id); - await _trackPushCacheService.UpdateAsync(oldTrackPushEntity.CustomId, false); - - ts.Complete(); - } + ts.Complete(); } + } break; default: @@ -182,62 +187,76 @@ public class TrackPushService : ApplicationService, ITransientDependency { if (input.Options != OptionTypeNoNull.删除) { - Expression> isContentAnyExp = x => x.TrackPushConfigId == input.TrackPushConfigId; + Expression> isContentAnyExp = x => + x.TrackPushConfigId == input.TrackPushConfigId; if (input.Options == OptionTypeNoNull.修改) isContentAnyExp = isContentAnyExp.And(x => x.Id != input.Id); - if (await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => x.TrackContentId == input.TrackContentId))) + if (await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => + x.TrackContentId == input.TrackContentId))) throw new BusinessException(message: _stringLocalizer["IsTrackPushContentAny"]); - else if (!input.TrackContentCodeValue.IsNullOrWhiteSpace() && await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => x.TrackContentCodeValue == input.TrackContentCodeValue))) + else if (!input.TrackContentCodeValue.IsNullOrWhiteSpace() && + await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => + x.TrackContentCodeValue == input.TrackContentCodeValue))) throw new BusinessException(message: _stringLocalizer["IsTrackPushContentCodeValueAny"]); - else if (!input.TrackStatusValue.IsNullOrWhiteSpace() && await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => x.TrackStatusValue == input.TrackStatusValue))) + else if (!input.TrackStatusValue.IsNullOrWhiteSpace() && + await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => + x.TrackStatusValue == input.TrackStatusValue))) throw new BusinessException(message: _stringLocalizer["IsTrackPushContentStatusValueAny"]); - else if (!input.TrackContentValue.IsNullOrWhiteSpace() && await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => x.TrackContentValue == input.TrackContentValue))) + else if (!input.TrackContentValue.IsNullOrWhiteSpace() && + await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => + x.TrackContentValue == input.TrackContentValue))) throw new BusinessException(message: _stringLocalizer["IsTrackPushContentValueAny"]); - else if (!input.TrackEnContentValue.IsNullOrWhiteSpace() && await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => x.TrackEnContentValue == input.TrackEnContentValue))) + else if (!input.TrackEnContentValue.IsNullOrWhiteSpace() && + await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => + x.TrackEnContentValue == input.TrackEnContentValue))) throw new BusinessException(message: _stringLocalizer["IsTrackPushEnContentValueAny"]); } switch (input.Options) { case OptionTypeNoNull.新增: - { - int maxSort = await _trackPushConfigRepository.ContentMaxAsync(x => x.Sort, x => x.TrackPushConfigId == input.TrackPushConfigId); + { + int maxSort = await _trackPushConfigRepository.ContentMaxAsync(x => x.Sort, + x => x.TrackPushConfigId == input.TrackPushConfigId); - var entity = ObjectMapper.Map(input); - entity.Sort = maxSort + 1; + var entity = ObjectMapper.Map(input); + entity.Sort = maxSort + 1; - await _trackPushConfigRepository.InsertContentAsync(entity); + await _trackPushConfigRepository.InsertContentAsync(entity); - break; - } + break; + } case OptionTypeNoNull.修改: - { - var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]); + { + var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? + throw new BusinessException(message: _stringLocalizer["NotFindData"]); - ObjectMapper.Map(input, entity); + ObjectMapper.Map(input, entity); - await _trackPushConfigRepository.UpdateContentAsync(entity); + await _trackPushConfigRepository.UpdateContentAsync(entity); - break; - } + break; + } case OptionTypeNoNull.删除: + { + var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? + throw new BusinessException(message: _stringLocalizer["NotFindData"]); + + using (var ts = TransactionScopeHelper.Create()) { - var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]); + await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id); - using (var ts = TransactionScopeHelper.Create()) - { - await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id); + await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1, + x => x.TrackPushConfigId == entity.TrackPushConfigId && x.Sort > entity.Sort); - await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1, x => x.TrackPushConfigId == entity.TrackPushConfigId && x.Sort > entity.Sort); - - ts.Complete(); - } - - break; + ts.Complete(); } + break; + } + default: throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum, nameof(EditTrackPushContentInput.Options)]); diff --git a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs index 66f704a3..3defe94f 100644 --- a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs +++ b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs @@ -43,10 +43,10 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot public bool IsCompleted { get; set; } /// - /// 订单是否推送完成(异步维护) + /// 最新推送轨迹内容id(异步维护) /// - [SugarColumn(ColumnName = "IsPushCompleted")] - public bool IsPushCompleted { get; set; } + [SugarColumn(ColumnName = "LatestPushTrackContentId")] + public int? LatestPushTrackContentId { get; set; } /// /// 最新轨迹内容(异步维护) @@ -112,7 +112,7 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot /// 问题类型(主数据枚举TrackQuestionType) /// [SugarColumn(ColumnName = "QuestionType")] - public int QuestionType { get; set; } + public int QuestionType { get; set; } /// /// 问题描述(主数据枚举TrackProblemDescription) diff --git a/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/TrackDetailsIndex.cs b/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/TrackDetailsIndex.cs index d5909320..812b2377 100644 --- a/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/TrackDetailsIndex.cs +++ b/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/TrackDetailsIndex.cs @@ -46,6 +46,11 @@ public class TrackDetailsIndex : IdBaseIndex /// public string TrackContent { get; set; } = null!; + /// + /// 轨迹内容Id + /// + public int TrackContentId { get; set; } + /// /// 是否意味着完成 /// diff --git a/src/SJZY.Track.Domain/Dtos/Order/LinkedOrderVO.cs b/src/SJZY.Track.Domain/Dtos/Order/LinkedOrderVO.cs index c0344880..8cc9fbb2 100644 --- a/src/SJZY.Track.Domain/Dtos/Order/LinkedOrderVO.cs +++ b/src/SJZY.Track.Domain/Dtos/Order/LinkedOrderVO.cs @@ -6,7 +6,7 @@ public class LinkedOrderVO /// 关联订单id /// public int OrderId { get; set; } - + /// /// 订单号 /// @@ -21,12 +21,12 @@ public class LinkedOrderVO /// 子系统id /// public int SubSystemId { get; set; } - + /// - /// 订单是否推送完成(异步维护) + /// 最新推送轨迹内容id(异步维护) /// - public bool IsPushCompleted { get; set; } - + public int? LatestPushTrackContentId { get; set; } + /// /// 客户id /// diff --git a/src/SJZY.Track.Domain/Dtos/TrackDetails/MatchTrackContentDto.cs b/src/SJZY.Track.Domain/Dtos/TrackDetails/MatchTrackContentDto.cs index adb51944..e0213b5e 100644 --- a/src/SJZY.Track.Domain/Dtos/TrackDetails/MatchTrackContentDto.cs +++ b/src/SJZY.Track.Domain/Dtos/TrackDetails/MatchTrackContentDto.cs @@ -2,6 +2,11 @@ public class MatchTrackContentDto { + /// + /// 轨迹内容id + /// + public int Id { get; set; } + /// /// 轨迹内容 /// diff --git a/src/SJZY.Track.Domain/Enums/TrackProblemType.cs b/src/SJZY.Track.Domain/Enums/TrackProblemType.cs new file mode 100644 index 00000000..4abcc47e --- /dev/null +++ b/src/SJZY.Track.Domain/Enums/TrackProblemType.cs @@ -0,0 +1,15 @@ +namespace SJZY.Track.Domain.Enums; + +[Flags] +public enum TrackProblemType +{ + /// + /// 异常 + /// + Error = 1, + + /// + /// 预警 + /// + Warn = 2, +} \ No newline at end of file diff --git a/src/SJZY.Track.Domain/GlobalConst.cs b/src/SJZY.Track.Domain/GlobalConst.cs index 981ce249..528115ea 100644 --- a/src/SJZY.Track.Domain/GlobalConst.cs +++ b/src/SJZY.Track.Domain/GlobalConst.cs @@ -37,6 +37,11 @@ public class GlobalConst /// public const string TrackPushKeyPrefix = "TrackPush"; + /// + /// 轨迹推送内容配置redis key前缀 + /// + public const string TrackPushContentKeyPrefix = "TrackPushContent"; + /// /// 轨迹拉取配置信息redis key前缀 /// diff --git a/src/SJZY.Track.Repository/Queries/ProvideQueries.cs b/src/SJZY.Track.Repository/Queries/ProvideQueries.cs index a84a28f5..04301286 100644 --- a/src/SJZY.Track.Repository/Queries/ProvideQueries.cs +++ b/src/SJZY.Track.Repository/Queries/ProvideQueries.cs @@ -70,6 +70,7 @@ public class ProvideQueries : ISugarRepository, IProvideQueries, .Where((x, a, b) => x.OrderId == orderId && b.Code == code) .Select((x, a, b, c) => new MatchTrackContentDto { + Id = b.Id, Content = b.Content, EnContent = b.EnContent, Status = c.Status, diff --git a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs index aac0ef93..47c0bb60 100644 --- a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs @@ -67,7 +67,7 @@ public class OrderRepository : BasicRepository, IOrderRepository, I OrderType = b.OrderType, OrderNo = b.OrderNo, SubSystemId = b.SubSystemId, - IsPushCompleted = b.IsPushCompleted, + LatestPushTrackContentId = b.LatestPushTrackContentId, CustomId = b.CustomId }) .ToListAsync();