对接接口通

This commit is contained in:
xiaolipro 2024-09-14 16:00:06 +08:00
parent ca7b3d7353
commit 9d2c10c4db
20 changed files with 289 additions and 147 deletions

View File

@ -2,18 +2,20 @@ namespace SJZY.Track.Application.Contract.Dtos.TrackPull;
public class TrackRefreshAttach
{
public TrackRefreshAttach(int serviceProviderId, string serviceProviderName, int subSystemId, int orderType)
public TrackRefreshAttach(string serviceProviderCode, string serviceProviderName, string subSystemCode,
int subSystemId, int orderType)
{
ServiceProviderId = serviceProviderId;
ServiceProviderCode = serviceProviderCode;
ServiceProviderName = serviceProviderName;
SubSystemCode = subSystemCode;
SubSystemId = subSystemId;
OrderType = orderType;
}
/// <summary>
/// 服务商id
/// 服务商code
/// </summary>
public int ServiceProviderId { get; set; }
public string ServiceProviderCode { get; set; }
/// <summary>
/// 服务商name
@ -25,6 +27,11 @@ public class TrackRefreshAttach
/// </summary>
public int OrderType { get; set; }
/// <summary>
/// 子系统code
/// </summary>
public string SubSystemCode { get; set; }
/// <summary>
/// 子系统id
/// </summary>

View File

@ -4,31 +4,22 @@ namespace SJZY.Track.Application.Contract.Services;
public interface ITrackPullCacheService
{
string TrackPullKey(int subSystemId, int serviceProviderId);
string TrackPullContentKey(int subSystemId, int serviceProviderId);
/// <summary>
/// 获取所有拉取配置
/// </summary>
/// <returns></returns>
Task<List<TrackPullConfigDto>> GetAllPullConfigsAsync();
string TrackPullKey(string subSystemCode, string serviceProviderCode);
string TrackPullContentKey(string subSystemCode, string serviceProviderCode);
/// <summary>
/// 获取服务商拉取配置
/// </summary>
/// <param name="subSystemId">子系统id</param>
/// <param name="serviceProviderId">服务商id</param>
/// <param name="subSystemCode">子系统code</param>
/// <param name="serviceProviderCode">服务商code</param>
/// <returns></returns>
Task<TrackPullParamsWithContentDto?>
GetPullParamsWithContentAsync(int subSystemId, int serviceProviderId);
GetPullParamsWithContentAsync(string subSystemCode, string serviceProviderCode);
/// <summary>
/// 设置拉取配置缓存
/// </summary>
/// <param name="id"></param>
/// <param name="subSystemId">子系统id</param>
/// <param name="serviceProviderId">服务商id</param>
/// <returns></returns>
Task<TrackPullParamsWithContentDto?> SetPullConfigAsync(int? id = null, int? subSystemId = null,
int? serviceProviderId = null);
Task<TrackPullParamsWithContentDto?> SetPullConfigAsync(int id);
}

View File

@ -1,5 +1,9 @@
using DotNetCore.CAP;
using System.Text;
using BSI.Stack.Rabbit;
using BSI.Stack.Rabbit.Handler;
using Newtonsoft.Json;
using RabbitMQ.Client.Events;
using SJZY.Expand.ABP.Core.Logger;
using SJZY.InterfaceRelay.Application.Contracts;
using SJZY.Track.Application.Contract.Dtos.TrackPush;
using SJZY.Track.Application.Helpers;
@ -8,23 +12,36 @@ using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
using SJZY.Track.Domain.Enums;
using Volo.Abp.DependencyInjection;
namespace SJZY.Track.Application.CAP.EventHandlers;
namespace SJZY.Track.Application.Rabbit;
public class TrackPushCompletedEventHandler : ITransientDependency, ICapSubscribe
public class TrackPushCompletedEventHandler : ITransientDependency, IRabbitHandler
{
private readonly IOrderRepository _orderRepository;
private readonly ITrackPushRecordEsRepository _trackPushRecordEsRepository;
public TrackPushCompletedEventHandler(ITrackPushRecordEsRepository trackPushRecordEsRepository,
IOrderRepository orderRepository)
public TrackPushCompletedEventHandler(IOrderRepository orderRepository,
ITrackPushRecordEsRepository trackPushRecordEsRepository)
{
_trackPushRecordEsRepository = trackPushRecordEsRepository;
_orderRepository = orderRepository;
_trackPushRecordEsRepository = trackPushRecordEsRepository;
}
[CapSubscribe(GlobalConst.TrackPushCompletedSubscribe, Group = GlobalConst.TrackPushSubscribe)]
public async Task ConsumerAsync(InterfaceRelayForwardReplayEvent @event)
public bool Enable(ConsumeOptions options)
{
return options.Queue == GlobalConst.TrackPushCompletedSubscribe;
}
public async Task Handle(IServiceProvider sp, BasicDeliverEventArgs args, ConsumeOptions options)
{
var msg = Encoding.UTF8.GetString(args.Body.ToArray());
var @event = System.Text.Json.JsonSerializer.Deserialize<InterfaceRelayForwardReplayEvent>(msg);
if (@event == null)
{
LogHelper.Warn(
$"rabbit on queue({options.Queue}) received msg can't convert to {nameof(InterfaceRelayForwardReplayEvent)}");
return;
}
string? logStr = null;
var optionType = Base64Helper.DeSerialize<string>(@event.Attach);
if (optionType == OptionType.新增.ToString())
@ -47,17 +64,6 @@ public class TrackPushCompletedEventHandler : ITransientDependency, ICapSubscrib
// 往es 写推送日志
await _trackPushRecordEsRepository.AddAsync(log);
// if (!log.IsSuccess)
// {
// // 重试过程中不会去更新订单主表
// if (@event.RetryNum < 3)
// {
// @event.RetryNum++;
// await _capPublisher.PublishAsync(GlobalConst.TrackPushSubscribe, @event);
// return;
// }
// }
// 同步去更新订单主表
await TrackPushAfterUpdateOrderAsync(log);
}

View File

@ -79,8 +79,8 @@ public class TrackRefreshEventHandler : ITransientDependency, IRabbitHandler
return;
}
var config = await _trackPullCacheService.GetPullParamsWithContentAsync(attach.SubSystemId,
attach.ServiceProviderId);
var config = await _trackPullCacheService.GetPullParamsWithContentAsync(attach.SubSystemCode,
attach.ServiceProviderCode);
if (config == null)
{
_logger.LogWarning("请求id: {@RequestId},轨迹消费失败,找不到拉取配置:{@Attach}", attach.ToJson(), @event.RequestId);

View File

@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="BSI.Stack.Rabbit" Version="2.0.9" />
<PackageReference Include="SJZY.InterfaceRelay.Application.Contracts" Version="7.2.2"/>
<PackageReference Include="SJZY.InterfaceRelay.Application.Contracts" Version="7.2.3"/>
<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.9-alpha"/>

View File

@ -8,6 +8,8 @@ using SJZY.Track.Application.Contract.Dtos.TrackPull;
using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Application.Helpers;
using SJZY.Track.Application.Rabbit;
using SJZY.Track.Application.Track2InterfaceRelay;
using SJZY.Track.Domain.Dtos.TrackPull;
using SJZY.Track.Domain.Queries;
using Volo.Abp.Http.Client.DynamicProxying;
@ -58,6 +60,7 @@ public class TrackPullService : ApplicationService
{
x.ServiceProviderName,
x.SubSystemId,
x.SubSystemCode,
x.OrderType
}))
{
@ -68,14 +71,20 @@ public class TrackPullService : ApplicationService
var serviceProviderCode = group.FirstOrDefault()!.ServiceProviderCode;
var attach = Base64Helper.SerializeObject(group.Key);
// 批量获取轨迹
var res = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data, GlobalConst.TrackRefreshSubscribe,
attach);
if (res.Code != InterfaceRelayConst.SuccessCode)
using (Track2InterfaceRelaySubSystemContext.Use(
new Track2InterfaceRelaySubSystemContext(group.Key.SubSystemCode)))
{
LogHelper.Error($"刷新轨迹失败:{res.ToJson()}");
// 批量获取轨迹
var res = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data,
GlobalConst.TrackRefreshSubscribe,
attach);
if (res.Code != InterfaceRelayConst.SuccessCode)
{
LogHelper.Error($"刷新轨迹失败:{res.ToJson()}");
}
}
}
@ -90,7 +99,7 @@ public class TrackPullService : ApplicationService
[HttpPost("Track/RefreshForTask")]
public async Task<bool> RefreshForTaskAsync()
{
var configs = await _trackPullCacheService.GetAllPullConfigsAsync();
var configs = await _provideQueries.GetAllPullConfigsAsync();
foreach (var config in configs)
{
@ -118,9 +127,9 @@ public class TrackPullService : ApplicationService
return true;
}
private async Task RefreshForConfigAsync(TrackPullConfigDto config)
private async Task RefreshForConfigAsync(TrackPullConfigVo config)
{
var redisKey = _trackPullCacheService.TrackPullKey(config.SubSystemId, config.ServiceProviderId);
var redisKey = _trackPullCacheService.TrackPullKey(config.SubSystemCode, config.ServiceProviderCode);
if (await RedisHelper.Client.ExistsAsync(redisKey))
{
return;
@ -130,36 +139,38 @@ public class TrackPullService : ApplicationService
{
try
{
var page = 1;
var orders = await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId, page);
while (orders.Any())
using (Track2InterfaceRelaySubSystemContext.Use(
new Track2InterfaceRelaySubSystemContext(config.SubSystemCode)))
{
var serviceProviderCode = orders.FirstOrDefault()?.ServiceProviderCode;
var serviceProviderName = orders.FirstOrDefault()?.ServiceProviderName;
foreach (var group in orders.GroupBy(x => new
var page = 1;
var orders =
await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId, page);
while (orders.Any())
{
x.SubSystemId,
x.OrderType
}))
{
var data = new List<object>(group.Select(x => new TrackPullPayload
{
OrderNo = x.OrderNo
}));
var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(config.ServiceProviderId,
serviceProviderName!, group.Key.SubSystemId, group.Key.OrderType));
var res = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data,
GlobalConst.TrackRefreshSubscribe, attach);
var serviceProviderCode = orders.FirstOrDefault()?.ServiceProviderCode;
var serviceProviderName = orders.FirstOrDefault()?.ServiceProviderName;
if (res.Code != InterfaceRelayConst.SuccessCode)
foreach (var group in orders.GroupBy(x => x.OrderType))
{
LogHelper.Error($"刷新轨迹失败:{res.ToJson()}");
var data = new List<object>(group.Select(x => new TrackPullPayload
{
OrderNo = x.OrderNo
}));
var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(config.ServiceProviderCode,
serviceProviderName!, config.SubSystemCode, config.SubSystemId, group.Key));
var res = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data,
GlobalConst.TrackRefreshSubscribe, attach);
if (res.Code != InterfaceRelayConst.SuccessCode)
{
LogHelper.Error($"刷新轨迹失败:{res.ToJson()}");
}
}
}
orders = await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId, ++page);
orders = await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId,
++page);
}
}
}
catch (Exception e)

