Merge branch 'S02-轨迹中台' of http://192.168.80.50:3000/Dotnet/SJZY.Track.Api into S02-轨迹中台

This commit is contained in:
moyongzhen 2024-03-15 15:33:34 +08:00
commit 68abebe60a
18 changed files with 234 additions and 131 deletions

View File

@ -0,0 +1,44 @@
namespace SJZY.Track.Application.Contract.Dtos.ProvideServices;
public class TrackPushContentConfigDto
{
/// <summary>
/// 扩展字段参数值
/// </summary>
public string? ExpandFieldsValue { get; set; }
/// <summary>
/// 推送单号类型(主数据枚举TrackOrderType)
/// </summary>
public int OrderType { get; set; }
/// <summary>
/// 轨迹代码参数值
/// </summary>
public string? TrackContentCodeValue { get; set; }
/// <summary>
/// 轨迹内容id
/// </summary>
public int TrackContentId { get; set; }
/// <summary>
/// 轨迹内容参数值
/// </summary>
public string? TrackContentValue { get; set; }
/// <summary>
/// 轨迹内容英文参数值
/// </summary>
public string? TrackEnContentValue { get; set; }
/// <summary>
/// 轨迹状态参数值
/// </summary>
public string? TrackStatusValue { get; set; }
/// <summary>
/// 轨迹时区GMT
/// </summary>
public double? TrackTimeZone { get; set; }
}

View File

@ -20,9 +20,9 @@ public class TrackUpsertEvent : UpsertTrackInput
public int SubSystemId { get; set; } public int SubSystemId { get; set; }
/// <summary> /// <summary>
/// 订单是否推送完成(异步维护) /// 最新推送代码(异步维护)
/// </summary> /// </summary>
public bool IsPushCompleted { get; set; } public int? LatestPushTrackContentId { get; set; }
/// <summary> /// <summary>
/// 上游子系统id /// 上游子系统id

View File

@ -41,4 +41,9 @@ public class UpdateOrderTrackEvent
/// 轨迹时区 /// 轨迹时区
/// </summary> /// </summary>
public float TrackTimeZone { get; set; } public float TrackTimeZone { get; set; }
/// <summary>
/// 轨迹代码
/// </summary>
public string TrackCode { get; set; } = null!;
} }

View File

@ -1,4 +1,6 @@
namespace SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Contract.Dtos.ProvideServices;
namespace SJZY.Track.Application.Contract.Services;
public interface ITrackPushCacheService public interface ITrackPushCacheService
{ {
@ -10,12 +12,22 @@ public interface ITrackPushCacheService
Task<bool> IsPushAsync(int customId); Task<bool> IsPushAsync(int customId);
/// <summary> /// <summary>
/// 判断客户是否需要推送 /// 获取服务商拉取配置
/// </summary>
/// <param name="subSystemId">子系统id</param>
/// <param name="customId">服务商id</param>
/// <returns></returns>
Task<List<TrackPushContentConfigDto>> GetPushContentConfigsAsync(int subSystemId, int customId);
/// <summary>
/// 根据轨迹代码推断下一个(升序)要推送的内容,如果找不到或者已经是最后一个了,返回null
/// </summary> /// </summary>
/// <param name="subSystemId"></param> /// <param name="subSystemId"></param>
/// <param name="customId"></param> /// <param name="customId"></param>
/// <param name="trackContentId"></param>
/// <returns></returns> /// <returns></returns>
Task<bool> IsPushAsync(int subSystemId, int customId); Task<TrackPushContentConfigDto?> InferNextPushContentOrNullAsync(int subSystemId, int customId,
int? trackContentId);
/// <summary> /// <summary>
/// 更新缓存 /// 更新缓存

View File

@ -31,7 +31,7 @@ public class OrderLinkAfterFillTrackHandler : ITransientDependency, ICapSubscrib
var order = await _orderRepository.GetFirstAsync(x => var order = await _orderRepository.GetFirstAsync(x =>
x.Id == linkOrderId, x => new x.Id == linkOrderId, x => new
{ {
x.OrderType, x.OrderNo, x.CustomId, x.IsPushCompleted, x.SubSystemId x.OrderType, x.OrderNo, x.CustomId, LatestPushCode = x.LatestPushTrackContentId, x.SubSystemId
}); });
if (order == default) continue; if (order == default) continue;
@ -50,7 +50,7 @@ public class OrderLinkAfterFillTrackHandler : ITransientDependency, ICapSubscrib
OrderId = linkOrderId, OrderId = linkOrderId,
CustomId = order.CustomId, CustomId = order.CustomId,
SubSystemId = order.SubSystemId, SubSystemId = order.SubSystemId,
IsPushCompleted = order.IsPushCompleted, LatestPushTrackContentId = order.LatestPushCode,
UpSubSystemId = @event.SubSystemId, UpSubSystemId = @event.SubSystemId,
}; };

