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