View File

@ -1,8 +1,9 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using SJZY.Expand.ABP.Core;
using SJZY.Expand.ABP.Core.Logger;
using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Application.Track2InterfaceRelay;
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
using SJZY.Track.Domain.Aggregates.OrderAggregate;
using SJZY.Track.Domain.Dtos.Forewarning;
@ -77,9 +78,9 @@ public class OrderWarningService
/// <returns></returns>
[AllowAnonymous]
[HttpPost("Track/SendWarningForTask")]
public async Task<bool> SendWarningForTaskAsync([FromBody] IConfiguration configuration)
public async Task<bool> SendWarningForTaskAsync([FromBody] IOptionsSnapshot<Track2InterfaceRelayOptions> options)
{
var configs = configuration.GetSection("SubSystemWarning").Get<Dictionary<string, int>>();
var configs = options.Value;
if (configs == null || configs.Keys.Count == 0)
{
throw new BusinessException("未配置预警系统");
@ -88,21 +89,22 @@ public class OrderWarningService
var subSystemIds = await _orderRepository.GetSubSystemListByCodesAsync(configs.Keys.ToList());
foreach (var item in subSystemIds)
{
var subSystemId = item.id;
// 如果已经发送过通知,不再发送
var redisKey = $"{GlobalConst.ForewarningNotifyCheckKey}:{subSystemIds}";
var redisKey = $"{GlobalConst.ForewarningNotifyCheckKey}:{subSystemId}";
if (await RedisHelper.Client.ExistsAsync(redisKey))
{
continue;
}
await RedisHelper.Client.SetExAsync(redisKey, 30 * 60, 1);
await RedisHelper.Client.SetExAsync(redisKey, configs[item.code].WarningNotifyInterval * 60, 1);
// todo:改mq分流?
_ = Task.Run(async () =>
{
try
{
var cnt = await _forewarningNotifyService.SendNotificationAsync(item.id);
var cnt = await _forewarningNotifyService.SendNotificationAsync(subSystemId);
LogHelper.Info($"预警通知发送成功,新增预警记录{cnt}条");
}
catch (Exception e)

View File

@ -1,78 +1,60 @@
using System.Linq.Expressions;
using SJZY.Expand.ABP.Core;
using SJZY.Track.Application.Contract.Dtos.TrackPull;
using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Dtos.TrackPull;
using Volo.Abp.DependencyInjection;
using Volo.Abp.ObjectMapping;
namespace SJZY.Track.Application.Services.TrackPull;
public class TrackPullCacheService : ApplicationService, ITrackPullCacheService
public class TrackPullCacheService : ITransientDependency, ITrackPullCacheService
{
private readonly IObjectMapper _objectMapper;
private readonly ITrackPullConfigRepository _trackPullConfigRepository;
public TrackPullCacheService(ITrackPullConfigRepository trackPullConfigRepository)
public TrackPullCacheService(ITrackPullConfigRepository trackPullConfigRepository, IObjectMapper objectMapper)
{
_trackPullConfigRepository = trackPullConfigRepository;
_objectMapper = objectMapper;
}
public string TrackPullKey(int subSystemId, int serviceProviderId) =>
$"{GlobalConst.TrackPullKeyPrefix}:{subSystemId}:{serviceProviderId}";
public string TrackPullKey(string subSystemCode, string serviceProviderCode) =>
$"{GlobalConst.TrackPullKeyPrefix}:{subSystemCode}:{serviceProviderCode}";
public string TrackPullContentKey(int subSystemId, int serviceProviderId) =>
$"{GlobalConst.TrackPullContentKeyPrefix}:{subSystemId}:{serviceProviderId}";
public string TrackPullContentKey(string subSystemCode, string serviceProviderCode) =>
$"{GlobalConst.TrackPullContentKeyPrefix}:{subSystemCode}:{serviceProviderCode}";
[NonAction]
public async Task<List<TrackPullConfigDto>> GetAllPullConfigsAsync()
{
return await _trackPullConfigRepository.GetListAsync(x => true,
x => new TrackPullConfigDto
{
SubSystemId = x.SubSystemId,
ServiceProviderId = x.ServiceProviderId,
PullInterval = x.PullInterval
});
}
[NonAction]
public async Task<TrackPullParamsWithContentDto?> GetPullParamsWithContentAsync(int subSystemId,
int serviceProviderId)
public async Task<TrackPullParamsWithContentDto?> GetPullParamsWithContentAsync(string subSystemCode,
string serviceProviderCode)
{
var data = await RedisHelper.Client.GetAsync<TrackPullParamsWithContentDto>(TrackPullContentKey(
subSystemId,
serviceProviderId));
subSystemCode, serviceProviderCode));
data ??= await SetPullConfigAsync(subSystemId: subSystemId, serviceProviderId: serviceProviderId);
var pullId = await _trackPullConfigRepository.FindIdAsync(subSystemCode, serviceProviderCode);
data ??= await SetPullConfigAsync(pullId);
return data;
}
[NonAction]
public async Task<TrackPullParamsWithContentDto?> SetPullConfigAsync(int? id = null, int? subSystemId = null,
int? serviceProviderId = null)
public async Task<TrackPullParamsWithContentDto?> SetPullConfigAsync(int id)
{
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 trackPullConfigDetail = await _trackPullConfigRepository.GetDetailAsync(id);
if (trackPullConfigDetail == null) return null;
var trackPullConfigEntity = await _trackPullConfigRepository.GetFirstAsync(exp);
if (trackPullConfigEntity == null) return null;
var trackPullConfigDetail = await _trackPullConfigRepository.GetDetailAsync(trackPullConfigEntity.Id);
var trackPullContentList = await _trackPullConfigRepository.GetContentListCacheAsync(trackPullConfigEntity.Id);
var trackPullContentList = await _trackPullConfigRepository.GetContentListCacheAsync(id);
if (trackPullContentList.Count == 0) return null;
var data = new TrackPullParamsWithContentDto
{
ParamConfig =
ObjectMapper.Map<GetTrackPullConfigDetailOutputVO, TrackPullParamConfigDto>(trackPullConfigDetail),
ContentConfigs = ObjectMapper.Map<List<GetTrackPullContentListCacheVO>, List<TrackPullContentConfigDto>>(
_objectMapper.Map<GetTrackPullConfigDetailOutputVO, TrackPullParamConfigDto>(trackPullConfigDetail),
ContentConfigs = _objectMapper.Map<List<GetTrackPullContentListCacheVO>, List<TrackPullContentConfigDto>>(
trackPullContentList)
};
await RedisHelper.Client.SetAsync(
TrackPullContentKey(trackPullConfigEntity.SubSystemId, trackPullConfigEntity.ServiceProviderId), data);
TrackPullContentKey(trackPullConfigDetail.SubSystemCode, trackPullConfigDetail.ServiceProviderCode), data);
return data;
}

View File

@ -63,7 +63,7 @@ public class TrackPullService : ApplicationService
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("GetDetail")]
public async Task<GetTrackPullConfigDetailOutputVO> GetDetailAsync(int id)
public async Task<GetTrackPullConfigDetailOutputVO?> GetDetailAsync(int id)
{
return await _trackPullConfigRepository.GetDetailAsync(id);
}
@ -143,7 +143,7 @@ public class TrackPullService : ApplicationService
await _trackPullConfigRepository.UpdateAsync(oldTrackPullEntity);
await _trackPullCacheService.SetPullConfigAsync(input.Id);
await _trackPullCacheService.SetPullConfigAsync(input.Id!.Value);
}
break;
@ -154,7 +154,7 @@ public class TrackPullService : ApplicationService
await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.TrackPullConfigId == input.Id);
await _trackPullCacheService.SetPullConfigAsync(input.Id);
await _trackPullCacheService.SetPullConfigAsync(input.Id!.Value);
ts.Complete();
}
@ -222,7 +222,7 @@ public class TrackPullService : ApplicationService
var entity = ObjectMapper.Map<EditTrackPullContentInput, TrackPullContentConfigEntity>(input);
await _trackPullConfigRepository.InsertContentAsync(entity);
await _trackPullCacheService.SetPullConfigAsync(input.TrackPullConfigId);
await _trackPullCacheService.SetPullConfigAsync(input.TrackPullConfigId!.Value);
break;
}

