瀏覽代碼

更新设备监控接口

oyq28 2 年之前
父節點
當前提交
e73ad23d7e
共有 1 個文件被更改,包括 16 次插入16 次删除
  1. 16 16
      IMCS_CCS/Service/Impl/TaskJobService.cs

+ 16 - 16
IMCS_CCS/Service/Impl/TaskJobService.cs

@@ -1250,7 +1250,7 @@ namespace IMCS.CCS.Service.Impl
                 }
 
                 List<EquipmentMonitor> equipmentMonitors = new List<EquipmentMonitor>();
-                string equipment_monitors_redis_key = imcs_redis_key + RedisKeyEnum.MonitorEquipmentStatusJob; ;
+                string equipment_monitors_redis_key = imcs_redis_key + RedisKeyEnum.MonitorEquipmentStatusJob;
                 var data = await _redisService.Database.StringGetAsync(equipment_monitors_redis_key);
                 if (data.IsNullOrEmpty)
                 {
@@ -1310,7 +1310,7 @@ namespace IMCS.CCS.Service.Impl
                         }
                         else
                         {
-                            tagValues = JsonConvert.DeserializeObject<List<CcsTagValue>>(data);
+                            tagValues = JsonConvert.DeserializeObject<List<CcsTagValue>>(tagData);
                         }
                         CcsTagValue ccsTagValue = tagValues.Where(x => x.Ip == equipment.IP && x.Address == equipment.Address).FirstOrDefault();
                         if (ccsTagValue != null)
@@ -1383,16 +1383,16 @@ namespace IMCS.CCS.Service.Impl
                     await _equipmentMonitorService.UpdateAndCache(equipmentMonitors); 
                 }
                 //在线设备,报警放入推送数组
-                List<Device> onlineDeviceList = await getDeviceList();
-                foreach (Device device in onlineDeviceList)
-                {
-                    EquipmentMonitor alarmEquipment = equipmentMonitors.Where(x => x.IP == device.Ip && x.Type == device.ProtocolType).FirstOrDefault(); 
+                List<Device> onlineDeviceList = await getDeviceList(); 
+                foreach (Device onlineDevice in onlineDeviceList)
+                    {
+                    EquipmentMonitor alarmEquipment = equipmentMonitors.Where(x => x.IP == onlineDevice.Ip && x.Type == onlineDevice.ProtocolType).FirstOrDefault(); 
 
-                    if (alarmEquipment.Type == "HEIDEHAIN")
+                    if (alarmEquipment != null && alarmEquipment.Type == "HEIDEHAIN")
                     { 
                         RequestHeidhData hdhReq = new RequestHeidhData();
-                        hdhReq.ServerUrl = device.ServerUrl;
-                        hdhReq.MachineName = device.UserName;
+                        hdhReq.ServerUrl = onlineDevice.ServerUrl;
+                        hdhReq.MachineName = onlineDevice.UserName;
                         hdhReq.Type = OpcUaActionTypeEnum.Connect.ToString();
                         var Result = await _apiRequestService.RequestAsync(RequsetModeEnum.Post, hdhUrlContext, hdhReq, null);
                         if (Result.IsSuccess)
@@ -1408,9 +1408,9 @@ namespace IMCS.CCS.Service.Impl
                             }
                         }
                     }
-                    else if (alarmEquipment.Type == "FANUC")
+                    else if (alarmEquipment != null && alarmEquipment.Type == "FANUC")
                     {
-                        string Url = fanucUrlContext + "?ip=" + device.Ip + "&port=" + device.Port;
+                        string Url = fanucUrlContext + "?ip=" + onlineDevice.Ip + "&port=" + onlineDevice.Port;
                         //调用发那科接口
                         var Result = await _apiRequestService.RequestAsync(RequsetModeEnum.Get, Url + "&fun=AlmInfo", null, null);
                         if (Result.IsSuccess)
@@ -1431,17 +1431,17 @@ namespace IMCS.CCS.Service.Impl
                         }
 
                     }
-                    else
+                    else if(alarmEquipment != null)
                     {
                         //缓存取PLCagvalue 值
                         List<CcsTagValue> tagValues = new List<CcsTagValue>();
-                        string tag_value_redis_key = imcs_redis_key + device.Ip + ":" + device.ProtocolType;
+                        string tag_value_redis_key = imcs_redis_key + onlineDevice.Ip + ":" + onlineDevice.ProtocolType;
                         var tagData = await _redisService.Database.StringGetAsync(tag_value_redis_key);
                         if (tagData.IsNullOrEmpty)
                         { 
                             CcsTagValue tagQuery = new CcsTagValue();
-                            tagQuery.ProtocolType = device.ProtocolType;
-                            tagQuery.Ip = device.Ip;
+                            tagQuery.ProtocolType = onlineDevice.ProtocolType;
+                            tagQuery.Ip = onlineDevice.Ip;
                             tagValues = _ccsTagValueService.GetList(tagQuery);
                             //首次设置redis
                             if (tagValues != null && tagValues.Count > 0)
@@ -1451,7 +1451,7 @@ namespace IMCS.CCS.Service.Impl
                         }
                         else
                         {
-                            tagValues = JsonConvert.DeserializeObject<List<CcsTagValue>>(data);
+                            tagValues = JsonConvert.DeserializeObject<List<CcsTagValue>>(tagData);
                         }
                         //获取机械手报警信息
                         CcsTagValue plcWarnValue = tagValues.Where(x => x.Ip == alarmEquipment.IP && x.Address == "DB200.34").FirstOrDefault();