View File

@ -63,7 +63,7 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
var order = await _orderRepository.GetFirstAsync(x => var order = await _orderRepository.GetFirstAsync(x =>
x.OrderType == orderType && x.OrderNo == orderNo, x => new x.OrderType == orderType && x.OrderNo == orderNo, x => new
{ {
x.Id, x.SubSystemId, x.IsPushCompleted, x.CustomId x.Id, x.SubSystemId, LatestPushCode = x.LatestPushTrackContentId, x.CustomId
}); });
if (order == default) return; if (order == default) return;
@ -73,7 +73,7 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
{ {
OrderId = order.Id, OrderId = order.Id,
SubSystemId = order.SubSystemId, SubSystemId = order.SubSystemId,
IsPushCompleted = order.IsPushCompleted, LatestPushTrackContentId = order.LatestPushCode,
CustomId = order.CustomId, CustomId = order.CustomId,
OrderType = orderType, OrderType = orderType,
OrderNo = orderNo!, OrderNo = orderNo!,

View File

@ -88,6 +88,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
TrackStatus = trackContent.Status, TrackStatus = trackContent.Status,
TrackCode = @event.TrackCode, TrackCode = @event.TrackCode,
TrackContent = trackContent.Content, TrackContent = trackContent.Content,
TrackContentId = trackContent.Id,
IsCompleted = orderIsCompleted, IsCompleted = orderIsCompleted,
TrackEnContent = trackContent.EnContent, TrackEnContent = trackContent.EnContent,
TrackPlace = @event.TrackPlace, TrackPlace = @event.TrackPlace,
@ -97,13 +98,6 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
CreateUser = CurrentUserRequest.CurrentUser.Name, CreateUser = CurrentUserRequest.CurrentUser.Name,
CreateTime = DateTime.Now CreateTime = DateTime.Now
}; };
// todo:推送只做新增的,更新和删除的不做先
if (!@event.IsPushCompleted &&
await _trackPushCacheService.IsPushAsync(@event.SubSystemId, @event.CustomId))
{
//await PushTrack();
}
} }
else else
{ {
@ -114,13 +108,24 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
track.UpdateTime = DateTime.Now; track.UpdateTime = DateTime.Now;
} }
// upsert es轨迹
await _trackDetailsRepository.UpsertAsync(track); await _trackDetailsRepository.UpsertAsync(track);
// 触发轨迹推送事件
var content = await _trackPushCacheService.InferNextPushContentOrNullAsync(
@event.SubSystemId, @event.CustomId, @event.LatestPushTrackContentId);
if (content != default && content.TrackContentId == track.TrackContentId &&
content.OrderType == @event.OrderType)
{
//await PushTrack(content);
}
// 触发订单主表更新事件 // 触发订单主表更新事件
await _capPublisher.PublishAsync(GlobalConst.UpdateOrderTrackSubscribe, new UpdateOrderTrackEvent await _capPublisher.PublishAsync(GlobalConst.UpdateOrderTrackSubscribe, new UpdateOrderTrackEvent
{ {
OrderId = track.OrderId, OrderId = track.OrderId,
IsCompleted = orderIsCompleted, IsCompleted = orderIsCompleted,
TrackCode = track.TrackCode,
TrackContent = track.TrackContent, TrackContent = track.TrackContent,
TrackEnContent = track.TrackEnContent, TrackEnContent = track.TrackEnContent,
TrackPlace = track.TrackPlace, TrackPlace = track.TrackPlace,
@ -137,7 +142,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
nextEvent.OrderType = linkedOrder.OrderType; nextEvent.OrderType = linkedOrder.OrderType;
nextEvent.OrderNo = linkedOrder.OrderNo; nextEvent.OrderNo = linkedOrder.OrderNo;
nextEvent.SubSystemId = linkedOrder.SubSystemId; nextEvent.SubSystemId = linkedOrder.SubSystemId;
nextEvent.IsPushCompleted = linkedOrder.IsPushCompleted; nextEvent.LatestPushTrackContentId = linkedOrder.LatestPushTrackContentId;
nextEvent.CustomId = linkedOrder.CustomId; nextEvent.CustomId = linkedOrder.CustomId;
nextEvent.UpSubSystemId = @event.SubSystemId; nextEvent.UpSubSystemId = @event.SubSystemId;
await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, nextEvent); await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, nextEvent);

View File

@ -41,7 +41,7 @@ public partial class TrackService : ApplicationService, ITrackService
var order = await _orderRepository.GetFirstAsync(x => var order = await _orderRepository.GetFirstAsync(x =>
x.OrderType == input.OrderType && x.OrderNo == input.OrderNo, x => new x.OrderType == input.OrderType && x.OrderNo == input.OrderNo, x => new
{ {
x.Id, x.SubSystemId, x.IsPushCompleted, x.CustomId x.Id, x.SubSystemId, LatestPushCode = x.LatestPushTrackContentId, x.CustomId
}); });
if (order == default) if (order == default)
{ {
@ -52,7 +52,7 @@ public partial class TrackService : ApplicationService, ITrackService
var @event = ObjectMapper.Map<UpsertTrackInput, TrackUpsertEvent>(input); var @event = ObjectMapper.Map<UpsertTrackInput, TrackUpsertEvent>(input);
@event.OrderId = order.Id; @event.OrderId = order.Id;
@event.SubSystemId = order.SubSystemId; @event.SubSystemId = order.SubSystemId;
@event.IsPushCompleted = order.IsPushCompleted; @event.LatestPushTrackContentId = order.LatestPushCode;
@event.CustomId = order.CustomId; @event.CustomId = order.CustomId;
await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, @event); await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, @event);
return true; return true;
@ -76,7 +76,7 @@ public partial class TrackService : ApplicationService, ITrackService
var orders = await _orderRepository.GetListAsync(x => var orders = await _orderRepository.GetListAsync(x =>
x.OrderType == input.OrderType && input.OrderNos.Contains(x.OrderNo), x => new x.OrderType == input.OrderType && input.OrderNos.Contains(x.OrderNo), x => new
{ {
x.Id, x.OrderNo, x.SubSystemId, x.IsPushCompleted, x.CustomId x.Id, x.OrderNo, x.SubSystemId, LatestPushCode = x.LatestPushTrackContentId, x.CustomId
}); });
foreach (var order in orders) foreach (var order in orders)
@ -92,7 +92,7 @@ public partial class TrackService : ApplicationService, ITrackService
OrderNo = order.OrderNo, OrderNo = order.OrderNo,
OrderId = order.Id, OrderId = order.Id,
SubSystemId = order.SubSystemId, SubSystemId = order.SubSystemId,
IsPushCompleted = order.IsPushCompleted, LatestPushTrackContentId = order.LatestPushCode,
CustomId = order.CustomId CustomId = order.CustomId
}; };
await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, @event); await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, @event);

