Merge branch 'S01-轨迹中台' of http://192.168.80.50:3000/Dotnet/SJZY.Track.Api into S01-轨迹中台

This commit is contained in:
moyongzhen 2024-02-27 21:17:14 +08:00
commit e5419ec2f9
8 changed files with 153 additions and 14 deletions

View File

@ -1,5 +1,6 @@
using AutoMapper; using AutoMapper;
using SJZY.Track.Application.Dtos.TrackTemplates; using SJZY.Track.Application.Dtos.TrackTemplates;
using SJZY.Track.Domain.TrackTemplateAggregate;
using SJZY.Track.Domain.TrackTemplateAggregate.Dtos; using SJZY.Track.Domain.TrackTemplateAggregate.Dtos;
namespace SJZY.Track.Application.AutoMapper namespace SJZY.Track.Application.AutoMapper
@ -14,6 +15,8 @@ namespace SJZY.Track.Application.AutoMapper
CreateMap<GetTrackTemplateDetailVO, GetTrackTemplateDetailDto>(MemberList.None); CreateMap<GetTrackTemplateDetailVO, GetTrackTemplateDetailDto>(MemberList.None);
//CreateMap<UnifyResultDto<GetTrackTemplateDetailVO>, UnifyResultDto<GetTrackTemplateDetailDto>>(MemberList.None); //CreateMap<UnifyResultDto<GetTrackTemplateDetailVO>, UnifyResultDto<GetTrackTemplateDetailDto>>(MemberList.None);
CreateMap<EditTrackTemplateContentInput, TrackTemplateContentEntity>(MemberList.None);
} }
} }
} }

View File

@ -0,0 +1,38 @@
namespace SJZY.Track.Application.Dtos.TrackTemplates;
/// <inheritdoc/>
public class EditTrackTemplateContentInput
{
/// <summary>
/// 操作类型
/// </summary>
public OptionTypeNoNull Options { get; set; }
/// <inheritdoc/>
public int? Id { get; set; }
/// <summary>
/// 是否可删
/// </summary>
public bool IsCanDelete { get; set; }
/// <summary>
/// 是否对外
/// </summary>
public bool IsExternal { get; set; }
/// <summary>
/// 排序
/// </summary>
public int Sort { get; set; }
/// <summary>
/// 轨迹内容id
/// </summary>
public int TrackContentId { get; set; }
/// <summary>
/// 轨迹模板id
/// </summary>
public int TrackTemplateId { get; set; }
}

View File

@ -1,8 +1,10 @@
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using SJZY.Expand.ABP.Core.Localization;
using SJZY.Track.Application.Dtos.TrackTemplates; using SJZY.Track.Application.Dtos.TrackTemplates;
using SJZY.Track.Application.Localization; using SJZY.Track.Application.Localization;
using SJZY.Track.Domain.TrackTemplateAggregate; using SJZY.Track.Domain.TrackTemplateAggregate;
using SJZY.Track.Domain.TrackTemplateAggregate.Dtos; using SJZY.Track.Domain.TrackTemplateAggregate.Dtos;
using System.Linq.Expressions;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace SJZY.Track.Application.Services.TrackTemplates; namespace SJZY.Track.Application.Services.TrackTemplates;
@ -111,7 +113,7 @@ public class TrackTemplateService : ApplicationService, ITransientDependency
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("GetContentPage")] [HttpPost("GetContentPage")]
public async Task<UnifyPageResultDto<GetContentPageOutputVO>> GetContentPageAsync([FromBody] GetContentPageInputVO input) public async Task<UnifyPageResultDto<GetTrackTemplateContentPageOutputVO>> GetContentPageAsync([FromBody] GetTrackTemplateContentPageInputVO input)
{ {
return await _trackTemplateRepository.GetContentPageAsync(input); return await _trackTemplateRepository.GetContentPageAsync(input);
} }
@ -122,8 +124,59 @@ public class TrackTemplateService : ApplicationService, ITransientDependency
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet("GetContentDetail")] [HttpGet("GetContentDetail")]
public async Task<GetContentDetailOutputVO> GetContentDetailAsync(int id) public async Task<GetTrackTemplateContentDetailOutputVO> GetContentDetailAsync(int id)
{ {
return await _trackTemplateRepository.GetContentDetailAsync(id); return await _trackTemplateRepository.GetContentDetailAsync(id);
} }
/// <summary>
/// 轨迹模板内容编辑
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("EditContent")]
public async Task<bool> EditContentAsync([FromBody] EditTrackTemplateContentInput input)
{
if (input.Options != OptionTypeNoNull.删除)
{
Expression<Func<TrackTemplateContentEntity, bool>> 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<EditTrackTemplateContentInput, TrackTemplateContentEntity>(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;
}
} }

