290 lines
12 KiB
C#
290 lines
12 KiB
C#
using System.Linq.Expressions;
|
|
using Microsoft.Extensions.Localization;
|
|
using Microsoft.Extensions.Options;
|
|
using SJZY.Expand.ABP.Core.Localization;
|
|
using SJZY.Expand.ABP.Core.PublicMethords;
|
|
using SJZY.Track.Application.Contract.Dtos.TrackPull;
|
|
using SJZY.Track.Application.Contract.Services;
|
|
using SJZY.Track.Application.Localization;
|
|
using SJZY.Track.Application.Options;
|
|
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
|
|
using SJZY.Track.Domain.Dtos.Common;
|
|
using SJZY.Track.Domain.Dtos.TrackPull;
|
|
using SqlSugar;
|
|
|
|
namespace SJZY.Track.Application.Services.TrackPull;
|
|
|
|
/// <summary>
|
|
/// 轨迹拉取
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "轨迹拉取")]
|
|
[Route("/Track/PullConfig")]
|
|
public class TrackPullService : ApplicationService
|
|
{
|
|
private readonly IOptionsMonitor<InterfaceRelayParamsConfigOptions> _options;
|
|
private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer;
|
|
private readonly ITrackPullCacheService _trackPullCacheService;
|
|
private readonly ITrackPullConfigRepository _trackPullConfigRepository;
|
|
|
|
public TrackPullService(
|
|
IStringLocalizer<TrackLocalizationResource> stringLocalizer,
|
|
ITrackPullConfigRepository trackPullConfigRepository,
|
|
ITrackPullCacheService trackPullCacheService, IOptionsMonitor<InterfaceRelayParamsConfigOptions> options)
|
|
{
|
|
_stringLocalizer = stringLocalizer;
|
|
_trackPullConfigRepository = trackPullConfigRepository;
|
|
_trackPullCacheService = trackPullCacheService;
|
|
_options = options;
|
|
}
|
|
|
|
/// <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)
|
|
{
|
|
var res = await _trackPullConfigRepository.GetDetailAsync(id);
|
|
|
|
if (res == null)
|
|
{
|
|
throw new BusinessException(message: "轨迹拉取配置不存在");
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
/// <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.PullInterval < 60) input.PullInterval = 60;
|
|
|
|
if (input.Options != OptionTypeNoNull.删除)
|
|
{
|
|
Expression<Func<TrackPullConfigEntity, bool>> isAnyExp = x =>
|
|
x.SubSystemId == input.SubSystemId && x.ServiceProviderId == input.ServiceProviderId;
|
|
if (input.Options == OptionTypeNoNull.修改) isAnyExp = 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);
|
|
|
|
if (input.ParseMethod == (int) ParseMethod.InterfaceRelay)
|
|
{
|
|
var paramsConfig = _options.CurrentValue;
|
|
if (paramsConfig == null)
|
|
{
|
|
throw new BusinessException(message: "未找到接口通参数配置,联系管理员添加");
|
|
}
|
|
|
|
trackPullEntity.OrderPath = paramsConfig.OrderPath;
|
|
trackPullEntity.OrderNoName = paramsConfig.OrderNoName;
|
|
trackPullEntity.TrackDetailsPath = paramsConfig.TrackDetailsPath;
|
|
trackPullEntity.TrackContentCodeName = paramsConfig.TrackContentCodeName;
|
|
trackPullEntity.TrackStatusName = paramsConfig.TrackStatusName;
|
|
trackPullEntity.TrackContentName = paramsConfig.TrackContentName;
|
|
trackPullEntity.TrackPlaceName = paramsConfig.TrackPlaceName;
|
|
trackPullEntity.TrackIsoTimeName = paramsConfig.TrackIsoTimeName;
|
|
trackPullEntity.TrackTimeName = paramsConfig.TrackTimeName;
|
|
trackPullEntity.TrackTimeZoneName = paramsConfig.TrackTimeZoneName;
|
|
}
|
|
|
|
var id = await _trackPullConfigRepository.InsertReturnIdentityAsync(trackPullEntity);
|
|
|
|
await _trackPullCacheService.SetPullConfigAsync(id);
|
|
}
|
|
break;
|
|
|
|
case OptionTypeNoNull.修改:
|
|
{
|
|
var oldTrackPullEntity = await _trackPullConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
|
|
throw new BusinessException(message: _stringLocalizer["NotFindData"]);
|
|
|
|
ObjectMapper.Map(input, oldTrackPullEntity);
|
|
if (input.ParseMethod == (int) ParseMethod.InterfaceRelay)
|
|
{
|
|
var paramsConfig = _options.CurrentValue;
|
|
if (paramsConfig == null)
|
|
{
|
|
throw new BusinessException(message: "未找到接口通参数配置,联系管理员添加");
|
|
}
|
|
|
|
oldTrackPullEntity.OrderPath = paramsConfig.OrderPath;
|
|
oldTrackPullEntity.OrderNoName = paramsConfig.OrderNoName;
|
|
oldTrackPullEntity.TrackDetailsPath = paramsConfig.TrackDetailsPath;
|
|
oldTrackPullEntity.TrackContentCodeName = paramsConfig.TrackContentCodeName;
|
|
oldTrackPullEntity.TrackStatusName = paramsConfig.TrackStatusName;
|
|
oldTrackPullEntity.TrackContentName = paramsConfig.TrackContentName;
|
|
oldTrackPullEntity.TrackPlaceName = paramsConfig.TrackPlaceName;
|
|
oldTrackPullEntity.TrackIsoTimeName = paramsConfig.TrackIsoTimeName;
|
|
oldTrackPullEntity.TrackTimeName = paramsConfig.TrackTimeName;
|
|
oldTrackPullEntity.TrackTimeZoneName = paramsConfig.TrackTimeZoneName;
|
|
}
|
|
|
|
await _trackPullConfigRepository.UpdateAsync(oldTrackPullEntity);
|
|
|
|
await _trackPullCacheService.SetPullConfigAsync(input.Id!.Value);
|
|
}
|
|
break;
|
|
|
|
case OptionTypeNoNull.删除:
|
|
using (var ts = TransactionScopeHelper.Create())
|
|
{
|
|
await _trackPullConfigRepository.SoftDeleteAsync(x => x.Id == input.Id);
|
|
|
|
await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.TrackPullConfigId == input.Id);
|
|
|
|
await _trackPullCacheService.SetPullConfigAsync(input.Id!.Value);
|
|
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("EditContent")]
|
|
public async Task<bool> EditContentAsync([FromBody] EditTrackPullContentInput input)
|
|
{
|
|
if (input.Options != OptionTypeNoNull.删除)
|
|
{
|
|
Expression<Func<TrackPullContentConfigEntity, bool>> isContentAnyExp = x =>
|
|
x.TrackPullConfigId == input.TrackPullConfigId;
|
|
|
|
if (input.Options == OptionTypeNoNull.修改)
|
|
{
|
|
isContentAnyExp = isContentAnyExp.And(x => x.Id != input.Id);
|
|
}
|
|
|
|
if (await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
|
|
x.TrackContentId == input.TrackContentId)))
|
|
throw new BusinessException(message: _stringLocalizer["IsTrackPullContentAny"]);
|
|
|
|
if (!input.TrackStatusValues.IsNullOrEmpty())
|
|
{
|
|
Expression<Func<TrackPullContentConfigEntity, bool>> trackStatusValuesExp = _ => false;
|
|
input.TrackStatusValues!.ForEach(item =>
|
|
{
|
|
trackStatusValuesExp = trackStatusValuesExp.Or(x => SqlFunc.SplitIn(x.TrackStatusValue, item));
|
|
});
|
|
|
|
if (await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(trackStatusValuesExp)))
|
|
throw new BusinessException(message: _stringLocalizer["IsTrackPullContentStatusValueAny"]);
|
|
}
|
|
|
|
if (!input.TrackKeywords.IsNullOrEmpty())
|
|
{
|
|
Expression<Func<TrackPullContentConfigEntity, bool>> trackKeywordExp = _ => false;
|
|
input.TrackKeywords!.ForEach(item =>
|
|
{
|
|
trackKeywordExp = trackKeywordExp.Or(x => SqlFunc.SplitIn(x.TrackKeyword, item));
|
|
});
|
|
|
|
if (await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(trackKeywordExp)))
|
|
throw new BusinessException(message: _stringLocalizer["IsTrackPullContentKeywordsAny"]);
|
|
}
|
|
}
|
|
|
|
switch (input.Options)
|
|
{
|
|
case OptionTypeNoNull.新增:
|
|
{
|
|
var entity = ObjectMapper.Map<EditTrackPullContentInput, TrackPullContentConfigEntity>(input);
|
|
|
|
await _trackPullConfigRepository.InsertContentAsync(entity);
|
|
await _trackPullCacheService.SetPullConfigAsync(input.TrackPullConfigId!.Value);
|
|
|
|
break;
|
|
}
|
|
|
|
case OptionTypeNoNull.修改:
|
|
{
|
|
var oldTrackPullContentEntity =
|
|
await _trackPullConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
|
|
throw new BusinessException(message: _stringLocalizer["NotFindData"]);
|
|
|
|
ObjectMapper.Map(input, oldTrackPullContentEntity);
|
|
|
|
await _trackPullConfigRepository.UpdateContentAsync(oldTrackPullContentEntity);
|
|
await _trackPullCacheService.SetPullConfigAsync(oldTrackPullContentEntity.TrackPullConfigId);
|
|
|
|
break;
|
|
}
|
|
|
|
case OptionTypeNoNull.删除:
|
|
{
|
|
var oldTrackPullContentEntity =
|
|
await _trackPullConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
|
|
throw new BusinessException(message: _stringLocalizer["NotFindData"]);
|
|
|
|
await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
|
|
await _trackPullCacheService.SetPullConfigAsync(oldTrackPullContentEntity.TrackPullConfigId);
|
|
|
|
break;
|
|
}
|
|
|
|
default:
|
|
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,
|
|
nameof(EditTrackPullContentInput.Options)]);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|