add-添加设备报警采集

dev
liuwf 3 months ago
parent f2bd9ae8f7
commit 6c755133d9

@ -0,0 +1,102 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Security.Principal;
using System.Text;
namespace SlnMesnac.Model.domain
{
[SugarTable("dms_base_alarm_rule"), TenantAttribute("mes")]
public class DmsBaseAlarmRule
{
/// <summary>
/// 主键标识
/// </summary>
[SugarColumn(ColumnName = "alarm_rule_id", IsPrimaryKey = true, IsIdentity = true)]
public long AlarmRuleId { get; set; }
/// <summary>
/// 设备台账id, 关联dms_base_device_ledger的device_id
/// </summary>
[SugarColumn(ColumnName = "device_id")]
public long DeviceId { get; set; }
/// <summary>
/// 报警类型1AGV 2PLC 3其他设备
/// </summary>
[SugarColumn(ColumnName = "alarm_type")]
public string AlarmType { get; set; }
/// <summary>
/// 报警级别1一级 2二级 3三级
/// </summary>
[SugarColumn(ColumnName = "alarm_level")]
public string AlarmLevel { get; set; }
/// <summary>
/// 通知方式1WEB 2公众号 3PLC可多选
/// </summary>
[SugarColumn(ColumnName = "notice_type")]
public string NoticeType { get; set; }
/// <summary>
/// 自动恢复标识0否 1是
/// </summary>
[SugarColumn(ColumnName = "recover_type")]
public string RecoverType { get; set; }
/// <summary>
/// 报警持续时间ms
/// </summary>
[SugarColumn(ColumnName = "continue_time")]
public long? ContinueTime { get; set; }
/// <summary>
/// 报警状态字
/// </summary>
[SugarColumn(ColumnName = "alarm_status_word")]
public string AlarmStatusWord { get; set; }
/// <summary>
/// 报警原因
/// </summary>
[SugarColumn(ColumnName = "alarm_reason")]
public string AlarmReason { get; set; }
/// <summary>
/// 处理建议
/// </summary>
[SugarColumn(ColumnName = "handle_suggest")]
public string HandleSuggest { get; set; }
/// <summary>
/// 备注
/// </summary>
[SugarColumn(ColumnName = "remark")]
public string Remark { get; set; }
/// <summary>
/// 创建人
/// </summary>
[SugarColumn(ColumnName = "create_by")]
public string CreateBy { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[SugarColumn(ColumnName = "create_time")]
public DateTime? CreateTime { get; set; }
/// <summary>
/// 更新人
/// </summary>
[SugarColumn(ColumnName = "update_by")]
public string UpdateBy { get; set; }
/// <summary>
/// 更新时间
/// </summary>
[SugarColumn(ColumnName = "update_time")]
public DateTime? UpdateTime { get; set; }
}
}

@ -0,0 +1,126 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Security.Principal;
using System.Text;
namespace SlnMesnac.Model.domain
{
[SugarTable("dms_record_alarm_info"), TenantAttribute("mes")]
public class DmsRecordAlarmInfo
{
/// <summary>
/// 主键标识
/// </summary>
[SugarColumn(ColumnName = "alarm_id", IsPrimaryKey = true, IsIdentity = true)]
public long AlarmId { get; set; }
/// <summary>
/// 设备台账id,关联dms_base_device_ledger的device_id
/// </summary>
[SugarColumn(ColumnName = "device_id")]
public long DeviceId { get; set; }
/// <summary>
/// 设备报警规则id,关联dms_base_alarm_rule的alarm_rule_id
/// </summary>
[SugarColumn(ColumnName = "alarm_rule_id")]
public long AlarmRuleId { get; set; }
/// <summary>
/// 报警开始时间
/// </summary>
[SugarColumn(ColumnName = "alarm_begin_time")]
public DateTime? AlarmBeginTime { get; set; }
/// <summary>
/// 报警结束时间
/// </summary>
[SugarColumn(ColumnName = "alarm_end_time")]
public DateTime? AlarmEndTime { get; set; }
/// <summary>
/// 报警持续时间ms
/// </summary>
[SugarColumn(ColumnName = "continue_time")]
public long? ContinueTime { get; set; }
/// <summary>
/// 报警原因
/// </summary>
[SugarColumn(ColumnName = "alarm_reason")]
public string AlarmReason { get; set; }
/// <summary>
/// 报警数据
/// </summary>
[SugarColumn(ColumnName = "alarm_data")]
public string AlarmData { get; set; }
/// <summary>
/// 报警状态0未处理 1人工已处理 2自动恢复
/// </summary>
[SugarColumn(ColumnName = "alarm_status")]
public string AlarmStatus { get; set; }
/// <summary>
/// 处理建议
/// </summary>
[SugarColumn(ColumnName = "handle_suggest")]
public string HandleSuggest { get; set; }
/// <summary>
/// 通知状态0未通知 1已通知
/// </summary>
[SugarColumn(ColumnName = "notice_status")]
public string NoticeStatus { get; set; }
/// <summary>
/// 处理人员
/// </summary>
[SugarColumn(ColumnName = "handle_user")]
public string HandleUser { get; set; }
/// <summary>
/// 处理时间
/// </summary>
[SugarColumn(ColumnName = "handle_time")]
public DateTime? HandleTime { get; set; }
/// <summary>
/// 原因分析
/// </summary>
[SugarColumn(ColumnName = "cause_analysis")]
public string CauseAnalysis { get; set; }
/// <summary>
/// 备注
/// </summary>
[SugarColumn(ColumnName = "remark")]
public string Remark { get; set; }
/// <summary>
/// 创建人
/// </summary>
[SugarColumn(ColumnName = "create_by")]
public string CreateBy { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[SugarColumn(ColumnName = "create_time")]
public DateTime? CreateTime { get; set; }
/// <summary>
/// 更新人
/// </summary>
[SugarColumn(ColumnName = "update_by")]
public string UpdateBy { get; set; }
/// <summary>
/// 更新时间
/// </summary>
[SugarColumn(ColumnName = "update_time")]
public DateTime? UpdateTime { get; set; }
}
}

@ -0,0 +1,90 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Security.Principal;
using System.Text;
namespace SlnMesnac.Model.domain
{
[SugarTable("dms_record_alarm_time"), TenantAttribute("mes")]
public class DmsRecordAlarmTime
{
/// <summary>
/// 主键标识
/// </summary>
[SugarColumn(ColumnName = "alarm_id", IsPrimaryKey = true, IsIdentity = true)]
public long AlarmId { get; set; }
/// <summary>
/// 设备台账id,关联dms_base_device_ledger的device_id
/// </summary>
[SugarColumn(ColumnName = "device_id")]
public long DeviceId { get; set; }
/// <summary>
/// 设备报警规则id,关联dms_base_alarm_rule的alarm_rule_id
/// </summary>
[SugarColumn(ColumnName = "alarm_rule_id")]
public long AlarmRuleId { get; set; }
/// <summary>
/// 报警开始时间
/// </summary>
[SugarColumn(ColumnName = "alarm_begin_time")]
public DateTime AlarmBeginTime { get; set; }
/// <summary>
/// 报警持续时间ms
/// </summary>
[SugarColumn(ColumnName = "continue_time")]
public long? ContinueTime { get; set; }
/// <summary>
/// 报警原因
/// </summary>
[SugarColumn(ColumnName = "alarm_reason")]
public string AlarmReason { get; set; }
/// <summary>
/// 报警数据
/// </summary>
[SugarColumn(ColumnName = "alarm_data")]
public string AlarmData { get; set; }
/// <summary>
/// 处理建议
/// </summary>
[SugarColumn(ColumnName = "handle_suggest")]
public string HandleSuggest { get; set; }
/// <summary>
/// 备注
/// </summary>
[SugarColumn(ColumnName = "remark")]
public string Remark { get; set; }
/// <summary>
/// 创建人
/// </summary>
[SugarColumn(ColumnName = "create_by")]
public string CreateBy { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[SugarColumn(ColumnName = "create_time")]
public DateTime? CreateTime { get; set; }
/// <summary>
/// 更新人
/// </summary>
[SugarColumn(ColumnName = "update_by")]
public string UpdateBy { get; set; }
/// <summary>
/// 更新时间
/// </summary>
[SugarColumn(ColumnName = "update_time")]
public DateTime? UpdateTime { get; set; }
}
}

@ -0,0 +1,16 @@
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System.Collections.Generic;
namespace SlnMesnac.Repository.service
{
public interface IDmsRecordAlarmTimeService : IBaseService<DmsRecordAlarmTime>
{
/// <summary>
/// 获取设备各种规则(报警规则id2001-2010)的第一条记录
/// </summary>
/// <returns></returns>
List<DmsRecordAlarmTime> GetMachineWarnList();
}
}

@ -7,7 +7,7 @@ namespace SlnMesnac.Repository.service
public interface IDmsRecordShutDownService : IBaseService<DmsRecordShutDown> public interface IDmsRecordShutDownService : IBaseService<DmsRecordShutDown>
{ {
/// <summary> /// <summary>
/// 查询 /// 查询每个设备关机记录第一条
/// </summary> /// </summary>
/// <param name="palleCode"></param> /// <param name="palleCode"></param>
/// <returns></returns> /// <returns></returns>

@ -0,0 +1,62 @@
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Repository.service.Impl
* 50d84911-9088-4fd3-b85a-151411028afc
*
* WenJY
* wenjy@mesnac.com
* 2024-04-08 16:47:57
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Repository.service.Impl
{
public class DmsRecordAlarmTimeServiceImpl : BaseServiceImpl<DmsRecordAlarmTime>, IDmsRecordAlarmTimeService
{
public DmsRecordAlarmTimeServiceImpl(Repository<DmsRecordAlarmTime> rep) : base(rep)
{
}
/// <summary>
/// 获取设备各种规则(报警规则id2001-2010)的第一条记录
/// </summary>
/// <returns></returns>
public List<DmsRecordAlarmTime> GetMachineWarnList()
{
List<DmsRecordAlarmTime> list = null;
try
{
string sql = "WITH RankedRecords AS ( SELECT *, ROW_NUMBER() OVER (PARTITION BY device_id ORDER BY create_time DESC) AS rn FROM dms_record_alarm_time WHERE alarm_rule_id BETWEEN 2001 AND 2010) SELECT * FROM RankedRecords WHERE rn = 1;";
list = this._rep.Context.Ado.SqlQuery<DmsRecordAlarmTime>(sql);
}catch (Exception ex)
{
Console.WriteLine(ex.Message);
list = null;
}
return list;
}
}
}

@ -37,7 +37,7 @@ namespace SlnMesnac.Repository.service.Impl
} }
/// <summary> /// <summary>
/// 根据托盘编码获取托盘信息 /// 查询每个设备关机记录第一条
/// </summary> /// </summary>
/// <param name="palleCode"></param> /// <param name="palleCode"></param>
/// <returns></returns> /// <returns></returns>

@ -38,11 +38,15 @@ namespace SlnMesnac.WPF.Page
{ {
// 设备OEE采集缓存 // 设备OEE采集缓存
private List<DmsRecordShutDown> DmsList = null; private List<DmsRecordShutDown> DmsList = null;
// 设备报警采集缓存
private List<DmsRecordAlarmTime> WarningList = null;
private ISqlSugarClient? sqlClient = null; private ISqlSugarClient? sqlClient = null;
private BaseBusiness baseBusiness = null; private BaseBusiness baseBusiness = null;
private readonly ConfigInfoBusiness _configInfoBusiness; private readonly ConfigInfoBusiness _configInfoBusiness;
private readonly IDmsRecordShutDownService dmsRecordShutDownService; private readonly IDmsRecordShutDownService dmsRecordShutDownService;
private readonly IDmsRecordAlarmTimeService dmsRecordAlarmTimeService;
PlcAbsractFactory plc = null; PlcAbsractFactory plc = null;
int MachineSleep = 1000; int MachineSleep = 1000;
private readonly ILogger<DevMonitorPage> _logger; private readonly ILogger<DevMonitorPage> _logger;
@ -56,6 +60,7 @@ namespace SlnMesnac.WPF.Page
{ {
sqlClient = App.ServiceProvider.GetService<ISqlSugarClient>(); sqlClient = App.ServiceProvider.GetService<ISqlSugarClient>();
dmsRecordShutDownService = App.ServiceProvider.GetService<IDmsRecordShutDownService>(); dmsRecordShutDownService = App.ServiceProvider.GetService<IDmsRecordShutDownService>();
dmsRecordAlarmTimeService = App.ServiceProvider.GetService<IDmsRecordAlarmTimeService>();
RecipeModeSetWindow.ManualChangeRecipeEvent += ManualChangeRecipe; RecipeModeSetWindow.ManualChangeRecipeEvent += ManualChangeRecipe;
_logger = App.ServiceProvider.GetService<ILogger<DevMonitorPage>>(); _logger = App.ServiceProvider.GetService<ILogger<DevMonitorPage>>();
_configInfoBusiness = App.ServiceProvider.GetService<ConfigInfoBusiness>(); _configInfoBusiness = App.ServiceProvider.GetService<ConfigInfoBusiness>();
@ -127,7 +132,9 @@ namespace SlnMesnac.WPF.Page
{ {
Task.Run(() => Task.Run(() =>
{ {
DmsList = dmsRecordShutDownService.GetAllMachineFirst(); DmsList = dmsRecordShutDownService.GetAllMachineFirst();
WarningList = dmsRecordAlarmTimeService.GetMachineWarnList();
while (true) while (true)
{ {
try try
@ -226,11 +233,76 @@ namespace SlnMesnac.WPF.Page
{ {
try try
{ {
int alarmRuleId = int.Parse(machineStatusDto.warnStatus.GetDescription());
// 无报警,找出该设备的报警记录,如果报警记录未结束,则消除报警
if (machineStatusDto.warnStatus == WarnStatusEnum.)
{
DmsRecordAlarmTime? dmsRecordAlarmTime = WarningList.FirstOrDefault(x => x.DeviceId == machineStatusDto.deviceId);
if (dmsRecordAlarmTime != null)
{
sqlClient.AsTenant().BeginTran();
DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmInfo>().First(x => x.AlarmRuleId == dmsRecordAlarmTime.AlarmRuleId && x.AlarmStatus=="0");
if (dmsRecordAlarmInfo != null)
{
dmsRecordAlarmInfo.AlarmEndTime = DateTime.Now;
dmsRecordAlarmInfo.AlarmStatus = "2";
dmsRecordAlarmInfo.UpdateTime = DateTime.Now;
sqlClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmInfo).ExecuteCommand();
}
sqlClient.AsTenant().GetConnection("mes").Deleteable(dmsRecordAlarmTime).ExecuteCommand();
// sqlClient.AsTenant().GetConnection("local").Updateable(localPlan).ExecuteCommand();
sqlClient.AsTenant().CommitTran();
WarningList = dmsRecordAlarmTimeService.GetMachineWarnList();
}
}
else
{
// 有报警,找出该设备的报警记录,如果没有报警记录或者报警记录已结束,则新增报警记录
int warnRuleId = int.Parse(machineStatusDto.warnStatus.GetDescription());
DmsRecordAlarmTime? dmsRecordAlarmTime = WarningList.FirstOrDefault(x => x.AlarmRuleId == warnRuleId);
if (dmsRecordAlarmTime == null)
{
DmsBaseAlarmRule dmsBaseAlarmRule = sqlClient.AsTenant().GetConnection("mes").Queryable<DmsBaseAlarmRule>().First(x => x.AlarmRuleId == warnRuleId);
sqlClient.AsTenant().BeginTran();
dmsRecordAlarmTime = new DmsRecordAlarmTime();
dmsRecordAlarmTime.DeviceId = machineStatusDto.deviceId;
dmsRecordAlarmTime.AlarmRuleId = warnRuleId;
dmsRecordAlarmTime.AlarmBeginTime = DateTime.Now;
dmsRecordAlarmTime.ContinueTime = dmsBaseAlarmRule.ContinueTime;
dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason;
dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason;
dmsRecordAlarmTime.AlarmData = machineStatusDto.warnStatus.ToString();
dmsRecordAlarmTime.HandleSuggest = dmsBaseAlarmRule.HandleSuggest;
dmsRecordAlarmTime.CreateBy = "SlnMesnac";
dmsRecordAlarmTime.CreateTime = DateTime.Now;
DmsRecordAlarmInfo dmsRecordAlarmInfo = new DmsRecordAlarmInfo();
dmsRecordAlarmInfo.DeviceId = machineStatusDto.deviceId;
dmsRecordAlarmInfo.AlarmRuleId = warnRuleId;
dmsRecordAlarmInfo.AlarmBeginTime = DateTime.Now;
dmsRecordAlarmInfo.AlarmStatus = "0";
dmsRecordAlarmInfo.NoticeStatus = "0";
dmsRecordAlarmInfo.ContinueTime = dmsBaseAlarmRule.ContinueTime;
dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason;
dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason;
dmsRecordAlarmInfo.AlarmData = machineStatusDto.warnStatus.ToString();
dmsRecordAlarmInfo.HandleSuggest = dmsBaseAlarmRule.HandleSuggest;
dmsRecordAlarmInfo.CreateBy = "SlnMesnac";
dmsRecordAlarmInfo.CreateTime = DateTime.Now;
sqlClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmTime).ExecuteCommand();
sqlClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmInfo).ExecuteCommand();
sqlClient.AsTenant().CommitTran();
WarningList = dmsRecordAlarmTimeService.GetMachineWarnList();
}
}
// sqlClient.SqlQueryable<DmsRecordShutDown>("").ToList();
} }
catch (Exception ex) catch (Exception ex)
{ {
sqlClient.AsTenant().RollbackTran();
_logger.LogError($"OEE设备报警采集异常:{ex.Message}"); _logger.LogError($"OEE设备报警采集异常:{ex.Message}");
} }
} }
@ -1402,7 +1474,6 @@ namespace SlnMesnac.WPF.Page
})); }));
MachineStatusDto machineStatusDto = new MachineStatusDto(); MachineStatusDto machineStatusDto = new MachineStatusDto();
machineStatusDto.deviceId = 1017; machineStatusDto.deviceId = 1017;
machineStatusDto.status = signal0 && signal1; machineStatusDto.status = signal0 && signal1;
@ -1416,6 +1487,9 @@ namespace SlnMesnac.WPF.Page
} }
machineStatusDtos.Add(machineStatusDto); machineStatusDtos.Add(machineStatusDto);
} }
catch (Exception ex) catch (Exception ex)
{ {

Loading…
Cancel
Save