View File

@ -1,6 +1,6 @@
namespace SJZY.Track.Domain.TrackTemplateAggregate.Dtos namespace SJZY.Track.Domain.TrackTemplateAggregate.Dtos
{ {
public class GetContentDetailOutputVO public class GetTrackTemplateContentDetailOutputVO
{ {
public int Id { get; set; } public int Id { get; set; }

View File

@ -1,6 +1,6 @@
namespace SJZY.Track.Domain.TrackTemplateAggregate.Dtos; namespace SJZY.Track.Domain.TrackTemplateAggregate.Dtos;
public class GetContentPageInputVO : PageInfoInput public class GetTrackTemplateContentPageInputVO : PageInfoInput
{ {
/// <summary> /// <summary>
/// 轨迹模板id /// 轨迹模板id

View File

@ -1,6 +1,6 @@
namespace SJZY.Track.Domain.TrackTemplateAggregate.Dtos; namespace SJZY.Track.Domain.TrackTemplateAggregate.Dtos;
public class GetContentPageOutputVO public class GetTrackTemplateContentPageOutputVO
{ {
/// <summary> /// <summary>
/// 轨迹内容代码 /// 轨迹内容代码

View File

@ -15,12 +15,22 @@ public interface ITrackTemplateRepository : IBasicRepository<TrackTemplateEntity
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
Task<UnifyPageResultDto<GetContentPageOutputVO>> GetContentPageAsync(GetContentPageInputVO input); Task<UnifyPageResultDto<GetTrackTemplateContentPageOutputVO>> GetContentPageAsync(GetTrackTemplateContentPageInputVO input);
/// <summary> /// <summary>
/// 轨迹模板内容详情 /// 轨迹模板内容详情
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
Task<GetContentDetailOutputVO> GetContentDetailAsync(int id); Task<GetTrackTemplateContentDetailOutputVO> GetContentDetailAsync(int id);
Task<bool> IsAnyAsync(Expression<Func<TrackTemplateContentEntity, bool>> whereExpression);
Task<bool> InsertAsync(TrackTemplateContentEntity insertObj);
Task<TrackTemplateContentEntity> GetByIdAsync(int id);
Task<bool> UpdateAsync(TrackTemplateContentEntity updateObj);
Task<bool> SoftDeleteContentAsync(int id);
} }

View File

@ -7,9 +7,11 @@ using SJZY.Track.Domain.TrackTemplateAggregate;
using SJZY.Track.Domain.TrackTemplateAggregate.Dtos; using SJZY.Track.Domain.TrackTemplateAggregate.Dtos;
using SJZY.Track.Domain.VEntities; using SJZY.Track.Domain.VEntities;
using SJZY.Track.Repository.Enum; using SJZY.Track.Repository.Enum;
using System.Linq.Expressions;
namespace SJZY.Track.Repository; namespace SJZY.Track.Repository;
/// <inheritdoc/>
public class TrackTemplateRepository : BasicRepository<TrackTemplateEntity>, ITrackTemplateRepository, IScopedDependency public class TrackTemplateRepository : BasicRepository<TrackTemplateEntity>, ITrackTemplateRepository, IScopedDependency
{ {
public Task<TemplateContentDto> GetTemplateContentsAsync(List<int> distinctTemplateIds) public Task<TemplateContentDto> GetTemplateContentsAsync(List<int> distinctTemplateIds)
@ -98,9 +100,9 @@ public class TrackTemplateRepository : BasicRepository<TrackTemplateEntity>, ITr
} }
/// <inheritdoc/> /// <inheritdoc/>
public async Task<UnifyPageResultDto<GetContentPageOutputVO>> GetContentPageAsync(GetContentPageInputVO input) public async Task<UnifyPageResultDto<GetTrackTemplateContentPageOutputVO>> GetContentPageAsync(GetTrackTemplateContentPageInputVO input)
{ {
return await AsSugarClient().Queryable<TrackTemplateContentEntity>() return await Context.Queryable<TrackTemplateContentEntity>()
.InnerJoin<TrackContentEntity>((templateContent, trackContent) => templateContent.TrackContentId == trackContent.Id && !trackContent.IsDeleted) .InnerJoin<TrackContentEntity>((templateContent, trackContent) => templateContent.TrackContentId == trackContent.Id && !trackContent.IsDeleted)
.LeftJoin<TrackStatusEntity>((templateContent, trackContent, trackStatus) => trackContent.TrackStatusId == trackStatus.Id && !trackStatus.IsDeleted) .LeftJoin<TrackStatusEntity>((templateContent, trackContent, trackStatus) => trackContent.TrackStatusId == trackStatus.Id && !trackStatus.IsDeleted)
.LeftJoin<VEnumValueInfoEntity>((templateContent, trackContent, trackStatus, enumValue) => enumValue.Property == EnumPropertyEnums.节点.GetDescription() && trackStatus.Node == enumValue.Enumkey && !enumValue.IsDeleted) .LeftJoin<VEnumValueInfoEntity>((templateContent, trackContent, trackStatus, enumValue) => enumValue.Property == EnumPropertyEnums.节点.GetDescription() && trackStatus.Node == enumValue.Enumkey && !enumValue.IsDeleted)
@ -109,7 +111,7 @@ public class TrackTemplateRepository : BasicRepository<TrackTemplateEntity>, ITr
.LeftJoin<VUserEntity>((templateContent, trackContent, trackStatus, enumValue, trackFlag, createUser, updateUser) => templateContent.UpdateUserId == updateUser.Id && !updateUser.IsDeleted) .LeftJoin<VUserEntity>((templateContent, trackContent, trackStatus, enumValue, trackFlag, createUser, updateUser) => templateContent.UpdateUserId == updateUser.Id && !updateUser.IsDeleted)
.Filter(null, true) .Filter(null, true)
.Where(templateContent => templateContent.TrackTemplateId == input.TrackTemplateId && !templateContent.IsDeleted) .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, Id = templateContent.Id,
TrackStatus = trackStatus.Status, TrackStatus = trackStatus.Status,
@ -124,14 +126,14 @@ public class TrackTemplateRepository : BasicRepository<TrackTemplateEntity>, ITr
} }
/// <inheritdoc/> /// <inheritdoc/>
public async Task<GetContentDetailOutputVO> GetContentDetailAsync(int id) public async Task<GetTrackTemplateContentDetailOutputVO> GetContentDetailAsync(int id)
{ {
return await AsSugarClient().Queryable<TrackTemplateContentEntity>() return await Context.Queryable<TrackTemplateContentEntity>()
.InnerJoin<TrackContentEntity>((templateContent, trackContent) => templateContent.TrackContentId == trackContent.Id && !trackContent.IsDeleted) .InnerJoin<TrackContentEntity>((templateContent, trackContent) => templateContent.TrackContentId == trackContent.Id && !trackContent.IsDeleted)
.LeftJoin<TrackStatusEntity>((templateContent, trackContent, trackStatus) => trackContent.TrackStatusId == trackStatus.Id && !trackStatus.IsDeleted) .LeftJoin<TrackStatusEntity>((templateContent, trackContent, trackStatus) => trackContent.TrackStatusId == trackStatus.Id && !trackStatus.IsDeleted)
.Filter(null, true) .Filter(null, true)
.Where(templateContent => templateContent.Id == id && !templateContent.IsDeleted) .Where(templateContent => templateContent.Id == id && !templateContent.IsDeleted)
.Select((templateContent, trackContent, trackStatus) => new GetContentDetailOutputVO .Select((templateContent, trackContent, trackStatus) => new GetTrackTemplateContentDetailOutputVO
{ {
Id = templateContent.Id, Id = templateContent.Id,
TrackContent = trackContent.Code + "-" + trackContent.Content, TrackContent = trackContent.Code + "-" + trackContent.Content,
@ -139,4 +141,37 @@ public class TrackTemplateRepository : BasicRepository<TrackTemplateEntity>, ITr
}, true) }, true)
.SingleAsync(); .SingleAsync();
} }
/// <inheritdoc/>
public async Task<bool> IsAnyAsync(Expression<Func<TrackTemplateContentEntity, bool>> whereExpression)
{
return await Context.Queryable<TrackTemplateContentEntity>().Where(whereExpression).AnyAsync();
}
/// <inheritdoc/>
public async Task<bool> InsertAsync(TrackTemplateContentEntity insertObj)
{
return await Context.Insertable(insertObj).ExecuteCommandAsync() > 0;
}
/// <inheritdoc/>
public async Task<TrackTemplateContentEntity> GetByIdAsync(int id)
{
return await Context.Queryable<TrackTemplateContentEntity>().InSingleAsync(id);
}
/// <inheritdoc/>
public async Task<bool> UpdateAsync(TrackTemplateContentEntity updateObj)
{
return await Context.Updateable(updateObj).ExecuteCommandHasChangeAsync();
}
/// <inheritdoc/>
public async Task<bool> SoftDeleteContentAsync(int id)
{
return await Context.Updateable<TrackTemplateContentEntity>()
.Where(x => x.Id == id)
.SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true)
.ExecuteCommandHasChangeAsync();
}
} }