完成 轨迹拉取配置编辑 接口

This commit is contained in:
柳文翔 2024-02-29 17:22:13 +08:00
parent 90e59e27ea
commit 812546bfa3
7 changed files with 265 additions and 1 deletions

View File

@ -0,0 +1,17 @@
using AutoMapper;
using SJZY.Track.Application.Dtos.TrackPull;
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using Volo.Abp.AutoMapper;
namespace SJZY.Track.Application.AutoMapper
{
public class TrackPullAutoMapperProfile : Profile
{
public TrackPullAutoMapperProfile()
{
CreateMap<EditTrackPullConfigInput, TrackPullConfigEntity>(MemberList.None);
CreateMap<EditTrackPullConfigInput, TrackPushPullParamsConfigEntity>(MemberList.None).Ignore(dest => dest.Id)
.ForMember(dest => dest.IsPush, opt => opt.MapFrom(source => false));
}
}
}

View File

@ -0,0 +1,71 @@
namespace SJZY.Track.Application.Dtos.TrackPull;
public class EditTrackPullConfigInput
{
public int? Id { get; set; }
/// <summary>
/// 操作类型
/// </summary>
public OptionTypeNoNull Options { get; set; }
/// <summary>
/// 拉取轨迹订单号
/// </summary>
public string OrderNoName { get; set; }
/// <summary>
/// 返参解析对象
/// </summary>
public int ParseMethod { get; set; }
/// <summary>
/// 定时任务(分钟)
/// </summary>
public int PullInterval { get; set; }
/// <summary>
/// 服务商id
/// </summary>
public int ServiceProviderId { get; set; }
/// <summary>
/// 子系统id
/// </summary>
public int SubSystemId { get; set; }
/// <summary>
/// 拉取轨迹时区
/// </summary>
public string TackTimeZoneName { get; set; }
/// <summary>
/// 拉取轨迹内容代码
/// </summary>
public string TrackContentCodeName { get; set; }
/// <summary>
/// 拉取轨迹内容
/// </summary>
public string TrackContentName { get; set; }
/// <summary>
/// 拉取轨迹发生地
/// </summary>
public string TrackPlaceName { get; set; }
/// <summary>
/// 拉取轨迹状态
/// </summary>
public string TrackStatusName { get; set; }
/// <summary>
/// 轨迹模板id
/// </summary>
public int TrackTemplateId { get; set; }
/// <summary>
/// 拉取轨迹发生时间
/// </summary>
public string TrackTimeName { get; set; }
}

View File

