Merge pull request 'S01-轨迹中台' (#41) from S01-轨迹中台 into test

Reviewed-on: http://192.168.80.50:3000/Dotnet/SJZY.Track.Api/pulls/41
This commit is contained in:
liuwenxiang 2024-03-04 10:20:21 +08:00
commit d3edc93afd
9 changed files with 88 additions and 29 deletions

View File

@ -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;
}
/// <summary>
@ -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<EditTrackContentInput, TrackContentEntity>(input);
@ -117,6 +115,7 @@ namespace SJZY.Track.Application.Services.TrackContents
private async Task<UnifyResultDto> 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);

View File

@ -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);

View File

@ -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;

View File

@ -215,26 +215,42 @@ public class TrackPushService : ApplicationService, ITransientDependency
{
case OptionTypeNoNull.新增:
{
var trackPushContentEntity = ObjectMapper.Map<EditTrackPushContentInput, TrackPushContentConfigEntity>(input);
int maxSort = await _trackPushConfigRepository.ContentMaxAsync(x => x.Sort, x => x.TrackPushConfigId == input.TrackPushConfigId);
await _trackPushConfigRepository.InsertContentAsync(trackPushContentEntity);
var entity = ObjectMapper.Map<EditTrackPushContentInput, TrackPushContentConfigEntity>(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,

View File

@ -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<EditTrackTemplateContentInput, TrackTemplateContentEntity>(input);
var entity = ObjectMapper.Map<EditTrackTemplateContentInput, TrackTemplateContentEntity>(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,

View File

@ -26,4 +26,8 @@ public interface ITrackPushConfigRepository : IBasicRepository<TrackPushConfigEn
Task<List<TrackPushContentConfigEntity>> GetContentListAsync(Expression<Func<TrackPushContentConfigEntity, bool>> whereExpression);
Task<bool> UpdateContentRangeAsync(List<TrackPushContentConfigEntity> updateObjs);
Task<T> ContentMaxAsync<T>(Expression<Func<TrackPushContentConfigEntity, T>> columns, Expression<Func<TrackPushContentConfigEntity, bool>> whereExpression);
Task<bool> UpdateContentAsync(Expression<Func<TrackPushContentConfigEntity, bool>> columns, Expression<Func<TrackPushContentConfigEntity, bool>> whereExpression);
}

View File

@ -40,4 +40,8 @@ public interface ITrackTemplateRepository : IBasicRepository<TrackTemplateEntity
Task<bool> UpdateContentRangeAsync(List<TrackTemplateContentEntity> updateObjs);
Task<UnifyPageResultDto<DropdownListDataDto>> GetContentDropDownListAsync(GetTrackTemplateContentDropDownListVO input);
Task<T> ContentMaxAsync<T>(Expression<Func<TrackTemplateContentEntity, T>> columns, Expression<Func<TrackTemplateContentEntity, bool>> whereExpression);
Task<bool> UpdateContentAsync(Expression<Func<TrackTemplateContentEntity, bool>> columns, Expression<Func<TrackTemplateContentEntity, bool>> whereExpression);
}

View File

@ -124,4 +124,14 @@ public class TrackPushConfigRepository : BasicRepository<TrackPushConfigEntity>,
{
return await Context.Updateable(updateObjs).ExecuteCommandHasChangeAsync();
}
public async Task<T> ContentMaxAsync<T>(Expression<Func<TrackPushContentConfigEntity, T>> columns, Expression<Func<TrackPushContentConfigEntity, bool>> whereExpression)
{
return await Context.Queryable<TrackPushContentConfigEntity>().Where(whereExpression).MaxAsync(columns);
}
public async Task<bool> UpdateContentAsync(Expression<Func<TrackPushContentConfigEntity, bool>> columns, Expression<Func<TrackPushContentConfigEntity, bool>> whereExpression)
{
return await Context.Updateable<TrackPushContentConfigEntity>().SetColumns(columns).Where(whereExpression).ExecuteCommandHasChangeAsync();
}
}

View File

@ -179,4 +179,14 @@ public class TrackTemplateRepository : BasicRepository<TrackTemplateEntity>, ITr
.Distinct()
.ToPagedListAsync(input.PageIndex, input.PageSize);
}
public async Task<T> ContentMaxAsync<T>(Expression<Func<TrackTemplateContentEntity, T>> columns, Expression<Func<TrackTemplateContentEntity, bool>> whereExpression)
{
return await Context.Queryable<TrackTemplateContentEntity>().Where(whereExpression).MaxAsync(columns);
}
public async Task<bool> UpdateContentAsync(Expression<Func<TrackTemplateContentEntity, bool>> columns, Expression<Func<TrackTemplateContentEntity, bool>> whereExpression)
{
return await Context.Updateable<TrackTemplateContentEntity>().SetColumns(columns).Where(whereExpression).ExecuteCommandHasChangeAsync();
}
}