View File

@ -11,6 +11,7 @@ using SJZY.InterfaceRelay.Application.Contracts;
using SJZY.Track.Application.CAP;
using SJZY.Track.Application.Contract;
using SJZY.Track.Application.Localization;
using SJZY.Track.Application.Track2InterfaceRelay;
using SJZY.UserCenter.Contracts;
using SJZY.UserCenter.SharedModel;
using SJZY.UserCenter.SharedModel.Pub;
@ -68,7 +69,11 @@ public class SjzyTrackApplicationModule : AbpModule
//用户中心
context.Services.AddHttpClientProxies(typeof(SjzyUserCenterHttpApiModule).Assembly, "UserCenter", false);
context.Services.AddHttpClient("InterfaceForward").AddHttpMessageHandler<InterfaceForwardHeaderHandler>();
// 接口通
context.Services.Configure<Track2InterfaceRelayOptions>(configuration.GetSection("Track2InterfaceRelay"));
context.Services.AddHttpClient("InterfaceForward")
.AddHttpMessageHandler<Track2InterfaceRelayHttpMessageHandler>();
context.Services.AddHttpClientProxies(typeof(SJZYInterfaceRelayApplicationContractsModule).Assembly,
"InterfaceForward", false
);

View File

@ -0,0 +1,36 @@
using Microsoft.Extensions.Options;
using SJZY.InterfaceRelay.Application.Contracts;
using Volo.Abp.DependencyInjection;
namespace SJZY.Track.Application.Track2InterfaceRelay;
public class Track2InterfaceRelayHttpMessageHandler : DelegatingHandler, ITransientDependency
{
private readonly Track2InterfaceRelayOptions _options;
public Track2InterfaceRelayHttpMessageHandler(IOptionsSnapshot<Track2InterfaceRelayOptions> options)
{
_options = options.Value;
}
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
CancellationToken cancellationToken)
{
if (Track2InterfaceRelaySubSystemContext.Current == null)
{
throw new BusinessException(message: $"请在{nameof(Track2InterfaceRelaySubSystemContext)}中调用接口通");
}
var subSystemCode = Track2InterfaceRelaySubSystemContext.Current.Code;
var config = _options.GetOrDefault(subSystemCode);
if (config == null)
{
throw new BusinessException(message: $"子系统{subSystemCode}未在轨迹中台配置,请联系管理员");
}
request.Headers.TryAddWithoutValidation(nameof(InterfaceForwardOptions.AppKey), config.AppKey);
request.Headers.TryAddWithoutValidation(nameof(InterfaceForwardOptions.AppSecret), config.AppSecret);
return await base.SendAsync(request, cancellationToken);
}
}

