update:单个轨迹删除去除goto,附加比较字段逻辑
This commit is contained in:
parent
a517eae81f
commit
60324b0e26
@ -225,12 +225,32 @@ public partial class TrackService : ApplicationService, ITrackService
|
||||
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;
|
||||
if (trackIds == null || trackIds.Count == 0)
|
||||
{
|
||||
throw new BusinessException(message: "没有任何轨迹要删除,请检查输入参数");
|
||||
}
|
||||
|
||||
//删除轨迹约束,只要其中有一条来源是外部的就立即返回错误
|
||||
tracks = await _trackDetailsEsRepository.GetListAsync(new[] { orderId }, trackCodes);
|
||||
//检查删除的轨迹中是否包含外部轨迹
|
||||
existsExternal = tracks
|
||||
.Where(x => x.Source == (int) TrackSourceEnum.ExternalServiceProvide)
|
||||
.WhereIf(!input.CompareFields.IsNullOrWhiteSpace(), y =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(y.Extra))
|
||||
{
|
||||
throw new BusinessException(message: "轨迹extra为空无法使用比较字段比较,请检查轨迹");
|
||||
}
|
||||
|
||||
var extraDict = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, object>>(y.Extra);
|
||||
if (extraDict!.TryGetValue(input.CompareFields!, out var compareValue))
|
||||
{
|
||||
//tips:可能会有问题
|
||||
return compareValue.Equals(input.CompareValue);
|
||||
}
|
||||
|
||||
return false;
|
||||
})
|
||||
.Select(x => $"{x.TrackCode}{x.TrackTime}")
|
||||
.Any(x => trackIds.Contains(x));
|
||||
}
|
||||
@ -240,24 +260,23 @@ public partial class TrackService : ApplicationService, ITrackService
|
||||
throw new BusinessException(message: "存在来源于外部服务商的轨迹,不允许删除");
|
||||
}
|
||||
|
||||
|
||||
// todo:非必须不用goto,除非是在写算法,业务逻辑理论上都能通过if和方法规避
|
||||
NO_DELETE_TRACK:
|
||||
if (tracks.Count == 0)
|
||||
{
|
||||
throw new BusinessException(message: "没有任何轨迹要删除,请检查输入参数");
|
||||
}
|
||||
|
||||
// 删除轨迹
|
||||
var @event = new TrackDeleteEvent
|
||||
{
|
||||
EsIds = input.EsIds?.ToArray(),
|
||||
OrderIds = new[] { orderId },
|
||||
TrackIdentifiers = input.TrackIdentifiers,
|
||||
SubSystemId = input.SubSystemId,
|
||||
OperationMan = name
|
||||
};
|
||||
await _capPublisher.PublishAsync(GlobalConst.TrackDeleteSubscribe, @event);
|
||||
await _capPublisher.PublishAsync(GlobalConst.TrackDeleteSubscribe,
|
||||
new TrackDeleteEvent
|
||||
{
|
||||
EsIds = input.EsIds?.ToArray(),
|
||||
OrderIds = new[] { orderId },
|
||||
CompareFields = input.CompareFields,
|
||||
CompareValue = input.CompareValue,
|
||||
TrackIdentifiers = input.TrackIdentifiers,
|
||||
SubSystemId = input.SubSystemId,
|
||||
OperationMan = name
|
||||
});
|
||||
|
||||
return new UnifyResultDto(true, true);
|
||||
}
|
||||
@ -351,6 +370,8 @@ public partial class TrackService : ApplicationService, ITrackService
|
||||
{
|
||||
OrderIds = orderIds.ToArray(),
|
||||
TrackIdentifiers = input.TrackIdentifiers,
|
||||
CompareFields = input.CompareFields,
|
||||
CompareValue = input.CompareValue,
|
||||
SubSystemId = input.SubSystemId,
|
||||
OperationMan = userInfo.Data.UserName,
|
||||
};
|
||||
@ -360,7 +381,6 @@ public partial class TrackService : ApplicationService, ITrackService
|
||||
}
|
||||
|
||||
|
||||
|
||||
// todo:代码封装性太差了,拆小一点
|
||||
/// <summary>
|
||||
/// 批量新增、更新轨迹
|
||||
|
||||
Loading…
Reference in New Issue
Block a user