using HslCommunication.WebSocket; using Newtonsoft.Json; using Quartz; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEAWCS_Core.HttpContextUser; using WIDESEAWCS_Core; using WIDESEAWCS_ITaskInfoService; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_TelescopicService; using WIDESEAWCS_ISystemServices; namespace WIDESEAWCS_Tasks { [DisallowConcurrentExecution] public class AlarmResetJob : JobBase, IJob { private readonly IAlarmResetHsyServer _alarmResetHsyServer; private readonly ISys_UserService _UserService; WebSocketServer _webSocketServer; public AlarmResetJob(WebSocketServer webSocketServer, IAlarmResetHsyServer alarmResetHsyServer, ISys_UserService UserService) { _webSocketServer = webSocketServer; _alarmResetHsyServer = alarmResetHsyServer; _UserService = UserService; } public Task Execute(IJobExecutionContext context) { try { //获取设备号 // 获取全部设备配置 OtherDevice serialPortDevice = (OtherDevice)context.JobDetail.JobDataMap.Get("JobParams"); if (serialPortDevice!=null) { HandleAlarm(serialPortDevice); } var alarmInfo = _alarmResetHsyServer.GetWebSocketInfo(); _webSocketServer.PublishAllClientPayload(JsonConvert.SerializeObject(alarmInfo)); } catch (Exception ex) { Console.WriteLine("错误信息:" + ex.Message); Console.WriteLine(ex.StackTrace); } return Task.CompletedTask; } private void HandleAlarm(OtherDevice device) { try { var stuck = device.Communicator.Read("M104");//伸缩杆报警//默认是false var other = device.Communicator.Read("M105");//其他报警 //默认是false Console.WriteLine($"{device.DeviceName}:卡住报警的默认值为{stuck},其他报警的默认值为{other}"); string location = device.DeviceCode switch { "SSG001" => "轨道一-左", "SSG002" => "轨道一-右", "SSG003" => "轨道二-左", "SSG004" => "轨道二-右", "SSG005" => "轨道三-左", "SSG006" => "轨道三-右", "SSG007" => "轨道四-左", "SSG008" => "轨道四-右", "SSG009" => "轨道五-左", "SSG0010" => "轨道五-右", // 依此类推... _ => $"未知设备({device.DeviceCode})" }; if (stuck && !other) { var alarm= _alarmResetHsyServer.AddAlarmHsy($"{location}:伸缩杆卡住报警", stuck); Console.WriteLine($"{location}:伸缩杆卡住报警", stuck); } else if (!stuck && other) { var alarm = _alarmResetHsyServer.AddAlarmHsy($"{location}:其他报警", other); Console.WriteLine($"{location}:其他报警", other); } else if (stuck && other) { var alarm= _alarmResetHsyServer.AddAlarmHsy($"{location}:伸缩杆卡住报警和其他报警", other); Console.WriteLine($"{location}:伸缩杆卡住报警和其他报警", other); } } catch (Exception ex) { Console.WriteLine($"设备 {device.DeviceCode} 处理异常:" + ex.Message); } } } }