89 lines
2.9 KiB
C#
89 lines
2.9 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using SJZY.Track.Application.Contract.Dtos.Forewarning;
|
|
using SJZY.Track.Application.Helpers;
|
|
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
|
|
using SJZY.Track.Domain.Dtos.Forewarning;
|
|
|
|
namespace SJZY.Track.Application.Services.ForewarningServices;
|
|
|
|
[ApiExplorerSettings(GroupName = "预警服务")]
|
|
[Route("/ForewarningService")]
|
|
public class ForewarningService : ApplicationService
|
|
{
|
|
private readonly IWarningRepository _warningRepository;
|
|
|
|
public ForewarningService(IWarningRepository warningRepository)
|
|
{
|
|
_warningRepository = warningRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建预警
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("CreateWarning")]
|
|
public async Task<bool> CreateWarning(CreateWarningInput input)
|
|
{
|
|
var warning = ObjectMapper.Map<CreateWarningInput, WarningEntity>(input);
|
|
warning.WarningRules = ForewarningHelper.CalcRuleList(input.TrackStatusSpans, input.WarningFactors);
|
|
warning.WarningFactors = ForewarningHelper.MapFactorEntities(input.WarningFactors);
|
|
await _warningRepository.CreateForewarningAsync(warning);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改预警规则时效
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="BusinessException"></exception>
|
|
[HttpPost("ModifyTimeSpans")]
|
|
public async Task<bool> ModifyTimeSpans(ModifyTimeSpanInput input)
|
|
{
|
|
if (!await _warningRepository.IsAnyAsync(x => x.Id == input.WarningId))
|
|
{
|
|
throw new BusinessException(message: "预警不存在");
|
|
}
|
|
|
|
if (input.Items.IsNullOrEmpty()) return false;
|
|
|
|
var warningRules = ObjectMapper.Map<List<WarningTimeSpanDto>, List<WarningRuleEntity>>(input.Items);
|
|
|
|
await _warningRepository.ModifyTimeSpansAsync(warningRules);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取预警分页列表
|
|
/// </summary>
|
|
/// <param name="inputVo"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("GetWarningPageList")]
|
|
public async Task<UnifyPageResultDto<WarningPageOutput>> GetWarningPageList(GetWarningPageInputVo inputVo)
|
|
{
|
|
if (!inputVo.KeyWord.IsNullOrEmpty()) inputVo.KeyWord = inputVo.KeyWord!.Trim();
|
|
return await _warningRepository.GetWarningPageListAsync(inputVo);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询预警规则列表
|
|
/// </summary>
|
|
/// <param name="warningId">预警规则id</param>
|
|
/// <returns></returns>
|
|
[HttpGet("GetWarningRuleList")]
|
|
public async Task<List<WarningRuleOutput>> GetWarningRuleListAsync([Required] int warningId)
|
|
{
|
|
return await _warningRepository.GetWarningRuleListAsync(warningId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送预警通知
|
|
/// </summary>
|
|
[HttpPost("SendForewarningNotification")]
|
|
public void SendForewarningNotification()
|
|
{
|
|
}
|
|
} |