From 2905b47d1a7175d4b1a88384a945c2ba176e976d Mon Sep 17 00:00:00 2001 From: moyongzhen <2534173414@qq.com> Date: Mon, 4 Mar 2024 09:26:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=BD=A8=E8=BF=B9=E6=A0=87=E8=AE=B0?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=8F=90=E7=A4=BA=E8=AF=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/TrackFlags/TrackFlagService.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SJZY.Track.Application/Services/TrackFlags/TrackFlagService.cs b/src/SJZY.Track.Application/Services/TrackFlags/TrackFlagService.cs index d46b6d96..bc3f68ad 100644 --- a/src/SJZY.Track.Application/Services/TrackFlags/TrackFlagService.cs +++ b/src/SJZY.Track.Application/Services/TrackFlags/TrackFlagService.cs @@ -129,7 +129,8 @@ namespace SJZY.Track.Application.Services.TrackFlags var isExistContent = await _trackContentRepository.GetFirstAsync(a => a.TrackFlagId==input.Id); if (isExistContent!=null) { - throw new BusinessException(message: _stringLocalizer["IsExistTrackFlag"]); + //throw new BusinessException(message: _stringLocalizer["IsExistTrackFlag"]); + throw new BusinessException(message: "该标记关联轨迹内容,禁止删除"); } #endregion var isTrue = await _trackFlagRepository.SoftDeleteAsync(x => x.Id == input.Id); From 28462ffc8331b204bf7adab6e1557a7110942bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=96=87=E7=BF=94?= <878130837@qq.com> Date: Mon, 4 Mar 2024 10:20:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TrackContents/TrackContentService.cs | 14 +++---- .../Services/TrackPull/TrackPullService.cs | 1 - .../Services/TrackPush/TrackPushService.cs | 34 ++++++++++++----- .../TrackTemplates/TrackTemplateService.cs | 37 +++++++++++++------ .../ITrackPushConfigRepository.cs | 4 ++ .../ITrackTemplateRepository.cs | 4 ++ .../Repositories/TrackPushConfigRepository.cs | 10 +++++ .../Repositories/TrackTemplateRepository.cs | 10 +++++ 8 files changed, 86 insertions(+), 28 deletions(-) diff --git a/src/SJZY.Track.Application/Services/TrackContents/TrackContentService.cs b/src/SJZY.Track.Application/Services/TrackContents/TrackContentService.cs index 9490f1d3..cac9a7a6 100644 --- a/src/SJZY.Track.Application/Services/TrackContents/TrackContentService.cs +++ b/src/SJZY.Track.Application/Services/TrackContents/TrackContentService.cs @@ -1,12 +1,9 @@ using Microsoft.Extensions.Localization; -using SJZY.Expand.ABP.Core.Common.Dto; using SJZY.Expand.ABP.Core.Localization; using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Track.Application.Contract.Dtos.TrackContents; -using SJZY.Track.Application.Contract.Dtos.TrackPull; using SJZY.Track.Application.Localization; using SJZY.Track.Domain.Aggregates.TrackContentAggregate; -using SJZY.Track.Domain.Aggregates.TrackPullAggregate; using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate; using SJZY.Track.Domain.Dtos.TrackContents; using SJZY.Track.Domain.Queries; @@ -36,8 +33,8 @@ namespace SJZY.Track.Application.Services.TrackContents { this._stringLocalizer = stringLocalizer; this._trackContentRepository = trackContentRepository; - this._trackContentMapBasicQuery=trackContentMapBasicQuery; - this._trackTemplateContentBasicQuery=trackTemplateContentBasicQuery; + this._trackContentMapBasicQuery = trackContentMapBasicQuery; + this._trackTemplateContentBasicQuery = trackTemplateContentBasicQuery; } /// @@ -106,6 +103,7 @@ namespace SJZY.Track.Application.Services.TrackContents //throw new BusinessException(message: _stringLocalizer["TrackContentExist"]); throw new BusinessException(message: "当前子系统下,轨迹代码或轨迹内容或轨迹内容英文存在"); } + #endregion 业务逻辑校验 var entity = ObjectMapper.Map(input); @@ -117,6 +115,7 @@ namespace SJZY.Track.Application.Services.TrackContents private async Task UpdateAsync(EditTrackContentInput input) { #region 业务逻辑校验 + var trackContentEntitys = await _trackContentRepository.GetListAsync(a => a.Id != input.Id && a.SubSystemId == input.SubSystemId && (a.Code == input.Code || a.Content == input.Content || a.EnContent == input.EnContent)); @@ -166,18 +165,19 @@ namespace SJZY.Track.Application.Services.TrackContents #region 业务校验 //查询是否关联了轨迹模版内容 - var trackTemplateContents = await _trackTemplateContentBasicQuery.GetListAsync(a => a.TrackContentId==input.Id); + var trackTemplateContents = await _trackTemplateContentBasicQuery.GetListAsync(a => a.TrackContentId == input.Id); if (trackTemplateContents.Any()) { throw new BusinessException(message: "该轨迹内容关联轨迹模板,禁止删除"); } //需要加个判断,存在内容映射,则出提示 - var trackContentMapEntities = await _trackContentMapBasicQuery.GetListAsync(a => a.TrackContentId==input.Id|| a.MapTrackContentId==input.Id); + var trackContentMapEntities = await _trackContentMapBasicQuery.GetListAsync(a => a.TrackContentId == input.Id || a.MapTrackContentId == input.Id); if (trackContentMapEntities.Any()) { throw new BusinessException(message: "无法删除该内容,该轨迹内容已在轨迹内容映射中使用了,请检查"); } + #endregion 业务校验 var isTrue = await _trackContentRepository.SoftDeleteAsync(x => x.Id == input.Id); diff --git a/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs b/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs index df2e40bd..f1bc092a 100644 --- a/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs +++ b/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs @@ -5,7 +5,6 @@ using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Track.Application.Contract.Dtos.TrackPull; using SJZY.Track.Application.Localization; using SJZY.Track.Domain.Aggregates.TrackPullAggregate; -using SJZY.Track.Domain.Aggregates.TrackPushAggregate; using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate; using SJZY.Track.Domain.Dtos.Common; using SJZY.Track.Domain.Dtos.TrackPull; diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs index ff0c193d..dfdeba35 100644 --- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs +++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs @@ -215,26 +215,42 @@ public class TrackPushService : ApplicationService, ITransientDependency { case OptionTypeNoNull.新增: { - var trackPushContentEntity = ObjectMapper.Map(input); + int maxSort = await _trackPushConfigRepository.ContentMaxAsync(x => x.Sort, x => x.TrackPushConfigId == input.TrackPushConfigId); - await _trackPushConfigRepository.InsertContentAsync(trackPushContentEntity); + var entity = ObjectMapper.Map(input); + entity.Sort = maxSort + 1; + + await _trackPushConfigRepository.InsertContentAsync(entity); + + break; } - break; case OptionTypeNoNull.修改: { - var oldTrackPushContentEntity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]); + var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]); - ObjectMapper.Map(input, oldTrackPushContentEntity); + ObjectMapper.Map(input, entity); - await _trackPushConfigRepository.UpdateContentAsync(oldTrackPushContentEntity); + await _trackPushConfigRepository.UpdateContentAsync(entity); + + break; } - break; case OptionTypeNoNull.删除: - await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id); + { + var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]); - break; + using (var ts = TransactionScopeHelper.Create()) + { + await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id); + + await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1, x => x.TrackPushConfigId == entity.TrackPushConfigId && x.Sort > entity.Sort); + + ts.Complete(); + } + + break; + } default: throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum, diff --git a/src/SJZY.Track.Application/Services/TrackTemplates/TrackTemplateService.cs b/src/SJZY.Track.Application/Services/TrackTemplates/TrackTemplateService.cs index 99cf36dc..831a17e0 100644 --- a/src/SJZY.Track.Application/Services/TrackTemplates/TrackTemplateService.cs +++ b/src/SJZY.Track.Application/Services/TrackTemplates/TrackTemplateService.cs @@ -2,7 +2,6 @@ using Microsoft.Extensions.Localization; using SJZY.Expand.ABP.Core.Localization; using SJZY.Expand.ABP.Core.PublicMethords; -using SJZY.Track.Application.Contract.Dtos.TrackPush; using SJZY.Track.Application.Contract.Dtos.TrackTemplates; using SJZY.Track.Application.Localization; using SJZY.Track.Domain.Aggregates.TrackPullAggregate; @@ -216,29 +215,45 @@ public class TrackTemplateService : ApplicationService, ITransientDependency switch (input.Options) { case OptionTypeNoNull.新增: + { + int maxSort = await _trackTemplateRepository.ContentMaxAsync(x => x.Sort, x => x.TrackTemplateId == input.TrackTemplateId); - var entity = ObjectMapper.Map(input); + var entity = ObjectMapper.Map(input); + entity.Sort = maxSort + 1; - await _trackTemplateRepository.InsertContentAsync(entity); + await _trackTemplateRepository.InsertContentAsync(entity); - break; + break; + } case OptionTypeNoNull.修改: - - var oldEntity = await _trackTemplateRepository.GetContentByIdAsync(input.Id!.Value) ?? + { + var entity = await _trackTemplateRepository.GetContentByIdAsync(input.Id!.Value) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]); - ObjectMapper.Map(input, oldEntity); + ObjectMapper.Map(input, entity); - await _trackTemplateRepository.UpdateContentAsync(oldEntity); + await _trackTemplateRepository.UpdateContentAsync(entity); - break; + break; + } case OptionTypeNoNull.删除: + { + var entity = await _trackTemplateRepository.GetContentByIdAsync(input.Id!.Value) ?? + throw new BusinessException(message: _stringLocalizer["NotFindData"]); - await _trackTemplateRepository.SoftDeleteContentAsync(input.Id!.Value); + using (var ts = TransactionScopeHelper.Create()) + { + await _trackTemplateRepository.SoftDeleteContentAsync(input.Id!.Value); - break; + await _trackTemplateRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1, x => x.TrackTemplateId == entity.TrackTemplateId && x.Sort > entity.Sort); + + ts.Complete(); + } + + break; + } default: throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum, diff --git a/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/ITrackPushConfigRepository.cs b/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/ITrackPushConfigRepository.cs index 3d33a4ee..80013967 100644 --- a/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/ITrackPushConfigRepository.cs +++ b/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/ITrackPushConfigRepository.cs @@ -26,4 +26,8 @@ public interface ITrackPushConfigRepository : IBasicRepository> GetContentListAsync(Expression> whereExpression); Task UpdateContentRangeAsync(List updateObjs); + + Task ContentMaxAsync(Expression> columns, Expression> whereExpression); + + Task UpdateContentAsync(Expression> columns, Expression> whereExpression); } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Aggregates/TrackTemplateAggregate/ITrackTemplateRepository.cs b/src/SJZY.Track.Domain/Aggregates/TrackTemplateAggregate/ITrackTemplateRepository.cs index 5c738f78..e6ab4b0b 100644 --- a/src/SJZY.Track.Domain/Aggregates/TrackTemplateAggregate/ITrackTemplateRepository.cs +++ b/src/SJZY.Track.Domain/Aggregates/TrackTemplateAggregate/ITrackTemplateRepository.cs @@ -40,4 +40,8 @@ public interface ITrackTemplateRepository : IBasicRepository UpdateContentRangeAsync(List updateObjs); Task> GetContentDropDownListAsync(GetTrackTemplateContentDropDownListVO input); + + Task ContentMaxAsync(Expression> columns, Expression> whereExpression); + + Task UpdateContentAsync(Expression> columns, Expression> whereExpression); } \ No newline at end of file diff --git a/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs b/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs index 29300b59..2531f141 100644 --- a/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs @@ -124,4 +124,14 @@ public class TrackPushConfigRepository : BasicRepository, { return await Context.Updateable(updateObjs).ExecuteCommandHasChangeAsync(); } + + public async Task ContentMaxAsync(Expression> columns, Expression> whereExpression) + { + return await Context.Queryable().Where(whereExpression).MaxAsync(columns); + } + + public async Task UpdateContentAsync(Expression> columns, Expression> whereExpression) + { + return await Context.Updateable().SetColumns(columns).Where(whereExpression).ExecuteCommandHasChangeAsync(); + } } \ No newline at end of file diff --git a/src/SJZY.Track.Repository/Repositories/TrackTemplateRepository.cs b/src/SJZY.Track.Repository/Repositories/TrackTemplateRepository.cs index 37d27a78..d414e5c8 100644 --- a/src/SJZY.Track.Repository/Repositories/TrackTemplateRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/TrackTemplateRepository.cs @@ -179,4 +179,14 @@ public class TrackTemplateRepository : BasicRepository, ITr .Distinct() .ToPagedListAsync(input.PageIndex, input.PageSize); } + + public async Task ContentMaxAsync(Expression> columns, Expression> whereExpression) + { + return await Context.Queryable().Where(whereExpression).MaxAsync(columns); + } + + public async Task UpdateContentAsync(Expression> columns, Expression> whereExpression) + { + return await Context.Updateable().SetColumns(columns).Where(whereExpression).ExecuteCommandHasChangeAsync(); + } } \ No newline at end of file