Merge branch 'S02-轨迹中台' into test
This commit is contained in:
commit
e738cc711c
@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
||||
|
||||
public class PushTrackInput : OrderNosInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 轨迹code,必填
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string TrackCode { get; set; } = null!;
|
||||
}
|
||||
@ -1,5 +1,18 @@
|
||||
namespace SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
||||
|
||||
public class TrackPushConfigDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否自动推送
|
||||
/// </summary>
|
||||
public bool IsAutoPush { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹推送内容配置
|
||||
/// </summary>
|
||||
public List<TrackPushContentConfigDto> ContentConfigs { get; set; }
|
||||
}
|
||||
|
||||
public class TrackPushContentConfigDto
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@ -4,13 +4,6 @@ namespace SJZY.Track.Application.Contract.Services;
|
||||
|
||||
public interface ITrackPushCacheService
|
||||
{
|
||||
/// <summary>
|
||||
/// 判断客户是否需要推送
|
||||
/// </summary>
|
||||
/// <param name="customId"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> IsPushAsync(int customId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务商拉取配置
|
||||
/// </summary>
|
||||
@ -19,6 +12,15 @@ public interface ITrackPushCacheService
|
||||
/// <returns></returns>
|
||||
Task<List<TrackPushContentConfigDto>> GetPushContentConfigsAsync(int subSystemId, int customId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务商拉取配置
|
||||
/// </summary>
|
||||
/// <param name="subSystemId">子系统id</param>
|
||||
/// <param name="customId">服务商id</param>
|
||||
/// <param name="trackContentId"></param>
|
||||
/// <returns></returns>
|
||||
Task<TrackPushContentConfigDto> GetPushContentConfigAsync(int subSystemId, int customId, int trackContentId);
|
||||
|
||||
/// <summary>
|
||||
/// 根据轨迹代码推断下一个(升序)要推送的内容,如果找不到或者已经是最后一个了,返回null
|
||||
/// </summary>
|
||||
@ -30,9 +32,11 @@ public interface ITrackPushCacheService
|
||||
int? trackContentId);
|
||||
|
||||
/// <summary>
|
||||
/// 更新缓存
|
||||
/// 设置推送配置缓存
|
||||
/// </summary>
|
||||
/// <param name="customId"></param>
|
||||
/// <param name="isPush"></param>
|
||||
Task UpdateAsync(int customId, bool isPush);
|
||||
/// <param name="id"></param>
|
||||
/// <param name="subSystemId">子系统id</param>
|
||||
/// <param name="customId">客户id</param>
|
||||
/// <returns></returns>
|
||||
Task<TrackPushConfigDto> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null);
|
||||
}
|
||||
@ -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<EditTrackPushConfigInput, TrackPushPullParamsConfigEntity>(MemberList.None).Ignore(dest => dest.Id)
|
||||
.ForMember(dest => dest.IsPush, opt => opt.MapFrom(source => true));
|
||||
CreateMap<EditTrackPushContentInput, TrackPushContentConfigEntity>(MemberList.None);
|
||||
CreateMap<TrackPushContentConfigEntity, TrackPushContentConfigDto>(MemberList.None)
|
||||
.ForMember(dest => dest.OrderType, opt => opt.MapFrom(source => source.OrderNoType));
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
};
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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!,
|
||||
|
||||
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹推送、拉取服务
|
||||
/// 轨迹刷新服务
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "提供接口")]
|
||||
[Route("/ProviderService")]
|
||||
public class TrackPushPullService : ApplicationService
|
||||
public class TrackPullService : ApplicationService
|
||||
{
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
private readonly IProvideQueries _provideQueries;
|
||||
private readonly IHttpClientProxy<IInterfaceForwardServiceV2> _httpClientProxy;
|
||||
private readonly ITrackPullCacheService _trackPullCacheService;
|
||||
|
||||
public TrackPushPullService(IOrderRepository orderRepository,
|
||||
public TrackPullService(IProvideQueries provideQueries,
|
||||
IHttpClientProxy<IInterfaceForwardServiceV2> httpClientProxy,
|
||||
ITrackPullCacheService trackPullCacheService)
|
||||
{
|
||||
_orderRepository = orderRepository;
|
||||
_provideQueries = provideQueries;
|
||||
_httpClientProxy = httpClientProxy;
|
||||
_trackPullCacheService = trackPullCacheService;
|
||||
}
|
||||
@ -38,17 +39,16 @@ public class TrackPushPullService : ApplicationService
|
||||
public async Task<bool> 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
|
||||
/// 定时任务刷新轨迹
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpPost("Track/RefreshForTask")]
|
||||
public async Task<bool> 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,
|
||||
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹推送服务
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "提供接口")]
|
||||
[Route("/ProviderService")]
|
||||
public class TrackPushService : ApplicationService
|
||||
{
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
private readonly ITrackContentRepository _trackContentRepository;
|
||||
private readonly ITrackPushCacheService _pushCacheService;
|
||||
private readonly IHttpClientProxy<IInterfaceForwardServiceV2> _httpClientProxy;
|
||||
|
||||
public TrackPushService(IOrderRepository orderRepository,
|
||||
IHttpClientProxy<IInterfaceForwardServiceV2> httpClientProxy, ITrackPushCacheService pushCacheService,
|
||||
ITrackContentRepository trackContentRepository)
|
||||
{
|
||||
_orderRepository = orderRepository;
|
||||
_httpClientProxy = httpClientProxy;
|
||||
_pushCacheService = pushCacheService;
|
||||
_trackContentRepository = trackContentRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 推送轨迹
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Track/Push")]
|
||||
public async Task<bool> 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;
|
||||
var config = 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;
|
||||
}
|
||||
}
|
||||
@ -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<UpsertTrackInput, TrackUpsertEvent>(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);
|
||||
|
||||
@ -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);
|
||||
@ -71,8 +73,7 @@ public class TrackPullCacheService : ApplicationService, ITrackPullCacheService
|
||||
trackPullContentList);
|
||||
|
||||
await RedisHelper.Client.SetAsync(
|
||||
TrackPullContentKey(trackPullConfigEntity.SubSystemId, trackPullConfigEntity.ServiceProviderId), data,
|
||||
86400);
|
||||
TrackPullContentKey(trackPullConfigEntity.SubSystemId, trackPullConfigEntity.ServiceProviderId), data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -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 _trackPullCacheService.SetPullConfigAsync(oldTrackPullContentEntity.TrackPullConfigId);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,
|
||||
|
||||
@ -2,40 +2,89 @@
|
||||
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
||||
using SJZY.Track.Application.Contract.Services;
|
||||
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
|
||||
using SJZY.Track.Domain.Queries;
|
||||
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<TrackPushConfigEntity> _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<TrackPushConfigEntity> trackPushConfigQuery)
|
||||
public TrackPushCacheService(ITrackPushConfigRepository trackPushConfigRepository)
|
||||
{
|
||||
_trackPushConfigQuery = trackPushConfigQuery;
|
||||
_trackPushConfigRepository = trackPushConfigRepository;
|
||||
}
|
||||
|
||||
public Task<bool> IsPushAsync(int customId)
|
||||
[NonAction]
|
||||
public async Task<List<TrackPushContentConfigDto>> GetPushContentConfigsAsync(int subSystemId, int customId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var data = await GetPushConfigAsync(subSystemId, customId);
|
||||
|
||||
return data.ContentConfigs;
|
||||
}
|
||||
|
||||
public Task<List<TrackPushContentConfigDto>> GetPushContentConfigsAsync(int subSystemId, int customId)
|
||||
[NonAction]
|
||||
public async Task<TrackPushContentConfigDto> GetPushContentConfigAsync(int subSystemId, int customId, int trackContentId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var data = await GetPushContentConfigsAsync(subSystemId, customId);
|
||||
|
||||
return data.Single(x => x.TrackContentId == trackContentId);
|
||||
}
|
||||
|
||||
public Task<TrackPushContentConfigDto?> InferNextPushContentOrNullAsync(int subSystemId, int customId,
|
||||
int? trackContentId)
|
||||
[NonAction]
|
||||
public async Task<TrackPushContentConfigDto?> InferNextPushContentOrNullAsync(int subSystemId, int customId, int? trackContentId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var data = await GetPushConfigAsync(subSystemId, customId);
|
||||
if (!data.IsAutoPush) return null;
|
||||
|
||||
if (trackContentId.HasValue)
|
||||
{
|
||||
if (data.ContentConfigs.Count > 1 && data.ContentConfigs.Any(x => x.TrackContentId == trackContentId))
|
||||
{
|
||||
int index = data.ContentConfigs.FindIndex(x => x.TrackContentId == trackContentId);
|
||||
int nextIndex = (index + 1) % data.ContentConfigs.Count; // 计算下一个索引,处理最后一个元素的情况
|
||||
|
||||
return data.ContentConfigs[nextIndex];
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
else return data.ContentConfigs.FirstOrDefault();
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(int customId, bool isPush)
|
||||
[NonAction]
|
||||
public async Task<TrackPushConfigDto> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null)
|
||||
{
|
||||
await RedisHelper.Client.SetAsync(RedisKey(customId), isPush);
|
||||
var data = new TrackPushConfigDto { ContentConfigs = [] };
|
||||
|
||||
Expression<Func<TrackPushConfigEntity, bool>> 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;
|
||||
|
||||
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.IsAutoPush = trackPushConfigEntity.IsAutoPush;
|
||||
data.ContentConfigs = ObjectMapper.Map<List<TrackPushContentConfigEntity>, List<TrackPushContentConfigDto>>(trackPushContentList);
|
||||
|
||||
await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private async Task<TrackPushConfigDto> GetPushConfigAsync(int subSystemId, int customId)
|
||||
{
|
||||
var data = await RedisHelper.Client.GetAsync<TrackPushConfigDto>(TrackPushContentKey(subSystemId, customId));
|
||||
|
||||
data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId);
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -94,8 +94,7 @@ public class TrackPushService : ApplicationService
|
||||
if (input.Options != OptionTypeNoNull.删除)
|
||||
{
|
||||
Expression<Func<TrackPushConfigEntity, bool>> 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))
|
||||
@ -117,8 +116,6 @@ public class TrackPushService : ApplicationService
|
||||
trackPushParamsEntity.PullOrPushConfigId = id;
|
||||
await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity);
|
||||
|
||||
if (input.IsAutoPush!.Value) await _trackPushCacheService.IsPushAsync(input.CustomId!.Value);
|
||||
|
||||
ts.Complete();
|
||||
}
|
||||
}
|
||||
@ -143,11 +140,10 @@ public class TrackPushService : ApplicationService
|
||||
await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity);
|
||||
await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPushParamsEntity);
|
||||
|
||||
await _trackPushCacheService.UpdateAsync(oldCustomId, false);
|
||||
if (input.IsAutoPush!.Value) await _trackPushCacheService.IsPushAsync(input.CustomId!.Value);
|
||||
|
||||
ts.Complete();
|
||||
}
|
||||
|
||||
if (input.IsAutoPush!.Value) await _trackPushCacheService.SetPushContentConfigsAsync(input.Id);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -162,7 +158,6 @@ public class TrackPushService : ApplicationService
|
||||
await _trackPullConfigRepository.SoftDeleteParamsAsync(x =>
|
||||
x.PullOrPushConfigId == input.Id && x.IsPush);
|
||||
await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id);
|
||||
await _trackPushCacheService.UpdateAsync(oldTrackPushEntity.CustomId, false);
|
||||
|
||||
ts.Complete();
|
||||
}
|
||||
@ -223,6 +218,7 @@ public class TrackPushService : ApplicationService
|
||||
entity.Sort = maxSort + 1;
|
||||
|
||||
await _trackPushConfigRepository.InsertContentAsync(entity);
|
||||
await _trackPushCacheService.SetPushContentConfigsAsync(input.TrackPushConfigId);
|
||||
|
||||
break;
|
||||
}
|
||||
@ -235,6 +231,7 @@ public class TrackPushService : ApplicationService
|
||||
ObjectMapper.Map(input, entity);
|
||||
|
||||
await _trackPushConfigRepository.UpdateContentAsync(entity);
|
||||
await _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId);
|
||||
|
||||
break;
|
||||
}
|
||||
@ -247,13 +244,14 @@ public class TrackPushService : ApplicationService
|
||||
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;
|
||||
}
|
||||
|
||||
@ -282,7 +280,11 @@ public class TrackPushService : ApplicationService
|
||||
item.Sort = input.SortInfo.Single(x => x.Key == item.Id.ToString()).Value;
|
||||
});
|
||||
|
||||
if (trackPushContentEntities.Count > 0)
|
||||
{
|
||||
await _trackPushConfigRepository.UpdateContentRangeAsync(trackPushContentEntities);
|
||||
await _trackPushCacheService.SetPushContentConfigsAsync(trackPushContentEntities[0].TrackPushConfigId);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -50,19 +50,4 @@ public interface IOrderRepository : IBasicRepository<OrderEntity>
|
||||
Task UnLinkByIdsAsync(List<int> linkIds);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据订单模板找对应服务商
|
||||
/// </summary>
|
||||
/// <param name="orderNos"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<OrderServiceProviderVO>> FindServiceProviderByOrderAsync(List<string> orderNos);
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务商下所有单(未完成的)
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<OrderServiceProviderVO>> FindOrderByServiceProviderAsync(int serviceProvider);
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
namespace SJZY.Track.Domain.Dtos.Order;
|
||||
|
||||
public class OrderServiceProviderVO
|
||||
public class OrderWithServiceProviderVO
|
||||
{
|
||||
public string OrderNo { get; set; } = null!;
|
||||
|
||||
@ -48,4 +48,18 @@ public interface IProvideQueries
|
||||
/// <param name="trackCodes"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<string>> MapTrackCodesAsync(int upSubSystemId, int subSystemId, params string[] trackCodes);
|
||||
|
||||
/// <summary>
|
||||
/// 根据订单模板找对应服务商
|
||||
/// </summary>
|
||||
/// <param name="orderNos"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<OrderWithServiceProviderVO>> FindOrderWithServiceProviderAsync(List<string> orderNos);
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务商下所有单(未完成的)
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<OrderWithServiceProviderVO>> FindOrderWithServiceProviderAsync(int serviceProvider);
|
||||
}
|
||||
@ -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<List<OrderWithServiceProviderVO>> FindOrderWithServiceProviderAsync(List<string> orderNos)
|
||||
{
|
||||
return await Context.Queryable<OrderEntity>()
|
||||
.LeftJoin<OrderTemplateEntity>((a, b) => a.Id == b.OrderId)
|
||||
.LeftJoin<VServiceProviderEntity>((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<List<OrderWithServiceProviderVO>> FindOrderWithServiceProviderAsync(int serviceProvider)
|
||||
{
|
||||
return await Context.Queryable<OrderEntity>()
|
||||
.RightJoin<OrderTemplateEntity>((a, b) => a.Id == b.OrderId)
|
||||
.LeftJoin<VServiceProviderEntity>((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();
|
||||
}
|
||||
}
|
||||
@ -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<OrderEntity>, IOrderRepository, I
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public async Task<List<OrderServiceProviderVO>> FindServiceProviderByOrderAsync(List<string> orderNos)
|
||||
{
|
||||
return await Context.Queryable<OrderEntity>()
|
||||
.LeftJoin<OrderTemplateEntity>((a, b) => a.Id == b.OrderId)
|
||||
.LeftJoin<VServiceProviderEntity>((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<List<OrderServiceProviderVO>> FindOrderByServiceProviderAsync(int serviceProvider)
|
||||
{
|
||||
return await Context.Queryable<OrderEntity>()
|
||||
.RightJoin<OrderTemplateEntity>((a, b) => a.Id == b.OrderId)
|
||||
.LeftJoin<VServiceProviderEntity>((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();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user