This commit is contained in:
xiaolipro 2025-08-01 18:01:44 +08:00
parent e25b0ba048
commit 44fddf4843
6 changed files with 52 additions and 78 deletions

View File

@ -1,3 +1,4 @@
using InterfaceForward.Domain.Shared.Helpers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Options;
using TrackCenter.Application.Dtos.ProvideServices;
@ -18,16 +19,16 @@ namespace TrackCenter.Application.Services.ProvideServices;
[Route("/ProviderService")]
public class TrackPullService : ApplicationServiceBase
{
private readonly IHttpClientProxy<IInterfaceForwardServiceV2> _httpClientProxy;
private readonly IOptionsMonitor<InterfaceRelayParamsConfigOptions> _options;
private readonly ProvideQueries _provideQueries;
private readonly InterfaceForwardService _interfaceForwardService;
public TrackPullService(ProvideQueries provideQueries,
IHttpClientProxy<IInterfaceForwardServiceV2> httpClientProxy,
InterfaceForwardService interfaceForwardService,
IOptionsMonitor<InterfaceRelayParamsConfigOptions> options)
{
_provideQueries = provideQueries;
_httpClientProxy = httpClientProxy;
_interfaceForwardService = interfaceForwardService;
_options = options;
}
@ -73,7 +74,7 @@ public class TrackPullService : ApplicationServiceBase
new Track2InterfaceRelaySubSystemContext(group.Key.SubSystemCode)))
{
// 批量获取轨迹
var res = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
var res = await _interfaceForwardService.BatchForwardThenPushToQueueAsync(
_options.CurrentValue.GetTrackInterfaceCode, serviceProviderCode, data,
GlobalConst.TrackRefreshSubscribe,
attach);

View File

@ -1,19 +1,15 @@
using DotNetCore.CAP;
using SJZY.Expand.ABP.Core.Common;
using TrackCenter.Application.Dtos.ProvideServices;
using TrackCenter.Application.Dtos.TrackOrder;
using TrackCenter.Application.Dtos.TrackPush;
using TrackCenter.Application.Events;
using TrackCenter.Application.Services.ProvideServices;
using TrackCenter.Domain.Aggregates.OrderAggregate;
using TrackCenter.Domain.Aggregates.TrackDetailsAggregate;
using TrackCenter.Domain.Aggregates.TrackPushAggregate;
using TrackCenter.Domain.Dtos.TrackPush;
using TrackCenter.Domain.Extensions;
using TrackCenter.Domain.Queries;
using SJZY.UserCenter.HttpApi.Services.User;
using TrackCenter.Application.Helpers;
using Volo.Abp.Http.Client.DynamicProxying;
using TrackCenter.Application.Queries;
namespace TrackCenter.Application.Services.ProvideServices;
@ -22,12 +18,11 @@ namespace TrackCenter.Application.Services.ProvideServices;
/// </summary>
[ApiExplorerSettings(GroupName = "提供接口")]
[Route("/ProviderService")]
public class TrackPushService : ApplicationServiceBase, ITrackPushService
public class TrackPushService : ApplicationServiceBase
{
private readonly ICapPublisher _capPublisher;
private readonly IOrderRepository _orderRepository;
private readonly IProvideQueries _provideQueries;
private readonly IHttpClientProxy<IUserBaseInfoService> _requestCurrentUserService;
private readonly ProvideQueries _provideQueries;
private readonly ITrackPushConfigRepository _trackPushConfigRepository;
private readonly ITrackPushRecordEsRepository _trackPushRecordEsRepository;
private readonly ITrackDetailsEsRepository _trackDetailsEsRepository;
@ -35,14 +30,12 @@ public class TrackPushService : ApplicationServiceBase, ITrackPushService
public TrackPushService(IOrderRepository orderRepository
, ICapPublisher capPublisher
, ITrackPushRecordEsRepository trackPushRecordEsRepository
, IHttpClientProxy<IUserBaseInfoService> requestCurrentUserService
, ITrackPushConfigRepository trackPushConfigRepository, IProvideQueries provideQueries,
, ITrackPushConfigRepository trackPushConfigRepository, ProvideQueries provideQueries,
ITrackDetailsEsRepository trackDetailsEsRepository)
{
_orderRepository = orderRepository;
_capPublisher = capPublisher;
_trackPushRecordEsRepository = trackPushRecordEsRepository;
_requestCurrentUserService = requestCurrentUserService;
_trackPushConfigRepository = trackPushConfigRepository;
_provideQueries = provideQueries;
_trackDetailsEsRepository = trackDetailsEsRepository;
@ -54,13 +47,12 @@ public class TrackPushService : ApplicationServiceBase, ITrackPushService
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("Track/Push")]
[CustomerResult]
public async Task<UnifyResultDto> PushTrackAsync(PushTrackInput input)
public async Task PushTrackAsync(PushTrackInput input)
{
input.OrderNos = input.OrderNos.Where(x => !x.IsNullOrWhiteSpace()).Distinct().ToList(); // 单号去重、去空
var subSystemCode = await _provideQueries.SubSystemId2CodeAsync(input.SubSystemId);
var orders = await _orderRepository.GetArrayAsync(x =>
var orders = await _orderRepository.GetListAsync(x =>
x.SubSystemId == input.SubSystemId
&& x.OrderType == input.OrderType
&& input.OrderNos.Contains(x.OrderNo), x => new
@ -73,14 +65,7 @@ public class TrackPushService : ApplicationServiceBase, ITrackPushService
{
throw new BusinessException(message: "一个订单都不存在");
}
var userInfo = await _requestCurrentUserService.Service.GetCurrentUserBasicInfoAsync();
if (userInfo.Code != GlobalConst.SuccessCode || userInfo.Data is null)
{
throw new BusinessException(message: $"调用用户中心,获取用户信息失败:{userInfo.Msg}");
}
var name = userInfo.Data.UserName;
var name = CurrentUser.UserName;
//查出可能需要推送的轨迹
var tracks = await _trackDetailsEsRepository.GetListAsync(input.SubSystemId, input.OrderType, input.OrderNos, new List<string>
@ -136,9 +121,9 @@ public class TrackPushService : ApplicationServiceBase, ITrackPushService
SubSystemId = input.SubSystemId,
SubSystemCode = subSystemCode,
CustomId = order.CustomId,
OrderIdTrackMetadataDict = new Dictionary<int, KeyValuePair<string, long>>
OrderIdTrackMetadataDict = new Dictionary<int, TrackMetadata>
{
[order.Id] = KeyValuePair.Create(track.Id, track.Version)
[order.Id] = TrackMetadata.Build(track.Id, track.Version, track.CreateTime)
},
// OrderIds = new[] { order.Id },
TrackCode = input.TrackCode,
@ -160,7 +145,7 @@ public class TrackPushService : ApplicationServiceBase, ITrackPushService
await _capPublisher.PublishAsync(GlobalConst.TrackManualPushSubscribe, trackPushEvent);
}
return new UnifyResultDto(true, $"即将推送轨迹代码{input.TrackCode}给{orderIdTrackDict.Count}个订单");
LogHelper.Info($"即将推送轨迹代码{input.TrackCode}给{orderIdTrackDict.Count}个订单");
}
@ -171,14 +156,13 @@ public class TrackPushService : ApplicationServiceBase, ITrackPushService
/// <param name="customerId"></param>
/// <returns></returns>
[HttpGet("Track/GetTrackPushContentList")]
[CustomerResult]
public async Task<UnifyResultDto<List<TrackPushContentDto>>> GetTrackPushContentListAsync(int subSystemId, int customerId)
public async Task<List<TrackPushContentDto>> GetTrackPushContentListAsync(int subSystemId, int customerId)
{
var list = await _trackPushConfigRepository.GetTrackPushContentListAsync(subSystemId, customerId);
var result = ObjectMapper.Map<List<GetTrackPushContentListVo>, List<TrackPushContentDto>>(list);
return new UnifyResultDto<List<TrackPushContentDto>>(true, result, "操作成功");
return result;
}
/// <summary>
@ -187,8 +171,7 @@ public class TrackPushService : ApplicationServiceBase, ITrackPushService
/// <returns></returns>
/// <param name="input"></param>
[HttpGet("Track/GetTrackPushRecords")]
[CustomerResult]
public async Task<UnifyResultDto<List<TrackPushRecordOutput>>> GetTrackPushRecordsAsync([FromQuery] OrderNoInfo input)
public async Task<List<TrackPushRecordOutput>> GetTrackPushRecordsAsync([FromQuery] OrderNoInfo input)
{
var orderId = await _orderRepository.GetFirstAsync(x =>
x.SubSystemId == input.SubSystemId
@ -204,7 +187,7 @@ public class TrackPushService : ApplicationServiceBase, ITrackPushService
var records = await _trackPushRecordEsRepository.GetTrackPushRecordsAsync(orderId);
var res = ObjectMapper.Map<List<TrackPushRecordIndex>, List<TrackPushRecordOutput>>(records);
return new UnifyResultDto<List<TrackPushRecordOutput>>(true, res, "操作成功");
return res;
}
/// <summary>
@ -214,8 +197,7 @@ public class TrackPushService : ApplicationServiceBase, ITrackPushService
/// <returns></returns>
/// <exception cref="BusinessException"></exception>
[HttpPost("Track/QueryTrackPushRecords")]
[CustomerResult]
public async Task<UnifyResultDto<List<TrackPushRecordOutput>>> QueryTrackPushRecordsAsync(QueryPushRecordInput input)
public async Task<List<TrackPushRecordOutput>> QueryTrackPushRecordsAsync(QueryPushRecordInput input)
{
var orderIds = await _orderRepository.GetListAsync(
x => x.SubSystemId == input.SubSystemId
@ -258,10 +240,10 @@ public class TrackPushService : ApplicationServiceBase, ITrackPushService
TrackPushTimeEnd = input.TrackPushTimeEnd?.AddHours(-8),
});
if (records.Count == 0) return new UnifyResultDto<List<TrackPushRecordOutput>>(true, new List<TrackPushRecordOutput>(), "操作成功");
if (records.Count == 0) return new List<TrackPushRecordOutput>();
var res = ObjectMapper.Map<List<TrackPushRecordIndex>, List<TrackPushRecordOutput>>(records);
return new UnifyResultDto<List<TrackPushRecordOutput>>(true, res, "操作成功");
return res;
}
}

View File

@ -139,12 +139,7 @@ public partial class TrackService
EnContent = x.TrackEnContent,
OriginContent = x.OriginTrackContent,
Location = x.TrackPlace,
Time = Math.Abs(x.TrackTimeZone - GlobalConst.NoneTrackTimeZone) < 1
? x.TrackTime
: x.ZeroTrackTime.AddHours(input.TimeZone ?? 8),
TimeZone = Math.Abs(x.TrackTimeZone - GlobalConst.NoneTrackTimeZone) < 1
? null
: input.TimeZone ?? 8,
Time = x.TrackTime,
IsExternal = x.IsExternal,
Source = x.Source,
Remarks = x.Remarks,
@ -164,10 +159,7 @@ public partial class TrackService
DestinationTimeZone = x.DestinationTimeZone,
EstimatedDeliveryDate = x.EstimatedDeliveryDate,
Extra = x.Extra,
CreateUser = x.CreateUser,
CreateTime = x.CreateTime,
PodFileUrls = x.PodFileUrls?.Split(",").ToList() ?? Empty<string>.List,
TrackFlags = BuildTrackFlags(trackFlagIdsDict, flagDict, x)
}).ToList();
res.Add(item);
@ -176,7 +168,7 @@ public partial class TrackService
// 排序
var sortedList = await TracksOrdered(res, input, input.SortMethod);
return new UnifyResultDto<List<GetTrackOutput>>(true, sortedList, "操作成功");
return sortedList;
}
//内部系统展示所有轨迹,外部系统则要求过滤外部轨迹

