add:预警crud

This commit is contained in:
xiaolipro 2024-07-26 12:59:01 +08:00
parent 9ba1ee660b
commit 061cffc6c3
20 changed files with 530 additions and 202 deletions

View File

@ -0,0 +1,42 @@
using SJZY.Track.Domain.Dtos.Forewarning;
using SJZY.Track.Domain.Enums;
namespace SJZY.Track.Application.Contract.Dtos.Forewarning;
public class CreateWarningInput
{
/// <summary>
/// 模板名称
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// 子系统id
/// </summary>
public int SubSystemId { get; set; }
/// <summary>
/// 客户id
/// </summary>
public int CustomerId { get; set; }
/// <summary>
/// 通知方式
/// </summary>
public NotifyMode NotifyMode { get; set; }
/// <summary>
/// 通知模板
/// </summary>
public string NotifyTemplate { get; set; } = null!;
/// <summary>
/// 轨迹状态跨度列表
/// </summary>
public List<WarningNitifyDto> TrackStatusSpans { get; set; } = new();
/// <summary>
/// 预警因素列表。
/// </summary>
public List<WarningFactorDto> WarningFactors { get; set; } = new();
}

View File

@ -0,0 +1,58 @@
using SJZY.Track.Domain.Dtos.Forewarning;
using SJZY.Track.Domain.Enums;
namespace SJZY.Track.Application.Contract.Dtos.Forewarning;
public class EditWarningOutput
{
/// <summary>
/// 模板名称
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// 子系统id
/// </summary>
public int SubSystemId { get; set; }
/// <summary>
/// 客户id
/// </summary>
public int CustomerId { get; set; }
/// <summary>
/// 通知方式
/// </summary>
public NotifyMode NotifyMode { get; set; }
/// <summary>
/// 通知模板
/// </summary>
public string NotifyTemplate { get; set; } = null!;
/// <summary>
/// 通知列表
/// </summary>
public List<WarningNotifyWithIdDto> TrackStatusSpans { get; set; } = new();
/// <summary>
/// 预警因素列表。
/// </summary>
public List<WarningFactorWithIdDto> WarningFactors { get; set; } = new();
}
public class WarningNotifyWithIdDto: WarningNitifyDto
{
/// <summary>
/// 通知id
/// </summary>
public int Id { get; set; }
}
public class WarningFactorWithIdDto : WarningFactorDto
{
/// <summary>
/// 因素id
/// </summary>
public int Id { get; set; }
}

View File

@ -0,0 +1,45 @@
using SJZY.Track.Domain.Dtos.Forewarning;
using SJZY.Track.Domain.Enums;
namespace SJZY.Track.Application.Contract.Dtos.Forewarning;
public class UpdateWarningInput
{
/// <summary>
/// 预警id
/// </summary>
public int Id { get; set; }
/// <summary>
/// 模板名称
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// 通知方式
/// </summary>
public NotifyMode NotifyMode { get; set; }
/// <summary>
/// 通知模板
/// </summary>
public string NotifyTemplate { get; set; } = null!;
/// <summary>
/// 通知列表
/// </summary>
public List<NotifyDto> Notifies { get; set; } = new();
}
public class NotifyDto
{
/// <summary>
/// 通知id
/// </summary>
public int Id { get; set; }
/// <summary>
/// 通知人id
/// </summary>
public int NotifyUserId { get; set; }
}

View File

