对接接口通
This commit is contained in:
parent
ca7b3d7353
commit
9d2c10c4db
@ -2,18 +2,20 @@ namespace SJZY.Track.Application.Contract.Dtos.TrackPull;
|
|||||||
|
|
||||||
public class TrackRefreshAttach
|
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;
|
ServiceProviderName = serviceProviderName;
|
||||||
|
SubSystemCode = subSystemCode;
|
||||||
SubSystemId = subSystemId;
|
SubSystemId = subSystemId;
|
||||||
OrderType = orderType;
|
OrderType = orderType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 服务商id
|
/// 服务商code
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int ServiceProviderId { get; set; }
|
public string ServiceProviderCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 服务商name
|
/// 服务商name
|
||||||
@ -25,6 +27,11 @@ public class TrackRefreshAttach
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int OrderType { get; set; }
|
public int OrderType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 子系统code
|
||||||
|
/// </summary>
|
||||||
|
public string SubSystemCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 子系统id
|
/// 子系统id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -4,31 +4,22 @@ namespace SJZY.Track.Application.Contract.Services;
|
|||||||
|
|
||||||
public interface ITrackPullCacheService
|
public interface ITrackPullCacheService
|
||||||
{
|
{
|
||||||
string TrackPullKey(int subSystemId, int serviceProviderId);
|
string TrackPullKey(string subSystemCode, string serviceProviderCode);
|
||||||
string TrackPullContentKey(int subSystemId, int serviceProviderId);
|
string TrackPullContentKey(string subSystemCode, string serviceProviderCode);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取所有拉取配置
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<List<TrackPullConfigDto>> GetAllPullConfigsAsync();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取服务商拉取配置
|
/// 获取服务商拉取配置
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="subSystemId">子系统id</param>
|
/// <param name="subSystemCode">子系统code</param>
|
||||||
/// <param name="serviceProviderId">服务商id</param>
|
/// <param name="serviceProviderCode">服务商code</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<TrackPullParamsWithContentDto?>
|
Task<TrackPullParamsWithContentDto?>
|
||||||
GetPullParamsWithContentAsync(int subSystemId, int serviceProviderId);
|
GetPullParamsWithContentAsync(string subSystemCode, string serviceProviderCode);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置拉取配置缓存
|
/// 设置拉取配置缓存
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="subSystemId">子系统id</param>
|
|
||||||
/// <param name="serviceProviderId">服务商id</param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<TrackPullParamsWithContentDto?> SetPullConfigAsync(int? id = null, int? subSystemId = null,
|
Task<TrackPullParamsWithContentDto?> SetPullConfigAsync(int id);
|
||||||
int? serviceProviderId = null);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
using DotNetCore.CAP;
|
using System.Text;
|
||||||
|
using BSI.Stack.Rabbit;
|
||||||
|
using BSI.Stack.Rabbit.Handler;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using RabbitMQ.Client.Events;
|
||||||
|
using SJZY.Expand.ABP.Core.Logger;
|
||||||
using SJZY.InterfaceRelay.Application.Contracts;
|
using SJZY.InterfaceRelay.Application.Contracts;
|
||||||
using SJZY.Track.Application.Contract.Dtos.TrackPush;
|
using SJZY.Track.Application.Contract.Dtos.TrackPush;
|
||||||
using SJZY.Track.Application.Helpers;
|
using SJZY.Track.Application.Helpers;
|
||||||
@ -8,23 +12,36 @@ using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
|
|||||||
using SJZY.Track.Domain.Enums;
|
using SJZY.Track.Domain.Enums;
|
||||||
using Volo.Abp.DependencyInjection;
|
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 IOrderRepository _orderRepository;
|
||||||
private readonly ITrackPushRecordEsRepository _trackPushRecordEsRepository;
|
private readonly ITrackPushRecordEsRepository _trackPushRecordEsRepository;
|
||||||
|
|
||||||
public TrackPushCompletedEventHandler(ITrackPushRecordEsRepository trackPushRecordEsRepository,
|
public TrackPushCompletedEventHandler(IOrderRepository orderRepository,
|
||||||
IOrderRepository orderRepository)
|
ITrackPushRecordEsRepository trackPushRecordEsRepository)
|
||||||
{
|
{
|
||||||
_trackPushRecordEsRepository = trackPushRecordEsRepository;
|
|
||||||
_orderRepository = orderRepository;
|
_orderRepository = orderRepository;
|
||||||
|
_trackPushRecordEsRepository = trackPushRecordEsRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
[CapSubscribe(GlobalConst.TrackPushCompletedSubscribe, Group = GlobalConst.TrackPushSubscribe)]
|
public bool Enable(ConsumeOptions options)
|
||||||
public async Task ConsumerAsync(InterfaceRelayForwardReplayEvent @event)
|
|
||||||
{
|
{
|
||||||
|
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;
|
string? logStr = null;
|
||||||
var optionType = Base64Helper.DeSerialize<string>(@event.Attach);
|
var optionType = Base64Helper.DeSerialize<string>(@event.Attach);
|
||||||
if (optionType == OptionType.新增.ToString())
|
if (optionType == OptionType.新增.ToString())
|
||||||
@ -47,17 +64,6 @@ public class TrackPushCompletedEventHandler : ITransientDependency, ICapSubscrib
|
|||||||
// 往es 写推送日志
|
// 往es 写推送日志
|
||||||
await _trackPushRecordEsRepository.AddAsync(log);
|
await _trackPushRecordEsRepository.AddAsync(log);
|
||||||
|
|
||||||
// if (!log.IsSuccess)
|
|
||||||
// {
|
|
||||||
// // 重试过程中不会去更新订单主表
|
|
||||||
// if (@event.RetryNum < 3)
|
|
||||||
// {
|
|
||||||
// @event.RetryNum++;
|
|
||||||
// await _capPublisher.PublishAsync(GlobalConst.TrackPushSubscribe, @event);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 同步去更新订单主表
|
// 同步去更新订单主表
|
||||||
await TrackPushAfterUpdateOrderAsync(log);
|
await TrackPushAfterUpdateOrderAsync(log);
|
||||||
}
|
}
|
||||||
@ -79,8 +79,8 @@ public class TrackRefreshEventHandler : ITransientDependency, IRabbitHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var config = await _trackPullCacheService.GetPullParamsWithContentAsync(attach.SubSystemId,
|
var config = await _trackPullCacheService.GetPullParamsWithContentAsync(attach.SubSystemCode,
|
||||||
attach.ServiceProviderId);
|
attach.ServiceProviderCode);
|
||||||
if (config == null)
|
if (config == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("请求id: {@RequestId},轨迹消费失败,找不到拉取配置:{@Attach}", attach.ToJson(), @event.RequestId);
|
_logger.LogWarning("请求id: {@RequestId},轨迹消费失败,找不到拉取配置:{@Attach}", attach.ToJson(), @event.RequestId);
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="BSI.Stack.Rabbit" Version="2.0.9" />
|
<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.Http.Client" Version="7.0.2" />
|
||||||
<PackageReference Include="Volo.Abp.FluentValidation" Version="7.0.2" />
|
<PackageReference Include="Volo.Abp.FluentValidation" Version="7.0.2" />
|
||||||
<PackageReference Include="SJZY.UserCenter.HttpApi" Version="3.0.9-alpha"/>
|
<PackageReference Include="SJZY.UserCenter.HttpApi" Version="3.0.9-alpha"/>
|
||||||
|
|||||||
@ -8,6 +8,8 @@ using SJZY.Track.Application.Contract.Dtos.TrackPull;
|
|||||||
using SJZY.Track.Application.Contract.Services;
|
using SJZY.Track.Application.Contract.Services;
|
||||||
using SJZY.Track.Application.Helpers;
|
using SJZY.Track.Application.Helpers;
|
||||||
using SJZY.Track.Application.Rabbit;
|
using SJZY.Track.Application.Rabbit;
|
||||||
|
using SJZY.Track.Application.Track2InterfaceRelay;
|
||||||
|
using SJZY.Track.Domain.Dtos.TrackPull;
|
||||||
using SJZY.Track.Domain.Queries;
|
using SJZY.Track.Domain.Queries;
|
||||||
using Volo.Abp.Http.Client.DynamicProxying;
|
using Volo.Abp.Http.Client.DynamicProxying;
|
||||||
|
|
||||||
@ -58,6 +60,7 @@ public class TrackPullService : ApplicationService
|
|||||||
{
|
{
|
||||||
x.ServiceProviderName,
|
x.ServiceProviderName,
|
||||||
x.SubSystemId,
|
x.SubSystemId,
|
||||||
|
x.SubSystemCode,
|
||||||
x.OrderType
|
x.OrderType
|
||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
@ -68,9 +71,14 @@ public class TrackPullService : ApplicationService
|
|||||||
var serviceProviderCode = group.FirstOrDefault()!.ServiceProviderCode;
|
var serviceProviderCode = group.FirstOrDefault()!.ServiceProviderCode;
|
||||||
|
|
||||||
var attach = Base64Helper.SerializeObject(group.Key);
|
var attach = Base64Helper.SerializeObject(group.Key);
|
||||||
|
|
||||||
|
using (Track2InterfaceRelaySubSystemContext.Use(
|
||||||
|
new Track2InterfaceRelaySubSystemContext(group.Key.SubSystemCode)))
|
||||||
|
{
|
||||||
// 批量获取轨迹
|
// 批量获取轨迹
|
||||||
var res = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
|
var res = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
|
||||||
InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data, GlobalConst.TrackRefreshSubscribe,
|
InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data,
|
||||||
|
GlobalConst.TrackRefreshSubscribe,
|
||||||
attach);
|
attach);
|
||||||
|
|
||||||
if (res.Code != InterfaceRelayConst.SuccessCode)
|
if (res.Code != InterfaceRelayConst.SuccessCode)
|
||||||
@ -78,6 +86,7 @@ public class TrackPullService : ApplicationService
|
|||||||
LogHelper.Error($"刷新轨迹失败:{res.ToJson()}");
|
LogHelper.Error($"刷新轨迹失败:{res.ToJson()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -90,7 +99,7 @@ public class TrackPullService : ApplicationService
|
|||||||
[HttpPost("Track/RefreshForTask")]
|
[HttpPost("Track/RefreshForTask")]
|
||||||
public async Task<bool> RefreshForTaskAsync()
|
public async Task<bool> RefreshForTaskAsync()
|
||||||
{
|
{
|
||||||
var configs = await _trackPullCacheService.GetAllPullConfigsAsync();
|
var configs = await _provideQueries.GetAllPullConfigsAsync();
|
||||||
|
|
||||||
foreach (var config in configs)
|
foreach (var config in configs)
|
||||||
{
|
{
|
||||||
@ -118,9 +127,9 @@ public class TrackPullService : ApplicationService
|
|||||||
return true;
|
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))
|
if (await RedisHelper.Client.ExistsAsync(redisKey))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -129,26 +138,26 @@ public class TrackPullService : ApplicationService
|
|||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
using (Track2InterfaceRelaySubSystemContext.Use(
|
||||||
|
new Track2InterfaceRelaySubSystemContext(config.SubSystemCode)))
|
||||||
{
|
{
|
||||||
var page = 1;
|
var page = 1;
|
||||||
var orders = await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId, page);
|
var orders =
|
||||||
|
await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId, page);
|
||||||
while (orders.Any())
|
while (orders.Any())
|
||||||
{
|
{
|
||||||
var serviceProviderCode = orders.FirstOrDefault()?.ServiceProviderCode;
|
var serviceProviderCode = orders.FirstOrDefault()?.ServiceProviderCode;
|
||||||
var serviceProviderName = orders.FirstOrDefault()?.ServiceProviderName;
|
var serviceProviderName = orders.FirstOrDefault()?.ServiceProviderName;
|
||||||
|
|
||||||
foreach (var group in orders.GroupBy(x => new
|
foreach (var group in orders.GroupBy(x => x.OrderType))
|
||||||
{
|
|
||||||
x.SubSystemId,
|
|
||||||
x.OrderType
|
|
||||||
}))
|
|
||||||
{
|
{
|
||||||
var data = new List<object>(group.Select(x => new TrackPullPayload
|
var data = new List<object>(group.Select(x => new TrackPullPayload
|
||||||
{
|
{
|
||||||
OrderNo = x.OrderNo
|
OrderNo = x.OrderNo
|
||||||
}));
|
}));
|
||||||
var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(config.ServiceProviderId,
|
var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(config.ServiceProviderCode,
|
||||||
serviceProviderName!, group.Key.SubSystemId, group.Key.OrderType));
|
serviceProviderName!, config.SubSystemCode, config.SubSystemId, group.Key));
|
||||||
var res = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
|
var res = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
|
||||||
InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data,
|
InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data,
|
||||||
GlobalConst.TrackRefreshSubscribe, attach);
|
GlobalConst.TrackRefreshSubscribe, attach);
|
||||||
@ -159,7 +168,9 @@ public class TrackPullService : ApplicationService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
orders = await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId, ++page);
|
orders = await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId,
|
||||||
|
++page);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Options;
|
||||||
using SJZY.Expand.ABP.Core;
|
using SJZY.Expand.ABP.Core;
|
||||||
using SJZY.Expand.ABP.Core.Logger;
|
using SJZY.Expand.ABP.Core.Logger;
|
||||||
using SJZY.Track.Application.Contract.Services;
|
using SJZY.Track.Application.Contract.Services;
|
||||||
|
using SJZY.Track.Application.Track2InterfaceRelay;
|
||||||
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
|
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
|
||||||
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
||||||
using SJZY.Track.Domain.Dtos.Forewarning;
|
using SJZY.Track.Domain.Dtos.Forewarning;
|
||||||
@ -77,9 +78,9 @@ public class OrderWarningService
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[HttpPost("Track/SendWarningForTask")]
|
[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)
|
if (configs == null || configs.Keys.Count == 0)
|
||||||
{
|
{
|
||||||
throw new BusinessException("未配置预警系统");
|
throw new BusinessException("未配置预警系统");
|
||||||
@ -88,21 +89,22 @@ public class OrderWarningService
|
|||||||
var subSystemIds = await _orderRepository.GetSubSystemListByCodesAsync(configs.Keys.ToList());
|
var subSystemIds = await _orderRepository.GetSubSystemListByCodesAsync(configs.Keys.ToList());
|
||||||
foreach (var item in subSystemIds)
|
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))
|
if (await RedisHelper.Client.ExistsAsync(redisKey))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
await RedisHelper.Client.SetExAsync(redisKey, 30 * 60, 1);
|
await RedisHelper.Client.SetExAsync(redisKey, configs[item.code].WarningNotifyInterval * 60, 1);
|
||||||
|
|
||||||
// todo:改mq分流?
|
// todo:改mq分流?
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var cnt = await _forewarningNotifyService.SendNotificationAsync(item.id);
|
var cnt = await _forewarningNotifyService.SendNotificationAsync(subSystemId);
|
||||||
LogHelper.Info($"预警通知发送成功,新增预警记录{cnt}条");
|
LogHelper.Info($"预警通知发送成功,新增预警记录{cnt}条");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@ -1,78 +1,60 @@
|
|||||||
using System.Linq.Expressions;
|
|
||||||
using SJZY.Expand.ABP.Core;
|
using SJZY.Expand.ABP.Core;
|
||||||
using SJZY.Track.Application.Contract.Dtos.TrackPull;
|
using SJZY.Track.Application.Contract.Dtos.TrackPull;
|
||||||
using SJZY.Track.Application.Contract.Services;
|
using SJZY.Track.Application.Contract.Services;
|
||||||
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
|
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
|
||||||
using SJZY.Track.Domain.Dtos.TrackPull;
|
using SJZY.Track.Domain.Dtos.TrackPull;
|
||||||
|
using Volo.Abp.DependencyInjection;
|
||||||
|
using Volo.Abp.ObjectMapping;
|
||||||
|
|
||||||
namespace SJZY.Track.Application.Services.TrackPull;
|
namespace SJZY.Track.Application.Services.TrackPull;
|
||||||
|
|
||||||
public class TrackPullCacheService : ApplicationService, ITrackPullCacheService
|
public class TrackPullCacheService : ITransientDependency, ITrackPullCacheService
|
||||||
{
|
{
|
||||||
|
private readonly IObjectMapper _objectMapper;
|
||||||
private readonly ITrackPullConfigRepository _trackPullConfigRepository;
|
private readonly ITrackPullConfigRepository _trackPullConfigRepository;
|
||||||
|
|
||||||
public TrackPullCacheService(ITrackPullConfigRepository trackPullConfigRepository)
|
public TrackPullCacheService(ITrackPullConfigRepository trackPullConfigRepository, IObjectMapper objectMapper)
|
||||||
{
|
{
|
||||||
_trackPullConfigRepository = trackPullConfigRepository;
|
_trackPullConfigRepository = trackPullConfigRepository;
|
||||||
|
_objectMapper = objectMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string TrackPullKey(int subSystemId, int serviceProviderId) =>
|
public string TrackPullKey(string subSystemCode, string serviceProviderCode) =>
|
||||||
$"{GlobalConst.TrackPullKeyPrefix}:{subSystemId}:{serviceProviderId}";
|
$"{GlobalConst.TrackPullKeyPrefix}:{subSystemCode}:{serviceProviderCode}";
|
||||||
|
|
||||||
public string TrackPullContentKey(int subSystemId, int serviceProviderId) =>
|
public string TrackPullContentKey(string subSystemCode, string serviceProviderCode) =>
|
||||||
$"{GlobalConst.TrackPullContentKeyPrefix}:{subSystemId}:{serviceProviderId}";
|
$"{GlobalConst.TrackPullContentKeyPrefix}:{subSystemCode}:{serviceProviderCode}";
|
||||||
|
|
||||||
[NonAction]
|
public async Task<TrackPullParamsWithContentDto?> GetPullParamsWithContentAsync(string subSystemCode,
|
||||||
public async Task<List<TrackPullConfigDto>> GetAllPullConfigsAsync()
|
string serviceProviderCode)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
var data = await RedisHelper.Client.GetAsync<TrackPullParamsWithContentDto>(TrackPullContentKey(
|
var data = await RedisHelper.Client.GetAsync<TrackPullParamsWithContentDto>(TrackPullContentKey(
|
||||||
subSystemId,
|
subSystemCode, serviceProviderCode));
|
||||||
serviceProviderId));
|
|
||||||
|
|
||||||
data ??= await SetPullConfigAsync(subSystemId: subSystemId, serviceProviderId: serviceProviderId);
|
var pullId = await _trackPullConfigRepository.FindIdAsync(subSystemCode, serviceProviderCode);
|
||||||
|
data ??= await SetPullConfigAsync(pullId);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
[NonAction]
|
public async Task<TrackPullParamsWithContentDto?> SetPullConfigAsync(int id)
|
||||||
public async Task<TrackPullParamsWithContentDto?> SetPullConfigAsync(int? id = null, int? subSystemId = null,
|
|
||||||
int? serviceProviderId = null)
|
|
||||||
{
|
{
|
||||||
Expression<Func<TrackPullConfigEntity, bool>> exp = x => true;
|
var trackPullConfigDetail = await _trackPullConfigRepository.GetDetailAsync(id);
|
||||||
if (id.HasValue) exp = x => x.Id == id;
|
if (trackPullConfigDetail == null) return null;
|
||||||
else if (subSystemId.HasValue && serviceProviderId.HasValue)
|
|
||||||
exp = x => x.SubSystemId == subSystemId && x.ServiceProviderId == serviceProviderId;
|
|
||||||
|
|
||||||
var trackPullConfigEntity = await _trackPullConfigRepository.GetFirstAsync(exp);
|
var trackPullContentList = await _trackPullConfigRepository.GetContentListCacheAsync(id);
|
||||||
if (trackPullConfigEntity == null) return null;
|
|
||||||
|
|
||||||
var trackPullConfigDetail = await _trackPullConfigRepository.GetDetailAsync(trackPullConfigEntity.Id);
|
|
||||||
var trackPullContentList = await _trackPullConfigRepository.GetContentListCacheAsync(trackPullConfigEntity.Id);
|
|
||||||
if (trackPullContentList.Count == 0) return null;
|
if (trackPullContentList.Count == 0) return null;
|
||||||
|
|
||||||
var data = new TrackPullParamsWithContentDto
|
var data = new TrackPullParamsWithContentDto
|
||||||
{
|
{
|
||||||
ParamConfig =
|
ParamConfig =
|
||||||
ObjectMapper.Map<GetTrackPullConfigDetailOutputVO, TrackPullParamConfigDto>(trackPullConfigDetail),
|
_objectMapper.Map<GetTrackPullConfigDetailOutputVO, TrackPullParamConfigDto>(trackPullConfigDetail),
|
||||||
ContentConfigs = ObjectMapper.Map<List<GetTrackPullContentListCacheVO>, List<TrackPullContentConfigDto>>(
|
ContentConfigs = _objectMapper.Map<List<GetTrackPullContentListCacheVO>, List<TrackPullContentConfigDto>>(
|
||||||
trackPullContentList)
|
trackPullContentList)
|
||||||
};
|
};
|
||||||
|
|
||||||
await RedisHelper.Client.SetAsync(
|
await RedisHelper.Client.SetAsync(
|
||||||
TrackPullContentKey(trackPullConfigEntity.SubSystemId, trackPullConfigEntity.ServiceProviderId), data);
|
TrackPullContentKey(trackPullConfigDetail.SubSystemCode, trackPullConfigDetail.ServiceProviderCode), data);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public class TrackPullService : ApplicationService
|
|||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("GetDetail")]
|
[HttpGet("GetDetail")]
|
||||||
public async Task<GetTrackPullConfigDetailOutputVO> GetDetailAsync(int id)
|
public async Task<GetTrackPullConfigDetailOutputVO?> GetDetailAsync(int id)
|
||||||
{
|
{
|
||||||
return await _trackPullConfigRepository.GetDetailAsync(id);
|
return await _trackPullConfigRepository.GetDetailAsync(id);
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ public class TrackPullService : ApplicationService
|
|||||||
|
|
||||||
await _trackPullConfigRepository.UpdateAsync(oldTrackPullEntity);
|
await _trackPullConfigRepository.UpdateAsync(oldTrackPullEntity);
|
||||||
|
|
||||||
await _trackPullCacheService.SetPullConfigAsync(input.Id);
|
await _trackPullCacheService.SetPullConfigAsync(input.Id!.Value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ public class TrackPullService : ApplicationService
|
|||||||
|
|
||||||
await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.TrackPullConfigId == input.Id);
|
await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.TrackPullConfigId == input.Id);
|
||||||
|
|
||||||
await _trackPullCacheService.SetPullConfigAsync(input.Id);
|
await _trackPullCacheService.SetPullConfigAsync(input.Id!.Value);
|
||||||
ts.Complete();
|
ts.Complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ public class TrackPullService : ApplicationService
|
|||||||
var entity = ObjectMapper.Map<EditTrackPullContentInput, TrackPullContentConfigEntity>(input);
|
var entity = ObjectMapper.Map<EditTrackPullContentInput, TrackPullContentConfigEntity>(input);
|
||||||
|
|
||||||
await _trackPullConfigRepository.InsertContentAsync(entity);
|
await _trackPullConfigRepository.InsertContentAsync(entity);
|
||||||
await _trackPullCacheService.SetPullConfigAsync(input.TrackPullConfigId);
|
await _trackPullCacheService.SetPullConfigAsync(input.TrackPullConfigId!.Value);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ using SJZY.InterfaceRelay.Application.Contracts;
|
|||||||
using SJZY.Track.Application.CAP;
|
using SJZY.Track.Application.CAP;
|
||||||
using SJZY.Track.Application.Contract;
|
using SJZY.Track.Application.Contract;
|
||||||
using SJZY.Track.Application.Localization;
|
using SJZY.Track.Application.Localization;
|
||||||
|
using SJZY.Track.Application.Track2InterfaceRelay;
|
||||||
using SJZY.UserCenter.Contracts;
|
using SJZY.UserCenter.Contracts;
|
||||||
using SJZY.UserCenter.SharedModel;
|
using SJZY.UserCenter.SharedModel;
|
||||||
using SJZY.UserCenter.SharedModel.Pub;
|
using SJZY.UserCenter.SharedModel.Pub;
|
||||||
@ -68,7 +69,11 @@ public class SjzyTrackApplicationModule : AbpModule
|
|||||||
|
|
||||||
//用户中心
|
//用户中心
|
||||||
context.Services.AddHttpClientProxies(typeof(SjzyUserCenterHttpApiModule).Assembly, "UserCenter", false);
|
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,
|
context.Services.AddHttpClientProxies(typeof(SJZYInterfaceRelayApplicationContractsModule).Assembly,
|
||||||
"InterfaceForward", false
|
"InterfaceForward", false
|
||||||
);
|
);
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -31,7 +31,7 @@ public interface ITrackPullConfigRepository : IBasicRepository<TrackPullConfigEn
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<GetTrackPullConfigDetailOutputVO> GetDetailAsync(int id);
|
Task<GetTrackPullConfigDetailOutputVO?> GetDetailAsync(int id);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 轨迹拉取配置内容详情
|
/// 轨迹拉取配置内容详情
|
||||||
@ -49,4 +49,5 @@ public interface ITrackPullConfigRepository : IBasicRepository<TrackPullConfigEn
|
|||||||
Task<bool> UpdateContentAsync(TrackPullContentConfigEntity updateObj);
|
Task<bool> UpdateContentAsync(TrackPullContentConfigEntity updateObj);
|
||||||
|
|
||||||
Task<bool> IsContentAnyAsync(Expression<Func<TrackPullContentConfigEntity, bool>> whereExpression);
|
Task<bool> IsContentAnyAsync(Expression<Func<TrackPullContentConfigEntity, bool>> whereExpression);
|
||||||
|
Task<int> FindIdAsync(string subSystemCode, string serviceProviderCode);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,11 @@ public class OrderWithServiceProviderVO
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string ServiceProviderName { get; set; } = null!;
|
public string ServiceProviderName { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 子系统code
|
||||||
|
/// </summary>
|
||||||
|
public string SubSystemCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 子系统id
|
/// 子系统id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -25,9 +25,9 @@ public class GetTrackPullConfigDetailOutputVO
|
|||||||
public string ServiceProvider { get; set; }
|
public string ServiceProvider { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 服务商id
|
/// 服务商code
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int ServiceProviderId { get; set; }
|
public string ServiceProviderCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 子系统
|
/// 子系统
|
||||||
@ -35,9 +35,9 @@ public class GetTrackPullConfigDetailOutputVO
|
|||||||
public string SubSystem { get; set; }
|
public string SubSystem { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 子系统id
|
/// 子系统code
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int SubSystemId { get; set; }
|
public string SubSystemCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 拉取轨迹时区
|
/// 拉取轨迹时区
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
namespace SJZY.Track.Application.Contract.Dtos.TrackPull;
|
namespace SJZY.Track.Domain.Dtos.TrackPull;
|
||||||
|
|
||||||
public class TrackPullConfigDto
|
public class TrackPullConfigVo
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 服务商拉取频率(分钟)
|
/// 服务商拉取频率(分钟)
|
||||||
@ -12,6 +12,16 @@ public class TrackPullConfigDto
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int ServiceProviderId { get; set; }
|
public int ServiceProviderId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 服务商code
|
||||||
|
/// </summary>
|
||||||
|
public string ServiceProviderCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 子系统code
|
||||||
|
/// </summary>
|
||||||
|
public string SubSystemCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 子系统id
|
/// 子系统id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -1,5 +1,6 @@
|
|||||||
using SJZY.Track.Domain.Dtos.Order;
|
using SJZY.Track.Domain.Dtos.Order;
|
||||||
using SJZY.Track.Domain.Dtos.TrackContents;
|
using SJZY.Track.Domain.Dtos.TrackContents;
|
||||||
|
using SJZY.Track.Domain.Dtos.TrackPull;
|
||||||
|
|
||||||
namespace SJZY.Track.Domain.Queries;
|
namespace SJZY.Track.Domain.Queries;
|
||||||
|
|
||||||
@ -34,5 +35,17 @@ public interface IProvideQueries
|
|||||||
Task<List<OrderWithServiceProviderVO>> FindOrderWithServiceProviderAsync(int serviceProviderId, int pageIndex,
|
Task<List<OrderWithServiceProviderVO>> FindOrderWithServiceProviderAsync(int serviceProviderId, int pageIndex,
|
||||||
int pageSize = 1000);
|
int pageSize = 1000);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取轨迹内容
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="subSystemId"></param>
|
||||||
|
/// <param name="trackCode"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task<TrackContentVO?> GetTrackContentAsync(int subSystemId, string trackCode);
|
Task<TrackContentVO?> GetTrackContentAsync(int subSystemId, string trackCode);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取所有拉取配置
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<List<TrackPullConfigVo>> GetAllPullConfigsAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
||||||
using SJZY.Track.Domain.Aggregates.TrackContentAggregate;
|
using SJZY.Track.Domain.Aggregates.TrackContentAggregate;
|
||||||
|
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
|
||||||
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
|
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
|
||||||
using SJZY.Track.Domain.Dtos.Order;
|
using SJZY.Track.Domain.Dtos.Order;
|
||||||
using SJZY.Track.Domain.Dtos.TrackContents;
|
using SJZY.Track.Domain.Dtos.TrackContents;
|
||||||
|
using SJZY.Track.Domain.Dtos.TrackPull;
|
||||||
using SJZY.Track.Domain.Queries;
|
using SJZY.Track.Domain.Queries;
|
||||||
using SJZY.Track.Domain.VEntities;
|
using SJZY.Track.Domain.VEntities;
|
||||||
|
|
||||||
@ -11,8 +13,7 @@ namespace SJZY.Track.Repository.Queries;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 提供服务相关查询
|
/// 提供服务相关查询
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ProvideQueries : ISugarRepository, IProvideQueries,
|
public class ProvideQueries : ISugarRepository, IProvideQueries, ITransientDependency
|
||||||
ITransientDependency
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ctor
|
/// ctor
|
||||||
@ -22,7 +23,6 @@ public class ProvideQueries : ISugarRepository, IProvideQueries,
|
|||||||
Context = SqlsugarScopeBasic.GetContextSafely("default");
|
Context = SqlsugarScopeBasic.GetContextSafely("default");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public async Task<List<string>> MapTrackCodesAsync(int upSubSystemId, int subSystemId, params string[] trackCodes)
|
public async Task<List<string>> MapTrackCodesAsync(int upSubSystemId, int subSystemId, params string[] trackCodes)
|
||||||
{
|
{
|
||||||
// 根据上游code得到下游code
|
// 根据上游code得到下游code
|
||||||
@ -37,16 +37,18 @@ public class ProvideQueries : ISugarRepository, IProvideQueries,
|
|||||||
public async Task<List<OrderWithServiceProviderVO>> FindOrderWithServiceProviderAsync(List<string> orderNos)
|
public async Task<List<OrderWithServiceProviderVO>> FindOrderWithServiceProviderAsync(List<string> orderNos)
|
||||||
{
|
{
|
||||||
return await Context.Queryable<OrderEntity>()
|
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<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))
|
.Where(a => !a.IsCompleted && orderNos.Contains(a.OrderNo))
|
||||||
.Select((a, b, c) => new OrderWithServiceProviderVO
|
.Select((a, b, c, d) => new OrderWithServiceProviderVO
|
||||||
{
|
{
|
||||||
OrderNo = a.OrderNo,
|
OrderNo = a.OrderNo,
|
||||||
OrderType = a.OrderType,
|
OrderType = a.OrderType,
|
||||||
ServiceProviderCode = c.Code,
|
ServiceProviderCode = c.Code,
|
||||||
ServiceProviderName = c.Name,
|
ServiceProviderName = c.Name,
|
||||||
SubSystemId = a.SubSystemId
|
SubSystemId = a.SubSystemId,
|
||||||
|
SubSystemCode = d.Key
|
||||||
})
|
})
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
@ -58,16 +60,17 @@ public class ProvideQueries : ISugarRepository, IProvideQueries,
|
|||||||
return await Context.Queryable<OrderEntity>()
|
return await Context.Queryable<OrderEntity>()
|
||||||
.RightJoin<OrderPullStatusEntity>((a, b) => a.Id == b.OrderId)
|
.RightJoin<OrderPullStatusEntity>((a, b) => a.Id == b.OrderId)
|
||||||
.LeftJoin<VServiceProviderEntity>((a, b, c) => b.ServiceProviderCode == c.Code)
|
.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
|
.Where((a, b, c) => c.Id == serviceProviderId && !a.IsCompleted
|
||||||
&& b.StartTime <= DateTime.Now && b.EndTime >= DateTime.Now)
|
&& b.StartTime <= DateTime.Now && b.EndTime >= DateTime.Now)
|
||||||
.Select((a, b, c) => new OrderWithServiceProviderVO
|
.Select((a, b, c, d) => new OrderWithServiceProviderVO
|
||||||
{
|
{
|
||||||
OrderNo = a.OrderNo,
|
OrderNo = a.OrderNo,
|
||||||
OrderType = a.OrderType,
|
OrderType = a.OrderType,
|
||||||
ServiceProviderCode = c.Code,
|
ServiceProviderCode = c.Code,
|
||||||
ServiceProviderName = c.Name,
|
ServiceProviderName = c.Name,
|
||||||
SubSystemId = a.SubSystemId,
|
SubSystemId = a.SubSystemId,
|
||||||
TrackPullStatus = b.PullStatus
|
SubSystemCode = d.Key
|
||||||
})
|
})
|
||||||
.Skip((pageIndex - 1) * pageSize)
|
.Skip((pageIndex - 1) * pageSize)
|
||||||
.Take(pageSize)
|
.Take(pageSize)
|
||||||
@ -91,6 +94,22 @@ public class ProvideQueries : ISugarRepository, IProvideQueries,
|
|||||||
.FirstAsync();
|
.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>
|
/// <summary>
|
||||||
/// db context
|
/// db context
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -73,22 +73,22 @@ public class TrackPullConfigRepository : BasicRepository<TrackPullConfigEntity>,
|
|||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<GetTrackPullConfigDetailOutputVO> GetDetailAsync(int id)
|
public async Task<GetTrackPullConfigDetailOutputVO?> GetDetailAsync(int id)
|
||||||
{
|
{
|
||||||
return await AsQueryable()
|
return await AsQueryable()
|
||||||
.LeftJoin<VSystemEntity>((trackPull, system) => trackPull.SubSystemId == system.Id && !system.IsDeleted)
|
.LeftJoin<VSystemEntity>((trackPull, system) => trackPull.SubSystemId == system.Id)
|
||||||
.LeftJoin<VServiceProviderEntity>((trackPull, system, service) =>
|
.LeftJoin<VServiceProviderEntity>((trackPull, system, service) => trackPull.ServiceProviderId == service.Id)
|
||||||
trackPull.ServiceProviderId == service.Id && !service.IsDeleted)
|
.Where(trackPull => trackPull.Id == id)
|
||||||
.Filter(null, true)
|
|
||||||
.Where(trackPull => trackPull.Id == id && !trackPull.IsDeleted)
|
|
||||||
.Select(
|
.Select(
|
||||||
(trackPull, system, service) => new GetTrackPullConfigDetailOutputVO
|
(trackPull, system, service) => new GetTrackPullConfigDetailOutputVO
|
||||||
{
|
{
|
||||||
Id = trackPull.Id,
|
Id = trackPull.Id,
|
||||||
SubSystem = system.CnName,
|
SubSystem = system.CnName,
|
||||||
|
SubSystemCode = system.Key,
|
||||||
ServiceProvider = service.Name,
|
ServiceProvider = service.Name,
|
||||||
|
ServiceProviderCode = service.Code,
|
||||||
}, true)
|
}, true)
|
||||||
.SingleAsync();
|
.FirstAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<GetTrackPullContentDetailOutputVO> GetContentDetailAsync(int id)
|
public async Task<GetTrackPullContentDetailOutputVO> GetContentDetailAsync(int id)
|
||||||
@ -140,4 +140,14 @@ public class TrackPullConfigRepository : BasicRepository<TrackPullConfigEntity>,
|
|||||||
{
|
{
|
||||||
return await Context.Queryable<TrackPullContentConfigEntity>().Where(whereExpression).AnyAsync();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user