Merge branch 'S03-轨迹中台' into dev

# Conflicts:
#	src/SJZY.Track.Application/Services/ProvideServices/OrderService.Link.cs
#	src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs
This commit is contained in:
李鹏军 2024-04-01 16:09:11 +08:00
commit 5c4b79fd0c
72 changed files with 1326 additions and 1279 deletions

View File

@ -5,9 +5,11 @@
"Apollo": {
"AppId": "SJZY.Track.Configuration",
"Env": "DEV",
"Namespace": "Test",
"Namespace": "Dev",
"MetaServer": "http://apollo-service-test-apollo-configservice.apollo.svc.cluster.local:8080",
"ConfigServer": [ "http://apollo-service-test-apollo-configservice.apollo.svc.cluster.local:8080" ]
"ConfigServer": [
"http://apollo-service-test-apollo-configservice.apollo.svc.cluster.local:8080"
]
}
},
"Kestrel": {

View File

@ -1,100 +1,107 @@
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
{
/// <summary>
/// 轨迹订单id
/// </summary>
public int OrderId { get; set; }
/// <summary>
/// 轨迹订单id
/// </summary>
public int OrderId { get; set; }
/// <summary>
/// 子系统id
/// </summary>
public int SubSystemId { get; set; }
/// <summary>
/// 子系统id
/// </summary>
public int SubSystemId { get; set; }
/// <summary>
/// 轨迹模板Id
/// </summary>
public List<int>? TrackTemplateIds { get; set; } = new List<int>();
}
/// <summary>
/// 轨迹模板Id
/// </summary>
public List<int>? TrackTemplateIds { get; set; } = new List<int>();
}
public class TrackOrderDetailDto
{
/// <summary>
/// Id es主键
/// </summary>
public int Id { get; set; }
public class TrackOrderDetailDto
{
/// <summary>
/// Id es主键
/// </summary>
public string Id { get; set; } = null!;
/// <summary>
/// 轨迹订单id
/// </summary>
public int OrderId { set; get; }
/// <summary>
/// 轨迹订单id
/// </summary>
public int OrderId { set; get; }
/// <summary>
/// 订单类型(主数据枚举TrackOrderType)
/// </summary>
public int OrderType { get; set; }
/// <summary>
/// 订单类型(主数据枚举TrackOrderType)
/// </summary>
public int OrderType { get; set; }
/// <summary>
/// 订单号
/// </summary>
public string OrderNo { get; set; } = null!;
/// <summary>
/// 订单号
/// </summary>
public string OrderNo { get; set; } = null!;
/// <summary>
/// 轨迹代码
/// </summary>
public string? Code { get; set; }
/// <summary>
/// 轨迹代码
/// </summary>
public string? Code { get; set; }
/// <summary>
/// 轨迹内容
/// </summary>
public string? Content { get; set; }
/// <summary>
/// 轨迹内容
/// </summary>
public string? Content { get; set; }
/// <summary>
/// 轨迹内容英文
/// </summary>
public string? EnContent { get; set; }
/// <summary>
/// 轨迹内容英文
/// </summary>
public string? EnContent { get; set; }
/// <summary>
/// 轨迹发生地
/// </summary>
public string? TrackPlace { get; set; }
/// <summary>
/// 服务商
/// </summary>
public string? ServiceProviderName { get; set; }
/// <summary>
/// 轨迹发生时间
/// </summary>
public DateTime? TrackTime { get; set; }
/// <summary>
/// 原轨迹内容
/// </summary>
public string? OriginTrackContent { get; set; }
/// <summary>
/// 轨迹发生时区
/// </summary>
public string? TrackTimeZone { get; set; }
/// <summary>
/// 轨迹发生地
/// </summary>
public string? TrackPlace { get; set; }
/// <summary>
/// 时区的值
/// </summary>
public float TrackTimeZoneValue { get; set; }
/// <summary>
/// 轨迹发生时间
/// </summary>
public DateTime? TrackTime { get; set; }
/// <summary>
/// 是否可删
/// </summary>
public bool IsCanDelete { get; set; }
/// <summary>
/// 轨迹发生时区
/// </summary>
public string? TrackTimeZone { get; set; }
/// <summary>
/// 是否对外
/// </summary>
public bool IsExternal { get; set; }
/// <summary>
/// 时区的值
/// </summary>
public float TrackTimeZoneValue { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreateTime { get; set; }
/// <summary>
/// 是否可删
/// </summary>
public bool IsCanDelete { get; set; }
/// <summary>
/// 创建人
/// </summary>
public string? CreateUser { get; set; }
}
/// <summary>
/// 是否对外
/// </summary>
public bool IsExternal { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreateTime { get; set; }
/// <summary>
/// 创建人
/// </summary>
public string? CreateUser { get; set; }
}

View File

@ -20,7 +20,7 @@ public class LinkOrderInput
/// 订单号,必填
/// </summary>
[Required]
public string OrderNo { get; set; }
public string OrderNo { get; set; } = null!;
/// <summary>
/// 关联单类型

View File

@ -41,11 +41,6 @@
/// 轨迹标记id
/// </summary>
public int TrackFlagId { get; set; }
/// <summary>
/// 是否完结
/// </summary>
public bool IsFinish { get; set; }
}
public class GetTrackContentDetailDto
@ -99,10 +94,5 @@
/// 轨迹标记
/// </summary>
public string TrackFlag { get; set; }
/// <summary>
/// 是否完结
/// </summary>
public bool IsFinish { get; set; }
}
}

View File

@ -20,7 +20,7 @@
/// <summary>
/// 选中的轨迹内容id
/// </summary>
public List<int>? SelectIds { get; set; }
public List<int>? SelectIds { get; set; }
}
public class GetTrackContentListDto
@ -84,10 +84,5 @@
/// 修改人
/// </summary>
public string UpdateUser { get; set; }
/// <summary>
/// 是否完结
/// </summary>
public bool IsFinish { get; set; }
}
}

View File

@ -53,4 +53,9 @@ public class EditTrackPullContentInput
/// 轨迹时区GMT
/// </summary>
public double? TrackTimeZone { get; set; }
/// <summary>
/// 是否完结
/// </summary>
public bool IsCompleted { get; set; }
}

View File

@ -41,4 +41,9 @@ public class TrackPullContentConfigDto
/// 轨迹时区GMT值
/// </summary>
public float? TrackTimeZoneValue { get; set; }
/// <summary>
/// 订单是否完成(由轨迹刷新配置决定)
/// </summary>
public bool IsCompleted { get; set; }
}

View File

@ -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<TrackPullContentConfigDto> ContentConfigs { get; set; }
public List<TrackPullContentConfigDto> ContentConfigs { get; set; } = new();
}

View File

@ -2,10 +2,10 @@
public class TrackRefreshAttach
{
public TrackRefreshAttach(int serviceProviderId, string serviceProviderCode, int subSystemId, int orderType)
public TrackRefreshAttach(int serviceProviderId, string serviceProviderName, int subSystemId, int orderType)
{
ServiceProviderId = serviceProviderId;
ServiceProviderCode = serviceProviderCode;
ServiceProviderName = serviceProviderName;
SubSystemId = subSystemId;
OrderType = orderType;
}
@ -16,9 +16,9 @@ public class TrackRefreshAttach
public int ServiceProviderId { get; set; }
/// <summary>
/// 服务商code
/// 服务商name
/// </summary>
public string ServiceProviderCode { get; set; }
public string ServiceProviderName { get; set; }
/// <summary>
/// 订单类型(主数据枚举TrackOrderType)

View File

@ -0,0 +1,34 @@
namespace SJZY.Track.Application.Contract.Dtos.TrackPull;
public class TrackRefreshContext
{
/// <summary>
/// 订单id
/// </summary>
public int OrderId { get; set; }
/// <summary>
/// 订单类型
/// </summary>
public int OrderType { get; set; }
/// <summary>
/// 订单号
/// </summary>
public string OrderNo { get; set; } = null!;
/// <summary>
/// 服务商
/// </summary>
public string ServiceProviderName { get; set; } = null!;
/// <summary>
/// 客户id
/// </summary>
public int CustomId { get; set; }
/// <summary>
/// 子系统id
/// </summary>
public int SubSystemId { get; set; }
}

View File

@ -7,11 +7,6 @@ public class EditTrackPushConfigInput
/// </summary>
public int? CustomId { get; set; }
/// <summary>
/// 推送扩展字段
/// </summary>
public string? ExpandFieldsName { get; set; }
public int? Id { get; set; }
/// <summary>
@ -39,41 +34,6 @@ public class EditTrackPushConfigInput
/// </summary>
public int? SubSystemId { get; set; }
/// <summary>
/// 推送轨迹时区
/// </summary>
public string? TrackTimeZoneName { get; set; }
/// <summary>
/// 推送轨迹内容代码
/// </summary>
public string? TrackContentCodeName { get; set; }
/// <summary>
/// 推送轨迹内容
/// </summary>
public string? TrackContentName { get; set; }
/// <summary>
/// 推送轨迹内容英文
/// </summary>
public string? TrackEnContentName { get; set; }
/// <summary>
/// 推送轨迹发生地
/// </summary>
public string? TrackPlaceName { get; set; }
/// <summary>
/// 推送轨迹状态
/// </summary>
public string? TrackStatusName { get; set; }
/// <summary>
/// 推送轨迹发生时间
/// </summary>
public string? TrackTimeName { get; set; }
/// <summary>
/// 是否支持更新
/// </summary>
@ -83,4 +43,9 @@ public class EditTrackPushConfigInput
/// 是否支持删除
/// </summary>
public bool? IsCanDelete { get; set; }
/// <summary>
/// 是否全量推送
/// </summary>
public bool? IsAllPush { get; set; }
}

View File

@ -34,6 +34,11 @@ public class EditTrackPushContentInput
/// </summary>
public int TrackContentId { get; set; }
/// <summary>
/// 可交换顺序的轨迹内容id
/// </summary>
public int? SwapTrackContentId { get; set; }
/// <summary>
/// 轨迹内容参数值
/// </summary>

View File

@ -1,6 +1,6 @@
namespace SJZY.Track.Application.Contract.Events;
namespace SJZY.Track.Application.Contract.Dtos.TrackPush;
public class TrackPushAfterUpdateOrderEvent
public class TrackPushAfterUpdateOrderDto
{
/// <summary>
/// 操作类型
@ -13,9 +13,9 @@ public class TrackPushAfterUpdateOrderEvent
public int OrderId { get; set; }
/// <summary>
/// 轨迹内容id
/// 轨迹code
/// </summary>
public int TrackContentId { get; set; }
public string TrackCode { get; set; } = null!;
/// <summary>
/// 问题类型

View File

@ -1,18 +1,5 @@
namespace SJZY.Track.Application.Contract.Dtos.TrackPush;
public class TrackPushConfigDto
{
/// <summary>
/// 是否自动推送
/// </summary>
public bool IsAutoPush { get; set; }
/// <summary>
/// 轨迹推送内容配置
/// </summary>
public List<TrackPushContentConfigDto> ContentConfigs { get; set; } = new();
}
public class TrackPushContentConfigDto
{
/// <summary>
@ -25,31 +12,41 @@ public class TrackPushContentConfigDto
/// </summary>
public bool IsCanUpdate { get; set; }
/// <summary>
/// 是否全量推送
/// </summary>
public bool IsAllPush { get; set; }
/// <summary>
/// 是否支持删除
/// </summary>
public bool IsCanDelete { get; set; }
/// <summary>
/// 服务商code
/// </summary>
public string ServiceProviderCode { get; set; } = null!;
/// <summary>
/// 扩展字段参数值
/// </summary>
public string? ExpandFieldsValue { get; set; }
/// <summary>
/// 推送单号类型(主数据枚举TrackOrderType)
/// </summary>
public int OrderType { get; set; }
/// <summary>
/// 我们系统的轨迹code
/// </summary>
public string TrackCode { get; set; } = null!;
/// <summary>
/// 可交换顺序的轨迹code
/// </summary>
public string? SwapTrackCode { get; set; }
/// <summary>
/// 轨迹代码参数值
/// </summary>
public string? TrackContentCodeValue { get; set; }
/// <summary>
/// 轨迹内容id
/// </summary>
public int TrackContentId { get; set; }
/// <summary>
/// 轨迹内容参数值
/// </summary>
@ -69,4 +66,9 @@ public class TrackPushContentConfigDto
/// 轨迹时区GMT
/// </summary>
public double? TrackTimeZone { get; set; }
/// <summary>
/// 扩展字段参数值
/// </summary>
public string? ExpandFieldsValue { get; set; }
}

View File

@ -15,5 +15,14 @@ public class OrderLinkAfterFillTrackEvent
/// <summary>
/// 关联订单
/// </summary>
public List<int> LinkedOrderIds { get; set; } = null!;
public List<LinkedOrder> 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; }
}

