From 397297177ea436af3732ec8425781b8fa430da0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=96=87=E7=BF=94?= <878130837@qq.com> Date: Tue, 27 Feb 2024 20:52:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20=E8=BD=A8=E8=BF=B9?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=86=85=E5=AE=B9=E7=BC=96=E8=BE=91=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TrackTemplateAutoMapperProfile.cs | 5 +- .../EditTrackTemplateContentInput.cs | 38 +++++++++++++ .../TrackTemplates/TrackTemplateService.cs | 57 ++++++++++++++++++- ... GetTrackTemplateContentDetailOutputVO.cs} | 2 +- ... => GetTrackTemplateContentPageInputVO.cs} | 2 +- ...=> GetTrackTemplateContentPageOutputVO.cs} | 2 +- .../ITrackTemplateRepository.cs | 14 ++++- .../TrackTemplateRepository.cs | 47 +++++++++++++-- 8 files changed, 153 insertions(+), 14 deletions(-) create mode 100644 src/SJZY.Track.Application/Dtos/TrackTemplates/EditTrackTemplateContentInput.cs rename src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/{GetContentDetailOutputVO.cs => GetTrackTemplateContentDetailOutputVO.cs} (94%) rename src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/{GetContentPageInputVO.cs => GetTrackTemplateContentPageInputVO.cs} (72%) rename src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/{GetContentPageOutputVO.cs => GetTrackTemplateContentPageOutputVO.cs} (96%) diff --git a/src/SJZY.Track.Application/AutoMapper/TrackTemplateAutoMapperProfile.cs b/src/SJZY.Track.Application/AutoMapper/TrackTemplateAutoMapperProfile.cs index e581521f..bd6d7f2b 100644 --- a/src/SJZY.Track.Application/AutoMapper/TrackTemplateAutoMapperProfile.cs +++ b/src/SJZY.Track.Application/AutoMapper/TrackTemplateAutoMapperProfile.cs @@ -1,5 +1,6 @@ using AutoMapper; using SJZY.Track.Application.Dtos.TrackTemplates; +using SJZY.Track.Domain.TrackTemplateAggregate; using SJZY.Track.Domain.TrackTemplateAggregate.Dtos; namespace SJZY.Track.Application.AutoMapper @@ -14,6 +15,8 @@ namespace SJZY.Track.Application.AutoMapper CreateMap(MemberList.None); //CreateMap, UnifyResultDto>(MemberList.None); + + CreateMap(MemberList.None); } } -} +} \ No newline at end of file diff --git a/src/SJZY.Track.Application/Dtos/TrackTemplates/EditTrackTemplateContentInput.cs b/src/SJZY.Track.Application/Dtos/TrackTemplates/EditTrackTemplateContentInput.cs new file mode 100644 index 00000000..bb45dc74 --- /dev/null +++ b/src/SJZY.Track.Application/Dtos/TrackTemplates/EditTrackTemplateContentInput.cs @@ -0,0 +1,38 @@ +namespace SJZY.Track.Application.Dtos.TrackTemplates; + +/// +public class EditTrackTemplateContentInput +{ + /// + /// 操作类型 + /// + public OptionTypeNoNull Options { get; set; } + + /// + public int? Id { get; set; } + + /// + /// 是否可删 + /// + public bool IsCanDelete { get; set; } + + /// + /// 是否对外 + /// + public bool IsExternal { get; set; } + + /// + /// 排序 + /// + public int Sort { get; set; } + + /// + /// 轨迹内容id + /// + public int TrackContentId { get; set; } + + /// + /// 轨迹模板id + /// + public int TrackTemplateId { get; set; } +} \ No newline at end of file diff --git a/src/SJZY.Track.Application/Services/TrackTemplates/TrackTemplateService.cs b/src/SJZY.Track.Application/Services/TrackTemplates/TrackTemplateService.cs index d0920499..03ce0705 100644 --- a/src/SJZY.Track.Application/Services/TrackTemplates/TrackTemplateService.cs +++ b/src/SJZY.Track.Application/Services/TrackTemplates/TrackTemplateService.cs @@ -1,8 +1,10 @@ using Microsoft.Extensions.Localization; +using SJZY.Expand.ABP.Core.Localization; using SJZY.Track.Application.Dtos.TrackTemplates; using SJZY.Track.Application.Localization; using SJZY.Track.Domain.TrackTemplateAggregate; using SJZY.Track.Domain.TrackTemplateAggregate.Dtos; +using System.Linq.Expressions; using Volo.Abp.DependencyInjection; namespace SJZY.Track.Application.Services.TrackTemplates; @@ -111,7 +113,7 @@ public class TrackTemplateService : ApplicationService, ITrackTemplateService, I /// /// [HttpPost("GetContentPage")] - public async Task> GetContentPageAsync([FromBody] GetContentPageInputVO input) + public async Task> GetContentPageAsync([FromBody] GetTrackTemplateContentPageInputVO input) { return await _trackTemplateRepository.GetContentPageAsync(input); } @@ -122,8 +124,59 @@ public class TrackTemplateService : ApplicationService, ITrackTemplateService, I /// /// [HttpGet("GetContentDetail")] - public async Task GetContentDetailAsync(int id) + public async Task GetContentDetailAsync(int id) { return await _trackTemplateRepository.GetContentDetailAsync(id); } + + /// + /// 轨迹模板内容编辑 + /// + /// + /// + [HttpPost("EditContent")] + public async Task EditContentAsync([FromBody] EditTrackTemplateContentInput input) + { + if (input.Options != OptionTypeNoNull.删除) + { + Expression> isAnyExp = x => + x.TrackTemplateId == input.TrackTemplateId && x.TrackContentId == input.TrackContentId; + if (input.Options == OptionTypeNoNull.修改) isAnyExp.And(x => x.Id != input.Id); + + if (await _trackTemplateRepository.IsAnyAsync(isAnyExp)) + throw new BusinessException(message: _stringLocalizer["IsTrackTemplateContentAny"]); + } + + switch (input.Options) + { + case OptionTypeNoNull.新增: + + var entity = ObjectMapper.Map(input); + + await _trackTemplateRepository.InsertAsync(entity); + + break; + + case OptionTypeNoNull.修改: + + var oldEntity = await _trackTemplateRepository.GetByIdAsync(input.Id!.Value) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]); + + ObjectMapper.Map(input, oldEntity); + + await _trackTemplateRepository.UpdateAsync(oldEntity); + + break; + + case OptionTypeNoNull.删除: + + await _trackTemplateRepository.SoftDeleteContentAsync(input.Id!.Value); + + break; + + default: + throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum, nameof(EditTrackTemplateContentInput.Options)]); + } + + return true; + } } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetContentDetailOutputVO.cs b/src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetTrackTemplateContentDetailOutputVO.cs similarity index 94% rename from src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetContentDetailOutputVO.cs rename to src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetTrackTemplateContentDetailOutputVO.cs index 0f67eed7..eb787aef 100644 --- a/src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetContentDetailOutputVO.cs +++ b/src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetTrackTemplateContentDetailOutputVO.cs @@ -1,6 +1,6 @@ namespace SJZY.Track.Domain.TrackTemplateAggregate.Dtos { - public class GetContentDetailOutputVO + public class GetTrackTemplateContentDetailOutputVO { public int Id { get; set; } diff --git a/src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetContentPageInputVO.cs b/src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetTrackTemplateContentPageInputVO.cs similarity index 72% rename from src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetContentPageInputVO.cs rename to src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetTrackTemplateContentPageInputVO.cs index 396fe85b..01f0d8ad 100644 --- a/src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetContentPageInputVO.cs +++ b/src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetTrackTemplateContentPageInputVO.cs @@ -1,6 +1,6 @@ namespace SJZY.Track.Domain.TrackTemplateAggregate.Dtos; -public class GetContentPageInputVO : PageInfoInput +public class GetTrackTemplateContentPageInputVO : PageInfoInput { /// /// 轨迹模板id diff --git a/src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetContentPageOutputVO.cs b/src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetTrackTemplateContentPageOutputVO.cs similarity index 96% rename from src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetContentPageOutputVO.cs rename to src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetTrackTemplateContentPageOutputVO.cs index d008a8ef..d5159437 100644 --- a/src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetContentPageOutputVO.cs +++ b/src/SJZY.Track.Domain/TrackTemplateAggregate/Dtos/GetTrackTemplateContentPageOutputVO.cs @@ -1,6 +1,6 @@ namespace SJZY.Track.Domain.TrackTemplateAggregate.Dtos; -public class GetContentPageOutputVO +public class GetTrackTemplateContentPageOutputVO { /// /// 轨迹内容代码 diff --git a/src/SJZY.Track.Domain/TrackTemplateAggregate/ITrackTemplateRepository.cs b/src/SJZY.Track.Domain/TrackTemplateAggregate/ITrackTemplateRepository.cs index 252a1a44..41f4fbf3 100644 --- a/src/SJZY.Track.Domain/TrackTemplateAggregate/ITrackTemplateRepository.cs +++ b/src/SJZY.Track.Domain/TrackTemplateAggregate/ITrackTemplateRepository.cs @@ -15,12 +15,22 @@ public interface ITrackTemplateRepository : IBasicRepository /// /// - Task> GetContentPageAsync(GetContentPageInputVO input); + Task> GetContentPageAsync(GetTrackTemplateContentPageInputVO input); /// /// 轨迹模板内容详情 /// /// /// - Task GetContentDetailAsync(int id); + Task GetContentDetailAsync(int id); + + Task IsAnyAsync(Expression> whereExpression); + + Task InsertAsync(TrackTemplateContentEntity insertObj); + + Task GetByIdAsync(int id); + + Task UpdateAsync(TrackTemplateContentEntity updateObj); + + Task SoftDeleteContentAsync(int id); } \ No newline at end of file diff --git a/src/SJZY.Track.Repository/TrackTemplateRepository.cs b/src/SJZY.Track.Repository/TrackTemplateRepository.cs index 4c293af4..63d889c6 100644 --- a/src/SJZY.Track.Repository/TrackTemplateRepository.cs +++ b/src/SJZY.Track.Repository/TrackTemplateRepository.cs @@ -6,9 +6,11 @@ using SJZY.Track.Domain.TrackTemplateAggregate; using SJZY.Track.Domain.TrackTemplateAggregate.Dtos; using SJZY.Track.Domain.VEntities; using SJZY.Track.Repository.Enum; +using System.Linq.Expressions; namespace SJZY.Track.Repository; +/// public class TrackTemplateRepository : BasicRepository, ITrackTemplateRepository, IScopedDependency { public Task GetTemplateContentsAsync(List distinctTemplateIds) @@ -61,9 +63,9 @@ public class TrackTemplateRepository : BasicRepository, ITr } /// - public async Task> GetContentPageAsync(GetContentPageInputVO input) + public async Task> GetContentPageAsync(GetTrackTemplateContentPageInputVO input) { - return await AsSugarClient().Queryable() + return await Context.Queryable() .InnerJoin((templateContent, trackContent) => templateContent.TrackContentId == trackContent.Id && !trackContent.IsDeleted) .LeftJoin((templateContent, trackContent, trackStatus) => trackContent.TrackStatusId == trackStatus.Id && !trackStatus.IsDeleted) .LeftJoin((templateContent, trackContent, trackStatus, enumValue) => enumValue.Property == EnumPropertyEnums.节点.GetDescription() && trackStatus.Node == enumValue.Enumkey && !enumValue.IsDeleted) @@ -72,7 +74,7 @@ public class TrackTemplateRepository : BasicRepository, ITr .LeftJoin((templateContent, trackContent, trackStatus, enumValue, trackFlag, createUser, updateUser) => templateContent.UpdateUserId == updateUser.Id && !updateUser.IsDeleted) .Filter(null, true) .Where(templateContent => templateContent.TrackTemplateId == input.TrackTemplateId && !templateContent.IsDeleted) - .Select((templateContent, trackContent, trackStatus, enumValue, trackFlag, createUser, updateUser) => new GetContentPageOutputVO + .Select((templateContent, trackContent, trackStatus, enumValue, trackFlag, createUser, updateUser) => new GetTrackTemplateContentPageOutputVO { Id = templateContent.Id, TrackStatus = trackStatus.Status, @@ -87,14 +89,14 @@ public class TrackTemplateRepository : BasicRepository, ITr } /// - public async Task GetContentDetailAsync(int id) + public async Task GetContentDetailAsync(int id) { - return await AsSugarClient().Queryable() + return await Context.Queryable() .InnerJoin((templateContent, trackContent) => templateContent.TrackContentId == trackContent.Id && !trackContent.IsDeleted) .LeftJoin((templateContent, trackContent, trackStatus) => trackContent.TrackStatusId == trackStatus.Id && !trackStatus.IsDeleted) .Filter(null, true) .Where(templateContent => templateContent.Id == id && !templateContent.IsDeleted) - .Select((templateContent, trackContent, trackStatus) => new GetContentDetailOutputVO + .Select((templateContent, trackContent, trackStatus) => new GetTrackTemplateContentDetailOutputVO { Id = templateContent.Id, TrackContent = trackContent.Code + "-" + trackContent.Content, @@ -102,4 +104,37 @@ public class TrackTemplateRepository : BasicRepository, ITr }, true) .SingleAsync(); } + + /// + public async Task IsAnyAsync(Expression> whereExpression) + { + return await Context.Queryable().Where(whereExpression).AnyAsync(); + } + + /// + public async Task InsertAsync(TrackTemplateContentEntity insertObj) + { + return await Context.Insertable(insertObj).ExecuteCommandAsync() > 0; + } + + /// + public async Task GetByIdAsync(int id) + { + return await Context.Queryable().InSingleAsync(id); + } + + /// + public async Task UpdateAsync(TrackTemplateContentEntity updateObj) + { + return await Context.Updateable(updateObj).ExecuteCommandHasChangeAsync(); + } + + /// + public async Task SoftDeleteContentAsync(int id) + { + return await Context.Updateable() + .Where(x => x.Id == id) + .SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true) + .ExecuteCommandHasChangeAsync(); + } } \ No newline at end of file