View File

@ -0,0 +1,23 @@
namespace SJZY.Track.Application.Track2InterfaceRelay;
public class Track2InterfaceRelayOptions : Dictionary<string, SubSystemConfig>
{
}
public class SubSystemConfig
{
/// <summary>
/// 接口通appKey
/// </summary>
public string AppKey { get; set; }
/// <summary>
/// 接口通app秘钥
/// </summary>
public string AppSecret { get; set; }
/// <summary>
/// 预警通知间隔(分钟)
/// </summary>
public int WarningNotifyInterval { get; set; } = 30;
}

View File

@ -0,0 +1,21 @@
namespace SJZY.Track.Application.Track2InterfaceRelay;
public class Track2InterfaceRelaySubSystemContext
{
private static readonly AsyncLocal<Track2InterfaceRelaySubSystemContext?> LocalContext = new();
public Track2InterfaceRelaySubSystemContext(string code)
{
Code = code;
}
public string Code { get; set; }
public static Track2InterfaceRelaySubSystemContext? Current => LocalContext.Value;
public static IDisposable Use(Track2InterfaceRelaySubSystemContext context)
{
var previousValue = Current;
LocalContext.Value = context;
return new DisposeAction(() => LocalContext.Value = previousValue);
}
}

View File

@ -31,7 +31,7 @@ public interface ITrackPullConfigRepository : IBasicRepository<TrackPullConfigEn
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<GetTrackPullConfigDetailOutputVO> GetDetailAsync(int id);
Task<GetTrackPullConfigDetailOutputVO?> GetDetailAsync(int id);
/// <summary>
/// 轨迹拉取配置内容详情
@ -49,4 +49,5 @@ public interface ITrackPullConfigRepository : IBasicRepository<TrackPullConfigEn
Task<bool> UpdateContentAsync(TrackPullContentConfigEntity updateObj);
Task<bool> IsContentAnyAsync(Expression<Func<TrackPullContentConfigEntity, bool>> whereExpression);
Task<int> FindIdAsync(string subSystemCode, string serviceProviderCode);
}

