add-添加设备OEE关机时间采集

dev
liuwf 3 months ago
parent 187c169240
commit c264ad3daa

@ -0,0 +1,103 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Model.domain
* a4dbd270-62c5-47db-a5f7-7e7cb895d15a
*
* WenJY
* wenjy@mesnac.com
* 2024-04-07 16:55:22
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Model.domain
{
/// <summary>
/// 设备停机记录
///</summary>
[SugarTable("dms_record_shut_down"), TenantAttribute("mes")]
public class DmsRecordShutDown
{
/// <summary>
/// 主键标识;scada上报的记录
///</summary>
[SugarColumn(ColumnName = "record_shut_down_id", IsPrimaryKey = true, IsIdentity = true)]
public int RecordShutDownId { get; set; }
/// <summary>
/// 设备ID关联dms_base_device_ledger的device_id
///</summary>
[SugarColumn(ColumnName = "device_id")]
public int DeviceId { get; set; }
/// <summary>
/// 停机类型ID关联dm_base_shut_type的shut_type_id
///</summary>
[SugarColumn(ColumnName = "shut_type")]
public int? ShutType { get; set; }
/// <summary>
/// 停机原因
///</summary>
[SugarColumn(ColumnName = "shut_reason")]
public string? ShutReason { get; set; }
/// <summary>
/// 停机开始时间
///</summary>
[SugarColumn(ColumnName = "shut_begin_time")]
public DateTime? ShutBeginTime { get; set; }
/// <summary>
/// 停机结束时间
///</summary>
[SugarColumn(ColumnName = "shut_end_time")]
public DateTime? ShutEndTime { get; set; }
/// <summary>
/// 停机时长
///</summary>
[SugarColumn(ColumnName = "shut_time")]
public Decimal? ShutTime { get; set; }
/// <summary>
/// 是否标识1-是2-否
///</summary>
[SugarColumn(ColumnName = "is_flag")]
public int IsFlag { 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,40 @@
using System.ComponentModel;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Model.enums
* dd489bb9-a90d-4552-82c6-289eb7dfe64e
*
* WenJY
* wenjy@mesnac.com
* 2024-04-08 13:30:10
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Model.enums
{
public enum WarnStatusEnum
{
[Description("0")]
,
[Description("1")]
,
[Description("2")]
,
}
}

@ -357,5 +357,10 @@ namespace SlnMesnac.Plc.Factory
{
throw new NotImplementedException();
}
public override bool writeByteByAddress(string address, int value)
{
throw new NotImplementedException();
}
}
}

@ -298,5 +298,10 @@ namespace SlnMesnac.Plc.Factory
{
throw new NotImplementedException();
}
public override bool writeByteByAddress(string address, int value)
{
throw new NotImplementedException();
}
}
}

@ -301,5 +301,10 @@ namespace SlnMesnac.Plc.Factory
{
throw new NotImplementedException();
}
public override bool writeByteByAddress(string address, int value)
{
throw new NotImplementedException();
}
}
}

@ -0,0 +1,18 @@
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System.Collections.Generic;
namespace SlnMesnac.Repository.service
{
public interface IDmsRecordShutDownService : IBaseService<DmsRecordShutDown>
{
/// <summary>
/// 查询
/// </summary>
/// <param name="palleCode"></param>
/// <returns></returns>
List<DmsRecordShutDown> GetAllMachineFirst();
}
}

@ -0,0 +1,63 @@
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Repository.service.Impl
* 2ef6cbc3-f5ce-4d6a-9750-06aac8227b6f
*
* WenJY
* wenjy@mesnac.com
* 2024-04-07 16:57:02
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Repository.service.Impl
{
public class DmsRecordShutDownServiceImpl : BaseServiceImpl<DmsRecordShutDown>, IDmsRecordShutDownService
{
public DmsRecordShutDownServiceImpl(Repository<DmsRecordShutDown> rep):base(rep)
{
}
/// <summary>
/// 根据托盘编码获取托盘信息
/// </summary>
/// <param name="palleCode"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public List<DmsRecordShutDown> GetAllMachineFirst()
{
List<DmsRecordShutDown> 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_shut_down WHERE device_id IN (1016, 1017, 1018, 1019, 1020)) SELECT * FROM RankedRecords WHERE rn = 1;";
list = base._rep.Context.Ado.SqlQuery<DmsRecordShutDown>(sql);
return list;
}
catch (Exception e)
{
return list;
}
}
}
}