@ -1,8 +1,10 @@
using Newtonsoft.Json.Linq;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Track.Application.Contract.Dtos.Forewarning;
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
using SJZY.Track.Domain.Dtos.Forewarning;
using SJZY.Track.Domain.Enums;
using SqlSugar;
namespace SJZY.Track.Application.Helpers;
@ -14,9 +16,14 @@ public class ForewarningHelper
/// <param name="statusSpans"></param>
/// <param name="factors"></param>
/// <returns></returns>
public static List<WarningRuleEntity> CalcRuleList(List<TrackStatusSpanDto> statusSpans,
public static List<WarningRuleEntity> CalcRuleList(List<WarningNitifyDto> statusSpans,
List<WarningFactorDto> factors)
{
if (statusSpans.Count == 0 || factors.Count == 0)
{
throw new BusinessException(message: "轨迹状态区间或因素列表为空");
}
var len = statusSpans.Count * factors.Select(f => f.FactorValue.Count).Aggregate((pre, cur) => pre * cur);
if (len == 0)
{
@ -32,19 +39,18 @@ public class ForewarningHelper
foreach (var factor in factors)
{
var factorValueCount = factor.FactorValue.Count;
repeat /= factor.FactorValue.Count; // repeat梯度下降,与times成反比关系
for (int time = 0; time < len / repeat / factorValueCount; time++)
{
FillFactor(factor, rules, repeat, time);
}
// repeat梯度下降,与times成反比关系
repeat /= factor.FactorValue.Count;
var times = len / repeat / factorValueCount;
FillFactor(factor, rules, repeat, times);
}
return rules;
}
private static void FillStatus(List<TrackStatusSpanDto> statusSpans, List<WarningRuleEntity> rules, int repeat)
private static void FillStatus(List<WarningNitifyDto> statusSpans, List<WarningRuleEntity> rules, int repeat)
{
for (var i = 0; i < statusSpans.Count; i++)
{
@ -59,70 +65,77 @@ public class ForewarningHelper
}
}
private static void FillFactor(WarningFactorDto factor, List<WarningRuleEntity> rules, int repeat, int time)
private static void FillFactor(WarningFactorDto factor, List<WarningRuleEntity> rules, int repeat, int times)
{
for (var i = 0; i < factor.FactorValue.Count * time; i++)
var row = 0;
for (var i = 0; i < times; i++)
{
for (var j = 0; j < repeat; j++)
foreach (var value in factor.FactorValue)
{
var row = i * repeat + j;
var value = factor.FactorValue[row];
var strValue = value.ToString();
switch (factor.FactorType)
if (strValue.IsNullOrEmpty())
{
case RuleFactorType.CargoType:
if (value.Type is not JTokenType.String)
{
throw new BusinessException(message: "货物类型只接收字符串");
}
throw new BusinessException(message: "因素值不能为空");
}
rules[row].CargoType = strValue;
break;
case RuleFactorType.Months:
foreach (var item in strValue.Split("/"))
{
if (!int.TryParse(item, out var month) || month < 1 || month > 12)
for (var j = 0; j < repeat; j++, row++)
{
switch (factor.FactorType)
{
case RuleFactorType.CargoType:
if (value.Type is not JTokenType.String)
{
throw new BusinessException(message: "请输入合法的月份,多个月份请以'/'连接");
throw new BusinessException(message: "货物类型只接收字符串");
}
}
rules[row].Months = strValue;
break;
case RuleFactorType.Areas:
if (value.Type is not JTokenType.Integer)
{
throw new BusinessException(message: "分区请传id");
}
rules[row].CargoType = strValue;
break;
case RuleFactorType.Months:
foreach (var item in strValue.Split("/"))
{
if (!int.TryParse(item, out var month) || month < 1 || month > 12)
{
throw new BusinessException(message: "请输入合法的月份,多个月份请以'/'连接");
}
}
rules[row].AreaId = int.Parse(strValue);
break;
case RuleFactorType.IsTransit:
if (value.Type is not JTokenType.Boolean)
{
throw new BusinessException(message: "是否中转只接收bool类型");
}
rules[row].Months = strValue;
break;
case RuleFactorType.Areas:
if (value.Type is not JTokenType.Integer)
{
throw new BusinessException(message: "分区请传id");
}
rules[row].IsTransit = bool.Parse(strValue);
break;
case RuleFactorType.LeavePort:
if (value.Type is not JTokenType.String)
{
throw new BusinessException(message: "货物类型只接收字符串");
}
rules[row].AreaId = int.Parse(strValue);
break;
case RuleFactorType.IsTransit:
if (value.Type is not JTokenType.Boolean)
{
throw new BusinessException(message: "是否中转只接收bool类型");
}
rules[row].LeavePort = strValue;
break;
case RuleFactorType.ProductCode:
if (value.Type is not JTokenType.String)
{
throw new BusinessException(message: "货物类型只接收字符串");
}
rules[row].IsTransit = bool.Parse(strValue);
break;
case RuleFactorType.LeavePort:
if (value.Type is not JTokenType.String)
{
throw new BusinessException(message: "货物类型只接收字符串");
}
rules[row].ProductCode = strValue;
break;
default:
throw new BusinessException(message: $"不支持的因素:{factor.FactorType}");
rules[row].LeavePort = strValue;
break;
case RuleFactorType.ProductCode:
if (value.Type is not JTokenType.String)
{
throw new BusinessException(message: "货物类型只接收字符串");
}
rules[row].ProductCode = strValue;
break;
default:
throw new BusinessException(message: $"不支持的因素:{factor.FactorType}");
}
}
}
}
@ -136,4 +149,41 @@ public class ForewarningHelper
Value = x.FactorValue.ToJson()
}).ToList();
}
public static List<WarningNotifyEntity> MapNotifyEntities(CreateWarningInput input)
{
return input.TrackStatusSpans.Select(x => new WarningNotifyEntity
{
StartTrackStatusId = x.StartTrackStatusId,
EndTrackStatusId = x.EndTrackStatusId,
NotifyMode = input.NotifyMode,
NotifyTemplate = input.NotifyTemplate,
NotifyUserId = x.NotifyUserId
}).ToList();
}
public static EditWarningOutput MapWarningSummary(WarningEntity warning)
{
return new EditWarningOutput
{
Name = warning.Name,
SubSystemId = warning.SubSystemId,
CustomerId = warning.CustomerId,
NotifyMode = warning.WarningNotifies.First().NotifyMode,
NotifyTemplate = warning.WarningNotifies.First().NotifyTemplate,
TrackStatusSpans = warning.WarningNotifies.Select(x => new WarningNotifyWithIdDto
{
Id = x.Id,
StartTrackStatusId = x.StartTrackStatusId,
EndTrackStatusId = x.EndTrackStatusId,
NotifyUserId = x.NotifyUserId,
}).ToList(),
WarningFactors = warning.WarningFactors.Select(x => new WarningFactorWithIdDto
{
Id = x.Id,
FactorType = x.Type,
FactorValue = JArray.Parse(x.Value),
}).ToList()
};
}
}