View File

@ -21,6 +21,11 @@ public class OrderWithServiceProviderVO
/// </summary>
public string ServiceProviderName { get; set; } = null!;
/// <summary>
/// 子系统code
/// </summary>
public string SubSystemCode { get; set; }
/// <summary>
/// 子系统id
/// </summary>

View File

@ -25,9 +25,9 @@ public class GetTrackPullConfigDetailOutputVO
public string ServiceProvider { get; set; }
/// <summary>
/// 服务商id
/// 服务商code
/// </summary>
public int ServiceProviderId { get; set; }
public string ServiceProviderCode { get; set; }
/// <summary>
/// 子系统
@ -35,9 +35,9 @@ public class GetTrackPullConfigDetailOutputVO
public string SubSystem { get; set; }
/// <summary>
/// 子系统id
/// 子系统code
/// </summary>
public int SubSystemId { get; set; }
public string SubSystemCode { get; set; }
/// <summary>
/// 拉取轨迹时区

View File

@ -1,6 +1,6 @@
namespace SJZY.Track.Application.Contract.Dtos.TrackPull;
namespace SJZY.Track.Domain.Dtos.TrackPull;
public class TrackPullConfigDto
public class TrackPullConfigVo
{
/// <summary>
/// 服务商拉取频率(分钟)
@ -12,6 +12,16 @@ public class TrackPullConfigDto
/// </summary>
public int ServiceProviderId { get; set; }
/// <summary>
/// 服务商code
/// </summary>
public string ServiceProviderCode { get; set; }
/// <summary>
/// 子系统code
/// </summary>
public string SubSystemCode { get; set; }
/// <summary>
/// 子系统id
/// </summary>

View File

@ -1,5 +1,6 @@
using SJZY.Track.Domain.Dtos.Order;
using SJZY.Track.Domain.Dtos.TrackContents;
using SJZY.Track.Domain.Dtos.TrackPull;
namespace SJZY.Track.Domain.Queries;
@ -34,5 +35,17 @@ public interface IProvideQueries
Task<List<OrderWithServiceProviderVO>> FindOrderWithServiceProviderAsync(int serviceProviderId, int pageIndex,
int pageSize = 1000);
/// <summary>
/// 获取轨迹内容
/// </summary>
/// <param name="subSystemId"></param>
/// <param name="trackCode"></param>
/// <returns></returns>
Task<TrackContentVO?> GetTrackContentAsync(int subSystemId, string trackCode);
/// <summary>
/// 获取所有拉取配置
/// </summary>
/// <returns></returns>
Task<List<TrackPullConfigVo>> GetAllPullConfigsAsync();
}