View File

@ -1,4 +1,5 @@
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.Application.Contract.Services;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate; using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
using SJZY.Track.Domain.Queries; using SJZY.Track.Domain.Queries;
@ -17,34 +18,20 @@ public class TrackPushCacheService : ITrackPushCacheService, ITransientDependenc
_trackPushConfigQuery = trackPushConfigQuery; _trackPushConfigQuery = trackPushConfigQuery;
} }
public async Task<bool> IsPushAsync(int customId) public Task<bool> IsPushAsync(int customId)
{ {
var isPush = throw new NotImplementedException();
await RedisHelper.Client.GetAsync<bool?>(RedisKey(customId));
if (isPush == null)
{
isPush = await _trackPushConfigQuery.GetFirstAsync(x => x.CustomId == customId,
x => x.IsAutoPush);
await RedisHelper.Client.SetAsync(RedisKey(customId), isPush);
}
return (bool)isPush;
} }
public async Task<bool> IsPushAsync(int subSystemId, int customId) public Task<List<TrackPushContentConfigDto>> GetPushContentConfigsAsync(int subSystemId, int customId)
{ {
var isPush = throw new NotImplementedException();
await RedisHelper.Client.GetAsync<bool?>(RedisKey(customId)); }
if (isPush == null) public Task<TrackPushContentConfigDto?> InferNextPushContentOrNullAsync(int subSystemId, int customId,
{ int? trackContentId)
isPush = await _trackPushConfigQuery.GetFirstAsync(x => x.CustomId == customId, {
x => x.IsAutoPush); throw new NotImplementedException();
await RedisHelper.Client.SetAsync(RedisKey(customId), isPush);
}
return (bool)isPush;
} }
public async Task UpdateAsync(int customId, bool isPush) public async Task UpdateAsync(int customId, bool isPush)