View File

@ -13,7 +13,7 @@ public class TrackChangeAfterUpdateOrderEvent
public bool IsDelete { get; set; }
/// <summary>
/// 这条轨迹是否意味着完成
/// 这条轨迹是否意味着完成(只有刷新会设为true)
/// </summary>
public bool IsCompleted { get; set; }

View File

@ -0,0 +1,49 @@
namespace SJZY.Track.Application.Contract.Events;
public class TrackInsertForNotMappedEvent
{
/// <summary>
/// 订单id
/// </summary>
public int OrderId { get; set; }
/// <summary>
/// 订单类型
/// </summary>
public int OrderType { get; set; }
/// <summary>
/// 订单号
/// </summary>
public string OrderNo { get; set; } = null!;
/// <summary>
/// 服务商
/// </summary>
public string ServiceProviderName { get; set; } = null!;
/// <summary>
/// 原轨迹内容
/// </summary>
public string? OriginTrackContent { get; set; }
/// <summary>
/// 原轨迹报文
/// </summary>
public string? OriginTrackData { get; set; }
/// <summary>
/// 轨迹发生地
/// </summary>
public string TrackPlace { get; set; } = null!;
/// <summary>
/// 轨迹发生时间
/// </summary>
public DateTime TrackTime { get; set; }
/// <summary>
/// 轨迹发生时区
/// </summary>
public float TrackTimeZone { get; set; }
}

View File

@ -5,12 +5,7 @@ public class TrackPushEvent
/// <summary>
/// 操作类型
/// </summary>
public OptionType OptionType { get; set; } = OptionType.新增;
/// <summary>
/// 服务商code
/// </summary>
public string ServiceProviderCode { get; set; } = null!;
public OptionType OptionType { get; set; }
/// <summary>
/// 订单id
@ -22,23 +17,13 @@ public class TrackPushEvent
/// </summary>
public string OrderNo { get; set; } = null!;
/// <summary>
/// 订单类型
/// </summary>
public int OrderType { get; set; }
/// <summary>
/// 轨迹内容id
/// </summary>
public int TrackContentId { get; set; }
/// <summary>
/// 轨迹状态
/// </summary>
public string TrackStatus { get; set; } = null!;
/// <summary>
/// 轨迹内容代码
/// 轨迹代码(我们系统的)
/// </summary>
public string TrackCode { get; set; } = null!;
@ -62,31 +47,6 @@ public class TrackPushEvent
/// </summary>
public float TrackTimeZone { get; set; }
/// <summary>
/// 轨迹代码参数值
/// </summary>
public string? TrackContentCodeValue { get; set; }
/// <summary>
/// 轨迹内容参数值
/// </summary>
public string? TrackContentValue { get; set; }
/// <summary>
/// 轨迹内容英文参数值
/// </summary>
public string? TrackEnContentValue { get; set; }
/// <summary>
/// 轨迹状态参数值
/// </summary>
public string? TrackStatusValue { get; set; }
/// <summary>
/// 扩展字段参数值
/// </summary>
public string? ExpandFieldsValue { get; set; }
/// <summary>
/// 操作人
/// </summary>

View File

@ -18,14 +18,15 @@ public class TrackUpsertEvent
public string OrderNo { get; set; } = null!;
/// <summary>
/// 订单是否完成
/// 服务商
/// </summary>
public bool IsCompleted { get; set; }
public string? ServiceProviderName { get; set; }
/// <summary>
/// 客户id
/// 表示订单是否完成(只由轨迹刷新配置决定)
/// tips:能够使得IsCompleted为true的点,全局只有一个:轨迹刷新
/// </summary>
public int CustomId { get; set; }
public bool IsCompleted { get; set; }
/// <summary>
/// 子系统id
@ -33,32 +34,17 @@ public class TrackUpsertEvent
public int SubSystemId { get; set; }
/// <summary>
/// 最新推送轨迹内容id(异步维护)
/// </summary>
public int? LatestPushTrackContentId { get; set; }
/// <summary>
/// 上游子系统id
/// 上游子系统id(0表示事件起点)
/// </summary>
public int UpSubSystemId { get; set; }
/// <summary>
/// 原轨迹内容
/// </summary>
public string? OriginTrackContent { get; set; }
/// <summary>
/// 原轨迹报文
/// </summary>
public string? OriginTrackData { get; set; }
/// <summary>
/// 操作人
/// 操作人(null则默认系统)
/// </summary>
public string? OperationMan { get; set; }
/// <summary>
/// true新增,false更新,null表示刷新引发的新增/更新
/// true新增,false更新,null表示新增/更新
/// </summary>
public bool? IsAdd { get; set; }

View File

@ -5,7 +5,7 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Version>1.0.1</Version>
<Version>7.0.0</Version>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>

View File

@ -19,7 +19,8 @@ public interface ITrackPullCacheService
/// <param name="subSystemId">子系统id</param>
/// <param name="serviceProviderId">服务商id</param>
/// <returns></returns>
Task<TrackPullParamWithContentConfigDto> GetPullParamWithContentConfigAsync(int subSystemId, int serviceProviderId);
Task<TrackPullParamWithContentConfigDto?>
GetPullParamWithContentConfigAsync(int subSystemId, int serviceProviderId);
/// <summary>
/// 设置拉取配置缓存
@ -28,6 +29,6 @@ public interface ITrackPullCacheService
/// <param name="subSystemId">子系统id</param>
/// <param name="serviceProviderId">服务商id</param>
/// <returns></returns>
Task<TrackPullParamWithContentConfigDto> SetPullConfigAsync(int? id = null, int? subSystemId = null,
Task<TrackPullParamWithContentConfigDto?> SetPullConfigAsync(int? id = null, int? subSystemId = null,
int? serviceProviderId = null);
}

View File

@ -10,26 +10,29 @@ public interface ITrackPushCacheService
/// <param name="subSystemId">子系统id</param>
/// <param name="customId">服务商id</param>
/// <returns></returns>
Task<List<TrackPushContentConfigDto>> GetPushContentConfigsAsync(int subSystemId, int customId);
Task<List<TrackPushContentConfigDto>?> GetPushContentConfigsAsync(int subSystemId, int customId);
/// <summary>
/// 获取服务商拉取配置
/// </summary>
/// <param name="subSystemId">子系统id</param>
/// <param name="customId">服务商id</param>
/// <param name="trackContentId"></param>
/// <param name="trackConde">轨迹代码</param>
/// <returns></returns>
Task<TrackPushContentConfigDto?> GetPushContentConfigAsync(int subSystemId, int customId, int trackContentId);
Task<TrackPushContentConfigDto?> GetPushContentConfigAsync(int subSystemId, int customId, string trackConde);
/// <summary>
/// 根据轨迹代码推断下一个(升序)要推送的内容,如果找不到或者已经是最后一个了,返回null
/// 根据轨迹代码推断下一个(升序)要推送的内容,如果找不到或者已经是最后一个了
/// 则查询有没有可交换的推送,没有就返回null
/// </summary>
/// <param name="subSystemId"></param>
/// <param name="customId"></param>
/// <param name="trackContentId"></param>
/// <param name="latestPushTrackCode"></param>
/// <param name="trackCode"></param>
/// <returns></returns>
Task<TrackPushContentConfigDto?> InferNextPushContentOrNullAsync(int subSystemId, int customId,
int? trackContentId);
Task<TrackPushContentConfigDto?> IsValidPushAsync(int subSystemId, int customId,
string? latestPushTrackCode,
string? trackCode);
/// <summary>
/// 设置推送配置缓存
@ -38,5 +41,6 @@ public interface ITrackPushCacheService
/// <param name="subSystemId">子系统id</param>
/// <param name="customId">客户id</param>
/// <returns></returns>
Task<TrackPushConfigDto> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null);
Task<List<TrackPushContentConfigDto>?> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null,
int? customId = null);
}

View File

@ -10,21 +10,21 @@ public interface ITrackService : IRemoteService
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task<bool> UpsertTrackAsync(UpsertTrackInput input);
Task<UnifyResultDto> UpsertTrackAsync(UpsertTrackInput input);
/// <summary>
/// 删除轨迹
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task<bool> DeleteTrackAsync(DeleteTrackInput input);
Task<UnifyResultDto> DeleteTrackAsync(DeleteTrackInput input);
/// <summary>
/// 批量删除轨迹
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task<bool> BatchDeleteTrackAsync(BatchDeleteTrackInput input);
Task<UnifyResultDto> BatchDeleteTrackAsync(BatchDeleteTrackInput input);
/// <summary>
/// 根据订单号获取轨迹

View File

