Merge branch 'S01-轨迹中台' of http://192.168.80.50:3000/Dotnet/SJZY.Track.Api into S01-轨迹中台
This commit is contained in:
commit
e6ae2ca464
@ -1,6 +0,0 @@
|
||||
namespace SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
||||
|
||||
public class TrackUpsertEvent
|
||||
{
|
||||
public int Order { get; set; }
|
||||
}
|
||||
@ -5,12 +5,12 @@ public class UpsertTrackInput : OrderNoInfo
|
||||
/// <summary>
|
||||
/// 轨迹内容代码
|
||||
/// </summary>
|
||||
public string TrackCode { get; set; }
|
||||
public string TrackCode { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹发生地
|
||||
/// </summary>
|
||||
public string TrackPlace { get; set; }
|
||||
public string TrackPlace { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹发生时间
|
||||
|
||||
@ -0,0 +1,81 @@
|
||||
namespace SJZY.Track.Application.Contract.Dtos.TrackPush;
|
||||
|
||||
public class EditTrackPushConfigInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 客户id
|
||||
/// </summary>
|
||||
public int CustomId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 推送扩展字段
|
||||
/// </summary>
|
||||
public string ExpandFieldsName { get; set; }
|
||||
|
||||
public int? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否自动推送
|
||||
/// </summary>
|
||||
public bool IsAutoPush { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 操作类型
|
||||
/// </summary>
|
||||
public OptionTypeNoNull Options { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 推送轨迹订单号
|
||||
/// </summary>
|
||||
public string OrderNoName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 服务商id
|
||||
/// </summary>
|
||||
public int ServiceProviderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子系统id
|
||||
/// </summary>
|
||||
public int SubSystemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 推送轨迹时区
|
||||
/// </summary>
|
||||
public string TackTimeZoneName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 推送轨迹内容代码
|
||||
/// </summary>
|
||||
public string TrackContentCodeName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 推送轨迹内容
|
||||
/// </summary>
|
||||
public string TrackContentName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 推送轨迹内容英文
|
||||
/// </summary>
|
||||
public string TrackEnContentName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 推送轨迹发生地
|
||||
/// </summary>
|
||||
public string TrackPlaceName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 推送轨迹状态
|
||||
/// </summary>
|
||||
public string TrackStatusName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹模板id
|
||||
/// </summary>
|
||||
public List<int> TrackTemplateIds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 推送轨迹发生时间
|
||||
/// </summary>
|
||||
public string TrackTimeName { get; set; }
|
||||
}
|
||||
@ -1,6 +1,21 @@
|
||||
namespace SJZY.Track.Application.Contract.Events;
|
||||
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
||||
|
||||
public class TrackUpsertEvent
|
||||
namespace SJZY.Track.Application.Contract.Events;
|
||||
|
||||
public class TrackUpsertEvent : UpsertTrackInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 订单id
|
||||
/// </summary>
|
||||
public int OrderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子系统id
|
||||
/// </summary>
|
||||
public int SubSystemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上游子系统id
|
||||
/// </summary>
|
||||
public int UpSubSystemId { get; set; }
|
||||
}
|
||||
@ -1,14 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="../../common.props"/>
|
||||
<Import Project="../../common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Version>0.0.2</Version>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SJZY.Expand.ABP.Common" Version="7.0.11"/>
|
||||
<PackageReference Include="Volo.Abp.Core" Version="7.0.2"/>
|
||||
<PackageReference Include="SJZY.Expand.ABP.Common" Version="7.0.11" />
|
||||
<PackageReference Include="Volo.Abp.Core" Version="7.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
using AutoMapper;
|
||||
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
||||
using SJZY.Track.Application.Contract.Events;
|
||||
|
||||
namespace SJZY.Track.Application.AutoMapper;
|
||||
|
||||
public class TrackAutoMapperProfile:Profile
|
||||
{
|
||||
public TrackAutoMapperProfile()
|
||||
{
|
||||
CreateMap<UpsertTrackInput, TrackUpsertEvent>(MemberList.None);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,8 @@
|
||||
using AutoMapper;
|
||||
using SJZY.Track.Application.Contract.Dtos.TrackPush;
|
||||
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
|
||||
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
|
||||
using Volo.Abp.AutoMapper;
|
||||
|
||||
namespace SJZY.Track.Application.AutoMapper;
|
||||
|
||||
@ -6,5 +10,9 @@ public class TrackPushAutoMapperProfile : Profile
|
||||
{
|
||||
public TrackPushAutoMapperProfile()
|
||||
{
|
||||
CreateMap<EditTrackPushConfigInput, TrackPushConfigEntity>(MemberList.None)
|
||||
.ForMember(dest => dest.TrackTemplateId, opt => opt.MapFrom(source => string.Join(',', source.TrackTemplateIds)));
|
||||
CreateMap<EditTrackPushConfigInput, TrackPushPullParamsConfigEntity>(MemberList.None).Ignore(dest => dest.Id)
|
||||
.ForMember(dest => dest.IsPush, opt => opt.MapFrom(source => true));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,108 @@
|
||||
using DotNetCore.CAP;
|
||||
using SJZY.Expand.ABP.Core.PublicMethords;
|
||||
using SJZY.Track.Application.Contract.Events;
|
||||
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
||||
using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
|
||||
using SJZY.Track.Domain.Queries;
|
||||
using SJZY.UserCenter.HttpApi.Services;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace SJZY.Track.Application.EventHandlers;
|
||||
|
||||
public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
||||
{
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
private readonly ITrackQueries _trackQueries;
|
||||
private readonly ITrackDetailsRepository _trackDetailsRepository;
|
||||
private readonly ICapPublisher _capPublisher;
|
||||
|
||||
public TrackUpsertEventHandler(IOrderRepository orderRepository, ICapPublisher capPublisher,
|
||||
ITrackQueries trackQueries, ITrackDetailsRepository trackDetailsRepository)
|
||||
{
|
||||
_orderRepository = orderRepository;
|
||||
_capPublisher = capPublisher;
|
||||
_trackQueries = trackQueries;
|
||||
_trackDetailsRepository = trackDetailsRepository;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[CapSubscribe(GlobalConst.TrackUpsertSubscribe)]
|
||||
public async Task ConsumerAsync(TrackUpsertEvent @event)
|
||||
{
|
||||
// 不同子系统需要做内容映射
|
||||
if (@event.UpSubSystemId != @event.SubSystemId)
|
||||
{
|
||||
var mapCode = await _trackQueries.MapTrackContentCodeAsync(@event.UpSubSystemId, @event.SubSystemId, @event.TrackCode);
|
||||
|
||||
if (mapCode == default)
|
||||
{
|
||||
throw new BusinessException(message: "订单跨子系统,未配置内容映射,请联系管理员");
|
||||
}
|
||||
|
||||
@event.TrackCode = mapCode;
|
||||
}
|
||||
|
||||
await UpsertTrackAsync(@event);
|
||||
}
|
||||
|
||||
internal async Task UpsertTrackAsync(TrackUpsertEvent @event)
|
||||
{
|
||||
// 不存在则新增轨迹,存在则更新
|
||||
var track = await _trackDetailsRepository.GetFirstOrDefaultAsync(@event.OrderId, @event.TrackCode);
|
||||
|
||||
var isPush = false; // 推送只做新增的,更新和删除的不做先
|
||||
if (track == default)
|
||||
{
|
||||
// 根据轨迹code在订单模板内容中寻找匹配的
|
||||
var trackContent = await _trackQueries.MatchTrackContentAsync(@event.OrderId, @event.TrackCode);
|
||||
if (trackContent == default)
|
||||
{
|
||||
throw new BusinessException(message: $"订单:{@event.OrderNo} 所绑定的模板,没有一条内容可以匹配轨迹代码:{@event.TrackCode}");
|
||||
}
|
||||
|
||||
track = new TrackDetailsIndex
|
||||
{
|
||||
OrderId = @event.OrderId,
|
||||
OrderNo = @event.OrderNo,
|
||||
OrderType = @event.OrderType,
|
||||
TrackStatus = trackContent.Status,
|
||||
TrackCode = @event.TrackCode,
|
||||
TrackContent = trackContent.Content,
|
||||
TrackEnContent = trackContent.EnContent,
|
||||
TrackPlace = @event.TrackPlace,
|
||||
TrackTime = @event.TrackTime,
|
||||
TraceTimeZone = @event.TraceTimeZone,
|
||||
CreateUserId = CurrentUserRequest.CurrentUser.UserId,
|
||||
CreateTime = DateTime.Now
|
||||
};
|
||||
|
||||
isPush = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
track.TrackPlace = @event.TrackPlace;
|
||||
track.TrackTime = @event.TrackTime;
|
||||
track.TraceTimeZone = @event.TraceTimeZone;
|
||||
track.UpdateUserId = CurrentUserRequest.CurrentUser.UserId;
|
||||
track.UpdateTime = DateTime.Now;
|
||||
}
|
||||
|
||||
await _trackDetailsRepository.UpsertAsync(track);
|
||||
|
||||
// 根据订单关联关系异步向下刷
|
||||
var linkedOrders = await _orderRepository.GetLinkedOrdersAsync(@event.OrderId);
|
||||
foreach (var linkedOrder in linkedOrders)
|
||||
{
|
||||
var nextEvent = @event.DeepCopy();
|
||||
nextEvent.OrderId = linkedOrder.OrderId;
|
||||
nextEvent.SubSystemId = linkedOrder.SubSystemId;
|
||||
nextEvent.UpSubSystemId = @event.SubSystemId;
|
||||
await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, nextEvent);
|
||||
}
|
||||
|
||||
if (isPush)
|
||||
{
|
||||
//await PushTrack();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="../../common.props"/>
|
||||
<Import Project="../../common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
@ -8,14 +8,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Http.Client" Version="7.0.2"/>
|
||||
<PackageReference Include="Volo.Abp.FluentValidation" Version="7.0.2"/>
|
||||
<PackageReference Include="SJZY.UserCenter.HttpApi" Version="3.0.3-alpha8"/>
|
||||
<PackageReference Include="SJZY.Expand.CAP" Version="7.8.0"/>
|
||||
<PackageReference Include="Volo.Abp.Http.Client" Version="7.0.2" />
|
||||
<PackageReference Include="Volo.Abp.FluentValidation" Version="7.0.2" />
|
||||
<PackageReference Include="SJZY.UserCenter.HttpApi" Version="3.0.3-alpha8" />
|
||||
<PackageReference Include="SJZY.Expand.CAP" Version="7.8.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SJZY.Track.Domain\SJZY.Track.Domain.csproj"/>
|
||||
<ProjectReference Include="..\SJZY.Track.Application.Contract\SJZY.Track.Application.Contract.csproj"/>
|
||||
<ProjectReference Include="..\SJZY.Track.Domain\SJZY.Track.Domain.csproj" />
|
||||
<ProjectReference Include="..\SJZY.Track.Application.Contract\SJZY.Track.Application.Contract.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
using DotNetCore.CAP;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace SJZY.Track.Application.Services.ProvideServices;
|
||||
|
||||
public class TrackCustomer : ITransientDependency, ICapSubscribe
|
||||
{
|
||||
public const string CapSubscribe = "SJZY.Track.Upsert";
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
namespace SJZY.Track.Application.Services.ProvideServices;
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹推送服务
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "提供接口")]
|
||||
public class TrackPushService: ApplicationService
|
||||
{
|
||||
|
||||
}
|
||||
@ -1,9 +1,7 @@
|
||||
using DotNetCore.CAP;
|
||||
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
||||
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
||||
using SJZY.Track.Application.Contract.Events;
|
||||
using SJZY.Track.Application.EventHandlers;
|
||||
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
||||
using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
|
||||
using SJZY.Track.Domain.Queries;
|
||||
using SJZY.UserCenter.HttpApi.Services;
|
||||
|
||||
namespace SJZY.Track.Application.Services.ProvideServices;
|
||||
|
||||
@ -14,17 +12,12 @@ namespace SJZY.Track.Application.Services.ProvideServices;
|
||||
public class TrackService : ApplicationService
|
||||
{
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
private readonly ITrackDetailsRepository _trackDetailsRepository;
|
||||
private readonly ITrackQueries _trackQueries;
|
||||
private readonly ICapPublisher _capPublisher;
|
||||
private readonly TrackUpsertEventHandler _trackUpsertEventHandler;
|
||||
|
||||
public TrackService(ITrackQueries trackQueries, IOrderRepository orderRepository,
|
||||
ITrackDetailsRepository trackDetailsRepository, ICapPublisher capPublisher)
|
||||
public TrackService(IOrderRepository orderRepository, TrackUpsertEventHandler trackUpsertEventHandler)
|
||||
{
|
||||
_trackQueries = trackQueries;
|
||||
_orderRepository = orderRepository;
|
||||
_trackDetailsRepository = trackDetailsRepository;
|
||||
_capPublisher = capPublisher;
|
||||
_trackUpsertEventHandler = trackUpsertEventHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -36,59 +29,21 @@ public class TrackService : ApplicationService
|
||||
[HttpPost("Track/Upsert")]
|
||||
public async Task<bool> UpsertTrackAsync(UpsertTrackInput input)
|
||||
{
|
||||
var orderId = await _orderRepository.GetFirstAsync(x =>
|
||||
x.OrderType == input.OrderType && x.OrderNo == input.OrderNo, x => x.Id);
|
||||
if (orderId == default)
|
||||
var order = await _orderRepository.GetFirstAsync(x =>
|
||||
x.OrderType == input.OrderType && x.OrderNo == input.OrderNo, x => new
|
||||
{
|
||||
x.Id, x.SubSystemId, x.IsPushCompleted
|
||||
});
|
||||
if (order == default)
|
||||
{
|
||||
throw new BusinessException(message: $"订单:{input.OrderNo}不存在");
|
||||
}
|
||||
|
||||
// 不存在则新增轨迹,存在则更新
|
||||
var track = await _trackDetailsRepository.GetFirstOrDefaultAsync(orderId, input.TrackCode);
|
||||
if (track == default)
|
||||
{
|
||||
var trackContent = await _trackQueries.MatchTrackContentAsync(orderId, input.TrackCode);
|
||||
if (trackContent == default)
|
||||
{
|
||||
throw new BusinessException(message: $"订单:{input.OrderNo} 所绑定的模板,没有一条内容可以匹配轨迹代码:{input.TrackCode}");
|
||||
}
|
||||
|
||||
track = new TrackDetailsIndex
|
||||
{
|
||||
OrderId = orderId,
|
||||
OrderNo = input.OrderNo,
|
||||
OrderType = input.OrderType,
|
||||
TrackStatus = trackContent.Status,
|
||||
TrackCode = input.TrackCode,
|
||||
TrackContent = trackContent.Content,
|
||||
TrackEnContent = trackContent.EnContent,
|
||||
TrackPlace = input.TrackPlace,
|
||||
TrackTime = input.TrackTime,
|
||||
TraceTimeZone = input.TraceTimeZone,
|
||||
CreateUserId = CurrentUserRequest.CurrentUser.UserId,
|
||||
CreateTime = DateTime.Now
|
||||
};
|
||||
await _trackDetailsRepository.CreateAsync(track);
|
||||
}
|
||||
else
|
||||
{
|
||||
track.UpdateUserId = CurrentUserRequest.CurrentUser.UserId;
|
||||
track.UpdateTime = DateTime.Now;
|
||||
track.TrackPlace = input.TrackPlace;
|
||||
track.TrackTime = input.TrackTime;
|
||||
track.TraceTimeZone = input.TraceTimeZone;
|
||||
await _trackDetailsRepository.UpdateAsync(track);
|
||||
}
|
||||
|
||||
// 根据订单关联关系向下刷,不同子系统还需要做内容映射
|
||||
var linkedOrderIds = await _orderRepository.GetLinkedOrderIdsAsync(orderId);
|
||||
|
||||
if (linkedOrderIds.Count > 0)
|
||||
{
|
||||
await _capPublisher.PublishAsync(TrackCustomer.CapSubscribe, new TrackUpsertEvent { });
|
||||
}
|
||||
|
||||
// 推送
|
||||
// 新增/更新轨迹
|
||||
var @event = ObjectMapper.Map<UpsertTrackInput, TrackUpsertEvent>(input);
|
||||
@event.OrderId = order.Id;
|
||||
@event.SubSystemId = order.SubSystemId;
|
||||
await _trackUpsertEventHandler.UpsertTrackAsync(@event);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,15 @@
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SJZY.Expand.ABP.Core.Localization;
|
||||
using SJZY.Expand.ABP.Core.PublicMethords;
|
||||
using SJZY.Track.Application.Contract.Dtos.TrackPush;
|
||||
using SJZY.Track.Application.Localization;
|
||||
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
|
||||
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
|
||||
using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate;
|
||||
using SJZY.Track.Domain.Dtos.Common;
|
||||
using SJZY.Track.Domain.Dtos.TrackPush;
|
||||
using SqlSugar;
|
||||
using System.Linq.Expressions;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace SJZY.Track.Application.Services.TrackPush;
|
||||
@ -16,13 +23,19 @@ public class TrackPushService : ApplicationService, ITransientDependency
|
||||
{
|
||||
private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer;
|
||||
private readonly ITrackPushConfigRepository _trackPushConfigRepository;
|
||||
private readonly ITrackTemplateRepository _trackTemplateRepository;
|
||||
private readonly ITrackPullConfigRepository _trackPullConfigRepository;
|
||||
|
||||
public TrackPushService(
|
||||
IStringLocalizer<TrackLocalizationResource> stringLocalizer,
|
||||
ITrackPushConfigRepository trackPushConfigRepository)
|
||||
ITrackPushConfigRepository trackPushConfigRepository,
|
||||
ITrackTemplateRepository trackTemplateRepository,
|
||||
ITrackPullConfigRepository trackPullConfigRepository)
|
||||
{
|
||||
_stringLocalizer = stringLocalizer;
|
||||
_trackPushConfigRepository = trackPushConfigRepository;
|
||||
_trackTemplateRepository = trackTemplateRepository;
|
||||
_trackPullConfigRepository = trackPullConfigRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -53,9 +66,18 @@ public class TrackPushService : ApplicationService, ITransientDependency
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetDetail")]
|
||||
public async Task<GetTrackPushConfigDetailOutputVO> GetDetailAsync(int id)
|
||||
public async Task<GetTrackPushConfigDetailOutputVO?> GetDetailAsync(int id)
|
||||
{
|
||||
return await _trackPushConfigRepository.GetDetailAsync(id);
|
||||
var res = await _trackPushConfigRepository.GetDetailAsync(id);
|
||||
if (res is null) return null;
|
||||
|
||||
List<int> trackTemplateIds = res.TrackTemplateId.Split(',').Select(int.Parse).ToList();
|
||||
|
||||
var trackTemplateEntities = await _trackTemplateRepository.GetListAsync(x => trackTemplateIds.Contains(x.Id));
|
||||
|
||||
trackTemplateEntities.ForEach(item => { (res.TrackTemplate ??= new()).Add(new() { Value = item.Id, Key = item.Name }); });
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -68,4 +90,86 @@ public class TrackPushService : ApplicationService, ITransientDependency
|
||||
{
|
||||
return await _trackPushConfigRepository.GetContentDetailAsync(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹推送配置编辑
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Edit")]
|
||||
public async Task<bool> EditAsync([FromBody] EditTrackPushConfigInput input)
|
||||
{
|
||||
if (input.Options != OptionTypeNoNull.删除)
|
||||
{
|
||||
Expression<Func<TrackPushConfigEntity, bool>> isAnyExp = x =>
|
||||
x.SubSystemId == input.SubSystemId && x.CustomId == input.CustomId && x.ServiceProviderId == input.ServiceProviderId;
|
||||
if (input.Options == OptionTypeNoNull.修改) isAnyExp.And(x => x.Id != input.Id);
|
||||
|
||||
var trackTemplateIdExp = Expressionable.Create<TrackPushConfigEntity>();
|
||||
foreach (var trackTemplateId in input.TrackTemplateIds) { trackTemplateIdExp.Or(x => SqlFunc.SplitIn(x.TrackTemplateId, trackTemplateId.ToString())); }
|
||||
|
||||
if (await _trackPushConfigRepository.IsAnyAsync(isAnyExp.And(trackTemplateIdExp.ToExpression())))
|
||||
throw new BusinessException(message: _stringLocalizer["IsTrackPushConfigAny"]);
|
||||
}
|
||||
|
||||
switch (input.Options)
|
||||
{
|
||||
case OptionTypeNoNull.新增:
|
||||
{
|
||||
var trackPushEntity = ObjectMapper.Map<EditTrackPushConfigInput, TrackPushConfigEntity>(input);
|
||||
var trackPushParamsEntity = ObjectMapper.Map<EditTrackPushConfigInput, TrackPushPullParamsConfigEntity>(input);
|
||||
|
||||
using (var ts = TransactionScopeHelper.Create())
|
||||
{
|
||||
int id = await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity);
|
||||
|
||||
trackPushParamsEntity.PullOrPushConfigId = id;
|
||||
await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity);
|
||||
|
||||
ts.Complete();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case OptionTypeNoNull.修改:
|
||||
{
|
||||
var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]);
|
||||
|
||||
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.删除:
|
||||
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:
|
||||
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,
|
||||
nameof(EditTrackPushConfigInput.Options)]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -38,11 +38,11 @@ public interface IOrderRepository : IBasicRepository<OrderEntity>
|
||||
#region 订单关联
|
||||
|
||||
/// <summary>
|
||||
/// 根据订单id,获取关联的订单id集合
|
||||
/// 根据订单id,获取关联的订单集合
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<int>> GetLinkedOrderIdsAsync(int orderId);
|
||||
Task<List<LinkedOrderVO>> GetLinkedOrdersAsync(int orderId);
|
||||
|
||||
/// <summary>
|
||||
/// 关联订单
|
||||
|
||||
@ -42,6 +42,12 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot
|
||||
[SugarColumn(ColumnName = "IsCompleted")]
|
||||
public bool IsCompleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单是否推送完成(异步维护)
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "IsPushCompleted")]
|
||||
public bool IsPushCompleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最新轨迹内容(异步维护)
|
||||
/// </summary>
|
||||
|
||||
@ -13,14 +13,38 @@ public class TrackContentMapEntity : IFullAuditedBasicEntitys, IEntity
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 映射轨迹内容id
|
||||
/// 源子系统id
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "MapTrackContentId")]
|
||||
public int MapTrackContentId { get; set; }
|
||||
[SugarColumn(ColumnName = "SubSystemId")]
|
||||
public int SubSystemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 源轨迹内容id
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "TrackContentId")]
|
||||
public int TrackContentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 源轨迹内容code
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "TrackContentCode")]
|
||||
public string TrackContentCode { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 映射子系统id
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "MapSubSystemId")]
|
||||
public int MapSubSystemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 映射轨迹内容id
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "MapTrackContentId")]
|
||||
public int MapTrackContentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 映射轨迹内容code
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "MapTrackContentCode")]
|
||||
public string MapTrackContentCode { get; set; } = null!;
|
||||
}
|
||||
@ -6,9 +6,7 @@ public interface ITrackDetailsRepository
|
||||
{
|
||||
Task<TrackDetailsIndex?> GetFirstOrDefaultAsync(int orderId, string inputTrackCode);
|
||||
|
||||
Task UpdateAsync(TrackDetailsIndex index);
|
||||
|
||||
Task CreateAsync(TrackDetailsIndex index);
|
||||
Task UpsertAsync(TrackDetailsIndex index);
|
||||
|
||||
Task<List<TrackDetailsIndex>> GetListAsync(int orderType, List<string> orderNos);
|
||||
|
||||
|
||||
@ -3,11 +3,9 @@ using SJZY.Expand.ElasticSearch;
|
||||
|
||||
namespace SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
|
||||
|
||||
[ElasticsearchType(RelationName = IndexName)]
|
||||
[ElasticsearchType(RelationName = GlobalConst.TrackIndex)]
|
||||
public class TrackDetailsIndex : IdBaseIndex
|
||||
{
|
||||
public const string IndexName = "sjzy_track_details";
|
||||
|
||||
/// <summary>
|
||||
/// 订单Id
|
||||
/// </summary>
|
||||
@ -16,7 +14,7 @@ public class TrackDetailsIndex : IdBaseIndex
|
||||
/// <summary>
|
||||
/// 订单号
|
||||
/// </summary>
|
||||
public string OrderNo { get; set; }
|
||||
public string OrderNo { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 订单类型(主数据枚举TrackOrderType)
|
||||
@ -26,42 +24,42 @@ public class TrackDetailsIndex : IdBaseIndex
|
||||
/// <summary>
|
||||
/// 轨迹状态
|
||||
/// </summary>
|
||||
public string TrackStatus { get; set; }
|
||||
public string TrackStatus { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 原轨迹状态
|
||||
/// </summary>
|
||||
public string OriginTrackStatus { get; set; }
|
||||
public string? OriginTrackStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹内容代码
|
||||
/// </summary>
|
||||
public string TrackCode { get; set; }
|
||||
public string TrackCode { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹内容
|
||||
/// </summary>
|
||||
public string TrackContent { get; set; }
|
||||
public string TrackContent { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 原轨迹内容
|
||||
/// </summary>
|
||||
public string OriginTrackContent { get; set; }
|
||||
public string? OriginTrackContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 原轨迹报文
|
||||
/// </summary>
|
||||
public string OriginTrackData { get; set; }
|
||||
public string? OriginTrackData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹内容英文
|
||||
/// </summary>
|
||||
public string TrackEnContent { get; set; }
|
||||
public string TrackEnContent { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹发生地
|
||||
/// </summary>
|
||||
public string TrackPlace { get; set; }
|
||||
public string? TrackPlace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹发生时间
|
||||
|
||||
@ -12,4 +12,6 @@ public interface ITrackPushConfigRepository : IBasicRepository<TrackPushConfigEn
|
||||
Task<GetTrackPushConfigDetailOutputVO> GetDetailAsync(int id);
|
||||
|
||||
Task<GetTrackPushContentDetailOutputVO> GetContentDetailAsync(int id);
|
||||
|
||||
Task<bool> SoftDeleteContentAsync(Expression<Func<TrackPushContentConfigEntity, bool>> whereExpression);
|
||||
}
|
||||
14
src/SJZY.Track.Domain/Dtos/Order/LinkedOrderVO.cs
Normal file
14
src/SJZY.Track.Domain/Dtos/Order/LinkedOrderVO.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace SJZY.Track.Domain.Dtos.Order;
|
||||
|
||||
public class LinkedOrderVO
|
||||
{
|
||||
/// <summary>
|
||||
/// 关联订单id
|
||||
/// </summary>
|
||||
public int OrderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子系统id
|
||||
/// </summary>
|
||||
public int SubSystemId { get; set; }
|
||||
}
|
||||
@ -5,15 +5,15 @@ public class MatchTrackContentDto
|
||||
/// <summary>
|
||||
/// 轨迹内容
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
public string Content { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹内容英文
|
||||
/// </summary>
|
||||
public string EnContent { get; set; }
|
||||
public string EnContent { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹状态
|
||||
/// </summary>
|
||||
public string Status { get; set; }
|
||||
public string Status { get; set; } = null!;
|
||||
}
|
||||
@ -89,7 +89,7 @@ public class GetTrackPushConfigDetailOutputVO
|
||||
/// <summary>
|
||||
/// 轨迹模板id
|
||||
/// </summary>
|
||||
public int TrackTemplateId { get; set; }
|
||||
public string TrackTemplateId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 推送轨迹发生时间
|
||||
|
||||
14
src/SJZY.Track.Domain/GlobalConst.cs
Normal file
14
src/SJZY.Track.Domain/GlobalConst.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace SJZY.Track.Domain;
|
||||
|
||||
public class GlobalConst
|
||||
{
|
||||
/// <summary>
|
||||
/// 轨迹明细es索引名称
|
||||
/// </summary>
|
||||
public const string TrackIndex = "sjzy_track_details";
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹新增/更新cap订阅名称
|
||||
/// </summary>
|
||||
public const string TrackUpsertSubscribe = "SJZY.Track.Upsert";
|
||||
}
|
||||
@ -31,4 +31,13 @@ public interface ITrackQueries
|
||||
/// <param name="code">轨迹代码</param>
|
||||
/// <returns></returns>
|
||||
Task<MatchTrackContentDto?> MatchTrackContentAsync(int orderId, string code);
|
||||
|
||||
/// <summary>
|
||||
/// 根据子系统内容映射,得到映射后的轨迹code
|
||||
/// </summary>
|
||||
/// <param name="upSubSystemId"></param>
|
||||
/// <param name="subSystemId"></param>
|
||||
/// <param name="trackCode"></param>
|
||||
/// <returns></returns>
|
||||
Task<string?> MapTrackContentCodeAsync(int upSubSystemId, int subSystemId, string trackCode);
|
||||
}
|
||||
@ -75,4 +75,13 @@ public class TrackQueries : ISugarRepository, ITrackQueries,
|
||||
})
|
||||
.FirstAsync();
|
||||
}
|
||||
|
||||
public async Task<string?> MapTrackContentCodeAsync(int upSubSystemId, int subSystemId, string trackCode)
|
||||
{
|
||||
return await Context.Queryable<TrackContentMapEntity>()
|
||||
.Where(x => x.SubSystemId == upSubSystemId && x.MapSubSystemId == subSystemId &&
|
||||
x.TrackContentCode == trackCode)
|
||||
.Select(x => x.MapTrackContentCode)
|
||||
.FirstAsync();
|
||||
}
|
||||
}
|
||||
@ -53,12 +53,16 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
|
||||
|
||||
#region 订单关联
|
||||
|
||||
public async Task<List<int>> GetLinkedOrderIdsAsync(int orderId)
|
||||
public async Task<List<LinkedOrderVO>> GetLinkedOrdersAsync(int orderId)
|
||||
{
|
||||
return await Context.Queryable<OrderEntity>()
|
||||
.LeftJoin<OrderLinkEntity>((a, b) => a.Id == b.OrderId)
|
||||
.Where(a => a.Id == orderId)
|
||||
.Select((a, b) => b.LinkOrderId)
|
||||
.Select((a, b) => new LinkedOrderVO
|
||||
{
|
||||
OrderId = b.LinkOrderId,
|
||||
SubSystemId = a.SubSystemId
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using Nest;
|
||||
using SJZY.Expand.ElasticSearch.Services;
|
||||
using SJZY.Track.Domain;
|
||||
using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
|
||||
using SJZY.Track.Domain.Dtos.TrackDetails;
|
||||
|
||||
@ -8,7 +9,7 @@ namespace SJZY.Track.Repository.Repositories;
|
||||
internal class TrackDetailsRepository : ElasticSearchContextAbstract<TrackDetailsIndex>, ITrackDetailsRepository,
|
||||
ITransientDependency
|
||||
{
|
||||
public string IndexName => $"{TrackDetailsIndex.IndexName}-{DateTime.Now:yyyy.MM.dd}";
|
||||
public string IndexName => $"{GlobalConst.TrackIndex}-{DateTime.Now:yyyy.MM.dd}";
|
||||
|
||||
public TrackDetailsRepository(ConnectionFactory connectionFactory) : base(connectionFactory)
|
||||
{
|
||||
@ -17,7 +18,7 @@ internal class TrackDetailsRepository : ElasticSearchContextAbstract<TrackDetail
|
||||
public async Task<TrackDetailsIndex?> GetFirstOrDefaultAsync(int orderId, string trackCode)
|
||||
{
|
||||
var r = await Context.SearchAsync<TrackDetailsIndex>(s => s
|
||||
.Index($"{TrackDetailsIndex.IndexName}-{DateTime.Now:yyyy.MM.dd}")
|
||||
.Index(IndexName)
|
||||
.Query(q =>
|
||||
q.Term(t => t.Field(f => f.OrderId).Value(orderId))
|
||||
&& q.Term(t => t.Field(f => f.TrackCode).Value(trackCode))
|
||||
@ -32,24 +33,18 @@ internal class TrackDetailsRepository : ElasticSearchContextAbstract<TrackDetail
|
||||
return default;
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(TrackDetailsIndex index)
|
||||
public async Task UpsertAsync(TrackDetailsIndex index)
|
||||
{
|
||||
var response = await Context.UpdateAsync<TrackDetailsIndex>(index.Id, u => u
|
||||
.Index(IndexName)
|
||||
.Doc(index)
|
||||
.DocAsUpsert()
|
||||
//.Refresh(Refresh.True) // 可选:立即刷新索引使更改立即可见
|
||||
);
|
||||
if (!response.IsValid)
|
||||
throw new Exception($"数据修改失败,原因:{response.DebugInformation}");
|
||||
}
|
||||
|
||||
public async Task CreateAsync(TrackDetailsIndex index)
|
||||
{
|
||||
var response = await Context.IndexAsync(index, request => request.Index(IndexName));
|
||||
if (!response.IsValid)
|
||||
throw new Exception($"数据添加失败,原因:{response.DebugInformation}");
|
||||
}
|
||||
|
||||
public async Task<List<TrackDetailsIndex>> GetListAsync(int orderType, List<string> orderNos)
|
||||
{
|
||||
if (orderNos.Count < 1) return new List<TrackDetailsIndex>();
|
||||
|
||||
@ -6,6 +6,7 @@ using SJZY.Track.Domain.Dtos.Common;
|
||||
using SJZY.Track.Domain.Dtos.TrackPush;
|
||||
using SJZY.Track.Domain.VEntities;
|
||||
using SJZY.Track.Repository.VData.Entitys;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace SJZY.Track.Repository.Repositories;
|
||||
|
||||
@ -82,4 +83,12 @@ public class TrackPushConfigRepository : BasicRepository<TrackPushConfigEntity>,
|
||||
}, true)
|
||||
.SingleAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> SoftDeleteContentAsync(Expression<Func<TrackPushContentConfigEntity, bool>> whereExpression)
|
||||
{
|
||||
return await Context.Updateable<TrackPushContentConfigEntity>()
|
||||
.Where(whereExpression)
|
||||
.SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true)
|
||||
.ExecuteCommandHasChangeAsync();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user