@ -0,0 +1,29 @@
using SlnMesnac.Model.enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.WPF.Dto
{
/// <summary>
/// 存储数据采集状态及报警信息
/// </summary>
public class MachineStatusDto
{
//设备ID
public int deviceId { get; set; }
//设备运行状态
public bool status { get; set; }
//报警类型
// public WarnStatusEnum warnStatus { get; set; } = WarnStatusEnum.无报警;
}
}

@ -4,7 +4,10 @@ using Newtonsoft.Json.Linq;
using SlnMesnac.Business;
using SlnMesnac.Business.@base;
using SlnMesnac.Model.domain;
using SlnMesnac.Model.enums;
using SlnMesnac.Plc;
using SlnMesnac.Repository.service;
using SlnMesnac.WPF.Dto;
using SlnMesnac.WPF.Model;
using SlnMesnac.WPF.ViewModel;
using System;
@ -32,8 +35,13 @@ namespace SlnMesnac.WPF.Page
/// </summary>
public partial class DevMonitorPage : UserControl
{
// 设备OEE采集缓存
private List<DmsRecordShutDown> DmsList = null;
private BaseBusiness baseBusiness = null;
private readonly ConfigInfoBusiness _configInfoBusiness;
private readonly IDmsRecordShutDownService dmsRecordShutDownService;
PlcAbsractFactory plc = null;
int MachineSleep = 1000;
private readonly ILogger<DevMonitorPage> _logger;
@ -45,6 +53,7 @@ namespace SlnMesnac.WPF.Page
public DevMonitorPage()
{
dmsRecordShutDownService = App.ServiceProvider.GetService<IDmsRecordShutDownService>();
RecipeModeSetWindow.ManualChangeRecipeEvent += ManualChangeRecipe;
_logger = App.ServiceProvider.GetService<ILogger<DevMonitorPage>>();
_configInfoBusiness = App.ServiceProvider.GetService<ConfigInfoBusiness>();
@ -120,13 +129,22 @@ namespace SlnMesnac.WPF.Page
{
try
{
DmsList = dmsRecordShutDownService.GetAllMachineFirst();
List<MachineStatusDto> machineStatusDtos = new List<MachineStatusDto>();
Thread.Sleep(2000);
if (plc != null)
{
RefreshMagNet();
RefreshSpiral();
RefreshHot();
RefreshUnPack();
lock (string.Empty)
{
RefreshMagNet(machineStatusDtos);
RefreshSpiral(machineStatusDtos);
RefreshHot(machineStatusDtos);
RefreshUnPack(machineStatusDtos);
//开关机时间采集
machineStatusDtos.ForEach(x => OeeCollection(x));
}
}
else
{
@ -148,6 +166,52 @@ namespace SlnMesnac.WPF.Page
});
}
/// <summary>
/// OEE设备关机采集
/// </summary>
/// <param name="machineStatusDto"></param>
private void OeeCollection(MachineStatusDto machineStatusDto)
{
try
{
#region 设备OEE关机采集
DmsRecordShutDown? record = DmsList.FirstOrDefault(x => x.DeviceId == machineStatusDto.deviceId);
if (!machineStatusDto.status) // 关机
{
if (record == null || record.ShutEndTime != null)
{
DmsRecordShutDown newRecord = new DmsRecordShutDown();
newRecord.DeviceId = machineStatusDto.deviceId;
newRecord.ShutType = 1;
newRecord.ShutReason = "正常停机";
newRecord.ShutBeginTime = DateTime.Now;
newRecord.CreateBy = "SlnMesnac";
newRecord.CreateTime = DateTime.Now;
dmsRecordShutDownService.Insert(newRecord);
//更新本地缓存
DmsList = dmsRecordShutDownService.GetAllMachineFirst();
}
}
else //开机
{
if (record != null && record.ShutEndTime == null) //有关机记录,且未结束
{
record.ShutEndTime = DateTime.Now;
record.ShutTime = record.ShutTime = (decimal)(record.ShutEndTime - record.ShutBeginTime).Value.TotalMilliseconds;
record.UpdateTime = DateTime.Now;
record.UpdateBy = "SlnMesnac";
dmsRecordShutDownService.Update(record);
//更新本地缓存
DmsList = dmsRecordShutDownService.GetAllMachineFirst();
}
}
#endregion
}catch(Exception ex)
{
_logger.LogError($"OEE设备关机采集异常:{ex.Message}");
}
}
#region 监测缓存区重量,动态调整配方频率
/// <summary>
/// 开始启动监测缓存区重量,动态调整配方频率
@ -1224,7 +1288,7 @@ namespace SlnMesnac.WPF.Page
/// <summary>
/// 拆包机参数监控
/// </summary>
private async void RefreshUnPack()
private async void RefreshUnPack(List<MachineStatusDto> machineStatusDtos)
{
try
{
@ -1266,6 +1330,11 @@ namespace SlnMesnac.WPF.Page
UnpackStatus13.Text = unPackStatus13.ToString("F2");
MachineStatusDto machineStatusDto = new MachineStatusDto();
machineStatusDto.deviceId = 1016;
machineStatusDto.status = unPackStatus1;
machineStatusDtos.Add(machineStatusDto);
}));
}
catch (Exception ex)
@ -1280,7 +1349,7 @@ namespace SlnMesnac.WPF.Page
/// <summary>
/// 磁选机参数监控
/// </summary>
private async void RefreshMagNet()
private async Task RefreshMagNet(List<MachineStatusDto> machineStatusDtos)
{
try
{
@ -1288,6 +1357,7 @@ namespace SlnMesnac.WPF.Page
bool signal1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机磁选启动"));
bool signal2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机MES允许远程"));
bool signal3 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机设备故障反馈"));
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
MagNetStatus1.Fill = signal0 ? Brushes.Green : Brushes.Red;
@ -1296,6 +1366,17 @@ namespace SlnMesnac.WPF.Page
MagNetStatus4.Fill = signal3 ? Brushes.Red : Brushes.Green;
}));
MachineStatusDto machineStatusDto = new MachineStatusDto();
machineStatusDto.deviceId = 1017;
machineStatusDto.status = signal0 && signal1;
//if (signal3)
//{
// machineStatusDto.warnStatus = WarnStatusEnum.磁选机设备故障;
//}
machineStatusDtos.Add(machineStatusDto);
}
catch (Exception ex)
{
@ -1307,7 +1388,7 @@ namespace SlnMesnac.WPF.Page
/// <summary>
/// 螺旋机参数监控
/// </summary>
private async void RefreshSpiral()
private async void RefreshSpiral(List<MachineStatusDto> machineStatusDtos)
{
try
{
@ -1343,6 +1424,14 @@ namespace SlnMesnac.WPF.Page
SpiralSignal7_Value.Text = speed2.ToString();
}));
MachineStatusDto machineStatusDto = new MachineStatusDto();
machineStatusDto.deviceId = 1018;
machineStatusDto.status = signal2&& signal3;
machineStatusDtos.Add(machineStatusDto);
}
catch (Exception ex)
{
@ -1357,7 +1446,7 @@ namespace SlnMesnac.WPF.Page
/// <summary>
/// 烘干机参数监控
/// </summary>
private async void RefreshHot()
private async void RefreshHot(List<MachineStatusDto> machineStatusDtos)
{
try
{
@ -1409,6 +1498,11 @@ namespace SlnMesnac.WPF.Page
HotSignal7_2_Value.Text = ChangeHotWarn(signal7_2);
MachineStatusDto machineStatusDto = new MachineStatusDto();
machineStatusDto.deviceId = 1019;
machineStatusDto.status = signal1_2 && signal2_2;
machineStatusDtos.Add(machineStatusDto);
}));
}
catch (Exception ex)

Loading…
Cancel
Save