View File

@ -1,4 +1,5 @@
using Microsoft.Extensions.Localization; using System.Linq.Expressions;
using Microsoft.Extensions.Localization;
using SJZY.Expand.ABP.Core.Localization; using SJZY.Expand.ABP.Core.Localization;
using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Track.Application.Contract.Dtos.TrackPush; using SJZY.Track.Application.Contract.Dtos.TrackPush;
@ -9,9 +10,6 @@ using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate; using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate;
using SJZY.Track.Domain.Dtos.Common; using SJZY.Track.Domain.Dtos.Common;
using SJZY.Track.Domain.Dtos.TrackPush; using SJZY.Track.Domain.Dtos.TrackPush;
using SqlSugar;
using System.Linq.Expressions;
using Volo.Abp.DependencyInjection;
namespace SJZY.Track.Application.Services.TrackPush; namespace SJZY.Track.Application.Services.TrackPush;
@ -20,11 +18,10 @@ namespace SJZY.Track.Application.Services.TrackPush;
/// </summary> /// </summary>
[ApiExplorerSettings(GroupName = "轨迹推送")] [ApiExplorerSettings(GroupName = "轨迹推送")]
[Route("/Track/PushConfig")] [Route("/Track/PushConfig")]
public class TrackPushService : ApplicationService, ITransientDependency public class TrackPushService : ApplicationService
{ {
private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer; private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer;
private readonly ITrackPushConfigRepository _trackPushConfigRepository; private readonly ITrackPushConfigRepository _trackPushConfigRepository;
private readonly ITrackTemplateRepository _trackTemplateRepository;
private readonly ITrackPullConfigRepository _trackPullConfigRepository; private readonly ITrackPullConfigRepository _trackPullConfigRepository;
private readonly ITrackPushCacheService _trackPushCacheService; private readonly ITrackPushCacheService _trackPushCacheService;
@ -37,7 +34,6 @@ public class TrackPushService : ApplicationService, ITransientDependency
{ {
_stringLocalizer = stringLocalizer; _stringLocalizer = stringLocalizer;
_trackPushConfigRepository = trackPushConfigRepository; _trackPushConfigRepository = trackPushConfigRepository;
_trackTemplateRepository = trackTemplateRepository;
_trackPullConfigRepository = trackPullConfigRepository; _trackPullConfigRepository = trackPullConfigRepository;
_trackPushCacheService = trackPushCacheService; _trackPushCacheService = trackPushCacheService;
} }
@ -59,7 +55,8 @@ public class TrackPushService : ApplicationService, ITransientDependency
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("GetContentPage")] [HttpPost("GetContentPage")]
public async Task<UnifyPageResultDto<GetTrackPushContentPageOutputVO>> GetContentPageAsync([FromBody] GetTrackPushContentPageInputVO input) public async Task<UnifyPageResultDto<GetTrackPushContentPageOutputVO>> GetContentPageAsync(
[FromBody] GetTrackPushContentPageInputVO input)
{ {
return await _trackPushConfigRepository.GetContentPageAsync(input); return await _trackPushConfigRepository.GetContentPageAsync(input);
} }
@ -97,71 +94,79 @@ public class TrackPushService : ApplicationService, ITransientDependency
if (input.Options != OptionTypeNoNull.删除) if (input.Options != OptionTypeNoNull.删除)
{ {
Expression<Func<TrackPushConfigEntity, bool>> isAnyExp = x => 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 &&
x.ServiceProviderId == input.ServiceProviderId;
if (input.Options == OptionTypeNoNull.修改) isAnyExp = isAnyExp.And(x => x.Id != input.Id); if (input.Options == OptionTypeNoNull.修改) isAnyExp = isAnyExp.And(x => x.Id != input.Id);
if (await _trackPushConfigRepository.IsAnyAsync(isAnyExp)) throw new BusinessException(message: _stringLocalizer["IsTrackPushConfigAny"]); if (await _trackPushConfigRepository.IsAnyAsync(isAnyExp))
throw new BusinessException(message: _stringLocalizer["IsTrackPushConfigAny"]);
} }
switch (input.Options) switch (input.Options)
{ {
case OptionTypeNoNull.新增: case OptionTypeNoNull.新增:
{
var trackPushEntity = ObjectMapper.Map<EditTrackPushConfigInput, TrackPushConfigEntity>(input);
var trackPushParamsEntity =
ObjectMapper.Map<EditTrackPushConfigInput, TrackPushPullParamsConfigEntity>(input);
using (var ts = TransactionScopeHelper.Create())
{ {
var trackPushEntity = ObjectMapper.Map<EditTrackPushConfigInput, TrackPushConfigEntity>(input); int id = await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity);
var trackPushParamsEntity = ObjectMapper.Map<EditTrackPushConfigInput, TrackPushPullParamsConfigEntity>(input);
using (var ts = TransactionScopeHelper.Create()) trackPushParamsEntity.PullOrPushConfigId = id;
{ await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity);
int id = await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity);
trackPushParamsEntity.PullOrPushConfigId = id; if (input.IsAutoPush!.Value) await _trackPushCacheService.IsPushAsync(input.CustomId!.Value);
await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity);
if (input.IsAutoPush!.Value) await _trackPushCacheService.IsPushAsync(input.CustomId!.Value); ts.Complete();
ts.Complete();
}
} }
}
break; break;
case OptionTypeNoNull.修改: 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())
{ {
var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]); await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity);
await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPushParamsEntity);
int oldCustomId = oldTrackPushEntity.CustomId; await _trackPushCacheService.UpdateAsync(oldCustomId, false);
if (input.IsAutoPush!.Value) await _trackPushCacheService.IsPushAsync(input.CustomId!.Value);
var oldTrackPushParamsEntity = await _trackPullConfigRepository.GetParamsSingleAsync(x => x.PullOrPushConfigId == input.Id && x.IsPush); ts.Complete();
ObjectMapper.Map(input, oldTrackPushEntity);
ObjectMapper.Map(input, oldTrackPushParamsEntity);
using (var ts = TransactionScopeHelper.Create())
{
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();
}
} }
}
break; break;
case OptionTypeNoNull.删除: case OptionTypeNoNull.删除:
{
var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
throw new BusinessException(message: _stringLocalizer["NotFindData"]);
using (var ts = TransactionScopeHelper.Create())
{ {
var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]); 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);
using (var ts = TransactionScopeHelper.Create()) ts.Complete();
{
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);
ts.Complete();
}
} }
}
break; break;
default: default:
@ -182,62 +187,76 @@ public class TrackPushService : ApplicationService, ITransientDependency
{ {
if (input.Options != OptionTypeNoNull.删除) if (input.Options != OptionTypeNoNull.删除)
{ {
Expression<Func<TrackPushContentConfigEntity, bool>> isContentAnyExp = x => x.TrackPushConfigId == input.TrackPushConfigId; Expression<Func<TrackPushContentConfigEntity, bool>> isContentAnyExp = x =>
x.TrackPushConfigId == input.TrackPushConfigId;
if (input.Options == OptionTypeNoNull.修改) isContentAnyExp = isContentAnyExp.And(x => x.Id != input.Id); if (input.Options == OptionTypeNoNull.修改) isContentAnyExp = isContentAnyExp.And(x => x.Id != input.Id);
if (await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => x.TrackContentId == input.TrackContentId))) if (await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentId == input.TrackContentId)))
throw new BusinessException(message: _stringLocalizer["IsTrackPushContentAny"]); throw new BusinessException(message: _stringLocalizer["IsTrackPushContentAny"]);
else if (!input.TrackContentCodeValue.IsNullOrWhiteSpace() && await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => x.TrackContentCodeValue == input.TrackContentCodeValue))) else if (!input.TrackContentCodeValue.IsNullOrWhiteSpace() &&
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentCodeValue == input.TrackContentCodeValue)))
throw new BusinessException(message: _stringLocalizer["IsTrackPushContentCodeValueAny"]); throw new BusinessException(message: _stringLocalizer["IsTrackPushContentCodeValueAny"]);
else if (!input.TrackStatusValue.IsNullOrWhiteSpace() && await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => x.TrackStatusValue == input.TrackStatusValue))) else if (!input.TrackStatusValue.IsNullOrWhiteSpace() &&
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackStatusValue == input.TrackStatusValue)))
throw new BusinessException(message: _stringLocalizer["IsTrackPushContentStatusValueAny"]); throw new BusinessException(message: _stringLocalizer["IsTrackPushContentStatusValueAny"]);
else if (!input.TrackContentValue.IsNullOrWhiteSpace() && await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => x.TrackContentValue == input.TrackContentValue))) else if (!input.TrackContentValue.IsNullOrWhiteSpace() &&
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentValue == input.TrackContentValue)))
throw new BusinessException(message: _stringLocalizer["IsTrackPushContentValueAny"]); throw new BusinessException(message: _stringLocalizer["IsTrackPushContentValueAny"]);
else if (!input.TrackEnContentValue.IsNullOrWhiteSpace() && await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => x.TrackEnContentValue == input.TrackEnContentValue))) else if (!input.TrackEnContentValue.IsNullOrWhiteSpace() &&
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackEnContentValue == input.TrackEnContentValue)))
throw new BusinessException(message: _stringLocalizer["IsTrackPushEnContentValueAny"]); throw new BusinessException(message: _stringLocalizer["IsTrackPushEnContentValueAny"]);
} }
switch (input.Options) switch (input.Options)
{ {
case OptionTypeNoNull.新增: case OptionTypeNoNull.新增:
{ {
int maxSort = await _trackPushConfigRepository.ContentMaxAsync(x => x.Sort, x => x.TrackPushConfigId == input.TrackPushConfigId); int maxSort = await _trackPushConfigRepository.ContentMaxAsync(x => x.Sort,
x => x.TrackPushConfigId == input.TrackPushConfigId);
var entity = ObjectMapper.Map<EditTrackPushContentInput, TrackPushContentConfigEntity>(input); var entity = ObjectMapper.Map<EditTrackPushContentInput, TrackPushContentConfigEntity>(input);
entity.Sort = maxSort + 1; entity.Sort = maxSort + 1;
await _trackPushConfigRepository.InsertContentAsync(entity); await _trackPushConfigRepository.InsertContentAsync(entity);
break; break;
} }
case OptionTypeNoNull.修改: case OptionTypeNoNull.修改:
{ {
var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]); var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
throw new BusinessException(message: _stringLocalizer["NotFindData"]);
ObjectMapper.Map(input, entity); ObjectMapper.Map(input, entity);
await _trackPushConfigRepository.UpdateContentAsync(entity); await _trackPushConfigRepository.UpdateContentAsync(entity);
break; break;
} }
case OptionTypeNoNull.删除: case OptionTypeNoNull.删除:
{
var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
throw new BusinessException(message: _stringLocalizer["NotFindData"]);
using (var ts = TransactionScopeHelper.Create())
{ {
var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]); await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
using (var ts = TransactionScopeHelper.Create()) await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1,
{ x => x.TrackPushConfigId == entity.TrackPushConfigId && x.Sort > entity.Sort);
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();
ts.Complete();
}
break;
} }
break;
}
default: default:
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum, throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,
nameof(EditTrackPushContentInput.Options)]); nameof(EditTrackPushContentInput.Options)]);

