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 0dfe71fa..e4f875dc 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, ITransientDependency /// /// [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, ITransientDependency /// /// [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 03b0435d..55c78505 100644 --- a/src/SJZY.Track.Repository/TrackTemplateRepository.cs +++ b/src/SJZY.Track.Repository/TrackTemplateRepository.cs @@ -7,9 +7,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) @@ -98,9 +100,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) @@ -109,7 +111,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, @@ -124,14 +126,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, @@ -139,4 +141,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