@ -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<GetPageTrackOrderInput, GetPageTrackOrderInputVO>(MemberList.None);
CreateMap<TrackOrderVO, TrackOrderDto>(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<TrackOrderVO>, UnifyPageResultDto<TrackOrderDto>>(MemberList.None);
CreateMap<TrackDetailsIndex, TrackOrderDetailDto>(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;

View File

@ -9,8 +9,7 @@ namespace SJZY.Track.Application.AutoMapper
{
public TrackContentAutoMapperProfile()
{
CreateMap<EditTrackContentInput, TrackContentEntity>(MemberList.None)
.ForMember(dest => dest.IsCompleted, opt => opt.MapFrom(source => source.IsFinish));
CreateMap<EditTrackContentInput, TrackContentEntity>(MemberList.None);
CreateMap<GetTrackContentDetailVO, GetTrackContentDetailDto>(MemberList.None);
CreateMap<GetPageTrackContentInput, GetPageTrackContentVO>(MemberList.None);
CreateMap<GetTrackContentListVO, GetTrackContentListDto>(MemberList.None);

View File

@ -3,12 +3,13 @@ using DotNetCore.CAP.Filter;
using SJZY.Expand.ABP.Core;
using SJZY.Expand.ABP.Core.Logger;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Track.Domain.Consts;
namespace SJZY.Track.Application.EventHandlers;
public class CAPFilter : SubscribeFilter
public class CapFilter : SubscribeFilter
{
const string _ERROR_CODE = "Error599";
const string ErrorCode = "Error599";
/// <summary>
/// 执行前
@ -17,9 +18,13 @@ public class CAPFilter : SubscribeFilter
/// <returns></returns>
public override Task OnSubscribeExecutingAsync(ExecutingContext context)
{
var argumentJsonStr = context.Arguments.ToJson();
context.DeliverMessage.Headers["sjzy-receive-time"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff");
// 轨迹刷新不做幂等
if (context.DeliverMessage.Headers["cap-msg-name"]!.EndsWith(GlobalConst.TrackRefreshSubscribe))
return Task.CompletedTask;
var argumentJsonStr = context.Arguments.ToJson();
context.DeliverMessage.Headers["sjzy-arguments"] = argumentJsonStr;
if (!string.IsNullOrEmpty(argumentJsonStr))
@ -29,7 +34,7 @@ public class CAPFilter : SubscribeFilter
{
var isSkip = !string.IsNullOrEmpty(RedisHelper.Client.Get($"CapExcuteFilter:{hash}"));
if (isSkip)
throw new BusinessException(_ERROR_CODE, $"检测到重复消费,消费参数:{argumentJsonStr}");
throw new BusinessException(ErrorCode, $"检测到重复消费,消费参数:{argumentJsonStr}");
RedisHelper.Client.Set($"CapExcuteFilter:{hash}", 60 * 10,
TimeSpan.FromHours(1).Seconds); // 1h内不允许一模一样的参数重复消费
@ -51,7 +56,7 @@ public class CAPFilter : SubscribeFilter
context.DeliverMessage.Headers.TryGetValue("sjzy-arguments", out var arguments);
context.DeliverMessage.Headers.TryGetValue("cap-msg-id", out var messageId);
BuildLog(receiveTime, receiveName, arguments, false, messageId);
BuildLog(receiveTime!, receiveName!, arguments!, false, messageId!);
return Task.CompletedTask;
}
@ -67,7 +72,7 @@ public class CAPFilter : SubscribeFilter
context.ExceptionHandled = true;
context.DeliverMessage.Headers.TryGetValue("cap-msg-id", out var messageId);
if (context.Exception is BusinessException ex && ex.Code == _ERROR_CODE)
if (context.Exception is BusinessException ex && ex.Code == ErrorCode)
LogHelper.Warn(ex.ToString());
else
LogHelper.Error($"cap-msg-id:{messageId}\n{context.Exception}");
@ -77,13 +82,13 @@ public class CAPFilter : SubscribeFilter
context.DeliverMessage.Headers.TryGetValue("cap-msg-name", out var receiveName);
context.DeliverMessage.Headers.TryGetValue("sjzy-arguments", out var arguments);
BuildLog(receiveTime, receiveName, arguments, true, messageId);
BuildLog(receiveTime!, receiveName!, arguments, true, messageId!);
return Task.CompletedTask;
}
private void BuildLog(string receiveTime, string receiveName, string arguments, bool isFromExecptionFliter,
private void BuildLog(string receiveTime, string receiveName, string? arguments, bool isFromExecptionFliter,
string messageId)
{
var parsedDate = DateTime.ParseExact(receiveTime, "yyyy-MM-dd HH:mm:ss fff", CultureInfo.InvariantCulture);

View File

@ -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,
};

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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
});
}
}

View File

@ -1,8 +1,14 @@
using DotNetCore.CAP;
using Newtonsoft.Json.Linq;
using SJZY.Expand.ABP.Core.PublicMethords;
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,106 +18,175 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
{
private readonly IHttpClientProxy<IInterfaceForwardServiceV2> _httpClientProxy;
private readonly ITrackPushRecordsRepository _trackPushRecordsRepository;
private readonly ICapPublisher _capPublisher;
private readonly IOrderRepository _orderRepository;
private readonly ITrackPushCacheService _trackPushCacheService;
public TrackPushEventHandler(IHttpClientProxy<IInterfaceForwardServiceV2> 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!;
switch (@event.OptionType)
var order = await _orderRepository.GetFirstAsync(x =>
x.Id == @event.OrderId, x => new
{
case OptionType.无:
return;
case OptionType.新增:
res = await PushAddAsync(@event);
break;
case OptionType.删除:
break;
case OptionType.修改:
res = await PushUpdateAsync(@event);
break;
default:
throw new ArgumentOutOfRangeException();
}
x.SubSystemId, x.LatestPushTrackCode, x.CustomId
});
if (order == null) return;
var isSuccess = res.Code == InterfaceRelayConst.SuccessCode;
TrackPushContentConfigDto? config = null;
// 往es 写推送日志
await _trackPushRecordsRepository.AddAsync(new TrackPushRecordIndex
var log = new TrackPushRecordIndex
{
IndexName = $"{GlobalConst.TrackPushRecordsIndex}-{DateTime.Now:yyyy.MM.dd}",
RequestId = res.RequestId,
Message = res.Msg,
OptionType = @event.OptionType.ToString(),
OrderId = @event.OrderId,
OrderType = @event.OrderType,
OrderNo = @event.OrderNo,
TrackStatus = @event.TrackStatus,
TrackCode = @event.TrackCode,
TrackContent = @event.TrackContent,
TrackPlace = @event.TrackPlace,
TrackTime = @event.TrackTime,
TrackTimeZone = @event.TrackTimeZone,
TrackContentCodeValue = @event.TrackContentCodeValue,
TrackContentValue = @event.TrackContentValue,
TrackEnContentValue = @event.TrackEnContentValue,
TrackStatusValue = @event.TrackStatusValue,
ExpandFieldsValue = @event.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
});
}
private async Task<InterfaceRelayUnifyResultDto> PushAddAsync(TrackPushEvent @event)
{
var data = new
{
orderNo = @event.OrderNo,
data = new[]
{
new
{
// 推真实的发生地和发生时间(时间是计算后的)
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
}
}
};
var allPush = false;
switch (@event.OptionType)
{
case OptionType.无:
return;
case OptionType.新增:
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 is { IsAllPush: true })
{
}
}
var res = await _httpClientProxy.Service.ForwardWithSubscribeAsync(InterfaceRelayConst.PushTrackInterfaceCode,
@event.ServiceProviderCode, data);
if (config == null) return;
await DoAddAsync(@event, config, log, allPush);
break;
case OptionType.删除:
break;
case OptionType.修改:
config = await _trackPushCacheService.GetPushContentConfigAsync(order.SubSystemId, order.CustomId,
@event.TrackCode);
if (config == null || !config.IsCanUpdate) return;
await DoUpdateAsync(@event, config, log);
break;
default:
throw new ArgumentOutOfRangeException();
}
return res;
if (config == null) return;
// 往es 写推送日志
await _trackPushRecordsRepository.AddAsync(log);
// 同步去更新订单主表
await TrackPushAfterUpdateOrderAsync(new TrackPushAfterUpdateOrderDto
{
OptionType = @event.OptionType,
OrderId = @event.OrderId,
TrackCode = @event.TrackCode,
IsSuccess = log.IsSuccess,
Message = res.Msg
});
}
private async Task<InterfaceRelayUnifyResultDto> PushUpdateAsync(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, TrackPushRecordIndex log, bool allPush)
{
var track = new
{
// 推真实的发生地和发生时间(时间是计算后的)
location = @event.TrackPlace,
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
};
JObject body = JObject.FromObject(new
{
orderNo = @event.OrderNo,
data = new[] { track }
});
if (allPush)
{
var history = await _trackPushRecordsRepository.GetLatestTrackPushRecordAsync(@event.OrderId);
if (history != default)
{
body = JObject.Parse(history.PushContent);
((JArray)body["data"]!).Add(track);
}
}
var res = await _httpClientProxy.Service.ForwardWithSubscribeAsync(InterfaceRelayConst.PushTrackInterfaceCode,
config.ServiceProviderCode, body);
log.PushContent = body.ToJson();
log.IsSuccess = res.Code == InterfaceRelayConst.SuccessCode;
}
private async Task DoUpdateAsync(TrackPushEvent @event,
TrackPushContentConfigDto config, TrackPushRecordIndex log)
{
var data = new
{
@ -122,21 +197,23 @@ 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;
log.PushContent = data.ToJson();
log.IsSuccess = res.Code == InterfaceRelayConst.SuccessCode;
}
}

View File

@ -3,11 +3,11 @@ 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;
using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Application.Helpers;
using SJZY.Track.Domain.Aggregates.OrderAggregate;
using SJZY.Track.Domain.Consts;
using SJZY.Track.Domain.Enums;
@ -32,70 +32,72 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
[CapSubscribe(GlobalConst.TrackRefreshSubscribe, Group = GlobalConst.TrackRefreshSubscribe)]
public async Task ConsumerAsync(InterfaceRelayForwardReplayEvent @event)
{
var attach = JsonConvert.DeserializeObject<TrackRefreshAttach>(@event.Attach);
var attach = Base64Helper.DeSerialize<TrackRefreshAttach>(@event.Attach);
if (attach is null) return;
var config = await _trackPullCacheService.GetPullParamWithContentConfigAsync(attach.SubSystemId,
attach.ServiceProviderId);
if (@event.Data == null || config == null) return;
var data = JObject.Parse(@event.Data.ToString()!);
var data = JObject.Parse(@event.Data);
var orderToken = data[config.ParamConfig.OrderPath];
if (orderToken is JArray orderTokens)
{
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<string>();
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;
@ -124,7 +126,6 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
var trackContent = trackToken[paramConfig.TrackContentName]?.Value<string>();
if (!trackContent.IsNullOrWhiteSpace())
{
trackUpsertEvent.OriginTrackContent = trackContent;
Debug.Assert(trackContent != null, nameof(trackContent) + " != null");
matchedContentConfig = contentConfigs.FirstOrDefault(x => x.TrackContentValue == trackContent);
@ -158,8 +159,6 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
}
}
if (matchedContentConfig is null) return;
// 轨迹发生地
var trackPlace = paramConfig.TrackPlaceName == null
? null
@ -178,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);
}
// 轨迹发生时间
@ -190,11 +189,42 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
? null
: trackToken[paramConfig.TrackTimeZoneName]?.Value<float>();
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<string>();
}
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);
}
}

View File

@ -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)]
@ -40,7 +35,6 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
return;
}
var isUnProcessed = false;
// 不同子系统需要做内容映射
if (@event.UpSubSystemId != 0 && @event.UpSubSystemId != @event.SubSystemId)
{
@ -57,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; // 存在不让创建
@ -72,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,
@ -97,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);
}
@ -127,55 +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 = new TrackDetailsIndex
{
TrackStatus = trackContent.Status,
TrackContent = trackContent.Content,
TrackContentId = trackContent.Id,
IsCompleted = trackContent.IsCompleted,
TrackEnContent = trackContent.EnContent,
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;
}
@ -183,60 +165,4 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
return track;
}
/// <summary>
/// 处理轨迹自动推送
/// </summary>
/// <param name="event"></param>
/// <param name="track"></param>
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);
}
}

View File

@ -0,0 +1,33 @@
using System.Text;
using Newtonsoft.Json;
namespace SJZY.Track.Application.Helpers;
public class Base64Helper
{
/// <summary>
/// json序列化base64
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static string SerializeObject(object obj)
{
var json = JsonConvert.SerializeObject(obj);
var bytes = Encoding.UTF8.GetBytes(json);
return Convert.ToBase64String(bytes);
}
/// <summary>
/// json反序列化base64
/// </summary>
/// <param name="json"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static T? DeSerialize<T>(string json)
{
byte[] bytes = Convert.FromBase64String(json);
return JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(bytes));
}
}

View File

@ -12,7 +12,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SJZY.InterfaceRelay.Application.Contracts" Version="7.1.6" />
<PackageReference Include="SJZY.InterfaceRelay.Application.Contracts" Version="7.1.8"/>
<PackageReference Include="Volo.Abp.Http.Client" Version="7.0.2" />
<PackageReference Include="Volo.Abp.FluentValidation" Version="7.0.2" />
<PackageReference Include="SJZY.UserCenter.HttpApi" Version="3.0.3-alpha8" />

View File

@ -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);
return new UnifyResultDto(true, true);
}
private async Task<List<int>> DoLinkOrderAsync(LinkOrderInput input, int orderId)
private async Task<List<LinkedOrder>> 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<int>();
if (canLinkOrders.Count == 0) return new List<LinkedOrder>();
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<UnifyResultDto> UnLinkOrderAsync(LinkOrderInput input)
@ -108,6 +114,6 @@ public partial class OrderService
// real del
await _orderRepository.UnLinkByIdsAsync(unLinkIds);
return new UnifyResultDto(true);
return new UnifyResultDto(true, true);
}
}

View File

@ -70,7 +70,7 @@ public partial class OrderService : ApplicationService, IOrderService
await _orderRepository.DeleteOrderAsync(orderId);
return new UnifyResultDto(true);
return new UnifyResultDto(true, true);
}
private async Task UpdateOrderAsync(UpdateOrderInput input, OrderEntity order)

View File

@ -1,10 +1,10 @@
using Microsoft.AspNetCore.Authorization;
using Newtonsoft.Json;
using SJZY.Expand.ABP.Core;
using SJZY.InterfaceRelay.Application.Contracts;
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
using SJZY.Track.Application.Contract.Dtos.TrackPull;
using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Application.Helpers;
using SJZY.Track.Domain.Consts;
using SJZY.Track.Domain.Queries;
using Volo.Abp.Http.Client.DynamicProxying;
@ -51,18 +51,21 @@ public class TrackPullService : ApplicationService
throw new BusinessException(message: "一个能更新的都没有");
}
foreach (var group in orders.GroupBy(x =>
new TrackRefreshAttach(x.ServiceProviderId, x.ServiceProviderCode, x.SubSystemId, x.OrderType)))
foreach (var group in orders.GroupBy(x => new
{ x.ServiceProviderId, x.ServiceProviderName, x.SubSystemId, x.OrderType }))
{
var data = group.Select(x => new
{
x.OrderNo
}).ToList();
var serviceProviderCode = group.FirstOrDefault()!.ServiceProviderCode;
var attach = Base64Helper.SerializeObject(group.Key);
// 批量获取轨迹
await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
"A012", group.Key.ServiceProviderCode, data,
GlobalConst.TrackRefreshSubscribe, JsonConvert.SerializeObject(group.Key));
"A012", serviceProviderCode, data, GlobalConst.TrackRefreshSubscribe, attach);
}
return true;
@ -87,6 +90,7 @@ public class TrackPullService : ApplicationService
var orders = await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId);
var serviceProviderCode = orders.FirstOrDefault()?.ServiceProviderCode;
var serviceProviderName = orders.FirstOrDefault()?.ServiceProviderName;
foreach (var group in orders.GroupBy(x =>
new { x.SubSystemId, x.OrderType }))
@ -96,12 +100,13 @@ public class TrackPullService : ApplicationService
x.OrderNo
}).ToList();
var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(config.ServiceProviderId,
serviceProviderName!,
group.Key.SubSystemId, group.Key.OrderType));
// 批量获取轨迹
await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data,
GlobalConst.TrackRefreshSubscribe,
JsonConvert.SerializeObject(new TrackRefreshAttach(config.ServiceProviderId, serviceProviderCode!,
group.Key.SubSystemId, group.Key.OrderType)));
GlobalConst.TrackRefreshSubscribe, attach);
}
if (config.PullInterval < 60) config.PullInterval = 60;

