304 lines
12 KiB
C#
304 lines
12 KiB
C#
using System.Linq.Expressions;
|
|
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.Services;
|
|
using SJZY.Track.Application.Localization;
|
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
|
|
using SJZY.Track.Domain.Dtos.Common;
|
|
using SJZY.Track.Domain.Dtos.TrackPush;
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
namespace SJZY.Track.Application.Services.TrackPush;
|
|
|
|
/// <summary>
|
|
/// 轨迹推送
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "轨迹推送")]
|
|
[Route("/Track/PushConfig")]
|
|
public class TrackPushService : ApplicationService, ISingletonDependency
|
|
{
|
|
private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer;
|
|
private readonly ITrackPushCacheService _trackPushCacheService;
|
|
private readonly ITrackPushConfigRepository _trackPushConfigRepository;
|
|
private readonly IOrderRepository _orderRepository;
|
|
|
|
public TrackPushService(
|
|
IStringLocalizer<TrackLocalizationResource> stringLocalizer,
|
|
ITrackPushConfigRepository trackPushConfigRepository,
|
|
ITrackPushCacheService trackPushCacheService,
|
|
IOrderRepository orderRepository)
|
|
{
|
|
_stringLocalizer = stringLocalizer;
|
|
_trackPushConfigRepository = trackPushConfigRepository;
|
|
_trackPushCacheService = trackPushCacheService;
|
|
_orderRepository = orderRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹推送配置列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("GetPage")]
|
|
public async Task<UnifyPageResultDto<GetTrackPushConfigPageOutputVO>> GetPageAsync([FromBody] KeywordsInputVO input)
|
|
{
|
|
return await _trackPushConfigRepository.GetPageAsync(input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取推送配置类型标签卡列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("GetConfigTags")]
|
|
public async Task<List<TrackPushConfigTagDto>> GetConfigTags([FromBody] GetConfigTagsInputVO inputVo)
|
|
{
|
|
var orderTypes = await _trackPushConfigRepository.GetConfigTags(inputVo);
|
|
if (orderTypes.Count == 0) return new List<TrackPushConfigTagDto>();
|
|
var trackOrderTypes = await _orderRepository.GetTrackOrderTypeDict();
|
|
|
|
return orderTypes.Select(x => new TrackPushConfigTagDto
|
|
{
|
|
Type = x,
|
|
Name = trackOrderTypes[x.ToString()]
|
|
})
|
|
.OrderBy(x => x.Type)
|
|
.ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹推送配置内容列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("GetContentPage")]
|
|
public async Task<UnifyPageResultDto<GetTrackPushContentPageOutputVO>> GetContentPageAsync(
|
|
[FromBody] GetTrackPushContentPageInputVO input)
|
|
{
|
|
return await _trackPushConfigRepository.GetContentPageAsync(input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹推送配置详情
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("GetDetail")]
|
|
public async Task<GetTrackPushConfigDetailOutputVO> GetDetailAsync(int id)
|
|
{
|
|
return await _trackPushConfigRepository.GetDetailAsync(id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹推送配置内容详情
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("GetContentDetail")]
|
|
public async Task<GetTrackPushContentDetailOutputVO> GetContentDetailAsync(int id)
|
|
{
|
|
return await _trackPushConfigRepository.GetContentDetailAsync(id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹推送配置编辑
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Edit")]
|
|
public async Task<bool> EditAsync([FromBody] EditTrackPushConfigInput input)
|
|
{
|
|
if (input.Options != OptionTypeNoNull.删除)
|
|
{
|
|
Expression<Func<TrackPushConfigEntity, bool>> isAnyExp = x =>
|
|
x.SubSystemId == input.SubSystemId && x.CustomId == input.CustomId;
|
|
if (input.Options == OptionTypeNoNull.修改) isAnyExp = isAnyExp.And(x => x.Id != input.Id);
|
|
|
|
if (await _trackPushConfigRepository.IsAnyAsync(isAnyExp))
|
|
throw new BusinessException(message: _stringLocalizer["IsTrackPushConfigAny"]);
|
|
}
|
|
|
|
using var ts = TransactionScopeHelper.Create();
|
|
|
|
switch (input.Options)
|
|
{
|
|
case OptionTypeNoNull.新增:
|
|
var trackPushEntity = ObjectMapper.Map<EditTrackPushConfigInput, TrackPushConfigEntity>(input);
|
|
|
|
await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity);
|
|
await _trackPushCacheService.SetPushContentConfigsAsync(trackPushEntity.SubSystemId,
|
|
trackPushEntity.CustomId);
|
|
break;
|
|
|
|
case OptionTypeNoNull.修改:
|
|
var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
|
|
throw new BusinessException(message: _stringLocalizer["NotFindData"]);
|
|
|
|
ObjectMapper.Map(input, oldTrackPushEntity);
|
|
await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity);
|
|
await _trackPushCacheService.SetPushContentConfigsAsync(oldTrackPushEntity.SubSystemId,
|
|
oldTrackPushEntity.CustomId);
|
|
break;
|
|
|
|
case OptionTypeNoNull.删除:
|
|
var entity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
|
|
throw new BusinessException(message: _stringLocalizer["NotFindData"]);
|
|
|
|
await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id);
|
|
await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id);
|
|
await _trackPushCacheService.SetPushContentConfigsAsync(entity.SubSystemId, entity.CustomId);
|
|
break;
|
|
|
|
default:
|
|
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,
|
|
nameof(EditTrackPushConfigInput.Options)]);
|
|
}
|
|
|
|
ts.Complete();
|
|
return true;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取服务商code根据客户id
|
|
/// </summary>
|
|
/// <param name="customerId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("GetServiceCodeByCustomerId")]
|
|
public async Task<string?> GetServiceCodeByCustomerId(int customerId)
|
|
{
|
|
return await _trackPushConfigRepository.GetServiceCodeByCustomerIdAsync(customerId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹推送配置内容编辑
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("EditContent")]
|
|
public async Task<bool> EditContentAsync([FromBody] EditTrackPushContentInput input)
|
|
{
|
|
if (input.Options != OptionTypeNoNull.删除)
|
|
{
|
|
Expression<Func<TrackPushContentConfigEntity, bool>> isContentAnyExp = x =>
|
|
x.TrackPushConfigId == input.TrackPushConfigId
|
|
&& x.OrderNoType == input.OrderNoType;
|
|
if (input.Options == OptionTypeNoNull.修改) isContentAnyExp = isContentAnyExp.And(x => x.Id != input.Id);
|
|
|
|
if (await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
|
|
x.TrackContentId == input.TrackContentId)))
|
|
throw new BusinessException(message: _stringLocalizer["IsTrackPushContentAny"]);
|
|
if (!input.TrackContentCodeValue.IsNullOrWhiteSpace() &&
|
|
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
|
|
x.TrackContentCodeValue == input.TrackContentCodeValue)))
|
|
throw new BusinessException(message: _stringLocalizer["IsTrackPushContentCodeValueAny"]);
|
|
if (!input.TrackStatusValue.IsNullOrWhiteSpace() &&
|
|
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
|
|
x.TrackStatusValue == input.TrackStatusValue)))
|
|
throw new BusinessException(message: _stringLocalizer["IsTrackPushContentStatusValueAny"]);
|
|
if (!input.TrackContentValue.IsNullOrWhiteSpace() &&
|
|
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
|
|
x.TrackContentValue == input.TrackContentValue)))
|
|
throw new BusinessException(message: _stringLocalizer["IsTrackPushContentValueAny"]);
|
|
if (!input.TrackEnContentValue.IsNullOrWhiteSpace() &&
|
|
await _trackPushConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
|
|
x.TrackEnContentValue == input.TrackEnContentValue)))
|
|
throw new BusinessException(message: _stringLocalizer["IsTrackPushEnContentValueAny"]);
|
|
}
|
|
|
|
var trackPushConfigId = input.TrackPushConfigId;
|
|
|
|
using var ts = TransactionScopeHelper.Create();
|
|
|
|
switch (input.Options)
|
|
{
|
|
case OptionTypeNoNull.新增:
|
|
{
|
|
var maxSort = await _trackPushConfigRepository.ContentMaxAsync(x => x.Sort, x =>
|
|
x.OrderNoType == input.OrderNoType
|
|
&& x.TrackPushConfigId == input.TrackPushConfigId
|
|
);
|
|
|
|
var entity = ObjectMapper.Map<EditTrackPushContentInput, TrackPushContentConfigEntity>(input);
|
|
entity.Sort = maxSort + 1;
|
|
await _trackPushConfigRepository.InsertContentAsync(entity);
|
|
break;
|
|
}
|
|
|
|
case OptionTypeNoNull.修改:
|
|
{
|
|
var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
|
|
throw new BusinessException(message: _stringLocalizer["NotFindData"]);
|
|
|
|
ObjectMapper.Map(input, entity);
|
|
await _trackPushConfigRepository.UpdateContentAsync(entity);
|
|
break;
|
|
}
|
|
|
|
case OptionTypeNoNull.删除:
|
|
{
|
|
var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
|
|
throw new BusinessException(message: _stringLocalizer["NotFindData"]);
|
|
trackPushConfigId = entity.TrackPushConfigId;
|
|
await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
|
|
await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1, x =>
|
|
x.OrderNoType == entity.OrderNoType
|
|
&& x.TrackPushConfigId == entity.TrackPushConfigId
|
|
&& x.Sort > entity.Sort
|
|
);
|
|
break;
|
|
}
|
|
|
|
default:
|
|
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,
|
|
nameof(EditTrackPushContentInput.Options)]);
|
|
}
|
|
|
|
var pushConfig = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == trackPushConfigId);
|
|
if (pushConfig != null)
|
|
{
|
|
await _trackPushCacheService.SetPushContentConfigsAsync(pushConfig.SubSystemId, pushConfig.CustomId);
|
|
}
|
|
|
|
ts.Complete();
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹推送配置内容排序
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("SortContent")]
|
|
public async Task<bool> SortContentAsync([FromBody] SortTrackPushContentInput input)
|
|
{
|
|
List<int> ids = input.SortInfo.Select(x => int.Parse(x.Key)).ToList();
|
|
|
|
var trackPushContentEntities = await _trackPushConfigRepository.GetContentListAsync(x => ids.Contains(x.Id));
|
|
|
|
trackPushContentEntities.ForEach(item => { item.Sort = input.SortInfo.Single(x => x.Key == item.Id.ToString()).Value; });
|
|
|
|
if (trackPushContentEntities.Count > 0)
|
|
{
|
|
using var ts = TransactionScopeHelper.Create();
|
|
|
|
await _trackPushConfigRepository.UpdateContentRangeAsync(trackPushContentEntities);
|
|
|
|
var pushConfig =
|
|
await _trackPushConfigRepository.GetFirstAsync(x =>
|
|
x.Id == trackPushContentEntities[0].TrackPushConfigId);
|
|
if (pushConfig != null)
|
|
{
|
|
await _trackPushCacheService.SetPushContentConfigsAsync(pushConfig.SubSystemId, pushConfig.CustomId);
|
|
}
|
|
|
|
ts.Complete();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|