View File

@ -43,10 +43,10 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot
public bool IsCompleted { get; set; } public bool IsCompleted { get; set; }
/// <summary> /// <summary>
/// 订单是否推送完成(异步维护) /// 最新推送轨迹内容id(异步维护)
/// </summary> /// </summary>
[SugarColumn(ColumnName = "IsPushCompleted")] [SugarColumn(ColumnName = "LatestPushTrackContentId")]
public bool IsPushCompleted { get; set; } public int? LatestPushTrackContentId { get; set; }
/// <summary> /// <summary>
/// 最新轨迹内容(异步维护) /// 最新轨迹内容(异步维护)
@ -112,7 +112,7 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot
/// 问题类型(主数据枚举TrackQuestionType) /// 问题类型(主数据枚举TrackQuestionType)
/// </summary> /// </summary>
[SugarColumn(ColumnName = "QuestionType")] [SugarColumn(ColumnName = "QuestionType")]
public int QuestionType { get; set; } public int QuestionType { get; set; }
/// <summary> /// <summary>
/// 问题描述(主数据枚举TrackProblemDescription) /// 问题描述(主数据枚举TrackProblemDescription)

View File

@ -46,6 +46,11 @@ public class TrackDetailsIndex : IdBaseIndex
/// </summary> /// </summary>
public string TrackContent { get; set; } = null!; public string TrackContent { get; set; } = null!;
/// <summary>
/// 轨迹内容Id
/// </summary>
public int TrackContentId { get; set; }
/// <summary> /// <summary>
/// 是否意味着完成 /// 是否意味着完成
/// </summary> /// </summary>