View File

@ -2,12 +2,10 @@
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;
using SJZY.Track.Domain.Consts;
using SJZY.Track.Domain.Enums;
using SJZY.UserCenter.HttpApi.Services;
namespace SJZY.Track.Application.Services.ProvideServices;
@ -21,17 +19,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 +63,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,
};
@ -120,20 +96,9 @@ public class TrackPushService : ApplicationService
[HttpPost("Track/PushWarnForTask")]
public async Task<string> PushWarnForTaskAsync()
{
var orders = await _orderRepository.GetPushWarnOrdersAsync();
var time = DateTime.Now.Subtract(TimeSpan.FromHours(12));
orders.ForEach(x =>
{
x.QuestionType = x.LatestPushTime == null || x.LatestPushTime < time
? (int)TrackProblemType.Warn
: (int)TrackProblemType.None;
});
await _orderRepository.UpdateRangeAsync(orders, x => new { x.QuestionType });
return $"成功将:{orders.Count(x => x.QuestionType == (int)TrackProblemType.Warn)}个订单置为预警";
// todo:订单数据上来后一次性update是否会引发长时间X独占?
var count = await _orderRepository.PushWarnOrdersAsync();
return $"本次预警扫描了:{count}个订单";
}
/// <summary>
@ -144,6 +109,13 @@ public class TrackPushService : ApplicationService
[HttpGet("Track/GetTrackPushRecords")]
public async Task<List<TrackPushRecordIndex>> GetTrackPushRecordsAsync(OrderNoInfo input)
{
return await _trackPushRecordsRepository.GetTrackPushRecordsAsync(input.OrderNo, input.OrderType);
var orderId = await _orderRepository.GetFirstAsync(x =>
x.OrderType == input.OrderType && input.OrderNo == x.OrderNo, x => x.Id);
if (orderId == default)
{
throw new BusinessException(message: "订单不存在");
}
return await _trackPushRecordsRepository.GetTrackPushRecordsAsync(orderId);
}
}

View File

@ -38,12 +38,12 @@ public partial class TrackService : ApplicationService, ITrackService
/// <returns></returns>
/// <exception cref="BusinessException"></exception>
[HttpPost("Track/Upsert")]
public async Task<bool> UpsertTrackAsync(UpsertTrackInput input)
public async Task<UnifyResultDto> UpsertTrackAsync(UpsertTrackInput input)
{
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)
{
@ -54,12 +54,9 @@ public partial class TrackService : ApplicationService, ITrackService
var @event = ObjectMapper.Map<UpsertTrackInput, TrackUpsertEvent>(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 true;
return new UnifyResultDto(true, true);
}
/// <summary>
@ -69,7 +66,7 @@ public partial class TrackService : ApplicationService, ITrackService
/// <returns></returns>
/// <exception cref="BusinessException"></exception>
[HttpPost("Track/BatchUpsert")]
public async Task<bool> BatchUpsertTrackAsync(BatchUpsertTrackInput input)
public async Task<UnifyResultDto> BatchUpsertTrackAsync(BatchUpsertTrackInput input)
{
input.OrderNos = input.OrderNos.Where(x => !x.IsNullOrWhiteSpace()).Distinct().ToList(); // 单号去重、去空
if (input.OrderNos.Count == 0)
@ -80,7 +77,7 @@ public partial class TrackService : ApplicationService, ITrackService
var orders = await _orderRepository.GetListAsync(x =>
x.OrderType == input.OrderType && input.OrderNos.Contains(x.OrderNo), x => new
{
x.Id, x.OrderNo, x.SubSystemId, x.LatestPushTrackContentId, x.CustomId, x.IsCompleted
x.Id, x.OrderNo, x.SubSystemId
});
foreach (var order in orders)
@ -97,15 +94,12 @@ 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);
}
return true;
return new UnifyResultDto(true, true);
}
/// <summary>
@ -115,12 +109,13 @@ public partial class TrackService : ApplicationService, ITrackService
/// <returns></returns>
/// <exception cref="BusinessException"></exception>
[HttpPost("Track/Delete")]
public async Task<bool> DeleteTrackAsync(DeleteTrackInput input)
public async Task<UnifyResultDto> DeleteTrackAsync(DeleteTrackInput input)
{
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)
{
@ -144,7 +139,7 @@ public partial class TrackService : ApplicationService, ITrackService
};
await _capPublisher.PublishAsync(GlobalConst.TrackDeleteSubscribe, @event);
return true;
return new UnifyResultDto(true, true);
}
/// <summary>
@ -154,13 +149,14 @@ public partial class TrackService : ApplicationService, ITrackService
/// <returns></returns>
/// <exception cref="BusinessException"></exception>
[HttpPost("Track/BatchDelete")]
public async Task<bool> BatchDeleteTrackAsync(BatchDeleteTrackInput input)
public async Task<UnifyResultDto> BatchDeleteTrackAsync(BatchDeleteTrackInput input)
{
var orders = await _orderRepository.GetListAsync(x =>
x.OrderType == input.OrderType && input.OrderNos.Contains(x.OrderNo)
, x => new
{
x.Id, x.SubSystemId
x.Id,
x.SubSystemId
});
var codes = await _provideQueries.GetCanDeleteTrackCodesAsync(
@ -185,6 +181,6 @@ public partial class TrackService : ApplicationService, ITrackService
await _capPublisher.PublishAsync(GlobalConst.TrackDeleteSubscribe, @event);
}
return true;
return new UnifyResultDto(true, true);
}
}

View File

