diff --git a/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs b/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs
index 1b99555b..48967bfb 100644
--- a/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs
+++ b/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs
@@ -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)
diff --git a/src/SJZY.Track.Domain/Dtos/TrackContents/TrackContentVO.cs b/src/SJZY.Track.Domain/Dtos/TrackContents/TrackContentVO.cs
index b0a98b0e..f9f6da60 100644
--- a/src/SJZY.Track.Domain/Dtos/TrackContents/TrackContentVO.cs
+++ b/src/SJZY.Track.Domain/Dtos/TrackContents/TrackContentVO.cs
@@ -36,4 +36,19 @@ public class TrackContentVO
/// 轨迹状态代码
///
public string TrackStatusCode { get; set; }
+
+ ///
+ /// 是否可重复
+ ///
+ public bool IsRepeatable { get; set; }
+
+ ///
+ /// 是否允许手动修改
+ ///
+ public bool IsAllowManuallyUpdate { get; set; }
+
+ ///
+ /// 是否允许手动创建
+ ///
+ public bool IsAllowManuallyCreate { get; set; }
}
diff --git a/src/SJZY.Track.Repository/Queries/ProvideQueries.cs b/src/SJZY.Track.Repository/Queries/ProvideQueries.cs
index c91ba95d..25d2c0d9 100644
--- a/src/SJZY.Track.Repository/Queries/ProvideQueries.cs
+++ b/src/SJZY.Track.Repository/Queries/ProvideQueries.cs
@@ -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();
}
diff --git a/src/SJZY.Track.Repository/Repositories/TrackDetailsEsRepository.cs b/src/SJZY.Track.Repository/Repositories/TrackDetailsEsRepository.cs
index 262d9d32..014c0c45 100644
--- a/src/SJZY.Track.Repository/Repositories/TrackDetailsEsRepository.cs
+++ b/src/SJZY.Track.Repository/Repositories/TrackDetailsEsRepository.cs
@@ -146,6 +146,17 @@ public class TrackDetailsEsRepository : ElasticSearchContextAbstract