View File

@ -16,7 +16,19 @@ public class ForewarningService : ApplicationService
{
_warningRepository = warningRepository;
}
/// <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>
@ -28,10 +40,106 @@ public class ForewarningService : ApplicationService
var warning = ObjectMapper.Map<CreateWarningInput, WarningEntity>(input);
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>
/// <returns></returns>
[HttpPost("EditWarning")]
public async Task<EditWarningOutput> EditWarning(int warningId)
{
var warning = await _warningRepository.GetByIdAsync(warningId);
if (warning == null)
{
throw new BusinessException(message: "预警不存在");
}
return ForewarningHelper.MapWarningSummary(warning);
}
/// <summary>
/// 更新预警
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("UpdateWarning")]
public async Task<bool> UpdateWarning(UpdateWarningInput input)
{
var warning = await _warningRepository.GetFirstAsync(x => x.Id == input.Id);
if (warning == null)
{
throw new BusinessException(message: "预警不存在");
}
if (await _warningRepository.IsAnyAsync(x =>
x.SubSystemId == warning.SubSystemId && x.CustomerId == warning.CustomerId && x.Id != warning.Id))
{
throw new BusinessException(message: "该子系统下的客户已经存在一个同名预警: " + warning.Name);
}
warning.SetName(input.Name);
warning.WarningNotifies = input.Notifies.Select(x => new WarningNotifyEntity
{
Id = x.Id,
NotifyMode = input.NotifyMode,
NotifyTemplate = input.NotifyTemplate,
NotifyUserId = x.NotifyUserId
}).ToList();
await _warningRepository.UpdateForewarningAsync(warning);
return true;
}
/// <summary>
/// 启用or禁用预警
/// </summary>
/// <param name="warningId">预警id</param>
/// <param name="isEnable">是否启用</param>
/// <returns></returns>
[HttpPost("TurnWarning")]
public async Task<bool> TurnWarning(int warningId, bool isEnable)
{
var warning = await _warningRepository.GetFirstAsync(x => x.Id == warningId);
if (warning == null)
{
throw new BusinessException(message: "预警不存在");
}
if (isEnable)
{
if (await _warningRepository.IsAnyAsync(x =>
x.SubSystemId == warning.SubSystemId && x.CustomerId == warning.CustomerId && x.IsEnable))
{
throw new BusinessException(message: "该子系统下的客户已经存在一个启用的预警,请先禁用");
}
}
warning.SetEnable(isEnable);
return await _warningRepository.TurnWarningAsync(warning);
}
/// <summary>
/// 查询预警规则列表
/// </summary>
/// <param name="warningId">预警规则id</param>
/// <returns></returns>
[HttpGet("GetWarningRuleList")]
public async Task<List<WarningRuleVo>> GetWarningRuleListAsync([Required] int warningId)
{
var rules = await _warningRepository.GetWarningRuleListAsync(warningId);
return rules;
}
/// <summary>
/// 修改预警规则时效
/// </summary>
@ -54,36 +162,4 @@ public class ForewarningService : ApplicationService
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()
{
}
}

