From 44fddf48431607555bbfb2b00a6dbdb22faec9df Mon Sep 17 00:00:00 2001 From: xiaolipro <2357729423@qq.com> Date: Fri, 1 Aug 2025 18:01:44 +0800 Subject: [PATCH] 11 --- .../ProvideServices/TrackPullService.cs | 9 ++-- .../ProvideServices/TrackPushService.cs | 52 ++++++------------- .../ProvideServices/TrackService.Query.cs | 12 +---- .../Services/TimerTaskss/TrackPullTask.cs | 20 ++++--- .../Services/TimerTaskss/TrackPushTask.cs | 4 +- .../TrackContents/TrackContentService.cs | 33 +++++------- 6 files changed, 52 insertions(+), 78 deletions(-) diff --git a/src/TrackCenter.Application/Services/ProvideServices/TrackPullService.cs b/src/TrackCenter.Application/Services/ProvideServices/TrackPullService.cs index ac032655..75bb4ea6 100644 --- a/src/TrackCenter.Application/Services/ProvideServices/TrackPullService.cs +++ b/src/TrackCenter.Application/Services/ProvideServices/TrackPullService.cs @@ -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 _httpClientProxy; private readonly IOptionsMonitor _options; private readonly ProvideQueries _provideQueries; + private readonly InterfaceForwardService _interfaceForwardService; public TrackPullService(ProvideQueries provideQueries, - IHttpClientProxy httpClientProxy, + InterfaceForwardService interfaceForwardService, IOptionsMonitor 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); diff --git a/src/TrackCenter.Application/Services/ProvideServices/TrackPushService.cs b/src/TrackCenter.Application/Services/ProvideServices/TrackPushService.cs index 0375358c..ae320337 100644 --- a/src/TrackCenter.Application/Services/ProvideServices/TrackPushService.cs +++ b/src/TrackCenter.Application/Services/ProvideServices/TrackPushService.cs @@ -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; /// [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 _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 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 /// /// [HttpPost("Track/Push")] - [CustomerResult] - public async Task 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 @@ -136,9 +121,9 @@ public class TrackPushService : ApplicationServiceBase, ITrackPushService SubSystemId = input.SubSystemId, SubSystemCode = subSystemCode, CustomId = order.CustomId, - OrderIdTrackMetadataDict = new Dictionary> + OrderIdTrackMetadataDict = new Dictionary { - [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 /// /// [HttpGet("Track/GetTrackPushContentList")] - [CustomerResult] - public async Task>> GetTrackPushContentListAsync(int subSystemId, int customerId) + public async Task> GetTrackPushContentListAsync(int subSystemId, int customerId) { var list = await _trackPushConfigRepository.GetTrackPushContentListAsync(subSystemId, customerId); var result = ObjectMapper.Map, List>(list); - return new UnifyResultDto>(true, result, "操作成功"); + return result; } /// @@ -187,8 +171,7 @@ public class TrackPushService : ApplicationServiceBase, ITrackPushService /// /// [HttpGet("Track/GetTrackPushRecords")] - [CustomerResult] - public async Task>> GetTrackPushRecordsAsync([FromQuery] OrderNoInfo input) + public async Task> 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>(records); - return new UnifyResultDto>(true, res, "操作成功"); + return res; } /// @@ -214,8 +197,7 @@ public class TrackPushService : ApplicationServiceBase, ITrackPushService /// /// [HttpPost("Track/QueryTrackPushRecords")] - [CustomerResult] - public async Task>> QueryTrackPushRecordsAsync(QueryPushRecordInput input) + public async Task> 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>(true, new List(), "操作成功"); + if (records.Count == 0) return new List(); var res = ObjectMapper.Map, List>(records); - return new UnifyResultDto>(true, res, "操作成功"); + return res; } } diff --git a/src/TrackCenter.Application/Services/ProvideServices/TrackService.Query.cs b/src/TrackCenter.Application/Services/ProvideServices/TrackService.Query.cs index 18dd3a2d..9fd6149f 100644 --- a/src/TrackCenter.Application/Services/ProvideServices/TrackService.Query.cs +++ b/src/TrackCenter.Application/Services/ProvideServices/TrackService.Query.cs @@ -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.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>(true, sortedList, "操作成功"); + return sortedList; } //内部系统展示所有轨迹,外部系统则要求过滤外部轨迹 diff --git a/src/TrackCenter.Application/Services/TimerTaskss/TrackPullTask.cs b/src/TrackCenter.Application/Services/TimerTaskss/TrackPullTask.cs index d78263a4..057a77fa 100644 --- a/src/TrackCenter.Application/Services/TimerTaskss/TrackPullTask.cs +++ b/src/TrackCenter.Application/Services/TimerTaskss/TrackPullTask.cs @@ -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(); + var provideQueries = serviceScope.ServiceProvider.GetRequiredService(); 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(); + var trackPullCacheService = LazyServiceProvider.GetRequiredService(); 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(); - var httpClientProxy = serviceScope.ServiceProvider - .GetRequiredService>(); + var provideQueries = serviceScope.ServiceProvider.GetRequiredService(); + var interfaceForward = serviceScope.ServiceProvider + .GetRequiredService(); var interfaceOptions = serviceScope.ServiceProvider .GetRequiredService>(); 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 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); diff --git a/src/TrackCenter.Application/Services/TimerTaskss/TrackPushTask.cs b/src/TrackCenter.Application/Services/TimerTaskss/TrackPushTask.cs index c1c32338..014e8a73 100644 --- a/src/TrackCenter.Application/Services/TimerTaskss/TrackPushTask.cs +++ b/src/TrackCenter.Application/Services/TimerTaskss/TrackPushTask.cs @@ -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; diff --git a/src/TrackCenter.Application/Services/TrackContents/TrackContentService.cs b/src/TrackCenter.Application/Services/TrackContents/TrackContentService.cs index ac41e761..e0cd8f24 100644 --- a/src/TrackCenter.Application/Services/TrackContents/TrackContentService.cs +++ b/src/TrackCenter.Application/Services/TrackContents/TrackContentService.cs @@ -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 _stringLocalizer; private readonly ITrackContentRepository _trackContentRepository; private readonly ITrackTemplateRepository _trackTemplateRepository; - private readonly IBasicQuery _trackFlagBasicQuery; - private readonly IBasicQuery _trackStatusBasicQuery; + private readonly IBasicRepository _trackFlagBasicQuery; + private readonly IBasicRepository _trackStatusBasicQuery; private readonly IOrderRepository _orderRepository; private readonly ITrackDetailsEsRepository _trackDetailsEsRepository; - private readonly ITrackPushCacheService _trackPushCacheService; + private readonly TrackPushCacheService _trackPushCacheService; public TrackContentService( - IStringLocalizer stringLocalizer, ITrackContentRepository trackContentRepository, - IBasicQuery trackStatusBasicQuery, - IBasicQuery trackFlagBasicQuery, + IBasicRepository trackStatusBasicQuery, + IBasicRepository 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 /// /// [HttpPost("Edit")] - public async Task EditAsync(EditTrackContentInput input) + public async Task EditAsync(EditTrackContentInput input) { if (input.TrackStatusId != null) { @@ -95,17 +95,12 @@ public class TrackContentService : ApplicationServiceBase /// /// [HttpGet("GetDetail")] - public async Task> GetDetailAsync(int id) + public async Task GetDetailAsync(int id) { var detailInfo = await _trackContentRepository.GetDetailAsync(id); - if (detailInfo == null) - { - return new UnifyResultDto(false, null!, "未查询到轨迹状态"); - } + if (detailInfo == null) return null; - var dto = ObjectMapper.Map(detailInfo); - - return new UnifyResultDto(GlobalConst.SuccessCode, "", dto); + return ObjectMapper.Map(detailInfo); } /// @@ -204,7 +199,7 @@ public class TrackContentService : ApplicationServiceBase /// /// [HttpPost("GetTrackContentByCode")] - public async Task> GetTrackContentByCodeAsync([FromBody] GetTrackContentByCodeInput input) + public async Task GetTrackContentByCodeAsync([FromBody] GetTrackContentByCodeInput input) { if (input.SystemId <= 0) return new UnifyResultDto(false, "子系统Id必须大于等于0");