@ -1,297 +1,296 @@
using Microsoft.Extensions.Localization;
using System.Linq.Expressions;
using Microsoft.Extensions.Localization;
using SJZY.Expand.ABP.Core.Localization;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Track.Application.Contract.Dtos.TrackContents;
using SJZY.Track.Application.Localization;
using SJZY.Track.Domain.Aggregates.TrackContentAggregate;
using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate;
using SJZY.Track.Domain.Dtos.TrackContents;
using SJZY.Track.Domain.Queries;
using System.Linq.Expressions;
using Volo.Abp.DependencyInjection;
namespace SJZY.Track.Application.Services.TrackContents
namespace SJZY.Track.Application.Services.TrackContents;
/// <summary>
/// 轨迹内容服务
/// </summary>
[ApiExplorerSettings(GroupName = "轨迹内容")]
[Route("/Track/Content")]
public class TrackContentService : ApplicationService
{
/// <summary>
/// 轨迹内容服务
/// </summary>
[ApiExplorerSettings(GroupName = "轨迹内容")]
[Route("/Track/Content")]
public class TrackContentService : ApplicationService, ITransientDependency
private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer;
private readonly ITrackContentRepository _trackContentRepository;
public TrackContentService(
IStringLocalizer<TrackLocalizationResource> stringLocalizer,
ITrackContentRepository trackContentRepository
)
{
private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer;
private readonly ITrackContentRepository _trackContentRepository;
private readonly IBasicQuery<TrackContentMapEntity> _trackContentMapBasicQuery;
private readonly IBasicQuery<TrackTemplateContentEntity> _trackTemplateContentBasicQuery;
_stringLocalizer = stringLocalizer;
_trackContentRepository = trackContentRepository;
}
public TrackContentService(
IStringLocalizer<TrackLocalizationResource> stringLocalizer,
ITrackContentRepository trackContentRepository,
IBasicQuery<TrackContentMapEntity> trackContentMapBasicQuery,
IBasicQuery<TrackTemplateContentEntity> trackTemplateContentBasicQuery
)
/// <summary>
/// 轨迹内容编辑
/// </summary>
/// <returns></returns>
[HttpPost("Edit")]
public async Task<UnifyResultDto> EditAsync(EditTrackContentInput input)
{
return input.Options switch
{
this._stringLocalizer = stringLocalizer;
this._trackContentRepository = trackContentRepository;
this._trackContentMapBasicQuery = trackContentMapBasicQuery;
this._trackTemplateContentBasicQuery = trackTemplateContentBasicQuery;
OptionType.新增 => await AddAsync(input),
OptionType.修改 => await UpdateAsync(input),
OptionType.删除 => await DeleteAsync(input),
_ => throw new BusinessException(message: "当前操作动作不合法")
};
}
/// <summary>
/// 根据内容id获取轨迹内容
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("GetDetail")]
public async Task<UnifyResultDto<GetTrackContentDetailDto>> GetDetailAsync(int id)
{
var detailInfo = await _trackContentRepository.GetDetailAsync(id);
if (detailInfo == null)
{
return new UnifyResultDto<GetTrackContentDetailDto>(false, null!, "未查询到轨迹状态");
}
/// <summary>
/// 轨迹内容编辑
/// </summary>
/// <returns></returns>
[HttpPost("Edit")]
public async Task<UnifyResultDto> EditAsync(EditTrackContentInput input)
{
return input.Options switch
{
OptionType.新增 => await AddAsync(input),
OptionType.修改 => await UpdateAsync(input),
OptionType.删除 => await DeleteAsync(input),
_ => throw new BusinessException(message: "当前操作动作不合法")
};
}
var dto = ObjectMapper.Map<GetTrackContentDetailVO, GetTrackContentDetailDto>(detailInfo);
return new UnifyResultDto<GetTrackContentDetailDto>("200", "", dto);
}
/// <summary>
/// 根据内容id获取轨迹内容
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("GetDetail")]
public async Task<UnifyResultDto<GetTrackContentDetailDto>> GetDetailAsync(int id)
/// <summary>
/// 获取分页轨迹内容
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("GetList")]
public async Task<UnifyPageResultDto<GetTrackContentListDto>> GetPageTrackContent(
GetPageTrackContentInput input)
{
var vo = ObjectMapper.Map<GetPageTrackContentInput, GetPageTrackContentVO>(input);
var resultDto = await _trackContentRepository.GetPageTrackContent(vo);
var pageResultDto =
ObjectMapper.Map<UnifyPageResultDto<GetTrackContentListVO>, UnifyPageResultDto<GetTrackContentListDto>>(
resultDto);
return pageResultDto;
}
#region 私有方法
private async Task<UnifyResultDto> AddAsync(EditTrackContentInput input)
{
#region 业务逻辑校验
var trackContentEntitys = await _trackContentRepository.GetListAsync(a =>
a.SubSystemId == input.SubSystemId && (a.Code == input.Code ||
a.Content == input.Content || a.EnContent == input.EnContent));
if (trackContentEntitys.Any())
{
var detailInfo = await _trackContentRepository.GetDetailAsync(id);
if (detailInfo == null)
//throw new BusinessException(message: _stringLocalizer["TrackContentExist"]);
var codes = trackContentEntitys.FirstOrDefault(a => a.Code == input.Code);
if (codes != null)
{
return new UnifyResultDto<GetTrackContentDetailDto>(false, null!, "未查询到轨迹状态");
throw new BusinessException(message: "该子系统下轨迹代码已存在");
}
var dto = ObjectMapper.Map<GetTrackContentDetailVO, GetTrackContentDetailDto>(detailInfo);
return new UnifyResultDto<GetTrackContentDetailDto>("200", "", dto);
}
/// <summary>
/// 获取分页轨迹内容
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("GetList")]
public async Task<UnifyPageResultDto<GetTrackContentListDto>> GetPageTrackContent(
GetPageTrackContentInput input)
{
var vo = ObjectMapper.Map<GetPageTrackContentInput, GetPageTrackContentVO>(input);
var resultDto = await _trackContentRepository.GetPageTrackContent(vo);
var pageResultDto =
ObjectMapper.Map<UnifyPageResultDto<GetTrackContentListVO>, UnifyPageResultDto<GetTrackContentListDto>>(
resultDto);
return pageResultDto;
}
#region 私有方法
private async Task<UnifyResultDto> AddAsync(EditTrackContentInput input)
{
#region 业务逻辑校验
var trackContentEntitys = await _trackContentRepository.GetListAsync(a =>
a.SubSystemId == input.SubSystemId && (a.Code == input.Code ||
a.Content == input.Content || a.EnContent == input.EnContent));
if (trackContentEntitys.Any())
var contents = trackContentEntitys.FirstOrDefault(a => a.Content == input.Content);
if (contents != null)
{
//throw new BusinessException(message: _stringLocalizer["TrackContentExist"]);
var codes = trackContentEntitys.FirstOrDefault(a => a.Code == input.Code);
if (codes != null)
{
throw new BusinessException(message: "该子系统下轨迹代码已存在");
}
var contents = trackContentEntitys.FirstOrDefault(a => a.Content == input.Content);
if (contents != null)
{
throw new BusinessException(message: "该子系统下轨迹内容已存在");
}
var contentEns = trackContentEntitys.FirstOrDefault(a => a.EnContent == input.EnContent);
if (contentEns != null)
{
throw new BusinessException(message: "该子系统下轨迹内容英文已存在");
}
//throw new BusinessException(message: "当前子系统下,轨迹代码或轨迹内容或轨迹内容英文存在");
throw new BusinessException(message: "该子系统下轨迹内容已存在");
}
#endregion 业务逻辑校验
var entity = ObjectMapper.Map<EditTrackContentInput, TrackContentEntity>(input);
var isTrue = await _trackContentRepository.InsertAsync(entity);
return new UnifyResultDto("200", "新增成功", isTrue);
var contentEns = trackContentEntitys.FirstOrDefault(a => a.EnContent == input.EnContent);
if (contentEns != null)
{
throw new BusinessException(message: "该子系统下轨迹内容英文已存在");
}
//throw new BusinessException(message: "当前子系统下,轨迹代码或轨迹内容或轨迹内容英文存在");
}
private async Task<UnifyResultDto> UpdateAsync(EditTrackContentInput input)
{
#region 业务逻辑校验
#endregion 业务逻辑校验
var trackContentEntitys = await _trackContentRepository.GetListAsync(a => a.Id != input.Id &&
a.SubSystemId == input.SubSystemId && (a.Code == input.Code ||
a.Content == input.Content || a.EnContent == input.EnContent));
if (trackContentEntitys.Any())
var entity = ObjectMapper.Map<EditTrackContentInput, TrackContentEntity>(input);
var isTrue = await _trackContentRepository.InsertAsync(entity);
return new UnifyResultDto("200", "新增成功", isTrue);
}
private async Task<UnifyResultDto> UpdateAsync(EditTrackContentInput input)
{
#region 业务逻辑校验
var trackContentEntitys = await _trackContentRepository.GetListAsync(a => a.Id != input.Id &&
a.SubSystemId == input.SubSystemId && (a.Code == input.Code ||
a.Content == input.Content || a.EnContent == input.EnContent));
if (trackContentEntitys.Any())
{
//throw new BusinessException(message: _stringLocalizer["TrackContentExist"]);
//throw new BusinessException(message: "当前子系统下,轨迹代码或轨迹内容或轨迹内容英文存在");
var codes = trackContentEntitys.FirstOrDefault(a => a.Code == input.Code);
if (codes != null)
{
//throw new BusinessException(message: _stringLocalizer["TrackContentExist"]);
//throw new BusinessException(message: "当前子系统下,轨迹代码或轨迹内容或轨迹内容英文存在");
var codes = trackContentEntitys.FirstOrDefault(a => a.Code == input.Code);
if (codes != null)
throw new BusinessException(message: "该子系统下轨迹代码已存在");
}
var contents = trackContentEntitys.FirstOrDefault(a => a.Content == input.Content);
if (contents != null)
{
throw new BusinessException(message: "该子系统下轨迹内容已存在");
}
var contentEns = trackContentEntitys.FirstOrDefault(a => a.EnContent == input.EnContent);
if (contentEns != null)
{
throw new BusinessException(message: "该子系统下轨迹内容英文已存在");
}
}
#endregion 业务逻辑校验
//更新的时候需要覆盖内容映射轨迹代码
var templateEntity = await _trackContentRepository.GetFirstAsync(a => a.Id == input.Id);
bool isTrue;
using (var ts = TransactionScopeHelper.Create())
{
// 如果轨迹内容的子系统和code发生变化,同步到轨迹映射表
if (templateEntity.SubSystemId != input.SubSystemId || templateEntity.Code != input.Code)
{
await _trackContentRepository.UpdateMapAsync(x => new TrackContentMapEntity
{
throw new BusinessException(message: "该子系统下轨迹代码已存在");
}
var contents = trackContentEntitys.FirstOrDefault(a => a.Content == input.Content);
if (contents != null)
SubSystemId = input.SubSystemId,
TrackContentCode = input.Code
}, x => x.TrackContentId == input.Id);
await _trackContentRepository.UpdateMapAsync(x => new TrackContentMapEntity
{
throw new BusinessException(message: "该子系统下轨迹内容已存在");
}
var contentEns = trackContentEntitys.FirstOrDefault(a => a.EnContent == input.EnContent);
if (contentEns != null)
{
throw new BusinessException(message: "该子系统下轨迹内容英文已存在");
}
MapSubSystemId = input.SubSystemId,
MapTrackContentCode = input.Code
}, x => x.MapTrackContentId == input.Id);
}
#endregion 业务逻辑校验
ObjectMapper.Map(input, templateEntity);
//更新的时候需要覆盖内容映射轨迹代码
var templateEntity = await _trackContentRepository.GetFirstAsync(a => a.Id == input.Id);
isTrue = await _trackContentRepository.UpdateAsync(templateEntity);
bool isTrue = false;
using (var ts = TransactionScopeHelper.Create())
{
// 如果轨迹内容的子系统和code发生变化,同步到轨迹映射表
if (templateEntity.SubSystemId != input.SubSystemId || templateEntity.Code != input.Code)
{
await _trackContentRepository.UpdateMapAsync(x => new TrackContentMapEntity
{
SubSystemId = input.SubSystemId,
TrackContentCode = input.Code
}, x => x.TrackContentId == input.Id);
await _trackContentRepository.UpdateMapAsync(x => new TrackContentMapEntity
{
MapSubSystemId = input.SubSystemId,
MapTrackContentCode = input.Code
}, x => x.MapTrackContentId == input.Id);
}
ObjectMapper.Map(input, templateEntity);
isTrue = await _trackContentRepository.UpdateAsync(templateEntity);
ts.Complete();
}
return new UnifyResultDto("200", "修改成功", isTrue);
ts.Complete();
}
private async Task<UnifyResultDto> DeleteAsync(EditTrackContentInput input)
return new UnifyResultDto("200", "修改成功", isTrue);
}
private async Task<UnifyResultDto> DeleteAsync(EditTrackContentInput input)
{
#region 业务校验
//查询是否关联了轨迹模版内容
var isExistTemplate = await _trackContentRepository.GetTemplateIsExist(input.Id);
if (isExistTemplate)
{
#region 业务校验
//查询是否关联了轨迹模版内容
var isExistTemplate = await _trackContentRepository.GetTemplateIsExist(input.Id);
if (isExistTemplate)
{
throw new BusinessException(message: "该轨迹内容关联轨迹模板,禁止删除");
}
//var trackTemplateContents = await _trackTemplateContentBasicQuery.GetListAsync(a => a.TrackContentId == input.Id);
//if (trackTemplateContents.Any())
//{
// throw new BusinessException(message: "该轨迹内容关联轨迹模板,禁止删除");
//}
//需要加个判断,存在内容映射,则出提示
//var trackContentMapEntities = await _trackContentMapBasicQuery.GetListAsync(a => a.TrackContentId == input.Id || a.MapTrackContentId == input.Id);
//if (trackContentMapEntities.Any())
//{
// throw new BusinessException(message: "无法删除该内容,该轨迹内容已在轨迹内容映射中使用了,请检查");
//}
#endregion 业务校验
var isTrue = await _trackContentRepository.SoftDeleteAsync(x => x.Id == input.Id);
return new UnifyResultDto("200", "删除成功", isTrue);
throw new BusinessException(message: "该轨迹内容关联轨迹模板,禁止删除");
}
//var trackTemplateContents = await _trackTemplateContentBasicQuery.GetListAsync(a => a.TrackContentId == input.Id);
//if (trackTemplateContents.Any())
//{
// throw new BusinessException(message: "该轨迹内容关联轨迹模板,禁止删除");
//}
#endregion 私有方法
//需要加个判断,存在内容映射,则出提示
//var trackContentMapEntities = await _trackContentMapBasicQuery.GetListAsync(a => a.TrackContentId == input.Id || a.MapTrackContentId == input.Id);
//if (trackContentMapEntities.Any())
//{
// throw new BusinessException(message: "无法删除该内容,该轨迹内容已在轨迹内容映射中使用了,请检查");
//}
/// <summary>
/// 轨迹内容映射列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("GetMapPage")]
public async Task<UnifyPageResultDto<GetTrackContentMapPageOutputVO>> GetMapPageAsync([FromBody] GetTrackContentMapPageInputVO input)
#endregion 业务校验
var isTrue = await _trackContentRepository.SoftDeleteAsync(x => x.Id == input.Id);
return new UnifyResultDto("200", "删除成功", isTrue);
}
#endregion 私有方法
/// <summary>
/// 轨迹内容映射列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("GetMapPage")]
public async Task<UnifyPageResultDto<GetTrackContentMapPageOutputVO>> GetMapPageAsync(
[FromBody] GetTrackContentMapPageInputVO input)
{
return await _trackContentRepository.GetMapPageAsync(input);
}
/// <summary>
/// 轨迹内容映射详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("GetMapDetail")]
public async Task<GetTrackContentMapDetailOutputVO> GetMapDetailAsync(int id)
{
return await _trackContentRepository.GetMapDetailAsync(id);
}
/// <summary>
/// 轨迹内容映射编辑
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("EditMap")]
public async Task<bool> EditMapAsync([FromBody] EditTrackContentMapInput input)
{
if (input.Options != OptionTypeNoNull.删除)
{
return await _trackContentRepository.GetMapPageAsync(input);
if (input.SubSystemId == input.MapSubSystemId)
throw new BusinessException(message: _stringLocalizer["NotAllowedToMapSubSystem"]);
Expression<Func<TrackContentMapEntity, bool>> isMapAnyExp = x =>
x.TrackContentId == input.TrackContentId && x.MapTrackContentId == input.MapTrackContentId;
if (input.Options == OptionTypeNoNull.修改) isMapAnyExp.And(x => x.Id != input.Id);
if (await _trackContentRepository.IsMapAnyAsync(isMapAnyExp))
throw new BusinessException(message: _stringLocalizer["IsTrackContentMapAny"]);
}
/// <summary>
/// 轨迹内容映射详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("GetMapDetail")]
public async Task<GetTrackContentMapDetailOutputVO> GetMapDetailAsync(int id)
switch (input.Options)
{
return await _trackContentRepository.GetMapDetailAsync(id);
case OptionTypeNoNull.新增:
{
var trackContentMapEntity = ObjectMapper.Map<EditTrackContentMapInput, TrackContentMapEntity>(input);
await _trackContentRepository.InsertMapAsync(trackContentMapEntity);
}
break;
case OptionTypeNoNull.修改:
{
var oldTrackContentMapEntity = await _trackContentRepository.GetMapByIdAsync(input.Id!.Value) ??
throw new BusinessException(message: _stringLocalizer["NotFindData"]);
ObjectMapper.Map(input, oldTrackContentMapEntity);
await _trackContentRepository.UpdateMapAsync(oldTrackContentMapEntity);
}
break;
case OptionTypeNoNull.删除:
await _trackContentRepository.SoftDeleteMapAsync(x => x.Id == input.Id);
break;
default:
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,
nameof(EditTrackContentMapInput.Options)]);
}
/// <summary>
/// 轨迹内容映射编辑
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("EditMap")]
public async Task<bool> EditMapAsync([FromBody] EditTrackContentMapInput input)
{
if (input.Options != OptionTypeNoNull.删除)
{
if (input.SubSystemId == input.MapSubSystemId) throw new BusinessException(message: _stringLocalizer["NotAllowedToMapSubSystem"]);
Expression<Func<TrackContentMapEntity, bool>> isMapAnyExp = x =>
x.TrackContentId == input.TrackContentId && x.MapTrackContentId == input.MapTrackContentId;
if (input.Options == OptionTypeNoNull.修改) isMapAnyExp.And(x => x.Id != input.Id);
if (await _trackContentRepository.IsMapAnyAsync(isMapAnyExp))
throw new BusinessException(message: _stringLocalizer["IsTrackContentMapAny"]);
}
switch (input.Options)
{
case OptionTypeNoNull.新增:
{
var trackContentMapEntity = ObjectMapper.Map<EditTrackContentMapInput, TrackContentMapEntity>(input);
await _trackContentRepository.InsertMapAsync(trackContentMapEntity);
}
break;
case OptionTypeNoNull.修改:
{
var oldTrackContentMapEntity = await _trackContentRepository.GetMapByIdAsync(input.Id!.Value) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]);
ObjectMapper.Map(input, oldTrackContentMapEntity);
await _trackContentRepository.UpdateMapAsync(oldTrackContentMapEntity);
}
break;
case OptionTypeNoNull.删除:
await _trackContentRepository.SoftDeleteMapAsync(x => x.Id == input.Id);
break;
default:
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,
nameof(EditTrackContentMapInput.Options)]);
}
return true;
}
return true;
}
}

