修改寿命计算代码

This commit is contained in:
郭睿 2024-12-02 17:46:35 +08:00
parent 35a4749766
commit 4c3d4f14ba
7 changed files with 151 additions and 27 deletions

View File

@ -2,6 +2,7 @@
using Abp.Authorization;
using Abp.Collections.Extensions;
using Abp.Domain.Repositories;
using Abp.UI;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
@ -149,25 +150,54 @@ namespace YunDa.ISAS.Application.GeneralInformation.ProtectionDevice
try
{
var decices = _protectionDeviceInfoRepository
.GetAllIncluding()
// 从仓储中查询设备信息
var devices = _protectionDeviceInfoRepository
.GetAllIncluding(t => t.EquipmentInfo)
.WhereIf(equipmentInfoId != default, t => t.EquipmentInfoId == equipmentInfoId)
.ToList();
var data = decices.Select(t => new EquipmentInfoRemainingLifeAssessment
// 定义基准寿命年限
float totalLifetimeInYears = 15;
// 计算设备剩余寿命
var data = devices.Select(t =>
{
EquipmentInfoId = t.EquipmentInfoId,
RemainingLifeInYears ="5.8年"
double remainingYears;
if (t.EquipmentInfo?.ProductionDate == null)
{
// 当出厂日期为空,寿命按 15 年计算
remainingYears = totalLifetimeInYears;
}
else
{
// 计算已用寿命年限
double elapsedYears = (DateTime.Now - t.EquipmentInfo.ProductionDate.Value).TotalDays / 365.0;
// 剩余寿命 = 基准寿命 - 已用寿命
remainingYears = Math.Max(totalLifetimeInYears - elapsedYears, 0);
}
// 返回计算结果
return new EquipmentInfoRemainingLifeAssessment
{
EquipmentInfoId = t.EquipmentInfoId,
RemainingLifeInYears = $"{Math.Round(remainingYears, 1)}年" // 保留一位小数
};
});
// 设置返回结果
rst.ResultData = data.ToList();
rst.Flag = true;
}
catch (Exception ex)
{
throw;
// 捕获异常并记录日志
//_logger.LogError(ex, "计算设备剩余寿命时发生错误");
//throw new UserFriendlyException("计算设备剩余寿命失败,请联系管理员", ex);
}
return rst;
}
}

View File

@ -215,5 +215,8 @@ namespace Yunda.ISAS.DataMonitoringServer.DataAnalysis.Model
public static string RequestModifyBoardInfoList => $"{WebAddr}/api/services/isas/BoardCardInfo/ModifyBoardInfoList";
public static string RequestSecondaryCircuitLogicExpressionList => $"{WebAddr}/api/services/isas/SecondaryCircuitLogicExpression/FindDatas";
public static string RequestProtectionDeviceGetDeviceEventTypeList => $"{WebAddr}/api/services/isas/ProtectionDevice/GetDeviceEventType";
}
}

View File

@ -39,6 +39,7 @@ using YunDa.ISAS.ExternalInteraction.DataTransferObject.InspectionEquipment.Requ
using YunDa.SOMS.DataTransferObject.GeneralInformation.ProtectionDeviceInfoDto;
using YunDa.SOMS.DataTransferObject.GeneralInformation.ProtectionSettingDto;
using YunDa.SOMS.DataTransferObject.GeneralInformation.SecondaryCircuitDto;
using YunDa.SOMS.DataTransferObject.MainStationMaintenanceInfo.OperationReport;
using ConstantModel = Yunda.ISAS.DataMonitoringServer.DataAnalysis.Model.ConstantModel;
namespace Yunda.ISAS.DataMonitoringServer.DataAnalysis
@ -1112,5 +1113,29 @@ namespace Yunda.ISAS.DataMonitoringServer.DataAnalysis
return null;
}
//http://localhost:38091?deviceAddr=1&eventCode=1
public EquipmentInfoAbnormalComponent GetDeviceAbnormalComponent(byte deviceAddr, byte eventCode)
{
try
{
JObject rstDataJObject = ToolLibrary
.HttpHelper
.HttpGetRequest<JObject>
(ConstantModel
.RequestProtectionDeviceGetDeviceEventTypeList+$"?deviceAddr={deviceAddr}&eventCode={eventCode}"
);
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
var res = rst.ToObject<EquipmentInfoAbnormalComponent>();
return res;
}
catch (Exception ex)
{
MonitoringEventBus.LogHandler(ex.Message, "获取遥测报警配置缓存");
}
return null;
}
}
}

