@ -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 )
{
{