View File

@ -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;
}

View File

@ -35,7 +35,7 @@ public class TrackPullCacheService : ApplicationService, ITrackPullCacheService
}
[NonAction]
public async Task<TrackPullParamWithContentConfigDto> GetPullParamWithContentConfigAsync(int subSystemId,
public async Task<TrackPullParamWithContentConfigDto?> GetPullParamWithContentConfigAsync(int subSystemId,
int serviceProviderId)
{
var data = await RedisHelper.Client.GetAsync<TrackPullParamWithContentConfigDto>(TrackPullContentKey(
@ -48,23 +48,22 @@ public class TrackPullCacheService : ApplicationService, ITrackPullCacheService
}
[NonAction]
public async Task<TrackPullParamWithContentConfigDto> SetPullConfigAsync(int? id = null, int? subSystemId = null,
public async Task<TrackPullParamWithContentConfigDto?> SetPullConfigAsync(int? id = null, int? subSystemId = null,
int? serviceProviderId = null)
{
var data = new TrackPullParamWithContentConfigDto();
Expression<Func<TrackPullConfigEntity, bool>> exp = x => true;
if (id.HasValue) exp = x => x.Id == id;
else if (subSystemId.HasValue && serviceProviderId.HasValue)
exp = x => x.SubSystemId == subSystemId && x.ServiceProviderId == serviceProviderId;
var trackPullConfigEntity = await _trackPullConfigRepository.GetFirstAsync(exp);
if (trackPullConfigEntity == null) return data;
if (trackPullConfigEntity == null) return null;
var trackPullConfigDetail = await _trackPullConfigRepository.GetDetailAsync(trackPullConfigEntity.Id);
if (trackPullConfigDetail is null) return data;
var trackPullContentList = await _trackPullConfigRepository.GetContentListCacheAsync(trackPullConfigEntity.Id);
if (trackPullContentList.Count == 0) return data;
if (trackPullContentList.Count == 0) return null;
var data = new TrackPullParamWithContentConfigDto();
data.ParamConfig =
ObjectMapper.Map<GetTrackPullConfigDetailOutputVO, TrackPullParamConfigDto>(trackPullConfigDetail);

View File

@ -152,6 +152,7 @@ public class TrackPullService : ApplicationService
x.PullOrPushConfigId == input.Id && !x.IsPush);
await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.TrackPullConfigId == input.Id);
await _trackPullCacheService.SetPullConfigAsync(input.Id);
ts.Complete();
}
@ -182,19 +183,19 @@ public class TrackPullService : ApplicationService
if (await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentId == input.TrackContentId)))
throw new BusinessException(message: _stringLocalizer["IsTrackPullContentAny"]);
else if (!input.TrackContentCodeValue.IsNullOrWhiteSpace() &&
await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentCodeValue == input.TrackContentCodeValue)))
if (!input.TrackContentCodeValue.IsNullOrWhiteSpace() &&
await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentCodeValue == input.TrackContentCodeValue)))
throw new BusinessException(message: _stringLocalizer["IsTrackPullContentCodeValueAny"]);
else if (!input.TrackStatusValue.IsNullOrWhiteSpace() &&
await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackStatusValue == input.TrackStatusValue)))
if (!input.TrackStatusValue.IsNullOrWhiteSpace() &&
await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackStatusValue == input.TrackStatusValue)))
throw new BusinessException(message: _stringLocalizer["IsTrackPullContentStatusValueAny"]);
else if (!input.TrackContentValue.IsNullOrWhiteSpace() &&
await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentValue == input.TrackContentValue)))
if (!input.TrackContentValue.IsNullOrWhiteSpace() &&
await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentValue == input.TrackContentValue)))
throw new BusinessException(message: _stringLocalizer["IsTrackPullContentValueAny"]);
else if (!input.TrackKeywords.IsNullOrEmpty())
if (!input.TrackKeywords.IsNullOrEmpty())
{
Expression<Func<TrackPullContentConfigEntity, bool>> trackKeywordExp = _ => false;
input.TrackKeywords!.ForEach(item =>

View File

@ -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<List<TrackPushContentConfigDto>> GetPushContentConfigsAsync(int subSystemId, int customId)
public async Task<List<TrackPushContentConfigDto>?> GetPushContentConfigsAsync(int subSystemId, int customId)
{
var data = await GetPushConfigAsync(subSystemId, customId);
return data.ContentConfigs;
}
[NonAction]
public async Task<TrackPushContentConfigDto?> GetPushContentConfigAsync(int subSystemId, int customId,
int trackContentId)
{
var data = await GetPushContentConfigsAsync(subSystemId, customId);
return data?.FirstOrDefault(x => x.TrackContentId == trackContentId);
}
[NonAction]
public async Task<TrackPushContentConfigDto?> 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<TrackPushConfigDto> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null,
int? customId = null)
{
var data = new TrackPushConfigDto { ContentConfigs = new() };
Expression<Func<TrackPushConfigEntity, bool>> 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<TrackPushContentConfigVO>, List<TrackPushContentConfigDto>>(trackPushContentList);
;
await RedisHelper.Client.SetAsync(
TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data);
return data;
}
private async Task<TrackPushConfigDto> GetPushConfigAsync(int subSystemId, int customId)
{
var data = await RedisHelper.Client.GetAsync<TrackPushConfigDto>(TrackPushContentKey(subSystemId, customId));
var data = await RedisHelper.Client.GetAsync<List<TrackPushContentConfigDto>>(
TrackPushContentKey(subSystemId, customId));
data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId);
return data;
}
public async Task<TrackPushContentConfigDto?> GetPushContentConfigAsync(int subSystemId, int customId,
string trackConde)
{
var configs = await GetPushContentConfigsAsync(subSystemId, customId);
return configs?.FirstOrDefault(x => x.TrackCode == trackConde);
}
public async Task<TrackPushContentConfigDto?> 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.IsAutoPush ? matched : default;
}
public async Task<List<TrackPushContentConfigDto>?> SetPushContentConfigsAsync(int? id = null,
int? subSystemId = null,
int? customId = null)
{
Expression<Func<TrackPushConfigEntity, bool>> 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;
}
}

View File

@ -5,9 +5,7 @@ using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Track.Application.Contract.Dtos.TrackPush;
using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Application.Localization;
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate;
using SJZY.Track.Domain.Dtos.Common;
using SJZY.Track.Domain.Dtos.TrackPush;
@ -22,19 +20,15 @@ public class TrackPushService : ApplicationService
{
private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer;
private readonly ITrackPushConfigRepository _trackPushConfigRepository;
private readonly ITrackPullConfigRepository _trackPullConfigRepository;
private readonly ITrackPushCacheService _trackPushCacheService;
public TrackPushService(
IStringLocalizer<TrackLocalizationResource> stringLocalizer,
ITrackPushConfigRepository trackPushConfigRepository,
ITrackTemplateRepository trackTemplateRepository,
ITrackPullConfigRepository trackPullConfigRepository,
ITrackPushCacheService trackPushCacheService)
{
_stringLocalizer = stringLocalizer;
_trackPushConfigRepository = trackPushConfigRepository;
_trackPullConfigRepository = trackPullConfigRepository;
_trackPushCacheService = trackPushCacheService;
}
@ -104,64 +98,35 @@ public class TrackPushService : ApplicationService
switch (input.Options)
{
case OptionTypeNoNull.新增:
{
var trackPushEntity = ObjectMapper.Map<EditTrackPushConfigInput, TrackPushConfigEntity>(input);
var trackPushParamsEntity =
ObjectMapper.Map<EditTrackPushConfigInput, TrackPushPullParamsConfigEntity>(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<EditTrackPushConfigInput, TrackPushConfigEntity>(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:
@ -189,72 +154,72 @@ public class TrackPushService : ApplicationService
if (await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentId == input.TrackContentId)))
throw new BusinessException(message: _stringLocalizer["IsTrackPushContentAny"]);
else if (!input.TrackContentCodeValue.IsNullOrWhiteSpace() &&
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentCodeValue == input.TrackContentCodeValue)))
if (!input.TrackContentCodeValue.IsNullOrWhiteSpace() &&
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentCodeValue == input.TrackContentCodeValue)))
throw new BusinessException(message: _stringLocalizer["IsTrackPushContentCodeValueAny"]);
else if (!input.TrackStatusValue.IsNullOrWhiteSpace() &&
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackStatusValue == input.TrackStatusValue)))
if (!input.TrackStatusValue.IsNullOrWhiteSpace() &&
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackStatusValue == input.TrackStatusValue)))
throw new BusinessException(message: _stringLocalizer["IsTrackPushContentStatusValueAny"]);
else if (!input.TrackContentValue.IsNullOrWhiteSpace() &&
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentValue == input.TrackContentValue)))
if (!input.TrackContentValue.IsNullOrWhiteSpace() &&
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentValue == input.TrackContentValue)))
throw new BusinessException(message: _stringLocalizer["IsTrackPushContentValueAny"]);
else if (!input.TrackEnContentValue.IsNullOrWhiteSpace() &&
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackEnContentValue == input.TrackEnContentValue)))
if (!input.TrackEnContentValue.IsNullOrWhiteSpace() &&
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackEnContentValue == input.TrackEnContentValue)))
throw new BusinessException(message: _stringLocalizer["IsTrackPushEnContentValueAny"]);
}
switch (input.Options)
{
case OptionTypeNoNull.新增:
{
int maxSort = await _trackPushConfigRepository.ContentMaxAsync(x => x.Sort,
x => x.TrackPushConfigId == input.TrackPushConfigId);
{
int maxSort = await _trackPushConfigRepository.ContentMaxAsync(x => x.Sort,
x => x.TrackPushConfigId == input.TrackPushConfigId);
var entity = ObjectMapper.Map<EditTrackPushContentInput, TrackPushContentConfigEntity>(input);
entity.Sort = maxSort + 1;
var entity = ObjectMapper.Map<EditTrackPushContentInput, TrackPushContentConfigEntity>(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)]);

View File

@ -85,8 +85,11 @@ namespace SJZY.Track.Application
configure.Password = configuration["RabbitMQ:Password"]!;
configure.Port = configuration.GetValue<int>("RabbitMQ:Port");
});
// options.TopicNamePrefix = "v1";
options.SucceedMessageExpiredAfter = 6 * 60 * 60;
options.FailedRetryInterval = 60;
options.FailedRetryCount = 10;
options.FailedRetryCount = 3;
options.UseDashboard(dashboardOptions =>
{
dashboardOptions.PathBase = System.Diagnostics.Debugger.IsAttached
@ -101,14 +104,14 @@ namespace SJZY.Track.Application
|-CAP失败回调事件:
|-处理类型:{(faileCalback.MessageType == DotNetCore.CAP.Messages.MessageType.Subscribe ? "消费消息达到最大重试次数,需要开发人员介入" : "生产消息推送失败")}
|-头部信息:{faileCalback.Message.Headers.ToJson()}
|-消息内容:{((JsonElement?)faileCalback.Message.Value)?.GetRawText()}");
|-消息内容:{(faileCalback.Message.Value is string ? faileCalback.Message.Value : ((JsonElement?)faileCalback.Message.Value)?.GetRawText())}");
}
catch (Exception ex)
{
LogHelper.Error("【严重】CAP失败回调事件发生未处理异常" + ex);
}
};
}).AddSubscribeFilter<CAPFilter>();
}).AddSubscribeFilter<CapFilter>();
}
public override void PreConfigureServices(ServiceConfigurationContext context)

