diff --git a/SlnMesnac.Model/domain/DmsBaseAlarmRule.cs b/SlnMesnac.Model/domain/DmsBaseAlarmRule.cs
new file mode 100644
index 0000000..cb5ff8c
--- /dev/null
+++ b/SlnMesnac.Model/domain/DmsBaseAlarmRule.cs
@@ -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
+ {
+ ///
+ /// 主键标识
+ ///
+ [SugarColumn(ColumnName = "alarm_rule_id", IsPrimaryKey = true, IsIdentity = true)]
+ public long AlarmRuleId { get; set; }
+
+ ///
+ /// 设备台账id, 关联dms_base_device_ledger的device_id
+ ///
+ [SugarColumn(ColumnName = "device_id")]
+ public long DeviceId { get; set; }
+
+ ///
+ /// 报警类型(1AGV 2PLC 3其他设备)
+ ///
+ [SugarColumn(ColumnName = "alarm_type")]
+ public string AlarmType { get; set; }
+
+ ///
+ /// 报警级别(1一级 2二级 3三级)
+ ///
+ [SugarColumn(ColumnName = "alarm_level")]
+ public string AlarmLevel { get; set; }
+
+ ///
+ /// 通知方式(1WEB 2公众号 3PLC)可多选
+ ///
+ [SugarColumn(ColumnName = "notice_type")]
+ public string NoticeType { get; set; }
+
+ ///
+ /// 自动恢复标识(0否 1是)
+ ///
+ [SugarColumn(ColumnName = "recover_type")]
+ public string RecoverType { get; set; }
+
+ ///
+ /// 报警持续时间(ms)
+ ///
+ [SugarColumn(ColumnName = "continue_time")]
+ public long? ContinueTime { get; set; }
+
+ ///
+ /// 报警状态字
+ ///
+ [SugarColumn(ColumnName = "alarm_status_word")]
+ public string AlarmStatusWord { get; set; }
+
+ ///
+ /// 报警原因
+ ///
+ [SugarColumn(ColumnName = "alarm_reason")]
+ public string AlarmReason { get; set; }
+
+ ///
+ /// 处理建议
+ ///
+ [SugarColumn(ColumnName = "handle_suggest")]
+ public string HandleSuggest { get; set; }
+
+ ///
+ /// 备注
+ ///
+ [SugarColumn(ColumnName = "remark")]
+ public string Remark { get; set; }
+
+ ///
+ /// 创建人
+ ///
+ [SugarColumn(ColumnName = "create_by")]
+ public string CreateBy { get; set; }
+
+ ///
+ /// 创建时间
+ ///
+ [SugarColumn(ColumnName = "create_time")]
+ public DateTime? CreateTime { get; set; }
+
+ ///
+ /// 更新人
+ ///
+ [SugarColumn(ColumnName = "update_by")]
+ public string UpdateBy { get; set; }
+
+ ///
+ /// 更新时间
+ ///
+ [SugarColumn(ColumnName = "update_time")]
+ public DateTime? UpdateTime { get; set; }
+ }
+}
diff --git a/SlnMesnac.Model/domain/DmsRecordAlarmInfo.cs b/SlnMesnac.Model/domain/DmsRecordAlarmInfo.cs
new file mode 100644
index 0000000..1ca674e
--- /dev/null
+++ b/SlnMesnac.Model/domain/DmsRecordAlarmInfo.cs
@@ -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
+ {
+ ///
+ /// 主键标识
+ ///
+ [SugarColumn(ColumnName = "alarm_id", IsPrimaryKey = true, IsIdentity = true)]
+ public long AlarmId { get; set; }
+
+ ///
+ /// 设备台账id,关联dms_base_device_ledger的device_id
+ ///
+ [SugarColumn(ColumnName = "device_id")]
+ public long DeviceId { get; set; }
+
+ ///
+ /// 设备报警规则id,关联dms_base_alarm_rule的alarm_rule_id
+ ///
+ [SugarColumn(ColumnName = "alarm_rule_id")]
+ public long AlarmRuleId { get; set; }
+
+ ///
+ /// 报警开始时间
+ ///
+ [SugarColumn(ColumnName = "alarm_begin_time")]
+ public DateTime? AlarmBeginTime { get; set; }
+
+ ///
+ /// 报警结束时间
+ ///
+ [SugarColumn(ColumnName = "alarm_end_time")]
+ public DateTime? AlarmEndTime { get; set; }
+
+ ///
+ /// 报警持续时间(ms)
+ ///
+ [SugarColumn(ColumnName = "continue_time")]
+ public long? ContinueTime { get; set; }
+
+ ///
+ /// 报警原因
+ ///
+ [SugarColumn(ColumnName = "alarm_reason")]
+ public string AlarmReason { get; set; }
+
+ ///
+ /// 报警数据
+ ///
+ [SugarColumn(ColumnName = "alarm_data")]
+ public string AlarmData { get; set; }
+
+ ///
+ /// 报警状态(0未处理 1人工已处理 2自动恢复)
+ ///
+ [SugarColumn(ColumnName = "alarm_status")]
+ public string AlarmStatus { get; set; }
+
+ ///
+ /// 处理建议
+ ///
+ [SugarColumn(ColumnName = "handle_suggest")]
+ public string HandleSuggest { get; set; }
+
+ ///
+ /// 通知状态(0未通知 1已通知)
+ ///
+ [SugarColumn(ColumnName = "notice_status")]
+ public string NoticeStatus { get; set; }
+
+ ///
+ /// 处理人员
+ ///
+ [SugarColumn(ColumnName = "handle_user")]
+ public string HandleUser { get; set; }
+
+ ///
+ /// 处理时间
+ ///
+ [SugarColumn(ColumnName = "handle_time")]
+ public DateTime? HandleTime { get; set; }
+
+ ///
+ /// 原因分析
+ ///
+ [SugarColumn(ColumnName = "cause_analysis")]
+ public string CauseAnalysis { get; set; }
+
+ ///
+ /// 备注
+ ///
+ [SugarColumn(ColumnName = "remark")]
+ public string Remark { get; set; }
+
+ ///
+ /// 创建人
+ ///
+ [SugarColumn(ColumnName = "create_by")]
+ public string CreateBy { get; set; }
+
+ ///
+ /// 创建时间
+ ///
+ [SugarColumn(ColumnName = "create_time")]
+ public DateTime? CreateTime { get; set; }
+
+ ///
+ /// 更新人
+ ///
+ [SugarColumn(ColumnName = "update_by")]
+ public string UpdateBy { get; set; }
+
+ ///
+ /// 更新时间
+ ///
+ [SugarColumn(ColumnName = "update_time")]
+ public DateTime? UpdateTime { get; set; }
+ }
+}
diff --git a/SlnMesnac.Model/domain/DmsRecordAlarmTime.cs b/SlnMesnac.Model/domain/DmsRecordAlarmTime.cs
new file mode 100644
index 0000000..70e28f7
--- /dev/null
+++ b/SlnMesnac.Model/domain/DmsRecordAlarmTime.cs
@@ -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
+ {
+ ///
+ /// 主键标识
+ ///
+ [SugarColumn(ColumnName = "alarm_id", IsPrimaryKey = true, IsIdentity = true)]
+ public long AlarmId { get; set; }
+
+ ///
+ /// 设备台账id,关联dms_base_device_ledger的device_id
+ ///
+ [SugarColumn(ColumnName = "device_id")]
+ public long DeviceId { get; set; }
+
+ ///
+ /// 设备报警规则id,关联dms_base_alarm_rule的alarm_rule_id
+ ///
+ [SugarColumn(ColumnName = "alarm_rule_id")]
+ public long AlarmRuleId { get; set; }
+
+ ///
+ /// 报警开始时间
+ ///
+ [SugarColumn(ColumnName = "alarm_begin_time")]
+ public DateTime AlarmBeginTime { get; set; }
+
+ ///
+ /// 报警持续时间(ms)
+ ///
+ [SugarColumn(ColumnName = "continue_time")]
+ public long? ContinueTime { get; set; }
+
+ ///
+ /// 报警原因
+ ///
+ [SugarColumn(ColumnName = "alarm_reason")]
+ public string AlarmReason { get; set; }
+
+ ///
+ /// 报警数据
+ ///
+ [SugarColumn(ColumnName = "alarm_data")]
+ public string AlarmData { get; set; }
+
+ ///
+ /// 处理建议
+ ///
+ [SugarColumn(ColumnName = "handle_suggest")]
+ public string HandleSuggest { get; set; }
+
+ ///
+ /// 备注
+ ///
+ [SugarColumn(ColumnName = "remark")]
+ public string Remark { get; set; }
+
+ ///
+ /// 创建人
+ ///
+ [SugarColumn(ColumnName = "create_by")]
+ public string CreateBy { get; set; }
+
+ ///
+ /// 创建时间
+ ///
+ [SugarColumn(ColumnName = "create_time")]
+ public DateTime? CreateTime { get; set; }
+
+ ///
+ /// 更新人
+ ///
+ [SugarColumn(ColumnName = "update_by")]
+ public string UpdateBy { get; set; }
+
+ ///
+ /// 更新时间
+ ///
+ [SugarColumn(ColumnName = "update_time")]
+ public DateTime? UpdateTime { get; set; }
+ }
+}
diff --git a/SlnMesnac.Repository/service/IDmsRecordAlarmTimeService.cs b/SlnMesnac.Repository/service/IDmsRecordAlarmTimeService.cs
new file mode 100644
index 0000000..40e22fc
--- /dev/null
+++ b/SlnMesnac.Repository/service/IDmsRecordAlarmTimeService.cs
@@ -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
+ {
+ ///
+ /// 获取设备各种规则(报警规则id2001-2010)的第一条记录
+ ///
+ ///
+ List GetMachineWarnList();
+
+ }
+}
\ No newline at end of file
diff --git a/SlnMesnac.Repository/service/IDmsRecordShutDownService.cs b/SlnMesnac.Repository/service/IDmsRecordShutDownService.cs
index 458a7bc..86fd027 100644
--- a/SlnMesnac.Repository/service/IDmsRecordShutDownService.cs
+++ b/SlnMesnac.Repository/service/IDmsRecordShutDownService.cs
@@ -7,7 +7,7 @@ namespace SlnMesnac.Repository.service
public interface IDmsRecordShutDownService : IBaseService
{
///
- /// 查询
+ /// 查询每个设备关机记录第一条
///
///
///
diff --git a/SlnMesnac.Repository/service/Impl/DmsRecordAlarmTimeServiceImpl.cs b/SlnMesnac.Repository/service/Impl/DmsRecordAlarmTimeServiceImpl.cs
new file mode 100644
index 0000000..63397a6
--- /dev/null
+++ b/SlnMesnac.Repository/service/Impl/DmsRecordAlarmTimeServiceImpl.cs
@@ -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 保留所有权利。
+* CLR版本:4.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, IDmsRecordAlarmTimeService
+ {
+
+ public DmsRecordAlarmTimeServiceImpl(Repository rep) : base(rep)
+ {
+
+ }
+
+
+ ///
+ /// 获取设备各种规则(报警规则id2001-2010)的第一条记录
+ ///
+ ///
+ public List GetMachineWarnList()
+ {
+ List 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(sql);
+ }catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message);
+ list = null;
+ }
+ return list;
+
+ }
+ }
+}
diff --git a/SlnMesnac.Repository/service/Impl/DmsRecordShutDownServiceImpl.cs b/SlnMesnac.Repository/service/Impl/DmsRecordShutDownServiceImpl.cs
index e3bf3ff..0f60133 100644
--- a/SlnMesnac.Repository/service/Impl/DmsRecordShutDownServiceImpl.cs
+++ b/SlnMesnac.Repository/service/Impl/DmsRecordShutDownServiceImpl.cs
@@ -37,7 +37,7 @@ namespace SlnMesnac.Repository.service.Impl
}
///
- /// 根据托盘编码获取托盘信息
+ /// 查询每个设备关机记录第一条
///
///
///
diff --git a/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs b/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs
index 154d9f0..d06be70 100644
--- a/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs
+++ b/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs
@@ -38,11 +38,15 @@ namespace SlnMesnac.WPF.Page
{
// 设备OEE采集缓存
private List DmsList = null;
+ // 设备报警采集缓存
+ private List WarningList = null;
+
private ISqlSugarClient? sqlClient = null;
private BaseBusiness baseBusiness = null;
private readonly ConfigInfoBusiness _configInfoBusiness;
private readonly IDmsRecordShutDownService dmsRecordShutDownService;
+ private readonly IDmsRecordAlarmTimeService dmsRecordAlarmTimeService;
PlcAbsractFactory plc = null;
int MachineSleep = 1000;
private readonly ILogger _logger;
@@ -56,6 +60,7 @@ namespace SlnMesnac.WPF.Page
{
sqlClient = App.ServiceProvider.GetService();
dmsRecordShutDownService = App.ServiceProvider.GetService();
+ dmsRecordAlarmTimeService = App.ServiceProvider.GetService();
RecipeModeSetWindow.ManualChangeRecipeEvent += ManualChangeRecipe;
_logger = App.ServiceProvider.GetService>();
_configInfoBusiness = App.ServiceProvider.GetService();
@@ -127,7 +132,9 @@ namespace SlnMesnac.WPF.Page
{
Task.Run(() =>
{
+
DmsList = dmsRecordShutDownService.GetAllMachineFirst();
+ WarningList = dmsRecordAlarmTimeService.GetMachineWarnList();
while (true)
{
try
@@ -226,11 +233,76 @@ namespace SlnMesnac.WPF.Page
{
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().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().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("").ToList();
+
}
catch (Exception ex)
{
+ sqlClient.AsTenant().RollbackTran();
_logger.LogError($"OEE设备报警采集异常:{ex.Message}");
}
}
@@ -1402,7 +1474,6 @@ namespace SlnMesnac.WPF.Page
}));
-
MachineStatusDto machineStatusDto = new MachineStatusDto();
machineStatusDto.deviceId = 1017;
machineStatusDto.status = signal0 && signal1;
@@ -1416,6 +1487,9 @@ namespace SlnMesnac.WPF.Page
}
machineStatusDtos.Add(machineStatusDto);
+
+
+
}
catch (Exception ex)
{