connect: 对接预警编辑

This commit is contained in:
xiaolipro 2024-07-27 17:44:23 +08:00
parent 707a05f911
commit 7454827e0f
4 changed files with 52 additions and 16 deletions

View File

@ -0,0 +1,8 @@
namespace SJZY.Track.Application.Contract.Dtos.Common;
public class IdWithNameDto
{
public int Id { get; set; }
public string Name { get; set; }
}

View File

@ -2,6 +2,7 @@ using System.Dynamic;
using Nest;
using Newtonsoft.Json.Linq;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Track.Application.Contract.Dtos.Common;
using SJZY.Track.Application.Contract.Dtos.Forewarning;
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
using SJZY.Track.Domain.Dtos.Forewarning;
@ -119,7 +120,7 @@ public class ForewarningHelper
case RuleFactorType.LeavePort:
if (value.Type is not JTokenType.String)
{
throw new BusinessException(message: "货物类型只接收字符串");
throw new BusinessException(message: "起运港只接收字符串");
}
rules[row].LeavePort = strValue;
@ -127,7 +128,7 @@ public class ForewarningHelper
case RuleFactorType.ProductCode:
if (value.Type is not JTokenType.String)
{
throw new BusinessException(message: "货物类型只接收字符串");
throw new BusinessException(message: "产品代码只接收字符串");
}
rules[row].ProductCode = strValue;
@ -161,8 +162,9 @@ public class ForewarningHelper
}).ToList();
}
public static EditWarningOutput MapWarningSummary(WarningEntity warning)
public static EditWarningOutput MapWarningSummary(WarningEntity warning, List<IdWithNameDto> statusList)
{
var statusDic = statusList.ToDictionary(x => x.Id, x => x.Name);
return new EditWarningOutput
{
Name = warning.Name,
@ -174,7 +176,9 @@ public class ForewarningHelper
{
Id = x.Id,
StartTrackStatusId = x.StartTrackStatusId,
StartTrackStatus = statusDic.TryGetValue(x.StartTrackStatusId, out var start) ? start : "",
EndTrackStatusId = x.EndTrackStatusId,
EndTrackStatus = statusDic.TryGetValue(x.EndTrackStatusId, out var end) ? end : "",
NotifyUserId = x.NotifyUserId,
}).ToList(),
WarningFactors = warning.WarningFactors.Select(x => new WarningFactorWithIdDto

View File

@ -1,8 +1,11 @@
using System.ComponentModel.DataAnnotations;
using SJZY.Track.Application.Contract.Dtos.Common;
using SJZY.Track.Application.Contract.Dtos.Forewarning;
using SJZY.Track.Application.Helpers;
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
using SJZY.Track.Domain.Dtos.Forewarning;
using SJZY.Track.Domain.Dtos.TrackStatus;
using SJZY.Track.Domain.Queries;
namespace SJZY.Track.Application.Services.ForewarningServices;
@ -17,7 +20,7 @@ public class ForewarningService : ApplicationService
{
_warningRepository = warningRepository;
}
/// <summary>
/// 获取预警分页列表
/// </summary>
@ -29,7 +32,7 @@ public class ForewarningService : ApplicationService
if (!inputVo.KeyWord.IsNullOrEmpty()) inputVo.KeyWord = inputVo.KeyWord!.Trim();
return await _warningRepository.GetWarningPageListAsync(inputVo);
}
/// <summary>
/// 创建预警
/// </summary>
@ -45,21 +48,23 @@ public class ForewarningService : ApplicationService
{
throw new BusinessException(message: "该子系统下的客户已经存在一个同名预警: " + warning.Name);
}
warning.WarningRules = ForewarningHelper.CalcRuleList(input.TrackStatusSpans, input.WarningFactors);
warning.WarningFactors = ForewarningHelper.MapFactorEntities(input.WarningFactors);
warning.WarningNotifies = ForewarningHelper.MapNotifyEntities(input);
await _warningRepository.CreateForewarningAsync(warning);
return true;
}
/// <summary>
/// 编辑预警
/// </summary>
/// <param name="warningId"></param>
/// <param name="statusQuery"></param>
/// <returns></returns>
[HttpPost("EditWarning")]
public async Task<EditWarningOutput> EditWarning(int warningId)
public async Task<EditWarningOutput> EditWarning(int warningId,
[FromServices] IBasicQuery<TrackStatusEntity> statusQuery)
{
var warning = await _warningRepository.GetByIdAsync(warningId);
@ -67,8 +72,15 @@ public class ForewarningService : ApplicationService
{
throw new BusinessException(message: "预警不存在");
}
return ForewarningHelper.MapWarningSummary(warning);
var statusList = await statusQuery.GetListAsync(x => x.SubSystemId == warning.SubSystemId, x =>
new IdWithNameDto
{
Id = x.Id,
Name = x.Status
});
return ForewarningHelper.MapWarningSummary(warning, statusList);
}
/// <summary>
@ -86,7 +98,8 @@ public class ForewarningService : ApplicationService
}
if (await _warningRepository.IsAnyAsync(x =>
x.SubSystemId == warning.SubSystemId && x.CustomerId == warning.CustomerId && x.Id != warning.Id))
x.SubSystemId == warning.SubSystemId && x.CustomerId == warning.CustomerId && x.Id != warning.Id &&
x.Name == input.Name))
{
throw new BusinessException(message: "该子系统下的客户已经存在一个同名预警: " + warning.Name);
}
@ -120,7 +133,7 @@ public class ForewarningService : ApplicationService
{
throw new BusinessException(message: "预警不存在");
}
if (isEnable)
{
if (await _warningRepository.IsAnyAsync(x =>
@ -129,7 +142,7 @@ public class ForewarningService : ApplicationService
throw new BusinessException(message: "该子系统下的客户已经存在一个启用的预警,请先禁用");
}
}
warning.SetEnable(isEnable);
return await _warningRepository.TurnWarningAsync(warning);
@ -142,15 +155,16 @@ public class ForewarningService : ApplicationService
/// <param name="factorQuery"></param>
/// <returns></returns>
[HttpGet("GetWarningRuleList")]
public async Task<List<dynamic>> GetWarningRuleListAsync([Required] int warningId, [FromServices] IBasicQuery<WarningFactorEntity> factorQuery)
public async Task<List<dynamic>> GetWarningRuleListAsync([Required] int warningId,
[FromServices] IBasicQuery<WarningFactorEntity> factorQuery)
{
var factors = await factorQuery.GetListAsync(x => x.WarningId == warningId, x => x.Type);
var rules = await _warningRepository.GetWarningRuleListAsync(warningId);
var dynamicList = ForewarningHelper.DynamicCalcRuleList(rules, factors);
return dynamicList;
}
/// <summary>
/// 修改预警规则时效
/// </summary>

View File

@ -12,6 +12,16 @@ public class WarningNitifyDto
/// </summary>
public int EndTrackStatusId { get; set; }
/// <summary>
/// 起始轨迹状态
/// </summary>
public string StartTrackStatus { get; set; } = null!;
/// <summary>
/// 终止轨迹状态
/// </summary>
public string EndTrackStatus { get; set; } = null!;
/// <summary>
/// 通知人id
/// </summary>