View File

@ -26,10 +26,10 @@ public interface IOrderRepository : IBasicRepository<OrderEntity>
Task DeleteOrderAsync(int orderId);
/// <summary>
/// 获取推送预警单
/// 更新推送预警单
/// </summary>
/// <returns></returns>
Task<List<OrderEntity>> GetPushWarnOrdersAsync();
Task<int> PushWarnOrdersAsync();
#region 订单关联

View File

@ -43,10 +43,10 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot
public bool IsCompleted { get; set; }
/// <summary>
/// 最新推送轨迹内容id(异步维护)
/// 最新推送轨迹code(异步维护)
/// </summary>
[SugarColumn(ColumnName = "LatestPushTrackContentId")]
public int? LatestPushTrackContentId { get; set; }
[SugarColumn(ColumnName = "LatestPushTrackCode")]
public string? LatestPushTrackCode { get; set; }
/// <summary>
/// 最新推送时间(异步维护)
@ -54,6 +54,12 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot
[SugarColumn(ColumnName = "LatestPushTime")]
public DateTime? LatestPushTime { get; set; }
/// <summary>
/// 推送异常信息
/// </summary>
[SugarColumn(ColumnName = "LatestPushError")]
public string? LatestPushError { get; set; }
/// <summary>
/// 最新轨迹内容(异步维护)
/// </summary>
@ -120,12 +126,6 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot
[SugarColumn(ColumnName = "QuestionType")]
public int QuestionType { get; set; }
/// <summary>
/// 问题描述
/// </summary>
[SugarColumn(ColumnName = "ProblemDescription")]
public string? ProblemDescription { get; set; }
/// <summary>
/// 起运港口
/// </summary>

View File

@ -47,10 +47,4 @@ public class TrackContentEntity : IFullAuditedBasicEntitys, IAggregateRoot
/// </summary>
[SugarColumn(ColumnName = "TrackStatusId")]
public int TrackStatusId { get; set; }
/// <summary>
/// 是否完结
/// </summary>
[SugarColumn(ColumnName = "IsCompleted")]
public bool IsCompleted { get; set; }
}

View File

@ -6,7 +6,7 @@ public interface ITrackDetailsRepository
{
Task<TrackDetailsIndex?> GetFirstOrDefaultAsync(int orderId, string trackCode);
Task<TrackDetailsIndex?> GetFirstOrDefaultAsync(int orderId, DateTime trackTime);
Task<bool> AnyAsync(int orderId, DateTime trackTime);
Task UpsertAsync(TrackDetailsIndex index);

View File

@ -43,14 +43,9 @@ public class TrackDetailsIndex : IdBaseIndex
public string TrackContent { get; set; } = null!;
/// <summary>
/// 轨迹内容Id
/// 服务商
/// </summary>
public int TrackContentId { get; set; }
/// <summary>
/// 这条轨迹是否意味着完成
/// </summary>
public bool IsCompleted { get; set; }
public string? ServiceProviderName { get; set; }
/// <summary>
/// 原轨迹内容

View File

@ -65,4 +65,10 @@ public class TrackPullContentConfigEntity : IFullAuditedBasicEntitys, IEntity
/// </summary>
[SugarColumn(ColumnName = "TrackTimeZone")]
public float? TrackTimeZone { get; set; }
/// <summary>
/// 是否完结
/// </summary>
[SugarColumn(ColumnName = "IsCompleted")]
public bool IsCompleted { get; set; }
}

View File

@ -16,5 +16,10 @@ public interface ITrackPushRecordsRepository
/// <returns></returns>
Task<List<TrackPushRecordIndex>> GetTrackPushRecordsAsync(int orderId);
Task<List<TrackPushRecordIndex>> GetTrackPushRecordsAsync(string inputOrderNo, int inputOrderType);
/// <summary>
/// 获取最新轨迹推送记录
/// </summary>
/// <param name="orderId"></param>
/// <returns></returns>
Task<TrackPushRecordIndex?> GetLatestTrackPushRecordAsync(int orderId);
}

View File

@ -47,4 +47,10 @@ public class TrackPushConfigEntity : IFullAuditedBasicEntitys, IAggregateRoot
/// </summary>
[SugarColumn(ColumnName = "IsCanDelete")]
public bool IsCanDelete { get; set; }
/// <summary>
/// 是否全量推送
/// </summary>
[SugarColumn(ColumnName = "IsAllPush")]
public bool IsAllPush { get; set; }
}

View File

@ -12,18 +12,24 @@ public class TrackPushContentConfigEntity : IFullAuditedBasicEntitys, IEntity
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 扩展字段参数值
/// </summary>
[SugarColumn(ColumnName = "ExpandFieldsValue")]
public string ExpandFieldsValue { get; set; }
/// <summary>
/// 推送单号类型(主数据枚举TrackOrderType)
/// </summary>
[SugarColumn(ColumnName = "OrderNoType")]
public int OrderNoType { get; set; }
/// <summary>
/// 轨迹内容id
/// </summary>
[SugarColumn(ColumnName = "TrackContentId")]
public int TrackContentId { get; set; }
/// <summary>
/// 可交换顺序的轨迹内容id
/// </summary>
[SugarColumn(ColumnName = "SwapTrackContentId")]
public int? SwapTrackContentId { get; set; }
/// <summary>
/// 推送轨迹排序
/// </summary>
@ -36,12 +42,6 @@ public class TrackPushContentConfigEntity : IFullAuditedBasicEntitys, IEntity
[SugarColumn(ColumnName = "TrackContentCodeValue")]
public string TrackContentCodeValue { get; set; }
/// <summary>
/// 轨迹内容id
/// </summary>
[SugarColumn(ColumnName = "TrackContentId")]
public int TrackContentId { get; set; }
/// <summary>
/// 轨迹内容参数值
/// </summary>
@ -71,4 +71,10 @@ public class TrackPushContentConfigEntity : IFullAuditedBasicEntitys, IEntity
/// </summary>
[SugarColumn(ColumnName = "TrackTimeZone")]
public double? TrackTimeZone { get; set; }
/// <summary>
/// 扩展字段参数值
/// </summary>
[SugarColumn(ColumnName = "ExpandFieldsValue")]
public string ExpandFieldsValue { get; set; }
}

View File

@ -17,16 +17,6 @@ public class TrackPushRecordIndex : IdBaseIndex
/// </summary>
public int OrderId { get; set; }
/// <summary>
/// 订单号
/// </summary>
public string OrderNo { get; set; } = null!;
/// <summary>
/// 订单类型(主数据枚举TrackOrderType)
/// </summary>
public int OrderType { get; set; }
/// <summary>
/// 接口通请求Id
/// </summary>
@ -78,29 +68,9 @@ public class TrackPushRecordIndex : IdBaseIndex
public bool IsSuccess { get; set; }
/// <summary>
/// 轨迹代码参数值
/// 推送内容(json)
/// </summary>
public string? TrackContentCodeValue { get; set; }
/// <summary>
/// 轨迹内容参数值
/// </summary>
public string? TrackContentValue { get; set; }
/// <summary>
/// 轨迹内容英文参数值
/// </summary>
public string? TrackEnContentValue { get; set; }
/// <summary>
/// 轨迹状态参数值
/// </summary>
public string? TrackStatusValue { get; set; }
/// <summary>
/// 扩展字段参数值
/// </summary>
public string? ExpandFieldsValue { get; set; }
public string PushContent { get; set; } = null!;
/// <summary>创建人</summary>
public string? CreateUser { get; set; }

View File

@ -7,6 +7,11 @@ public partial class GlobalConst
/// </summary>
public const string TrackUpsertSubscribe = "SJZY.Track.TrackUpsert";
/// <summary>
/// 无法映射的轨迹新增
/// </summary>
public const string TrackInsertForNotMappedEventSubscribe = "SJZY.Track.TrackInsertForNotMapped";
/// <summary>
/// 轨迹删除
/// </summary>
@ -30,7 +35,7 @@ public partial class GlobalConst
/// <summary>
/// 轨迹推送后触发更新订单主表
/// </summary>
public const string TrackPushAfterUpdateOrderSubscribe = "SJZY.Traack.TrackPushAfterUpdateOrder";
public const string TrackPushAfterUpdateOrderSubscribe = "SJZY.Track.TrackPushAfterUpdateOrder";
/// <summary>
/// 关联订单后补轨迹

View File

@ -2,5 +2,6 @@
public partial class GlobalConst
{
public const string SystemUser = "系统";
public const string EmptyString = "--";
}

View File

@ -21,19 +21,4 @@ public class LinkedOrderVO
/// 子系统id
/// </summary>
public int SubSystemId { get; set; }
/// <summary>
/// 最新推送轨迹内容id(异步维护)
/// </summary>
public int? LatestPushTrackContentId { get; set; }
/// <summary>
/// 客户id
/// </summary>
public int CustomId { get; set; }
/// <summary>
/// 订单是否完成
/// </summary>
public bool IsCompleted { get; set; }
}

View File

@ -16,6 +16,11 @@ public class OrderWithServiceProviderVO
/// </summary>
public string ServiceProviderCode { get; set; } = null!;
/// <summary>
/// 服务商name
/// </summary>
public string ServiceProviderName { get; set; } = null!;
/// <summary>
/// 子系统id
/// </summary>

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SJZY.Track.Domain.Dtos.TrackContents
namespace SJZY.Track.Domain.Dtos.TrackContents
{
public class GetPageTrackContentVO : PageInfoInput
{
@ -90,10 +84,5 @@ namespace SJZY.Track.Domain.Dtos.TrackContents
/// 修改人
/// </summary>
public string UpdateUser { get; set; }
/// <summary>
/// 是否完结
/// </summary>
public bool IsFinish { get; set; }
}
}
}

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SJZY.Track.Domain.Dtos.TrackContents
namespace SJZY.Track.Domain.Dtos.TrackContents
{
public class GetTrackContentDetailVO
{
@ -57,10 +51,5 @@ namespace SJZY.Track.Domain.Dtos.TrackContents
/// 轨迹标记
/// </summary>
public string TrackFlag { get; set; }
/// <summary>
/// 是否完结
/// </summary>
public bool IsFinish { get; set; }
}
}
}

View File

@ -5,7 +5,7 @@ public class MatchTrackContentDto
/// <summary>
/// 轨迹内容id
/// </summary>
public int Id { get; set; }
public string TrackCode { get; set; }
/// <summary>
/// 轨迹内容
@ -22,11 +22,6 @@ public class MatchTrackContentDto
/// </summary>
public string Status { get; set; } = null!;
/// <summary>
/// 是否意味着完成
/// </summary>
public bool IsCompleted { get; set; }
/// <summary>
/// 是否可删
/// </summary>

View File

@ -41,4 +41,9 @@ public class GetTrackPullContentListCacheVO
/// 轨迹时区GMT
/// </summary>
public float? TrackTimeZone { get; set; }
/// <summary>
/// 订单是否完成(由轨迹刷新配置决定)
/// </summary>
public bool IsCompleted { get; set; }
}

View File

@ -12,15 +12,25 @@ public class TrackPushContentConfigVO
/// </summary>
public bool IsCanUpdate { get; set; }
/// <summary>
/// 是否全量推送
/// </summary>
public bool IsAllPush { get; set; }
/// <summary>
/// 服务商code
/// </summary>
public string ServiceProviderCode { get; set; } = null!;
/// <summary>
/// 扩展字段参数值
/// 轨迹code
/// </summary>
public string? ExpandFieldsValue { get; set; }
public string TrackCode { get; set; } = null!;
/// <summary>
/// 可交换顺序的轨迹code
/// </summary>
public string? SwapTrackCode { get; set; }
/// <summary>
/// 推送单号类型(主数据枚举TrackOrderType)
@ -32,11 +42,6 @@ public class TrackPushContentConfigVO
/// </summary>
public string? TrackContentCodeValue { get; set; }
/// <summary>
/// 轨迹内容id
/// </summary>
public int TrackContentId { get; set; }
/// <summary>
/// 轨迹内容参数值
/// </summary>
@ -56,4 +61,9 @@ public class TrackPushContentConfigVO
/// 轨迹时区GMT
/// </summary>
public double? TrackTimeZone { get; set; }
/// <summary>
/// 扩展字段参数值
/// </summary>
public string? ExpandFieldsValue { get; set; }
}

