From 69e0731b7e6cb937d562a20ade2db7f6fa4f15bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=BE=99=20=E7=8E=8B?= Date: Fri, 15 Nov 2024 11:47:27 +0800 Subject: [PATCH] =?UTF-8?q?update:=E3=80=90=E5=8D=95=E4=B8=AA/=E6=89=B9?= =?UTF-8?q?=E9=87=8F=EF=BC=8C=E6=96=B0=E5=A2=9E/=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=BD=A8=E8=BF=B9=E3=80=91=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91=EF=BC=8C=E4=B8=BA=E4=BA=86?= =?UTF-8?q?=E5=9C=A8=E5=BC=95=E5=8F=91=E4=BA=8B=E4=BB=B6=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E5=81=9A=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit update:轨迹明细更新:批量操作删除修改轨迹状态字段,单个操作增加部分字段 --- .../Services/ProvideServices/TrackService.cs | 80 +++++++++++++++++++ .../Dtos/TrackContents/TrackContentVO.cs | 15 ++++ .../Queries/ProvideQueries.cs | 3 + .../Repositories/TrackDetailsEsRepository.cs | 15 +++- 4 files changed, 110 insertions(+), 3 deletions(-) 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