View File

@ -1,8 +1,10 @@
using SJZY.Track.Domain.Aggregates.OrderAggregate;
using SJZY.Track.Domain.Aggregates.TrackContentAggregate;
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
using SJZY.Track.Domain.Dtos.Order;
using SJZY.Track.Domain.Dtos.TrackContents;
using SJZY.Track.Domain.Dtos.TrackPull;
using SJZY.Track.Domain.Queries;
using SJZY.Track.Domain.VEntities;
@ -11,8 +13,7 @@ namespace SJZY.Track.Repository.Queries;
/// <summary>
/// 提供服务相关查询
/// </summary>
public class ProvideQueries : ISugarRepository, IProvideQueries,
ITransientDependency
public class ProvideQueries : ISugarRepository, IProvideQueries, ITransientDependency
{
/// <summary>
/// ctor
@ -22,7 +23,6 @@ public class ProvideQueries : ISugarRepository, IProvideQueries,
Context = SqlsugarScopeBasic.GetContextSafely("default");
}
/// <inheritdoc />
public async Task<List<string>> MapTrackCodesAsync(int upSubSystemId, int subSystemId, params string[] trackCodes)
{
// 根据上游code得到下游code
@ -37,16 +37,18 @@ public class ProvideQueries : ISugarRepository, IProvideQueries,
public async Task<List<OrderWithServiceProviderVO>> FindOrderWithServiceProviderAsync(List<string> orderNos)
{
return await Context.Queryable<OrderEntity>()
.LeftJoin<OrderPullStatusEntity>((a, b) => a.Id == b.OrderId)
.InnerJoin<OrderPullStatusEntity>((a, b) => a.Id == b.OrderId)
.LeftJoin<VServiceProviderEntity>((a, b, c) => b.ServiceProviderCode == c.Code)
.LeftJoin<VSystemEntity>((a, b, c, d) => a.SubSystemId == d.Id)
.Where(a => !a.IsCompleted && orderNos.Contains(a.OrderNo))
.Select((a, b, c) => new OrderWithServiceProviderVO
.Select((a, b, c, d) => new OrderWithServiceProviderVO
{
OrderNo = a.OrderNo,
OrderType = a.OrderType,
ServiceProviderCode = c.Code,
ServiceProviderName = c.Name,
SubSystemId = a.SubSystemId
SubSystemId = a.SubSystemId,
SubSystemCode = d.Key
})
.ToListAsync();
}
@ -58,16 +60,17 @@ public class ProvideQueries : ISugarRepository, IProvideQueries,
return await Context.Queryable<OrderEntity>()
.RightJoin<OrderPullStatusEntity>((a, b) => a.Id == b.OrderId)
.LeftJoin<VServiceProviderEntity>((a, b, c) => b.ServiceProviderCode == c.Code)
.LeftJoin<VSystemEntity>((a, b, c, d) => a.SubSystemId == d.Id)
.Where((a, b, c) => c.Id == serviceProviderId && !a.IsCompleted
&& b.StartTime <= DateTime.Now && b.EndTime >= DateTime.Now)
.Select((a, b, c) => new OrderWithServiceProviderVO
.Select((a, b, c, d) => new OrderWithServiceProviderVO
{
OrderNo = a.OrderNo,
OrderType = a.OrderType,
ServiceProviderCode = c.Code,
ServiceProviderName = c.Name,
SubSystemId = a.SubSystemId,
TrackPullStatus = b.PullStatus
SubSystemCode = d.Key
})
.Skip((pageIndex - 1) * pageSize)
.Take(pageSize)
@ -91,6 +94,22 @@ public class ProvideQueries : ISugarRepository, IProvideQueries,
.FirstAsync();
}
public async Task<List<TrackPullConfigVo>> GetAllPullConfigsAsync()
{
return await Context.Queryable<TrackPullConfigEntity>()
.LeftJoin<VServiceProviderEntity>((a, b) => a.ServiceProviderId == b.Id)
.LeftJoin<VSystemEntity>((a, b, c) => a.SubSystemId == c.Id)
.Select((a, b, c) => new TrackPullConfigVo
{
PullInterval = a.PullInterval,
ServiceProviderId = a.ServiceProviderId,
ServiceProviderCode = b.Code,
SubSystemCode = c.Key,
SubSystemId = c.Id
})
.ToListAsync();
}
/// <summary>
/// db context
/// </summary>

View File

@ -73,22 +73,22 @@ public class TrackPullConfigRepository : BasicRepository<TrackPullConfigEntity>,
.ToListAsync();
}
public async Task<GetTrackPullConfigDetailOutputVO> GetDetailAsync(int id)
public async Task<GetTrackPullConfigDetailOutputVO?> GetDetailAsync(int id)
{
return await AsQueryable()
.LeftJoin<VSystemEntity>((trackPull, system) => trackPull.SubSystemId == system.Id && !system.IsDeleted)
.LeftJoin<VServiceProviderEntity>((trackPull, system, service) =>
trackPull.ServiceProviderId == service.Id && !service.IsDeleted)
.Filter(null, true)
.Where(trackPull => trackPull.Id == id && !trackPull.IsDeleted)
.LeftJoin<VSystemEntity>((trackPull, system) => trackPull.SubSystemId == system.Id)
.LeftJoin<VServiceProviderEntity>((trackPull, system, service) => trackPull.ServiceProviderId == service.Id)
.Where(trackPull => trackPull.Id == id)
.Select(
(trackPull, system, service) => new GetTrackPullConfigDetailOutputVO
{
Id = trackPull.Id,
SubSystem = system.CnName,
SubSystemCode = system.Key,
ServiceProvider = service.Name,
ServiceProviderCode = service.Code,
}, true)
.SingleAsync();
.FirstAsync();
}
public async Task<GetTrackPullContentDetailOutputVO> GetContentDetailAsync(int id)
@ -140,4 +140,14 @@ public class TrackPullConfigRepository : BasicRepository<TrackPullConfigEntity>,
{
return await Context.Queryable<TrackPullContentConfigEntity>().Where(whereExpression).AnyAsync();
}
public async Task<int> FindIdAsync(string subSystemCode, string serviceProviderCode)
{
return await AsQueryable()
.LeftJoin<VSystemEntity>((trackPull, system) => trackPull.SubSystemId == system.Id)
.LeftJoin<VServiceProviderEntity>((trackPull, system, service) => trackPull.ServiceProviderId == service.Id)
.Where((trackPull, system, service) => system.Key == subSystemCode && service.Code == serviceProviderCode)
.Select(trackPull => trackPull.Id)
.FirstAsync();
}
}