View File

@ -1,4 +1,5 @@
using FluentValidation;
using SJZY.Track.Application.Contract.Dtos.Forewarning;
using SJZY.Track.Domain.Dtos.Forewarning;
namespace SJZY.Track.Application.Validations.Forewarning;

View File

@ -3,7 +3,7 @@ using SJZY.Track.Domain.Dtos.Forewarning;
namespace SJZY.Track.Application.Validations.Forewarning;
public class RuleTrackStateDtoValidator : AbstractValidator<TrackStatusSpanDto>
public class RuleTrackStateDtoValidator : AbstractValidator<WarningNitifyDto>
{
public RuleTrackStateDtoValidator()
{

View File

@ -5,18 +5,11 @@ namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
public interface IWarningRepository : IBasicRepository<WarningEntity>
{
/// <summary>
/// 创建预警
/// 创建预警,include factors, notifies, rules
/// </summary>
/// <param name="warning"></param>
/// <returns></returns>
Task<int> CreateForewarningAsync(WarningEntity warning);
/// <summary>
/// 修改预警
/// </summary>
/// <param name="warning"></param>
/// <returns></returns>
Task<int> UpdateForewarningAsync(WarningEntity warning);
/// <summary>
/// 复制预警
@ -37,7 +30,14 @@ public interface IWarningRepository : IBasicRepository<WarningEntity>
/// </summary>
/// <param name="warningId">预警id</param>
/// <returns></returns>
Task<List<WarningRuleOutput>> GetWarningRuleListAsync(int warningId);
Task<List<WarningRuleVo>> GetWarningRuleListAsync(int warningId);
/// <summary>
/// 修改预警
/// </summary>
/// <param name="warning"></param>
/// <returns></returns>
Task UpdateForewarningAsync(WarningEntity warning);
/// <summary>
/// 修改预警时效
@ -45,4 +45,18 @@ public interface IWarningRepository : IBasicRepository<WarningEntity>
/// <param name="inputItems"></param>
/// <returns></returns>
Task<int> ModifyTimeSpansAsync(List<WarningRuleEntity> inputItems);
/// <summary>
/// 启用预警
/// </summary>
/// <param name="warning"></param>
/// <returns></returns>
Task<bool> TurnWarningAsync(WarningEntity warning);
/// <summary>
/// 获取预警,include factors, notifies
/// </summary>
/// <param name="warningId"></param>
/// <returns></returns>
Task<WarningEntity?> GetByIdAsync(int warningId);
}

View File

@ -1,3 +1,6 @@
using SJZY.Track.Domain.Enums;
using Volo.Abp;
namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
[SugarTable("t_warning")]
@ -21,12 +24,6 @@ public class WarningEntity: IFullAuditedBasicEntitys, IAggregateRoot
[SugarColumn(ColumnName = "CustomerId")]
public int CustomerId { get; set; }
/// <summary>
/// 客户
/// </summary>
[SugarColumn(ColumnName = "CustomerName", Length = 255)]
public string CustomerName { get; set; } = null!;
/// <summary>
/// 规则模板名称,KPI名称
/// </summary>
@ -50,4 +47,25 @@ public class WarningEntity: IFullAuditedBasicEntitys, IAggregateRoot
/// </summary>
[SugarColumn(IsIgnore = true)]
public List<WarningFactorEntity> WarningFactors { get; set; } = new();
/// <summary>
/// 预警通知
/// </summary>
[SugarColumn(IsIgnore = true)]
public List<WarningNotifyEntity> WarningNotifies { get; set; } = new();
public void SetName(string name)
{
Name = name;
}
public void SetEnable(bool isEnable)
{
if (IsEnable == isEnable)
{
throw new BusinessException(message: $"预警已经是{(isEnable ? "启用" : "禁用")}状态");
}
IsEnable = isEnable;
}
}

View File

@ -2,7 +2,7 @@ using SJZY.Track.Domain.Enums;
namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
public class WarningFactorEntity : IFullAuditedBasicEntitys
public class WarningFactorEntity : IFullAuditedBasicEntitys, IEntity
{
/// <summary>
/// 自增主键

View File

@ -0,0 +1,48 @@
using SJZY.Track.Domain.Enums;
namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
public class WarningNotifyEntity : IFullAuditedBasicEntitys, IEntity
{
/// <summary>
/// 自增主键
/// </summary>
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 预警id
/// </summary>
[SugarColumn(ColumnName = "WarningId")]
public int WarningId { get; set; }
/// <summary>
/// 起始轨迹状态id
/// </summary>
[SugarColumn(ColumnName = "StartTrackStatusId", IsNullable = false)]
public int StartTrackStatusId { get; set; }
/// <summary>
/// 终止轨迹状态id
/// </summary>
[SugarColumn(ColumnName = "EndTrackStatusId", IsNullable = false)]
public int EndTrackStatusId { get; set; }
/// <summary>
/// 通知方式
/// </summary>
[SugarColumn(ColumnName = "NotifyMode")]
public NotifyMode NotifyMode { get; set; }
/// <summary>
/// 通知模板
/// </summary>
[SugarColumn(ColumnName = "NotifyTemplate", Length = 256)]
public string NotifyTemplate { get; set; } = null!;
/// <summary>
/// 通知人
/// </summary>
[SugarColumn(ColumnName = "NotifyUserId")]
public int NotifyUserId { get; set; }
}

View File

@ -1,7 +1,7 @@
namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
[SugarTable("t_warning_rule")]
public class WarningRuleEntity : IFullAuditedBasicEntitys
public class WarningRuleEntity : IFullAuditedBasicEntitys, IEntity
{
/// <summary>
/// 自增主键

View File

@ -1,48 +0,0 @@
using System.ComponentModel.DataAnnotations;
using SJZY.Track.Domain.Enums;
namespace SJZY.Track.Domain.Dtos.Forewarning
{
public class CreateWarningInput
{
/// <summary>
/// 模板名称
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// 子系统id
/// </summary>
public int SubSystemId { get; set; }
/// <summary>
/// 客户id
/// </summary>
public int CustomerId { get; set; }
/// <summary>
/// 客户名称
/// </summary>
public string CustomerName { get; set; } = null!;
/// <summary>
/// 通知方式
/// </summary>
public NotifyMode NotifyMode { get; set; }
/// <summary>
/// 通知模板
/// </summary>
public string NotifyTemplate { get; set; } = null!;
/// <summary>
/// 轨迹状态跨度列表
/// </summary>
public List<TrackStatusSpanDto> TrackStatusSpans { get; set; } = new();
/// <summary>
/// 预警因素列表。
/// </summary>
public List<WarningFactorDto> WarningFactors { get; set; } = new();
}
}

View File

@ -1,6 +1,6 @@
namespace SJZY.Track.Domain.Dtos.Forewarning;
public class TrackStatusSpanDto
public class WarningNitifyDto
{
/// <summary>
/// 起始轨迹状态id

View File

@ -1,6 +1,6 @@
namespace SJZY.Track.Domain.Dtos.Forewarning;
public class WarningRuleOutput
public class WarningRuleVo
{
/// <summary>
/// 自增主键
@ -45,7 +45,7 @@ public class WarningRuleOutput
/// <summary>
/// 区域
/// </summary>
public int? AreaId { get; set; }
public string? Area { get; set; }
/// <summary>
/// 是否中转

View File

@ -1,4 +1,4 @@
namespace SJZY.Track.Repository.VData.Entitys;
namespace SJZY.Track.Domain.VEntities;
/// <summary>
/// 外部主体

View File

@ -20,21 +20,20 @@ public class DataBaseContext
//新增
if (entityInfo.OperationType == DataFilterType.InsertByObject)
{
var time = DateTime.Now;
var userId = CurrentUserRequest.CurrentUser.UserId;
if (entityInfo.PropertyName == nameof(ICreateBaicEntity.CreateTime))
entityInfo.SetValue(DateTime.Now);
if (entityInfo.PropertyName == nameof(ICreateBaicEntity.CreateUserId))
entityInfo.SetValue(time);
else if (entityInfo.PropertyName == nameof(IUpdateBasicEntity.UpdateTime))
entityInfo.SetValue(time);
else if (entityInfo.PropertyName == nameof(ICreateBaicEntity.CreateUserId))
{
if (oldValue == null || (int)oldValue == 0)
{
try
{
entityInfo.SetValue(CurrentUserRequest.CurrentUser?.UserId);
}
catch
{
}
}
//entityInfo.SetValue(CurrentUserRequest.CurrentUser.UserId);
entityInfo.SetValue(userId);
}
else if (entityInfo.PropertyName == nameof(IUpdateBasicEntity.UpdateUserId))
{
entityInfo.SetValue(userId);
}
}
//修改
@ -44,17 +43,7 @@ public class DataBaseContext
entityInfo.SetValue(DateTime.Now);
else if (entityInfo.PropertyName == nameof(IUpdateBasicEntity.UpdateUserId))
{
if (oldValue == null || (int)oldValue == 1)
{
try
{
entityInfo.SetValue(CurrentUserRequest.CurrentUser.UserId);
}
catch
{
}
}
//entityInfo.SetValue(CurrentUserRequest.CurrentUser.UserId);
entityInfo.SetValue(CurrentUserRequest.CurrentUser.UserId);
}
//删除
else if (entityInfo.PropertyName == nameof(IDeleteBasicEntity.IsDeleted))

View File

@ -4,7 +4,6 @@ using SJZY.Track.Domain.Dtos.Order;
using SJZY.Track.Domain.Enums;
using SJZY.Track.Domain.Queries;
using SJZY.Track.Domain.VEntities;
using SJZY.Track.Repository.VData.Entitys;
namespace SJZY.Track.Repository.Queries;

View File

@ -6,7 +6,6 @@ using SJZY.Track.Domain.Dtos.Common;
using SJZY.Track.Domain.Dtos.TrackPush;
using SJZY.Track.Domain.Enums;
using SJZY.Track.Domain.VEntities;
using SJZY.Track.Repository.VData.Entitys;
namespace SJZY.Track.Repository.Repositories;

View File

@ -1,5 +1,6 @@
using SJZY.Track.Domain;
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
using SJZY.Track.Domain.Aggregates.KPIAreaAggregate;
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
using SJZY.Track.Domain.Dtos.Forewarning;
using SJZY.Track.Domain.VEntities;
@ -13,20 +14,17 @@ public class WarningRepository : BasicRepository<WarningEntity>, IWarningReposit
using var tran = TransactionHelper.GetReadCommitted();
var ruleId = await InsertReturnIdentityAsync(warning);
warning.WarningRules.ForEach(x => x.WarningId = ruleId);
warning.WarningNotifies.ForEach(x => x.WarningId = ruleId);
warning.WarningFactors.ForEach(x => x.WarningId = ruleId);
warning.WarningRules.ForEach(x => x.WarningId = ruleId);
await Context.Insertable(warning.WarningRules).ExecuteCommandAsync();
await Context.Insertable(warning.WarningFactors).ExecuteCommandAsync();
await Context.Insertable(warning.WarningNotifies).ExecuteCommandAsync();
await Context.Insertable(warning.WarningRules).ExecuteCommandAsync();
tran.Complete();
return ruleId;
}
public Task<int> UpdateForewarningAsync(WarningEntity warning)
{
throw new NotImplementedException();
}
public Task CopyForewarning(int warningId)
{
throw new NotImplementedException();
@ -36,40 +34,79 @@ public class WarningRepository : BasicRepository<WarningEntity>, IWarningReposit
{
var query = Context.Queryable<WarningEntity>()
.LeftJoin<VSystemEntity>((a, b) => a.SubSystemId == b.Id)
.LeftJoin<VExternalSubjectEntity>((a, b, c) => a.CustomerId == c.Id)
.WhereIF(input.SystemId.HasValue, (a, b) => a.SubSystemId == input.SystemId)
.WhereIF(!string.IsNullOrEmpty(input.KeyWord), a => a.CustomerName.Contains(input.KeyWord!) || a.Name.Contains(input.KeyWord!))
.WhereIF(!string.IsNullOrEmpty(input.KeyWord),
(a, b, c) => a.Name.Contains(input.KeyWord!) || c.Name.Contains(input.KeyWord!))
.OrderBy(a => a.UpdateTime, OrderByType.Desc);
return query
.Select((a, b) => new WarningPageOutput
.Select((a, b, c) => new WarningPageOutput
{
Id = a.Id,
SubSystem = b.CnName,
Custom = a.CustomerName,
Custom = c.Name,
Name = a.Name,
UpdateTime = a.UpdateTime
})
.ToPagedListAsync(input.PageIndex, input.PageSize);
}
public async Task<List<WarningRuleOutput>> GetWarningRuleListAsync(int warningId)
public async Task<List<WarningRuleVo>> GetWarningRuleListAsync(int warningId)
{
return await Context.Queryable<WarningRuleEntity>()
.LeftJoin<TrackStatusEntity>((a, b) => a.StartTrackStatusId == b.Id)
.LeftJoin<TrackStatusEntity>((a, b, c) => a.EndTrackStatusId == c.Id)
.LeftJoin<RuleAreaEntity>((a, b, c, d) => a.AreaId == d.Id)
.Where(a => a.WarningId == warningId)
.Select((a, b, c) => new WarningRuleOutput
.Select((a, b, c, d) => new WarningRuleVo
{
StartTrackStatus = b.Status,
EndTrackStatus = c.Status,
Area = d.Name
}, true)
.ToListAsync();
}
public async Task UpdateForewarningAsync(WarningEntity warning)
{
using var tran = TransactionHelper.GetReadCommitted();
await Context.Updateable(warning).ExecuteCommandAsync();
await Context.Updateable(warning.WarningNotifies)
.UpdateColumns(x => new { x.NotifyMode, x.NotifyTemplate, x.NotifyUserId, x.UpdateTime, x.UpdateUserId })
.ExecuteCommandAsync();
tran.Complete();
}
public async Task<int> ModifyTimeSpansAsync(List<WarningRuleEntity> rules)
{
return await Context.Updateable(rules)
.UpdateColumns(x => new { x.TotalTimeSpan, x.WarnTimeSpan, x.WarnCount })
.UpdateColumns(x => new { x.TotalTimeSpan, x.WarnTimeSpan, x.WarnCount, x.UpdateTime, x.UpdateUserId })
.ExecuteCommandAsync();
}
public async Task<bool> TurnWarningAsync(WarningEntity warning)
{
return await Context.Updateable(warning)
.UpdateColumns(x => new { x.IsEnable, x.UpdateTime, x.UpdateUserId })
.ExecuteCommandAsync() > 0;
}
public async Task<WarningEntity?> GetByIdAsync(int warningId)
{
var warning = await GetFirstAsync(x => x.Id == warningId);
if (warning == null) return null;
warning.WarningFactors = await Context.Queryable<WarningFactorEntity>()
.Where(x => x.WarningId == warningId)
.ToListAsync();
warning.WarningNotifies = await Context.Queryable<WarningNotifyEntity>()
.Where(x => x.WarningId == warningId)
.ToListAsync();
return warning;
}
}