View File

@ -1,3 +1,4 @@
using InterfaceForward.Domain.Shared.Helpers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Options;
using SJZY.Expand.ABP.Core;
@ -8,8 +9,11 @@ using TrackCenter.Application.Dtos.TrackPull;
using TrackCenter.Application.Services;
using TrackCenter.Application.Helpers;
using TrackCenter.Application.Options;
using TrackCenter.Application.Queries;
using TrackCenter.Application.Services.TrackPull;
using TrackCenter.Application.Track2InterfaceRelay;
using TrackCenter.Domain.Dtos.TrackPull;
using TrackCenter.Domain.Extensions;
using TrackCenter.Domain.Queries;
using TrackCenter.Repository.Redis;
using Volo.Abp.DependencyInjection;
@ -40,7 +44,7 @@ public class TrackPullTask : ApplicationServiceBase, ISingletonDependency
{
using var serviceScope = _serviceScopeFactory.CreateScope();
var provideQueries = serviceScope.ServiceProvider.GetRequiredService<IProvideQueries>();
var provideQueries = serviceScope.ServiceProvider.GetRequiredService<ProvideQueries>();
var configs = await provideQueries.GetAllPullConfigsAsync();
foreach (var config in configs)
@ -55,7 +59,7 @@ public class TrackPullTask : ApplicationServiceBase, ISingletonDependency
private async Task RefreshForConfigAsync(IServiceScope serviceScope, TrackPullConfigVo config)
{
var trackPullCacheService = LazyServiceProvider.LazyGetRequiredService<ITrackPullCacheService>();
var trackPullCacheService = LazyServiceProvider.GetRequiredService<TrackPullCacheService>();
var redisKey = trackPullCacheService.TrackPullKey(config.SubSystemId, config.ServiceProviderCode);
if (await RedisHelper.Client.ExistsAsync(redisKey))
{
@ -68,9 +72,9 @@ public class TrackPullTask : ApplicationServiceBase, ISingletonDependency
{
try
{
var provideQueries = serviceScope.ServiceProvider.GetRequiredService<IProvideQueries>();
var httpClientProxy = serviceScope.ServiceProvider
.GetRequiredService<IHttpClientProxy<IInterfaceForwardServiceV2>>();
var provideQueries = serviceScope.ServiceProvider.GetRequiredService<ProvideQueries>();
var interfaceForward = serviceScope.ServiceProvider
.GetRequiredService<InterfaceForwardService>();
var interfaceOptions = serviceScope.ServiceProvider
.GetRequiredService<IOptions<InterfaceRelayParamsConfigOptions>>();
await DoRefreshAsync(config, provideQueries, httpClientProxy, interfaceOptions.Value);
@ -83,8 +87,8 @@ public class TrackPullTask : ApplicationServiceBase, ISingletonDependency
});
}
private static async Task DoRefreshAsync(TrackPullConfigVo config, IProvideQueries provideQueries,
IHttpClientProxy<IInterfaceForwardServiceV2> httpClientProxy,
private static async Task DoRefreshAsync(TrackPullConfigVo config, ProvideQueries provideQueries,
InterfaceForwardService interfaceForward,
InterfaceRelayParamsConfigOptions interfaceOptionsValue)
{
using (Track2InterfaceRelaySubSystemContext.Use(
@ -105,7 +109,7 @@ public class TrackPullTask : ApplicationServiceBase, ISingletonDependency
}));
var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(config.ServiceProviderCode,
config.SubSystemId, group.Key));
var res = await httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
var res = await interfaceForward.BatchForwardThenPushToQueueAsync(
interfaceOptionsValue.GetTrackInterfaceCode, serviceProviderCode, data,
GlobalConst.TrackRefreshSubscribe, attach);

View File

@ -1,9 +1,9 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Options;
using SJZY.Expand.ABP.Core;
using SJZY.Expand.ABP.Core.Logger;
using TrackCenter.Application.Track2InterfaceRelay;
using TrackCenter.Domain.Aggregates.OrderAggregate;
using TrackCenter.Domain.Extensions;
using TrackCenter.Repository.Redis;
namespace TrackCenter.Application.Services.TimerTaskss;

View File

@ -1,12 +1,15 @@
using System.Linq.Expressions;
using Fake.Application.Dtos;
using Microsoft.Extensions.Localization;
using SJZY.Expand.ABP.Core.Localization;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Expand.AliyunOSS;
using TrackCenter.Application.Dtos.ProvideServices;
using TrackCenter.Application.Dtos.TrackContents;
using TrackCenter.Application.Helpers.OSS;
using TrackCenter.Application.Services;
using TrackCenter.Application.Localization;
using TrackCenter.Application.Services.TrackPush;
using TrackCenter.Domain.Aggregates.OrderAggregate;
using TrackCenter.Domain.Aggregates.TrackContentAggregate;
using TrackCenter.Domain.Aggregates.TrackDetailsAggregate;
@ -26,25 +29,22 @@ namespace TrackCenter.Application.Services.TrackContents;
[Route("/Track/Content")]
public class TrackContentService : ApplicationServiceBase
{
private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer;
private readonly ITrackContentRepository _trackContentRepository;
private readonly ITrackTemplateRepository _trackTemplateRepository;
private readonly IBasicQuery<TrackFlagEntity> _trackFlagBasicQuery;
private readonly IBasicQuery<TrackStatusEntity> _trackStatusBasicQuery;
private readonly IBasicRepository<TrackFlagEntity> _trackFlagBasicQuery;
private readonly IBasicRepository<TrackStatusEntity> _trackStatusBasicQuery;
private readonly IOrderRepository _orderRepository;
private readonly ITrackDetailsEsRepository _trackDetailsEsRepository;
private readonly ITrackPushCacheService _trackPushCacheService;
private readonly TrackPushCacheService _trackPushCacheService;
public TrackContentService(
IStringLocalizer<TrackLocalizationResource> stringLocalizer,
ITrackContentRepository trackContentRepository,
IBasicQuery<TrackStatusEntity> trackStatusBasicQuery,
IBasicQuery<TrackFlagEntity> trackFlagBasicQuery,
IBasicRepository<TrackStatusEntity> trackStatusBasicQuery,
IBasicRepository<TrackFlagEntity> trackFlagBasicQuery,
IOrderRepository orderRepository,
ITrackDetailsEsRepository trackDetailsEsRepository,
ITrackTemplateRepository trackTemplateRepository, ITrackPushCacheService trackPushCacheService)
ITrackTemplateRepository trackTemplateRepository, TrackPushCacheService trackPushCacheService)
{
_stringLocalizer = stringLocalizer;
_trackContentRepository = trackContentRepository;
_trackStatusBasicQuery = trackStatusBasicQuery;
_trackFlagBasicQuery = trackFlagBasicQuery;
@ -59,7 +59,7 @@ public class TrackContentService : ApplicationServiceBase
/// </summary>
/// <returns></returns>
[HttpPost("Edit")]
public async Task<UnifyResultDto> EditAsync(EditTrackContentInput input)
public async Task EditAsync(EditTrackContentInput input)
{
if (input.TrackStatusId != null)
{
@ -95,17 +95,12 @@ public class TrackContentService : ApplicationServiceBase
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("GetDetail")]
public async Task<UnifyResultDto<GetTrackContentDetailDto>> GetDetailAsync(int id)
public async Task<GetTrackContentDetailDto> GetDetailAsync(int id)
{
var detailInfo = await _trackContentRepository.GetDetailAsync(id);
if (detailInfo == null)
{
return new UnifyResultDto<GetTrackContentDetailDto>(false, null!, "未查询到轨迹状态");
}
if (detailInfo == null) return null;
var dto = ObjectMapper.Map<GetTrackContentDetailVO, GetTrackContentDetailDto>(detailInfo);
return new UnifyResultDto<GetTrackContentDetailDto>(GlobalConst.SuccessCode, "", dto);
return ObjectMapper.Map<GetTrackContentDetailVO, GetTrackContentDetailDto>(detailInfo);
}
/// <summary>
@ -204,7 +199,7 @@ public class TrackContentService : ApplicationServiceBase
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("GetTrackContentByCode")]
public async Task<UnifyResultDto<GetTrackContentByCodeOutput>> GetTrackContentByCodeAsync([FromBody] GetTrackContentByCodeInput input)
public async Task<GetTrackContentByCodeOutput> GetTrackContentByCodeAsync([FromBody] GetTrackContentByCodeInput input)
{
if (input.SystemId <= 0)
return new UnifyResultDto<GetTrackContentByCodeOutput>(false, "子系统Id必须大于等于0");