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

View File

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

View File

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