View File

@ -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();
@ -120,6 +119,7 @@ public class ProvideQueries : ISugarRepository, IProvideQueries,
OrderType = a.OrderType,
ServiceProviderId = b.ServiceProviderId,
ServiceProviderCode = c.Code,
ServiceProviderName = c.Name,
SubSystemId = a.SubSystemId
})
.ToListAsync();
@ -137,6 +137,7 @@ public class ProvideQueries : ISugarRepository, IProvideQueries,
OrderType = a.OrderType,
ServiceProviderId = b.ServiceProviderId,
ServiceProviderCode = c.Code,
ServiceProviderName = c.Name,
SubSystemId = a.SubSystemId
})
.ToListAsync();

View File

@ -1,8 +1,6 @@
using SJZY.Track.Domain;
using SJZY.Track.Domain.Aggregates.OrderAggregate;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
using SJZY.Track.Domain.Dtos.Order;
using SJZY.Track.Domain.Enums;
namespace SJZY.Track.Repository.Repositories;
@ -55,21 +53,16 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
tran.Complete();
}
public async Task<List<OrderEntity>> GetPushWarnOrdersAsync()
public async Task<int> PushWarnOrdersAsync()
{
var errorType = (int)TrackProblemType.Error;
return await Context.Queryable<TrackPushConfigEntity>()
.LeftJoin<OrderEntity>((a, b) => a.SubSystemId == b.SubSystemId && a.CustomId == b.CustomId)
.Where((a, b) => !b.IsCompleted && b.QuestionType != errorType)
.Where("a.CreateTime < DATE_SUB(now(),INTERVAL 12 hour)") // 过滤掉创建时间不足12小时的
.Select((a, b) => new OrderEntity
{
Id = b.Id,
QuestionType = b.QuestionType,
LatestPushTime = b.LatestPushTime
})
.ToListAsync();
return await Context.Ado.ExecuteCommandAsync(@"UPDATE `t_track_push_config` `a`
LEFT JOIN `t_order` `b` ON `a`.`SubSystemId` = `b`.`SubSystemId` AND `a`.`CustomId` = `b`.`CustomId`
SET `b`.`QuestionType` = CASE
WHEN `b`.`LatestPushTime` IS NULL THEN 2
WHEN `b`.`LatestPushTime` < DATE_SUB(NOW(), INTERVAL 12 HOUR) THEN 2
ELSE 0 END
WHERE `b`.`IsCompleted` = 0 AND `b`.`QuestionType` != 1 AND `b`.`CreateTime` < DATE_SUB(NOW(), INTERVAL 12 HOUR)
AND `a`.`IsDeleted` = 0 AND `b`.`IsDeleted` = 0;");
}
#region 订单关联
@ -84,10 +77,7 @@ public class OrderRepository : BasicRepository<OrderEntity>, 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();
}

View File

@ -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<TrackContentEntity>, 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<TrackContentEntity>, 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<TrackContentEntity>, 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<TrackContentEntity>, ITrac
/// 获取轨迹内容属性值
/// </summary>
/// <returns></returns>
public async Task<List<GetTemplateContentAttributeValueVO>> GetTrackContentAttributeValue(GetTemplateContentAttributeValueInputVO input)
public async Task<List<GetTemplateContentAttributeValueVO>> GetTrackContentAttributeValue(
GetTemplateContentAttributeValueInputVO input)
{
var list = await Context.Queryable<TrackContentEntity>()
.LeftJoin<TrackTemplateContentEntity>((a, b) => a.Id == b.TrackContentId && b.TrackTemplateId > 0 && b.IsDeleted == false)
.LeftJoin<TrackTemplateContentEntity>((a, b) =>
a.Id == b.TrackContentId && b.TrackTemplateId > 0 && b.IsDeleted == false)
.LeftJoin<TrackTemplateEntity>((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<TrackContentEntity>, ITrac
public async Task<bool> GetTemplateIsExist(int trackContentId)
{
//var trackTemplateContents = await _trackTemplateContentBasicQuery.GetListAsync(a => a.TrackContentId == input.Id);
var trackContentEntities = await Context.Queryable<TrackContentEntity>().LeftJoin<TrackTemplateContentEntity>((a, b) => a.Id == b.TrackContentId && b.IsDeleted == false)
.LeftJoin<TrackTemplateEntity>((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<TrackContentEntity>()
.LeftJoin<TrackTemplateContentEntity>((a, b) => a.Id == b.TrackContentId && b.IsDeleted == false)
.LeftJoin<TrackTemplateEntity>((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<TrackContentEntity>, ITrac
}
public async Task<UnifyPageResultDto<GetTrackContentMapPageOutputVO>> GetMapPageAsync(GetTrackContentMapPageInputVO input)
public async Task<UnifyPageResultDto<GetTrackContentMapPageOutputVO>> GetMapPageAsync(
GetTrackContentMapPageInputVO input)
{
return await Context.Queryable<TrackContentMapEntity>()
.InnerJoin<TrackContentEntity>((contentMap, sourceContent) => contentMap.TrackContentId == sourceContent.Id && !sourceContent.IsDeleted)
.InnerJoin<TrackContentEntity>((contentMap, sourceContent, targetContent) => contentMap.MapTrackContentId == targetContent.Id && !targetContent.IsDeleted)
.LeftJoin<VSystemEntity>((contentMap, sourceContent, targetContent, sourceSystem) => contentMap.SubSystemId == sourceSystem.Id && !sourceSystem.IsDeleted)
.LeftJoin<VSystemEntity>((contentMap, sourceContent, targetContent, sourceSystem, targetSystem) => contentMap.MapSubSystemId == targetSystem.Id && !targetSystem.IsDeleted)
.LeftJoin<TrackStatusEntity>((contentMap, sourceContent, targetContent, sourceSystem, targetSystem, sourceStatus) => sourceContent.TrackStatusId == sourceStatus.Id && !sourceStatus.IsDeleted)
.LeftJoin<TrackStatusEntity>((contentMap, sourceContent, targetContent, sourceSystem, targetSystem, sourceStatus, targetStatus) => targetContent.TrackStatusId == targetStatus.Id && !targetStatus.IsDeleted)
.InnerJoin<TrackContentEntity>((contentMap, sourceContent) =>
contentMap.TrackContentId == sourceContent.Id && !sourceContent.IsDeleted)
.InnerJoin<TrackContentEntity>((contentMap, sourceContent, targetContent) =>
contentMap.MapTrackContentId == targetContent.Id && !targetContent.IsDeleted)
.LeftJoin<VSystemEntity>((contentMap, sourceContent, targetContent, sourceSystem) =>
contentMap.SubSystemId == sourceSystem.Id && !sourceSystem.IsDeleted)
.LeftJoin<VSystemEntity>((contentMap, sourceContent, targetContent, sourceSystem, targetSystem) =>
contentMap.MapSubSystemId == targetSystem.Id && !targetSystem.IsDeleted)
.LeftJoin<TrackStatusEntity>(
(contentMap, sourceContent, targetContent, sourceSystem, targetSystem, sourceStatus) =>
sourceContent.TrackStatusId == sourceStatus.Id && !sourceStatus.IsDeleted)
.LeftJoin<TrackStatusEntity>(
(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<GetTrackContentMapDetailOutputVO> GetMapDetailAsync(int id)
{
return await Context.Queryable<TrackContentMapEntity>()
.InnerJoin<TrackContentEntity>((contentMap, sourceContent) => contentMap.TrackContentId == sourceContent.Id && !sourceContent.IsDeleted)
.InnerJoin<TrackContentEntity>((contentMap, sourceContent, targetContent) => contentMap.MapTrackContentId == targetContent.Id && !targetContent.IsDeleted)
.LeftJoin<VSystemEntity>((contentMap, sourceContent, targetContent, sourceSystem) => contentMap.SubSystemId == sourceSystem.Id && !sourceSystem.IsDeleted)
.LeftJoin<VSystemEntity>((contentMap, sourceContent, targetContent, sourceSystem, targetSystem) => contentMap.MapSubSystemId == targetSystem.Id && !targetSystem.IsDeleted)
.InnerJoin<TrackContentEntity>((contentMap, sourceContent) =>
contentMap.TrackContentId == sourceContent.Id && !sourceContent.IsDeleted)
.InnerJoin<TrackContentEntity>((contentMap, sourceContent, targetContent) =>
contentMap.MapTrackContentId == targetContent.Id && !targetContent.IsDeleted)
.LeftJoin<VSystemEntity>((contentMap, sourceContent, targetContent, sourceSystem) =>
contentMap.SubSystemId == sourceSystem.Id && !sourceSystem.IsDeleted)
.LeftJoin<VSystemEntity>((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<TrackContentEntity>, ITrac
.ExecuteCommandHasChangeAsync();
}
public async Task<bool> UpdateMapAsync(Expression<Func<TrackContentMapEntity, TrackContentMapEntity>> columns, Expression<Func<TrackContentMapEntity, bool>> whereExpression)
public async Task<bool> UpdateMapAsync(Expression<Func<TrackContentMapEntity, TrackContentMapEntity>> columns,
Expression<Func<TrackContentMapEntity, bool>> whereExpression)
{
return await Context.Updateable<TrackContentMapEntity>().SetColumns(columns).Where(whereExpression)
.ExecuteCommandAsync() > 0;

View File

@ -32,23 +32,17 @@ internal class TrackDetailsRepository : ElasticSearchContextAbstract<TrackDetail
return res;
}
public async Task<TrackDetailsIndex?> GetFirstOrDefaultAsync(int orderId, DateTime trackTime)
public async Task<bool> AnyAsync(int orderId, DateTime trackTime)
{
var r = await Context.SearchAsync<TrackDetailsIndex>(s => s
.Source()
var r = await Context.SearchAsync<TrackDetailsIndex>(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<TrackDetail
.Field(f => 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)
@ -146,22 +139,10 @@ internal class TrackDetailsRepository : ElasticSearchContextAbstract<TrackDetail
return data.Documents.ToList();
}
public async Task<List<TrackDetailsIndex>?> GetListAsync(List<int> orderIds)
{
var data = await Context.SearchAsync<TrackDetailsIndex>(x => x.Query(q =>
q.Terms(t => t.Field(g => g.OrderId).Terms(orderIds))
)
.Size(10000)
.Sort(s => s.Field(c => c.TrackTime, SortOrder.Descending))
);
return data?.Documents?.ToList();
}
public async Task<TrackDetailsIndex?> GetLatestAsync(int orderId)
{
var data = await Context.SearchAsync<TrackDetailsIndex>(x => x
.Source(s => s.Includes(fd => fd
.Field(f => f.IsCompleted)
.Field(f => f.TrackEnContent)
.Field(f => f.TrackContent)
.Field(f => f.TrackPlace)

View File

@ -125,21 +125,25 @@ public class TrackPushConfigRepository : BasicRepository<TrackPushConfigEntity>,
return await Context.Queryable<TrackPushConfigEntity>()
.LeftJoin<TrackPushContentConfigEntity>((a, b) => a.Id == b.TrackPushConfigId)
.LeftJoin<VServiceProviderEntity>((a, b, c) => a.ServiceProviderId == c.Id)
.LeftJoin<TrackContentEntity>((a, b, c, d) => b.TrackContentId == d.Id)
.LeftJoin<TrackContentEntity>((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();
}

View File

@ -41,17 +41,16 @@ public class TrackPushRecordsRepository : ElasticSearchContextAbstract<TrackDeta
return data.Documents.ToList();
}
public async Task<List<TrackPushRecordIndex>> GetTrackPushRecordsAsync(string orderNo, int orderType)
public async Task<TrackPushRecordIndex?> GetLatestTrackPushRecordAsync(int orderId)
{
var data = await Context.SearchAsync<TrackPushRecordIndex>(x => x
.Index(GlobalConst.TrackPushRecordsIndex)
.Query(q =>
q.Term(t => t.OrderNo.Suffix("keyword"), orderNo)
&& q.Term(f => f.OrderType, orderType)
q.Term(t => t.OrderId, orderId)
)
.Size(1000)
.Sort(s => s.Field(f => f.CreateTime, SortOrder.Descending)));
return data.Documents.ToList();
return data.Documents.FirstOrDefault();
}
}