@ -1,8 +1,14 @@
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using SJZY.Expand.ABP.Core.Localization;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Track.Application.Dtos.TrackPull;
using SJZY.Track.Application.Dtos.TrackTemplates;
using SJZY.Track.Application.Localization; using SJZY.Track.Application.Localization;
using SJZY.Track.Domain.Aggregates.TrackPullAggregate; using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate;
using SJZY.Track.Domain.Dtos.Common; using SJZY.Track.Domain.Dtos.Common;
using SJZY.Track.Domain.Dtos.TrackPull; using SJZY.Track.Domain.Dtos.TrackPull;
using System.Linq.Expressions;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace SJZY.Track.Application.Services.TrackPull; namespace SJZY.Track.Application.Services.TrackPull;
@ -16,13 +22,16 @@ public class TrackPullService : ApplicationService, ITransientDependency
{ {
private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer; private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer;
private readonly ITrackPullConfigRepository _trackPullConfigRepository; private readonly ITrackPullConfigRepository _trackPullConfigRepository;
private readonly ITrackTemplateRepository _trackTemplateRepository;
public TrackPullService( public TrackPullService(
IStringLocalizer<TrackLocalizationResource> stringLocalizer, IStringLocalizer<TrackLocalizationResource> stringLocalizer,
ITrackPullConfigRepository trackPullConfigRepository) ITrackPullConfigRepository trackPullConfigRepository,
ITrackTemplateRepository trackTemplateRepository)
{ {
_stringLocalizer = stringLocalizer; _stringLocalizer = stringLocalizer;
_trackPullConfigRepository = trackPullConfigRepository; _trackPullConfigRepository = trackPullConfigRepository;
_trackTemplateRepository = trackTemplateRepository;
} }
/// <summary> /// <summary>
@ -68,4 +77,115 @@ public class TrackPullService : ApplicationService, ITransientDependency
{ {
return await _trackPullConfigRepository.GetContentDetailAsync(id); return await _trackPullConfigRepository.GetContentDetailAsync(id);
} }
/// <summary>
/// 轨迹拉取配置编辑
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("Edit")]
public async Task<bool> EditAsync([FromBody] EditTrackPullConfigInput input)
{
if (input.Options != OptionTypeNoNull.删除)
{
Expression<Func<TrackPullConfigEntity, bool>> isAnyExp = x =>
x.SubSystemId == input.SubSystemId && x.TrackTemplateId == input.TrackTemplateId && x.ServiceProviderId == input.ServiceProviderId;
if (input.Options == OptionTypeNoNull.修改) isAnyExp.And(x => x.Id != input.Id);
if (await _trackPullConfigRepository.IsAnyAsync(isAnyExp))
throw new BusinessException(message: _stringLocalizer["IsTrackPullConfigAny"]);
}
switch (input.Options)
{
case OptionTypeNoNull.新增:
{
var trackPullEntity = ObjectMapper.Map<EditTrackPullConfigInput, TrackPullConfigEntity>(input);
var trackPullParamsEntity = ObjectMapper.Map<EditTrackPullConfigInput, TrackPushPullParamsConfigEntity>(input);
var trackTemplateContentEntities = await _trackTemplateRepository.GetContentListAsync(x => x.TrackTemplateId == input.TrackTemplateId);
var trackPullContentEntities = new List<TrackPullContentConfigEntity>();
using (var ts = TransactionScopeHelper.Create())
{
int id = await _trackPullConfigRepository.InsertReturnIdentityAsync(trackPullEntity);
trackPullParamsEntity.PullOrPushConfigId = id;
await _trackPullConfigRepository.InsertParamsAsync(trackPullParamsEntity);
foreach (var item in trackTemplateContentEntities)
{
trackPullContentEntities.Add(new()
{
TrackPullConfigId = id,
TrackContentId = item.TrackContentId
});
}
await _trackPullConfigRepository.InsertContentRangeAsync(trackPullContentEntities);
ts.Complete();
}
}
break;
case OptionTypeNoNull.修改:
{
var oldTrackPullEntity = await _trackPullConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]);
var oldTrackPullParamsEntity = await _trackPullConfigRepository.GetParamsSingleAsync(x => x.PullOrPushConfigId == input.Id && !x.IsPush);
var trackPullContentEntities = new List<TrackPullContentConfigEntity>();
if (oldTrackPullEntity.TrackTemplateId != input.TrackTemplateId)
{
var trackTemplateContentEntities = await _trackTemplateRepository.GetContentListAsync(x => x.TrackTemplateId == input.TrackTemplateId);
foreach (var item in trackTemplateContentEntities)
{
trackPullContentEntities.Add(new()
{
TrackPullConfigId = oldTrackPullEntity.Id,
TrackContentId = item.TrackContentId
});
}
}
ObjectMapper.Map(input, oldTrackPullEntity);
ObjectMapper.Map(input, oldTrackPullParamsEntity);
using (var ts = TransactionScopeHelper.Create())
{
await _trackPullConfigRepository.UpdateAsync(oldTrackPullEntity);
await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPullParamsEntity);
if (oldTrackPullEntity.TrackTemplateId != input.TrackTemplateId)
{
await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.TrackPullConfigId == input.Id);
await _trackPullConfigRepository.InsertContentRangeAsync(trackPullContentEntities);
}
ts.Complete();
}
}
break;
case OptionTypeNoNull.删除:
using (var ts = TransactionScopeHelper.Create())
{
await _trackPullConfigRepository.SoftDeleteAsync(x => x.Id == input.Id);
await _trackPullConfigRepository.SoftDeleteParamsAsync(x => x.PullOrPushConfigId == input.Id && !x.IsPush);
await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.TrackPullConfigId == input.Id);
ts.Complete();
}
break;
default:
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,
nameof(EditTrackPullConfigInput.Options)]);
}
return true;
}
} }

View File

