2025-10-30 12:29:31 +08:00
|
|
|
|
using Abp.Auditing;
|
|
|
|
|
|
using Abp.Domain.Repositories;
|
|
|
|
|
|
using Abp.Domain.Uow;
|
|
|
|
|
|
using Abp.EntityFrameworkCore.Repositories;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2025-11-18 16:28:29 +08:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2025-10-21 09:59:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2025-11-18 16:28:29 +08:00
|
|
|
|
using ToolLibrary;
|
2025-10-21 09:59:22 +08:00
|
|
|
|
using ToolLibrary.LogHelper;
|
|
|
|
|
|
using YunDa.SOMS.Application.Core;
|
2025-11-18 16:28:29 +08:00
|
|
|
|
using YunDa.SOMS.Application.Core.Configuration;
|
2025-10-21 09:59:22 +08:00
|
|
|
|
using YunDa.SOMS.Application.Core.Session;
|
|
|
|
|
|
using YunDa.SOMS.Application.Core.SwaggerHelper;
|
|
|
|
|
|
using YunDa.SOMS.DataTransferObject;
|
2025-10-30 12:29:31 +08:00
|
|
|
|
using YunDa.SOMS.DataTransferObject.Account;
|
2025-10-21 09:59:22 +08:00
|
|
|
|
using YunDa.SOMS.DataTransferObject.DataMonitoring.SecondaryCircuitInspection;
|
2025-10-30 12:29:31 +08:00
|
|
|
|
using YunDa.SOMS.DataTransferObject.DataMonitoring.SecondaryCircuitInspection.Configurations;
|
2025-11-18 16:28:29 +08:00
|
|
|
|
using YunDa.SOMS.DataTransferObject.DataMonitoring.SecondaryCircuitInspection.Results;
|
2025-10-21 09:59:22 +08:00
|
|
|
|
using YunDa.SOMS.DataTransferObject.DataMonitoring.TelemeteringConfigurationDto;
|
|
|
|
|
|
using YunDa.SOMS.DataTransferObject.DataMonitoring.TelesignalisationConfigurationDto;
|
|
|
|
|
|
using YunDa.SOMS.DataTransferObject.GeneralInformation.EquipmentLiveDataDto;
|
2025-11-18 16:28:29 +08:00
|
|
|
|
using YunDa.SOMS.Entities.DataMonitoring;
|
2025-10-26 12:34:48 +08:00
|
|
|
|
using YunDa.SOMS.Entities.DataMonitoring.SecondaryCircuitInspection;
|
2025-11-18 16:28:29 +08:00
|
|
|
|
using YunDa.SOMS.Entities.GeneralInformation;
|
2025-10-30 12:29:31 +08:00
|
|
|
|
using YunDa.SOMS.Redis.Repositories;
|
2025-11-19 10:19:16 +08:00
|
|
|
|
using YunDa.SOMS.Application.DataMonitoring.SecondaryCircuitInspection.Test;
|
2025-10-21 09:59:22 +08:00
|
|
|
|
|
|
|
|
|
|
namespace YunDa.SOMS.Application.DataMonitoring.SecondaryCircuitInspection
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 二次回路事件驱动配置应用服务实现
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Description("二次回路事件驱动配置管理服务")]
|
|
|
|
|
|
public class SecondaryCircuitEventDrivenConfigAppService : SOMSAppServiceBase, ISecondaryCircuitEventDrivenConfigAppService
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IRepository<SecondaryCircuitEventDrivenConfig, Guid> _eventDrivenConfigRepository;
|
|
|
|
|
|
private readonly IRepository<SecondaryCircuitInspectionItem, Guid> _inspectionItemRepository;
|
|
|
|
|
|
private readonly IRepository<SecondaryCircuitInspectionEventItem, Guid> _inspectionEventItemRepository;
|
|
|
|
|
|
private readonly IRepository<SecondaryCircuitInspectionTelemetryConfig, Guid> _telemetryConfigRepository;
|
|
|
|
|
|
private readonly IRepository<SecondaryCircuitInspectionTelesignalConfig, Guid> _telesignalConfigRepository;
|
|
|
|
|
|
private readonly IRedisRepository<TelemeteringModel, string> _telemeteringRedisRepository;
|
|
|
|
|
|
private readonly IRedisRepository<TelesignalisationModel, string> _telesignalisationRedisRepository;
|
2025-11-18 16:28:29 +08:00
|
|
|
|
private readonly IRepository<EquipmentInfo, Guid> _equipmentInfoRepository;
|
2025-10-21 09:59:22 +08:00
|
|
|
|
private LoginUserOutput _currentUser = null;
|
|
|
|
|
|
private IUnitOfWorkManager _unitOfWorkManager = null;
|
2025-11-18 16:28:29 +08:00
|
|
|
|
private string _ISMSGateWayIp = "http://127.0.0.1:38094";
|
2025-10-21 09:59:22 +08:00
|
|
|
|
|
2025-11-19 10:19:16 +08:00
|
|
|
|
// 测试数据服务(懒加载)
|
|
|
|
|
|
private SecondaryCircuitInspectionTestDataService _testDataService;
|
|
|
|
|
|
private SecondaryCircuitInspectionTestDataService TestDataService
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_testDataService == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_testDataService = new SecondaryCircuitInspectionTestDataService();
|
|
|
|
|
|
}
|
|
|
|
|
|
return _testDataService;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-21 09:59:22 +08:00
|
|
|
|
|
|
|
|
|
|
public SecondaryCircuitEventDrivenConfigAppService(
|
|
|
|
|
|
IRepository<SecondaryCircuitEventDrivenConfig, Guid> eventDrivenConfigRepository,
|
|
|
|
|
|
IRepository<SecondaryCircuitInspectionItem, Guid> inspectionItemRepository,
|
|
|
|
|
|
IRepository<SecondaryCircuitInspectionEventItem, Guid> inspectionEventItemRepository,
|
|
|
|
|
|
IRepository<SecondaryCircuitInspectionTelemetryConfig, Guid> telemetryConfigRepository,
|
|
|
|
|
|
IRepository<SecondaryCircuitInspectionTelesignalConfig, Guid> telesignalConfigRepository,
|
|
|
|
|
|
IRedisRepository<TelemeteringModel, string> telemeteringRedisRepository,
|
|
|
|
|
|
IRedisRepository<TelesignalisationModel, string> telesignalisationRedisRepository,
|
2025-11-18 16:28:29 +08:00
|
|
|
|
IRepository<EquipmentInfo, Guid> equipmentInfoRepository,
|
2025-10-21 09:59:22 +08:00
|
|
|
|
IUnitOfWorkManager unitOfWorkManager,
|
2025-11-18 16:28:29 +08:00
|
|
|
|
ISessionAppService sessionAppService,
|
|
|
|
|
|
IAppServiceConfiguration appServiceConfiguration) : base(sessionAppService, appServiceConfiguration)
|
2025-10-21 09:59:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
_unitOfWorkManager = unitOfWorkManager;
|
|
|
|
|
|
_eventDrivenConfigRepository = eventDrivenConfigRepository;
|
|
|
|
|
|
_inspectionItemRepository = inspectionItemRepository;
|
|
|
|
|
|
_inspectionEventItemRepository = inspectionEventItemRepository;
|
|
|
|
|
|
_telemetryConfigRepository = telemetryConfigRepository;
|
|
|
|
|
|
_telesignalConfigRepository = telesignalConfigRepository;
|
|
|
|
|
|
_telemeteringRedisRepository = telemeteringRedisRepository;
|
|
|
|
|
|
_telesignalisationRedisRepository = telesignalisationRedisRepository;
|
2025-11-18 16:28:29 +08:00
|
|
|
|
_equipmentInfoRepository = equipmentInfoRepository;
|
|
|
|
|
|
_ISMSGateWayIp = appServiceConfiguration.IsmsGateWayIp;
|
2025-10-21 09:59:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 增/改
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建或更新事件驱动配置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[HttpPost, Audited, Description("创建或更新事件驱动配置")]
|
|
|
|
|
|
[ShowApi]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
public async Task<RequestResult<SecondaryCircuitEventDrivenConfigOutput>> CreateOrUpdateAsync(
|
|
|
|
|
|
EditSecondaryCircuitEventDrivenConfigInput input,
|
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (input == null) return null;
|
|
|
|
|
|
if (_currentUser == null)
|
|
|
|
|
|
_currentUser = base.GetCurrentUser();
|
|
|
|
|
|
|
|
|
|
|
|
return input.Id.HasValue ?
|
|
|
|
|
|
await this.UpdateAsync(input, cancellationToken).ConfigureAwait(false) :
|
|
|
|
|
|
await this.CreateAsync(input, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建事件驱动配置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private async Task<RequestResult<SecondaryCircuitEventDrivenConfigOutput>> CreateAsync(
|
|
|
|
|
|
EditSecondaryCircuitEventDrivenConfigInput input,
|
|
|
|
|
|
CancellationToken cancellationToken = default)
|
2025-10-26 12:34:48 +08:00
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
var rst = new RequestResult<SecondaryCircuitEventDrivenConfigOutput>();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-30 12:29:31 +08:00
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
// 验证配置名称是否重复(排除当前记录)
|
|
|
|
|
|
var nameExists = await _eventDrivenConfigRepository.GetAll()
|
|
|
|
|
|
.AnyAsync(x => x.Name == input.Name && x.Id != input.Id, cancellationToken);
|
|
|
|
|
|
if (nameExists)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = "已存在相同名称的事件驱动配置";
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
input.CreationTime = DateTime.Now;
|
|
|
|
|
|
input.CreatorUserId = _currentUser.Id;
|
2025-10-26 12:34:48 +08:00
|
|
|
|
|
|
|
|
|
|
SecondaryCircuitEventDrivenConfig entity = ObjectMapper.Map<SecondaryCircuitEventDrivenConfig>(input);
|
2025-10-21 09:59:22 +08:00
|
|
|
|
using var uow = _unitOfWorkManager.Begin();
|
|
|
|
|
|
|
|
|
|
|
|
entity = await _eventDrivenConfigRepository.InsertAsync(entity).ConfigureAwait(false);
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
|
|
|
|
|
|
// 创建巡检项关联
|
|
|
|
|
|
if (input.SecondaryCircuitInspectionEventItems != null && input.SecondaryCircuitInspectionEventItems.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var secondaryCircuitInspectionEventItems = _inspectionItemRepository.GetAll()
|
|
|
|
|
|
.Where(t => input.SecondaryCircuitInspectionEventItems.Contains(t.Id))
|
|
|
|
|
|
.Select(t => t.Id);
|
|
|
|
|
|
foreach (var item in secondaryCircuitInspectionEventItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
var secondaryCircuitInspectionEventItem = new SecondaryCircuitInspectionEventItem(entity.Id, item);
|
|
|
|
|
|
_inspectionEventItemRepository.Insert(secondaryCircuitInspectionEventItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 创建遥测配置关联
|
|
|
|
|
|
if (input.TelemetryConfigs != null && input.TelemetryConfigs.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var telemetryConfigId in input.TelemetryConfigs)
|
|
|
|
|
|
{
|
2025-10-30 12:29:31 +08:00
|
|
|
|
|
2025-10-26 12:34:48 +08:00
|
|
|
|
var telemetryConfig = new SecondaryCircuitInspectionTelemetryConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
SecondaryCircuitEventDrivenConfigId = entity.Id,
|
|
|
|
|
|
TelemetryConfigurationId = telemetryConfigId,
|
|
|
|
|
|
IsActive = true
|
|
|
|
|
|
};
|
|
|
|
|
|
await _telemetryConfigRepository.InsertAsync(telemetryConfig).ConfigureAwait(false);
|
|
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 创建遥信配置关联
|
|
|
|
|
|
if (input.TelesignalConfigs != null && input.TelesignalConfigs.Count > 0)
|
|
|
|
|
|
{
|
2025-10-26 12:34:48 +08:00
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
foreach (var telesignalConfigId in input.TelesignalConfigs)
|
|
|
|
|
|
{
|
2025-10-30 12:29:31 +08:00
|
|
|
|
|
2025-10-26 12:34:48 +08:00
|
|
|
|
var telesignalConfig = new SecondaryCircuitInspectionTelesignalConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
SecondaryCircuitEventDrivenConfigId = entity.Id,
|
|
|
|
|
|
TelesignalConfigurationId = telesignalConfigId,
|
|
|
|
|
|
IsActive = true
|
|
|
|
|
|
};
|
|
|
|
|
|
await _telesignalConfigRepository.InsertAsync(telesignalConfig).ConfigureAwait(false);
|
|
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rst.ResultData = ObjectMapper.Map<SecondaryCircuitEventDrivenConfigOutput>(entity);
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = ex.ToString();
|
|
|
|
|
|
Log4Helper.Error(this.GetType(), "创建事件驱动配置", ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新事件驱动配置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private async Task<RequestResult<SecondaryCircuitEventDrivenConfigOutput>> UpdateAsync(
|
|
|
|
|
|
EditSecondaryCircuitEventDrivenConfigInput input,
|
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rst = new RequestResult<SecondaryCircuitEventDrivenConfigOutput>();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var entity = await _eventDrivenConfigRepository.FirstOrDefaultAsync(u => u.Id == input.Id).ConfigureAwait(false);
|
|
|
|
|
|
if (entity == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = "事件驱动配置不存在";
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input.CreationTime = entity.CreationTime;
|
|
|
|
|
|
input.CreatorUserId = entity.CreatorUserId.Value;
|
|
|
|
|
|
input.LastModificationTime = DateTime.Now;
|
|
|
|
|
|
input.LastModifierUserId = _currentUser.Id;
|
|
|
|
|
|
|
2025-10-30 12:29:31 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(input.Name))
|
|
|
|
|
|
{
|
|
|
|
|
|
entity.Name = input.Name;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(input.TriggerExpression))
|
|
|
|
|
|
{
|
|
|
|
|
|
entity.TriggerExpression = input.TriggerExpression;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (input.DelayTriggerSeconds.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
entity.DelayTriggerSeconds = input.DelayTriggerSeconds.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (input.MandatoryWaitSeconds.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
entity.MandatoryWaitSeconds = input.MandatoryWaitSeconds.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (input.TimeWindowSeconds.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
entity.TimeWindowSeconds = input.TimeWindowSeconds.Value;
|
|
|
|
|
|
}
|
2025-10-21 09:59:22 +08:00
|
|
|
|
await _eventDrivenConfigRepository.UpdateAsync(entity);
|
2025-10-30 12:29:31 +08:00
|
|
|
|
|
2025-10-26 12:34:48 +08:00
|
|
|
|
// 重新插入(仅当有数据时)
|
2025-11-19 10:19:16 +08:00
|
|
|
|
if (input.SecondaryCircuitInspectionEventItems != null )
|
2025-10-21 09:59:22 +08:00
|
|
|
|
{
|
2025-10-30 12:29:31 +08:00
|
|
|
|
// 更新巡检项关联(删除后重新插入)
|
|
|
|
|
|
// 删除现有关联
|
|
|
|
|
|
await _inspectionEventItemRepository.BatchDeleteAsync(t => t.InpectionEventDrivenId == entity.Id);
|
2025-11-19 10:19:16 +08:00
|
|
|
|
if (input.SecondaryCircuitInspectionEventItems.Count > 0)
|
2025-10-21 09:59:22 +08:00
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
var secondaryCircuitInspectionEventItems = _inspectionItemRepository.GetAll()
|
|
|
|
|
|
.Where(t => input.SecondaryCircuitInspectionEventItems.Contains(t.Id))
|
|
|
|
|
|
.Select(t => t.Id);
|
|
|
|
|
|
foreach (var item in secondaryCircuitInspectionEventItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
var secondaryCircuitInspectionEventItem = new SecondaryCircuitInspectionEventItem(entity.Id, item);
|
|
|
|
|
|
_inspectionEventItemRepository.Insert(secondaryCircuitInspectionEventItem);
|
|
|
|
|
|
}
|
2025-10-21 09:59:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 重新插入遥测配置关联
|
2025-11-19 10:19:16 +08:00
|
|
|
|
if (input.TelemetryConfigs != null )
|
2025-10-21 09:59:22 +08:00
|
|
|
|
{
|
2025-10-30 12:29:31 +08:00
|
|
|
|
// 更新遥测配置关联(删除后重新插入)
|
|
|
|
|
|
// 删除现有遥测配置关联
|
|
|
|
|
|
await _telemetryConfigRepository.BatchDeleteAsync(t => t.SecondaryCircuitEventDrivenConfigId == entity.Id);
|
2025-11-19 10:19:16 +08:00
|
|
|
|
if (input.TelemetryConfigs.Count > 0)
|
2025-10-21 09:59:22 +08:00
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
foreach (var telemetryConfigId in input.TelemetryConfigs)
|
2025-10-21 09:59:22 +08:00
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
var telemetryConfig = new SecondaryCircuitInspectionTelemetryConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
SecondaryCircuitEventDrivenConfigId = entity.Id,
|
|
|
|
|
|
TelemetryConfigurationId = telemetryConfigId,
|
|
|
|
|
|
IsActive = true
|
|
|
|
|
|
};
|
|
|
|
|
|
await _telemetryConfigRepository.InsertAsync(telemetryConfig).ConfigureAwait(false);
|
|
|
|
|
|
}
|
2025-10-21 09:59:22 +08:00
|
|
|
|
}
|
2025-11-19 10:19:16 +08:00
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-30 12:29:31 +08:00
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
// 重新插入遥信配置关联
|
2025-11-19 10:19:16 +08:00
|
|
|
|
if (input.TelesignalConfigs != null )
|
2025-10-21 09:59:22 +08:00
|
|
|
|
{
|
2025-10-30 12:29:31 +08:00
|
|
|
|
// 更新遥信配置关联(删除后重新插入)
|
|
|
|
|
|
// 删除现有遥信配置关联
|
|
|
|
|
|
await _telesignalConfigRepository.BatchDeleteAsync(t => t.SecondaryCircuitEventDrivenConfigId == entity.Id);
|
2025-11-19 10:19:16 +08:00
|
|
|
|
if (input.TelesignalConfigs.Count > 0)
|
2025-10-21 09:59:22 +08:00
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
foreach (var telesignalConfigId in input.TelesignalConfigs)
|
2025-10-21 09:59:22 +08:00
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
var telesignalConfig = new SecondaryCircuitInspectionTelesignalConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
SecondaryCircuitEventDrivenConfigId = entity.Id,
|
|
|
|
|
|
TelesignalConfigurationId = telesignalConfigId,
|
|
|
|
|
|
IsActive = true
|
|
|
|
|
|
};
|
|
|
|
|
|
await _telesignalConfigRepository.InsertAsync(telesignalConfig).ConfigureAwait(false);
|
|
|
|
|
|
}
|
2025-10-21 09:59:22 +08:00
|
|
|
|
}
|
2025-11-19 10:19:16 +08:00
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rst.ResultData = ObjectMapper.Map<SecondaryCircuitEventDrivenConfigOutput>(entity);
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = ex.ToString();
|
|
|
|
|
|
Log4Helper.Error(this.GetType(), "更新事件驱动配置", ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-26 12:34:48 +08:00
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 查
|
|
|
|
|
|
|
2025-10-26 12:34:48 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询所有事件驱动配置(不分页)
|
|
|
|
|
|
/// </summary>
|
2025-10-30 12:29:31 +08:00
|
|
|
|
[HttpPost, Description("查询所有事件驱动配置(不分页)")]
|
2025-10-26 12:34:48 +08:00
|
|
|
|
[ShowApi]
|
2025-10-30 12:29:31 +08:00
|
|
|
|
[AllowAnonymous]
|
2025-11-18 16:28:29 +08:00
|
|
|
|
public RequestResult<List<SecondaryCircuitEventDrivenConfigOutput>> GetListAsync(
|
2025-10-21 09:59:22 +08:00
|
|
|
|
SecondaryCircuitEventDrivenConfigSearchInput searchCondition)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rst = new RequestResult<List<SecondaryCircuitEventDrivenConfigOutput>>();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var query = _eventDrivenConfigRepository.GetAll()
|
2025-10-30 12:29:31 +08:00
|
|
|
|
.Include(x => x.SecondaryCircuitInspectionEventItems)
|
|
|
|
|
|
.ThenInclude(t => t.InspectionItem)
|
2025-11-18 16:28:29 +08:00
|
|
|
|
.ThenInclude(t => t.TelemetryConfigs)
|
|
|
|
|
|
.ThenInclude(t => t.TelemeteringConfiguration)
|
|
|
|
|
|
.Include(x => x.SecondaryCircuitInspectionEventItems)
|
|
|
|
|
|
.ThenInclude(t => t.InspectionItem)
|
|
|
|
|
|
.ThenInclude(t => t.TelesignalConfigs)
|
|
|
|
|
|
.ThenInclude(t => t.TelesignalisationConfiguration)
|
2025-10-21 09:59:22 +08:00
|
|
|
|
.Include(x => x.TelemetryConfigs)
|
2025-10-30 12:29:31 +08:00
|
|
|
|
.ThenInclude(t => t.TelemeteringConfiguration)
|
2025-10-21 09:59:22 +08:00
|
|
|
|
.Include(x => x.TelesignalConfigs)
|
|
|
|
|
|
.ThenInclude(t => t.TelesignalisationConfiguration)
|
|
|
|
|
|
.Where(x => x.IsActive);
|
|
|
|
|
|
|
2025-11-18 16:28:29 +08:00
|
|
|
|
// 提前加载所有设备信息并转换为字典以提高查询效率
|
|
|
|
|
|
var equipmentInfoDict = _equipmentInfoRepository.GetAll()
|
|
|
|
|
|
.ToDictionary(e => e.Id, e => e.Name);
|
|
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
// 应用搜索条件
|
|
|
|
|
|
if (searchCondition != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchCondition.Name))
|
|
|
|
|
|
{
|
|
|
|
|
|
query = query.Where(x => x.Name.Contains(searchCondition.Name) ||
|
|
|
|
|
|
x.Remark.Contains(searchCondition.Name));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (searchCondition.Priority.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
query = query.Where(x => x.Priority == searchCondition.Priority.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var entities = query.OrderBy(x => x.SortOrder).ThenBy(x => x.Name).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
// 映射到输出DTO
|
|
|
|
|
|
var outputList = new List<SecondaryCircuitEventDrivenConfigOutput>();
|
|
|
|
|
|
foreach (var entity in entities)
|
|
|
|
|
|
{
|
|
|
|
|
|
var output = ObjectMapper.Map<SecondaryCircuitEventDrivenConfigOutput>(entity);
|
2025-10-30 12:29:31 +08:00
|
|
|
|
output.SecondaryCircuitInspectionEventItems = ObjectMapper.Map<List<SecondaryCircuitInspectionItemOutput>>(entity.SecondaryCircuitInspectionEventItems.Select(t => t.InspectionItem));
|
2025-11-18 16:28:29 +08:00
|
|
|
|
|
|
|
|
|
|
// Enrich nested inspection items with telemetry and telesignal config details
|
|
|
|
|
|
foreach (var eventItem in entity.SecondaryCircuitInspectionEventItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (eventItem.InspectionItem == null) continue;
|
|
|
|
|
|
|
|
|
|
|
|
var outputItem = output.SecondaryCircuitInspectionEventItems.FirstOrDefault(x => x.Id == eventItem.InspectionItem.Id);
|
|
|
|
|
|
if (outputItem == null) continue;
|
|
|
|
|
|
|
|
|
|
|
|
// Enrich telemetry configs for nested inspection item
|
|
|
|
|
|
if (eventItem.InspectionItem.TelemetryConfigs != null && eventItem.InspectionItem.TelemetryConfigs.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
outputItem.TelemetryConfigs = eventItem.InspectionItem.TelemetryConfigs.Select(tc => new SecondaryCircuitInspectionTelemetryConfigOutput
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = tc.Id,
|
|
|
|
|
|
EquipmentInfoId = tc.TelemeteringConfiguration.EquipmentInfoId.Value,
|
|
|
|
|
|
EquipmentInfoName = equipmentInfoDict.ContainsKey(tc.TelemeteringConfiguration.EquipmentInfoId.Value)
|
|
|
|
|
|
? equipmentInfoDict[tc.TelemeteringConfiguration.EquipmentInfoId.Value]
|
|
|
|
|
|
: string.Empty,
|
|
|
|
|
|
TelemetryConfigurationId = tc.TelemetryConfigurationId ?? Guid.Empty,
|
|
|
|
|
|
TelemetryConfigurationName = tc.TelemeteringConfiguration?.Name,
|
|
|
|
|
|
TelemetryConfigurationIsmsId = tc.TelemeteringConfiguration?.ismsbaseYCId
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
outputItem.TelemetryConfigCount = outputItem.TelemetryConfigs.Count;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Enrich telesignal configs for nested inspection item
|
|
|
|
|
|
if (eventItem.InspectionItem.TelesignalConfigs != null && eventItem.InspectionItem.TelesignalConfigs.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
outputItem.TelesignalConfigs = eventItem.InspectionItem.TelesignalConfigs.Select(tc => new SecondaryCircuitInspectionTelesignalConfigOutput
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = tc.Id,
|
|
|
|
|
|
EquipmentInfoId = tc.TelesignalisationConfiguration.EquipmentInfoId.Value,
|
|
|
|
|
|
EquipmentInfoName = equipmentInfoDict.ContainsKey(tc.TelesignalisationConfiguration.EquipmentInfoId.Value)
|
|
|
|
|
|
? equipmentInfoDict[tc.TelesignalisationConfiguration.EquipmentInfoId.Value]
|
|
|
|
|
|
: string.Empty,
|
|
|
|
|
|
TelesignalConfigurationId = tc.TelesignalConfigurationId ?? Guid.Empty,
|
|
|
|
|
|
TelesignalConfigurationName = tc.TelesignalisationConfiguration?.Name,
|
|
|
|
|
|
TelesignalConfigurationIsmsId = tc.TelesignalisationConfiguration?.ismsbaseYXId
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
outputItem.TelesignalConfigCount = outputItem.TelesignalConfigs.Count;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
// 映射遥测配置关联
|
|
|
|
|
|
if (entity.TelemetryConfigs != null && entity.TelemetryConfigs.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
output.TelemetryConfigs = entity.TelemetryConfigs.Select(tc => new SecondaryCircuitInspectionTelemetryConfigOutput
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = tc.Id,
|
2025-11-18 16:28:29 +08:00
|
|
|
|
EquipmentInfoId = tc.TelemeteringConfiguration.EquipmentInfoId.Value,
|
|
|
|
|
|
EquipmentInfoName = equipmentInfoDict.ContainsKey(tc.TelemeteringConfiguration.EquipmentInfoId.Value)
|
|
|
|
|
|
? equipmentInfoDict[tc.TelemeteringConfiguration.EquipmentInfoId.Value]
|
|
|
|
|
|
: string.Empty,
|
2025-10-21 09:59:22 +08:00
|
|
|
|
TelemetryConfigurationId = tc.TelemetryConfigurationId ?? Guid.Empty,
|
|
|
|
|
|
TelemetryConfigurationName = tc.TelemeteringConfiguration?.Name,
|
2025-11-18 16:28:29 +08:00
|
|
|
|
TelemetryConfigurationIsmsId = tc.TelemeteringConfiguration?.ismsbaseYCId
|
2025-10-21 09:59:22 +08:00
|
|
|
|
}).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
output.TelemetryConfigs = new List<SecondaryCircuitInspectionTelemetryConfigOutput>();
|
|
|
|
|
|
}
|
2025-11-18 16:28:29 +08:00
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
// 映射遥信配置关联
|
|
|
|
|
|
if (entity.TelesignalConfigs != null && entity.TelesignalConfigs.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
output.TelesignalConfigs = entity.TelesignalConfigs.Select(tc => new SecondaryCircuitInspectionTelesignalConfigOutput
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = tc.Id,
|
2025-11-18 16:28:29 +08:00
|
|
|
|
EquipmentInfoId = tc.TelesignalisationConfiguration.EquipmentInfoId.Value,
|
|
|
|
|
|
EquipmentInfoName = equipmentInfoDict.ContainsKey(tc.TelesignalisationConfiguration.EquipmentInfoId.Value)
|
|
|
|
|
|
? equipmentInfoDict[tc.TelesignalisationConfiguration.EquipmentInfoId.Value]
|
|
|
|
|
|
: string.Empty,
|
2025-10-21 09:59:22 +08:00
|
|
|
|
TelesignalConfigurationId = tc.TelesignalConfigurationId ?? Guid.Empty,
|
|
|
|
|
|
TelesignalConfigurationName = tc.TelesignalisationConfiguration?.Name,
|
2025-11-18 16:28:29 +08:00
|
|
|
|
TelesignalConfigurationIsmsId = tc.TelesignalisationConfiguration?.ismsbaseYXId
|
2025-10-21 09:59:22 +08:00
|
|
|
|
}).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
output.TelesignalConfigs = new List<SecondaryCircuitInspectionTelesignalConfigOutput>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
outputList.Add(output);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rst.ResultData = outputList;
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = ex.Message;
|
2025-11-18 16:28:29 +08:00
|
|
|
|
Log4Helper.Error(this.GetType(), "查询所有事件驱动配置(不分页)", ex);
|
2025-10-21 09:59:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
2025-11-18 16:28:29 +08:00
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 删
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除事件驱动配置
|
|
|
|
|
|
/// </summary>
|
2025-10-30 12:29:31 +08:00
|
|
|
|
[HttpGet, Description("删除事件驱动配置")]
|
2025-10-21 09:59:22 +08:00
|
|
|
|
[ShowApi]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
public async Task<RequestEasyResult> DeleteAsync(
|
|
|
|
|
|
Guid id,
|
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rst = new RequestEasyResult();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var entity = await _eventDrivenConfigRepository.FirstOrDefaultAsync(u => u.Id == id).ConfigureAwait(false);
|
|
|
|
|
|
if (entity == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = "事件驱动配置不存在";
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
//var items = _inspectionEventItemRepository.GetAll().Where(t => t.InpectionEventDrivenId == id).Select(t=>t.Id);
|
|
|
|
|
|
//if (items!=null&& items.Any())
|
|
|
|
|
|
//{
|
|
|
|
|
|
// _inspectionEventItemRepository.BatchDeleteAsync(t=>);
|
|
|
|
|
|
// foreach (var item in items)
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
await _eventDrivenConfigRepository.DeleteAsync(entity).ConfigureAwait(false);
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = ex.ToString();
|
|
|
|
|
|
Log4Helper.Error(this.GetType(), "删除事件驱动配置", ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 批量删除事件驱动配置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[HttpPost, Description("批量删除事件驱动配置")]
|
|
|
|
|
|
[ShowApi]
|
|
|
|
|
|
public async Task<RequestEasyResult> BatchDeleteAsync(
|
|
|
|
|
|
List<Guid> ids,
|
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rst = new RequestEasyResult();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ids == null || !ids.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = "请选择要删除的配置";
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var entities = await _eventDrivenConfigRepository.GetAll()
|
|
|
|
|
|
.Where(x => ids.Contains(x.Id))
|
|
|
|
|
|
.ToListAsync(cancellationToken);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var entity in entities)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _eventDrivenConfigRepository.DeleteAsync(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
rst.Message = $"成功删除 {entities.Count} 个事件驱动配置";
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = ex.ToString();
|
|
|
|
|
|
Log4Helper.Error(this.GetType(), "批量删除事件驱动配置", ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 其他操作
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 启用/禁用事件驱动配置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[HttpPost, Description("启用/禁用事件驱动配置")]
|
|
|
|
|
|
[ShowApi]
|
|
|
|
|
|
public async Task<RequestEasyResult> SetActiveStatusAsync(
|
|
|
|
|
|
Guid id,
|
|
|
|
|
|
bool isActive,
|
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rst = new RequestEasyResult();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var entity = await _eventDrivenConfigRepository.FirstOrDefaultAsync(u => u.Id == id).ConfigureAwait(false);
|
|
|
|
|
|
if (entity == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = "事件驱动配置不存在";
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
entity.IsActive = isActive;
|
|
|
|
|
|
await _eventDrivenConfigRepository.UpdateAsync(entity);
|
|
|
|
|
|
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
rst.Message = isActive ? "启用成功" : "禁用成功";
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = ex.ToString();
|
|
|
|
|
|
Log4Helper.Error(this.GetType(), "启用/禁用事件驱动配置", ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 事件驱动巡检项管理
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取事件驱动配置的巡检项列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[HttpPost, Description("获取事件驱动配置的巡检项列表")]
|
|
|
|
|
|
[ShowApi]
|
|
|
|
|
|
public async Task<RequestResult<List<SecondaryCircuitInspectionEventItemOutput>>> GetEventItemsAsync(
|
|
|
|
|
|
Guid eventDrivenConfigId,
|
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rst = new RequestResult<List<SecondaryCircuitInspectionEventItemOutput>>();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var items = await _inspectionEventItemRepository.GetAll()
|
|
|
|
|
|
.Include(x => x.InspectionItem)
|
|
|
|
|
|
.Where(x => x.InpectionEventDrivenId == eventDrivenConfigId)
|
|
|
|
|
|
|
|
|
|
|
|
.ToListAsync(cancellationToken);
|
|
|
|
|
|
|
|
|
|
|
|
rst.ResultData = ObjectMapper.Map<List<SecondaryCircuitInspectionEventItemOutput>>(items);
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = ex.Message;
|
|
|
|
|
|
Log4Helper.Error(this.GetType(), "获取事件驱动配置的巡检项列表", ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除事件驱动配置的巡检项
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[HttpPost, Description("删除事件驱动配置的巡检项")]
|
|
|
|
|
|
[ShowApi]
|
|
|
|
|
|
public async Task<RequestEasyResult> RemoveEventItemAsync(
|
|
|
|
|
|
Guid eventItemId,
|
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rst = new RequestEasyResult();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
await _inspectionEventItemRepository.DeleteAsync(eventItemId);
|
|
|
|
|
|
await CurrentUnitOfWork.SaveChangesAsync();
|
|
|
|
|
|
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
rst.Message = "删除成功";
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = ex.ToString();
|
|
|
|
|
|
Log4Helper.Error(this.GetType(), "删除事件驱动配置的巡检项", ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2025-11-18 16:28:29 +08:00
|
|
|
|
#region 获取实时数据
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取事件驱动配置关联的遥测实时数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="eventDrivenConfigId">事件驱动配置ID</param>
|
|
|
|
|
|
/// <returns>遥测实时数据列表</returns>
|
|
|
|
|
|
[HttpGet, Audited]
|
|
|
|
|
|
[ShowApi]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
public async Task<RequestResult<List<TelemetryInfoOutput>>> GetTelemetryInfoData(Guid eventDrivenConfigId)
|
|
|
|
|
|
{
|
|
|
|
|
|
RequestResult<List<TelemetryInfoOutput>> rst = new RequestResult<List<TelemetryInfoOutput>>();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取事件驱动配置以获取时间窗口设置
|
|
|
|
|
|
var eventDrivenConfig = await _eventDrivenConfigRepository.FirstOrDefaultAsync(e => e.Id == eventDrivenConfigId);
|
|
|
|
|
|
if (eventDrivenConfig == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = "事件驱动配置不存在";
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取所有遥测配置(仅综自数据源)
|
2025-11-19 10:19:16 +08:00
|
|
|
|
var telemetryConfigs = await _telemetryConfigRepository.GetAll()
|
|
|
|
|
|
.Include(t => t.TelemeteringConfiguration)
|
|
|
|
|
|
.ThenInclude(t => t.EquipmentInfo)
|
|
|
|
|
|
.Where(t => t.SecondaryCircuitEventDrivenConfigId == eventDrivenConfigId)
|
|
|
|
|
|
.Where(t => t.DataSourceCategory == DataSourceCategoryEnum.Zongzi)
|
|
|
|
|
|
.ToListAsync();
|
2025-11-18 16:28:29 +08:00
|
|
|
|
|
|
|
|
|
|
string url = $"{_ISMSGateWayIp}/api/CallYCByDataId";
|
|
|
|
|
|
var ids = new List<string>();
|
|
|
|
|
|
var equipmentNameMap = new Dictionary<string, string>();
|
|
|
|
|
|
var telemetryNameMap = new Dictionary<string, string>();
|
|
|
|
|
|
|
|
|
|
|
|
// 收集所有遥测ID
|
2025-11-19 10:19:16 +08:00
|
|
|
|
foreach (var telemetryConfig in telemetryConfigs)
|
2025-11-18 16:28:29 +08:00
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
if (telemetryConfig.TelemeteringConfiguration != null &&
|
|
|
|
|
|
!string.IsNullOrEmpty(telemetryConfig.TelemeteringConfiguration.ismsbaseYCId))
|
2025-11-18 16:28:29 +08:00
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
var ismsId = telemetryConfig.TelemeteringConfiguration.ismsbaseYCId;
|
|
|
|
|
|
|
|
|
|
|
|
if (!ids.Contains(ismsId))
|
2025-11-18 16:28:29 +08:00
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
ids.Add(ismsId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 映射设备名称
|
|
|
|
|
|
if (!equipmentNameMap.ContainsKey(ismsId))
|
|
|
|
|
|
{
|
|
|
|
|
|
equipmentNameMap[ismsId] =
|
|
|
|
|
|
telemetryConfig.TelemeteringConfiguration.EquipmentInfo?.Name ?? string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 映射遥测名称
|
|
|
|
|
|
if (!telemetryNameMap.ContainsKey(ismsId))
|
|
|
|
|
|
{
|
|
|
|
|
|
telemetryNameMap[ismsId] =
|
|
|
|
|
|
telemetryConfig.TelemeteringConfiguration.Name ?? string.Empty;
|
2025-11-18 16:28:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ids.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = "未找到有效的遥测配置";
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
rst.ResultData = new List<TelemetryInfoOutput>();
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var obj = new
|
|
|
|
|
|
{
|
|
|
|
|
|
id = ids,
|
|
|
|
|
|
times = eventDrivenConfig.TimeWindowSeconds,
|
|
|
|
|
|
timeWindowType = TimeWindowTypeEnum.Both // 使用前后时间窗口
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var str = HttpHelper.HttpPostRequest<JObject>(url, obj);
|
|
|
|
|
|
if (str != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (bool.Parse(str["success"].ToString()) == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<TelemetryInfoOutput> telemetryInfoOutputs = str["data"].ToObject<List<TelemetryInfoOutput>>();
|
|
|
|
|
|
// 填充设备名称
|
|
|
|
|
|
foreach (var telemetryInfo in telemetryInfoOutputs)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (equipmentNameMap.ContainsKey(telemetryInfo.id))
|
|
|
|
|
|
{
|
|
|
|
|
|
telemetryInfo.deviceName = equipmentNameMap[telemetryInfo.id];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
rst.ResultData = telemetryInfoOutputs;
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
// API返回失败,使用测试数据
|
|
|
|
|
|
rst.ResultData = TestDataService.GenerateTelemetryTestData(
|
|
|
|
|
|
ids,
|
|
|
|
|
|
telemetryNameMap,
|
|
|
|
|
|
eventDrivenConfig.TimeWindowSeconds,
|
|
|
|
|
|
TimeWindowTypeEnum.Both,
|
|
|
|
|
|
-1,
|
|
|
|
|
|
equipmentNameMap);
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
rst.Message = "使用测试数据(API返回失败)";
|
2025-11-18 16:28:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
// HTTP请求失败,使用测试数据
|
|
|
|
|
|
rst.ResultData = TestDataService.GenerateTelemetryTestData(
|
|
|
|
|
|
ids,
|
|
|
|
|
|
telemetryNameMap,
|
|
|
|
|
|
eventDrivenConfig.TimeWindowSeconds,
|
|
|
|
|
|
TimeWindowTypeEnum.Both,
|
|
|
|
|
|
-1,
|
|
|
|
|
|
equipmentNameMap);
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
rst.Message = "使用测试数据(HTTP请求失败)";
|
2025-11-18 16:28:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = ex.Message;
|
|
|
|
|
|
Log4Helper.Error(this.GetType(), "获取事件驱动配置关联的遥测实时数据", ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取事件驱动配置关联的遥信实时数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="eventDrivenConfigId">事件驱动配置ID</param>
|
|
|
|
|
|
/// <returns>遥信实时数据列表</returns>
|
|
|
|
|
|
[HttpGet, Audited]
|
|
|
|
|
|
[ShowApi]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
public async Task<RequestResult<List<TeleSignalOutput>>> GetTeleSignalData(Guid eventDrivenConfigId)
|
|
|
|
|
|
{
|
|
|
|
|
|
RequestResult<List<TeleSignalOutput>> rst = new RequestResult<List<TeleSignalOutput>>();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取事件驱动配置以获取时间窗口设置
|
|
|
|
|
|
var eventDrivenConfig = await _eventDrivenConfigRepository.FirstOrDefaultAsync(e => e.Id == eventDrivenConfigId);
|
|
|
|
|
|
if (eventDrivenConfig == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = "事件驱动配置不存在";
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取所有遥信配置(仅综自数据源)
|
2025-11-19 10:19:16 +08:00
|
|
|
|
var telesignalConfigs = await _telesignalConfigRepository.GetAll()
|
|
|
|
|
|
.Include(t => t.TelesignalisationConfiguration)
|
|
|
|
|
|
.ThenInclude(t => t.EquipmentInfo)
|
|
|
|
|
|
.Where(t => t.SecondaryCircuitEventDrivenConfigId == eventDrivenConfigId)
|
|
|
|
|
|
.Where(t => t.DataSourceCategory == DataSourceCategoryEnum.Zongzi)
|
|
|
|
|
|
.ToListAsync();
|
2025-11-18 16:28:29 +08:00
|
|
|
|
|
|
|
|
|
|
string url = $"{_ISMSGateWayIp}/api/CallYXByDataId";
|
|
|
|
|
|
var ids = new List<string>();
|
|
|
|
|
|
var equipmentNameMap = new Dictionary<string, string>();
|
|
|
|
|
|
var telesignalNameMap = new Dictionary<string, string>();
|
|
|
|
|
|
|
|
|
|
|
|
// 收集所有遥信ID
|
2025-11-19 10:19:16 +08:00
|
|
|
|
foreach (var telesignalConfig in telesignalConfigs)
|
2025-11-18 16:28:29 +08:00
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
if (telesignalConfig.TelesignalisationConfiguration != null &&
|
|
|
|
|
|
!string.IsNullOrEmpty(telesignalConfig.TelesignalisationConfiguration.ismsbaseYXId))
|
2025-11-18 16:28:29 +08:00
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
var ismsId = telesignalConfig.TelesignalisationConfiguration.ismsbaseYXId;
|
|
|
|
|
|
|
|
|
|
|
|
if (!ids.Contains(ismsId))
|
2025-11-18 16:28:29 +08:00
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
ids.Add(ismsId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 映射设备名称
|
|
|
|
|
|
if (!equipmentNameMap.ContainsKey(ismsId))
|
|
|
|
|
|
{
|
|
|
|
|
|
equipmentNameMap[ismsId] =
|
|
|
|
|
|
telesignalConfig.TelesignalisationConfiguration.EquipmentInfo?.Name ?? string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 映射遥信名称
|
|
|
|
|
|
if (!telesignalNameMap.ContainsKey(ismsId))
|
|
|
|
|
|
{
|
|
|
|
|
|
telesignalNameMap[ismsId] =
|
|
|
|
|
|
telesignalConfig.TelesignalisationConfiguration.Name ?? string.Empty;
|
2025-11-18 16:28:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ids.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = "未找到有效的遥信配置";
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
rst.ResultData = new List<TeleSignalOutput>();
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var obj = new
|
|
|
|
|
|
{
|
|
|
|
|
|
id = ids,
|
|
|
|
|
|
times = eventDrivenConfig.TimeWindowSeconds,
|
|
|
|
|
|
timeWindowType = TimeWindowTypeEnum.Both // 使用前后时间窗口
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var str = HttpHelper.HttpPostRequest<JObject>(url, obj);
|
|
|
|
|
|
if (str != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (bool.Parse(str["success"].ToString()) == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<TeleSignalOutput> telesignalInfoOutputs = str["data"].ToObject<List<TeleSignalOutput>>();
|
|
|
|
|
|
// 填充设备名称
|
|
|
|
|
|
foreach (var telesignalInfo in telesignalInfoOutputs)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (equipmentNameMap.ContainsKey(telesignalInfo.id))
|
|
|
|
|
|
{
|
|
|
|
|
|
telesignalInfo.deviceName = equipmentNameMap[telesignalInfo.id];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
rst.ResultData = telesignalInfoOutputs;
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
// API返回失败,使用测试数据
|
|
|
|
|
|
rst.ResultData = TestDataService.GenerateTeleSignalTestData(
|
|
|
|
|
|
ids,
|
|
|
|
|
|
telesignalNameMap,
|
|
|
|
|
|
eventDrivenConfig.TimeWindowSeconds,
|
|
|
|
|
|
TimeWindowTypeEnum.Both,
|
|
|
|
|
|
-1);
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
rst.Message = "使用测试数据(API返回失败)";
|
2025-11-18 16:28:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-11-19 10:19:16 +08:00
|
|
|
|
// HTTP请求失败,使用测试数据
|
|
|
|
|
|
rst.ResultData = TestDataService.GenerateTeleSignalTestData(
|
|
|
|
|
|
ids,
|
|
|
|
|
|
telesignalNameMap,
|
|
|
|
|
|
eventDrivenConfig.TimeWindowSeconds,
|
|
|
|
|
|
TimeWindowTypeEnum.Both,
|
|
|
|
|
|
-1);
|
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
|
rst.Message = "使用测试数据(HTTP请求失败)";
|
2025-11-18 16:28:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
rst.Message = ex.Message;
|
|
|
|
|
|
Log4Helper.Error(this.GetType(), "获取事件驱动配置关联的遥信实时数据", ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
return rst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2025-10-21 09:59:22 +08:00
|
|
|
|
|
|
|
|
|
|
#region 私有方法
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-18 16:28:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-21 09:59:22 +08:00
|
|
|
|
public RequestPageResult<SecondaryCircuitEventDrivenConfigOutput> FindDatas(PageSearchCondition<SecondaryCircuitEventDrivenConfigSearchInput> searchCondition)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 辅助类
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 事件驱动巡检项输出DTO
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class SecondaryCircuitInspectionEventItemOutput
|
|
|
|
|
|
{
|
|
|
|
|
|
public Guid Id { get; set; }
|
|
|
|
|
|
public Guid? InpectionEventDrivenId { get; set; }
|
|
|
|
|
|
public Guid? InspectionItemId { get; set; }
|
|
|
|
|
|
public string InspectionItemName { get; set; }
|
|
|
|
|
|
public int ExecutionOrder { get; set; }
|
|
|
|
|
|
public bool IsActive { get; set; }
|
|
|
|
|
|
public decimal WeightCoefficient { get; set; }
|
|
|
|
|
|
public DateTime? LastExecutionTime { get; set; }
|
|
|
|
|
|
public SecondaryCircuitInspectionResultStatus LastExecutionResult { get; set; }
|
|
|
|
|
|
public string LastExecutionErrorMessage { get; set; }
|
|
|
|
|
|
public int TotalExecutionCount { get; set; }
|
|
|
|
|
|
public int SuccessExecutionCount { get; set; }
|
|
|
|
|
|
public int AbnormalExecutionCount { get; set; }
|
|
|
|
|
|
public int ErrorExecutionCount { get; set; }
|
|
|
|
|
|
public long AverageExecutionDurationMs { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|