| | |
| | | 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 WIDESEA_Model.Models.WMSInfo; |
| | | using static WIDESEA_DTO.SquareCabin.AlarmDto; |
| | | using static WIDESEA_DTO.SquareCabin.TowcsDto; |
| | | |
| | | namespace WIDESEA_WMsInfoServices |
| | | { |
| | | public class EquipmentAlarmInforService : ServiceBase<Dt_EquipmentAlarmInfor, IRepository<Dt_EquipmentAlarmInfor>>, IEquipmentAlarmInforService |
| | | { |
| | | public EquipmentAlarmInforService(IRepository<Dt_EquipmentAlarmInfor> BaseDal) : base(BaseDal) |
| | | private readonly IMessageInfoService _messageInfoService; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | |
| | | public EquipmentAlarmInforService(IRepository<Dt_EquipmentAlarmInfor> 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<AGVResponse<DeviceStatusData>>(result); |
| | | if (response == null || response.code != "0" || response.data == null) return content.Error($"è·å设å¤ä¿¡æ¯å¤±è´¥: {response?.msg}"); |
| | | List<string> codes = new List<string>(); |
| | | if (response.data.robot.Count < 1 || response.data.sorters.Count < 0) return content.Error($"è·å设å¤ä¿¡æ¯ä¸ºç©º: {response?.msg}"); |
| | | |
| | | //public WebResponseContent getDeviceStatus(string? deviceCode) |
| | | //{ |
| | | // try |
| | | // { |
| | | // var url = "http://172.16.1.2:9357/cube/taskInfo/getDeviceStatus"; |
| | | // å¤çæºå¨äººè®¾å¤æ°æ® |
| | | codes.AddRange(response.data.robot.Select(x => x.robotCode).ToList()); |
| | | |
| | | // // è°ç¨WCSæ¥å£è·å设å¤ç¶æ |
| | | // var result = HttpHelper.Get(url + (string.IsNullOrEmpty(deviceCode) ? "" : $"?deviceCode={deviceCode}")); |
| | | // var response = JsonConvert.DeserializeObject<TowcsResponse<DeviceStatusData>>(result); |
| | | // å¤ç忣å°è®¾å¤æ°æ® |
| | | codes.AddRange(response.data.sorters.Select(x => x.sorterCode).ToList()); |
| | | |
| | | // // æ£æ¥æ¥å£ååºæ¯å¦æå |
| | | // if (response == null || response.code != "0") |
| | | // { |
| | | // return new WebResponseContent { Status = false, Message = $"WCSæ¥å£è°ç¨å¤±è´¥: {response?.msg}" }; |
| | | // } |
| | | if (codes.Count < 1) return content; |
| | | List<Dt_EquipmentAlarmInfor> equipmentAlarmInfors = BaseDal.QueryData(x => codes.Contains(x.RobotCode)); |
| | | List<Dt_EquipmentAlarmInfor> equipmentAlarmInforsAdd = new List<Dt_EquipmentAlarmInfor>(); |
| | | List<Dt_EquipmentAlarmInfor> equipmentAlarmInforsUp = new List<Dt_EquipmentAlarmInfor>(); |
| | | 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.sorterCode; |
| | | 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.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; |
| | | } |
| | | |
| | | // var syncTime = DateTime.Now; |
| | | // var saveCount = 0; |
| | | |
| | | // // å¤çæºå¨äººè®¾å¤æ°æ® |
| | | // if (response.data?.robot != null && response.data.robot.Any()) |
| | | // { |
| | | // foreach (var robot in response.data.robot) |
| | | // { |
| | | // // æ ¹æ®è®¾å¤ç¼ç æ¥è¯¢æ¯å¦åå¨è®°å½ |
| | | // var existingRecord = BaseDal.QueryData(x => x.RobotCode == robot.robotCode).FirstOrDefault(); |
| | | |
| | | // if (existingRecord == null) |
| | | // { |
| | | // // å建æ°è®°å½ |
| | | // var newRecord = new Dt_EquipmentAlarmInfor |
| | | // { |
| | | // RobotName = robot.robotName, |
| | | // RobotCode = robot.robotCode, |
| | | // Status = robot.status, |
| | | // SyncTime = syncTime, |
| | | // CreateDate = syncTime, |
| | | // Creater = "System" |
| | | // }; |
| | | // BaseDal.AddData(newRecord); |
| | | // } |
| | | // else |
| | | // { |
| | | // // æ´æ°ç°æè®°å½ |
| | | // existingRecord.RobotName = robot.robotName; |
| | | // existingRecord.Status = robot.status; |
| | | // existingRecord.SyncTime = syncTime; |
| | | // existingRecord.ModifyDate = syncTime; |
| | | // existingRecord.Modifier = "System"; |
| | | // BaseDal.UpdateData(existingRecord); |
| | | // } |
| | | // saveCount++; |
| | | // } |
| | | // } |
| | | |
| | | // // å¤ç忣å°è®¾å¤æ°æ® |
| | | // if (response.data?.sorters != null && response.data.sorters.Any()) |
| | | // { |
| | | // foreach (var sorter in response.data.sorters) |
| | | // { |
| | | // // æ ¹æ®è®¾å¤ç¼ç æ¥è¯¢æ¯å¦åå¨è®°å½ |
| | | // var existingRecord = BaseDal.QueryData(x => x.RobotCode == sorter.sorterCode).FirstOrDefault(); |
| | | |
| | | // if (existingRecord == null) |
| | | // { |
| | | // // å建æ°è®°å½ |
| | | // var newRecord = new Dt_EquipmentAlarmInfor |
| | | // { |
| | | // RobotName = sorter.sorterName, |
| | | // RobotCode = sorter.sorterCode, |
| | | // Status = sorter.status, |
| | | // SyncTime = syncTime, |
| | | // CreateDate = syncTime, |
| | | // Creater = "System" |
| | | // }; |
| | | // BaseDal.AddData(newRecord); |
| | | // } |
| | | // else |
| | | // { |
| | | // // æ´æ°ç°æè®°å½ |
| | | // existingRecord.RobotName = sorter.sorterName; |
| | | // existingRecord.Status = sorter.status; |
| | | // existingRecord.SyncTime = syncTime; |
| | | // existingRecord.ModifyDate = syncTime; |
| | | // existingRecord.Modifier = "System"; |
| | | // BaseDal.UpdateData(existingRecord); |
| | | // } |
| | | // saveCount++; |
| | | // } |
| | | // } |
| | | |
| | | // //// è¿åç¶æç»è®¡ä¿¡æ¯ |
| | | // //var stateStats = response.data?.stateStatistics; |
| | | // //var statsInfo = stateStats != null ? |
| | | // // $"å¯ç¨:{stateStats.enable}, å
çµ:{stateStats.charging}, ä¸å¯ç¨:{stateStats.disabled}, é误:{stateStats.error}, 离åº:{stateStats.down}, å ç¨:{stateStats.occupied}" |
| | | // // : "æ ç»è®¡ä¿¡æ¯"; |
| | | |
| | | // return new WebResponseContent |
| | | // { |
| | | // Status = true, |
| | | // Message = $"忥æåï¼å
±å¤ç {saveCount} æ¡è®¾å¤è®°å½ãç¶æç»è®¡: {statsInfo}" |
| | | // }; |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // // è®°å½è¯¦ç»é误æ¥å¿ |
| | | // Console.WriteLine($"è·å设å¤ç¶æå¼å¸¸: {ex.Message}, StackTrace: {ex.StackTrace}"); |
| | | |
| | | // return new WebResponseContent |
| | | // { |
| | | // Status = false, |
| | | // Message = $"è·å设å¤ç¶æå¤±è´¥: {ex.Message}" |
| | | // }; |
| | | // } |
| | | //} |
| | | |
| | | } |
| | | } |
| | | } |