From 1d80a8de4eb58ed77808373a2110ae13412cc600 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9F=B3=E6=96=87=E7=BF=94?= <878130837@qq.com>
Date: Fri, 15 Mar 2024 16:09:27 +0800
Subject: [PATCH 1/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A8=E9=80=81?=
=?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=BC=93=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Services/ITrackPushCacheService.cs | 17 +-
.../AutoMapper/TrackPushAutoMapperProfile.cs | 3 +
.../TrackPull/TrackPullCacheService.cs | 6 +-
.../Services/TrackPull/TrackPullService.cs | 11 +-
.../TrackPush/TrackPushCacheService.cs | 71 ++++++--
.../Services/TrackPush/TrackPushService.cs | 160 +++++++++---------
6 files changed, 153 insertions(+), 115 deletions(-)
diff --git a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
index acc00b72..cc7fec74 100644
--- a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
+++ b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
@@ -4,13 +4,6 @@ namespace SJZY.Track.Application.Contract.Services;
public interface ITrackPushCacheService
{
- ///
- /// 判断客户是否需要推送
- ///
- ///
- ///
- Task IsPushAsync(int customId);
-
///
/// 获取服务商拉取配置
///
@@ -30,9 +23,11 @@ public interface ITrackPushCacheService
int? trackContentId);
///
- /// 更新缓存
+ /// 设置推送配置缓存
///
- ///
- ///
- Task UpdateAsync(int customId, bool isPush);
+ ///
+ /// 子系统id
+ /// 客户id
+ ///
+ Task> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null);
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/AutoMapper/TrackPushAutoMapperProfile.cs b/src/SJZY.Track.Application/AutoMapper/TrackPushAutoMapperProfile.cs
index eed8b90b..6be69d46 100644
--- a/src/SJZY.Track.Application/AutoMapper/TrackPushAutoMapperProfile.cs
+++ b/src/SJZY.Track.Application/AutoMapper/TrackPushAutoMapperProfile.cs
@@ -1,4 +1,5 @@
using AutoMapper;
+using SJZY.Track.Application.Contract.Dtos.ProvideServices;
using SJZY.Track.Application.Contract.Dtos.TrackPush;
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
@@ -14,5 +15,7 @@ public class TrackPushAutoMapperProfile : Profile
CreateMap(MemberList.None).Ignore(dest => dest.Id)
.ForMember(dest => dest.IsPush, opt => opt.MapFrom(source => true));
CreateMap(MemberList.None);
+ CreateMap(MemberList.None)
+ .ForMember(dest => dest.OrderType, opt => opt.MapFrom(source => source.OrderNoType));
}
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs b/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs
index 26541474..1a57ea08 100644
--- a/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs
@@ -4,10 +4,11 @@ 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;
namespace SJZY.Track.Application.Services.TrackPull;
-public class TrackPullCacheService : ApplicationService, ITrackPullCacheService
+public class TrackPullCacheService : ApplicationService, ITrackPullCacheService, ITransientDependency
{
private readonly ITrackPullConfigRepository _trackPullConfigRepository;
@@ -59,6 +60,7 @@ public class TrackPullCacheService : ApplicationService, ITrackPullCacheService
var trackPullConfigEntity = await _trackPullConfigRepository.GetFirstAsync(exp);
if (trackPullConfigEntity == null) return data;
+
var trackPullConfigDetail = await _trackPullConfigRepository.GetDetailAsync(trackPullConfigEntity.Id);
if (trackPullConfigDetail is null) return data;
var trackPullContentList = await _trackPullConfigRepository.GetContentListCacheAsync(trackPullConfigEntity.Id);
@@ -72,7 +74,7 @@ public class TrackPullCacheService : ApplicationService, ITrackPullCacheService
await RedisHelper.Client.SetAsync(
TrackPullContentKey(trackPullConfigEntity.SubSystemId, trackPullConfigEntity.ServiceProviderId), data,
- 86400);
+ (int)TimeSpan.FromDays(1).TotalSeconds);
return data;
}
diff --git a/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs b/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs
index 61f2cb2d..daba134c 100644
--- a/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs
@@ -212,16 +212,21 @@ public class TrackPullService : ApplicationService, ITransientDependency
ObjectMapper.Map(input, oldTrackPullContentEntity);
await _trackPullConfigRepository.UpdateContentAsync(oldTrackPullContentEntity);
- await _trackPullCacheService.SetPullConfigAsync(input.TrackPullConfigId);
+ await _trackPullCacheService.SetPullConfigAsync(oldTrackPullContentEntity.TrackPullConfigId);
break;
}
case OptionTypeNoNull.删除:
+ {
+ var oldTrackPullContentEntity = await _trackPullConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
+ throw new BusinessException(message: _stringLocalizer["NotFindData"]);
- await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
+ await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
+ await _trackPullCacheService.SetPullConfigAsync(oldTrackPullContentEntity.TrackPullConfigId);
- break;
+ break;
+ }
default:
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
index eb11ae2c..c8581b7c 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
@@ -1,41 +1,78 @@
-using SJZY.Expand.ABP.Core;
+using Microsoft.Extensions.DependencyInjection;
+using Nest;
+using SJZY.Expand.ABP.Core;
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
using SJZY.Track.Application.Contract.Services;
+using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
using SJZY.Track.Domain.Queries;
+using SJZY.UserCenter.SharedModel.Dtos.PHP.User;
+using System.Linq.Expressions;
using Volo.Abp.DependencyInjection;
namespace SJZY.Track.Application.Services.TrackPush;
-public class TrackPushCacheService : ITrackPushCacheService, ITransientDependency
+public class TrackPushCacheService : ApplicationService, ITrackPushCacheService, ITransientDependency
{
- private readonly IBasicQuery _trackPushConfigQuery;
+ private readonly ITrackPushConfigRepository _trackPushConfigRepository;
- private string RedisKey(int customId) => $"{GlobalConst.TrackPushKeyPrefix}:{customId}";
+ private string TrackPushContentKey(int subSystemId, int customId) => $"{GlobalConst.TrackPushKeyPrefix}:{subSystemId}:{customId}";
- public TrackPushCacheService(IBasicQuery trackPushConfigQuery)
+ public TrackPushCacheService(ITrackPushConfigRepository trackPushConfigRepository)
{
- _trackPushConfigQuery = trackPushConfigQuery;
+ _trackPushConfigRepository = trackPushConfigRepository;
}
- public Task IsPushAsync(int customId)
+ [NonAction]
+ public async Task> GetPushContentConfigsAsync(int subSystemId, int customId)
{
- throw new NotImplementedException();
+ var data = await RedisHelper.Client.GetAsync>(TrackPushContentKey(subSystemId, customId));
+
+ data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId);
+
+ return data;
}
- public Task> GetPushContentConfigsAsync(int subSystemId, int customId)
+ [NonAction]
+ public async Task InferNextPushContentOrNullAsync(int subSystemId, int customId, int? trackContentId)
{
- throw new NotImplementedException();
+ var data = await GetPushContentConfigsAsync(subSystemId, customId);
+
+ if (trackContentId.HasValue)
+ {
+ if (data.Count > 1 && data.Any(x => x.TrackContentId == trackContentId))
+ {
+ int index = data.FindIndex(x => x.TrackContentId == trackContentId);
+ int nextIndex = (index + 1) % data.Count; // 计算下一个索引,处理最后一个元素的情况
+
+ return data[nextIndex];
+ }
+ else return null;
+ }
+ else return data.FirstOrDefault();
}
- public Task InferNextPushContentOrNullAsync(int subSystemId, int customId,
- int? trackContentId)
+ [NonAction]
+ public async Task> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null)
{
- throw new NotImplementedException();
- }
+ var data = new List();
+ Expression> exp = x => true;
+ if (id.HasValue) exp = x => x.Id == id;
+ else if (subSystemId.HasValue && customId.HasValue)
+ exp = x => x.SubSystemId == subSystemId && x.CustomId == customId;
- public async Task UpdateAsync(int customId, bool isPush)
- {
- await RedisHelper.Client.SetAsync(RedisKey(customId), isPush);
+ var trackPushConfigEntity = await _trackPushConfigRepository.GetFirstAsync(exp);
+ if (trackPushConfigEntity == null) return data;
+
+ var trackPushContentList = await _trackPushConfigRepository.GetContentListAsync(x => x.TrackPushConfigId == trackPushConfigEntity.Id);
+ if (trackPushContentList.Count == 0) return data;
+
+ trackPushContentList = trackPushContentList.OrderBy(x => x.Sort).ToList();
+
+ data = ObjectMapper.Map, List>(trackPushContentList);
+
+ await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data, (int)TimeSpan.FromDays(1).TotalSeconds);
+
+ return data;
}
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
index 34903f75..e2771645 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
@@ -94,8 +94,7 @@ public class TrackPushService : ApplicationService
if (input.Options != OptionTypeNoNull.删除)
{
Expression> isAnyExp = x =>
- x.SubSystemId == input.SubSystemId && x.CustomId == input.CustomId &&
- x.ServiceProviderId == input.ServiceProviderId;
+ x.SubSystemId == input.SubSystemId && x.CustomId == input.CustomId;
if (input.Options == OptionTypeNoNull.修改) isAnyExp = isAnyExp.And(x => x.Id != input.Id);
if (await _trackPushConfigRepository.IsAnyAsync(isAnyExp))
@@ -105,68 +104,62 @@ public class TrackPushService : ApplicationService
switch (input.Options)
{
case OptionTypeNoNull.新增:
- {
- var trackPushEntity = ObjectMapper.Map(input);
- var trackPushParamsEntity =
- ObjectMapper.Map(input);
-
- using (var ts = TransactionScopeHelper.Create())
{
- int id = await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity);
+ var trackPushEntity = ObjectMapper.Map(input);
+ var trackPushParamsEntity =
+ ObjectMapper.Map(input);
- trackPushParamsEntity.PullOrPushConfigId = id;
- await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity);
+ using (var ts = TransactionScopeHelper.Create())
+ {
+ int id = await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity);
- if (input.IsAutoPush!.Value) await _trackPushCacheService.IsPushAsync(input.CustomId!.Value);
+ trackPushParamsEntity.PullOrPushConfigId = id;
+ await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity);
- ts.Complete();
+ ts.Complete();
+ }
}
- }
break;
case OptionTypeNoNull.修改:
- {
- var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
- throw new BusinessException(message: _stringLocalizer["NotFindData"]);
-
- int oldCustomId = oldTrackPushEntity.CustomId;
-
- var oldTrackPushParamsEntity =
- await _trackPullConfigRepository.GetParamsSingleAsync(x =>
- x.PullOrPushConfigId == input.Id && x.IsPush);
-
- ObjectMapper.Map(input, oldTrackPushEntity);
- ObjectMapper.Map(input, oldTrackPushParamsEntity);
-
- using (var ts = TransactionScopeHelper.Create())
{
- await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity);
- await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPushParamsEntity);
+ var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
+ throw new BusinessException(message: _stringLocalizer["NotFindData"]);
- await _trackPushCacheService.UpdateAsync(oldCustomId, false);
- if (input.IsAutoPush!.Value) await _trackPushCacheService.IsPushAsync(input.CustomId!.Value);
+ int oldCustomId = oldTrackPushEntity.CustomId;
- ts.Complete();
+ var oldTrackPushParamsEntity =
+ await _trackPullConfigRepository.GetParamsSingleAsync(x =>
+ x.PullOrPushConfigId == input.Id && x.IsPush);
+
+ ObjectMapper.Map(input, oldTrackPushEntity);
+ ObjectMapper.Map(input, oldTrackPushParamsEntity);
+
+ using (var ts = TransactionScopeHelper.Create())
+ {
+ await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity);
+ await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPushParamsEntity);
+
+ ts.Complete();
+ }
}
- }
break;
case OptionTypeNoNull.删除:
- {
- var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
- throw new BusinessException(message: _stringLocalizer["NotFindData"]);
-
- using (var ts = TransactionScopeHelper.Create())
{
- await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id);
- await _trackPullConfigRepository.SoftDeleteParamsAsync(x =>
- x.PullOrPushConfigId == input.Id && x.IsPush);
- await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id);
- await _trackPushCacheService.UpdateAsync(oldTrackPushEntity.CustomId, false);
+ var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
+ throw new BusinessException(message: _stringLocalizer["NotFindData"]);
- ts.Complete();
+ using (var ts = TransactionScopeHelper.Create())
+ {
+ await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id);
+ await _trackPullConfigRepository.SoftDeleteParamsAsync(x =>
+ x.PullOrPushConfigId == input.Id && x.IsPush);
+ await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id);
+
+ ts.Complete();
+ }
}
- }
break;
default:
@@ -215,47 +208,50 @@ public class TrackPushService : ApplicationService
switch (input.Options)
{
case OptionTypeNoNull.新增:
- {
- int maxSort = await _trackPushConfigRepository.ContentMaxAsync(x => x.Sort,
- x => x.TrackPushConfigId == input.TrackPushConfigId);
-
- var entity = ObjectMapper.Map(input);
- entity.Sort = maxSort + 1;
-
- await _trackPushConfigRepository.InsertContentAsync(entity);
-
- break;
- }
-
- case OptionTypeNoNull.修改:
- {
- var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
- throw new BusinessException(message: _stringLocalizer["NotFindData"]);
-
- ObjectMapper.Map(input, entity);
-
- await _trackPushConfigRepository.UpdateContentAsync(entity);
-
- break;
- }
-
- case OptionTypeNoNull.删除:
- {
- var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
- throw new BusinessException(message: _stringLocalizer["NotFindData"]);
-
- using (var ts = TransactionScopeHelper.Create())
{
- await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
+ int maxSort = await _trackPushConfigRepository.ContentMaxAsync(x => x.Sort,
+ x => x.TrackPushConfigId == input.TrackPushConfigId);
- await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1,
- x => x.TrackPushConfigId == entity.TrackPushConfigId && x.Sort > entity.Sort);
+ var entity = ObjectMapper.Map(input);
+ entity.Sort = maxSort + 1;
- ts.Complete();
+ await _trackPushConfigRepository.InsertContentAsync(entity);
+ await _trackPushCacheService.SetPushContentConfigsAsync(input.TrackPushConfigId);
+
+ break;
}
- break;
- }
+ case OptionTypeNoNull.修改:
+ {
+ var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
+ throw new BusinessException(message: _stringLocalizer["NotFindData"]);
+
+ ObjectMapper.Map(input, entity);
+
+ await _trackPushConfigRepository.UpdateContentAsync(entity);
+ await _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId);
+
+ break;
+ }
+
+ case OptionTypeNoNull.删除:
+ {
+ var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
+ throw new BusinessException(message: _stringLocalizer["NotFindData"]);
+
+ using (var ts = TransactionScopeHelper.Create())
+ {
+ await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
+ await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1,
+ x => x.TrackPushConfigId == entity.TrackPushConfigId && x.Sort > entity.Sort);
+
+ ts.Complete();
+ }
+
+ await _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId);
+
+ break;
+ }
default:
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,
From 06e43db12c11e743ca0877602605081664a7c0a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9F=B3=E6=96=87=E7=BF=94?= <878130837@qq.com>
Date: Fri, 15 Mar 2024 16:12:55 +0800
Subject: [PATCH 2/8] =?UTF-8?q?=E8=A1=A5=E5=85=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Services/TrackPush/TrackPushService.cs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
index e2771645..e7498c2c 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
@@ -278,7 +278,11 @@ public class TrackPushService : ApplicationService
item.Sort = input.SortInfo.Single(x => x.Key == item.Id.ToString()).Value;
});
- await _trackPushConfigRepository.UpdateContentRangeAsync(trackPushContentEntities);
+ if (trackPushContentEntities.Count > 0)
+ {
+ await _trackPushConfigRepository.UpdateContentRangeAsync(trackPushContentEntities);
+ await _trackPushCacheService.SetPushContentConfigsAsync(trackPushContentEntities[0].TrackPushConfigId);
+ }
return true;
}
From 3871b31af0c6eb66470ef4892c382e189839dd73 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9F=B3=E6=96=87=E7=BF=94?= <878130837@qq.com>
Date: Fri, 15 Mar 2024 16:13:47 +0800
Subject: [PATCH 3/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?=
=?UTF-8?q?=E5=BC=95=E7=94=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Services/TrackPush/TrackPushCacheService.cs | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
index c8581b7c..b5988ab3 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
@@ -1,12 +1,7 @@
-using Microsoft.Extensions.DependencyInjection;
-using Nest;
-using SJZY.Expand.ABP.Core;
+using SJZY.Expand.ABP.Core;
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
using SJZY.Track.Application.Contract.Services;
-using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
-using SJZY.Track.Domain.Queries;
-using SJZY.UserCenter.SharedModel.Dtos.PHP.User;
using System.Linq.Expressions;
using Volo.Abp.DependencyInjection;
From f8d5705551068934d8f76b121034168775db8a07 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=86=9B?= <2357729423@qq.com>
Date: Fri, 15 Mar 2024 16:52:36 +0800
Subject: [PATCH 4/8] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Dtos/ProvideServices/PushTrackInput.cs | 12 +++
.../Services/ITrackPushCacheService.cs | 9 +++
.../OrderLinkAfterFillTrackHandler.cs | 4 +-
.../EventHandlers/TrackRefreshEventHandler.cs | 4 +-
...PushPullService.cs => TrackPullService.cs} | 27 +++----
.../ProvideServices/TrackPushService.cs | 77 +++++++++++++++++++
.../Services/ProvideServices/TrackService.cs | 8 +-
.../TrackPush/TrackPushCacheService.cs | 5 ++
.../OrderAggregate/IOrderRepository.cs | 15 ----
...derVO.cs => OrderWithServiceProviderVO.cs} | 2 +-
.../Queries/IProvideQueries.cs | 14 ++++
.../Queries/ProvideQueries.cs | 36 +++++++++
.../Repositories/OrderRepository.cs | 35 ---------
13 files changed, 176 insertions(+), 72 deletions(-)
create mode 100644 src/SJZY.Track.Application.Contract/Dtos/ProvideServices/PushTrackInput.cs
rename src/SJZY.Track.Application/Services/ProvideServices/{TrackPushPullService.cs => TrackPullService.cs} (79%)
create mode 100644 src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs
rename src/SJZY.Track.Domain/Dtos/Order/{OrderServiceProviderVO.cs => OrderWithServiceProviderVO.cs} (92%)
diff --git a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/PushTrackInput.cs b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/PushTrackInput.cs
new file mode 100644
index 00000000..5eaff31e
--- /dev/null
+++ b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/PushTrackInput.cs
@@ -0,0 +1,12 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace SJZY.Track.Application.Contract.Dtos.ProvideServices;
+
+public class PushTrackInput : OrderNosInfo
+{
+ ///
+ /// 轨迹code,必填
+ ///
+ [Required]
+ public string TrackCode { get; set; } = null!;
+}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
index acc00b72..12db0f65 100644
--- a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
+++ b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
@@ -19,6 +19,15 @@ public interface ITrackPushCacheService
///
Task> GetPushContentConfigsAsync(int subSystemId, int customId);
+ ///
+ /// 获取服务商拉取配置
+ ///
+ /// 子系统id
+ /// 服务商id
+ ///
+ ///
+ Task GetPushContentConfigAsync(int subSystemId, int customId, int trackContentId);
+
///
/// 根据轨迹代码推断下一个(升序)要推送的内容,如果找不到或者已经是最后一个了,返回null
///
diff --git a/src/SJZY.Track.Application/EventHandlers/OrderLinkAfterFillTrackHandler.cs b/src/SJZY.Track.Application/EventHandlers/OrderLinkAfterFillTrackHandler.cs
index 80c5dda8..9335175a 100644
--- a/src/SJZY.Track.Application/EventHandlers/OrderLinkAfterFillTrackHandler.cs
+++ b/src/SJZY.Track.Application/EventHandlers/OrderLinkAfterFillTrackHandler.cs
@@ -31,7 +31,7 @@ public class OrderLinkAfterFillTrackHandler : ITransientDependency, ICapSubscrib
var order = await _orderRepository.GetFirstAsync(x =>
x.Id == linkOrderId, x => new
{
- x.OrderType, x.OrderNo, x.CustomId, LatestPushCode = x.LatestPushTrackContentId, x.SubSystemId
+ x.OrderType, x.OrderNo, x.CustomId, x.LatestPushTrackContentId, x.SubSystemId
});
if (order == default) continue;
@@ -50,7 +50,7 @@ public class OrderLinkAfterFillTrackHandler : ITransientDependency, ICapSubscrib
OrderId = linkOrderId,
CustomId = order.CustomId,
SubSystemId = order.SubSystemId,
- LatestPushTrackContentId = order.LatestPushCode,
+ LatestPushTrackContentId = order.LatestPushTrackContentId,
UpSubSystemId = @event.SubSystemId,
};
diff --git a/src/SJZY.Track.Application/EventHandlers/TrackRefreshEventHandler.cs b/src/SJZY.Track.Application/EventHandlers/TrackRefreshEventHandler.cs
index 5d74b758..e5207ee2 100644
--- a/src/SJZY.Track.Application/EventHandlers/TrackRefreshEventHandler.cs
+++ b/src/SJZY.Track.Application/EventHandlers/TrackRefreshEventHandler.cs
@@ -63,7 +63,7 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
var order = await _orderRepository.GetFirstAsync(x =>
x.OrderType == orderType && x.OrderNo == orderNo, x => new
{
- x.Id, x.SubSystemId, LatestPushCode = x.LatestPushTrackContentId, x.CustomId
+ x.Id, x.SubSystemId, x.LatestPushTrackContentId, x.CustomId
});
if (order == default) return;
@@ -73,7 +73,7 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
{
OrderId = order.Id,
SubSystemId = order.SubSystemId,
- LatestPushTrackContentId = order.LatestPushCode,
+ LatestPushTrackContentId = order.LatestPushTrackContentId,
CustomId = order.CustomId,
OrderType = orderType,
OrderNo = orderNo!,
diff --git a/src/SJZY.Track.Application/Services/ProvideServices/TrackPushPullService.cs b/src/SJZY.Track.Application/Services/ProvideServices/TrackPullService.cs
similarity index 79%
rename from src/SJZY.Track.Application/Services/ProvideServices/TrackPushPullService.cs
rename to src/SJZY.Track.Application/Services/ProvideServices/TrackPullService.cs
index faa64a0f..e74ca894 100644
--- a/src/SJZY.Track.Application/Services/ProvideServices/TrackPushPullService.cs
+++ b/src/SJZY.Track.Application/Services/ProvideServices/TrackPullService.cs
@@ -1,30 +1,31 @@
-using Newtonsoft.Json;
+using Microsoft.AspNetCore.Authorization;
+using Newtonsoft.Json;
using SJZY.Expand.ABP.Core;
using SJZY.InterfaceRelay.Application.Contracts;
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
using SJZY.Track.Application.Contract.Dtos.TrackPull;
using SJZY.Track.Application.Contract.Services;
-using SJZY.Track.Domain.Aggregates.OrderAggregate;
+using SJZY.Track.Domain.Queries;
using Volo.Abp.Http.Client.DynamicProxying;
namespace SJZY.Track.Application.Services.ProvideServices;
///
-/// 轨迹推送、拉取服务
+/// 轨迹刷新服务
///
[ApiExplorerSettings(GroupName = "提供接口")]
[Route("/ProviderService")]
-public class TrackPushPullService : ApplicationService
+public class TrackPullService : ApplicationService
{
- private readonly IOrderRepository _orderRepository;
+ private readonly IProvideQueries _provideQueries;
private readonly IHttpClientProxy _httpClientProxy;
private readonly ITrackPullCacheService _trackPullCacheService;
- public TrackPushPullService(IOrderRepository orderRepository,
+ public TrackPullService(IProvideQueries provideQueries,
IHttpClientProxy httpClientProxy,
ITrackPullCacheService trackPullCacheService)
{
- _orderRepository = orderRepository;
+ _provideQueries = provideQueries;
_httpClientProxy = httpClientProxy;
_trackPullCacheService = trackPullCacheService;
}
@@ -38,17 +39,16 @@ public class TrackPushPullService : ApplicationService
public async Task RefreshTrackAsync(RefreshTrackInput input)
{
// todo:罚时?
+ input.OrderNos = input.OrderNos.Where(x => !x.IsNullOrWhiteSpace()).Distinct().ToList(); // 单号去重、去空
if (input.OrderNos.Count == 0)
{
- throw new BusinessException(message: "订单号数组不能为空");
+ throw new BusinessException(message: "订单一个都不存在");
}
- input.OrderNos = input.OrderNos.Distinct().ToList();
-
// 这里没有区分订单类型,就算的不同类型的单一起刷新了也无所谓
- var orderTemplates = await _orderRepository.FindServiceProviderByOrderAsync(input.OrderNos);
+ var orders = await _provideQueries.FindOrderWithServiceProviderAsync(input.OrderNos);
- foreach (var group in orderTemplates.GroupBy(x =>
+ foreach (var group in orders.GroupBy(x =>
new TrackRefreshAttach(x.ServiceProviderId, x.ServiceProviderCode, x.SubSystemId, x.OrderType)))
{
var data = group.Select(x => new
@@ -69,6 +69,7 @@ public class TrackPushPullService : ApplicationService
/// 定时任务刷新轨迹
///
///
+ [AllowAnonymous]
[HttpPost("Track/RefreshForTask")]
public async Task RefreshTrackAsync()
{
@@ -81,7 +82,7 @@ public class TrackPushPullService : ApplicationService
continue;
}
- var orders = await _orderRepository.FindOrderByServiceProviderAsync(config.ServiceProviderId);
+ var orders = await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId);
foreach (var group in orders.GroupBy(x =>
new TrackRefreshAttach(x.ServiceProviderId, x.ServiceProviderCode, x.SubSystemId,
diff --git a/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs b/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs
new file mode 100644
index 00000000..10b28796
--- /dev/null
+++ b/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs
@@ -0,0 +1,77 @@
+using SJZY.InterfaceRelay.Application.Contracts;
+using SJZY.Track.Application.Contract.Dtos.ProvideServices;
+using SJZY.Track.Application.Contract.Services;
+using SJZY.Track.Domain.Aggregates.OrderAggregate;
+using SJZY.Track.Domain.Aggregates.TrackContentAggregate;
+using Volo.Abp.Http.Client.DynamicProxying;
+
+namespace SJZY.Track.Application.Services.ProvideServices;
+
+///
+/// 轨迹推送服务
+///
+[ApiExplorerSettings(GroupName = "提供接口")]
+[Route("/ProviderService")]
+public class TrackPushService : ApplicationService
+{
+ private readonly IOrderRepository _orderRepository;
+ private readonly ITrackContentRepository _trackContentRepository;
+ private readonly ITrackPushCacheService _pushCacheService;
+ private readonly IHttpClientProxy _httpClientProxy;
+
+ public TrackPushService(IOrderRepository orderRepository,
+ IHttpClientProxy httpClientProxy, ITrackPushCacheService pushCacheService,
+ ITrackContentRepository trackContentRepository)
+ {
+ _orderRepository = orderRepository;
+ _httpClientProxy = httpClientProxy;
+ _pushCacheService = pushCacheService;
+ _trackContentRepository = trackContentRepository;
+ }
+
+ ///
+ /// 推送轨迹
+ ///
+ ///
+ ///
+ [HttpPost("Track/Push")]
+ public async Task PushTrackAsync(PushTrackInput input)
+ {
+ input.OrderNos = input.OrderNos.Where(x => !x.IsNullOrWhiteSpace()).Distinct().ToList(); // 单号去重、去空
+ if (input.OrderNos.Count == 0)
+ {
+ throw new BusinessException(message: "订单一个都不存在");
+ }
+
+ var orders = await _orderRepository.GetListAsync(x =>
+ x.OrderType == input.OrderType && input.OrderNos.Contains(x.OrderNo), x => new
+ {
+ x.Id, x.OrderNo, x.SubSystemId, x.CustomId
+ });
+
+ var trackContents = await _trackContentRepository.GetListAsync(x => x.Code == input.TrackCode, x => new
+ {
+ x.SubSystemId, x.Id
+ });
+
+ foreach (var group in orders.GroupBy(x =>
+ new { x.SubSystemId, x.CustomId }))
+ {
+ var trackContent = trackContents.FirstOrDefault(x => x.SubSystemId == group.Key.SubSystemId);
+ if (trackContent == null) continue;
+ await _pushCacheService.GetPushContentConfigAsync(group.Key.SubSystemId, group.Key.CustomId,
+ trackContent.Id);
+ var data = group.Select(x => new
+ {
+ x.OrderNo
+ }).ToList();
+
+ // 批量获取轨迹
+ // await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
+ // "A024", group.Key.ServiceProviderCode, data,
+ // GlobalConst.TrackRefreshSubscribe, JsonConvert.SerializeObject(group.Key));
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs b/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs
index b1c809d3..b9af7e6e 100644
--- a/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs
+++ b/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs
@@ -41,7 +41,7 @@ public partial class TrackService : ApplicationService, ITrackService
var order = await _orderRepository.GetFirstAsync(x =>
x.OrderType == input.OrderType && x.OrderNo == input.OrderNo, x => new
{
- x.Id, x.SubSystemId, LatestPushCode = x.LatestPushTrackContentId, x.CustomId
+ x.Id, x.SubSystemId, x.LatestPushTrackContentId, x.CustomId
});
if (order == default)
{
@@ -52,7 +52,7 @@ public partial class TrackService : ApplicationService, ITrackService
var @event = ObjectMapper.Map(input);
@event.OrderId = order.Id;
@event.SubSystemId = order.SubSystemId;
- @event.LatestPushTrackContentId = order.LatestPushCode;
+ @event.LatestPushTrackContentId = order.LatestPushTrackContentId;
@event.CustomId = order.CustomId;
await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, @event);
return true;
@@ -76,7 +76,7 @@ public partial class TrackService : ApplicationService, ITrackService
var orders = await _orderRepository.GetListAsync(x =>
x.OrderType == input.OrderType && input.OrderNos.Contains(x.OrderNo), x => new
{
- x.Id, x.OrderNo, x.SubSystemId, LatestPushCode = x.LatestPushTrackContentId, x.CustomId
+ x.Id, x.OrderNo, x.SubSystemId, x.LatestPushTrackContentId, x.CustomId
});
foreach (var order in orders)
@@ -92,7 +92,7 @@ public partial class TrackService : ApplicationService, ITrackService
OrderNo = order.OrderNo,
OrderId = order.Id,
SubSystemId = order.SubSystemId,
- LatestPushTrackContentId = order.LatestPushCode,
+ LatestPushTrackContentId = order.LatestPushTrackContentId,
CustomId = order.CustomId
};
await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, @event);
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
index eb11ae2c..d2bb3e2d 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
@@ -28,6 +28,11 @@ public class TrackPushCacheService : ITrackPushCacheService, ITransientDependenc
throw new NotImplementedException();
}
+ public Task GetPushContentConfigAsync(int subSystemId, int customId, int trackContentId)
+ {
+ throw new NotImplementedException();
+ }
+
public Task InferNextPushContentOrNullAsync(int subSystemId, int customId,
int? trackContentId)
{
diff --git a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/IOrderRepository.cs b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/IOrderRepository.cs
index 2f99ba3f..acc0d4de 100644
--- a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/IOrderRepository.cs
+++ b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/IOrderRepository.cs
@@ -50,19 +50,4 @@ public interface IOrderRepository : IBasicRepository
Task UnLinkByIdsAsync(List linkIds);
#endregion
-
-
- ///
- /// 根据订单模板找对应服务商
- ///
- ///
- ///
- Task> FindServiceProviderByOrderAsync(List orderNos);
-
- ///
- /// 获取服务商下所有单(未完成的)
- ///
- ///
- ///
- Task> FindOrderByServiceProviderAsync(int serviceProvider);
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Domain/Dtos/Order/OrderServiceProviderVO.cs b/src/SJZY.Track.Domain/Dtos/Order/OrderWithServiceProviderVO.cs
similarity index 92%
rename from src/SJZY.Track.Domain/Dtos/Order/OrderServiceProviderVO.cs
rename to src/SJZY.Track.Domain/Dtos/Order/OrderWithServiceProviderVO.cs
index 36a46aa8..df193e03 100644
--- a/src/SJZY.Track.Domain/Dtos/Order/OrderServiceProviderVO.cs
+++ b/src/SJZY.Track.Domain/Dtos/Order/OrderWithServiceProviderVO.cs
@@ -1,6 +1,6 @@
namespace SJZY.Track.Domain.Dtos.Order;
-public class OrderServiceProviderVO
+public class OrderWithServiceProviderVO
{
public string OrderNo { get; set; } = null!;
diff --git a/src/SJZY.Track.Domain/Queries/IProvideQueries.cs b/src/SJZY.Track.Domain/Queries/IProvideQueries.cs
index a3f8450c..2795df48 100644
--- a/src/SJZY.Track.Domain/Queries/IProvideQueries.cs
+++ b/src/SJZY.Track.Domain/Queries/IProvideQueries.cs
@@ -48,4 +48,18 @@ public interface IProvideQueries
///
///
Task> MapTrackCodesAsync(int upSubSystemId, int subSystemId, params string[] trackCodes);
+
+ ///
+ /// 根据订单模板找对应服务商
+ ///
+ ///
+ ///
+ Task> FindOrderWithServiceProviderAsync(List orderNos);
+
+ ///
+ /// 获取服务商下所有单(未完成的)
+ ///
+ ///
+ ///
+ Task> FindOrderWithServiceProviderAsync(int serviceProvider);
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Repository/Queries/ProvideQueries.cs b/src/SJZY.Track.Repository/Queries/ProvideQueries.cs
index 04301286..8058689e 100644
--- a/src/SJZY.Track.Repository/Queries/ProvideQueries.cs
+++ b/src/SJZY.Track.Repository/Queries/ProvideQueries.cs
@@ -6,6 +6,7 @@ using SJZY.Track.Domain.Dtos.Order;
using SJZY.Track.Domain.Dtos.TrackDetails;
using SJZY.Track.Domain.Dtos.TrackTemplate;
using SJZY.Track.Domain.Queries;
+using SJZY.Track.Domain.VEntities;
namespace SJZY.Track.Repository.Queries;
@@ -105,4 +106,39 @@ public class ProvideQueries : ISugarRepository, IProvideQueries,
.Select(x => x.TrackContentCode)
.ToListAsync();
}
+
+
+ public async Task> FindOrderWithServiceProviderAsync(List orderNos)
+ {
+ return await Context.Queryable()
+ .LeftJoin((a, b) => a.Id == b.OrderId)
+ .LeftJoin((a, b, c) => b.ServiceProviderId == c.Id)
+ .Where(a => orderNos.Contains(a.OrderNo))
+ .Select((a, b, c) => new OrderWithServiceProviderVO
+ {
+ OrderNo = a.OrderNo,
+ OrderType = a.OrderType,
+ ServiceProviderId = b.ServiceProviderId,
+ ServiceProviderCode = c.Code,
+ SubSystemId = a.SubSystemId
+ })
+ .ToListAsync();
+ }
+
+ public async Task> FindOrderWithServiceProviderAsync(int serviceProvider)
+ {
+ return await Context.Queryable()
+ .RightJoin((a, b) => a.Id == b.OrderId)
+ .LeftJoin((a, b, c) => b.ServiceProviderId == c.Id)
+ .Where((a, b) => b.ServiceProviderId == serviceProvider && !a.IsCompleted)
+ .Select((a, b, c) => new OrderWithServiceProviderVO
+ {
+ OrderNo = a.OrderNo,
+ OrderType = a.OrderType,
+ ServiceProviderId = b.ServiceProviderId,
+ ServiceProviderCode = c.Code,
+ SubSystemId = a.SubSystemId
+ })
+ .ToListAsync();
+ }
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs
index 47c0bb60..633db8c2 100644
--- a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs
+++ b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs
@@ -1,7 +1,6 @@
using SJZY.Track.Domain;
using SJZY.Track.Domain.Aggregates.OrderAggregate;
using SJZY.Track.Domain.Dtos.Order;
-using SJZY.Track.Domain.VEntities;
namespace SJZY.Track.Repository.Repositories;
@@ -84,38 +83,4 @@ public class OrderRepository : BasicRepository, IOrderRepository, I
}
#endregion
-
- public async Task> FindServiceProviderByOrderAsync(List orderNos)
- {
- return await Context.Queryable()
- .LeftJoin((a, b) => a.Id == b.OrderId)
- .LeftJoin((a, b, c) => b.ServiceProviderId == c.Id)
- .Where(a => orderNos.Contains(a.OrderNo))
- .Select((a, b, c) => new OrderServiceProviderVO
- {
- OrderNo = a.OrderNo,
- OrderType = a.OrderType,
- ServiceProviderId = b.ServiceProviderId,
- ServiceProviderCode = c.Code,
- SubSystemId = a.SubSystemId
- })
- .ToListAsync();
- }
-
- public async Task> FindOrderByServiceProviderAsync(int serviceProvider)
- {
- return await Context.Queryable()
- .RightJoin((a, b) => a.Id == b.OrderId)
- .LeftJoin((a, b, c) => b.ServiceProviderId == c.Id)
- .Where((a, b) => b.ServiceProviderId == serviceProvider && !a.IsCompleted)
- .Select((a, b, c) => new OrderServiceProviderVO
- {
- OrderNo = a.OrderNo,
- OrderType = a.OrderType,
- ServiceProviderId = b.ServiceProviderId,
- ServiceProviderCode = c.Code,
- SubSystemId = a.SubSystemId
- })
- .ToListAsync();
- }
}
\ No newline at end of file
From b10f1cedfdf0ea5dc619dd44a0cba8a621fa041e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9F=B3=E6=96=87=E7=BF=94?= <878130837@qq.com>
Date: Fri, 15 Mar 2024 17:06:46 +0800
Subject: [PATCH 5/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../TrackPushContentConfigDto.cs | 13 +++++++
.../Services/ITrackPushCacheService.cs | 2 +-
.../TrackPush/TrackPushCacheService.cs | 39 ++++++++++++-------
.../Services/TrackPush/TrackPushService.cs | 2 +
4 files changed, 40 insertions(+), 16 deletions(-)
diff --git a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs
index ed2e02d0..578c298d 100644
--- a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs
+++ b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs
@@ -1,5 +1,18 @@
namespace SJZY.Track.Application.Contract.Dtos.ProvideServices;
+public class TrackPushConfigDto
+{
+ ///
+ /// 是否自动推送
+ ///
+ public bool IsAutoPush { get; set; }
+
+ ///
+ /// 轨迹推送内容配置
+ ///
+ public List ContentConfigs { get; set; }
+}
+
public class TrackPushContentConfigDto
{
///
diff --git a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
index cc7fec74..77c35661 100644
--- a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
+++ b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
@@ -29,5 +29,5 @@ public interface ITrackPushCacheService
/// 子系统id
/// 客户id
///
- Task> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null);
+ Task SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null);
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
index b5988ab3..c0eca26e 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
@@ -21,40 +21,39 @@ public class TrackPushCacheService : ApplicationService, ITrackPushCacheService,
[NonAction]
public async Task> GetPushContentConfigsAsync(int subSystemId, int customId)
{
- var data = await RedisHelper.Client.GetAsync>(TrackPushContentKey(subSystemId, customId));
+ var data = await GetPushConfigAsync(subSystemId, customId);
- data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId);
-
- return data;
+ return data.ContentConfigs;
}
[NonAction]
public async Task InferNextPushContentOrNullAsync(int subSystemId, int customId, int? trackContentId)
{
- var data = await GetPushContentConfigsAsync(subSystemId, customId);
+ var data = await GetPushConfigAsync(subSystemId, customId);
+ if (!data.IsAutoPush) return null;
if (trackContentId.HasValue)
{
- if (data.Count > 1 && data.Any(x => x.TrackContentId == trackContentId))
+ if (data.ContentConfigs.Count > 1 && data.ContentConfigs.Any(x => x.TrackContentId == trackContentId))
{
- int index = data.FindIndex(x => x.TrackContentId == trackContentId);
- int nextIndex = (index + 1) % data.Count; // 计算下一个索引,处理最后一个元素的情况
+ int index = data.ContentConfigs.FindIndex(x => x.TrackContentId == trackContentId);
+ int nextIndex = (index + 1) % data.ContentConfigs.Count; // 计算下一个索引,处理最后一个元素的情况
- return data[nextIndex];
+ return data.ContentConfigs[nextIndex];
}
else return null;
}
- else return data.FirstOrDefault();
+ else return data.ContentConfigs.FirstOrDefault();
}
[NonAction]
- public async Task> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null)
+ public async Task SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null)
{
- var data = new List();
+ var data = new TrackPushConfigDto { ContentConfigs = [] };
+
Expression> exp = x => true;
if (id.HasValue) exp = x => x.Id == id;
- else if (subSystemId.HasValue && customId.HasValue)
- exp = x => x.SubSystemId == subSystemId && x.CustomId == customId;
+ else if (subSystemId.HasValue && customId.HasValue) exp = x => x.SubSystemId == subSystemId && x.CustomId == customId;
var trackPushConfigEntity = await _trackPushConfigRepository.GetFirstAsync(exp);
if (trackPushConfigEntity == null) return data;
@@ -64,10 +63,20 @@ public class TrackPushCacheService : ApplicationService, ITrackPushCacheService,
trackPushContentList = trackPushContentList.OrderBy(x => x.Sort).ToList();
- data = ObjectMapper.Map, List>(trackPushContentList);
+ data.IsAutoPush = trackPushConfigEntity.IsAutoPush;
+ data.ContentConfigs = ObjectMapper.Map, List>(trackPushContentList);
await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data, (int)TimeSpan.FromDays(1).TotalSeconds);
return data;
}
+
+ private async Task GetPushConfigAsync(int subSystemId, int customId)
+ {
+ var data = await RedisHelper.Client.GetAsync(TrackPushContentKey(subSystemId, customId));
+
+ data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId);
+
+ return data;
+ }
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
index e7498c2c..712bbc3c 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
@@ -142,6 +142,8 @@ public class TrackPushService : ApplicationService
ts.Complete();
}
+
+ if (input.IsAutoPush!.Value) await _trackPushCacheService.SetPushContentConfigsAsync(input.Id);
}
break;
From 2845acce761db12249e993c9964e4dd001c2844f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9F=B3=E6=96=87=E7=BF=94?= <878130837@qq.com>
Date: Fri, 15 Mar 2024 17:10:11 +0800
Subject: [PATCH 6/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=9E=E7=8E=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Services/TrackPush/TrackPushCacheService.cs | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
index eb0f3910..0b8f4378 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
@@ -25,10 +25,13 @@ public class TrackPushCacheService : ApplicationService, ITrackPushCacheService,
return data.ContentConfigs;
}
-
- public Task GetPushContentConfigAsync(int subSystemId, int customId, int trackContentId)
+
+ [NonAction]
+ public async Task GetPushContentConfigAsync(int subSystemId, int customId, int trackContentId)
{
- throw new NotImplementedException();
+ var data = await GetPushContentConfigsAsync(subSystemId, customId);
+
+ return data.Single(x => x.TrackContentId == trackContentId);
}
[NonAction]
From b484a53711c37fd2d3920fc1d9ddc294af50141a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9F=B3=E6=96=87=E7=BF=94?= <878130837@qq.com>
Date: Fri, 15 Mar 2024 17:12:24 +0800
Subject: [PATCH 7/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=BC=93=E5=AD=98?=
=?UTF-8?q?=E6=97=B6=E9=97=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Services/TrackPull/TrackPullCacheService.cs | 3 +--
.../Services/TrackPush/TrackPushCacheService.cs | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs b/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs
index 1a57ea08..b5418f24 100644
--- a/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs
@@ -73,8 +73,7 @@ public class TrackPullCacheService : ApplicationService, ITrackPullCacheService,
trackPullContentList);
await RedisHelper.Client.SetAsync(
- TrackPullContentKey(trackPullConfigEntity.SubSystemId, trackPullConfigEntity.ServiceProviderId), data,
- (int)TimeSpan.FromDays(1).TotalSeconds);
+ TrackPullContentKey(trackPullConfigEntity.SubSystemId, trackPullConfigEntity.ServiceProviderId), data);
return data;
}
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
index 0b8f4378..30766856 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
@@ -74,7 +74,7 @@ public class TrackPushCacheService : ApplicationService, ITrackPushCacheService,
data.IsAutoPush = trackPushConfigEntity.IsAutoPush;
data.ContentConfigs = ObjectMapper.Map, List>(trackPushContentList);
- await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data, (int)TimeSpan.FromDays(1).TotalSeconds);
+ await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data);
return data;
}
From 25b7fc724ad359d09de2e26589806d14f11ad5f6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=86=9B?= <2357729423@qq.com>
Date: Fri, 15 Mar 2024 17:47:10 +0800
Subject: [PATCH 8/8] =?UTF-8?q?=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../EventHandlers/TrackDeleteEventHandler.cs | 3 ++-
.../Services/ProvideServices/TrackPushService.cs | 4 ++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/SJZY.Track.Application/EventHandlers/TrackDeleteEventHandler.cs b/src/SJZY.Track.Application/EventHandlers/TrackDeleteEventHandler.cs
index 1994118d..1bbf3aac 100644
--- a/src/SJZY.Track.Application/EventHandlers/TrackDeleteEventHandler.cs
+++ b/src/SJZY.Track.Application/EventHandlers/TrackDeleteEventHandler.cs
@@ -76,7 +76,8 @@ public class TrackDeleteEventHandler : ITransientDependency, ICapSubscribe
TrackEnContent = track.TrackEnContent,
TrackPlace = track.TrackPlace,
TrackTime = track.TrackTime,
- TrackTimeZone = track.TrackTimeZone
+ TrackTimeZone = track.TrackTimeZone,
+ IsDelete = true
};
await _capPublisher.PublishAsync(GlobalConst.UpdateOrderTrackSubscribe, updateOrderEvent);
}
diff --git a/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs b/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs
index 10b28796..03e18f69 100644
--- a/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs
+++ b/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs
@@ -59,8 +59,8 @@ public class TrackPushService : ApplicationService
{
var trackContent = trackContents.FirstOrDefault(x => x.SubSystemId == group.Key.SubSystemId);
if (trackContent == null) continue;
- await _pushCacheService.GetPushContentConfigAsync(group.Key.SubSystemId, group.Key.CustomId,
- trackContent.Id);
+ var config = await _pushCacheService.GetPushContentConfigAsync(group.Key.SubSystemId,
+ group.Key.CustomId, trackContent.Id);
var data = group.Select(x => new
{
x.OrderNo