You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
4.0 KiB
C#

1 year ago
using Admin.Core.Common;
12 months ago
using Admin.Core.IService;
1 year ago
using Admin.Core.IService.ISys;
12 months ago
using Admin.Core.Model;
using Admin.Core.PlcServer;
using Admin.Core.Service;
1 year ago
using Quartz;
using System;
12 months ago
using System.Collections.Generic;
using System.Linq;
1 year ago
using System.Threading.Tasks;
/// <summary>
/// 这里要注意下,命名空间和程序集是一样的,不然反射不到
/// </summary>
namespace Admin.Core.Tasks
{
public class Job_Admin_Quartz : JobBase, IJob
{
12 months ago
private readonly IPmt_AlarmServices _pmtAlarmServices;
private readonly ILR_AlarmlogServices _lrAlarmlogServices;
public Job_Admin_Quartz(ISysTasksQzService SysTasksQzService, ISysJobLogService sysJobLogService,
IPmt_AlarmServices pmtAlarmServices, ILR_AlarmlogServices lrAlarmlogServices)
1 year ago
{
_SysTasksQzService = SysTasksQzService;
_sysJobLogService = sysJobLogService;
12 months ago
_pmtAlarmServices = pmtAlarmServices;
_lrAlarmlogServices = lrAlarmlogServices;
1 year ago
}
public async Task Execute(IJobExecutionContext context)
{
await ExecuteJob(context, async () => await Run(context));
}
12 months ago
public async Task Run(IJobExecutionContext context)
{
var plcList = PlcHelper.siemensList.SingleOrDefault(d => d.EquipName.Equals("小料PLC"));
if (plcList.plc.IsConnected)
{
List<LR_Alarmlog> addAlarmList = new List<LR_Alarmlog>();
List<LR_Alarmlog> updateAlarmList = new List<LR_Alarmlog>();
List<Pmt_Alarm> list = await _pmtAlarmServices.QueryAsync();
foreach (var item in list)
{
if (plcList.plc.ReadBool(item.Alarm_Point))
{
var alarm = await _lrAlarmlogServices.FirstAsync(d => d.Alarm_ID == item.Alarm_ID);
if (alarm==null)
{
LR_Alarmlog lR_Alarmlog = new LR_Alarmlog();
lR_Alarmlog.Equip_Code = "01";
lR_Alarmlog.Alarm_ID = item.Alarm_ID;
lR_Alarmlog.Alarm_OccurTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
lR_Alarmlog.Alarm_Status = 1;
lR_Alarmlog.Alarm_GUID = "01";
await _lrAlarmlogServices.AddAsync(lR_Alarmlog);
//addAlarmList.Add(lR_Alarmlog);
}
else
{
alarm.Alarm_ClearTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
alarm.Alarm_Status = 1;
await _lrAlarmlogServices.UpdateAsync(alarm);
}
}
else
{
var alarm = await _lrAlarmlogServices.FirstAsync(d => d.Alarm_ID == item.Alarm_ID);
if (alarm == null)
{
LR_Alarmlog lR_Alarmlog = new LR_Alarmlog();
lR_Alarmlog.Equip_Code = "01";
lR_Alarmlog.Alarm_ID = item.Alarm_ID;
lR_Alarmlog.Alarm_OccurTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
lR_Alarmlog.Alarm_Status = 0;
lR_Alarmlog.Alarm_GUID = "01";
await _lrAlarmlogServices.UpdateAsync(lR_Alarmlog);
}
else
{
alarm.Alarm_ClearTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
alarm.Alarm_Status = 0;
await _lrAlarmlogServices.UpdateAsync(alarm);
}
}
}
}
1 year ago
}
}
}