208 lines
8.5 KiB
C#
208 lines
8.5 KiB
C#
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.Domain.Aggregates.TrackPullAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate;
|
|
using SJZY.Track.Domain.Dtos.Common;
|
|
using SJZY.Track.Domain.Dtos.TrackPull;
|
|
using System.Linq.Expressions;
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
namespace SJZY.Track.Application.Services.TrackPull;
|
|
|
|
/// <summary>
|
|
/// 轨迹拉取
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "轨迹拉取")]
|
|
[Route("/Track/PullConfig")]
|
|
public class TrackPullService : ApplicationService, ITransientDependency
|
|
{
|
|
private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer;
|
|
private readonly ITrackPullConfigRepository _trackPullConfigRepository;
|
|
private readonly ITrackTemplateRepository _trackTemplateRepository;
|
|
|
|
public TrackPullService(
|
|
IStringLocalizer<TrackLocalizationResource> stringLocalizer,
|
|
ITrackPullConfigRepository trackPullConfigRepository,
|
|
ITrackTemplateRepository trackTemplateRepository)
|
|
{
|
|
_stringLocalizer = stringLocalizer;
|
|
_trackPullConfigRepository = trackPullConfigRepository;
|
|
_trackTemplateRepository = trackTemplateRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹拉取配置列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("GetPage")]
|
|
public async Task<UnifyPageResultDto<GetTrackPullConfigPageOutputVO>> GetPageAsync([FromBody] KeywordsInputVO input)
|
|
{
|
|
return await _trackPullConfigRepository.GetPageAsync(input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹拉取配置内容列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("GetContentPage")]
|
|
public async Task<UnifyPageResultDto<GetTrackPullContentPageOutputVO>> GetContentPageAsync([FromBody] GetTrackPullContentPageInputVO input)
|
|
{
|
|
return await _trackPullConfigRepository.GetContentPageAsync(input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹拉取配置详情
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("GetDetail")]
|
|
public async Task<GetTrackPullConfigDetailOutputVO> GetDetailAsync(int id)
|
|
{
|
|
return await _trackPullConfigRepository.GetDetailAsync(id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹拉取配置内容详情
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("GetContentDetail")]
|
|
public async Task<GetTrackPullContentDetailOutputVO> GetContentDetailAsync(int 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹拉取配置内容修改
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("UpdateContent")]
|
|
public async Task<bool> UpdateContentAsync([FromBody] UpdateTrackPullContentInput input)
|
|
{
|
|
var oldTrackPullContentEntity = await _trackPullConfigRepository.GetContentByIdAsync(input.Id) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]);
|
|
|
|
ObjectMapper.Map(input, oldTrackPullContentEntity);
|
|
|
|
await _trackPullConfigRepository.UpdateContentAsync(oldTrackPullContentEntity);
|
|
|
|
return true;
|
|
}
|
|
} |