update:【单个/批量,新增/修改轨迹】接口增加校验逻辑,为了在引发事件之前做拦截
update:轨迹明细更新:批量操作删除修改轨迹状态字段,单个操作增加部分字段
This commit is contained in:
parent
e35ee25a4e
commit
69e0731b7e
@ -66,6 +66,41 @@ public partial class TrackService : ApplicationService, ITrackService
|
||||
throw new BusinessException(message: "【目的地时区】和【预计到达时间】必须同时输入");
|
||||
}
|
||||
|
||||
var trackContent = await _trackContentRepository.GetByCodeAsync(input.SubSystemId, input.TrackCode);
|
||||
if (trackContent == default)
|
||||
{
|
||||
throw new BusinessException(message: $"轨迹代码:{input.TrackCode}轨迹内容不存在");
|
||||
}
|
||||
|
||||
//指示是否为手动操作
|
||||
var manualOperation = input.Source == (int) TrackSourceEnum.Artificial;
|
||||
|
||||
//不允许手动创建
|
||||
if (manualOperation && input.IsAdd && !trackContent.IsAllowManuallyCreate)
|
||||
{
|
||||
throw new BusinessException(message: $"轨迹代码:{input.TrackCode}不允许手动创建");
|
||||
}
|
||||
|
||||
//不允许手动更新
|
||||
if (manualOperation && !input.IsAdd && trackContent.IsAllowManuallyUpdate)
|
||||
{
|
||||
throw new BusinessException(message: $"轨迹代码:{input.TrackCode}不允许手动更新");
|
||||
}
|
||||
|
||||
var tracks = await _trackDetailsEsRepository.GetListAsync(new[] { order.Id }, input.TrackCode, true);
|
||||
|
||||
//轨迹内容不允许重复,并且已经存在了轨迹记录
|
||||
if (!trackContent.IsRepeatable && tracks.Count >= 1)
|
||||
{
|
||||
throw new BusinessException(message: $"轨迹代码:{input.TrackCode}不允许重复添加");
|
||||
}
|
||||
|
||||
//更新轨迹,但存在多条轨迹记录,理由:不清晰到底要修改哪一条或是全部修改
|
||||
if (!input.IsAdd && tracks.Count > 1)
|
||||
{
|
||||
throw new BusinessException(message: $"订单:{input.OrderNo},轨迹代码:{input.TrackCode}存在多条记录,不允许修改");
|
||||
}
|
||||
|
||||
var userInfo = await _requestCurrentUserService.Service.GetCurrentUserBasicInfoAsync();
|
||||
if (userInfo.Code != GlobalConst.SuccessCode || userInfo.Data is null)
|
||||
{
|
||||
@ -214,12 +249,57 @@ public partial class TrackService : ApplicationService, ITrackService
|
||||
throw new BusinessException(message: "订单一个都不存在");
|
||||
}
|
||||
|
||||
// 校验主体:批量新增只选取第一条订单进行校验
|
||||
//【新增】存在指定轨迹的内容,进行更新覆盖(只处理一条的情况,并且决定权交给用户),不存在直接插入即可
|
||||
//【更新】存在指定轨迹的内容(匹配到多条则不处理)
|
||||
var order = orders.First();
|
||||
|
||||
if (input.TrackTime < DateTime.Now.AddYears(-100) || input.TrackTime > DateTime.Now.AddYears(100))
|
||||
{
|
||||
throw new BusinessException(message: "轨迹时间不合法");
|
||||
}
|
||||
|
||||
if ((input.EstimatedDeliveryDate.HasValue == false && input.DestinationTimeZone.HasValue) ||
|
||||
(input.EstimatedDeliveryDate.HasValue && input.DestinationTimeZone.HasValue == false))
|
||||
{
|
||||
throw new BusinessException(message: "【目的地时区】和【预计到达时间】必须同时输入");
|
||||
}
|
||||
|
||||
var trackContent = await _trackContentRepository.GetByCodeAsync(input.SubSystemId, input.TrackCode);
|
||||
if (trackContent == default)
|
||||
{
|
||||
throw new BusinessException(message: $"轨迹代码:{input.TrackCode}轨迹内容不存在");
|
||||
}
|
||||
|
||||
//指示是否为手动操作
|
||||
var manualOperation = input.Source == (int) TrackSourceEnum.Artificial;
|
||||
|
||||
//不允许手动创建
|
||||
if (manualOperation && input.IsAdd && !trackContent.IsAllowManuallyCreate)
|
||||
{
|
||||
throw new BusinessException(message: $"轨迹代码:{input.TrackCode}不允许手动创建");
|
||||
}
|
||||
|
||||
//不允许手动更新
|
||||
if (manualOperation && !input.IsAdd && trackContent.IsAllowManuallyUpdate)
|
||||
{
|
||||
throw new BusinessException(message: $"轨迹代码:{input.TrackCode}不允许手动更新");
|
||||
}
|
||||
|
||||
var tracks = await _trackDetailsEsRepository.GetListAsync(new[] { order.Id }, input.TrackCode, true);
|
||||
|
||||
//轨迹内容不允许重复,并且已经存在了轨迹记录
|
||||
if (!trackContent.IsRepeatable && tracks.Count >= 1)
|
||||
{
|
||||
throw new BusinessException(message: $"轨迹代码:{input.TrackCode}不允许重复添加");
|
||||
}
|
||||
|
||||
//更新轨迹,存在多条轨迹记录不允许更改,理由:不清晰到底要修改哪一条或是全部修改
|
||||
if (!input.IsAdd && tracks.Count > 1)
|
||||
{
|
||||
throw new BusinessException(message: $"订单:{order.OrderNo},轨迹代码:{input.TrackCode}存在多条记录,不允许修改");
|
||||
}
|
||||
|
||||
// 获取用户name
|
||||
var userInfo = await _requestCurrentUserService.Service.GetCurrentUserBasicInfoAsync();
|
||||
if (userInfo.Code != GlobalConst.SuccessCode || userInfo.Data is null)
|
||||
|
||||
@ -36,4 +36,19 @@ public class TrackContentVO
|
||||
/// 轨迹状态代码
|
||||
/// </summary>
|
||||
public string TrackStatusCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否可重复
|
||||
/// </summary>
|
||||
public bool IsRepeatable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许手动修改
|
||||
/// </summary>
|
||||
public bool IsAllowManuallyUpdate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许手动创建
|
||||
/// </summary>
|
||||
public bool IsAllowManuallyCreate { get; set; }
|
||||
}
|
||||
|
||||
@ -91,6 +91,9 @@ public class ProvideQueries : ISugarRepository, IProvideQueries, ITransientDepen
|
||||
TrackContent = x.Content,
|
||||
TrackEnContent = x.EnContent,
|
||||
IsCompleted = y.IsCompleted,
|
||||
IsRepeatable = x.IsRepeatable,
|
||||
IsAllowManuallyUpdate = x.IsAllowManuallyUpdate,
|
||||
IsAllowManuallyCreate = x.IsAllowManuallyCreate
|
||||
})
|
||||
.FirstAsync();
|
||||
}
|
||||
|
||||
@ -146,6 +146,17 @@ public class TrackDetailsEsRepository : ElasticSearchContextAbstract<TrackDetail
|
||||
track.TrackTimeZone,
|
||||
track.UpdateUser,
|
||||
UpdateTime = DateTime.Now,
|
||||
track.TrackContent,
|
||||
track.TrackEnContent,
|
||||
track.IsVisibility,
|
||||
track.Remarks,
|
||||
track.Files,
|
||||
track.TrackPlaceCity,
|
||||
track.TrackPlaceProvince,
|
||||
track.TrackPlaceNation,
|
||||
track.TrackPlacePostcode,
|
||||
track.DestinationTimeZone,
|
||||
track.EstimatedDeliveryDate
|
||||
})
|
||||
);
|
||||
|
||||
@ -175,7 +186,6 @@ public class TrackDetailsEsRepository : ElasticSearchContextAbstract<TrackDetail
|
||||
ctx._source.trackTimeZone = params.trackTimeZone;
|
||||
ctx._source.updateUser = params.updateUser;
|
||||
ctx._source.updateTime = params.updateTime;
|
||||
ctx._source.trackStatus = params.trackStatus;
|
||||
ctx._source.trackContent = params.trackContent;
|
||||
ctx._source.trackEnContent = params.trackEnContent;
|
||||
ctx._source.isVisibility = params.isVisibility;
|
||||
@ -195,8 +205,7 @@ public class TrackDetailsEsRepository : ElasticSearchContextAbstract<TrackDetail
|
||||
.Add("trackTimeZone", track.TrackTimeZone)
|
||||
.Add("updateUser", track.UpdateUser)
|
||||
.Add("updateTime", DateTime.Now)
|
||||
//新增字段更新
|
||||
.Add("trackStatus", track.TrackStatus)
|
||||
//S06新增字段更新
|
||||
.Add("trackContent", track.TrackContent)
|
||||
.Add("trackEnContent", track.TrackEnContent)
|
||||
.Add("isVisibility", track.IsVisibility)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user