View File

@ -6,7 +6,7 @@ public class LinkedOrderVO
/// 关联订单id /// 关联订单id
/// </summary> /// </summary>
public int OrderId { get; set; } public int OrderId { get; set; }
/// <summary> /// <summary>
/// 订单号 /// 订单号
/// </summary> /// </summary>
@ -21,12 +21,12 @@ public class LinkedOrderVO
/// 子系统id /// 子系统id
/// </summary> /// </summary>
public int SubSystemId { get; set; } public int SubSystemId { get; set; }
/// <summary> /// <summary>
/// 订单是否推送完成(异步维护) /// 最新推送轨迹内容id(异步维护)
/// </summary> /// </summary>
public bool IsPushCompleted { get; set; } public int? LatestPushTrackContentId { get; set; }
/// <summary> /// <summary>
/// 客户id /// 客户id
/// </summary> /// </summary>

View File

@ -2,6 +2,11 @@
public class MatchTrackContentDto public class MatchTrackContentDto
{ {
/// <summary>
/// 轨迹内容id
/// </summary>
public int Id { get; set; }
/// <summary> /// <summary>
/// 轨迹内容 /// 轨迹内容
/// </summary> /// </summary>

View File

@ -0,0 +1,15 @@
namespace SJZY.Track.Domain.Enums;
[Flags]
public enum TrackProblemType
{
/// <summary>
/// 异常
/// </summary>
Error = 1,
/// <summary>
/// 预警
/// </summary>
Warn = 2,
}

View File

@ -37,6 +37,11 @@ public class GlobalConst
/// </summary> /// </summary>
public const string TrackPushKeyPrefix = "TrackPush"; public const string TrackPushKeyPrefix = "TrackPush";
/// <summary>
/// 轨迹推送内容配置redis key前缀
/// </summary>
public const string TrackPushContentKeyPrefix = "TrackPushContent";
/// <summary> /// <summary>
/// 轨迹拉取配置信息redis key前缀 /// 轨迹拉取配置信息redis key前缀
/// </summary> /// </summary>

View File

@ -70,6 +70,7 @@ public class ProvideQueries : ISugarRepository, IProvideQueries,
.Where((x, a, b) => x.OrderId == orderId && b.Code == code) .Where((x, a, b) => x.OrderId == orderId && b.Code == code)
.Select((x, a, b, c) => new MatchTrackContentDto .Select((x, a, b, c) => new MatchTrackContentDto
{ {
Id = b.Id,
Content = b.Content, Content = b.Content,
EnContent = b.EnContent, EnContent = b.EnContent,
Status = c.Status, Status = c.Status,

View File

@ -67,7 +67,7 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
OrderType = b.OrderType, OrderType = b.OrderType,
OrderNo = b.OrderNo, OrderNo = b.OrderNo,
SubSystemId = b.SubSystemId, SubSystemId = b.SubSystemId,
IsPushCompleted = b.IsPushCompleted, LatestPushTrackContentId = b.LatestPushTrackContentId,
CustomId = b.CustomId CustomId = b.CustomId
}) })
.ToListAsync(); .ToListAsync();