View File

@ -42,6 +42,9 @@ namespace Yunda.ISAS.DataMonitoringServer.DataCenter
/// 遥信数据变位库
/// </summary>
public IRedisRepository<TelesignalisationModel, string> TelesignalisationModelInflectionListRedis { get; }
public string DeviceSelfTestChannelRediskey = "deviceSelfTestChannel";
public IRedisRepository<EquipmentInfoAbnormalComponent, string> AbnormalComponentRedis { get; }
public IRedisRepository<SecondaryCircuitComponent, string> SecondaryCircuitComponentRedis { get; }
public IRedisRepository<EquipmentInfoRemainingLifeAssessment, string> EquipmentInfoRemainingLifeAssessmentRedis { get; }

View File

@ -7,6 +7,7 @@ using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Threading.Tasks;
using ToolLibrary.LogHelper;
using Yunda.ISAS.DataMonitoringServer.DataAnalysis;
using Yunda.SOMS.DataMonitoringServer.TcpSocket.Server;
using YunDa.ISAS.Redis.Repositories;
@ -15,11 +16,13 @@ namespace Yunda.SOMS.DataMonitoringServer.ProtectionDeviceHandle
{
public class ProtectionDeviceDataCenter: ISingletonDependency
{
public static List<ProtectionDeviceCommInfoOutput> _devices;
WebApiRequest _webApiRequest;
ProtectionDeviceDZDataHandle _protectionDeviceDZDataHandle;
ProtectionDeviceVersionHandle _protectionDeviceVersionHandle;
ProtectionDeviceIOInfoHandle _protectionDeviceIOInfoHandle;
ProtectionDeviceRunInfoHandle _protectionDeviceRunInfoHandle;
ProtectionDeviceSelfCheckHandle _protectionDeviceSelfCheckHandle;
IRedisRepository<int[], string> _deviceBoardStatesRedis;
DotNettyTcpServer _dotNettyTcpServer;
string deviceBoardStatesRedisKey = "deviceBoardStates";
@ -29,7 +32,8 @@ namespace Yunda.SOMS.DataMonitoringServer.ProtectionDeviceHandle
, ProtectionDeviceVersionHandle protectionDeviceVersionHandle
, ProtectionDeviceIOInfoHandle protectionDeviceIOInfoHandle
, DotNettyTcpServer dotNettyTcpServer
,ProtectionDeviceRunInfoHandle protectionDeviceRunInfoHandle
, ProtectionDeviceSelfCheckHandle protectionDeviceSelfCheckHandle
, ProtectionDeviceRunInfoHandle protectionDeviceRunInfoHandle
, IRedisRepository<int[], string> deviceBoardStatesRedis
)
{
@ -41,6 +45,20 @@ namespace Yunda.SOMS.DataMonitoringServer.ProtectionDeviceHandle
_protectionDeviceRunInfoHandle = protectionDeviceRunInfoHandle;
_dotNettyTcpServer.deviceBoardStatesAction += _dotNettyTcpServer_deviceBoardStatesAction;
_deviceBoardStatesRedis = deviceBoardStatesRedis;
_protectionDeviceSelfCheckHandle = protectionDeviceSelfCheckHandle;
Task.Run(async () =>
{
try
{
_devices = _webApiRequest.GetProtectionDeviceCommInfos("神池南");
await Task.Delay(1000);
}
catch (Exception ex)
{
Log4Helper.Error(this.GetType(), "初始化装置IO错误", ex);
}
});
}
/// <summary>
/// 将装置状态写入到内存数据库中

View File

@ -22,7 +22,6 @@ namespace Yunda.SOMS.DataMonitoringServer.ProtectionDeviceHandle
WebApiRequest _webApiRequest;
FtpFile _ftpFile;
DotNettyTcpServer _dotNettyTcpServer;
List<ProtectionDeviceCommInfoOutput> _devices;
private readonly RedisDataRepository _redisDataRepository;
public ProtectionDeviceRunInfoHandle(
FtpFile ftpFile,
@ -36,19 +35,6 @@ namespace Yunda.SOMS.DataMonitoringServer.ProtectionDeviceHandle
_dotNettyTcpServer = dotNettyTcpServer;
_redisDataRepository = redisDataRepository;
_dotNettyTcpServer.MessageReceived += OnMessageReceived; // 订阅事件
Task.Run(async () =>
{
try
{
_devices = _webApiRequest.GetProtectionDeviceCommInfos("神池南");
await Task.Delay(10000);
}
catch (Exception ex)
{
Log4Helper.Error(this.GetType(), "初始化装置IO错误", ex);
}
});
}
int _commCount = 0;
@ -60,7 +46,7 @@ namespace Yunda.SOMS.DataMonitoringServer.ProtectionDeviceHandle
{
if (_commCount == 0)
{
var device = _devices.FirstOrDefault(t => t.DeviceAddr == address);
var device = ProtectionDeviceDataCenter._devices.FirstOrDefault(t => t.DeviceAddr == address);
var localFile = _ftpFile.GetFileFromFtp(device.GatewayIP1, "/nor/root/status/", "status.txt",address.ToString());
if (File.Exists(localFile))
{

View File

@ -1,13 +1,72 @@
using System;
using Abp.Dependency;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ToolLibrary.LogHelper;
using Yunda.ISAS.DataMonitoringServer.DataAnalysis;
using Yunda.ISAS.DataMonitoringServer.DataCenter;
using Yunda.SOMS.DataMonitoringServer.FTPHandle;
using Yunda.SOMS.DataMonitoringServer.TcpSocket.Server;
using YunDa.ISAS.Entities.System;
using YunDa.SOMS.Commdb.Models;
using YunDa.SOMS.DataTransferObject.MainStationMaintenanceInfo.OperationReport;
namespace Yunda.SOMS.DataMonitoringServer.ProtectionDeviceHandle
{
public class ProtectionDeviceSelfCheckHandle
public class ProtectionDeviceSelfCheckHandle : ISingletonDependency
{
WebApiRequest _webApiRequest;
DotNettyTcpServer _dotNettyTcpServer;
private readonly RedisDataRepository _redisDataRepository;
public ProtectionDeviceSelfCheckHandle(WebApiRequest webApiRequest,
DotNettyTcpServer dotNettyTcpServer,
RedisDataRepository redisDataRepository)
{
_webApiRequest = webApiRequest;
_dotNettyTcpServer = dotNettyTcpServer;
_redisDataRepository = redisDataRepository;
_dotNettyTcpServer.MessageReceived += OnMessageReceived; // 订阅事件
}
private void OnMessageReceived(byte address, byte[] message, byte functionType)
{
try
{
if (functionType == 4) //通信状态
{
var device = ProtectionDeviceDataCenter._devices.FirstOrDefault(t => t.DeviceAddr == address);
if (device != null)
{
if (message.Length > 0)
{
if (message[0] != 0)
{
var abnormalComponent = _webApiRequest.GetDeviceAbnormalComponent(address, message[0]);
if (abnormalComponent != null)
{
abnormalComponent.EquipmentInfoId = device.EquipmentInfoId;
Task.Run(async () =>
{
string redisChannel = _redisDataRepository.DeviceSelfTestChannelRediskey;
await _redisDataRepository.AbnormalComponentRedis.PublishAsync(redisChannel, abnormalComponent);
});
}
}
}
}
}
}
catch (Exception ex)
{
Log4Helper.Error(this.GetType(), "自检信息", ex);
}
}
//GetDeviceAbnormalComponent
}
}