diff --git a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/GetOrderDetailsInput.cs b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/GetOrderDetailsInput.cs index 9ec96ba5..9f4a3dc2 100644 --- a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/GetOrderDetailsInput.cs +++ b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/GetOrderDetailsInput.cs @@ -1,100 +1,97 @@ -using System.Reflection.Metadata.Ecma335; +namespace SJZY.Track.Application.Contract.Dtos.ProvideServices; -namespace SJZY.Track.Application.Contract.Dtos.ProvideServices +public class GetOrderDetailsInput { - public class GetOrderDetailsInput - { - /// - /// 轨迹订单id - /// - public int OrderId { get; set; } + /// + /// 轨迹订单id + /// + public int OrderId { get; set; } - /// - /// 子系统id - /// - public int SubSystemId { get; set; } + /// + /// 子系统id + /// + public int SubSystemId { get; set; } - /// - /// 轨迹模板Id - /// - public List? TrackTemplateIds { get; set; } = new List(); - } + /// + /// 轨迹模板Id + /// + public List? TrackTemplateIds { get; set; } = new List(); +} - public class TrackOrderDetailDto - { - /// - /// Id es主键 - /// - public int Id { get; set; } +public class TrackOrderDetailDto +{ + /// + /// Id es主键 + /// + public string Id { get; set; } = null!; - /// - /// 轨迹订单id - /// - public int OrderId { set; get; } + /// + /// 轨迹订单id + /// + public int OrderId { set; get; } - /// - /// 订单类型(主数据枚举TrackOrderType) - /// - public int OrderType { get; set; } + /// + /// 订单类型(主数据枚举TrackOrderType) + /// + public int OrderType { get; set; } - /// - /// 订单号 - /// - public string OrderNo { get; set; } = null!; + /// + /// 订单号 + /// + public string OrderNo { get; set; } = null!; - /// - /// 轨迹代码 - /// - public string? Code { get; set; } + /// + /// 轨迹代码 + /// + public string? Code { get; set; } - /// - /// 轨迹内容 - /// - public string? Content { get; set; } + /// + /// 轨迹内容 + /// + public string? Content { get; set; } - /// - /// 轨迹内容英文 - /// - public string? EnContent { get; set; } + /// + /// 轨迹内容英文 + /// + public string? EnContent { get; set; } - /// - /// 轨迹发生地 - /// - public string? TrackPlace { get; set; } + /// + /// 轨迹发生地 + /// + public string? TrackPlace { get; set; } - /// - /// 轨迹发生时间 - /// - public DateTime? TrackTime { get; set; } + /// + /// 轨迹发生时间 + /// + public DateTime? TrackTime { get; set; } - /// - /// 轨迹发生时区 - /// - public string? TrackTimeZone { get; set; } + /// + /// 轨迹发生时区 + /// + public string? TrackTimeZone { get; set; } - /// - /// 时区的值 - /// - public float TrackTimeZoneValue { get; set; } + /// + /// 时区的值 + /// + public float TrackTimeZoneValue { get; set; } - /// - /// 是否可删 - /// - public bool IsCanDelete { get; set; } + /// + /// 是否可删 + /// + public bool IsCanDelete { get; set; } - /// - /// 是否对外 - /// - public bool IsExternal { get; set; } + /// + /// 是否对外 + /// + public bool IsExternal { get; set; } - /// - /// 创建时间 - /// - public DateTime CreateTime { get; set; } + /// + /// 创建时间 + /// + public DateTime CreateTime { get; set; } - /// - /// 创建人 - /// - public string? CreateUser { get; set; } - } + /// + /// 创建人 + /// + public string? CreateUser { get; set; } } \ No newline at end of file diff --git a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/LinkOrderInput.cs b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/LinkOrderInput.cs index 7d30b3c5..da8b3110 100644 --- a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/LinkOrderInput.cs +++ b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/LinkOrderInput.cs @@ -20,7 +20,7 @@ public class LinkOrderInput /// 订单号,必填 /// [Required] - public string OrderNo { get; set; } + public string OrderNo { get; set; } = null!; /// /// 关联单类型 diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackContents/EditTrackContentInput.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackContents/EditTrackContentInput.cs index f13eac46..bf4ddc54 100644 --- a/src/SJZY.Track.Application.Contract/Dtos/TrackContents/EditTrackContentInput.cs +++ b/src/SJZY.Track.Application.Contract/Dtos/TrackContents/EditTrackContentInput.cs @@ -41,11 +41,6 @@ /// 轨迹标记id /// public int TrackFlagId { get; set; } - - /// - /// 是否完结 - /// - public bool IsFinish { get; set; } } public class GetTrackContentDetailDto diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackPullContentConfigDto.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackPullContentConfigDto.cs index cab541f3..771b328c 100644 --- a/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackPullContentConfigDto.cs +++ b/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackPullContentConfigDto.cs @@ -41,4 +41,9 @@ public class TrackPullContentConfigDto /// 轨迹时区GMT值 /// public float? TrackTimeZoneValue { get; set; } + + /// + /// 订单是否完成(由轨迹刷新配置决定) + /// + public bool IsCompleted { get; set; } } \ No newline at end of file diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackPullParamWithContentConfigDto.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackPullParamWithContentConfigDto.cs index ba38457f..fe807cb0 100644 --- a/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackPullParamWithContentConfigDto.cs +++ b/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackPullParamWithContentConfigDto.cs @@ -2,7 +2,7 @@ namespace SJZY.Track.Application.Contract.Dtos.TrackPull; public class TrackPullParamWithContentConfigDto { - public TrackPullParamConfigDto ParamConfig { get; set; } + public TrackPullParamConfigDto ParamConfig { get; set; } = new(); - public List ContentConfigs { get; set; } + public List ContentConfigs { get; set; } = new(); } \ No newline at end of file diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackRefreshContext.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackRefreshContext.cs new file mode 100644 index 00000000..d7e67a39 --- /dev/null +++ b/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackRefreshContext.cs @@ -0,0 +1,34 @@ +namespace SJZY.Track.Application.Contract.Dtos.TrackPull; + +public class TrackRefreshContext +{ + /// + /// 订单id + /// + public int OrderId { get; set; } + + /// + /// 订单类型 + /// + public int OrderType { get; set; } + + /// + /// 订单号 + /// + public string OrderNo { get; set; } = null!; + + /// + /// 服务商 + /// + public string ServiceProviderName { get; set; } = null!; + + /// + /// 客户id + /// + public int CustomId { get; set; } + + /// + /// 子系统id + /// + public int SubSystemId { get; set; } +} \ No newline at end of file diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/EditTrackPushConfigInput.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/EditTrackPushConfigInput.cs index 20473d85..b4ed8f6e 100644 --- a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/EditTrackPushConfigInput.cs +++ b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/EditTrackPushConfigInput.cs @@ -7,11 +7,6 @@ public class EditTrackPushConfigInput /// public int? CustomId { get; set; } - /// - /// 推送扩展字段 - /// - public string? ExpandFieldsName { get; set; } - public int? Id { get; set; } /// @@ -39,41 +34,6 @@ public class EditTrackPushConfigInput /// public int? SubSystemId { get; set; } - /// - /// 推送轨迹时区 - /// - public string? TrackTimeZoneName { get; set; } - - /// - /// 推送轨迹内容代码 - /// - public string? TrackContentCodeName { get; set; } - - /// - /// 推送轨迹内容 - /// - public string? TrackContentName { get; set; } - - /// - /// 推送轨迹内容英文 - /// - public string? TrackEnContentName { get; set; } - - /// - /// 推送轨迹发生地 - /// - public string? TrackPlaceName { get; set; } - - /// - /// 推送轨迹状态 - /// - public string? TrackStatusName { get; set; } - - /// - /// 推送轨迹发生时间 - /// - public string? TrackTimeName { get; set; } - /// /// 是否支持更新 /// @@ -83,4 +43,9 @@ public class EditTrackPushConfigInput /// 是否支持删除 /// public bool? IsCanDelete { get; set; } + + /// + /// 是否全量推送 + /// + public bool? IsAllPush { get; set; } } \ No newline at end of file diff --git a/src/SJZY.Track.Application.Contract/Events/TrackPushAfterUpdateOrderEvent.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushAfterUpdateOrderDto.cs similarity index 72% rename from src/SJZY.Track.Application.Contract/Events/TrackPushAfterUpdateOrderEvent.cs rename to src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushAfterUpdateOrderDto.cs index f57fad41..3e6ca93d 100644 --- a/src/SJZY.Track.Application.Contract/Events/TrackPushAfterUpdateOrderEvent.cs +++ b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushAfterUpdateOrderDto.cs @@ -1,6 +1,6 @@ -namespace SJZY.Track.Application.Contract.Events; +namespace SJZY.Track.Application.Contract.Dtos.TrackPush; -public class TrackPushAfterUpdateOrderEvent +public class TrackPushAfterUpdateOrderDto { /// /// 操作类型 @@ -13,9 +13,9 @@ public class TrackPushAfterUpdateOrderEvent public int OrderId { get; set; } /// - /// 轨迹内容id + /// 轨迹code /// - public int TrackContentId { get; set; } + public string TrackCode { get; set; } = null!; /// /// 问题类型 diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushConfigDto.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushContentConfigDto.cs similarity index 80% rename from src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushConfigDto.cs rename to src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushContentConfigDto.cs index 1f129458..c2bcf867 100644 --- a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushConfigDto.cs +++ b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushContentConfigDto.cs @@ -1,18 +1,5 @@ namespace SJZY.Track.Application.Contract.Dtos.TrackPush; -public class TrackPushConfigDto -{ - /// - /// 是否自动推送 - /// - public bool IsAutoPush { get; set; } - - /// - /// 轨迹推送内容配置 - /// - public List ContentConfigs { get; set; } = new(); -} - public class TrackPushContentConfigDto { /// @@ -25,31 +12,41 @@ public class TrackPushContentConfigDto /// public bool IsCanUpdate { get; set; } + /// + /// 是否全量推送 + /// + public bool IsAllPush { get; set; } + + /// + /// 是否支持删除 + /// + public bool IsCanDelete { get; set; } + /// /// 服务商code /// public string ServiceProviderCode { get; set; } = null!; - /// - /// 扩展字段参数值 - /// - public string? ExpandFieldsValue { get; set; } - /// /// 推送单号类型(主数据枚举TrackOrderType) /// public int OrderType { get; set; } + /// + /// 我们系统的轨迹code + /// + public string TrackCode { get; set; } = null!; + + /// + /// 可交换顺序的轨迹code + /// + public string? SwapTrackCode { get; set; } + /// /// 轨迹代码参数值 /// public string? TrackContentCodeValue { get; set; } - /// - /// 轨迹内容id - /// - public int TrackContentId { get; set; } - /// /// 轨迹内容参数值 /// @@ -69,4 +66,9 @@ public class TrackPushContentConfigDto /// 轨迹时区GMT /// public double? TrackTimeZone { get; set; } + + /// + /// 扩展字段参数值 + /// + public string? ExpandFieldsValue { get; set; } } \ No newline at end of file diff --git a/src/SJZY.Track.Application.Contract/Events/OrderLinkAfterFillTrackEvent.cs b/src/SJZY.Track.Application.Contract/Events/OrderLinkAfterFillTrackEvent.cs index 5caa784e..f4caa481 100644 --- a/src/SJZY.Track.Application.Contract/Events/OrderLinkAfterFillTrackEvent.cs +++ b/src/SJZY.Track.Application.Contract/Events/OrderLinkAfterFillTrackEvent.cs @@ -15,5 +15,14 @@ public class OrderLinkAfterFillTrackEvent /// /// 关联订单 /// - public List LinkedOrderIds { get; set; } = null!; + public List LinkedOrders { get; set; } = null!; +} + +public struct LinkedOrder +{ + public int SubSystemId { get; set; } + + public int OrderId { get; set; } + public string OrderNo { get; set; } + public int OrderType { get; set; } } \ No newline at end of file diff --git a/src/SJZY.Track.Application.Contract/Events/TrackChangeAfterUpdateOrderEvent.cs b/src/SJZY.Track.Application.Contract/Events/TrackChangeAfterUpdateOrderEvent.cs index 448b5bf2..c779a647 100644 --- a/src/SJZY.Track.Application.Contract/Events/TrackChangeAfterUpdateOrderEvent.cs +++ b/src/SJZY.Track.Application.Contract/Events/TrackChangeAfterUpdateOrderEvent.cs @@ -13,7 +13,7 @@ public class TrackChangeAfterUpdateOrderEvent public bool IsDelete { get; set; } /// - /// 这条轨迹是否意味着完成 + /// 这条轨迹是否意味着完成(只有刷新会设为true) /// public bool IsCompleted { get; set; } diff --git a/src/SJZY.Track.Application.Contract/Events/TrackInsertForNotMappedEvent.cs b/src/SJZY.Track.Application.Contract/Events/TrackInsertForNotMappedEvent.cs new file mode 100644 index 00000000..8ab3f2ae --- /dev/null +++ b/src/SJZY.Track.Application.Contract/Events/TrackInsertForNotMappedEvent.cs @@ -0,0 +1,49 @@ +namespace SJZY.Track.Application.Contract.Events; + +public class TrackInsertForNotMappedEvent +{ + /// + /// 订单id + /// + public int OrderId { get; set; } + + /// + /// 订单类型 + /// + public int OrderType { get; set; } + + /// + /// 订单号 + /// + public string OrderNo { get; set; } = null!; + + /// + /// 服务商 + /// + public string ServiceProviderName { get; set; } = null!; + + /// + /// 原轨迹内容 + /// + public string? OriginTrackContent { get; set; } + + /// + /// 原轨迹报文 + /// + public string? OriginTrackData { get; set; } + + /// + /// 轨迹发生地 + /// + public string TrackPlace { get; set; } = null!; + + /// + /// 轨迹发生时间 + /// + public DateTime TrackTime { get; set; } + + /// + /// 轨迹发生时区 + /// + public float TrackTimeZone { get; set; } +} \ No newline at end of file diff --git a/src/SJZY.Track.Application.Contract/Events/TrackPushEvent.cs b/src/SJZY.Track.Application.Contract/Events/TrackPushEvent.cs index 92ce75e1..9d98dcf1 100644 --- a/src/SJZY.Track.Application.Contract/Events/TrackPushEvent.cs +++ b/src/SJZY.Track.Application.Contract/Events/TrackPushEvent.cs @@ -5,12 +5,7 @@ public class TrackPushEvent /// /// 操作类型 /// - public OptionType OptionType { get; set; } = OptionType.新增; - - /// - /// 服务商code - /// - public string ServiceProviderCode { get; set; } = null!; + public OptionType OptionType { get; set; } /// /// 订单id @@ -22,23 +17,13 @@ public class TrackPushEvent /// public string OrderNo { get; set; } = null!; - /// - /// 订单类型 - /// - public int OrderType { get; set; } - - /// - /// 轨迹内容id - /// - public int TrackContentId { get; set; } - /// /// 轨迹状态 /// public string TrackStatus { get; set; } = null!; /// - /// 轨迹内容代码 + /// 轨迹代码(我们系统的) /// public string TrackCode { get; set; } = null!; @@ -62,31 +47,6 @@ public class TrackPushEvent /// public float TrackTimeZone { get; set; } - /// - /// 轨迹代码参数值 - /// - public string? TrackContentCodeValue { get; set; } - - /// - /// 轨迹内容参数值 - /// - public string? TrackContentValue { get; set; } - - /// - /// 轨迹内容英文参数值 - /// - public string? TrackEnContentValue { get; set; } - - /// - /// 轨迹状态参数值 - /// - public string? TrackStatusValue { get; set; } - - /// - /// 扩展字段参数值 - /// - public string? ExpandFieldsValue { get; set; } - /// /// 操作人 /// diff --git a/src/SJZY.Track.Application.Contract/Events/TrackUpsertEvent.cs b/src/SJZY.Track.Application.Contract/Events/TrackUpsertEvent.cs index 1215e1e8..3533f2e6 100644 --- a/src/SJZY.Track.Application.Contract/Events/TrackUpsertEvent.cs +++ b/src/SJZY.Track.Application.Contract/Events/TrackUpsertEvent.cs @@ -18,14 +18,15 @@ public class TrackUpsertEvent public string OrderNo { get; set; } = null!; /// - /// 订单是否完成 + /// 服务商 /// - public bool IsCompleted { get; set; } + public string? ServiceProviderName { get; set; } /// - /// 客户id + /// 表示订单是否完成(只由轨迹刷新配置决定) + /// tips:能够使得IsCompleted为true的点,全局只有一个:轨迹刷新 /// - public int CustomId { get; set; } + public bool IsCompleted { get; set; } /// /// 子系统id @@ -33,32 +34,17 @@ public class TrackUpsertEvent public int SubSystemId { get; set; } /// - /// 最新推送轨迹内容id(异步维护) - /// - public int? LatestPushTrackContentId { get; set; } - - /// - /// 上游子系统id + /// 上游子系统id(0表示事件起点) /// public int UpSubSystemId { get; set; } /// - /// 原轨迹内容 - /// - public string? OriginTrackContent { get; set; } - - /// - /// 原轨迹报文 - /// - public string? OriginTrackData { get; set; } - - /// - /// 操作人 + /// 操作人(null则默认系统) /// public string? OperationMan { get; set; } /// - /// true新增,false更新,null表示刷新引发的新增/更新 + /// true新增,false更新,null表示新增/更新 /// public bool? IsAdd { get; set; } diff --git a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs index 91b80c3e..d04c0fa2 100644 --- a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs +++ b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs @@ -10,26 +10,29 @@ public interface ITrackPushCacheService /// 子系统id /// 服务商id /// - Task> GetPushContentConfigsAsync(int subSystemId, int customId); + Task?> GetPushContentConfigsAsync(int subSystemId, int customId); /// /// 获取服务商拉取配置 /// /// 子系统id /// 服务商id - /// + /// 轨迹代码 /// - Task GetPushContentConfigAsync(int subSystemId, int customId, int trackContentId); + Task GetPushContentConfigAsync(int subSystemId, int customId, string trackConde); /// - /// 根据轨迹代码推断下一个(升序)要推送的内容,如果找不到或者已经是最后一个了,返回null + /// 根据轨迹代码推断下一个(升序)要推送的内容,如果找不到或者已经是最后一个了 + /// 则查询有没有可交换的推送,没有就返回null /// /// /// - /// + /// + /// /// - Task InferNextPushContentOrNullAsync(int subSystemId, int customId, - int? trackContentId); + Task IsValidPushAsync(int subSystemId, int customId, + string? latestPushTrackCode, + string? trackCode); /// /// 设置推送配置缓存 @@ -38,5 +41,6 @@ public interface ITrackPushCacheService /// 子系统id /// 客户id /// - Task SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null); + Task?> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, + int? customId = null); } \ No newline at end of file diff --git a/src/SJZY.Track.Application/AutoMapper/OrderAutoMapperProfile.cs b/src/SJZY.Track.Application/AutoMapper/OrderAutoMapperProfile.cs index da077adf..8befae94 100644 --- a/src/SJZY.Track.Application/AutoMapper/OrderAutoMapperProfile.cs +++ b/src/SJZY.Track.Application/AutoMapper/OrderAutoMapperProfile.cs @@ -1,13 +1,10 @@ using AutoMapper; -using Google.Protobuf.WellKnownTypes; using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Track.Application.Contract.Dtos.ProvideServices; using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate; using SJZY.Track.Domain.Dtos.Order; using SJZY.Track.Domain.Enums; -using System.ComponentModel; -using System.Reflection; using Volo.Abp.AutoMapper; namespace SJZY.Track.Application.AutoMapper; @@ -26,12 +23,13 @@ public class OrderAutoMapperProfile : Profile CreateMap(MemberList.None); CreateMap(MemberList.None) - .ForMember(dest => dest.OrderTypeName, opt => opt.MapFrom(source => GetEnumDescription(2, source.OrderType))) - .ForMember(dest => dest.QuestionTypeName, opt => opt.MapFrom(source => GetEnumDescription(1, source.QuestionType))); + .ForMember(dest => dest.OrderTypeName, + opt => opt.MapFrom(source => GetEnumDescription(2, source.OrderType))) + .ForMember(dest => dest.QuestionTypeName, + opt => opt.MapFrom(source => GetEnumDescription(1, source.QuestionType))); CreateMap, UnifyPageResultDto>(MemberList.None); CreateMap(MemberList.None).Ignore(dest => dest.TrackTimeZone) - .ForMember(dest => dest.Id, opt => opt.Ignore()) .ForMember(dest => dest.Code, opt => opt.MapFrom(m => m.TrackCode)) .ForMember(dest => dest.Content, opt => opt.MapFrom(m => m.TrackContent)) .ForMember(dest => dest.EnContent, opt => opt.MapFrom(m => m.TrackEnContent)) @@ -62,7 +60,6 @@ public class OrderAutoMapperProfile : Profile enumDescription = ""; else enumDescription = orderType.GetDescription(); // 获取描述标记 - } return enumDescription; diff --git a/src/SJZY.Track.Application/AutoMapper/TrackContentAutoMapperProfile.cs b/src/SJZY.Track.Application/AutoMapper/TrackContentAutoMapperProfile.cs index 77b0c47d..bf20809b 100644 --- a/src/SJZY.Track.Application/AutoMapper/TrackContentAutoMapperProfile.cs +++ b/src/SJZY.Track.Application/AutoMapper/TrackContentAutoMapperProfile.cs @@ -9,8 +9,7 @@ namespace SJZY.Track.Application.AutoMapper { public TrackContentAutoMapperProfile() { - CreateMap(MemberList.None) - .ForMember(dest => dest.IsCompleted, opt => opt.MapFrom(source => source.IsFinish)); + CreateMap(MemberList.None); CreateMap(MemberList.None); CreateMap(MemberList.None); CreateMap(MemberList.None); diff --git a/src/SJZY.Track.Application/EventHandlers/OrderLinkAfterFillTrackHandler.cs b/src/SJZY.Track.Application/EventHandlers/OrderLinkAfterFillTrackHandler.cs index 1d628a3a..2d8a0ef5 100644 --- a/src/SJZY.Track.Application/EventHandlers/OrderLinkAfterFillTrackHandler.cs +++ b/src/SJZY.Track.Application/EventHandlers/OrderLinkAfterFillTrackHandler.cs @@ -27,31 +27,21 @@ public class OrderLinkAfterFillTrackHandler : ITransientDependency, ICapSubscrib var tracks = await _trackDetailsRepository.GetListAsync(@event.OrderId); - foreach (var linkOrderId in @event.LinkedOrderIds) + foreach (var order in @event.LinkedOrders) { - var order = await _orderRepository.GetFirstAsync(x => - x.Id == linkOrderId, x => new - { - x.OrderType, x.OrderNo, x.CustomId, x.LatestPushTrackContentId, x.SubSystemId - }); - - if (order == default) continue; - // 补轨迹 foreach (var track in tracks) { var fillTrackEvent = new TrackUpsertEvent { + OrderId = order.OrderId, OrderType = order.OrderType, OrderNo = order.OrderNo, TrackCode = track.TrackCode, TrackPlace = track.TrackPlace, TrackTime = track.TrackTime, TrackTimeZone = track.TrackTimeZone, - OrderId = linkOrderId, - CustomId = order.CustomId, SubSystemId = order.SubSystemId, - LatestPushTrackContentId = order.LatestPushTrackContentId, UpSubSystemId = @event.SubSystemId, }; diff --git a/src/SJZY.Track.Application/EventHandlers/TrackChangeAfterUpdateOrderEventHandler.cs b/src/SJZY.Track.Application/EventHandlers/TrackChangeAfterUpdateOrderEventHandler.cs index 82dae4c9..a738576e 100644 --- a/src/SJZY.Track.Application/EventHandlers/TrackChangeAfterUpdateOrderEventHandler.cs +++ b/src/SJZY.Track.Application/EventHandlers/TrackChangeAfterUpdateOrderEventHandler.cs @@ -43,7 +43,7 @@ public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICa } // 删除引发的回退更新 - order.IsCompleted = track.IsCompleted; + order.IsCompleted = @event.IsCompleted; order.LatestTrackContent = track.TrackContent; order.LatestTrackEnContent = track.TrackEnContent; order.LatestTrackPlace = track.TrackPlace; diff --git a/src/SJZY.Track.Application/EventHandlers/TrackInsertForNotMappedEventHandler.cs b/src/SJZY.Track.Application/EventHandlers/TrackInsertForNotMappedEventHandler.cs new file mode 100644 index 00000000..f135b558 --- /dev/null +++ b/src/SJZY.Track.Application/EventHandlers/TrackInsertForNotMappedEventHandler.cs @@ -0,0 +1,50 @@ +using DotNetCore.CAP; +using SJZY.Track.Application.Contract.Events; +using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate; +using SJZY.Track.Domain.Consts; +using Volo.Abp.DependencyInjection; + +namespace SJZY.Track.Application.EventHandlers; + +public class TrackInsertForNotMappedEventHandler : ITransientDependency, ICapSubscribe +{ + private readonly ITrackDetailsRepository _trackDetailsRepository; + + public TrackInsertForNotMappedEventHandler(ITrackDetailsRepository trackDetailsRepository) + { + _trackDetailsRepository = trackDetailsRepository; + } + + [CapSubscribe(GlobalConst.TrackInsertForNotMappedEventSubscribe)] + public async Task ConsumerAsync(TrackInsertForNotMappedEvent @event) + { + if (await _trackDetailsRepository.AnyAsync(@event.OrderId, @event.TrackTime)) + { + return; // 无法映射的轨迹只做新增 + } + + // 新增服务商轨迹到es + var track = new TrackDetailsIndex + { + IndexName = $"{GlobalConst.TrackIndex}-{DateTime.Now:yyyy.MM.dd}", + OrderId = @event.OrderId, + OrderNo = @event.OrderNo, + OrderType = @event.OrderType, + TrackPlace = @event.TrackPlace, + TrackTime = @event.TrackTime, + TrackTimeZone = @event.TrackTimeZone, + ServiceProviderName = @event.ServiceProviderName, + OriginTrackContent = @event.OriginTrackContent, + OriginTrackData = @event.OriginTrackData, + CreateUser = GlobalConst.SystemUser, + CreateTime = DateTime.Now + }; + track.TrackCode = GlobalConst.EmptyString; + track.TrackStatus = GlobalConst.EmptyString; + track.TrackContent = GlobalConst.EmptyString; + track.TrackEnContent = GlobalConst.EmptyString; + track.ZeroTrackTime = track.TrackTime.Subtract(TimeSpan.FromHours(track.TrackTimeZone)); + + await _trackDetailsRepository.UpsertAsync(track); + } +} \ No newline at end of file diff --git a/src/SJZY.Track.Application/EventHandlers/TrackPushAfterUpdateOrderEventHandler.cs b/src/SJZY.Track.Application/EventHandlers/TrackPushAfterUpdateOrderEventHandler.cs index 268db6c1..a6c65fdd 100644 --- a/src/SJZY.Track.Application/EventHandlers/TrackPushAfterUpdateOrderEventHandler.cs +++ b/src/SJZY.Track.Application/EventHandlers/TrackPushAfterUpdateOrderEventHandler.cs @@ -1,5 +1,5 @@ using DotNetCore.CAP; -using SJZY.Track.Application.Contract.Events; +using SJZY.Track.Application.Contract.Dtos.TrackPush; using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Consts; using SJZY.Track.Domain.Enums; @@ -17,34 +17,34 @@ public class TrackPushAfterUpdateOrderEventHandler : ITransientDependency, ICapS } [CapSubscribe(GlobalConst.TrackPushAfterUpdateOrderSubscribe)] - public async Task ConsumerAsync(TrackPushAfterUpdateOrderEvent @event) + public async Task ConsumerAsync(TrackPushAfterUpdateOrderDto dto) { - var order = await _orderRepository.GetFirstAsync(x => x.Id == @event.OrderId); + var order = await _orderRepository.GetFirstAsync(x => x.Id == dto.OrderId); if (order == default) return; /* * 异常:最近一条推送是失败 */ - if (!@event.IsSuccess) + if (!dto.IsSuccess) { order.QuestionType = (int)TrackProblemType.Error; - order.ProblemDescription = @event.Message; + order.LatestPushError = dto.Message; } else { order.QuestionType = (int)TrackProblemType.None; - if (@event.OptionType == OptionType.新增) + order.LatestPushError = null; + if (dto.OptionType == OptionType.新增) { - // tips:只有新增会影响推送进度? - order.LatestPushTrackContentId = @event.TrackContentId; + // tips:只有新增会影响推送进度 + order.LatestPushTrackCode = dto.TrackCode; order.LatestPushTime = DateTime.Now; } } - await _orderRepository.UpdateColumnAsync(order, x => new { - x.LatestPushTrackContentId, x.QuestionType, x.ProblemDescription, x.LatestPushTime + x.LatestPushTrackCode, x.QuestionType, x.LatestPushError, x.LatestPushTime }); } } \ No newline at end of file diff --git a/src/SJZY.Track.Application/EventHandlers/TrackPushEventHandler.cs b/src/SJZY.Track.Application/EventHandlers/TrackPushEventHandler.cs index a1f9aba4..837fc960 100644 --- a/src/SJZY.Track.Application/EventHandlers/TrackPushEventHandler.cs +++ b/src/SJZY.Track.Application/EventHandlers/TrackPushEventHandler.cs @@ -1,8 +1,12 @@ using DotNetCore.CAP; using SJZY.InterfaceRelay.Application.Contracts; +using SJZY.Track.Application.Contract.Dtos.TrackPush; using SJZY.Track.Application.Contract.Events; +using SJZY.Track.Application.Contract.Services; +using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Aggregates.TrackPushAggregate; using SJZY.Track.Domain.Consts; +using SJZY.Track.Domain.Enums; using Volo.Abp.DependencyInjection; using Volo.Abp.Http.Client.DynamicProxying; @@ -12,31 +16,63 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe { private readonly IHttpClientProxy _httpClientProxy; private readonly ITrackPushRecordsRepository _trackPushRecordsRepository; - private readonly ICapPublisher _capPublisher; + private readonly IOrderRepository _orderRepository; + private readonly ITrackPushCacheService _trackPushCacheService; public TrackPushEventHandler(IHttpClientProxy httpClientProxy, - ITrackPushRecordsRepository trackPushRecordsRepository, ICapPublisher capPublisher) + ITrackPushRecordsRepository trackPushRecordsRepository, + IOrderRepository orderRepository, ITrackPushCacheService trackPushCacheService) { _httpClientProxy = httpClientProxy; _trackPushRecordsRepository = trackPushRecordsRepository; - _capPublisher = capPublisher; + _orderRepository = orderRepository; + _trackPushCacheService = trackPushCacheService; } [CapSubscribe(GlobalConst.TrackPushSubscribe, Group = GlobalConst.TrackPushSubscribe)] public async Task ConsumerAsync(TrackPushEvent @event) { InterfaceRelayUnifyResultDto res = null!; + + var order = await _orderRepository.GetFirstAsync(x => + x.Id == @event.OrderId, x => new + { + x.SubSystemId, x.LatestPushTrackCode, x.CustomId, x.OrderType + }); + if (order == null) return; + + TrackPushContentConfigDto? config = null; switch (@event.OptionType) { case OptionType.无: return; case OptionType.新增: - res = await PushAddAsync(@event); + if (@event.OperationMan == null) // 系统推送需要推断 + { + // 推送新增,需要根据上一次的推送 推断 本次推送 是否可行 + config = await _trackPushCacheService.IsValidPushAsync(order.SubSystemId, order.CustomId, + order.LatestPushTrackCode, @event.TrackCode); + } + else + { + // 手工推送不推断,直接无脑推 + config = await _trackPushCacheService.GetPushContentConfigAsync(order.SubSystemId, order.CustomId, + @event.TrackCode); + } + + if (config == null) return; + + // 当前发生的轨迹不是要推送的,直接结束 + if (config.TrackCode != @event.TrackCode) return; + res = await DoAddAsync(@event, config); break; case OptionType.删除: break; case OptionType.修改: - res = await PushUpdateAsync(@event); + config = await _trackPushCacheService.GetPushContentConfigAsync(order.SubSystemId, order.CustomId, + @event.TrackCode); + if (config == null || !config.IsCanUpdate) return; + res = await DoUpdateAsync(@event, config); break; default: throw new ArgumentOutOfRangeException(); @@ -44,6 +80,8 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe var isSuccess = res.Code == InterfaceRelayConst.SuccessCode; + if (config == null) return; + // 往es 写推送日志 await _trackPushRecordsRepository.AddAsync(new TrackPushRecordIndex { @@ -52,7 +90,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe Message = res.Msg, OptionType = @event.OptionType.ToString(), OrderId = @event.OrderId, - OrderType = @event.OrderType, + OrderType = order.OrderType, OrderNo = @event.OrderNo, TrackStatus = @event.TrackStatus, TrackCode = @event.TrackCode, @@ -60,29 +98,59 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe TrackPlace = @event.TrackPlace, TrackTime = @event.TrackTime, TrackTimeZone = @event.TrackTimeZone, - TrackContentCodeValue = @event.TrackContentCodeValue, - TrackContentValue = @event.TrackContentValue, - TrackEnContentValue = @event.TrackEnContentValue, - TrackStatusValue = @event.TrackStatusValue, - ExpandFieldsValue = @event.ExpandFieldsValue, + TrackContentCodeValue = config.TrackContentCodeValue, + TrackContentValue = config.TrackContentValue, + TrackEnContentValue = config.TrackEnContentValue, + TrackStatusValue = config.TrackStatusValue, + ExpandFieldsValue = config.ExpandFieldsValue, IsSuccess = isSuccess, - CreateUser = @event.OperationMan ?? "系统", + CreateUser = @event.OperationMan ?? GlobalConst.SystemUser, CreateTime = DateTime.Now }); - // 更新订单主表(异步) - await _capPublisher.PublishAsync(GlobalConst.TrackPushAfterUpdateOrderSubscribe, - new TrackPushAfterUpdateOrderEvent - { - OptionType = @event.OptionType, - OrderId = @event.OrderId, - TrackContentId = @event.TrackContentId, - IsSuccess = isSuccess, - Message = res.Msg - }); + // 同步去更新订单主表 + await TrackPushAfterUpdateOrderAsync(new TrackPushAfterUpdateOrderDto + { + OptionType = @event.OptionType, + OrderId = @event.OrderId, + TrackCode = @event.TrackCode, + IsSuccess = isSuccess, + Message = res.Msg + }); } - private async Task PushAddAsync(TrackPushEvent @event) + private async Task TrackPushAfterUpdateOrderAsync(TrackPushAfterUpdateOrderDto dto) + { + var order = new OrderEntity(); + order.Id = dto.OrderId; + /* + * 异常:最近一条推送是失败 + */ + if (!dto.IsSuccess) + { + order.QuestionType = (int)TrackProblemType.Error; + order.LatestPushError = dto.Message; + } + else + { + order.QuestionType = (int)TrackProblemType.None; + order.LatestPushError = null; + if (dto.OptionType == OptionType.新增) + { + // tips:只有新增会影响推送进度? + order.LatestPushTrackCode = dto.TrackCode; + order.LatestPushTime = DateTime.Now; + } + } + + await _orderRepository.UpdateColumnAsync(order, x => new + { + x.LatestPushTrackCode, x.QuestionType, x.LatestPushError, x.LatestPushTime + }); + } + + private async Task DoAddAsync(TrackPushEvent @event, + TrackPushContentConfigDto config) { var data = new { @@ -93,25 +161,27 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe { // 推真实的发生地和发生时间(时间是计算后的) location = @event.TrackPlace, - date = @event.TrackTime, - timeZone = @event.TrackTimeZone, - description = @event.TrackEnContentValue, - description_cn = @event.TrackContentValue, - code = @event.TrackContentCodeValue, - status = @event.TrackStatusValue, - extra = @event.ExpandFieldsValue + date = @event.TrackTime.AddHours( + config.TrackTimeZone ?? @event.TrackTimeZone - @event.TrackTimeZone), + timeZone = config.TrackTimeZone ?? @event.TrackTimeZone, + description = config.TrackEnContentValue, + description_cn = config.TrackContentValue, + code = config.TrackContentCodeValue, + status = config.TrackStatusValue, + extra = config.ExpandFieldsValue } } }; var res = await _httpClientProxy.Service.ForwardWithSubscribeAsync(InterfaceRelayConst.PushTrackInterfaceCode, - @event.ServiceProviderCode, data); + config.ServiceProviderCode, data); return res; } - private async Task PushUpdateAsync(TrackPushEvent @event) + private async Task DoUpdateAsync(TrackPushEvent @event, + TrackPushContentConfigDto config) { var data = new { @@ -122,20 +192,21 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe { // 推真实的发生地和发生时间 location = @event.TrackPlace, - date = @event.TrackTime, - timeZone = @event.TrackTimeZone, - description = @event.TrackEnContentValue, - description_cn = @event.TrackContentValue, - code = @event.TrackContentCodeValue, - status = @event.TrackStatusValue, - extra = @event.ExpandFieldsValue + date = @event.TrackTime.AddHours( + config.TrackTimeZone ?? @event.TrackTimeZone - @event.TrackTimeZone), + timeZone = config.TrackTimeZone ?? @event.TrackTimeZone, + description = config.TrackEnContentValue, + description_cn = config.TrackContentValue, + code = config.TrackContentCodeValue, + status = config.TrackStatusValue, + extra = config.ExpandFieldsValue } } }; var res = await _httpClientProxy.Service.ForwardWithSubscribeAsync(InterfaceRelayConst.TrackUpdateInterfaceCode, - @event.ServiceProviderCode, data); + config.ServiceProviderCode, data); return res; } diff --git a/src/SJZY.Track.Application/EventHandlers/TrackRefreshEventHandler.cs b/src/SJZY.Track.Application/EventHandlers/TrackRefreshEventHandler.cs index 2e85c484..b4bfe207 100644 --- a/src/SJZY.Track.Application/EventHandlers/TrackRefreshEventHandler.cs +++ b/src/SJZY.Track.Application/EventHandlers/TrackRefreshEventHandler.cs @@ -3,7 +3,6 @@ using System.Linq.Expressions; using DotNetCore.CAP; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.InterfaceRelay.Application.Contracts; using SJZY.Track.Application.Contract.Dtos.TrackPull; using SJZY.Track.Application.Contract.Events; @@ -46,59 +45,59 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe { foreach (var token in orderTokens) { - await HandleOrderAsync(token, config, attach.OrderType); + await HandleOrderAsync(token, config, attach); } } else if (orderToken is JObject) { - await HandleOrderAsync(orderToken, config, attach.OrderType); + await HandleOrderAsync(orderToken, config, attach); } } private async Task HandleOrderAsync(JToken orderToken, TrackPullParamWithContentConfigDto paramWithContentConfig, - int orderType) + TrackRefreshAttach attach) { var paramConfig = paramWithContentConfig.ParamConfig; var orderNo = orderToken[paramConfig.OrderNoName]?.Value(); if (orderNo.IsNullOrWhiteSpace()) return; + var trackToken = orderToken[paramConfig.TrackDetailsPath]; + if (trackToken is null) return; + var order = await _orderRepository.GetFirstAsync(x => - x.OrderType == orderType && x.OrderNo == orderNo, x => new + x.OrderType == attach.OrderType && x.OrderNo == orderNo, x => new { - x.Id, x.SubSystemId, x.LatestPushTrackContentId, x.CustomId + x.Id, x.LatestPushTrackCode, x.CustomId }); if (order == default) return; - var trackToken = orderToken[paramConfig.TrackDetailsPath]; - if (trackToken is null) return; - var trackUpsertEvent = new TrackUpsertEvent + var context = new TrackRefreshContext { OrderId = order.Id, - SubSystemId = order.SubSystemId, - LatestPushTrackContentId = order.LatestPushTrackContentId, - CustomId = order.CustomId, - OrderType = orderType, + OrderType = attach.OrderType, OrderNo = orderNo!, + ServiceProviderName = attach.ServiceProviderName, + CustomId = order.CustomId, + SubSystemId = attach.SubSystemId }; + if (trackToken is JArray trackTokens) { foreach (var item in trackTokens) { - await HandleTrackAsync(item, paramWithContentConfig, trackUpsertEvent); + await HandleTrackAsync(item, paramWithContentConfig, context); } } else if (orderToken is JObject) { - await HandleTrackAsync(orderToken, paramWithContentConfig, trackUpsertEvent); + await HandleTrackAsync(orderToken, paramWithContentConfig, context); } } private async Task HandleTrackAsync(JToken trackToken, TrackPullParamWithContentConfigDto paramWithContentConfig, - TrackUpsertEvent @event) + TrackRefreshContext context) { - var trackUpsertEvent = @event.DeepCopy(); - trackUpsertEvent.OriginTrackData = JsonConvert.SerializeObject(trackToken); var paramConfig = paramWithContentConfig.ParamConfig; var contentConfigs = paramWithContentConfig.ContentConfigs; TrackPullContentConfigDto? matchedContentConfig = null; @@ -127,7 +126,6 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe var trackContent = trackToken[paramConfig.TrackContentName]?.Value(); if (!trackContent.IsNullOrWhiteSpace()) { - trackUpsertEvent.OriginTrackContent = trackContent; Debug.Assert(trackContent != null, nameof(trackContent) + " != null"); matchedContentConfig = contentConfigs.FirstOrDefault(x => x.TrackContentValue == trackContent); @@ -161,8 +159,6 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe } } - if (matchedContentConfig is null) return; - // 轨迹发生地 var trackPlace = paramConfig.TrackPlaceName == null ? null @@ -181,7 +177,7 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe _ => x => x.LeaveCountry }; trackPlace = await _orderRepository.GetFirstAsync(x => - x.Id == trackUpsertEvent.OrderId, resultExpression); + x.Id == context.OrderId, resultExpression); } // 轨迹发生时间 @@ -193,11 +189,42 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe ? null : trackToken[paramConfig.TrackTimeZoneName]?.Value(); + if (matchedContentConfig is null) + { + var notMappedEvent = new TrackInsertForNotMappedEvent + { + OrderId = context.OrderId, + OrderType = context.OrderType, + OrderNo = context.OrderNo, + ServiceProviderName = context.ServiceProviderName, + OriginTrackData = JsonConvert.SerializeObject(trackToken), + TrackPlace = trackPlace ?? GlobalConst.EmptyString, + TrackTime = trackTime ?? DateTime.Now, + TrackTimeZone = trackTimeZone ?? matchedContentConfig?.TrackTimeZoneValue ?? 8 + }; + if (paramConfig.TrackContentName != null) + { + notMappedEvent.OriginTrackContent = trackToken[paramConfig.TrackContentName]?.Value(); + } + + await _capPublisher.PublishAsync(GlobalConst.TrackInsertForNotMappedEventSubscribe, notMappedEvent); + return; + } + // 新增/更新轨迹 - trackUpsertEvent.TrackCode = matchedContentConfig?.TrackContentCode ?? GlobalConst.EmptyString; - trackUpsertEvent.TrackPlace = trackPlace ?? GlobalConst.EmptyString; - trackUpsertEvent.TrackTime = trackTime ?? DateTime.Now; - trackUpsertEvent.TrackTimeZone = trackTimeZone ?? matchedContentConfig?.TrackTimeZoneValue ?? 8; + var trackUpsertEvent = new TrackUpsertEvent + { + OrderId = context.OrderId, + OrderType = context.OrderType, + OrderNo = context.OrderNo, + ServiceProviderName = context.ServiceProviderName, + IsCompleted = matchedContentConfig.IsCompleted, + SubSystemId = context.SubSystemId, + TrackCode = matchedContentConfig.TrackContentCode, + TrackPlace = trackPlace ?? GlobalConst.EmptyString, + TrackTime = trackTime ?? DateTime.Now, + TrackTimeZone = trackTimeZone ?? matchedContentConfig.TrackTimeZoneValue ?? 8 + }; await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, trackUpsertEvent); } } \ No newline at end of file diff --git a/src/SJZY.Track.Application/EventHandlers/TrackUpsertEventHandler.cs b/src/SJZY.Track.Application/EventHandlers/TrackUpsertEventHandler.cs index c1b19b5f..41ce263b 100644 --- a/src/SJZY.Track.Application/EventHandlers/TrackUpsertEventHandler.cs +++ b/src/SJZY.Track.Application/EventHandlers/TrackUpsertEventHandler.cs @@ -1,9 +1,7 @@ using DotNetCore.CAP; using SJZY.Expand.ABP.Core.Logger; using SJZY.Expand.ABP.Core.PublicMethords; -using SJZY.Track.Application.Contract.Dtos.TrackPush; using SJZY.Track.Application.Contract.Events; -using SJZY.Track.Application.Contract.Services; using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate; using SJZY.Track.Domain.Consts; @@ -17,18 +15,15 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe private readonly IOrderRepository _orderRepository; private readonly IProvideQueries _provideQueries; private readonly ITrackDetailsRepository _trackDetailsRepository; - private readonly ITrackPushCacheService _trackPushCacheService; private readonly ICapPublisher _capPublisher; public TrackUpsertEventHandler(IOrderRepository orderRepository, ICapPublisher capPublisher, - IProvideQueries provideQueries, ITrackDetailsRepository trackDetailsRepository, - ITrackPushCacheService trackPushCacheService) + IProvideQueries provideQueries, ITrackDetailsRepository trackDetailsRepository) { _orderRepository = orderRepository; _capPublisher = capPublisher; _provideQueries = provideQueries; _trackDetailsRepository = trackDetailsRepository; - _trackPushCacheService = trackPushCacheService; } [CapSubscribe(GlobalConst.TrackUpsertSubscribe, Group = GlobalConst.TrackUpsertSubscribe)] @@ -56,13 +51,9 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe @event.TrackCode = mapCode; } - var track = @event.TrackCode == GlobalConst.EmptyString - ? await _trackDetailsRepository.GetFirstOrDefaultAsync(@event.OrderId, @event.TrackTime) - : await _trackDetailsRepository.GetFirstOrDefaultAsync(@event.OrderId, @event.TrackCode); + var track = await _trackDetailsRepository.GetFirstOrDefaultAsync(@event.OrderId, @event.TrackCode); - if (@event.TrackCode == GlobalConst.EmptyString && track != null) return; // 无法映射的轨迹只做新增 - - if (@event.IsAdd != null) // 手动操作需要做区分 + if (@event.IsAdd != null) { if (track == null && !@event.IsAdd!.Value) return; // 不存在不让改 if (track != null && @event.IsAdd!.Value) return; // 存在不让创建 @@ -71,17 +62,30 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe // step1、upsert es轨迹 track = await UpsertTrackAsync(track, @event); - if (track == null || @event.TrackCode == GlobalConst.EmptyString) return; // 模板没配该轨迹代码,不再继续 + if (track == null) return; // 模板没配该轨迹代码,不再继续 // step2、触发轨迹推送事件(异步) - await HandleTrackPushAsync(@event, track); + var trackPushEvent = new TrackPushEvent + { + OptionType = track.Id.IsNullOrWhiteSpace() ? OptionType.新增 : OptionType.修改, + OrderId = track.OrderId, + OrderNo = track.OrderNo, + TrackStatus = track.TrackStatus, + TrackCode = track.TrackCode, + TrackContent = track.TrackContent, + TrackPlace = track.TrackPlace, + TrackTime = track.TrackTime, + TrackTimeZone = track.TrackTimeZone, + }; + + await _capPublisher.PublishAsync(GlobalConst.TrackPushSubscribe, trackPushEvent); // step3、触发订单主表更新事件(异步) await _capPublisher.PublishAsync(GlobalConst.TrackChangeAfterUpdateOrderSubscribe, new TrackChangeAfterUpdateOrderEvent { OrderId = track.OrderId, - IsCompleted = track.IsCompleted, + IsCompleted = @event.IsCompleted, TrackCode = track.TrackCode, TrackContent = track.TrackContent, TrackEnContent = track.TrackEnContent, @@ -96,12 +100,12 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe { var nextEvent = @event.DeepCopy(); nextEvent.Visited.Add(@event.OrderId); + // tips:一定要重置为false,父级订单的完成不会使得关联订单完成,关联单也必须由刷新来完成或手动设置完成!! + nextEvent.IsCompleted = false; // 能够使得轨迹IsCompleted为true的点,全局只有一个:轨迹刷新 nextEvent.OrderId = linkedOrder.OrderId; nextEvent.OrderType = linkedOrder.OrderType; nextEvent.OrderNo = linkedOrder.OrderNo; nextEvent.SubSystemId = linkedOrder.SubSystemId; - nextEvent.LatestPushTrackContentId = linkedOrder.LatestPushTrackContentId; - nextEvent.CustomId = linkedOrder.CustomId; nextEvent.UpSubSystemId = @event.SubSystemId; await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, nextEvent); } @@ -126,51 +130,34 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe TrackPlace = @event.TrackPlace, TrackTime = @event.TrackTime, TrackTimeZone = @event.TrackTimeZone, + ServiceProviderName = @event.ServiceProviderName, IsCanDelete = false, - OriginTrackContent = @event.OriginTrackContent, - OriginTrackData = @event.OriginTrackData, - CreateUser = @event.OperationMan ?? "系统", + CreateUser = @event.OperationMan ?? GlobalConst.SystemUser, CreateTime = DateTime.Now }; - // tips:刷新到无法匹配内容的轨迹引起的插入 - if (@event.TrackCode == GlobalConst.EmptyString) + //todo:可以优化 + // 根据轨迹code在订单模板内容中寻找匹配的 + var trackContent = await _provideQueries.MatchTrackContentAsync(@event.OrderId, @event.TrackCode); + if (trackContent == default) { - track.TrackStatus = GlobalConst.EmptyString; - track.TrackContent = GlobalConst.EmptyString; - track.TrackContentId = 0; - track.IsCompleted = false; - track.TrackEnContent = GlobalConst.EmptyString; + // 订单所绑定的模板,没有一条内容可以匹配发生的轨迹 + return null; } - else - { - //todo:可以优化 - // 根据轨迹code在订单模板内容中寻找匹配的 - var trackContent = await _provideQueries.MatchTrackContentAsync(@event.OrderId, @event.TrackCode); - if (trackContent == default) - { - // 订单所绑定的模板,没有一条内容可以匹配发生的轨迹 - return null; - } - track.TrackStatus = trackContent.Status; - track.TrackContent = trackContent.Content; - track.TrackContentId = trackContent.Id; - track.IsCompleted = trackContent.IsCompleted; - track.TrackEnContent = trackContent.EnContent; - track.IsCanDelete = trackContent.IsCanDelete; - track.ZeroTrackTime = track.TrackTime.Subtract(TimeSpan.FromHours(track.TrackTimeZone)); - } + track.TrackStatus = trackContent.Status; + track.TrackCode = trackContent.TrackCode; + track.TrackContent = trackContent.Content; + track.TrackEnContent = trackContent.EnContent; + track.IsCanDelete = trackContent.IsCanDelete; + track.ZeroTrackTime = track.TrackTime.Subtract(TimeSpan.FromHours(track.TrackTimeZone)); } else { - // tips:刷新到无法匹配内容的轨迹 相同的发生时间不做更新处理 - if (@event.TrackCode == GlobalConst.EmptyString) return track; - track.TrackPlace = @event.TrackPlace; track.TrackTime = @event.TrackTime; track.TrackTimeZone = @event.TrackTimeZone; - track.UpdateUser = @event.OperationMan ?? "系统"; + track.UpdateUser = @event.OperationMan ?? GlobalConst.SystemUser; track.UpdateTime = DateTime.Now; } @@ -178,60 +165,4 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe return track; } - - /// - /// 处理轨迹自动推送 - /// - /// - /// - private async Task HandleTrackPushAsync(TrackUpsertEvent @event, TrackDetailsIndex track) - { - TrackPushContentConfigDto? config; - OptionType optionType = OptionType.修改; - // 推送更新 - if (!track.Id.IsNullOrWhiteSpace()) - { - config = await _trackPushCacheService.GetPushContentConfigAsync( - @event.SubSystemId, @event.CustomId, track.TrackContentId); - if (config == null || !config.IsCanUpdate) return; - } - else - { - // 推送新增,需要根据上一次的推送 推断 本次推送 是否可行 - config = await _trackPushCacheService.InferNextPushContentOrNullAsync( - @event.SubSystemId, @event.CustomId, @event.LatestPushTrackContentId); - - if (config == null || !config.IsAutoPush) return; - - // 当前发生的轨迹就是要推送的 - if (config.TrackContentId != track.TrackContentId) return; - - optionType = OptionType.新增; - } - - if (config.OrderType != @event.OrderType) return; - - var trackPushEvent = new TrackPushEvent - { - OptionType = optionType, - ServiceProviderCode = config.ServiceProviderCode, - OrderNo = track.OrderNo, - OrderType = track.OrderType, - OrderId = track.OrderId, - TrackContentId = config.TrackContentId, - TrackStatus = track.TrackStatus, - TrackCode = track.TrackCode, - TrackContent = track.TrackContent, - TrackPlace = track.TrackPlace, - TrackTime = track.TrackTime.AddHours(config.TrackTimeZone ?? track.TrackTimeZone - track.TrackTimeZone), - TrackTimeZone = (float)(config.TrackTimeZone ?? track.TrackTimeZone), - TrackContentCodeValue = config.TrackContentCodeValue, - TrackContentValue = config.TrackContentValue, - TrackEnContentValue = config.TrackEnContentValue, - TrackStatusValue = config.TrackStatusValue, - ExpandFieldsValue = config.ExpandFieldsValue - }; - - await _capPublisher.PublishAsync(GlobalConst.TrackPushSubscribe, trackPushEvent); - } } \ No newline at end of file diff --git a/src/SJZY.Track.Application/Services/ProvideServices/OrderService.Link.cs b/src/SJZY.Track.Application/Services/ProvideServices/OrderService.Link.cs index 1f5e0446..5eca209c 100644 --- a/src/SJZY.Track.Application/Services/ProvideServices/OrderService.Link.cs +++ b/src/SJZY.Track.Application/Services/ProvideServices/OrderService.Link.cs @@ -26,10 +26,10 @@ public partial class OrderService { var order = await _orderRepository.GetFirstAsync(x => x.OrderType == input.OrderType && x.OrderNo == input.OrderNo, x => new - { - x.Id, - x.SubSystemId - }); + { + x.Id, + x.SubSystemId + }); if (order == default) { throw new BusinessException(message: $"订单:{input.OrderNo}不存在"); @@ -52,23 +52,23 @@ public partial class OrderService if (!input.IsLink) return await UnLinkOrderAsync(input); // 关联订单 - var linkedOrderIds = await DoLinkOrderAsync(input, order.Id); + var linkedOrders = await DoLinkOrderAsync(input, order.Id); // 补轨迹 - if (linkedOrderIds.Count > 0) + if (linkedOrders.Count > 0) { await _capPublisher.PublishAsync(GlobalConst.OrderLinkAfterFillTrack, new OrderLinkAfterFillTrackEvent { OrderId = order.Id, SubSystemId = order.SubSystemId, - LinkedOrderIds = linkedOrderIds, + LinkedOrders = linkedOrders, }); } return new UnifyResultDto(true, true); } - private async Task> DoLinkOrderAsync(LinkOrderInput input, int orderId) + private async Task> DoLinkOrderAsync(LinkOrderInput input, int orderId) { // 获取已关联的订单 var linkOrderNos = await _orderLinkQuery.GetListAsync(x => @@ -81,9 +81,9 @@ public partial class OrderService // 过滤掉不存在的订单 var canLinkOrders = await _orderRepository.GetListAsync(x => x.OrderType == input.LinkOrderType && noLinkOrderNos.Contains(x.OrderNo), - x => new { x.Id, x.OrderNo }); + x => new { x.Id, x.OrderNo, x.SubSystemId }); - if (canLinkOrders.Count == 0) return new List(); + if (canLinkOrders.Count == 0) return new List(); await _orderRepository.LinkOrderAsync(canLinkOrders.Select(x => new OrderLinkEntity { @@ -95,7 +95,13 @@ public partial class OrderService LinkOrderType = input.LinkOrderType }).ToList()); - return canLinkOrders.Select(x => x.Id).ToList(); + return canLinkOrders.Select(x => new LinkedOrder + { + SubSystemId = x.SubSystemId, + OrderId = x.Id, + OrderNo = x.OrderNo, + OrderType = input.LinkOrderType + }).ToList(); } private async Task UnLinkOrderAsync(LinkOrderInput input) diff --git a/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs b/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs index 78611294..8555ba39 100644 --- a/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs +++ b/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Authorization; using SJZY.Track.Application.Contract.Dtos.ProvideServices; using SJZY.Track.Application.Contract.Events; -using SJZY.Track.Application.Contract.Services; using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate; using SJZY.Track.Domain.Aggregates.TrackPushAggregate; @@ -21,17 +20,14 @@ public class TrackPushService : ApplicationService { private readonly ITrackDetailsRepository _trackDetailsRepository; private readonly IOrderRepository _orderRepository; - private readonly ITrackPushCacheService _pushCacheService; private readonly ICapPublisher _capPublisher; private readonly ITrackPushRecordsRepository _trackPushRecordsRepository; - public TrackPushService(ITrackPushCacheService pushCacheService, - ITrackDetailsRepository trackDetailsRepository + public TrackPushService(ITrackDetailsRepository trackDetailsRepository , IOrderRepository orderRepository , ICapPublisher capPublisher , ITrackPushRecordsRepository trackPushRecordsRepository) { - _pushCacheService = pushCacheService; _trackDetailsRepository = trackDetailsRepository; _orderRepository = orderRepository; _capPublisher = capPublisher; @@ -68,38 +64,19 @@ public class TrackPushService : ApplicationService var res = 0; - foreach (var order in orders) + foreach (var track in tracks) { - // 如果没有轨迹,就不需要推 - var track = tracks.FirstOrDefault(x => x.OrderId == order.Id); - if (track == null) continue; - - // 手工推送不推断,直接无脑推 - var config = - await _pushCacheService.GetPushContentConfigAsync(order.SubSystemId, order.CustomId, - track.TrackContentId); - - if (config == null) continue; - var trackPushEvent = new TrackPushEvent { - ServiceProviderCode = config.ServiceProviderCode, - OrderNo = order.OrderNo, - OrderType = order.OrderType, - OrderId = order.Id, - TrackContentId = config.TrackContentId, + OptionType = OptionType.新增, + OrderId = track.OrderId, + OrderNo = track.OrderNo, TrackStatus = track.TrackStatus, TrackCode = track.TrackCode, TrackContent = track.TrackContent, TrackPlace = track.TrackPlace, - TrackTime = track.TrackTime.AddHours(config.TrackTimeZone ?? - track.TrackTimeZone - track.TrackTimeZone), - TrackTimeZone = (float)(config.TrackTimeZone ?? track.TrackTimeZone), - TrackContentCodeValue = config.TrackContentCodeValue, - TrackContentValue = config.TrackContentValue, - TrackEnContentValue = config.TrackEnContentValue, - TrackStatusValue = config.TrackStatusValue, - ExpandFieldsValue = config.ExpandFieldsValue, + TrackTime = track.TrackTime, + TrackTimeZone = track.TrackTimeZone, OperationMan = CurrentUserRequest.CurrentUser.Name, }; diff --git a/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs b/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs index ab387b25..1d081ead 100644 --- a/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs +++ b/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs @@ -42,13 +42,9 @@ 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.LatestPushTrackContentId, - x.CustomId, - x.IsCompleted - }); + { + x.Id, x.SubSystemId + }); if (order == default) { throw new BusinessException(message: $"订单:{input.OrderNo}不存在"); @@ -58,9 +54,6 @@ public partial class TrackService : ApplicationService, ITrackService var @event = ObjectMapper.Map(input); @event.OrderId = order.Id; @event.SubSystemId = order.SubSystemId; - @event.LatestPushTrackContentId = order.LatestPushTrackContentId; - @event.CustomId = order.CustomId; - @event.IsCompleted = order.IsCompleted; @event.OperationMan = CurrentUserRequest.CurrentUser.Name; await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, @event); return new UnifyResultDto(true, true); @@ -83,14 +76,9 @@ 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.LatestPushTrackContentId, - x.CustomId, - x.IsCompleted - }); + { + x.Id, x.OrderNo, x.SubSystemId + }); foreach (var order in orders) { @@ -106,9 +94,6 @@ public partial class TrackService : ApplicationService, ITrackService OrderNo = order.OrderNo, OrderId = order.Id, SubSystemId = order.SubSystemId, - LatestPushTrackContentId = order.LatestPushTrackContentId, - CustomId = order.CustomId, - IsCompleted = order.IsCompleted, OperationMan = CurrentUserRequest.CurrentUser.Name }; await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, @event); @@ -128,10 +113,10 @@ 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.Id, + x.SubSystemId + }); if (order == default) { throw new BusinessException(message: $"订单:{input.OrderNo}不存在"); diff --git a/src/SJZY.Track.Application/Services/TrackOrders/TrackOrderService.cs b/src/SJZY.Track.Application/Services/TrackOrders/TrackOrderService.cs index 74354a7a..335adde3 100644 --- a/src/SJZY.Track.Application/Services/TrackOrders/TrackOrderService.cs +++ b/src/SJZY.Track.Application/Services/TrackOrders/TrackOrderService.cs @@ -58,14 +58,12 @@ public class TrackOrderService : ApplicationService }); Debug.Assert(input.TrackTemplateIds != null, "input.TrackTemplateIds != null"); input.TrackTemplateIds = input.TrackTemplateIds.Where(a => a > 0).ToList(); - int id = 1; list.ForEach(a => { - a.Id = id++; - var trackContentsOfTemplates = trackContents.Where(b => b.SubSystemId == input.SubSystemId && - b.TrackCode == a.Code - && input.TrackTemplateIds.Contains( - b.TrackTemplateId)).ToList(); + var trackContentsOfTemplates = trackContents.Where(b => + b.SubSystemId == input.SubSystemId && b.TrackCode == a.Code && + input.TrackTemplateIds.Contains(b.TrackTemplateId)) + .ToList(); GetTemplateContentAttributeValueVO? trackContent = null; var insertData = input.TrackTemplateIds .Intersect(trackContentsOfTemplates.Select(aa => aa.TrackTemplateId)).ToList(); @@ -78,7 +76,6 @@ public class TrackOrderService : ApplicationService if (trackContent != null) { - a.IsCanDelete = trackContent.IsCanDelete; a.IsExternal = trackContent.IsExternal; } @@ -87,7 +84,6 @@ public class TrackOrderService : ApplicationService a.TrackTimeZone = "GTM +00:00"; } else - { // 将小数形式的小时转换为时区偏移量 int hours = (int)a.TrackTimeZoneValue; // 提取整数部分作为小时 diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs index fe72985a..b0bb479b 100644 --- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs +++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs @@ -4,11 +4,10 @@ using SJZY.Track.Application.Contract.Dtos.TrackPush; using SJZY.Track.Application.Contract.Services; using SJZY.Track.Domain.Aggregates.TrackPushAggregate; using SJZY.Track.Domain.Consts; -using SJZY.Track.Domain.Dtos.TrackPush; namespace SJZY.Track.Application.Services.TrackPush; -public class TrackPushCacheService : ApplicationService, ITrackPushCacheService +public class TrackPushCacheService : ITrackPushCacheService { private readonly ITrackPushConfigRepository _trackPushConfigRepository; @@ -20,80 +19,96 @@ public class TrackPushCacheService : ApplicationService, ITrackPushCacheService _trackPushConfigRepository = trackPushConfigRepository; } - [NonAction] - public async Task> GetPushContentConfigsAsync(int subSystemId, int customId) + public async Task?> GetPushContentConfigsAsync(int subSystemId, int customId) { - var data = await GetPushConfigAsync(subSystemId, customId); - - return data.ContentConfigs; - } - - [NonAction] - public async Task GetPushContentConfigAsync(int subSystemId, int customId, - int trackContentId) - { - var data = await GetPushContentConfigsAsync(subSystemId, customId); - - return data?.FirstOrDefault(x => x.TrackContentId == trackContentId); - } - - [NonAction] - public async Task InferNextPushContentOrNullAsync(int subSystemId, int customId, - int? trackContentId) - { - var data = await GetPushConfigAsync(subSystemId, customId); - if (!data.IsAutoPush) return null; - - if (trackContentId.HasValue) - { - if (data.ContentConfigs.Count > 1 && data.ContentConfigs.Any(x => x.TrackContentId == trackContentId)) - { - int index = data.ContentConfigs.FindIndex(x => x.TrackContentId == trackContentId); - if (index == data.ContentConfigs.Count - 1) return null; - int nextIndex = (index + 1) % data.ContentConfigs.Count; // 计算下一个索引,处理最后一个元素的情况 - - return data.ContentConfigs[nextIndex]; - } - - return null; - } - - return data.ContentConfigs.FirstOrDefault(); - } - - [NonAction] - public async Task SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, - int? customId = null) - { - var data = new TrackPushConfigDto { ContentConfigs = new() }; - - Expression> exp = x => true; - if (id.HasValue) exp = x => x.Id == id; - else if (subSystemId.HasValue && customId.HasValue) - exp = x => x.SubSystemId == subSystemId && x.CustomId == customId; - - var trackPushConfigEntity = await _trackPushConfigRepository.GetFirstAsync(exp); - if (trackPushConfigEntity == null) return data; - - var trackPushContentList = await _trackPushConfigRepository.GetContentListAsync(trackPushConfigEntity.Id); - if (trackPushContentList.Count == 0) return data; - - data.IsAutoPush = trackPushConfigEntity.IsAutoPush; - data.ContentConfigs = - ObjectMapper.Map, List>(trackPushContentList); - ; - await RedisHelper.Client.SetAsync( - TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data); - - return data; - } - - private async Task GetPushConfigAsync(int subSystemId, int customId) - { - var data = await RedisHelper.Client.GetAsync(TrackPushContentKey(subSystemId, customId)); + var data = await RedisHelper.Client.GetAsync>( + TrackPushContentKey(subSystemId, customId)); data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId); return data; } + + public async Task GetPushContentConfigAsync(int subSystemId, int customId, + string trackConde) + { + var configs = await GetPushContentConfigsAsync(subSystemId, customId); + return configs?.FirstOrDefault(x => x.TrackCode == trackConde); + } + + public async Task IsValidPushAsync(int subSystemId, int customId, + string? latestPushTrackCode, + string? trackCode) + { + var cache = await GetPushContentConfigsAsync(subSystemId, customId); + if (cache == null || cache.Count < 1) return default; + + TrackPushContentConfigDto? matched; + if (latestPushTrackCode == null) + { + matched = cache.First(); + } + else + { + var idx = cache.FindIndex(x => x.TrackCode == latestPushTrackCode); + + if (idx == -1) return default; // 是否预警? + + // find next + if (idx + 1 < cache.Count && cache[idx + 1].TrackCode == trackCode) + { + matched = cache[idx + 1]; + } + else + { + // find swap + matched = cache.FirstOrDefault(x => x.TrackCode == cache[idx].SwapTrackCode); + } + } + + return matched != null && matched.TrackCode == trackCode ? matched : default; + } + + public async Task?> SetPushContentConfigsAsync(int? id = null, + int? subSystemId = null, + int? customId = null) + { + Expression> exp = x => true; + if (id.HasValue) exp = x => x.Id == id; + else if (subSystemId.HasValue && customId.HasValue) + exp = x => x.SubSystemId == subSystemId && x.CustomId == customId; + + var trackPushConfig = await _trackPushConfigRepository.GetFirstAsync(exp, x => new + { + x.Id, x.IsAutoPush, x.IsAllPush, x.IsCanDelete, x.IsCanUpdate, x.SubSystemId, x.CustomId + }); + if (trackPushConfig == null) return null; + + var trackPushContentList = await _trackPushConfigRepository.GetContentListAsync(trackPushConfig.Id); + if (trackPushContentList.Count == 0) return null; + + // tips:hot path,auto mapper性能不如原生 + var res = trackPushContentList.Select(item => new TrackPushContentConfigDto + { + IsAutoPush = trackPushConfig.IsAutoPush, + IsCanUpdate = trackPushConfig.IsCanUpdate, + IsAllPush = trackPushConfig.IsAllPush, + IsCanDelete = trackPushConfig.IsCanDelete, + ServiceProviderCode = item.ServiceProviderCode, + OrderType = item.OrderType, + TrackCode = item.TrackCode, + SwapTrackCode = item.SwapTrackCode, + TrackStatusValue = item.TrackStatusValue, + TrackContentCodeValue = item.TrackContentCodeValue, + TrackContentValue = item.TrackContentValue, + TrackEnContentValue = item.TrackEnContentValue, + TrackTimeZone = item.TrackTimeZone, + ExpandFieldsValue = item.ExpandFieldsValue, + }).ToList(); + + await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfig.SubSystemId, trackPushConfig.CustomId), + res); + + return res; + } } \ No newline at end of file diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs index 712bbc3c..e506cc3f 100644 --- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs +++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs @@ -104,64 +104,35 @@ public class TrackPushService : ApplicationService switch (input.Options) { case OptionTypeNoNull.新增: - { - var trackPushEntity = ObjectMapper.Map(input); - var trackPushParamsEntity = - ObjectMapper.Map(input); - - using (var ts = TransactionScopeHelper.Create()) - { - int id = await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity); - - trackPushParamsEntity.PullOrPushConfigId = id; - await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity); - - ts.Complete(); - } - } + { + var trackPushEntity = ObjectMapper.Map(input); + await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity); + } break; case OptionTypeNoNull.修改: - { - var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? - throw new BusinessException(message: _stringLocalizer["NotFindData"]); + { + var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? + throw new BusinessException(message: _stringLocalizer["NotFindData"]); - int oldCustomId = oldTrackPushEntity.CustomId; + ObjectMapper.Map(input, oldTrackPushEntity); + await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity); - 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); - - ts.Complete(); - } - - if (input.IsAutoPush!.Value) await _trackPushCacheService.SetPushContentConfigsAsync(input.Id); - } + if (input.IsAutoPush!.Value) await _trackPushCacheService.SetPushContentConfigsAsync(input.Id); + } break; case OptionTypeNoNull.删除: - { - var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? - throw new BusinessException(message: _stringLocalizer["NotFindData"]); + { + _ = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? + throw new BusinessException(message: _stringLocalizer["NotFindData"]); - 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); + using var ts = TransactionScopeHelper.Create(); + await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id); + await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id); - ts.Complete(); - } - } + ts.Complete(); + } break; default: @@ -210,51 +181,51 @@ public class TrackPushService : ApplicationService 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 _trackPushCacheService.SetPushContentConfigsAsync(input.TrackPushConfigId); + await _trackPushConfigRepository.InsertContentAsync(entity); + await _trackPushCacheService.SetPushContentConfigsAsync(input.TrackPushConfigId); - 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 _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId); + await _trackPushConfigRepository.UpdateContentAsync(entity); + await _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId); - 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); + await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1, + x => x.TrackPushConfigId == entity.TrackPushConfigId && x.Sort > entity.Sort); - 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); - - ts.Complete(); - } - - await _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId); - - break; + ts.Complete(); } + await _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId); + + 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 2553cb31..e0f19389 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(异步维护) + /// 最新推送轨迹code(异步维护) /// - [SugarColumn(ColumnName = "LatestPushTrackContentId")] - public int? LatestPushTrackContentId { get; set; } + [SugarColumn(ColumnName = "LatestPushTrackCode")] + public string? LatestPushTrackCode { get; set; } /// /// 最新推送时间(异步维护) @@ -54,6 +54,12 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot [SugarColumn(ColumnName = "LatestPushTime")] public DateTime? LatestPushTime { get; set; } + /// + /// 推送异常信息 + /// + [SugarColumn(ColumnName = "LatestPushError")] + public string? LatestPushError { get; set; } + /// /// 最新轨迹内容(异步维护) /// @@ -120,12 +126,6 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot [SugarColumn(ColumnName = "QuestionType")] public int QuestionType { get; set; } - /// - /// 问题描述 - /// - [SugarColumn(ColumnName = "ProblemDescription")] - public string? ProblemDescription { get; set; } - /// /// 起运港口 /// diff --git a/src/SJZY.Track.Domain/Aggregates/TrackContentAggregate/TrackContentEntity.cs b/src/SJZY.Track.Domain/Aggregates/TrackContentAggregate/TrackContentEntity.cs index 44d00b9d..02fac985 100644 --- a/src/SJZY.Track.Domain/Aggregates/TrackContentAggregate/TrackContentEntity.cs +++ b/src/SJZY.Track.Domain/Aggregates/TrackContentAggregate/TrackContentEntity.cs @@ -47,10 +47,4 @@ public class TrackContentEntity : IFullAuditedBasicEntitys, IAggregateRoot /// [SugarColumn(ColumnName = "TrackStatusId")] public int TrackStatusId { get; set; } - - /// - /// 是否完结 - /// - [SugarColumn(ColumnName = "IsCompleted")] - public bool IsCompleted { get; set; } } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/ITrackDetailsRepository.cs b/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/ITrackDetailsRepository.cs index c78d9b2f..628acc1f 100644 --- a/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/ITrackDetailsRepository.cs +++ b/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/ITrackDetailsRepository.cs @@ -6,7 +6,7 @@ public interface ITrackDetailsRepository { Task GetFirstOrDefaultAsync(int orderId, string trackCode); - Task GetFirstOrDefaultAsync(int orderId, DateTime trackTime); + Task AnyAsync(int orderId, DateTime trackTime); Task UpsertAsync(TrackDetailsIndex index); diff --git a/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/TrackDetailsIndex.cs b/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/TrackDetailsIndex.cs index b3319d35..7cb77e84 100644 --- a/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/TrackDetailsIndex.cs +++ b/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/TrackDetailsIndex.cs @@ -43,14 +43,9 @@ public class TrackDetailsIndex : IdBaseIndex public string TrackContent { get; set; } = null!; /// - /// 轨迹内容Id + /// 服务商 /// - public int TrackContentId { get; set; } - - /// - /// 这条轨迹是否意味着完成 - /// - public bool IsCompleted { get; set; } + public string? ServiceProviderName { get; set; } /// /// 原轨迹内容 diff --git a/src/SJZY.Track.Domain/Aggregates/TrackPullAggregate/TrackPullContentConfigEntity.cs b/src/SJZY.Track.Domain/Aggregates/TrackPullAggregate/TrackPullContentConfigEntity.cs index 13d74a83..5afef0fb 100644 --- a/src/SJZY.Track.Domain/Aggregates/TrackPullAggregate/TrackPullContentConfigEntity.cs +++ b/src/SJZY.Track.Domain/Aggregates/TrackPullAggregate/TrackPullContentConfigEntity.cs @@ -65,4 +65,10 @@ public class TrackPullContentConfigEntity : IFullAuditedBasicEntitys, IEntity /// [SugarColumn(ColumnName = "TrackTimeZone")] public float? TrackTimeZone { get; set; } + + /// + /// 是否完结 + /// + [SugarColumn(ColumnName = "IsCompleted")] + public bool IsCompleted { get; set; } } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/TrackPushConfigEntity.cs b/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/TrackPushConfigEntity.cs index 0c417253..659e3281 100644 --- a/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/TrackPushConfigEntity.cs +++ b/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/TrackPushConfigEntity.cs @@ -47,4 +47,10 @@ public class TrackPushConfigEntity : IFullAuditedBasicEntitys, IAggregateRoot /// [SugarColumn(ColumnName = "IsCanDelete")] public bool IsCanDelete { get; set; } + + /// + /// 是否全量推送 + /// + [SugarColumn(ColumnName = "IsAllPush")] + public bool IsAllPush { get; set; } } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/TrackPushContentConfigEntity.cs b/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/TrackPushContentConfigEntity.cs index 1c392d52..163b5b34 100644 --- a/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/TrackPushContentConfigEntity.cs +++ b/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/TrackPushContentConfigEntity.cs @@ -12,18 +12,24 @@ public class TrackPushContentConfigEntity : IFullAuditedBasicEntitys, IEntity [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)] public int Id { get; set; } - /// - /// 扩展字段参数值 - /// - [SugarColumn(ColumnName = "ExpandFieldsValue")] - public string ExpandFieldsValue { get; set; } - /// /// 推送单号类型(主数据枚举TrackOrderType) /// [SugarColumn(ColumnName = "OrderNoType")] public int OrderNoType { get; set; } + /// + /// 轨迹内容id + /// + [SugarColumn(ColumnName = "TrackContentId")] + public int TrackContentId { get; set; } + + /// + /// 可交换顺序的轨迹内容id + /// + [SugarColumn(ColumnName = "SwapTrackContentId")] + public int? SwapTrackContentId { get; set; } + /// /// 推送轨迹排序 /// @@ -36,12 +42,6 @@ public class TrackPushContentConfigEntity : IFullAuditedBasicEntitys, IEntity [SugarColumn(ColumnName = "TrackContentCodeValue")] public string TrackContentCodeValue { get; set; } - /// - /// 轨迹内容id - /// - [SugarColumn(ColumnName = "TrackContentId")] - public int TrackContentId { get; set; } - /// /// 轨迹内容参数值 /// @@ -71,4 +71,10 @@ public class TrackPushContentConfigEntity : IFullAuditedBasicEntitys, IEntity /// [SugarColumn(ColumnName = "TrackTimeZone")] public double? TrackTimeZone { get; set; } + + /// + /// 扩展字段参数值 + /// + [SugarColumn(ColumnName = "ExpandFieldsValue")] + public string ExpandFieldsValue { get; set; } } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Consts/GlobalConst.MQ.cs b/src/SJZY.Track.Domain/Consts/GlobalConst.MQ.cs index 535dcc4d..35179262 100644 --- a/src/SJZY.Track.Domain/Consts/GlobalConst.MQ.cs +++ b/src/SJZY.Track.Domain/Consts/GlobalConst.MQ.cs @@ -7,6 +7,11 @@ public partial class GlobalConst /// public const string TrackUpsertSubscribe = "SJZY.Track.TrackUpsert"; + /// + /// 无法映射的轨迹新增 + /// + public const string TrackInsertForNotMappedEventSubscribe = "SJZY.Track.TrackInsertForNotMapped"; + /// /// 轨迹删除 /// diff --git a/src/SJZY.Track.Domain/Consts/GlobalConst.cs b/src/SJZY.Track.Domain/Consts/GlobalConst.cs index a7167357..ec269ee2 100644 --- a/src/SJZY.Track.Domain/Consts/GlobalConst.cs +++ b/src/SJZY.Track.Domain/Consts/GlobalConst.cs @@ -2,5 +2,6 @@ public partial class GlobalConst { + public const string SystemUser = "系统"; public const string EmptyString = "--"; } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Dtos/Order/LinkedOrderVO.cs b/src/SJZY.Track.Domain/Dtos/Order/LinkedOrderVO.cs index 2e0ffbed..c6eea835 100644 --- a/src/SJZY.Track.Domain/Dtos/Order/LinkedOrderVO.cs +++ b/src/SJZY.Track.Domain/Dtos/Order/LinkedOrderVO.cs @@ -21,19 +21,4 @@ public class LinkedOrderVO /// 子系统id /// public int SubSystemId { get; set; } - - /// - /// 最新推送轨迹内容id(异步维护) - /// - public int? LatestPushTrackContentId { get; set; } - - /// - /// 客户id - /// - public int CustomId { get; set; } - - /// - /// 订单是否完成 - /// - public bool IsCompleted { get; set; } } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Dtos/TrackDetails/MatchTrackContentDto.cs b/src/SJZY.Track.Domain/Dtos/TrackDetails/MatchTrackContentDto.cs index e0213b5e..58429cdb 100644 --- a/src/SJZY.Track.Domain/Dtos/TrackDetails/MatchTrackContentDto.cs +++ b/src/SJZY.Track.Domain/Dtos/TrackDetails/MatchTrackContentDto.cs @@ -5,7 +5,7 @@ public class MatchTrackContentDto /// /// 轨迹内容id /// - public int Id { get; set; } + public string TrackCode { get; set; } /// /// 轨迹内容 @@ -22,11 +22,6 @@ public class MatchTrackContentDto /// public string Status { get; set; } = null!; - /// - /// 是否意味着完成 - /// - public bool IsCompleted { get; set; } - /// /// 是否可删 /// diff --git a/src/SJZY.Track.Domain/Dtos/TrackPull/GetTrackPullContentListCacheVO.cs b/src/SJZY.Track.Domain/Dtos/TrackPull/GetTrackPullContentListCacheVO.cs index 1551647d..047431d9 100644 --- a/src/SJZY.Track.Domain/Dtos/TrackPull/GetTrackPullContentListCacheVO.cs +++ b/src/SJZY.Track.Domain/Dtos/TrackPull/GetTrackPullContentListCacheVO.cs @@ -41,4 +41,9 @@ public class GetTrackPullContentListCacheVO /// 轨迹时区GMT /// public float? TrackTimeZone { get; set; } + + /// + /// 订单是否完成(由轨迹刷新配置决定) + /// + public bool IsCompleted { get; set; } } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Dtos/TrackPush/TrackPushContentConfigVO.cs b/src/SJZY.Track.Domain/Dtos/TrackPush/TrackPushContentConfigVO.cs index 1f67fb8d..6ec62e85 100644 --- a/src/SJZY.Track.Domain/Dtos/TrackPush/TrackPushContentConfigVO.cs +++ b/src/SJZY.Track.Domain/Dtos/TrackPush/TrackPushContentConfigVO.cs @@ -12,15 +12,25 @@ public class TrackPushContentConfigVO /// public bool IsCanUpdate { get; set; } + /// + /// 是否全量推送 + /// + public bool IsAllPush { get; set; } + /// /// 服务商code /// public string ServiceProviderCode { get; set; } = null!; /// - /// 扩展字段参数值 + /// 轨迹code /// - public string? ExpandFieldsValue { get; set; } + public string TrackCode { get; set; } = null!; + + /// + /// 可交换顺序的轨迹code + /// + public string? SwapTrackCode { get; set; } /// /// 推送单号类型(主数据枚举TrackOrderType) @@ -32,11 +42,6 @@ public class TrackPushContentConfigVO /// public string? TrackContentCodeValue { get; set; } - /// - /// 轨迹内容id - /// - public int TrackContentId { get; set; } - /// /// 轨迹内容参数值 /// @@ -56,4 +61,9 @@ public class TrackPushContentConfigVO /// 轨迹时区GMT /// public double? TrackTimeZone { get; set; } + + /// + /// 扩展字段参数值 + /// + public string? ExpandFieldsValue { get; set; } } \ No newline at end of file diff --git a/src/SJZY.Track.Repository/Queries/ProvideQueries.cs b/src/SJZY.Track.Repository/Queries/ProvideQueries.cs index 483cd181..cce3c885 100644 --- a/src/SJZY.Track.Repository/Queries/ProvideQueries.cs +++ b/src/SJZY.Track.Repository/Queries/ProvideQueries.cs @@ -71,11 +71,10 @@ 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, + TrackCode = b.Code, Content = b.Content, EnContent = b.EnContent, Status = c.Status, - IsCompleted = b.IsCompleted, IsCanDelete = a.IsCanDelete }) .FirstAsync(); diff --git a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs index bbbdca05..6537263b 100644 --- a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs @@ -84,10 +84,7 @@ public class OrderRepository : BasicRepository, IOrderRepository, I OrderId = b.Id, OrderType = b.OrderType, OrderNo = b.OrderNo, - SubSystemId = b.SubSystemId, - LatestPushTrackContentId = b.LatestPushTrackContentId, - CustomId = b.CustomId, - IsCompleted = b.IsCompleted + SubSystemId = b.SubSystemId }) .ToListAsync(); } diff --git a/src/SJZY.Track.Repository/Repositories/TrackContentRepository.cs b/src/SJZY.Track.Repository/Repositories/TrackContentRepository.cs index 360f2a88..53b23855 100644 --- a/src/SJZY.Track.Repository/Repositories/TrackContentRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/TrackContentRepository.cs @@ -1,12 +1,11 @@ -using SJZY.Track.Domain.Aggregates.TrackContentAggregate; +using System.Linq.Expressions; +using SJZY.Track.Domain.Aggregates.TrackContentAggregate; using SJZY.Track.Domain.Aggregates.TrackFlagAggregate; using SJZY.Track.Domain.Aggregates.TrackStatusAggregate; using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate; using SJZY.Track.Domain.Dtos.TrackContents; using SJZY.Track.Domain.Dtos.TrackTemplate; using SJZY.Track.Domain.VEntities; -using System.Linq; -using System.Linq.Expressions; namespace SJZY.Track.Repository.Repositories; @@ -39,8 +38,7 @@ public class TrackContentRepository : BasicRepository, ITrac Content = a.Content, EnContent = a.EnContent, TrackFlagId = a.TrackFlagId, - TrackFlag = c.Name, - IsFinish = a.IsCompleted + TrackFlag = c.Name }) .FirstAsync(); return detail; @@ -63,10 +61,12 @@ public class TrackContentRepository : BasicRepository, ITrac .WhereIF(input.SubSystemId > 0, (a, b, c, d, e, f) => a.SubSystemId == input.SubSystemId) .WhereIF(!input.Keywords.IsNullOrWhiteSpace(), (a, b, c, d, e, f) => a.Code.Contains(input.Keywords) || a.Content.Contains(input.Keywords) - || a.EnContent.Contains(input.Keywords)) + || a.EnContent.Contains(input.Keywords)) .WhereIF(input.TrackStatusId > 0, (a, b, c, d, e, f) => a.TrackStatusId == input.TrackStatusId) .OrderByIF(input.SelectIds.IsNullOrEmpty(), (a, b, c, d, e, f) => a.CreateTime, OrderByType.Desc) - .OrderByIF(!input.SelectIds.IsNullOrEmpty(), (a, b, c, d, e, f) => SqlFunc.IIF(input.SelectIds.Contains(a.Id), SqlFunc.DateAdd(SqlFunc.GetDate(), 1), a.CreateTime), OrderByType.Desc) + .OrderByIF(!input.SelectIds.IsNullOrEmpty(), + (a, b, c, d, e, f) => SqlFunc.IIF(input.SelectIds.Contains(a.Id), SqlFunc.DateAdd(SqlFunc.GetDate(), 1), + a.CreateTime), OrderByType.Desc) .Select((a, b, c, d, e, f) => new GetTrackContentListVO { Id = a.Id, @@ -75,15 +75,15 @@ public class TrackContentRepository : BasicRepository, ITrac Content = a.Content, EnContent = a.EnContent, TrackStatus = b.Status, - Node = SqlFunc.IF(b.Node == 1).Return("揽收").ElseIF(b.Node == 2).Return("清关").ElseIF(b.Node == 3).Return("干线") - .ElseIF(b.Node == 4).Return("派送").ElseIF(b.Node == 5).Return("其他") - .End(""), + Node = SqlFunc.IF(b.Node == 1).Return("揽收").ElseIF(b.Node == 2).Return("清关").ElseIF(b.Node == 3) + .Return("干线") + .ElseIF(b.Node == 4).Return("派送").ElseIF(b.Node == 5).Return("其他") + .End(""), TrackFlag = c.Name, CreateTime = a.CreateTime, CreateUser = e.Name, UpdateTime = a.UpdateTime, UpdateUser = f.Name, - IsFinish = a.IsCompleted }) .ToPagedListAsync(input.PageIndex, input.PageSize); @@ -94,10 +94,12 @@ public class TrackContentRepository : BasicRepository, ITrac /// 获取轨迹内容属性值 /// /// - public async Task> GetTrackContentAttributeValue(GetTemplateContentAttributeValueInputVO input) + public async Task> GetTrackContentAttributeValue( + GetTemplateContentAttributeValueInputVO input) { var list = await Context.Queryable() - .LeftJoin((a, b) => a.Id == b.TrackContentId && b.TrackTemplateId > 0 && b.IsDeleted == false) + .LeftJoin((a, b) => + a.Id == b.TrackContentId && b.TrackTemplateId > 0 && b.IsDeleted == false) .LeftJoin((a, b, c) => b.TrackTemplateId == c.Id && c.IsDeleted == false) .WhereIF(!input.TrackCodes.IsNullOrEmpty(), (a, b, c) => input.TrackCodes!.Contains(a.Code)) .WhereIF(input.SubSystemId > 0, (a, b, c) => a.SubSystemId == input.SubSystemId) @@ -125,15 +127,16 @@ public class TrackContentRepository : BasicRepository, ITrac public async Task GetTemplateIsExist(int trackContentId) { //var trackTemplateContents = await _trackTemplateContentBasicQuery.GetListAsync(a => a.TrackContentId == input.Id); - var trackContentEntities = await Context.Queryable().LeftJoin((a, b) => a.Id == b.TrackContentId && b.IsDeleted == false) - .LeftJoin((a, b, c) => b.TrackTemplateId == c.Id && c.IsDeleted == false) - .Where((a, b, c) => a.Id == trackContentId) - .Select((a, b, c) => new - { - TrackContentId = a.Id, - TemplateId = c.Id - }) - .ToListAsync(); + var trackContentEntities = await Context.Queryable() + .LeftJoin((a, b) => a.Id == b.TrackContentId && b.IsDeleted == false) + .LeftJoin((a, b, c) => b.TrackTemplateId == c.Id && c.IsDeleted == false) + .Where((a, b, c) => a.Id == trackContentId) + .Select((a, b, c) => new + { + TrackContentId = a.Id, + TemplateId = c.Id + }) + .ToListAsync(); if (trackContentEntities.Any(a => a.TemplateId > 0)) { @@ -144,57 +147,75 @@ public class TrackContentRepository : BasicRepository, ITrac } - - public async Task> GetMapPageAsync(GetTrackContentMapPageInputVO input) + public async Task> GetMapPageAsync( + GetTrackContentMapPageInputVO input) { return await Context.Queryable() - .InnerJoin((contentMap, sourceContent) => contentMap.TrackContentId == sourceContent.Id && !sourceContent.IsDeleted) - .InnerJoin((contentMap, sourceContent, targetContent) => contentMap.MapTrackContentId == targetContent.Id && !targetContent.IsDeleted) - .LeftJoin((contentMap, sourceContent, targetContent, sourceSystem) => contentMap.SubSystemId == sourceSystem.Id && !sourceSystem.IsDeleted) - .LeftJoin((contentMap, sourceContent, targetContent, sourceSystem, targetSystem) => contentMap.MapSubSystemId == targetSystem.Id && !targetSystem.IsDeleted) - .LeftJoin((contentMap, sourceContent, targetContent, sourceSystem, targetSystem, sourceStatus) => sourceContent.TrackStatusId == sourceStatus.Id && !sourceStatus.IsDeleted) - .LeftJoin((contentMap, sourceContent, targetContent, sourceSystem, targetSystem, sourceStatus, targetStatus) => targetContent.TrackStatusId == targetStatus.Id && !targetStatus.IsDeleted) + .InnerJoin((contentMap, sourceContent) => + contentMap.TrackContentId == sourceContent.Id && !sourceContent.IsDeleted) + .InnerJoin((contentMap, sourceContent, targetContent) => + contentMap.MapTrackContentId == targetContent.Id && !targetContent.IsDeleted) + .LeftJoin((contentMap, sourceContent, targetContent, sourceSystem) => + contentMap.SubSystemId == sourceSystem.Id && !sourceSystem.IsDeleted) + .LeftJoin((contentMap, sourceContent, targetContent, sourceSystem, targetSystem) => + contentMap.MapSubSystemId == targetSystem.Id && !targetSystem.IsDeleted) + .LeftJoin( + (contentMap, sourceContent, targetContent, sourceSystem, targetSystem, sourceStatus) => + sourceContent.TrackStatusId == sourceStatus.Id && !sourceStatus.IsDeleted) + .LeftJoin( + (contentMap, sourceContent, targetContent, sourceSystem, targetSystem, sourceStatus, targetStatus) => + targetContent.TrackStatusId == targetStatus.Id && !targetStatus.IsDeleted) .Filter(null, true) .Where(contentMap => !contentMap.IsDeleted) .WhereIF(input.SubSystemId.HasValue, contentMap => contentMap.SubSystemId == input.SubSystemId) .WhereIF(input.MapSubSystemId.HasValue, contentMap => contentMap.MapSubSystemId == input.MapSubSystemId) - .WhereIF(!input.Keywords.IsNullOrWhiteSpace(), (contentMap, sourceContent) => sourceContent.Code.Contains(input.Keywords) || sourceContent.Content.Contains(input.Keywords) || sourceContent.EnContent.Contains(input.Keywords)) + .WhereIF(!input.Keywords.IsNullOrWhiteSpace(), + (contentMap, sourceContent) => sourceContent.Code.Contains(input.Keywords) || + sourceContent.Content.Contains(input.Keywords) || + sourceContent.EnContent.Contains(input.Keywords)) .OrderByDescending(contentMap => contentMap.CreateTime) - .Select((contentMap, sourceContent, targetContent, sourceSystem, targetSystem, sourceStatus, targetStatus) => new GetTrackContentMapPageOutputVO - { - Id = contentMap.Id, - SubSystem = sourceSystem.CnName, - Code = contentMap.TrackContentCode, - TrackStatus = sourceStatus.Status, - Content = sourceContent.Content, - EnContent = sourceContent.EnContent, - MapSubSystem = targetSystem.CnName, - MapCode = contentMap.MapTrackContentCode, - MapTrackStatus = targetStatus.Status, - MapContent = targetContent.Content, - MapEnContent = targetContent.EnContent - }) + .Select( + (contentMap, sourceContent, targetContent, sourceSystem, targetSystem, sourceStatus, targetStatus) => + new GetTrackContentMapPageOutputVO + { + Id = contentMap.Id, + SubSystem = sourceSystem.CnName, + Code = contentMap.TrackContentCode, + TrackStatus = sourceStatus.Status, + Content = sourceContent.Content, + EnContent = sourceContent.EnContent, + MapSubSystem = targetSystem.CnName, + MapCode = contentMap.MapTrackContentCode, + MapTrackStatus = targetStatus.Status, + MapContent = targetContent.Content, + MapEnContent = targetContent.EnContent + }) .ToPagedListAsync(input.PageIndex, input.PageSize); } public async Task GetMapDetailAsync(int id) { return await Context.Queryable() - .InnerJoin((contentMap, sourceContent) => contentMap.TrackContentId == sourceContent.Id && !sourceContent.IsDeleted) - .InnerJoin((contentMap, sourceContent, targetContent) => contentMap.MapTrackContentId == targetContent.Id && !targetContent.IsDeleted) - .LeftJoin((contentMap, sourceContent, targetContent, sourceSystem) => contentMap.SubSystemId == sourceSystem.Id && !sourceSystem.IsDeleted) - .LeftJoin((contentMap, sourceContent, targetContent, sourceSystem, targetSystem) => contentMap.MapSubSystemId == targetSystem.Id && !targetSystem.IsDeleted) + .InnerJoin((contentMap, sourceContent) => + contentMap.TrackContentId == sourceContent.Id && !sourceContent.IsDeleted) + .InnerJoin((contentMap, sourceContent, targetContent) => + contentMap.MapTrackContentId == targetContent.Id && !targetContent.IsDeleted) + .LeftJoin((contentMap, sourceContent, targetContent, sourceSystem) => + contentMap.SubSystemId == sourceSystem.Id && !sourceSystem.IsDeleted) + .LeftJoin((contentMap, sourceContent, targetContent, sourceSystem, targetSystem) => + contentMap.MapSubSystemId == targetSystem.Id && !targetSystem.IsDeleted) .Filter(null, true) .Where(contentMap => contentMap.Id == id && !contentMap.IsDeleted) - .Select((contentMap, sourceContent, targetContent, sourceSystem, targetSystem) => new GetTrackContentMapDetailOutputVO - { - Id = contentMap.Id, - SubSystemId = contentMap.SubSystemId, - SubSystem = sourceSystem.CnName, - TrackContent = contentMap.TrackContentCode + "-" + sourceContent.Content, - MapSubSystem = targetSystem.CnName, - MapTrackContent = contentMap.MapTrackContentCode + "-" + targetContent.Content - }, true) + .Select((contentMap, sourceContent, targetContent, sourceSystem, targetSystem) => + new GetTrackContentMapDetailOutputVO + { + Id = contentMap.Id, + SubSystemId = contentMap.SubSystemId, + SubSystem = sourceSystem.CnName, + TrackContent = contentMap.TrackContentCode + "-" + sourceContent.Content, + MapSubSystem = targetSystem.CnName, + MapTrackContent = contentMap.MapTrackContentCode + "-" + targetContent.Content + }, true) .SingleAsync(); } @@ -226,7 +247,8 @@ public class TrackContentRepository : BasicRepository, ITrac .ExecuteCommandHasChangeAsync(); } - public async Task UpdateMapAsync(Expression> columns, Expression> whereExpression) + public async Task UpdateMapAsync(Expression> columns, + Expression> whereExpression) { return await Context.Updateable().SetColumns(columns).Where(whereExpression) .ExecuteCommandAsync() > 0; diff --git a/src/SJZY.Track.Repository/Repositories/TrackDetailsRepository.cs b/src/SJZY.Track.Repository/Repositories/TrackDetailsRepository.cs index 05ee176c..1229eec7 100644 --- a/src/SJZY.Track.Repository/Repositories/TrackDetailsRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/TrackDetailsRepository.cs @@ -32,23 +32,17 @@ internal class TrackDetailsRepository : ElasticSearchContextAbstract GetFirstOrDefaultAsync(int orderId, DateTime trackTime) + public async Task AnyAsync(int orderId, DateTime trackTime) { - var r = await Context.SearchAsync(s => s - .Source() + var r = await Context.SearchAsync(x => x + .Source(s => s.Includes(fd => fd.Field(f => f.Id))) .Query(q => q.Term(f => f.OrderId, orderId) && q.Term(f => f.TrackTime, trackTime) ) ); - var res = r.Documents.FirstOrDefault(); - if (res != default && r.Hits.FirstOrDefault() != default) - { - res.Id = r.Hits.FirstOrDefault()!.Id; - } - - return res; + return r.Hits.Count > 0; } public async Task UpsertAsync(TrackDetailsIndex index) @@ -117,7 +111,6 @@ internal class TrackDetailsRepository : ElasticSearchContextAbstract f.TrackStatus) .Field(f => f.TrackCode) .Field(f => f.TrackContent) - .Field(f => f.TrackContentId) .Field(f => f.TrackPlace) .Field(f => f.TrackTime) .Field(f => f.TrackTimeZone) @@ -150,7 +143,6 @@ internal class TrackDetailsRepository : ElasticSearchContextAbstract(x => x .Source(s => s.Includes(fd => fd - .Field(f => f.IsCompleted) .Field(f => f.TrackEnContent) .Field(f => f.TrackContent) .Field(f => f.TrackPlace) diff --git a/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs b/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs index 74bfc0d3..41f4e708 100644 --- a/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs @@ -125,21 +125,25 @@ public class TrackPushConfigRepository : BasicRepository, return await Context.Queryable() .LeftJoin((a, b) => a.Id == b.TrackPushConfigId) .LeftJoin((a, b, c) => a.ServiceProviderId == c.Id) + .LeftJoin((a, b, c, d) => b.TrackContentId == d.Id) + .LeftJoin((a, b, c, d, e) => b.SwapTrackContentId == e.Id) .Where(a => a.Id == configId) .OrderBy((a, b) => b.Sort) - .Select((a, b, c) => new TrackPushContentConfigVO + .Select((a, b, c, d, e) => new TrackPushContentConfigVO { IsAutoPush = a.IsAutoPush, IsCanUpdate = a.IsCanUpdate, + IsAllPush = a.IsAllPush, ServiceProviderCode = c.Code, - ExpandFieldsValue = b.ExpandFieldsValue, OrderType = b.OrderNoType, + TrackCode = d.Code, + SwapTrackCode = e.Code, TrackContentCodeValue = b.TrackContentCodeValue, - TrackContentId = b.TrackContentId, TrackContentValue = b.TrackContentValue, TrackEnContentValue = b.TrackEnContentValue, TrackStatusValue = b.TrackStatusValue, - TrackTimeZone = b.TrackTimeZone + TrackTimeZone = b.TrackTimeZone, + ExpandFieldsValue = b.ExpandFieldsValue, }) .ToListAsync(); }