Merge remote-tracking branch 'origin/S06' into S06

This commit is contained in:
xiaolipro 2025-01-09 11:36:31 +08:00
commit 24c5f0a2ed
9 changed files with 73 additions and 19 deletions

View File

@ -9,8 +9,12 @@ public class DeleteOrderInput : OrderNoInfo
public class DeleteTrackInput : OrderNoInfo public class DeleteTrackInput : OrderNoInfo
{ {
/// <summary> /// <summary>
/// 轨迹标识符集合,必填 /// 轨迹标识符集合,为支持esid删除,所以非必填
/// </summary> /// </summary>
[Required] public List<TrackIdentifierDto>? TrackIdentifiers { get; set; } = new();
public List<TrackIdentifierDto> TrackIdentifiers { get; set; } = new();
/// <summary>
/// 轨迹ESId集合,非必填,如果有优先级最高
/// </summary>
public List<string>? EsIds { get; set; }
} }

View File

@ -15,6 +15,7 @@ public class GetTrackOutput
public class TrackDetail public class TrackDetail
{ {
public string EsId { get; set; } = null!;
public string Code { get; set; } = null!; public string Code { get; set; } = null!;
public string Status { get; set; } = null!; public string Status { get; set; } = null!;
public string? Content { get; set; } public string? Content { get; set; }

View File

@ -9,6 +9,11 @@ public class UpsertTrackInput : OrderNoInfo
/// </summary> /// </summary>
public bool IsAdd { get; set; } public bool IsAdd { get; set; }
/// <summary>
/// 轨迹唯一标识(可选)
/// </summary>
public string? EsId { get; set; }
/// <summary> /// <summary>
/// 轨迹内容代码 /// 轨迹内容代码
/// </summary> /// </summary>

View File

@ -19,6 +19,11 @@ public class TrackUpsertEvent
/// </summary> /// </summary>
public OrderIdentifier[] OrderIdentifiers { get; set; } = null!; public OrderIdentifier[] OrderIdentifiers { get; set; } = null!;
/// <summary>
/// 轨迹唯一标识(用于单个订单更新单条轨迹,如果有的话优先级最高)
/// </summary>
public string? EsId { get; set; }
/// <summary> /// <summary>
/// 操作人(null则默认系统) /// 操作人(null则默认系统)
/// </summary> /// </summary>

View File

@ -5,7 +5,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<GenerateDocumentationFile>True</GenerateDocumentationFile> <GenerateDocumentationFile>True</GenerateDocumentationFile>
<Version>7.0.11</Version> <Version>7.0.12</Version>
<GenerateDocumentationFile>True</GenerateDocumentationFile> <GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -242,6 +242,12 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
TrackDetailsIndex? track; TrackDetailsIndex? track;
if (!@event.IsAdd) if (!@event.IsAdd)
{ {
//如果命中了esId
track = string.IsNullOrWhiteSpace(@event.EsId)
? null
: tracks.FirstOrDefault(x => x.Id == @event.EsId);
if (track != null) goto TipEsIdTrack;
//同一订单同轨迹code同一轨迹时间如果有多条轨迹明细则不允许修改 //同一订单同轨迹code同一轨迹时间如果有多条轨迹明细则不允许修改
var existTracks = tracks.Where(x => x.OrderId == order.OrderId var existTracks = tracks.Where(x => x.OrderId == order.OrderId
&& x.TrackTime == @event.TrackTime).ToArray(); && x.TrackTime == @event.TrackTime).ToArray();
@ -291,6 +297,8 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
//其余情况:A,D都为新增操作,无需检查数量,track为null执行新增操作 //其余情况:A,D都为新增操作,无需检查数量,track为null执行新增操作
} }
//通过esId命中了轨迹
TipEsIdTrack:
if (track == default) if (track == default)
{ {
track = new TrackDetailsIndex track = new TrackDetailsIndex

View File

@ -61,6 +61,7 @@ public partial class TrackService
item.TrackDetails = trackDetails.Select(x => new TrackDetail item.TrackDetails = trackDetails.Select(x => new TrackDetail
{ {
EsId = x.Id,
Code = x.TrackCode, Code = x.TrackCode,
Status = x.TrackStatus, Status = x.TrackStatus,
Content = x.TrackContent, Content = x.TrackContent,
@ -146,6 +147,7 @@ public partial class TrackService
item.TrackDetails = trackDetails.Select(x => new TrackDetail item.TrackDetails = trackDetails.Select(x => new TrackDetail
{ {
EsId = x.Id,
Code = x.TrackCode, Code = x.TrackCode,
Status = x.TrackStatus, Status = x.TrackStatus,
Content = x.TrackContent, Content = x.TrackContent,

View File

@ -27,12 +27,16 @@ public partial class TrackService : ApplicationService, ITrackService
private readonly IHttpClientProxy<IUserBaseInfoService> _requestCurrentUserService; private readonly IHttpClientProxy<IUserBaseInfoService> _requestCurrentUserService;
private readonly ITrackContentRepository _trackContentRepository; private readonly ITrackContentRepository _trackContentRepository;
public TrackService(IOrderRepository orderRepository, ICapPublisher capPublisher, public TrackService(IOrderRepository orderRepository,
ITrackDetailsEsRepository trackDetailsEsRepository, ITrackContentRepository trackContentRepository, ICapPublisher capPublisher,
IHttpClientProxy<IUserBaseInfoService> requestCurrentUserService, ITrackTemplateRepository trackTemplateRepository, IHttpContextAccessor contextAccessor, IVSystemQueries vSystemQueries) ITrackDetailsEsRepository trackDetailsEsRepository,
ITrackContentRepository trackContentRepository,
IHttpClientProxy<IUserBaseInfoService> requestCurrentUserService,
ITrackTemplateRepository trackTemplateRepository,
IHttpContextAccessor contextAccessor,
IVSystemQueries vSystemQueries)
{ {
_orderRepository = orderRepository; _orderRepository = orderRepository;
this._orderRepository = orderRepository;
_capPublisher = capPublisher; _capPublisher = capPublisher;
_trackContentRepository = trackContentRepository; _trackContentRepository = trackContentRepository;
_requestCurrentUserService = requestCurrentUserService; _requestCurrentUserService = requestCurrentUserService;
@ -108,7 +112,10 @@ public partial class TrackService : ApplicationService, ITrackService
throw new BusinessException(message: $"轨迹代码:{input.TrackCode}不允许手动更新"); throw new BusinessException(message: $"轨迹代码:{input.TrackCode}不允许手动更新");
} }
var tracks = (await _trackDetailsEsRepository.GetListAsync(new[] { order.Id }, input.TrackCode, true)) //如果传递了esId并且是修改操作则使用esid
var tracks = (!string.IsNullOrWhiteSpace(input.EsId) && !input.IsAdd)
? await _trackDetailsEsRepository.GetDataByIds(new[] { input.EsId })
: (await _trackDetailsEsRepository.GetListAsync(new[] { order.Id }, input.TrackCode, true))
.Where(x => x.TrackTime == input.TrackTime) .Where(x => x.TrackTime == input.TrackTime)
.ToList(); .ToList();
@ -204,23 +211,45 @@ public partial class TrackService : ApplicationService, ITrackService
var name = userInfo.Data.UserName; var name = userInfo.Data.UserName;
//删除轨迹约束,只要其中有一条来源是外部的就立即返回错误 var tracks = new List<TrackDetailsIndex>();
var tracks = await _trackDetailsEsRepository var existsExternal = false;
.GetListAsync(new[] { orderId }, var esIds = input.EsIds?.Distinct().ToArray();
input.TrackIdentifiers.Select(x => x.TrackCode).ToList(), //优先使用esId
TrackSourceEnum.ExternalServiceProvide); if (esIds != null && esIds.Length > 0)
{
tracks = await _trackDetailsEsRepository.GetDataByIds(esIds);
existsExternal = tracks.Any(x => x.Source == (int) TrackSourceEnum.ExternalServiceProvide);
}
else
{
var trackCodes = input.TrackIdentifiers?.Select(x => x.TrackCode).ToList();
var trackIds = input.TrackIdentifiers?.Select(y => $"{y.TrackCode}{y.TrackTime}").ToHashSet();
//没有任何需要操作的轨迹
if (trackIds == null || trackIds.Count == 0) goto NO_DELETE_TRACK;
//删除轨迹约束,只要其中有一条来源是外部的就立即返回错误
tracks = await _trackDetailsEsRepository.GetListAsync(new[] { orderId }, trackCodes);
//检查删除的轨迹中是否包含外部轨迹
existsExternal = tracks
.Where(x => x.Source == (int) TrackSourceEnum.ExternalServiceProvide)
.Select(x => $"{x.TrackCode}{x.TrackTime}")
.Any(x => trackIds.Contains(x));
}
//当要删除的轨迹标识出现交叉则不允许删除 if (existsExternal)
var intersect = tracks.Select(x => $"{x.TrackCode}{x.TrackTime}")
.Intersect(input.TrackIdentifiers.Select(y => $"{y.TrackCode}{y.TrackTime}")).ToList();
if (intersect.Count > 0)
{ {
throw new BusinessException(message: "存在来源于外部服务商的轨迹,不允许删除"); throw new BusinessException(message: "存在来源于外部服务商的轨迹,不允许删除");
} }
NO_DELETE_TRACK:
if (tracks.Count == 0)
{
throw new BusinessException(message: "没有任何轨迹要删除,请检查输入参数");
}
// 删除轨迹 // 删除轨迹
var @event = new TrackDeleteEvent var @event = new TrackDeleteEvent
{ {
EsIds = input.EsIds?.ToArray(),
OrderIds = new[] { orderId }, OrderIds = new[] { orderId },
TrackIdentifiers = input.TrackIdentifiers, TrackIdentifiers = input.TrackIdentifiers,
SubSystemId = input.SubSystemId, SubSystemId = input.SubSystemId,

View File

@ -419,7 +419,7 @@ public class TrackDetailsEsRepository : ElasticSearchContextAbstract<TrackDetail
$"轨迹查询失败,orderType:{orderType},orderNos:{orderNos},原因:{r.DebugInformation}。"); $"轨迹查询失败,orderType:{orderType},orderNos:{orderNos},原因:{r.DebugInformation}。");
} }
return r.Documents.ToList(); return r.ToIdList();
} }
public async Task<List<TrackDetailsIndex>> GetListAsync(int orderId) public async Task<List<TrackDetailsIndex>> GetListAsync(int orderId)