@ -32,4 +32,16 @@ public interface ITrackPullConfigRepository : IBasicRepository<TrackPullConfigEn
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
Task<GetTrackPullContentDetailOutputVO> GetContentDetailAsync(int id); Task<GetTrackPullContentDetailOutputVO> GetContentDetailAsync(int id);
Task<bool> InsertParamsAsync(TrackPushPullParamsConfigEntity insertObj);
Task<bool> InsertContentRangeAsync(List<TrackPullContentConfigEntity> insertObjs);
Task<TrackPushPullParamsConfigEntity> GetParamsSingleAsync(Expression<Func<TrackPushPullParamsConfigEntity, bool>> whereExpression);
Task<bool> UpdateParamsAsync(TrackPushPullParamsConfigEntity updateObj);
Task<bool> SoftDeleteContentAsync(Expression<Func<TrackPullContentConfigEntity, bool>> whereExpression);
Task<bool> SoftDeleteParamsAsync(Expression<Func<TrackPushPullParamsConfigEntity, bool>> whereExpression);
} }

View File

@ -34,4 +34,6 @@ public interface ITrackTemplateRepository : IBasicRepository<TrackTemplateEntity
Task<bool> UpdateContentAsync(TrackTemplateContentEntity updateObj); Task<bool> UpdateContentAsync(TrackTemplateContentEntity updateObj);
Task<bool> SoftDeleteContentAsync(int id); Task<bool> SoftDeleteContentAsync(int id);
Task<List<TrackTemplateContentEntity>> GetContentListAsync(Expression<Func<TrackTemplateContentEntity, bool>> whereExpression);
} }

View File

@ -4,6 +4,7 @@ using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate;
using SJZY.Track.Domain.Dtos.Common; using SJZY.Track.Domain.Dtos.Common;
using SJZY.Track.Domain.Dtos.TrackPull; using SJZY.Track.Domain.Dtos.TrackPull;
using SJZY.Track.Domain.VEntities; using SJZY.Track.Domain.VEntities;
using System.Linq.Expressions;
namespace SJZY.Track.Repository; namespace SJZY.Track.Repository;
@ -83,4 +84,40 @@ public class TrackPullConfigRepository : BasicRepository<TrackPullConfigEntity>,
}, true) }, true)
.SingleAsync(); .SingleAsync();
} }
public async Task<bool> InsertParamsAsync(TrackPushPullParamsConfigEntity insertObj)
{
return await Context.Insertable(insertObj).ExecuteCommandAsync() > 0;
}
public async Task<bool> InsertContentRangeAsync(List<TrackPullContentConfigEntity> insertObjs)
{
return await Context.Insertable(insertObjs).ExecuteCommandAsync() > 0;
}
public async Task<TrackPushPullParamsConfigEntity> GetParamsSingleAsync(Expression<Func<TrackPushPullParamsConfigEntity, bool>> whereExpression)
{
return await Context.Queryable<TrackPushPullParamsConfigEntity>().SingleAsync(whereExpression);
}
public async Task<bool> UpdateParamsAsync(TrackPushPullParamsConfigEntity updateObj)
{
return await Context.Updateable(updateObj).ExecuteCommandHasChangeAsync();
}
public async Task<bool> SoftDeleteContentAsync(Expression<Func<TrackPullContentConfigEntity, bool>> whereExpression)
{
return await Context.Updateable<TrackPullContentConfigEntity>()
.Where(whereExpression)
.SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true)
.ExecuteCommandHasChangeAsync();
}
public async Task<bool> SoftDeleteParamsAsync(Expression<Func<TrackPushPullParamsConfigEntity, bool>> whereExpression)
{
return await Context.Updateable<TrackPushPullParamsConfigEntity>()
.Where(whereExpression)
.SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true)
.ExecuteCommandHasChangeAsync();
}
} }

View File

@ -157,4 +157,9 @@ public class TrackTemplateRepository : BasicRepository<TrackTemplateEntity>, ITr
.SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true) .SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true)
.ExecuteCommandHasChangeAsync(); .ExecuteCommandHasChangeAsync();
} }
public async Task<List<TrackTemplateContentEntity>> GetContentListAsync(Expression<Func<TrackTemplateContentEntity, bool>> whereExpression)
{
return await Context.Queryable<TrackTemplateContentEntity>().Where(whereExpression).ToListAsync();
}
} }