using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using OfficeOpenXml.FormulaParsing.Excel.Functions.Numeric; using WIDESEAWCS_Core; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_QuartzJob.Models; using WIDESEAWCS_QuartzJob.Repository; using WIDESEAWCS_Tasks.ElevatorJob; using WIDESEAWCS_Tasks.StackerCraneJob; namespace WIDESEAWCS_Server.Controllers.Task { [Route("/api/EquipmentStatus")] [ApiController] public class EquipmentStatusController : ControllerBase { private readonly IDeviceInfoRepository _deviceInfoRepository; public EquipmentStatusController(IDeviceInfoRepository deviceInfoRepository) { _deviceInfoRepository = deviceInfoRepository; } [HttpGet, HttpPost, Route("GetData"), AllowAnonymous] public WebResponseContent GetData() { WebResponseContent content = new WebResponseContent(); try { List equipments = new List(); List dt_DeviceInfos = _deviceInfoRepository.QueryData(); if(dt_DeviceInfos.Count() > 0) { foreach(var item in dt_DeviceInfos) { Equipment equipment = new Equipment(); if (item.DeviceCode == "1001") continue; if (item.DeviceCode == "TSJ2") continue; equipment.DeviceCode = item.DeviceCode; equipment.DeviceName = item.DeviceName; equipment.DeviceType = item.DeviceType; equipments.Add(equipment); } } else { return content.Error("未查询到设备!!"); } CommonElevator? commonElevator = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "TSJ1") as CommonElevator; CommonStackerCrane? commonStackerCrane = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "SC1") as CommonStackerCrane; foreach (var item in equipments) { if(item.DeviceCode == "TSJ1") { if (commonElevator.GetValue(ElevatorDBName.ElevatorStatus) == 0) { item.DeviceRunStatus = "无状态"; } else if(commonElevator.GetValue(ElevatorDBName.ElevatorStatus) == 1) { item.DeviceRunStatus = "运行中"; } else if (commonElevator.GetValue(ElevatorDBName.ElevatorStatus) == 2) { item.DeviceRunStatus = "待机"; } else { item.DeviceRunStatus = "报警"; } if(commonElevator.GetValue(ElevatorDBName.ElevatorAlarm1)) { item.AlarmInformation = "急停被按下报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm2)) { item.AlarmInformation = "电梯内输送线电机过载报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm3)) { item.AlarmInformation = "地面输送线电机过载报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm4)) { item.AlarmInformation = "电梯系统异常报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm5)) { item.AlarmInformation = "初始化时设备上有货物报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm6)) { item.AlarmInformation = "一层输送线AGV放货异常报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm7)) { item.AlarmInformation = "一层光幕检测到物体报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm8)) { item.AlarmInformation = "二层光幕检测到物体报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm9)) { item.AlarmInformation = "二层输送线AGV放货异常报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm10)) { item.AlarmInformation = "一层电梯对准光电未检测到报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm11)) { item.AlarmInformation = "二层电梯对准光电未检测到报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm12)) { item.AlarmInformation = "有货物在一层输送线上报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm13)) { item.AlarmInformation = "AGV一层取货异常报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm14)) { item.AlarmInformation = "AGV二层取货异常报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm15)) { item.AlarmInformation = "有货物在二层输送线上报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm16)) { item.AlarmInformation = "电梯不在1楼报警"; } if (commonElevator.GetValue(ElevatorDBName.ElevatorAlarm17)) { item.AlarmInformation = "电梯不在2楼报警"; } } if (item.DeviceCode == "SC1") { var alarm = commonStackerCrane.GetValue(StackerCraneDBName.Alarm); if(StackerCraneAlarm(alarm) != null) { item.AlarmInformation = StackerCraneAlarm(alarm); } var status = commonStackerCrane.GetValue(StackerCraneDBName.StackerCraneWorkStatus); if(StackerCraneStatus(status) != null) { item.DeviceRunStatus = StackerCraneStatus(status); } } } content = WebResponseContent.Instance.OK(data: equipments); } catch(Exception ex) { return content.Error(ex.Message); } return content; } public class Equipment { public string DeviceCode { get; set; } public string DeviceName { get; set; } public string DeviceType { get; set; } public string DeviceRunStatus { get; set; } public string AlarmInformation {get; set;} } #region 报警代码转换成文字说明 public string StackerCraneAlarm(short alarm) => alarm switch { 1 => "左超限", 2 => "右超限", 3 => "前超限", 4 => "后超限", 5 => "高超限", 6 => "取货载货台有货", 7 => "放货载货台无货", 8 => "取货左货格无货", 9 => "取货右货格无货", 10 => "放货左一有货", 11 => "放货右一有货", 12 => "取左二货格无货", 13 => "取右二货格无货", 14 => "放货左二货格有货", 15 => "放货右二货格有货", 16 => "左二取货左一有货", 17 => "右二取货右一有货", 18 => "左取货失败", 19 => "右取货失败", 20 => "左放货失败", 21 => "右放货失败", 22 => "货叉运行超时", 23 => "货叉断路器跳闸", 24 => "货叉变频器报警", 25 => "货叉编码器故障", 26 => "货叉伸叉故障", 27 => "层运行货叉不在中位", 28 => "列运行货叉不在中位", 29 => "货叉中位开关故障", 30 => "货叉变频器通讯故障", 31 => "货叉编码器通讯故障", 32 => "伸叉超出左极限", 33 => "伸又超出右极限", 34 => "入左二货格货时左一货格有货", 35 => "入右二货格货时右一货格有货", 36 => "货叉右侧回中停止位置错误", 37 => "货叉左侧回中停止位置错误", 38 => "货叉左侧极限停止位置错误", 39 => "货叉右侧极限停止位置错误", 40 => "面板急停", 41 => "远程急停", 42 => "主接触器控制回路故障", 43 => "超重保护", 44 => "松绳保护", 45 => "限速保护", 46 => "层停止位置错误", 47 => "列停止位置错误", 48 => "接收任务错误", 49 => "接收列超限", 50 => "接收层超限", 51 => "行走前进极限", 52 => "行走后退极限", 53 => "提升上极限", 54 => "提升下极限", 55 => "行走运行超时", 56 => "提升运行超时", 57 => "行走断路器跳闸", 58 => "提升断路器跳闸", 59 => "行走变频器故障", 60 => "提升变频器故障", 61 => "行走测距/条码故障", 62 => "提升测距/条码故障", 63 => "行走测距/条码被挡", 64 => "提升测距/条码被挡", 65 => "上升减速光电故障", 66 => "下降减速光电故障", 67 => "提升原点光电故障", 68 => "行走前减速光电故障", 69 => "行走后减速光电故障", 70 => "行走原点光电故障", 71 => "与输送机通讯故障", 72 => "升降超出最小层", 73 => "升降超出最大层", 74 => "行走超出最小列", 75 => "行走超出最大列", 76 => "接收排错误", 77 => "起始站货格被禁用", 78 => "目的站货格被禁用", 79 => "行走抱闸故障", 80 => "提升抱闸故障", 81 => "安全门打开故障", _ => "" }; #endregion #region 设备状态转换成文字说明 public string StackerCraneStatus(short status) => status switch { 0 => "空闲", 1 => "取货走行", 2 => "取货等待", 3 => "取货中", 4 => "放货走行", 5 => "放货等待", 6 => "放货中", 7 => "回原点", 8 => "回反原点", 9 => "走行中", 10 => "任务完成等待WCS确认", 11 => "有货待命", 99 => "报警", 100 => "维护", _ => $"未知状态({status})" }; #endregion } }