using HslCommunication; using Newtonsoft.Json; using Quartz.Util; using System; using System.Collections.Generic; using System.Linq; using System.Security.Policy; using System.Text; using System.Threading.Tasks; using WIDESEA_Common; using WIDESEA_Core; using WIDESEA_Core.BaseRepository; using WIDESEA_Core.BaseServices; using WIDESEA_Core.Helper; using WIDESEA_IWMsInfoServices; using WIDESEA_Model.Models; using static WIDESEA_DTO.SquareCabin.AlarmDto; using static WIDESEA_DTO.SquareCabin.TowcsDto; namespace WIDESEA_WMsInfoServices { public class EquipmentAlarmInforService : ServiceBase>, IEquipmentAlarmInforService { private readonly IMessageInfoService _messageInfoService; private readonly IUnitOfWorkManage _unitOfWorkManage; public EquipmentAlarmInforService(IRepository BaseDal, IMessageInfoService messageInfoService, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal) { _messageInfoService = messageInfoService; _unitOfWorkManage = unitOfWorkManage; } public WebResponseContent getDeviceStatus() { WebResponseContent content = new WebResponseContent(); try { var url = "http://172.16.1.2:8080/cube/taskInfo/getDeviceStatus?token=wH5zdAUCv2BEHJIinmowyki8cdc5ge8fAwFDcYZs0bVldNgmORt0O0l4GJTDv1dglRdMxb9xDK5Qb3NJAqL1Li2GkfdVa3KnIkfrQZtsP7UXhMmUz6xEuztG6d5svAJO9HENLb8JWVqCfpO2EWV6ebo/g5tJ9x7kbwwAxvCBrWdiEJv09FvaRQ== "; var result = HttpHelper.Get(url); var response = JsonConvert.DeserializeObject>(result); if (response == null || response.code != "0" || response.data == null) return content.Error($"获取设备信息失败: {response?.msg}"); List codes = new List(); if (response.data.robot.Count < 1 || response.data.sorters.Count < 0) return content.Error($"获取设备信息为空: {response?.msg}"); // 处理机器人设备数据 codes.AddRange(response.data.robot.Select(x => x.robotCode).ToList()); // 处理分拣台设备数据 codes.AddRange(response.data.sorters.Select(x => x.sorterCode).ToList()); if (codes.Count < 1) return content; List equipmentAlarmInfors = BaseDal.QueryData(x => codes.Contains(x.RobotCode)); if (equipmentAlarmInfors.Count < 1) return content; List equipmentAlarmInforsAdd = new List(); List equipmentAlarmInforsUp = new List(); foreach (var item in response.data.robot) { Dt_EquipmentAlarmInfor? equipmentAlarmInfor = equipmentAlarmInfors.Where(x => x.RobotCode == item.robotCode).FirstOrDefault(); if (equipmentAlarmInfor == null) { equipmentAlarmInfor = new Dt_EquipmentAlarmInfor() { RobotCode = item.robotCode, RobotName = item.robotName, Status = item.status, SyncTime = DateTime.Now, CreateDate = DateTime.Now, }; equipmentAlarmInforsAdd.Add(equipmentAlarmInfor); } else { equipmentAlarmInfor.RobotName = item.robotName; equipmentAlarmInfor.Status = item.status; equipmentAlarmInfor.SyncTime = DateTime.Now; equipmentAlarmInforsUp.Add(equipmentAlarmInfor); } if (string.Equals(item.status, nameof(DeviceStatus.Error), StringComparison.OrdinalIgnoreCase)) { _messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm, "小车编号" + item.robotCode, item.status); } } foreach (var item in response.data.sorters) { Dt_EquipmentAlarmInfor? equipmentAlarmInfor = equipmentAlarmInfors.Where(x => x.RobotCode == item.sorterCode).FirstOrDefault(); if (equipmentAlarmInfor == null) { equipmentAlarmInfor = new Dt_EquipmentAlarmInfor() { RobotCode = item.sorterCode, RobotName = item.sorterName, Status = item.status, SyncTime = DateTime.Now, CreateDate = DateTime.Now, }; equipmentAlarmInforsAdd.Add(equipmentAlarmInfor); } else { equipmentAlarmInfor.RobotName = item.sorterName; equipmentAlarmInfor.Status = item.status; equipmentAlarmInfor.SyncTime = DateTime.Now; equipmentAlarmInforsUp.Add(equipmentAlarmInfor); } if (string.Equals(item.status, nameof(DeviceStatus.Error), StringComparison.OrdinalIgnoreCase)) { _messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm, "分拣台b编码" + item.sorterCode, item.status); } } if (equipmentAlarmInforsAdd.Count > 0) BaseDal.AddData(equipmentAlarmInforsAdd); if (equipmentAlarmInforsUp.Count > 0) BaseDal.UpdateData(equipmentAlarmInforsUp); } catch (Exception ex) { content.Error(ex.Message); } return content; } } }