|
@@ -1242,9 +1242,8 @@ namespace IMCS.CCS.Service.Impl
|
|
|
List<Device> devices = await getDeviceList();
|
|
|
//在线设备
|
|
|
//ftp不监控
|
|
|
- devices = devices.Where(x => !x.ProtocolType.Equals(ProtocalTypeEnum.FTP.ToString())).ToList();
|
|
|
- CcsTagValue tagQuery = new CcsTagValue();
|
|
|
- List<CcsTagValue> tagValues = _ccsTagValueService.GetList(tagQuery);
|
|
|
+ devices = devices.Where(x => !x.ProtocolType.Equals(ProtocalTypeEnum.FTP.ToString())).ToList();
|
|
|
+
|
|
|
List<EquipmentMonitor> equipmentMonitors = new List<EquipmentMonitor>();
|
|
|
string redis_key = "IMCS_CCS:MonitorEquipmentStatusJob";
|
|
|
var data = await _redisService.Database.StringGetAsync(redis_key);
|
|
@@ -1252,7 +1251,7 @@ namespace IMCS.CCS.Service.Impl
|
|
|
{
|
|
|
equipmentMonitors = await _equipmentMonitorService.GetList();
|
|
|
//首次设置redis
|
|
|
- if (tagValues != null && tagValues.Count > 0)
|
|
|
+ if (equipmentMonitors != null && equipmentMonitors.Count > 0)
|
|
|
{
|
|
|
await _redisService.Database.StringSetAsync(redis_key, JsonConvert.SerializeObject(equipmentMonitors));
|
|
|
}
|
|
@@ -1278,6 +1277,27 @@ namespace IMCS.CCS.Service.Impl
|
|
|
}
|
|
|
else if (device != null && equipment.Name == "机械手")
|
|
|
{
|
|
|
+ //缓存取PLCagvalue 值
|
|
|
+ List<CcsTagValue> tagValues = new List<CcsTagValue>();
|
|
|
+ string tag_value_redis_key = "IMCS_CCS:" + device.Ip + ":" + device.ProtocolType;
|
|
|
+ var tagData = await _redisService.Database.StringGetAsync(tag_value_redis_key);
|
|
|
+ if (data.IsNullOrEmpty)
|
|
|
+ {
|
|
|
+
|
|
|
+ CcsTagValue tagQuery = new CcsTagValue();
|
|
|
+ tagQuery.ProtocolType = device.ProtocolType;
|
|
|
+ tagQuery.Ip = device.Ip;
|
|
|
+ tagValues = _ccsTagValueService.GetList(tagQuery);
|
|
|
+ //首次设置redis
|
|
|
+ if (tagValues != null && tagValues.Count > 0)
|
|
|
+ {
|
|
|
+ await _redisService.Database.StringSetAsync(redis_key, JsonConvert.SerializeObject(tagValues));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tagValues = JsonConvert.DeserializeObject<List<CcsTagValue>>(data);
|
|
|
+ }
|
|
|
CcsTagValue ccsTagValue = tagValues.Where(x => x.Ip.Equals(equipment.IP) && x.Address.Equals(equipment.Address)).FirstOrDefault();
|
|
|
if (ccsTagValue != null)
|
|
|
{
|
|
@@ -1331,10 +1351,12 @@ namespace IMCS.CCS.Service.Impl
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ List<ProductionStatus> productionStatusList = new List<ProductionStatus>();
|
|
|
+
|
|
|
//变化的修改 并且更新缓存
|
|
|
if (changeEquipmentMonitors.Count > 0)
|
|
|
- {
|
|
|
- List<ProductionStatus> productionStatusList = new List<ProductionStatus>();
|
|
|
+ {
|
|
|
foreach (EquipmentMonitor changeEquipment in changeEquipmentMonitors)
|
|
|
{
|
|
|
ProductionStatus productionStatus = new ProductionStatus();
|
|
@@ -1342,74 +1364,106 @@ namespace IMCS.CCS.Service.Impl
|
|
|
productionStatus.onlineStatus = syncStatusMap[changeEquipment.Status].ToString();
|
|
|
//equipment.Status == "离线" ? "0" : "1";
|
|
|
//productionStatus.alertMsg = equipment.AlertMsg;
|
|
|
- if (productionStatus.onlineStatus != "3" && !string.IsNullOrEmpty(changeEquipment.Type))
|
|
|
+
|
|
|
+ productionStatusList.Add(productionStatus);
|
|
|
+
|
|
|
+ }
|
|
|
+ //修改并重置缓存
|
|
|
+ await _equipmentMonitorService.UpdateAndCache(equipmentMonitors);
|
|
|
+ }
|
|
|
+ //报警放入推送数组
|
|
|
+ foreach (Device device in devices)
|
|
|
+ {
|
|
|
+ EquipmentMonitor alarmEquipment = equipmentMonitors.Where(x => x.IP == device.Ip && x.Type == device.ProtocolType).FirstOrDefault();
|
|
|
+ ProductionStatus productionStatus = new ProductionStatus();
|
|
|
+ productionStatus.id = alarmEquipment.Id.ToString();
|
|
|
+
|
|
|
+ if (alarmEquipment.Type == "HEIDEHAIN")
|
|
|
+ {
|
|
|
+
|
|
|
+ RequestHeidhData hdhReq = new RequestHeidhData();
|
|
|
+ hdhReq.ServerUrl = device.ServerUrl;
|
|
|
+ hdhReq.MachineName = device.UserName;
|
|
|
+ hdhReq.Type = OpcUaActionTypeEnum.Connect.ToString();
|
|
|
+ var Result = await _apiRequestService.RequestAsync(RequsetModeEnum.Post, hdhUrlContext, hdhReq, null);
|
|
|
+ if (Result.IsSuccess)
|
|
|
{
|
|
|
- if (changeEquipment.Type == "HEIDEHAIN")
|
|
|
+ ResponseHeidhData responseData = JsonConvert.DeserializeObject<ResponseHeidhData>(Result.Message);
|
|
|
+ if (!string.IsNullOrEmpty(responseData.errorsInfo))
|
|
|
{
|
|
|
- RequestHeidhData hdhReq = new RequestHeidhData();
|
|
|
- Device device = devices.Where(x => x.Ip.Equals(changeEquipment.IP)).FirstOrDefault();
|
|
|
- hdhReq.ServerUrl = device.ServerUrl;
|
|
|
- hdhReq.MachineName = device.UserName;
|
|
|
- hdhReq.Type = OpcUaActionTypeEnum.Connect.ToString();
|
|
|
- var Result = await _apiRequestService.RequestAsync(RequsetModeEnum.Post, hdhUrlContext, hdhReq, null);
|
|
|
- if (Result.IsSuccess)
|
|
|
- {
|
|
|
- ResponseHeidhData responseData = JsonConvert.DeserializeObject<ResponseHeidhData>(Result.Message);
|
|
|
- if (!string.IsNullOrEmpty(responseData.errorsInfo))
|
|
|
- {
|
|
|
- productionStatus.alertMsg = responseData.errorsInfo;
|
|
|
- }
|
|
|
- }
|
|
|
+ productionStatus.alertMsg = responseData.errorsInfo;
|
|
|
+ productionStatusList.Add(productionStatus);
|
|
|
}
|
|
|
- else if (changeEquipment.Type == "FANUC")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (alarmEquipment.Type == "FANUC")
|
|
|
+ {
|
|
|
+ string Url = fanucUrlContext + "?ip=" + device.Ip + "&port=" + device.Port;
|
|
|
+ //调用发那科接口
|
|
|
+ var Result = await _apiRequestService.RequestAsync(RequsetModeEnum.Get, Url + "&fun=AlmInfo", null, null);
|
|
|
+ if (Result.IsSuccess)
|
|
|
+ {
|
|
|
+ //ResponseFanucData fncReq = new ResponseFanucData();
|
|
|
+ List<AlmInfo> AlmMsg = JsonConvert.DeserializeObject<List<AlmInfo>>(Result.Message);
|
|
|
+ //List<AlmInfo> AlmMsg = fncReq.AlmMsg;
|
|
|
+ if (AlmMsg != null && AlmMsg.Count > 0)
|
|
|
{
|
|
|
- Device device = devices.Where(x => x.Ip.Equals(changeEquipment.IP)).FirstOrDefault();
|
|
|
- string Url = fanucUrlContext + "?ip=" + device.Ip + "&port=" + device.Port;
|
|
|
- //调用发那科接口
|
|
|
- var Result = await _apiRequestService.RequestAsync(RequsetModeEnum.Get, Url + "&fun=AlmInfo", null, null);
|
|
|
- if (Result.IsSuccess)
|
|
|
- {
|
|
|
- //ResponseFanucData fncReq = new ResponseFanucData();
|
|
|
- List<AlmInfo> AlmMsg = JsonConvert.DeserializeObject<List<AlmInfo>>(Result.Message);
|
|
|
- //List<AlmInfo> AlmMsg = fncReq.AlmMsg;
|
|
|
- if (AlmMsg != null && AlmMsg.Count > 0)
|
|
|
- {
|
|
|
- var msgs = from o in AlmMsg select o.msg;
|
|
|
- productionStatus.alertMsg = string.Join(",", msgs.ToArray());
|
|
|
- }
|
|
|
- }
|
|
|
+ var msgs = from o in AlmMsg select o.msg;
|
|
|
+ productionStatus.alertMsg = string.Join(",", msgs.ToArray());
|
|
|
+ productionStatusList.Add(productionStatus);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //缓存取PLCagvalue 值
|
|
|
+ List<CcsTagValue> tagValues = new List<CcsTagValue>();
|
|
|
+ string tag_value_redis_key = "IMCS_CCS:" + device.Ip + ":" + device.ProtocolType;
|
|
|
+ var tagData = await _redisService.Database.StringGetAsync(tag_value_redis_key);
|
|
|
+ if (data.IsNullOrEmpty)
|
|
|
+ {
|
|
|
+ CcsTagValue tagQuery = new CcsTagValue();
|
|
|
+ tagQuery.ProtocolType = device.ProtocolType;
|
|
|
+ tagQuery.Ip = device.Ip;
|
|
|
+ tagValues = _ccsTagValueService.GetList(tagQuery);
|
|
|
+ //首次设置redis
|
|
|
+ if (tagValues != null && tagValues.Count > 0)
|
|
|
+ {
|
|
|
+ await _redisService.Database.StringSetAsync(redis_key, JsonConvert.SerializeObject(tagValues));
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //获取机械手报警信息
|
|
|
- CcsTagValue plcWarnValue = tagValues.Where(x => x.Ip ==changeEquipment.IP && x.Address =="DB200.34").FirstOrDefault();
|
|
|
- if (plcWarnValue != null)
|
|
|
- {
|
|
|
- ToolDto ccsDictionary = new ToolDto();
|
|
|
- ccsDictionary.Type = "PlcWarnInfo";
|
|
|
+ tagValues = JsonConvert.DeserializeObject<List<CcsTagValue>>(data);
|
|
|
+ }
|
|
|
+ //获取机械手报警信息
|
|
|
+ CcsTagValue plcWarnValue = tagValues.Where(x => x.Ip == alarmEquipment.IP && x.Address == "DB200.34").FirstOrDefault();
|
|
|
+ if (plcWarnValue != null)
|
|
|
+ {
|
|
|
+ ToolDto ccsDictionary = new ToolDto();
|
|
|
+ ccsDictionary.Type = "PlcWarnInfo";
|
|
|
|
|
|
- List<ToolDto> dictList = await _dictionaryService.GetList(ccsDictionary);
|
|
|
- if (dictList.Count > 0 && dictList[0] != null)
|
|
|
+ List<ToolDto> dictList = await _dictionaryService.GetList(ccsDictionary);
|
|
|
+ if (dictList.Count > 0 && dictList[0] != null)
|
|
|
+ {
|
|
|
+ ToolDto dictObj = dictList.Where(x => x.Code.Equals(plcWarnValue.TagValue) && x.state).FirstOrDefault();
|
|
|
+ if (null != dictObj && !string.IsNullOrEmpty(dictObj.DictValue.Trim()))
|
|
|
{
|
|
|
- ToolDto dictObj = dictList.Where(x => x.Code.Equals(plcWarnValue.TagValue) && x.state).FirstOrDefault();
|
|
|
- if (null!=dictObj && !string.IsNullOrEmpty(dictObj.DictValue.Trim()))
|
|
|
- {
|
|
|
- productionStatus.alertMsg = dictObj.DictValue.Trim();
|
|
|
- }
|
|
|
+ productionStatus.alertMsg = dictObj.DictValue.Trim();
|
|
|
}
|
|
|
+ productionStatusList.Add(productionStatus);
|
|
|
}
|
|
|
}
|
|
|
- productionStatusList.Add(productionStatus);
|
|
|
-
|
|
|
}
|
|
|
- //修改并重置缓存
|
|
|
- await _equipmentMonitorService.UpdateAndCache(equipmentMonitors);
|
|
|
- //await _redisService.Database.StringSetAsync(redis_key, JsonConvert.SerializeObject(equipmentMonitors));
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ //推送
|
|
|
+ if (productionStatusList != null && productionStatusList.Count > 0)
|
|
|
+ {
|
|
|
//主动推送同步状态数据接口
|
|
|
- RequestSynStatusData requestData = new RequestSynStatusData();
|
|
|
+ RequestSynStatusData requestData = new RequestSynStatusData();
|
|
|
requestData.productionStatus = JsonConvert.SerializeObject(productionStatusList);
|
|
|
String synStatusUrl = ecsRootUrlContext + "/api/authority/synStatus/synProductionStatus";
|
|
|
var result = await _apiRequestService.RequestAsync(RequsetModeEnum.Post, synStatusUrl, requestData, null);
|